aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2011-01-14 09:45:56 -0500
committerPatrick McHardy <kaber@trash.net>2011-01-14 09:45:56 -0500
commitd862a6622e9db508d4b28cc7c5bc28bd548cc24e (patch)
treed0d65ef88e8f158a33c370a0f1a6f98b41191d6c
parent0134e89c7bcc9fde1da962c82a120691e185619f (diff)
netfilter: nf_conntrack: use is_vmalloc_addr()
Use is_vmalloc_addr() in nf_ct_free_hashtable() and get rid of the vmalloc flags to indicate that a hash table has been allocated using vmalloc(). Signed-off-by: Patrick McHardy <kaber@trash.net>
-rw-r--r--include/net/netfilter/nf_conntrack.h4
-rw-r--r--include/net/netns/conntrack.h2
-rw-r--r--include/net/netns/ipv4.h1
-rw-r--r--net/ipv4/netfilter/nf_nat_core.c6
-rw-r--r--net/netfilter/nf_conntrack_core.c26
-rw-r--r--net/netfilter/nf_conntrack_expect.c9
-rw-r--r--net/netfilter/nf_conntrack_helper.c10
7 files changed, 19 insertions, 39 deletions
diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index 2bc344c98215..d0d13378991e 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -202,9 +202,9 @@ extern void nf_ct_l3proto_module_put(unsigned short l3proto);
202 * Allocate a hashtable of hlist_head (if nulls == 0), 202 * Allocate a hashtable of hlist_head (if nulls == 0),
203 * or hlist_nulls_head (if nulls == 1) 203 * or hlist_nulls_head (if nulls == 1)
204 */ 204 */
205extern void *nf_ct_alloc_hashtable(unsigned int *sizep, int *vmalloced, int nulls); 205extern void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls);
206 206
207extern void nf_ct_free_hashtable(void *hash, int vmalloced, unsigned int size); 207extern void nf_ct_free_hashtable(void *hash, unsigned int size);
208 208
209extern struct nf_conntrack_tuple_hash * 209extern struct nf_conntrack_tuple_hash *
210__nf_conntrack_find(struct net *net, u16 zone, 210__nf_conntrack_find(struct net *net, u16 zone,
diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
index d4958d4c6574..5cf8a8c141aa 100644
--- a/include/net/netns/conntrack.h
+++ b/include/net/netns/conntrack.h
@@ -28,8 +28,6 @@ struct netns_ct {
28 struct ctl_table_header *acct_sysctl_header; 28 struct ctl_table_header *acct_sysctl_header;
29 struct ctl_table_header *event_sysctl_header; 29 struct ctl_table_header *event_sysctl_header;
30#endif 30#endif
31 int hash_vmalloc;
32 int expect_vmalloc;
33 char *slabname; 31 char *slabname;
34}; 32};
35#endif 33#endif
diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index d68c3f121774..e2e2ef57eca2 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -43,7 +43,6 @@ struct netns_ipv4 {
43 struct xt_table *nat_table; 43 struct xt_table *nat_table;
44 struct hlist_head *nat_bysource; 44 struct hlist_head *nat_bysource;
45 unsigned int nat_htable_size; 45 unsigned int nat_htable_size;
46 int nat_vmalloced;
47#endif 46#endif
48 47
49 int sysctl_icmp_echo_ignore_all; 48 int sysctl_icmp_echo_ignore_all;
diff --git a/net/ipv4/netfilter/nf_nat_core.c b/net/ipv4/netfilter/nf_nat_core.c
index eb55835a02c3..6972ceee99c6 100644
--- a/net/ipv4/netfilter/nf_nat_core.c
+++ b/net/ipv4/netfilter/nf_nat_core.c
@@ -682,8 +682,7 @@ static int __net_init nf_nat_net_init(struct net *net)
682{ 682{
683 /* Leave them the same for the moment. */ 683 /* Leave them the same for the moment. */
684 net->ipv4.nat_htable_size = net->ct.htable_size; 684 net->ipv4.nat_htable_size = net->ct.htable_size;
685 net->ipv4.nat_bysource = nf_ct_alloc_hashtable(&net->ipv4.nat_htable_size, 685 net->ipv4.nat_bysource = nf_ct_alloc_hashtable(&net->ipv4.nat_htable_size, 0);
686 &net->ipv4.nat_vmalloced, 0);
687 if (!net->ipv4.nat_bysource) 686 if (!net->ipv4.nat_bysource)
688 return -ENOMEM; 687 return -ENOMEM;
689 return 0; 688 return 0;
@@ -705,8 +704,7 @@ static void __net_exit nf_nat_net_exit(struct net *net)
705{ 704{
706 nf_ct_iterate_cleanup(net, &clean_nat, NULL); 705 nf_ct_iterate_cleanup(net, &clean_nat, NULL);
707 synchronize_rcu(); 706 synchronize_rcu();
708 nf_ct_free_hashtable(net->ipv4.nat_bysource, net->ipv4.nat_vmalloced, 707 nf_ct_free_hashtable(net->ipv4.nat_bysource, net->ipv4.nat_htable_size);
709 net->ipv4.nat_htable_size);
710} 708}
711 709
712static struct pernet_operations nf_nat_net_ops = { 710static struct pernet_operations nf_nat_net_ops = {
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index e95ac42ef673..dc2ff2cd0a7e 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -1202,9 +1202,9 @@ static int kill_all(struct nf_conn *i, void *data)
1202 return 1; 1202 return 1;
1203} 1203}
1204 1204
1205void nf_ct_free_hashtable(void *hash, int vmalloced, unsigned int size) 1205void nf_ct_free_hashtable(void *hash, unsigned int size)
1206{ 1206{
1207 if (vmalloced) 1207 if (is_vmalloc_addr(hash))
1208 vfree(hash); 1208 vfree(hash);
1209 else 1209 else
1210 free_pages((unsigned long)hash, 1210 free_pages((unsigned long)hash,
@@ -1271,8 +1271,7 @@ static void nf_conntrack_cleanup_net(struct net *net)
1271 goto i_see_dead_people; 1271 goto i_see_dead_people;
1272 } 1272 }
1273 1273
1274 nf_ct_free_hashtable(net->ct.hash, net->ct.hash_vmalloc, 1274 nf_ct_free_hashtable(net->ct.hash, net->ct.htable_size);
1275 net->ct.htable_size);
1276 nf_conntrack_ecache_fini(net); 1275 nf_conntrack_ecache_fini(net);
1277 nf_conntrack_acct_fini(net); 1276 nf_conntrack_acct_fini(net);
1278 nf_conntrack_expect_fini(net); 1277 nf_conntrack_expect_fini(net);
@@ -1301,21 +1300,18 @@ void nf_conntrack_cleanup(struct net *net)
1301 } 1300 }
1302} 1301}
1303 1302
1304void *nf_ct_alloc_hashtable(unsigned int *sizep, int *vmalloced, int nulls) 1303void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls)
1305{ 1304{
1306 struct hlist_nulls_head *hash; 1305 struct hlist_nulls_head *hash;
1307 unsigned int nr_slots, i; 1306 unsigned int nr_slots, i;
1308 size_t sz; 1307 size_t sz;
1309 1308
1310 *vmalloced = 0;
1311
1312 BUILD_BUG_ON(sizeof(struct hlist_nulls_head) != sizeof(struct hlist_head)); 1309 BUILD_BUG_ON(sizeof(struct hlist_nulls_head) != sizeof(struct hlist_head));
1313 nr_slots = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct hlist_nulls_head)); 1310 nr_slots = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct hlist_nulls_head));
1314 sz = nr_slots * sizeof(struct hlist_nulls_head); 1311 sz = nr_slots * sizeof(struct hlist_nulls_head);
1315 hash = (void *)__get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, 1312 hash = (void *)__get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
1316 get_order(sz)); 1313 get_order(sz));
1317 if (!hash) { 1314 if (!hash) {
1318 *vmalloced = 1;
1319 printk(KERN_WARNING "nf_conntrack: falling back to vmalloc.\n"); 1315 printk(KERN_WARNING "nf_conntrack: falling back to vmalloc.\n");
1320 hash = __vmalloc(sz, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, 1316 hash = __vmalloc(sz, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
1321 PAGE_KERNEL); 1317 PAGE_KERNEL);
@@ -1331,7 +1327,7 @@ EXPORT_SYMBOL_GPL(nf_ct_alloc_hashtable);
1331 1327
1332int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp) 1328int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp)
1333{ 1329{
1334 int i, bucket, vmalloced, old_vmalloced; 1330 int i, bucket;
1335 unsigned int hashsize, old_size; 1331 unsigned int hashsize, old_size;
1336 struct hlist_nulls_head *hash, *old_hash; 1332 struct hlist_nulls_head *hash, *old_hash;
1337 struct nf_conntrack_tuple_hash *h; 1333 struct nf_conntrack_tuple_hash *h;
@@ -1348,7 +1344,7 @@ int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp)
1348 if (!hashsize) 1344 if (!hashsize)
1349 return -EINVAL; 1345 return -EINVAL;
1350 1346
1351 hash = nf_ct_alloc_hashtable(&hashsize, &vmalloced, 1); 1347 hash = nf_ct_alloc_hashtable(&hashsize, 1);
1352 if (!hash) 1348 if (!hash)
1353 return -ENOMEM; 1349 return -ENOMEM;
1354 1350
@@ -1370,15 +1366,13 @@ int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp)
1370 } 1366 }
1371 } 1367 }
1372 old_size = init_net.ct.htable_size; 1368 old_size = init_net.ct.htable_size;
1373 old_vmalloced = init_net.ct.hash_vmalloc;
1374 old_hash = init_net.ct.hash; 1369 old_hash = init_net.ct.hash;
1375 1370
1376 init_net.ct.htable_size = nf_conntrack_htable_size = hashsize; 1371 init_net.ct.htable_size = nf_conntrack_htable_size = hashsize;
1377 init_net.ct.hash_vmalloc = vmalloced;
1378 init_net.ct.hash = hash; 1372 init_net.ct.hash = hash;
1379 spin_unlock_bh(&nf_conntrack_lock); 1373 spin_unlock_bh(&nf_conntrack_lock);
1380 1374
1381 nf_ct_free_hashtable(old_hash, old_vmalloced, old_size); 1375 nf_ct_free_hashtable(old_hash, old_size);
1382 return 0; 1376 return 0;
1383} 1377}
1384EXPORT_SYMBOL_GPL(nf_conntrack_set_hashsize); 1378EXPORT_SYMBOL_GPL(nf_conntrack_set_hashsize);
@@ -1491,8 +1485,7 @@ static int nf_conntrack_init_net(struct net *net)
1491 } 1485 }
1492 1486
1493 net->ct.htable_size = nf_conntrack_htable_size; 1487 net->ct.htable_size = nf_conntrack_htable_size;
1494 net->ct.hash = nf_ct_alloc_hashtable(&net->ct.htable_size, 1488 net->ct.hash = nf_ct_alloc_hashtable(&net->ct.htable_size, 1);
1495 &net->ct.hash_vmalloc, 1);
1496 if (!net->ct.hash) { 1489 if (!net->ct.hash) {
1497 ret = -ENOMEM; 1490 ret = -ENOMEM;
1498 printk(KERN_ERR "Unable to create nf_conntrack_hash\n"); 1491 printk(KERN_ERR "Unable to create nf_conntrack_hash\n");
@@ -1515,8 +1508,7 @@ err_ecache:
1515err_acct: 1508err_acct:
1516 nf_conntrack_expect_fini(net); 1509 nf_conntrack_expect_fini(net);
1517err_expect: 1510err_expect:
1518 nf_ct_free_hashtable(net->ct.hash, net->ct.hash_vmalloc, 1511 nf_ct_free_hashtable(net->ct.hash, net->ct.htable_size);
1519 net->ct.htable_size);
1520err_hash: 1512err_hash:
1521 kmem_cache_destroy(net->ct.nf_conntrack_cachep); 1513 kmem_cache_destroy(net->ct.nf_conntrack_cachep);
1522err_cache: 1514err_cache:
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index 4a9ed23180df..cd1e8e0970f2 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -639,8 +639,7 @@ int nf_conntrack_expect_init(struct net *net)
639 } 639 }
640 640
641 net->ct.expect_count = 0; 641 net->ct.expect_count = 0;
642 net->ct.expect_hash = nf_ct_alloc_hashtable(&nf_ct_expect_hsize, 642 net->ct.expect_hash = nf_ct_alloc_hashtable(&nf_ct_expect_hsize, 0);
643 &net->ct.expect_vmalloc, 0);
644 if (net->ct.expect_hash == NULL) 643 if (net->ct.expect_hash == NULL)
645 goto err1; 644 goto err1;
646 645
@@ -662,8 +661,7 @@ err3:
662 if (net_eq(net, &init_net)) 661 if (net_eq(net, &init_net))
663 kmem_cache_destroy(nf_ct_expect_cachep); 662 kmem_cache_destroy(nf_ct_expect_cachep);
664err2: 663err2:
665 nf_ct_free_hashtable(net->ct.expect_hash, net->ct.expect_vmalloc, 664 nf_ct_free_hashtable(net->ct.expect_hash, nf_ct_expect_hsize);
666 nf_ct_expect_hsize);
667err1: 665err1:
668 return err; 666 return err;
669} 667}
@@ -675,6 +673,5 @@ void nf_conntrack_expect_fini(struct net *net)
675 rcu_barrier(); /* Wait for call_rcu() before destroy */ 673 rcu_barrier(); /* Wait for call_rcu() before destroy */
676 kmem_cache_destroy(nf_ct_expect_cachep); 674 kmem_cache_destroy(nf_ct_expect_cachep);
677 } 675 }
678 nf_ct_free_hashtable(net->ct.expect_hash, net->ct.expect_vmalloc, 676 nf_ct_free_hashtable(net->ct.expect_hash, nf_ct_expect_hsize);
679 nf_ct_expect_hsize);
680} 677}
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index 767bbe98a0f0..1bdfea357955 100644
--- a/net/netfilter/nf_conntrack_helper.c
+++ b/net/netfilter/nf_conntrack_helper.c
@@ -33,7 +33,6 @@ static DEFINE_MUTEX(nf_ct_helper_mutex);
33static struct hlist_head *nf_ct_helper_hash __read_mostly; 33static struct hlist_head *nf_ct_helper_hash __read_mostly;
34static unsigned int nf_ct_helper_hsize __read_mostly; 34static unsigned int nf_ct_helper_hsize __read_mostly;
35static unsigned int nf_ct_helper_count __read_mostly; 35static unsigned int nf_ct_helper_count __read_mostly;
36static int nf_ct_helper_vmalloc;
37 36
38 37
39/* Stupid hash, but collision free for the default registrations of the 38/* Stupid hash, but collision free for the default registrations of the
@@ -267,8 +266,7 @@ int nf_conntrack_helper_init(void)
267 int err; 266 int err;
268 267
269 nf_ct_helper_hsize = 1; /* gets rounded up to use one page */ 268 nf_ct_helper_hsize = 1; /* gets rounded up to use one page */
270 nf_ct_helper_hash = nf_ct_alloc_hashtable(&nf_ct_helper_hsize, 269 nf_ct_helper_hash = nf_ct_alloc_hashtable(&nf_ct_helper_hsize, 0);
271 &nf_ct_helper_vmalloc, 0);
272 if (!nf_ct_helper_hash) 270 if (!nf_ct_helper_hash)
273 return -ENOMEM; 271 return -ENOMEM;
274 272
@@ -279,14 +277,12 @@ int nf_conntrack_helper_init(void)
279 return 0; 277 return 0;
280 278
281err1: 279err1:
282 nf_ct_free_hashtable(nf_ct_helper_hash, nf_ct_helper_vmalloc, 280 nf_ct_free_hashtable(nf_ct_helper_hash, nf_ct_helper_hsize);
283 nf_ct_helper_hsize);
284 return err; 281 return err;
285} 282}
286 283
287void nf_conntrack_helper_fini(void) 284void nf_conntrack_helper_fini(void)
288{ 285{
289 nf_ct_extend_unregister(&helper_extend); 286 nf_ct_extend_unregister(&helper_extend);
290 nf_ct_free_hashtable(nf_ct_helper_hash, nf_ct_helper_vmalloc, 287 nf_ct_free_hashtable(nf_ct_helper_hash, nf_ct_helper_hsize);
291 nf_ct_helper_hsize);
292} 288}