Commit acd0a7ab authored by Zhengchao Shao's avatar Zhengchao Shao Committed by David S. Miller
Browse files

net: sched: act: move global static variable net_id to tc_action_ops



Each tc action module has a corresponding net_id, so put net_id directly
into the structure tc_action_ops.

Signed-off-by: default avatarZhengchao Shao <shaozhengchao@huawei.com>
Acked-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dd14043a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ struct tc_action_ops {
	struct list_head head;
	char    kind[IFNAMSIZ];
	enum tca_id  id; /* identifier should match kind */
	unsigned int	net_id;
	size_t	size;
	struct module		*owner;
	int     (*act)(struct sk_buff *, const struct tc_action *,
+6 −7
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ struct tcf_bpf_cfg {
	bool is_ebpf;
};

static unsigned int bpf_net_id;
static struct tc_action_ops act_bpf_ops;

static int tcf_bpf_act(struct sk_buff *skb, const struct tc_action *act,
@@ -280,7 +279,7 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla,
			struct tcf_proto *tp, u32 flags,
			struct netlink_ext_ack *extack)
{
	struct tc_action_net *tn = net_generic(net, bpf_net_id);
	struct tc_action_net *tn = net_generic(net, act_bpf_ops.net_id);
	bool bind = flags & TCA_ACT_FLAGS_BIND;
	struct nlattr *tb[TCA_ACT_BPF_MAX + 1];
	struct tcf_chain *goto_ch = NULL;
@@ -395,14 +394,14 @@ static int tcf_bpf_walker(struct net *net, struct sk_buff *skb,
			  const struct tc_action_ops *ops,
			  struct netlink_ext_ack *extack)
{
	struct tc_action_net *tn = net_generic(net, bpf_net_id);
	struct tc_action_net *tn = net_generic(net, act_bpf_ops.net_id);

	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
}

static int tcf_bpf_search(struct net *net, struct tc_action **a, u32 index)
{
	struct tc_action_net *tn = net_generic(net, bpf_net_id);
	struct tc_action_net *tn = net_generic(net, act_bpf_ops.net_id);

	return tcf_idr_search(tn, a, index);
}
@@ -422,20 +421,20 @@ static struct tc_action_ops act_bpf_ops __read_mostly = {

static __net_init int bpf_init_net(struct net *net)
{
	struct tc_action_net *tn = net_generic(net, bpf_net_id);
	struct tc_action_net *tn = net_generic(net, act_bpf_ops.net_id);

	return tc_action_net_init(net, tn, &act_bpf_ops);
}

static void __net_exit bpf_exit_net(struct list_head *net_list)
{
	tc_action_net_exit(net_list, bpf_net_id);
	tc_action_net_exit(net_list, act_bpf_ops.net_id);
}

static struct pernet_operations bpf_net_ops = {
	.init = bpf_init_net,
	.exit_batch = bpf_exit_net,
	.id   = &bpf_net_id,
	.id   = &act_bpf_ops.net_id,
	.size = sizeof(struct tc_action_net),
};

+6 −7
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@
#include <net/netfilter/nf_conntrack_core.h>
#include <net/netfilter/nf_conntrack_zones.h>

static unsigned int connmark_net_id;
static struct tc_action_ops act_connmark_ops;

static int tcf_connmark_act(struct sk_buff *skb, const struct tc_action *a,
@@ -99,7 +98,7 @@ static int tcf_connmark_init(struct net *net, struct nlattr *nla,
			     struct tcf_proto *tp, u32 flags,
			     struct netlink_ext_ack *extack)
{
	struct tc_action_net *tn = net_generic(net, connmark_net_id);
	struct tc_action_net *tn = net_generic(net, act_connmark_ops.net_id);
	struct nlattr *tb[TCA_CONNMARK_MAX + 1];
	bool bind = flags & TCA_ACT_FLAGS_BIND;
	struct tcf_chain *goto_ch = NULL;
@@ -205,14 +204,14 @@ static int tcf_connmark_walker(struct net *net, struct sk_buff *skb,
			       const struct tc_action_ops *ops,
			       struct netlink_ext_ack *extack)
{
	struct tc_action_net *tn = net_generic(net, connmark_net_id);
	struct tc_action_net *tn = net_generic(net, act_connmark_ops.net_id);

	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
}

static int tcf_connmark_search(struct net *net, struct tc_action **a, u32 index)
{
	struct tc_action_net *tn = net_generic(net, connmark_net_id);
	struct tc_action_net *tn = net_generic(net, act_connmark_ops.net_id);

	return tcf_idr_search(tn, a, index);
}
@@ -231,20 +230,20 @@ static struct tc_action_ops act_connmark_ops = {

static __net_init int connmark_init_net(struct net *net)
{
	struct tc_action_net *tn = net_generic(net, connmark_net_id);
	struct tc_action_net *tn = net_generic(net, act_connmark_ops.net_id);

	return tc_action_net_init(net, tn, &act_connmark_ops);
}

static void __net_exit connmark_exit_net(struct list_head *net_list)
{
	tc_action_net_exit(net_list, connmark_net_id);
	tc_action_net_exit(net_list, act_connmark_ops.net_id);
}

static struct pernet_operations connmark_net_ops = {
	.init = connmark_init_net,
	.exit_batch = connmark_exit_net,
	.id   = &connmark_net_id,
	.id   = &act_connmark_ops.net_id,
	.size = sizeof(struct tc_action_net),
};

+6 −7
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = {
	[TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), },
};

static unsigned int csum_net_id;
static struct tc_action_ops act_csum_ops;

static int tcf_csum_init(struct net *net, struct nlattr *nla,
@@ -45,7 +44,7 @@ static int tcf_csum_init(struct net *net, struct nlattr *nla,
			 struct tcf_proto *tp,
			 u32 flags, struct netlink_ext_ack *extack)
{
	struct tc_action_net *tn = net_generic(net, csum_net_id);
	struct tc_action_net *tn = net_generic(net, act_csum_ops.net_id);
	bool bind = flags & TCA_ACT_FLAGS_BIND;
	struct tcf_csum_params *params_new;
	struct nlattr *tb[TCA_CSUM_MAX + 1];
@@ -678,14 +677,14 @@ static int tcf_csum_walker(struct net *net, struct sk_buff *skb,
			   const struct tc_action_ops *ops,
			   struct netlink_ext_ack *extack)
{
	struct tc_action_net *tn = net_generic(net, csum_net_id);
	struct tc_action_net *tn = net_generic(net, act_csum_ops.net_id);

	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
}

static int tcf_csum_search(struct net *net, struct tc_action **a, u32 index)
{
	struct tc_action_net *tn = net_generic(net, csum_net_id);
	struct tc_action_net *tn = net_generic(net, act_csum_ops.net_id);

	return tcf_idr_search(tn, a, index);
}
@@ -731,20 +730,20 @@ static struct tc_action_ops act_csum_ops = {

static __net_init int csum_init_net(struct net *net)
{
	struct tc_action_net *tn = net_generic(net, csum_net_id);
	struct tc_action_net *tn = net_generic(net, act_csum_ops.net_id);

	return tc_action_net_init(net, tn, &act_csum_ops);
}

static void __net_exit csum_exit_net(struct list_head *net_list)
{
	tc_action_net_exit(net_list, csum_net_id);
	tc_action_net_exit(net_list, act_csum_ops.net_id);
}

static struct pernet_operations csum_net_ops = {
	.init = csum_init_net,
	.exit_batch = csum_exit_net,
	.id   = &csum_net_id,
	.id   = &act_csum_ops.net_id,
	.size = sizeof(struct tc_action_net),
};

+8 −9
Original line number Diff line number Diff line
@@ -649,7 +649,6 @@ static void tcf_ct_flow_tables_uninit(void)
}

static struct tc_action_ops act_ct_ops;
static unsigned int ct_net_id;

struct tc_ct_action_net {
	struct tc_action_net tn; /* Must be first */
@@ -1255,7 +1254,7 @@ static int tcf_ct_fill_params(struct net *net,
			      struct nlattr **tb,
			      struct netlink_ext_ack *extack)
{
	struct tc_ct_action_net *tn = net_generic(net, ct_net_id);
	struct tc_ct_action_net *tn = net_generic(net, act_ct_ops.net_id);
	struct nf_conntrack_zone zone;
	struct nf_conn *tmpl;
	int err;
@@ -1330,7 +1329,7 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
		       struct tcf_proto *tp, u32 flags,
		       struct netlink_ext_ack *extack)
{
	struct tc_action_net *tn = net_generic(net, ct_net_id);
	struct tc_action_net *tn = net_generic(net, act_ct_ops.net_id);
	bool bind = flags & TCA_ACT_FLAGS_BIND;
	struct tcf_ct_params *params = NULL;
	struct nlattr *tb[TCA_CT_MAX + 1];
@@ -1563,14 +1562,14 @@ static int tcf_ct_walker(struct net *net, struct sk_buff *skb,
			 const struct tc_action_ops *ops,
			 struct netlink_ext_ack *extack)
{
	struct tc_action_net *tn = net_generic(net, ct_net_id);
	struct tc_action_net *tn = net_generic(net, act_ct_ops.net_id);

	return tcf_generic_walker(tn, skb, cb, type, ops, extack);
}

static int tcf_ct_search(struct net *net, struct tc_action **a, u32 index)
{
	struct tc_action_net *tn = net_generic(net, ct_net_id);
	struct tc_action_net *tn = net_generic(net, act_ct_ops.net_id);

	return tcf_idr_search(tn, a, index);
}
@@ -1623,7 +1622,7 @@ static struct tc_action_ops act_ct_ops = {
static __net_init int ct_init_net(struct net *net)
{
	unsigned int n_bits = sizeof_field(struct tcf_ct_params, labels) * 8;
	struct tc_ct_action_net *tn = net_generic(net, ct_net_id);
	struct tc_ct_action_net *tn = net_generic(net, act_ct_ops.net_id);

	if (nf_connlabels_get(net, n_bits - 1)) {
		tn->labels = false;
@@ -1641,20 +1640,20 @@ static void __net_exit ct_exit_net(struct list_head *net_list)

	rtnl_lock();
	list_for_each_entry(net, net_list, exit_list) {
		struct tc_ct_action_net *tn = net_generic(net, ct_net_id);
		struct tc_ct_action_net *tn = net_generic(net, act_ct_ops.net_id);

		if (tn->labels)
			nf_connlabels_put(net);
	}
	rtnl_unlock();

	tc_action_net_exit(net_list, ct_net_id);
	tc_action_net_exit(net_list, act_ct_ops.net_id);
}

static struct pernet_operations ct_net_ops = {
	.init = ct_init_net,
	.exit_batch = ct_exit_net,
	.id   = &ct_net_id,
	.id   = &act_ct_ops.net_id,
	.size = sizeof(struct tc_ct_action_net),
};

Loading