mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
api/t/network: represent MAC addrs as byte slices
Make invalid states unrepresentable by moving away from stringly-typed MAC address values in API structs. As go.dev/issue/29678 has not yet been implemented, provide our own HardwareAddr byte-slice type which implements TextMarshaler and TextUnmarshaler to retain compatibility with the API wire format. When stdlib's net.HardwareAddr type implements TextMarshaler and TextUnmarshaler and GODEBUG=netmarshal becomes the default, we should be able to make the type a straight alias for stdlib net.HardwareAddr as a non-breaking change. Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
"runtime"
|
||||
@@ -545,13 +544,6 @@ func validateEndpointSettings(nw *libnetwork.Network, nwName string, epConfig *n
|
||||
errs = validateIPAMConfigIsInRange(errs, ipamConfig, v4Configs, v6Configs)
|
||||
}
|
||||
|
||||
if epConfig.MacAddress != "" {
|
||||
_, err := net.ParseMAC(epConfig.MacAddress)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid MAC address %s", epConfig.MacAddress)
|
||||
}
|
||||
}
|
||||
|
||||
if sysctls, ok := epConfig.DriverOpts[netlabel.EndpointSysctls]; ok {
|
||||
for _, sysctl := range strings.Split(sysctls, ",") {
|
||||
scname := strings.SplitN(sysctl, ".", 5)
|
||||
@@ -647,7 +639,7 @@ func cleanOperationalData(es *network.EndpointSettings) {
|
||||
es.IPv6Gateway = netip.Addr{}
|
||||
es.GlobalIPv6Address = netip.Addr{}
|
||||
es.GlobalIPv6PrefixLen = 0
|
||||
es.MacAddress = ""
|
||||
es.MacAddress = nil
|
||||
if es.IPAMOperational {
|
||||
es.IPAMConfig = nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user