Linux Audio

Check our new training course

Loading...
v3.15
 
 1/*
 2 *	IPV6 GSO/GRO offload support
 3 *	Linux INET6 implementation
 4 *
 5 *	This program is free software; you can redistribute it and/or
 6 *      modify it under the terms of the GNU General Public License
 7 *      as published by the Free Software Foundation; either version
 8 *      2 of the License, or (at your option) any later version.
 9 *
10 *      TCPv6 GSO/GRO support
11 */
 
12#include <linux/skbuff.h>
 
13#include <net/protocol.h>
14#include <net/tcp.h>
15#include <net/ip6_checksum.h>
16#include "ip6_offload.h"
17
18static int tcp_v6_gso_send_check(struct sk_buff *skb)
 
19{
20	const struct ipv6hdr *ipv6h;
21	struct tcphdr *th;
22
23	if (!pskb_may_pull(skb, sizeof(*th)))
24		return -EINVAL;
25
26	ipv6h = ipv6_hdr(skb);
27	th = tcp_hdr(skb);
28
29	th->check = 0;
30	skb->ip_summed = CHECKSUM_PARTIAL;
31	__tcp_v6_send_check(skb, &ipv6h->saddr, &ipv6h->daddr);
32	return 0;
33}
34
35static struct sk_buff **tcp6_gro_receive(struct sk_buff **head,
36					 struct sk_buff *skb)
37{
38	const struct ipv6hdr *iph = skb_gro_network_header(skb);
39	__wsum wsum;
40
41	/* Don't bother verifying checksum if we're going to flush anyway. */
42	if (NAPI_GRO_CB(skb)->flush)
43		goto skip_csum;
44
45	wsum = NAPI_GRO_CB(skb)->csum;
46
47	switch (skb->ip_summed) {
48	case CHECKSUM_NONE:
49		wsum = skb_checksum(skb, skb_gro_offset(skb), skb_gro_len(skb),
50				    wsum);
51
52		/* fall through */
53
54	case CHECKSUM_COMPLETE:
55		if (!tcp_v6_check(skb_gro_len(skb), &iph->saddr, &iph->daddr,
56				  wsum)) {
57			skb->ip_summed = CHECKSUM_UNNECESSARY;
58			break;
59		}
60
61		NAPI_GRO_CB(skb)->flush = 1;
62		return NULL;
63	}
64
65skip_csum:
66	return tcp_gro_receive(head, skb);
67}
68
69static int tcp6_gro_complete(struct sk_buff *skb, int thoff)
70{
71	const struct ipv6hdr *iph = ipv6_hdr(skb);
72	struct tcphdr *th = tcp_hdr(skb);
73
74	th->check = ~tcp_v6_check(skb->len - thoff, &iph->saddr,
75				  &iph->daddr, 0);
76	skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
77
78	return tcp_gro_complete(skb);
79}
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81static const struct net_offload tcpv6_offload = {
82	.callbacks = {
83		.gso_send_check	=	tcp_v6_gso_send_check,
84		.gso_segment	=	tcp_gso_segment,
85		.gro_receive	=	tcp6_gro_receive,
86		.gro_complete	=	tcp6_gro_complete,
87	},
88};
89
90int __init tcpv6_offload_init(void)
91{
92	return inet6_add_offload(&tcpv6_offload, IPPROTO_TCP);
93}
v6.2
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 *	IPV6 GSO/GRO offload support
 4 *	Linux INET6 implementation
 5 *
 
 
 
 
 
 6 *      TCPv6 GSO/GRO support
 7 */
 8#include <linux/indirect_call_wrapper.h>
 9#include <linux/skbuff.h>
10#include <net/gro.h>
11#include <net/protocol.h>
12#include <net/tcp.h>
13#include <net/ip6_checksum.h>
14#include "ip6_offload.h"
15
16INDIRECT_CALLABLE_SCOPE
17struct sk_buff *tcp6_gro_receive(struct list_head *head, struct sk_buff *skb)
18{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19	/* Don't bother verifying checksum if we're going to flush anyway. */
20	if (!NAPI_GRO_CB(skb)->flush &&
21	    skb_gro_checksum_validate(skb, IPPROTO_TCP,
22				      ip6_gro_compute_pseudo)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23		NAPI_GRO_CB(skb)->flush = 1;
24		return NULL;
25	}
26
 
27	return tcp_gro_receive(head, skb);
28}
29
30INDIRECT_CALLABLE_SCOPE int tcp6_gro_complete(struct sk_buff *skb, int thoff)
31{
32	const struct ipv6hdr *iph = ipv6_hdr(skb);
33	struct tcphdr *th = tcp_hdr(skb);
34
35	th->check = ~tcp_v6_check(skb->len - thoff, &iph->saddr,
36				  &iph->daddr, 0);
37	skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6;
38
39	return tcp_gro_complete(skb);
40}
41
42static struct sk_buff *tcp6_gso_segment(struct sk_buff *skb,
43					netdev_features_t features)
44{
45	struct tcphdr *th;
46
47	if (!(skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6))
48		return ERR_PTR(-EINVAL);
49
50	if (!pskb_may_pull(skb, sizeof(*th)))
51		return ERR_PTR(-EINVAL);
52
53	if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
54		const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
55		struct tcphdr *th = tcp_hdr(skb);
56
57		/* Set up pseudo header, usually expect stack to have done
58		 * this.
59		 */
60
61		th->check = 0;
62		skb->ip_summed = CHECKSUM_PARTIAL;
63		__tcp_v6_send_check(skb, &ipv6h->saddr, &ipv6h->daddr);
64	}
65
66	return tcp_gso_segment(skb, features);
67}
68static const struct net_offload tcpv6_offload = {
69	.callbacks = {
70		.gso_segment	=	tcp6_gso_segment,
 
71		.gro_receive	=	tcp6_gro_receive,
72		.gro_complete	=	tcp6_gro_complete,
73	},
74};
75
76int __init tcpv6_offload_init(void)
77{
78	return inet6_add_offload(&tcpv6_offload, IPPROTO_TCP);
79}