hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/sched/act_csum.c
....@@ -1,13 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Checksum updating actions
34 *
45 * Copyright (c) 2010 Gregoire Baron <baronchon@n7mm.org>
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms of the GNU General Public License as published by the Free
8
- * Software Foundation; either version 2 of the License, or (at your option)
9
- * any later version.
10
- *
116 */
127
138 #include <linux/types.h>
....@@ -33,6 +28,7 @@
3328 #include <net/sctp/checksum.h>
3429
3530 #include <net/act_api.h>
31
+#include <net/pkt_cls.h>
3632
3733 #include <linux/tc_act/tc_csum.h>
3834 #include <net/tc_act/tc_csum.h>
....@@ -46,12 +42,13 @@
4642
4743 static int tcf_csum_init(struct net *net, struct nlattr *nla,
4844 struct nlattr *est, struct tc_action **a, int ovr,
49
- int bind, bool rtnl_held,
50
- struct netlink_ext_ack *extack)
45
+ int bind, bool rtnl_held, struct tcf_proto *tp,
46
+ u32 flags, struct netlink_ext_ack *extack)
5147 {
5248 struct tc_action_net *tn = net_generic(net, csum_net_id);
5349 struct tcf_csum_params *params_new;
5450 struct nlattr *tb[TCA_CSUM_MAX + 1];
51
+ struct tcf_chain *goto_ch = NULL;
5552 struct tc_csum *parm;
5653 struct tcf_csum *p;
5754 int ret = 0, err;
....@@ -60,7 +57,8 @@
6057 if (nla == NULL)
6158 return -EINVAL;
6259
63
- err = nla_parse_nested(tb, TCA_CSUM_MAX, nla, csum_policy, NULL);
60
+ err = nla_parse_nested_deprecated(tb, TCA_CSUM_MAX, nla, csum_policy,
61
+ NULL);
6462 if (err < 0)
6563 return err;
6664
....@@ -70,8 +68,8 @@
7068 index = parm->index;
7169 err = tcf_idr_check_alloc(tn, &index, a, bind);
7270 if (!err) {
73
- ret = tcf_idr_create(tn, index, est, a,
74
- &act_csum_ops, bind, true);
71
+ ret = tcf_idr_create_from_flags(tn, index, est, a,
72
+ &act_csum_ops, bind, flags);
7573 if (ret) {
7674 tcf_idr_cleanup(tn, index);
7775 return ret;
....@@ -88,28 +86,37 @@
8886 return err;
8987 }
9088
89
+ err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
90
+ if (err < 0)
91
+ goto release_idr;
92
+
9193 p = to_tcf_csum(*a);
9294
9395 params_new = kzalloc(sizeof(*params_new), GFP_KERNEL);
9496 if (unlikely(!params_new)) {
95
- tcf_idr_release(*a, bind);
96
- return -ENOMEM;
97
+ err = -ENOMEM;
98
+ goto put_chain;
9799 }
98100 params_new->update_flags = parm->update_flags;
99101
100102 spin_lock_bh(&p->tcf_lock);
101
- p->tcf_action = parm->action;
102
- rcu_swap_protected(p->params, params_new,
103
- lockdep_is_held(&p->tcf_lock));
103
+ goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
104
+ params_new = rcu_replace_pointer(p->params, params_new,
105
+ lockdep_is_held(&p->tcf_lock));
104106 spin_unlock_bh(&p->tcf_lock);
105107
108
+ if (goto_ch)
109
+ tcf_chain_put_by_act(goto_ch);
106110 if (params_new)
107111 kfree_rcu(params_new, rcu);
108112
109
- if (ret == ACT_P_CREATED)
110
- tcf_idr_insert(tn, *a);
111
-
112113 return ret;
114
+put_chain:
115
+ if (goto_ch)
116
+ tcf_chain_put_by_act(goto_ch);
117
+release_idr:
118
+ tcf_idr_release(*a, bind);
119
+ return err;
113120 }
114121
115122 /**
....@@ -570,7 +577,7 @@
570577 params = rcu_dereference_bh(p->params);
571578
572579 tcf_lastuse_update(&p->tcf_tm);
573
- bstats_cpu_update(this_cpu_ptr(p->common.cpu_bstats), skb);
580
+ tcf_action_update_bstats(&p->common, skb);
574581
575582 action = READ_ONCE(p->tcf_action);
576583 if (unlikely(action == TC_ACT_SHOT))
....@@ -588,7 +595,8 @@
588595 if (!tcf_csum_ipv6(skb, update_flags))
589596 goto drop;
590597 break;
591
- case cpu_to_be16(ETH_P_8021AD): /* fall through */
598
+ case cpu_to_be16(ETH_P_8021AD):
599
+ fallthrough;
592600 case cpu_to_be16(ETH_P_8021Q):
593601 if (skb_vlan_tag_present(skb) && !orig_vlan_tag_present) {
594602 protocol = skb->protocol;
....@@ -614,7 +622,7 @@
614622 return action;
615623
616624 drop:
617
- qstats_drop_inc(this_cpu_ptr(p->common.cpu_qstats));
625
+ tcf_action_inc_drop_qstats(&p->common);
618626 action = TC_ACT_SHOT;
619627 goto out;
620628 }
....@@ -674,8 +682,7 @@
674682 return tcf_generic_walker(tn, skb, cb, type, ops, extack);
675683 }
676684
677
-static int tcf_csum_search(struct net *net, struct tc_action **a, u32 index,
678
- struct netlink_ext_ack *extack)
685
+static int tcf_csum_search(struct net *net, struct tc_action **a, u32 index)
679686 {
680687 struct tc_action_net *tn = net_generic(net, csum_net_id);
681688
....@@ -689,7 +696,7 @@
689696
690697 static struct tc_action_ops act_csum_ops = {
691698 .kind = "csum",
692
- .type = TCA_ACT_CSUM,
699
+ .id = TCA_ID_CSUM,
693700 .owner = THIS_MODULE,
694701 .act = tcf_csum_act,
695702 .dump = tcf_csum_dump,