summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/dhcpv6relay.go
diff options
context:
space:
mode:
authorSean Karlage <skarlage@fb.com>2018-08-15 10:34:04 -0700
committerSean Karlage <skarlage@fb.com>2018-08-15 10:34:04 -0700
commit40169a2169f788c41cb806c9d344148e72a3a0bd (patch)
tree6cfee5029c946710e4ed7789151ac02e62fa852b /dhcpv6/dhcpv6relay.go
parent8ea2525c898436a2a935580de67727bbe7035c85 (diff)
parent926a42d133247d7a4fa388548e4323b77421f798 (diff)
Merge branch 'master' into dhcpv4-moar-tests
Diffstat (limited to 'dhcpv6/dhcpv6relay.go')
-rw-r--r--dhcpv6/dhcpv6relay.go25
1 files changed, 16 insertions, 9 deletions
diff --git a/dhcpv6/dhcpv6relay.go b/dhcpv6/dhcpv6relay.go
index d9555cb..5c30bad 100644
--- a/dhcpv6/dhcpv6relay.go
+++ b/dhcpv6/dhcpv6relay.go
@@ -158,23 +158,26 @@ func (d *DHCPv6Relay) GetInnerMessage() (DHCPv6, error) {
}
}
-// NewRelayReplFromRelayForw creates a RELAY_REPL packet based on a RELAY_FORW
-// packet and replaces the inner message with the passed DHCPv6 message.
+// NewRelayReplFromRelayForw creates a MessageTypeRelayReply based on a
+// MessageTypeRelayForward and replaces the inner message with the passed
+// DHCPv6 message. It copies the OptionInterfaceID and OptionRemoteID if the
+// options are present in the Relay packet.
func NewRelayReplFromRelayForw(relayForw, msg DHCPv6) (DHCPv6, error) {
var (
err error
linkAddr, peerAddr []net.IP
- optiids []Option
+ optiid []Option
+ optrid []Option
)
if relayForw == nil {
- return nil, errors.New("RELAY_FORW cannot be nil")
+ return nil, errors.New("Relay message cannot be nil")
}
relay, ok := relayForw.(*DHCPv6Relay)
if !ok {
return nil, errors.New("Not a DHCPv6Relay")
}
if relay.Type() != MessageTypeRelayForward {
- return nil, errors.New("The passed packet is not of type RELAY_FORW")
+ return nil, errors.New("The passed packet is not of type MessageTypeRelayForward")
}
if msg == nil {
return nil, errors.New("The passed message cannot be nil")
@@ -185,7 +188,8 @@ func NewRelayReplFromRelayForw(relayForw, msg DHCPv6) (DHCPv6, error) {
for {
linkAddr = append(linkAddr, relay.LinkAddr())
peerAddr = append(peerAddr, relay.PeerAddr())
- optiids = append(optiids, relay.GetOneOption(OptionInterfaceID))
+ optiid = append(optiid, relay.GetOneOption(OptionInterfaceID))
+ optrid = append(optrid, relay.GetOneOption(OptionRemoteID))
decap, err := DecapsulateRelay(relay)
if err != nil {
return nil, err
@@ -198,12 +202,15 @@ func NewRelayReplFromRelayForw(relayForw, msg DHCPv6) (DHCPv6, error) {
}
for i := len(linkAddr) - 1; i >= 0; i-- {
msg, err = EncapsulateRelay(msg, MessageTypeRelayReply, linkAddr[i], peerAddr[i])
- if opt := optiids[i]; opt != nil {
- msg.AddOption(opt)
- }
if err != nil {
return nil, err
}
+ if opt := optiid[i]; opt != nil {
+ msg.AddOption(opt)
+ }
+ if opt := optrid[i]; opt != nil {
+ msg.AddOption(opt)
+ }
}
return msg, nil
}