blob: af427a3dbcba238103169ab2a58005feda5fa2f1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * net/sched/act_api.c Packet action API.
3 *
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 *
9 * Author: Jamal Hadi Salim
10 *
11 *
12 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/types.h>
15#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/errno.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/init.h>
21#include <linux/kmod.h>
Patrick McHardyab27cfb2008-01-23 20:33:13 -080022#include <linux/err.h>
Paul Gortmaker3a9a2312011-05-27 09:12:25 -040023#include <linux/module.h>
Denis V. Lunevb8542722007-12-01 00:21:31 +110024#include <net/net_namespace.h>
25#include <net/sock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <net/sch_generic.h>
27#include <net/act_api.h>
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -070028#include <net/netlink.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
WANG Cong86062032014-02-11 17:07:31 -080030void tcf_hash_destroy(struct tc_action *a)
David S. Millere9ce1cd2006-08-21 23:54:55 -070031{
WANG Cong86062032014-02-11 17:07:31 -080032 struct tcf_common *p = a->priv;
33 struct tcf_hashinfo *hinfo = a->ops->hinfo;
34
WANG Cong89819dc2013-12-15 20:15:09 -080035 spin_lock_bh(&hinfo->lock);
36 hlist_del(&p->tcfc_head);
37 spin_unlock_bh(&hinfo->lock);
38 gen_kill_estimator(&p->tcfc_bstats,
39 &p->tcfc_rate_est);
40 /*
41 * gen_estimator est_timer() might access p->tcfc_lock
42 * or bstats, wait a RCU grace period before freeing p
43 */
44 kfree_rcu(p, tcfc_rcu);
David S. Millere9ce1cd2006-08-21 23:54:55 -070045}
46EXPORT_SYMBOL(tcf_hash_destroy);
47
WANG Cong86062032014-02-11 17:07:31 -080048int tcf_hash_release(struct tc_action *a, int bind)
David S. Millere9ce1cd2006-08-21 23:54:55 -070049{
WANG Cong86062032014-02-11 17:07:31 -080050 struct tcf_common *p = a->priv;
David S. Millere9ce1cd2006-08-21 23:54:55 -070051 int ret = 0;
52
53 if (p) {
54 if (bind)
55 p->tcfc_bindcnt--;
WANG Cong55334a52014-02-11 17:07:34 -080056 else if (p->tcfc_bindcnt > 0)
57 return -EPERM;
David S. Millere9ce1cd2006-08-21 23:54:55 -070058
59 p->tcfc_refcnt--;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +090060 if (p->tcfc_bindcnt <= 0 && p->tcfc_refcnt <= 0) {
WANG Conga5b5c952014-02-11 17:07:32 -080061 if (a->ops->cleanup)
62 a->ops->cleanup(a, bind);
WANG Cong86062032014-02-11 17:07:31 -080063 tcf_hash_destroy(a);
David S. Millere9ce1cd2006-08-21 23:54:55 -070064 ret = 1;
65 }
66 }
67 return ret;
68}
69EXPORT_SYMBOL(tcf_hash_release);
70
71static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb,
WANG Congc779f7a2014-01-17 11:37:02 -080072 struct tc_action *a)
David S. Millere9ce1cd2006-08-21 23:54:55 -070073{
WANG Congc779f7a2014-01-17 11:37:02 -080074 struct tcf_hashinfo *hinfo = a->ops->hinfo;
WANG Cong89819dc2013-12-15 20:15:09 -080075 struct hlist_head *head;
David S. Millere9ce1cd2006-08-21 23:54:55 -070076 struct tcf_common *p;
Eric Dumazetcc7ec452011-01-19 19:26:56 +000077 int err = 0, index = -1, i = 0, s_i = 0, n_i = 0;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -080078 struct nlattr *nest;
David S. Millere9ce1cd2006-08-21 23:54:55 -070079
WANG Cong89819dc2013-12-15 20:15:09 -080080 spin_lock_bh(&hinfo->lock);
David S. Millere9ce1cd2006-08-21 23:54:55 -070081
82 s_i = cb->args[0];
83
84 for (i = 0; i < (hinfo->hmask + 1); i++) {
WANG Cong89819dc2013-12-15 20:15:09 -080085 head = &hinfo->htab[tcf_hash(i, hinfo->hmask)];
David S. Millere9ce1cd2006-08-21 23:54:55 -070086
WANG Cong89819dc2013-12-15 20:15:09 -080087 hlist_for_each_entry_rcu(p, head, tcfc_head) {
David S. Millere9ce1cd2006-08-21 23:54:55 -070088 index++;
89 if (index < s_i)
90 continue;
91 a->priv = p;
92 a->order = n_i;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -080093
94 nest = nla_nest_start(skb, a->order);
95 if (nest == NULL)
96 goto nla_put_failure;
David S. Millere9ce1cd2006-08-21 23:54:55 -070097 err = tcf_action_dump_1(skb, a, 0, 0);
98 if (err < 0) {
99 index--;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800100 nlmsg_trim(skb, nest);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700101 goto done;
102 }
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800103 nla_nest_end(skb, nest);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700104 n_i++;
105 if (n_i >= TCA_ACT_MAX_PRIO)
106 goto done;
107 }
108 }
109done:
WANG Cong89819dc2013-12-15 20:15:09 -0800110 spin_unlock_bh(&hinfo->lock);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700111 if (n_i)
112 cb->args[0] += n_i;
113 return n_i;
114
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800115nla_put_failure:
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800116 nla_nest_cancel(skb, nest);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700117 goto done;
118}
119
WANG Congc779f7a2014-01-17 11:37:02 -0800120static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a)
David S. Millere9ce1cd2006-08-21 23:54:55 -0700121{
WANG Congc779f7a2014-01-17 11:37:02 -0800122 struct tcf_hashinfo *hinfo = a->ops->hinfo;
WANG Cong89819dc2013-12-15 20:15:09 -0800123 struct hlist_head *head;
124 struct hlist_node *n;
125 struct tcf_common *p;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800126 struct nlattr *nest;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000127 int i = 0, n_i = 0;
WANG Cong55334a52014-02-11 17:07:34 -0800128 int ret = -EINVAL;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700129
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800130 nest = nla_nest_start(skb, a->order);
131 if (nest == NULL)
132 goto nla_put_failure;
David S. Miller1b34ec42012-03-29 05:11:39 -0400133 if (nla_put_string(skb, TCA_KIND, a->ops->kind))
134 goto nla_put_failure;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700135 for (i = 0; i < (hinfo->hmask + 1); i++) {
WANG Cong89819dc2013-12-15 20:15:09 -0800136 head = &hinfo->htab[tcf_hash(i, hinfo->hmask)];
137 hlist_for_each_entry_safe(p, n, head, tcfc_head) {
WANG Cong86062032014-02-11 17:07:31 -0800138 a->priv = p;
WANG Cong55334a52014-02-11 17:07:34 -0800139 ret = tcf_hash_release(a, 0);
140 if (ret == ACT_P_DELETED) {
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000141 module_put(a->ops->owner);
Jamal Hadi Salim805c1f42013-12-23 08:02:13 -0500142 n_i++;
WANG Cong55334a52014-02-11 17:07:34 -0800143 } else if (ret < 0)
144 goto nla_put_failure;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700145 }
146 }
David S. Miller1b34ec42012-03-29 05:11:39 -0400147 if (nla_put_u32(skb, TCA_FCNT, n_i))
148 goto nla_put_failure;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800149 nla_nest_end(skb, nest);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700150
151 return n_i;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800152nla_put_failure:
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800153 nla_nest_cancel(skb, nest);
WANG Cong55334a52014-02-11 17:07:34 -0800154 return ret;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700155}
156
stephen hemminger9c75f402013-12-31 11:54:00 -0800157static int tcf_generic_walker(struct sk_buff *skb, struct netlink_callback *cb,
158 int type, struct tc_action *a)
David S. Millere9ce1cd2006-08-21 23:54:55 -0700159{
David S. Millere9ce1cd2006-08-21 23:54:55 -0700160 if (type == RTM_DELACTION) {
WANG Congc779f7a2014-01-17 11:37:02 -0800161 return tcf_del_walker(skb, a);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700162 } else if (type == RTM_GETACTION) {
WANG Congc779f7a2014-01-17 11:37:02 -0800163 return tcf_dump_walker(skb, cb, a);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700164 } else {
stephen hemminger6ff9c362010-05-12 06:37:05 +0000165 WARN(1, "tcf_generic_walker: unknown action %d\n", type);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700166 return -EINVAL;
167 }
168}
David S. Millere9ce1cd2006-08-21 23:54:55 -0700169
WANG Cong6e6a50c2014-01-17 11:37:03 -0800170static struct tcf_common *tcf_hash_lookup(u32 index, struct tcf_hashinfo *hinfo)
David S. Millere9ce1cd2006-08-21 23:54:55 -0700171{
WANG Cong89819dc2013-12-15 20:15:09 -0800172 struct tcf_common *p = NULL;
173 struct hlist_head *head;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700174
WANG Cong89819dc2013-12-15 20:15:09 -0800175 spin_lock_bh(&hinfo->lock);
176 head = &hinfo->htab[tcf_hash(index, hinfo->hmask)];
177 hlist_for_each_entry_rcu(p, head, tcfc_head)
David S. Millere9ce1cd2006-08-21 23:54:55 -0700178 if (p->tcfc_index == index)
179 break;
WANG Cong89819dc2013-12-15 20:15:09 -0800180 spin_unlock_bh(&hinfo->lock);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700181
182 return p;
183}
David S. Millere9ce1cd2006-08-21 23:54:55 -0700184
WANG Congddafd342014-01-09 16:13:59 -0800185u32 tcf_hash_new_index(struct tcf_hashinfo *hinfo)
David S. Millere9ce1cd2006-08-21 23:54:55 -0700186{
WANG Congddafd342014-01-09 16:13:59 -0800187 u32 val = hinfo->index;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700188
189 do {
190 if (++val == 0)
191 val = 1;
192 } while (tcf_hash_lookup(val, hinfo));
193
WANG Congddafd342014-01-09 16:13:59 -0800194 hinfo->index = val;
Yang Yingliang17569fa2013-12-10 20:55:29 +0800195 return val;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700196}
197EXPORT_SYMBOL(tcf_hash_new_index);
198
WANG Cong6e6a50c2014-01-17 11:37:03 -0800199int tcf_hash_search(struct tc_action *a, u32 index)
David S. Millere9ce1cd2006-08-21 23:54:55 -0700200{
201 struct tcf_hashinfo *hinfo = a->ops->hinfo;
202 struct tcf_common *p = tcf_hash_lookup(index, hinfo);
203
204 if (p) {
205 a->priv = p;
206 return 1;
207 }
208 return 0;
209}
WANG Cong6e6a50c2014-01-17 11:37:03 -0800210EXPORT_SYMBOL(tcf_hash_search);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700211
WANG Cong86062032014-02-11 17:07:31 -0800212int tcf_hash_check(u32 index, struct tc_action *a, int bind)
David S. Millere9ce1cd2006-08-21 23:54:55 -0700213{
WANG Congc779f7a2014-01-17 11:37:02 -0800214 struct tcf_hashinfo *hinfo = a->ops->hinfo;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700215 struct tcf_common *p = NULL;
216 if (index && (p = tcf_hash_lookup(index, hinfo)) != NULL) {
Jamal Hadi Salim76aab2c2008-08-07 20:37:22 -0700217 if (bind)
David S. Millere9ce1cd2006-08-21 23:54:55 -0700218 p->tcfc_bindcnt++;
Jamal Hadi Salim76aab2c2008-08-07 20:37:22 -0700219 p->tcfc_refcnt++;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700220 a->priv = p;
WANG Cong86062032014-02-11 17:07:31 -0800221 return 1;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700222 }
WANG Cong86062032014-02-11 17:07:31 -0800223 return 0;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700224}
225EXPORT_SYMBOL(tcf_hash_check);
226
WANG Cong86062032014-02-11 17:07:31 -0800227void tcf_hash_cleanup(struct tc_action *a, struct nlattr *est)
228{
229 struct tcf_common *pc = a->priv;
230 if (est)
231 gen_kill_estimator(&pc->tcfc_bstats,
232 &pc->tcfc_rate_est);
233 kfree_rcu(pc, tcfc_rcu);
234}
235EXPORT_SYMBOL(tcf_hash_cleanup);
236
237int tcf_hash_create(u32 index, struct nlattr *est, struct tc_action *a,
238 int size, int bind)
David S. Millere9ce1cd2006-08-21 23:54:55 -0700239{
WANG Congc779f7a2014-01-17 11:37:02 -0800240 struct tcf_hashinfo *hinfo = a->ops->hinfo;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700241 struct tcf_common *p = kzalloc(size, GFP_KERNEL);
242
243 if (unlikely(!p))
WANG Cong86062032014-02-11 17:07:31 -0800244 return -ENOMEM;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700245 p->tcfc_refcnt = 1;
246 if (bind)
247 p->tcfc_bindcnt = 1;
248
249 spin_lock_init(&p->tcfc_lock);
WANG Cong89819dc2013-12-15 20:15:09 -0800250 INIT_HLIST_NODE(&p->tcfc_head);
WANG Congddafd342014-01-09 16:13:59 -0800251 p->tcfc_index = index ? index : tcf_hash_new_index(hinfo);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700252 p->tcfc_tm.install = jiffies;
253 p->tcfc_tm.lastuse = jiffies;
Stephen Hemminger0e991ec2008-11-25 21:12:32 -0800254 if (est) {
John Fastabend22e0f8b2014-09-28 11:52:56 -0700255 int err = gen_new_estimator(&p->tcfc_bstats, NULL,
256 &p->tcfc_rate_est,
Stephen Hemminger0e991ec2008-11-25 21:12:32 -0800257 &p->tcfc_lock, est);
258 if (err) {
259 kfree(p);
WANG Cong86062032014-02-11 17:07:31 -0800260 return err;
Stephen Hemminger0e991ec2008-11-25 21:12:32 -0800261 }
262 }
263
David S. Millere9ce1cd2006-08-21 23:54:55 -0700264 a->priv = (void *) p;
WANG Cong86062032014-02-11 17:07:31 -0800265 return 0;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700266}
267EXPORT_SYMBOL(tcf_hash_create);
268
WANG Cong86062032014-02-11 17:07:31 -0800269void tcf_hash_insert(struct tc_action *a)
David S. Millere9ce1cd2006-08-21 23:54:55 -0700270{
WANG Cong86062032014-02-11 17:07:31 -0800271 struct tcf_common *p = a->priv;
272 struct tcf_hashinfo *hinfo = a->ops->hinfo;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700273 unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask);
274
WANG Cong89819dc2013-12-15 20:15:09 -0800275 spin_lock_bh(&hinfo->lock);
276 hlist_add_head(&p->tcfc_head, &hinfo->htab[h]);
277 spin_unlock_bh(&hinfo->lock);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700278}
279EXPORT_SYMBOL(tcf_hash_insert);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
WANG Cong1f747c22013-12-15 20:15:10 -0800281static LIST_HEAD(act_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282static DEFINE_RWLOCK(act_mod_lock);
283
WANG Cong4f1e9d82014-02-11 17:07:33 -0800284int tcf_register_action(struct tc_action_ops *act, unsigned int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
WANG Cong1f747c22013-12-15 20:15:10 -0800286 struct tc_action_ops *a;
WANG Cong4f1e9d82014-02-11 17:07:33 -0800287 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
WANG Conga5b5c952014-02-11 17:07:32 -0800289 /* Must supply act, dump and init */
290 if (!act->act || !act->dump || !act->init)
Jamal Hadi Salim76c82d72013-12-04 09:26:52 -0500291 return -EINVAL;
292
Jamal Hadi Salim382ca8a2013-12-04 09:26:55 -0500293 /* Supply defaults */
Jamal Hadi Salim63ef6172013-12-04 09:26:53 -0500294 if (!act->lookup)
295 act->lookup = tcf_hash_search;
Jamal Hadi Salim382ca8a2013-12-04 09:26:55 -0500296 if (!act->walk)
297 act->walk = tcf_generic_walker;
Jamal Hadi Salim63ef6172013-12-04 09:26:53 -0500298
WANG Cong4f1e9d82014-02-11 17:07:33 -0800299 act->hinfo = kmalloc(sizeof(struct tcf_hashinfo), GFP_KERNEL);
300 if (!act->hinfo)
301 return -ENOMEM;
302 err = tcf_hashinfo_init(act->hinfo, mask);
303 if (err) {
304 kfree(act->hinfo);
305 return err;
306 }
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 write_lock(&act_mod_lock);
WANG Cong1f747c22013-12-15 20:15:10 -0800309 list_for_each_entry(a, &act_base, head) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) {
311 write_unlock(&act_mod_lock);
WANG Cong4f1e9d82014-02-11 17:07:33 -0800312 tcf_hashinfo_destroy(act->hinfo);
313 kfree(act->hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 return -EEXIST;
315 }
316 }
WANG Cong1f747c22013-12-15 20:15:10 -0800317 list_add_tail(&act->head, &act_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 write_unlock(&act_mod_lock);
319 return 0;
320}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800321EXPORT_SYMBOL(tcf_register_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323int tcf_unregister_action(struct tc_action_ops *act)
324{
WANG Cong1f747c22013-12-15 20:15:10 -0800325 struct tc_action_ops *a;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 int err = -ENOENT;
327
328 write_lock(&act_mod_lock);
Eric Dumazeta7928662013-12-20 12:32:32 -0800329 list_for_each_entry(a, &act_base, head) {
330 if (a == act) {
331 list_del(&act->head);
WANG Cong4f1e9d82014-02-11 17:07:33 -0800332 tcf_hashinfo_destroy(act->hinfo);
333 kfree(act->hinfo);
Eric Dumazeta7928662013-12-20 12:32:32 -0800334 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 break;
Eric Dumazeta7928662013-12-20 12:32:32 -0800336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 }
338 write_unlock(&act_mod_lock);
339 return err;
340}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800341EXPORT_SYMBOL(tcf_unregister_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343/* lookup by name */
344static struct tc_action_ops *tc_lookup_action_n(char *kind)
345{
Eric Dumazeta7928662013-12-20 12:32:32 -0800346 struct tc_action_ops *a, *res = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 if (kind) {
349 read_lock(&act_mod_lock);
WANG Cong1f747c22013-12-15 20:15:10 -0800350 list_for_each_entry(a, &act_base, head) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 if (strcmp(kind, a->kind) == 0) {
Eric Dumazeta7928662013-12-20 12:32:32 -0800352 if (try_module_get(a->owner))
353 res = a;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 break;
355 }
356 }
357 read_unlock(&act_mod_lock);
358 }
Eric Dumazeta7928662013-12-20 12:32:32 -0800359 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360}
361
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800362/* lookup by nlattr */
363static struct tc_action_ops *tc_lookup_action(struct nlattr *kind)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Eric Dumazeta7928662013-12-20 12:32:32 -0800365 struct tc_action_ops *a, *res = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 if (kind) {
368 read_lock(&act_mod_lock);
WANG Cong1f747c22013-12-15 20:15:10 -0800369 list_for_each_entry(a, &act_base, head) {
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800370 if (nla_strcmp(kind, a->kind) == 0) {
Eric Dumazeta7928662013-12-20 12:32:32 -0800371 if (try_module_get(a->owner))
372 res = a;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 break;
374 }
375 }
376 read_unlock(&act_mod_lock);
377 }
Eric Dumazeta7928662013-12-20 12:32:32 -0800378 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
380
WANG Cong33be6272013-12-15 20:15:05 -0800381int tcf_action_exec(struct sk_buff *skb, const struct list_head *actions,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900382 struct tcf_result *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
Eric Dumazetdc7f9f62011-07-05 23:25:42 +0000384 const struct tc_action *a;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 int ret = -1;
386
387 if (skb->tc_verd & TC_NCLS) {
388 skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 ret = TC_ACT_OK;
390 goto exec_done;
391 }
WANG Cong33be6272013-12-15 20:15:05 -0800392 list_for_each_entry(a, actions, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393repeat:
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500394 ret = a->ops->act(skb, a, res);
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500395 if (ret == TC_ACT_REPEAT)
396 goto repeat; /* we need a ttl - JHS */
397 if (ret != TC_ACT_PIPE)
398 goto exec_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 }
400exec_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 return ret;
402}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800403EXPORT_SYMBOL(tcf_action_exec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
WANG Cong55334a52014-02-11 17:07:34 -0800405int tcf_action_destroy(struct list_head *actions, int bind)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
WANG Cong33be6272013-12-15 20:15:05 -0800407 struct tc_action *a, *tmp;
WANG Cong55334a52014-02-11 17:07:34 -0800408 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
WANG Cong33be6272013-12-15 20:15:05 -0800410 list_for_each_entry_safe(a, tmp, actions, list) {
WANG Cong55334a52014-02-11 17:07:34 -0800411 ret = tcf_hash_release(a, bind);
412 if (ret == ACT_P_DELETED)
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500413 module_put(a->ops->owner);
WANG Cong55334a52014-02-11 17:07:34 -0800414 else if (ret < 0)
415 return ret;
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500416 list_del(&a->list);
417 kfree(a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
WANG Cong55334a52014-02-11 17:07:34 -0800419 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
422int
423tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
424{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 return a->ops->dump(skb, a, bind, ref);
426}
427
428int
429tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
430{
431 int err = -EINVAL;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700432 unsigned char *b = skb_tail_pointer(skb);
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800433 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
David S. Miller1b34ec42012-03-29 05:11:39 -0400435 if (nla_put_string(skb, TCA_KIND, a->ops->kind))
436 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 if (tcf_action_copy_stats(skb, a, 0))
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800438 goto nla_put_failure;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800439 nest = nla_nest_start(skb, TCA_OPTIONS);
440 if (nest == NULL)
441 goto nla_put_failure;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000442 err = tcf_action_dump_old(skb, a, bind, ref);
443 if (err > 0) {
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800444 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return err;
446 }
447
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800448nla_put_failure:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700449 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 return -1;
451}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800452EXPORT_SYMBOL(tcf_action_dump_1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454int
WANG Cong33be6272013-12-15 20:15:05 -0800455tcf_action_dump(struct sk_buff *skb, struct list_head *actions, int bind, int ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456{
457 struct tc_action *a;
458 int err = -EINVAL;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800459 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
WANG Cong33be6272013-12-15 20:15:05 -0800461 list_for_each_entry(a, actions, list) {
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800462 nest = nla_nest_start(skb, a->order);
463 if (nest == NULL)
464 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 err = tcf_action_dump_1(skb, a, bind, ref);
466 if (err < 0)
Thomas Graf4fe683f2006-07-05 20:47:28 -0700467 goto errout;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800468 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
470
471 return 0;
472
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800473nla_put_failure:
Thomas Graf4fe683f2006-07-05 20:47:28 -0700474 err = -EINVAL;
475errout:
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800476 nla_nest_cancel(skb, nest);
Thomas Graf4fe683f2006-07-05 20:47:28 -0700477 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478}
479
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000480struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
481 struct nlattr *est, char *name, int ovr,
482 int bind)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
484 struct tc_action *a;
485 struct tc_action_ops *a_o;
486 char act_name[IFNAMSIZ];
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000487 struct nlattr *tb[TCA_ACT_MAX + 1];
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800488 struct nlattr *kind;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800489 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 if (name == NULL) {
Patrick McHardycee63722008-01-23 20:33:32 -0800492 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
493 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 goto err_out;
Patrick McHardycee63722008-01-23 20:33:32 -0800495 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800496 kind = tb[TCA_ACT_KIND];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 if (kind == NULL)
498 goto err_out;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800499 if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 goto err_out;
501 } else {
Patrick McHardycee63722008-01-23 20:33:32 -0800502 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 if (strlcpy(act_name, name, IFNAMSIZ) >= IFNAMSIZ)
504 goto err_out;
505 }
506
507 a_o = tc_lookup_action_n(act_name);
508 if (a_o == NULL) {
Johannes Berg95a5afc2008-10-16 15:24:51 -0700509#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 rtnl_unlock();
Patrick McHardy4bba3922006-01-08 22:22:14 -0800511 request_module("act_%s", act_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 rtnl_lock();
513
514 a_o = tc_lookup_action_n(act_name);
515
516 /* We dropped the RTNL semaphore in order to
517 * perform the module load. So, even if we
518 * succeeded in loading the module we have to
519 * tell the caller to replay the request. We
520 * indicate this using -EAGAIN.
521 */
522 if (a_o != NULL) {
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800523 err = -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 goto err_mod;
525 }
526#endif
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800527 err = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 goto err_out;
529 }
530
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800531 err = -ENOMEM;
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700532 a = kzalloc(sizeof(*a), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 if (a == NULL)
534 goto err_mod;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
WANG Congc779f7a2014-01-17 11:37:02 -0800536 a->ops = a_o;
WANG Cong33be6272013-12-15 20:15:05 -0800537 INIT_LIST_HEAD(&a->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 /* backward compatibility for policer */
539 if (name == NULL)
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000540 err = a_o->init(net, tb[TCA_ACT_OPTIONS], est, a, ovr, bind);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 else
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000542 err = a_o->init(net, nla, est, a, ovr, bind);
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800543 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 goto err_free;
545
546 /* module count goes up only when brand new policy is created
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000547 * if it exists and is only bound to in a_o->init() then
548 * ACT_P_CREATED is not returned (a zero is).
549 */
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800550 if (err != ACT_P_CREATED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 module_put(a_o->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 return a;
554
555err_free:
556 kfree(a);
557err_mod:
558 module_put(a_o->owner);
559err_out:
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800560 return ERR_PTR(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561}
562
WANG Cong33be6272013-12-15 20:15:05 -0800563int tcf_action_init(struct net *net, struct nlattr *nla,
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000564 struct nlattr *est, char *name, int ovr,
WANG Cong33be6272013-12-15 20:15:05 -0800565 int bind, struct list_head *actions)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566{
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000567 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
WANG Cong33be6272013-12-15 20:15:05 -0800568 struct tc_action *act;
Patrick McHardycee63722008-01-23 20:33:32 -0800569 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 int i;
571
Patrick McHardycee63722008-01-23 20:33:32 -0800572 err = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
573 if (err < 0)
WANG Cong33be6272013-12-15 20:15:05 -0800574 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800576 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000577 act = tcf_action_init_1(net, tb[i], est, name, ovr, bind);
WANG Cong33be6272013-12-15 20:15:05 -0800578 if (IS_ERR(act)) {
579 err = PTR_ERR(act);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 goto err;
WANG Cong33be6272013-12-15 20:15:05 -0800581 }
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800582 act->order = i;
WANG Cong33be6272013-12-15 20:15:05 -0800583 list_add_tail(&act->list, actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 }
WANG Cong33be6272013-12-15 20:15:05 -0800585 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587err:
WANG Cong33be6272013-12-15 20:15:05 -0800588 tcf_action_destroy(actions, bind);
589 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
591
592int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,
593 int compat_mode)
594{
595 int err = 0;
596 struct gnet_dump d;
WANG Cong7eb88962014-01-09 16:14:05 -0800597 struct tcf_common *p = a->priv;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900598
WANG Cong7eb88962014-01-09 16:14:05 -0800599 if (p == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 goto errout;
601
602 /* compat_mode being true specifies a call that is supposed
Dirk Hohndel06fe9fb2009-09-28 21:43:57 -0400603 * to add additional backward compatibility statistic TLVs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 */
605 if (compat_mode) {
606 if (a->type == TCA_OLD_COMPAT)
607 err = gnet_stats_start_copy_compat(skb, 0,
WANG Cong7eb88962014-01-09 16:14:05 -0800608 TCA_STATS, TCA_XSTATS, &p->tcfc_lock, &d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 else
610 return 0;
611 } else
612 err = gnet_stats_start_copy(skb, TCA_ACT_STATS,
WANG Cong7eb88962014-01-09 16:14:05 -0800613 &p->tcfc_lock, &d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 if (err < 0)
616 goto errout;
617
John Fastabend22e0f8b2014-09-28 11:52:56 -0700618 if (gnet_stats_copy_basic(&d, NULL, &p->tcfc_bstats) < 0 ||
WANG Cong7eb88962014-01-09 16:14:05 -0800619 gnet_stats_copy_rate_est(&d, &p->tcfc_bstats,
620 &p->tcfc_rate_est) < 0 ||
John Fastabendb0ab6f92014-09-28 11:54:24 -0700621 gnet_stats_copy_queue(&d, NULL,
John Fastabend64015852014-09-28 11:53:57 -0700622 &p->tcfc_qstats,
623 p->tcfc_qstats.qlen) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 goto errout;
625
626 if (gnet_stats_finish_copy(&d) < 0)
627 goto errout;
628
629 return 0;
630
631errout:
632 return -1;
633}
634
635static int
WANG Cong33be6272013-12-15 20:15:05 -0800636tca_get_fill(struct sk_buff *skb, struct list_head *actions, u32 portid, u32 seq,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900637 u16 flags, int event, int bind, int ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638{
639 struct tcamsg *t;
640 struct nlmsghdr *nlh;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700641 unsigned char *b = skb_tail_pointer(skb);
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800642 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Eric W. Biederman15e47302012-09-07 20:12:54 +0000644 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*t), flags);
David S. Miller8b00a532012-06-26 21:39:32 -0700645 if (!nlh)
646 goto out_nlmsg_trim;
647 t = nlmsg_data(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -0700649 t->tca__pad1 = 0;
650 t->tca__pad2 = 0;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900651
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800652 nest = nla_nest_start(skb, TCA_ACT_TAB);
653 if (nest == NULL)
David S. Miller8b00a532012-06-26 21:39:32 -0700654 goto out_nlmsg_trim;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
WANG Cong33be6272013-12-15 20:15:05 -0800656 if (tcf_action_dump(skb, actions, bind, ref) < 0)
David S. Miller8b00a532012-06-26 21:39:32 -0700657 goto out_nlmsg_trim;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800659 nla_nest_end(skb, nest);
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900660
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700661 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 return skb->len;
663
David S. Miller8b00a532012-06-26 21:39:32 -0700664out_nlmsg_trim:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700665 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 return -1;
667}
668
669static int
Eric W. Biederman15e47302012-09-07 20:12:54 +0000670act_get_notify(struct net *net, u32 portid, struct nlmsghdr *n,
WANG Cong33be6272013-12-15 20:15:05 -0800671 struct list_head *actions, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
673 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
676 if (!skb)
677 return -ENOBUFS;
WANG Cong33be6272013-12-15 20:15:05 -0800678 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, event, 0, 0) <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 kfree_skb(skb);
680 return -EINVAL;
681 }
Thomas Graf2942e902006-08-15 00:30:25 -0700682
Eric W. Biederman15e47302012-09-07 20:12:54 +0000683 return rtnl_unicast(skb, net, portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684}
685
WANG Cong03701d62014-02-11 17:07:35 -0800686static struct tc_action *create_a(int i)
687{
688 struct tc_action *act;
689
690 act = kzalloc(sizeof(*act), GFP_KERNEL);
691 if (act == NULL) {
692 pr_debug("create_a: failed to alloc!\n");
693 return NULL;
694 }
695 act->order = i;
696 INIT_LIST_HEAD(&act->list);
697 return act;
698}
699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700static struct tc_action *
Eric W. Biederman15e47302012-09-07 20:12:54 +0000701tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 portid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000703 struct nlattr *tb[TCA_ACT_MAX + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 struct tc_action *a;
705 int index;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800706 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Patrick McHardycee63722008-01-23 20:33:32 -0800708 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
709 if (err < 0)
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800710 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Patrick McHardycee63722008-01-23 20:33:32 -0800712 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800713 if (tb[TCA_ACT_INDEX] == NULL ||
714 nla_len(tb[TCA_ACT_INDEX]) < sizeof(index))
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800715 goto err_out;
Patrick McHardy1587bac2008-01-23 20:35:03 -0800716 index = nla_get_u32(tb[TCA_ACT_INDEX]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800718 err = -ENOMEM;
WANG Cong03701d62014-02-11 17:07:35 -0800719 a = create_a(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 if (a == NULL)
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800721 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800723 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800724 a->ops = tc_lookup_action(tb[TCA_ACT_KIND]);
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500725 if (a->ops == NULL) /* could happen in batch of actions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 goto err_free;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800727 err = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 if (a->ops->lookup(a, index) == 0)
729 goto err_mod;
730
731 module_put(a->ops->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 return a;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734err_mod:
735 module_put(a->ops->owner);
736err_free:
737 kfree(a);
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800738err_out:
739 return ERR_PTR(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740}
741
WANG Cong33be6272013-12-15 20:15:05 -0800742static void cleanup_a(struct list_head *actions)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743{
WANG Cong33be6272013-12-15 20:15:05 -0800744 struct tc_action *a, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
WANG Cong33be6272013-12-15 20:15:05 -0800746 list_for_each_entry_safe(a, tmp, actions, list) {
747 list_del(&a->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 kfree(a);
749 }
750}
751
Tom Goff7316ae82010-03-19 15:40:13 +0000752static int tca_action_flush(struct net *net, struct nlattr *nla,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000753 struct nlmsghdr *n, u32 portid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754{
755 struct sk_buff *skb;
756 unsigned char *b;
757 struct nlmsghdr *nlh;
758 struct tcamsg *t;
759 struct netlink_callback dcb;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800760 struct nlattr *nest;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000761 struct nlattr *tb[TCA_ACT_MAX + 1];
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800762 struct nlattr *kind;
WANG Cong03701d62014-02-11 17:07:35 -0800763 struct tc_action a;
Jamal Hadi Salim36723872008-08-13 02:41:45 -0700764 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
767 if (!skb) {
stephen hemminger6ff9c362010-05-12 06:37:05 +0000768 pr_debug("tca_action_flush: failed skb alloc\n");
Jamal Hadi Salim36723872008-08-13 02:41:45 -0700769 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 }
771
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700772 b = skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Patrick McHardycee63722008-01-23 20:33:32 -0800774 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
775 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 goto err_out;
777
Patrick McHardycee63722008-01-23 20:33:32 -0800778 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800779 kind = tb[TCA_ACT_KIND];
WANG Cong03701d62014-02-11 17:07:35 -0800780 memset(&a, 0, sizeof(struct tc_action));
781 INIT_LIST_HEAD(&a.list);
782 a.ops = tc_lookup_action(kind);
783 if (a.ops == NULL) /*some idjot trying to flush unknown action */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 goto err_out;
785
Eric W. Biederman15e47302012-09-07 20:12:54 +0000786 nlh = nlmsg_put(skb, portid, n->nlmsg_seq, RTM_DELACTION, sizeof(*t), 0);
David S. Miller8b00a532012-06-26 21:39:32 -0700787 if (!nlh)
788 goto out_module_put;
789 t = nlmsg_data(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -0700791 t->tca__pad1 = 0;
792 t->tca__pad2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800794 nest = nla_nest_start(skb, TCA_ACT_TAB);
795 if (nest == NULL)
David S. Miller8b00a532012-06-26 21:39:32 -0700796 goto out_module_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
WANG Cong03701d62014-02-11 17:07:35 -0800798 err = a.ops->walk(skb, &dcb, RTM_DELACTION, &a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 if (err < 0)
David S. Miller8b00a532012-06-26 21:39:32 -0700800 goto out_module_put;
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700801 if (err == 0)
802 goto noflush_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800804 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700806 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 nlh->nlmsg_flags |= NLM_F_ROOT;
WANG Cong03701d62014-02-11 17:07:35 -0800808 module_put(a.ops->owner);
Eric W. Biederman15e47302012-09-07 20:12:54 +0000809 err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000810 n->nlmsg_flags & NLM_F_ECHO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 if (err > 0)
812 return 0;
813
814 return err;
815
David S. Miller8b00a532012-06-26 21:39:32 -0700816out_module_put:
WANG Cong03701d62014-02-11 17:07:35 -0800817 module_put(a.ops->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818err_out:
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700819noflush_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 return err;
822}
823
824static int
WANG Conga56e1952014-01-09 16:14:00 -0800825tcf_del_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
826 u32 portid)
827{
828 int ret;
829 struct sk_buff *skb;
830
831 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
832 if (!skb)
833 return -ENOBUFS;
834
835 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, RTM_DELACTION,
836 0, 1) <= 0) {
837 kfree_skb(skb);
838 return -EINVAL;
839 }
840
841 /* now do the delete */
WANG Cong55334a52014-02-11 17:07:34 -0800842 ret = tcf_action_destroy(actions, 0);
843 if (ret < 0) {
844 kfree_skb(skb);
845 return ret;
846 }
WANG Conga56e1952014-01-09 16:14:00 -0800847
848 ret = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
849 n->nlmsg_flags & NLM_F_ECHO);
850 if (ret > 0)
851 return 0;
852 return ret;
853}
854
855static int
Tom Goff7316ae82010-03-19 15:40:13 +0000856tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000857 u32 portid, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858{
Patrick McHardycee63722008-01-23 20:33:32 -0800859 int i, ret;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000860 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
WANG Cong33be6272013-12-15 20:15:05 -0800861 struct tc_action *act;
862 LIST_HEAD(actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
Patrick McHardycee63722008-01-23 20:33:32 -0800864 ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
865 if (ret < 0)
866 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000868 if (event == RTM_DELACTION && n->nlmsg_flags & NLM_F_ROOT) {
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700869 if (tb[1] != NULL)
Eric W. Biederman15e47302012-09-07 20:12:54 +0000870 return tca_action_flush(net, tb[1], n, portid);
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700871 else
872 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 }
874
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800875 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
Eric W. Biederman15e47302012-09-07 20:12:54 +0000876 act = tcf_action_get_1(tb[i], n, portid);
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800877 if (IS_ERR(act)) {
878 ret = PTR_ERR(act);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 goto err;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800880 }
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800881 act->order = i;
WANG Cong33be6272013-12-15 20:15:05 -0800882 list_add_tail(&act->list, &actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 }
884
885 if (event == RTM_GETACTION)
WANG Cong33be6272013-12-15 20:15:05 -0800886 ret = act_get_notify(net, portid, n, &actions, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 else { /* delete */
WANG Conga56e1952014-01-09 16:14:00 -0800888 ret = tcf_del_notify(net, n, &actions, portid);
889 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 return ret;
892 }
893err:
WANG Cong33be6272013-12-15 20:15:05 -0800894 cleanup_a(&actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 return ret;
896}
897
WANG Conga56e1952014-01-09 16:14:00 -0800898static int
899tcf_add_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
900 u32 portid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 int err = 0;
904
905 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
906 if (!skb)
907 return -ENOBUFS;
908
WANG Conga56e1952014-01-09 16:14:00 -0800909 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, n->nlmsg_flags,
910 RTM_NEWACTION, 0, 0) <= 0) {
911 kfree_skb(skb);
912 return -EINVAL;
913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
WANG Conga56e1952014-01-09 16:14:00 -0800915 err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
916 n->nlmsg_flags & NLM_F_ECHO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 if (err > 0)
918 err = 0;
919 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920}
921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922static int
Tom Goff7316ae82010-03-19 15:40:13 +0000923tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000924 u32 portid, int ovr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925{
926 int ret = 0;
WANG Cong33be6272013-12-15 20:15:05 -0800927 LIST_HEAD(actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
WANG Cong33be6272013-12-15 20:15:05 -0800929 ret = tcf_action_init(net, nla, NULL, NULL, ovr, 0, &actions);
930 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 goto done;
932
933 /* dump then free all the actions after update; inserted policy
934 * stays intact
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000935 */
WANG Conga56e1952014-01-09 16:14:00 -0800936 ret = tcf_add_notify(net, n, &actions, portid);
WANG Cong33be6272013-12-15 20:15:05 -0800937 cleanup_a(&actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938done:
939 return ret;
940}
941
Thomas Graf661d2962013-03-21 07:45:29 +0000942static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900944 struct net *net = sock_net(skb->sk);
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800945 struct nlattr *tca[TCA_ACT_MAX + 1];
Eric W. Biederman15e47302012-09-07 20:12:54 +0000946 u32 portid = skb ? NETLINK_CB(skb).portid : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 int ret = 0, ovr = 0;
948
Eric W. Biederman90f62cf2014-04-23 14:29:27 -0700949 if ((n->nlmsg_type != RTM_GETACTION) && !netlink_capable(skb, CAP_NET_ADMIN))
Eric W. Biedermandfc47ef2012-11-16 03:03:00 +0000950 return -EPERM;
951
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800952 ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL);
953 if (ret < 0)
954 return ret;
955
956 if (tca[TCA_ACT_TAB] == NULL) {
stephen hemminger6ff9c362010-05-12 06:37:05 +0000957 pr_notice("tc_ctl_action: received NO action attribs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 return -EINVAL;
959 }
960
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000961 /* n->nlmsg_flags & NLM_F_CREATE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 switch (n->nlmsg_type) {
963 case RTM_NEWACTION:
964 /* we are going to assume all other flags
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300965 * imply create only if it doesn't exist
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 * Note that CREATE | EXCL implies that
967 * but since we want avoid ambiguity (eg when flags
968 * is zero) then just set this
969 */
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000970 if (n->nlmsg_flags & NLM_F_REPLACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 ovr = 1;
972replay:
Eric W. Biederman15e47302012-09-07 20:12:54 +0000973 ret = tcf_action_add(net, tca[TCA_ACT_TAB], n, portid, ovr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 if (ret == -EAGAIN)
975 goto replay;
976 break;
977 case RTM_DELACTION:
Tom Goff7316ae82010-03-19 15:40:13 +0000978 ret = tca_action_gd(net, tca[TCA_ACT_TAB], n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000979 portid, RTM_DELACTION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 break;
981 case RTM_GETACTION:
Tom Goff7316ae82010-03-19 15:40:13 +0000982 ret = tca_action_gd(net, tca[TCA_ACT_TAB], n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000983 portid, RTM_GETACTION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 break;
985 default:
986 BUG();
987 }
988
989 return ret;
990}
991
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800992static struct nlattr *
Patrick McHardy3a6c2b42009-08-25 16:07:40 +0200993find_dump_kind(const struct nlmsghdr *n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000995 struct nlattr *tb1, *tb2[TCA_ACT_MAX + 1];
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800996 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
997 struct nlattr *nla[TCAA_MAX + 1];
998 struct nlattr *kind;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
Patrick McHardyc96c9472008-01-23 20:32:58 -08001000 if (nlmsg_parse(n, sizeof(struct tcamsg), nla, TCAA_MAX, NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 return NULL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001002 tb1 = nla[TCA_ACT_TAB];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 if (tb1 == NULL)
1004 return NULL;
1005
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001006 if (nla_parse(tb, TCA_ACT_MAX_PRIO, nla_data(tb1),
1007 NLMSG_ALIGN(nla_len(tb1)), NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Patrick McHardy6d834e02008-01-23 20:32:42 -08001010 if (tb[1] == NULL)
1011 return NULL;
1012 if (nla_parse(tb2, TCA_ACT_MAX, nla_data(tb[1]),
1013 nla_len(tb[1]), NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 return NULL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001015 kind = tb2[TCA_ACT_KIND];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Thomas Graf26dab892006-07-05 20:45:06 -07001017 return kind;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018}
1019
1020static int
1021tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
1022{
1023 struct nlmsghdr *nlh;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001024 unsigned char *b = skb_tail_pointer(skb);
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001025 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 struct tc_action_ops *a_o;
1027 struct tc_action a;
1028 int ret = 0;
David S. Miller8b00a532012-06-26 21:39:32 -07001029 struct tcamsg *t = (struct tcamsg *) nlmsg_data(cb->nlh);
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001030 struct nlattr *kind = find_dump_kind(cb->nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
1032 if (kind == NULL) {
stephen hemminger6ff9c362010-05-12 06:37:05 +00001033 pr_info("tc_dump_action: action bad kind\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 return 0;
1035 }
1036
Thomas Graf26dab892006-07-05 20:45:06 -07001037 a_o = tc_lookup_action(kind);
Eric Dumazetcc7ec452011-01-19 19:26:56 +00001038 if (a_o == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
1041 memset(&a, 0, sizeof(struct tc_action));
1042 a.ops = a_o;
1043
Eric W. Biederman15e47302012-09-07 20:12:54 +00001044 nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
David S. Miller8b00a532012-06-26 21:39:32 -07001045 cb->nlh->nlmsg_type, sizeof(*t), 0);
1046 if (!nlh)
1047 goto out_module_put;
1048 t = nlmsg_data(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -07001050 t->tca__pad1 = 0;
1051 t->tca__pad2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001053 nest = nla_nest_start(skb, TCA_ACT_TAB);
1054 if (nest == NULL)
David S. Miller8b00a532012-06-26 21:39:32 -07001055 goto out_module_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
1057 ret = a_o->walk(skb, cb, RTM_GETACTION, &a);
1058 if (ret < 0)
David S. Miller8b00a532012-06-26 21:39:32 -07001059 goto out_module_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
1061 if (ret > 0) {
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001062 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 ret = skb->len;
1064 } else
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001065 nla_nest_cancel(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001067 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Eric W. Biederman15e47302012-09-07 20:12:54 +00001068 if (NETLINK_CB(cb->skb).portid && ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 nlh->nlmsg_flags |= NLM_F_MULTI;
1070 module_put(a_o->owner);
1071 return skb->len;
1072
David S. Miller8b00a532012-06-26 21:39:32 -07001073out_module_put:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 module_put(a_o->owner);
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -07001075 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 return skb->len;
1077}
1078
1079static int __init tc_action_init(void)
1080{
Greg Rosec7ac8672011-06-10 01:27:09 +00001081 rtnl_register(PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL, NULL);
1082 rtnl_register(PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL, NULL);
1083 rtnl_register(PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action,
1084 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 return 0;
1087}
1088
1089subsys_initcall(tc_action_init);