summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPablo Mazzini <pmazzini@gmail.com>2022-09-10 13:53:31 +0100
committerGitHub <noreply@github.com>2022-09-10 13:53:31 +0100
commit0bb6da28c4dba193221eb2067be1900abf3ef6d6 (patch)
treef44aedeff9a309bc5aa31122b14370abd4a1af79
parent99ad3cf323903d0ecddca3106736c4a747f60a11 (diff)
parent69cde97383c2cb98112b7dd6e4b20198b8c38353 (diff)
Merge branch 'master' into fix-nil-options
-rw-r--r--dhcpv4/server4/conn_unix.go4
-rw-r--r--dhcpv4/ztpv4/parse_circuitid.go2
-rw-r--r--dhcpv4/ztpv4/parse_circuitid_test.go2
-rw-r--r--dhcpv6/ztpv6/parse_vendor_options.go3
-rw-r--r--dhcpv6/ztpv6/parse_vendor_options_test.go5
5 files changed, 15 insertions, 1 deletions
diff --git a/dhcpv4/server4/conn_unix.go b/dhcpv4/server4/conn_unix.go
index da62398..18dd986 100644
--- a/dhcpv4/server4/conn_unix.go
+++ b/dhcpv4/server4/conn_unix.go
@@ -33,6 +33,10 @@ func NewIPv4UDPConn(iface string, addr *net.UDPAddr) (*net.UDPConn, error) {
if err := unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_REUSEADDR, 1); err != nil {
return nil, fmt.Errorf("cannot set reuseaddr on socket: %v", err)
}
+ // Allow reusing the port to aid debugging and testing.
+ if err := unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
+ return nil, fmt.Errorf("cannot set reuseport on socket: %v", err)
+ }
if len(iface) != 0 {
// Bind directly to the interface.
if err := dhcpv4.BindToInterface(fd, iface); err != nil {
diff --git a/dhcpv4/ztpv4/parse_circuitid.go b/dhcpv4/ztpv4/parse_circuitid.go
index 13852ea..42f7647 100644
--- a/dhcpv4/ztpv4/parse_circuitid.go
+++ b/dhcpv4/ztpv4/parse_circuitid.go
@@ -37,6 +37,8 @@ var circuitRegexs = []*regexp.Regexp{
regexp.MustCompile("^Ethernet(?P<slot>[0-9]+)/(?P<port>[0-9]+)$"),
// Juniper bundle interface ae52.0
regexp.MustCompile("^ae(?P<port>[0-9]+).(?P<subport>[0-9])$"),
+ // Ciena interface format
+ regexp.MustCompile(`\.OSC(-[0-9]+)?-(?P<slot>[0-9]+)-(?P<port>[0-9]+)$`),
}
// ParseCircuitID will parse dhcpv4 packet and return CircuitID info
diff --git a/dhcpv4/ztpv4/parse_circuitid_test.go b/dhcpv4/ztpv4/parse_circuitid_test.go
index cec7403..695d331 100644
--- a/dhcpv4/ztpv4/parse_circuitid_test.go
+++ b/dhcpv4/ztpv4/parse_circuitid_test.go
@@ -89,6 +89,8 @@ func TestParseCircuitID(t *testing.T) {
{name: "Juniper Bundle Pattern", circuit: []byte("ae52.0"), want: &CircuitID{Port: "52", SubPort: "0"}},
{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"}},
+ {name: "Ciena pattern 1", circuit: []byte("tt-tt-tttt-6-7.OSC-1-2"), want: &CircuitID{Slot: "1", Port: "2"}},
+ {name: "Ciena pattern 2", circuit: []byte("tt-tt-tttt-6-7.OSC-1-2-3"), want: &CircuitID{Slot: "2", Port: "3"}},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
diff --git a/dhcpv6/ztpv6/parse_vendor_options.go b/dhcpv6/ztpv6/parse_vendor_options.go
index 3d1fd01..b3ce55b 100644
--- a/dhcpv6/ztpv6/parse_vendor_options.go
+++ b/dhcpv6/ztpv6/parse_vendor_options.go
@@ -46,7 +46,8 @@ func ParseVendorData(packet dhcpv6.DHCPv6) (*VendorData, error) {
for _, d := range vData {
switch {
// Arista;DCS-0000;00.00;ZZZ00000000
- case strings.HasPrefix(d, "Arista;"):
+ // Cisco;8800;12.34;FOC00000000
+ case strings.HasPrefix(d, "Arista;"), strings.HasPrefix(d, "Cisco;"):
p := strings.Split(d, ";")
if len(p) < 4 {
return nil, errVendorOptionMalformed
diff --git a/dhcpv6/ztpv6/parse_vendor_options_test.go b/dhcpv6/ztpv6/parse_vendor_options_test.go
index cd2fb3d..03ff8cf 100644
--- a/dhcpv6/ztpv6/parse_vendor_options_test.go
+++ b/dhcpv6/ztpv6/parse_vendor_options_test.go
@@ -18,12 +18,17 @@ func TestParseVendorDataWithVendorOpts(t *testing.T) {
{name: "empty", fail: true},
{name: "unknownVendor", vc: "VendorX;BFR10K;XX12345", fail: true, want: nil},
{name: "truncatedArista", vc: "Arista;1234", fail: true, want: nil},
+ {name: "truncatedCisco", vc: "Cisco;1234", fail: true, want: nil},
{name: "truncatedZPE", vc: "ZPESystems:1234", fail: true, want: nil},
{
name: "arista",
vc: "Arista;DCS-7050S-64;01.23;JPE12345678",
want: &VendorData{VendorName: "Arista", Model: "DCS-7050S-64", Serial: "JPE12345678"},
}, {
+ name: "cisco",
+ vc: "Cisco;SYS-8801;01.23;FOC12345678",
+ want: &VendorData{VendorName: "Cisco", Model: "SYS-8801", Serial: "FOC12345678"},
+ }, {
name: "zpe",
vc: "ZPESystems:NSC:001234567",
want: &VendorData{VendorName: "ZPESystems", Model: "NSC", Serial: "001234567"},