diff options
author | Andrea Barberio <insomniac@slackware.it> | 2017-12-07 00:10:05 +0000 |
---|---|---|
committer | Andrea Barberio <insomniac@slackware.it> | 2017-12-07 00:10:05 +0000 |
commit | f5d849e1e72d2b92136eadc66a82cad83f8bac91 (patch) | |
tree | 4980eebf315548abee44151125936f8d31bdbce6 /dhcpv6 | |
parent | 13f86883b764b61a15bbcd2914d09541572866ee (diff) |
Relay message options instead of a raw byte sequence
Diffstat (limited to 'dhcpv6')
-rw-r--r-- | dhcpv6/dhcpv6.go | 6 | ||||
-rw-r--r-- | dhcpv6/dhcpv6message.go | 7 | ||||
-rw-r--r-- | dhcpv6/dhcpv6relay.go | 11 |
3 files changed, 18 insertions, 6 deletions
diff --git a/dhcpv6/dhcpv6.go b/dhcpv6/dhcpv6.go index 621cc73..de5ebf4 100644 --- a/dhcpv6/dhcpv6.go +++ b/dhcpv6/dhcpv6.go @@ -34,8 +34,12 @@ func FromBytes(data []byte) (DHCPv6, error) { hopCount: uint8(data[1]), linkAddr: append(data[2:18]), peerAddr: append(data[18:34]), - payload: append(data[34:]), } + options, err := options.FromBytes(data[34:]) + if err != nil { + return nil, err + } + d.options = options return &d, nil } else { tid, err := BytesToTransactionID(data[1:4]) diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go index 4461c50..f1ba601 100644 --- a/dhcpv6/dhcpv6message.go +++ b/dhcpv6/dhcpv6message.go @@ -106,9 +106,14 @@ func (d *DHCPv6Message) Type() MessageType { } func (d *DHCPv6Message) SetMessage(messageType MessageType) { - if d.MessageTypeToString() == "" { + msgString := MessageTypeToString(messageType) + if msgString == "" { log.Printf("Warning: unknown DHCPv6 message type: %v", messageType) } + if messageType == RELAY_FORW || messageType == RELAY_REPL { + log.Printf("Warning: using a RELAY message type with a non-relay message: %v (%v)", + msgString, messageType) + } d.messageType = messageType } diff --git a/dhcpv6/dhcpv6relay.go b/dhcpv6/dhcpv6relay.go index 8fa1c4e..100a878 100644 --- a/dhcpv6/dhcpv6relay.go +++ b/dhcpv6/dhcpv6relay.go @@ -2,6 +2,7 @@ package dhcpv6 import ( "fmt" + "github.com/insomniacslk/dhcp/dhcpv6/options" "net" ) @@ -12,7 +13,7 @@ type DHCPv6Relay struct { hopCount uint8 linkAddr net.IP peerAddr net.IP - payload []byte // TODO implement relay payload + options []options.Option } func (r *DHCPv6Relay) Type() MessageType { @@ -30,12 +31,12 @@ func (r *DHCPv6Relay) Summary() string { " hopcount=%v\n"+ " linkaddr=%v\n"+ " peeraddr=%v\n"+ - " payload=%v\n", + " options=%v\n", r.MessageTypeToString(), r.hopCount, r.linkAddr, r.peerAddr, - r.payload, + r.options, ) return ret } @@ -46,7 +47,9 @@ func (r *DHCPv6Relay) ToBytes() []byte { ret[1] = byte(r.hopCount) copy(ret[2:18], r.peerAddr) copy(ret[18:34], r.linkAddr) - ret = append(ret, r.payload...) + for _, opt := range r.options { + ret = append(opt.ToBytes()) + } return ret } |