diff options
author | Chris Koch <chrisko@google.com> | 2019-07-28 22:43:07 -0700 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2019-07-29 08:34:01 +0100 |
commit | 6d0d21cc633742eb4de9b08ad7a53572a6907623 (patch) | |
tree | 72cdadae64b0e6af751446b0361e9cb9f223ac15 /dhcpv4/server4/server.go | |
parent | f672bc204f35cdafd26aeefa5faf44ab4de7c4dc (diff) |
server4: set peer to broadcast if client IP is zero
Clients without an IP set their source address to 0.0.0.0, so the peer
returned by ReadFrom may not actually be the address to send to.
Clients without an IP should have their response broadcast.
Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'dhcpv4/server4/server.go')
-rw-r--r-- | dhcpv4/server4/server.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/dhcpv4/server4/server.go b/dhcpv4/server4/server.go index 3a2aee0..5567bae 100644 --- a/dhcpv4/server4/server.go +++ b/dhcpv4/server4/server.go @@ -90,11 +90,24 @@ func (s *Server) Serve() error { log.Printf("Error parsing DHCPv4 request: %v", err) continue } - go s.Handler(s.conn, peer, m) + + upeer, ok := peer.(*net.UDPAddr) + if !ok { + log.Printf("Not a UDP connection? Peer is %s", peer) + continue + } + // Set peer to broadcast if the client did not have an IP. + if upeer.IP == nil || upeer.IP.Equal(net.IPv4zero) { + upeer = &net.UDPAddr{ + IP: net.IPv4bcast, + Port: upeer.Port, + } + } + go s.Handler(s.conn, upeer, m) } } -// Close sends a termination request to the server, and closes the UDP listener +// Close sends a termination request to the server, and closes the UDP listener. func (s *Server) Close() error { return s.conn.Close() } |