diff options
author | akshay navale <akshaynawale@gmail.com> | 2020-04-01 11:58:30 -0600 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2020-04-02 19:51:28 +0100 |
commit | 5dd7202f19711228cb4a51aa8b3415421c2edefe (patch) | |
tree | 6345f08babff964f312775c41032f7a68a164ae3 /dhcpv6/ztpv6/parse_remote_id.go | |
parent | 5763873e2f3b9b186abff90203fd6257927d71cd (diff) |
adding fallback logic to remote id parsing
Signed-off-by: akshay navale <akshaynawale@gmail.com>
Diffstat (limited to 'dhcpv6/ztpv6/parse_remote_id.go')
-rw-r--r-- | dhcpv6/ztpv6/parse_remote_id.go | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/dhcpv6/ztpv6/parse_remote_id.go b/dhcpv6/ztpv6/parse_remote_id.go index 9de9bdf..9dd72b1 100644 --- a/dhcpv6/ztpv6/parse_remote_id.go +++ b/dhcpv6/ztpv6/parse_remote_id.go @@ -36,29 +36,36 @@ func ParseRemoteID(packet dhcpv6.DHCPv6) (*CircuitID, error) { if rid := rm.Options.RemoteID(); rid != nil { remoteID := string(rid.RemoteID) circ, err := matchCircuitId(remoteID) - if err != nil { - return nil, err + if err == nil { + return circ, nil + } + } + // if we fail to find circuit id from remote id try to use interface ID option + if iid := rm.Options.InterfaceID(); iid != nil { + interfaceID := string(iid) + circ, err := matchCircuitId(interfaceID) + if err == nil { + return circ, nil } - return circ, nil } } - return nil, errors.New("failed to parse RemoteID option data") + return nil, errors.New("failed to parse RemoteID and InterfaceID option data") } -func matchCircuitId(remoteID string) (*CircuitID, error) { +func matchCircuitId(circuitInfo string) (*CircuitID, error) { var names, matches []string switch { - case aristaPVPattern.MatchString(remoteID): - matches = aristaPVPattern.FindStringSubmatch(remoteID) + case aristaPVPattern.MatchString(circuitInfo): + matches = aristaPVPattern.FindStringSubmatch(circuitInfo) names = aristaPVPattern.SubexpNames() - case aristaSMPPattern.MatchString(remoteID): - matches = aristaSMPPattern.FindStringSubmatch(remoteID) + case aristaSMPPattern.MatchString(circuitInfo): + matches = aristaSMPPattern.FindStringSubmatch(circuitInfo) names = aristaSMPPattern.SubexpNames() } if len(matches) == 0 { - return nil, fmt.Errorf("no circuitId regex matches for %v", remoteID) + return nil, fmt.Errorf("no circuitId regex matches for %v", circuitInfo) } var circuit CircuitID |