diff options
author | Sean Karlage <skarlage@get9.io> | 2018-03-16 08:42:29 -0700 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2018-03-16 15:42:29 +0000 |
commit | 79b8450e99efee338596f15fc1f8f88c3e42edc0 (patch) | |
tree | 9e62bedb49ca5b6b8a61188f71a9cdfd248edafd /dhcpv4/bsdp/bsdp.go | |
parent | 1d020f7d3aba3dfe1c142c5f73d3b3b3992ad2ad (diff) |
Add more specific dhcpv4 options (#17)
Added several DHCPv4 options
Diffstat (limited to 'dhcpv4/bsdp/bsdp.go')
-rw-r--r-- | dhcpv4/bsdp/bsdp.go | 61 |
1 files changed, 20 insertions, 41 deletions
diff --git a/dhcpv4/bsdp/bsdp.go b/dhcpv4/bsdp/bsdp.go index f18fdce..e93b654 100644 --- a/dhcpv4/bsdp/bsdp.go +++ b/dhcpv4/bsdp/bsdp.go @@ -213,36 +213,25 @@ func NewInformListForInterface(iface string, replyPort uint16) (*dhcpv4.DHCPv4, for _, opt := range vendorOpts { vendorOptsBytes = append(vendorOptsBytes, opt.ToBytes()...) } - d.AddOption(dhcpv4.OptionGeneric{ + d.AddOption(&dhcpv4.OptionGeneric{ OptionCode: dhcpv4.OptionVendorSpecificInformation, Data: vendorOptsBytes, }) - d.AddOption(dhcpv4.OptionGeneric{ - OptionCode: dhcpv4.OptionParameterRequestList, - Data: []byte{ - byte(dhcpv4.OptionVendorSpecificInformation), - byte(dhcpv4.OptionClassIdentifier), + d.AddOption(&dhcpv4.OptParameterRequestList{ + RequestedOpts: []dhcpv4.OptionCode{ + dhcpv4.OptionVendorSpecificInformation, + dhcpv4.OptionClassIdentifier, }, }) - - u16 := make([]byte, 2) - binary.BigEndian.PutUint16(u16, MaxDHCPMessageSize) - d.AddOption(dhcpv4.OptionGeneric{ - OptionCode: dhcpv4.OptionMaximumDHCPMessageSize, - Data: u16, - }) + d.AddOption(&dhcpv4.OptMaximumDHCPMessageSize{Size: MaxDHCPMessageSize}) vendorClassID, err := makeVendorClassIdentifier() if err != nil { return nil, err } - d.AddOption(dhcpv4.OptionGeneric{ - OptionCode: dhcpv4.OptionClassIdentifier, - Data: []byte(vendorClassID), - }) - - d.AddOption(dhcpv4.OptionGeneric{OptionCode: dhcpv4.OptionEnd}) + d.AddOption(&dhcpv4.OptClassIdentifier{Identifier: vendorClassID}) + d.AddOption(&dhcpv4.OptionGeneric{OptionCode: dhcpv4.OptionEnd}) return d, nil } @@ -296,10 +285,7 @@ func InformSelectForAck(ack dhcpv4.DHCPv4, replyPort uint16, selectedImage BootI if serverIP.To4() == nil { return nil, fmt.Errorf("could not parse server identifier from ACK") } - vendorOpts = append(vendorOpts, dhcpv4.OptionGeneric{ - OptionCode: OptionServerIdentifier, - Data: serverIP, - }) + vendorOpts = append(vendorOpts, &dhcpv4.OptServerIdentifier{ServerID: serverIP}) // Validate replyPort if requested. if needsReplyPort(replyPort) { @@ -313,32 +299,25 @@ func InformSelectForAck(ack dhcpv4.DHCPv4, replyPort uint16, selectedImage BootI if err != nil { return nil, err } - d.AddOption(dhcpv4.OptionGeneric{ - OptionCode: dhcpv4.OptionClassIdentifier, - Data: []byte(vendorClassID), - }) - d.AddOption(dhcpv4.OptionGeneric{ - OptionCode: dhcpv4.OptionParameterRequestList, - Data: []byte{ - byte(dhcpv4.OptionSubnetMask), - byte(dhcpv4.OptionRouter), - byte(dhcpv4.OptionBootfileName), - byte(dhcpv4.OptionVendorSpecificInformation), - byte(dhcpv4.OptionClassIdentifier), + d.AddOption(&dhcpv4.OptClassIdentifier{Identifier: vendorClassID}) + d.AddOption(&dhcpv4.OptParameterRequestList{ + RequestedOpts: []dhcpv4.OptionCode{ + dhcpv4.OptionSubnetMask, + dhcpv4.OptionRouter, + dhcpv4.OptionBootfileName, + dhcpv4.OptionVendorSpecificInformation, + dhcpv4.OptionClassIdentifier, }, }) - d.AddOption(dhcpv4.OptionGeneric{ - OptionCode: dhcpv4.OptionDHCPMessageType, - Data: []byte{byte(dhcpv4.MessageTypeInform)}, - }) + d.AddOption(&dhcpv4.OptMessageType{MessageType: dhcpv4.MessageTypeInform}) var vendorOptsBytes []byte for _, opt := range vendorOpts { vendorOptsBytes = append(vendorOptsBytes, opt.ToBytes()...) } - d.AddOption(dhcpv4.OptionGeneric{ + d.AddOption(&dhcpv4.OptionGeneric{ OptionCode: dhcpv4.OptionVendorSpecificInformation, Data: vendorOptsBytes, }) - d.AddOption(dhcpv4.OptionGeneric{OptionCode: dhcpv4.OptionEnd}) + d.AddOption(&dhcpv4.OptionGeneric{OptionCode: dhcpv4.OptionEnd}) return d, nil } |