From 6d0d21cc633742eb4de9b08ad7a53572a6907623 Mon Sep 17 00:00:00 2001 From: Chris Koch Date: Sun, 28 Jul 2019 22:43:07 -0700 Subject: 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 --- dhcpv4/server4/server.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'dhcpv4/server4/server.go') 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() } -- cgit v1.2.3