Skip to content

Commit ddf97cc

Browse files
congwangdavem330
authored andcommitted
net_sched: add network namespace support for tc actions
Currently tc actions are stored in a per-module hashtable, therefore are visible to all network namespaces. This is probably the last part of the tc subsystem which is not aware of netns now. This patch makes them per-netns, several tc action API's need to be adjusted for this. The tc action API code is ugly due to historical reasons, we need to refactor that code in the future. Cc: Jamal Hadi Salim <[email protected]> Signed-off-by: Cong Wang <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1d4150c commit ddf97cc

14 files changed

+746
-149
lines changed

include/net/act_api.h

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include <net/sch_generic.h>
99
#include <net/pkt_sched.h>
10+
#include <net/net_namespace.h>
11+
#include <net/netns/generic.h>
1012

1113
struct tcf_common {
1214
struct hlist_node tcfc_head;
@@ -87,31 +89,65 @@ struct tc_action {
8789
__u32 type; /* for backward compat(TCA_OLD_COMPAT) */
8890
__u32 order;
8991
struct list_head list;
92+
struct tcf_hashinfo *hinfo;
9093
};
9194

9295
struct tc_action_ops {
9396
struct list_head head;
94-
struct tcf_hashinfo *hinfo;
9597
char kind[IFNAMSIZ];
9698
__u32 type; /* TBD to match kind */
9799
struct module *owner;
98100
int (*act)(struct sk_buff *, const struct tc_action *, struct tcf_result *);
99101
int (*dump)(struct sk_buff *, struct tc_action *, int, int);
100102
void (*cleanup)(struct tc_action *, int bind);
101-
int (*lookup)(struct tc_action *, u32);
103+
int (*lookup)(struct net *, struct tc_action *, u32);
102104
int (*init)(struct net *net, struct nlattr *nla,
103105
struct nlattr *est, struct tc_action *act, int ovr,
104106
int bind);
105-
int (*walk)(struct sk_buff *, struct netlink_callback *, int, struct tc_action *);
107+
int (*walk)(struct net *, struct sk_buff *,
108+
struct netlink_callback *, int, struct tc_action *);
109+
};
110+
111+
struct tc_action_net {
112+
struct tcf_hashinfo *hinfo;
113+
const struct tc_action_ops *ops;
106114
};
107115

108-
int tcf_hash_search(struct tc_action *a, u32 index);
109-
u32 tcf_hash_new_index(struct tcf_hashinfo *hinfo);
110-
int tcf_hash_check(u32 index, struct tc_action *a, int bind);
111-
int tcf_hash_create(u32 index, struct nlattr *est, struct tc_action *a,
112-
int size, int bind, bool cpustats);
116+
static inline
117+
int tc_action_net_init(struct tc_action_net *tn, const struct tc_action_ops *ops,
118+
unsigned int mask)
119+
{
120+
int err = 0;
121+
122+
tn->hinfo = kmalloc(sizeof(*tn->hinfo), GFP_KERNEL);
123+
if (!tn->hinfo)
124+
return -ENOMEM;
125+
tn->ops = ops;
126+
err = tcf_hashinfo_init(tn->hinfo, mask);
127+
if (err)
128+
kfree(tn->hinfo);
129+
return err;
130+
}
131+
132+
void tcf_hashinfo_destroy(const struct tc_action_ops *ops,
133+
struct tcf_hashinfo *hinfo);
134+
135+
static inline void tc_action_net_exit(struct tc_action_net *tn)
136+
{
137+
tcf_hashinfo_destroy(tn->ops, tn->hinfo);
138+
}
139+
140+
int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
141+
struct netlink_callback *cb, int type,
142+
struct tc_action *a);
143+
int tcf_hash_search(struct tc_action_net *tn, struct tc_action *a, u32 index);
144+
u32 tcf_hash_new_index(struct tc_action_net *tn);
145+
int tcf_hash_check(struct tc_action_net *tn, u32 index, struct tc_action *a,
146+
int bind);
147+
int tcf_hash_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
148+
struct tc_action *a, int size, int bind, bool cpustats);
113149
void tcf_hash_cleanup(struct tc_action *a, struct nlattr *est);
114-
void tcf_hash_insert(struct tc_action *a);
150+
void tcf_hash_insert(struct tc_action_net *tn, struct tc_action *a);
115151

116152
int __tcf_hash_release(struct tc_action *a, bool bind, bool strict);
117153

@@ -120,8 +156,8 @@ static inline int tcf_hash_release(struct tc_action *a, bool bind)
120156
return __tcf_hash_release(a, bind, false);
121157
}
122158

123-
int tcf_register_action(struct tc_action_ops *a, unsigned int mask);
124-
int tcf_unregister_action(struct tc_action_ops *a);
159+
int tcf_register_action(struct tc_action_ops *a, struct pernet_operations *ops);
160+
int tcf_unregister_action(struct tc_action_ops *a, struct pernet_operations *ops);
125161
int tcf_action_destroy(struct list_head *actions, int bind);
126162
int tcf_action_exec(struct sk_buff *skb, const struct list_head *actions,
127163
struct tcf_result *res);

0 commit comments

Comments
 (0)