lkml.org 
[lkml]   [2010]   [Apr]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [Patch 3/3] net: reserve ports for applications using fixed port numbers
    From
    Date
    Hello.

    > --- linux-2.6.orig/drivers/infiniband/core/cma.c
    > +++ linux-2.6/drivers/infiniband/core/cma.c
    > @@ -1980,6 +1980,8 @@ retry:
    > /* FIXME: add proper port randomization per like inet_csk_get_port */
    > do {
    > ret = idr_get_new_above(ps, bind_list, next_port, &port);
    > + if (!ret && inet_is_reserved_local_port(port))
    > + ret = -EAGAIN;
    > } while ((ret == -EAGAIN) && idr_pre_get(ps, GFP_KERNEL));
    >
    > if (ret)
    >
    I think above part is wrong. Below program
    --------------------
    #include <linux/module.h>
    #include <linux/sched.h>
    #include <linux/idr.h>

    static DEFINE_IDR(idr);
    static int idr_demo_init(void)
    {
    int next_port = 65530;
    int port = 0;
    int ret = -EINTR;
    while (!signal_pending(current)) {
    msleep(1000);
    ret = idr_get_new_above(&idr, NULL, next_port, &port);
    printk(KERN_INFO "idr_get_new_above() = %d\n", ret);
    if (!ret) {
    /* Emulate inet_is_reserved_local_port(port) = true */
    printk(KERN_INFO "Port %u is reserved.\n", port);
    ret = -EAGAIN;
    }
    if (ret == -EAGAIN) {
    if (idr_pre_get(&idr, GFP_KERNEL)) {
    printk(KERN_INFO "idr_pre_get() succeeded.\n");
    continue;
    }
    printk(KERN_INFO "idr_pre_get() failed.\n");
    break;
    } else {
    printk(KERN_INFO "next_port=%u port=%u\n",
    next_port, port);
    break;
    }
    }
    if (!ret)
    idr_remove(&idr, port);
    idr_destroy(&idr);
    return -EINVAL;
    }
    module_init(idr_demo_init);
    MODULE_LICENSE("GPL");
    --------------------
    generated below output.

    idr_get_new_above() = -11
    idr_pre_get() succeeded.
    idr_get_new_above() = 0
    Port 65530 is reserved.
    idr_pre_get() succeeded.
    idr_get_new_above() = 0
    Port 65531 is reserved.
    idr_pre_get() succeeded.
    idr_get_new_above() = 0
    Port 65532 is reserved.
    idr_pre_get() succeeded.
    idr_get_new_above() = 0
    Port 65533 is reserved.
    idr_pre_get() succeeded.
    idr_get_new_above() = 0
    Port 65534 is reserved.
    idr_pre_get() succeeded.
    idr_get_new_above() = 0
    Port 65535 is reserved.
    idr_pre_get() succeeded.
    idr_get_new_above() = 0
    Port 65536 is reserved.
    idr_pre_get() succeeded.
    idr_get_new_above() = 0
    Port 65537 is reserved.
    idr_pre_get() succeeded.
    idr_get_new_above() = 0
    (...snipped...)

    This result suggests that above loop will continue until idr_pre_get() fails
    due to out of memory if all ports were reserved.

    Also, if idr_get_new_above() returned 0, bind_list (which is a kmalloc()ed
    pointer) is already installed into a free slot (see comment on
    idr_get_new_above_int()). Thus, simply calling idr_get_new_above() again will
    install the same pointer into multiple slots. I guess it will malfunction later.


    \
     
     \ /
      Last update: 2010-04-13 03:25    [W:2.992 / U:1.460 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site