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)  * Checksum updating actions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2010 Gregoire Baron <baronchon@n7mm.org>
^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) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/init.h>
^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/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <net/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/igmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <net/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <net/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <net/ip6_checksum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <net/sctp/checksum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <net/act_api.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <net/pkt_cls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/tc_act/tc_csum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <net/tc_act/tc_csum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	[TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static unsigned int csum_net_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static struct tc_action_ops act_csum_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static int tcf_csum_init(struct net *net, struct nlattr *nla,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			 struct nlattr *est, struct tc_action **a, int ovr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			 int bind, bool rtnl_held, struct tcf_proto *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			 u32 flags, struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct tc_action_net *tn = net_generic(net, csum_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct tcf_csum_params *params_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct nlattr *tb[TCA_CSUM_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct tcf_chain *goto_ch = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct tc_csum *parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct tcf_csum *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int ret = 0, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	u32 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (nla == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	err = nla_parse_nested_deprecated(tb, TCA_CSUM_MAX, nla, csum_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 					  NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (tb[TCA_CSUM_PARMS] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	parm = nla_data(tb[TCA_CSUM_PARMS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	index = parm->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	err = tcf_idr_check_alloc(tn, &index, a, bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		ret = tcf_idr_create_from_flags(tn, index, est, a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 						&act_csum_ops, bind, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			tcf_idr_cleanup(tn, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		ret = ACT_P_CREATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	} else if (err > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		if (bind)/* dont override defaults */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		if (!ovr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			tcf_idr_release(*a, bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		goto release_idr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	p = to_tcf_csum(*a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	params_new = kzalloc(sizeof(*params_new), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (unlikely(!params_new)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		goto put_chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	params_new->update_flags = parm->update_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	spin_lock_bh(&p->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	params_new = rcu_replace_pointer(p->params, params_new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 					 lockdep_is_held(&p->tcf_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	spin_unlock_bh(&p->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (goto_ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		tcf_chain_put_by_act(goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (params_new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		kfree_rcu(params_new, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) put_chain:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (goto_ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		tcf_chain_put_by_act(goto_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) release_idr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	tcf_idr_release(*a, bind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * tcf_csum_skb_nextlayer - Get next layer pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * @skb: sk_buff to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * @ihl: previous summed headers length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * @ipl: complete packet length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * @jhl: next header length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * Check the expected next layer availability in the specified sk_buff.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * Return the next layer pointer if pass, NULL otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static void *tcf_csum_skb_nextlayer(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 				    unsigned int ihl, unsigned int ipl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 				    unsigned int jhl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	int ntkoff = skb_network_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	int hl = ihl + jhl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (!pskb_may_pull(skb, ipl + ntkoff) || (ipl < hl) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	    skb_try_make_writable(skb, hl + ntkoff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		return (void *)(skb_network_header(skb) + ihl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int tcf_csum_ipv4_icmp(struct sk_buff *skb, unsigned int ihl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			      unsigned int ipl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct icmphdr *icmph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	icmph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*icmph));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (icmph == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	icmph->checksum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	skb->csum = csum_partial(icmph, ipl - ihl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	icmph->checksum = csum_fold(skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int tcf_csum_ipv4_igmp(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			      unsigned int ihl, unsigned int ipl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct igmphdr *igmph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	igmph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*igmph));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (igmph == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	igmph->csum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	skb->csum = csum_partial(igmph, ipl - ihl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	igmph->csum = csum_fold(skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static int tcf_csum_ipv6_icmp(struct sk_buff *skb, unsigned int ihl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			      unsigned int ipl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct icmp6hdr *icmp6h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	const struct ipv6hdr *ip6h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	icmp6h = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*icmp6h));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (icmp6h == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	ip6h = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	icmp6h->icmp6_cksum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	skb->csum = csum_partial(icmp6h, ipl - ihl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	icmp6h->icmp6_cksum = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 					      ipl - ihl, IPPROTO_ICMPV6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 					      skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static int tcf_csum_ipv4_tcp(struct sk_buff *skb, unsigned int ihl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			     unsigned int ipl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct tcphdr *tcph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	const struct iphdr *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	tcph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*tcph));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (tcph == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	iph = ip_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	tcph->check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	skb->csum = csum_partial(tcph, ipl - ihl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	tcph->check = tcp_v4_check(ipl - ihl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 				   iph->saddr, iph->daddr, skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static int tcf_csum_ipv6_tcp(struct sk_buff *skb, unsigned int ihl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			     unsigned int ipl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	struct tcphdr *tcph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	const struct ipv6hdr *ip6h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	tcph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*tcph));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (tcph == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	ip6h = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	tcph->check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	skb->csum = csum_partial(tcph, ipl - ihl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	tcph->check = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				      ipl - ihl, IPPROTO_TCP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				      skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int tcf_csum_ipv4_udp(struct sk_buff *skb, unsigned int ihl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			     unsigned int ipl, int udplite)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	struct udphdr *udph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	const struct iphdr *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	u16 ul;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	 * Support both UDP and UDPLITE checksum algorithms, Don't use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	 * udph->len to get the real length without any protocol check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	 * UDPLITE uses udph->len for another thing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	 * Use iph->tot_len, or just ipl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	udph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*udph));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (udph == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	iph = ip_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	ul = ntohs(udph->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (udplite || udph->check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		udph->check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		if (udplite) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			if (ul == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 				skb->csum = csum_partial(udph, ipl - ihl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			else if ((ul >= sizeof(*udph)) && (ul <= ipl - ihl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 				skb->csum = csum_partial(udph, ul, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 				goto ignore_obscure_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			if (ul != ipl - ihl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 				goto ignore_obscure_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			skb->csum = csum_partial(udph, ul, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 						ul, iph->protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 						skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		if (!udph->check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			udph->check = CSUM_MANGLED_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) ignore_obscure_skb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static int tcf_csum_ipv6_udp(struct sk_buff *skb, unsigned int ihl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			     unsigned int ipl, int udplite)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	struct udphdr *udph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	const struct ipv6hdr *ip6h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	u16 ul;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	 * Support both UDP and UDPLITE checksum algorithms, Don't use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	 * udph->len to get the real length without any protocol check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	 * UDPLITE uses udph->len for another thing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	 * Use ip6h->payload_len + sizeof(*ip6h) ... , or just ipl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	udph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*udph));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if (udph == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	ip6h = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	ul = ntohs(udph->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	udph->check = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (udplite) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		if (ul == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			skb->csum = csum_partial(udph, ipl - ihl, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		else if ((ul >= sizeof(*udph)) && (ul <= ipl - ihl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			skb->csum = csum_partial(udph, ul, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			goto ignore_obscure_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		if (ul != ipl - ihl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			goto ignore_obscure_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		skb->csum = csum_partial(udph, ul, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	udph->check = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, ul,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 				      udplite ? IPPROTO_UDPLITE : IPPROTO_UDP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 				      skb->csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	if (!udph->check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		udph->check = CSUM_MANGLED_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) ignore_obscure_skb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) static int tcf_csum_sctp(struct sk_buff *skb, unsigned int ihl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			 unsigned int ipl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	struct sctphdr *sctph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	if (skb_is_gso(skb) && skb_is_gso_sctp(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	sctph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*sctph));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (!sctph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	sctph->checksum = sctp_compute_cksum(skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 					     skb_network_offset(skb) + ihl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	skb->csum_not_inet = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static int tcf_csum_ipv4(struct sk_buff *skb, u32 update_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	const struct iphdr *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	int ntkoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	ntkoff = skb_network_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	if (!pskb_may_pull(skb, sizeof(*iph) + ntkoff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	iph = ip_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	switch (iph->frag_off & htons(IP_OFFSET) ? 0 : iph->protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	case IPPROTO_ICMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		if (update_flags & TCA_CSUM_UPDATE_FLAG_ICMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 			if (!tcf_csum_ipv4_icmp(skb, iph->ihl * 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 						ntohs(iph->tot_len)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	case IPPROTO_IGMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		if (update_flags & TCA_CSUM_UPDATE_FLAG_IGMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			if (!tcf_csum_ipv4_igmp(skb, iph->ihl * 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 						ntohs(iph->tot_len)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	case IPPROTO_TCP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		if (update_flags & TCA_CSUM_UPDATE_FLAG_TCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			if (!tcf_csum_ipv4_tcp(skb, iph->ihl * 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 					       ntohs(iph->tot_len)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	case IPPROTO_UDP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		if (update_flags & TCA_CSUM_UPDATE_FLAG_UDP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			if (!tcf_csum_ipv4_udp(skb, iph->ihl * 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 					       ntohs(iph->tot_len), 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	case IPPROTO_UDPLITE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		if (update_flags & TCA_CSUM_UPDATE_FLAG_UDPLITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			if (!tcf_csum_ipv4_udp(skb, iph->ihl * 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 					       ntohs(iph->tot_len), 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	case IPPROTO_SCTP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		if ((update_flags & TCA_CSUM_UPDATE_FLAG_SCTP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		    !tcf_csum_sctp(skb, iph->ihl * 4, ntohs(iph->tot_len)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	if (update_flags & TCA_CSUM_UPDATE_FLAG_IPV4HDR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		if (skb_try_make_writable(skb, sizeof(*iph) + ntkoff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		ip_send_check(ip_hdr(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) static int tcf_csum_ipv6_hopopts(struct ipv6_opt_hdr *ip6xh, unsigned int ixhl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 				 unsigned int *pl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	int off, len, optlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	unsigned char *xh = (void *)ip6xh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	off = sizeof(*ip6xh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	len = ixhl - off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	while (len > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		switch (xh[off]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		case IPV6_TLV_PAD1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 			optlen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		case IPV6_TLV_JUMBO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 			optlen = xh[off + 1] + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 			if (optlen != 6 || len < 6 || (off & 3) != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 				/* wrong jumbo option length/alignment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 			*pl = ntohl(*(__be32 *)(xh + off + 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 			optlen = xh[off + 1] + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 			if (optlen > len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 				/* ignore obscure options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 				goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		off += optlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		len -= optlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static int tcf_csum_ipv6(struct sk_buff *skb, u32 update_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	struct ipv6hdr *ip6h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	struct ipv6_opt_hdr *ip6xh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	unsigned int hl, ixhl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	unsigned int pl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	int ntkoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	u8 nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	ntkoff = skb_network_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	hl = sizeof(*ip6h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	if (!pskb_may_pull(skb, hl + ntkoff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	ip6h = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	pl = ntohs(ip6h->payload_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	nexthdr = ip6h->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		switch (nexthdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		case NEXTHDR_FRAGMENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 			goto ignore_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		case NEXTHDR_ROUTING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		case NEXTHDR_HOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		case NEXTHDR_DEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 			if (!pskb_may_pull(skb, hl + sizeof(*ip6xh) + ntkoff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 			ip6xh = (void *)(skb_network_header(skb) + hl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 			ixhl = ipv6_optlen(ip6xh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 			if (!pskb_may_pull(skb, hl + ixhl + ntkoff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 			ip6xh = (void *)(skb_network_header(skb) + hl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 			if ((nexthdr == NEXTHDR_HOP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 			    !(tcf_csum_ipv6_hopopts(ip6xh, ixhl, &pl)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 			nexthdr = ip6xh->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 			hl += ixhl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		case IPPROTO_ICMPV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 			if (update_flags & TCA_CSUM_UPDATE_FLAG_ICMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 				if (!tcf_csum_ipv6_icmp(skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 							hl, pl + sizeof(*ip6h)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 					goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		case IPPROTO_TCP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 			if (update_flags & TCA_CSUM_UPDATE_FLAG_TCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 				if (!tcf_csum_ipv6_tcp(skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 						       hl, pl + sizeof(*ip6h)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 					goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		case IPPROTO_UDP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 			if (update_flags & TCA_CSUM_UPDATE_FLAG_UDP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 				if (!tcf_csum_ipv6_udp(skb, hl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 						       pl + sizeof(*ip6h), 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 					goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		case IPPROTO_UDPLITE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 			if (update_flags & TCA_CSUM_UPDATE_FLAG_UDPLITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 				if (!tcf_csum_ipv6_udp(skb, hl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 						       pl + sizeof(*ip6h), 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 					goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		case IPPROTO_SCTP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 			if ((update_flags & TCA_CSUM_UPDATE_FLAG_SCTP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 			    !tcf_csum_sctp(skb, hl, pl + sizeof(*ip6h)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 			goto ignore_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	} while (pskb_may_pull(skb, hl + 1 + ntkoff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) ignore_skb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) static int tcf_csum_act(struct sk_buff *skb, const struct tc_action *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 			struct tcf_result *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	struct tcf_csum *p = to_tcf_csum(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	bool orig_vlan_tag_present = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	unsigned int vlan_hdr_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	struct tcf_csum_params *params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	u32 update_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	__be16 protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	int action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	params = rcu_dereference_bh(p->params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	tcf_lastuse_update(&p->tcf_tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	tcf_action_update_bstats(&p->common, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	action = READ_ONCE(p->tcf_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	if (unlikely(action == TC_ACT_SHOT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	update_flags = params->update_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	protocol = skb_protocol(skb, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	switch (protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	case cpu_to_be16(ETH_P_IP):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		if (!tcf_csum_ipv4(skb, update_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 			goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	case cpu_to_be16(ETH_P_IPV6):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		if (!tcf_csum_ipv6(skb, update_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 			goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	case cpu_to_be16(ETH_P_8021AD):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	case cpu_to_be16(ETH_P_8021Q):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		if (skb_vlan_tag_present(skb) && !orig_vlan_tag_present) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 			protocol = skb->protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 			orig_vlan_tag_present = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 			struct vlan_hdr *vlan = (struct vlan_hdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 			protocol = vlan->h_vlan_encapsulated_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 			skb_pull(skb, VLAN_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 			skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 			vlan_hdr_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	/* Restore the skb for the pulled VLAN tags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	while (vlan_hdr_count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		skb_push(skb, VLAN_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	return action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	tcf_action_inc_drop_qstats(&p->common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	action = TC_ACT_SHOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) static int tcf_csum_dump(struct sk_buff *skb, struct tc_action *a, int bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 			 int ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	unsigned char *b = skb_tail_pointer(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	struct tcf_csum *p = to_tcf_csum(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	struct tcf_csum_params *params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	struct tc_csum opt = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 		.index   = p->tcf_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		.refcnt  = refcount_read(&p->tcf_refcnt) - ref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 		.bindcnt = atomic_read(&p->tcf_bindcnt) - bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	struct tcf_t t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	spin_lock_bh(&p->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	params = rcu_dereference_protected(p->params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 					   lockdep_is_held(&p->tcf_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	opt.action = p->tcf_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	opt.update_flags = params->update_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	if (nla_put(skb, TCA_CSUM_PARMS, sizeof(opt), &opt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	tcf_tm_dump(&t, &p->tcf_tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	if (nla_put_64bit(skb, TCA_CSUM_TM, sizeof(t), &t, TCA_CSUM_PAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	spin_unlock_bh(&p->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	spin_unlock_bh(&p->tcf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	nlmsg_trim(skb, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) static void tcf_csum_cleanup(struct tc_action *a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	struct tcf_csum *p = to_tcf_csum(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	struct tcf_csum_params *params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	params = rcu_dereference_protected(p->params, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	if (params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		kfree_rcu(params, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) static int tcf_csum_walker(struct net *net, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 			   struct netlink_callback *cb, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 			   const struct tc_action_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 			   struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	struct tc_action_net *tn = net_generic(net, csum_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) static int tcf_csum_search(struct net *net, struct tc_action **a, u32 index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	struct tc_action_net *tn = net_generic(net, csum_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	return tcf_idr_search(tn, a, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) static size_t tcf_csum_get_fill_size(const struct tc_action *act)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	return nla_total_size(sizeof(struct tc_csum));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) static struct tc_action_ops act_csum_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	.kind		= "csum",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	.id		= TCA_ID_CSUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	.act		= tcf_csum_act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	.dump		= tcf_csum_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	.init		= tcf_csum_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	.cleanup	= tcf_csum_cleanup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	.walk		= tcf_csum_walker,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	.lookup		= tcf_csum_search,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	.get_fill_size  = tcf_csum_get_fill_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	.size		= sizeof(struct tcf_csum),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) static __net_init int csum_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	struct tc_action_net *tn = net_generic(net, csum_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	return tc_action_net_init(net, tn, &act_csum_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) static void __net_exit csum_exit_net(struct list_head *net_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	tc_action_net_exit(net_list, csum_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) static struct pernet_operations csum_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	.init = csum_init_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	.exit_batch = csum_exit_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	.id   = &csum_net_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	.size = sizeof(struct tc_action_net),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) MODULE_DESCRIPTION("Checksum updating actions");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) static int __init csum_init_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	return tcf_register_action(&act_csum_ops, &csum_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) static void __exit csum_cleanup_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	tcf_unregister_action(&act_csum_ops, &csum_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) module_init(csum_init_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) module_exit(csum_cleanup_module);