History

netfilter: ipset: options and flags support added to the kernel API

The support makes possible to specify the timeout value for the SET target and a flag to reset the timeout for already existing entries.

Jozsef Kadlecsik committed 15 years ago

Commit ac8cc921 parent 483e9ea16 files · +206 −134Browse files

Unified · Split

16 files
  1. include/linux/netfilter/ipset/ip_set.h +14 −4
  2. include/linux/netfilter/ipset/ip_set_ahash.h +1 −1
  3. include/linux/netfilter/ipset/ip_set_timeout.h +3 −0
  4. include/linux/netfilter/xt_set.h +12 −3
  5. net/netfilter/ipset/ip_set_bitmap_ip.c +3 −3
  6. net/netfilter/ipset/ip_set_bitmap_ipmac.c +4 −4
  7. net/netfilter/ipset/ip_set_bitmap_port.c +4 −3
  8. net/netfilter/ipset/ip_set_core.c +13 −13
  9. net/netfilter/ipset/ip_set_hash_ip.c +6 −6
  10. net/netfilter/ipset/ip_set_hash_ipport.c +8 −8
  11. net/netfilter/ipset/ip_set_hash_ipportip.c +10 −10
  12. net/netfilter/ipset/ip_set_hash_ipportnet.c +10 −10
  13. net/netfilter/ipset/ip_set_hash_net.c +6 −6
  14. net/netfilter/ipset/ip_set_hash_netport.c +8 −8
  15. net/netfilter/ipset/ip_set_list_set.c +4 −4
  16. net/netfilter/xt_set.c +100 −51
include/linux/netfilter/ipset/ip_set.h+14−4
@@ -217,6 +217,15 @@ struct ip_set; · 216 unmodified lines
217217 typedef int (*ipset_adtfn)(struct ip_set *set, void *value,
218218 u32 timeout, u32 flags);
219219
220+/* Kernel API function options */
221+struct ip_set_adt_opt {
222+ u8 family; /* Actual protocol family */
223+ u8 dim; /* Dimension of match/target */
224+ u8 flags; /* Direction and negation flags */
225+ u32 cmdflags; /* Command-like flags */
226+ u32 timeout; /* Timeout value */
227+};
228+
220229 /* Set type, variant-specific part */
221230 struct ip_set_type_variant {
222231 /* Kernelspace: test/add/del entries
@@ -224,7 +233,7 @@ struct ip_set_type_variant { · 1 unmodified line
224233 * zero for no match/success to add/delete
225234 * positive for matching element */
226235 int (*kadt)(struct ip_set *set, const struct sk_buff * skb,
227− enum ipset_adt adt, u8 pf, u8 dim, u8 flags);
236+ enum ipset_adt adt, const struct ip_set_adt_opt *opt);
228237
229238 /* Userspace: test/add/del entries
230239 * returns negative error code,
@@ -314,12 +323,13 @@ extern ip_set_id_t ip_set_nfnl_get_byindex(ip_set_id_t index); · 83 unmodified lines
314323 extern void ip_set_nfnl_put(ip_set_id_t index);
315324
316325 /* API for iptables set match, and SET target */
326+
317327 extern int ip_set_add(ip_set_id_t id, const struct sk_buff *skb,
318− u8 family, u8 dim, u8 flags);
328+ const struct ip_set_adt_opt *opt);
319329 extern int ip_set_del(ip_set_id_t id, const struct sk_buff *skb,
320− u8 family, u8 dim, u8 flags);
330+ const struct ip_set_adt_opt *opt);
321331 extern int ip_set_test(ip_set_id_t id, const struct sk_buff *skb,
322− u8 family, u8 dim, u8 flags);
332+ const struct ip_set_adt_opt *opt);
323333
324334 /* Utility functions */
325335 extern void * ip_set_alloc(size_t size);
include/linux/netfilter/ipset/ip_set_ahash.h+1−1
@@ -586,7 +586,7 @@ nla_put_failure: · 585 unmodified lines
586586
587587 static int
588588 type_pf_kadt(struct ip_set *set, const struct sk_buff * skb,
589− enum ipset_adt adt, u8 pf, u8 dim, u8 flags);
589+ enum ipset_adt adt, const struct ip_set_adt_opt *opt);
590590 static int
591591 type_pf_uadt(struct ip_set *set, struct nlattr *tb[],
592592 enum ipset_adt adt, u32 *lineno, u32 flags);
include/linux/netfilter/ipset/ip_set_timeout.h+3−0
@@ -22,6 +22,9 @@ · 21 unmodified lines
2222
2323 #define with_timeout(timeout) ((timeout) != IPSET_NO_TIMEOUT)
2424
25+#define opt_timeout(opt, map) \
26+ (with_timeout((opt)->timeout) ? (opt)->timeout : (map)->timeout)
27+
2528 static inline unsigned int
2629 ip_set_timeout_uget(struct nlattr *tb)
2730 {
include/linux/netfilter/xt_set.h+12−3
@@ -35,7 +35,7 @@ struct xt_set_info_target_v0 { · 34 unmodified lines
3535 struct xt_set_info_v0 del_set;
3636 };
3737
38−/* Revision 1: current interface to netfilter/iptables */
38+/* Revision 1 match and target */
3939
4040 struct xt_set_info {
4141 ip_set_id_t index;
@@ -44,13 +44,22 @@ struct xt_set_info { · 2 unmodified lines
4444 };
4545
4646 /* match and target infos */
47−struct xt_set_info_match {
47+struct xt_set_info_match_v1 {
4848 struct xt_set_info match_set;
4949 };
5050
51−struct xt_set_info_target {
51+struct xt_set_info_target_v1 {
5252 struct xt_set_info add_set;
5353 struct xt_set_info del_set;
5454 };
5555
56+/* Revision 2 target */
57+
58+struct xt_set_info_target_v2 {
59+ struct xt_set_info add_set;
60+ struct xt_set_info del_set;
61+ u32 flags;
62+ u32 timeout;
63+};
64+
5665 #endif /*_XT_SET_H*/
net/netfilter/ipset/ip_set_bitmap_ip.c+3−3
@@ -219,19 +219,19 @@ nla_put_failure: · 218 unmodified lines
219219
220220 static int
221221 bitmap_ip_kadt(struct ip_set *set, const struct sk_buff *skb,
222− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
222+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
223223 {
224224 struct bitmap_ip *map = set->data;
225225 ipset_adtfn adtfn = set->variant->adt[adt];
226226 u32 ip;
227227
228− ip = ntohl(ip4addr(skb, flags & IPSET_DIM_ONE_SRC));
228+ ip = ntohl(ip4addr(skb, opt->flags & IPSET_DIM_ONE_SRC));
229229 if (ip < map->first_ip || ip > map->last_ip)
230230 return -IPSET_ERR_BITMAP_RANGE;
231231
232232 ip = ip_to_id(map, ip);
233233
234− return adtfn(set, &ip, map->timeout, flags);
234+ return adtfn(set, &ip, opt_timeout(opt, map), opt->cmdflags);
235235 }
236236
237237 static int
net/netfilter/ipset/ip_set_bitmap_ipmac.c+4−4
@@ -338,17 +338,17 @@ nla_put_failure: · 337 unmodified lines
338338
339339 static int
340340 bitmap_ipmac_kadt(struct ip_set *set, const struct sk_buff *skb,
341− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
341+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
342342 {
343343 struct bitmap_ipmac *map = set->data;
344344 ipset_adtfn adtfn = set->variant->adt[adt];
345345 struct ipmac data;
346346
347347 /* MAC can be src only */
348− if (!(flags & IPSET_DIM_TWO_SRC))
348+ if (!(opt->flags & IPSET_DIM_TWO_SRC))
349349 return 0;
350350
351− data.id = ntohl(ip4addr(skb, flags & IPSET_DIM_ONE_SRC));
351+ data.id = ntohl(ip4addr(skb, opt->flags & IPSET_DIM_ONE_SRC));
352352 if (data.id < map->first_ip || data.id > map->last_ip)
353353 return -IPSET_ERR_BITMAP_RANGE;
354354
@@ -360,7 +360,7 @@ bitmap_ipmac_kadt(struct ip_set *set, const struct sk_buff *skb, · 5 unmodified lines
360360 data.id -= map->first_ip;
361361 data.ether = eth_hdr(skb)->h_source;
362362
363− return adtfn(set, &data, map->timeout, flags);
363+ return adtfn(set, &data, opt_timeout(opt, map), opt->cmdflags);
364364 }
365365
366366 static int
net/netfilter/ipset/ip_set_bitmap_port.c+4−3
@@ -208,14 +208,15 @@ nla_put_failure: · 207 unmodified lines
208208
209209 static int
210210 bitmap_port_kadt(struct ip_set *set, const struct sk_buff *skb,
211− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
211+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
212212 {
213213 struct bitmap_port *map = set->data;
214214 ipset_adtfn adtfn = set->variant->adt[adt];
215215 __be16 __port;
216216 u16 port = 0;
217217
218− if (!ip_set_get_ip_port(skb, pf, flags & IPSET_DIM_ONE_SRC, &__port))
218+ if (!ip_set_get_ip_port(skb, opt->family,
219+ opt->flags & IPSET_DIM_ONE_SRC, &__port))
219220 return -EINVAL;
220221
221222 port = ntohs(__port);
@@ -225,7 +226,7 @@ bitmap_port_kadt(struct ip_set *set, const struct sk_buff *skb, · 3 unmodified lines
225226
226227 port -= map->first_port;
227228
228− return adtfn(set, &port, map->timeout, flags);
229+ return adtfn(set, &port, opt_timeout(opt, map), opt->cmdflags);
229230 }
230231
231232 static int
net/netfilter/ipset/ip_set_core.c+13−13
@@ -325,7 +325,7 @@ __ip_set_put(ip_set_id_t index) · 324 unmodified lines
325325
326326 int
327327 ip_set_test(ip_set_id_t index, const struct sk_buff *skb,
328− u8 family, u8 dim, u8 flags)
328+ const struct ip_set_adt_opt *opt)
329329 {
330330 struct ip_set *set = ip_set_list[index];
331331 int ret = 0;
@@ -333,19 +333,19 @@ ip_set_test(ip_set_id_t index, const struct sk_buff *skb, · 1 unmodified line
333333 BUG_ON(set == NULL);
334334 pr_debug("set %s, index %u\n", set->name, index);
335335
336− if (dim < set->type->dimension ||
337− !(family == set->family || set->family == AF_UNSPEC))
336+ if (opt->dim < set->type->dimension ||
337+ !(opt->family == set->family || set->family == AF_UNSPEC))
338338 return 0;
339339
340340 read_lock_bh(&set->lock);
341− ret = set->variant->kadt(set, skb, IPSET_TEST, family, dim, flags);
341+ ret = set->variant->kadt(set, skb, IPSET_TEST, opt);
342342 read_unlock_bh(&set->lock);
343343
344344 if (ret == -EAGAIN) {
345345 /* Type requests element to be completed */
346346 pr_debug("element must be competed, ADD is triggered\n");
347347 write_lock_bh(&set->lock);
348− set->variant->kadt(set, skb, IPSET_ADD, family, dim, flags);
348+ set->variant->kadt(set, skb, IPSET_ADD, opt);
349349 write_unlock_bh(&set->lock);
350350 ret = 1;
351351 }
@@ -357,7 +357,7 @@ EXPORT_SYMBOL_GPL(ip_set_test); · 5 unmodified lines
357357
358358 int
359359 ip_set_add(ip_set_id_t index, const struct sk_buff *skb,
360− u8 family, u8 dim, u8 flags)
360+ const struct ip_set_adt_opt *opt)
361361 {
362362 struct ip_set *set = ip_set_list[index];
363363 int ret;
@@ -365,12 +365,12 @@ ip_set_add(ip_set_id_t index, const struct sk_buff *skb, · 1 unmodified line
365365 BUG_ON(set == NULL);
366366 pr_debug("set %s, index %u\n", set->name, index);
367367
368− if (dim < set->type->dimension ||
369− !(family == set->family || set->family == AF_UNSPEC))
368+ if (opt->dim < set->type->dimension ||
369+ !(opt->family == set->family || set->family == AF_UNSPEC))
370370 return 0;
371371
372372 write_lock_bh(&set->lock);
373− ret = set->variant->kadt(set, skb, IPSET_ADD, family, dim, flags);
373+ ret = set->variant->kadt(set, skb, IPSET_ADD, opt);
374374 write_unlock_bh(&set->lock);
375375
376376 return ret;
@@ -379,7 +379,7 @@ EXPORT_SYMBOL_GPL(ip_set_add); · 2 unmodified lines
379379
380380 int
381381 ip_set_del(ip_set_id_t index, const struct sk_buff *skb,
382− u8 family, u8 dim, u8 flags)
382+ const struct ip_set_adt_opt *opt)
383383 {
384384 struct ip_set *set = ip_set_list[index];
385385 int ret = 0;
@@ -387,12 +387,12 @@ ip_set_del(ip_set_id_t index, const struct sk_buff *skb, · 1 unmodified line
387387 BUG_ON(set == NULL);
388388 pr_debug("set %s, index %u\n", set->name, index);
389389
390− if (dim < set->type->dimension ||
391− !(family == set->family || set->family == AF_UNSPEC))
390+ if (opt->dim < set->type->dimension ||
391+ !(opt->family == set->family || set->family == AF_UNSPEC))
392392 return 0;
393393
394394 write_lock_bh(&set->lock);
395− ret = set->variant->kadt(set, skb, IPSET_DEL, family, dim, flags);
395+ ret = set->variant->kadt(set, skb, IPSET_DEL, opt);
396396 write_unlock_bh(&set->lock);
397397
398398 return ret;
net/netfilter/ipset/ip_set_hash_ip.c+6−6
@@ -110,18 +110,18 @@ nla_put_failure: · 109 unmodified lines
110110
111111 static int
112112 hash_ip4_kadt(struct ip_set *set, const struct sk_buff *skb,
113− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
113+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
114114 {
115115 const struct ip_set_hash *h = set->data;
116116 ipset_adtfn adtfn = set->variant->adt[adt];
117117 __be32 ip;
118118
119− ip4addrptr(skb, flags & IPSET_DIM_ONE_SRC, &ip);
119+ ip4addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &ip);
120120 ip &= ip_set_netmask(h->netmask);
121121 if (ip == 0)
122122 return -EINVAL;
123123
124− return adtfn(set, &ip, h->timeout, flags);
124+ return adtfn(set, &ip, opt_timeout(opt, h), opt->cmdflags);
125125 }
126126
127127 static int
@@ -283,18 +283,18 @@ nla_put_failure: · 155 unmodified lines
283283
284284 static int
285285 hash_ip6_kadt(struct ip_set *set, const struct sk_buff *skb,
286− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
286+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
287287 {
288288 const struct ip_set_hash *h = set->data;
289289 ipset_adtfn adtfn = set->variant->adt[adt];
290290 union nf_inet_addr ip;
291291
292− ip6addrptr(skb, flags & IPSET_DIM_ONE_SRC, &ip.in6);
292+ ip6addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &ip.in6);
293293 ip6_netmask(&ip, h->netmask);
294294 if (ipv6_addr_any(&ip.in6))
295295 return -EINVAL;
296296
297− return adtfn(set, &ip, h->timeout, flags);
297+ return adtfn(set, &ip, opt_timeout(opt, h), opt->cmdflags);
298298 }
299299
300300 static const struct nla_policy hash_ip6_adt_policy[IPSET_ATTR_ADT_MAX + 1] = {
net/netfilter/ipset/ip_set_hash_ipport.c+8−8
@@ -126,19 +126,19 @@ nla_put_failure: · 125 unmodified lines
126126
127127 static int
128128 hash_ipport4_kadt(struct ip_set *set, const struct sk_buff *skb,
129− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
129+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
130130 {
131131 const struct ip_set_hash *h = set->data;
132132 ipset_adtfn adtfn = set->variant->adt[adt];
133133 struct hash_ipport4_elem data = { };
134134
135− if (!ip_set_get_ip4_port(skb, flags & IPSET_DIM_TWO_SRC,
135+ if (!ip_set_get_ip4_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
136136 &data.port, &data.proto))
137137 return -EINVAL;
138138
139− ip4addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip);
139+ ip4addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &data.ip);
140140
141− return adtfn(set, &data, h->timeout, flags);
141+ return adtfn(set, &data, opt_timeout(opt, h), opt->cmdflags);
142142 }
143143
144144 static int
@@ -330,19 +330,19 @@ nla_put_failure: · 185 unmodified lines
330330
331331 static int
332332 hash_ipport6_kadt(struct ip_set *set, const struct sk_buff *skb,
333− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
333+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
334334 {
335335 const struct ip_set_hash *h = set->data;
336336 ipset_adtfn adtfn = set->variant->adt[adt];
337337 struct hash_ipport6_elem data = { };
338338
339− if (!ip_set_get_ip6_port(skb, flags & IPSET_DIM_TWO_SRC,
339+ if (!ip_set_get_ip6_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
340340 &data.port, &data.proto))
341341 return -EINVAL;
342342
343− ip6addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip.in6);
343+ ip6addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &data.ip.in6);
344344
345− return adtfn(set, &data, h->timeout, flags);
345+ return adtfn(set, &data, opt_timeout(opt, h), opt->cmdflags);
346346 }
347347
348348 static int
net/netfilter/ipset/ip_set_hash_ipportip.c+10−10
@@ -129,20 +129,20 @@ nla_put_failure: · 128 unmodified lines
129129
130130 static int
131131 hash_ipportip4_kadt(struct ip_set *set, const struct sk_buff *skb,
132− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
132+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
133133 {
134134 const struct ip_set_hash *h = set->data;
135135 ipset_adtfn adtfn = set->variant->adt[adt];
136136 struct hash_ipportip4_elem data = { };
137137
138− if (!ip_set_get_ip4_port(skb, flags & IPSET_DIM_TWO_SRC,
138+ if (!ip_set_get_ip4_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
139139 &data.port, &data.proto))
140140 return -EINVAL;
141141
142− ip4addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip);
143− ip4addrptr(skb, flags & IPSET_DIM_THREE_SRC, &data.ip2);
142+ ip4addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &data.ip);
143+ ip4addrptr(skb, opt->flags & IPSET_DIM_THREE_SRC, &data.ip2);
144144
145− return adtfn(set, &data, h->timeout, flags);
145+ return adtfn(set, &data, opt_timeout(opt, h), opt->cmdflags);
146146 }
147147
148148 static int
@@ -343,20 +343,20 @@ nla_put_failure: · 194 unmodified lines
343343
344344 static int
345345 hash_ipportip6_kadt(struct ip_set *set, const struct sk_buff *skb,
346− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
346+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
347347 {
348348 const struct ip_set_hash *h = set->data;
349349 ipset_adtfn adtfn = set->variant->adt[adt];
350350 struct hash_ipportip6_elem data = { };
351351
352− if (!ip_set_get_ip6_port(skb, flags & IPSET_DIM_TWO_SRC,
352+ if (!ip_set_get_ip6_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
353353 &data.port, &data.proto))
354354 return -EINVAL;
355355
356− ip6addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip.in6);
357− ip6addrptr(skb, flags & IPSET_DIM_THREE_SRC, &data.ip2.in6);
356+ ip6addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &data.ip.in6);
357+ ip6addrptr(skb, opt->flags & IPSET_DIM_THREE_SRC, &data.ip2.in6);
358358
359− return adtfn(set, &data, h->timeout, flags);
359+ return adtfn(set, &data, opt_timeout(opt, h), opt->cmdflags);
360360 }
361361
362362 static int
net/netfilter/ipset/ip_set_hash_ipportnet.c+10−10
@@ -142,7 +142,7 @@ nla_put_failure: · 141 unmodified lines
142142
143143 static int
144144 hash_ipportnet4_kadt(struct ip_set *set, const struct sk_buff *skb,
145− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
145+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
146146 {
147147 const struct ip_set_hash *h = set->data;
148148 ipset_adtfn adtfn = set->variant->adt[adt];
@@ -154,15 +154,15 @@ hash_ipportnet4_kadt(struct ip_set *set, const struct sk_buff *skb, · 5 unmodified lines
154154 if (adt == IPSET_TEST)
155155 data.cidr = HOST_MASK;
156156
157− if (!ip_set_get_ip4_port(skb, flags & IPSET_DIM_TWO_SRC,
157+ if (!ip_set_get_ip4_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
158158 &data.port, &data.proto))
159159 return -EINVAL;
160160
161− ip4addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip);
162− ip4addrptr(skb, flags & IPSET_DIM_THREE_SRC, &data.ip2);
161+ ip4addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &data.ip);
162+ ip4addrptr(skb, opt->flags & IPSET_DIM_THREE_SRC, &data.ip2);
163163 data.ip2 &= ip_set_netmask(data.cidr);
164164
165− return adtfn(set, &data, h->timeout, flags);
165+ return adtfn(set, &data, opt_timeout(opt, h), opt->cmdflags);
166166 }
167167
168168 static int
@@ -390,7 +390,7 @@ nla_put_failure: · 221 unmodified lines
390390
391391 static int
392392 hash_ipportnet6_kadt(struct ip_set *set, const struct sk_buff *skb,
393− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
393+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
394394 {
395395 const struct ip_set_hash *h = set->data;
396396 ipset_adtfn adtfn = set->variant->adt[adt];
@@ -402,15 +402,15 @@ hash_ipportnet6_kadt(struct ip_set *set, const struct sk_buff *skb, · 5 unmodified lines
402402 if (adt == IPSET_TEST)
403403 data.cidr = HOST_MASK;
404404
405− if (!ip_set_get_ip6_port(skb, flags & IPSET_DIM_TWO_SRC,
405+ if (!ip_set_get_ip6_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
406406 &data.port, &data.proto))
407407 return -EINVAL;
408408
409− ip6addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip.in6);
410− ip6addrptr(skb, flags & IPSET_DIM_THREE_SRC, &data.ip2.in6);
409+ ip6addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &data.ip.in6);
410+ ip6addrptr(skb, opt->flags & IPSET_DIM_THREE_SRC, &data.ip2.in6);
411411 ip6_netmask(&data.ip2, data.cidr);
412412
413− return adtfn(set, &data, h->timeout, flags);
413+ return adtfn(set, &data, opt_timeout(opt, h), opt->cmdflags);
414414 }
415415
416416 static int
net/netfilter/ipset/ip_set_hash_net.c+6−6
@@ -127,7 +127,7 @@ nla_put_failure: · 126 unmodified lines
127127
128128 static int
129129 hash_net4_kadt(struct ip_set *set, const struct sk_buff *skb,
130− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
130+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
131131 {
132132 const struct ip_set_hash *h = set->data;
133133 ipset_adtfn adtfn = set->variant->adt[adt];
@@ -138,10 +138,10 @@ hash_net4_kadt(struct ip_set *set, const struct sk_buff *skb, · 4 unmodified lines
138138 if (adt == IPSET_TEST)
139139 data.cidr = HOST_MASK;
140140
141− ip4addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip);
141+ ip4addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &data.ip);
142142 data.ip &= ip_set_netmask(data.cidr);
143143
144− return adtfn(set, &data, h->timeout, flags);
144+ return adtfn(set, &data, opt_timeout(opt, h), opt->cmdflags);
145145 }
146146
147147 static int
@@ -292,7 +292,7 @@ nla_put_failure: · 144 unmodified lines
292292
293293 static int
294294 hash_net6_kadt(struct ip_set *set, const struct sk_buff *skb,
295− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
295+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
296296 {
297297 const struct ip_set_hash *h = set->data;
298298 ipset_adtfn adtfn = set->variant->adt[adt];
@@ -303,10 +303,10 @@ hash_net6_kadt(struct ip_set *set, const struct sk_buff *skb, · 4 unmodified lines
303303 if (adt == IPSET_TEST)
304304 data.cidr = HOST_MASK;
305305
306− ip6addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip.in6);
306+ ip6addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &data.ip.in6);
307307 ip6_netmask(&data.ip, data.cidr);
308308
309− return adtfn(set, &data, h->timeout, flags);
309+ return adtfn(set, &data, opt_timeout(opt, h), opt->cmdflags);
310310 }
311311
312312 static int
net/netfilter/ipset/ip_set_hash_netport.c+8−8
@@ -139,7 +139,7 @@ nla_put_failure: · 138 unmodified lines
139139
140140 static int
141141 hash_netport4_kadt(struct ip_set *set, const struct sk_buff *skb,
142− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
142+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
143143 {
144144 const struct ip_set_hash *h = set->data;
145145 ipset_adtfn adtfn = set->variant->adt[adt];
@@ -151,14 +151,14 @@ hash_netport4_kadt(struct ip_set *set, const struct sk_buff *skb, · 5 unmodified lines
151151 if (adt == IPSET_TEST)
152152 data.cidr = HOST_MASK;
153153
154− if (!ip_set_get_ip4_port(skb, flags & IPSET_DIM_TWO_SRC,
154+ if (!ip_set_get_ip4_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
155155 &data.port, &data.proto))
156156 return -EINVAL;
157157
158− ip4addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip);
158+ ip4addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &data.ip);
159159 data.ip &= ip_set_netmask(data.cidr);
160160
161− return adtfn(set, &data, h->timeout, flags);
161+ return adtfn(set, &data, opt_timeout(opt, h), opt->cmdflags);
162162 }
163163
164164 static int
@@ -352,7 +352,7 @@ nla_put_failure: · 187 unmodified lines
352352
353353 static int
354354 hash_netport6_kadt(struct ip_set *set, const struct sk_buff *skb,
355− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
355+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
356356 {
357357 const struct ip_set_hash *h = set->data;
358358 ipset_adtfn adtfn = set->variant->adt[adt];
@@ -364,14 +364,14 @@ hash_netport6_kadt(struct ip_set *set, const struct sk_buff *skb, · 5 unmodified lines
364364 if (adt == IPSET_TEST)
365365 data.cidr = HOST_MASK;
366366
367− if (!ip_set_get_ip6_port(skb, flags & IPSET_DIM_TWO_SRC,
367+ if (!ip_set_get_ip6_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
368368 &data.port, &data.proto))
369369 return -EINVAL;
370370
371− ip6addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip.in6);
371+ ip6addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &data.ip.in6);
372372 ip6_netmask(&data.ip, data.cidr);
373373
374− return adtfn(set, &data, h->timeout, flags);
374+ return adtfn(set, &data, opt_timeout(opt, h), opt->cmdflags);
375375 }
376376
377377 static int
net/netfilter/ipset/ip_set_list_set.c+4−4
@@ -72,7 +72,7 @@ list_set_expired(const struct list_set *map, u32 id) · 71 unmodified lines
7272
7373 static int
7474 list_set_kadt(struct ip_set *set, const struct sk_buff *skb,
75− enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
75+ enum ipset_adt adt, const struct ip_set_adt_opt *opt)
7676 {
7777 struct list_set *map = set->data;
7878 struct set_elem *elem;
@@ -87,17 +87,17 @@ list_set_kadt(struct ip_set *set, const struct sk_buff *skb, · 8 unmodified lines
8787 continue;
8888 switch (adt) {
8989 case IPSET_TEST:
90− ret = ip_set_test(elem->id, skb, pf, dim, flags);
90+ ret = ip_set_test(elem->id, skb, opt);
9191 if (ret > 0)
9292 return ret;
9393 break;
9494 case IPSET_ADD:
95− ret = ip_set_add(elem->id, skb, pf, dim, flags);
95+ ret = ip_set_add(elem->id, skb, opt);
9696 if (ret == 0)
9797 return ret;
9898 break;
9999 case IPSET_DEL:
100− ret = ip_set_del(elem->id, skb, pf, dim, flags);
100+ ret = ip_set_del(elem->id, skb, opt);
101101 if (ret == 0)
102102 return ret;
103103 break;
net/netfilter/xt_set.c+100−51
@@ -29,23 +29,32 @@ MODULE_ALIAS("ip6t_SET"); · 28 unmodified lines
2929
3030 static inline int
3131 match_set(ip_set_id_t index, const struct sk_buff *skb,
32− u8 pf, u8 dim, u8 flags, int inv)
32+ const struct ip_set_adt_opt *opt, int inv)
3333 {
34− if (ip_set_test(index, skb, pf, dim, flags))
34+ if (ip_set_test(index, skb, opt))
3535 inv = !inv;
3636 return inv;
3737 }
3838
39+#define ADT_OPT(n, f, d, fs, cfs, t) \
40+const struct ip_set_adt_opt n = { \
41+ .family = f, \
42+ .dim = d, \
43+ .flags = fs, \
44+ .cmdflags = cfs, \
45+ .timeout = t, \
46+}
47+
3948 /* Revision 0 interface: backward compatible with netfilter/iptables */
4049
4150 static bool
4251 set_match_v0(const struct sk_buff *skb, struct xt_action_param *par)
4352 {
4453 const struct xt_set_info_match_v0 *info = par->matchinfo;
54+ ADT_OPT(opt, par->family, info->match_set.u.compat.dim,
55+ info->match_set.u.compat.flags, 0, UINT_MAX);
4556
46− return match_set(info->match_set.index, skb, par->family,
47− info->match_set.u.compat.dim,
48− info->match_set.u.compat.flags,
57+ return match_set(info->match_set.index, skb, &opt,
4958 info->match_set.u.compat.flags & IPSET_INV_MATCH);
5059 }
5160
@@ -103,15 +112,15 @@ static unsigned int · 51 unmodified lines
103112 set_target_v0(struct sk_buff *skb, const struct xt_action_param *par)
104113 {
105114 const struct xt_set_info_target_v0 *info = par->targinfo;
115+ ADT_OPT(add_opt, par->family, info->add_set.u.compat.dim,
116+ info->add_set.u.compat.flags, 0, UINT_MAX);
117+ ADT_OPT(del_opt, par->family, info->del_set.u.compat.dim,
118+ info->del_set.u.compat.flags, 0, UINT_MAX);
106119
107120 if (info->add_set.index != IPSET_INVALID_ID)
108− ip_set_add(info->add_set.index, skb, par->family,
109− info->add_set.u.compat.dim,
110− info->add_set.u.compat.flags);
121+ ip_set_add(info->add_set.index, skb, &add_opt);
111122 if (info->del_set.index != IPSET_INVALID_ID)
112− ip_set_del(info->del_set.index, skb, par->family,
113− info->del_set.u.compat.dim,
114− info->del_set.u.compat.flags);
123+ ip_set_del(info->del_set.index, skb, &del_opt);
115124
116125 return XT_CONTINUE;
117126 }
@@ -170,23 +179,23 @@ set_target_v0_destroy(const struct xt_tgdtor_param *par) · 52 unmodified lines
170179 ip_set_nfnl_put(info->del_set.index);
171180 }
172181
173−/* Revision 1: current interface to netfilter/iptables */
182+/* Revision 1 match and target */
174183
175184 static bool
176−set_match(const struct sk_buff *skb, struct xt_action_param *par)
185+set_match_v1(const struct sk_buff *skb, struct xt_action_param *par)
177186 {
178− const struct xt_set_info_match *info = par->matchinfo;
187+ const struct xt_set_info_match_v1 *info = par->matchinfo;
188+ ADT_OPT(opt, par->family, info->match_set.dim,
189+ info->match_set.flags, 0, UINT_MAX);
179190
180− return match_set(info->match_set.index, skb, par->family,
181− info->match_set.dim,
182− info->match_set.flags,
191+ return match_set(info->match_set.index, skb, &opt,
183192 info->match_set.flags & IPSET_INV_MATCH);
184193 }
185194
186195 static int
187−set_match_checkentry(const struct xt_mtchk_param *par)
196+set_match_v1_checkentry(const struct xt_mtchk_param *par)
188197 {
189− struct xt_set_info_match *info = par->matchinfo;
198+ struct xt_set_info_match_v1 *info = par->matchinfo;
190199 ip_set_id_t index;
191200
192201 index = ip_set_nfnl_get_byindex(info->match_set.index);
@@ -207,36 +216,34 @@ set_match_checkentry(const struct xt_mtchk_param *par) · 14 unmodified lines
207216 }
208217
209218 static void
210−set_match_destroy(const struct xt_mtdtor_param *par)
219+set_match_v1_destroy(const struct xt_mtdtor_param *par)
211220 {
212− struct xt_set_info_match *info = par->matchinfo;
221+ struct xt_set_info_match_v1 *info = par->matchinfo;
213222
214223 ip_set_nfnl_put(info->match_set.index);
215224 }
216225
217226 static unsigned int
218−set_target(struct sk_buff *skb, const struct xt_action_param *par)
227+set_target_v1(struct sk_buff *skb, const struct xt_action_param *par)
219228 {
220− const struct xt_set_info_target *info = par->targinfo;
229+ const struct xt_set_info_target_v1 *info = par->targinfo;
230+ ADT_OPT(add_opt, par->family, info->add_set.dim,
231+ info->add_set.flags, 0, UINT_MAX);
232+ ADT_OPT(del_opt, par->family, info->del_set.dim,
233+ info->del_set.flags, 0, UINT_MAX);
221234
222235 if (info->add_set.index != IPSET_INVALID_ID)
223− ip_set_add(info->add_set.index,
224− skb, par->family,
225− info->add_set.dim,
226− info->add_set.flags);
236+ ip_set_add(info->add_set.index, skb, &add_opt);
227237 if (info->del_set.index != IPSET_INVALID_ID)
228− ip_set_del(info->del_set.index,
229− skb, par->family,
230− info->del_set.dim,
231− info->del_set.flags);
238+ ip_set_del(info->del_set.index, skb, &del_opt);
232239
233240 return XT_CONTINUE;
234241 }
235242
236243 static int
237−set_target_checkentry(const struct xt_tgchk_param *par)
244+set_target_v1_checkentry(const struct xt_tgchk_param *par)
238245 {
239− const struct xt_set_info_target *info = par->targinfo;
246+ const struct xt_set_info_target_v1 *info = par->targinfo;
240247 ip_set_id_t index;
241248
242249 if (info->add_set.index != IPSET_INVALID_ID) {
@@ -273,9 +280,9 @@ set_target_checkentry(const struct xt_tgchk_param *par) · 30 unmodified lines
273280 }
274281
275282 static void
276−set_target_destroy(const struct xt_tgdtor_param *par)
283+set_target_v1_destroy(const struct xt_tgdtor_param *par)
277284 {
278− const struct xt_set_info_target *info = par->targinfo;
285+ const struct xt_set_info_target_v1 *info = par->targinfo;
279286
280287 if (info->add_set.index != IPSET_INVALID_ID)
281288 ip_set_nfnl_put(info->add_set.index);
@@ -283,6 +290,28 @@ set_target_destroy(const struct xt_tgdtor_param *par) · 1 unmodified line
283290 ip_set_nfnl_put(info->del_set.index);
284291 }
285292
293+/* Revision 2 target */
294+
295+static unsigned int
296+set_target_v2(struct sk_buff *skb, const struct xt_action_param *par)
297+{
298+ const struct xt_set_info_target_v2 *info = par->targinfo;
299+ ADT_OPT(add_opt, par->family, info->add_set.dim,
300+ info->add_set.flags, info->flags, info->timeout);
301+ ADT_OPT(del_opt, par->family, info->del_set.dim,
302+ info->del_set.flags, 0, UINT_MAX);
303+
304+ if (info->add_set.index != IPSET_INVALID_ID)
305+ ip_set_add(info->add_set.index, skb, &add_opt);
306+ if (info->del_set.index != IPSET_INVALID_ID)
307+ ip_set_del(info->del_set.index, skb, &del_opt);
308+
309+ return XT_CONTINUE;
310+}
311+
312+#define set_target_v2_checkentry set_target_v1_checkentry
313+#define set_target_v2_destroy set_target_v1_destroy
314+
286315 static struct xt_match set_matches[] __read_mostly = {
287316 {
288317 .name = "set",
@@ -298,20 +327,20 @@ static struct xt_match set_matches[] __read_mostly = { · 9 unmodified lines
298327 .name = "set",
299328 .family = NFPROTO_IPV4,
300329 .revision = 1,
301− .match = set_match,
302− .matchsize = sizeof(struct xt_set_info_match),
303− .checkentry = set_match_checkentry,
304− .destroy = set_match_destroy,
330+ .match = set_match_v1,
331+ .matchsize = sizeof(struct xt_set_info_match_v1),
332+ .checkentry = set_match_v1_checkentry,
333+ .destroy = set_match_v1_destroy,
305334 .me = THIS_MODULE
306335 },
307336 {
308337 .name = "set",
309338 .family = NFPROTO_IPV6,
310339 .revision = 1,
311− .match = set_match,
312− .matchsize = sizeof(struct xt_set_info_match),
313− .checkentry = set_match_checkentry,
314− .destroy = set_match_destroy,
340+ .match = set_match_v1,
341+ .matchsize = sizeof(struct xt_set_info_match_v1),
342+ .checkentry = set_match_v1_checkentry,
343+ .destroy = set_match_v1_destroy,
315344 .me = THIS_MODULE
316345 },
317346 };
@@ -331,20 +360,40 @@ static struct xt_target set_targets[] __read_mostly = { · 13 unmodified lines
331360 .name = "SET",
332361 .revision = 1,
333362 .family = NFPROTO_IPV4,
334− .target = set_target,
335− .targetsize = sizeof(struct xt_set_info_target),
336− .checkentry = set_target_checkentry,
337− .destroy = set_target_destroy,
363+ .target = set_target_v1,
364+ .targetsize = sizeof(struct xt_set_info_target_v1),
365+ .checkentry = set_target_v1_checkentry,
366+ .destroy = set_target_v1_destroy,
338367 .me = THIS_MODULE
339368 },
340369 {
341370 .name = "SET",
342371 .revision = 1,
343372 .family = NFPROTO_IPV6,
344− .target = set_target,
345− .targetsize = sizeof(struct xt_set_info_target),
346− .checkentry = set_target_checkentry,
347− .destroy = set_target_destroy,
373+ .target = set_target_v1,
374+ .targetsize = sizeof(struct xt_set_info_target_v1),
375+ .checkentry = set_target_v1_checkentry,
376+ .destroy = set_target_v1_destroy,
377+ .me = THIS_MODULE
378+ },
379+ {
380+ .name = "SET",
381+ .revision = 2,
382+ .family = NFPROTO_IPV4,
383+ .target = set_target_v2,
384+ .targetsize = sizeof(struct xt_set_info_target_v2),
385+ .checkentry = set_target_v2_checkentry,
386+ .destroy = set_target_v2_destroy,
387+ .me = THIS_MODULE
388+ },
389+ {
390+ .name = "SET",
391+ .revision = 2,
392+ .family = NFPROTO_IPV6,
393+ .target = set_target_v2,
394+ .targetsize = sizeof(struct xt_set_info_target_v2),
395+ .checkentry = set_target_v2_checkentry,
396+ .destroy = set_target_v2_destroy,
348397 .me = THIS_MODULE
349398 },
350399 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t