summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/dhcpv6relay.go
diff options
context:
space:
mode:
authorAndrea Barberio <insomniac@slackware.it>2017-12-11 09:25:20 +0000
committerAndrea Barberio <insomniac@slackware.it>2017-12-11 09:25:20 +0000
commit2c9cdc34d045b5cb528ae086fd2b875c0c73d145 (patch)
treee02e2afd31dc288403534b6a4437698aa7b664d0 /dhcpv6/dhcpv6relay.go
parent5db858ce8450757dd7dff589c7d258213c3b7baa (diff)
Added DHCPv6Relay.GetInnerMessage
Diffstat (limited to 'dhcpv6/dhcpv6relay.go')
-rw-r--r--dhcpv6/dhcpv6relay.go21
1 files changed, 21 insertions, 0 deletions
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()
+ }
+}