fix httptap incorrectly capturing GRO frames

This commit is contained in:
soypat
2025-12-31 17:08:53 -03:00
parent 7369ec0b7e
commit 243d1a720d
4 changed files with 19 additions and 41 deletions
+7 -31
View File
@@ -5,17 +5,16 @@ import (
"flag"
"fmt"
"log"
"math"
"net"
"net/http"
"net/netip"
"strings"
"time"
"github.com/soypat/lneto"
"github.com/soypat/lneto/internal"
"github.com/soypat/lneto/internal/ltesto"
"github.com/soypat/lneto/internet/pcap"
"github.com/soypat/lneto/tcp"
)
func main() {
@@ -30,9 +29,14 @@ func main() {
func run() error {
var (
flagInterface = "tap0"
flagMinMTU = math.MaxUint16
)
flag.StringVar(&flagInterface, "i", flagInterface, "Interface to select. tap* creates a tap interface. Any other name will create a bridge to the name of the interface i.e: 'enp7s0', 'wlp8s0', 'lo'")
flag.IntVar(&flagMinMTU, "mtu", flagMinMTU, "Set the interface minimum MTU to use for buffer.")
flag.Parse()
if flagMinMTU < 1500 {
return errors.New("minimum MTU too small")
}
var (
flagNet = "192.168.10.1/24"
flagiface = "tap0"
@@ -57,7 +61,7 @@ func run() error {
iface = br
}
sv, err := ltesto.NewHTTPTapServer(iface, flagPacketQueueSize, flagPacketQueueSize)
sv, err := ltesto.NewHTTPTapServer(iface, flagMinMTU, flagPacketQueueSize, flagPacketQueueSize)
if err != nil {
return err
}
@@ -91,31 +95,3 @@ func run() error {
http.ListenAndServe(":7070", sv)
return errors.New("finished")
}
func getTCPData(frames []pcap.Frame, pkt []byte) (flags tcp.Flags, src, dst uint16) {
for i := range frames {
proto := frames[i].Protocol
if proto == lneto.IPProtoTCP {
return tcp.Flags(getFrameClassUint(frames[i], pkt, pcap.FieldClassFlags)),
uint16(getFrameClassUint(frames[i], pkt, pcap.FieldClassSrc)),
uint16(getFrameClassUint(frames[i], pkt, pcap.FieldClassDst))
} else if proto == lneto.IPProtoUDP {
return 0,
uint16(getFrameClassUint(frames[i], pkt, pcap.FieldClassSrc)),
uint16(getFrameClassUint(frames[i], pkt, pcap.FieldClassDst))
}
}
return 0, 0, 0
}
func getFrameClassUint(frame pcap.Frame, pkt []byte, class pcap.FieldClass) uint64 {
iflags, err := frame.FieldByClass(class)
if err != nil {
return 0
}
v, err := frame.FieldAsUint(iflags, pkt)
if err != nil {
return 0
}
return v
}