Commit db50514f authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

net: sched: add termination action to allow goto chain

Introduce new type of termination action called "goto_chain". This allows
user to specify a chain to be processed. This action type is
then processed as a return value in tcf_classify loop in similar
way as "reclassify" is, only it does not reset to the first filter
in chain but rather reset to the first filter of the desired chain.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Acked-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9fb9f251
...@@ -42,6 +42,7 @@ struct tc_action { ...@@ -42,6 +42,7 @@ struct tc_action {
struct gnet_stats_basic_cpu __percpu *cpu_bstats; struct gnet_stats_basic_cpu __percpu *cpu_bstats;
struct gnet_stats_queue __percpu *cpu_qstats; struct gnet_stats_queue __percpu *cpu_qstats;
struct tc_cookie *act_cookie; struct tc_cookie *act_cookie;
struct tcf_chain *goto_chain;
}; };
#define tcf_head common.tcfa_head #define tcf_head common.tcfa_head
#define tcf_index common.tcfa_index #define tcf_index common.tcfa_index
......
...@@ -193,8 +193,13 @@ struct Qdisc_ops { ...@@ -193,8 +193,13 @@ struct Qdisc_ops {
struct tcf_result { struct tcf_result {
unsigned long class; union {
u32 classid; struct {
unsigned long class;
u32 classid;
};
const struct tcf_proto *goto_tp;
};
}; };
struct tcf_proto_ops { struct tcf_proto_ops {
......
...@@ -51,6 +51,7 @@ enum { ...@@ -51,6 +51,7 @@ enum {
(((combined) & (~TC_ACT_EXT_VAL_MASK)) == opcode) (((combined) & (~TC_ACT_EXT_VAL_MASK)) == opcode)
#define TC_ACT_JUMP __TC_ACT_EXT(1) #define TC_ACT_JUMP __TC_ACT_EXT(1)
#define TC_ACT_GOTO_CHAIN __TC_ACT_EXT(2)
/* Action type identifiers*/ /* Action type identifiers*/
enum { enum {
......
...@@ -28,6 +28,31 @@ ...@@ -28,6 +28,31 @@
#include <net/act_api.h> #include <net/act_api.h>
#include <net/netlink.h> #include <net/netlink.h>
static int tcf_action_goto_chain_init(struct tc_action *a, struct tcf_proto *tp)
{
u32 chain_index = a->tcfa_action & TC_ACT_EXT_VAL_MASK;
if (!tp)
return -EINVAL;
a->goto_chain = tcf_chain_get(tp->chain->block, chain_index);
if (!a->goto_chain)
return -ENOMEM;
return 0;
}
static void tcf_action_goto_chain_fini(struct tc_action *a)
{
tcf_chain_put(a->goto_chain);
}
static void tcf_action_goto_chain_exec(const struct tc_action *a,
struct tcf_result *res)
{
const struct tcf_chain *chain = a->goto_chain;
res->goto_tp = rcu_dereference_bh(chain->filter_chain);
}
static void free_tcf(struct rcu_head *head) static void free_tcf(struct rcu_head *head)
{ {
struct tc_action *p = container_of(head, struct tc_action, tcfa_rcu); struct tc_action *p = container_of(head, struct tc_action, tcfa_rcu);
...@@ -39,6 +64,8 @@ static void free_tcf(struct rcu_head *head) ...@@ -39,6 +64,8 @@ static void free_tcf(struct rcu_head *head)
kfree(p->act_cookie->data); kfree(p->act_cookie->data);
kfree(p->act_cookie); kfree(p->act_cookie);
} }
if (p->goto_chain)
tcf_action_goto_chain_fini(p);
kfree(p); kfree(p);
} }
...@@ -465,6 +492,8 @@ int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions, ...@@ -465,6 +492,8 @@ int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions,
else /* faulty graph, stop pipeline */ else /* faulty graph, stop pipeline */
return TC_ACT_OK; return TC_ACT_OK;
} }
} else if (TC_ACT_EXT_CMP(ret, TC_ACT_GOTO_CHAIN)) {
tcf_action_goto_chain_exec(a, res);
} }
if (ret != TC_ACT_PIPE) if (ret != TC_ACT_PIPE)
...@@ -657,6 +686,17 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, ...@@ -657,6 +686,17 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
if (err != ACT_P_CREATED) if (err != ACT_P_CREATED)
module_put(a_o->owner); module_put(a_o->owner);
if (TC_ACT_EXT_CMP(a->tcfa_action, TC_ACT_GOTO_CHAIN)) {
err = tcf_action_goto_chain_init(a, tp);
if (err) {
LIST_HEAD(actions);
list_add_tail(&a->list, &actions);
tcf_action_destroy(&actions, bind);
return ERR_PTR(err);
}
}
return a; return a;
err_mod: err_mod:
......
...@@ -307,8 +307,12 @@ int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp, ...@@ -307,8 +307,12 @@ int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
err = tp->classify(skb, tp, res); err = tp->classify(skb, tp, res);
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
if (unlikely(err == TC_ACT_RECLASSIFY && !compat_mode)) if (unlikely(err == TC_ACT_RECLASSIFY && !compat_mode)) {
goto reset; goto reset;
} else if (unlikely(TC_ACT_EXT_CMP(err, TC_ACT_GOTO_CHAIN))) {
old_tp = res->goto_tp;
goto reset;
}
#endif #endif
if (err >= 0) if (err >= 0)
return err; return err;
......
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