diff options
author | kevin <kworm@missouri-telecom.com> | 2019-11-18 20:09:41 -0600 |
---|---|---|
committer | Chris K <c@chrisko.ch> | 2019-11-20 12:30:56 -0800 |
commit | ee2727953b7a5e79131fedfeb3d8b7fa64e990cb (patch) | |
tree | ab4566e1570463e64e86bf7ddd39dc94b943f59e | |
parent | c058740140122368226eaaf7debce03c376e6ae8 (diff) |
Add support for copying relay options
Signed-off-by: kevin <kworm@missouri-telecom.com>
-rw-r--r-- | dhcpv4/dhcpv4.go | 1 | ||||
-rw-r--r-- | dhcpv4/modifiers.go | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index f85fe2e..d3890c5 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -262,6 +262,7 @@ func NewReplyFromRequest(request *DHCPv4, modifiers ...Modifier) (*DHCPv4, error return New(PrependModifiers(modifiers, WithReply(request), WithGatewayIP(request.GatewayIPAddr), + WithRelayOptions(request), )...) } diff --git a/dhcpv4/modifiers.go b/dhcpv4/modifiers.go index 16d1d57..168b178 100644 --- a/dhcpv4/modifiers.go +++ b/dhcpv4/modifiers.go @@ -43,6 +43,18 @@ func WithGatewayIP(ip net.IP) Modifier { } } +//WithRelayOptions copies the relay options from the request to the reply +func WithRelayOptions(request *DHCPv4) Modifier { + return func(d *DHCPv4) { + // If request has Relay Agent Info copy it to the reply + if request.Options.Has(OptionRelayAgentInformation) { + relayopt := request.Options.Get(OptionRelayAgentInformation) + opt := OptGeneric(OptionRelayAgentInformation, relayopt) + d.Options.Update(opt) + } + } +} + // WithReply fills in opcode, hwtype, xid, clienthwaddr, flags, and gateway ip // addr from the given packet. func WithReply(request *DHCPv4) Modifier { |