From 042bb4b29f75f9bd9a971a71091d47d110303be6 Mon Sep 17 00:00:00 2001 From: Andrea Barberio Date: Thu, 7 Dec 2017 00:56:15 +0000 Subject: Added RelayMsg basic parsing --- dhcpv6/options/options.go | 2 ++ dhcpv6/options/relaymsg.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 dhcpv6/options/relaymsg.go diff --git a/dhcpv6/options/options.go b/dhcpv6/options/options.go index 6b587dd..2eeaa44 100644 --- a/dhcpv6/options/options.go +++ b/dhcpv6/options/options.go @@ -88,6 +88,8 @@ func ParseOption(dataStart []byte) (Option, error) { opt, err = ParseOptIAPrefix(optData) case OPTION_STATUS_CODE: opt, err = ParseOptStatusCode(optData) + case OPTION_RELAY_MSG: + opt, err = ParseOptRelayMsg(optData) default: opt = &OptionGeneric{OptionCode: code, OptionData: optData} } diff --git a/dhcpv6/options/relaymsg.go b/dhcpv6/options/relaymsg.go new file mode 100644 index 0000000..4384c30 --- /dev/null +++ b/dhcpv6/options/relaymsg.go @@ -0,0 +1,44 @@ +package options + +// This module defines the OptRelayMsg structure. +// https://www.ietf.org/rfc/rfc3315.txt + +import ( + "fmt" +) + +type OptRelayMsg struct { + relayMessage []byte // FIXME this has to become []DHCPv6 +} + +func (op *OptRelayMsg) Code() OptionCode { + return OPTION_RELAY_MSG +} + +func (op *OptRelayMsg) ToBytes() []byte { + return []byte(op.relayMessage) +} + +func (op *OptRelayMsg) RelayMessage() []byte { + return op.relayMessage +} + +func (op *OptRelayMsg) SetRelayMessage(relayMessage []byte) { + op.relayMessage = relayMessage +} + +func (op *OptRelayMsg) Length() int { + return len(op.relayMessage) +} + +func (op *OptRelayMsg) String() string { + return fmt.Sprintf("OptRelayMsg{relaymsg=%v}", op.relayMessage) +} + +// build an OptRelayMsg structure from a sequence of bytes. +// The input data does not include option code and length bytes. +func ParseOptRelayMsg(data []byte) (*OptRelayMsg, error) { + opt := OptRelayMsg{} + opt.relayMessage = []byte(data) + return &opt, nil +} -- cgit v1.2.3