尝试从Linux内核发送UDP数据包时操作系统冻结

时间:2016-06-29 12:07:29

标签: linux-kernel network-programming udp

我正在修改UDP以实现自定义协议。 UDP连接建立路由后,我想将自定义UDP数据包发送到目的地(如TCP中的SYN数据包)。当我在运行我的自定义内核的机器上尝试connect()套接字函数时,它冻结而不向内核日志写出任何内容。这是我的代码

int quic_connect(struct sock *sk, struct flowi4 *fl4, struct rtable *rt){
    struct sk_buff *skb, *buff;
    struct inet_cork cork;  
    struct ipcm_cookie ipc;
    struct sk_buff_head queue;
    char *hello;
    int err = 0, exthdrlen, hh_len, datalen, trailerlen;
    char *data;

    hh_len = LL_RESERVED_SPACE(rt->dst.dev);
    exthdrlen = rt->dst.header_len;
    trailerlen = rt->dst.trailer_len;
    datalen = 200;

    //Create a buffer to be send without fragmentation
    skb = sock_alloc_send_skb(sk,
            exthdrlen + datalen + hh_len + trailerlen + 15,
            MSG_DONTWAIT, &err);
    if (skb == NULL)
        goto out;

    skb->ip_summed = CHECKSUM_PARTIAL;      // Use hardware checksum
    skb->csum = 0;
    skb_reserve(skb, hh_len);
    skb_shinfo(skb)->tx_flags = 1;          //Time stamp the packet 


    /*
     *  Find where to start putting bytes.
     */
    data = skb_put(skb, datalen + exthdrlen);
    skb_set_network_header(skb, exthdrlen);
    skb->transport_header = (skb->network_header +
                 sizeof(struct iphdr));

    __skb_queue_head_init(&queue);
    /*
     * Put the packet on the pending queue.
     */
    __skb_queue_tail(&queue, skb);

    cork.flags = 0;
    cork.addr = 0;
    cork.opt = NULL;
    ipc.opt = NULL;
    ipc.tx_flags = 0;
    ipc.ttl = 0;
    ipc.tos = -1;
    ipc.addr = fl4->daddr;
    err = ip_setup_cork(sk, &cork, &ipc, &rt);

    buff = __ip_make_skb(sk, fl4, &queue, &cork);
    kfree(skb);
    err = PTR_ERR(buff);
    if (!IS_ERR_OR_NULL(buff))
        err = udp_send_skb(buff, fl4);    

out:                                     
    return err;                      

}

函数quic_connectip4_datagram_connect函数的末尾调用,该函数是UDP连接的注册处理程序。

内核日志中没有任何内容。

我在这里做错了什么?

**编辑1:**问题发生在err = udp_send_skb(buff, fl4);,因为当我注释掉该行时没有问题。所以我假设我的sk_buff没有正确形成。有什么想法吗?

0 个答案:

没有答案