summaryrefslogtreecommitdiffhomepage
path: root/netboot
diff options
context:
space:
mode:
authorChris Koch <chrisko@google.com>2019-12-28 07:41:20 -0800
committerinsomniac <insomniacslk@users.noreply.github.com>2020-03-05 15:51:55 +0000
commitd9b1a20bc08c08acc5e43e818fe1c3b71612f0a7 (patch)
treebaae82a03470d3d20761de6b46532f4e6eaa71dd /netboot
parent26ec6ccc1813d21a91bc0227ce36dee3531c5c96 (diff)
v6: add BootFileURL getter
Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'netboot')
-rw-r--r--netboot/netboot.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/netboot/netboot.go b/netboot/netboot.go
index e771e3d..4e1603c 100644
--- a/netboot/netboot.go
+++ b/netboot/netboot.go
@@ -96,13 +96,13 @@ func RequestNetbootv4(ifname string, timeout time.Duration, retries int, modifie
// ConversationToNetconf extracts network configuration and boot file URL from a
// DHCPv6 4-way conversation and returns them, or an error if any.
func ConversationToNetconf(conversation []dhcpv6.DHCPv6) (*BootConf, error) {
- var advertise, reply, optionsSource dhcpv6.DHCPv6
+ var advertise, reply, optionsSource *dhcpv6.Message
for _, m := range conversation {
switch m.Type() {
case dhcpv6.MessageTypeAdvertise:
- advertise = m
+ advertise = m.(*dhcpv6.Message)
case dhcpv6.MessageTypeReply:
- reply = m
+ reply = m.(*dhcpv6.Message)
}
}
if reply == nil {
@@ -110,24 +110,25 @@ func ConversationToNetconf(conversation []dhcpv6.DHCPv6) (*BootConf, error) {
}
bootconf := &BootConf{}
- netconf, err := GetNetConfFromPacketv6(reply.(*dhcpv6.Message))
+ netconf, err := GetNetConfFromPacketv6(reply)
if err != nil {
return nil, fmt.Errorf("cannot get netconf from packet: %v", err)
}
bootconf.NetConf = *netconf
- if reply.GetOneOption(dhcpv6.OptionBootfileURL) != nil {
+ if u := reply.Options.BootFileURL(); len(u) > 0 {
+ bootconf.BootfileURL = u
optionsSource = reply
} else {
log.Printf("no bootfile URL option found in REPLY, fallback to ADVERTISE's value")
- if advertise.GetOneOption(dhcpv6.OptionBootfileURL) != nil {
+ if u := advertise.Options.BootFileURL(); len(u) > 0 {
+ bootconf.BootfileURL = u
optionsSource = advertise
}
}
- if optionsSource == nil {
+ if len(bootconf.BootfileURL) == 0 {
return nil, errors.New("no bootfile URL option found")
}
- bootconf.BootfileURL = string(optionsSource.GetOneOption(dhcpv6.OptionBootfileURL).(dhcpv6.OptBootFileURL))
if bootfileParamOption := optionsSource.GetOneOption(dhcpv6.OptionBootfileParam); bootfileParamOption != nil {
bootconf.BootfileParam = bootfileParamOption.(dhcpv6.OptBootFileParam)