diff options
| author | Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> | 2013-09-25 11:44:35 -0400 |
|---|---|---|
| committer | Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> | 2013-09-30 15:42:36 -0400 |
| commit | 3fd986b3d99e3847f1cce6fc36043d0f16508e1d (patch) | |
| tree | 8b54a2ef0a69634dc83a33f01ec191524f9a0d82 | |
| parent | 8ec81f9a4db94fa5638c55793365b896dd9daecc (diff) | |
netfilter: ipset: Use a common function at listing the extensions
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
| -rw-r--r-- | include/linux/netfilter/ipset/ip_set.h | 21 | ||||
| -rw-r--r-- | net/netfilter/ipset/ip_set_bitmap_gen.h | 29 | ||||
| -rw-r--r-- | net/netfilter/ipset/ip_set_bitmap_ipmac.c | 11 | ||||
| -rw-r--r-- | net/netfilter/ipset/ip_set_hash_gen.h | 11 | ||||
| -rw-r--r-- | net/netfilter/ipset/ip_set_list_set.c | 11 |
5 files changed, 33 insertions, 50 deletions
diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h index 407f84df6a47..da2a45acf74c 100644 --- a/include/linux/netfilter/ipset/ip_set.h +++ b/include/linux/netfilter/ipset/ip_set.h | |||
| @@ -461,6 +461,27 @@ bitmap_bytes(u32 a, u32 b) | |||
| 461 | #include <linux/netfilter/ipset/ip_set_timeout.h> | 461 | #include <linux/netfilter/ipset/ip_set_timeout.h> |
| 462 | #include <linux/netfilter/ipset/ip_set_comment.h> | 462 | #include <linux/netfilter/ipset/ip_set_comment.h> |
| 463 | 463 | ||
| 464 | static inline int | ||
| 465 | ip_set_put_extensions(struct sk_buff *skb, const struct ip_set *set, | ||
| 466 | const void *e, bool active) | ||
| 467 | { | ||
| 468 | if (SET_WITH_TIMEOUT(set)) { | ||
| 469 | unsigned long *timeout = ext_timeout(e, set); | ||
| 470 | |||
| 471 | if (nla_put_net32(skb, IPSET_ATTR_TIMEOUT, | ||
| 472 | htonl(active ? ip_set_timeout_get(timeout) | ||
| 473 | : *timeout))) | ||
| 474 | return -EMSGSIZE; | ||
| 475 | } | ||
| 476 | if (SET_WITH_COUNTER(set) && | ||
| 477 | ip_set_put_counter(skb, ext_counter(e, set))) | ||
| 478 | return -EMSGSIZE; | ||
| 479 | if (SET_WITH_COMMENT(set) && | ||
| 480 | ip_set_put_comment(skb, ext_comment(e, set))) | ||
| 481 | return -EMSGSIZE; | ||
| 482 | return 0; | ||
| 483 | } | ||
| 484 | |||
| 464 | #define IP_SET_INIT_KEXT(skb, opt, set) \ | 485 | #define IP_SET_INIT_KEXT(skb, opt, set) \ |
| 465 | { .bytes = (skb)->len, .packets = 1, \ | 486 | { .bytes = (skb)->len, .packets = 1, \ |
| 466 | .timeout = ip_set_adt_opt_timeout(opt, set) } | 487 | .timeout = ip_set_adt_opt_timeout(opt, set) } |
diff --git a/net/netfilter/ipset/ip_set_bitmap_gen.h b/net/netfilter/ipset/ip_set_bitmap_gen.h index 6167fc9d0efe..a13e15be7911 100644 --- a/net/netfilter/ipset/ip_set_bitmap_gen.h +++ b/net/netfilter/ipset/ip_set_bitmap_gen.h | |||
| @@ -183,6 +183,14 @@ mtype_del(struct ip_set *set, void *value, const struct ip_set_ext *ext, | |||
| 183 | return 0; | 183 | return 0; |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | #ifndef IP_SET_BITMAP_STORED_TIMEOUT | ||
| 187 | static inline bool | ||
| 188 | mtype_is_filled(const struct mtype_elem *x) | ||
| 189 | { | ||
| 190 | return true; | ||
| 191 | } | ||
| 192 | #endif | ||
| 193 | |||
| 186 | static int | 194 | static int |
| 187 | mtype_list(const struct ip_set *set, | 195 | mtype_list(const struct ip_set *set, |
| 188 | struct sk_buff *skb, struct netlink_callback *cb) | 196 | struct sk_buff *skb, struct netlink_callback *cb) |
| @@ -215,25 +223,8 @@ mtype_list(const struct ip_set *set, | |||
| 215 | } | 223 | } |
| 216 | if (mtype_do_list(skb, map, id, set->dsize)) | 224 | if (mtype_do_list(skb, map, id, set->dsize)) |
| 217 | goto nla_put_failure; | 225 | goto nla_put_failure; |
| 218 | if (SET_WITH_TIMEOUT(set)) { | 226 | if (ip_set_put_extensions(skb, set, x, |
| 219 | #ifdef IP_SET_BITMAP_STORED_TIMEOUT | 227 | mtype_is_filled((const struct mtype_elem *) x))) |
| 220 | if (nla_put_net32(skb, IPSET_ATTR_TIMEOUT, | ||
| 221 | htonl(ip_set_timeout_stored(map, id, | ||
| 222 | ext_timeout(x, set), | ||
| 223 | set->dsize)))) | ||
| 224 | goto nla_put_failure; | ||
| 225 | #else | ||
| 226 | if (nla_put_net32(skb, IPSET_ATTR_TIMEOUT, | ||
| 227 | htonl(ip_set_timeout_get( | ||
| 228 | ext_timeout(x, set))))) | ||
| 229 | goto nla_put_failure; | ||
| 230 | #endif | ||
| 231 | } | ||
| 232 | if (SET_WITH_COUNTER(set) && | ||
| 233 | ip_set_put_counter(skb, ext_counter(x, set))) | ||
| 234 | goto nla_put_failure; | ||
| 235 | if (SET_WITH_COMMENT(set) && | ||
| 236 | ip_set_put_comment(skb, ext_comment(x, set))) | ||
| 237 | goto nla_put_failure; | 228 | goto nla_put_failure; |
| 238 | ipset_nest_end(skb, nested); | 229 | ipset_nest_end(skb, nested); |
| 239 | } | 230 | } |
diff --git a/net/netfilter/ipset/ip_set_bitmap_ipmac.c b/net/netfilter/ipset/ip_set_bitmap_ipmac.c index fb4d163dea82..87a218f8ab5f 100644 --- a/net/netfilter/ipset/ip_set_bitmap_ipmac.c +++ b/net/netfilter/ipset/ip_set_bitmap_ipmac.c | |||
| @@ -176,17 +176,6 @@ bitmap_ipmac_do_del(const struct bitmap_ipmac_adt_elem *e, | |||
| 176 | return !test_and_clear_bit(e->id, map->members); | 176 | return !test_and_clear_bit(e->id, map->members); |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | static inline unsigned long | ||
| 180 | ip_set_timeout_stored(struct bitmap_ipmac *map, u32 id, unsigned long *timeout, | ||
| 181 | size_t dsize) | ||
| 182 | { | ||
| 183 | const struct bitmap_ipmac_elem *elem = | ||
| 184 | get_elem(map->extensions, id, dsize); | ||
| 185 | |||
| 186 | return elem->filled == MAC_FILLED ? ip_set_timeout_get(timeout) : | ||
| 187 | *timeout; | ||
| 188 | } | ||
| 189 | |||
| 190 | static inline int | 179 | static inline int |
| 191 | bitmap_ipmac_do_list(struct sk_buff *skb, const struct bitmap_ipmac *map, | 180 | bitmap_ipmac_do_list(struct sk_buff *skb, const struct bitmap_ipmac *map, |
| 192 | u32 id, size_t dsize) | 181 | u32 id, size_t dsize) |
diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h index 1cffeb977605..b4add206c603 100644 --- a/net/netfilter/ipset/ip_set_hash_gen.h +++ b/net/netfilter/ipset/ip_set_hash_gen.h | |||
| @@ -961,16 +961,7 @@ mtype_list(const struct ip_set *set, | |||
| 961 | } | 961 | } |
| 962 | if (mtype_data_list(skb, e)) | 962 | if (mtype_data_list(skb, e)) |
| 963 | goto nla_put_failure; | 963 | goto nla_put_failure; |
| 964 | if (SET_WITH_TIMEOUT(set) && | 964 | if (ip_set_put_extensions(skb, set, e, true)) |
| 965 | nla_put_net32(skb, IPSET_ATTR_TIMEOUT, | ||
| 966 | htonl(ip_set_timeout_get( | ||
| 967 | ext_timeout(e, set))))) | ||
| 968 | goto nla_put_failure; | ||
| 969 | if (SET_WITH_COUNTER(set) && | ||
| 970 | ip_set_put_counter(skb, ext_counter(e, set))) | ||
| 971 | goto nla_put_failure; | ||
| 972 | if (SET_WITH_COMMENT(set) && | ||
| 973 | ip_set_put_comment(skb, ext_comment(e, set))) | ||
| 974 | goto nla_put_failure; | 965 | goto nla_put_failure; |
| 975 | ipset_nest_end(skb, nested); | 966 | ipset_nest_end(skb, nested); |
| 976 | } | 967 | } |
diff --git a/net/netfilter/ipset/ip_set_list_set.c b/net/netfilter/ipset/ip_set_list_set.c index e23f33c14435..ba4232e451f4 100644 --- a/net/netfilter/ipset/ip_set_list_set.c +++ b/net/netfilter/ipset/ip_set_list_set.c | |||
| @@ -512,16 +512,7 @@ list_set_list(const struct ip_set *set, | |||
| 512 | if (nla_put_string(skb, IPSET_ATTR_NAME, | 512 | if (nla_put_string(skb, IPSET_ATTR_NAME, |
| 513 | ip_set_name_byindex(e->id))) | 513 | ip_set_name_byindex(e->id))) |
| 514 | goto nla_put_failure; | 514 | goto nla_put_failure; |
| 515 | if (SET_WITH_TIMEOUT(set) && | 515 | if (ip_set_put_extensions(skb, set, e, true)) |
| 516 | nla_put_net32(skb, IPSET_ATTR_TIMEOUT, | ||
| 517 | htonl(ip_set_timeout_get( | ||
| 518 | ext_timeout(e, set))))) | ||
| 519 | goto nla_put_failure; | ||
| 520 | if (SET_WITH_COUNTER(set) && | ||
| 521 | ip_set_put_counter(skb, ext_counter(e, set))) | ||
| 522 | goto nla_put_failure; | ||
| 523 | if (SET_WITH_COMMENT(set) && | ||
| 524 | ip_set_put_comment(skb, ext_comment(e, set))) | ||
| 525 | goto nla_put_failure; | 516 | goto nla_put_failure; |
| 526 | ipset_nest_end(skb, nested); | 517 | ipset_nest_end(skb, nested); |
| 527 | } | 518 | } |
