diff options
author | Akshay Navale <akna8887@colorado.edu> | 2019-05-24 09:49:55 -0600 |
---|---|---|
committer | Pablo Mazzini <pmazzini@gmail.com> | 2019-05-24 16:49:55 +0100 |
commit | 32228cdfe81f31b2ac5d6bbfbe36db7cdee92ea6 (patch) | |
tree | 544dce81176c4fad49758b3ce9cbd5c9d77446e2 /dhcpv4/ztpv4 | |
parent | 5dce45b2b680c398f6052c14c0f7558add495130 (diff) |
Changing Arista cid regex forprepended bytes (#293)
Diffstat (limited to 'dhcpv4/ztpv4')
-rw-r--r-- | dhcpv4/ztpv4/parse_circuitid.go | 12 | ||||
-rw-r--r-- | dhcpv4/ztpv4/parse_circuitid_test.go | 2 |
2 files changed, 5 insertions, 9 deletions
diff --git a/dhcpv4/ztpv4/parse_circuitid.go b/dhcpv4/ztpv4/parse_circuitid.go index caa172d..a0616f2 100644 --- a/dhcpv4/ztpv4/parse_circuitid.go +++ b/dhcpv4/ztpv4/parse_circuitid.go @@ -1,7 +1,6 @@ package ztpv4 import ( - "bytes" "fmt" "regexp" @@ -25,12 +24,13 @@ var circuitRegexs = []*regexp.Regexp{ // Juniper EX ge-0/0/0.0 regexp.MustCompile("^ge-(?P<slot>[0-9]+)/(?P<mod>[0-9]+)/(?P<port>[0-9]+).(?P<subport>[0-9]+).*"), // Arista Ethernet3/17/1 - regexp.MustCompile("^Ethernet(?P<slot>[0-9]+)/(?P<mod>[0-9]+)/(?P<port>[0-9]+)$"), + // Sometimes Arista prepend circuit id type(1 byte) and length(1 byte) not useing ^ + regexp.MustCompile("Ethernet(?P<slot>[0-9]+)/(?P<mod>[0-9]+)/(?P<port>[0-9]+)$"), // Juniper QFX et-1/0/61 regexp.MustCompile("^et-(?P<slot>[0-9]+)/(?P<mod>[0-9]+)/(?P<port>[0-9]+)$"), // Arista Ethernet14:Vlan2001 // Arista Ethernet10:2020 - regexp.MustCompile("^Ethernet(?P<port>[0-9]+):(?P<vlan>.*)$"), + regexp.MustCompile("Ethernet(?P<port>[0-9]+):(?P<vlan>.*)$"), // Cisco Gi1/10:2020 regexp.MustCompile("^Gi(?P<slot>[0-9]+)/(?P<port>[0-9]+):(?P<vlan>.*)$"), // Nexus Ethernet1/3 @@ -50,11 +50,7 @@ func ParseCircuitID(packet *dhcpv4.DHCPv4) (*CircuitID, error) { // As per RFC 3046 sub-Option 1 is circuit-id. Look at 2.0 section in that RFC // https://tools.ietf.org/html/rfc3046 - cid := relayOptions.Options.Get(dhcpv4.AgentCircuitIDSubOption) - // Some Vendor like Arista sends SHIFT IN character i.e. 0x000f before circuitid - // remove it before matching against regexps. - cid = bytes.TrimPrefix(cid, []byte{0x00, 0x0f}) - circuitIdStr := string(cid) + circuitIdStr := string(relayOptions.Options.Get(dhcpv4.AgentCircuitIDSubOption)) if circuitIdStr == "" { return nil, fmt.Errorf("no circuit-id suboption found in dhcpv4 packet") } diff --git a/dhcpv4/ztpv4/parse_circuitid_test.go b/dhcpv4/ztpv4/parse_circuitid_test.go index 848fb33..d51b075 100644 --- a/dhcpv4/ztpv4/parse_circuitid_test.go +++ b/dhcpv4/ztpv4/parse_circuitid_test.go @@ -86,7 +86,7 @@ func TestParseCircuitID(t *testing.T) { {name: "Cisco pattern", circuit: []byte("Gi1/10:2020"), want: &CircuitID{Slot: "1", Port: "10", Vlan: "2020"}}, {name: "Cisco Nexus pattern", circuit: []byte("Ethernet1/3"), want: &CircuitID{Slot: "1", Port: "3"}}, {name: "Juniper Bundle Pattern", circuit: []byte("ae52.0"), want: &CircuitID{Port: "52", SubPort: "0"}}, - {name: "Arista Vlan pattern 1 with SHIFT IN", circuit: []byte("\x00\x0fEthernet14:Vlan2001"), want: &CircuitID{Port: "14", Vlan: "Vlan2001"}}, + {name: "Arista Vlan pattern 1 with circuitid type and length", circuit: []byte("\x00\x0fEthernet14:2001"), want: &CircuitID{Port: "14", Vlan: "2001"}}, {name: "juniperEX pattern", circuit: []byte("ge-0/0/0.0:RANDOMCHAR"), want: &CircuitID{Slot: "0", Module: "0", Port: "0", SubPort: "0"}}, } for _, tc := range tt { |