From a0205a54ec442363d2e0afc72fc0de1f83a8ba2f Mon Sep 17 00:00:00 2001 From: Brian Kemper Date: Sun, 19 Mar 2023 17:29:04 -0600 Subject: [PATCH] Remove direct dep on mdlayher/raw package --- go.mod | 4 ++-- internal/dhcpd/conn_unix.go | 10 ++++------ internal/dhcpd/conn_unix_test.go | 8 +++----- internal/dhcpd/v4_unix.go | 6 ++---- internal/dhcpd/v4_unix_test.go | 6 ++---- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 05729ad5..7ab8f0bd 100644 --- a/go.mod +++ b/go.mod @@ -21,9 +21,10 @@ require ( github.com/kardianos/service v1.2.2 github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 github.com/mdlayher/netlink v1.7.1 + github.com/mdlayher/packet v1.1.1 // TODO(a.garipov): This package is deprecated; find a new one or use // our own code for that. Perhaps, use gopacket. - github.com/mdlayher/raw v0.1.0 + github.com/mdlayher/raw v0.1.0 // indirect github.com/miekg/dns v1.1.50 github.com/quic-go/quic-go v0.32.0 github.com/stretchr/testify v1.8.2 @@ -49,7 +50,6 @@ require ( github.com/golang/mock v1.6.0 // indirect github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect github.com/josharian/native v1.1.0 // indirect - github.com/mdlayher/packet v1.1.1 // indirect github.com/mdlayher/socket v0.4.0 // indirect github.com/onsi/ginkgo/v2 v2.8.3 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect diff --git a/internal/dhcpd/conn_unix.go b/internal/dhcpd/conn_unix.go index efcbc8aa..37994e31 100644 --- a/internal/dhcpd/conn_unix.go +++ b/internal/dhcpd/conn_unix.go @@ -15,18 +15,16 @@ import ( "github.com/insomniacslk/dhcp/dhcpv4" "github.com/insomniacslk/dhcp/dhcpv4/server4" "github.com/mdlayher/ethernet" - - //lint:ignore SA1019 See the TODO in go.mod. - "github.com/mdlayher/raw" + "github.com/mdlayher/packet" ) // dhcpUnicastAddr is the combination of MAC and IP addresses for responding to // the unconfigured host. type dhcpUnicastAddr struct { - // raw.Addr is embedded here to make *dhcpUcastAddr a net.Addr without + // packet.Addr is embedded here to make *dhcpUcastAddr a net.Addr without // actually implementing all methods. It also contains the client's // hardware address. - raw.Addr + packet.Addr // yiaddr is an IP address just allocated by server for the host. yiaddr net.IP @@ -52,7 +50,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 - if ucast, err = raw.ListenPacket(iface, uint16(ethernet.EtherTypeIPv4), nil); err != nil { + if ucast, err = packet.Listen(iface, packet.Raw, int(ethernet.EtherTypeIPv4), nil); err != nil { return nil, fmt.Errorf("creating raw udp connection: %w", err) } diff --git a/internal/dhcpd/conn_unix_test.go b/internal/dhcpd/conn_unix_test.go index aab79082..65e64682 100644 --- a/internal/dhcpd/conn_unix_test.go +++ b/internal/dhcpd/conn_unix_test.go @@ -10,11 +10,9 @@ 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) { @@ -57,7 +55,7 @@ func TestBuildEtherPkt(t *testing.T) { srcIP: net.IP{1, 2, 3, 4}, } peer := &dhcpUnicastAddr{ - Addr: raw.Addr{HardwareAddr: net.HardwareAddr{6, 5, 4, 3, 2, 1}}, + Addr: packet.Addr{HardwareAddr: net.HardwareAddr{6, 5, 4, 3, 2, 1}}, yiaddr: net.IP{4, 3, 2, 1}, } payload := (&dhcpv4.DHCPv4{}).ToBytes() @@ -102,7 +100,7 @@ func TestBuildEtherPkt(t *testing.T) { t.Run("serializing_error", func(t *testing.T) { // Create a peer with invalid MAC. badPeer := &dhcpUnicastAddr{ - Addr: raw.Addr{HardwareAddr: net.HardwareAddr{5, 4, 3, 2, 1}}, + Addr: packet.Addr{HardwareAddr: net.HardwareAddr{5, 4, 3, 2, 1}}, yiaddr: net.IP{4, 3, 2, 1}, } diff --git a/internal/dhcpd/v4_unix.go b/internal/dhcpd/v4_unix.go index 63ae46d9..da45acca 100644 --- a/internal/dhcpd/v4_unix.go +++ b/internal/dhcpd/v4_unix.go @@ -20,10 +20,8 @@ import ( "github.com/go-ping/ping" "github.com/insomniacslk/dhcp/dhcpv4" "github.com/insomniacslk/dhcp/dhcpv4/server4" + "github.com/mdlayher/packet" "golang.org/x/exp/slices" - - //lint:ignore SA1019 See the TODO in go.mod. - "github.com/mdlayher/raw" ) // v4Server is a DHCPv4 server. @@ -1136,7 +1134,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: raw.Addr{HardwareAddr: req.ClientHWAddr}, + Addr: packet.Addr{HardwareAddr: req.ClientHWAddr}, yiaddr: resp.YourIPAddr, } default: diff --git a/internal/dhcpd/v4_unix_test.go b/internal/dhcpd/v4_unix_test.go index 8c1255e1..8a9d56f9 100644 --- a/internal/dhcpd/v4_unix_test.go +++ b/internal/dhcpd/v4_unix_test.go @@ -15,11 +15,9 @@ 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 ( @@ -810,7 +808,7 @@ func TestV4Server_Send(t *testing.T) { req: &dhcpv4.DHCPv4{ClientHWAddr: knownMAC}, resp: &dhcpv4.DHCPv4{YourIPAddr: knownIP}, want: &dhcpUnicastAddr{ - Addr: raw.Addr{HardwareAddr: knownMAC}, + Addr: packet.Addr{HardwareAddr: knownMAC}, yiaddr: knownIP, }, }, {