Skip to content

Commit

Permalink
keep working on dhcp
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Nov 26, 2023
1 parent 86d7cb4 commit 61a805e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion stacks/dhcp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (d *DHCPServer) HandleUDP(resp []byte, packet *UDPPacket) (_ int, err error
}

mac := packet.Eth.Source
client, _ := d.hosts[mac]
client := d.hosts[mac]
var msgType uint8
rcvHdr, err = parseDHCP(incpayload, func(opt dhcpOption) error {
switch opt.Opt {
Expand Down
2 changes: 1 addition & 1 deletion stacks/portstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (ps *PortStack) RecvEth(ethernetFrame []byte) (err error) {
case ipOffset < eth.SizeIPv4Header:
return errInvalidIHL

case ps.ip != ihdr.Destination:
case ps.ip != ihdr.Destination && ps.ip != [4]byte{}:
return nil // Not for us.
case uint16(offset) > end || int(offset) > len(payload) || int(end) > len(payload):
return errors.New("bad IP TotalLength/IHL")
Expand Down
9 changes: 6 additions & 3 deletions stacks/stacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ import (
const exchangesToEstablish = 4

func TestDHCP(t *testing.T) {
const networkSize = 20 // How many distinct IP/MAC addresses on network.
const networkSize = 2 // How many distinct IP/MAC addresses on network.
requestedIP := netip.AddrFrom4([4]byte{192, 168, 1, 69})
Stacks := createPortStacks(t, networkSize)
clientStack := Stacks[0]
serverStack := Stacks[1]

client := stacks.DHCPv4Client{
MAC: clientStack.MACAs6(),
MAC: clientStack.MACAs6(),
RequestedIP: requestedIP.As4(),
}
server := stacks.NewDHCPServer(67, serverStack.MACAs6(), serverStack.Addr())

clientStack.SetAddr(netip.AddrFrom4([4]byte{}))
serverStack.SetAddr(netip.AddrFrom4([4]byte{}))
err := clientStack.OpenUDP(68, client.HandleUDP)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 61a805e

Please sign in to comment.