blob: 3d43e4979f27c8dca3083c863549592216f741fe [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);
395 if (TC_MUNGED & skb->tc_verd) {
396 /* copied already, allow trampling */
397 skb->tc_verd = SET_TC_OK2MUNGE(skb->tc_verd);
398 skb->tc_verd = CLR_TC_MUNGED(skb->tc_verd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 }
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500400 if (ret == TC_ACT_REPEAT)
401 goto repeat; /* we need a ttl - JHS */
402 if (ret != TC_ACT_PIPE)
403 goto exec_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405exec_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 return ret;
407}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800408EXPORT_SYMBOL(tcf_action_exec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
WANG Cong55334a52014-02-11 17:07:34 -0800410int tcf_action_destroy(struct list_head *actions, int bind)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
WANG Cong33be6272013-12-15 20:15:05 -0800412 struct tc_action *a, *tmp;
WANG Cong55334a52014-02-11 17:07:34 -0800413 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
WANG Cong33be6272013-12-15 20:15:05 -0800415 list_for_each_entry_safe(a, tmp, actions, list) {
WANG Cong55334a52014-02-11 17:07:34 -0800416 ret = tcf_hash_release(a, bind);
417 if (ret == ACT_P_DELETED)
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500418 module_put(a->ops->owner);
WANG Cong55334a52014-02-11 17:07:34 -0800419 else if (ret < 0)
420 return ret;
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500421 list_del(&a->list);
422 kfree(a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
WANG Cong55334a52014-02-11 17:07:34 -0800424 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426
427int
428tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
429{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 return a->ops->dump(skb, a, bind, ref);
431}
432
433int
434tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
435{
436 int err = -EINVAL;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700437 unsigned char *b = skb_tail_pointer(skb);
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800438 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
David S. Miller1b34ec42012-03-29 05:11:39 -0400440 if (nla_put_string(skb, TCA_KIND, a->ops->kind))
441 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 if (tcf_action_copy_stats(skb, a, 0))
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800443 goto nla_put_failure;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800444 nest = nla_nest_start(skb, TCA_OPTIONS);
445 if (nest == NULL)
446 goto nla_put_failure;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000447 err = tcf_action_dump_old(skb, a, bind, ref);
448 if (err > 0) {
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800449 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 return err;
451 }
452
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800453nla_put_failure:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700454 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 return -1;
456}
Patrick McHardy62e3ba12008-01-22 22:10:23 -0800457EXPORT_SYMBOL(tcf_action_dump_1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459int
WANG Cong33be6272013-12-15 20:15:05 -0800460tcf_action_dump(struct sk_buff *skb, struct list_head *actions, int bind, int ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
462 struct tc_action *a;
463 int err = -EINVAL;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800464 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
WANG Cong33be6272013-12-15 20:15:05 -0800466 list_for_each_entry(a, actions, list) {
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800467 nest = nla_nest_start(skb, a->order);
468 if (nest == NULL)
469 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 err = tcf_action_dump_1(skb, a, bind, ref);
471 if (err < 0)
Thomas Graf4fe683f2006-07-05 20:47:28 -0700472 goto errout;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800473 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 }
475
476 return 0;
477
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800478nla_put_failure:
Thomas Graf4fe683f2006-07-05 20:47:28 -0700479 err = -EINVAL;
480errout:
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800481 nla_nest_cancel(skb, nest);
Thomas Graf4fe683f2006-07-05 20:47:28 -0700482 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483}
484
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000485struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
486 struct nlattr *est, char *name, int ovr,
487 int bind)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
489 struct tc_action *a;
490 struct tc_action_ops *a_o;
491 char act_name[IFNAMSIZ];
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000492 struct nlattr *tb[TCA_ACT_MAX + 1];
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800493 struct nlattr *kind;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800494 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 if (name == NULL) {
Patrick McHardycee63722008-01-23 20:33:32 -0800497 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
498 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 goto err_out;
Patrick McHardycee63722008-01-23 20:33:32 -0800500 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800501 kind = tb[TCA_ACT_KIND];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 if (kind == NULL)
503 goto err_out;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800504 if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 goto err_out;
506 } else {
Patrick McHardycee63722008-01-23 20:33:32 -0800507 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (strlcpy(act_name, name, IFNAMSIZ) >= IFNAMSIZ)
509 goto err_out;
510 }
511
512 a_o = tc_lookup_action_n(act_name);
513 if (a_o == NULL) {
Johannes Berg95a5afc2008-10-16 15:24:51 -0700514#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 rtnl_unlock();
Patrick McHardy4bba3922006-01-08 22:22:14 -0800516 request_module("act_%s", act_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 rtnl_lock();
518
519 a_o = tc_lookup_action_n(act_name);
520
521 /* We dropped the RTNL semaphore in order to
522 * perform the module load. So, even if we
523 * succeeded in loading the module we have to
524 * tell the caller to replay the request. We
525 * indicate this using -EAGAIN.
526 */
527 if (a_o != NULL) {
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800528 err = -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 goto err_mod;
530 }
531#endif
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800532 err = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 goto err_out;
534 }
535
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800536 err = -ENOMEM;
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700537 a = kzalloc(sizeof(*a), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 if (a == NULL)
539 goto err_mod;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
WANG Congc779f7a2014-01-17 11:37:02 -0800541 a->ops = a_o;
WANG Cong33be6272013-12-15 20:15:05 -0800542 INIT_LIST_HEAD(&a->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 /* backward compatibility for policer */
544 if (name == NULL)
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000545 err = a_o->init(net, tb[TCA_ACT_OPTIONS], est, a, ovr, bind);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 else
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000547 err = a_o->init(net, nla, est, a, ovr, bind);
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800548 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 goto err_free;
550
551 /* module count goes up only when brand new policy is created
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000552 * if it exists and is only bound to in a_o->init() then
553 * ACT_P_CREATED is not returned (a zero is).
554 */
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800555 if (err != ACT_P_CREATED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 module_put(a_o->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 return a;
559
560err_free:
561 kfree(a);
562err_mod:
563 module_put(a_o->owner);
564err_out:
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800565 return ERR_PTR(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
567
WANG Cong33be6272013-12-15 20:15:05 -0800568int tcf_action_init(struct net *net, struct nlattr *nla,
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000569 struct nlattr *est, char *name, int ovr,
WANG Cong33be6272013-12-15 20:15:05 -0800570 int bind, struct list_head *actions)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000572 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
WANG Cong33be6272013-12-15 20:15:05 -0800573 struct tc_action *act;
Patrick McHardycee63722008-01-23 20:33:32 -0800574 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 int i;
576
Patrick McHardycee63722008-01-23 20:33:32 -0800577 err = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
578 if (err < 0)
WANG Cong33be6272013-12-15 20:15:05 -0800579 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800581 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000582 act = tcf_action_init_1(net, tb[i], est, name, ovr, bind);
WANG Cong33be6272013-12-15 20:15:05 -0800583 if (IS_ERR(act)) {
584 err = PTR_ERR(act);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 goto err;
WANG Cong33be6272013-12-15 20:15:05 -0800586 }
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800587 act->order = i;
WANG Cong33be6272013-12-15 20:15:05 -0800588 list_add_tail(&act->list, actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 }
WANG Cong33be6272013-12-15 20:15:05 -0800590 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592err:
WANG Cong33be6272013-12-15 20:15:05 -0800593 tcf_action_destroy(actions, bind);
594 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
597int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *a,
598 int compat_mode)
599{
600 int err = 0;
601 struct gnet_dump d;
WANG Cong7eb88962014-01-09 16:14:05 -0800602 struct tcf_common *p = a->priv;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900603
WANG Cong7eb88962014-01-09 16:14:05 -0800604 if (p == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 goto errout;
606
607 /* compat_mode being true specifies a call that is supposed
Dirk Hohndel06fe9fb2009-09-28 21:43:57 -0400608 * to add additional backward compatibility statistic TLVs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 */
610 if (compat_mode) {
611 if (a->type == TCA_OLD_COMPAT)
612 err = gnet_stats_start_copy_compat(skb, 0,
WANG Cong7eb88962014-01-09 16:14:05 -0800613 TCA_STATS, TCA_XSTATS, &p->tcfc_lock, &d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 else
615 return 0;
616 } else
617 err = gnet_stats_start_copy(skb, TCA_ACT_STATS,
WANG Cong7eb88962014-01-09 16:14:05 -0800618 &p->tcfc_lock, &d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 if (err < 0)
621 goto errout;
622
John Fastabend22e0f8b2014-09-28 11:52:56 -0700623 if (gnet_stats_copy_basic(&d, NULL, &p->tcfc_bstats) < 0 ||
WANG Cong7eb88962014-01-09 16:14:05 -0800624 gnet_stats_copy_rate_est(&d, &p->tcfc_bstats,
625 &p->tcfc_rate_est) < 0 ||
John Fastabendb0ab6f92014-09-28 11:54:24 -0700626 gnet_stats_copy_queue(&d, NULL,
John Fastabend64015852014-09-28 11:53:57 -0700627 &p->tcfc_qstats,
628 p->tcfc_qstats.qlen) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 goto errout;
630
631 if (gnet_stats_finish_copy(&d) < 0)
632 goto errout;
633
634 return 0;
635
636errout:
637 return -1;
638}
639
640static int
WANG Cong33be6272013-12-15 20:15:05 -0800641tca_get_fill(struct sk_buff *skb, struct list_head *actions, u32 portid, u32 seq,
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900642 u16 flags, int event, int bind, int ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
644 struct tcamsg *t;
645 struct nlmsghdr *nlh;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700646 unsigned char *b = skb_tail_pointer(skb);
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800647 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Eric W. Biederman15e47302012-09-07 20:12:54 +0000649 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*t), flags);
David S. Miller8b00a532012-06-26 21:39:32 -0700650 if (!nlh)
651 goto out_nlmsg_trim;
652 t = nlmsg_data(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -0700654 t->tca__pad1 = 0;
655 t->tca__pad2 = 0;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900656
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800657 nest = nla_nest_start(skb, TCA_ACT_TAB);
658 if (nest == NULL)
David S. Miller8b00a532012-06-26 21:39:32 -0700659 goto out_nlmsg_trim;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
WANG Cong33be6272013-12-15 20:15:05 -0800661 if (tcf_action_dump(skb, actions, bind, ref) < 0)
David S. Miller8b00a532012-06-26 21:39:32 -0700662 goto out_nlmsg_trim;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800664 nla_nest_end(skb, nest);
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900665
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700666 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 return skb->len;
668
David S. Miller8b00a532012-06-26 21:39:32 -0700669out_nlmsg_trim:
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -0700670 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 return -1;
672}
673
674static int
Eric W. Biederman15e47302012-09-07 20:12:54 +0000675act_get_notify(struct net *net, u32 portid, struct nlmsghdr *n,
WANG Cong33be6272013-12-15 20:15:05 -0800676 struct list_head *actions, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677{
678 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
681 if (!skb)
682 return -ENOBUFS;
WANG Cong33be6272013-12-15 20:15:05 -0800683 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, event, 0, 0) <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 kfree_skb(skb);
685 return -EINVAL;
686 }
Thomas Graf2942e902006-08-15 00:30:25 -0700687
Eric W. Biederman15e47302012-09-07 20:12:54 +0000688 return rtnl_unicast(skb, net, portid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
WANG Cong03701d62014-02-11 17:07:35 -0800691static struct tc_action *create_a(int i)
692{
693 struct tc_action *act;
694
695 act = kzalloc(sizeof(*act), GFP_KERNEL);
696 if (act == NULL) {
697 pr_debug("create_a: failed to alloc!\n");
698 return NULL;
699 }
700 act->order = i;
701 INIT_LIST_HEAD(&act->list);
702 return act;
703}
704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705static struct tc_action *
Eric W. Biederman15e47302012-09-07 20:12:54 +0000706tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 portid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000708 struct nlattr *tb[TCA_ACT_MAX + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 struct tc_action *a;
710 int index;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800711 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Patrick McHardycee63722008-01-23 20:33:32 -0800713 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
714 if (err < 0)
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800715 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Patrick McHardycee63722008-01-23 20:33:32 -0800717 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800718 if (tb[TCA_ACT_INDEX] == NULL ||
719 nla_len(tb[TCA_ACT_INDEX]) < sizeof(index))
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800720 goto err_out;
Patrick McHardy1587bac2008-01-23 20:35:03 -0800721 index = nla_get_u32(tb[TCA_ACT_INDEX]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800723 err = -ENOMEM;
WANG Cong03701d62014-02-11 17:07:35 -0800724 a = create_a(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 if (a == NULL)
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800726 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800728 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800729 a->ops = tc_lookup_action(tb[TCA_ACT_KIND]);
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500730 if (a->ops == NULL) /* could happen in batch of actions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 goto err_free;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800732 err = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 if (a->ops->lookup(a, index) == 0)
734 goto err_mod;
735
736 module_put(a->ops->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 return a;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739err_mod:
740 module_put(a->ops->owner);
741err_free:
742 kfree(a);
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800743err_out:
744 return ERR_PTR(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745}
746
WANG Cong33be6272013-12-15 20:15:05 -0800747static void cleanup_a(struct list_head *actions)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
WANG Cong33be6272013-12-15 20:15:05 -0800749 struct tc_action *a, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
WANG Cong33be6272013-12-15 20:15:05 -0800751 list_for_each_entry_safe(a, tmp, actions, list) {
752 list_del(&a->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 kfree(a);
754 }
755}
756
Tom Goff7316ae82010-03-19 15:40:13 +0000757static int tca_action_flush(struct net *net, struct nlattr *nla,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000758 struct nlmsghdr *n, u32 portid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759{
760 struct sk_buff *skb;
761 unsigned char *b;
762 struct nlmsghdr *nlh;
763 struct tcamsg *t;
764 struct netlink_callback dcb;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800765 struct nlattr *nest;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000766 struct nlattr *tb[TCA_ACT_MAX + 1];
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800767 struct nlattr *kind;
WANG Cong03701d62014-02-11 17:07:35 -0800768 struct tc_action a;
Jamal Hadi Salim36723872008-08-13 02:41:45 -0700769 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
772 if (!skb) {
stephen hemminger6ff9c362010-05-12 06:37:05 +0000773 pr_debug("tca_action_flush: failed skb alloc\n");
Jamal Hadi Salim36723872008-08-13 02:41:45 -0700774 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 }
776
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700777 b = skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Patrick McHardycee63722008-01-23 20:33:32 -0800779 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
780 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 goto err_out;
782
Patrick McHardycee63722008-01-23 20:33:32 -0800783 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800784 kind = tb[TCA_ACT_KIND];
WANG Cong03701d62014-02-11 17:07:35 -0800785 memset(&a, 0, sizeof(struct tc_action));
786 INIT_LIST_HEAD(&a.list);
787 a.ops = tc_lookup_action(kind);
788 if (a.ops == NULL) /*some idjot trying to flush unknown action */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 goto err_out;
790
Eric W. Biederman15e47302012-09-07 20:12:54 +0000791 nlh = nlmsg_put(skb, portid, n->nlmsg_seq, RTM_DELACTION, sizeof(*t), 0);
David S. Miller8b00a532012-06-26 21:39:32 -0700792 if (!nlh)
793 goto out_module_put;
794 t = nlmsg_data(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -0700796 t->tca__pad1 = 0;
797 t->tca__pad2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800799 nest = nla_nest_start(skb, TCA_ACT_TAB);
800 if (nest == NULL)
David S. Miller8b00a532012-06-26 21:39:32 -0700801 goto out_module_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
WANG Cong03701d62014-02-11 17:07:35 -0800803 err = a.ops->walk(skb, &dcb, RTM_DELACTION, &a);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 if (err < 0)
David S. Miller8b00a532012-06-26 21:39:32 -0700805 goto out_module_put;
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700806 if (err == 0)
807 goto noflush_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800809 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700811 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 nlh->nlmsg_flags |= NLM_F_ROOT;
WANG Cong03701d62014-02-11 17:07:35 -0800813 module_put(a.ops->owner);
Eric W. Biederman15e47302012-09-07 20:12:54 +0000814 err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000815 n->nlmsg_flags & NLM_F_ECHO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 if (err > 0)
817 return 0;
818
819 return err;
820
David S. Miller8b00a532012-06-26 21:39:32 -0700821out_module_put:
WANG Cong03701d62014-02-11 17:07:35 -0800822 module_put(a.ops->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823err_out:
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700824noflush_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 return err;
827}
828
829static int
WANG Conga56e1952014-01-09 16:14:00 -0800830tcf_del_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
831 u32 portid)
832{
833 int ret;
834 struct sk_buff *skb;
835
836 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
837 if (!skb)
838 return -ENOBUFS;
839
840 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, RTM_DELACTION,
841 0, 1) <= 0) {
842 kfree_skb(skb);
843 return -EINVAL;
844 }
845
846 /* now do the delete */
WANG Cong55334a52014-02-11 17:07:34 -0800847 ret = tcf_action_destroy(actions, 0);
848 if (ret < 0) {
849 kfree_skb(skb);
850 return ret;
851 }
WANG Conga56e1952014-01-09 16:14:00 -0800852
853 ret = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
854 n->nlmsg_flags & NLM_F_ECHO);
855 if (ret > 0)
856 return 0;
857 return ret;
858}
859
860static int
Tom Goff7316ae82010-03-19 15:40:13 +0000861tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000862 u32 portid, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863{
Patrick McHardycee63722008-01-23 20:33:32 -0800864 int i, ret;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000865 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
WANG Cong33be6272013-12-15 20:15:05 -0800866 struct tc_action *act;
867 LIST_HEAD(actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Patrick McHardycee63722008-01-23 20:33:32 -0800869 ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
870 if (ret < 0)
871 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000873 if (event == RTM_DELACTION && n->nlmsg_flags & NLM_F_ROOT) {
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700874 if (tb[1] != NULL)
Eric W. Biederman15e47302012-09-07 20:12:54 +0000875 return tca_action_flush(net, tb[1], n, portid);
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700876 else
877 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 }
879
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800880 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
Eric W. Biederman15e47302012-09-07 20:12:54 +0000881 act = tcf_action_get_1(tb[i], n, portid);
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800882 if (IS_ERR(act)) {
883 ret = PTR_ERR(act);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 goto err;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800885 }
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800886 act->order = i;
WANG Cong33be6272013-12-15 20:15:05 -0800887 list_add_tail(&act->list, &actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 }
889
890 if (event == RTM_GETACTION)
WANG Cong33be6272013-12-15 20:15:05 -0800891 ret = act_get_notify(net, portid, n, &actions, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 else { /* delete */
WANG Conga56e1952014-01-09 16:14:00 -0800893 ret = tcf_del_notify(net, n, &actions, portid);
894 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 return ret;
897 }
898err:
WANG Cong33be6272013-12-15 20:15:05 -0800899 cleanup_a(&actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 return ret;
901}
902
WANG Conga56e1952014-01-09 16:14:00 -0800903static int
904tcf_add_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
905 u32 portid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 int err = 0;
909
910 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
911 if (!skb)
912 return -ENOBUFS;
913
WANG Conga56e1952014-01-09 16:14:00 -0800914 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, n->nlmsg_flags,
915 RTM_NEWACTION, 0, 0) <= 0) {
916 kfree_skb(skb);
917 return -EINVAL;
918 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
WANG Conga56e1952014-01-09 16:14:00 -0800920 err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
921 n->nlmsg_flags & NLM_F_ECHO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 if (err > 0)
923 err = 0;
924 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925}
926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927static int
Tom Goff7316ae82010-03-19 15:40:13 +0000928tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000929 u32 portid, int ovr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930{
931 int ret = 0;
WANG Cong33be6272013-12-15 20:15:05 -0800932 LIST_HEAD(actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
WANG Cong33be6272013-12-15 20:15:05 -0800934 ret = tcf_action_init(net, nla, NULL, NULL, ovr, 0, &actions);
935 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 goto done;
937
938 /* dump then free all the actions after update; inserted policy
939 * stays intact
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000940 */
WANG Conga56e1952014-01-09 16:14:00 -0800941 ret = tcf_add_notify(net, n, &actions, portid);
WANG Cong33be6272013-12-15 20:15:05 -0800942 cleanup_a(&actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943done:
944 return ret;
945}
946
Thomas Graf661d2962013-03-21 07:45:29 +0000947static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900949 struct net *net = sock_net(skb->sk);
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800950 struct nlattr *tca[TCA_ACT_MAX + 1];
Eric W. Biederman15e47302012-09-07 20:12:54 +0000951 u32 portid = skb ? NETLINK_CB(skb).portid : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 int ret = 0, ovr = 0;
953
Eric W. Biederman90f62cf2014-04-23 14:29:27 -0700954 if ((n->nlmsg_type != RTM_GETACTION) && !netlink_capable(skb, CAP_NET_ADMIN))
Eric W. Biedermandfc47ef2012-11-16 03:03:00 +0000955 return -EPERM;
956
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800957 ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL);
958 if (ret < 0)
959 return ret;
960
961 if (tca[TCA_ACT_TAB] == NULL) {
stephen hemminger6ff9c362010-05-12 06:37:05 +0000962 pr_notice("tc_ctl_action: received NO action attribs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 return -EINVAL;
964 }
965
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000966 /* n->nlmsg_flags & NLM_F_CREATE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 switch (n->nlmsg_type) {
968 case RTM_NEWACTION:
969 /* we are going to assume all other flags
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300970 * imply create only if it doesn't exist
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 * Note that CREATE | EXCL implies that
972 * but since we want avoid ambiguity (eg when flags
973 * is zero) then just set this
974 */
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000975 if (n->nlmsg_flags & NLM_F_REPLACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 ovr = 1;
977replay:
Eric W. Biederman15e47302012-09-07 20:12:54 +0000978 ret = tcf_action_add(net, tca[TCA_ACT_TAB], n, portid, ovr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 if (ret == -EAGAIN)
980 goto replay;
981 break;
982 case RTM_DELACTION:
Tom Goff7316ae82010-03-19 15:40:13 +0000983 ret = tca_action_gd(net, tca[TCA_ACT_TAB], n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000984 portid, RTM_DELACTION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 break;
986 case RTM_GETACTION:
Tom Goff7316ae82010-03-19 15:40:13 +0000987 ret = tca_action_gd(net, tca[TCA_ACT_TAB], n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000988 portid, RTM_GETACTION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 break;
990 default:
991 BUG();
992 }
993
994 return ret;
995}
996
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800997static struct nlattr *
Patrick McHardy3a6c2b42009-08-25 16:07:40 +0200998find_dump_kind(const struct nlmsghdr *n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999{
Eric Dumazetcc7ec452011-01-19 19:26:56 +00001000 struct nlattr *tb1, *tb2[TCA_ACT_MAX + 1];
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001001 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
1002 struct nlattr *nla[TCAA_MAX + 1];
1003 struct nlattr *kind;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
Patrick McHardyc96c9472008-01-23 20:32:58 -08001005 if (nlmsg_parse(n, sizeof(struct tcamsg), nla, TCAA_MAX, NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 return NULL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001007 tb1 = nla[TCA_ACT_TAB];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 if (tb1 == NULL)
1009 return NULL;
1010
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001011 if (nla_parse(tb, TCA_ACT_MAX_PRIO, nla_data(tb1),
1012 NLMSG_ALIGN(nla_len(tb1)), NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Patrick McHardy6d834e02008-01-23 20:32:42 -08001015 if (tb[1] == NULL)
1016 return NULL;
1017 if (nla_parse(tb2, TCA_ACT_MAX, nla_data(tb[1]),
1018 nla_len(tb[1]), NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 return NULL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001020 kind = tb2[TCA_ACT_KIND];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
Thomas Graf26dab892006-07-05 20:45:06 -07001022 return kind;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023}
1024
1025static int
1026tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
1027{
1028 struct nlmsghdr *nlh;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001029 unsigned char *b = skb_tail_pointer(skb);
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001030 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 struct tc_action_ops *a_o;
1032 struct tc_action a;
1033 int ret = 0;
David S. Miller8b00a532012-06-26 21:39:32 -07001034 struct tcamsg *t = (struct tcamsg *) nlmsg_data(cb->nlh);
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001035 struct nlattr *kind = find_dump_kind(cb->nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
1037 if (kind == NULL) {
stephen hemminger6ff9c362010-05-12 06:37:05 +00001038 pr_info("tc_dump_action: action bad kind\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 return 0;
1040 }
1041
Thomas Graf26dab892006-07-05 20:45:06 -07001042 a_o = tc_lookup_action(kind);
Eric Dumazetcc7ec452011-01-19 19:26:56 +00001043 if (a_o == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
1046 memset(&a, 0, sizeof(struct tc_action));
1047 a.ops = a_o;
1048
Eric W. Biederman15e47302012-09-07 20:12:54 +00001049 nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
David S. Miller8b00a532012-06-26 21:39:32 -07001050 cb->nlh->nlmsg_type, sizeof(*t), 0);
1051 if (!nlh)
1052 goto out_module_put;
1053 t = nlmsg_data(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -07001055 t->tca__pad1 = 0;
1056 t->tca__pad2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001058 nest = nla_nest_start(skb, TCA_ACT_TAB);
1059 if (nest == NULL)
David S. Miller8b00a532012-06-26 21:39:32 -07001060 goto out_module_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
1062 ret = a_o->walk(skb, cb, RTM_GETACTION, &a);
1063 if (ret < 0)
David S. Miller8b00a532012-06-26 21:39:32 -07001064 goto out_module_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066 if (ret > 0) {
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001067 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 ret = skb->len;
1069 } else
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001070 nla_nest_cancel(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001072 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Eric W. Biederman15e47302012-09-07 20:12:54 +00001073 if (NETLINK_CB(cb->skb).portid && ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 nlh->nlmsg_flags |= NLM_F_MULTI;
1075 module_put(a_o->owner);
1076 return skb->len;
1077
David S. Miller8b00a532012-06-26 21:39:32 -07001078out_module_put:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 module_put(a_o->owner);
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -07001080 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 return skb->len;
1082}
1083
1084static int __init tc_action_init(void)
1085{
Greg Rosec7ac8672011-06-10 01:27:09 +00001086 rtnl_register(PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL, NULL);
1087 rtnl_register(PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL, NULL);
1088 rtnl_register(PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action,
1089 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 return 0;
1092}
1093
1094subsys_initcall(tc_action_init);