当前位置:网站首页>Listen in the network
Listen in the network
2022-07-01 13:28:00 【To maintain world peace_】
listen Main work
Request and initialize the receive queue , Full connection receive queue and half receive queue
int __sys_listen(int fd, int backlog)
{
struct socket *sock;
int err, fput_needed;
int somaxconn;
// according to fd lookup socket Kernel object
sock = sockfd_lookup_light(fd, &err, &fput_needed);
if (sock) {
// Get the kernel somaxconn Parameters ;net.core.somaxconn, And backlog Take the small one
somaxconn = sock_net(sock->sk)->core.sysctl_somaxconn;
if ((unsigned int)backlog > somaxconn)
backlog = somaxconn;
err = security_socket_listen(sock, backlog);
if (!err)// Call protocol stack initialization listen
err = sock->ops->listen(sock, backlog);
fput_light(sock->file, fput_needed);
}
return err;
}backlog And in the system net.core.somaxconn Select a small kernel parameter
sock->ops->listen function
int inet_listen(struct socket *sock, int backlog)
{
struct sock *sk = sock->sk;
unsigned char old_state;
int err, tcp_fastopen;
// If it is listening , allows backlog Parameter adjustment , Set the full connection queue length
WRITE_ONCE(sk->sk_max_ack_backlog, backlog);
// No listen state , Enter listening
if (old_state != TCP_LISTEN) {
tcp_fastopen = sock_net(sk)->ipv4.sysctl_tcp_fastopen;
if ((tcp_fastopen & TFO_SERVER_WO_SOCKOPT1) &&
(tcp_fastopen & TFO_SERVER_ENABLE) &&
!inet_csk(sk)->icsk_accept_queue.fastopenq.max_qlen) {
fastopen_queue_tune(sk, backlog);
tcp_fastopen_init_key_once(sock_net(sk));
}
// Start listening
err = inet_csk_listen_start(sk, backlog);
if (err)
goto out;
tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_LISTEN_CB, 0, NULL);
}
err = 0;
out:
release_sock(sk);
return err;
}Full connection queue structure
struct inet_connection_sock {
/* inet_sock has to be the first member! */
struct inet_sock icsk_inet;
struct request_sock_queue icsk_accept_queue;
...
}
struct request_sock_queue {
spinlock_t rskq_lock;
u8 rskq_defer_accept;
u32 synflood_warned;
atomic_t qlen;
atomic_t young;
// Full connection queue
struct request_sock *rskq_accept_head;
struct request_sock *rskq_accept_tail;
struct fastopen_queue fastopenq; /* Check max_qlen != 0 to determine
* if TFO is enabled.
*/
};int inet_csk_listen_start(struct sock *sk, int backlog)
{
struct inet_connection_sock *icsk = inet_csk(sk);
struct inet_sock *inet = inet_sk(sk);
int err = -EADDRINUSE;
//icsk_accept_queue Receiving queue
// Receive queue kernel object initialization
reqsk_queue_alloc(&icsk->icsk_accept_queue);
sk->sk_ack_backlog = 0;
inet_csk_delack_init(sk);
inet_sk_state_store(sk, TCP_LISTEN);
if (!sk->sk_prot->get_port(sk, inet->inet_num)) {
inet->inet_sport = htons(inet->inet_num);
sk_dst_reset(sk);
err = sk->sk_prot->hash(sk);
if (likely(!err))
return 0;
}
inet_sk_set_state(sk, TCP_CLOSE);
return err;
}
static inline void fastopen_queue_tune(struct sock *sk, int backlog)
{
struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue;
int somaxconn = READ_ONCE(sock_net(sk)->core.sysctl_somaxconn);
// Semi connected queue length
queue->fastopenq.max_qlen = min_t(unsigned int, backlog, somaxconn);
}summary :listen It mainly applies for work and initializes the receiving queue , Full connection receive queue and half receive queue
Full connection receive queue length
backlog And net.core.somaxconn Smaller value between
边栏推荐
- Global and Chinese polypropylene industry prospect analysis and market demand forecast report Ⓝ 2022 ~ 2027
- Feign & Eureka & Zuul & Hystrix 流程
- Nexus builds NPM dependent private database
- 启动solr报错The stack size specified is too small,Specify at least 328k
- Has anyone ever encountered this situation? When Oracle logminer is synchronized, the value of CLOB field is lost
- Analysis report on the development pattern of China's smart emergency industry and the 14th five year plan Ⓠ 2022 ~ 2028
- Anti fraud, refusing to gamble, safe payment | there are many online investment scams, so it's impossible to make money like this
- Jenkins+webhooks- multi branch parametric construction-
- 逆向调试入门-PE结构-输入表输出表05/07
- 【机器学习】VAE变分自编码器学习笔记
猜你喜欢

硬件开发笔记(九): 硬件开发基本流程,制作一个USB转RS232的模块(八):创建asm1117-3.3V封装库并关联原理图元器件

What is the future development direction of people with ordinary education, appearance and family background? The career planning after 00 has been made clear

【大型电商项目开发】性能压测-压力测试基本概念&JMeter-38

Meta enlarge again! VR new model posted on CVPR oral: read and understand voice like a human

Google Earth Engine(GEE)——全球人类居住区网格数据 1975-1990-2000-2014 (P2016)

啟動solr報錯The stack size specified is too small,Specify at least 328k

Google Earth engine (GEE) - Global Human Settlements grid data 1975-1990-2000-2014 (p2016)
![[development of large e-commerce projects] performance pressure test - basic concept of pressure test & jmeter-38](/img/50/819b9c2f69534afc6dc391c9de5f05.png)
[development of large e-commerce projects] performance pressure test - basic concept of pressure test & jmeter-38

终端识别技术和管理技术

Build a vc2010 development environment and create a tutorial of "realizing Tetris game in C language"
随机推荐
受益互联网出海 汇量科技业绩重回高增长
学历、长相、家境普通的人,未来的发展方向是什么?00后的职业规划都已经整得明明白白......
Jenkins+webhooks-多分支参数化构建-
波浪动画彩色五角星loader加载js特效
Fiori applications are shared through the enhancement of adaptation project
MySQL六十六问,两万字+五十图详解!复习必备
Vs code setting Click to open a new file window without overwriting the previous window
Build a vc2010 development environment and create a tutorial of "realizing Tetris game in C language"
Yarn重启applications记录恢复
word2vec训练中文词向量
Introduction to reverse debugging PE structure input table output table 05/07
Has anyone ever encountered this situation? When Oracle logminer is synchronized, the value of CLOB field is lost
Apache-Atlas-2.2.0 独立编译部署
逆向调试入门-PE结构-输入表输出表05/07
Flow management technology
Feign & Eureka & zuul & hystrix process
flinkcdc要实时抽取oracle,对oracle要配置什么东西?
单工,半双工,全双工区别以及TDD和FDD区别
10. Page layout, guess you like it
Simple two ball loading