Linux Audio

Check our new training course

Loading...
v4.17
 
 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 struct sk_buff **tcp6_gro_receive(struct sk_buff **head,
19					 struct sk_buff *skb)
20{
21	/* Don't bother verifying checksum if we're going to flush anyway. */
22	if (!NAPI_GRO_CB(skb)->flush &&
23	    skb_gro_checksum_validate(skb, IPPROTO_TCP,
24				      ip6_gro_compute_pseudo)) {
25		NAPI_GRO_CB(skb)->flush = 1;
26		return NULL;
27	}
28
29	return tcp_gro_receive(head, skb);
30}
31
32static int tcp6_gro_complete(struct sk_buff *skb, int thoff)
33{
34	const struct ipv6hdr *iph = ipv6_hdr(skb);
35	struct tcphdr *th = tcp_hdr(skb);
36
37	th->check = ~tcp_v6_check(skb->len - thoff, &iph->saddr,
38				  &iph->daddr, 0);
39	skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6;
40
41	return tcp_gro_complete(skb);
 
42}
43
44static struct sk_buff *tcp6_gso_segment(struct sk_buff *skb,
45					netdev_features_t features)
46{
47	struct tcphdr *th;
48
49	if (!(skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6))
50		return ERR_PTR(-EINVAL);
51
52	if (!pskb_may_pull(skb, sizeof(*th)))
53		return ERR_PTR(-EINVAL);
54
55	if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
56		const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
57		struct tcphdr *th = tcp_hdr(skb);
58
59		/* Set up pseudo header, usually expect stack to have done
60		 * this.
61		 */
62
63		th->check = 0;
64		skb->ip_summed = CHECKSUM_PARTIAL;
65		__tcp_v6_send_check(skb, &ipv6h->saddr, &ipv6h->daddr);
66	}
67
68	return tcp_gso_segment(skb, features);
69}
70static const struct net_offload tcpv6_offload = {
71	.callbacks = {
72		.gso_segment	=	tcp6_gso_segment,
73		.gro_receive	=	tcp6_gro_receive,
74		.gro_complete	=	tcp6_gro_complete,
75	},
76};
77
78int __init tcpv6_offload_init(void)
79{
80	return inet6_add_offload(&tcpv6_offload, IPPROTO_TCP);
 
 
 
 
 
 
 
81}
v6.9.4
 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	tcp_gro_complete(skb);
40	return 0;
41}
42
43static struct sk_buff *tcp6_gso_segment(struct sk_buff *skb,
44					netdev_features_t features)
45{
46	struct tcphdr *th;
47
48	if (!(skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6))
49		return ERR_PTR(-EINVAL);
50
51	if (!pskb_may_pull(skb, sizeof(*th)))
52		return ERR_PTR(-EINVAL);
53
54	if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
55		const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
56		struct tcphdr *th = tcp_hdr(skb);
57
58		/* Set up pseudo header, usually expect stack to have done
59		 * this.
60		 */
61
62		th->check = 0;
63		skb->ip_summed = CHECKSUM_PARTIAL;
64		__tcp_v6_send_check(skb, &ipv6h->saddr, &ipv6h->daddr);
65	}
66
67	return tcp_gso_segment(skb, features);
68}
 
 
 
 
 
 
 
69
70int __init tcpv6_offload_init(void)
71{
72	net_hotdata.tcpv6_offload = (struct net_offload) {
73		.callbacks = {
74			.gso_segment	=	tcp6_gso_segment,
75			.gro_receive	=	tcp6_gro_receive,
76			.gro_complete	=	tcp6_gro_complete,
77		},
78	};
79	return inet6_add_offload(&net_hotdata.tcpv6_offload, IPPROTO_TCP);
80}