summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--dhcpv4/dhcpv4.go5
-rw-r--r--dhcpv4/modifiers.go7
2 files changed, 11 insertions, 1 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go
index b15c9e2..eb02bdc 100644
--- a/dhcpv4/dhcpv4.go
+++ b/dhcpv4/dhcpv4.go
@@ -247,7 +247,10 @@ func NewRequestFromOffer(offer *DHCPv4, modifiers ...Modifier) (*DHCPv4, error)
// NewReplyFromRequest builds a DHCPv4 reply from a request.
func NewReplyFromRequest(request *DHCPv4, modifiers ...Modifier) (*DHCPv4, error) {
- return New(PrependModifiers(modifiers, WithReply(request))...)
+ return New(PrependModifiers(modifiers,
+ WithReply(request),
+ WithGatewayIP(request.GatewayIPAddr),
+ )...)
}
// FromBytes encodes the DHCPv4 packet into a sequence of bytes, and returns an
diff --git a/dhcpv4/modifiers.go b/dhcpv4/modifiers.go
index 477f48f..16d1d57 100644
--- a/dhcpv4/modifiers.go
+++ b/dhcpv4/modifiers.go
@@ -36,6 +36,13 @@ func WithServerIP(ip net.IP) Modifier {
}
}
+// WithGatewayIP sets the Gateway IP for the DHCPv4 packet.
+func WithGatewayIP(ip net.IP) Modifier {
+ return func(d *DHCPv4) {
+ d.GatewayIPAddr = ip
+ }
+}
+
// WithReply fills in opcode, hwtype, xid, clienthwaddr, flags, and gateway ip
// addr from the given packet.
func WithReply(request *DHCPv4) Modifier {