今天整理了一下Linux协议栈针对TCP客户端三次握手的SYN请求流程
简要流程如下:
入口:
-> ip_local_deliver_finish(struct sk_buff *skb) // L4入口
-> ipprot->handler(skb);//进入udp、tcp传输层
-> tcp_v4_rcv(struct sk_buff *skb)
-> tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
-> sk->sk_state == TCP_LISTEN //三次握手,①SYN③ACK
-> tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb, struct tcphdr *th, unsigned len) //收到服务器的SYN
-> case TCP_LISTEN: // 服务端收到SYN
-> th->syn
-> tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb) //服务端处理SYN
-> 队列存储状况检查 //reqsk_queue, acceptq
-> inet_reqsk_alloc(struct request_sock_ops *ops) //tcp_request_sock_ops
-> tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx, u8 **hvpp, int estab) //解析SYN段中的TCP选项
-> tcp_openreq_init(struct request_sock *req, struct tcp_options_received *rx_opt, struct sk_buff *skb)
-> tcp_v4_init_sequence(struct sk_buff *skb) //服务端初始序列号
-> tcp_v4_send_synack(struct sock *sk, struct dst_entry *dst, struct request_sock *req, struct request_values *rvp)
-> inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req, unsigned long timeout) //TCP_TIMEOUT_INIT