blob: 27e4c531ade1fc629d1d338fb5402e9f863654ef [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
688static struct tc_action *
Eric W. Biederman15e47302012-09-07 20:12:54 +0000689tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 portid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000691 struct nlattr *tb[TCA_ACT_MAX + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 struct tc_action *a;
693 int index;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800694 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Patrick McHardycee63722008-01-23 20:33:32 -0800696 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
697 if (err < 0)
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800698 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Patrick McHardycee63722008-01-23 20:33:32 -0800700 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800701 if (tb[TCA_ACT_INDEX] == NULL ||
702 nla_len(tb[TCA_ACT_INDEX]) < sizeof(index))
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800703 goto err_out;
Patrick McHardy1587bac2008-01-23 20:35:03 -0800704 index = nla_get_u32(tb[TCA_ACT_INDEX]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800706 err = -ENOMEM;
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700707 a = kzalloc(sizeof(struct tc_action), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 if (a == NULL)
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800709 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
WANG Cong33be6272013-12-15 20:15:05 -0800711 INIT_LIST_HEAD(&a->list);
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800712 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800713 a->ops = tc_lookup_action(tb[TCA_ACT_KIND]);
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500714 if (a->ops == NULL) /* could happen in batch of actions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 goto err_free;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800716 err = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 if (a->ops->lookup(a, index) == 0)
718 goto err_mod;
719
720 module_put(a->ops->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 return a;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723err_mod:
724 module_put(a->ops->owner);
725err_free:
726 kfree(a);
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800727err_out:
728 return ERR_PTR(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729}
730
WANG Cong33be6272013-12-15 20:15:05 -0800731static void cleanup_a(struct list_head *actions)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
WANG Cong33be6272013-12-15 20:15:05 -0800733 struct tc_action *a, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
WANG Cong33be6272013-12-15 20:15:05 -0800735 list_for_each_entry_safe(a, tmp, actions, list) {
736 list_del(&a->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 kfree(a);
738 }
739}
740
741static struct tc_action *create_a(int i)
742{
743 struct tc_action *act;
744
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700745 act = kzalloc(sizeof(*act), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 if (act == NULL) {
stephen hemminger6ff9c362010-05-12 06:37:05 +0000747 pr_debug("create_a: failed to alloc!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 return NULL;
749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 act->order = i;
WANG Cong33be6272013-12-15 20:15:05 -0800751 INIT_LIST_HEAD(&act->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 return act;
753}
754
Tom Goff7316ae82010-03-19 15:40:13 +0000755static int tca_action_flush(struct net *net, struct nlattr *nla,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000756 struct nlmsghdr *n, u32 portid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
758 struct sk_buff *skb;
759 unsigned char *b;
760 struct nlmsghdr *nlh;
761 struct tcamsg *t;
762 struct netlink_callback dcb;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800763 struct nlattr *nest;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000764 struct nlattr *tb[TCA_ACT_MAX + 1];
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800765 struct nlattr *kind;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 struct tc_action *a = create_a(0);
Jamal Hadi Salim36723872008-08-13 02:41:45 -0700767 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769 if (a == NULL) {
stephen hemminger6ff9c362010-05-12 06:37:05 +0000770 pr_debug("tca_action_flush: couldnt create tc_action\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 return err;
772 }
773
774 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
775 if (!skb) {
stephen hemminger6ff9c362010-05-12 06:37:05 +0000776 pr_debug("tca_action_flush: failed skb alloc\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 kfree(a);
Jamal Hadi Salim36723872008-08-13 02:41:45 -0700778 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 }
780
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700781 b = skb_tail_pointer(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Patrick McHardycee63722008-01-23 20:33:32 -0800783 err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
784 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 goto err_out;
786
Patrick McHardycee63722008-01-23 20:33:32 -0800787 err = -EINVAL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800788 kind = tb[TCA_ACT_KIND];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 a->ops = tc_lookup_action(kind);
Jamal Hadi Salim63acd682013-12-23 08:02:12 -0500790 if (a->ops == NULL) /*some idjot trying to flush unknown action */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 goto err_out;
792
Eric W. Biederman15e47302012-09-07 20:12:54 +0000793 nlh = nlmsg_put(skb, portid, n->nlmsg_seq, RTM_DELACTION, sizeof(*t), 0);
David S. Miller8b00a532012-06-26 21:39:32 -0700794 if (!nlh)
795 goto out_module_put;
796 t = nlmsg_data(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -0700798 t->tca__pad1 = 0;
799 t->tca__pad2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800801 nest = nla_nest_start(skb, TCA_ACT_TAB);
802 if (nest == NULL)
David S. Miller8b00a532012-06-26 21:39:32 -0700803 goto out_module_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 err = a->ops->walk(skb, &dcb, RTM_DELACTION, a);
806 if (err < 0)
David S. Miller8b00a532012-06-26 21:39:32 -0700807 goto out_module_put;
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700808 if (err == 0)
809 goto noflush_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800811 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700813 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 nlh->nlmsg_flags |= NLM_F_ROOT;
815 module_put(a->ops->owner);
816 kfree(a);
Eric W. Biederman15e47302012-09-07 20:12:54 +0000817 err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000818 n->nlmsg_flags & NLM_F_ECHO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 if (err > 0)
820 return 0;
821
822 return err;
823
David S. Miller8b00a532012-06-26 21:39:32 -0700824out_module_put:
Thomas Grafebbaeab2006-07-09 11:36:23 -0700825 module_put(a->ops->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826err_out:
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700827noflush_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 kfree_skb(skb);
829 kfree(a);
830 return err;
831}
832
833static int
WANG Conga56e1952014-01-09 16:14:00 -0800834tcf_del_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
835 u32 portid)
836{
837 int ret;
838 struct sk_buff *skb;
839
840 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
841 if (!skb)
842 return -ENOBUFS;
843
844 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, 0, RTM_DELACTION,
845 0, 1) <= 0) {
846 kfree_skb(skb);
847 return -EINVAL;
848 }
849
850 /* now do the delete */
WANG Cong55334a52014-02-11 17:07:34 -0800851 ret = tcf_action_destroy(actions, 0);
852 if (ret < 0) {
853 kfree_skb(skb);
854 return ret;
855 }
WANG Conga56e1952014-01-09 16:14:00 -0800856
857 ret = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
858 n->nlmsg_flags & NLM_F_ECHO);
859 if (ret > 0)
860 return 0;
861 return ret;
862}
863
864static int
Tom Goff7316ae82010-03-19 15:40:13 +0000865tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000866 u32 portid, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867{
Patrick McHardycee63722008-01-23 20:33:32 -0800868 int i, ret;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000869 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
WANG Cong33be6272013-12-15 20:15:05 -0800870 struct tc_action *act;
871 LIST_HEAD(actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Patrick McHardycee63722008-01-23 20:33:32 -0800873 ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
874 if (ret < 0)
875 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000877 if (event == RTM_DELACTION && n->nlmsg_flags & NLM_F_ROOT) {
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700878 if (tb[1] != NULL)
Eric W. Biederman15e47302012-09-07 20:12:54 +0000879 return tca_action_flush(net, tb[1], n, portid);
Jamal Hadi Salimf97017c2008-08-13 02:41:22 -0700880 else
881 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 }
883
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800884 for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
Eric W. Biederman15e47302012-09-07 20:12:54 +0000885 act = tcf_action_get_1(tb[i], n, portid);
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800886 if (IS_ERR(act)) {
887 ret = PTR_ERR(act);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 goto err;
Patrick McHardyab27cfb2008-01-23 20:33:13 -0800889 }
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800890 act->order = i;
WANG Cong33be6272013-12-15 20:15:05 -0800891 list_add_tail(&act->list, &actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 }
893
894 if (event == RTM_GETACTION)
WANG Cong33be6272013-12-15 20:15:05 -0800895 ret = act_get_notify(net, portid, n, &actions, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 else { /* delete */
WANG Conga56e1952014-01-09 16:14:00 -0800897 ret = tcf_del_notify(net, n, &actions, portid);
898 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 return ret;
901 }
902err:
WANG Cong33be6272013-12-15 20:15:05 -0800903 cleanup_a(&actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 return ret;
905}
906
WANG Conga56e1952014-01-09 16:14:00 -0800907static int
908tcf_add_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
909 u32 portid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 int err = 0;
913
914 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
915 if (!skb)
916 return -ENOBUFS;
917
WANG Conga56e1952014-01-09 16:14:00 -0800918 if (tca_get_fill(skb, actions, portid, n->nlmsg_seq, n->nlmsg_flags,
919 RTM_NEWACTION, 0, 0) <= 0) {
920 kfree_skb(skb);
921 return -EINVAL;
922 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
WANG Conga56e1952014-01-09 16:14:00 -0800924 err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
925 n->nlmsg_flags & NLM_F_ECHO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 if (err > 0)
927 err = 0;
928 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931static int
Tom Goff7316ae82010-03-19 15:40:13 +0000932tcf_action_add(struct net *net, struct nlattr *nla, struct nlmsghdr *n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000933 u32 portid, int ovr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
935 int ret = 0;
WANG Cong33be6272013-12-15 20:15:05 -0800936 LIST_HEAD(actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
WANG Cong33be6272013-12-15 20:15:05 -0800938 ret = tcf_action_init(net, nla, NULL, NULL, ovr, 0, &actions);
939 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 goto done;
941
942 /* dump then free all the actions after update; inserted policy
943 * stays intact
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000944 */
WANG Conga56e1952014-01-09 16:14:00 -0800945 ret = tcf_add_notify(net, n, &actions, portid);
WANG Cong33be6272013-12-15 20:15:05 -0800946 cleanup_a(&actions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947done:
948 return ret;
949}
950
Thomas Graf661d2962013-03-21 07:45:29 +0000951static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900953 struct net *net = sock_net(skb->sk);
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800954 struct nlattr *tca[TCA_ACT_MAX + 1];
Eric W. Biederman15e47302012-09-07 20:12:54 +0000955 u32 portid = skb ? NETLINK_CB(skb).portid : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 int ret = 0, ovr = 0;
957
Eric W. Biedermandfc47ef2012-11-16 03:03:00 +0000958 if ((n->nlmsg_type != RTM_GETACTION) && !capable(CAP_NET_ADMIN))
959 return -EPERM;
960
Patrick McHardy7ba699c2008-01-22 22:11:50 -0800961 ret = nlmsg_parse(n, sizeof(struct tcamsg), tca, TCA_ACT_MAX, NULL);
962 if (ret < 0)
963 return ret;
964
965 if (tca[TCA_ACT_TAB] == NULL) {
stephen hemminger6ff9c362010-05-12 06:37:05 +0000966 pr_notice("tc_ctl_action: received NO action attribs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 return -EINVAL;
968 }
969
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000970 /* n->nlmsg_flags & NLM_F_CREATE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 switch (n->nlmsg_type) {
972 case RTM_NEWACTION:
973 /* we are going to assume all other flags
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300974 * imply create only if it doesn't exist
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 * Note that CREATE | EXCL implies that
976 * but since we want avoid ambiguity (eg when flags
977 * is zero) then just set this
978 */
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000979 if (n->nlmsg_flags & NLM_F_REPLACE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 ovr = 1;
981replay:
Eric W. Biederman15e47302012-09-07 20:12:54 +0000982 ret = tcf_action_add(net, tca[TCA_ACT_TAB], n, portid, ovr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 if (ret == -EAGAIN)
984 goto replay;
985 break;
986 case RTM_DELACTION:
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_DELACTION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 break;
990 case RTM_GETACTION:
Tom Goff7316ae82010-03-19 15:40:13 +0000991 ret = tca_action_gd(net, tca[TCA_ACT_TAB], n,
Eric W. Biederman15e47302012-09-07 20:12:54 +0000992 portid, RTM_GETACTION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 break;
994 default:
995 BUG();
996 }
997
998 return ret;
999}
1000
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001001static struct nlattr *
Patrick McHardy3a6c2b42009-08-25 16:07:40 +02001002find_dump_kind(const struct nlmsghdr *n)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003{
Eric Dumazetcc7ec452011-01-19 19:26:56 +00001004 struct nlattr *tb1, *tb2[TCA_ACT_MAX + 1];
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001005 struct nlattr *tb[TCA_ACT_MAX_PRIO + 1];
1006 struct nlattr *nla[TCAA_MAX + 1];
1007 struct nlattr *kind;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Patrick McHardyc96c9472008-01-23 20:32:58 -08001009 if (nlmsg_parse(n, sizeof(struct tcamsg), nla, TCAA_MAX, NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 return NULL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001011 tb1 = nla[TCA_ACT_TAB];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 if (tb1 == NULL)
1013 return NULL;
1014
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001015 if (nla_parse(tb, TCA_ACT_MAX_PRIO, nla_data(tb1),
1016 NLMSG_ALIGN(nla_len(tb1)), NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
Patrick McHardy6d834e02008-01-23 20:32:42 -08001019 if (tb[1] == NULL)
1020 return NULL;
1021 if (nla_parse(tb2, TCA_ACT_MAX, nla_data(tb[1]),
1022 nla_len(tb[1]), NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 return NULL;
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001024 kind = tb2[TCA_ACT_KIND];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Thomas Graf26dab892006-07-05 20:45:06 -07001026 return kind;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027}
1028
1029static int
1030tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
1031{
1032 struct nlmsghdr *nlh;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001033 unsigned char *b = skb_tail_pointer(skb);
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001034 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 struct tc_action_ops *a_o;
1036 struct tc_action a;
1037 int ret = 0;
David S. Miller8b00a532012-06-26 21:39:32 -07001038 struct tcamsg *t = (struct tcamsg *) nlmsg_data(cb->nlh);
Patrick McHardy7ba699c2008-01-22 22:11:50 -08001039 struct nlattr *kind = find_dump_kind(cb->nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
1041 if (kind == NULL) {
stephen hemminger6ff9c362010-05-12 06:37:05 +00001042 pr_info("tc_dump_action: action bad kind\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 return 0;
1044 }
1045
Thomas Graf26dab892006-07-05 20:45:06 -07001046 a_o = tc_lookup_action(kind);
Eric Dumazetcc7ec452011-01-19 19:26:56 +00001047 if (a_o == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050 memset(&a, 0, sizeof(struct tc_action));
1051 a.ops = a_o;
1052
Eric W. Biederman15e47302012-09-07 20:12:54 +00001053 nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
David S. Miller8b00a532012-06-26 21:39:32 -07001054 cb->nlh->nlmsg_type, sizeof(*t), 0);
1055 if (!nlh)
1056 goto out_module_put;
1057 t = nlmsg_data(nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 t->tca_family = AF_UNSPEC;
Patrick McHardy9ef1d4c2005-06-28 12:55:30 -07001059 t->tca__pad1 = 0;
1060 t->tca__pad2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001062 nest = nla_nest_start(skb, TCA_ACT_TAB);
1063 if (nest == NULL)
David S. Miller8b00a532012-06-26 21:39:32 -07001064 goto out_module_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066 ret = a_o->walk(skb, cb, RTM_GETACTION, &a);
1067 if (ret < 0)
David S. Miller8b00a532012-06-26 21:39:32 -07001068 goto out_module_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
1070 if (ret > 0) {
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001071 nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 ret = skb->len;
1073 } else
Patrick McHardy4b3550ef2008-01-23 20:34:11 -08001074 nla_nest_cancel(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07001076 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
Eric W. Biederman15e47302012-09-07 20:12:54 +00001077 if (NETLINK_CB(cb->skb).portid && ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 nlh->nlmsg_flags |= NLM_F_MULTI;
1079 module_put(a_o->owner);
1080 return skb->len;
1081
David S. Miller8b00a532012-06-26 21:39:32 -07001082out_module_put:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 module_put(a_o->owner);
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -07001084 nlmsg_trim(skb, b);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 return skb->len;
1086}
1087
1088static int __init tc_action_init(void)
1089{
Greg Rosec7ac8672011-06-10 01:27:09 +00001090 rtnl_register(PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL, NULL);
1091 rtnl_register(PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL, NULL);
1092 rtnl_register(PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action,
1093 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 return 0;
1096}
1097
1098subsys_initcall(tc_action_init);