diff options
author | Akshay Navale <akna8887@colorado.edu> | 2019-05-14 12:01:24 -0600 |
---|---|---|
committer | Pablo Mazzini <pmazzini@gmail.com> | 2019-05-14 19:01:24 +0100 |
commit | 5edbeccad6b7f79c95bc4f8193d7af023fa3f331 (patch) | |
tree | 22a140b776e0f0a160612c91d88371e06a6ca4e4 /dhcpv4 | |
parent | fcbde74dab23754aa33fbcd409327c0a1409f2a7 (diff) |
Remove SHIFT IN character bytes from Circuit ID (#289)
Diffstat (limited to 'dhcpv4')
-rw-r--r-- | dhcpv4/ztpv4/parse_circuitid.go | 7 | ||||
-rw-r--r-- | dhcpv4/ztpv4/parse_circuitid_test.go | 1 |
2 files changed, 7 insertions, 1 deletions
diff --git a/dhcpv4/ztpv4/parse_circuitid.go b/dhcpv4/ztpv4/parse_circuitid.go index b9db358..5bcee24 100644 --- a/dhcpv4/ztpv4/parse_circuitid.go +++ b/dhcpv4/ztpv4/parse_circuitid.go @@ -1,6 +1,7 @@ package ztpv4 import ( + "bytes" "fmt" "regexp" @@ -47,7 +48,11 @@ 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 - circuitIdStr := string(relayOptions.Options.Get(dhcpv4.AgentCircuitIDSubOption)) + 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) 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 94061c4..897fdb2 100644 --- a/dhcpv4/ztpv4/parse_circuitid_test.go +++ b/dhcpv4/ztpv4/parse_circuitid_test.go @@ -85,6 +85,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"}}, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { |