]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - net/sched/act_api.c
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 <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/skbuff.h>
19 #include <linux/init.h>
20 #include <linux/kmod.h>
21 #include <net/net_namespace.h>
23 #include <net/sch_generic.h>
24 #include <net/act_api.h>
25 #include <net/netlink.h>
27 void tcf_hash_destroy(struct tcf_common
*p
, struct tcf_hashinfo
*hinfo
)
29 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
30 struct tcf_common
**p1p
;
32 for (p1p
= &hinfo
->htab
[h
]; *p1p
; p1p
= &(*p1p
)->tcfc_next
) {
34 write_lock_bh(hinfo
->lock
);
36 write_unlock_bh(hinfo
->lock
);
37 gen_kill_estimator(&p
->tcfc_bstats
,
45 EXPORT_SYMBOL(tcf_hash_destroy
);
47 int tcf_hash_release(struct tcf_common
*p
, int bind
,
48 struct tcf_hashinfo
*hinfo
)
57 if (p
->tcfc_bindcnt
<= 0 && p
->tcfc_refcnt
<= 0) {
58 tcf_hash_destroy(p
, hinfo
);
64 EXPORT_SYMBOL(tcf_hash_release
);
66 static int tcf_dump_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
67 struct tc_action
*a
, struct tcf_hashinfo
*hinfo
)
70 int err
= 0, index
= -1,i
= 0, s_i
= 0, n_i
= 0;
73 read_lock_bh(hinfo
->lock
);
77 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
78 p
= hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
80 for (; p
; p
= p
->tcfc_next
) {
86 r
= (struct rtattr
*)skb_tail_pointer(skb
);
87 RTA_PUT(skb
, a
->order
, 0, NULL
);
88 err
= tcf_action_dump_1(skb
, a
, 0, 0);
94 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
96 if (n_i
>= TCA_ACT_MAX_PRIO
)
101 read_unlock_bh(hinfo
->lock
);
111 static int tcf_del_walker(struct sk_buff
*skb
, struct tc_action
*a
,
112 struct tcf_hashinfo
*hinfo
)
114 struct tcf_common
*p
, *s_p
;
118 r
= (struct rtattr
*)skb_tail_pointer(skb
);
119 RTA_PUT(skb
, a
->order
, 0, NULL
);
120 RTA_PUT(skb
, TCA_KIND
, IFNAMSIZ
, a
->ops
->kind
);
121 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
122 p
= hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
126 if (ACT_P_DELETED
== tcf_hash_release(p
, 0, hinfo
))
127 module_put(a
->ops
->owner
);
132 RTA_PUT(skb
, TCA_FCNT
, 4, &n_i
);
133 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
141 int tcf_generic_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
142 int type
, struct tc_action
*a
)
144 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
146 if (type
== RTM_DELACTION
) {
147 return tcf_del_walker(skb
, a
, hinfo
);
148 } else if (type
== RTM_GETACTION
) {
149 return tcf_dump_walker(skb
, cb
, a
, hinfo
);
151 printk("tcf_generic_walker: unknown action %d\n", type
);
155 EXPORT_SYMBOL(tcf_generic_walker
);
157 struct tcf_common
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
159 struct tcf_common
*p
;
161 read_lock_bh(hinfo
->lock
);
162 for (p
= hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)]; p
;
164 if (p
->tcfc_index
== index
)
167 read_unlock_bh(hinfo
->lock
);
171 EXPORT_SYMBOL(tcf_hash_lookup
);
173 u32
tcf_hash_new_index(u32
*idx_gen
, struct tcf_hashinfo
*hinfo
)
180 } while (tcf_hash_lookup(val
, hinfo
));
182 return (*idx_gen
= val
);
184 EXPORT_SYMBOL(tcf_hash_new_index
);
186 int tcf_hash_search(struct tc_action
*a
, u32 index
)
188 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
189 struct tcf_common
*p
= tcf_hash_lookup(index
, hinfo
);
197 EXPORT_SYMBOL(tcf_hash_search
);
199 struct tcf_common
*tcf_hash_check(u32 index
, struct tc_action
*a
, int bind
,
200 struct tcf_hashinfo
*hinfo
)
202 struct tcf_common
*p
= NULL
;
203 if (index
&& (p
= tcf_hash_lookup(index
, hinfo
)) != NULL
) {
212 EXPORT_SYMBOL(tcf_hash_check
);
214 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
)
216 struct tcf_common
*p
= kzalloc(size
, GFP_KERNEL
);
224 spin_lock_init(&p
->tcfc_lock
);
225 p
->tcfc_index
= index
? index
: tcf_hash_new_index(idx_gen
, hinfo
);
226 p
->tcfc_tm
.install
= jiffies
;
227 p
->tcfc_tm
.lastuse
= jiffies
;
229 gen_new_estimator(&p
->tcfc_bstats
, &p
->tcfc_rate_est
,
231 a
->priv
= (void *) p
;
234 EXPORT_SYMBOL(tcf_hash_create
);
236 void tcf_hash_insert(struct tcf_common
*p
, struct tcf_hashinfo
*hinfo
)
238 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
240 write_lock_bh(hinfo
->lock
);
241 p
->tcfc_next
= hinfo
->htab
[h
];
243 write_unlock_bh(hinfo
->lock
);
245 EXPORT_SYMBOL(tcf_hash_insert
);
247 static struct tc_action_ops
*act_base
= NULL
;
248 static DEFINE_RWLOCK(act_mod_lock
);
250 int tcf_register_action(struct tc_action_ops
*act
)
252 struct tc_action_ops
*a
, **ap
;
254 write_lock(&act_mod_lock
);
255 for (ap
= &act_base
; (a
= *ap
) != NULL
; ap
= &a
->next
) {
256 if (act
->type
== a
->type
|| (strcmp(act
->kind
, a
->kind
) == 0)) {
257 write_unlock(&act_mod_lock
);
263 write_unlock(&act_mod_lock
);
266 EXPORT_SYMBOL(tcf_register_action
);
268 int tcf_unregister_action(struct tc_action_ops
*act
)
270 struct tc_action_ops
*a
, **ap
;
273 write_lock(&act_mod_lock
);
274 for (ap
= &act_base
; (a
= *ap
) != NULL
; ap
= &a
->next
)
282 write_unlock(&act_mod_lock
);
285 EXPORT_SYMBOL(tcf_unregister_action
);
288 static struct tc_action_ops
*tc_lookup_action_n(char *kind
)
290 struct tc_action_ops
*a
= NULL
;
293 read_lock(&act_mod_lock
);
294 for (a
= act_base
; a
; a
= a
->next
) {
295 if (strcmp(kind
, a
->kind
) == 0) {
296 if (!try_module_get(a
->owner
)) {
297 read_unlock(&act_mod_lock
);
303 read_unlock(&act_mod_lock
);
308 /* lookup by rtattr */
309 static struct tc_action_ops
*tc_lookup_action(struct rtattr
*kind
)
311 struct tc_action_ops
*a
= NULL
;
314 read_lock(&act_mod_lock
);
315 for (a
= act_base
; a
; a
= a
->next
) {
316 if (rtattr_strcmp(kind
, a
->kind
) == 0) {
317 if (!try_module_get(a
->owner
)) {
318 read_unlock(&act_mod_lock
);
324 read_unlock(&act_mod_lock
);
331 static struct tc_action_ops
*tc_lookup_action_id(u32 type
)
333 struct tc_action_ops
*a
= NULL
;
336 read_lock(&act_mod_lock
);
337 for (a
= act_base
; a
; a
= a
->next
) {
338 if (a
->type
== type
) {
339 if (!try_module_get(a
->owner
)) {
340 read_unlock(&act_mod_lock
);
346 read_unlock(&act_mod_lock
);
352 int tcf_action_exec(struct sk_buff
*skb
, struct tc_action
*act
,
353 struct tcf_result
*res
)
358 if (skb
->tc_verd
& TC_NCLS
) {
359 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
363 while ((a
= act
) != NULL
) {
365 if (a
->ops
&& a
->ops
->act
) {
366 ret
= a
->ops
->act(skb
, a
, res
);
367 if (TC_MUNGED
& skb
->tc_verd
) {
368 /* copied already, allow trampling */
369 skb
->tc_verd
= SET_TC_OK2MUNGE(skb
->tc_verd
);
370 skb
->tc_verd
= CLR_TC_MUNGED(skb
->tc_verd
);
372 if (ret
== TC_ACT_REPEAT
)
373 goto repeat
; /* we need a ttl - JHS */
374 if (ret
!= TC_ACT_PIPE
)
382 EXPORT_SYMBOL(tcf_action_exec
);
384 void tcf_action_destroy(struct tc_action
*act
, int bind
)
388 for (a
= act
; a
; a
= act
) {
389 if (a
->ops
&& a
->ops
->cleanup
) {
390 if (a
->ops
->cleanup(a
, bind
) == ACT_P_DELETED
)
391 module_put(a
->ops
->owner
);
394 } else { /*FIXME: Remove later - catch insertion bugs*/
395 printk("tcf_action_destroy: BUG? destroying NULL ops\n");
403 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
407 if (a
->ops
== NULL
|| a
->ops
->dump
== NULL
)
409 return a
->ops
->dump(skb
, a
, bind
, ref
);
413 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
416 unsigned char *b
= skb_tail_pointer(skb
);
419 if (a
->ops
== NULL
|| a
->ops
->dump
== NULL
)
422 RTA_PUT(skb
, TCA_KIND
, IFNAMSIZ
, a
->ops
->kind
);
423 if (tcf_action_copy_stats(skb
, a
, 0))
425 r
= (struct rtattr
*)skb_tail_pointer(skb
);
426 RTA_PUT(skb
, TCA_OPTIONS
, 0, NULL
);
427 if ((err
= tcf_action_dump_old(skb
, a
, bind
, ref
)) > 0) {
428 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
436 EXPORT_SYMBOL(tcf_action_dump_1
);
439 tcf_action_dump(struct sk_buff
*skb
, struct tc_action
*act
, int bind
, int ref
)
443 unsigned char *b
= skb_tail_pointer(skb
);
446 while ((a
= act
) != NULL
) {
447 r
= (struct rtattr
*)skb_tail_pointer(skb
);
449 RTA_PUT(skb
, a
->order
, 0, NULL
);
450 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
453 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
465 struct tc_action
*tcf_action_init_1(struct rtattr
*rta
, struct rtattr
*est
,
466 char *name
, int ovr
, int bind
, int *err
)
469 struct tc_action_ops
*a_o
;
470 char act_name
[IFNAMSIZ
];
471 struct rtattr
*tb
[TCA_ACT_MAX
+1];
477 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
479 kind
= tb
[TCA_ACT_KIND
-1];
482 if (rtattr_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
485 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
489 a_o
= tc_lookup_action_n(act_name
);
493 request_module("act_%s", act_name
);
496 a_o
= tc_lookup_action_n(act_name
);
498 /* We dropped the RTNL semaphore in order to
499 * perform the module load. So, even if we
500 * succeeded in loading the module we have to
501 * tell the caller to replay the request. We
502 * indicate this using -EAGAIN.
514 a
= kzalloc(sizeof(*a
), GFP_KERNEL
);
518 /* backward compatibility for policer */
520 *err
= a_o
->init(tb
[TCA_ACT_OPTIONS
-1], est
, a
, ovr
, bind
);
522 *err
= a_o
->init(rta
, est
, a
, ovr
, bind
);
526 /* module count goes up only when brand new policy is created
527 if it exists and is only bound to in a_o->init() then
528 ACT_P_CREATED is not returned (a zero is).
530 if (*err
!= ACT_P_CREATED
)
531 module_put(a_o
->owner
);
540 module_put(a_o
->owner
);
545 struct tc_action
*tcf_action_init(struct rtattr
*rta
, struct rtattr
*est
,
546 char *name
, int ovr
, int bind
, int *err
)
548 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+1];
549 struct tc_action
*head
= NULL
, *act
, *act_prev
= NULL
;
552 if (rtattr_parse_nested(tb
, TCA_ACT_MAX_PRIO
, rta
) < 0) {
557 for (i
=0; i
< TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
558 act
= tcf_action_init_1(tb
[i
], est
, name
, ovr
, bind
, err
);
566 act_prev
->next
= act
;
573 tcf_action_destroy(head
, bind
);
577 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*a
,
582 struct tcf_act_hdr
*h
= a
->priv
;
587 /* compat_mode being true specifies a call that is supposed
588 * to add additional backward compatiblity statistic TLVs.
591 if (a
->type
== TCA_OLD_COMPAT
)
592 err
= gnet_stats_start_copy_compat(skb
, 0,
593 TCA_STATS
, TCA_XSTATS
, &h
->tcf_lock
, &d
);
597 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
603 if (a
->ops
!= NULL
&& a
->ops
->get_stats
!= NULL
)
604 if (a
->ops
->get_stats(skb
, a
) < 0)
607 if (gnet_stats_copy_basic(&d
, &h
->tcf_bstats
) < 0 ||
608 gnet_stats_copy_rate_est(&d
, &h
->tcf_rate_est
) < 0 ||
609 gnet_stats_copy_queue(&d
, &h
->tcf_qstats
) < 0)
612 if (gnet_stats_finish_copy(&d
) < 0)
622 tca_get_fill(struct sk_buff
*skb
, struct tc_action
*a
, u32 pid
, u32 seq
,
623 u16 flags
, int event
, int bind
, int ref
)
626 struct nlmsghdr
*nlh
;
627 unsigned char *b
= skb_tail_pointer(skb
);
630 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*t
), flags
);
633 t
->tca_family
= AF_UNSPEC
;
637 x
= (struct rtattr
*)skb_tail_pointer(skb
);
638 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
640 if (tcf_action_dump(skb
, a
, bind
, ref
) < 0)
643 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
645 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
655 act_get_notify(u32 pid
, struct nlmsghdr
*n
, struct tc_action
*a
, int event
)
659 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
662 if (tca_get_fill(skb
, a
, pid
, n
->nlmsg_seq
, 0, event
, 0, 0) <= 0) {
667 return rtnl_unicast(skb
, &init_net
, pid
);
670 static struct tc_action
*
671 tcf_action_get_1(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int *err
)
673 struct rtattr
*tb
[TCA_ACT_MAX
+1];
678 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
681 if (tb
[TCA_ACT_INDEX
- 1] == NULL
||
682 RTA_PAYLOAD(tb
[TCA_ACT_INDEX
- 1]) < sizeof(index
))
684 index
= *(int *)RTA_DATA(tb
[TCA_ACT_INDEX
- 1]);
687 a
= kzalloc(sizeof(struct tc_action
), GFP_KERNEL
);
692 a
->ops
= tc_lookup_action(tb
[TCA_ACT_KIND
- 1]);
695 if (a
->ops
->lookup
== NULL
)
698 if (a
->ops
->lookup(a
, index
) == 0)
701 module_put(a
->ops
->owner
);
705 module_put(a
->ops
->owner
);
711 static void cleanup_a(struct tc_action
*act
)
715 for (a
= act
; a
; a
= act
) {
721 static struct tc_action
*create_a(int i
)
723 struct tc_action
*act
;
725 act
= kzalloc(sizeof(*act
), GFP_KERNEL
);
727 printk("create_a: failed to alloc!\n");
734 static int tca_action_flush(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
)
738 struct nlmsghdr
*nlh
;
740 struct netlink_callback dcb
;
742 struct rtattr
*tb
[TCA_ACT_MAX
+1];
744 struct tc_action
*a
= create_a(0);
748 printk("tca_action_flush: couldnt create tc_action\n");
752 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
754 printk("tca_action_flush: failed skb alloc\n");
759 b
= skb_tail_pointer(skb
);
761 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
764 kind
= tb
[TCA_ACT_KIND
-1];
765 a
->ops
= tc_lookup_action(kind
);
769 nlh
= NLMSG_PUT(skb
, pid
, n
->nlmsg_seq
, RTM_DELACTION
, sizeof(*t
));
771 t
->tca_family
= AF_UNSPEC
;
775 x
= (struct rtattr
*)skb_tail_pointer(skb
);
776 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
778 err
= a
->ops
->walk(skb
, &dcb
, RTM_DELACTION
, a
);
782 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
784 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
785 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
786 module_put(a
->ops
->owner
);
788 err
= rtnetlink_send(skb
, &init_net
, pid
, RTNLGRP_TC
, n
->nlmsg_flags
&NLM_F_ECHO
);
796 module_put(a
->ops
->owner
);
804 tca_action_gd(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int event
)
807 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+1];
808 struct tc_action
*head
= NULL
, *act
, *act_prev
= NULL
;
810 if (rtattr_parse_nested(tb
, TCA_ACT_MAX_PRIO
, rta
) < 0)
813 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
&NLM_F_ROOT
) {
814 if (tb
[0] != NULL
&& tb
[1] == NULL
)
815 return tca_action_flush(tb
[0], n
, pid
);
818 for (i
=0; i
< TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
819 act
= tcf_action_get_1(tb
[i
], n
, pid
, &ret
);
827 act_prev
->next
= act
;
831 if (event
== RTM_GETACTION
)
832 ret
= act_get_notify(pid
, n
, head
, event
);
836 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
842 if (tca_get_fill(skb
, head
, pid
, n
->nlmsg_seq
, 0, event
,
849 /* now do the delete */
850 tcf_action_destroy(head
, 0);
851 ret
= rtnetlink_send(skb
, &init_net
, pid
, RTNLGRP_TC
,
852 n
->nlmsg_flags
&NLM_F_ECHO
);
862 static int tcf_add_notify(struct tc_action
*a
, u32 pid
, u32 seq
, int event
,
866 struct nlmsghdr
*nlh
;
872 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
876 b
= skb_tail_pointer(skb
);
878 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*t
), flags
);
880 t
->tca_family
= AF_UNSPEC
;
884 x
= (struct rtattr
*)skb_tail_pointer(skb
);
885 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
887 if (tcf_action_dump(skb
, a
, 0, 0) < 0)
890 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
892 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
893 NETLINK_CB(skb
).dst_group
= RTNLGRP_TC
;
895 err
= rtnetlink_send(skb
, &init_net
, pid
, RTNLGRP_TC
, flags
&NLM_F_ECHO
);
908 tcf_action_add(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int ovr
)
911 struct tc_action
*act
;
913 u32 seq
= n
->nlmsg_seq
;
915 act
= tcf_action_init(rta
, NULL
, NULL
, ovr
, 0, &ret
);
919 /* dump then free all the actions after update; inserted policy
922 ret
= tcf_add_notify(act
, pid
, seq
, RTM_NEWACTION
, n
->nlmsg_flags
);
923 for (a
= act
; a
; a
= act
) {
931 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
, void *arg
)
933 struct net
*net
= skb
->sk
->sk_net
;
934 struct rtattr
**tca
= arg
;
935 u32 pid
= skb
? NETLINK_CB(skb
).pid
: 0;
936 int ret
= 0, ovr
= 0;
938 if (net
!= &init_net
)
941 if (tca
[TCA_ACT_TAB
-1] == NULL
) {
942 printk("tc_ctl_action: received NO action attribs\n");
946 /* n->nlmsg_flags&NLM_F_CREATE
948 switch (n
->nlmsg_type
) {
950 /* we are going to assume all other flags
951 * imply create only if it doesnt exist
952 * Note that CREATE | EXCL implies that
953 * but since we want avoid ambiguity (eg when flags
954 * is zero) then just set this
956 if (n
->nlmsg_flags
&NLM_F_REPLACE
)
959 ret
= tcf_action_add(tca
[TCA_ACT_TAB
-1], n
, pid
, ovr
);
964 ret
= tca_action_gd(tca
[TCA_ACT_TAB
-1], n
, pid
, RTM_DELACTION
);
967 ret
= tca_action_gd(tca
[TCA_ACT_TAB
-1], n
, pid
, RTM_GETACTION
);
976 static struct rtattr
*
977 find_dump_kind(struct nlmsghdr
*n
)
979 struct rtattr
*tb1
, *tb2
[TCA_ACT_MAX
+1];
980 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
981 struct rtattr
*rta
[TCAA_MAX
+ 1];
983 int min_len
= NLMSG_LENGTH(sizeof(struct tcamsg
));
984 int attrlen
= n
->nlmsg_len
- NLMSG_ALIGN(min_len
);
985 struct rtattr
*attr
= (void *) n
+ NLMSG_ALIGN(min_len
);
987 if (rtattr_parse(rta
, TCAA_MAX
, attr
, attrlen
) < 0)
989 tb1
= rta
[TCA_ACT_TAB
- 1];
993 if (rtattr_parse(tb
, TCA_ACT_MAX_PRIO
, RTA_DATA(tb1
),
994 NLMSG_ALIGN(RTA_PAYLOAD(tb1
))) < 0)
999 if (rtattr_parse(tb2
, TCA_ACT_MAX
, RTA_DATA(tb
[0]),
1000 RTA_PAYLOAD(tb
[0])) < 0)
1002 kind
= tb2
[TCA_ACT_KIND
-1];
1008 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1010 struct net
*net
= skb
->sk
->sk_net
;
1011 struct nlmsghdr
*nlh
;
1012 unsigned char *b
= skb_tail_pointer(skb
);
1014 struct tc_action_ops
*a_o
;
1017 struct tcamsg
*t
= (struct tcamsg
*) NLMSG_DATA(cb
->nlh
);
1018 struct rtattr
*kind
= find_dump_kind(cb
->nlh
);
1020 if (net
!= &init_net
)
1024 printk("tc_dump_action: action bad kind\n");
1028 a_o
= tc_lookup_action(kind
);
1033 memset(&a
, 0, sizeof(struct tc_action
));
1036 if (a_o
->walk
== NULL
) {
1037 printk("tc_dump_action: %s !capable of dumping table\n", a_o
->kind
);
1038 goto rtattr_failure
;
1041 nlh
= NLMSG_PUT(skb
, NETLINK_CB(cb
->skb
).pid
, cb
->nlh
->nlmsg_seq
,
1042 cb
->nlh
->nlmsg_type
, sizeof(*t
));
1043 t
= NLMSG_DATA(nlh
);
1044 t
->tca_family
= AF_UNSPEC
;
1048 x
= (struct rtattr
*)skb_tail_pointer(skb
);
1049 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
1051 ret
= a_o
->walk(skb
, cb
, RTM_GETACTION
, &a
);
1053 goto rtattr_failure
;
1056 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
1061 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1062 if (NETLINK_CB(cb
->skb
).pid
&& ret
)
1063 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1064 module_put(a_o
->owner
);
1069 module_put(a_o
->owner
);
1074 static int __init
tc_action_init(void)
1076 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
);
1077 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
);
1078 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
);
1083 subsys_initcall(tc_action_init
);