]>
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 <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/init.h>
29 #include <linux/kmod.h>
31 #include <net/sch_generic.h>
32 #include <net/act_api.h>
33 #include <net/netlink.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 gen_kill_estimator(&p
->tcfc_bstats
,
53 EXPORT_SYMBOL(tcf_hash_destroy
);
55 int tcf_hash_release(struct tcf_common
*p
, int bind
,
56 struct tcf_hashinfo
*hinfo
)
65 if (p
->tcfc_bindcnt
<= 0 && p
->tcfc_refcnt
<= 0) {
66 tcf_hash_destroy(p
, hinfo
);
72 EXPORT_SYMBOL(tcf_hash_release
);
74 static int tcf_dump_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
75 struct tc_action
*a
, struct tcf_hashinfo
*hinfo
)
78 int err
= 0, index
= -1,i
= 0, s_i
= 0, n_i
= 0;
81 read_lock(hinfo
->lock
);
85 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
86 p
= hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
88 for (; p
; p
= p
->tcfc_next
) {
94 r
= (struct rtattr
*)skb_tail_pointer(skb
);
95 RTA_PUT(skb
, a
->order
, 0, NULL
);
96 err
= tcf_action_dump_1(skb
, a
, 0, 0);
102 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
104 if (n_i
>= TCA_ACT_MAX_PRIO
)
109 read_unlock(hinfo
->lock
);
119 static int tcf_del_walker(struct sk_buff
*skb
, struct tc_action
*a
,
120 struct tcf_hashinfo
*hinfo
)
122 struct tcf_common
*p
, *s_p
;
126 r
= (struct rtattr
*)skb_tail_pointer(skb
);
127 RTA_PUT(skb
, a
->order
, 0, NULL
);
128 RTA_PUT(skb
, TCA_KIND
, IFNAMSIZ
, a
->ops
->kind
);
129 for (i
= 0; i
< (hinfo
->hmask
+ 1); i
++) {
130 p
= hinfo
->htab
[tcf_hash(i
, hinfo
->hmask
)];
134 if (ACT_P_DELETED
== tcf_hash_release(p
, 0, hinfo
))
135 module_put(a
->ops
->owner
);
140 RTA_PUT(skb
, TCA_FCNT
, 4, &n_i
);
141 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
149 int tcf_generic_walker(struct sk_buff
*skb
, struct netlink_callback
*cb
,
150 int type
, struct tc_action
*a
)
152 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
154 if (type
== RTM_DELACTION
) {
155 return tcf_del_walker(skb
, a
, hinfo
);
156 } else if (type
== RTM_GETACTION
) {
157 return tcf_dump_walker(skb
, cb
, a
, hinfo
);
159 printk("tcf_generic_walker: unknown action %d\n", type
);
163 EXPORT_SYMBOL(tcf_generic_walker
);
165 struct tcf_common
*tcf_hash_lookup(u32 index
, struct tcf_hashinfo
*hinfo
)
167 struct tcf_common
*p
;
169 read_lock(hinfo
->lock
);
170 for (p
= hinfo
->htab
[tcf_hash(index
, hinfo
->hmask
)]; p
;
172 if (p
->tcfc_index
== index
)
175 read_unlock(hinfo
->lock
);
179 EXPORT_SYMBOL(tcf_hash_lookup
);
181 u32
tcf_hash_new_index(u32
*idx_gen
, struct tcf_hashinfo
*hinfo
)
188 } while (tcf_hash_lookup(val
, hinfo
));
190 return (*idx_gen
= val
);
192 EXPORT_SYMBOL(tcf_hash_new_index
);
194 int tcf_hash_search(struct tc_action
*a
, u32 index
)
196 struct tcf_hashinfo
*hinfo
= a
->ops
->hinfo
;
197 struct tcf_common
*p
= tcf_hash_lookup(index
, hinfo
);
205 EXPORT_SYMBOL(tcf_hash_search
);
207 struct tcf_common
*tcf_hash_check(u32 index
, struct tc_action
*a
, int bind
,
208 struct tcf_hashinfo
*hinfo
)
210 struct tcf_common
*p
= NULL
;
211 if (index
&& (p
= tcf_hash_lookup(index
, hinfo
)) != NULL
) {
220 EXPORT_SYMBOL(tcf_hash_check
);
222 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
)
224 struct tcf_common
*p
= kzalloc(size
, GFP_KERNEL
);
232 spin_lock_init(&p
->tcfc_lock
);
233 p
->tcfc_stats_lock
= &p
->tcfc_lock
;
234 p
->tcfc_index
= index
? index
: tcf_hash_new_index(idx_gen
, hinfo
);
235 p
->tcfc_tm
.install
= jiffies
;
236 p
->tcfc_tm
.lastuse
= jiffies
;
238 gen_new_estimator(&p
->tcfc_bstats
, &p
->tcfc_rate_est
,
239 p
->tcfc_stats_lock
, est
);
240 a
->priv
= (void *) p
;
243 EXPORT_SYMBOL(tcf_hash_create
);
245 void tcf_hash_insert(struct tcf_common
*p
, struct tcf_hashinfo
*hinfo
)
247 unsigned int h
= tcf_hash(p
->tcfc_index
, hinfo
->hmask
);
249 write_lock_bh(hinfo
->lock
);
250 p
->tcfc_next
= hinfo
->htab
[h
];
252 write_unlock_bh(hinfo
->lock
);
254 EXPORT_SYMBOL(tcf_hash_insert
);
256 static struct tc_action_ops
*act_base
= NULL
;
257 static DEFINE_RWLOCK(act_mod_lock
);
259 int tcf_register_action(struct tc_action_ops
*act
)
261 struct tc_action_ops
*a
, **ap
;
263 write_lock(&act_mod_lock
);
264 for (ap
= &act_base
; (a
= *ap
) != NULL
; ap
= &a
->next
) {
265 if (act
->type
== a
->type
|| (strcmp(act
->kind
, a
->kind
) == 0)) {
266 write_unlock(&act_mod_lock
);
272 write_unlock(&act_mod_lock
);
276 int tcf_unregister_action(struct tc_action_ops
*act
)
278 struct tc_action_ops
*a
, **ap
;
281 write_lock(&act_mod_lock
);
282 for (ap
= &act_base
; (a
= *ap
) != NULL
; ap
= &a
->next
)
290 write_unlock(&act_mod_lock
);
295 static struct tc_action_ops
*tc_lookup_action_n(char *kind
)
297 struct tc_action_ops
*a
= NULL
;
300 read_lock(&act_mod_lock
);
301 for (a
= act_base
; a
; a
= a
->next
) {
302 if (strcmp(kind
, a
->kind
) == 0) {
303 if (!try_module_get(a
->owner
)) {
304 read_unlock(&act_mod_lock
);
310 read_unlock(&act_mod_lock
);
315 /* lookup by rtattr */
316 static struct tc_action_ops
*tc_lookup_action(struct rtattr
*kind
)
318 struct tc_action_ops
*a
= NULL
;
321 read_lock(&act_mod_lock
);
322 for (a
= act_base
; a
; a
= a
->next
) {
323 if (rtattr_strcmp(kind
, a
->kind
) == 0) {
324 if (!try_module_get(a
->owner
)) {
325 read_unlock(&act_mod_lock
);
331 read_unlock(&act_mod_lock
);
338 static struct tc_action_ops
*tc_lookup_action_id(u32 type
)
340 struct tc_action_ops
*a
= NULL
;
343 read_lock(&act_mod_lock
);
344 for (a
= act_base
; a
; a
= a
->next
) {
345 if (a
->type
== type
) {
346 if (!try_module_get(a
->owner
)) {
347 read_unlock(&act_mod_lock
);
353 read_unlock(&act_mod_lock
);
359 int tcf_action_exec(struct sk_buff
*skb
, struct tc_action
*act
,
360 struct tcf_result
*res
)
365 if (skb
->tc_verd
& TC_NCLS
) {
366 skb
->tc_verd
= CLR_TC_NCLS(skb
->tc_verd
);
370 while ((a
= act
) != NULL
) {
372 if (a
->ops
&& a
->ops
->act
) {
373 ret
= a
->ops
->act(skb
, a
, res
);
374 if (TC_MUNGED
& skb
->tc_verd
) {
375 /* copied already, allow trampling */
376 skb
->tc_verd
= SET_TC_OK2MUNGE(skb
->tc_verd
);
377 skb
->tc_verd
= CLR_TC_MUNGED(skb
->tc_verd
);
379 if (ret
== TC_ACT_REPEAT
)
380 goto repeat
; /* we need a ttl - JHS */
381 if (ret
!= TC_ACT_PIPE
)
390 void tcf_action_destroy(struct tc_action
*act
, int bind
)
394 for (a
= act
; a
; a
= act
) {
395 if (a
->ops
&& a
->ops
->cleanup
) {
396 if (a
->ops
->cleanup(a
, bind
) == ACT_P_DELETED
)
397 module_put(a
->ops
->owner
);
400 } else { /*FIXME: Remove later - catch insertion bugs*/
401 printk("tcf_action_destroy: BUG? destroying NULL ops\n");
409 tcf_action_dump_old(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
413 if (a
->ops
== NULL
|| a
->ops
->dump
== NULL
)
415 return a
->ops
->dump(skb
, a
, bind
, ref
);
419 tcf_action_dump_1(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
422 unsigned char *b
= skb_tail_pointer(skb
);
425 if (a
->ops
== NULL
|| a
->ops
->dump
== NULL
)
428 RTA_PUT(skb
, TCA_KIND
, IFNAMSIZ
, a
->ops
->kind
);
429 if (tcf_action_copy_stats(skb
, a
, 0))
431 r
= (struct rtattr
*)skb_tail_pointer(skb
);
432 RTA_PUT(skb
, TCA_OPTIONS
, 0, NULL
);
433 if ((err
= tcf_action_dump_old(skb
, a
, bind
, ref
)) > 0) {
434 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
444 tcf_action_dump(struct sk_buff
*skb
, struct tc_action
*act
, int bind
, int ref
)
448 unsigned char *b
= skb_tail_pointer(skb
);
451 while ((a
= act
) != NULL
) {
452 r
= (struct rtattr
*)skb_tail_pointer(skb
);
454 RTA_PUT(skb
, a
->order
, 0, NULL
);
455 err
= tcf_action_dump_1(skb
, a
, bind
, ref
);
458 r
->rta_len
= skb_tail_pointer(skb
) - (u8
*)r
;
470 struct tc_action
*tcf_action_init_1(struct rtattr
*rta
, struct rtattr
*est
,
471 char *name
, int ovr
, int bind
, int *err
)
474 struct tc_action_ops
*a_o
;
475 char act_name
[IFNAMSIZ
];
476 struct rtattr
*tb
[TCA_ACT_MAX
+1];
482 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
484 kind
= tb
[TCA_ACT_KIND
-1];
487 if (rtattr_strlcpy(act_name
, kind
, IFNAMSIZ
) >= IFNAMSIZ
)
490 if (strlcpy(act_name
, name
, IFNAMSIZ
) >= IFNAMSIZ
)
494 a_o
= tc_lookup_action_n(act_name
);
498 request_module("act_%s", act_name
);
501 a_o
= tc_lookup_action_n(act_name
);
503 /* We dropped the RTNL semaphore in order to
504 * perform the module load. So, even if we
505 * succeeded in loading the module we have to
506 * tell the caller to replay the request. We
507 * indicate this using -EAGAIN.
519 a
= kzalloc(sizeof(*a
), GFP_KERNEL
);
523 /* backward compatibility for policer */
525 *err
= a_o
->init(tb
[TCA_ACT_OPTIONS
-1], est
, a
, ovr
, bind
);
527 *err
= a_o
->init(rta
, est
, a
, ovr
, bind
);
531 /* module count goes up only when brand new policy is created
532 if it exists and is only bound to in a_o->init() then
533 ACT_P_CREATED is not returned (a zero is).
535 if (*err
!= ACT_P_CREATED
)
536 module_put(a_o
->owner
);
545 module_put(a_o
->owner
);
550 struct tc_action
*tcf_action_init(struct rtattr
*rta
, struct rtattr
*est
,
551 char *name
, int ovr
, int bind
, int *err
)
553 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+1];
554 struct tc_action
*head
= NULL
, *act
, *act_prev
= NULL
;
557 if (rtattr_parse_nested(tb
, TCA_ACT_MAX_PRIO
, rta
) < 0) {
562 for (i
=0; i
< TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
563 act
= tcf_action_init_1(tb
[i
], est
, name
, ovr
, bind
, err
);
571 act_prev
->next
= act
;
578 tcf_action_destroy(head
, bind
);
582 int tcf_action_copy_stats(struct sk_buff
*skb
, struct tc_action
*a
,
587 struct tcf_act_hdr
*h
= a
->priv
;
592 /* compat_mode being true specifies a call that is supposed
593 * to add additional backward compatiblity statistic TLVs.
596 if (a
->type
== TCA_OLD_COMPAT
)
597 err
= gnet_stats_start_copy_compat(skb
, 0,
598 TCA_STATS
, TCA_XSTATS
, h
->tcf_stats_lock
, &d
);
602 err
= gnet_stats_start_copy(skb
, TCA_ACT_STATS
,
603 h
->tcf_stats_lock
, &d
);
608 if (a
->ops
!= NULL
&& a
->ops
->get_stats
!= NULL
)
609 if (a
->ops
->get_stats(skb
, a
) < 0)
612 if (gnet_stats_copy_basic(&d
, &h
->tcf_bstats
) < 0 ||
613 gnet_stats_copy_rate_est(&d
, &h
->tcf_rate_est
) < 0 ||
614 gnet_stats_copy_queue(&d
, &h
->tcf_qstats
) < 0)
617 if (gnet_stats_finish_copy(&d
) < 0)
627 tca_get_fill(struct sk_buff
*skb
, struct tc_action
*a
, u32 pid
, u32 seq
,
628 u16 flags
, int event
, int bind
, int ref
)
631 struct nlmsghdr
*nlh
;
632 unsigned char *b
= skb_tail_pointer(skb
);
635 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*t
), flags
);
638 t
->tca_family
= AF_UNSPEC
;
642 x
= (struct rtattr
*)skb_tail_pointer(skb
);
643 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
645 if (tcf_action_dump(skb
, a
, bind
, ref
) < 0)
648 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
650 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
660 act_get_notify(u32 pid
, struct nlmsghdr
*n
, struct tc_action
*a
, int event
)
664 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
667 if (tca_get_fill(skb
, a
, pid
, n
->nlmsg_seq
, 0, event
, 0, 0) <= 0) {
672 return rtnl_unicast(skb
, pid
);
675 static struct tc_action
*
676 tcf_action_get_1(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int *err
)
678 struct rtattr
*tb
[TCA_ACT_MAX
+1];
683 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
686 if (tb
[TCA_ACT_INDEX
- 1] == NULL
||
687 RTA_PAYLOAD(tb
[TCA_ACT_INDEX
- 1]) < sizeof(index
))
689 index
= *(int *)RTA_DATA(tb
[TCA_ACT_INDEX
- 1]);
692 a
= kzalloc(sizeof(struct tc_action
), GFP_KERNEL
);
697 a
->ops
= tc_lookup_action(tb
[TCA_ACT_KIND
- 1]);
700 if (a
->ops
->lookup
== NULL
)
703 if (a
->ops
->lookup(a
, index
) == 0)
706 module_put(a
->ops
->owner
);
710 module_put(a
->ops
->owner
);
716 static void cleanup_a(struct tc_action
*act
)
720 for (a
= act
; a
; a
= act
) {
726 static struct tc_action
*create_a(int i
)
728 struct tc_action
*act
;
730 act
= kzalloc(sizeof(*act
), GFP_KERNEL
);
732 printk("create_a: failed to alloc!\n");
739 static int tca_action_flush(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
)
743 struct nlmsghdr
*nlh
;
745 struct netlink_callback dcb
;
747 struct rtattr
*tb
[TCA_ACT_MAX
+1];
749 struct tc_action
*a
= create_a(0);
753 printk("tca_action_flush: couldnt create tc_action\n");
757 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
759 printk("tca_action_flush: failed skb alloc\n");
764 b
= skb_tail_pointer(skb
);
766 if (rtattr_parse_nested(tb
, TCA_ACT_MAX
, rta
) < 0)
769 kind
= tb
[TCA_ACT_KIND
-1];
770 a
->ops
= tc_lookup_action(kind
);
774 nlh
= NLMSG_PUT(skb
, pid
, n
->nlmsg_seq
, RTM_DELACTION
, sizeof(*t
));
776 t
->tca_family
= AF_UNSPEC
;
780 x
= (struct rtattr
*)skb_tail_pointer(skb
);
781 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
783 err
= a
->ops
->walk(skb
, &dcb
, RTM_DELACTION
, a
);
787 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
789 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
790 nlh
->nlmsg_flags
|= NLM_F_ROOT
;
791 module_put(a
->ops
->owner
);
793 err
= rtnetlink_send(skb
, pid
, RTNLGRP_TC
, n
->nlmsg_flags
&NLM_F_ECHO
);
801 module_put(a
->ops
->owner
);
809 tca_action_gd(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int event
)
812 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+1];
813 struct tc_action
*head
= NULL
, *act
, *act_prev
= NULL
;
815 if (rtattr_parse_nested(tb
, TCA_ACT_MAX_PRIO
, rta
) < 0)
818 if (event
== RTM_DELACTION
&& n
->nlmsg_flags
&NLM_F_ROOT
) {
819 if (tb
[0] != NULL
&& tb
[1] == NULL
)
820 return tca_action_flush(tb
[0], n
, pid
);
823 for (i
=0; i
< TCA_ACT_MAX_PRIO
&& tb
[i
]; i
++) {
824 act
= tcf_action_get_1(tb
[i
], n
, pid
, &ret
);
832 act_prev
->next
= act
;
836 if (event
== RTM_GETACTION
)
837 ret
= act_get_notify(pid
, n
, head
, event
);
841 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
847 if (tca_get_fill(skb
, head
, pid
, n
->nlmsg_seq
, 0, event
,
854 /* now do the delete */
855 tcf_action_destroy(head
, 0);
856 ret
= rtnetlink_send(skb
, pid
, RTNLGRP_TC
,
857 n
->nlmsg_flags
&NLM_F_ECHO
);
867 static int tcf_add_notify(struct tc_action
*a
, u32 pid
, u32 seq
, int event
,
871 struct nlmsghdr
*nlh
;
877 skb
= alloc_skb(NLMSG_GOODSIZE
, GFP_KERNEL
);
881 b
= skb_tail_pointer(skb
);
883 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*t
), flags
);
885 t
->tca_family
= AF_UNSPEC
;
889 x
= (struct rtattr
*)skb_tail_pointer(skb
);
890 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
892 if (tcf_action_dump(skb
, a
, 0, 0) < 0)
895 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
897 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
898 NETLINK_CB(skb
).dst_group
= RTNLGRP_TC
;
900 err
= rtnetlink_send(skb
, pid
, RTNLGRP_TC
, flags
&NLM_F_ECHO
);
913 tcf_action_add(struct rtattr
*rta
, struct nlmsghdr
*n
, u32 pid
, int ovr
)
916 struct tc_action
*act
;
918 u32 seq
= n
->nlmsg_seq
;
920 act
= tcf_action_init(rta
, NULL
, NULL
, ovr
, 0, &ret
);
924 /* dump then free all the actions after update; inserted policy
927 ret
= tcf_add_notify(act
, pid
, seq
, RTM_NEWACTION
, n
->nlmsg_flags
);
928 for (a
= act
; a
; a
= act
) {
936 static int tc_ctl_action(struct sk_buff
*skb
, struct nlmsghdr
*n
, void *arg
)
938 struct rtattr
**tca
= arg
;
939 u32 pid
= skb
? NETLINK_CB(skb
).pid
: 0;
940 int ret
= 0, ovr
= 0;
942 if (tca
[TCA_ACT_TAB
-1] == NULL
) {
943 printk("tc_ctl_action: received NO action attribs\n");
947 /* n->nlmsg_flags&NLM_F_CREATE
949 switch (n
->nlmsg_type
) {
951 /* we are going to assume all other flags
952 * imply create only if it doesnt exist
953 * Note that CREATE | EXCL implies that
954 * but since we want avoid ambiguity (eg when flags
955 * is zero) then just set this
957 if (n
->nlmsg_flags
&NLM_F_REPLACE
)
960 ret
= tcf_action_add(tca
[TCA_ACT_TAB
-1], n
, pid
, ovr
);
965 ret
= tca_action_gd(tca
[TCA_ACT_TAB
-1], n
, pid
, RTM_DELACTION
);
968 ret
= tca_action_gd(tca
[TCA_ACT_TAB
-1], n
, pid
, RTM_GETACTION
);
977 static struct rtattr
*
978 find_dump_kind(struct nlmsghdr
*n
)
980 struct rtattr
*tb1
, *tb2
[TCA_ACT_MAX
+1];
981 struct rtattr
*tb
[TCA_ACT_MAX_PRIO
+ 1];
982 struct rtattr
*rta
[TCAA_MAX
+ 1];
984 int min_len
= NLMSG_LENGTH(sizeof(struct tcamsg
));
985 int attrlen
= n
->nlmsg_len
- NLMSG_ALIGN(min_len
);
986 struct rtattr
*attr
= (void *) n
+ NLMSG_ALIGN(min_len
);
988 if (rtattr_parse(rta
, TCAA_MAX
, attr
, attrlen
) < 0)
990 tb1
= rta
[TCA_ACT_TAB
- 1];
994 if (rtattr_parse(tb
, TCA_ACT_MAX_PRIO
, RTA_DATA(tb1
),
995 NLMSG_ALIGN(RTA_PAYLOAD(tb1
))) < 0)
1000 if (rtattr_parse(tb2
, TCA_ACT_MAX
, RTA_DATA(tb
[0]),
1001 RTA_PAYLOAD(tb
[0])) < 0)
1003 kind
= tb2
[TCA_ACT_KIND
-1];
1009 tc_dump_action(struct sk_buff
*skb
, struct netlink_callback
*cb
)
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
);
1021 printk("tc_dump_action: action bad kind\n");
1025 a_o
= tc_lookup_action(kind
);
1030 memset(&a
, 0, sizeof(struct tc_action
));
1033 if (a_o
->walk
== NULL
) {
1034 printk("tc_dump_action: %s !capable of dumping table\n", a_o
->kind
);
1035 goto rtattr_failure
;
1038 nlh
= NLMSG_PUT(skb
, NETLINK_CB(cb
->skb
).pid
, cb
->nlh
->nlmsg_seq
,
1039 cb
->nlh
->nlmsg_type
, sizeof(*t
));
1040 t
= NLMSG_DATA(nlh
);
1041 t
->tca_family
= AF_UNSPEC
;
1045 x
= (struct rtattr
*)skb_tail_pointer(skb
);
1046 RTA_PUT(skb
, TCA_ACT_TAB
, 0, NULL
);
1048 ret
= a_o
->walk(skb
, cb
, RTM_GETACTION
, &a
);
1050 goto rtattr_failure
;
1053 x
->rta_len
= skb_tail_pointer(skb
) - (u8
*)x
;
1058 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1059 if (NETLINK_CB(cb
->skb
).pid
&& ret
)
1060 nlh
->nlmsg_flags
|= NLM_F_MULTI
;
1061 module_put(a_o
->owner
);
1066 module_put(a_o
->owner
);
1071 static int __init
tc_action_init(void)
1073 rtnl_register(PF_UNSPEC
, RTM_NEWACTION
, tc_ctl_action
, NULL
);
1074 rtnl_register(PF_UNSPEC
, RTM_DELACTION
, tc_ctl_action
, NULL
);
1075 rtnl_register(PF_UNSPEC
, RTM_GETACTION
, tc_ctl_action
, tc_dump_action
);
1080 subsys_initcall(tc_action_init
);
1082 EXPORT_SYMBOL(tcf_register_action
);
1083 EXPORT_SYMBOL(tcf_unregister_action
);
1084 EXPORT_SYMBOL(tcf_action_exec
);
1085 EXPORT_SYMBOL(tcf_action_dump_1
);