diff options
author | Pablo Mazzini <pmazzini@gmail.com> | 2021-08-10 07:48:32 +0100 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2021-10-26 14:51:28 +0200 |
commit | ad197bcd36fd5fde44d2eacc50c5aa7aef87a742 (patch) | |
tree | 18ea982692e684dc474ddb1b503028ef16c29674 | |
parent | 94de7a00bf095cb550525eb3744e56e1f3dc4899 (diff) |
use iana EntID
-rw-r--r-- | dhcpv4/option_vivc.go | 7 | ||||
-rw-r--r-- | dhcpv4/ztpv4/ztp.go | 10 | ||||
-rw-r--r-- | dhcpv4/ztpv4/ztp_test.go | 8 | ||||
-rw-r--r-- | iana/entid.go | 18 |
4 files changed, 22 insertions, 21 deletions
diff --git a/dhcpv4/option_vivc.go b/dhcpv4/option_vivc.go index a073149..3900bf0 100644 --- a/dhcpv4/option_vivc.go +++ b/dhcpv4/option_vivc.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" + "github.com/insomniacslk/dhcp/iana" "github.com/u-root/uio/uio" ) @@ -11,7 +12,7 @@ import ( // described by RFC 3925. type VIVCIdentifier struct { // EntID is the enterprise ID. - EntID uint32 + EntID iana.EnterpriseID Data []byte } @@ -33,7 +34,7 @@ type VIVCIdentifiers []VIVCIdentifier func (ids *VIVCIdentifiers) FromBytes(data []byte) error { buf := uio.NewBigEndianBuffer(data) for buf.Has(5) { - entID := buf.Read32() + entID := iana.EnterpriseID(buf.Read32()) idLen := int(buf.Read8()) *ids = append(*ids, VIVCIdentifier{EntID: entID, Data: buf.CopyN(idLen)}) } @@ -44,7 +45,7 @@ func (ids *VIVCIdentifiers) FromBytes(data []byte) error { func (ids VIVCIdentifiers) ToBytes() []byte { buf := uio.NewBigEndianBuffer(nil) for _, id := range ids { - buf.Write32(id.EntID) + buf.Write32(uint32(id.EntID)) buf.Write8(uint8(len(id.Data))) buf.WriteBytes(id.Data) } diff --git a/dhcpv4/ztpv4/ztp.go b/dhcpv4/ztpv4/ztp.go index af7c8f7..ecb63c6 100644 --- a/dhcpv4/ztpv4/ztp.go +++ b/dhcpv4/ztpv4/ztp.go @@ -75,12 +75,12 @@ func parseClassIdentifier(packet *dhcpv4.DHCPv4) (*VendorData, error) { // 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))): + case strings.HasPrefix(vc, strconv.Itoa(int(iana.EnterpriseIDCienaCorporation))): v := strings.Split(vc, "-") if len(v) != 3 { return nil, fmt.Errorf("%w got '%s'", errVendorOptionMalformed, vc) } - vd.VendorName = iana.EntIDCienaCorporation.String() + vd.VendorName = iana.EnterpriseIDCienaCorporation.String() vd.Model = v[1] + "-" + v[2] vd.Serial = dhcpv4.GetString(dhcpv4.OptionClientIdentifier, packet.Options) if len(vd.Serial) == 0 { @@ -91,7 +91,7 @@ func parseClassIdentifier(packet *dhcpv4.DHCPv4) (*VendorData, error) { // Cisco Firepower FPR4100/9300 models use Opt 60 for model info // and Opt 61 contains the serial number case vc == "FPR4100" || vc == "FPR9300": - vd.VendorName = iana.EntIDCiscoSystems.String() + vd.VendorName = iana.EnterpriseIDCiscoSystems.String() vd.Model = vc vd.Serial = dhcpv4.GetString(dhcpv4.OptionClientIdentifier, packet.Options) if len(vd.Serial) == 0 { @@ -107,8 +107,8 @@ func parseVIVC(packet *dhcpv4.DHCPv4) (*VendorData, error) { vd := &VendorData{} for _, id := range packet.VIVC() { - if id.EntID == uint32(iana.EntIDCiscoSystems) { - vd.VendorName = iana.EntIDCiscoSystems.String() + if id.EntID == iana.EnterpriseIDCiscoSystems { + vd.VendorName = iana.EnterpriseIDCiscoSystems.String() //SN:0;PID:R-IOSXRV9000-CC for _, f := range bytes.Split(id.Data, []byte(";")) { p := bytes.Split(f, []byte(":")) diff --git a/dhcpv4/ztpv4/ztp_test.go b/dhcpv4/ztpv4/ztp_test.go index 5fa3f40..5d8ae8d 100644 --- a/dhcpv4/ztpv4/ztp_test.go +++ b/dhcpv4/ztpv4/ztp_test.go @@ -95,19 +95,19 @@ func TestParseVIVC(t *testing.T) { tt := []struct { name string vivc string - entID iana.EntID + entID iana.EnterpriseID want *VendorData fail bool }{ { name: "cisco", - entID: iana.EntIDCiscoSystems, + entID: iana.EnterpriseIDCiscoSystems, vivc: "SN:0;PID:R-IOSXRV9000-CC", want: &VendorData{VendorName: "Cisco Systems", Model: "R-IOSXRV9000-CC", Serial: "0"}, }, { name: "ciscoMultipleColonDelimiters", - entID: iana.EntIDCiscoSystems, + entID: iana.EnterpriseIDCiscoSystems, vivc: "SN:0:123;PID:R-IOSXRV9000-CC:456", fail: true, }, @@ -121,7 +121,7 @@ func TestParseVIVC(t *testing.T) { } if tc.vivc != "" { - vivc := dhcpv4.VIVCIdentifier{EntID: uint32(tc.entID), Data: []byte(tc.vivc)} + vivc := dhcpv4.VIVCIdentifier{EntID: tc.entID, Data: []byte(tc.vivc)} packet.UpdateOption(dhcpv4.OptVIVC(vivc)) } diff --git a/iana/entid.go b/iana/entid.go index dbcb51e..8703b79 100644 --- a/iana/entid.go +++ b/iana/entid.go @@ -1,22 +1,22 @@ package iana -// EntID represents the Enterprise IDs as set by IANA -type EntID int +// EnterpriseID represents the Enterprise IDs as set by IANA +type EnterpriseID int // See https://www.iana.org/assignments/enterprise-numbers/enterprise-numbers for values const ( - EntIDCiscoSystems EntID = 9 - EntIDCienaCorporation EntID = 1271 + EnterpriseIDCiscoSystems EnterpriseID = 9 + EnterpriseIDCienaCorporation EnterpriseID = 1271 ) -var entIDToStringMap = map[EntID]string{ - EntIDCiscoSystems: "Cisco Systems", - EntIDCienaCorporation: "Ciena Corporation", +var enterpriseIDToStringMap = map[EnterpriseID]string{ + EnterpriseIDCiscoSystems: "Cisco Systems", + EnterpriseIDCienaCorporation: "Ciena Corporation", } // String returns the vendor name for a given Enterprise ID -func (e EntID) String() string { - if vendor := entIDToStringMap[e]; vendor != "" { +func (e EnterpriseID) String() string { + if vendor := enterpriseIDToStringMap[e]; vendor != "" { return vendor } return "Unknown" |