Skip to content

Commit a85a970

Browse files
congwangdavem330
authored andcommitted
net_sched: move tc_action into tcf_common
struct tc_action is confusing, currently we use it for two purposes: 1) Pass in arguments and carry out results from helper functions 2) A generic representation for tc actions The first one is error-prone, since we need to make sure we don't miss anything. This patch aims to get rid of this use, by moving tc_action into tcf_common, so that they are allocated together in hashtable and can be cast'ed easily. And together with the following patch, we could really make tc_action a generic representation for all tc actions and each type of action can inherit from it. Cc: Jamal Hadi Salim <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b93dd49 commit a85a970

27 files changed

+298
-329
lines changed

include/net/act_api.h

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,26 @@
1010
#include <net/net_namespace.h>
1111
#include <net/netns/generic.h>
1212

13+
14+
struct tcf_hashinfo {
15+
struct hlist_head *htab;
16+
unsigned int hmask;
17+
spinlock_t lock;
18+
u32 index;
19+
};
20+
21+
struct tc_action_ops;
22+
23+
struct tc_action {
24+
const struct tc_action_ops *ops;
25+
__u32 type; /* for backward compat(TCA_OLD_COMPAT) */
26+
__u32 order;
27+
struct list_head list;
28+
struct tcf_hashinfo *hinfo;
29+
};
30+
1331
struct tcf_common {
32+
struct tc_action tcfc_act;
1433
struct hlist_node tcfc_head;
1534
u32 tcfc_index;
1635
int tcfc_refcnt;
@@ -26,6 +45,7 @@ struct tcf_common {
2645
struct gnet_stats_basic_cpu __percpu *cpu_bstats;
2746
struct gnet_stats_queue __percpu *cpu_qstats;
2847
};
48+
#define tcf_act common.tcfc_act
2949
#define tcf_head common.tcfc_head
3050
#define tcf_index common.tcfc_index
3151
#define tcf_refcnt common.tcfc_refcnt
@@ -39,13 +59,6 @@ struct tcf_common {
3959
#define tcf_lock common.tcfc_lock
4060
#define tcf_rcu common.tcfc_rcu
4161

42-
struct tcf_hashinfo {
43-
struct hlist_head *htab;
44-
unsigned int hmask;
45-
spinlock_t lock;
46-
u32 index;
47-
};
48-
4962
static inline unsigned int tcf_hash(u32 index, unsigned int hmask)
5063
{
5164
return index & hmask;
@@ -88,15 +101,6 @@ static inline void tcf_tm_dump(struct tcf_t *dtm, const struct tcf_t *stm)
88101
dtm->expires = jiffies_to_clock_t(stm->expires);
89102
}
90103

91-
struct tc_action {
92-
void *priv;
93-
const struct tc_action_ops *ops;
94-
__u32 type; /* for backward compat(TCA_OLD_COMPAT) */
95-
__u32 order;
96-
struct list_head list;
97-
struct tcf_hashinfo *hinfo;
98-
};
99-
100104
#ifdef CONFIG_NET_CLS_ACT
101105

102106
#define ACT_P_CREATED 1
@@ -106,17 +110,18 @@ struct tc_action_ops {
106110
struct list_head head;
107111
char kind[IFNAMSIZ];
108112
__u32 type; /* TBD to match kind */
113+
size_t size;
109114
struct module *owner;
110115
int (*act)(struct sk_buff *, const struct tc_action *,
111116
struct tcf_result *);
112117
int (*dump)(struct sk_buff *, struct tc_action *, int, int);
113118
void (*cleanup)(struct tc_action *, int bind);
114-
int (*lookup)(struct net *, struct tc_action *, u32);
119+
int (*lookup)(struct net *, struct tc_action **, u32);
115120
int (*init)(struct net *net, struct nlattr *nla,
116-
struct nlattr *est, struct tc_action *act, int ovr,
121+
struct nlattr *est, struct tc_action **act, int ovr,
117122
int bind);
118123
int (*walk)(struct net *, struct sk_buff *,
119-
struct netlink_callback *, int, struct tc_action *);
124+
struct netlink_callback *, int, const struct tc_action_ops *);
120125
void (*stats_update)(struct tc_action *, u64, u32, u64);
121126
};
122127

@@ -152,13 +157,14 @@ static inline void tc_action_net_exit(struct tc_action_net *tn)
152157

153158
int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
154159
struct netlink_callback *cb, int type,
155-
struct tc_action *a);
156-
int tcf_hash_search(struct tc_action_net *tn, struct tc_action *a, u32 index);
160+
const struct tc_action_ops *ops);
161+
int tcf_hash_search(struct tc_action_net *tn, struct tc_action **a, u32 index);
157162
u32 tcf_hash_new_index(struct tc_action_net *tn);
158-
bool tcf_hash_check(struct tc_action_net *tn, u32 index, struct tc_action *a,
163+
bool tcf_hash_check(struct tc_action_net *tn, u32 index, struct tc_action **a,
159164
int bind);
160165
int tcf_hash_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
161-
struct tc_action *a, int size, int bind, bool cpustats);
166+
struct tc_action **a, const struct tc_action_ops *ops, int bind,
167+
bool cpustats);
162168
void tcf_hash_cleanup(struct tc_action *a, struct nlattr *est);
163169
void tcf_hash_insert(struct tc_action_net *tn, struct tc_action *a);
164170

include/net/tc_act/tc_bpf.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ struct tcf_bpf {
2323
struct sock_filter *bpf_ops;
2424
const char *bpf_name;
2525
};
26-
#define to_bpf(a) \
27-
container_of(a->priv, struct tcf_bpf, common)
26+
#define to_bpf(a) ((struct tcf_bpf *)a)
2827

2928
#endif /* __NET_TC_BPF_H */

include/net/tc_act/tc_connmark.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ struct tcf_connmark_info {
99
u16 zone;
1010
};
1111

12-
#define to_connmark(a) \
13-
container_of(a->priv, struct tcf_connmark_info, common)
12+
#define to_connmark(a) ((struct tcf_connmark_info *)a)
1413

1514
#endif /* __NET_TC_CONNMARK_H */

include/net/tc_act/tc_csum.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ struct tcf_csum {
99

1010
u32 update_flags;
1111
};
12-
#define to_tcf_csum(a) \
13-
container_of(a->priv,struct tcf_csum,common)
12+
#define to_tcf_csum(a) ((struct tcf_csum *)a)
1413

1514
#endif /* __NET_TC_CSUM_H */

include/net/tc_act/tc_defact.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ struct tcf_defact {
88
u32 tcfd_datalen;
99
void *tcfd_defdata;
1010
};
11-
#define to_defact(a) \
12-
container_of(a->priv, struct tcf_defact, common)
11+
#define to_defact(a) ((struct tcf_defact *)a)
1312

1413
#endif /* __NET_TC_DEF_H */

include/net/tc_act/tc_gact.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ struct tcf_gact {
1313
atomic_t packets;
1414
#endif
1515
};
16-
#define to_gact(a) \
17-
container_of(a->priv, struct tcf_gact, common)
16+
#define to_gact(a) ((struct tcf_gact *)a)
1817

1918
static inline bool is_tcf_gact_shot(const struct tc_action *a)
2019
{
@@ -24,7 +23,7 @@ static inline bool is_tcf_gact_shot(const struct tc_action *a)
2423
if (a->ops && a->ops->type != TCA_ACT_GACT)
2524
return false;
2625

27-
gact = a->priv;
26+
gact = to_gact(a);
2827
if (gact->tcf_action == TC_ACT_SHOT)
2928
return true;
3029

include/net/tc_act/tc_ife.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ struct tcf_ife_info {
1616
/* list of metaids allowed */
1717
struct list_head metalist;
1818
};
19-
#define to_ife(a) \
20-
container_of(a->priv, struct tcf_ife_info, common)
19+
#define to_ife(a) ((struct tcf_ife_info *)a)
2120

2221
struct tcf_meta_info {
2322
const struct tcf_meta_ops *ops;

include/net/tc_act/tc_ipt.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ struct tcf_ipt {
1111
char *tcfi_tname;
1212
struct xt_entry_target *tcfi_t;
1313
};
14-
#define to_ipt(a) \
15-
container_of(a->priv, struct tcf_ipt, common)
14+
#define to_ipt(a) ((struct tcf_ipt *)a)
1615

1716
#endif /* __NET_TC_IPT_H */

include/net/tc_act/tc_mirred.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ struct tcf_mirred {
1212
struct net_device __rcu *tcfm_dev;
1313
struct list_head tcfm_list;
1414
};
15-
#define to_mirred(a) \
16-
container_of(a->priv, struct tcf_mirred, common)
15+
#define to_mirred(a) ((struct tcf_mirred *)a)
1716

1817
static inline bool is_tcf_mirred_redirect(const struct tc_action *a)
1918
{

include/net/tc_act/tc_nat.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ struct tcf_nat {
1313
u32 flags;
1414
};
1515

16-
static inline struct tcf_nat *to_tcf_nat(struct tc_action *a)
17-
{
18-
return container_of(a->priv, struct tcf_nat, common);
19-
}
16+
#define to_tcf_nat(a) ((struct tcf_nat *)a)
2017

2118
#endif /* __NET_TC_NAT_H */

include/net/tc_act/tc_pedit.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ struct tcf_pedit {
99
unsigned char tcfp_flags;
1010
struct tc_pedit_key *tcfp_keys;
1111
};
12-
#define to_pedit(a) \
13-
container_of(a->priv, struct tcf_pedit, common)
12+
#define to_pedit(a) ((struct tcf_pedit *)a)
1413

1514
#endif /* __NET_TC_PED_H */

include/net/tc_act/tc_skbedit.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ struct tcf_skbedit {
3030
u16 queue_mapping;
3131
u16 ptype;
3232
};
33-
#define to_skbedit(a) \
34-
container_of(a->priv, struct tcf_skbedit, common)
33+
#define to_skbedit(a) ((struct tcf_skbedit *)a)
3534

3635
/* Return true iff action is mark */
3736
static inline bool is_tcf_skbedit_mark(const struct tc_action *a)

include/net/tc_act/tc_vlan.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ struct tcf_vlan {
2121
u16 tcfv_push_vid;
2222
__be16 tcfv_push_proto;
2323
};
24-
#define to_vlan(a) \
25-
container_of(a->priv, struct tcf_vlan, common)
24+
#define to_vlan(a) ((struct tcf_vlan *)a)
2625

2726
#endif /* __NET_TC_VLAN_H */

0 commit comments

Comments
 (0)