免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2494 | 回复: 1
打印 上一主题 下一主题

关于LISTEN队列的问题,请教 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-04-17 18:16 |只看该作者 |倒序浏览
监听队列上分配的request_sock结构好像没被使用,而在tcp_v4_conn_request()又会重新分配一个这样的结构再插入到这个队列中中。这好像不符合逻辑,也没见到在哪个地方释放。是这样吗? 



int
reqsk_queue_alloc(struct request_sock_queue *queue,
              unsigned int nr_table_entries)
{
    size_t lopt_size = sizeof(struct listen_sock);
    struct listen_sock *lopt;

    nr_table_entries = min_t(u32, nr_table_entries, sysctl_max_syn_backlog);
    nr_table_entries = max_t(u32, nr_table_entries, 8);
    nr_table_entries = roundup_pow_of_two(nr_table_entries + 1);
    lopt_size += nr_table_entries * sizeof(struct request_sock *);
    if (lopt_size > PAGE_SIZE)
        lopt = __vmalloc(lopt_size,
            GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,PAGE_KERNEL);
    else
        lopt = kzalloc(lopt_size, GFP_KERNEL);
    if (lopt == NULL)
        return -ENOMEM;

    for (lopt->max_qlen_log = 3;
         (1 << lopt->max_qlen_log) < nr_table_entries;
         lopt->max_qlen_log++);

    get_random_bytes(&lopt->hash_rnd, sizeof(lopt->hash_rnd));
    rwlock_init(&queue->syn_wait_lock);
    queue->rskq_accept_head = NULL;
    lopt->nr_table_entries = nr_table_entries;

    write_lock_bh(&queue->syn_wait_lock);
    queue->listen_opt = lopt;
    write_unlock_bh(&queue->syn_wait_lock);

    return 0;
}
int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
{
    struct inet_request_sock *ireq;
    struct tcp_options_received tmp_opt;
    struct request_sock *req;
    __be32 saddr = skb->nh.iph->saddr;
    __be32 daddr = skb->nh.iph->daddr;
    __u32 isn = TCP_SKB_CB(skb)->when;
    struct dst_entry *dst = NULL;

    ......
   
    if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1)
        goto drop;

    req = reqsk_alloc(&tcp_request_sock_ops);
    if (!req)
        goto drop;



    ......

    if (tcp_v4_send_synack(sk, req, dst))
        goto drop_and_free;

    if (want_cookie) {
           reqsk_free(req);
    } else {
        inet_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT);
    }
    return 0;

    ......
}


[ 本帖最后由 R.wen 于 2007-4-17 18:56 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2007-04-17 18:17 |只看该作者

void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   unsigned long timeout)
{
&nbsp;&nbsp;&nbsp;&nbsp;struct inet_connection_sock *icsk = inet_csk(sk);
&nbsp;&nbsp;&nbsp;&nbsp;struct listen_sock *lopt = icsk-&gt;icsk_accept_queue.listen_opt;
&nbsp;&nbsp;&nbsp;&nbsp;const u32 h = inet_synq_hash(inet_rsk(req)-&gt;rmt_addr, inet_rsk(req)-&gt;rmt_port,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     lopt-&gt;hash_rnd, lopt-&gt;nr_table_entries);

&nbsp;&nbsp;&nbsp;&nbsp;reqsk_queue_hash_req(&amp;icsk-&gt;icsk_accept_queue, h, req, timeout);
&nbsp;&nbsp;&nbsp;&nbsp;inet_csk_reqsk_queue_added(sk, timeout);
}

static inline void reqsk_queue_hash_req(struct request_sock_queue *queue,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u32 hash, struct request_sock *req,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unsigned long timeout)
{
&nbsp;&nbsp;&nbsp;&nbsp;struct listen_sock *lopt = queue-&gt;listen_opt;

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

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


[ 本帖最后由 R.wen 于 2007-4-17 18:19 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP