14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/slab.h>
23 #include <linux/module.h>
77 int err = 0,
index = -1,
i = 0, s_i = 0, n_i = 0;
84 for (
i = 0;
i < (hinfo->
hmask + 1);
i++) {
94 nest = nla_nest_start(skb, a->order);
100 nlmsg_trim(skb, nest);
103 nla_nest_end(skb, nest);
116 nla_nest_cancel(skb, nest);
120 static int tcf_del_walker(
struct sk_buff *skb,
struct tc_action *a,
127 nest = nla_nest_start(skb, a->order);
129 goto nla_put_failure;
130 if (nla_put_string(skb,
TCA_KIND, a->ops->kind))
131 goto nla_put_failure;
132 for (i = 0; i < (hinfo->
hmask + 1); i++) {
133 p = hinfo->
htab[tcf_hash(i, hinfo->
hmask)];
138 module_put(a->ops->owner);
143 if (nla_put_u32(skb,
TCA_FCNT, n_i))
144 goto nla_put_failure;
145 nla_nest_end(skb, nest);
149 nla_nest_cancel(skb, nest);
154 int type,
struct tc_action *a)
159 return tcf_del_walker(skb, a, hinfo);
161 return tcf_dump_walker(skb, cb, a, hinfo);
163 WARN(1,
"tcf_generic_walker: unknown action %d\n", type);
174 for (p = hinfo->
htab[tcf_hash(index, hinfo->
hmask)]; p;
194 return (*idx_gen = val);
226 struct tc_action *a,
int size,
int bind,
250 a->priv = (
void *) p;
266 static struct tc_action_ops *act_base =
NULL;
271 struct tc_action_ops *
a, **ap;
274 for (ap = &act_base; (a = *ap) !=
NULL; ap = &a->next) {
275 if (act->type == a->type || (
strcmp(act->kind, a->kind) == 0)) {
289 struct tc_action_ops *
a, **ap;
293 for (ap = &act_base; (a = *ap) !=
NULL; ap = &a->next)
307 static struct tc_action_ops *tc_lookup_action_n(
char *
kind)
309 struct tc_action_ops *a =
NULL;
313 for (a = act_base;
a; a = a->next) {
314 if (
strcmp(kind, a->kind) == 0) {
315 if (!try_module_get(a->owner)) {
328 static struct tc_action_ops *tc_lookup_action(
struct nlattr *kind)
330 struct tc_action_ops *a =
NULL;
334 for (a = act_base;
a; a = a->next) {
336 if (!try_module_get(a->owner)) {
350 static struct tc_action_ops *tc_lookup_action_id(
u32 type)
352 struct tc_action_ops *a =
NULL;
356 for (a = act_base;
a; a = a->next) {
357 if (a->type == type) {
358 if (!try_module_get(a->owner)) {
374 const struct tc_action *
a;
382 while ((a = act) !=
NULL) {
384 if (a->ops && a->ops->act) {
385 ret = a->ops->act(skb, a, res);
407 for (a = act;
a; a = act) {
408 if (a->ops && a->ops->cleanup) {
409 if (a->ops->cleanup(a, bind) == ACT_P_DELETED)
410 module_put(a->ops->owner);
415 WARN(1,
"tcf_action_destroy: BUG? destroying NULL ops\n");
427 if (a->ops ==
NULL || a->ops->dump ==
NULL)
429 return a->ops->dump(skb, a, bind, ref);
436 unsigned char *
b = skb_tail_pointer(skb);
439 if (a->ops ==
NULL || a->ops->dump ==
NULL)
442 if (nla_put_string(skb,
TCA_KIND, a->ops->kind))
443 goto nla_put_failure;
445 goto nla_put_failure;
448 goto nla_put_failure;
451 nla_nest_end(skb, nest);
468 while ((a = act) !=
NULL) {
470 nest = nla_nest_start(skb, a->order);
472 goto nla_put_failure;
476 nla_nest_end(skb, nest);
484 nla_nest_cancel(skb, nest);
489 char *
name,
int ovr,
int bind)
492 struct tc_action_ops *a_o;
514 a_o = tc_lookup_action_n(act_name);
516 #ifdef CONFIG_MODULES
518 request_module(
"act_%s", act_name);
521 a_o = tc_lookup_action_n(act_name);
547 err = a_o->init(nla, est, a, ovr, bind);
555 if (err != ACT_P_CREATED)
556 module_put(a_o->owner);
564 module_put(a_o->owner);
570 char *
name,
int ovr,
int bind)
590 act_prev->next = act;
606 struct tcf_act_hdr *
h = a->priv;
627 if (a->ops !=
NULL && a->ops->get_stats !=
NULL)
628 if (a->ops->get_stats(skb, a) < 0)
633 &h->tcf_rate_est) < 0 ||
647 tca_get_fill(
struct sk_buff *skb,
struct tc_action *a,
u32 portid,
u32 seq,
652 unsigned char *
b = skb_tail_pointer(skb);
655 nlh = nlmsg_put(skb, portid, seq, event,
sizeof(*t), flags);
670 nla_nest_end(skb, nest);
682 struct tc_action *a,
int event)
689 if (tca_get_fill(skb, a, portid, n->
nlmsg_seq, 0, event, 0, 0) <= 0) {
697 static struct tc_action *
713 index = nla_get_u32(tb[TCA_ACT_INDEX]);
716 a = kzalloc(
sizeof(
struct tc_action),
GFP_KERNEL);
724 if (a->ops->lookup ==
NULL)
727 if (a->ops->lookup(a, index) == 0)
730 module_put(a->ops->owner);
734 module_put(a->ops->owner);
741 static void cleanup_a(
struct tc_action *act)
745 for (a = act;
a; a = act) {
751 static struct tc_action *create_a(
int i)
753 struct tc_action *act;
757 pr_debug(
"create_a: failed to alloc!\n");
764 static int tca_action_flush(
struct net *net,
struct nlattr *nla,
775 struct tc_action *a = create_a(0);
779 pr_debug(
"tca_action_flush: couldnt create tc_action\n");
785 pr_debug(
"tca_action_flush: failed skb alloc\n");
790 b = skb_tail_pointer(skb);
798 a->ops = tc_lookup_action(kind);
820 nla_nest_end(skb, nest);
824 module_put(a->ops->owner);
834 module_put(a->ops->owner);
843 tca_action_gd(
struct net *net,
struct nlattr *nla,
struct nlmsghdr *n,
844 u32 portid,
int event)
856 return tca_action_flush(net, tb[1], n, portid);
862 act = tcf_action_get_1(tb[i], n, portid);
872 act_prev->next = act;
877 ret = act_get_notify(net, portid, n, head, event);
887 if (tca_get_fill(skb, head, portid, n->
nlmsg_seq, 0, event,
907 static int tcf_add_notify(
struct net *net,
struct tc_action *a,
908 u32 portid,
u32 seq,
int event,
u16 flags)
921 b = skb_tail_pointer(skb);
923 nlh = nlmsg_put(skb, portid, seq, event,
sizeof(*t), flags);
938 nla_nest_end(skb, nest);
955 tcf_action_add(
struct net *net,
struct nlattr *nla,
struct nlmsghdr *n,
959 struct tc_action *act;
975 for (a = act;
a; a = act) {
985 struct net *net = sock_net(skb->
sk);
988 int ret = 0, ovr = 0;
995 pr_notice(
"tc_ctl_action: received NO action attribs\n");
1011 ret = tcf_action_add(net, tca[
TCA_ACT_TAB], n, portid, ovr);
1031 find_dump_kind(
const struct nlmsghdr *n)
1062 unsigned char *b = skb_tail_pointer(skb);
1064 struct tc_action_ops *a_o;
1068 struct nlattr *kind = find_dump_kind(cb->
nlh);
1071 pr_info(
"tc_dump_action: action bad kind\n");
1075 a_o = tc_lookup_action(kind);
1079 memset(&a, 0,
sizeof(
struct tc_action));
1082 if (a_o->walk ==
NULL) {
1083 WARN(1,
"tc_dump_action: %s !capable of dumping table\n",
1085 goto out_module_put;
1089 cb->
nlh->nlmsg_type,
sizeof(*t), 0);
1091 goto out_module_put;
1092 t = nlmsg_data(nlh);
1099 goto out_module_put;
1103 goto out_module_put;
1106 nla_nest_end(skb, nest);
1109 nla_nest_cancel(skb, nest);
1114 module_put(a_o->owner);
1118 module_put(a_o->owner);
1123 static int __init tc_action_init(
void)