diff options
author | David S. Miller <davem@sunset.davemloft.net> | 2006-08-22 02:54:55 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-09-22 17:55:10 -0400 |
commit | e9ce1cd3cf6cf35b21d0ce990f2e738f35907386 (patch) | |
tree | 22a3ee7b78ae7cbf00520c66dcc389d87740069c /include/net/act_api.h | |
parent | 2e4ca75b31b6851dcc036c2cdebf3ecfe279a653 (diff) |
[PKT_SCHED]: Kill pkt_act.h inlining.
This was simply making templates of functions and mostly causing a lot
of code duplication in the classifier action modules.
We solve this more cleanly by having a common "struct tcf_common" that
hash worker functions contained once in act_api.c can work with.
Callers work with real action objects that have the common struct
plus their module specific struct members. You go from a common
object to the higher level one using a "to_foo()" macro which makes
use of container_of() to do the dirty work.
This also kills off act_generic.h which was only used by act_simple.c
and keeping it around was more work than the it's value.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/act_api.h')
-rw-r--r-- | include/net/act_api.h | 136 |
1 files changed, 88 insertions, 48 deletions
diff --git a/include/net/act_api.h b/include/net/act_api.h index 11e9eaf79f5a..8b06c2f3657f 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h | |||
@@ -8,70 +8,110 @@ | |||
8 | #include <net/sch_generic.h> | 8 | #include <net/sch_generic.h> |
9 | #include <net/pkt_sched.h> | 9 | #include <net/pkt_sched.h> |
10 | 10 | ||
11 | #define tca_gen(name) \ | 11 | struct tcf_common { |
12 | struct tcf_##name *next; \ | 12 | struct tcf_common *tcfc_next; |
13 | u32 index; \ | 13 | u32 tcfc_index; |
14 | int refcnt; \ | 14 | int tcfc_refcnt; |
15 | int bindcnt; \ | 15 | int tcfc_bindcnt; |
16 | u32 capab; \ | 16 | u32 tcfc_capab; |
17 | int action; \ | 17 | int tcfc_action; |
18 | struct tcf_t tm; \ | 18 | struct tcf_t tcfc_tm; |
19 | struct gnet_stats_basic bstats; \ | 19 | struct gnet_stats_basic tcfc_bstats; |
20 | struct gnet_stats_queue qstats; \ | 20 | struct gnet_stats_queue tcfc_qstats; |
21 | struct gnet_stats_rate_est rate_est; \ | 21 | struct gnet_stats_rate_est tcfc_rate_est; |
22 | spinlock_t *stats_lock; \ | 22 | spinlock_t *tcfc_stats_lock; |
23 | spinlock_t lock | 23 | spinlock_t tcfc_lock; |
24 | 24 | }; | |
25 | struct tcf_police | 25 | #define tcf_next common.tcfc_next |
26 | { | 26 | #define tcf_index common.tcfc_index |
27 | tca_gen(police); | 27 | #define tcf_refcnt common.tcfc_refcnt |
28 | int result; | 28 | #define tcf_bindcnt common.tcfc_bindcnt |
29 | u32 ewma_rate; | 29 | #define tcf_capab common.tcfc_capab |
30 | u32 burst; | 30 | #define tcf_action common.tcfc_action |
31 | u32 mtu; | 31 | #define tcf_tm common.tcfc_tm |
32 | u32 toks; | 32 | #define tcf_bstats common.tcfc_bstats |
33 | u32 ptoks; | 33 | #define tcf_qstats common.tcfc_qstats |
34 | psched_time_t t_c; | 34 | #define tcf_rate_est common.tcfc_rate_est |
35 | struct qdisc_rate_table *R_tab; | 35 | #define tcf_stats_lock common.tcfc_stats_lock |
36 | struct qdisc_rate_table *P_tab; | 36 | #define tcf_lock common.tcfc_lock |
37 | |||
38 | struct tcf_police { | ||
39 | struct tcf_common common; | ||
40 | int tcfp_result; | ||
41 | u32 tcfp_ewma_rate; | ||
42 | u32 tcfp_burst; | ||
43 | u32 tcfp_mtu; | ||
44 | u32 tcfp_toks; | ||
45 | u32 tcfp_ptoks; | ||
46 | psched_time_t tcfp_t_c; | ||
47 | struct qdisc_rate_table *tcfp_R_tab; | ||
48 | struct qdisc_rate_table *tcfp_P_tab; | ||
37 | }; | 49 | }; |
50 | #define to_police(pc) \ | ||
51 | container_of(pc, struct tcf_police, common) | ||
52 | |||
53 | struct tcf_hashinfo { | ||
54 | struct tcf_common **htab; | ||
55 | unsigned int hmask; | ||
56 | rwlock_t *lock; | ||
57 | }; | ||
58 | |||
59 | static inline unsigned int tcf_hash(u32 index, unsigned int hmask) | ||
60 | { | ||
61 | return index & hmask; | ||
62 | } | ||
38 | 63 | ||
39 | #ifdef CONFIG_NET_CLS_ACT | 64 | #ifdef CONFIG_NET_CLS_ACT |
40 | 65 | ||
41 | #define ACT_P_CREATED 1 | 66 | #define ACT_P_CREATED 1 |
42 | #define ACT_P_DELETED 1 | 67 | #define ACT_P_DELETED 1 |
43 | 68 | ||
44 | struct tcf_act_hdr | 69 | struct tcf_act_hdr { |
45 | { | 70 | struct tcf_common common; |
46 | tca_gen(act_hdr); | ||
47 | }; | 71 | }; |
48 | 72 | ||
49 | struct tc_action | 73 | struct tc_action { |
50 | { | 74 | void *priv; |
51 | void *priv; | 75 | struct tc_action_ops *ops; |
52 | struct tc_action_ops *ops; | 76 | __u32 type; /* for backward compat(TCA_OLD_COMPAT) */ |
53 | __u32 type; /* for backward compat(TCA_OLD_COMPAT) */ | 77 | __u32 order; |
54 | __u32 order; | 78 | struct tc_action *next; |
55 | struct tc_action *next; | ||
56 | }; | 79 | }; |
57 | 80 | ||
58 | #define TCA_CAP_NONE 0 | 81 | #define TCA_CAP_NONE 0 |
59 | struct tc_action_ops | 82 | struct tc_action_ops { |
60 | { | ||
61 | struct tc_action_ops *next; | 83 | struct tc_action_ops *next; |
84 | struct tcf_hashinfo *hinfo; | ||
62 | char kind[IFNAMSIZ]; | 85 | char kind[IFNAMSIZ]; |
63 | __u32 type; /* TBD to match kind */ | 86 | __u32 type; /* TBD to match kind */ |
64 | __u32 capab; /* capabilities includes 4 bit version */ | 87 | __u32 capab; /* capabilities includes 4 bit version */ |
65 | struct module *owner; | 88 | struct module *owner; |
66 | int (*act)(struct sk_buff *, struct tc_action *, struct tcf_result *); | 89 | int (*act)(struct sk_buff *, struct tc_action *, struct tcf_result *); |
67 | int (*get_stats)(struct sk_buff *, struct tc_action *); | 90 | int (*get_stats)(struct sk_buff *, struct tc_action *); |
68 | int (*dump)(struct sk_buff *, struct tc_action *,int , int); | 91 | int (*dump)(struct sk_buff *, struct tc_action *, int, int); |
69 | int (*cleanup)(struct tc_action *, int bind); | 92 | int (*cleanup)(struct tc_action *, int bind); |
70 | int (*lookup)(struct tc_action *, u32 ); | 93 | int (*lookup)(struct tc_action *, u32); |
71 | int (*init)(struct rtattr *,struct rtattr *,struct tc_action *, int , int ); | 94 | int (*init)(struct rtattr *, struct rtattr *, struct tc_action *, int , int); |
72 | int (*walk)(struct sk_buff *, struct netlink_callback *, int , struct tc_action *); | 95 | int (*walk)(struct sk_buff *, struct netlink_callback *, int, struct tc_action *); |
73 | }; | 96 | }; |
74 | 97 | ||
98 | extern struct tcf_common *tcf_hash_lookup(u32 index, | ||
99 | struct tcf_hashinfo *hinfo); | ||
100 | extern void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo); | ||
101 | extern int tcf_hash_release(struct tcf_common *p, int bind, | ||
102 | struct tcf_hashinfo *hinfo); | ||
103 | extern int tcf_generic_walker(struct sk_buff *skb, struct netlink_callback *cb, | ||
104 | int type, struct tc_action *a); | ||
105 | extern u32 tcf_hash_new_index(u32 *idx_gen, struct tcf_hashinfo *hinfo); | ||
106 | extern int tcf_hash_search(struct tc_action *a, u32 index); | ||
107 | extern struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a, | ||
108 | int bind, struct tcf_hashinfo *hinfo); | ||
109 | extern struct tcf_common *tcf_hash_create(u32 index, struct rtattr *est, | ||
110 | struct tc_action *a, int size, | ||
111 | int bind, u32 *idx_gen, | ||
112 | struct tcf_hashinfo *hinfo); | ||
113 | extern void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo); | ||
114 | |||
75 | extern int tcf_register_action(struct tc_action_ops *a); | 115 | extern int tcf_register_action(struct tc_action_ops *a); |
76 | extern int tcf_unregister_action(struct tc_action_ops *a); | 116 | extern int tcf_unregister_action(struct tc_action_ops *a); |
77 | extern void tcf_action_destroy(struct tc_action *a, int bind); | 117 | extern void tcf_action_destroy(struct tc_action *a, int bind); |
@@ -96,17 +136,17 @@ tcf_police_release(struct tcf_police *p, int bind) | |||
96 | int ret = 0; | 136 | int ret = 0; |
97 | #ifdef CONFIG_NET_CLS_ACT | 137 | #ifdef CONFIG_NET_CLS_ACT |
98 | if (p) { | 138 | if (p) { |
99 | if (bind) { | 139 | if (bind) |
100 | p->bindcnt--; | 140 | p->tcf_bindcnt--; |
101 | } | 141 | |
102 | p->refcnt--; | 142 | p->tcf_refcnt--; |
103 | if (p->refcnt <= 0 && !p->bindcnt) { | 143 | if (p->tcf_refcnt <= 0 && !p->tcf_bindcnt) { |
104 | tcf_police_destroy(p); | 144 | tcf_police_destroy(p); |
105 | ret = 1; | 145 | ret = 1; |
106 | } | 146 | } |
107 | } | 147 | } |
108 | #else | 148 | #else |
109 | if (p && --p->refcnt == 0) | 149 | if (p && --p->tcf_refcnt == 0) |
110 | tcf_police_destroy(p); | 150 | tcf_police_destroy(p); |
111 | 151 | ||
112 | #endif /* CONFIG_NET_CLS_ACT */ | 152 | #endif /* CONFIG_NET_CLS_ACT */ |