3232#define mtype_gc IPSET_TOKEN(MTYPE, _gc)
3333#define mtype MTYPE
3434
35- #define ext_timeout (e , m ) \
36- (unsigned long *)((e) + (m)->offset[IPSET_EXT_ID_TIMEOUT])
37- #define ext_counter (e , m ) \
38- (struct ip_set_counter *)((e) + (m)->offset[IPSET_EXT_ID_COUNTER])
39- #define get_ext (map , id ) ((map)->extensions + (map)->dsize * (id))
35+ #define get_ext (set , map , id ) ((map)->extensions + (set)->dsize * (id))
4036
4137static void
4238mtype_gc_init (struct ip_set * set , void (* gc )(unsigned long ul_set ))
@@ -46,7 +42,7 @@ mtype_gc_init(struct ip_set *set, void (*gc)(unsigned long ul_set))
4642 init_timer (& map -> gc );
4743 map -> gc .data = (unsigned long ) set ;
4844 map -> gc .function = gc ;
49- map -> gc .expires = jiffies + IPSET_GC_PERIOD (map -> timeout ) * HZ ;
45+ map -> gc .expires = jiffies + IPSET_GC_PERIOD (set -> timeout ) * HZ ;
5046 add_timer (& map -> gc );
5147}
5248
@@ -59,7 +55,7 @@ mtype_destroy(struct ip_set *set)
5955 del_timer_sync (& map -> gc );
6056
6157 ip_set_free (map -> members );
62- if (map -> dsize )
58+ if (set -> dsize )
6359 ip_set_free (map -> extensions );
6460 kfree (map );
6561
@@ -88,9 +84,9 @@ mtype_head(struct ip_set *set, struct sk_buff *skb)
8884 nla_put_net32 (skb , IPSET_ATTR_MEMSIZE ,
8985 htonl (sizeof (* map ) +
9086 map -> memsize +
91- map -> dsize * map -> elements )) ||
87+ set -> dsize * map -> elements )) ||
9288 (SET_WITH_TIMEOUT (set ) &&
93- nla_put_net32 (skb , IPSET_ATTR_TIMEOUT , htonl (map -> timeout ))) ||
89+ nla_put_net32 (skb , IPSET_ATTR_TIMEOUT , htonl (set -> timeout ))) ||
9490 (SET_WITH_COUNTER (set ) &&
9591 nla_put_net32 (skb , IPSET_ATTR_CADT_FLAGS ,
9692 htonl (IPSET_FLAG_WITH_COUNTERS ))))
@@ -108,16 +104,16 @@ mtype_test(struct ip_set *set, void *value, const struct ip_set_ext *ext,
108104{
109105 struct mtype * map = set -> data ;
110106 const struct mtype_adt_elem * e = value ;
111- void * x = get_ext (map , e -> id );
112- int ret = mtype_do_test (e , map );
107+ void * x = get_ext (set , map , e -> id );
108+ int ret = mtype_do_test (e , map , set -> dsize );
113109
114110 if (ret <= 0 )
115111 return ret ;
116112 if (SET_WITH_TIMEOUT (set ) &&
117- ip_set_timeout_expired (ext_timeout (x , map )))
113+ ip_set_timeout_expired (ext_timeout (x , set )))
118114 return 0 ;
119115 if (SET_WITH_COUNTER (set ))
120- ip_set_update_counter (ext_counter (x , map ), ext , mext , flags );
116+ ip_set_update_counter (ext_counter (x , set ), ext , mext , flags );
121117 return 1 ;
122118}
123119
@@ -127,26 +123,26 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,
127123{
128124 struct mtype * map = set -> data ;
129125 const struct mtype_adt_elem * e = value ;
130- void * x = get_ext (map , e -> id );
131- int ret = mtype_do_add (e , map , flags );
126+ void * x = get_ext (set , map , e -> id );
127+ int ret = mtype_do_add (e , map , flags , set -> dsize );
132128
133129 if (ret == IPSET_ADD_FAILED ) {
134130 if (SET_WITH_TIMEOUT (set ) &&
135- ip_set_timeout_expired (ext_timeout (x , map )))
131+ ip_set_timeout_expired (ext_timeout (x , set )))
136132 ret = 0 ;
137133 else if (!(flags & IPSET_FLAG_EXIST ))
138134 return - IPSET_ERR_EXIST ;
139135 }
140136
141137 if (SET_WITH_TIMEOUT (set ))
142138#ifdef IP_SET_BITMAP_STORED_TIMEOUT
143- mtype_add_timeout (ext_timeout (x , map ), e , ext , map , ret );
139+ mtype_add_timeout (ext_timeout (x , set ), e , ext , set , map , ret );
144140#else
145- ip_set_timeout_set (ext_timeout (x , map ), ext -> timeout );
141+ ip_set_timeout_set (ext_timeout (x , set ), ext -> timeout );
146142#endif
147143
148144 if (SET_WITH_COUNTER (set ))
149- ip_set_init_counter (ext_counter (x , map ), ext );
145+ ip_set_init_counter (ext_counter (x , set ), ext );
150146 return 0 ;
151147}
152148
@@ -156,11 +152,11 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext,
156152{
157153 struct mtype * map = set -> data ;
158154 const struct mtype_adt_elem * e = value ;
159- const void * x = get_ext (map , e -> id );
155+ const void * x = get_ext (set , map , e -> id );
160156
161157 if (mtype_do_del (e , map ) ||
162158 (SET_WITH_TIMEOUT (set ) &&
163- ip_set_timeout_expired (ext_timeout (x , map ))))
159+ ip_set_timeout_expired (ext_timeout (x , set ))))
164160 return - IPSET_ERR_EXIST ;
165161
166162 return 0 ;
@@ -180,13 +176,13 @@ mtype_list(const struct ip_set *set,
180176 return - EMSGSIZE ;
181177 for (; cb -> args [2 ] < map -> elements ; cb -> args [2 ]++ ) {
182178 id = cb -> args [2 ];
183- x = get_ext (map , id );
179+ x = get_ext (set , map , id );
184180 if (!test_bit (id , map -> members ) ||
185181 (SET_WITH_TIMEOUT (set ) &&
186182#ifdef IP_SET_BITMAP_STORED_TIMEOUT
187183 mtype_is_filled ((const struct mtype_elem * ) x ) &&
188184#endif
189- ip_set_timeout_expired (ext_timeout (x , map ))))
185+ ip_set_timeout_expired (ext_timeout (x , set ))))
190186 continue ;
191187 nested = ipset_nest_start (skb , IPSET_ATTR_DATA );
192188 if (!nested ) {
@@ -196,23 +192,24 @@ mtype_list(const struct ip_set *set,
196192 } else
197193 goto nla_put_failure ;
198194 }
199- if (mtype_do_list (skb , map , id ))
195+ if (mtype_do_list (skb , map , id , set -> dsize ))
200196 goto nla_put_failure ;
201197 if (SET_WITH_TIMEOUT (set )) {
202198#ifdef IP_SET_BITMAP_STORED_TIMEOUT
203199 if (nla_put_net32 (skb , IPSET_ATTR_TIMEOUT ,
204200 htonl (ip_set_timeout_stored (map , id ,
205- ext_timeout (x , map )))))
201+ ext_timeout (x , set ),
202+ set -> dsize ))))
206203 goto nla_put_failure ;
207204#else
208205 if (nla_put_net32 (skb , IPSET_ATTR_TIMEOUT ,
209206 htonl (ip_set_timeout_get (
210- ext_timeout (x , map )))))
207+ ext_timeout (x , set )))))
211208 goto nla_put_failure ;
212209#endif
213210 }
214211 if (SET_WITH_COUNTER (set ) &&
215- ip_set_put_counter (skb , ext_counter (x , map )))
212+ ip_set_put_counter (skb , ext_counter (x , set )))
216213 goto nla_put_failure ;
217214 ipset_nest_end (skb , nested );
218215 }
@@ -245,14 +242,14 @@ mtype_gc(unsigned long ul_set)
245242 * but adding/deleting new entries is locked out */
246243 read_lock_bh (& set -> lock );
247244 for (id = 0 ; id < map -> elements ; id ++ )
248- if (mtype_gc_test (id , map )) {
249- x = get_ext (map , id );
250- if (ip_set_timeout_expired (ext_timeout (x , map )))
245+ if (mtype_gc_test (id , map , set -> dsize )) {
246+ x = get_ext (set , map , id );
247+ if (ip_set_timeout_expired (ext_timeout (x , set )))
251248 clear_bit (id , map -> members );
252249 }
253250 read_unlock_bh (& set -> lock );
254251
255- map -> gc .expires = jiffies + IPSET_GC_PERIOD (map -> timeout ) * HZ ;
252+ map -> gc .expires = jiffies + IPSET_GC_PERIOD (set -> timeout ) * HZ ;
256253 add_timer (& map -> gc );
257254}
258255
0 commit comments