From 100d70dccf05ae43aa05145f4a6773220d870bfa Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Sat, 10 Aug 2024 16:15:11 +1000 Subject: [PATCH] Ensure frame padding --- router/aarp.go | 9 +++++++++ router/peer_eth.go | 3 +++ router/port.go | 3 +++ 3 files changed, 15 insertions(+) diff --git a/router/aarp.go b/router/aarp.go index 62261ef..815471e 100644 --- a/router/aarp.go +++ b/router/aarp.go @@ -337,6 +337,9 @@ func (a *AARPMachine) heyThatsMe(targ aarp.AddrPair) error { if err != nil { return err } + if len(respFrameRaw) < 64 { + respFrameRaw = append(respFrameRaw, make([]byte, 64-len(respFrameRaw))...) + } return a.pcapHandle.WritePacketData(respFrameRaw) } @@ -350,6 +353,9 @@ func (a *AARPMachine) probe() error { if err != nil { return err } + if len(probeFrameRaw) < 64 { + probeFrameRaw = append(probeFrameRaw, make([]byte, 64-len(probeFrameRaw))...) + } return a.pcapHandle.WritePacketData(probeFrameRaw) } @@ -363,6 +369,9 @@ func (a *AARPMachine) request(ddpAddr ddp.Addr) error { if err != nil { return err } + if len(reqFrameRaw) < 64 { + reqFrameRaw = append(reqFrameRaw, make([]byte, 64-len(reqFrameRaw))...) + } return a.pcapHandle.WritePacketData(reqFrameRaw) } diff --git a/router/peer_eth.go b/router/peer_eth.go index 4b181a2..e3fb8ce 100644 --- a/router/peer_eth.go +++ b/router/peer_eth.go @@ -46,5 +46,8 @@ func (p *EtherTalkPeer) Forward(ctx context.Context, pkt *ddp.ExtPacket) error { if err != nil { return err } + if len(outFrameRaw) < 64 { + outFrameRaw = append(outFrameRaw, make([]byte, 64-len(outFrameRaw))...) + } return p.Port.PcapHandle.WritePacketData(outFrameRaw) } diff --git a/router/port.go b/router/port.go index e6c05bb..6147baa 100644 --- a/router/port.go +++ b/router/port.go @@ -200,5 +200,8 @@ func (port *EtherTalkPort) send(dstEth ethernet.Addr, pkt *ddp.ExtPacket) error if err != nil { return err } + if len(outFrameRaw) < 64 { + outFrameRaw = append(outFrameRaw, make([]byte, 64-len(outFrameRaw))...) + } return port.PcapHandle.WritePacketData(outFrameRaw) }