blob: 648778aef1a254b9739443e93012798a134d0d86 [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) {
255 int err = gen_new_estimator(&p->tcfc_bstats, &p->tcfc_rate_est,
256 &p->tcfc_lock, est);
257 if (err) {
258 kfree(p);
WANG Cong86062032014-02-11 17:07:31 -0800259 return err;
Stephen Hemminger0e991ec2008-11-25 21:12:32 -0800260 }
261 }
262
David S. Millere9ce1cd2006-08-21 23:54:55 -0700263 a->priv = (void *) p;
WANG Cong86062032014-02-11 17:07:31 -0800264 return 0;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700265}
266EXPORT_SYMBOL(tcf_hash_create);
267
WANG Cong86062032014-02-11 17:07:31 -0800268void tcf_hash_insert(struct tc_action *a)
David S. Millere9ce1cd2006-08-21 23:54:55 -0700269{
WANG Cong86062032014-02-11 17:07:31 -0800270 struct tcf_common *p = a->priv;
271 struct tcf_hashinfo *hinfo = a->ops->hinfo;
David S. Millere9ce1cd2006-08-21 23:54:55 -0700272 unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask);
273
WANG Cong89819dc2013-12-15 20:15:09 -0800274 spin_lock_bh(&hinfo->lock);
275 hlist_add_head(&p->tcfc_head, &hinfo->htab[h]);
276 spin_unlock_bh(&hinfo->lock);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700277}
278EXPORT_SYMBOL(tcf_hash_insert);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
WANG Cong1f747c22013-12-15 20:15:10 -0800280static LIST_HEAD(act_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281static DEFINE_RWLOCK(act_mod_lock);
282
WANG Cong4f1e9d82014-02-11 17:07:33 -0800283int tcf_register_action(struct tc_action_ops *act, unsigned int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
WANG Cong1f747c22013-12-15 20:15:10 -0800285 struct tc_action_ops *a;
WANG Cong4f1e9d82014-02-11 17:07:33 -0800286 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
WANG Conga5b5c952014-02-11 17:07:32 -0800288 /* Must supply act, dump and init */
289 if (!act->act || !act->dump || !act->init)
Jamal Hadi Salim76c82d72013-12-04 09:26:52 -0500290 return -EINVAL;
291
Jamal Hadi Salim382ca8a2013-12-04 09:26:55 -0500292 /* Supply defaults */
Jamal Hadi Salim63ef6172013-12-04 09:26:53 -0500293 if (!act->lookup)
294 act->lookup = tcf_hash_search;
Jamal Hadi Salim382ca8a2013-12-04 09:26:55 -0500295 if (!act->walk)
296 act->walk = tcf_generic_walker;
Jamal Hadi Salim63ef6172013-12-04 09:26:53 -0500297
WANG Cong4f1e9d82014-02-11 17:07:33 -0800298 act->hinfo = kmalloc(sizeof(struct tcf_hashinfo), GFP_KERNEL);
299 if (!act->hinfo)
300 return -ENOMEM;
301 err = tcf_hashinfo_init(act->hinfo, mask);
302 if (err) {
303 kfree(act->hinfo);
304 return err;
305 }
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 write_lock(&act_mod_lock);
WANG Cong1f747c22013-12-15 20:15:10 -0800308 list_for_each_entry(a, &act_base, head) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) {
310 write_unlock(&act_mod_lock);
WANG Cong4f1e9d82014-02-11 17:07:33 -0800311 tcf_hashinfo_destroy(act->hinfo);
312 kfree(act->hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 return -EEXIST;
314 }
315 }
WANG Cong1f747c22013-12-15 20:15:10 -0800316 list_add_tail(&act->head, &act_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 write_unlock(&act_mod_lock);
318 return 0;
319}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800320EXPORT_SYMBOL(tcf_register_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322int tcf_unregister_action(struct tc_action_ops *act)
323{
WANG Cong1f747c22013-12-15 20:15:10 -0800324 struct tc_action_ops *a;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 int err = -ENOENT;
326
327 write_lock(&act_mod_lock);
Eric Dumazeta7928662013-12-20 12:32:32 -0800328 list_for_each_entry(a, &act_base, head) {
329 if (a == act) {
330 list_del(&act->head);
WANG Cong4f1e9d82014-02-11 17:07:33 -0800331 tcf_hashinfo_destroy(act->hinfo);
332 kfree(act->hinfo);
Eric Dumazeta7928662013-12-20 12:32:32 -0800333 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 break;
Eric Dumazeta7928662013-12-20 12:32:32 -0800335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 }
337 write_unlock(&act_mod_lock);
338 return err;
339}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800340EXPORT_SYMBOL(tcf_unregister_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342/* lookup by name */
343static struct tc_action_ops *tc_lookup_action_n(char *kind)
344{
Eric Dumazeta7928662013-12-20 12:32:32 -0800345 struct tc_action_ops *a, *res = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 if (kind) {
348 read_lock(&act_mod_lock);
WANG Cong1f747c22013-12-15 20:15:10 -0800349 list_for_each_entry(a, &act_base, head) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (strcmp(kind, a->kind) == 0) {
Eric Dumazeta7928662013-12-20 12:32:32 -0800351 if (try_module_get(a->owner))
352 res = a;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 break;
354 }
355 }
356 read_unlock(&act_mod_lock);
357 }
Eric Dumazeta7928662013-12-20 12:32:32 -0800358 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800361/* lookup by nlattr */
362static struct tc_action_ops *tc_lookup_action(struct nlattr *kind)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Eric Dumazeta7928662013-12-20 12:32:32 -0800364 struct tc_action_ops *a, *res = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 if (kind) {
367 read_lock(&act_mod_lock);
WANG Cong1f747c22013-12-15 20:15:10 -0800368 list_for_each_entry(a, &act_base, head) {
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800369 if (nla_strcmp(kind, a->kind) == 0) {
Eric Dumazeta7928662013-12-20 12:32:32 -0800370 if (try_module_get(a->owner))
371 res = a;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 break;
373 }
374 }
375 read_unlock(&act_mod_lock);
376 }
Eric Dumazeta7928662013-12-20 12:32:32 -0800377 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
WANG Cong33be6272013-12-15 20:15:05 -0800380int tcf_action_exec(struct sk_buff *skb, const struct list_head *actions,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900381 struct tcf_result *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
Eric Dumazetdc7f9f62011-07-05 23:25:42 +0000383 const struct tc_action *a;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 int ret = -1;
385
386 if (skb->tc_verd & TC_NCLS) {
387 skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 ret = TC_ACT_OK;
389 goto exec_done;
390 }
WANG Cong33be6272013-12-15 20:15:05 -0800391 list_for_each_entry(a, actions, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392repeat:
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500393 ret = a->ops->act(skb, a, res);
394 if (TC_MUNGED & skb->tc_verd) {
395 /* copied already, allow trampling */
396 skb->tc_verd = SET_TC_OK2MUNGE(skb->tc_verd);
397 skb->tc_verd = CLR_TC_MUNGED(skb->tc_verd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 }
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500399 if (ret == TC_ACT_REPEAT)
400 goto repeat; /* we need a ttl - JHS */
401 if (ret != TC_ACT_PIPE)
402 goto exec_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 }
404exec_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 return ret;
406}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800407EXPORT_SYMBOL(tcf_action_exec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
WANG Cong55334a52014-02-11 17:07:34 -0800409int tcf_action_destroy(struct list_head *actions, int bind)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
WANG Cong33be6272013-12-15 20:15:05 -0800411 struct tc_action *a, *tmp;
WANG Cong55334a52014-02-11 17:07:34 -0800412 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
WANG Cong33be6272013-12-15 20:15:05 -0800414 list_for_each_entry_safe(a, tmp, actions, list) {
WANG Cong55334a52014-02-11 17:07:34 -0800415 ret = tcf_hash_release(a, bind);
416 if (ret == ACT_P_DELETED)
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500417 module_put(a->ops->owner);
WANG Cong55334a52014-02-11 17:07:34 -0800418 else if (ret < 0)
419 return ret;
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500420 list_del(&a->list);
421 kfree(a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 }
WANG Cong55334a52014-02-11 17:07:34 -0800423 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424}
425
426int
427tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
428{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 return a->ops->dump(skb, a, bind, ref);
430}
431
432int
433tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
434{
435 int err = -EINVAL;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700436 unsigned char *b = skb_tail_pointer(skb);
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800437 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
David S. Miller1b34ec42012-03-29 05:11:39 -0400439 if (nla_put_string(skb, TCA_KIND, a->ops->kind))
440 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 if (tcf_action_copy_stats(skb, a, 0))
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800442 goto nla_put_failure;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800443 nest = nla_nest_start(skb, TCA_OPTIONS);
444 if (nest == NULL)
445 goto nla_put_failure;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000446 err = tcf_action_dump_old(skb, a, bind, ref);
447 if (err > 0) {
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800448 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 return err;
450 }
451
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800452nla_put_failure:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700453 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 return -1;
455}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800456EXPORT_SYMBOL(tcf_action_dump_1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458int
WANG Cong33be6272013-12-15 20:15:05 -0800459tcf_action_dump(struct sk_buff *skb, struct list_head *actions, int bind, int ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460{
461 struct tc_action *a;
462 int err = -EINVAL;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800463 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
WANG Cong33be6272013-12-15 20:15:05 -0800465 list_for_each_entry(a, actions, list) {
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800466 nest = nla_nest_start(skb, a->order);
467 if (nest == NULL)
468 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 err = tcf_action_dump_1(skb, a, bind, ref);
470 if (err < 0)
Thomas Graf4fe683f2006-07-05 20:47:28 -0700471 goto errout;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800472 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 }
474
475 return 0;
476
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800477nla_put_failure:
Thomas Graf4fe683f2006-07-05 20:47:28 -0700478 err = -EINVAL;
479errout:
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800480 nla_nest_cancel(skb, nest);
Thomas Graf4fe683f2006-07-05 20:47:28 -0700481 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482}
483
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000484struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
485 struct nlattr *est, char *name, int ovr,
486 int bind)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487{
488 struct tc_action *a;
489 struct tc_action_ops *a_o;
490 char act_name[IFNAMSIZ];
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000491 struct nlattr *tb[TCA_ACT_MAX + 1];
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800492 struct nlattr *kind;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800493 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (name == NULL) {
Patrick McHardycee63722008-01-23 20:33:32 -0800496 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
497 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 goto err_out;
Patrick McHardycee63722008-01-23 20:33:32 -0800499 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800500 kind = tb[TCA_ACT_KIND];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 if (kind == NULL)
502 goto err_out;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800503 if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 goto err_out;
505 } else {
Patrick McHardycee63722008-01-23 20:33:32 -0800506 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 if (strlcpy(act_name, name, IFNAMSIZ) >= IFNAMSIZ)
508 goto err_out;
509 }
510
511 a_o = tc_lookup_action_n(act_name);
512 if (a_o == NULL) {
Johannes Berg95a5afc2008-10-16 15:24:51 -0700513#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 rtnl_unlock();
Patrick McHardy4bba3922006-01-08 22:22:14 -0800515 request_module("act_%s", act_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 rtnl_lock();
517
518 a_o = tc_lookup_action_n(act_name);
519
520 /* We dropped the RTNL semaphore in order to
521 * perform the module load. So, even if we
522 * succeeded in loading the module we have to
523 * tell the caller to replay the request. We
524 * indicate this using -EAGAIN.
525 */
526 if (a_o != NULL) {
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800527 err = -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 goto err_mod;
529 }
530#endif
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800531 err = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 goto err_out;
533 }
534
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800535 err = -ENOMEM;
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700536 a = kzalloc(sizeof(*a), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 if (a == NULL)
538 goto err_mod;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
WANG Congc779f7a2014-01-17 11:37:02 -0800540 a->ops = a_o;
WANG Cong33be6272013-12-15 20:15:05 -0800541 INIT_LIST_HEAD(&a->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 /* backward compatibility for policer */
543 if (name == NULL)
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000544 err = a_o->init(net, tb[TCA_ACT_OPTIONS], est, a, ovr, bind);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 else
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000546 err = a_o->init(net, nla, est, a, ovr, bind);
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800547 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 goto err_free;
549
550 /* module count goes up only when brand new policy is created
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000551 * if it exists and is only bound to in a_o->init() then
552 * ACT_P_CREATED is not returned (a zero is).
553 */
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800554 if (err != ACT_P_CREATED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 module_put(a_o->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 return a;
558
559err_free:
560 kfree(a);
561err_mod:
562 module_put(a_o->owner);
563err_out:
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800564 return ERR_PTR(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565}
566
WANG Cong33be6272013-12-15 20:15:05 -0800567int tcf_action_init(struct net *net, struct nlattr *nla,
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000568 struct nlattr *est, char *name, int ovr,
WANG Cong33be6272013-12-15 20:15:05 -0800569 int bind, struct list_head *actions)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000571 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
WANG Cong33be6272013-12-15 20:15:05 -0800572 struct tc_action *act;
Patrick McHardycee63722008-01-23 20:33:32 -0800573 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 int i;
575
Patrick McHardycee63722008-01-23 20:33:32 -0800576 err = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
577 if (err < 0)
WANG Cong33be6272013-12-15 20:15:05 -0800578 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800580 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000581 act = tcf_action_init_1(net, tb[i], est, name, ovr, bind);
WANG Cong33be6272013-12-15 20:15:05 -0800582 if (IS_ERR(act)) {
583 err = PTR_ERR(act);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 goto err;
WANG Cong33be6272013-12-15 20:15:05 -0800585 }
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800586 act->order = i;
WANG Cong33be6272013-12-15 20:15:05 -0800587 list_add_tail(&act->list, actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
WANG Cong33be6272013-12-15 20:15:05 -0800589 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591err:
WANG Cong33be6272013-12-15 20:15:05 -0800592 tcf_action_destroy(actions, bind);
593 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594}
595
596int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,
597 int compat_mode)
598{
599 int err = 0;
600 struct gnet_dump d;
WANG Cong7eb88962014-01-09 16:14:05 -0800601 struct tcf_common *p = a->priv;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900602
WANG Cong7eb88962014-01-09 16:14:05 -0800603 if (p == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 goto errout;
605
606 /* compat_mode being true specifies a call that is supposed
Dirk Hohndel06fe9fb2009-09-28 21:43:57 -0400607 * to add additional backward compatibility statistic TLVs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 */
609 if (compat_mode) {
610 if (a->type == TCA_OLD_COMPAT)
611 err = gnet_stats_start_copy_compat(skb, 0,
WANG Cong7eb88962014-01-09 16:14:05 -0800612 TCA_STATS, TCA_XSTATS, &p->tcfc_lock, &d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 else
614 return 0;
615 } else
616 err = gnet_stats_start_copy(skb, TCA_ACT_STATS,
WANG Cong7eb88962014-01-09 16:14:05 -0800617 &p->tcfc_lock, &d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
619 if (err < 0)
620 goto errout;
621
WANG Cong7eb88962014-01-09 16:14:05 -0800622 if (gnet_stats_copy_basic(&d, &p->tcfc_bstats) < 0 ||
623 gnet_stats_copy_rate_est(&d, &p->tcfc_bstats,
624 &p->tcfc_rate_est) < 0 ||
625 gnet_stats_copy_queue(&d, &p->tcfc_qstats) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 goto errout;
627
628 if (gnet_stats_finish_copy(&d) < 0)
629 goto errout;
630
631 return 0;
632
633errout:
634 return -1;
635}
636
637static int
WANG Cong33be6272013-12-15 20:15:05 -0800638tca_get_fill(struct sk_buff *skb, struct list_head *actions, u32 portid, u32 seq,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900639 u16 flags, int event, int bind, int ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640{
641 struct tcamsg *t;
642 struct nlmsghdr *nlh;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700643 unsigned char *b = skb_tail_pointer(skb);
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800644 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Eric W. Biederman15e47302012-09-07 20:12:54 +0000646 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*t), flags);
David S. Miller8b00a532012-06-26 21:39:32 -0700647 if (!nlh)
648 goto out_nlmsg_trim;
649 t = nlmsg_data(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -0700651 t->tca__pad1 = 0;
652 t->tca__pad2 = 0;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900653
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800654 nest = nla_nest_start(skb, TCA_ACT_TAB);
655 if (nest == NULL)
David S. Miller8b00a532012-06-26 21:39:32 -0700656 goto out_nlmsg_trim;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
WANG Cong33be6272013-12-15 20:15:05 -0800658 if (tcf_action_dump(skb, actions, bind, ref) < 0)
David S. Miller8b00a532012-06-26 21:39:32 -0700659 goto out_nlmsg_trim;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800661 nla_nest_end(skb, nest);
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900662
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700663 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 return skb->len;
665
David S. Miller8b00a532012-06-26 21:39:32 -0700666out_nlmsg_trim:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700667 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 return -1;
669}
670
671static int
Eric W. Biederman15e47302012-09-07 20:12:54 +0000672act_get_notify(struct net *net, u32 portid, struct nlmsghdr *n,
WANG Cong33be6272013-12-15 20:15:05 -0800673 struct list_head *actions, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
675 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
677 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
678 if (!skb)
679 return -ENOBUFS;
WANG Cong33be6272013-12-15 20:15:05 -0800680 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, event, 0, 0) <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 kfree_skb(skb);
682 return -EINVAL;
683 }
Thomas Graf2942e902006-08-15 00:30:25 -0700684
Eric W. Biederman15e47302012-09-07 20:12:54 +0000685 return rtnl_unicast(skb, net, portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686}
687
WANG Cong03701d62014-02-11 17:07:35 -0800688static struct tc_action *create_a(int i)
689{
690 struct tc_action *act;
691
692 act = kzalloc(sizeof(*act), GFP_KERNEL);
693 if (act == NULL) {
694 pr_debug("create_a: failed to alloc!\n");
695 return NULL;
696 }
697 act->order = i;
698 INIT_LIST_HEAD(&act->list);
699 return act;
700}
701
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702static struct tc_action *
Eric W. Biederman15e47302012-09-07 20:12:54 +0000703tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 portid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704{
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000705 struct nlattr *tb[TCA_ACT_MAX + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 struct tc_action *a;
707 int index;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800708 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Patrick McHardycee63722008-01-23 20:33:32 -0800710 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
711 if (err < 0)
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800712 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Patrick McHardycee63722008-01-23 20:33:32 -0800714 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800715 if (tb[TCA_ACT_INDEX] == NULL ||
716 nla_len(tb[TCA_ACT_INDEX]) < sizeof(index))
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800717 goto err_out;
Patrick McHardy1587bac2008-01-23 20:35:03 -0800718 index = nla_get_u32(tb[TCA_ACT_INDEX]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800720 err = -ENOMEM;
WANG Cong03701d62014-02-11 17:07:35 -0800721 a = create_a(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 if (a == NULL)
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800723 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800725 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800726 a->ops = tc_lookup_action(tb[TCA_ACT_KIND]);
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500727 if (a->ops == NULL) /* could happen in batch of actions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 goto err_free;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800729 err = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 if (a->ops->lookup(a, index) == 0)
731 goto err_mod;
732
733 module_put(a->ops->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 return a;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736err_mod:
737 module_put(a->ops->owner);
738err_free:
739 kfree(a);
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800740err_out:
741 return ERR_PTR(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
743
WANG Cong33be6272013-12-15 20:15:05 -0800744static void cleanup_a(struct list_head *actions)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745{
WANG Cong33be6272013-12-15 20:15:05 -0800746 struct tc_action *a, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
WANG Cong33be6272013-12-15 20:15:05 -0800748 list_for_each_entry_safe(a, tmp, actions, list) {
749 list_del(&a->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 kfree(a);
751 }
752}
753
Tom Goff7316ae82010-03-19 15:40:13 +0000754static int tca_action_flush(struct net *net, struct nlattr *nla,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000755 struct nlmsghdr *n, u32 portid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756{
757 struct sk_buff *skb;
758 unsigned char *b;
759 struct nlmsghdr *nlh;
760 struct tcamsg *t;
761 struct netlink_callback dcb;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800762 struct nlattr *nest;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000763 struct nlattr *tb[TCA_ACT_MAX + 1];
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800764 struct nlattr *kind;
WANG Cong03701d62014-02-11 17:07:35 -0800765 struct tc_action a;
Jamal Hadi Salim36723872008-08-13 02:41:45 -0700766 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
769 if (!skb) {
stephen hemminger6ff9c362010-05-12 06:37:05 +0000770 pr_debug("tca_action_flush: failed skb alloc\n");
Jamal Hadi Salim36723872008-08-13 02:41:45 -0700771 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 }
773
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700774 b = skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Patrick McHardycee63722008-01-23 20:33:32 -0800776 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
777 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 goto err_out;
779
Patrick McHardycee63722008-01-23 20:33:32 -0800780 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800781 kind = tb[TCA_ACT_KIND];
WANG Cong03701d62014-02-11 17:07:35 -0800782 memset(&a, 0, sizeof(struct tc_action));
783 INIT_LIST_HEAD(&a.list);
784 a.ops = tc_lookup_action(kind);
785 if (a.ops == NULL) /*some idjot trying to flush unknown action */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 goto err_out;
787
Eric W. Biederman15e47302012-09-07 20:12:54 +0000788 nlh = nlmsg_put(skb, portid, n->nlmsg_seq, RTM_DELACTION, sizeof(*t), 0);
David S. Miller8b00a532012-06-26 21:39:32 -0700789 if (!nlh)
790 goto out_module_put;
791 t = nlmsg_data(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -0700793 t->tca__pad1 = 0;
794 t->tca__pad2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800796 nest = nla_nest_start(skb, TCA_ACT_TAB);
797 if (nest == NULL)
David S. Miller8b00a532012-06-26 21:39:32 -0700798 goto out_module_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
WANG Cong03701d62014-02-11 17:07:35 -0800800 err = a.ops->walk(skb, &dcb, RTM_DELACTION, &a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 if (err < 0)
David S. Miller8b00a532012-06-26 21:39:32 -0700802 goto out_module_put;
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700803 if (err == 0)
804 goto noflush_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800806 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700808 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 nlh->nlmsg_flags |= NLM_F_ROOT;
WANG Cong03701d62014-02-11 17:07:35 -0800810 module_put(a.ops->owner);
Eric W. Biederman15e47302012-09-07 20:12:54 +0000811 err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000812 n->nlmsg_flags & NLM_F_ECHO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 if (err > 0)
814 return 0;
815
816 return err;
817
David S. Miller8b00a532012-06-26 21:39:32 -0700818out_module_put:
WANG Cong03701d62014-02-11 17:07:35 -0800819 module_put(a.ops->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820err_out:
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700821noflush_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 return err;
824}
825
826static int
WANG Conga56e1952014-01-09 16:14:00 -0800827tcf_del_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
828 u32 portid)
829{
830 int ret;
831 struct sk_buff *skb;
832
833 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
834 if (!skb)
835 return -ENOBUFS;
836
837 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, RTM_DELACTION,
838 0, 1) <= 0) {
839 kfree_skb(skb);
840 return -EINVAL;
841 }
842
843 /* now do the delete */
WANG Cong55334a52014-02-11 17:07:34 -0800844 ret = tcf_action_destroy(actions, 0);
845 if (ret < 0) {
846 kfree_skb(skb);
847 return ret;
848 }
WANG Conga56e1952014-01-09 16:14:00 -0800849
850 ret = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
851 n->nlmsg_flags & NLM_F_ECHO);
852 if (ret > 0)
853 return 0;
854 return ret;
855}
856
857static int
Tom Goff7316ae82010-03-19 15:40:13 +0000858tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000859 u32 portid, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860{
Patrick McHardycee63722008-01-23 20:33:32 -0800861 int i, ret;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000862 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
WANG Cong33be6272013-12-15 20:15:05 -0800863 struct tc_action *act;
864 LIST_HEAD(actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Patrick McHardycee63722008-01-23 20:33:32 -0800866 ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
867 if (ret < 0)
868 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000870 if (event == RTM_DELACTION && n->nlmsg_flags & NLM_F_ROOT) {
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700871 if (tb[1] != NULL)
Eric W. Biederman15e47302012-09-07 20:12:54 +0000872 return tca_action_flush(net, tb[1], n, portid);
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700873 else
874 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 }
876
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800877 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
Eric W. Biederman15e47302012-09-07 20:12:54 +0000878 act = tcf_action_get_1(tb[i], n, portid);
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800879 if (IS_ERR(act)) {
880 ret = PTR_ERR(act);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 goto err;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800882 }
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800883 act->order = i;
WANG Cong33be6272013-12-15 20:15:05 -0800884 list_add_tail(&act->list, &actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 }
886
887 if (event == RTM_GETACTION)
WANG Cong33be6272013-12-15 20:15:05 -0800888 ret = act_get_notify(net, portid, n, &actions, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 else { /* delete */
WANG Conga56e1952014-01-09 16:14:00 -0800890 ret = tcf_del_notify(net, n, &actions, portid);
891 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 return ret;
894 }
895err:
WANG Cong33be6272013-12-15 20:15:05 -0800896 cleanup_a(&actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 return ret;
898}
899
WANG Conga56e1952014-01-09 16:14:00 -0800900static int
901tcf_add_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
902 u32 portid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 int err = 0;
906
907 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
908 if (!skb)
909 return -ENOBUFS;
910
WANG Conga56e1952014-01-09 16:14:00 -0800911 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, n->nlmsg_flags,
912 RTM_NEWACTION, 0, 0) <= 0) {
913 kfree_skb(skb);
914 return -EINVAL;
915 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
WANG Conga56e1952014-01-09 16:14:00 -0800917 err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
918 n->nlmsg_flags & NLM_F_ECHO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 if (err > 0)
920 err = 0;
921 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922}
923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924static int
Tom Goff7316ae82010-03-19 15:40:13 +0000925tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000926 u32 portid, int ovr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927{
928 int ret = 0;
WANG Cong33be6272013-12-15 20:15:05 -0800929 LIST_HEAD(actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
WANG Cong33be6272013-12-15 20:15:05 -0800931 ret = tcf_action_init(net, nla, NULL, NULL, ovr, 0, &actions);
932 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 goto done;
934
935 /* dump then free all the actions after update; inserted policy
936 * stays intact
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000937 */
WANG Conga56e1952014-01-09 16:14:00 -0800938 ret = tcf_add_notify(net, n, &actions, portid);
WANG Cong33be6272013-12-15 20:15:05 -0800939 cleanup_a(&actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940done:
941 return ret;
942}
943
Thomas Graf661d2962013-03-21 07:45:29 +0000944static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900946 struct net *net = sock_net(skb->sk);
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800947 struct nlattr *tca[TCA_ACT_MAX + 1];
Eric W. Biederman15e47302012-09-07 20:12:54 +0000948 u32 portid = skb ? NETLINK_CB(skb).portid : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 int ret = 0, ovr = 0;
950
Eric W. Biederman90f62cf2014-04-23 14:29:27 -0700951 if ((n->nlmsg_type != RTM_GETACTION) && !netlink_capable(skb, CAP_NET_ADMIN))
Eric W. Biedermandfc47ef2012-11-16 03:03:00 +0000952 return -EPERM;
953
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800954 ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL);
955 if (ret < 0)
956 return ret;
957
958 if (tca[TCA_ACT_TAB] == NULL) {
stephen hemminger6ff9c362010-05-12 06:37:05 +0000959 pr_notice("tc_ctl_action: received NO action attribs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 return -EINVAL;
961 }
962
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000963 /* n->nlmsg_flags & NLM_F_CREATE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 switch (n->nlmsg_type) {
965 case RTM_NEWACTION:
966 /* we are going to assume all other flags
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300967 * imply create only if it doesn't exist
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 * Note that CREATE | EXCL implies that
969 * but since we want avoid ambiguity (eg when flags
970 * is zero) then just set this
971 */
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000972 if (n->nlmsg_flags & NLM_F_REPLACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 ovr = 1;
974replay:
Eric W. Biederman15e47302012-09-07 20:12:54 +0000975 ret = tcf_action_add(net, tca[TCA_ACT_TAB], n, portid, ovr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 if (ret == -EAGAIN)
977 goto replay;
978 break;
979 case RTM_DELACTION:
Tom Goff7316ae82010-03-19 15:40:13 +0000980 ret = tca_action_gd(net, tca[TCA_ACT_TAB], n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000981 portid, RTM_DELACTION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 break;
983 case RTM_GETACTION:
Tom Goff7316ae82010-03-19 15:40:13 +0000984 ret = tca_action_gd(net, tca[TCA_ACT_TAB], n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000985 portid, RTM_GETACTION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 break;
987 default:
988 BUG();
989 }
990
991 return ret;
992}
993
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800994static struct nlattr *
Patrick McHardy3a6c2b42009-08-25 16:07:40 +0200995find_dump_kind(const struct nlmsghdr *n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996{
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000997 struct nlattr *tb1, *tb2[TCA_ACT_MAX + 1];
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800998 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
999 struct nlattr *nla[TCAA_MAX + 1];
1000 struct nlattr *kind;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Patrick McHardyc96c9472008-01-23 20:32:58 -08001002 if (nlmsg_parse(n, sizeof(struct tcamsg), nla, TCAA_MAX, NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 return NULL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001004 tb1 = nla[TCA_ACT_TAB];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (tb1 == NULL)
1006 return NULL;
1007
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001008 if (nla_parse(tb, TCA_ACT_MAX_PRIO, nla_data(tb1),
1009 NLMSG_ALIGN(nla_len(tb1)), NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Patrick McHardy6d834e02008-01-23 20:32:42 -08001012 if (tb[1] == NULL)
1013 return NULL;
1014 if (nla_parse(tb2, TCA_ACT_MAX, nla_data(tb[1]),
1015 nla_len(tb[1]), NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 return NULL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001017 kind = tb2[TCA_ACT_KIND];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
Thomas Graf26dab892006-07-05 20:45:06 -07001019 return kind;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020}
1021
1022static int
1023tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
1024{
1025 struct nlmsghdr *nlh;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001026 unsigned char *b = skb_tail_pointer(skb);
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001027 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 struct tc_action_ops *a_o;
1029 struct tc_action a;
1030 int ret = 0;
David S. Miller8b00a532012-06-26 21:39:32 -07001031 struct tcamsg *t = (struct tcamsg *) nlmsg_data(cb->nlh);
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001032 struct nlattr *kind = find_dump_kind(cb->nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
1034 if (kind == NULL) {
stephen hemminger6ff9c362010-05-12 06:37:05 +00001035 pr_info("tc_dump_action: action bad kind\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 return 0;
1037 }
1038
Thomas Graf26dab892006-07-05 20:45:06 -07001039 a_o = tc_lookup_action(kind);
Eric Dumazetcc7ec452011-01-19 19:26:56 +00001040 if (a_o == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
1043 memset(&a, 0, sizeof(struct tc_action));
1044 a.ops = a_o;
1045
Eric W. Biederman15e47302012-09-07 20:12:54 +00001046 nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
David S. Miller8b00a532012-06-26 21:39:32 -07001047 cb->nlh->nlmsg_type, sizeof(*t), 0);
1048 if (!nlh)
1049 goto out_module_put;
1050 t = nlmsg_data(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -07001052 t->tca__pad1 = 0;
1053 t->tca__pad2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001055 nest = nla_nest_start(skb, TCA_ACT_TAB);
1056 if (nest == NULL)
David S. Miller8b00a532012-06-26 21:39:32 -07001057 goto out_module_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059 ret = a_o->walk(skb, cb, RTM_GETACTION, &a);
1060 if (ret < 0)
David S. Miller8b00a532012-06-26 21:39:32 -07001061 goto out_module_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063 if (ret > 0) {
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001064 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 ret = skb->len;
1066 } else
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001067 nla_nest_cancel(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001069 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Eric W. Biederman15e47302012-09-07 20:12:54 +00001070 if (NETLINK_CB(cb->skb).portid && ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 nlh->nlmsg_flags |= NLM_F_MULTI;
1072 module_put(a_o->owner);
1073 return skb->len;
1074
David S. Miller8b00a532012-06-26 21:39:32 -07001075out_module_put:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 module_put(a_o->owner);
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -07001077 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 return skb->len;
1079}
1080
1081static int __init tc_action_init(void)
1082{
Greg Rosec7ac8672011-06-10 01:27:09 +00001083 rtnl_register(PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL, NULL);
1084 rtnl_register(PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL, NULL);
1085 rtnl_register(PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action,
1086 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 return 0;
1089}
1090
1091subsys_initcall(tc_action_init);