~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ipv6/udp_offload.c

Version: ~ [ linux-5.4-rc1 ] ~ [ linux-5.3.2 ] ~ [ linux-5.2.18 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.76 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.146 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.194 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.194 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.74 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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  *      UDPv6 GSO support
 11  */
 12 #include <linux/skbuff.h>
 13 #include <linux/netdevice.h>
 14 #include <net/protocol.h>
 15 #include <net/ipv6.h>
 16 #include <net/udp.h>
 17 #include <net/ip6_checksum.h>
 18 #include "ip6_offload.h"
 19 
 20 static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb,
 21                                          netdev_features_t features)
 22 {
 23         struct sk_buff *segs = ERR_PTR(-EINVAL);
 24         unsigned int mss;
 25         unsigned int unfrag_ip6hlen, unfrag_len;
 26         struct frag_hdr *fptr;
 27         u8 *packet_start, *prevhdr;
 28         u8 nexthdr;
 29         u8 frag_hdr_sz = sizeof(struct frag_hdr);
 30         __wsum csum;
 31         int tnl_hlen;
 32         int err;
 33 
 34         mss = skb_shinfo(skb)->gso_size;
 35         if (unlikely(skb->len <= mss))
 36                 goto out;
 37 
 38         if (skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST)) {
 39                 /* Packet is from an untrusted source, reset gso_segs. */
 40                 int type = skb_shinfo(skb)->gso_type;
 41 
 42                 if (unlikely(type & ~(SKB_GSO_UDP |
 43                                       SKB_GSO_DODGY |
 44                                       SKB_GSO_UDP_TUNNEL |
 45                                       SKB_GSO_UDP_TUNNEL_CSUM |
 46                                       SKB_GSO_GRE |
 47                                       SKB_GSO_GRE_CSUM |
 48                                       SKB_GSO_IPIP |
 49                                       SKB_GSO_SIT |
 50                                       SKB_GSO_MPLS) ||
 51                              !(type & (SKB_GSO_UDP))))
 52                         goto out;
 53 
 54                 skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len, mss);
 55 
 56                 segs = NULL;
 57                 goto out;
 58         }
 59 
 60         if (skb->encapsulation && skb_shinfo(skb)->gso_type &
 61             (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM))
 62                 segs = skb_udp_tunnel_segment(skb, features, true);
 63         else {
 64                 const struct ipv6hdr *ipv6h;
 65                 struct udphdr *uh;
 66 
 67                 if (!pskb_may_pull(skb, sizeof(struct udphdr)))
 68                         goto out;
 69 
 70                 /* Do software UFO. Complete and fill in the UDP checksum as HW cannot
 71                  * do checksum of UDP packets sent as multiple IP fragments.
 72                  */
 73 
 74                 uh = udp_hdr(skb);
 75                 ipv6h = ipv6_hdr(skb);
 76 
 77                 uh->check = 0;
 78                 csum = skb_checksum(skb, 0, skb->len, 0);
 79                 uh->check = udp_v6_check(skb->len, &ipv6h->saddr,
 80                                           &ipv6h->daddr, csum);
 81 
 82                 if (uh->check == 0)
 83                         uh->check = CSUM_MANGLED_0;
 84 
 85                 skb->ip_summed = CHECKSUM_UNNECESSARY;
 86 
 87                 /* Check if there is enough headroom to insert fragment header. */
 88                 tnl_hlen = skb_tnl_header_len(skb);
 89                 if (skb->mac_header < (tnl_hlen + frag_hdr_sz)) {
 90                         if (gso_pskb_expand_head(skb, tnl_hlen + frag_hdr_sz))
 91                                 goto out;
 92                 }
 93 
 94                 /* Find the unfragmentable header and shift it left by frag_hdr_sz
 95                  * bytes to insert fragment header.
 96                  */
 97                 err = ip6_find_1stfragopt(skb, &prevhdr);
 98                 if (err < 0)
 99                         return ERR_PTR(err);
100                 unfrag_ip6hlen = err;
101                 nexthdr = *prevhdr;
102                 *prevhdr = NEXTHDR_FRAGMENT;
103                 unfrag_len = (skb_network_header(skb) - skb_mac_header(skb)) +
104                              unfrag_ip6hlen + tnl_hlen;
105                 packet_start = (u8 *) skb->head + SKB_GSO_CB(skb)->mac_offset;
106                 memmove(packet_start-frag_hdr_sz, packet_start, unfrag_len);
107 
108                 SKB_GSO_CB(skb)->mac_offset -= frag_hdr_sz;
109                 skb->mac_header -= frag_hdr_sz;
110                 skb->network_header -= frag_hdr_sz;
111 
112                 fptr = (struct frag_hdr *)(skb_network_header(skb) + unfrag_ip6hlen);
113                 fptr->nexthdr = nexthdr;
114                 fptr->reserved = 0;
115                 fptr->identification = skb_shinfo(skb)->ip6_frag_id;
116 
117                 /* Fragment the skb. ipv6 header and the remaining fields of the
118                  * fragment header are updated in ipv6_gso_segment()
119                  */
120                 segs = skb_segment(skb, features);
121         }
122 
123 out:
124         return segs;
125 }
126 
127 static struct sk_buff **udp6_gro_receive(struct sk_buff **head,
128                                          struct sk_buff *skb)
129 {
130         struct udphdr *uh = udp_gro_udphdr(skb);
131 
132         if (unlikely(!uh))
133                 goto flush;
134 
135         /* Don't bother verifying checksum if we're going to flush anyway. */
136         if (NAPI_GRO_CB(skb)->flush)
137                 goto skip;
138 
139         if (skb_gro_checksum_validate_zero_check(skb, IPPROTO_UDP, uh->check,
140                                                  ip6_gro_compute_pseudo))
141                 goto flush;
142         else if (uh->check)
143                 skb_gro_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
144                                              ip6_gro_compute_pseudo);
145 
146 skip:
147         NAPI_GRO_CB(skb)->is_ipv6 = 1;
148         return udp_gro_receive(head, skb, uh);
149 
150 flush:
151         NAPI_GRO_CB(skb)->flush = 1;
152         return NULL;
153 }
154 
155 static int udp6_gro_complete(struct sk_buff *skb, int nhoff)
156 {
157         const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
158         struct udphdr *uh = (struct udphdr *)(skb->data + nhoff);
159 
160         if (uh->check)
161                 uh->check = ~udp_v6_check(skb->len - nhoff, &ipv6h->saddr,
162                                           &ipv6h->daddr, 0);
163 
164         return udp_gro_complete(skb, nhoff);
165 }
166 
167 static const struct net_offload udpv6_offload = {
168         .callbacks = {
169                 .gso_segment    =       udp6_ufo_fragment,
170                 .gro_receive    =       udp6_gro_receive,
171                 .gro_complete   =       udp6_gro_complete,
172         },
173 };
174 
175 int __init udp_offload_init(void)
176 {
177         return inet6_add_offload(&udpv6_offload, IPPROTO_UDP);
178 }
179 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp