Skip to content

Commit

Permalink
Merge branch 'net_sched_actions'
Browse files Browse the repository at this point in the history
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: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Dec 6, 2013
2 parents e1ca87b + 651a649 commit 05f4720
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 29 deletions.
26 changes: 14 additions & 12 deletions net/sched/act_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ int tcf_register_action(struct tc_action_ops *act)
{
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);
for (ap = &act_base; (a = *ap) != NULL; ap = &a->next) {
if (act->type == a->type || (strcmp(act->kind, a->kind) == 0)) {
Expand Down Expand Up @@ -381,7 +391,7 @@ int tcf_action_exec(struct sk_buff *skb, const struct tc_action *act,
}
while ((a = act) != NULL) {
repeat:
if (a->ops && a->ops->act) {
if (a->ops) {
ret = a->ops->act(skb, a, res);
if (TC_MUNGED & skb->tc_verd) {
/* copied already, allow trampling */
Expand All @@ -405,7 +415,7 @@ void tcf_action_destroy(struct tc_action *act, int bind)
struct tc_action *a;

for (a = act; a; a = act) {
if (a->ops && a->ops->cleanup) {
if (a->ops) {
if (a->ops->cleanup(a, bind) == ACT_P_DELETED)
module_put(a->ops->owner);
act = act->next;
Expand All @@ -424,7 +434,7 @@ tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
{
int err = -EINVAL;

if (a->ops == NULL || a->ops->dump == NULL)
if (a->ops == NULL)
return err;
return a->ops->dump(skb, a, bind, ref);
}
Expand All @@ -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);
struct nlattr *nest;

if (a->ops == NULL || a->ops->dump == NULL)
if (a->ops == NULL)
return err;

if (nla_put_string(skb, TCA_KIND, a->ops->kind))
Expand Down Expand Up @@ -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]);
if (a->ops == NULL)
goto err_free;
if (a->ops->lookup == NULL)
goto err_mod;
err = -ENOENT;
if (a->ops->lookup(a, index) == 0)
goto err_mod;
Expand Down Expand Up @@ -1084,12 +1092,6 @@ tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
memset(&a, 0, sizeof(struct tc_action));
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,
cb->nlh->nlmsg_type, sizeof(*t), 0);
if (!nlh)
Expand Down
2 changes: 0 additions & 2 deletions net/sched/act_csum.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,7 @@ static struct tc_action_ops act_csum_ops = {
.act = tcf_csum,
.dump = tcf_csum_dump,
.cleanup = tcf_csum_cleanup,
.lookup = tcf_hash_search,
.init = tcf_csum_init,
.walk = tcf_generic_walker
};

MODULE_DESCRIPTION("Checksum updating actions");
Expand Down
2 changes: 0 additions & 2 deletions net/sched/act_gact.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ static struct tc_action_ops act_gact_ops = {
.act = tcf_gact,
.dump = tcf_gact_dump,
.cleanup = tcf_gact_cleanup,
.lookup = tcf_hash_search,
.init = tcf_gact_init,
.walk = tcf_generic_walker
};

MODULE_AUTHOR("Jamal Hadi Salim(2002-4)");
Expand Down
4 changes: 0 additions & 4 deletions net/sched/act_ipt.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ static struct tc_action_ops act_ipt_ops = {
.act = tcf_ipt,
.dump = tcf_ipt_dump,
.cleanup = tcf_ipt_cleanup,
.lookup = tcf_hash_search,
.init = tcf_ipt_init,
.walk = tcf_generic_walker
};

static struct tc_action_ops act_xt_ops = {
Expand All @@ -312,9 +310,7 @@ static struct tc_action_ops act_xt_ops = {
.act = tcf_ipt,
.dump = tcf_ipt_dump,
.cleanup = tcf_ipt_cleanup,
.lookup = tcf_hash_search,
.init = tcf_ipt_init,
.walk = tcf_generic_walker
};

MODULE_AUTHOR("Jamal Hadi Salim(2002-13)");
Expand Down
2 changes: 0 additions & 2 deletions net/sched/act_mirred.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,7 @@ static struct tc_action_ops act_mirred_ops = {
.act = tcf_mirred,
.dump = tcf_mirred_dump,
.cleanup = tcf_mirred_cleanup,
.lookup = tcf_hash_search,
.init = tcf_mirred_init,
.walk = tcf_generic_walker
};

MODULE_AUTHOR("Jamal Hadi Salim(2002)");
Expand Down
2 changes: 0 additions & 2 deletions net/sched/act_nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ static struct tc_action_ops act_nat_ops = {
.act = tcf_nat,
.dump = tcf_nat_dump,
.cleanup = tcf_nat_cleanup,
.lookup = tcf_hash_search,
.init = tcf_nat_init,
.walk = tcf_generic_walker
};

MODULE_DESCRIPTION("Stateless NAT actions");
Expand Down
2 changes: 0 additions & 2 deletions net/sched/act_pedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ static struct tc_action_ops act_pedit_ops = {
.act = tcf_pedit,
.dump = tcf_pedit_dump,
.cleanup = tcf_pedit_cleanup,
.lookup = tcf_hash_search,
.init = tcf_pedit_init,
.walk = tcf_generic_walker
};

MODULE_AUTHOR("Jamal Hadi Salim(2002-4)");
Expand Down
1 change: 0 additions & 1 deletion net/sched/act_police.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ static struct tc_action_ops act_police_ops = {
.act = tcf_act_police,
.dump = tcf_act_police_dump,
.cleanup = tcf_act_police_cleanup,
.lookup = tcf_hash_search,
.init = tcf_act_police_locate,
.walk = tcf_act_police_walker
};
Expand Down
1 change: 0 additions & 1 deletion net/sched/act_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ static struct tc_action_ops act_simp_ops = {
.dump = tcf_simp_dump,
.cleanup = tcf_simp_cleanup,
.init = tcf_simp_init,
.walk = tcf_generic_walker,
};

MODULE_AUTHOR("Jamal Hadi Salim(2005)");
Expand Down
1 change: 0 additions & 1 deletion net/sched/act_skbedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ static struct tc_action_ops act_skbedit_ops = {
.dump = tcf_skbedit_dump,
.cleanup = tcf_skbedit_cleanup,
.init = tcf_skbedit_init,
.walk = tcf_generic_walker,
};

MODULE_AUTHOR("Alexander Duyck, <alexander.h.duyck@intel.com>");
Expand Down

0 comments on commit 05f4720

Please sign in to comment.