summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6
diff options
context:
space:
mode:
authorAndrea Barberio <insomniac@slackware.it>2017-12-21 11:58:49 +0000
committerAndrea Barberio <insomniac@slackware.it>2017-12-21 11:58:49 +0000
commita9bfd733fda3db80de352bc79b7548c3c50430bf (patch)
tree0e2297f8b650fb5708b42ce0f42912e12706a453 /dhcpv6
parent307f1cd1b31c540ae4d90a6209b7c40e3a53fc64 (diff)
Added OptBootFileURL
Diffstat (limited to 'dhcpv6')
-rw-r--r--dhcpv6/option_bootfileurl.go49
-rw-r--r--dhcpv6/options.go2
2 files changed, 51 insertions, 0 deletions
diff --git a/dhcpv6/option_bootfileurl.go b/dhcpv6/option_bootfileurl.go
new file mode 100644
index 0000000..4dd0af3
--- /dev/null
+++ b/dhcpv6/option_bootfileurl.go
@@ -0,0 +1,49 @@
+package dhcpv6
+
+// This module defines the OptBootFileURL structure.
+// https://www.ietf.org/rfc/rfc5970.txt
+
+import (
+ "encoding/binary"
+ "fmt"
+)
+
+type OptBootFileURL struct {
+ bootFileUrl []byte
+}
+
+func (op *OptBootFileURL) Code() OptionCode {
+ return OPT_BOOTFILE_URL
+}
+
+func (op *OptBootFileURL) ToBytes() []byte {
+ buf := make([]byte, 4)
+ binary.BigEndian.PutUint16(buf[0:2], uint16(OPT_BOOTFILE_URL))
+ binary.BigEndian.PutUint16(buf[2:4], 2)
+ buf = append(buf, op.bootFileUrl...)
+ return buf
+}
+
+func (op *OptBootFileURL) BootFileURL() []byte {
+ return op.bootFileUrl
+}
+
+func (op *OptBootFileURL) SetBootFileURL(bootFileUrl []byte) {
+ op.bootFileUrl = bootFileUrl
+}
+
+func (op *OptBootFileURL) Length() int {
+ return len(op.bootFileUrl)
+}
+
+func (op *OptBootFileURL) String() string {
+ return fmt.Sprintf("OptBootFileURL{BootFileUrl=%v}", op.bootFileUrl)
+}
+
+// build an OptBootFileURL structure from a sequence of bytes.
+// The input data does not include option code and length bytes.
+func ParseOptBootFileURL(data []byte) (*OptBootFileURL, error) {
+ opt := OptBootFileURL{}
+ opt.bootFileUrl = append([]byte(nil), data...)
+ return &opt, nil
+}
diff --git a/dhcpv6/options.go b/dhcpv6/options.go
index 3bca963..fcfed37 100644
--- a/dhcpv6/options.go
+++ b/dhcpv6/options.go
@@ -98,6 +98,8 @@ func ParseOption(dataStart []byte) (Option, error) {
opt, err = ParseOptClientArchType(optData)
case OPTION_NII:
opt, err = ParseOptNetworkInterfaceId(optData)
+ case OPT_BOOTFILE_URL:
+ opt, err = ParseOptBootFileURL(optData)
default:
opt = &OptionGeneric{OptionCode: code, OptionData: optData}
}