Commit 05f4720e authored by David S. Miller's avatar David S. Miller

Merge branch 'net_sched_actions'

Jamal Hadi Salim says:

====================
net_sched: actions - Add default lookup and walker

This set of patches provide defaults for lookup and walkers for actions.
Users can override when needed.
It also enforces mandatory action methods to be passed.

Thanks to David Miller who paid attention and made this patch set
much better.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents e1ca87bb 651a6493
...@@ -270,6 +270,16 @@ int tcf_register_action(struct tc_action_ops *act) ...@@ -270,6 +270,16 @@ int tcf_register_action(struct tc_action_ops *act)
{ {
struct tc_action_ops *a, **ap; struct tc_action_ops *a, **ap;
/* Must supply act, dump, cleanup and init */
if (!act->act || !act->dump || !act->cleanup || !act->init)
return -EINVAL;
/* Supply defaults */
if (!act->lookup)
act->lookup = tcf_hash_search;
if (!act->walk)
act->walk = tcf_generic_walker;
write_lock(&act_mod_lock); write_lock(&act_mod_lock);
for (ap = &act_base; (a = *ap) != NULL; ap = &a->next) { for (ap = &act_base; (a = *ap) != NULL; ap = &a->next) {
if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) { if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) {
...@@ -381,7 +391,7 @@ int tcf_action_exec(struct sk_buff *skb, const struct tc_action *act, ...@@ -381,7 +391,7 @@ int tcf_action_exec(struct sk_buff *skb, const struct tc_action *act,
} }
while ((a = act) != NULL) { while ((a = act) != NULL) {
repeat: repeat:
if (a->ops && a->ops->act) { if (a->ops) {
ret = a->ops->act(skb, a, res); ret = a->ops->act(skb, a, res);
if (TC_MUNGED & skb->tc_verd) { if (TC_MUNGED & skb->tc_verd) {
/* copied already, allow trampling */ /* copied already, allow trampling */
...@@ -405,7 +415,7 @@ void tcf_action_destroy(struct tc_action *act, int bind) ...@@ -405,7 +415,7 @@ void tcf_action_destroy(struct tc_action *act, int bind)
struct tc_action *a; struct tc_action *a;
for (a = act; a; a = act) { for (a = act; a; a = act) {
if (a->ops && a->ops->cleanup) { if (a->ops) {
if (a->ops->cleanup(a, bind) == ACT_P_DELETED) if (a->ops->cleanup(a, bind) == ACT_P_DELETED)
module_put(a->ops->owner); module_put(a->ops->owner);
act = act->next; act = act->next;
...@@ -424,7 +434,7 @@ tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int bind, int ref) ...@@ -424,7 +434,7 @@ tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
{ {
int err = -EINVAL; int err = -EINVAL;
if (a->ops == NULL || a->ops->dump == NULL) if (a->ops == NULL)
return err; return err;
return a->ops->dump(skb, a, bind, ref); return a->ops->dump(skb, a, bind, ref);
} }
...@@ -436,7 +446,7 @@ tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref) ...@@ -436,7 +446,7 @@ tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
unsigned char *b = skb_tail_pointer(skb); unsigned char *b = skb_tail_pointer(skb);
struct nlattr *nest; struct nlattr *nest;
if (a->ops == NULL || a->ops->dump == NULL) if (a->ops == NULL)
return err; return err;
if (nla_put_string(skb, TCA_KIND, a->ops->kind)) if (nla_put_string(skb, TCA_KIND, a->ops->kind))
...@@ -723,8 +733,6 @@ tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 portid) ...@@ -723,8 +733,6 @@ tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 portid)
a->ops = tc_lookup_action(tb[TCA_ACT_KIND]); a->ops = tc_lookup_action(tb[TCA_ACT_KIND]);
if (a->ops == NULL) if (a->ops == NULL)
goto err_free; goto err_free;
if (a->ops->lookup == NULL)
goto err_mod;
err = -ENOENT; err = -ENOENT;
if (a->ops->lookup(a, index) == 0) if (a->ops->lookup(a, index) == 0)
goto err_mod; goto err_mod;
...@@ -1084,12 +1092,6 @@ tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1084,12 +1092,6 @@ tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
memset(&a, 0, sizeof(struct tc_action)); memset(&a, 0, sizeof(struct tc_action));
a.ops = a_o; a.ops = a_o;
if (a_o->walk == NULL) {
WARN(1, "tc_dump_action: %s !capable of dumping table\n",
a_o->kind);
goto out_module_put;
}
nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
cb->nlh->nlmsg_type, sizeof(*t), 0); cb->nlh->nlmsg_type, sizeof(*t), 0);
if (!nlh) if (!nlh)
......
...@@ -585,9 +585,7 @@ static struct tc_action_ops act_csum_ops = { ...@@ -585,9 +585,7 @@ static struct tc_action_ops act_csum_ops = {
.act = tcf_csum, .act = tcf_csum,
.dump = tcf_csum_dump, .dump = tcf_csum_dump,
.cleanup = tcf_csum_cleanup, .cleanup = tcf_csum_cleanup,
.lookup = tcf_hash_search,
.init = tcf_csum_init, .init = tcf_csum_init,
.walk = tcf_generic_walker
}; };
MODULE_DESCRIPTION("Checksum updating actions"); MODULE_DESCRIPTION("Checksum updating actions");
......
...@@ -206,9 +206,7 @@ static struct tc_action_ops act_gact_ops = { ...@@ -206,9 +206,7 @@ static struct tc_action_ops act_gact_ops = {
.act = tcf_gact, .act = tcf_gact,
.dump = tcf_gact_dump, .dump = tcf_gact_dump,
.cleanup = tcf_gact_cleanup, .cleanup = tcf_gact_cleanup,
.lookup = tcf_hash_search,
.init = tcf_gact_init, .init = tcf_gact_init,
.walk = tcf_generic_walker
}; };
MODULE_AUTHOR("Jamal Hadi Salim(2002-4)"); MODULE_AUTHOR("Jamal Hadi Salim(2002-4)");
......
...@@ -298,9 +298,7 @@ static struct tc_action_ops act_ipt_ops = { ...@@ -298,9 +298,7 @@ static struct tc_action_ops act_ipt_ops = {
.act = tcf_ipt, .act = tcf_ipt,
.dump = tcf_ipt_dump, .dump = tcf_ipt_dump,
.cleanup = tcf_ipt_cleanup, .cleanup = tcf_ipt_cleanup,
.lookup = tcf_hash_search,
.init = tcf_ipt_init, .init = tcf_ipt_init,
.walk = tcf_generic_walker
}; };
static struct tc_action_ops act_xt_ops = { static struct tc_action_ops act_xt_ops = {
...@@ -312,9 +310,7 @@ static struct tc_action_ops act_xt_ops = { ...@@ -312,9 +310,7 @@ static struct tc_action_ops act_xt_ops = {
.act = tcf_ipt, .act = tcf_ipt,
.dump = tcf_ipt_dump, .dump = tcf_ipt_dump,
.cleanup = tcf_ipt_cleanup, .cleanup = tcf_ipt_cleanup,
.lookup = tcf_hash_search,
.init = tcf_ipt_init, .init = tcf_ipt_init,
.walk = tcf_generic_walker
}; };
MODULE_AUTHOR("Jamal Hadi Salim(2002-13)"); MODULE_AUTHOR("Jamal Hadi Salim(2002-13)");
......
...@@ -271,9 +271,7 @@ static struct tc_action_ops act_mirred_ops = { ...@@ -271,9 +271,7 @@ static struct tc_action_ops act_mirred_ops = {
.act = tcf_mirred, .act = tcf_mirred,
.dump = tcf_mirred_dump, .dump = tcf_mirred_dump,
.cleanup = tcf_mirred_cleanup, .cleanup = tcf_mirred_cleanup,
.lookup = tcf_hash_search,
.init = tcf_mirred_init, .init = tcf_mirred_init,
.walk = tcf_generic_walker
}; };
MODULE_AUTHOR("Jamal Hadi Salim(2002)"); MODULE_AUTHOR("Jamal Hadi Salim(2002)");
......
...@@ -308,9 +308,7 @@ static struct tc_action_ops act_nat_ops = { ...@@ -308,9 +308,7 @@ static struct tc_action_ops act_nat_ops = {
.act = tcf_nat, .act = tcf_nat,
.dump = tcf_nat_dump, .dump = tcf_nat_dump,
.cleanup = tcf_nat_cleanup, .cleanup = tcf_nat_cleanup,
.lookup = tcf_hash_search,
.init = tcf_nat_init, .init = tcf_nat_init,
.walk = tcf_generic_walker
}; };
MODULE_DESCRIPTION("Stateless NAT actions"); MODULE_DESCRIPTION("Stateless NAT actions");
......
...@@ -243,9 +243,7 @@ static struct tc_action_ops act_pedit_ops = { ...@@ -243,9 +243,7 @@ static struct tc_action_ops act_pedit_ops = {
.act = tcf_pedit, .act = tcf_pedit,
.dump = tcf_pedit_dump, .dump = tcf_pedit_dump,
.cleanup = tcf_pedit_cleanup, .cleanup = tcf_pedit_cleanup,
.lookup = tcf_hash_search,
.init = tcf_pedit_init, .init = tcf_pedit_init,
.walk = tcf_generic_walker
}; };
MODULE_AUTHOR("Jamal Hadi Salim(2002-4)"); MODULE_AUTHOR("Jamal Hadi Salim(2002-4)");
......
...@@ -407,7 +407,6 @@ static struct tc_action_ops act_police_ops = { ...@@ -407,7 +407,6 @@ static struct tc_action_ops act_police_ops = {
.act = tcf_act_police, .act = tcf_act_police,
.dump = tcf_act_police_dump, .dump = tcf_act_police_dump,
.cleanup = tcf_act_police_cleanup, .cleanup = tcf_act_police_cleanup,
.lookup = tcf_hash_search,
.init = tcf_act_police_locate, .init = tcf_act_police_locate,
.walk = tcf_act_police_walker .walk = tcf_act_police_walker
}; };
......
...@@ -201,7 +201,6 @@ static struct tc_action_ops act_simp_ops = { ...@@ -201,7 +201,6 @@ static struct tc_action_ops act_simp_ops = {
.dump = tcf_simp_dump, .dump = tcf_simp_dump,
.cleanup = tcf_simp_cleanup, .cleanup = tcf_simp_cleanup,
.init = tcf_simp_init, .init = tcf_simp_init,
.walk = tcf_generic_walker,
}; };
MODULE_AUTHOR("Jamal Hadi Salim(2005)"); MODULE_AUTHOR("Jamal Hadi Salim(2005)");
......
...@@ -203,7 +203,6 @@ static struct tc_action_ops act_skbedit_ops = { ...@@ -203,7 +203,6 @@ static struct tc_action_ops act_skbedit_ops = {
.dump = tcf_skbedit_dump, .dump = tcf_skbedit_dump,
.cleanup = tcf_skbedit_cleanup, .cleanup = tcf_skbedit_cleanup,
.init = tcf_skbedit_init, .init = tcf_skbedit_init,
.walk = tcf_generic_walker,
}; };
MODULE_AUTHOR("Alexander Duyck, <alexander.h.duyck@intel.com>"); MODULE_AUTHOR("Alexander Duyck, <alexander.h.duyck@intel.com>");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment