2 * net/sched/act_api.c Packet action 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 * Author: Jamal Hadi Salim
14 #include <asm/uaccess.h>
15 #include <asm/system.h>
16 #include <linux/bitops.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/string.h>
21 #include <linux/socket.h>
22 #include <linux/sockios.h>
24 #include <linux/errno.h>
25 #include <linux/interrupt.h>
26 #include <linux/netdevice.h>
27 #include <linux/skbuff.h>
28 #include <linux/rtnetlink.h>
29 #include <linux/init.h>
30 #include <linux/kmod.h>
32 #include <net/sch_generic.h>
33 #include <net/act_api.h>
35 void tcf_hash_destroy(struct tcf_common
*p
, struct tcf_hashinfo
*hinfo
)
37 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
38 struct tcf_common
**p1p
;
40 for (p1p
= &hinfo
->htab
[h
]; *p1p
; p1p
= &(*p1p
)->tcfc_next
) {
42 write_lock_bh(hinfo
->lock
);
44 write_unlock_bh(hinfo
->lock
);
45 #ifdef CONFIG_NET_ESTIMATOR
46 gen_kill_estimator(&p
->tcfc_bstats
,
55 EXPORT_SYMBOL(tcf_hash_destroy
);
57 int tcf_hash_release(struct tcf_common
*p
, int bind
,
58 struct tcf_hashinfo
*hinfo
)
67 if (p
->tcfc_bindcnt
<= 0 && p
->tcfc_refcnt
<= 0) {
68 tcf_hash_destroy(p
, hinfo
);
74 EXPORT_SYMBOL(tcf_hash_release
);
76 static int tcf_dump_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
77 struct tc_action
*a
, struct tcf_hashinfo
*hinfo
)
80 int err
= 0, index
= -1,i
= 0, s_i
= 0, n_i
= 0;
83 read_lock(hinfo
->lock
);
87 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
88 p
= hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
90 for (; p
; p
= p
->tcfc_next
) {
96 r
= (struct rtattr
*) skb
->tail
;
97 RTA_PUT(skb
, a
->order
, 0, NULL
);
98 err
= tcf_action_dump_1(skb
, a
, 0, 0);
101 skb_trim(skb
, (u8
*)r
- skb
->data
);
104 r
->rta_len
= skb
->tail
- (u8
*)r
;
106 if (n_i
>= TCA_ACT_MAX_PRIO
)
111 read_unlock(hinfo
->lock
);
117 skb_trim(skb
, (u8
*)r
- skb
->data
);
121 static int tcf_del_walker(struct sk_buff
*skb
, struct tc_action
*a
,
122 struct tcf_hashinfo
*hinfo
)
124 struct tcf_common
*p
, *s_p
;
128 r
= (struct rtattr
*) skb
->tail
;
129 RTA_PUT(skb
, a
->order
, 0, NULL
);
130 RTA_PUT(skb
, TCA_KIND
, IFNAMSIZ
, a
->ops
->kind
);
131 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
132 p
= hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
136 if (ACT_P_DELETED
== tcf_hash_release(p
, 0, hinfo
))
137 module_put(a
->ops
->owner
);
142 RTA_PUT(skb
, TCA_FCNT
, 4, &n_i
);
143 r
->rta_len
= skb
->tail
- (u8
*)r
;
147 skb_trim(skb
, (u8
*)r
- skb
->data
);
151 int tcf_generic_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
152 int type
, struct tc_action
*a
)
154 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
156 if (type
== RTM_DELACTION
) {
157 return tcf_del_walker(skb
, a
, hinfo
);
158 } else if (type
== RTM_GETACTION
) {
159 return tcf_dump_walker(skb
, cb
, a
, hinfo
);
161 printk("tcf_generic_walker: unknown action %d\n", type
);
165 EXPORT_SYMBOL(tcf_generic_walker
);
167 struct tcf_common
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
169 struct tcf_common
*p
;
171 read_lock(hinfo
->lock
);
172 for (p
= hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)]; p
;
174 if (p
->tcfc_index
== index
)
177 read_unlock(hinfo
->lock
);
181 EXPORT_SYMBOL(tcf_hash_lookup
);
183 u32
tcf_hash_new_index(u32
*idx_gen
, struct tcf_hashinfo
*hinfo
)
190 } while (tcf_hash_lookup(val
, hinfo
));
192 return (*idx_gen
= val
);
194 EXPORT_SYMBOL(tcf_hash_new_index
);
196 int tcf_hash_search(struct tc_action
*a
, u32 index
)
198 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
199 struct tcf_common
*p
= tcf_hash_lookup(index
, hinfo
);
207 EXPORT_SYMBOL(tcf_hash_search
);
209 struct tcf_common
*tcf_hash_check(u32 index
, struct tc_action
*a
, int bind
,
210 struct tcf_hashinfo
*hinfo
)
212 struct tcf_common
*p
= NULL
;
213 if (index
&& (p
= tcf_hash_lookup(index
, hinfo
)) != NULL
) {
222 EXPORT_SYMBOL(tcf_hash_check
);
224 struct tcf_common
*tcf_hash_create(u32 index
, struct rtattr
*est
, struct tc_action
*a
, int size
, int bind
, u32
*idx_gen
, struct tcf_hashinfo
*hinfo
)
226 struct tcf_common
*p
= kzalloc(size
, GFP_KERNEL
);
234 spin_lock_init(&p
->tcfc_lock
);
235 p
->tcfc_stats_lock
= &p
->tcfc_lock
;
236 p
->tcfc_index
= index
? index
: tcf_hash_new_index(idx_gen
, hinfo
);
237 p
->tcfc_tm
.install
= jiffies
;
238 p
->tcfc_tm
.lastuse
= jiffies
;
239 #ifdef CONFIG_NET_ESTIMATOR
241 gen_new_estimator(&p
->tcfc_bstats
, &p
->tcfc_rate_est
,
242 p
->tcfc_stats_lock
, est
);
244 a
->priv
= (void *) p
;
247 EXPORT_SYMBOL(tcf_hash_create
);
249 void tcf_hash_insert(struct tcf_common
*p
, struct tcf_hashinfo
*hinfo
)
251 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
253 write_lock_bh(hinfo
->lock
);
254 p
->tcfc_next
= hinfo
->htab
[h
];
256 write_unlock_bh(hinfo
->lock
);
258 EXPORT_SYMBOL(tcf_hash_insert
);
260 static struct tc_action_ops
*act_base
= NULL
;
261 static DEFINE_RWLOCK(act_mod_lock
);
263 int tcf_register_action(struct tc_action_ops
*act
)
265 struct tc_action_ops
*a
, **ap
;
267 write_lock(&act_mod_lock
);
268 for (ap
= &act_base
; (a
= *ap
) != NULL
; ap
= &a
->next
) {
269 if (act
->type
== a
->type
|| (strcmp(act
->kind
, a
->kind
) == 0)) {
270 write_unlock(&act_mod_lock
);
276 write_unlock(&act_mod_lock
);
280 int tcf_unregister_action(struct tc_action_ops
*act
)
282 struct tc_action_ops
*a
, **ap
;
285 write_lock(&act_mod_lock
);
286 for (ap
= &act_base
; (a
= *ap
) != NULL
; ap
= &a
->next
)
294 write_unlock(&act_mod_lock
);
299 static struct tc_action_ops
*tc_lookup_action_n(char *kind
)
301 struct tc_action_ops
*a
= NULL
;
304 read_lock(&act_mod_lock
);
305 for (a
= act_base
; a
; a
= a
->next
) {
306 if (strcmp(kind
, a
->kind
) == 0) {
307 if (!try_module_get(a
->owner
)) {
308 read_unlock(&act_mod_lock
);
314 read_unlock(&act_mod_lock
);
319 /* lookup by rtattr */
320 static struct tc_action_ops
*tc_lookup_action(struct rtattr
*kind
)
322 struct tc_action_ops
*a
= NULL
;
325 read_lock(&act_mod_lock
);
326 for (a
= act_base
; a
; a
= a
->next
) {
327 if (rtattr_strcmp(kind
, a
->kind
) == 0) {
328 if (!try_module_get(a
->owner
)) {
329 read_unlock(&act_mod_lock
);
335 read_unlock(&act_mod_lock
);
342 static struct tc_action_ops
*tc_lookup_action_id(u32 type
)
344 struct tc_action_ops
*a
= NULL
;
347 read_lock(&act_mod_lock
);
348 for (a
= act_base
; a
; a
= a
->next
) {
349 if (a
->type
== type
) {
350 if (!try_module_get(a
->owner
)) {
351 read_unlock(&act_mod_lock
);
357 read_unlock(&act_mod_lock
);
363 int tcf_action_exec(struct sk_buff
*skb
, struct tc_action
*act
,
364 struct tcf_result
*res
)
369 if (skb
->tc_verd
& TC_NCLS
) {
370 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
374 while ((a
= act
) != NULL
) {
376 if (a
->ops
&& a
->ops
->act
) {
377 ret
= a
->ops
->act(skb
, a
, res
);
378 if (TC_MUNGED
& skb
->tc_verd
) {
379 /* copied already, allow trampling */
380 skb
->tc_verd
= SET_TC_OK2MUNGE(skb
->tc_verd
);
381 skb
->tc_verd
= CLR_TC_MUNGED(skb
->tc_verd
);
383 if (ret
== TC_ACT_REPEAT
)
384 goto repeat
; /* we need a ttl - JHS */
385 if (ret
!= TC_ACT_PIPE
)
394 void tcf_action_destroy(struct tc_action
*act
, int bind
)
398 for (a
= act
; a
; a
= act
) {
399 if (a
->ops
&& a
->ops
->cleanup
) {
400 if (a
->ops
->cleanup(a
, bind
) == ACT_P_DELETED
)
401 module_put(a
->ops
->owner
);
404 } else { /*FIXME: Remove later - catch insertion bugs*/
405 printk("tcf_action_destroy: BUG? destroying NULL ops\n");
413 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
417 if (a
->ops
== NULL
|| a
->ops
->dump
== NULL
)
419 return a
->ops
->dump(skb
, a
, bind
, ref
);
423 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
426 unsigned char *b
= skb
->tail
;
429 if (a
->ops
== NULL
|| a
->ops
->dump
== NULL
)
432 RTA_PUT(skb
, TCA_KIND
, IFNAMSIZ
, a
->ops
->kind
);
433 if (tcf_action_copy_stats(skb
, a
, 0))
435 r
= (struct rtattr
*) skb
->tail
;
436 RTA_PUT(skb
, TCA_OPTIONS
, 0, NULL
);
437 if ((err
= tcf_action_dump_old(skb
, a
, bind
, ref
)) > 0) {
438 r
->rta_len
= skb
->tail
- (u8
*)r
;
443 skb_trim(skb
, b
- skb
->data
);
448 tcf_action_dump(struct sk_buff
*skb
, struct tc_action
*act
, int bind
, int ref
)
452 unsigned char *b
= skb
->tail
;
455 while ((a
= act
) != NULL
) {
456 r
= (struct rtattr
*) skb
->tail
;
458 RTA_PUT(skb
, a
->order
, 0, NULL
);
459 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
462 r
->rta_len
= skb
->tail
- (u8
*)r
;
470 skb_trim(skb
, b
- skb
->data
);
474 struct tc_action
*tcf_action_init_1(struct rtattr
*rta
, struct rtattr
*est
,
475 char *name
, int ovr
, int bind
, int *err
)
478 struct tc_action_ops
*a_o
;
479 char act_name
[IFNAMSIZ
];
480 struct rtattr
*tb
[TCA_ACT_MAX
+1];
486 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
488 kind
= tb
[TCA_ACT_KIND
-1];
491 if (rtattr_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
494 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
498 a_o
= tc_lookup_action_n(act_name
);
502 request_module("act_%s", act_name
);
505 a_o
= tc_lookup_action_n(act_name
);
507 /* We dropped the RTNL semaphore in order to
508 * perform the module load. So, even if we
509 * succeeded in loading the module we have to
510 * tell the caller to replay the request. We
511 * indicate this using -EAGAIN.
523 a
= kzalloc(sizeof(*a
), GFP_KERNEL
);
527 /* backward compatibility for policer */
529 *err
= a_o
->init(tb
[TCA_ACT_OPTIONS
-1], est
, a
, ovr
, bind
);
531 *err
= a_o
->init(rta
, est
, a
, ovr
, bind
);
535 /* module count goes up only when brand new policy is created
536 if it exists and is only bound to in a_o->init() then
537 ACT_P_CREATED is not returned (a zero is).
539 if (*err
!= ACT_P_CREATED
)
540 module_put(a_o
->owner
);
549 module_put(a_o
->owner
);
554 struct tc_action
*tcf_action_init(struct rtattr
*rta
, struct rtattr
*est
,
555 char *name
, int ovr
, int bind
, int *err
)
557 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+1];
558 struct tc_action
*head
= NULL
, *act
, *act_prev
= NULL
;
561 if (rtattr_parse_nested(tb
, TCA_ACT_MAX_PRIO
, rta
) < 0) {
566 for (i
=0; i
< TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
567 act
= tcf_action_init_1(tb
[i
], est
, name
, ovr
, bind
, err
);
575 act_prev
->next
= act
;
582 tcf_action_destroy(head
, bind
);
586 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*a
,
591 struct tcf_act_hdr
*h
= a
->priv
;
596 /* compat_mode being true specifies a call that is supposed
597 * to add additional backward compatiblity statistic TLVs.
600 if (a
->type
== TCA_OLD_COMPAT
)
601 err
= gnet_stats_start_copy_compat(skb
, 0,
602 TCA_STATS
, TCA_XSTATS
, h
->tcf_stats_lock
, &d
);
606 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
607 h
->tcf_stats_lock
, &d
);
612 if (a
->ops
!= NULL
&& a
->ops
->get_stats
!= NULL
)
613 if (a
->ops
->get_stats(skb
, a
) < 0)
616 if (gnet_stats_copy_basic(&d
, &h
->tcf_bstats
) < 0 ||
617 #ifdef CONFIG_NET_ESTIMATOR
618 gnet_stats_copy_rate_est(&d
, &h
->tcf_rate_est
) < 0 ||
620 gnet_stats_copy_queue(&d
, &h
->tcf_qstats
) < 0)
623 if (gnet_stats_finish_copy(&d
) < 0)
633 tca_get_fill(struct sk_buff
*skb
, struct tc_action
*a
, u32 pid
, u32 seq
,
634 u16 flags
, int event
, int bind
, int ref
)
637 struct nlmsghdr
*nlh
;
638 unsigned char *b
= skb
->tail
;
641 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*t
), flags
);
644 t
->tca_family
= AF_UNSPEC
;
648 x
= (struct rtattr
*) skb
->tail
;
649 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
651 if (tcf_action_dump(skb
, a
, bind
, ref
) < 0)
654 x
->rta_len
= skb
->tail
- (u8
*)x
;
656 nlh
->nlmsg_len
= skb
->tail
- b
;
661 skb_trim(skb
, b
- skb
->data
);
666 act_get_notify(u32 pid
, struct nlmsghdr
*n
, struct tc_action
*a
, int event
)
670 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
673 if (tca_get_fill(skb
, a
, pid
, n
->nlmsg_seq
, 0, event
, 0, 0) <= 0) {
678 return rtnl_unicast(skb
, pid
);
681 static struct tc_action
*
682 tcf_action_get_1(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int *err
)
684 struct rtattr
*tb
[TCA_ACT_MAX
+1];
689 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
692 if (tb
[TCA_ACT_INDEX
- 1] == NULL
||
693 RTA_PAYLOAD(tb
[TCA_ACT_INDEX
- 1]) < sizeof(index
))
695 index
= *(int *)RTA_DATA(tb
[TCA_ACT_INDEX
- 1]);
698 a
= kzalloc(sizeof(struct tc_action
), GFP_KERNEL
);
703 a
->ops
= tc_lookup_action(tb
[TCA_ACT_KIND
- 1]);
706 if (a
->ops
->lookup
== NULL
)
709 if (a
->ops
->lookup(a
, index
) == 0)
712 module_put(a
->ops
->owner
);
716 module_put(a
->ops
->owner
);
722 static void cleanup_a(struct tc_action
*act
)
726 for (a
= act
; a
; a
= act
) {
732 static struct tc_action
*create_a(int i
)
734 struct tc_action
*act
;
736 act
= kzalloc(sizeof(*act
), GFP_KERNEL
);
738 printk("create_a: failed to alloc!\n");
745 static int tca_action_flush(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
)
749 struct nlmsghdr
*nlh
;
751 struct netlink_callback dcb
;
753 struct rtattr
*tb
[TCA_ACT_MAX
+1];
755 struct tc_action
*a
= create_a(0);
759 printk("tca_action_flush: couldnt create tc_action\n");
763 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
765 printk("tca_action_flush: failed skb alloc\n");
770 b
= (unsigned char *)skb
->tail
;
772 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
775 kind
= tb
[TCA_ACT_KIND
-1];
776 a
->ops
= tc_lookup_action(kind
);
780 nlh
= NLMSG_PUT(skb
, pid
, n
->nlmsg_seq
, RTM_DELACTION
, sizeof(*t
));
782 t
->tca_family
= AF_UNSPEC
;
786 x
= (struct rtattr
*) skb
->tail
;
787 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
789 err
= a
->ops
->walk(skb
, &dcb
, RTM_DELACTION
, a
);
793 x
->rta_len
= skb
->tail
- (u8
*) x
;
795 nlh
->nlmsg_len
= skb
->tail
- b
;
796 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
797 module_put(a
->ops
->owner
);
799 err
= rtnetlink_send(skb
, pid
, RTNLGRP_TC
, n
->nlmsg_flags
&NLM_F_ECHO
);
807 module_put(a
->ops
->owner
);
815 tca_action_gd(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int event
)
818 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+1];
819 struct tc_action
*head
= NULL
, *act
, *act_prev
= NULL
;
821 if (rtattr_parse_nested(tb
, TCA_ACT_MAX_PRIO
, rta
) < 0)
824 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
&NLM_F_ROOT
) {
825 if (tb
[0] != NULL
&& tb
[1] == NULL
)
826 return tca_action_flush(tb
[0], n
, pid
);
829 for (i
=0; i
< TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
830 act
= tcf_action_get_1(tb
[i
], n
, pid
, &ret
);
838 act_prev
->next
= act
;
842 if (event
== RTM_GETACTION
)
843 ret
= act_get_notify(pid
, n
, head
, event
);
847 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
853 if (tca_get_fill(skb
, head
, pid
, n
->nlmsg_seq
, 0, event
,
860 /* now do the delete */
861 tcf_action_destroy(head
, 0);
862 ret
= rtnetlink_send(skb
, pid
, RTNLGRP_TC
,
863 n
->nlmsg_flags
&NLM_F_ECHO
);
873 static int tcf_add_notify(struct tc_action
*a
, u32 pid
, u32 seq
, int event
,
877 struct nlmsghdr
*nlh
;
883 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
887 b
= (unsigned char *)skb
->tail
;
889 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*t
), flags
);
891 t
->tca_family
= AF_UNSPEC
;
895 x
= (struct rtattr
*) skb
->tail
;
896 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
898 if (tcf_action_dump(skb
, a
, 0, 0) < 0)
901 x
->rta_len
= skb
->tail
- (u8
*)x
;
903 nlh
->nlmsg_len
= skb
->tail
- b
;
904 NETLINK_CB(skb
).dst_group
= RTNLGRP_TC
;
906 err
= rtnetlink_send(skb
, pid
, RTNLGRP_TC
, flags
&NLM_F_ECHO
);
919 tcf_action_add(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int ovr
)
922 struct tc_action
*act
;
924 u32 seq
= n
->nlmsg_seq
;
926 act
= tcf_action_init(rta
, NULL
, NULL
, ovr
, 0, &ret
);
930 /* dump then free all the actions after update; inserted policy
933 ret
= tcf_add_notify(act
, pid
, seq
, RTM_NEWACTION
, n
->nlmsg_flags
);
934 for (a
= act
; a
; a
= act
) {
942 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
, void *arg
)
944 struct rtattr
**tca
= arg
;
945 u32 pid
= skb
? NETLINK_CB(skb
).pid
: 0;
946 int ret
= 0, ovr
= 0;
948 if (tca
[TCA_ACT_TAB
-1] == NULL
) {
949 printk("tc_ctl_action: received NO action attribs\n");
953 /* n->nlmsg_flags&NLM_F_CREATE
955 switch (n
->nlmsg_type
) {
957 /* we are going to assume all other flags
958 * imply create only if it doesnt exist
959 * Note that CREATE | EXCL implies that
960 * but since we want avoid ambiguity (eg when flags
961 * is zero) then just set this
963 if (n
->nlmsg_flags
&NLM_F_REPLACE
)
966 ret
= tcf_action_add(tca
[TCA_ACT_TAB
-1], n
, pid
, ovr
);
971 ret
= tca_action_gd(tca
[TCA_ACT_TAB
-1], n
, pid
, RTM_DELACTION
);
974 ret
= tca_action_gd(tca
[TCA_ACT_TAB
-1], n
, pid
, RTM_GETACTION
);
983 static struct rtattr
*
984 find_dump_kind(struct nlmsghdr
*n
)
986 struct rtattr
*tb1
, *tb2
[TCA_ACT_MAX
+1];
987 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
988 struct rtattr
*rta
[TCAA_MAX
+ 1];
990 int min_len
= NLMSG_LENGTH(sizeof(struct tcamsg
));
991 int attrlen
= n
->nlmsg_len
- NLMSG_ALIGN(min_len
);
992 struct rtattr
*attr
= (void *) n
+ NLMSG_ALIGN(min_len
);
994 if (rtattr_parse(rta
, TCAA_MAX
, attr
, attrlen
) < 0)
996 tb1
= rta
[TCA_ACT_TAB
- 1];
1000 if (rtattr_parse(tb
, TCA_ACT_MAX_PRIO
, RTA_DATA(tb1
),
1001 NLMSG_ALIGN(RTA_PAYLOAD(tb1
))) < 0)
1006 if (rtattr_parse(tb2
, TCA_ACT_MAX
, RTA_DATA(tb
[0]),
1007 RTA_PAYLOAD(tb
[0])) < 0)
1009 kind
= tb2
[TCA_ACT_KIND
-1];
1015 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1017 struct nlmsghdr
*nlh
;
1018 unsigned char *b
= skb
->tail
;
1020 struct tc_action_ops
*a_o
;
1023 struct tcamsg
*t
= (struct tcamsg
*) NLMSG_DATA(cb
->nlh
);
1024 struct rtattr
*kind
= find_dump_kind(cb
->nlh
);
1027 printk("tc_dump_action: action bad kind\n");
1031 a_o
= tc_lookup_action(kind
);
1036 memset(&a
, 0, sizeof(struct tc_action
));
1039 if (a_o
->walk
== NULL
) {
1040 printk("tc_dump_action: %s !capable of dumping table\n", a_o
->kind
);
1041 goto rtattr_failure
;
1044 nlh
= NLMSG_PUT(skb
, NETLINK_CB(cb
->skb
).pid
, cb
->nlh
->nlmsg_seq
,
1045 cb
->nlh
->nlmsg_type
, sizeof(*t
));
1046 t
= NLMSG_DATA(nlh
);
1047 t
->tca_family
= AF_UNSPEC
;
1051 x
= (struct rtattr
*) skb
->tail
;
1052 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
1054 ret
= a_o
->walk(skb
, cb
, RTM_GETACTION
, &a
);
1056 goto rtattr_failure
;
1059 x
->rta_len
= skb
->tail
- (u8
*) x
;
1062 skb_trim(skb
, (u8
*)x
- skb
->data
);
1064 nlh
->nlmsg_len
= skb
->tail
- b
;
1065 if (NETLINK_CB(cb
->skb
).pid
&& ret
)
1066 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1067 module_put(a_o
->owner
);
1072 module_put(a_o
->owner
);
1073 skb_trim(skb
, b
- skb
->data
);
1077 static int __init
tc_action_init(void)
1079 struct rtnetlink_link
*link_p
= rtnetlink_links
[PF_UNSPEC
];
1082 link_p
[RTM_NEWACTION
-RTM_BASE
].doit
= tc_ctl_action
;
1083 link_p
[RTM_DELACTION
-RTM_BASE
].doit
= tc_ctl_action
;
1084 link_p
[RTM_GETACTION
-RTM_BASE
].doit
= tc_ctl_action
;
1085 link_p
[RTM_GETACTION
-RTM_BASE
].dumpit
= tc_dump_action
;
1091 subsys_initcall(tc_action_init
);
1093 EXPORT_SYMBOL(tcf_register_action
);
1094 EXPORT_SYMBOL(tcf_unregister_action
);
1095 EXPORT_SYMBOL(tcf_action_exec
);
1096 EXPORT_SYMBOL(tcf_action_dump_1
);