Merge pull request #3568 from stgraber/main
Some checks are pending
Build / Build (${{ matrix.architecture }}) (amd64) (push) Waiting to run
Build / Build (${{ matrix.architecture }}) (arm64) (push) Waiting to run
Tests / Code (oldstable) (push) Waiting to run
Tests / Code (stable) (push) Waiting to run
Tests / Code (tip) (push) Waiting to run
Tests / System (btrfs, stable, ubuntu-24.04, cluster) (push) Waiting to run
Tests / System (btrfs, stable, ubuntu-24.04, standalone_storage) (push) Waiting to run
Tests / System (ceph, stable, ubuntu-24.04, cluster) (push) Waiting to run
Tests / System (ceph, stable, ubuntu-24.04, standalone_storage) (push) Waiting to run
Tests / System (dir, oldstable, ubuntu-24.04, cluster) (push) Waiting to run
Tests / System (dir, oldstable, ubuntu-24.04, standalone_container) (push) Waiting to run
Tests / System (dir, oldstable, ubuntu-24.04, standalone_core) (push) Waiting to run
Tests / System (dir, oldstable, ubuntu-24.04, standalone_network) (push) Waiting to run
Tests / System (dir, oldstable, ubuntu-24.04, standalone_storage) (push) Waiting to run
Tests / System (dir, oldstable, ubuntu-24.04-arm, cluster) (push) Waiting to run
Tests / System (dir, oldstable, ubuntu-24.04-arm, standalone_container) (push) Waiting to run
Tests / System (dir, oldstable, ubuntu-24.04-arm, standalone_core) (push) Waiting to run
Tests / System (dir, oldstable, ubuntu-24.04-arm, standalone_network) (push) Waiting to run
Tests / System (dir, oldstable, ubuntu-24.04-arm, standalone_storage) (push) Waiting to run
Tests / System (dir, stable, ubuntu-24.04, cluster) (push) Waiting to run
Tests / System (dir, stable, ubuntu-24.04, standalone_container) (push) Waiting to run
Tests / System (dir, stable, ubuntu-24.04, standalone_core) (push) Waiting to run
Tests / System (dir, stable, ubuntu-24.04, standalone_network) (push) Waiting to run
Tests / System (dir, stable, ubuntu-24.04, standalone_storage) (push) Waiting to run
Tests / System (dir, stable, ubuntu-24.04-arm, cluster) (push) Waiting to run
Tests / System (dir, stable, ubuntu-24.04-arm, standalone_container) (push) Waiting to run
Tests / System (dir, stable, ubuntu-24.04-arm, standalone_core) (push) Waiting to run
Tests / System (dir, stable, ubuntu-24.04-arm, standalone_network) (push) Waiting to run
Tests / System (dir, stable, ubuntu-24.04-arm, standalone_storage) (push) Waiting to run
Tests / System (dir, tip, ubuntu-24.04, cluster) (push) Waiting to run
Tests / System (dir, tip, ubuntu-24.04, standalone_container) (push) Waiting to run
Tests / System (dir, tip, ubuntu-24.04, standalone_core) (push) Waiting to run
Tests / System (dir, tip, ubuntu-24.04, standalone_network) (push) Waiting to run
Tests / System (dir, tip, ubuntu-24.04, standalone_storage) (push) Waiting to run
Tests / System (dir, tip, ubuntu-24.04-arm, cluster) (push) Waiting to run
Tests / System (dir, tip, ubuntu-24.04-arm, standalone_container) (push) Waiting to run
Tests / System (dir, tip, ubuntu-24.04-arm, standalone_core) (push) Waiting to run
Tests / System (dir, tip, ubuntu-24.04-arm, standalone_network) (push) Waiting to run
Tests / System (dir, tip, ubuntu-24.04-arm, standalone_storage) (push) Waiting to run
Tests / System (linstor, stable, ubuntu-24.04, cluster) (push) Waiting to run
Tests / System (linstor, stable, ubuntu-24.04, standalone_storage) (push) Waiting to run
Tests / System (lvm, stable, ubuntu-24.04, cluster) (push) Waiting to run
Tests / System (lvm, stable, ubuntu-24.04, standalone_storage) (push) Waiting to run
Tests / System (random, stable, ubuntu-24.04, cluster) (push) Waiting to run
Tests / System (random, stable, ubuntu-24.04, standalone_storage) (push) Waiting to run
Tests / System (zfs, stable, ubuntu-24.04, cluster) (push) Waiting to run
Tests / System (zfs, stable, ubuntu-24.04, standalone_storage) (push) Waiting to run
Tests / Client (oldstable, macos-latest) (push) Waiting to run
Tests / Client (oldstable, ubuntu-latest) (push) Waiting to run
Tests / Client (oldstable, windows-latest) (push) Waiting to run
Tests / Client (stable, macos-latest) (push) Waiting to run
Tests / Client (stable, ubuntu-latest) (push) Waiting to run
Tests / Client (stable, windows-latest) (push) Waiting to run
Tests / Documentation (push) Waiting to run

incusd/devices: Allow /32 and /128 for OCI addresses
This commit is contained in:
Stéphane Graber 2026-06-30 11:59:53 -04:00 committed by GitHub
commit 708f897921
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 28 additions and 16 deletions

View File

@ -169,11 +169,11 @@ func (c *cmdAdminInit) askNetworking(config *api.InitPreseed, d incus.InstanceSe
// IPv4
network.Config["ipv4.address"], err = c.global.asker.AskString(i18n.G("What IPv4 address should be used?")+" (CIDR subnet notation, “auto” or “none”) [default=auto]: ", "auto", func(value string) error {
if slices.Contains([]string{"auto", "none"}, value) {
if slices.Contains([]string{"auto", "none", ""}, value) {
return nil
}
return validate.Optional(validate.IsNetworkAddressCIDRV4)(value)
return validate.IsNetworkAddressCIDRV4(value, false)
})
if err != nil {
return err
@ -190,11 +190,11 @@ func (c *cmdAdminInit) askNetworking(config *api.InitPreseed, d incus.InstanceSe
// IPv6
network.Config["ipv6.address"], err = c.global.asker.AskString(i18n.G("What IPv6 address should be used?")+" (CIDR subnet notation, “auto” or “none”) [default=auto]: ", "auto", func(value string) error {
if slices.Contains([]string{"auto", "none"}, value) {
if slices.Contains([]string{"auto", "none", ""}, value) {
return nil
}
return validate.Optional(validate.IsNetworkAddressCIDRV6)(value)
return validate.IsNetworkAddressCIDRV6(value, false)
})
if err != nil {
return err

View File

@ -608,7 +608,7 @@ func (d *nicBridged) validateConfig(instConf instance.ConfigReader, partialValid
}
if strings.Contains(value, "/") {
return validate.IsNetworkAddressCIDRV4(value)
return validate.IsNetworkAddressCIDRV4(value, true)
}
return validate.IsNetworkAddressV4(value)
@ -620,7 +620,7 @@ func (d *nicBridged) validateConfig(instConf instance.ConfigReader, partialValid
}
if strings.Contains(value, "/") {
return validate.IsNetworkAddressCIDRV6(value)
return validate.IsNetworkAddressCIDRV6(value, true)
}
return validate.IsNetworkAddressV6(value)

View File

@ -509,7 +509,7 @@ func (d *nicOVN) validateConfig(instConf instance.ConfigReader, partialValidatio
}
if strings.Contains(value, "/") {
return validate.IsNetworkAddressCIDRV4(value)
return validate.IsNetworkAddressCIDRV4(value, true)
}
return validate.IsNetworkAddressV4(value)
@ -521,7 +521,7 @@ func (d *nicOVN) validateConfig(instConf instance.ConfigReader, partialValidatio
}
if strings.Contains(value, "/") {
return validate.IsNetworkAddressCIDRV6(value)
return validate.IsNetworkAddressCIDRV6(value, true)
}
return validate.IsNetworkAddressV6(value)

View File

@ -269,7 +269,7 @@ func (n *bridge) Validate(config map[string]string, clientType request.ClientTyp
return nil
}
return validate.IsNetworkAddressCIDRV4(value)
return validate.IsNetworkAddressCIDRV4(value, false)
}),
// gendoc:generate(entity=network_bridge, group=common, key=ipv4.firewall)
@ -398,7 +398,7 @@ func (n *bridge) Validate(config map[string]string, clientType request.ClientTyp
return nil
}
return validate.Or(validate.IsNetworkAddressCIDRV6, validate.IsNetworkV6)(value)
return validate.Or(func(value string) error { return validate.IsNetworkAddressCIDRV6(value, false) }, validate.IsNetworkV6)(value)
}),
// gendoc:generate(entity=network_bridge, group=common, key=ipv6.firewall)

View File

@ -510,7 +510,7 @@ func (n *ovn) Validate(config map[string]string, clientType request.ClientType)
return nil
}
return validate.IsNetworkAddressCIDRV4(value)
return validate.IsNetworkAddressCIDRV4(value, true)
}),
// gendoc:generate(entity=network_ovn, group=common, key=ipv4.dhcp)
@ -578,7 +578,7 @@ func (n *ovn) Validate(config map[string]string, clientType request.ClientType)
return nil
}
return validate.IsNetworkAddressCIDRV6(value)
return validate.IsNetworkAddressCIDRV6(value, true)
}),
// gendoc:generate(entity=network_ovn, group=common, key=ipv6.dhcp)

View File

@ -95,7 +95,7 @@ func (n *physical) Validate(config map[string]string, clientType request.ClientT
// type: string
// condition: standard mode
// shortdesc: IPv4 address for the gateway and network (CIDR)
"ipv4.gateway": validate.Optional(validate.IsNetworkAddressCIDRV4),
"ipv4.gateway": validate.Optional(func(value string) error { return validate.IsNetworkAddressCIDRV4(value, false) }),
// gendoc:generate(entity=network_physical, group=ipv6, key=ipv6.gateway)
//
@ -103,7 +103,7 @@ func (n *physical) Validate(config map[string]string, clientType request.ClientT
// type: string
// condition: standard mode
// shortdesc: IPv6 address for the gateway and network (CIDR)
"ipv6.gateway": validate.Optional(validate.IsNetworkAddressCIDRV6),
"ipv6.gateway": validate.Optional(func(value string) error { return validate.IsNetworkAddressCIDRV6(value, false) }),
// gendoc:generate(entity=network_physical, group=ipv4, key=ipv4.gateway.hwaddr)
//

View File

@ -367,7 +367,7 @@ func IsNetworkAddressV4(value string) error {
}
// IsNetworkAddressCIDRV4 validates an IPv4 address string in CIDR format.
func IsNetworkAddressCIDRV4(value string) error {
func IsNetworkAddressCIDRV4(value string, allowSingle bool) error {
ip, subnet, err := net.ParseCIDR(value)
if err != nil {
return err
@ -377,6 +377,12 @@ func IsNetworkAddressCIDRV4(value string) error {
return fmt.Errorf("Not an IPv4 address %q", value)
}
subnetSize, _ := subnet.Mask.Size()
if allowSingle && subnetSize == 32 {
// Single addresses are allowed through.
return nil
}
if ip.String() == subnet.IP.String() {
return fmt.Errorf("Not a usable IPv4 address %q", value)
}
@ -430,7 +436,7 @@ func IsNetworkAddressV6(value string) error {
}
// IsNetworkAddressCIDRV6 validates an IPv6 address string in CIDR format.
func IsNetworkAddressCIDRV6(value string) error {
func IsNetworkAddressCIDRV6(value string, allowSingle bool) error {
ip, subnet, err := net.ParseCIDR(value)
if err != nil {
return err
@ -440,6 +446,12 @@ func IsNetworkAddressCIDRV6(value string) error {
return fmt.Errorf("Not an IPv6 address %q", value)
}
subnetSize, _ := subnet.Mask.Size()
if allowSingle && subnetSize == 128 {
// Single addresses are allowed through.
return nil
}
if ip.String() == subnet.IP.String() {
return fmt.Errorf("Not a usable IPv6 address %q", value)
}