Skip to content

Commit

Permalink
Judge client id in dhcpv4
Browse files Browse the repository at this point in the history
  • Loading branch information
nmreadelf committed Nov 20, 2023
1 parent c8f1112 commit 9715789
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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
Expand Down
18 changes: 18 additions & 0 deletions internal/dhcpd/v4_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -1280,6 +1281,23 @@ 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)
hdType := buf.Read8()
// refer: https://github.com/wireshark/wireshark/blob/c3cc0e5fa7123f3d493c6a61b8919eac2973000f/epan/dissectors/packet-dhcp.c#L2306
// The code for this option is 61, and its minimum length is 2.
//
// Code Len Type Client-Identifier
// +-----+-----+-----+-----+-----+---
// | 61 | n | t1 | i1 | i2 | ...
// +-----+-----+-----+-----+-----+---
// A hardware type of 0 (zero) should be used when the value field
// contains an identifier other than a hardware address
// mac address length plus type field equal seven
if hdType > 0 && len(opt) == 7 {
buf.ReadBytes(req.ClientHWAddr)
}
}

err = netutil.ValidateMAC(req.ClientHWAddr)
if err != nil {
Expand Down

0 comments on commit 9715789

Please sign in to comment.