Pull request 1774: 5615-rm-raw

Updates #5615.

* commit '59a8265e31f802009f4ac6893ccec839cc5a2fb0':
  all: fmt go.mod
  Remove direct dep on mdlayher/raw package
This commit is contained in:
Ainar Garipov 2023-03-23 17:44:41 +03:00
commit 8de994d077
5 changed files with 13 additions and 23 deletions

6
go.mod
View file

@ -21,9 +21,7 @@ require (
github.com/kardianos/service v1.2.2 github.com/kardianos/service v1.2.2
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118
github.com/mdlayher/netlink v1.7.1 github.com/mdlayher/netlink v1.7.1
// TODO(a.garipov): This package is deprecated; find a new one or use github.com/mdlayher/packet v1.1.1
// our own code for that. Perhaps, use gopacket.
github.com/mdlayher/raw v0.1.0
github.com/miekg/dns v1.1.50 github.com/miekg/dns v1.1.50
github.com/quic-go/quic-go v0.32.0 github.com/quic-go/quic-go v0.32.0
github.com/stretchr/testify v1.8.2 github.com/stretchr/testify v1.8.2
@ -49,7 +47,7 @@ require (
github.com/golang/mock v1.6.0 // indirect github.com/golang/mock v1.6.0 // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/josharian/native v1.1.0 // indirect github.com/josharian/native v1.1.0 // indirect
github.com/mdlayher/packet v1.1.1 // indirect github.com/mdlayher/raw v0.1.0 // indirect
github.com/mdlayher/socket v0.4.0 // indirect github.com/mdlayher/socket v0.4.0 // indirect
github.com/onsi/ginkgo/v2 v2.8.3 // indirect github.com/onsi/ginkgo/v2 v2.8.3 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect

View file

@ -15,18 +15,16 @@ import (
"github.com/insomniacslk/dhcp/dhcpv4" "github.com/insomniacslk/dhcp/dhcpv4"
"github.com/insomniacslk/dhcp/dhcpv4/server4" "github.com/insomniacslk/dhcp/dhcpv4/server4"
"github.com/mdlayher/ethernet" "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 // dhcpUnicastAddr is the combination of MAC and IP addresses for responding to
// the unconfigured host. // the unconfigured host.
type dhcpUnicastAddr struct { 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 // actually implementing all methods. It also contains the client's
// hardware address. // hardware address.
raw.Addr packet.Addr
// yiaddr is an IP address just allocated by server for the host. // yiaddr is an IP address just allocated by server for the host.
yiaddr net.IP yiaddr net.IP
@ -52,7 +50,7 @@ type dhcpConn struct {
// newDHCPConn creates the special connection for DHCP server. // newDHCPConn creates the special connection for DHCP server.
func (s *v4Server) newDHCPConn(iface *net.Interface) (c net.PacketConn, err error) { func (s *v4Server) newDHCPConn(iface *net.Interface) (c net.PacketConn, err error) {
var ucast net.PacketConn 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) return nil, fmt.Errorf("creating raw udp connection: %w", err)
} }

View file

@ -10,11 +10,9 @@ import (
"github.com/google/gopacket" "github.com/google/gopacket"
"github.com/google/gopacket/layers" "github.com/google/gopacket/layers"
"github.com/insomniacslk/dhcp/dhcpv4" "github.com/insomniacslk/dhcp/dhcpv4"
"github.com/mdlayher/packet"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "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) { func TestDHCPConn_WriteTo_common(t *testing.T) {
@ -57,7 +55,7 @@ func TestBuildEtherPkt(t *testing.T) {
srcIP: net.IP{1, 2, 3, 4}, srcIP: net.IP{1, 2, 3, 4},
} }
peer := &dhcpUnicastAddr{ 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}, yiaddr: net.IP{4, 3, 2, 1},
} }
payload := (&dhcpv4.DHCPv4{}).ToBytes() payload := (&dhcpv4.DHCPv4{}).ToBytes()
@ -102,7 +100,7 @@ func TestBuildEtherPkt(t *testing.T) {
t.Run("serializing_error", func(t *testing.T) { t.Run("serializing_error", func(t *testing.T) {
// Create a peer with invalid MAC. // Create a peer with invalid MAC.
badPeer := &dhcpUnicastAddr{ 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}, yiaddr: net.IP{4, 3, 2, 1},
} }

View file

@ -20,10 +20,8 @@ import (
"github.com/go-ping/ping" "github.com/go-ping/ping"
"github.com/insomniacslk/dhcp/dhcpv4" "github.com/insomniacslk/dhcp/dhcpv4"
"github.com/insomniacslk/dhcp/dhcpv4/server4" "github.com/insomniacslk/dhcp/dhcpv4/server4"
"github.com/mdlayher/packet"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
//lint:ignore SA1019 See the TODO in go.mod.
"github.com/mdlayher/raw"
) )
// v4Server is a DHCPv4 server. // v4Server is a DHCPv4 server.
@ -1166,7 +1164,7 @@ func (s *v4Server) send(peer net.Addr, conn net.PacketConn, req, resp *dhcpv4.DH
// Unicast DHCPOFFER and DHCPACK messages to the client's // Unicast DHCPOFFER and DHCPACK messages to the client's
// hardware address and yiaddr. // hardware address and yiaddr.
peer = &dhcpUnicastAddr{ peer = &dhcpUnicastAddr{
Addr: raw.Addr{HardwareAddr: req.ClientHWAddr}, Addr: packet.Addr{HardwareAddr: req.ClientHWAddr},
yiaddr: resp.YourIPAddr, yiaddr: resp.YourIPAddr,
} }
default: default:

View file

@ -15,11 +15,9 @@ import (
"github.com/AdguardTeam/golibs/stringutil" "github.com/AdguardTeam/golibs/stringutil"
"github.com/AdguardTeam/golibs/testutil" "github.com/AdguardTeam/golibs/testutil"
"github.com/insomniacslk/dhcp/dhcpv4" "github.com/insomniacslk/dhcp/dhcpv4"
"github.com/mdlayher/packet"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
//lint:ignore SA1019 See the TODO in go.mod.
"github.com/mdlayher/raw"
) )
var ( var (
@ -821,7 +819,7 @@ func TestV4Server_Send(t *testing.T) {
req: &dhcpv4.DHCPv4{ClientHWAddr: knownMAC}, req: &dhcpv4.DHCPv4{ClientHWAddr: knownMAC},
resp: &dhcpv4.DHCPv4{YourIPAddr: knownIP}, resp: &dhcpv4.DHCPv4{YourIPAddr: knownIP},
want: &dhcpUnicastAddr{ want: &dhcpUnicastAddr{
Addr: raw.Addr{HardwareAddr: knownMAC}, Addr: packet.Addr{HardwareAddr: knownMAC},
yiaddr: knownIP, yiaddr: knownIP,
}, },
}, { }, {