2 * net/sched/cls_api.c Packet classifier API.
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.
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
13 * Eduardo J. Blanco <ejbs@netlabs.com.uy> :990222: kmod support
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>
30 #include <net/netlink.h>
31 #include <net/pkt_sched.h>
32 #include <net/pkt_cls.h>
34 /* The list of all installed classifier types */
35 static LIST_HEAD(tcf_proto_base
);
37 /* Protects list of registered TC modules. It is pure SMP lock. */
38 static DEFINE_RWLOCK(cls_mod_lock
);
40 /* Find classifier type by string name */
42 static const struct tcf_proto_ops
*tcf_proto_lookup_ops(const char *kind
)
44 const struct tcf_proto_ops
*t
, *res
= NULL
;
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
))
55 read_unlock(&cls_mod_lock
);
60 /* Register(unregister) new classifier type */
62 int register_tcf_proto_ops(struct tcf_proto_ops
*ops
)
64 struct tcf_proto_ops
*t
;
67 write_lock(&cls_mod_lock
);
68 list_for_each_entry(t
, &tcf_proto_base
, head
)
69 if (!strcmp(ops
->kind
, t
->kind
))
72 list_add_tail(&ops
->head
, &tcf_proto_base
);
75 write_unlock(&cls_mod_lock
);
78 EXPORT_SYMBOL(register_tcf_proto_ops
);
80 int unregister_tcf_proto_ops(struct tcf_proto_ops
*ops
)
82 struct tcf_proto_ops
*t
;
85 /* Wait for outstanding call_rcu()s, if any, from a
86 * tcf_proto_ops's destroy() handler.
90 write_lock(&cls_mod_lock
);
91 list_for_each_entry(t
, &tcf_proto_base
, head
) {
98 write_unlock(&cls_mod_lock
);
101 EXPORT_SYMBOL(unregister_tcf_proto_ops
);
103 /* Select new prio value from the range, managed by kernel. */
105 static inline u32
tcf_auto_prio(struct tcf_proto
*tp
)
107 u32 first
= TC_H_MAKE(0xC0000000U
, 0U);
110 first
= tp
->prio
- 1;
112 return TC_H_MAJ(first
);
115 static struct tcf_proto
*tcf_proto_create(const char *kind
, u32 protocol
,
116 u32 prio
, u32 parent
, struct Qdisc
*q
,
117 struct tcf_chain
*chain
)
119 struct tcf_proto
*tp
;
122 tp
= kzalloc(sizeof(*tp
), GFP_KERNEL
);
124 return ERR_PTR(-ENOBUFS
);
127 tp
->ops
= tcf_proto_lookup_ops(kind
);
129 #ifdef CONFIG_MODULES
131 request_module("cls_%s", kind
);
133 tp
->ops
= tcf_proto_lookup_ops(kind
);
134 /* We dropped the RTNL semaphore in order to perform
135 * the module load. So, even if we succeeded in loading
136 * the module we have to replay the request. We indicate
137 * this using -EAGAIN.
140 module_put(tp
->ops
->owner
);
148 tp
->classify
= tp
->ops
->classify
;
149 tp
->protocol
= protocol
;
151 tp
->classid
= parent
;
155 err
= tp
->ops
->init(tp
);
157 module_put(tp
->ops
->owner
);
167 static void tcf_proto_destroy(struct tcf_proto
*tp
)
169 tp
->ops
->destroy(tp
);
170 module_put(tp
->ops
->owner
);
174 static struct tcf_chain
*tcf_chain_create(struct tcf_block
*block
,
177 struct tcf_chain
*chain
;
179 chain
= kzalloc(sizeof(*chain
), GFP_KERNEL
);
182 list_add_tail(&chain
->list
, &block
->chain_list
);
183 chain
->block
= block
;
184 chain
->index
= chain_index
;
189 static void tcf_chain_flush(struct tcf_chain
*chain
)
191 struct tcf_proto
*tp
;
193 if (chain
->p_filter_chain
)
194 RCU_INIT_POINTER(*chain
->p_filter_chain
, NULL
);
195 while ((tp
= rtnl_dereference(chain
->filter_chain
)) != NULL
) {
196 RCU_INIT_POINTER(chain
->filter_chain
, tp
->next
);
197 tcf_proto_destroy(tp
);
201 static void tcf_chain_destroy(struct tcf_chain
*chain
)
203 /* May be already removed from the list by the previous call. */
204 if (!list_empty(&chain
->list
))
205 list_del_init(&chain
->list
);
207 /* There might still be a reference held when we got here from
208 * tcf_block_put. Wait for the user to drop reference before free.
214 struct tcf_chain
*tcf_chain_get(struct tcf_block
*block
, u32 chain_index
,
217 struct tcf_chain
*chain
;
219 list_for_each_entry(chain
, &block
->chain_list
, list
) {
220 if (chain
->index
== chain_index
)
223 chain
= create
? tcf_chain_create(block
, chain_index
) : NULL
;
230 EXPORT_SYMBOL(tcf_chain_get
);
232 void tcf_chain_put(struct tcf_chain
*chain
)
234 /* Destroy unused chain, with exception of chain 0, which is the
235 * default one and has to be always present.
237 if (--chain
->refcnt
== 0 && !chain
->filter_chain
&& chain
->index
!= 0)
238 tcf_chain_destroy(chain
);
240 EXPORT_SYMBOL(tcf_chain_put
);
243 tcf_chain_filter_chain_ptr_set(struct tcf_chain
*chain
,
244 struct tcf_proto __rcu
**p_filter_chain
)
246 chain
->p_filter_chain
= p_filter_chain
;
249 int tcf_block_get(struct tcf_block
**p_block
,
250 struct tcf_proto __rcu
**p_filter_chain
)
252 struct tcf_block
*block
= kzalloc(sizeof(*block
), GFP_KERNEL
);
253 struct tcf_chain
*chain
;
258 INIT_LIST_HEAD(&block
->chain_list
);
259 /* Create chain 0 by default, it has to be always present. */
260 chain
= tcf_chain_create(block
, 0);
263 goto err_chain_create
;
265 tcf_chain_filter_chain_ptr_set(chain
, p_filter_chain
);
273 EXPORT_SYMBOL(tcf_block_get
);
275 void tcf_block_put(struct tcf_block
*block
)
277 struct tcf_chain
*chain
, *tmp
;
282 list_for_each_entry_safe(chain
, tmp
, &block
->chain_list
, list
) {
283 tcf_chain_flush(chain
);
284 tcf_chain_destroy(chain
);
288 EXPORT_SYMBOL(tcf_block_put
);
290 /* Main classifier routine: scans classifier chain attached
291 * to this qdisc, (optionally) tests for protocol and asks
292 * specific classifiers.
294 int tcf_classify(struct sk_buff
*skb
, const struct tcf_proto
*tp
,
295 struct tcf_result
*res
, bool compat_mode
)
297 __be16 protocol
= tc_skb_protocol(skb
);
298 #ifdef CONFIG_NET_CLS_ACT
299 const int max_reclassify_loop
= 4;
300 const struct tcf_proto
*orig_tp
= tp
;
301 const struct tcf_proto
*first_tp
;
306 for (; tp
; tp
= rcu_dereference_bh(tp
->next
)) {
309 if (tp
->protocol
!= protocol
&&
310 tp
->protocol
!= htons(ETH_P_ALL
))
313 err
= tp
->classify(skb
, tp
, res
);
314 #ifdef CONFIG_NET_CLS_ACT
315 if (unlikely(err
== TC_ACT_RECLASSIFY
&& !compat_mode
)) {
318 } else if (unlikely(TC_ACT_EXT_CMP(err
, TC_ACT_GOTO_CHAIN
))) {
319 first_tp
= res
->goto_tp
;
327 return TC_ACT_UNSPEC
; /* signal: continue lookup */
328 #ifdef CONFIG_NET_CLS_ACT
330 if (unlikely(limit
++ >= max_reclassify_loop
)) {
331 net_notice_ratelimited("%s: reclassify loop, rule prio %u, protocol %02x\n",
332 tp
->q
->ops
->id
, tp
->prio
& 0xffff,
333 ntohs(tp
->protocol
));
338 protocol
= tc_skb_protocol(skb
);
342 EXPORT_SYMBOL(tcf_classify
);
344 struct tcf_chain_info
{
345 struct tcf_proto __rcu
**pprev
;
346 struct tcf_proto __rcu
*next
;
349 static struct tcf_proto
*tcf_chain_tp_prev(struct tcf_chain_info
*chain_info
)
351 return rtnl_dereference(*chain_info
->pprev
);
354 static void tcf_chain_tp_insert(struct tcf_chain
*chain
,
355 struct tcf_chain_info
*chain_info
,
356 struct tcf_proto
*tp
)
358 if (chain
->p_filter_chain
&&
359 *chain_info
->pprev
== chain
->filter_chain
)
360 rcu_assign_pointer(*chain
->p_filter_chain
, tp
);
361 RCU_INIT_POINTER(tp
->next
, tcf_chain_tp_prev(chain_info
));
362 rcu_assign_pointer(*chain_info
->pprev
, tp
);
365 static void tcf_chain_tp_remove(struct tcf_chain
*chain
,
366 struct tcf_chain_info
*chain_info
,
367 struct tcf_proto
*tp
)
369 struct tcf_proto
*next
= rtnl_dereference(chain_info
->next
);
371 if (chain
->p_filter_chain
&& tp
== chain
->filter_chain
)
372 RCU_INIT_POINTER(*chain
->p_filter_chain
, next
);
373 RCU_INIT_POINTER(*chain_info
->pprev
, next
);
376 static struct tcf_proto
*tcf_chain_tp_find(struct tcf_chain
*chain
,
377 struct tcf_chain_info
*chain_info
,
378 u32 protocol
, u32 prio
,
381 struct tcf_proto
**pprev
;
382 struct tcf_proto
*tp
;
384 /* Check the chain for existence of proto-tcf with this priority */
385 for (pprev
= &chain
->filter_chain
;
386 (tp
= rtnl_dereference(*pprev
)); pprev
= &tp
->next
) {
387 if (tp
->prio
>= prio
) {
388 if (tp
->prio
== prio
) {
390 (tp
->protocol
!= protocol
&& protocol
))
391 return ERR_PTR(-EINVAL
);
398 chain_info
->pprev
= pprev
;
399 chain_info
->next
= tp
? tp
->next
: NULL
;
403 static int tcf_fill_node(struct net
*net
, struct sk_buff
*skb
,
404 struct tcf_proto
*tp
, void *fh
, u32 portid
,
405 u32 seq
, u16 flags
, int event
)
408 struct nlmsghdr
*nlh
;
409 unsigned char *b
= skb_tail_pointer(skb
);
411 nlh
= nlmsg_put(skb
, portid
, seq
, event
, sizeof(*tcm
), flags
);
414 tcm
= nlmsg_data(nlh
);
415 tcm
->tcm_family
= AF_UNSPEC
;
418 tcm
->tcm_ifindex
= qdisc_dev(tp
->q
)->ifindex
;
419 tcm
->tcm_parent
= tp
->classid
;
420 tcm
->tcm_info
= TC_H_MAKE(tp
->prio
, tp
->protocol
);
421 if (nla_put_string(skb
, TCA_KIND
, tp
->ops
->kind
))
422 goto nla_put_failure
;
423 if (nla_put_u32(skb
, TCA_CHAIN
, tp
->chain
->index
))
424 goto nla_put_failure
;
428 if (tp
->ops
->dump
&& tp
->ops
->dump(net
, tp
, fh
, skb
, tcm
) < 0)
429 goto nla_put_failure
;
431 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
440 static int tfilter_notify(struct net
*net
, struct sk_buff
*oskb
,
441 struct nlmsghdr
*n
, struct tcf_proto
*tp
,
442 void *fh
, int event
, bool unicast
)
445 u32 portid
= oskb
? NETLINK_CB(oskb
).portid
: 0;
447 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
451 if (tcf_fill_node(net
, skb
, tp
, fh
, portid
, n
->nlmsg_seq
,
452 n
->nlmsg_flags
, event
) <= 0) {
458 return netlink_unicast(net
->rtnl
, skb
, portid
, MSG_DONTWAIT
);
460 return rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
461 n
->nlmsg_flags
& NLM_F_ECHO
);
464 static int tfilter_del_notify(struct net
*net
, struct sk_buff
*oskb
,
465 struct nlmsghdr
*n
, struct tcf_proto
*tp
,
466 void *fh
, bool unicast
, bool *last
)
469 u32 portid
= oskb
? NETLINK_CB(oskb
).portid
: 0;
472 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
476 if (tcf_fill_node(net
, skb
, tp
, fh
, portid
, n
->nlmsg_seq
,
477 n
->nlmsg_flags
, RTM_DELTFILTER
) <= 0) {
482 err
= tp
->ops
->delete(tp
, fh
, last
);
489 return netlink_unicast(net
->rtnl
, skb
, portid
, MSG_DONTWAIT
);
491 return rtnetlink_send(skb
, net
, portid
, RTNLGRP_TC
,
492 n
->nlmsg_flags
& NLM_F_ECHO
);
495 static void tfilter_notify_chain(struct net
*net
, struct sk_buff
*oskb
,
497 struct tcf_chain
*chain
, int event
)
499 struct tcf_proto
*tp
;
501 for (tp
= rtnl_dereference(chain
->filter_chain
);
502 tp
; tp
= rtnl_dereference(tp
->next
))
503 tfilter_notify(net
, oskb
, n
, tp
, 0, event
, false);
506 /* Add/change/delete/get a filter node */
508 static int tc_ctl_tfilter(struct sk_buff
*skb
, struct nlmsghdr
*n
,
509 struct netlink_ext_ack
*extack
)
511 struct net
*net
= sock_net(skb
->sk
);
512 struct nlattr
*tca
[TCA_MAX
+ 1];
519 struct net_device
*dev
;
521 struct tcf_chain_info chain_info
;
522 struct tcf_chain
*chain
= NULL
;
523 struct tcf_block
*block
;
524 struct tcf_proto
*tp
;
525 const struct Qdisc_class_ops
*cops
;
531 if ((n
->nlmsg_type
!= RTM_GETTFILTER
) &&
532 !netlink_ns_capable(skb
, net
->user_ns
, CAP_NET_ADMIN
))
538 err
= nlmsg_parse(n
, sizeof(*t
), tca
, TCA_MAX
, NULL
, extack
);
543 protocol
= TC_H_MIN(t
->tcm_info
);
544 prio
= TC_H_MAJ(t
->tcm_info
);
545 prio_allocate
= false;
546 parent
= t
->tcm_parent
;
550 switch (n
->nlmsg_type
) {
552 if (protocol
|| t
->tcm_handle
|| tca
[TCA_KIND
])
556 /* If no priority is provided by the user,
559 if (n
->nlmsg_flags
& NLM_F_CREATE
) {
560 prio
= TC_H_MAKE(0x80000000U
, 0U);
561 prio_allocate
= true;
570 /* Find head of filter chain. */
573 dev
= __dev_get_by_index(net
, t
->tcm_ifindex
);
582 q
= qdisc_lookup(dev
, TC_H_MAJ(t
->tcm_parent
));
587 /* Is it classful? */
588 cops
= q
->ops
->cl_ops
;
592 if (!cops
->tcf_block
)
595 /* Do we search for filter, attached to class? */
596 if (TC_H_MIN(parent
)) {
597 cl
= cops
->find(q
, parent
);
602 /* And the last stroke */
603 block
= cops
->tcf_block(q
, cl
);
609 chain_index
= tca
[TCA_CHAIN
] ? nla_get_u32(tca
[TCA_CHAIN
]) : 0;
610 if (chain_index
> TC_ACT_EXT_VAL_MASK
) {
614 chain
= tcf_chain_get(block
, chain_index
,
615 n
->nlmsg_type
== RTM_NEWTFILTER
);
617 err
= n
->nlmsg_type
== RTM_NEWTFILTER
? -ENOMEM
: -EINVAL
;
621 if (n
->nlmsg_type
== RTM_DELTFILTER
&& prio
== 0) {
622 tfilter_notify_chain(net
, skb
, n
, chain
, RTM_DELTFILTER
);
623 tcf_chain_flush(chain
);
628 tp
= tcf_chain_tp_find(chain
, &chain_info
, protocol
,
629 prio
, prio_allocate
);
636 /* Proto-tcf does not exist, create new one */
638 if (tca
[TCA_KIND
] == NULL
|| !protocol
) {
643 if (n
->nlmsg_type
!= RTM_NEWTFILTER
||
644 !(n
->nlmsg_flags
& NLM_F_CREATE
)) {
650 prio
= tcf_auto_prio(tcf_chain_tp_prev(&chain_info
));
652 tp
= tcf_proto_create(nla_data(tca
[TCA_KIND
]),
653 protocol
, prio
, parent
, q
, chain
);
659 } else if (tca
[TCA_KIND
] && nla_strcmp(tca
[TCA_KIND
], tp
->ops
->kind
)) {
664 fh
= tp
->ops
->get(tp
, t
->tcm_handle
);
667 if (n
->nlmsg_type
== RTM_DELTFILTER
&& t
->tcm_handle
== 0) {
668 tcf_chain_tp_remove(chain
, &chain_info
, tp
);
669 tfilter_notify(net
, skb
, n
, tp
, fh
,
670 RTM_DELTFILTER
, false);
671 tcf_proto_destroy(tp
);
676 if (n
->nlmsg_type
!= RTM_NEWTFILTER
||
677 !(n
->nlmsg_flags
& NLM_F_CREATE
)) {
684 switch (n
->nlmsg_type
) {
686 if (n
->nlmsg_flags
& NLM_F_EXCL
) {
688 tcf_proto_destroy(tp
);
694 err
= tfilter_del_notify(net
, skb
, n
, tp
, fh
, false,
699 tcf_chain_tp_remove(chain
, &chain_info
, tp
);
700 tcf_proto_destroy(tp
);
704 err
= tfilter_notify(net
, skb
, n
, tp
, fh
,
705 RTM_NEWTFILTER
, true);
713 err
= tp
->ops
->change(net
, skb
, tp
, cl
, t
->tcm_handle
, tca
, &fh
,
714 n
->nlmsg_flags
& NLM_F_CREATE
? TCA_ACT_NOREPLACE
: TCA_ACT_REPLACE
);
717 tcf_chain_tp_insert(chain
, &chain_info
, tp
);
718 tfilter_notify(net
, skb
, n
, tp
, fh
, RTM_NEWTFILTER
, false);
721 tcf_proto_destroy(tp
);
726 tcf_chain_put(chain
);
728 /* Replay the request. */
733 struct tcf_dump_args
{
736 struct netlink_callback
*cb
;
739 static int tcf_node_dump(struct tcf_proto
*tp
, void *n
, struct tcf_walker
*arg
)
741 struct tcf_dump_args
*a
= (void *)arg
;
742 struct net
*net
= sock_net(a
->skb
->sk
);
744 return tcf_fill_node(net
, a
->skb
, tp
, n
, NETLINK_CB(a
->cb
->skb
).portid
,
745 a
->cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
749 static bool tcf_chain_dump(struct tcf_chain
*chain
, struct sk_buff
*skb
,
750 struct netlink_callback
*cb
,
751 long index_start
, long *p_index
)
753 struct net
*net
= sock_net(skb
->sk
);
754 struct tcmsg
*tcm
= nlmsg_data(cb
->nlh
);
755 struct tcf_dump_args arg
;
756 struct tcf_proto
*tp
;
758 for (tp
= rtnl_dereference(chain
->filter_chain
);
759 tp
; tp
= rtnl_dereference(tp
->next
), (*p_index
)++) {
760 if (*p_index
< index_start
)
762 if (TC_H_MAJ(tcm
->tcm_info
) &&
763 TC_H_MAJ(tcm
->tcm_info
) != tp
->prio
)
765 if (TC_H_MIN(tcm
->tcm_info
) &&
766 TC_H_MIN(tcm
->tcm_info
) != tp
->protocol
)
768 if (*p_index
> index_start
)
769 memset(&cb
->args
[1], 0,
770 sizeof(cb
->args
) - sizeof(cb
->args
[0]));
771 if (cb
->args
[1] == 0) {
772 if (tcf_fill_node(net
, skb
, tp
, 0,
773 NETLINK_CB(cb
->skb
).portid
,
774 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
775 RTM_NEWTFILTER
) <= 0)
782 arg
.w
.fn
= tcf_node_dump
;
786 arg
.w
.skip
= cb
->args
[1] - 1;
788 tp
->ops
->walk(tp
, &arg
.w
);
789 cb
->args
[1] = arg
.w
.count
+ 1;
796 /* called with RTNL */
797 static int tc_dump_tfilter(struct sk_buff
*skb
, struct netlink_callback
*cb
)
799 struct net
*net
= sock_net(skb
->sk
);
800 struct nlattr
*tca
[TCA_MAX
+ 1];
801 struct net_device
*dev
;
803 struct tcf_block
*block
;
804 struct tcf_chain
*chain
;
805 struct tcmsg
*tcm
= nlmsg_data(cb
->nlh
);
806 unsigned long cl
= 0;
807 const struct Qdisc_class_ops
*cops
;
812 if (nlmsg_len(cb
->nlh
) < sizeof(*tcm
))
815 err
= nlmsg_parse(cb
->nlh
, sizeof(*tcm
), tca
, TCA_MAX
, NULL
, NULL
);
819 dev
= __dev_get_by_index(net
, tcm
->tcm_ifindex
);
823 if (!tcm
->tcm_parent
)
826 q
= qdisc_lookup(dev
, TC_H_MAJ(tcm
->tcm_parent
));
829 cops
= q
->ops
->cl_ops
;
832 if (!cops
->tcf_block
)
834 if (TC_H_MIN(tcm
->tcm_parent
)) {
835 cl
= cops
->find(q
, tcm
->tcm_parent
);
839 block
= cops
->tcf_block(q
, cl
);
843 index_start
= cb
->args
[0];
846 list_for_each_entry(chain
, &block
->chain_list
, list
) {
847 if (tca
[TCA_CHAIN
] &&
848 nla_get_u32(tca
[TCA_CHAIN
]) != chain
->index
)
850 if (!tcf_chain_dump(chain
, skb
, cb
, index_start
, &index
))
860 void tcf_exts_destroy(struct tcf_exts
*exts
)
862 #ifdef CONFIG_NET_CLS_ACT
865 tcf_exts_to_list(exts
, &actions
);
866 tcf_action_destroy(&actions
, TCA_ACT_UNBIND
);
867 kfree(exts
->actions
);
868 exts
->nr_actions
= 0;
871 EXPORT_SYMBOL(tcf_exts_destroy
);
873 int tcf_exts_validate(struct net
*net
, struct tcf_proto
*tp
, struct nlattr
**tb
,
874 struct nlattr
*rate_tlv
, struct tcf_exts
*exts
, bool ovr
)
876 #ifdef CONFIG_NET_CLS_ACT
878 struct tc_action
*act
;
880 if (exts
->police
&& tb
[exts
->police
]) {
881 act
= tcf_action_init_1(net
, tp
, tb
[exts
->police
],
882 rate_tlv
, "police", ovr
,
887 act
->type
= exts
->type
= TCA_OLD_COMPAT
;
888 exts
->actions
[0] = act
;
889 exts
->nr_actions
= 1;
890 } else if (exts
->action
&& tb
[exts
->action
]) {
894 err
= tcf_action_init(net
, tp
, tb
[exts
->action
],
895 rate_tlv
, NULL
, ovr
, TCA_ACT_BIND
,
899 list_for_each_entry(act
, &actions
, list
)
900 exts
->actions
[i
++] = act
;
901 exts
->nr_actions
= i
;
905 if ((exts
->action
&& tb
[exts
->action
]) ||
906 (exts
->police
&& tb
[exts
->police
]))
912 EXPORT_SYMBOL(tcf_exts_validate
);
914 void tcf_exts_change(struct tcf_exts
*dst
, struct tcf_exts
*src
)
916 #ifdef CONFIG_NET_CLS_ACT
917 struct tcf_exts old
= *dst
;
920 tcf_exts_destroy(&old
);
923 EXPORT_SYMBOL(tcf_exts_change
);
925 #ifdef CONFIG_NET_CLS_ACT
926 static struct tc_action
*tcf_exts_first_act(struct tcf_exts
*exts
)
928 if (exts
->nr_actions
== 0)
931 return exts
->actions
[0];
935 int tcf_exts_dump(struct sk_buff
*skb
, struct tcf_exts
*exts
)
937 #ifdef CONFIG_NET_CLS_ACT
940 if (exts
->action
&& tcf_exts_has_actions(exts
)) {
942 * again for backward compatible mode - we want
943 * to work with both old and new modes of entering
944 * tc data even if iproute2 was newer - jhs
946 if (exts
->type
!= TCA_OLD_COMPAT
) {
949 nest
= nla_nest_start(skb
, exts
->action
);
951 goto nla_put_failure
;
953 tcf_exts_to_list(exts
, &actions
);
954 if (tcf_action_dump(skb
, &actions
, 0, 0) < 0)
955 goto nla_put_failure
;
956 nla_nest_end(skb
, nest
);
957 } else if (exts
->police
) {
958 struct tc_action
*act
= tcf_exts_first_act(exts
);
959 nest
= nla_nest_start(skb
, exts
->police
);
960 if (nest
== NULL
|| !act
)
961 goto nla_put_failure
;
962 if (tcf_action_dump_old(skb
, act
, 0, 0) < 0)
963 goto nla_put_failure
;
964 nla_nest_end(skb
, nest
);
970 nla_nest_cancel(skb
, nest
);
976 EXPORT_SYMBOL(tcf_exts_dump
);
979 int tcf_exts_dump_stats(struct sk_buff
*skb
, struct tcf_exts
*exts
)
981 #ifdef CONFIG_NET_CLS_ACT
982 struct tc_action
*a
= tcf_exts_first_act(exts
);
983 if (a
!= NULL
&& tcf_action_copy_stats(skb
, a
, 1) < 0)
988 EXPORT_SYMBOL(tcf_exts_dump_stats
);
990 int tcf_exts_get_dev(struct net_device
*dev
, struct tcf_exts
*exts
,
991 struct net_device
**hw_dev
)
993 #ifdef CONFIG_NET_CLS_ACT
994 const struct tc_action
*a
;
997 if (!tcf_exts_has_actions(exts
))
1000 tcf_exts_to_list(exts
, &actions
);
1001 list_for_each_entry(a
, &actions
, list
) {
1002 if (a
->ops
->get_dev
) {
1003 a
->ops
->get_dev(a
, dev_net(dev
), hw_dev
);
1012 EXPORT_SYMBOL(tcf_exts_get_dev
);
1014 static int __init
tc_filter_init(void)
1016 rtnl_register(PF_UNSPEC
, RTM_NEWTFILTER
, tc_ctl_tfilter
, NULL
, 0);
1017 rtnl_register(PF_UNSPEC
, RTM_DELTFILTER
, tc_ctl_tfilter
, NULL
, 0);
1018 rtnl_register(PF_UNSPEC
, RTM_GETTFILTER
, tc_ctl_tfilter
,
1019 tc_dump_tfilter
, 0);
1024 subsys_initcall(tc_filter_init
);