Commit b9d19eff authored by Mikio Hara's avatar Mikio Hara

net: use EUI-48/EUI-64 reserved address blocks for documentation

Updates #15228.

Change-Id: I1b73defccb4c933d71c408aa31d32af9d1bc4ab8
Reviewed-on: https://go-review.googlesource.com/c/163357Reviewed-by: default avatarMatt Layher <mdlayher@gmail.com>
parent 9426d8c6
...@@ -26,15 +26,15 @@ func (a HardwareAddr) String() string { ...@@ -26,15 +26,15 @@ func (a HardwareAddr) String() string {
// ParseMAC parses s as an IEEE 802 MAC-48, EUI-48, EUI-64, or a 20-octet // 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: // IP over InfiniBand link-layer address using one of the following formats:
// 01:23:45:67:89:ab // 00:00:5e:00:53:01
// 01:23:45:67:89:ab:cd:ef // 02:00:5e:10:00:00:00:01
// 01:23:45:67:89:ab:cd:ef:00:00:01:23:45:67:89:ab:cd:ef:00:00 // 00:00:00:00:fe:80:00:00:00:00:00:00:02:00:5e:10:00:00:00:01
// 01-23-45-67-89-ab // 00-00-5e-00-53-01
// 01-23-45-67-89-ab-cd-ef // 02-00-5e-10-00-00-00-01
// 01-23-45-67-89-ab-cd-ef-00-00-01-23-45-67-89-ab-cd-ef-00-00 // 00-00-00-00-fe-80-00-00-00-00-00-00-02-00-5e-10-00-00-00-01
// 0123.4567.89ab // 0000.5e00.5301
// 0123.4567.89ab.cdef // 0200.5e10.0000.0001
// 0123.4567.89ab.cdef.0000.0123.4567.89ab.cdef.0000 // 0000.0000.fe80.0000.0000.0000.0200.5e10.0000.0001
func ParseMAC(s string) (hw HardwareAddr, err error) { func ParseMAC(s string) (hw HardwareAddr, err error) {
if len(s) < 14 { if len(s) < 14 {
goto error goto error
......
...@@ -15,49 +15,69 @@ var parseMACTests = []struct { ...@@ -15,49 +15,69 @@ var parseMACTests = []struct {
out HardwareAddr out HardwareAddr
err string err string
}{ }{
{"01:23:45:67:89:AB", HardwareAddr{1, 0x23, 0x45, 0x67, 0x89, 0xab}, ""}, // See RFC 7042, Section 2.1.1.
{"01-23-45-67-89-AB", HardwareAddr{1, 0x23, 0x45, 0x67, 0x89, 0xab}, ""}, {"00:00:5e:00:53:01", HardwareAddr{0x00, 0x00, 0x5e, 0x00, 0x53, 0x01}, ""},
{"0123.4567.89AB", HardwareAddr{1, 0x23, 0x45, 0x67, 0x89, 0xab}, ""}, {"00-00-5e-00-53-01", HardwareAddr{0x00, 0x00, 0x5e, 0x00, 0x53, 0x01}, ""},
{"ab:cd:ef:AB:CD:EF", HardwareAddr{0xab, 0xcd, 0xef, 0xab, 0xcd, 0xef}, ""}, {"0000.5e00.5301", HardwareAddr{0x00, 0x00, 0x5e, 0x00, 0x53, 0x01}, ""},
{"01.02.03.04.05.06", nil, "invalid MAC address"},
{"01:02:03:04:05:06:", nil, "invalid MAC address"}, // See RFC 7042, Section 2.2.2.
{"x1:02:03:04:05:06", nil, "invalid MAC address"}, {"02:00:5e:10:00:00:00:01", HardwareAddr{0x02, 0x00, 0x5e, 0x10, 0x00, 0x00, 0x00, 0x01}, ""},
{"01002:03:04:05:06", nil, "invalid MAC address"}, {"02-00-5e-10-00-00-00-01", HardwareAddr{0x02, 0x00, 0x5e, 0x10, 0x00, 0x00, 0x00, 0x01}, ""},
{"01:02003:04:05:06", nil, "invalid MAC address"}, {"0200.5e10.0000.0001", HardwareAddr{0x02, 0x00, 0x5e, 0x10, 0x00, 0x00, 0x00, 0x01}, ""},
{"01:02:03004:05:06", nil, "invalid MAC address"},
{"01:02:03:04005:06", nil, "invalid MAC address"}, // See RFC 4391, Section 9.1.1.
{"01:02:03:04:05006", nil, "invalid MAC address"},
{"01-02:03:04:05:06", nil, "invalid MAC address"},
{"01:02-03-04-05-06", nil, "invalid MAC address"},
{"0123:4567:89AF", nil, "invalid MAC address"},
{"0123-4567-89AF", nil, "invalid MAC address"},
{"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", "00:00:00:00:fe:80:00:00:00:00:00:00:02:00:5e:10:00:00:00:01",
HardwareAddr{ HardwareAddr{
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x5e, 0x10, 0x00, 0x00, 0x00, 0x01,
}, },
"", "",
}, },
{ {
"01-23-45-67-89-ab-cd-ef-00-00-01-23-45-67-89-ab-cd-ef-00-00", "00-00-00-00-fe-80-00-00-00-00-00-00-02-00-5e-10-00-00-00-01",
HardwareAddr{ HardwareAddr{
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x5e, 0x10, 0x00, 0x00, 0x00, 0x01,
}, },
"", "",
}, },
{ {
"0123.4567.89ab.cdef.0000.0123.4567.89ab.cdef.0000", "0000.0000.fe80.0000.0000.0000.0200.5e10.0000.0001",
HardwareAddr{ HardwareAddr{
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x5e, 0x10, 0x00, 0x00, 0x00, 0x01,
}, },
"", "",
}, },
{"ab:cd:ef:AB:CD:EF", HardwareAddr{0xab, 0xcd, 0xef, 0xab, 0xcd, 0xef}, ""},
{"ab:cd:ef:AB:CD:EF:ab:cd", HardwareAddr{0xab, 0xcd, 0xef, 0xab, 0xcd, 0xef, 0xab, 0xcd}, ""},
{
"ab:cd:ef:AB:CD:EF:ab:cd:ef:AB:CD:EF:ab:cd:ef:AB:CD:EF:ab:cd",
HardwareAddr{
0xab, 0xcd, 0xef, 0xab,
0xcd, 0xef, 0xab, 0xcd, 0xef, 0xab, 0xcd, 0xef,
0xab, 0xcd, 0xef, 0xab, 0xcd, 0xef, 0xab, 0xcd,
},
"",
},
{"01.02.03.04.05.06", nil, "invalid MAC address"},
{"01:02:03:04:05:06:", nil, "invalid MAC address"},
{"x1:02:03:04:05:06", nil, "invalid MAC address"},
{"01002:03:04:05:06", nil, "invalid MAC address"},
{"01:02003:04:05:06", nil, "invalid MAC address"},
{"01:02:03004:05:06", nil, "invalid MAC address"},
{"01:02:03:04005:06", nil, "invalid MAC address"},
{"01:02:03:04:05006", nil, "invalid MAC address"},
{"01-02:03:04:05:06", nil, "invalid MAC address"},
{"01:02-03-04-05-06", nil, "invalid MAC address"},
{"0123:4567:89AF", nil, "invalid MAC address"},
{"0123-4567-89AF", nil, "invalid MAC address"},
} }
func TestParseMAC(t *testing.T) { func TestParseMAC(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment