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

TOMOYO Linux Cross Reference
Linux/net/sctp/offload.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * sctp_offload - GRO/GSO Offloading for SCTP
  4  *
  5  * Copyright (C) 2015, Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
  6  */
  7 
  8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  9 
 10 #include <linux/kernel.h>
 11 #include <linux/kprobes.h>
 12 #include <linux/socket.h>
 13 #include <linux/sctp.h>
 14 #include <linux/proc_fs.h>
 15 #include <linux/vmalloc.h>
 16 #include <linux/module.h>
 17 #include <linux/kfifo.h>
 18 #include <linux/time.h>
 19 #include <net/net_namespace.h>
 20 
 21 #include <linux/skbuff.h>
 22 #include <net/sctp/sctp.h>
 23 #include <net/sctp/checksum.h>
 24 #include <net/protocol.h>
 25 #include <net/gso.h>
 26 
 27 static __le32 sctp_gso_make_checksum(struct sk_buff *skb)
 28 {
 29         skb->ip_summed = CHECKSUM_NONE;
 30         skb->csum_not_inet = 0;
 31         /* csum and csum_start in GSO CB may be needed to do the UDP
 32          * checksum when it's a UDP tunneling packet.
 33          */
 34         SKB_GSO_CB(skb)->csum = (__force __wsum)~0;
 35         SKB_GSO_CB(skb)->csum_start = skb_headroom(skb) + skb->len;
 36         return sctp_compute_cksum(skb, skb_transport_offset(skb));
 37 }
 38 
 39 static struct sk_buff *sctp_gso_segment(struct sk_buff *skb,
 40                                         netdev_features_t features)
 41 {
 42         struct sk_buff *segs = ERR_PTR(-EINVAL);
 43         struct sctphdr *sh;
 44 
 45         if (!skb_is_gso_sctp(skb))
 46                 goto out;
 47 
 48         sh = sctp_hdr(skb);
 49         if (!pskb_may_pull(skb, sizeof(*sh)))
 50                 goto out;
 51 
 52         __skb_pull(skb, sizeof(*sh));
 53 
 54         if (skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST)) {
 55                 /* Packet is from an untrusted source, reset gso_segs. */
 56                 struct skb_shared_info *pinfo = skb_shinfo(skb);
 57                 struct sk_buff *frag_iter;
 58 
 59                 pinfo->gso_segs = 0;
 60                 if (skb->len != skb->data_len) {
 61                         /* Means we have chunks in here too */
 62                         pinfo->gso_segs++;
 63                 }
 64 
 65                 skb_walk_frags(skb, frag_iter)
 66                         pinfo->gso_segs++;
 67 
 68                 segs = NULL;
 69                 goto out;
 70         }
 71 
 72         segs = skb_segment(skb, (features | NETIF_F_HW_CSUM) & ~NETIF_F_SG);
 73         if (IS_ERR(segs))
 74                 goto out;
 75 
 76         /* All that is left is update SCTP CRC if necessary */
 77         if (!(features & NETIF_F_SCTP_CRC)) {
 78                 for (skb = segs; skb; skb = skb->next) {
 79                         if (skb->ip_summed == CHECKSUM_PARTIAL) {
 80                                 sh = sctp_hdr(skb);
 81                                 sh->checksum = sctp_gso_make_checksum(skb);
 82                         }
 83                 }
 84         }
 85 
 86 out:
 87         return segs;
 88 }
 89 
 90 static const struct net_offload sctp_offload = {
 91         .callbacks = {
 92                 .gso_segment = sctp_gso_segment,
 93         },
 94 };
 95 
 96 static const struct net_offload sctp6_offload = {
 97         .callbacks = {
 98                 .gso_segment = sctp_gso_segment,
 99         },
100 };
101 
102 int __init sctp_offload_init(void)
103 {
104         int ret;
105 
106         ret = inet_add_offload(&sctp_offload, IPPROTO_SCTP);
107         if (ret)
108                 goto out;
109 
110         ret = inet6_add_offload(&sctp6_offload, IPPROTO_SCTP);
111         if (ret)
112                 goto ipv4;
113 
114         crc32c_csum_stub = &sctp_csum_ops;
115         return ret;
116 
117 ipv4:
118         inet_del_offload(&sctp_offload, IPPROTO_SCTP);
119 out:
120         return ret;
121 }
122 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php