青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

大龍的博客

常用鏈接

統(tǒng)計(jì)

最新評論

關(guān)于半連接隊(duì)列的釋疑 --- 轉(zhuǎn)

1、到底那個是半連接隊(duì)列
/** struct listen_sock – listen state
*
* @max_qlen_log – log_2 of maximal queued SYNs/REQUESTs
*/
struct listen_sock {
u8 max_qlen_log; /*2^max_qlen_log is the length of the accpet queue, max of max_qlen_log is 10. (2^10=1024)*/
/* 3 bytes hole, try to use */
int qlen; /* qlen is the current length of the accpet queue*/
int qlen_young;
int clock_hand;
u32 hash_rnd;
u32 nr_table_entries; /*nr_table_entries is the number of the syn_table,max is 512*/
struct request_sock *syn_table[0];
};
里面有幾個關(guān)鍵的成員變量:max_qlen_log、qlen和syn_table。注意syn_table是一個零數(shù)組。

跟蹤listen系統(tǒng)調(diào)用:
inet_listen
inet_csk_listen_start
reqsk_queue_alloc

在reqsk_queue_alloc中:
const int lopt_size = sizeof(struct listen_sock) +
nr_table_entries * sizeof(struct request_sock *);
struct listen_sock *lopt = kzalloc(lopt_size, GFP_KERNEL);
我們發(fā)現(xiàn)這里進(jìn)行了分配內(nèi)存,分配了nr_table_entries個struct request_sock *。
對于nr_table_entries,我們可以往回追蹤:
err = inet_csk_listen_start(sk, TCP_SYNQ_HSIZE);
#define TCP_SYNQ_HSIZE 512 /* Size of SYNACK hash table */

跟蹤SYN數(shù)據(jù)包的處理,在tcp_v4_conn_request中,最后調(diào)用了inet_csk_reqsk_queue_hash_add函數(shù):
void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
unsigned long timeout)
{
struct inet_connection_sock *icsk = inet_csk(sk);
struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt;
const u32 h = inet_synq_hash(inet_rsk(req)->rmt_addr, inet_rsk(req)->rmt_port,
lopt->hash_rnd, lopt->nr_table_entries);

reqsk_queue_hash_req(&icsk->icsk_accept_queue, h, req, timeout);
inet_csk_reqsk_queue_added(sk, timeout);
}

reqsk_queue_hash_req將新建的request_sock添加到reqsk_queue中:
static inline void reqsk_queue_hash_req(struct request_sock_queue *queue,
u32 hash, struct request_sock *req,
unsigned long timeout)
{
struct listen_sock *lopt = queue->listen_opt;

req->expires = jiffies + timeout;
req->retrans = 0;
req->sk = NULL;
req->dl_next = lopt->syn_table[hash];

write_lock(&queue->syn_wait_lock);
lopt->syn_table[hash] = req;
write_unlock(&queue->syn_wait_lock);
}

inet_csk_reqsk_queue_added增加連接請求隊(duì)列的計(jì)數(shù),必要是設(shè)置計(jì)數(shù)器:
static inline void inet_csk_reqsk_queue_added(struct sock *sk,
const unsigned long timeout)
{
if (reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue) == 0)
inet_csk_reset_keepalive_timer(sk, timeout);
}
static inline int reqsk_queue_added(struct request_sock_queue *queue)
{
struct listen_sock *lopt = queue->listen_opt;
const int prev_qlen = lopt->qlen;

lopt->qlen_young++;
lopt->qlen++;
return prev_qlen;
}

其他的幾個數(shù)據(jù)結(jié)構(gòu):
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 inet_bind_bucket *icsk_bind_hash;
unsigned long icsk_timeout;
struct timer_list icsk_retransmit_timer;
struct timer_list icsk_delack_timer;
__u32 icsk_rto;
__u32 icsk_pmtu_cookie;
const struct tcp_congestion_ops *icsk_ca_ops;
const struct inet_connection_sock_af_ops *icsk_af_ops;
unsigned int (*icsk_sync_mss)(struct sock *sk, u32 pmtu);
__u8 icsk_ca_state;
__u8 icsk_retransmits;
__u8 icsk_pending;
__u8 icsk_backoff;
__u8 icsk_syn_retries;
__u8 icsk_probes_out;
__u16 icsk_ext_hdr_len;
struct {
__u8 pending; /* ACK is pending */
__u8 quick; /* Scheduled number of quick acks */
__u8 pingpong; /* The session is interactive */
__u8 blocked; /* Delayed ACK was blocked by socket lock */
__u32 ato; /* Predicted tick of soft clock */
unsigned long timeout; /* Currently scheduled timeout */
__u32 lrcvtime; /* timestamp of last received data packet */
__u16 last_seg_size; /* Size of last incoming segment */
__u16 rcv_mss; /* MSS used for delayed ACK decisions */
} icsk_ack;
struct {
int enabled;

/* Range of MTUs to search */
int search_high;
int search_low;

/* Information on the current probe. */
int probe_size;
} icsk_mtup;
u32 icsk_ca_priv[16];
#define ICSK_CA_PRIV_SIZE (16 * sizeof(u32))
};

struct request_sock_queue {
/*Points to the request_sock accept queue, when after 3 handshake will add the request_sock from syn_table to here*/
struct request_sock *rskq_accept_head;
struct request_sock *rskq_accept_tail;
rwlock_t syn_wait_lock;
u8 rskq_defer_accept;
/* 3 bytes hole, try to pack */
struct listen_sock *listen_opt;
};

因此,半連接隊(duì)列在這里可以認(rèn)為是icsk_accept_queue,叫做連接請求隊(duì)列。

2、半連接隊(duì)列的長度
跟蹤inet_csk_reqsk_queue_is_full,發(fā)現(xiàn)會比較queue->listen_opt->qlen >> queue->listen_opt->max_qlen_log,看來關(guān)鍵在于max_qlen_log。
發(fā)現(xiàn)reqsk_queue_alloc中:
for (lopt->max_qlen_log = 6; /*64*/
(1 << lopt->max_qlen_log) < sysctl_max_syn_backlog;
lopt->max_qlen_log++);

我們在/proc/sys/net/ipv4/tcp_max_syn_backlog中會可以設(shè)置max_syn_backlog,這個就是我們可以設(shè)置的半連接隊(duì)列的長度。
默認(rèn)是1024,那么max_qlen_log就是10了;加入我們設(shè)置成64,那么max_qlen_log就是6了,我們設(shè)置成128,就是7了;其他的依次類推。

3、連接請求的數(shù)據(jù)流向
在前面的分析中,SYN數(shù)據(jù)包的處理中,接收到SYN數(shù)據(jù)包,將會建立一個reqest_sock結(jié)構(gòu),添加到syn_table哈希表相應(yīng)的表中。
接收到ACK數(shù)據(jù)包后,跟蹤tcp_v4_do_rcv,發(fā)現(xiàn)會調(diào)用tcp_v4_hnd_req。
在tcp_v4_hnd_req中:
/* Check the request_sock is in the syn_table or not.
If the request_sock have been in the syn_table, then call tcp_check_req*/
/*If ACK in 3 handsharks, will find a request_sock in syn_table, then call tcp_check_req().*/
struct request_sock *req = inet_csk_search_req(sk, &prev, th->source,
iph->saddr, iph->daddr);
/*Normal: Call syn_recv_sock function(tcp_v4_syn_recv_sock)*/
if (req)
return tcp_check_req(sk, skb, req, prev);

在tcp_check_req中:
/*ipv4_specific.syn_recv_sock = tcp_v4_syn_recv_sock*/
child = inet_csk(sk)->icsk_af_ops->syn_recv_sock(sk, skb,
req, NULL);
if (child == NULL)
goto listen_overflow;

/*Move the request_sock from the syn_table to accept_queue
Notes: syn_table isn’t A hlist_header structure.*/
inet_csk_reqsk_queue_unlink(sk, req, prev);
inet_csk_reqsk_queue_removed(sk, req);

inet_csk_reqsk_queue_add(sk, req, child);
return child;

tcp_v4_syn_recv_sock會根據(jù)request_sock新建一個sock結(jié)構(gòu),并且進(jìn)行一定的初始化,返回新建的sock結(jié)構(gòu)。
將request_sock從syn_table中移到accept_queue中。

static inline void inet_csk_reqsk_queue_add(struct sock *sk,
struct request_sock *req,
struct sock *child)
{
reqsk_queue_add(&inet_csk(sk)->icsk_accept_queue, req, sk, child);
}
static inline void reqsk_queue_add(struct request_sock_queue *queue,
struct request_sock *req,
struct sock *parent,
struct sock *child)
{
req->sk = child;
/*Add the number of backlog, that not completed 3 handsharks but have connected the server.*/*/
sk_acceptq_added(parent);

if (queue->rskq_accept_head == NULL)
queue->rskq_accept_head = req;
else
queue->rskq_accept_tail->dl_next = req;

queue->rskq_accept_tail = req;
req->dl_next = NULL;
}

4、accept系統(tǒng)調(diào)用的處理

三次握手之后,request_sock已經(jīng)在rskq_accept隊(duì)列中了,等待accept系統(tǒng)調(diào)用取走。
static inline void sk_acceptq_removed(struct sock *sk)
{
sk->sk_ack_backlog–;
}

static inline void sk_acceptq_added(struct sock *sk)
{
sk->sk_ack_backlog++;
}
這個時候,我們關(guān)注一個struct sock中的兩個變量:
unsigned short sk_ack_backlog; /*sk_ack_backlog is the socket number that not completed 3 handsharks but have connected the server.*/
unsigned short sk_max_ack_backlog; /*sk_max_ack_backlog is the Max sk_ack_backlog, is assigned in the listen()*/
其中,sk_ack_backlog是已經(jīng)完成了三次握手,但是還沒有被accept系統(tǒng)調(diào)用處理的連接請求數(shù)量;sk_max_ack_backlog就是我們經(jīng)常熟悉的listen的參數(shù)。

跟蹤accept系統(tǒng)調(diào)用:
inet_csk_accept:
newsk = reqsk_queue_get_child(&icsk->icsk_accept_queue, sk);

static inline struct sock *reqsk_queue_get_child(struct request_sock_queue *queue,
struct sock *parent)
{
struct request_sock *req = reqsk_queue_remove(queue);
struct sock *child = req->sk;

BUG_TRAP(child != NULL);

sk_acceptq_removed(parent);
__reqsk_free(req);
return child;
}

注意這里free掉了在三次握手中建立的request_sock結(jié)構(gòu)。

5、防止溢出的兩個鏈表檢查
在tcp_v4_conn_request中,對SYN包的處理過程中:

if (inet_csk_reqsk_queue_is_full(sk) && !isn) {
#ifdef CONFIG_SYN_COOKIES
if (sysctl_tcp_syncookies) {
want_cookie = 1;
} else
#endif
goto drop;
}

/* Accept backlog is full. If we have already queued enough
* of warm entries in syn queue, drop request. It is better than
* clogging syn queue with openreqs with exponentially increasing
* timeout.
*/
/*If Accept Queue is full, Drop the packet*/
if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1)
goto drop;

這里面有兩個隊(duì)列的檢查:request_sock隊(duì)列和accept隊(duì)列。
request_sock隊(duì)列:
static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
{
return reqsk_queue_is_full(&inet_csk(sk)->icsk_accept_queue);
}
static inline int reqsk_queue_is_full(const struct request_sock_queue *queue)
{
return queue->listen_opt->qlen >> queue->listen_opt->max_qlen_log;
}

accept隊(duì)列:
static inline int sk_acceptq_is_full(struct sock *sk)
{
return sk->sk_ack_backlog > sk->sk_max_ack_backlog;
}

其中關(guān)系到4個變量,其中兩個是sock的成員變量,兩個是request_sock_queue中l(wèi)isten_opt的變量。

max_qlen_log的初始化:
在reqsk_queue_alloc中:
for (lopt->max_qlen_log = 6; /*64*/
(1 << lopt->max_qlen_log) < sysctl_max_syn_backlog;
lopt->max_qlen_log++);

sk_max_ack_backlog的初始化:
在inet_listen中:
sk->sk_max_ack_backlog = backlog;
注:sk_max_ack_backlog就是我們經(jīng)常熟悉的listen的參數(shù)。

qlen的增加:
tcp_v4_conn_request
inet_csk_reqsk_queue_hash_add
inet_csk_reqsk_queue_added
reqsk_queue_added

注:跟蹤SYN數(shù)據(jù)包的處理,在tcp_v4_conn_request中,最后調(diào)用了inet_csk_reqsk_queue_hash_add函數(shù):
inet_csk_reqsk_queue_added(sk, timeout);
inet_csk_reqsk_queue_added增加連接請求隊(duì)列的計(jì)數(shù),必要時候設(shè)置計(jì)數(shù)器。
reqsk_queue_added:
lopt->qlen++;

qlen的減少:
tcp_v4_hnd_req
tcp_check_req
inet_csk_reqsk_queue_removed
reqsk_queue_removed

注:
在inet_csk_listen_stop中:
/* Following specs, it would be better either to send FIN
* (and enter FIN-WAIT-1, it is normal close)
* or to send active reset (abort).
* Certainly, it is pretty dangerous while synflood, but it is
* bad justification for our negligence 8)
* To be honest, we are not able to make either
* of the variants now. –ANK
*/
reqsk_queue_destroy(&icsk->icsk_accept_queue);

sk_ack_backlog的增加:
tcp_check_req
inet_csk_reqsk_queue_add
reqsk_queue_add
sk_acceptq_added

sk_ack_backlog的減少:
inet_csk_accept
reqsk_queue_get_child
sk_acceptq_removed

posted on 2013-02-16 00:04 大龍 閱讀(933) 評論(0)  編輯 收藏 引用

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲女女做受ⅹxx高潮| 亚洲特级毛片| 亚洲破处大片| 亚洲精品中文字幕女同| 国产一区二区三区久久| 美日韩精品视频免费看| 久久精品中文字幕免费mv| 亚洲专区一区二区三区| 一区二区高清在线观看| 亚洲一区黄色| 欧美中文字幕视频| 欧美成人午夜激情| 欧美日韩大片| 国产亚洲一区二区三区在线观看| 国产精品ⅴa在线观看h| 欧美色网在线| 国产一级揄自揄精品视频| 国内偷自视频区视频综合| 悠悠资源网久久精品| 一本久久青青| 久久久99久久精品女同性| 久久中文久久字幕| 亚洲精品网站在线播放gif| 这里只有精品丝袜| 美女国产一区| 国产日韩精品一区二区浪潮av| 狠狠综合久久| 亚洲欧美另类国产| 欧美二区在线观看| 性做久久久久久| 欧美新色视频| 亚洲精品一区二区在线| 久久精品五月婷婷| 亚洲美女网站| 91久久嫩草影院一区二区| 欧美国产精品一区| 亚洲国产小视频在线观看| 午夜精品福利电影| 国产精品免费一区二区三区在线观看 | 久久夜色精品| 亚洲欧美日韩成人高清在线一区| 欧美激情一区二区久久久| 在线精品高清中文字幕| 久久久久久久网| 久久久精品性| 亚洲三级视频| 99热精品在线观看| 国产精品夜夜嗨| 久久久久久久久久久久久久一区| 久久在线视频在线| 久久久在线视频| 欧美日本一区| 一区二区三区国产| 亚洲免费在线精品一区| 国产一区二区三区久久| 欧美国产精品久久| 国产精品久久久久久模特 | 欧美激情欧美激情在线五月| 亚洲国产欧美日韩| 亚洲新中文字幕| 亚洲午夜精品一区二区三区他趣| 欧美视频免费在线| 蜜臀久久久99精品久久久久久| 欧美大色视频| 久久精品在线视频| 欧美性事免费在线观看| 免费在线看一区| 国产精品一区二区在线观看网站| 美女精品视频一区| 国产麻豆视频精品| av成人手机在线| 亚洲精品影院| 欧美激情视频一区二区三区不卡| 欧美一区二区三区四区在线观看地址| 久久综合久久综合这里只有精品 | 久久精品国产v日韩v亚洲| 欧美风情在线观看| 久久一区中文字幕| 国产一区二区三区免费不卡| 亚洲精品偷拍| 国产精品久久久久久一区二区三区 | 久久精品日产第一区二区| 亚洲网友自拍| 国产精品久久国产愉拍| 欧美一级视频| 欧美精彩视频一区二区三区| 久久久久国产精品麻豆ai换脸 | 香蕉亚洲视频| 国产精品任我爽爆在线播放 | 亚洲一区黄色| 国产精品影片在线观看| 欧美在线三级| 亚洲国产精品一区二区www| 午夜精品一区二区三区在线播放| 欧美国产精品| 久久久精彩视频| 亚洲专区免费| 亚洲欧美清纯在线制服| 国产酒店精品激情| 久久久精品一区二区三区| 亚洲国产一区二区精品专区| 亚洲一区二区影院| 亚洲成色最大综合在线| 欧美日韩精品一区二区三区| 欧美在线精品一区| 亚洲另类一区二区| 欧美成人免费一级人片100| 亚洲欧美精品中文字幕在线| 亚洲国产高清一区二区三区| 国产精品影片在线观看| 欧美日韩天天操| 欧美破处大片在线视频| 久久婷婷av| 久久久亚洲高清| 久久久久久一区二区三区| 先锋影音久久久| 欧美亚洲免费| 欧美一区视频| 欧美一区观看| 欧美在线观看你懂的| 欧美一区免费| 亚洲欧美在线播放| 亚洲欧美国产va在线影院| 中日韩男男gay无套| 一本久道久久综合狠狠爱| 国产精品99久久99久久久二8| 亚洲精品久久久久久久久久久久久 | 欧美日一区二区在线观看| 欧美日本亚洲韩国国产| 欧美三级电影精品| 国产欧美日韩精品一区| 在线观看欧美视频| 亚洲丝袜av一区| 免费中文日韩| 一区二区毛片| 老色鬼久久亚洲一区二区| 国产精品v欧美精品v日韩| 亚洲专区欧美专区| 欧美成人精品在线| 国产精品视频导航| 亚洲日本视频| 久久偷窥视频| 亚洲资源av| 欧美刺激性大交免费视频 | 欧美成人精品h版在线观看| 欧美另类亚洲| 亚洲欧洲一区二区天堂久久| 亚洲欧洲99久久| 日韩系列在线| 欧美日韩免费一区二区三区视频| 国产精品天美传媒入口| 亚洲裸体视频| 欧美激情免费在线| 久久网站热最新地址| 国产精品mm| 亚洲一区二区视频| 日韩视频中午一区| 亚洲第一在线综合网站| 欧美日韩视频在线一区二区| 麻豆成人91精品二区三区| 久久精品国产一区二区三区免费看| 久久免费99精品久久久久久| 欧美伊人久久| 伊人久久大香线蕉综合热线| 欧美在线免费观看视频| 亚洲视频在线一区观看| 国产精品剧情在线亚洲| 欧美资源在线| 久久亚洲国产成人| 99精品国产在热久久| 亚洲视频axxx| 韩国成人福利片在线播放| 欧美成人精品影院| 欧美私人啪啪vps| 久久手机精品视频| 欧美日韩高清在线| 久久久久久久久久久久久女国产乱 | 一区福利视频| 99综合在线| 亚洲电影一级黄| 一区二区三区欧美视频| 亚洲第一色中文字幕| 中文精品一区二区三区| 亚洲二区免费| 欧美在线中文字幕| 亚洲在线观看| 欧美精品色综合| 欧美激情女人20p| 亚洲第一黄色网| 欧美中文字幕精品| 久久女同互慰一区二区三区| 欧美亚韩一区| 亚洲天堂男人| 亚洲在线视频观看| 欧美ed2k| 一区在线观看| 欧美中日韩免费视频| 久久久久国产精品午夜一区| 国产在线欧美| 美日韩精品视频|