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