From ee2727953b7a5e79131fedfeb3d8b7fa64e990cb Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 18 Nov 2019 20:09:41 -0600 Subject: Add support for copying relay options Signed-off-by: kevin --- dhcpv4/dhcpv4.go | 1 + dhcpv4/modifiers.go | 12 ++++++++++++ 2 files changed, 13 insertions(+) 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 { -- cgit v1.2.3