2021-09-07 18:33:23 +03:00
|
|
|
//go:build aix || darwin || dragonfly || linux || netbsd || solaris
|
|
|
|
// +build aix darwin dragonfly linux netbsd solaris
|
|
|
|
|
|
|
|
package dhcpd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
|
|
|
// broadcast sends resp to the broadcast address specific for network interface.
|
2021-09-30 18:28:19 +03:00
|
|
|
func (c *dhcpConn) broadcast(respData []byte, peer *net.UDPAddr) (n int, err error) {
|
2021-09-07 18:33:23 +03:00
|
|
|
// 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.
|
2021-09-30 18:28:19 +03:00
|
|
|
if n, err = c.udpConn.WriteTo(respData, peer); err != nil {
|
|
|
|
return n, err
|
2021-09-07 18:33:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Broadcast the message one more time using the interface-specific
|
|
|
|
// broadcast address.
|
2021-09-30 18:28:19 +03:00
|
|
|
peer.IP = c.bcastIP
|
2021-09-07 18:33:23 +03:00
|
|
|
|
2021-09-30 18:28:19 +03:00
|
|
|
return c.udpConn.WriteTo(respData, peer)
|
2021-09-07 18:33:23 +03:00
|
|
|
}
|