]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/net: gro: add self-test for TCP CWR flag
authorChia-Yu Chang <chia-yu.chang@nokia-bell-labs.com>
Sat, 31 Jan 2026 22:25:03 +0000 (23:25 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 3 Feb 2026 14:13:24 +0000 (15:13 +0100)
Currently, GRO does not flush packets when the CWR bit is set.
A corresponding self-test is being added, in which the CWR flag
is set for two consecutive packets, but the first packet with the
CWR flag set will not be flushed immediately.

+===================+==========+===============+===========+
|     Packet id     | CWR flag |    Payload    | Flushing? |
+===================+==========+===============+===========+
|         0         |     0    |  PAYLOAD_LEN  |     0     |
|        ...        |     0    |  PAYLOAD_LEN  |     1     |
+-------------------+----------+---------------+-----------+
| NUM_PACKETS/2 - 1 |     1    |  payload_len  |     0     |
|   NUM_PACKETS/2   |     1    |  payload_len  |     1     |
+-------------------+----------+---------------+-----------+
|        ...        |     0    |  PAYLOAD_LEN  |     0     |
|   NUM_PACKETS     |     0    |  PAYLOAD_LEN  |     1     |
+===================+==========+===============+===========+

Signed-off-by: Chia-Yu Chang <chia-yu.chang@nokia-bell-labs.com>
Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260131222515.8485-4-chia-yu.chang@nokia-bell-labs.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
tools/testing/selftests/drivers/net/gro.c
tools/testing/selftests/drivers/net/gro.py

index e76c618704cf87abe479e725e76015a9abbc5f93..3c0745b68bfaa26631130b338dfa6bef52ab3342 100644 (file)
@@ -17,8 +17,8 @@
  *  Pure ACK does not coalesce.
  *
  * flags_*:
- *  No packets with PSH, SYN, URG, RST set will be coalesced.
- *   - flags_psh, flags_syn, flags_rst, flags_urg
+ *  No packets with PSH, SYN, URG, RST, CWR set will be coalesced.
+ *   - flags_psh, flags_syn, flags_rst, flags_urg, flags_cwr
  *
  * tcp_*:
  *  Packets with incorrect checksum, non-consecutive seqno and
@@ -360,32 +360,58 @@ static void create_packet(void *buf, int seq_offset, int ack_offset,
        fill_datalinklayer(buf);
 }
 
-/* send one extra flag, not first and not last pkt */
-static void send_flags(int fd, struct sockaddr_ll *daddr, int psh, int syn,
-                      int rst, int urg)
+#ifndef TH_CWR
+#define TH_CWR 0x80
+#endif
+static void set_flags(struct tcphdr *tcph, int payload_len, int psh, int syn,
+                     int rst, int urg, int cwr)
 {
-       static char flag_buf[MAX_HDR_LEN + PAYLOAD_LEN];
-       static char buf[MAX_HDR_LEN + PAYLOAD_LEN];
-       int payload_len, pkt_size, flag, i;
-       struct tcphdr *tcph;
-
-       payload_len = PAYLOAD_LEN * psh;
-       pkt_size = total_hdr_len + payload_len;
-       flag = NUM_PACKETS / 2;
-
-       create_packet(flag_buf, flag * payload_len, 0, payload_len, 0);
-
-       tcph = (struct tcphdr *)(flag_buf + tcp_offset);
        tcph->psh = psh;
        tcph->syn = syn;
        tcph->rst = rst;
        tcph->urg = urg;
+       if (cwr)
+               tcph->th_flags |= TH_CWR;
+       else
+               tcph->th_flags &= ~TH_CWR;
        tcph->check = 0;
        tcph->check = tcp_checksum(tcph, payload_len);
+}
+
+/* send extra flags of the (NUM_PACKETS / 2) and (NUM_PACKETS / 2 - 1)
+ * pkts, not first and not last pkt
+ */
+static void send_flags(int fd, struct sockaddr_ll *daddr, int psh, int syn,
+                      int rst, int urg, int cwr)
+{
+       static char flag_buf[2][MAX_HDR_LEN + PAYLOAD_LEN];
+       static char buf[MAX_HDR_LEN + PAYLOAD_LEN];
+       int payload_len, pkt_size, i;
+       struct tcphdr *tcph;
+       int flag[2];
+
+       payload_len = PAYLOAD_LEN * (psh || cwr);
+       pkt_size = total_hdr_len + payload_len;
+       flag[0] = NUM_PACKETS / 2;
+       flag[1] = NUM_PACKETS / 2 - 1;
+
+       /* Create and configure packets with flags
+        */
+       for (i = 0; i < 2; i++) {
+               if (flag[i] > 0) {
+                       create_packet(flag_buf[i], flag[i] * payload_len, 0,
+                                     payload_len, 0);
+                       tcph = (struct tcphdr *)(flag_buf[i] + tcp_offset);
+                       set_flags(tcph, payload_len, psh, syn, rst, urg, cwr);
+               }
+       }
 
        for (i = 0; i < NUM_PACKETS + 1; i++) {
-               if (i == flag) {
-                       write_packet(fd, flag_buf, pkt_size, daddr);
+               if (i == flag[0]) {
+                       write_packet(fd, flag_buf[0], pkt_size, daddr);
+                       continue;
+               } else if (i == flag[1] && cwr) {
+                       write_packet(fd, flag_buf[1], pkt_size, daddr);
                        continue;
                }
                create_packet(buf, i * PAYLOAD_LEN, 0, PAYLOAD_LEN, 0);
@@ -1068,16 +1094,19 @@ static void gro_sender(void)
 
        /* flags sub-tests */
        } else if (strcmp(testname, "flags_psh") == 0) {
-               send_flags(txfd, &daddr, 1, 0, 0, 0);
+               send_flags(txfd, &daddr, 1, 0, 0, 0, 0);
                write_packet(txfd, fin_pkt, total_hdr_len, &daddr);
        } else if (strcmp(testname, "flags_syn") == 0) {
-               send_flags(txfd, &daddr, 0, 1, 0, 0);
+               send_flags(txfd, &daddr, 0, 1, 0, 0, 0);
                write_packet(txfd, fin_pkt, total_hdr_len, &daddr);
        } else if (strcmp(testname, "flags_rst") == 0) {
-               send_flags(txfd, &daddr, 0, 0, 1, 0);
+               send_flags(txfd, &daddr, 0, 0, 1, 0, 0);
                write_packet(txfd, fin_pkt, total_hdr_len, &daddr);
        } else if (strcmp(testname, "flags_urg") == 0) {
-               send_flags(txfd, &daddr, 0, 0, 0, 1);
+               send_flags(txfd, &daddr, 0, 0, 0, 1, 0);
+               write_packet(txfd, fin_pkt, total_hdr_len, &daddr);
+       } else if (strcmp(testname, "flags_cwr") == 0) {
+               send_flags(txfd, &daddr, 0, 0, 0, 0, 1);
                write_packet(txfd, fin_pkt, total_hdr_len, &daddr);
 
        /* tcp sub-tests */
@@ -1239,6 +1268,12 @@ static void gro_receiver(void)
                correct_payload[2] = PAYLOAD_LEN * 2;
                printf("urg flag ends coalescing: ");
                check_recv_pkts(rxfd, correct_payload, 3);
+       } else if (strcmp(testname, "flags_cwr") == 0) {
+               correct_payload[0] = PAYLOAD_LEN;
+               correct_payload[1] = PAYLOAD_LEN * 2;
+               correct_payload[2] = PAYLOAD_LEN * 2;
+               printf("cwr flag ends coalescing: ");
+               check_recv_pkts(rxfd, correct_payload, 3);
 
        /* tcp sub-tests */
        } else if (strcmp(testname, "tcp_csum") == 0) {
index 1bb8af571456e694d2093ffa27e7cd3f403a7714..cbc1b19dbc9108d439febfcbcb3dc6ed0eee172e 100755 (executable)
@@ -17,6 +17,7 @@ Test cases:
   - flags_syn: Packets with SYN flag don't coalesce
   - flags_rst: Packets with RST flag don't coalesce
   - flags_urg: Packets with URG flag don't coalesce
+  - flags_cwr: Packets with CWR flag don't coalesce
   - tcp_csum: Packets with incorrect checksum don't coalesce
   - tcp_seq: Packets with non-consecutive seqno don't coalesce
   - tcp_ts: Packets with different timestamp options don't coalesce
@@ -191,7 +192,7 @@ def _gro_variants():
     common_tests = [
         "data_same", "data_lrg_sml", "data_sml_lrg",
         "ack",
-        "flags_psh", "flags_syn", "flags_rst", "flags_urg",
+        "flags_psh", "flags_syn", "flags_rst", "flags_urg", "flags_cwr",
         "tcp_csum", "tcp_seq", "tcp_ts", "tcp_opt",
         "ip_ecn", "ip_tos",
         "large_max", "large_rem",