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

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

Version: ~ [ linux-5.3-rc5 ] ~ [ linux-5.2.9 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.67 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.139 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.189 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.189 ] ~ [ 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.72 ] ~ [ 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  *      IPV4 GSO/GRO offload support
  3  *      Linux INET 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  *      UDPv4 GSO support
 11  */
 12 
 13 #include <linux/skbuff.h>
 14 #include <net/udp.h>
 15 #include <net/protocol.h>
 16 
 17 static int udp4_ufo_send_check(struct sk_buff *skb)
 18 {
 19         if (!pskb_may_pull(skb, sizeof(struct udphdr)))
 20                 return -EINVAL;
 21 
 22         if (likely(!skb->encapsulation)) {
 23                 const struct iphdr *iph;
 24                 struct udphdr *uh;
 25 
 26                 iph = ip_hdr(skb);
 27                 uh = udp_hdr(skb);
 28 
 29                 uh->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, skb->len,
 30                                 IPPROTO_UDP, 0);
 31                 skb->csum_start = skb_transport_header(skb) - skb->head;
 32                 skb->csum_offset = offsetof(struct udphdr, check);
 33                 skb->ip_summed = CHECKSUM_PARTIAL;
 34         }
 35 
 36         return 0;
 37 }
 38 
 39 static struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb,
 40                                          netdev_features_t features)
 41 {
 42         struct sk_buff *segs = ERR_PTR(-EINVAL);
 43         unsigned int mss;
 44 
 45         mss = skb_shinfo(skb)->gso_size;
 46         if (unlikely(skb->len <= mss))
 47                 goto out;
 48 
 49         if (skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST)) {
 50                 /* Packet is from an untrusted source, reset gso_segs. */
 51                 int type = skb_shinfo(skb)->gso_type;
 52 
 53                 if (unlikely(type & ~(SKB_GSO_UDP | SKB_GSO_DODGY |
 54                                       SKB_GSO_UDP_TUNNEL |
 55                                       SKB_GSO_GRE | SKB_GSO_MPLS) ||
 56                              !(type & (SKB_GSO_UDP))))
 57                         goto out;
 58 
 59                 skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len, mss);
 60 
 61                 segs = NULL;
 62                 goto out;
 63         }
 64 
 65         /* Fragment the skb. IP headers of the fragments are updated in
 66          * inet_gso_segment()
 67          */
 68         if (skb->encapsulation && skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL)
 69                 segs = skb_udp_tunnel_segment(skb, features);
 70         else {
 71                 int offset;
 72                 __wsum csum;
 73 
 74                 /* Do software UFO. Complete and fill in the UDP checksum as
 75                  * HW cannot do checksum of UDP packets sent as multiple
 76                  * IP fragments.
 77                  */
 78                 offset = skb_checksum_start_offset(skb);
 79                 csum = skb_checksum(skb, offset, skb->len - offset, 0);
 80                 offset += skb->csum_offset;
 81                 *(__sum16 *)(skb->data + offset) = csum_fold(csum);
 82                 skb->ip_summed = CHECKSUM_NONE;
 83 
 84                 segs = skb_segment(skb, features);
 85         }
 86 out:
 87         return segs;
 88 }
 89 
 90 static const struct net_offload udpv4_offload = {
 91         .callbacks = {
 92                 .gso_send_check = udp4_ufo_send_check,
 93                 .gso_segment = udp4_ufo_fragment,
 94         },
 95 };
 96 
 97 int __init udpv4_offload_init(void)
 98 {
 99         return inet_add_offload(&udpv4_offload, IPPROTO_UDP);
100 }
101 

~ [ 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