diff --git a/collectors/sniffer_afpacket_linux.go b/collectors/sniffer_afpacket_linux.go index 14976e47..3ba278a2 100644 --- a/collectors/sniffer_afpacket_linux.go +++ b/collectors/sniffer_afpacket_linux.go @@ -200,7 +200,7 @@ func (c *AfpacketSniffer) Run() { if packet.NetworkLayer().LayerType() == layers.LayerTypeIPv4 { ip4 := packet.NetworkLayer().(*layers.IPv4) if ip4.Flags&layers.IPv4MoreFragments == 1 || ip4.FragOffset > 0 { - fragIP4Chan <- packet + // fragIP4Chan <- packet continue } } @@ -209,7 +209,7 @@ func (c *AfpacketSniffer) Run() { if packet.NetworkLayer().LayerType() == layers.LayerTypeIPv6 { v6frag := packet.Layer(layers.LayerTypeIPv6Fragment) if v6frag != nil { - fragIP6Chan <- packet + // fragIP6Chan <- packet continue } } diff --git a/netutils/ipdefrag_test.go b/netutils/ipdefrag_test.go new file mode 100644 index 00000000..665574c0 --- /dev/null +++ b/netutils/ipdefrag_test.go @@ -0,0 +1,40 @@ +package netutils + +// TODO +/* +func createIPv6FragmentPacketWithNilLayer() gopacket.Packet { + // IPv6 layer + ipLayer := &layers.IPv6{ + Version: 6, + NextHeader: layers.IPProtocolIPv6Fragment, // Next header is Fragmentation Header + HopLimit: 64, + SrcIP: net.ParseIP("2001:db8::1"), + DstIP: net.ParseIP("2001:db8::2"), + } + + // Create a packet with nil IPv6Fragment layer + builder := gopacket.NewSerializeBuffer() + ipLayer.SerializeTo(builder, gopacket.SerializeOptions{}) + // Set the IPv6 layer manually + packet := gopacket.NewPacket(builder.Bytes(), layers.LayerTypeIPv6, gopacket.Default) + // Remove IPv6Fragment layer + packet.Layer(layers.LayerTypeIPv6Fragment).(*layers.IPv6Fragment).Payload = nil + + return packet +} + + +func TestIpDefrag_WithNilIPv6Fragment(t *testing.T) { + defragger := NewIPDefragmenter() + + // Create an IPv6 packet with nil IPv6Fragment layer + packet := createIPv6FragmentPacketWithNilLayer() + + + // This packet has a nil IPv6Fragment layer, which should trigger an error + _, err := defragger.DefragIP(packet) + if err == nil { + t.Errorf("Expected error, got nil") + } +} +*/