diff options
| author | Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> | 2013-10-18 05:41:55 -0400 |
|---|---|---|
| committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-10-22 04:13:59 -0400 |
| commit | 93302880d8a3e5dc6b7da3f9825beb839152c940 (patch) | |
| tree | 695d00aceb4e46a58a915b3f2afe2c312019f125 | |
| parent | d86946d2c5b4e519ffe435c2deeb2c9436ceb04f (diff) | |
netfilter: ipset: Use netlink callback dump args only
Instead of cb->data, use callback dump args only and introduce symbolic
names instead of plain numbers at accessing the argument members.
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| -rw-r--r-- | include/linux/netfilter/ipset/ip_set.h | 10 | ||||
| -rw-r--r-- | net/netfilter/ipset/ip_set_bitmap_gen.h | 11 | ||||
| -rw-r--r-- | net/netfilter/ipset/ip_set_core.c | 70 | ||||
| -rw-r--r-- | net/netfilter/ipset/ip_set_hash_gen.h | 20 | ||||
| -rw-r--r-- | net/netfilter/ipset/ip_set_list_set.c | 11 |
5 files changed, 68 insertions, 54 deletions
diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h index 7967516adc0d..c7174b816674 100644 --- a/include/linux/netfilter/ipset/ip_set.h +++ b/include/linux/netfilter/ipset/ip_set.h | |||
| @@ -316,6 +316,16 @@ ip_set_init_counter(struct ip_set_counter *counter, | |||
| 316 | atomic64_set(&(counter)->packets, (long long)(ext->packets)); | 316 | atomic64_set(&(counter)->packets, (long long)(ext->packets)); |
| 317 | } | 317 | } |
| 318 | 318 | ||
| 319 | /* Netlink CB args */ | ||
| 320 | enum { | ||
| 321 | IPSET_CB_NET = 0, | ||
| 322 | IPSET_CB_DUMP, | ||
| 323 | IPSET_CB_INDEX, | ||
| 324 | IPSET_CB_ARG0, | ||
| 325 | IPSET_CB_ARG1, | ||
| 326 | IPSET_CB_ARG2, | ||
| 327 | }; | ||
| 328 | |||
| 319 | /* register and unregister set references */ | 329 | /* register and unregister set references */ |
| 320 | extern ip_set_id_t ip_set_get_byname(struct net *net, | 330 | extern ip_set_id_t ip_set_get_byname(struct net *net, |
| 321 | const char *name, struct ip_set **set); | 331 | const char *name, struct ip_set **set); |
diff --git a/net/netfilter/ipset/ip_set_bitmap_gen.h b/net/netfilter/ipset/ip_set_bitmap_gen.h index a13e15be7911..f2c7d83dc23f 100644 --- a/net/netfilter/ipset/ip_set_bitmap_gen.h +++ b/net/netfilter/ipset/ip_set_bitmap_gen.h | |||
| @@ -198,13 +198,14 @@ mtype_list(const struct ip_set *set, | |||
| 198 | struct mtype *map = set->data; | 198 | struct mtype *map = set->data; |
| 199 | struct nlattr *adt, *nested; | 199 | struct nlattr *adt, *nested; |
| 200 | void *x; | 200 | void *x; |
| 201 | u32 id, first = cb->args[2]; | 201 | u32 id, first = cb->args[IPSET_CB_ARG0]; |
| 202 | 202 | ||
| 203 | adt = ipset_nest_start(skb, IPSET_ATTR_ADT); | 203 | adt = ipset_nest_start(skb, IPSET_ATTR_ADT); |
| 204 | if (!adt) | 204 | if (!adt) |
| 205 | return -EMSGSIZE; | 205 | return -EMSGSIZE; |
| 206 | for (; cb->args[2] < map->elements; cb->args[2]++) { | 206 | for (; cb->args[IPSET_CB_ARG0] < map->elements; |
| 207 | id = cb->args[2]; | 207 | cb->args[IPSET_CB_ARG0]++) { |
| 208 | id = cb->args[IPSET_CB_ARG0]; | ||
| 208 | x = get_ext(set, map, id); | 209 | x = get_ext(set, map, id); |
| 209 | if (!test_bit(id, map->members) || | 210 | if (!test_bit(id, map->members) || |
| 210 | (SET_WITH_TIMEOUT(set) && | 211 | (SET_WITH_TIMEOUT(set) && |
| @@ -231,14 +232,14 @@ mtype_list(const struct ip_set *set, | |||
| 231 | ipset_nest_end(skb, adt); | 232 | ipset_nest_end(skb, adt); |
| 232 | 233 | ||
| 233 | /* Set listing finished */ | 234 | /* Set listing finished */ |
| 234 | cb->args[2] = 0; | 235 | cb->args[IPSET_CB_ARG0] = 0; |
| 235 | 236 | ||
| 236 | return 0; | 237 | return 0; |
| 237 | 238 | ||
| 238 | nla_put_failure: | 239 | nla_put_failure: |
| 239 | nla_nest_cancel(skb, nested); | 240 | nla_nest_cancel(skb, nested); |
| 240 | if (unlikely(id == first)) { | 241 | if (unlikely(id == first)) { |
| 241 | cb->args[2] = 0; | 242 | cb->args[IPSET_CB_ARG0] = 0; |
| 242 | return -EMSGSIZE; | 243 | return -EMSGSIZE; |
| 243 | } | 244 | } |
| 244 | ipset_nest_end(skb, adt); | 245 | ipset_nest_end(skb, adt); |
diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c index dc9284bdd2dd..bac7e01df67f 100644 --- a/net/netfilter/ipset/ip_set_core.c +++ b/net/netfilter/ipset/ip_set_core.c | |||
| @@ -1182,10 +1182,12 @@ ip_set_swap(struct sock *ctnl, struct sk_buff *skb, | |||
| 1182 | static int | 1182 | static int |
| 1183 | ip_set_dump_done(struct netlink_callback *cb) | 1183 | ip_set_dump_done(struct netlink_callback *cb) |
| 1184 | { | 1184 | { |
| 1185 | struct ip_set_net *inst = (struct ip_set_net *)cb->data; | 1185 | struct ip_set_net *inst = (struct ip_set_net *)cb->args[IPSET_CB_NET]; |
| 1186 | if (cb->args[2]) { | 1186 | if (cb->args[IPSET_CB_ARG0]) { |
| 1187 | pr_debug("release set %s\n", nfnl_set(inst, cb->args[1])->name); | 1187 | pr_debug("release set %s\n", |
| 1188 | __ip_set_put_byindex(inst, (ip_set_id_t) cb->args[1]); | 1188 | nfnl_set(inst, cb->args[IPSET_CB_INDEX])->name); |
| 1189 | __ip_set_put_byindex(inst, | ||
| 1190 | (ip_set_id_t) cb->args[IPSET_CB_INDEX]); | ||
| 1189 | } | 1191 | } |
| 1190 | return 0; | 1192 | return 0; |
| 1191 | } | 1193 | } |
| @@ -1203,7 +1205,7 @@ dump_attrs(struct nlmsghdr *nlh) | |||
| 1203 | } | 1205 | } |
| 1204 | 1206 | ||
| 1205 | static int | 1207 | static int |
| 1206 | dump_init(struct netlink_callback *cb) | 1208 | dump_init(struct netlink_callback *cb, struct ip_set_net *inst) |
| 1207 | { | 1209 | { |
| 1208 | struct nlmsghdr *nlh = nlmsg_hdr(cb->skb); | 1210 | struct nlmsghdr *nlh = nlmsg_hdr(cb->skb); |
| 1209 | int min_len = nlmsg_total_size(sizeof(struct nfgenmsg)); | 1211 | int min_len = nlmsg_total_size(sizeof(struct nfgenmsg)); |
| @@ -1211,15 +1213,15 @@ dump_init(struct netlink_callback *cb) | |||
| 1211 | struct nlattr *attr = (void *)nlh + min_len; | 1213 | struct nlattr *attr = (void *)nlh + min_len; |
| 1212 | u32 dump_type; | 1214 | u32 dump_type; |
| 1213 | ip_set_id_t index; | 1215 | ip_set_id_t index; |
| 1214 | struct ip_set_net *inst = (struct ip_set_net *)cb->data; | ||
| 1215 | 1216 | ||
| 1216 | /* Second pass, so parser can't fail */ | 1217 | /* Second pass, so parser can't fail */ |
| 1217 | nla_parse(cda, IPSET_ATTR_CMD_MAX, | 1218 | nla_parse(cda, IPSET_ATTR_CMD_MAX, |
| 1218 | attr, nlh->nlmsg_len - min_len, ip_set_setname_policy); | 1219 | attr, nlh->nlmsg_len - min_len, ip_set_setname_policy); |
| 1219 | 1220 | ||
| 1220 | /* cb->args[0] : dump single set/all sets | 1221 | /* cb->args[IPSET_CB_NET]: net namespace |
| 1221 | * [1] : set index | 1222 | * [IPSET_CB_DUMP]: dump single set/all sets |
| 1222 | * [..]: type specific | 1223 | * [IPSET_CB_INDEX]: set index |
| 1224 | * [IPSET_CB_ARG0]: type specific | ||
| 1223 | */ | 1225 | */ |
| 1224 | 1226 | ||
| 1225 | if (cda[IPSET_ATTR_SETNAME]) { | 1227 | if (cda[IPSET_ATTR_SETNAME]) { |
| @@ -1231,7 +1233,7 @@ dump_init(struct netlink_callback *cb) | |||
| 1231 | return -ENOENT; | 1233 | return -ENOENT; |
| 1232 | 1234 | ||
| 1233 | dump_type = DUMP_ONE; | 1235 | dump_type = DUMP_ONE; |
| 1234 | cb->args[1] = index; | 1236 | cb->args[IPSET_CB_INDEX] = index; |
| 1235 | } else | 1237 | } else |
| 1236 | dump_type = DUMP_ALL; | 1238 | dump_type = DUMP_ALL; |
| 1237 | 1239 | ||
| @@ -1239,7 +1241,8 @@ dump_init(struct netlink_callback *cb) | |||
| 1239 | u32 f = ip_set_get_h32(cda[IPSET_ATTR_FLAGS]); | 1241 | u32 f = ip_set_get_h32(cda[IPSET_ATTR_FLAGS]); |
| 1240 | dump_type |= (f << 16); | 1242 | dump_type |= (f << 16); |
| 1241 | } | 1243 | } |
| 1242 | cb->args[0] = dump_type; | 1244 | cb->args[IPSET_CB_NET] = (unsigned long)inst; |
| 1245 | cb->args[IPSET_CB_DUMP] = dump_type; | ||
| 1243 | 1246 | ||
| 1244 | return 0; | 1247 | return 0; |
| 1245 | } | 1248 | } |
| @@ -1251,12 +1254,12 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 1251 | struct ip_set *set = NULL; | 1254 | struct ip_set *set = NULL; |
| 1252 | struct nlmsghdr *nlh = NULL; | 1255 | struct nlmsghdr *nlh = NULL; |
| 1253 | unsigned int flags = NETLINK_CB(cb->skb).portid ? NLM_F_MULTI : 0; | 1256 | unsigned int flags = NETLINK_CB(cb->skb).portid ? NLM_F_MULTI : 0; |
| 1257 | struct ip_set_net *inst = ip_set_pernet(sock_net(skb->sk)); | ||
| 1254 | u32 dump_type, dump_flags; | 1258 | u32 dump_type, dump_flags; |
| 1255 | int ret = 0; | 1259 | int ret = 0; |
| 1256 | struct ip_set_net *inst = (struct ip_set_net *)cb->data; | ||
| 1257 | 1260 | ||
| 1258 | if (!cb->args[0]) { | 1261 | if (!cb->args[IPSET_CB_DUMP]) { |
| 1259 | ret = dump_init(cb); | 1262 | ret = dump_init(cb, inst); |
| 1260 | if (ret < 0) { | 1263 | if (ret < 0) { |
| 1261 | nlh = nlmsg_hdr(cb->skb); | 1264 | nlh = nlmsg_hdr(cb->skb); |
| 1262 | /* We have to create and send the error message | 1265 | /* We have to create and send the error message |
| @@ -1267,17 +1270,18 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 1267 | } | 1270 | } |
| 1268 | } | 1271 | } |
| 1269 | 1272 | ||
| 1270 | if (cb->args[1] >= inst->ip_set_max) | 1273 | if (cb->args[IPSET_CB_INDEX] >= inst->ip_set_max) |
| 1271 | goto out; | 1274 | goto out; |
| 1272 | 1275 | ||
| 1273 | dump_type = DUMP_TYPE(cb->args[0]); | 1276 | dump_type = DUMP_TYPE(cb->args[IPSET_CB_DUMP]); |
| 1274 | dump_flags = DUMP_FLAGS(cb->args[0]); | 1277 | dump_flags = DUMP_FLAGS(cb->args[IPSET_CB_DUMP]); |
