diff options
author | insomniac <insomniacslk@users.noreply.github.com> | 2018-12-23 19:37:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-23 19:37:10 +0100 |
commit | 2439a850c766acf2d21501bf075b4dbeb6d7d295 (patch) | |
tree | ea7dfd0937a6a5233e9f7a5d46c3f434dd101728 | |
parent | 2b569280e441c779406c8b2aaa1283ca5ce0f15b (diff) | |
parent | a0237e108316e4edf0302a61f0841d1f7f9e098e (diff) |
[ztpv4] make it consistent with ztpv6 (#221)
* [ztpv4] make it consistent with ztpv6
-rw-r--r-- | dhcpv4/ztpv4/ztp.go (renamed from dhcpv4/ztp/ztp.go) | 8 | ||||
-rw-r--r-- | dhcpv4/ztpv4/ztp_test.go (renamed from dhcpv4/ztp/ztp_test.go) | 12 |
2 files changed, 10 insertions, 10 deletions
diff --git a/dhcpv4/ztp/ztp.go b/dhcpv4/ztpv4/ztp.go index b899425..18075e9 100644 --- a/dhcpv4/ztp/ztp.go +++ b/dhcpv4/ztpv4/ztp.go @@ -10,9 +10,7 @@ import ( // VendorData is optional data a particular vendor may or may not include // in the Vendor Class options. type VendorData struct { - VendorName string - Model string - Serial string + VendorName, Model, Serial string } var errVendorOptionMalformed = errors.New("malformed vendor option") @@ -22,7 +20,7 @@ var errVendorOptionMalformed = errors.New("malformed vendor option") func ParseVendorData(packet *dhcpv4.DHCPv4) (*VendorData, error) { opt := packet.GetOneOption(dhcpv4.OptionClassIdentifier) if opt == nil { - return nil, nil + return nil, errors.New("vendor options not found") } vc := opt.(*dhcpv4.OptClassIdentifier).Identifier vd := &VendorData{} @@ -76,5 +74,5 @@ func ParseVendorData(packet *dhcpv4.DHCPv4) (*VendorData, error) { } // We didn't match anything. - return nil, nil + return nil, errors.New("no known ZTP vendor found") } diff --git a/dhcpv4/ztp/ztp_test.go b/dhcpv4/ztpv4/ztp_test.go index 15a9d26..9950bf5 100644 --- a/dhcpv4/ztp/ztp_test.go +++ b/dhcpv4/ztpv4/ztp_test.go @@ -14,8 +14,8 @@ func TestParseV4VendorClass(t *testing.T) { want *VendorData fail bool }{ - {name: "empty"}, - {name: "unknownVendor", vc: "VendorX;BFR10K;XX12345"}, + {name: "empty", fail: true}, + {name: "unknownVendor", vc: "VendorX;BFR10K;XX12345", fail: true}, {name: "truncatedVendor", vc: "Arista;1234", fail: true}, { name: "arista", @@ -53,9 +53,11 @@ func TestParseV4VendorClass(t *testing.T) { t.Fatalf("failed to creat dhcpv4 packet object: %v", err) } - packet.AddOption(&dhcpv4.OptClassIdentifier{ - Identifier: tc.vc, - }) + if tc.vc != "" { + packet.AddOption(&dhcpv4.OptClassIdentifier{ + Identifier: tc.vc, + }) + } if tc.hostname != "" { packet.AddOption(&dhcpv4.OptHostName{ |