From 2c9cdc34d045b5cb528ae086fd2b875c0c73d145 Mon Sep 17 00:00:00 2001 From: Andrea Barberio Date: Mon, 11 Dec 2017 09:25:20 +0000 Subject: Added DHCPv6Relay.GetInnerMessage --- dhcpv6/dhcpv6relay.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/dhcpv6/dhcpv6relay.go b/dhcpv6/dhcpv6relay.go index 0423f36..70fbc7f 100644 --- a/dhcpv6/dhcpv6relay.go +++ b/dhcpv6/dhcpv6relay.go @@ -83,3 +83,24 @@ func (r *DHCPv6Relay) GetOneOption(code OptionCode) Option { func (r *DHCPv6Relay) IsRelay() bool { return true } + +// Recurse into a relay message and extract and return the inner DHCPv6Message. +// Return nil if none found (e.g. not a relay message). +func (d *DHCPv6Relay) GetInnerMessage() (DHCPv6, error) { + var p DHCPv6 + p = d + for { + if !p.IsRelay() { + return p, nil + } + opt := p.GetOneOption(OPTION_RELAY_MSG) + if opt == nil { + return nil, fmt.Errorf("No OptRelayMsg found") + } + relayOpt := opt.(*OptRelayMsg) + if relayOpt.RelayMessage() == nil { + return nil, fmt.Errorf("Relay message cannot be nil") + } + p = relayOpt.RelayMessage() + } +} -- cgit v1.2.3