Skip to content

Commit

Permalink
dhcpd: reverd mod upd
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Aug 15, 2022
1 parent 14fd995 commit 6fe1721
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ See also the [v0.107.9 GitHub milestone][ms-v0.107.9].

### Fixed

- DHCP not working on most OSes ([#4836]).
- Several UI issues ([#4775], [#4776], [#4782]).

### Removed
Expand All @@ -89,6 +90,7 @@ See also the [v0.107.9 GitHub milestone][ms-v0.107.9].
[#4775]: https://github.com/AdguardTeam/AdGuardHome/issues/4775
[#4776]: https://github.com/AdguardTeam/AdGuardHome/issues/4776
[#4782]: https://github.com/AdguardTeam/AdGuardHome/issues/4782
[#4836]: https://github.com/AdguardTeam/AdGuardHome/issues/4836

[go-1.18.5]: https://groups.google.com/g/golang-announce/c/YqYYG87xB10
[ms-v0.107.9]: https://github.com/AdguardTeam/AdGuardHome/milestone/45?closed=1
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ require (
github.com/lucas-clemente/quic-go v0.28.1
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118
github.com/mdlayher/netlink v1.6.0
github.com/mdlayher/packet v1.0.0
// TODO(a.garipov): This package is deprecated; find a new one or use
// our own code for that.
github.com/mdlayher/raw v0.1.0 // indirect
// our own code for that. Perhaps, use gopacket.
github.com/mdlayher/raw v0.1.0
github.com/miekg/dns v1.1.50
github.com/stretchr/testify v1.7.1
github.com/ti-mo/netfilter v0.4.0
Expand Down Expand Up @@ -52,6 +51,7 @@ require (
github.com/marten-seemann/qtls-go1-17 v0.1.2 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.2 // indirect
github.com/marten-seemann/qtls-go1-19 v0.1.0-beta.1 // indirect
github.com/mdlayher/packet v1.0.0 // indirect
github.com/mdlayher/socket v0.2.3 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
Expand Down
16 changes: 6 additions & 10 deletions internal/dhcpd/conn_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ import (
"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/insomniacslk/dhcp/dhcpv4/server4"
"github.com/mdlayher/ethernet"
"github.com/mdlayher/packet"

//lint:ignore SA1019 See the TODO in go.mod.
"github.com/mdlayher/raw"
)

// dhcpUnicastAddr is the combination of MAC and IP addresses for responding to
// the unconfigured host.
type dhcpUnicastAddr struct {
// packet.Addr is embedded here to make *dhcpUcastAddr a net.Addr without
// raw.Addr is embedded here to make *dhcpUcastAddr a net.Addr without
// actually implementing all methods. It also contains the client's
// hardware address.
packet.Addr
raw.Addr

// yiaddr is an IP address just allocated by server for the host.
yiaddr net.IP
Expand All @@ -51,13 +53,7 @@ type dhcpConn struct {
// newDHCPConn creates the special connection for DHCP server.
func (s *v4Server) newDHCPConn(iface *net.Interface) (c net.PacketConn, err error) {
var ucast net.PacketConn
ucast, err = packet.Listen(
iface,
packet.Raw,
int(ethernet.EtherTypeIPv4),
nil,
)
if err != nil {
if ucast, err = raw.ListenPacket(iface, uint16(ethernet.EtherTypeIPv4), nil); err != nil {
return nil, fmt.Errorf("creating raw udp connection: %w", err)
}

Expand Down
8 changes: 5 additions & 3 deletions internal/dhcpd/conn_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/mdlayher/packet"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

//lint:ignore SA1019 See the TODO in go.mod.
"github.com/mdlayher/raw"
)

func TestDHCPConn_WriteTo_common(t *testing.T) {
Expand Down Expand Up @@ -56,7 +58,7 @@ func TestBuildEtherPkt(t *testing.T) {
srcIP: net.IP{1, 2, 3, 4},
}
peer := &dhcpUnicastAddr{
Addr: packet.Addr{HardwareAddr: net.HardwareAddr{6, 5, 4, 3, 2, 1}},
Addr: raw.Addr{HardwareAddr: net.HardwareAddr{6, 5, 4, 3, 2, 1}},
yiaddr: net.IP{4, 3, 2, 1},
}
payload := (&dhcpv4.DHCPv4{}).ToBytes()
Expand Down Expand Up @@ -102,7 +104,7 @@ func TestBuildEtherPkt(t *testing.T) {
t.Run("serializing_error", func(t *testing.T) {
// Create a peer with invalid MAC.
badPeer := &dhcpUnicastAddr{
Addr: packet.Addr{HardwareAddr: net.HardwareAddr{5, 4, 3, 2, 1}},
Addr: raw.Addr{HardwareAddr: net.HardwareAddr{5, 4, 3, 2, 1}},
yiaddr: net.IP{4, 3, 2, 1},
}

Expand Down
6 changes: 4 additions & 2 deletions internal/dhcpd/v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"github.com/go-ping/ping"
"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/insomniacslk/dhcp/dhcpv4/server4"
"github.com/mdlayher/packet"

//lint:ignore SA1019 See the TODO in go.mod.
"github.com/mdlayher/raw"
)

// v4Server is a DHCPv4 server.
Expand Down Expand Up @@ -992,7 +994,7 @@ func (s *v4Server) send(peer net.Addr, conn net.PacketConn, req, resp *dhcpv4.DH
// Unicast DHCPOFFER and DHCPACK messages to the client's
// hardware address and yiaddr.
peer = &dhcpUnicastAddr{
Addr: packet.Addr{HardwareAddr: req.ClientHWAddr},
Addr: raw.Addr{HardwareAddr: req.ClientHWAddr},
yiaddr: resp.YourIPAddr,
}
default:
Expand Down
6 changes: 4 additions & 2 deletions internal/dhcpd/v4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
"github.com/AdguardTeam/golibs/stringutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/mdlayher/packet"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

//lint:ignore SA1019 See the TODO in go.mod.
"github.com/mdlayher/raw"
)

var (
Expand Down Expand Up @@ -554,7 +556,7 @@ func TestV4Server_Send(t *testing.T) {
req: &dhcpv4.DHCPv4{ClientHWAddr: knownMAC},
resp: &dhcpv4.DHCPv4{YourIPAddr: knownIP},
want: &dhcpUnicastAddr{
Addr: packet.Addr{HardwareAddr: knownMAC},
Addr: raw.Addr{HardwareAddr: knownMAC},
yiaddr: knownIP,
},
}, {
Expand Down

0 comments on commit 6fe1721

Please sign in to comment.