]> Cypherpunks repositories - gostls13.git/commitdiff
net: allow ParseMAC to parse 20-octet IPoIB link-layer address
authorMatt Layher <mdlayher@gmail.com>
Fri, 17 Jul 2015 21:28:42 +0000 (17:28 -0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 24 Aug 2015 16:34:43 +0000 (16:34 +0000)
Fixes #11763

Change-Id: Ie291b36a8c29694e80940836d7e6fd96d2d76494
Reviewed-on: https://go-review.googlesource.com/12382
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>

src/net/mac.go
src/net/mac_test.go

index 8594a9146ae681772e1cbc1f5032d03eab2d0278..93f0b091219889ed337fb2b33e815e0a21048ce6 100644 (file)
@@ -24,14 +24,17 @@ func (a HardwareAddr) String() string {
        return string(buf)
 }
 
-// ParseMAC parses s as an IEEE 802 MAC-48, EUI-48, or EUI-64 using one of the
-// following formats:
+// ParseMAC parses s as an IEEE 802 MAC-48, EUI-48, EUI-64, or a 20-octet
+// IP over InfiniBand link-layer address using one of the following formats:
 //   01:23:45:67:89:ab
 //   01:23:45:67:89:ab:cd:ef
+//   01:23:45:67:89:ab:cd:ef:00:00:01:23:45:67:89:ab:cd:ef:00:00
 //   01-23-45-67-89-ab
 //   01-23-45-67-89-ab-cd-ef
+//   01-23-45-67-89-ab-cd-ef-00-00-01-23-45-67-89-ab-cd-ef-00-00
 //   0123.4567.89ab
 //   0123.4567.89ab.cdef
+//   0123.4567.89ab.cdef.0000.0123.4567.89ab.cdef.0000
 func ParseMAC(s string) (hw HardwareAddr, err error) {
        if len(s) < 14 {
                goto error
@@ -42,7 +45,7 @@ func ParseMAC(s string) (hw HardwareAddr, err error) {
                        goto error
                }
                n := (len(s) + 1) / 3
-               if n != 6 && n != 8 {
+               if n != 6 && n != 8 && n != 20 {
                        goto error
                }
                hw = make(HardwareAddr, n)
@@ -58,7 +61,7 @@ func ParseMAC(s string) (hw HardwareAddr, err error) {
                        goto error
                }
                n := 2 * (len(s) + 1) / 5
-               if n != 6 && n != 8 {
+               if n != 6 && n != 8 && n != 20 {
                        goto error
                }
                hw = make(HardwareAddr, n)
index 0af0c014f50736081268014ad42a6b7b075f0a14..1ec6b287ac3a4062299141657a83956a9110eaca 100644 (file)
@@ -34,6 +34,30 @@ var parseMACTests = []struct {
        {"01:23:45:67:89:AB:CD:EF", HardwareAddr{1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, ""},
        {"01-23-45-67-89-AB-CD-EF", HardwareAddr{1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, ""},
        {"0123.4567.89AB.CDEF", HardwareAddr{1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, ""},
+       {
+               "01:23:45:67:89:ab:cd:ef:00:00:01:23:45:67:89:ab:cd:ef:00:00",
+               HardwareAddr{
+                       0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00,
+                       0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00,
+               },
+               "",
+       },
+       {
+               "01-23-45-67-89-ab-cd-ef-00-00-01-23-45-67-89-ab-cd-ef-00-00",
+               HardwareAddr{
+                       0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00,
+                       0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00,
+               },
+               "",
+       },
+       {
+               "0123.4567.89ab.cdef.0000.0123.4567.89ab.cdef.0000",
+               HardwareAddr{
+                       0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00,
+                       0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00,
+               },
+               "",
+       },
 }
 
 func TestParseMAC(t *testing.T) {