You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
到TCP层后,skb需要转换成 struct sock,从 kernel 协议栈查找skb -> struct sk 映射
structsock*__inet_lookup_established(structnet*net,
structinet_hashinfo*hashinfo,
const__be32saddr, const__be16sport,
const__be32daddr, constu16hnum,
constintdif, constintsdif)
{
INET_ADDR_COOKIE(acookie, saddr, daddr);
const__portpairports=INET_COMBINED_PORTS(sport, hnum);
structsock*sk;
conststructhlist_nulls_node*node;
/* Optimize here for direct hit, only listening connections can * have wildcards anyways. */// hashtable查询unsigned inthash=inet_ehashfn(net, daddr, hnum, saddr, sport);
// 找到hashtable桶unsigned intslot=hash&hashinfo->ehash_mask;
structinet_ehash_bucket*head=&hashinfo->ehash[slot];
begin:
sk_nulls_for_each_rcu(sk, node, &head->chain) {
if (sk->sk_hash!=hash)
continue;
if (likely(inet_match(net, sk, acookie, ports, dif, sdif))) {
if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
goto out;
if (unlikely(!inet_match(net, sk, acookie,
ports, dif, sdif))) {
sock_gen_put(sk);
goto begin;
}
goto found;
}
}
/* * if the nulls value we got at the end of this lookup is * not the expected one, we must restart lookup. * We probably met an item that was moved to another chain. */if (get_nulls_value(node) !=slot)
goto begin;
out:
sk=NULL;
found:
returnsk;
}
tcp rev + tcp syn send
到TCP层后,skb需要转换成
struct sock
,从 kernel 协议栈查找skb -> struct sk 映射sock#sk_data_ready 回调通知
注意看左侧callstack,协议栈收到数据后
tcp_queue_rcv
tcp_data_ready
struct sock#sk_data_ready
默认是sock_def_readable唤醒
如何唤醒accept syscall
tcp server运行过程
注册唤醒回调
accept blocking
inet_csk_accept
prepare_to_wait_exclusive
如何唤醒epoll等异步回调机制
未完待续...
The text was updated successfully, but these errors were encountered: