diff options
author | Andrea Barberio <insomniac@slackware.it> | 2017-12-06 20:00:51 +0000 |
---|---|---|
committer | Andrea Barberio <insomniac@slackware.it> | 2017-12-06 20:00:51 +0000 |
commit | 70a90992790d76f3a5d27fbbef985cdf1ef46a80 (patch) | |
tree | 4931b318a7af76a59b4a92b78d394c41e1491f3a /dhcpv6/dhcpv6.go | |
parent | a8db4e3c50790c83f8ba459517cc70481a014d83 (diff) |
Added Relay message stub in decoder
Diffstat (limited to 'dhcpv6/dhcpv6.go')
-rw-r--r-- | dhcpv6/dhcpv6.go | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/dhcpv6/dhcpv6.go b/dhcpv6/dhcpv6.go index 0505301..dcd1ff0 100644 --- a/dhcpv6/dhcpv6.go +++ b/dhcpv6/dhcpv6.go @@ -11,7 +11,8 @@ import ( "time" ) -const HeaderSize = 4 +const MessageHeaderSize = 4 +const RelayMessageHeaderSize = 34 type DHCPv6 interface { Type() MessageType @@ -71,23 +72,40 @@ func GenerateTransactionID() (*uint32, error) { } func FromBytes(data []byte) (DHCPv6, error) { - if len(data) < HeaderSize { - return nil, fmt.Errorf("Invalid DHCPv6 header: shorter than %v bytes", HeaderSize) + var ( + isRelay = false + headerSize int + messageType = MessageType(data[0]) + ) + if messageType == RELAY_FORW || messageType == RELAY_REPL { + isRelay = true } - tid, err := BytesToTransactionID(data[1:4]) - if err != nil { - return nil, err + if isRelay { + headerSize = RelayMessageHeaderSize + } else { + headerSize = MessageHeaderSize } - d := DHCPv6Message{ - messageType: MessageType(data[0]), - transactionID: *tid, + if len(data) < headerSize { + return nil, fmt.Errorf("Invalid header size: shorter than %v bytes", headerSize) } - options, err := options.FromBytes(data[4:]) - if err != nil { - return nil, err + if isRelay { + return nil, fmt.Errorf("Relay messages not implemented yet") + } else { + tid, err := BytesToTransactionID(data[1:4]) + if err != nil { + return nil, err + } + d := DHCPv6Message{ + messageType: MessageType(data[0]), + transactionID: *tid, + } + options, err := options.FromBytes(data[4:]) + if err != nil { + return nil, err + } + d.options = options + return &d, nil } - d.options = options - return &d, nil } func NewMessage() (*DHCPv6Message, error) { |