当前位置:网站首页>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
边栏推荐
- Function test process in software testing
- Meta再放大招!VR新模型登CVPR Oral:像人一样「读」懂语音
- 学历、长相、家境普通的人,未来的发展方向是什么?00后的职业规划都已经整得明明白白......
- Wave animation color five pointed star loader loading JS special effects
- JS变色的乐高积木
- VM virtual machine configuration dynamic IP and static IP access
- Analysis report on production and marketing demand and investment forecast of global and Chinese diamond powder industry Ⓤ 2022 ~ 2027
- Flutter SQLite使用
- ZABBIX 6.0 source code installation and ha configuration
- Detailed explanation of OSPF LSA of routing Foundation
猜你喜欢
Different test techniques
Fiori applications are shared through the enhancement of adaptation project
5. Use of ly tab plug-in of header component
SVG钻石样式代码
MySQL报错1040Too many connections的原因以及解决方案
5G工业网关的科技治超应用 超限超重超速非现场联合执法
ZABBIX 6.0 source code installation and ha configuration
彩色五角星SVG动态网页背景js特效
Google Earth engine (GEE) - Global Human Settlements grid data 1975-1990-2000-2014 (p2016)
Detailed explanation of OSPF LSA of routing Foundation
随机推荐
Jenkins+webhooks- multi branch parametric construction-
软件测试中功能测试流程
运行游戏时出现0xc000007b错误的解决方法[通俗易懂]
flinkcdc要实时抽取oracle,对oracle要配置什么东西?
彩色五角星SVG动态网页背景js特效
Professor Li Zexiang, Hong Kong University of science and technology: I'm wrong. Why is engineering consciousness more important than the best university?
ArrayList扩容机制以及线程安全性
啟動solr報錯The stack size specified is too small,Specify at least 328k
3.4 《数据库系统概论》之数据查询—SELECT(单表查询、连接查询、嵌套查询、集合查询、多表查询)
C language learning
内容审计技术
用命令行 给 apk 签名
2.15 summary
终端识别技术和管理技术
Detailed explanation of OSPF LSA of routing Foundation
Application of 5g industrial gateway in scientific and technological overload control; off-site joint law enforcement for over limit, overweight and overspeed
1. Sum of two numbers: given an integer array num and an integer target value, please find the two integers whose sum is the target value target in the array and return their array subscripts
Content Audit Technology
China NdYAG crystal market research conclusion and development strategy proposal report Ⓥ 2022 ~ 2028
mysql统计账单信息(下):数据导入及查询