Skip to content

Commit 8941faa

Browse files
egrumbachdavem330
authored andcommitted
net: tso: add support for IPv6
Adding IPv6 for the TSO helper API is trivial: * Don't play with the id (which doesn't exist in IPv6) * Correctly update the payload_len (don't include the length of the IP header itself) Signed-off-by: Emmanuel Grumbach <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 61b9da9 commit 8941faa

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

include/net/tso.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct tso_t {
88
void *data;
99
size_t size;
1010
u16 ip_id;
11+
bool ipv6;
1112
u32 tcp_seq;
1213
};
1314

net/core/tso.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <linux/export.h>
2+
#include <linux/if_vlan.h>
23
#include <net/ip.h>
34
#include <net/tso.h>
45
#include <asm/unaligned.h>
@@ -14,18 +15,24 @@ EXPORT_SYMBOL(tso_count_descs);
1415
void tso_build_hdr(struct sk_buff *skb, char *hdr, struct tso_t *tso,
1516
int size, bool is_last)
1617
{
17-
struct iphdr *iph;
1818
struct tcphdr *tcph;
1919
int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2020
int mac_hdr_len = skb_network_offset(skb);
2121

2222
memcpy(hdr, skb->data, hdr_len);
23-
iph = (struct iphdr *)(hdr + mac_hdr_len);
24-
iph->id = htons(tso->ip_id);
25-
iph->tot_len = htons(size + hdr_len - mac_hdr_len);
23+
if (!tso->ipv6) {
24+
struct iphdr *iph = (void *)(hdr + mac_hdr_len);
25+
26+
iph->id = htons(tso->ip_id);
27+
iph->tot_len = htons(size + hdr_len - mac_hdr_len);
28+
tso->ip_id++;
29+
} else {
30+
struct ipv6hdr *iph = (void *)(hdr + mac_hdr_len);
31+
32+
iph->payload_len = htons(size + tcp_hdrlen(skb));
33+
}
2634
tcph = (struct tcphdr *)(hdr + skb_transport_offset(skb));
2735
put_unaligned_be32(tso->tcp_seq, &tcph->seq);
28-
tso->ip_id++;
2936

3037
if (!is_last) {
3138
/* Clear all special flags for not last packet */
@@ -61,6 +68,7 @@ void tso_start(struct sk_buff *skb, struct tso_t *tso)
6168
tso->ip_id = ntohs(ip_hdr(skb)->id);
6269
tso->tcp_seq = ntohl(tcp_hdr(skb)->seq);
6370
tso->next_frag_idx = 0;
71+
tso->ipv6 = vlan_get_protocol(skb) == htons(ETH_P_IPV6);
6472

6573
/* Build first data */
6674
tso->size = skb_headlen(skb) - hdr_len;

0 commit comments

Comments
 (0)