summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/ztpv4/ztp.go
diff options
context:
space:
mode:
authorEmanuele Fia <name29@users.noreply.github.com>2021-10-25 22:20:43 +0100
committerGitHub <noreply@github.com>2021-10-25 22:20:43 +0100
commitb28ed3e9daf60f867fe8475745add4461356eaad (patch)
tree966157a57908cd96191b3b04ef00c0472ee032d5 /dhcpv4/ztpv4/ztp.go
parent0c623abe15f981f59d47fc27ecca98951da40a76 (diff)
Adding support for parsing Ciena attributes in DHCPv4 (#450)
* Adding support for Ciena DHCPv4 Signed-off-by: Emanuele Fia <name29@fb.com>
Diffstat (limited to 'dhcpv4/ztpv4/ztp.go')
-rw-r--r--dhcpv4/ztpv4/ztp.go26
1 files changed, 23 insertions, 3 deletions
diff --git a/dhcpv4/ztpv4/ztp.go b/dhcpv4/ztpv4/ztp.go
index ef8e13d..c57d958 100644
--- a/dhcpv4/ztpv4/ztp.go
+++ b/dhcpv4/ztpv4/ztp.go
@@ -3,6 +3,8 @@ package ztpv4
import (
"bytes"
"errors"
+ "fmt"
+ "strconv"
"strings"
"github.com/insomniacslk/dhcp/dhcpv4"
@@ -16,6 +18,7 @@ type VendorData struct {
}
var errVendorOptionMalformed = errors.New("malformed vendor option")
+var errClientIDOptionMissing = errors.New("client identifier option is missing")
func parseClassIdentifier(packet *dhcpv4.DHCPv4) (*VendorData, error) {
vd := &VendorData{}
@@ -66,6 +69,25 @@ func parseClassIdentifier(packet *dhcpv4.DHCPv4) (*VendorData, error) {
vd.VendorName = p[0]
return vd, nil
+ // For Ciena the class identifier (opt 60) is written in the following format:
+ // {vendor iana code}-{product}-{type}
+ // For Ciena the iana code is 1271
+ // The product type is a number that maps to a Ciena product
+ // The type is used to identified different subtype of the product.
+ // An example can be ‘1271-23422Z11-123’.
+ case strings.HasPrefix(vc, strconv.Itoa(int(iana.EntIDCienaCorporation))):
+ v := strings.Split(vc, "-")
+ if len(v) != 3 {
+ return nil, fmt.Errorf("%w got '%s'", errVendorOptionMalformed, vc)
+ }
+ vd.VendorName = iana.EntIDCienaCorporation.String()
+ vd.Model = v[1] + "-" + v[2]
+ vd.Serial = dhcpv4.GetString(dhcpv4.OptionClientIdentifier, packet.Options)
+ if len(vd.Serial) == 0 {
+ return nil, errClientIDOptionMissing
+ }
+ return vd, nil
+
// Cisco Firepower FPR4100/9300 models use Opt 60 for model info
// and Opt 61 contains the serial number
case vc == "FPR4100" || vc == "FPR9300":
@@ -73,12 +95,10 @@ func parseClassIdentifier(packet *dhcpv4.DHCPv4) (*VendorData, error) {
vd.Model = vc
vd.Serial = dhcpv4.GetString(dhcpv4.OptionClientIdentifier, packet.Options)
if len(vd.Serial) == 0 {
- return nil, errors.New("client identifier option is missing")
+ return nil, errClientIDOptionMissing
}
return vd, nil
-
}
-
return nil, nil
}