aboutsummaryrefslogtreecommitdiffstats
path: root/net/xfrm/xfrm_state.c
diff options
context:
space:
mode:
authorSasha Levin <sasha.levin@oracle.com>2013-02-27 20:06:00 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 22:10:24 -0500
commitb67bfe0d42cac56c512dd5da4b1b347a23f4b70a (patch)
tree3d465aea12b97683f26ffa38eba8744469de9997 /net/xfrm/xfrm_state.c
parent1e142b29e210b5dfb2deeb6ce2210b60af16d2a6 (diff)
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived list_for_each_entry(pos, head, member) The hlist ones were greedy and wanted an extra parameter: hlist_for_each_entry(tpos, pos, head, member) Why did they need an extra pos parameter? I'm not quite sure. Not only they don't really need it, it also prevents the iterator from looking exactly like the list iterator, which is unfortunate. Besides the semantic patch, there was some manual work required: - Fix up the actual hlist iterators in linux/list.h - Fix up the declaration of other iterators based on the hlist ones. - A very small amount of places were using the 'node' parameter, this was modified to use 'obj->member' instead. - Coccinelle didn't handle the hlist_for_each_entry_safe iterator properly, so those had to be fixed up manually. The semantic patch which is mostly the work of Peter Senna Tschudin is here: @@ iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host; type T; expression a,c,d,e; identifier b; statement S; @@ -T b; <+... when != b ( hlist_for_each_entry(a, - b, c, d) S | hlist_for_each_entry_continue(a, - b, c) S | hlist_for_each_entry_from(a, - b, c) S | hlist_for_each_entry_rcu(a, - b, c, d) S | hlist_for_each_entry_rcu_bh(a, - b, c, d) S | hlist_for_each_entry_continue_rcu_bh(a, - b, c) S | for_each_busy_worker(a, c, - b, d) S | ax25_uid_for_each(a, - b, c) S | ax25_for_each(a, - b, c) S | inet_bind_bucket_for_each(a, - b, c) S | sctp_for_each_hentry(a, - b, c) S | sk_for_each(a, - b, c) S | sk_for_each_rcu(a, - b, c) S | sk_for_each_from -(a, b) +(a) S + sk_for_each_from(a) S | sk_for_each_safe(a, - b, c, d) S | sk_for_each_bound(a, - b, c) S | hlist_for_each_entry_safe(a, - b, c, d, e) S | hlist_for_each_entry_continue_rcu(a, - b, c) S | nr_neigh_for_each(a, - b, c) S | nr_neigh_for_each_safe(a, - b, c, d) S | nr_node_for_each(a, - b, c) S | nr_node_for_each_safe(a, - b, c, d) S | - for_each_gfn_sp(a, c, d, b) S + for_each_gfn_sp(a, c, d) S | - for_each_gfn_indirect_valid_sp(a, c, d, b) S + for_each_gfn_indirect_valid_sp(a, c, d) S | for_each_host(a, - b, c) S | for_each_host_safe(a, - b, c, d) S | for_each_mesh_entry(a, - b, c, d) S ) ...+> [akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c] [akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c] [akpm@linux-foundation.org: checkpatch fixes] [akpm@linux-foundation.org: fix warnings] [akpm@linux-foudnation.org: redo intrusive kvm changes] Tested-by: Peter Senna Tschudin <peter.senna@gmail.com> Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Signed-off-by: Sasha Levin <sasha.levin@oracle.com> Cc: Wu Fengguang <fengguang.wu@intel.com> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Gleb Natapov <gleb@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'net/xfrm/xfrm_state.c')
-rw-r--r--net/xfrm/xfrm_state.c42
1 files changed, 16 insertions, 26 deletions
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index ae01bdbcb294..2c341bdaf47c 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -72,10 +72,10 @@ static void xfrm_hash_transfer(struct hlist_head *list,
72 struct hlist_head *nspitable, 72 struct hlist_head *nspitable,
73 unsigned int nhashmask) 73 unsigned int nhashmask)
74{ 74{
75 struct hlist_node *entry, *tmp; 75 struct hlist_node *tmp;
76 struct xfrm_state *x; 76 struct xfrm_state *x;
77 77
78 hlist_for_each_entry_safe(x, entry, tmp, list, bydst) { 78 hlist_for_each_entry_safe(x, tmp, list, bydst) {
79 unsigned int h; 79 unsigned int h;
80 80
81 h = __xfrm_dst_hash(&x->id.daddr, &x->props.saddr, 81 h = __xfrm_dst_hash(&x->id.daddr, &x->props.saddr,
@@ -368,14 +368,14 @@ static void xfrm_state_gc_task(struct work_struct *work)
368{ 368{
369 struct net *net = container_of(work, struct net, xfrm.state_gc_work); 369 struct net *net = container_of(work, struct net, xfrm.state_gc_work);
370 struct xfrm_state *x; 370 struct xfrm_state *x;
371 struct hlist_node *entry, *tmp; 371 struct hlist_node *tmp;
372 struct hlist_head gc_list; 372 struct hlist_head gc_list;
373 373
374 spin_lock_bh(&xfrm_state_gc_lock); 374 spin_lock_bh(&xfrm_state_gc_lock);
375 hlist_move_list(&net->xfrm.state_gc_list, &gc_list); 375 hlist_move_list(&net->xfrm.state_gc_list, &gc_list);
376 spin_unlock_bh(&xfrm_state_gc_lock); 376 spin_unlock_bh(&xfrm_state_gc_lock);
377 377
378 hlist_for_each_entry_safe(x, entry, tmp, &gc_list, gclist) 378 hlist_for_each_entry_safe(x, tmp, &gc_list, gclist)
379 xfrm_state_gc_destroy(x); 379 xfrm_state_gc_destroy(x);
380 380
381 wake_up(&net->xfrm.km_waitq); 381 wake_up(&net->xfrm.km_waitq);
@@ -577,10 +577,9 @@ xfrm_state_flush_secctx_check(struct net *net, u8 proto, struct xfrm_audit *audi
577 int i, err = 0; 577 int i, err = 0;
578 578
579 for (i = 0; i <= net->xfrm.state_hmask; i++) { 579 for (i = 0; i <= net->xfrm.state_hmask; i++) {
580 struct hlist_node *entry;
581 struct xfrm_state *x; 580 struct xfrm_state *x;
582 581
583 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+i, bydst) { 582 hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
584 if (xfrm_id_proto_match(x->id.proto, proto) && 583 if (xfrm_id_proto_match(x->id.proto, proto) &&
585 (err = security_xfrm_state_delete(x)) != 0) { 584 (err = security_xfrm_state_delete(x)) != 0) {
586 xfrm_audit_state_delete(x, 0, 585 xfrm_audit_state_delete(x, 0,
@@ -613,10 +612,9 @@ int xfrm_state_flush(struct net *net, u8 proto, struct xfrm_audit *audit_info)
613 612
614 err = -ESRCH; 613 err = -ESRCH;
615 for (i = 0; i <= net->xfrm.state_hmask; i++) { 614 for (i = 0; i <= net->xfrm.state_hmask; i++) {
616 struct hlist_node *entry;
617 struct xfrm_state *x; 615 struct xfrm_state *x;
618restart: 616restart:
619 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+i, bydst) { 617 hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
620 if (!xfrm_state_kern(x) && 618 if (!xfrm_state_kern(x) &&
621 xfrm_id_proto_match(x->id.proto, proto)) { 619 xfrm_id_proto_match(x->id.proto, proto)) {
622 xfrm_state_hold(x); 620 xfrm_state_hold(x);
@@ -685,9 +683,8 @@ static struct xfrm_state *__xfrm_state_lookup(struct net *net, u32 mark,
685{ 683{
686 unsigned int h = xfrm_spi_hash(net, daddr, spi, proto, family); 684 unsigned int h = xfrm_spi_hash(net, daddr, spi, proto, family);
687 struct xfrm_state *x; 685 struct xfrm_state *x;
688 struct hlist_node *entry;
689 686
690 hlist_for_each_entry(x, entry, net->xfrm.state_byspi+h, byspi) { 687 hlist_for_each_entry(x, net->xfrm.state_byspi+h, byspi) {
691 if (x->props.family != family || 688 if (x->props.family != family ||
692 x->id.spi != spi || 689 x->id.spi != spi ||
693 x->id.proto != proto || 690 x->id.proto != proto ||
@@ -710,9 +707,8 @@ static struct xfrm_state *__xfrm_state_lookup_byaddr(struct net *net, u32 mark,
710{ 707{
711 unsigned int h = xfrm_src_hash(net, daddr, saddr, family); 708 unsigned int h = xfrm_src_hash(net, daddr, saddr, family);
712 struct xfrm_state *x; 709 struct xfrm_state *x;
713 struct hlist_node *entry;
714 710
715 hlist_for_each_entry(x, entry, net->xfrm.state_bysrc+h, bysrc) { 711 hlist_for_each_entry(x, net->xfrm.state_bysrc+h, bysrc) {
716 if (x->props.family != family || 712 if (x->props.family != family ||
717 x->id.proto != proto || 713 x->id.proto != proto ||
718 !xfrm_addr_equal(&x->id.daddr, daddr, family) || 714 !xfrm_addr_equal(&x->id.daddr, daddr, family) ||
@@ -798,7 +794,6 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
798 static xfrm_address_t saddr_wildcard = { }; 794 static xfrm_address_t saddr_wildcard = { };
799 struct net *net = xp_net(pol); 795 struct net *net = xp_net(pol);
800 unsigned int h, h_wildcard; 796 unsigned int h, h_wildcard;
801 struct hlist_node *entry;
802 struct xfrm_state *x, *x0, *to_put; 797 struct xfrm_state *x, *x0, *to_put;
803 int acquire_in_progress = 0; 798 int acquire_in_progress = 0;
804 int error = 0; 799 int error = 0;
@@ -810,7 +805,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
810 805
811 spin_lock_bh(&xfrm_state_lock); 806 spin_lock_bh(&xfrm_state_lock);
812 h = xfrm_dst_hash(net, daddr, saddr, tmpl->reqid, encap_family); 807 h = xfrm_dst_hash(net, daddr, saddr, tmpl->reqid, encap_family);
813 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) { 808 hlist_for_each_entry(x, net->xfrm.state_bydst+h, bydst) {
814 if (x->props.family == encap_family && 809 if (x->props.family == encap_family &&
815 x->props.reqid == tmpl->reqid && 810 x->props.reqid == tmpl->reqid &&
816 (mark & x->mark.m) == x->mark.v && 811 (mark & x->mark.m) == x->mark.v &&
@@ -826,7 +821,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
826 goto found; 821 goto found;
827 822
828 h_wildcard = xfrm_dst_hash(net, daddr, &saddr_wildcard, tmpl->reqid, encap_family); 823 h_wildcard = xfrm_dst_hash(net, daddr, &saddr_wildcard, tmpl->reqid, encap_family);
829 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h_wildcard, bydst) { 824 hlist_for_each_entry(x, net->xfrm.state_bydst+h_wildcard, bydst) {
830 if (x->props.family == encap_family && 825 if (x->props.family == encap_family &&
831 x->props.reqid == tmpl->reqid && 826 x->props.reqid == tmpl->reqid &&
832 (mark & x->mark.m) == x->mark.v && 827 (mark & x->mark.m) == x->mark.v &&
@@ -906,11 +901,10 @@ xfrm_stateonly_find(struct net *net, u32 mark,
906{ 901{
907 unsigned int h; 902 unsigned int h;
908 struct xfrm_state *rx = NULL, *x = NULL; 903 struct xfrm_state *rx = NULL, *x = NULL;
909 struct hlist_node *entry;
910 904
911 spin_lock(&xfrm_state_lock); 905 spin_lock(&xfrm_state_lock);
912 h = xfrm_dst_hash(net, daddr, saddr, reqid, family); 906 h = xfrm_dst_hash(net, daddr, saddr, reqid, family);
913 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) { 907 hlist_for_each_entry(x, net->xfrm.state_bydst+h, bydst) {
914 if (x->props.family == family && 908 if (x->props.family == family &&
915 x->props.reqid == reqid && 909 x->props.reqid == reqid &&
916 (mark & x->mark.m) == x->mark.v && 910 (mark & x->mark.m) == x->mark.v &&
@@ -972,12 +966,11 @@ static void __xfrm_state_bump_genids(struct xfrm_state *xnew)
972 unsigned short family = xnew->props.family; 966 unsigned short family = xnew->props.family;
973 u32 reqid = xnew->props.reqid; 967 u32 reqid = xnew->props.reqid;
974 struct xfrm_state *x; 968 struct xfrm_state *x;
975 struct hlist_node *entry;
976 unsigned int h; 969 unsigned int h;
977 u32 mark = xnew->mark.v & xnew->mark.m; 970 u32 mark = xnew->mark.v & xnew->mark.m;
978 971
979 h = xfrm_dst_hash(net, &xnew->id.daddr, &xnew->props.saddr, reqid, family); 972 h = xfrm_dst_hash(net, &xnew->id.daddr, &xnew->props.saddr, reqid, family);
980 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) { 973 hlist_for_each_entry(x, net->xfrm.state_bydst+h, bydst) {
981 if (x->props.family == family && 974 if (x->props.family == family &&
982 x->props.reqid == reqid && 975 x->props.reqid == reqid &&
983 (mark & x->mark.m) == x->mark.v && 976 (mark & x->mark.m) == x->mark.v &&
@@ -1004,11 +997,10 @@ static struct xfrm_state *__find_acq_core(struct net *net, struct xfrm_mark *m,
1004 const xfrm_address_t *saddr, int create) 997 const xfrm_address_t *saddr, int create)
1005{ 998{
1006 unsigned int h = xfrm_dst_hash(net, daddr, saddr, reqid, family); 999 unsigned int h = xfrm_dst_hash(net, daddr, saddr, reqid, family);
1007 struct hlist_node *entry;
1008 struct xfrm_state *x; 1000 struct xfrm_state *x;
1009 u32 mark = m->v & m->m; 1001 u32 mark = m->v & m->m;
1010 1002
1011 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+h, bydst) { 1003 hlist_for_each_entry(x, net->xfrm.state_bydst+h, bydst) {
1012 if (x->props.reqid != reqid || 1004 if (x->props.reqid != reqid ||
1013 x->props.mode != mode || 1005 x->props.mode != mode ||
1014 x->props.family != family || 1006 x->props.family != family ||
@@ -1215,12 +1207,11 @@ struct xfrm_state * xfrm_migrate_state_find(struct xfrm_migrate *m)
1215{ 1207{
1216 unsigned int h; 1208 unsigned int h;
1217 struct xfrm_state *x; 1209 struct xfrm_state *x;
1218 struct hlist_node *entry;
1219 1210
1220 if (m->reqid) { 1211 if (m->reqid) {
1221 h = xfrm_dst_hash(&init_net, &m->old_daddr, &m->old_saddr, 1212 h = xfrm_dst_hash(&init_net, &m->old_daddr, &m->old_saddr,
1222 m->reqid, m->old_family); 1213 m->reqid, m->old_family);
1223 hlist_for_each_entry(x, entry, init_net.xfrm.state_bydst+h, bydst) { 1214 hlist_for_each_entry(x, init_net.xfrm.state_bydst+h, bydst) {
1224 if (x->props.mode != m->mode || 1215 if (x->props.mode != m->mode ||
1225 x->id.proto != m->proto) 1216 x->id.proto != m->proto)
1226 continue; 1217 continue;
@@ -1237,7 +1228,7 @@ struct xfrm_state * xfrm_migrate_state_find(struct xfrm_migrate *m)
1237 } else { 1228 } else {
1238 h = xfrm_src_hash(&init_net, &m->old_daddr, &m->old_saddr, 1229 h = xfrm_src_hash(&init_net, &m->old_daddr, &m->old_saddr,
1239 m->old_family); 1230 m->old_family);
1240 hlist_for_each_entry(x, entry, init_net.xfrm.state_bysrc+h, bysrc) { 1231 hlist_for_each_entry(x, init_net.xfrm.state_bysrc+h, bysrc) {
1241 if (x->props.mode != m->mode || 1232 if (x->props.mode != m->mode ||
1242 x->id.proto != m->proto) 1233 x->id.proto != m->proto)
1243 continue; 1234 continue;
@@ -1466,10 +1457,9 @@ static struct xfrm_state *__xfrm_find_acq_byseq(struct net *net, u32 mark, u32 s
1466 int i; 1457 int i;
1467 1458
1468 for (i = 0; i <= net->xfrm.state_hmask; i++) { 1459 for (i = 0; i <= net->xfrm.state_hmask; i++) {
1469 struct hlist_node *entry;
1470 struct xfrm_state *x; 1460 struct xfrm_state *x;
1471 1461
1472 hlist_for_each_entry(x, entry, net->xfrm.state_bydst+i, bydst) { 1462 hlist_for_each_entry(x, net->xfrm.state_bydst+i, bydst) {
1473 if (x->km.seq == seq && 1463 if (x->km.seq == seq &&
1474 (mark & x->mark.m) == x->mark.v && 1464 (mark & x->mark.m) == x->mark.v &&
1475 x->km.state == XFRM_STATE_ACQ) { 1465 x->km.state == XFRM_STATE_ACQ) {