Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 6253
b: refs/heads/master
c: 304a161
h: refs/heads/master
i:
  6251: 18d5526
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo authored and David S. Miller committed Aug 29, 2005
1 parent b74351b commit b40851d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0597f2680d666a3bcf101ac0c771ba7e50016bbd
refs/heads/master: 304a16180fb6d2b153b45f6fbbcec1fa814496e5
40 changes: 40 additions & 0 deletions trunk/include/net/inet_hashtables.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* INET An implementation of the TCP/IP protocol suite for the LINUX
* operating system. INET is implemented using the BSD Socket
* interface as the means of communication with the user level.
*
* Authors: Lotsa people, from code originally in tcp
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/

#ifndef _INET_HASHTABLES_H
#define _INET_HASHTABLES_H

#include <linux/types.h>

static inline int inet_ehashfn(const __u32 laddr, const __u16 lport,
const __u32 faddr, const __u16 fport,
const int ehash_size)
{
int h = (laddr ^ lport) ^ (faddr ^ fport);
h ^= h >> 16;
h ^= h >> 8;
return h & (ehash_size - 1);
}

static inline int inet_sk_ehashfn(const struct sock *sk, const int ehash_size)
{
const struct inet_sock *inet = inet_sk(sk);
const __u32 laddr = inet->rcv_saddr;
const __u16 lport = inet->num;
const __u32 faddr = inet->daddr;
const __u16 fport = inet->dport;

return inet_ehashfn(laddr, lport, faddr, fport, ehash_size);
}

#endif /* _INET_HASHTABLES_H */
28 changes: 5 additions & 23 deletions trunk/net/ipv4/tcp_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include <linux/times.h>

#include <net/icmp.h>
#include <net/inet_hashtables.h>
#include <net/tcp.h>
#include <net/ipv6.h>
#include <net/inet_common.h>
Expand Down Expand Up @@ -104,26 +105,6 @@ struct tcp_hashinfo __cacheline_aligned tcp_hashinfo = {
int sysctl_local_port_range[2] = { 1024, 4999 };
int tcp_port_rover = 1024 - 1;

static __inline__ int tcp_hashfn(__u32 laddr, __u16 lport,
__u32 faddr, __u16 fport)
{
int h = (laddr ^ lport) ^ (faddr ^ fport);
h ^= h >> 16;
h ^= h >> 8;
return h & (tcp_ehash_size - 1);
}

static __inline__ int tcp_sk_hashfn(struct sock *sk)
{
struct inet_sock *inet = inet_sk(sk);
__u32 laddr = inet->rcv_saddr;
__u16 lport = inet->num;
__u32 faddr = inet->daddr;
__u16 fport = inet->dport;

return tcp_hashfn(laddr, lport, faddr, fport);
}

/* Allocate and initialize a new TCP local port bind bucket.
* The bindhash mutex for snum's hash chain must be held here.
*/
Expand Down Expand Up @@ -367,7 +348,8 @@ static __inline__ void __tcp_v4_hash(struct sock *sk, const int listen_possible)
lock = &tcp_lhash_lock;
tcp_listen_wlock();
} else {
list = &tcp_ehash[(sk->sk_hashent = tcp_sk_hashfn(sk))].chain;
sk->sk_hashent = inet_sk_ehashfn(sk, tcp_ehash_size);
list = &tcp_ehash[sk->sk_hashent].chain;
lock = &tcp_ehash[sk->sk_hashent].lock;
write_lock(lock);
}
Expand Down Expand Up @@ -500,7 +482,7 @@ static inline struct sock *__tcp_v4_lookup_established(u32 saddr, u16 sport,
/* Optimize here for direct hit, only listening connections can
* have wildcards anyways.
*/
int hash = tcp_hashfn(daddr, hnum, saddr, sport);
const int hash = inet_ehashfn(daddr, hnum, saddr, sport, tcp_ehash_size);
head = &tcp_ehash[hash];
read_lock(&head->lock);
sk_for_each(sk, node, &head->chain) {
Expand Down Expand Up @@ -563,7 +545,7 @@ static int __tcp_v4_check_established(struct sock *sk, __u16 lport,
int dif = sk->sk_bound_dev_if;
TCP_V4_ADDR_COOKIE(acookie, saddr, daddr)
__u32 ports = TCP_COMBINED_PORTS(inet->dport, lport);
int hash = tcp_hashfn(daddr, lport, saddr, inet->dport);
const int hash = inet_ehashfn(daddr, lport, saddr, inet->dport, tcp_ehash_size);
struct tcp_ehash_bucket *head = &tcp_ehash[hash];
struct sock *sk2;
struct hlist_node *node;
Expand Down

0 comments on commit b40851d

Please sign in to comment.