]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
af-packet: delay setting default-packet-size for af-packet
authorJason Ish <jason.ish@oisf.net>
Mon, 17 Mar 2025 16:35:57 +0000 (10:35 -0600)
committerVictor Julien <vjulien@oisf.net>
Tue, 18 Mar 2025 10:34:43 +0000 (11:34 +0100)
AF_PACKET needs more information about its configuration before we can
set the default packet size, so on startup, leave unset in suricata.c
if in AF_PACKET mode.

If defrag is enabled, use a default packet size of 9k for tpacket-v2.
This can still lead to truncation events, then the user can increase
their 'default-packet-size'.

Tpacket-v3 does not need an increased packet size as it will handle
any size of packet that is smaller than the configured block size
which now has a default of 128k.

9k for the snap is somewhat arbitrary but is large enough for the
common 9000 jumbo frame plus some extra headers including tpacket
headers.

Ticket: #7458
(cherry picked from commit b8b6ed550a6f10150f5ecf154e7b60c6dc2f84fe)

src/source-af-packet.c
src/source-af-packet.h
src/suricata.c

index f9eb66023b0f86332804e7027468a36abd46b2b4..ee22592b99bcf205cfe790796d0a5ff0cf832e5b 100644 (file)
@@ -1585,10 +1585,16 @@ sockaddr_ll) + ETH_HLEN) - ETH_HLEN);
     int snaplen = default_packet_size;
 
     if (snaplen == 0) {
-        snaplen = GetIfaceMaxPacketSize(ptv->livedev);
-        if (snaplen <= 0) {
-            SCLogWarning("%s: unable to get MTU, setting snaplen default of 1514", ptv->iface);
-            snaplen = 1514;
+        if (ptv->cluster_type & PACKET_FANOUT_FLAG_DEFRAG) {
+            SCLogConfig("%s: defrag enabled, setting snaplen to %d", ptv->iface,
+                    DEFAULT_TPACKET_DEFRAG_SNAPLEN);
+            snaplen = DEFAULT_TPACKET_DEFRAG_SNAPLEN;
+        } else {
+            snaplen = GetIfaceMaxPacketSize(ptv->livedev);
+            if (snaplen <= 0) {
+                SCLogWarning("%s: unable to get MTU, setting snaplen default of 1514", ptv->iface);
+                snaplen = 1514;
+            }
         }
     }
 
@@ -1639,10 +1645,16 @@ sockaddr_ll) + ETH_HLEN) - ETH_HLEN);
     int snaplen = default_packet_size;
 
     if (snaplen == 0) {
-        snaplen = GetIfaceMaxPacketSize(ptv->livedev);
-        if (snaplen <= 0) {
-            SCLogWarning("%s: unable to get MTU, setting snaplen default of 1514", ptv->iface);
-            snaplen = 1514;
+        if (ptv->cluster_type & PACKET_FANOUT_FLAG_DEFRAG) {
+            SCLogConfig("%s: defrag enabled, setting snaplen to %d", ptv->iface,
+                    DEFAULT_TPACKET_DEFRAG_SNAPLEN);
+            snaplen = DEFAULT_TPACKET_DEFRAG_SNAPLEN;
+        } else {
+            snaplen = GetIfaceMaxPacketSize(ptv->livedev);
+            if (snaplen <= 0) {
+                SCLogWarning("%s: unable to get MTU, setting snaplen default of 1514", ptv->iface);
+                snaplen = 1514;
+            }
         }
     }
 
index 84cd52e03fa83b007f51667173eeedc5a23156af..022caaa0a36f523024966a523d2e674b437a1bda 100644 (file)
@@ -80,6 +80,11 @@ struct ebpf_timeout_config {
 /* Set max packet size to 65561: IP + Ethernet + 3 VLAN tags. */
 #define MAX_PACKET_SIZE 65561
 
+/* Default snaplen to use when defrag enabled. 9k is somewhat
+ * arbitrary but is large enough for the common 9000 jumbo frame plus
+ * some extra headers including tpacket headers. */
+#define DEFAULT_TPACKET_DEFRAG_SNAPLEN 9216
+
 typedef struct AFPIfaceConfig_
 {
     char iface[AFP_IFACE_NAME_LENGTH];
index 70b4dfae86938cbcb7cce810ee38d80f791e40da..75c4b6ac49dcb0c647260ef2daeeedff727c2ee2 100644 (file)
@@ -2449,6 +2449,11 @@ static int ConfigGetCaptureValue(SCInstance *suri)
         int nlive;
         int strip_trailing_plus = 0;
         switch (suri->run_mode) {
+            case RUNMODE_AFP_DEV:
+                /* For AF_PACKET we delay setting the
+                 * default-packet-size until we know more about the
+                 * configuration. */
+                break;
 #ifdef WINDIVERT
             case RUNMODE_WINDIVERT: {
                 /* by default, WinDivert collects from all devices */
@@ -2469,7 +2474,6 @@ static int ConfigGetCaptureValue(SCInstance *suri)
                 strip_trailing_plus = 1;
                 /* fall through */
             case RUNMODE_PCAP_DEV:
-            case RUNMODE_AFP_DEV:
             case RUNMODE_AFXDP_DEV:
             case RUNMODE_PFRING:
                 nlive = LiveGetDeviceCount();