aboutsummaryrefslogtreecommitdiffstats
path: root/net/xfrm/xfrm_state.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/xfrm/xfrm_state.c')
-rw-r--r--net/xfrm/xfrm_state.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 9f63edd39346..f927b7330f02 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -70,7 +70,7 @@ static inline unsigned int xfrm_src_hash(xfrm_address_t *addr,
70} 70}
71 71
72static inline unsigned int 72static inline unsigned int
73xfrm_spi_hash(xfrm_address_t *daddr, u32 spi, u8 proto, unsigned short family) 73xfrm_spi_hash(xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family)
74{ 74{
75 return __xfrm_spi_hash(daddr, spi, proto, family, xfrm_state_hmask); 75 return __xfrm_spi_hash(daddr, spi, proto, family, xfrm_state_hmask);
76} 76}
@@ -96,9 +96,12 @@ static void xfrm_hash_transfer(struct hlist_head *list,
96 nhashmask); 96 nhashmask);
97 hlist_add_head(&x->bysrc, nsrctable+h); 97 hlist_add_head(&x->bysrc, nsrctable+h);
98 98
99 h = __xfrm_spi_hash(&x->id.daddr, x->id.spi, x->id.proto, 99 if (x->id.spi) {
100 x->props.family, nhashmask); 100 h = __xfrm_spi_hash(&x->id.daddr, x->id.spi,
101 hlist_add_head(&x->byspi, nspitable+h); 101 x->id.proto, x->props.family,
102 nhashmask);
103 hlist_add_head(&x->byspi, nspitable+h);
104 }
102 } 105 }
103} 106}
104 107
@@ -421,7 +424,7 @@ xfrm_init_tempsel(struct xfrm_state *x, struct flowi *fl,
421 return 0; 424 return 0;
422} 425}
423 426
424static struct xfrm_state *__xfrm_state_lookup(xfrm_address_t *daddr, u32 spi, u8 proto, unsigned short family) 427static struct xfrm_state *__xfrm_state_lookup(xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family)
425{ 428{
426 unsigned int h = xfrm_spi_hash(daddr, spi, proto, family); 429 unsigned int h = xfrm_spi_hash(daddr, spi, proto, family);
427 struct xfrm_state *x; 430 struct xfrm_state *x;
@@ -622,7 +625,7 @@ static void __xfrm_state_insert(struct xfrm_state *x)
622 h = xfrm_src_hash(&x->props.saddr, x->props.family); 625 h = xfrm_src_hash(&x->props.saddr, x->props.family);
623 hlist_add_head(&x->bysrc, xfrm_state_bysrc+h); 626 hlist_add_head(&x->bysrc, xfrm_state_bysrc+h);
624 627
625 if (xfrm_id_proto_match(x->id.proto, IPSEC_PROTO_ANY)) { 628 if (x->id.spi) {
626 h = xfrm_spi_hash(&x->id.daddr, x->id.spi, x->id.proto, 629 h = xfrm_spi_hash(&x->id.daddr, x->id.spi, x->id.proto,
627 x->props.family); 630 x->props.family);
628 631
@@ -916,7 +919,7 @@ err:
916EXPORT_SYMBOL(xfrm_state_check); 919EXPORT_SYMBOL(xfrm_state_check);
917 920
918struct xfrm_state * 921struct xfrm_state *
919xfrm_state_lookup(xfrm_address_t *daddr, u32 spi, u8 proto, 922xfrm_state_lookup(xfrm_address_t *daddr, __be32 spi, u8 proto,
920 unsigned short family) 923 unsigned short family)
921{ 924{
922 struct xfrm_state *x; 925 struct xfrm_state *x;
@@ -1040,7 +1043,7 @@ u32 xfrm_get_acqseq(void)
1040EXPORT_SYMBOL(xfrm_get_acqseq); 1043EXPORT_SYMBOL(xfrm_get_acqseq);
1041 1044
1042void 1045void
1043xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi) 1046xfrm_alloc_spi(struct xfrm_state *x, __be32 minspi, __be32 maxspi)
1044{ 1047{
1045 unsigned int h; 1048 unsigned int h;
1046 struct xfrm_state *x0; 1049 struct xfrm_state *x0;
@@ -1057,10 +1060,10 @@ xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi)
1057 x->id.spi = minspi; 1060 x->id.spi = minspi;
1058 } else { 1061 } else {
1059 u32 spi = 0; 1062 u32 spi = 0;
1060 minspi = ntohl(minspi); 1063 u32 low = ntohl(minspi);
1061 maxspi = ntohl(maxspi); 1064 u32 high = ntohl(maxspi);
1062 for (h=0; h<maxspi-minspi+1; h++) { 1065 for (h=0; h<high-low+1; h++) {
1063 spi = minspi + net_random()%(maxspi-minspi+1); 1066 spi = low + net_random()%(high-low+1);
1064 x0 = xfrm_state_lookup(&x->id.daddr, htonl(spi), x->id.proto, x->props.family); 1067 x0 = xfrm_state_lookup(&x->id.daddr, htonl(spi), x->id.proto, x->props.family);
1065 if (x0 == NULL) { 1068 if (x0 == NULL) {
1066 x->id.spi = htonl(spi); 1069 x->id.spi = htonl(spi);
@@ -1180,11 +1183,10 @@ static void xfrm_replay_timer_handler(unsigned long data)
1180 spin_unlock(&x->lock); 1183 spin_unlock(&x->lock);
1181} 1184}
1182 1185
1183int xfrm_replay_check(struct xfrm_state *x, u32 seq) 1186int xfrm_replay_check(struct xfrm_state *x, __be32 net_seq)
1184{ 1187{
1185 u32 diff; 1188 u32 diff;
1186 1189 u32 seq = ntohl(net_seq);
1187 seq = ntohl(seq);
1188 1190
1189 if (unlikely(seq == 0)) 1191 if (unlikely(seq == 0))
1190 return -EINVAL; 1192 return -EINVAL;
@@ -1206,11 +1208,10 @@ int xfrm_replay_check(struct xfrm_state *x, u32 seq)
1206} 1208}
1207EXPORT_SYMBOL(xfrm_replay_check); 1209EXPORT_SYMBOL(xfrm_replay_check);
1208 1210
1209void xfrm_replay_advance(struct xfrm_state *x, u32 seq) 1211void xfrm_replay_advance(struct xfrm_state *x, __be32 net_seq)
1210{ 1212{
1211 u32 diff; 1213 u32 diff;
1212 1214 u32 seq = ntohl(net_seq);
1213 seq = ntohl(seq);
1214 1215
1215 if (seq > x->replay.seq) { 1216 if (seq > x->replay.seq) {
1216 diff = seq - x->replay.seq; 1217 diff = seq - x->replay.seq;