10
10
#include <net/net_namespace.h>
11
11
#include <net/netns/generic.h>
12
12
13
-
14
- struct tcf_hashinfo {
15
- struct hlist_head * htab ;
16
- unsigned int hmask ;
17
- spinlock_t lock ;
18
- u32 index ;
13
+ struct tcf_idrinfo {
14
+ spinlock_t lock ;
15
+ struct idr action_idr ;
19
16
};
20
17
21
18
struct tc_action_ops ;
@@ -25,9 +22,8 @@ struct tc_action {
25
22
__u32 type ; /* for backward compat(TCA_OLD_COMPAT) */
26
23
__u32 order ;
27
24
struct list_head list ;
28
- struct tcf_hashinfo * hinfo ;
25
+ struct tcf_idrinfo * idrinfo ;
29
26
30
- struct hlist_node tcfa_head ;
31
27
u32 tcfa_index ;
32
28
int tcfa_refcnt ;
33
29
int tcfa_bindcnt ;
@@ -44,7 +40,6 @@ struct tc_action {
44
40
struct tc_cookie * act_cookie ;
45
41
struct tcf_chain * goto_chain ;
46
42
};
47
- #define tcf_head common.tcfa_head
48
43
#define tcf_index common.tcfa_index
49
44
#define tcf_refcnt common.tcfa_refcnt
50
45
#define tcf_bindcnt common.tcfa_bindcnt
@@ -57,27 +52,6 @@ struct tc_action {
57
52
#define tcf_lock common.tcfa_lock
58
53
#define tcf_rcu common.tcfa_rcu
59
54
60
- static inline unsigned int tcf_hash (u32 index , unsigned int hmask )
61
- {
62
- return index & hmask ;
63
- }
64
-
65
- static inline int tcf_hashinfo_init (struct tcf_hashinfo * hf , unsigned int mask )
66
- {
67
- int i ;
68
-
69
- spin_lock_init (& hf -> lock );
70
- hf -> index = 0 ;
71
- hf -> hmask = mask ;
72
- hf -> htab = kzalloc ((mask + 1 ) * sizeof (struct hlist_head ),
73
- GFP_KERNEL );
74
- if (!hf -> htab )
75
- return - ENOMEM ;
76
- for (i = 0 ; i < mask + 1 ; i ++ )
77
- INIT_HLIST_HEAD (& hf -> htab [i ]);
78
- return 0 ;
79
- }
80
-
81
55
/* Update lastuse only if needed, to avoid dirtying a cache line.
82
56
* We use a temp variable to avoid fetching jiffies twice.
83
57
*/
@@ -126,53 +100,51 @@ struct tc_action_ops {
126
100
};
127
101
128
102
struct tc_action_net {
129
- struct tcf_hashinfo * hinfo ;
103
+ struct tcf_idrinfo * idrinfo ;
130
104
const struct tc_action_ops * ops ;
131
105
};
132
106
133
107
static inline
134
108
int tc_action_net_init (struct tc_action_net * tn ,
135
- const struct tc_action_ops * ops , unsigned int mask )
109
+ const struct tc_action_ops * ops )
136
110
{
137
111
int err = 0 ;
138
112
139
- tn -> hinfo = kmalloc (sizeof (* tn -> hinfo ), GFP_KERNEL );
140
- if (!tn -> hinfo )
113
+ tn -> idrinfo = kmalloc (sizeof (* tn -> idrinfo ), GFP_KERNEL );
114
+ if (!tn -> idrinfo )
141
115
return - ENOMEM ;
142
116
tn -> ops = ops ;
143
- err = tcf_hashinfo_init (tn -> hinfo , mask );
144
- if (err )
145
- kfree (tn -> hinfo );
117
+ spin_lock_init (& tn -> idrinfo -> lock );
118
+ idr_init (& tn -> idrinfo -> action_idr );
146
119
return err ;
147
120
}
148
121
149
- void tcf_hashinfo_destroy (const struct tc_action_ops * ops ,
150
- struct tcf_hashinfo * hinfo );
122
+ void tcf_idrinfo_destroy (const struct tc_action_ops * ops ,
123
+ struct tcf_idrinfo * idrinfo );
151
124
152
125
static inline void tc_action_net_exit (struct tc_action_net * tn )
153
126
{
154
- tcf_hashinfo_destroy (tn -> ops , tn -> hinfo );
155
- kfree (tn -> hinfo );
127
+ tcf_idrinfo_destroy (tn -> ops , tn -> idrinfo );
128
+ kfree (tn -> idrinfo );
156
129
}
157
130
158
131
int tcf_generic_walker (struct tc_action_net * tn , struct sk_buff * skb ,
159
132
struct netlink_callback * cb , int type ,
160
133
const struct tc_action_ops * ops );
161
- int tcf_hash_search (struct tc_action_net * tn , struct tc_action * * a , u32 index );
162
- u32 tcf_hash_new_index (struct tc_action_net * tn );
163
- bool tcf_hash_check (struct tc_action_net * tn , u32 index , struct tc_action * * a ,
134
+ int tcf_idr_search (struct tc_action_net * tn , struct tc_action * * a , u32 index );
135
+ bool tcf_idr_check (struct tc_action_net * tn , u32 index , struct tc_action * * a ,
164
136
int bind );
165
- int tcf_hash_create (struct tc_action_net * tn , u32 index , struct nlattr * est ,
166
- struct tc_action * * a , const struct tc_action_ops * ops , int bind ,
167
- bool cpustats );
168
- void tcf_hash_cleanup (struct tc_action * a , struct nlattr * est );
169
- void tcf_hash_insert (struct tc_action_net * tn , struct tc_action * a );
137
+ int tcf_idr_create (struct tc_action_net * tn , u32 index , struct nlattr * est ,
138
+ struct tc_action * * a , const struct tc_action_ops * ops ,
139
+ int bind , bool cpustats );
140
+ void tcf_idr_cleanup (struct tc_action * a , struct nlattr * est );
141
+ void tcf_idr_insert (struct tc_action_net * tn , struct tc_action * a );
170
142
171
- int __tcf_hash_release (struct tc_action * a , bool bind , bool strict );
143
+ int __tcf_idr_release (struct tc_action * a , bool bind , bool strict );
172
144
173
- static inline int tcf_hash_release (struct tc_action * a , bool bind )
145
+ static inline int tcf_idr_release (struct tc_action * a , bool bind )
174
146
{
175
- return __tcf_hash_release (a , bind , false);
147
+ return __tcf_idr_release (a , bind , false);
176
148
}
177
149
178
150
int tcf_register_action (struct tc_action_ops * a , struct pernet_operations * ops );
0 commit comments