diff options
-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 { |