tb = inet_csk(sk)->icsk_bind_hash; spin_lock_bh(&head->lock); if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) { hash(sk); spin_unlock_bh(&head->lock); return 0; } else { spin_unlock(&head->lock); /* No definite answer... Walk to established hash table */ ret = check_established(death_row, sk, snum, NULL); out: local_bh_enable(); return ret; } } (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next)这个判断条件就是用来判断是不是只有当前传输控制块在使用已绑定的端口,条件为false时,会执行else分支,检查是否可用。这么看来,调用bind()成功并不意味着这个端口就真的可以用。 check_established参数对应的函数是__inet_check_established(),在inet_hash_connect()中可以看到。在上面的代码中我们还注意到调用check_established()时第三个参数为NULL,这在后面的分析中会用到。 __inet_check_established()函数中,论文网 会分别在TIME_WAIT传输控制块和除TIME_WIAT、LISTEN状态外的传输控制块中查找是已绑定的端口是否已经使用,代码片段如下所示:
[cpp] view plaincopyprint? 01./* called with local bh disabled */ 02.static int __inet_check_established(struct inet_timewait_death_row *death_row, 03. struct sock *sk, __u16 lport, 04. struct inet_timewait_sock **twp) 05.{ 06. struct inet_hashinfo *hinfo = death_row->hashinfo; 07. struct inet_sock *inet = inet_sk(sk); 08. __be32 daddr = inet->rcv_saddr; 09. __be32 saddr = inet->daddr; 10. int dif = sk->sk_bound_dev_if; 11. INET_ADDR_COOKIE(acookie, saddr, daddr) 12. const __portpair ports = INET_COMBINED_PORTS(inet->dport, lport); 13. struct net *net = sock_net(sk); 14. unsigned int hash = inet_ehashfn(net, daddr, lport, saddr, inet->dport); 15. struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash); 16. spinlock_t *lock = inet_ehash_lockp(hinfo, hash); 17. struct sock *sk2; 18. const struct hlist_nulls_node *node; 19. struct inet_timewait_sock *tw; 20. 21. spin_lock(lock); 22. 23.&nbs << 上一页 [11] [12] [13] [14] [15] 下一页
|