diff options
author | Andrea Barberio <insomniac@slackware.it> | 2017-12-09 14:19:49 +0000 |
---|---|---|
committer | Andrea Barberio <insomniac@slackware.it> | 2017-12-09 14:19:49 +0000 |
commit | 8ffda0b0505a1f89886bc1664478b73bcd1571c8 (patch) | |
tree | 4dbf195705f640295c5e5b1920b2926384df4ba0 | |
parent | 36bdc96b81776eb1c9026fca85524e6dc694cb56 (diff) |
Added OptInterfaceId
-rw-r--r-- | dhcpv6/option_interfaceid.go | 49 | ||||
-rw-r--r-- | dhcpv6/options.go | 2 |
2 files changed, 51 insertions, 0 deletions
diff --git a/dhcpv6/option_interfaceid.go b/dhcpv6/option_interfaceid.go new file mode 100644 index 0000000..4ba83f5 --- /dev/null +++ b/dhcpv6/option_interfaceid.go @@ -0,0 +1,49 @@ +package dhcpv6 + +// This module defines the OptInterfaceId structure. +// https://www.ietf.org/rfc/rfc3315.txt + +import ( + "encoding/binary" + "fmt" +) + +type OptInterfaceId struct { + interfaceId []byte +} + +func (op *OptInterfaceId) Code() OptionCode { + return OPTION_INTERFACE_ID +} + +func (op *OptInterfaceId) ToBytes() []byte { + buf := make([]byte, 4) + binary.BigEndian.PutUint16(buf[0:2], uint16(OPTION_INTERFACE_ID)) + binary.BigEndian.PutUint16(buf[2:4], 2) + buf = append(buf, op.interfaceId...) + return buf +} + +func (op *OptInterfaceId) InterfaceID() []byte { + return op.interfaceId +} + +func (op *OptInterfaceId) SetInterfaceID(interfaceId []byte) { + op.interfaceId = append([]byte(nil), interfaceId...) +} + +func (op *OptInterfaceId) Length() int { + return 4 + len(op.interfaceId) +} + +func (op *OptInterfaceId) String() string { + return fmt.Sprintf("OptInterfaceId{interfaceid=%v}", op.interfaceId) +} + +// build an OptInterfaceId structure from a sequence of bytes. +// The input data does not include option code and length bytes. +func ParseOptInterfaceId(data []byte) (*OptInterfaceId, error) { + opt := OptInterfaceId{} + opt.interfaceId = append([]byte(nil), data[4:]...) + return &opt, nil +} diff --git a/dhcpv6/options.go b/dhcpv6/options.go index d5d299f..4ac5977 100644 --- a/dhcpv6/options.go +++ b/dhcpv6/options.go @@ -92,6 +92,8 @@ func ParseOption(dataStart []byte) (Option, error) { opt, err = ParseOptRelayMsg(optData) case OPTION_REMOTE_ID: opt, err = ParseOptRemoteId(optData) + case OPTION_INTERFACE_ID: + opt, err = ParseOptInterfaceId(optData) default: opt = &OptionGeneric{OptionCode: code, OptionData: optData} } |