Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5da57f42 authored by WANG Cong's avatar WANG Cong Committed by David S. Miller
Browse files

net_sched: cls: refactor out struct tcf_ext_map



These information can be saved in tcf_exts, and this will
simplify the code.

Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 33be6271
Loading
Loading
Loading
Loading
+10 −13
Original line number Original line Diff line number Diff line
@@ -65,21 +65,21 @@ struct tcf_exts {
	__u32	type; /* for backward compat(TCA_OLD_COMPAT) */
	__u32	type; /* for backward compat(TCA_OLD_COMPAT) */
	struct list_head actions;
	struct list_head actions;
#endif
#endif
};

	/* Map to export classifier specific extension TLV types to the
	/* Map to export classifier specific extension TLV types to the
	 * generic extensions API. Unsupported extensions must be set to 0.
	 * generic extensions API. Unsupported extensions must be set to 0.
	 */
	 */
struct tcf_ext_map {
	int action;
	int action;
	int police;
	int police;
};
};


static inline void tcf_exts_init(struct tcf_exts *exts)
static inline void tcf_exts_init(struct tcf_exts *exts, int action, int police)
{
{
#ifdef CONFIG_NET_CLS_ACT
#ifdef CONFIG_NET_CLS_ACT
	exts->type = 0;
	INIT_LIST_HEAD(&exts->actions);
	INIT_LIST_HEAD(&exts->actions);
#endif
#endif
	exts->action = action;
	exts->police = police;
}
}


/**
/**
@@ -136,15 +136,12 @@ tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts,


int tcf_exts_validate(struct net *net, struct tcf_proto *tp,
int tcf_exts_validate(struct net *net, struct tcf_proto *tp,
		      struct nlattr **tb, struct nlattr *rate_tlv,
		      struct nlattr **tb, struct nlattr *rate_tlv,
		      struct tcf_exts *exts,
		      struct tcf_exts *exts);
		      const struct tcf_ext_map *map);
void tcf_exts_destroy(struct tcf_proto *tp, struct tcf_exts *exts);
void tcf_exts_destroy(struct tcf_proto *tp, struct tcf_exts *exts);
void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
		     struct tcf_exts *src);
		     struct tcf_exts *src);
int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts,
int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts);
		  const struct tcf_ext_map *map);
int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts);
int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts,
			const struct tcf_ext_map *map);


/**
/**
 * struct tcf_pkt_info - packet information
 * struct tcf_pkt_info - packet information
+13 −18
Original line number Original line Diff line number Diff line
@@ -507,18 +507,15 @@ void tcf_exts_destroy(struct tcf_proto *tp, struct tcf_exts *exts)
EXPORT_SYMBOL(tcf_exts_destroy);
EXPORT_SYMBOL(tcf_exts_destroy);


int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
		  struct nlattr *rate_tlv, struct tcf_exts *exts,
		  struct nlattr *rate_tlv, struct tcf_exts *exts)
		  const struct tcf_ext_map *map)
{
{
	memset(exts, 0, sizeof(*exts));

#ifdef CONFIG_NET_CLS_ACT
#ifdef CONFIG_NET_CLS_ACT
	{
	{
		struct tc_action *act;
		struct tc_action *act;


		INIT_LIST_HEAD(&exts->actions);
		INIT_LIST_HEAD(&exts->actions);
		if (map->police && tb[map->police]) {
		if (exts->police && tb[exts->police]) {
			act = tcf_action_init_1(net, tb[map->police], rate_tlv,
			act = tcf_action_init_1(net, tb[exts->police], rate_tlv,
						"police", TCA_ACT_NOREPLACE,
						"police", TCA_ACT_NOREPLACE,
						TCA_ACT_BIND);
						TCA_ACT_BIND);
			if (IS_ERR(act))
			if (IS_ERR(act))
@@ -526,9 +523,9 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,


			act->type = exts->type = TCA_OLD_COMPAT;
			act->type = exts->type = TCA_OLD_COMPAT;
			list_add(&act->list, &exts->actions);
			list_add(&act->list, &exts->actions);
		} else if (map->action && tb[map->action]) {
		} else if (exts->action && tb[exts->action]) {
			int err;
			int err;
			err = tcf_action_init(net, tb[map->action], rate_tlv,
			err = tcf_action_init(net, tb[exts->action], rate_tlv,
					      NULL, TCA_ACT_NOREPLACE,
					      NULL, TCA_ACT_NOREPLACE,
					      TCA_ACT_BIND, &exts->actions);
					      TCA_ACT_BIND, &exts->actions);
			if (err)
			if (err)
@@ -536,8 +533,8 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
		}
		}
	}
	}
#else
#else
	if ((map->action && tb[map->action]) ||
	if ((exts->action && tb[exts->action]) ||
	    (map->police && tb[map->police]))
	    (exts->police && tb[exts->police]))
		return -EOPNOTSUPP;
		return -EOPNOTSUPP;
#endif
#endif


@@ -564,11 +561,10 @@ EXPORT_SYMBOL(tcf_exts_change);
#define tcf_exts_first_act(ext) \
#define tcf_exts_first_act(ext) \
		list_first_entry(&(exts)->actions, struct tc_action, list)
		list_first_entry(&(exts)->actions, struct tc_action, list)


int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts,
int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
		  const struct tcf_ext_map *map)
{
{
#ifdef CONFIG_NET_CLS_ACT
#ifdef CONFIG_NET_CLS_ACT
	if (map->action && !list_empty(&exts->actions)) {
	if (exts->action && !list_empty(&exts->actions)) {
		/*
		/*
		 * again for backward compatible mode - we want
		 * again for backward compatible mode - we want
		 * to work with both old and new modes of entering
		 * to work with both old and new modes of entering
@@ -576,15 +572,15 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts,
		 */
		 */
		struct nlattr *nest;
		struct nlattr *nest;
		if (exts->type != TCA_OLD_COMPAT) {
		if (exts->type != TCA_OLD_COMPAT) {
			nest = nla_nest_start(skb, map->action);
			nest = nla_nest_start(skb, exts->action);
			if (nest == NULL)
			if (nest == NULL)
				goto nla_put_failure;
				goto nla_put_failure;
			if (tcf_action_dump(skb, &exts->actions, 0, 0) < 0)
			if (tcf_action_dump(skb, &exts->actions, 0, 0) < 0)
				goto nla_put_failure;
				goto nla_put_failure;
			nla_nest_end(skb, nest);
			nla_nest_end(skb, nest);
		} else if (map->police) {
		} else if (exts->police) {
			struct tc_action *act = tcf_exts_first_act(exts);
			struct tc_action *act = tcf_exts_first_act(exts);
			nest = nla_nest_start(skb, map->police);
			nest = nla_nest_start(skb, exts->police);
			if (nest == NULL)
			if (nest == NULL)
				goto nla_put_failure;
				goto nla_put_failure;
			if (tcf_action_dump_old(skb, act, 0, 0) < 0)
			if (tcf_action_dump_old(skb, act, 0, 0) < 0)
@@ -600,8 +596,7 @@ nla_put_failure: __attribute__ ((unused))
EXPORT_SYMBOL(tcf_exts_dump);
EXPORT_SYMBOL(tcf_exts_dump);




int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts,
int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts)
			const struct tcf_ext_map *map)
{
{
#ifdef CONFIG_NET_CLS_ACT
#ifdef CONFIG_NET_CLS_ACT
	struct tc_action *a = tcf_exts_first_act(exts);
	struct tc_action *a = tcf_exts_first_act(exts);
+5 −9
Original line number Original line Diff line number Diff line
@@ -34,11 +34,6 @@ struct basic_filter {
	struct list_head	link;
	struct list_head	link;
};
};


static const struct tcf_ext_map basic_ext_map = {
	.action = TCA_BASIC_ACT,
	.police = TCA_BASIC_POLICE
};

static int basic_classify(struct sk_buff *skb, const struct tcf_proto *tp,
static int basic_classify(struct sk_buff *skb, const struct tcf_proto *tp,
			  struct tcf_result *res)
			  struct tcf_result *res)
{
{
@@ -141,7 +136,8 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp,
	struct tcf_exts e;
	struct tcf_exts e;
	struct tcf_ematch_tree t;
	struct tcf_ematch_tree t;


	err = tcf_exts_validate(net, tp, tb, est, &e, &basic_ext_map);
	tcf_exts_init(&e, TCA_BASIC_ACT, TCA_BASIC_POLICE);
	err = tcf_exts_validate(net, tp, tb, est, &e);
	if (err < 0)
	if (err < 0)
		return err;
		return err;


@@ -191,7 +187,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,
	if (f == NULL)
	if (f == NULL)
		goto errout;
		goto errout;


	tcf_exts_init(&f->exts);
	tcf_exts_init(&f->exts, TCA_BASIC_ACT, TCA_BASIC_POLICE);
	err = -EINVAL;
	err = -EINVAL;
	if (handle)
	if (handle)
		f->handle = handle;
		f->handle = handle;
@@ -264,13 +260,13 @@ static int basic_dump(struct tcf_proto *tp, unsigned long fh,
	    nla_put_u32(skb, TCA_BASIC_CLASSID, f->res.classid))
	    nla_put_u32(skb, TCA_BASIC_CLASSID, f->res.classid))
		goto nla_put_failure;
		goto nla_put_failure;


	if (tcf_exts_dump(skb, &f->exts, &basic_ext_map) < 0 ||
	if (tcf_exts_dump(skb, &f->exts) < 0 ||
	    tcf_em_tree_dump(skb, &f->ematches, TCA_BASIC_EMATCHES) < 0)
	    tcf_em_tree_dump(skb, &f->ematches, TCA_BASIC_EMATCHES) < 0)
		goto nla_put_failure;
		goto nla_put_failure;


	nla_nest_end(skb, nest);
	nla_nest_end(skb, nest);


	if (tcf_exts_dump_stats(skb, &f->exts, &basic_ext_map) < 0)
	if (tcf_exts_dump_stats(skb, &f->exts) < 0)
		goto nla_put_failure;
		goto nla_put_failure;


	return skb->len;
	return skb->len;
+5 −9
Original line number Original line Diff line number Diff line
@@ -46,11 +46,6 @@ static const struct nla_policy bpf_policy[TCA_BPF_MAX + 1] = {
				    .len = sizeof(struct sock_filter) * BPF_MAXINSNS },
				    .len = sizeof(struct sock_filter) * BPF_MAXINSNS },
};
};


static const struct tcf_ext_map bpf_ext_map = {
	.action = TCA_BPF_ACT,
	.police = TCA_BPF_POLICE,
};

static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
			    struct tcf_result *res)
			    struct tcf_result *res)
{
{
@@ -174,7 +169,8 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
	if (!tb[TCA_BPF_OPS_LEN] || !tb[TCA_BPF_OPS] || !tb[TCA_BPF_CLASSID])
	if (!tb[TCA_BPF_OPS_LEN] || !tb[TCA_BPF_OPS] || !tb[TCA_BPF_CLASSID])
		return -EINVAL;
		return -EINVAL;


	ret = tcf_exts_validate(net, tp, tb, est, &exts, &bpf_ext_map);
	tcf_exts_init(&exts, TCA_BPF_ACT, TCA_BPF_POLICE);
	ret = tcf_exts_validate(net, tp, tb, est, &exts);
	if (ret < 0)
	if (ret < 0)
		return ret;
		return ret;


@@ -271,7 +267,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
	if (prog == NULL)
	if (prog == NULL)
		return -ENOBUFS;
		return -ENOBUFS;


	tcf_exts_init(&prog->exts);
	tcf_exts_init(&prog->exts, TCA_BPF_ACT, TCA_BPF_POLICE);
	if (handle == 0)
	if (handle == 0)
		prog->handle = cls_bpf_grab_new_handle(tp, head);
		prog->handle = cls_bpf_grab_new_handle(tp, head);
	else
	else
@@ -326,12 +322,12 @@ static int cls_bpf_dump(struct tcf_proto *tp, unsigned long fh,


	memcpy(nla_data(nla), prog->bpf_ops, nla_len(nla));
	memcpy(nla_data(nla), prog->bpf_ops, nla_len(nla));


	if (tcf_exts_dump(skb, &prog->exts, &bpf_ext_map) < 0)
	if (tcf_exts_dump(skb, &prog->exts) < 0)
		goto nla_put_failure;
		goto nla_put_failure;


	nla_nest_end(skb, nest);
	nla_nest_end(skb, nest);


	if (tcf_exts_dump_stats(skb, &prog->exts, &bpf_ext_map) < 0)
	if (tcf_exts_dump_stats(skb, &prog->exts) < 0)
		goto nla_put_failure;
		goto nla_put_failure;


	return skb->len;
	return skb->len;
+5 −10
Original line number Original line Diff line number Diff line
@@ -172,11 +172,6 @@ static int cls_cgroup_init(struct tcf_proto *tp)
	return 0;
	return 0;
}
}


static const struct tcf_ext_map cgroup_ext_map = {
	.action = TCA_CGROUP_ACT,
	.police = TCA_CGROUP_POLICE,
};

static const struct nla_policy cgroup_policy[TCA_CGROUP_MAX + 1] = {
static const struct nla_policy cgroup_policy[TCA_CGROUP_MAX + 1] = {
	[TCA_CGROUP_EMATCHES]	= { .type = NLA_NESTED },
	[TCA_CGROUP_EMATCHES]	= { .type = NLA_NESTED },
};
};
@@ -203,7 +198,7 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
		if (head == NULL)
		if (head == NULL)
			return -ENOBUFS;
			return -ENOBUFS;


		tcf_exts_init(&head->exts);
		tcf_exts_init(&head->exts, TCA_CGROUP_ACT, TCA_CGROUP_POLICE);
		head->handle = handle;
		head->handle = handle;


		tcf_tree_lock(tp);
		tcf_tree_lock(tp);
@@ -219,8 +214,8 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
	if (err < 0)
	if (err < 0)
		return err;
		return err;


	err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e,
	tcf_exts_init(&e, TCA_CGROUP_ACT, TCA_CGROUP_POLICE);
				&cgroup_ext_map);
	err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e);
	if (err < 0)
	if (err < 0)
		return err;
		return err;


@@ -278,13 +273,13 @@ static int cls_cgroup_dump(struct tcf_proto *tp, unsigned long fh,
	if (nest == NULL)
	if (nest == NULL)
		goto nla_put_failure;
		goto nla_put_failure;


	if (tcf_exts_dump(skb, &head->exts, &cgroup_ext_map) < 0 ||
	if (tcf_exts_dump(skb, &head->exts) < 0 ||
	    tcf_em_tree_dump(skb, &head->ematches, TCA_CGROUP_EMATCHES) < 0)
	    tcf_em_tree_dump(skb, &head->ematches, TCA_CGROUP_EMATCHES) < 0)
		goto nla_put_failure;
		goto nla_put_failure;


	nla_nest_end(skb, nest);
	nla_nest_end(skb, nest);


	if (tcf_exts_dump_stats(skb, &head->exts, &cgroup_ext_map) < 0)
	if (tcf_exts_dump_stats(skb, &head->exts) < 0)
		goto nla_put_failure;
		goto nla_put_failure;


	return skb->len;
	return skb->len;
Loading