Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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