fix: clean up misc TODO comments and improve UDP source filtering (#89)

- http/httpraw: cap header slice growth to pre-allocated capacity, fix
  benchmark to reuse Header across iterations (0 allocs/op)
- internal/ring: replace TODO panic comments with invariant explanations
- tcp/conn: document truncated-frame offset check
- tcp/handler: replace TODO with net.ErrClosed on RST-closed connection
- internet/stack-udpport: filter incoming packets by remote IP address
  when configured via SetStackNode; skip filter for IPv4 multicast
  destinations (class D) so mDNS and similar protocols work correctly

Generated with LLM assistance.

Signed-off-by: Marvin Drees <marvin.drees@9elements.com>
This commit is contained in:
Marvin Drees
2026-05-20 19:29:09 +02:00
committed by GitHub
parent edf302baf8
commit 46d4c06b9f
11 changed files with 76 additions and 14 deletions
+1 -1
View File
@@ -101,7 +101,7 @@ func (si4 *stackip4) demux4(carrierData []byte, offset int) error {
}
dst := ifrm.DestinationAddr()
if si4.ip4 != ([4]byte{}) && *dst != si4.ip4 {
if !si4.acceptMulticast || dst[0]&0xF0 != 0xE0 {
if !si4.acceptMulticast || !internal.IsMulticastIPAddr(dst[:]) {
si4.handlers.debug("ip:not-for-us")
return lneto.ErrPacketDrop // Not meant for us.
}
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"github.com/soypat/lneto"
"github.com/soypat/lneto/ethernet"
"github.com/soypat/lneto/internal"
"github.com/soypat/lneto/ipv6"
"github.com/soypat/lneto/tcp"
"github.com/soypat/lneto/udp"
@@ -89,7 +90,7 @@ func (si6 *stackip6) demux6(carrierData []byte, offset int) error {
}
dst := ifrm.DestinationAddr()
if si6.ip6 != ([16]byte{}) && *dst != si6.ip6 {
if !si6.acceptMulticast || dst[0] != 0xFF {
if !si6.acceptMulticast || !internal.IsMulticastIPAddr(dst[:]) {
si6.handlers.debug("ip6:not-for-us")
return lneto.ErrPacketDrop
}
+9 -1
View File
@@ -45,7 +45,15 @@ func (sudp *StackUDPPort) Demux(carrierData []byte, frameOffset int) error {
if dst != sudp.h.lport {
return lneto.ErrPacketDrop // Not meant for us.
}
// TODO remote ip address handling.
if len(sudp.raddr) > 0 && !internal.IsMulticastIPAddr(sudp.raddr) {
srcIP, _, _, _, err := internal.GetIPAddr(carrierData[:frameOffset])
if err != nil {
return err
}
if !internal.BytesEqual(srcIP, sudp.raddr) {
return lneto.ErrPacketDrop
}
}
src := ufrm.SourcePort()
if sudp.rmport != 0 && src != sudp.rmport {