Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a55ebcc4 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by David S. Miller
Browse files

[INET]: Move bind_hash from tcp_sk to inet_sk



This should really be in a inet_connection_sock, but I'm leaving it
for a later optimization, when some more fields common to INET
transport protocols now in tcp_sk or inet_sk will be chunked out into
inet_connection_sock, for now its better to concentrate on getting the
changes in the core merged to leave the DCCP tree with only DCCP
specific code.

Next changesets will take advantage of this move to generalise things
like tcp_bind_hash, tcp_put_port, tcp_inherit_port, making the later
receive a inet_hashinfo parameter, and even __tcp_tw_hashdance, etc in
the future, when tcp_tw_bucket gets transformed into the struct
timewait_sock hierarchy.

tcp_destroy_sock also is eligible as soon as tcp_orphan_count gets
moved to sk_prot.

A cascade of incremental changes will ultimately make the tcp_lookup
functions be fully generic.

Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 77d8bf9c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ static inline struct inet_request_sock *inet_rsk(const struct request_sock *sk)
	return (struct inet_request_sock *)sk;
}

struct inet_bind_bucket;
struct ipv6_pinfo;

struct inet_sock {
@@ -157,6 +158,7 @@ struct inet_sock {
	int			mc_index;	/* Multicast device index */
	__u32			mc_addr;
	struct ip_mc_socklist	*mc_list;	/* Group array */
	struct inet_bind_bucket *bind_hash;
	/*
	 * Following members are used to retain the infomation to build
	 * an ip header on each ip fragmentation while the socket is corked.
+0 −1
Original line number Diff line number Diff line
@@ -258,7 +258,6 @@ struct tcp_sock {
 	__u32	snd_sml;	/* Last byte of the most recently transmitted small packet */
	__u32	rcv_tstamp;	/* timestamp of last received ACK (for keepalives) */
	__u32	lsndtime;	/* timestamp of last sent data packet (for restart window) */
	struct inet_bind_bucket *bind_hash;
	/* Delayed ACK control data */
	struct {
		__u8	pending;	/* ACK is pending */
+1 −1
Original line number Diff line number Diff line
@@ -1266,7 +1266,7 @@ static __inline__ void tcp_set_state(struct sock *sk, int state)
			TCP_INC_STATS(TCP_MIB_ESTABRESETS);

		sk->sk_prot->unhash(sk);
		if (tcp_sk(sk)->bind_hash &&
		if (inet_sk(sk)->bind_hash &&
		    !(sk->sk_userlocks & SOCK_BINDPORT_LOCK))
			tcp_put_port(sk);
		/* fall through */
+2 −2
Original line number Diff line number Diff line
@@ -1575,7 +1575,7 @@ void tcp_destroy_sock(struct sock *sk)
	BUG_TRAP(sk_unhashed(sk));

	/* If it has not 0 inet_sk(sk)->num, it must be bound */
	BUG_TRAP(!inet_sk(sk)->num || tcp_sk(sk)->bind_hash);
	BUG_TRAP(!inet_sk(sk)->num || inet_sk(sk)->bind_hash);

	sk->sk_prot->destroy(sk);

@@ -1802,7 +1802,7 @@ int tcp_disconnect(struct sock *sk, int flags)
	tcp_sack_reset(&tp->rx_opt);
	__sk_dst_reset(sk);

	BUG_TRAP(!inet->num || tp->bind_hash);
	BUG_TRAP(!inet->num || inet->bind_hash);

	sk->sk_error_report(sk);
	return err;
+11 −10
Original line number Diff line number Diff line
@@ -113,9 +113,9 @@ static __inline__ void __tcp_inherit_port(struct sock *sk, struct sock *child)
	struct inet_bind_bucket *tb;

	spin_lock(&head->lock);
	tb = tcp_sk(sk)->bind_hash;
	tb = inet_sk(sk)->bind_hash;
	sk_add_bind_node(child, &tb->owners);
	tcp_sk(child)->bind_hash = tb;
	inet_sk(child)->bind_hash = tb;
	spin_unlock(&head->lock);
}

@@ -129,9 +129,10 @@ inline void tcp_inherit_port(struct sock *sk, struct sock *child)
void tcp_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
		   const unsigned short snum)
{
	inet_sk(sk)->num = snum;
	struct inet_sock *inet = inet_sk(sk);
	inet->num	= snum;
	sk_add_bind_node(sk, &tb->owners);
	tcp_sk(sk)->bind_hash = tb;
	inet->bind_hash	= tb;
}

static inline int tcp_bind_conflict(struct sock *sk, struct inet_bind_bucket *tb)
@@ -246,9 +247,9 @@ static int tcp_v4_get_port(struct sock *sk, unsigned short snum)
		   (!sk->sk_reuse || sk->sk_state == TCP_LISTEN))
		tb->fastreuse = 0;
success:
	if (!tcp_sk(sk)->bind_hash)
	if (!inet_sk(sk)->bind_hash)
		tcp_bind_hash(sk, tb, snum);
	BUG_TRAP(tcp_sk(sk)->bind_hash == tb);
	BUG_TRAP(inet_sk(sk)->bind_hash == tb);
 	ret = 0;

fail_unlock:
@@ -269,9 +270,9 @@ static void __tcp_put_port(struct sock *sk)
	struct inet_bind_bucket *tb;

	spin_lock(&head->lock);
	tb = tcp_sk(sk)->bind_hash;
	tb = inet->bind_hash;
	__sk_del_bind_node(sk);
	tcp_sk(sk)->bind_hash = NULL;
	inet->bind_hash = NULL;
	inet->num = 0;
	inet_bind_bucket_destroy(tcp_bucket_cachep, tb);
	spin_unlock(&head->lock);
@@ -694,7 +695,7 @@ static inline int tcp_v4_hash_connect(struct sock *sk)
 	}

 	head = &tcp_bhash[inet_bhashfn(snum, tcp_bhash_size)];
 	tb  = tcp_sk(sk)->bind_hash;
 	tb  = inet_sk(sk)->bind_hash;
	spin_lock_bh(&head->lock);
	if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) {
		__tcp_v4_hash(sk, 0);
@@ -1940,7 +1941,7 @@ int tcp_v4_destroy_sock(struct sock *sk)
	__skb_queue_purge(&tp->ucopy.prequeue);

	/* Clean up a referenced TCP bind bucket. */
	if (tp->bind_hash)
	if (inet_sk(sk)->bind_hash)
		tcp_put_port(sk);

	/*
Loading