net: Change transport_header_end -> tranport_offset
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 6 Nov 2017 16:44:32 +0000 (11:44 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 16 Nov 2017 15:46:56 +0000 (10:46 -0500)
mlx4 wanted the size of a TCP packet, but other NICs want the start of the
TCP header.  We can go from "header start" -> "header end" easily, but not
the other way.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/drivers/net/mlx4/en_tx.c
kern/include/net/tcp.h
kern/include/ns.h
kern/src/net/tcp.c
kern/src/net/udp.c
kern/src/ns/qio.c

index c66d97c..c9da268 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <linux/mlx4/cq.h>
 #include <linux/mlx4/qp.h>
+#include <net/tcp.h>
 #include "mlx4_en.h"
 
 int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv,
@@ -740,7 +741,7 @@ static size_t get_lso_hdr_size(struct block *block)
 {
        if (!(block->flag & Btso))
                return 0;
-       return block->transport_header_end;
+       return block->transport_offset + tcp_hdrlen(block);
 }
 
 netdev_tx_t mlx4_send_packet(struct block *block, struct mlx4_en_priv *priv,
index 1d56fbb..8675cef 100644 (file)
@@ -404,3 +404,19 @@ static inline uint32_t seq_min(uint32_t x, uint32_t y)
 {
        return seq_le(x, y) ? x : y;
 }
+
+/* Caller needs to know we're TCP and with transport_offset set, which is
+ * usually on the outbound network path. */
+static inline struct tcphdr *tcp_hdr(struct block *bp)
+{
+       return (struct tcphdr*)(bp->rp + bp->transport_offset);
+}
+
+static inline size_t tcp_hdrlen(struct block *bp)
+{
+       struct tcphdr *hdr = tcp_hdr(bp);
+       uint8_t data_offset;
+
+       data_offset = hdr->tcpflag[0] & 0x0f;
+       return data_offset * 4;
+}
index b5ff1dd..d76a332 100644 (file)
@@ -387,7 +387,7 @@ struct block {
        uint16_t checksum_start;                /* off from start of block to start csum */
        uint16_t checksum_offset;               /* off from checksum_start to store csum */
        uint16_t mss;               /* TCP MSS for TSO */
-       uint16_t transport_header_end;  /* off from start to headers end */
+       uint16_t transport_offset;      /* offset from start */
        /* might want something to track the next free extra_data slot */
        size_t extra_len;
        unsigned int nr_extra_bufs;
index 2954840..203b13b 100644 (file)
@@ -776,8 +776,8 @@ static struct block *htontcp6(Tcp *tcph, struct block *data, Tcp6hdr *ph,
        data = alloc_or_pad_block(data, hdrlen + TCP6_PKT);
        if (data == NULL)
                return NULL;
-       /* relative to the block start (bp->rp) */
-       data->transport_header_end = hdrlen + TCP6_PKT;
+       /* relative to the block start (bp->rp).  Note TCP structs include IP. */
+       data->transport_offset = offsetof(Tcp6hdr, tcpsport);
 
        /* copy in pseudo ip header plus port numbers */
        h = (Tcp6hdr *) (data->rp);
@@ -826,8 +826,8 @@ static struct block *htontcp4(Tcp *tcph, struct block *data, Tcp4hdr *ph,
        data = alloc_or_pad_block(data, hdrlen + TCP4_PKT);
        if (data == NULL)
                return NULL;
-       /* relative to the block start (bp->rp) */
-       data->transport_header_end = hdrlen + TCP4_PKT;
+       /* relative to the block start (bp->rp).  Note TCP structs include IP. */
+       data->transport_offset = offsetof(Tcp4hdr, tcpsport);
 
        /* copy in pseudo ip header plus port numbers */
        h = (Tcp4hdr *) (data->rp);
index 8e75267..62105c4 100644 (file)
@@ -331,7 +331,7 @@ void udpkick(void *x, struct block *bp)
                                   ~ptclcsum(bp, UDP4_PHDR_OFF, UDP4_PHDR_SZ));
                        bp->checksum_start = UDP4_IPHDR_SZ;
                        bp->checksum_offset = uh4->udpcksum - uh4->udpsport;
-                       bp->transport_header_end = UDP4_IPHDR_SZ;
+                       bp->transport_offset = offsetof(Udp4hdr, udpsport);
                        bp->flag |= Budpck;
                        uh4->vihl = IP_VER4;
                        ipoput4(f, bp, 0, c->ttl, c->tos, rc);
@@ -370,7 +370,7 @@ void udpkick(void *x, struct block *bp)
                                   ptclcsum(bp, UDP6_PHDR_OFF,
                                                        dlen + UDP_UDPHDR_SZ + UDP6_PHDR_SZ));
                        memset(uh6, 0, 8);
-                       bp->transport_header_end = UDP6_IPHDR_SZ;
+                       bp->transport_offset = offsetof(Udp6hdr, udpsport);
                        uh6->viclfl[0] = IP_VER6;
                        hnputs(uh6->len, ptcllen);
                        uh6->nextheader = IP_UDPPROTO;
index 0814a1b..41105f2 100644 (file)
@@ -135,13 +135,13 @@ struct block *padblock(struct block *bp, int size)
        uint16_t checksum_start = bp->checksum_start;
        uint16_t checksum_offset = bp->checksum_offset;
        uint16_t mss = bp->mss;
-       uint16_t transport_header_end = bp->transport_header_end;
+       uint16_t transport_offset = bp->transport_offset;
 
        QDEBUG checkb(bp, "padblock 1");
        if (size >= 0) {
                if (bp->rp - bp->base >= size) {
                        bp->checksum_start += size;
-                       bp->transport_header_end += size;
+                       bp->transport_offset += size;
                        bp->rp -= size;
                        return bp;
                }
@@ -181,7 +181,7 @@ struct block *padblock(struct block *bp, int size)
                nbp->checksum_start = checksum_start;
                nbp->checksum_offset = checksum_offset;
                nbp->mss = mss;
-               nbp->transport_header_end = transport_header_end;
+               nbp->transport_offset = transport_offset;
        }
        QDEBUG checkb(nbp, "padblock 1");
        return nbp;
@@ -272,7 +272,7 @@ struct block *copyblock(struct block *bp, int mem_flags)
                newb->checksum_start = bp->checksum_start;
                newb->checksum_offset = bp->checksum_offset;
                newb->mss = bp->mss;
-               newb->transport_header_end = bp->transport_header_end;
+               newb->transport_offset = bp->transport_offset;
        }
        copyblockcnt++;
        QDEBUG checkb(newb, "copyblock 1");