Hi,

This diff introduces new counters for LRO packets, we get from the
network interface.  It shows, how many packets the network interface has
coalesced into LRO packets.

In followup diff, this packet counter will also be used to set the
ph_mss variable to valid value.  So, the stack is able to forward or
redirect this kind of packets.

ok?

bye,
Jan

Index: usr.bin/netstat/inet.c
===================================================================
RCS file: /cvs/src/usr.bin/netstat/inet.c,v
retrieving revision 1.175
diff -u -p -r1.175 inet.c
--- usr.bin/netstat/inet.c      10 May 2023 12:07:17 -0000      1.175
+++ usr.bin/netstat/inet.c      16 May 2023 17:55:20 -0000
@@ -412,6 +412,10 @@ tcp_stats(char *name)
        p(tcps_outhwtso, "\t\t%u output TSO packet%s hardware processed\n");
        p(tcps_outpkttso, "\t\t%u output TSO packet%s generated\n");
        p(tcps_outbadtso, "\t\t%u output TSO packet%s dropped\n");
+       p(tcps_inhwlro, "\t\t%u input LRO generated packet%s from hardware\n");
+       p(tcps_inpktlro, "\t\t%u input LRO coalesced packet%s from hardware\n");
+       p(tcps_inbadlro, "\t\t%u input bad LRO packet%s from hardware\n");
+
        p(tcps_rcvtotal, "\t%u packet%s received\n");
        p2(tcps_rcvackpack, tcps_rcvackbyte, "\t\t%u ack%s (for %llu 
byte%s)\n");
        p(tcps_rcvdupack, "\t\t%u duplicate ack%s\n");
Index: sys/dev/pci/if_ix.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_ix.c,v
retrieving revision 1.194
diff -u -p -r1.194 if_ix.c
--- sys/dev/pci/if_ix.c 16 May 2023 14:32:54 -0000      1.194
+++ sys/dev/pci/if_ix.c 16 May 2023 18:49:33 -0000
@@ -3175,12 +3175,23 @@ ixgbe_rxeof(struct rx_ring *rxr)
                sendmp = rxbuf->fmp;
                rxbuf->buf = rxbuf->fmp = NULL;
 
-               if (sendmp != NULL) /* secondary frag */
+               if (sendmp != NULL) { /* secondary frag */
                        sendmp->m_pkthdr.len += mp->m_len;
-               else {
+
+                       /*
+                        * This function iterates over interleaved descriptors.
+                        * Thus, we reuse ph_mss as global segment counter per
+                        * TCP connection, insteat of introducing a new variable
+                        * in m_pkthdr.
+                        */
+                       if (rsccnt)
+                               sendmp->m_pkthdr.ph_mss += rsccnt - 1;
+               } else {
                        /* first desc of a non-ps chain */
                        sendmp = mp;
                        sendmp->m_pkthdr.len = mp->m_len;
+                       if (rsccnt)
+                               sendmp->m_pkthdr.ph_mss = rsccnt - 1;
 #if NVLAN > 0
                        if (sc->vlan_stripping && staterr & IXGBE_RXD_STAT_VP) {
                                sendmp->m_pkthdr.ether_vtag = vtag;
@@ -3200,6 +3211,21 @@ ixgbe_rxeof(struct rx_ring *rxr)
                        if (hashtype != IXGBE_RXDADV_RSSTYPE_NONE) {
                                sendmp->m_pkthdr.ph_flowid = hash;
                                SET(sendmp->m_pkthdr.csum_flags, M_FLOWID);
+                       }
+
+                       if (sendmp->m_pkthdr.ph_mss == 1)
+                               sendmp->m_pkthdr.ph_mss = 0;
+
+                       if (sendmp->m_pkthdr.ph_mss > 0) {
+                               struct ether_extracted ext;
+                               uint16_t pkts = sendmp->m_pkthdr.ph_mss;
+
+                               ether_extract_headers(sendmp, &ext);
+                               if (ext.tcp)
+                                       tcpstat_inc(tcps_inhwlro);
+                               else
+                                       tcpstat_inc(tcps_inbadlro);
+                               tcpstat_add(tcps_inpktlro, pkts);
                        }
 
                        ml_enqueue(&ml, sendmp);
Index: sys/dev/pci/ixgbe.h
===================================================================
RCS file: /cvs/src/sys/dev/pci/ixgbe.h,v
retrieving revision 1.33
diff -u -p -r1.33 ixgbe.h
--- sys/dev/pci/ixgbe.h 8 Feb 2022 03:38:00 -0000       1.33
+++ sys/dev/pci/ixgbe.h 16 May 2023 17:55:20 -0000
@@ -60,12 +60,18 @@
 
 #include <net/if.h>
 #include <net/if_media.h>
+#include <net/route.h>
 #include <net/toeplitz.h>
 
+struct tdb;
+
 #include <netinet/in.h>
 #include <netinet/if_ether.h>
 #include <netinet/ip.h>
 #include <netinet/ip6.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
 
 #if NBPFILTER > 0
 #include <net/bpf.h>
Index: sys/netinet/tcp_usrreq.c
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v
retrieving revision 1.218
diff -u -p -r1.218 tcp_usrreq.c
--- sys/netinet/tcp_usrreq.c    10 May 2023 12:07:16 -0000      1.218
+++ sys/netinet/tcp_usrreq.c    16 May 2023 17:55:20 -0000
@@ -1340,6 +1340,9 @@ tcp_sysctl_tcpstat(void *oldp, size_t *o
        ASSIGN(tcps_outhwtso);
        ASSIGN(tcps_outpkttso);
        ASSIGN(tcps_outbadtso);
+       ASSIGN(tcps_inhwlro);
+       ASSIGN(tcps_inpktlro);
+       ASSIGN(tcps_inbadlro);
 
 #undef ASSIGN
 
Index: sys/netinet/tcp_var.h
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_var.h,v
retrieving revision 1.165
diff -u -p -r1.165 tcp_var.h
--- sys/netinet/tcp_var.h       15 May 2023 16:34:56 -0000      1.165
+++ sys/netinet/tcp_var.h       16 May 2023 17:55:20 -0000
@@ -447,6 +447,9 @@ struct      tcpstat {
        u_int32_t tcps_outhwtso;        /* output tso processed by hardware */
        u_int32_t tcps_outpkttso;       /* packets generated by tso */
        u_int32_t tcps_outbadtso;       /* output tso failed, packet dropped */
+       u_int32_t tcps_inhwlro;         /* input lro from hardware */
+       u_int32_t tcps_inpktlro;        /* packets coalessed by hardware lro */
+       u_int32_t tcps_inbadlro;        /* input bad lro packets from hardware 
*/
 };
 
 /*
@@ -625,6 +628,9 @@ enum tcpstat_counters {
        tcps_outhwtso,
        tcps_outpkttso,
        tcps_outbadtso,
+       tcps_inhwlro,
+       tcps_inpktlro,
+       tcps_inbadlro,
        tcps_ncounters,
 };
 

Reply via email to