From b06ba191b2e7eaca2d762ce7da9f494e43634dcf Mon Sep 17 00:00:00 2001 From: nmreadelf Date: Thu, 17 Aug 2023 10:27:28 +0800 Subject: [PATCH] Judge client id in dhcpv4 --- go.mod | 7 +++++-- internal/dhcpd/v4_unix.go | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index d4ba483c641..a98c03ee721 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/ameshkov/dnscrypt/v2 v2.2.7 github.com/bluele/gcache v0.0.2 github.com/digineo/go-ipset/v2 v2.2.1 - github.com/dimfeld/httptreemux/v5 v5.5.0 github.com/fsnotify/fsnotify v1.6.0 github.com/go-ping/ping v1.1.0 github.com/google/go-cmp v0.5.9 @@ -40,6 +39,11 @@ require ( howett.net/plist v1.0.0 ) +require ( + github.com/dimfeld/httptreemux/v5 v5.5.0 + github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63 +) + require ( github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635 // indirect @@ -57,7 +61,6 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect github.com/quic-go/qtls-go1-20 v0.3.2 // indirect - github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63 // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/sync v0.3.0 // indirect golang.org/x/text v0.12.0 // indirect diff --git a/internal/dhcpd/v4_unix.go b/internal/dhcpd/v4_unix.go index 6a973b24f7b..e6d84a70238 100644 --- a/internal/dhcpd/v4_unix.go +++ b/internal/dhcpd/v4_unix.go @@ -20,6 +20,7 @@ import ( "github.com/go-ping/ping" "github.com/insomniacslk/dhcp/dhcpv4" "github.com/insomniacslk/dhcp/dhcpv4/server4" + "github.com/u-root/uio/uio" "golang.org/x/exp/slices" ) @@ -1162,6 +1163,11 @@ func (s *v4Server) packetHandler(conn net.PacketConn, peer net.Addr, req *dhcpv4 return } + if opt := req.Options.Get(dhcpv4.OptionClientIdentifier); opt != nil { + buf := uio.NewBigEndianBuffer(opt) + _ = buf.Read8() + buf.ReadBytes(req.ClientHWAddr) + } err = netutil.ValidateMAC(req.ClientHWAddr) if err != nil {