mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-17 05:01:35 +03:00
b77ceaaf55
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
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
//go:build freebsd || openbsd
|
|
// +build freebsd openbsd
|
|
|
|
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) {
|
|
// 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
|
|
}
|
|
|
|
// Despite the fact that server4.NewIPv4UDPConn explicitly sets socket
|
|
// options to allow broadcasting, it also binds the connection to a
|
|
// specific interface. On FreeBSD and OpenBSD conn.WriteTo causes
|
|
// errors while writing to the addresses that belong to another
|
|
// interface. So, use the broadcast address specific for the binded
|
|
// interface.
|
|
udpPeer.IP = s.conf.broadcastIP
|
|
|
|
log.Debug("dhcpv4: sending to %s: %s", peer, resp.Summary())
|
|
|
|
if _, err := conn.WriteTo(resp.ToBytes(), peer); err != nil {
|
|
log.Error("dhcpv4: conn.Write to %s failed: %s", peer, err)
|
|
}
|
|
}
|