net: rtnetlink: plumb extended ack to doit function
[platform/kernel/linux-rpi.git] / net / sched / cls_api.c
1 /*
2  * net/sched/cls_api.c  Packet classifier 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  * Authors:     Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10  *
11  * Changes:
12  *
13  * Eduardo J. Blanco <ejbs@netlabs.com.uy> :990222: kmod support
14  *
15  */
16
17 #include <linux/module.h>
18 #include <linux/types.h>
19 #include <linux/kernel.h>
20 #include <linux/string.h>
21 #include <linux/errno.h>
22 #include <linux/err.h>
23 #include <linux/skbuff.h>
24 #include <linux/init.h>
25 #include <linux/kmod.h>
26 #include <linux/err.h>
27 #include <linux/slab.h>
28 #include <net/net_namespace.h>
29 #include <net/sock.h>
30 #include <net/netlink.h>
31 #include <net/pkt_sched.h>
32 #include <net/pkt_cls.h>
33
34 /* The list of all installed classifier types */
35 static LIST_HEAD(tcf_proto_base);
36
37 /* Protects list of registered TC modules. It is pure SMP lock. */
38 static DEFINE_RWLOCK(cls_mod_lock);
39
40 /* Find classifier type by string name */
41
42 static const struct tcf_proto_ops *tcf_proto_lookup_ops(const char *kind)
43 {
44         const struct tcf_proto_ops *t, *res = NULL;
45
46         if (kind) {
47                 read_lock(&cls_mod_lock);
48                 list_for_each_entry(t, &tcf_proto_base, head) {
49                         if (strcmp(kind, t->kind) == 0) {
50                                 if (try_module_get(t->owner))
51                                         res = t;
52                                 break;
53                         }
54                 }
55                 read_unlock(&cls_mod_lock);
56         }
57         return res;
58 }
59
60 /* Register(unregister) new classifier type */
61
62 int register_tcf_proto_ops(struct tcf_proto_ops *ops)
63 {
64         struct tcf_proto_ops *t;
65         int rc = -EEXIST;
66
67         write_lock(&cls_mod_lock);
68         list_for_each_entry(t, &tcf_proto_base, head)
69                 if (!strcmp(ops->kind, t->kind))
70                         goto out;
71
72         list_add_tail(&ops->head, &tcf_proto_base);
73         rc = 0;
74 out:
75         write_unlock(&cls_mod_lock);
76         return rc;
77 }
78 EXPORT_SYMBOL(register_tcf_proto_ops);
79
80 int unregister_tcf_proto_ops(struct tcf_proto_ops *ops)
81 {
82         struct tcf_proto_ops *t;
83         int rc = -ENOENT;
84
85         /* Wait for outstanding call_rcu()s, if any, from a
86          * tcf_proto_ops's destroy() handler.
87          */
88         rcu_barrier();
89
90         write_lock(&cls_mod_lock);
91         list_for_each_entry(t, &tcf_proto_base, head) {
92                 if (t == ops) {
93                         list_del(&t->head);
94                         rc = 0;
95                         break;
96                 }
97         }
98         write_unlock(&cls_mod_lock);
99         return rc;
100 }
101 EXPORT_SYMBOL(unregister_tcf_proto_ops);
102
103 static int tfilter_notify(struct net *net, struct sk_buff *oskb,
104                           struct nlmsghdr *n, struct tcf_proto *tp,
105                           unsigned long fh, int event, bool unicast);
106
107 static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb,
108                                  struct nlmsghdr *n,
109                                  struct tcf_proto __rcu **chain, int event)
110 {
111         struct tcf_proto __rcu **it_chain;
112         struct tcf_proto *tp;
113
114         for (it_chain = chain; (tp = rtnl_dereference(*it_chain)) != NULL;
115              it_chain = &tp->next)
116                 tfilter_notify(net, oskb, n, tp, 0, event, false);
117 }
118
119 /* Select new prio value from the range, managed by kernel. */
120
121 static inline u32 tcf_auto_prio(struct tcf_proto *tp)
122 {
123         u32 first = TC_H_MAKE(0xC0000000U, 0U);
124
125         if (tp)
126                 first = tp->prio - 1;
127
128         return first;
129 }
130
131 static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol,
132                                           u32 prio, u32 parent, struct Qdisc *q)
133 {
134         struct tcf_proto *tp;
135         int err;
136
137         tp = kzalloc(sizeof(*tp), GFP_KERNEL);
138         if (!tp)
139                 return ERR_PTR(-ENOBUFS);
140
141         err = -ENOENT;
142         tp->ops = tcf_proto_lookup_ops(kind);
143         if (!tp->ops) {
144 #ifdef CONFIG_MODULES
145                 rtnl_unlock();
146                 request_module("cls_%s", kind);
147                 rtnl_lock();
148                 tp->ops = tcf_proto_lookup_ops(kind);
149                 /* We dropped the RTNL semaphore in order to perform
150                  * the module load. So, even if we succeeded in loading
151                  * the module we have to replay the request. We indicate
152                  * this using -EAGAIN.
153                  */
154                 if (tp->ops) {
155                         module_put(tp->ops->owner);
156                         err = -EAGAIN;
157                 } else {
158                         err = -ENOENT;
159                 }
160                 goto errout;
161 #endif
162         }
163         tp->classify = tp->ops->classify;
164         tp->protocol = protocol;
165         tp->prio = prio;
166         tp->classid = parent;
167         tp->q = q;
168
169         err = tp->ops->init(tp);
170         if (err) {
171                 module_put(tp->ops->owner);
172                 goto errout;
173         }
174         return tp;
175
176 errout:
177         kfree(tp);
178         return ERR_PTR(err);
179 }
180
181 static bool tcf_proto_destroy(struct tcf_proto *tp, bool force)
182 {
183         if (tp->ops->destroy(tp, force)) {
184                 module_put(tp->ops->owner);
185                 kfree_rcu(tp, rcu);
186                 return true;
187         }
188         return false;
189 }
190
191 void tcf_destroy_chain(struct tcf_proto __rcu **fl)
192 {
193         struct tcf_proto *tp;
194
195         while ((tp = rtnl_dereference(*fl)) != NULL) {
196                 RCU_INIT_POINTER(*fl, tp->next);
197                 tcf_proto_destroy(tp, true);
198         }
199 }
200 EXPORT_SYMBOL(tcf_destroy_chain);
201
202 /* Add/change/delete/get a filter node */
203
204 static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
205                           struct netlink_ext_ack *extack)
206 {
207         struct net *net = sock_net(skb->sk);
208         struct nlattr *tca[TCA_MAX + 1];
209         struct tcmsg *t;
210         u32 protocol;
211         u32 prio;
212         u32 nprio;
213         u32 parent;
214         struct net_device *dev;
215         struct Qdisc  *q;
216         struct tcf_proto __rcu **back;
217         struct tcf_proto __rcu **chain;
218         struct tcf_proto *next;
219         struct tcf_proto *tp;
220         const struct Qdisc_class_ops *cops;
221         unsigned long cl;
222         unsigned long fh;
223         int err;
224         int tp_created;
225
226         if ((n->nlmsg_type != RTM_GETTFILTER) &&
227             !netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
228                 return -EPERM;
229
230 replay:
231         tp_created = 0;
232
233         err = nlmsg_parse(n, sizeof(*t), tca, TCA_MAX, NULL, extack);
234         if (err < 0)
235                 return err;
236
237         t = nlmsg_data(n);
238         protocol = TC_H_MIN(t->tcm_info);
239         prio = TC_H_MAJ(t->tcm_info);
240         nprio = prio;
241         parent = t->tcm_parent;
242         cl = 0;
243
244         if (prio == 0) {
245                 switch (n->nlmsg_type) {
246                 case RTM_DELTFILTER:
247                         if (protocol || t->tcm_handle || tca[TCA_KIND])
248                                 return -ENOENT;
249                         break;
250                 case RTM_NEWTFILTER:
251                         /* If no priority is provided by the user,
252                          * we allocate one.
253                          */
254                         if (n->nlmsg_flags & NLM_F_CREATE) {
255                                 prio = TC_H_MAKE(0x80000000U, 0U);
256                                 break;
257                         }
258                         /* fall-through */
259                 default:
260                         return -ENOENT;
261                 }
262         }
263
264         /* Find head of filter chain. */
265
266         /* Find link */
267         dev = __dev_get_by_index(net, t->tcm_ifindex);
268         if (dev == NULL)
269                 return -ENODEV;
270
271         /* Find qdisc */
272         if (!parent) {
273                 q = dev->qdisc;
274                 parent = q->handle;
275         } else {
276                 q = qdisc_lookup(dev, TC_H_MAJ(t->tcm_parent));
277                 if (q == NULL)
278                         return -EINVAL;
279         }
280
281         /* Is it classful? */
282         cops = q->ops->cl_ops;
283         if (!cops)
284                 return -EINVAL;
285
286         if (cops->tcf_chain == NULL)
287                 return -EOPNOTSUPP;
288
289         /* Do we search for filter, attached to class? */
290         if (TC_H_MIN(parent)) {
291                 cl = cops->get(q, parent);
292                 if (cl == 0)
293                         return -ENOENT;
294         }
295
296         /* And the last stroke */
297         chain = cops->tcf_chain(q, cl);
298         if (chain == NULL) {
299                 err = -EINVAL;
300                 goto errout;
301         }
302         if (n->nlmsg_type == RTM_DELTFILTER && prio == 0) {
303                 tfilter_notify_chain(net, skb, n, chain, RTM_DELTFILTER);
304                 tcf_destroy_chain(chain);
305                 err = 0;
306                 goto errout;
307         }
308
309         /* Check the chain for existence of proto-tcf with this priority */
310         for (back = chain;
311              (tp = rtnl_dereference(*back)) != NULL;
312              back = &tp->next) {
313                 if (tp->prio >= prio) {
314                         if (tp->prio == prio) {
315                                 if (!nprio ||
316                                     (tp->protocol != protocol && protocol)) {
317                                         err = -EINVAL;
318                                         goto errout;
319                                 }
320                         } else {
321                                 tp = NULL;
322                         }
323                         break;
324                 }
325         }
326
327         if (tp == NULL) {
328                 /* Proto-tcf does not exist, create new one */
329
330                 if (tca[TCA_KIND] == NULL || !protocol) {
331                         err = -EINVAL;
332                         goto errout;
333                 }
334
335                 if (n->nlmsg_type != RTM_NEWTFILTER ||
336                     !(n->nlmsg_flags & NLM_F_CREATE)) {
337                         err = -ENOENT;
338                         goto errout;
339                 }
340
341                 if (!nprio)
342                         nprio = TC_H_MAJ(tcf_auto_prio(rtnl_dereference(*back)));
343
344                 tp = tcf_proto_create(nla_data(tca[TCA_KIND]),
345                                       protocol, nprio, parent, q);
346                 if (IS_ERR(tp)) {
347                         err = PTR_ERR(tp);
348                         goto errout;
349                 }
350                 tp_created = 1;
351         } else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind)) {
352                 err = -EINVAL;
353                 goto errout;
354         }
355
356         fh = tp->ops->get(tp, t->tcm_handle);
357
358         if (fh == 0) {
359                 if (n->nlmsg_type == RTM_DELTFILTER && t->tcm_handle == 0) {
360                         next = rtnl_dereference(tp->next);
361                         RCU_INIT_POINTER(*back, next);
362                         tfilter_notify(net, skb, n, tp, fh,
363                                        RTM_DELTFILTER, false);
364                         tcf_proto_destroy(tp, true);
365                         err = 0;
366                         goto errout;
367                 }
368
369                 if (n->nlmsg_type != RTM_NEWTFILTER ||
370                     !(n->nlmsg_flags & NLM_F_CREATE)) {
371                         err = -ENOENT;
372                         goto errout;
373                 }
374         } else {
375                 switch (n->nlmsg_type) {
376                 case RTM_NEWTFILTER:
377                         if (n->nlmsg_flags & NLM_F_EXCL) {
378                                 if (tp_created)
379                                         tcf_proto_destroy(tp, true);
380                                 err = -EEXIST;
381                                 goto errout;
382                         }
383                         break;
384                 case RTM_DELTFILTER:
385                         err = tp->ops->delete(tp, fh);
386                         if (err)
387                                 goto errout;
388                         next = rtnl_dereference(tp->next);
389                         tfilter_notify(net, skb, n, tp, t->tcm_handle,
390                                        RTM_DELTFILTER, false);
391                         if (tcf_proto_destroy(tp, false))
392                                 RCU_INIT_POINTER(*back, next);
393                         goto errout;
394                 case RTM_GETTFILTER:
395                         err = tfilter_notify(net, skb, n, tp, fh,
396                                              RTM_NEWTFILTER, true);
397                         goto errout;
398                 default:
399                         err = -EINVAL;
400                         goto errout;
401                 }
402         }
403
404         err = tp->ops->change(net, skb, tp, cl, t->tcm_handle, tca, &fh,
405                               n->nlmsg_flags & NLM_F_CREATE ? TCA_ACT_NOREPLACE : TCA_ACT_REPLACE);
406         if (err == 0) {
407                 if (tp_created) {
408                         RCU_INIT_POINTER(tp->next, rtnl_dereference(*back));
409                         rcu_assign_pointer(*back, tp);
410                 }
411                 tfilter_notify(net, skb, n, tp, fh, RTM_NEWTFILTER, false);
412         } else {
413                 if (tp_created)
414                         tcf_proto_destroy(tp, true);
415         }
416
417 errout:
418         if (cl)
419                 cops->put(q, cl);
420         if (err == -EAGAIN)
421                 /* Replay the request. */
422                 goto replay;
423         return err;
424 }
425
426 static int tcf_fill_node(struct net *net, struct sk_buff *skb,
427                          struct tcf_proto *tp, unsigned long fh, u32 portid,
428                          u32 seq, u16 flags, int event)
429 {
430         struct tcmsg *tcm;
431         struct nlmsghdr  *nlh;
432         unsigned char *b = skb_tail_pointer(skb);
433
434         nlh = nlmsg_put(skb, portid, seq, event, sizeof(*tcm), flags);
435         if (!nlh)
436                 goto out_nlmsg_trim;
437         tcm = nlmsg_data(nlh);
438         tcm->tcm_family = AF_UNSPEC;
439         tcm->tcm__pad1 = 0;
440         tcm->tcm__pad2 = 0;
441         tcm->tcm_ifindex = qdisc_dev(tp->q)->ifindex;
442         tcm->tcm_parent = tp->classid;
443         tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol);
444         if (nla_put_string(skb, TCA_KIND, tp->ops->kind))
445                 goto nla_put_failure;
446         tcm->tcm_handle = fh;
447         if (RTM_DELTFILTER != event) {
448                 tcm->tcm_handle = 0;
449                 if (tp->ops->dump && tp->ops->dump(net, tp, fh, skb, tcm) < 0)
450                         goto nla_put_failure;
451         }
452         nlh->nlmsg_len = skb_tail_pointer(skb) - b;
453         return skb->len;
454
455 out_nlmsg_trim:
456 nla_put_failure:
457         nlmsg_trim(skb, b);
458         return -1;
459 }
460
461 static int tfilter_notify(struct net *net, struct sk_buff *oskb,
462                           struct nlmsghdr *n, struct tcf_proto *tp,
463                           unsigned long fh, int event, bool unicast)
464 {
465         struct sk_buff *skb;
466         u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
467
468         skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
469         if (!skb)
470                 return -ENOBUFS;
471
472         if (tcf_fill_node(net, skb, tp, fh, portid, n->nlmsg_seq,
473                           n->nlmsg_flags, event) <= 0) {
474                 kfree_skb(skb);
475                 return -EINVAL;
476         }
477
478         if (unicast)
479                 return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
480
481         return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
482                               n->nlmsg_flags & NLM_F_ECHO);
483 }
484
485 struct tcf_dump_args {
486         struct tcf_walker w;
487         struct sk_buff *skb;
488         struct netlink_callback *cb;
489 };
490
491 static int tcf_node_dump(struct tcf_proto *tp, unsigned long n,
492                          struct tcf_walker *arg)
493 {
494         struct tcf_dump_args *a = (void *)arg;
495         struct net *net = sock_net(a->skb->sk);
496
497         return tcf_fill_node(net, a->skb, tp, n, NETLINK_CB(a->cb->skb).portid,
498                              a->cb->nlh->nlmsg_seq, NLM_F_MULTI,
499                              RTM_NEWTFILTER);
500 }
501
502 /* called with RTNL */
503 static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
504 {
505         struct net *net = sock_net(skb->sk);
506         int t;
507         int s_t;
508         struct net_device *dev;
509         struct Qdisc *q;
510         struct tcf_proto *tp, __rcu **chain;
511         struct tcmsg *tcm = nlmsg_data(cb->nlh);
512         unsigned long cl = 0;
513         const struct Qdisc_class_ops *cops;
514         struct tcf_dump_args arg;
515
516         if (nlmsg_len(cb->nlh) < sizeof(*tcm))
517                 return skb->len;
518         dev = __dev_get_by_index(net, tcm->tcm_ifindex);
519         if (!dev)
520                 return skb->len;
521
522         if (!tcm->tcm_parent)
523                 q = dev->qdisc;
524         else
525                 q = qdisc_lookup(dev, TC_H_MAJ(tcm->tcm_parent));
526         if (!q)
527                 goto out;
528         cops = q->ops->cl_ops;
529         if (!cops)
530                 goto errout;
531         if (cops->tcf_chain == NULL)
532                 goto errout;
533         if (TC_H_MIN(tcm->tcm_parent)) {
534                 cl = cops->get(q, tcm->tcm_parent);
535                 if (cl == 0)
536                         goto errout;
537         }
538         chain = cops->tcf_chain(q, cl);
539         if (chain == NULL)
540                 goto errout;
541
542         s_t = cb->args[0];
543
544         for (tp = rtnl_dereference(*chain), t = 0;
545              tp; tp = rtnl_dereference(tp->next), t++) {
546                 if (t < s_t)
547                         continue;
548                 if (TC_H_MAJ(tcm->tcm_info) &&
549                     TC_H_MAJ(tcm->tcm_info) != tp->prio)
550                         continue;
551                 if (TC_H_MIN(tcm->tcm_info) &&
552                     TC_H_MIN(tcm->tcm_info) != tp->protocol)
553                         continue;
554                 if (t > s_t)
555                         memset(&cb->args[1], 0,
556                                sizeof(cb->args)-sizeof(cb->args[0]));
557                 if (cb->args[1] == 0) {
558                         if (tcf_fill_node(net, skb, tp, 0,
559                                           NETLINK_CB(cb->skb).portid,
560                                           cb->nlh->nlmsg_seq, NLM_F_MULTI,
561                                           RTM_NEWTFILTER) <= 0)
562                                 break;
563
564                         cb->args[1] = 1;
565                 }
566                 if (tp->ops->walk == NULL)
567                         continue;
568                 arg.w.fn = tcf_node_dump;
569                 arg.skb = skb;
570                 arg.cb = cb;
571                 arg.w.stop = 0;
572                 arg.w.skip = cb->args[1] - 1;
573                 arg.w.count = 0;
574                 tp->ops->walk(tp, &arg.w);
575                 cb->args[1] = arg.w.count + 1;
576                 if (arg.w.stop)
577                         break;
578         }
579
580         cb->args[0] = t;
581
582 errout:
583         if (cl)
584                 cops->put(q, cl);
585 out:
586         return skb->len;
587 }
588
589 void tcf_exts_destroy(struct tcf_exts *exts)
590 {
591 #ifdef CONFIG_NET_CLS_ACT
592         LIST_HEAD(actions);
593
594         tcf_exts_to_list(exts, &actions);
595         tcf_action_destroy(&actions, TCA_ACT_UNBIND);
596         kfree(exts->actions);
597         exts->nr_actions = 0;
598 #endif
599 }
600 EXPORT_SYMBOL(tcf_exts_destroy);
601
602 int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
603                       struct nlattr *rate_tlv, struct tcf_exts *exts, bool ovr)
604 {
605 #ifdef CONFIG_NET_CLS_ACT
606         {
607                 struct tc_action *act;
608
609                 if (exts->police && tb[exts->police]) {
610                         act = tcf_action_init_1(net, tb[exts->police], rate_tlv,
611                                                 "police", ovr, TCA_ACT_BIND);
612                         if (IS_ERR(act))
613                                 return PTR_ERR(act);
614
615                         act->type = exts->type = TCA_OLD_COMPAT;
616                         exts->actions[0] = act;
617                         exts->nr_actions = 1;
618                 } else if (exts->action && tb[exts->action]) {
619                         LIST_HEAD(actions);
620                         int err, i = 0;
621
622                         err = tcf_action_init(net, tb[exts->action], rate_tlv,
623                                               NULL, ovr, TCA_ACT_BIND,
624                                               &actions);
625                         if (err)
626                                 return err;
627                         list_for_each_entry(act, &actions, list)
628                                 exts->actions[i++] = act;
629                         exts->nr_actions = i;
630                 }
631         }
632 #else
633         if ((exts->action && tb[exts->action]) ||
634             (exts->police && tb[exts->police]))
635                 return -EOPNOTSUPP;
636 #endif
637
638         return 0;
639 }
640 EXPORT_SYMBOL(tcf_exts_validate);
641
642 void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
643                      struct tcf_exts *src)
644 {
645 #ifdef CONFIG_NET_CLS_ACT
646         struct tcf_exts old = *dst;
647
648         tcf_tree_lock(tp);
649         dst->nr_actions = src->nr_actions;
650         dst->actions = src->actions;
651         dst->type = src->type;
652         tcf_tree_unlock(tp);
653
654         tcf_exts_destroy(&old);
655 #endif
656 }
657 EXPORT_SYMBOL(tcf_exts_change);
658
659 #ifdef CONFIG_NET_CLS_ACT
660 static struct tc_action *tcf_exts_first_act(struct tcf_exts *exts)
661 {
662         if (exts->nr_actions == 0)
663                 return NULL;
664         else
665                 return exts->actions[0];
666 }
667 #endif
668
669 int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
670 {
671 #ifdef CONFIG_NET_CLS_ACT
672         struct nlattr *nest;
673
674         if (exts->action && exts->nr_actions) {
675                 /*
676                  * again for backward compatible mode - we want
677                  * to work with both old and new modes of entering
678                  * tc data even if iproute2  was newer - jhs
679                  */
680                 if (exts->type != TCA_OLD_COMPAT) {
681                         LIST_HEAD(actions);
682
683                         nest = nla_nest_start(skb, exts->action);
684                         if (nest == NULL)
685                                 goto nla_put_failure;
686
687                         tcf_exts_to_list(exts, &actions);
688                         if (tcf_action_dump(skb, &actions, 0, 0) < 0)
689                                 goto nla_put_failure;
690                         nla_nest_end(skb, nest);
691                 } else if (exts->police) {
692                         struct tc_action *act = tcf_exts_first_act(exts);
693                         nest = nla_nest_start(skb, exts->police);
694                         if (nest == NULL || !act)
695                                 goto nla_put_failure;
696                         if (tcf_action_dump_old(skb, act, 0, 0) < 0)
697                                 goto nla_put_failure;
698                         nla_nest_end(skb, nest);
699                 }
700         }
701         return 0;
702
703 nla_put_failure:
704         nla_nest_cancel(skb, nest);
705         return -1;
706 #else
707         return 0;
708 #endif
709 }
710 EXPORT_SYMBOL(tcf_exts_dump);
711
712
713 int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts)
714 {
715 #ifdef CONFIG_NET_CLS_ACT
716         struct tc_action *a = tcf_exts_first_act(exts);
717         if (a != NULL && tcf_action_copy_stats(skb, a, 1) < 0)
718                 return -1;
719 #endif
720         return 0;
721 }
722 EXPORT_SYMBOL(tcf_exts_dump_stats);
723
724 int tcf_exts_get_dev(struct net_device *dev, struct tcf_exts *exts,
725                      struct net_device **hw_dev)
726 {
727 #ifdef CONFIG_NET_CLS_ACT
728         const struct tc_action *a;
729         LIST_HEAD(actions);
730
731         if (tc_no_actions(exts))
732                 return -EINVAL;
733
734         tcf_exts_to_list(exts, &actions);
735         list_for_each_entry(a, &actions, list) {
736                 if (a->ops->get_dev) {
737                         a->ops->get_dev(a, dev_net(dev), hw_dev);
738                         break;
739                 }
740         }
741         if (*hw_dev)
742                 return 0;
743 #endif
744         return -EOPNOTSUPP;
745 }
746 EXPORT_SYMBOL(tcf_exts_get_dev);
747
748 static int __init tc_filter_init(void)
749 {
750         rtnl_register(PF_UNSPEC, RTM_NEWTFILTER, tc_ctl_tfilter, NULL, NULL);
751         rtnl_register(PF_UNSPEC, RTM_DELTFILTER, tc_ctl_tfilter, NULL, NULL);
752         rtnl_register(PF_UNSPEC, RTM_GETTFILTER, tc_ctl_tfilter,
753                       tc_dump_tfilter, NULL);
754
755         return 0;
756 }
757
758 subsys_initcall(tc_filter_init);