hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/net/sched/act_gact.c
....@@ -1,13 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * net/sched/act_gact.c Generic actions
34 *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License
6
- * as published by the Free Software Foundation; either version
7
- * 2 of the License, or (at your option) any later version.
8
- *
95 * copyright Jamal Hadi Salim (2002-4)
10
- *
116 */
127
138 #include <linux/types.h>
....@@ -20,6 +15,7 @@
2015 #include <linux/init.h>
2116 #include <net/netlink.h>
2217 #include <net/pkt_sched.h>
18
+#include <net/pkt_cls.h>
2319 #include <linux/tc_act/tc_gact.h>
2420 #include <net/tc_act/tc_gact.h>
2521
....@@ -57,10 +53,12 @@
5753 static int tcf_gact_init(struct net *net, struct nlattr *nla,
5854 struct nlattr *est, struct tc_action **a,
5955 int ovr, int bind, bool rtnl_held,
56
+ struct tcf_proto *tp, u32 flags,
6057 struct netlink_ext_ack *extack)
6158 {
6259 struct tc_action_net *tn = net_generic(net, gact_net_id);
6360 struct nlattr *tb[TCA_GACT_MAX + 1];
61
+ struct tcf_chain *goto_ch = NULL;
6462 struct tc_gact *parm;
6563 struct tcf_gact *gact;
6664 int ret = 0;
....@@ -73,7 +71,8 @@
7371 if (nla == NULL)
7472 return -EINVAL;
7573
76
- err = nla_parse_nested(tb, TCA_GACT_MAX, nla, gact_policy, NULL);
74
+ err = nla_parse_nested_deprecated(tb, TCA_GACT_MAX, nla, gact_policy,
75
+ NULL);
7776 if (err < 0)
7877 return err;
7978
....@@ -90,13 +89,18 @@
9089 p_parm = nla_data(tb[TCA_GACT_PROB]);
9190 if (p_parm->ptype >= MAX_RAND)
9291 return -EINVAL;
92
+ if (TC_ACT_EXT_CMP(p_parm->paction, TC_ACT_GOTO_CHAIN)) {
93
+ NL_SET_ERR_MSG(extack,
94
+ "goto chain not allowed on fallback");
95
+ return -EINVAL;
96
+ }
9397 }
9498 #endif
9599
96100 err = tcf_idr_check_alloc(tn, &index, a, bind);
97101 if (!err) {
98
- ret = tcf_idr_create(tn, index, est, a,
99
- &act_gact_ops, bind, true);
102
+ ret = tcf_idr_create_from_flags(tn, index, est, a,
103
+ &act_gact_ops, bind, flags);
100104 if (ret) {
101105 tcf_idr_cleanup(tn, index);
102106 return ret;
....@@ -113,10 +117,13 @@
113117 return err;
114118 }
115119
120
+ err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
121
+ if (err < 0)
122
+ goto release_idr;
116123 gact = to_gact(*a);
117124
118125 spin_lock_bh(&gact->tcf_lock);
119
- gact->tcf_action = parm->action;
126
+ goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
120127 #ifdef CONFIG_GACT_PROB
121128 if (p_parm) {
122129 gact->tcfg_paction = p_parm->paction;
....@@ -130,9 +137,13 @@
130137 #endif
131138 spin_unlock_bh(&gact->tcf_lock);
132139
133
- if (ret == ACT_P_CREATED)
134
- tcf_idr_insert(tn, *a);
140
+ if (goto_ch)
141
+ tcf_chain_put_by_act(goto_ch);
142
+
135143 return ret;
144
+release_idr:
145
+ tcf_idr_release(*a, bind);
146
+ return err;
136147 }
137148
138149 static int tcf_gact_act(struct sk_buff *skb, const struct tc_action *a,
....@@ -149,27 +160,24 @@
149160 action = gact_rand[ptype](gact);
150161 }
151162 #endif
152
- bstats_cpu_update(this_cpu_ptr(gact->common.cpu_bstats), skb);
163
+ tcf_action_update_bstats(&gact->common, skb);
153164 if (action == TC_ACT_SHOT)
154
- qstats_drop_inc(this_cpu_ptr(gact->common.cpu_qstats));
165
+ tcf_action_inc_drop_qstats(&gact->common);
155166
156167 tcf_lastuse_update(&gact->tcf_tm);
157168
158169 return action;
159170 }
160171
161
-static void tcf_gact_stats_update(struct tc_action *a, u64 bytes, u32 packets,
162
- u64 lastuse)
172
+static void tcf_gact_stats_update(struct tc_action *a, u64 bytes, u64 packets,
173
+ u64 drops, u64 lastuse, bool hw)
163174 {
164175 struct tcf_gact *gact = to_gact(a);
165176 int action = READ_ONCE(gact->tcf_action);
166177 struct tcf_t *tm = &gact->tcf_tm;
167178
168
- _bstats_cpu_update(this_cpu_ptr(gact->common.cpu_bstats), bytes,
169
- packets);
170
- if (action == TC_ACT_SHOT)
171
- this_cpu_ptr(gact->common.cpu_qstats)->drops += packets;
172
-
179
+ tcf_action_update_stats(a, bytes, packets,
180
+ action == TC_ACT_SHOT ? packets : drops, hw);
173181 tm->lastuse = max_t(u64, tm->lastuse, lastuse);
174182 }
175183
....@@ -224,8 +232,7 @@
224232 return tcf_generic_walker(tn, skb, cb, type, ops, extack);
225233 }
226234
227
-static int tcf_gact_search(struct net *net, struct tc_action **a, u32 index,
228
- struct netlink_ext_ack *extack)
235
+static int tcf_gact_search(struct net *net, struct tc_action **a, u32 index)
229236 {
230237 struct tc_action_net *tn = net_generic(net, gact_net_id);
231238
....@@ -247,7 +254,7 @@
247254
248255 static struct tc_action_ops act_gact_ops = {
249256 .kind = "gact",
250
- .type = TCA_ACT_GACT,
257
+ .id = TCA_ID_GACT,
251258 .owner = THIS_MODULE,
252259 .act = tcf_gact_act,
253260 .stats_update = tcf_gact_stats_update,