aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYOSHIFUJI Hideaki / 吉藤英明 <yoshfuji@linux-ipv6.org>2013-01-29 07:48:50 -0500
committerDavid S. Miller <davem@davemloft.net>2013-01-29 22:58:40 -0500
commit70e94e66aec255aff276397f5ed3f3626c548f1c (patch)
treef8a266b768f73394271a58a90b7d8375705079df
parentff88b30c717f21dffba6784cae4d3287da16f6ef (diff)
xfrm: Convert xfrm_addr_cmp() to boolean xfrm_addr_equal().
All users of xfrm_addr_cmp() use its result as boolean. Introduce xfrm_addr_equal() (which is equal to !xfrm_addr_cmp()) and convert all users. Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/xfrm.h25
-rw-r--r--net/key/af_key.c8
-rw-r--r--net/xfrm/xfrm_policy.c24
-rw-r--r--net/xfrm/xfrm_state.c34
-rw-r--r--net/xfrm/xfrm_user.c2
5 files changed, 46 insertions, 47 deletions
diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 0d8a797f0441..de34883e8b16 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -1574,27 +1574,26 @@ extern struct xfrm_algo_desc *xfrm_calg_get_byname(const char *name, int probe);
1574extern struct xfrm_algo_desc *xfrm_aead_get_byname(const char *name, int icv_len, 1574extern struct xfrm_algo_desc *xfrm_aead_get_byname(const char *name, int icv_len,
1575 int probe); 1575 int probe);
1576 1576
1577static inline int xfrm_addr_cmp(const xfrm_address_t *a, 1577static inline bool xfrm6_addr_equal(const xfrm_address_t *a,
1578 const xfrm_address_t *b, 1578 const xfrm_address_t *b)
1579 int family) 1579{
1580 return ipv6_addr_equal((const struct in6_addr *)a,
1581 (const struct in6_addr *)b);
1582}
1583
1584static inline bool xfrm_addr_equal(const xfrm_address_t *a,
1585 const xfrm_address_t *b,
1586 sa_family_t family)
1580{ 1587{
1581 switch (family) { 1588 switch (family) {
1582 default: 1589 default:
1583 case AF_INET: 1590 case AF_INET:
1584 return (__force u32)a->a4 - (__force u32)b->a4; 1591 return ((__force u32)a->a4 ^ (__force u32)b->a4) == 0;
1585 case AF_INET6: 1592 case AF_INET6:
1586 return ipv6_addr_cmp((const struct in6_addr *)a, 1593 return xfrm6_addr_equal(a, b);
1587 (const struct in6_addr *)b);
1588 } 1594 }
1589} 1595}
1590 1596
1591static inline bool xfrm6_addr_equal(const xfrm_address_t *a,
1592 const xfrm_address_t *b)
1593{
1594 return ipv6_addr_equal((const struct in6_addr *)a,
1595 (const struct in6_addr *)b);
1596}
1597
1598static inline int xfrm_policy_id2dir(u32 index) 1597static inline int xfrm_policy_id2dir(u32 index)
1599{ 1598{
1600 return index & 7; 1599 return index & 7;
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 5b426a646544..cc2630ac8061 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -762,7 +762,7 @@ static struct sk_buff *__pfkey_xfrm_state2msg(const struct xfrm_state *x,
762 } 762 }
763 763
764 /* identity & sensitivity */ 764 /* identity & sensitivity */
765 if (xfrm_addr_cmp(&x->sel.saddr, &x->props.saddr, x->props.family)) 765 if (!xfrm_addr_equal(&x->sel.saddr, &x->props.saddr, x->props.family))
766 size += sizeof(struct sadb_address) + sockaddr_size; 766 size += sizeof(struct sadb_address) + sockaddr_size;
767 767
768 if (add_keys) { 768 if (add_keys) {
@@ -909,8 +909,8 @@ static struct sk_buff *__pfkey_xfrm_state2msg(const struct xfrm_state *x,
909 if (!addr->sadb_address_prefixlen) 909 if (!addr->sadb_address_prefixlen)
910 BUG(); 910 BUG();
911 911
912 if (xfrm_addr_cmp(&x->sel.saddr, &x->props.saddr, 912 if (!xfrm_addr_equal(&x->sel.saddr, &x->props.saddr,
913 x->props.family)) { 913 x->props.family)) {
914 addr = (struct sadb_address*) skb_put(skb, 914 addr = (struct sadb_address*) skb_put(skb,
915 sizeof(struct sadb_address)+sockaddr_size); 915 sizeof(struct sadb_address)+sockaddr_size);
916 addr->sadb_address_len = 916 addr->sadb_address_len =
@@ -1321,7 +1321,7 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, const struct sadb_
1321 1321
1322 if (hdr->sadb_msg_seq) { 1322 if (hdr->sadb_msg_seq) {
1323 x = xfrm_find_acq_byseq(net, DUMMY_MARK, hdr->sadb_msg_seq); 1323 x = xfrm_find_acq_byseq(net, DUMMY_MARK, hdr->sadb_msg_seq);
1324 if (x && xfrm_addr_cmp(&x->id.daddr, xdaddr, family)) { 1324 if (x && !xfrm_addr_equal(&x->id.daddr, xdaddr, family)) {
1325 xfrm_state_put(x); 1325 xfrm_state_put(x);
1326 x = NULL; 1326 x = NULL;
1327 } 1327 }
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 07c585756d2a..6c9aa642a2ba 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -2786,10 +2786,10 @@ static bool xfrm_migrate_selector_match(const struct xfrm_selector *sel_cmp,
2786{ 2786{
2787 if (sel_cmp->proto == IPSEC_ULPROTO_ANY) { 2787 if (sel_cmp->proto == IPSEC_ULPROTO_ANY) {
2788 if (sel_tgt->family == sel_cmp->family && 2788 if (sel_tgt->family == sel_cmp->family &&
2789 xfrm_addr_cmp(&sel_tgt->daddr, &sel_cmp->daddr, 2789 xfrm_addr_equal(&sel_tgt->daddr, &sel_cmp->daddr,
2790 sel_cmp->family) == 0 && 2790 sel_cmp->family) &&
2791 xfrm_addr_cmp(&sel_tgt->saddr, &sel_cmp->saddr, 2791 xfrm_addr_equal(&sel_tgt->saddr, &sel_cmp->saddr,
2792 sel_cmp->family) == 0 && 2792 sel_cmp->family) &&
2793 sel_tgt->prefixlen_d == sel_cmp->prefixlen_d && 2793 sel_tgt->prefixlen_d == sel_cmp->prefixlen_d &&
2794 sel_tgt->prefixlen_s == sel_cmp->prefixlen_s) { 2794 sel_tgt->prefixlen_s == sel_cmp->prefixlen_s) {
2795 return true; 2795 return true;
@@ -2847,10 +2847,10 @@ static int migrate_tmpl_match(const struct xfrm_migrate *m, const struct xfrm_tm
2847 switch (t->mode) { 2847 switch (t->mode) {
2848 case XFRM_MODE_TUNNEL: 2848 case XFRM_MODE_TUNNEL:
2849 case XFRM_MODE_BEET: 2849 case XFRM_MODE_BEET:
2850 if (xfrm_addr_cmp(&t->id.daddr, &m->old_daddr, 2850 if (xfrm_addr_equal(&t->id.daddr, &m->old_daddr,
2851 m->old_family) == 0 && 2851 m->old_family) &&
2852 xfrm_addr_cmp(&t->saddr, &m->old_saddr, 2852 xfrm_addr_equal(&t->saddr, &m->old_saddr,
2853 m->old_family) == 0) { 2853 m->old_family)) {
2854 match = 1; 2854 match = 1;
2855 } 2855 }
2856 break; 2856 break;
@@ -2916,10 +2916,10 @@ static int xfrm_migrate_check(const struct xfrm_migrate *m, int num_migrate)
2916 return -EINVAL; 2916 return -EINVAL;
2917 2917
2918 for (i = 0; i < num_migrate; i++) { 2918 for (i = 0; i < num_migrate; i++) {
2919 if ((xfrm_addr_cmp(&m[i].old_daddr, &m[i].new_daddr, 2919 if (xfrm_addr_equal(&m[i].old_daddr, &m[i].new_daddr,
2920 m[i].old_family) == 0) && 2920 m[i].old_family) &&
2921 (xfrm_addr_cmp(&m[i].old_saddr, &m[i].new_saddr, 2921 xfrm_addr_equal(&m[i].old_saddr, &m[i].new_saddr,
2922 m[i].old_family) == 0)) 2922 m[i].old_family))
2923 return -EINVAL; 2923 return -EINVAL;
2924 if (xfrm_addr_any(&m[i].new_daddr, m[i].new_family) || 2924 if (xfrm_addr_any(&m[i].new_daddr, m[i].new_family) ||
2925 xfrm_addr_any(&m[i].new_saddr, m[i].new_family)) 2925 xfrm_addr_any(&m[i].new_saddr, m[i].new_family))
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 0adae918a7a2..ae01bdbcb294 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -691,7 +691,7 @@ static struct xfrm_state *__xfrm_state_lookup(struct net *net, u32 mark,
691 if (x->props.family != family || 691 if (x->props.family != family ||
692 x->id.spi != spi || 692 x->id.spi != spi ||
693 x->id.proto != proto || 693 x->id.proto != proto ||
694 xfrm_addr_cmp(&x->id.daddr, daddr, family)) 694 !xfrm_addr_equal(&x->id.daddr, daddr, family))
695 continue; 695 continue;
696 696
697 if ((mark & x->mark.m) != x->mark.v) 697 if ((mark & x->mark.m) != x->mark.v)
@@ -715,8 +715,8 @@ static struct xfrm_state *__xfrm_state_lookup_byaddr(struct net *net, u32 mark,
715 hlist_for_each_entry(x, entry, net->xfrm.state_bysrc+h, bysrc) { 715 hlist_for_each_entry(x, entry, net->xfrm.state_bysrc+h, bysrc) {
716 if (x->props.family != family || 716 if (x->props.family != family ||
717 x->id.proto != proto || 717 x->id.proto != proto ||
718 xfrm_addr_cmp(&x->id.daddr, daddr, family) || 718 !xfrm_addr_equal(&x->id.daddr, daddr, family) ||
719 xfrm_addr_cmp(&x->props.saddr, saddr, family)) 719 !xfrm_addr_equal(&x->props.saddr, saddr, family))
720 continue; 720 continue;
721 721
722 if ((mark & x->mark.m) != x->mark.v) 722 if ((mark & x->mark.m) != x->mark.v)
@@ -981,8 +981,8 @@ static void __xfrm_state_bump_genids(struct xfrm_state *xnew)
981 if (x->props.family == family && 981 if (x->props.family == family &&
982 x->props.reqid == reqid && 982 x->props.reqid == reqid &&
983 (mark & x->mark.m) == x->mark.v && 983 (mark & x->mark.m) == x->mark.v &&
984 !xfrm_addr_cmp(&x->id.daddr, &xnew->id.daddr, family) && 984 xfrm_addr_equal(&x->id.daddr, &xnew->id.daddr, family) &&
985 !xfrm_addr_cmp(&x->props.saddr, &xnew->props.saddr, family)) 985 xfrm_addr_equal(&x->props.saddr, &xnew->props.saddr, family))
986 x->genid++; 986 x->genid++;
987 } 987 }
988} 988}
@@ -1016,8 +1016,8 @@ static struct xfrm_state *__find_acq_core(struct net *net, struct xfrm_mark *m,
1016 x->id.spi != 0 || 1016 x->id.spi != 0 ||
1017 x->id.proto != proto || 1017 x->id.proto != proto ||
1018 (mark & x->mark.m) != x->mark.v || 1018 (mark & x->mark.m) != x->mark.v ||
1019 xfrm_addr_cmp(&x->id.daddr, daddr, family) || 1019 !xfrm_addr_equal(&x->id.daddr, daddr, family) ||
1020 xfrm_addr_cmp(&x->props.saddr, saddr, family)) 1020 !xfrm_addr_equal(&x->props.saddr, saddr, family))
1021 continue; 1021 continue;
1022 1022
1023 xfrm_state_hold(x); 1023 xfrm_state_hold(x);
@@ -1100,7 +1100,7 @@ int xfrm_state_add(struct xfrm_state *x)
1100 if (use_spi && x->km.seq) { 1100 if (use_spi && x->km.seq) {
1101 x1 = __xfrm_find_acq_byseq(net, mark, x->km.seq); 1101 x1 = __xfrm_find_acq_byseq(net, mark, x->km.seq);
1102 if (x1 && ((x1->id.proto != x->id.proto) || 1102 if (x1 && ((x1->id.proto != x->id.proto) ||
1103 xfrm_addr_cmp(&x1->id.daddr, &x->id.daddr, family))) { 1103 !xfrm_addr_equal(&x1->id.daddr, &x->id.daddr, family))) {
1104 to_put = x1; 1104 to_put = x1;
1105 x1 = NULL; 1105 x1 = NULL;
1106 } 1106 }
@@ -1226,10 +1226,10 @@ struct xfrm_state * xfrm_migrate_state_find(struct xfrm_migrate *m)
1226 continue; 1226 continue;
1227 if (m->reqid && x->props.reqid != m->reqid) 1227 if (m->reqid && x->props.reqid != m->reqid)
1228 continue; 1228 continue;
1229 if (xfrm_addr_cmp(&x->id.daddr, &m->old_daddr, 1229 if (!xfrm_addr_equal(&x->id.daddr, &m->old_daddr,
1230 m->old_family) || 1230 m->old_family) ||
1231 xfrm_addr_cmp(&x->props.saddr, &m->old_saddr, 1231 !xfrm_addr_equal(&x->props.saddr, &m->old_saddr,
1232 m->old_family)) 1232 m->old_family))
1233 continue; 1233 continue;
1234 xfrm_state_hold(x); 1234 xfrm_state_hold(x);
1235 return x; 1235 return x;
@@ -1241,10 +1241,10 @@ struct xfrm_state * xfrm_migrate_state_find(struct xfrm_migrate *m)
1241 if (x->props.mode != m->mode || 1241 if (x->props.mode != m->mode ||
1242 x->id.proto != m->proto) 1242 x->id.proto != m->proto)
1243 continue; 1243 continue;
1244 if (xfrm_addr_cmp(&x->id.daddr, &m->old_daddr, 1244 if (!xfrm_addr_equal(&x->id.daddr, &m->old_daddr,
1245 m->old_family) || 1245 m->old_family) ||
1246 xfrm_addr_cmp(&x->props.saddr, &m->old_saddr, 1246 !xfrm_addr_equal(&x->props.saddr, &m->old_saddr,
1247 m->old_family)) 1247 m->old_family))
1248 continue; 1248 continue;
1249 xfrm_state_hold(x); 1249 xfrm_state_hold(x);
1250 return x; 1250 return x;
@@ -1269,7 +1269,7 @@ struct xfrm_state * xfrm_state_migrate(struct xfrm_state *x,
1269 memcpy(&xc->props.saddr, &m->new_saddr, sizeof(xc->props.saddr)); 1269 memcpy(&xc->props.saddr, &m->new_saddr, sizeof(xc->props.saddr));
1270 1270
1271 /* add state */ 1271 /* add state */
1272 if (!xfrm_addr_cmp(&x->id.daddr, &m->new_daddr, m->new_family)) { 1272 if (xfrm_addr_equal(&x->id.daddr, &m->new_daddr, m->new_family)) {
1273 /* a care is needed when the destination address of the 1273 /* a care is needed when the destination address of the
1274 state is to be updated as it is a part of triplet */ 1274 state is to be updated as it is a part of triplet */
1275 xfrm_state_insert(xc); 1275 xfrm_state_insert(xc);
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index eb872b2e366e..fbd9e6cd0fd7 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -1112,7 +1112,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
1112 mark = xfrm_mark_get(attrs, &m); 1112 mark = xfrm_mark_get(attrs, &m);
1113 if (p->info.seq) { 1113 if (p->info.seq) {
1114 x = xfrm_find_acq_byseq(net, mark, p->info.seq); 1114 x = xfrm_find_acq_byseq(net, mark, p->info.seq);
1115 if (x && xfrm_addr_cmp(&x->id.daddr, daddr, family)) { 1115 if (x && !xfrm_addr_equal(&x->id.daddr, daddr, family)) {
1116 xfrm_state_put(x); 1116 xfrm_state_put(x);
1117 x = NULL; 1117 x = NULL;
1118 } 1118 }