Pull request: 3443 dhcp broadcast
Merge in DNS/adguard-home from 3443-fix-wired-dhcp to master Updates #3443. Squashed commit of the following: commit ec7c3b73e274ba7c05c5856cb2f4ea218ad46870 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 7 18:21:07 2021 +0300 dhcpd: imp docs & naming commit d87c646af44d837c81aa032e82aad846bde97bc8 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 7 16:56:36 2021 +0300 dhcpd: fix build tags & log changes commit cbd0b3c1aa0efb32aeaa9130111719ab3861e817 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 7 16:26:50 2021 +0300 dhcpd: revert 3443 & imp broadcasting
This commit is contained in:
51
internal/dhcpd/broadcast_others.go
Normal file
51
internal/dhcpd/broadcast_others.go
Normal file
@@ -0,0 +1,51 @@
|
||||
//go:build aix || darwin || dragonfly || linux || netbsd || solaris
|
||||
// +build aix darwin dragonfly linux netbsd solaris
|
||||
|
||||
package dhcpd
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
"github.com/insomniacslk/dhcp/dhcpv4"
|
||||
)
|
||||
|
||||
// broadcast sends resp to the broadcast address specific for network interface.
|
||||
func (s *v4Server) broadcast(peer net.Addr, conn net.PacketConn, resp *dhcpv4.DHCPv4) {
|
||||
respData := resp.ToBytes()
|
||||
|
||||
log.Debug("dhcpv4: sending to %s: %s", peer, resp.Summary())
|
||||
|
||||
// This write to 0xffffffff reverts some behavior changes made in
|
||||
// https://github.com/AdguardTeam/AdGuardHome/issues/3289. The DHCP
|
||||
// server should broadcast the message to 0xffffffff but it's
|
||||
// inconsistent with the actual mental model of DHCP implementation
|
||||
// which requires the network interface selection to bind to.
|
||||
//
|
||||
// See https://github.com/AdguardTeam/AdGuardHome/issues/3480 and
|
||||
// https://github.com/AdguardTeam/AdGuardHome/issues/3366.
|
||||
//
|
||||
// See also https://github.com/AdguardTeam/AdGuardHome/issues/3539.
|
||||
if _, err := conn.WriteTo(respData, peer); err != nil {
|
||||
log.Error("dhcpv4: conn.Write to %s failed: %s", peer, err)
|
||||
}
|
||||
|
||||
// peer is expected to be of type *net.UDPConn as the server4.NewServer
|
||||
// initializes it.
|
||||
udpPeer, ok := peer.(*net.UDPAddr)
|
||||
if !ok {
|
||||
log.Error("dhcpv4: peer is of unexpected type %T", peer)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Broadcast the message one more time using the interface-specific
|
||||
// broadcast address.
|
||||
udpPeer.IP = s.conf.broadcastIP
|
||||
|
||||
log.Debug("dhcpv4: sending to %s: %s", peer, resp.Summary())
|
||||
|
||||
if _, err := conn.WriteTo(respData, peer); err != nil {
|
||||
log.Error("dhcpv4: conn.Write to %s failed: %s", peer, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user