Pull request: 3443 dhcp broadcast vol.2
Merge in DNS/adguard-home from 3443-dhcp-broadcast-vol.2 to master
Closes #3443.
Squashed commit of the following:
commit a85af89cb43f2489126fe3c12366fc034e89f59d
Merge: 72eb3a88 a4e07827
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Sep 30 18:08:19 2021 +0300
Merge branch 'master' into 3443-dhcp-broadcast-vol.2
commit 72eb3a8853540b06ee1096decf50e836b539fe45
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Sep 30 18:03:19 2021 +0300
dhcpd: imp code readability
commit 2d1fbc40d04a4125855d6be9f02e09d15430150d
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Sep 30 14:16:59 2021 +0300
dhcpd: imp tests
commit 889fad3084ad2b81edfc12100e2ce29d323227ba
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Wed Sep 29 20:09:25 2021 +0300
dhcpd: imp code, docs
commit 1fd6b2346ff66e033bceaa169aed751be5822ca8
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Thu Sep 23 16:08:18 2021 +0300
dhcpd: unicast to mac address
This commit is contained in:
@@ -5,17 +5,10 @@ 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())
|
||||
|
||||
func (c *dhcpConn) broadcast(respData []byte, peer *net.UDPAddr) (n int, err error) {
|
||||
// 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
|
||||
@@ -26,26 +19,13 @@ func (s *v4Server) broadcast(peer net.Addr, conn net.PacketConn, resp *dhcpv4.DH
|
||||
// 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
|
||||
if n, err = c.udpConn.WriteTo(respData, peer); err != nil {
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Broadcast the message one more time using the interface-specific
|
||||
// broadcast address.
|
||||
udpPeer.IP = s.conf.broadcastIP
|
||||
peer.IP = c.bcastIP
|
||||
|
||||
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)
|
||||
}
|
||||
return c.udpConn.WriteTo(respData, peer)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user