Skip to content

Commit 6eb3e78

Browse files
committed
dhcpv6/ztpv6: avoid panic in ParseVendorData on non-Message packets
The Ciena branch of ParseVendorData unconditionally type-asserted the DHCPv6 packet to *dhcpv6.Message to read the client identifier. Because ParseVendorData accepts the dhcpv6.DHCPv6 interface and the ztpv6 helpers are documented to run on relayed packets, passing a *dhcpv6.RelayMessage carrying a Ciena vendor class option panicked with 'interface conversion: dhcpv6.DHCPv6 is *dhcpv6.RelayMessage, not *dhcpv6.Message'. Guard the assertion with the comma-ok form so a non-Message packet simply skips the serial-number lookup instead of crashing. Behavior for *dhcpv6.Message inputs is unchanged. Adds a regression test. Signed-off-by: Chris (ChrisJr404) <11917633+ChrisJr404@users.noreply.github.com>
1 parent c308df0 commit 6eb3e78

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

dhcpv6/ztpv6/parse_vendor_options.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ func ParseVendorData(packet dhcpv6.DHCPv6) (*VendorData, error) {
118118
}
119119
vd.VendorName = iana.EnterpriseIDCienaCorporation.String()
120120
vd.Model = v[1] + "-" + v[2]
121-
duid := packet.(*dhcpv6.Message).Options.ClientID()
122-
if enterpriseDUID, ok := duid.(*dhcpv6.DUIDEN); ok {
123-
vd.Serial = string(enterpriseDUID.EnterpriseIdentifier)
121+
if msg, ok := packet.(*dhcpv6.Message); ok {
122+
if enterpriseDUID, ok := msg.Options.ClientID().(*dhcpv6.DUIDEN); ok {
123+
vd.Serial = string(enterpriseDUID.EnterpriseIdentifier)
124+
}
124125
}
125126
return &vd, nil
126127
}

dhcpv6/ztpv6/parse_vendor_options_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,24 @@ func TestParseVendorDataWithVendorClass(t *testing.T) {
128128
})
129129
}
130130
}
131+
132+
// TestParseVendorDataCienaRelayMessage ensures ParseVendorData does not panic
133+
// when handed a RelayMessage (rather than a *Message) carrying a Ciena vendor
134+
// class option. The ztpv6 helpers are documented to run on relayed packets, so
135+
// a *RelayMessage is a legitimate input.
136+
func TestParseVendorDataCienaRelayMessage(t *testing.T) {
137+
relay := &dhcpv6.RelayMessage{
138+
MessageType: dhcpv6.MessageTypeRelayForward,
139+
}
140+
relay.Options.Add(&dhcpv6.OptVendorClass{
141+
EnterpriseNumber: uint32(iana.EnterpriseIDCienaCorporation),
142+
Data: [][]byte{[]byte("1271-23422Z11-123")},
143+
})
144+
145+
vd, err := ParseVendorData(relay)
146+
require.NoError(t, err)
147+
require.Equal(t, &VendorData{
148+
VendorName: iana.EnterpriseIDCienaCorporation.String(),
149+
Model: "23422Z11-123",
150+
}, vd)
151+
}

0 commit comments

Comments
 (0)