diff options
Diffstat (limited to 'net/ipv4/inet_hashtables.c')
-rw-r--r-- | net/ipv4/inet_hashtables.c | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index 150ace18dc75..fb662621c54e 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c | |||
@@ -262,7 +262,7 @@ not_unique: | |||
262 | static inline u32 inet_sk_port_offset(const struct sock *sk) | 262 | static inline u32 inet_sk_port_offset(const struct sock *sk) |
263 | { | 263 | { |
264 | const struct inet_sock *inet = inet_sk(sk); | 264 | const struct inet_sock *inet = inet_sk(sk); |
265 | return secure_ipv4_port_ephemeral(inet->rcv_saddr, inet->daddr, | 265 | return secure_ipv4_port_ephemeral(inet->rcv_saddr, inet->daddr, |
266 | inet->dport); | 266 | inet->dport); |
267 | } | 267 | } |
268 | 268 | ||
@@ -274,81 +274,81 @@ int inet_hash_connect(struct inet_timewait_death_row *death_row, | |||
274 | { | 274 | { |
275 | struct inet_hashinfo *hinfo = death_row->hashinfo; | 275 | struct inet_hashinfo *hinfo = death_row->hashinfo; |
276 | const unsigned short snum = inet_sk(sk)->num; | 276 | const unsigned short snum = inet_sk(sk)->num; |
277 | struct inet_bind_hashbucket *head; | 277 | struct inet_bind_hashbucket *head; |
278 | struct inet_bind_bucket *tb; | 278 | struct inet_bind_bucket *tb; |
279 | int ret; | 279 | int ret; |
280 | 280 | ||
281 | if (!snum) { | 281 | if (!snum) { |
282 | int low = sysctl_local_port_range[0]; | 282 | int low = sysctl_local_port_range[0]; |
283 | int high = sysctl_local_port_range[1]; | 283 | int high = sysctl_local_port_range[1]; |
284 | int range = high - low; | 284 | int range = high - low; |
285 | int i; | 285 | int i; |
286 | int port; | 286 | int port; |
287 | static u32 hint; | 287 | static u32 hint; |
288 | u32 offset = hint + inet_sk_port_offset(sk); | 288 | u32 offset = hint + inet_sk_port_offset(sk); |
289 | struct hlist_node *node; | 289 | struct hlist_node *node; |
290 | struct inet_timewait_sock *tw = NULL; | 290 | struct inet_timewait_sock *tw = NULL; |
291 | 291 | ||
292 | local_bh_disable(); | 292 | local_bh_disable(); |
293 | for (i = 1; i <= range; i++) { | 293 | for (i = 1; i <= range; i++) { |
294 | port = low + (i + offset) % range; | 294 | port = low + (i + offset) % range; |
295 | head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; | 295 | head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; |
296 | spin_lock(&head->lock); | 296 | spin_lock(&head->lock); |
297 | 297 | ||
298 | /* Does not bother with rcv_saddr checks, | 298 | /* Does not bother with rcv_saddr checks, |
299 | * because the established check is already | 299 | * because the established check is already |
300 | * unique enough. | 300 | * unique enough. |
301 | */ | 301 | */ |
302 | inet_bind_bucket_for_each(tb, node, &head->chain) { | 302 | inet_bind_bucket_for_each(tb, node, &head->chain) { |
303 | if (tb->port == port) { | 303 | if (tb->port == port) { |
304 | BUG_TRAP(!hlist_empty(&tb->owners)); | 304 | BUG_TRAP(!hlist_empty(&tb->owners)); |
305 | if (tb->fastreuse >= 0) | 305 | if (tb->fastreuse >= 0) |
306 | goto next_port; | 306 | goto next_port; |
307 | if (!__inet_check_established(death_row, | 307 | if (!__inet_check_established(death_row, |
308 | sk, port, | 308 | sk, port, |
309 | &tw)) | 309 | &tw)) |
310 | goto ok; | 310 | goto ok; |
311 | goto next_port; | 311 | goto next_port; |
312 | } | 312 | } |
313 | } | 313 | } |
314 | 314 | ||
315 | tb = inet_bind_bucket_create(hinfo->bind_bucket_cachep, head, port); | 315 | tb = inet_bind_bucket_create(hinfo->bind_bucket_cachep, head, port); |
316 | if (!tb) { | 316 | if (!tb) { |
317 | spin_unlock(&head->lock); | 317 | spin_unlock(&head->lock); |
318 | break; | 318 | break; |
319 | } | 319 | } |
320 | tb->fastreuse = -1; | 320 | tb->fastreuse = -1; |
321 | goto ok; | 321 | goto ok; |
322 | 322 | ||
323 | next_port: | 323 | next_port: |
324 | spin_unlock(&head->lock); | 324 | spin_unlock(&head->lock); |
325 | } | 325 | } |
326 | local_bh_enable(); | 326 | local_bh_enable(); |
327 | 327 | ||
328 | return -EADDRNOTAVAIL; | 328 | return -EADDRNOTAVAIL; |
329 | 329 | ||
330 | ok: | 330 | ok: |
331 | hint += i; | 331 | hint += i; |
332 | 332 | ||
333 | /* Head lock still held and bh's disabled */ | 333 | /* Head lock still held and bh's disabled */ |
334 | inet_bind_hash(sk, tb, port); | 334 | inet_bind_hash(sk, tb, port); |
335 | if (sk_unhashed(sk)) { | 335 | if (sk_unhashed(sk)) { |
336 | inet_sk(sk)->sport = htons(port); | 336 | inet_sk(sk)->sport = htons(port); |
337 | __inet_hash(hinfo, sk, 0); | 337 | __inet_hash(hinfo, sk, 0); |
338 | } | 338 | } |
339 | spin_unlock(&head->lock); | 339 | spin_unlock(&head->lock); |
340 | 340 | ||
341 | if (tw) { | 341 | if (tw) { |
342 | inet_twsk_deschedule(tw, death_row); | 342 | inet_twsk_deschedule(tw, death_row); |
343 | inet_twsk_put(tw); | 343 | inet_twsk_put(tw); |
344 | } | 344 | } |
345 | 345 | ||
346 | ret = 0; | 346 | ret = 0; |
347 | goto out; | 347 | goto out; |
348 | } | 348 | } |
349 | 349 | ||
350 | head = &hinfo->bhash[inet_bhashfn(snum, hinfo->bhash_size)]; | 350 | head = &hinfo->bhash[inet_bhashfn(snum, hinfo->bhash_size)]; |
351 | tb = inet_csk(sk)->icsk_bind_hash; | 351 | tb = inet_csk(sk)->icsk_bind_hash; |
352 | spin_lock_bh(&head->lock); | 352 | spin_lock_bh(&head->lock); |
353 | if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) { | 353 | if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) { |
354 | __inet_hash(hinfo, sk, 0); | 354 | __inet_hash(hinfo, sk, 0); |