aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@ghostprotocols.net>2005-08-09 22:59:20 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2005-08-29 18:38:22 -0400
commit304a16180fb6d2b153b45f6fbbcec1fa814496e5 (patch)
tree3cf82b06fcf12480a49d89ead016cb60e50c36b3 /net/ipv4
parent0597f2680d666a3bcf101ac0c771ba7e50016bbd (diff)
[INET]: Move the TCP ehash functions to include/net/inet_hashtables.h
To be shared with DCCP (and others), this is the start of a series of patches that will expose the already generic TCP hash table routines. The few changes noticed when calling gcc -S before/after on a pentium4 were of this type: movl 40(%esp), %edx cmpl %esi, 472(%edx) je .L168 - pushl $291 + pushl $272 pushl $.LC0 pushl $.LC1 pushl $.LC2 [acme@toy net-2.6.14]$ size net/ipv4/tcp_ipv4.before.o net/ipv4/tcp_ipv4.after.o text data bss dec hex filename 17804 516 140 18460 481c net/ipv4/tcp_ipv4.before.o 17804 516 140 18460 481c net/ipv4/tcp_ipv4.after.o Holler if some weird architecture has issues with things like this 8) Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/tcp_ipv4.c28
1 files changed, 5 insertions, 23 deletions
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index ae6fad99a9a9..c03d7e9688c8 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -64,6 +64,7 @@
64#include <linux/times.h> 64#include <linux/times.h>
65 65
66#include <net/icmp.h> 66#include <net/icmp.h>
67#include <net/inet_hashtables.h>
67#include <net/tcp.h> 68#include <net/tcp.h>
68#include <net/ipv6.h> 69#include <net/ipv6.h>
69#include <net/inet_common.h> 70#include <net/inet_common.h>
@@ -104,26 +105,6 @@ struct tcp_hashinfo __cacheline_aligned tcp_hashinfo = {
104int sysctl_local_port_range[2] = { 1024, 4999 }; 105int sysctl_local_port_range[2] = { 1024, 4999 };
105int tcp_port_rover = 1024 - 1; 106int tcp_port_rover = 1024 - 1;
106 107
107static __inline__ int tcp_hashfn(__u32 laddr, __u16 lport,
108 __u32 faddr, __u16 fport)
109{
110 int h = (laddr ^ lport) ^ (faddr ^ fport);
111 h ^= h >> 16;
112 h ^= h >> 8;
113 return h & (tcp_ehash_size - 1);
114}
115
116static __inline__ int tcp_sk_hashfn(struct sock *sk)
117{
118 struct inet_sock *inet = inet_sk(sk);
119 __u32 laddr = inet->rcv_saddr;
120 __u16 lport = inet->num;
121 __u32 faddr = inet->daddr;
122 __u16 fport = inet->dport;
123
124 return tcp_hashfn(laddr, lport, faddr, fport);
125}
126
127/* Allocate and initialize a new TCP local port bind bucket. 108/* Allocate and initialize a new TCP local port bind bucket.
128 * The bindhash mutex for snum's hash chain must be held here. 109 * The bindhash mutex for snum's hash chain must be held here.
129 */ 110 */
@@ -367,7 +348,8 @@ static __inline__ void __tcp_v4_hash(struct sock *sk, const int listen_possible)
367 lock = &tcp_lhash_lock; 348 lock = &tcp_lhash_lock;
368 tcp_listen_wlock(); 349 tcp_listen_wlock();
369 } else { 350 } else {
370 list = &tcp_ehash[(sk->sk_hashent = tcp_sk_hashfn(sk))].chain; 351 sk->sk_hashent = inet_sk_ehashfn(sk, tcp_ehash_size);
352 list = &tcp_ehash[sk->sk_hashent].chain;
371 lock = &tcp_ehash[sk->sk_hashent].lock; 353 lock = &tcp_ehash[sk->sk_hashent].lock;
372 write_lock(lock); 354 write_lock(lock);
373 } 355 }
@@ -500,7 +482,7 @@ static inline struct sock *__tcp_v4_lookup_established(u32 saddr, u16 sport,
500 /* Optimize here for direct hit, only listening connections can 482 /* Optimize here for direct hit, only listening connections can
501 * have wildcards anyways. 483 * have wildcards anyways.
502 */ 484 */
503 int hash = tcp_hashfn(daddr, hnum, saddr, sport); 485 const int hash = inet_ehashfn(daddr, hnum, saddr, sport, tcp_ehash_size);
504 head = &tcp_ehash[hash]; 486 head = &tcp_ehash[hash];
505 read_lock(&head->lock); 487 read_lock(&head->lock);
506 sk_for_each(sk, node, &head->chain) { 488 sk_for_each(sk, node, &head->chain) {
@@ -563,7 +545,7 @@ static int __tcp_v4_check_established(struct sock *sk, __u16 lport,
563 int dif = sk->sk_bound_dev_if; 545 int dif = sk->sk_bound_dev_if;
564 TCP_V4_ADDR_COOKIE(acookie, saddr, daddr) 546 TCP_V4_ADDR_COOKIE(acookie, saddr, daddr)
565 __u32 ports = TCP_COMBINED_PORTS(inet->dport, lport); 547 __u32 ports = TCP_COMBINED_PORTS(inet->dport, lport);
566 int hash = tcp_hashfn(daddr, lport, saddr, inet->dport); 548 const int hash = inet_ehashfn(daddr, lport, saddr, inet->dport, tcp_ehash_size);
567 struct tcp_ehash_bucket *head = &tcp_ehash[hash]; 549 struct tcp_ehash_bucket *head = &tcp_ehash[hash];
568 struct sock *sk2; 550 struct sock *sk2;
569 struct hlist_node *node; 551 struct hlist_node *node;