summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/dhcpv6.go
diff options
context:
space:
mode:
authorChristopher Koch <c@chrisko.ch>2019-01-20 04:05:36 +0000
committerinsomniac <insomniacslk@users.noreply.github.com>2019-01-26 23:34:26 +0000
commit8936b6e4e714e0b682e37fa81fde29606e58e7c2 (patch)
tree25aa6c19674258c391654e52af3dc7db1ba12f7b /dhcpv6/dhcpv6.go
parent6a9ec900f656439652b2f20e34b2452d561eb0a6 (diff)
dhcpv6: introduce options type.
Diffstat (limited to 'dhcpv6/dhcpv6.go')
-rw-r--r--dhcpv6/dhcpv6.go41
1 files changed, 3 insertions, 38 deletions
diff --git a/dhcpv6/dhcpv6.go b/dhcpv6/dhcpv6.go
index 9382334..c9f8c05 100644
--- a/dhcpv6/dhcpv6.go
+++ b/dhcpv6/dhcpv6.go
@@ -57,12 +57,10 @@ func FromBytes(data []byte) (DHCPv6, error) {
d.linkAddr = linkAddr
peerAddr = append(peerAddr, data[18:34]...)
d.peerAddr = peerAddr
- options, err := OptionsFromBytes(data[34:])
- if err != nil {
+ // TODO fail if no OptRelayMessage is present
+ if err := d.options.FromBytes(data[34:]); err != nil {
return nil, err
}
- // TODO fail if no OptRelayMessage is present
- d.options = options
return &d, nil
} else {
tid, err := BytesToTransactionID(data[1:4])
@@ -73,11 +71,9 @@ func FromBytes(data []byte) (DHCPv6, error) {
messageType: messageType,
transactionID: *tid,
}
- options, err := OptionsFromBytes(data[4:])
- if err != nil {
+ if err := d.options.FromBytes(data[4:]); err != nil {
return nil, err
}
- d.options = options
return &d, nil
}
}
@@ -100,37 +96,6 @@ func NewMessage(modifiers ...Modifier) (DHCPv6, error) {
return d, nil
}
-func getOptions(options []Option, code OptionCode, onlyFirst bool) []Option {
- var ret []Option
- for _, opt := range options {
- if opt.Code() == code {
- ret = append(ret, opt)
- if onlyFirst {
- break
- }
- }
- }
- return ret
-}
-
-func getOption(options []Option, code OptionCode) Option {
- opts := getOptions(options, code, true)
- if opts == nil {
- return nil
- }
- return opts[0]
-}
-
-func delOption(options []Option, code OptionCode) []Option {
- newOpts := make([]Option, 0, len(options))
- for _, opt := range options {
- if opt.Code() != code {
- newOpts = append(newOpts, opt)
- }
- }
- return newOpts
-}
-
// DecapsulateRelay extracts the content of a relay message. It does not recurse
// if there are nested relay messages. Returns the original packet if is not not
// a relay message