From 36d9523e317d958c4022d7a56c8bf85bbcb9c043 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 9 Oct 2025 13:46:33 +0200 Subject: [PATCH] opts: deprecate ValidateMACAddress It was a wrapper around net.ParseMAC from stdlib, so users should use that directly. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 17d6a929548ae0693affef54f36f03d27f00e603) Signed-off-by: Sebastiaan van Stijn --- cli/command/container/opts.go | 5 +++-- opts/opts.go | 2 ++ opts/opts_test.go | 14 -------------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index 5ff39c4ee0..b520d6b13a 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "net" "os" "path" "path/filepath" @@ -350,7 +351,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con // Validate the input mac address if copts.macAddress != "" { - if _, err := opts.ValidateMACAddress(copts.macAddress); err != nil { + if _, err := net.ParseMAC(strings.TrimSpace(copts.macAddress)); err != nil { return nil, errors.Errorf("%s is not a valid mac address", copts.macAddress) } } @@ -883,7 +884,7 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*networktypes.End } } if ep.MacAddress != "" { - if _, err := opts.ValidateMACAddress(ep.MacAddress); err != nil { + if _, err := net.ParseMAC(strings.TrimSpace(ep.MacAddress)); err != nil { return nil, errors.Errorf("%s is not a valid mac address", ep.MacAddress) } epConfig.MacAddress = ep.MacAddress diff --git a/opts/opts.go b/opts/opts.go index 94eda0560a..d1072f6ca1 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -264,6 +264,8 @@ func ValidateIPAddress(val string) (string, error) { } // ValidateMACAddress validates a MAC address. +// +// Deprecated: use [net.ParseMAC]. This function will be removed in the next release. func ValidateMACAddress(val string) (string, error) { _, err := net.ParseMAC(strings.TrimSpace(val)) if err != nil { diff --git a/opts/opts_test.go b/opts/opts_test.go index 7dc87cad9e..d49c7fb5fc 100644 --- a/opts/opts_test.go +++ b/opts/opts_test.go @@ -396,20 +396,6 @@ func TestNamedMapOpts(t *testing.T) { } } -func TestValidateMACAddress(t *testing.T) { - if _, err := ValidateMACAddress(`92:d0:c6:0a:29:33`); err != nil { - t.Fatalf("ValidateMACAddress(`92:d0:c6:0a:29:33`) got %s", err) - } - - if _, err := ValidateMACAddress(`92:d0:c6:0a:33`); err == nil { - t.Fatalf("ValidateMACAddress(`92:d0:c6:0a:33`) succeeded; expected failure on invalid MAC") - } - - if _, err := ValidateMACAddress(`random invalid string`); err == nil { - t.Fatalf("ValidateMACAddress(`random invalid string`) succeeded; expected failure on invalid MAC") - } -} - func TestValidateLink(t *testing.T) { valid := []string{ "name",