示例#1
0
int
mlvpn_tuntap_alloc(struct tuntap_s *tuntap)
{
    int fd;

    if ((fd = priv_open_tun(tuntap->type,
                            tuntap->devname, tuntap->maxmtu)) <= 0 )
        fatalx("failed to open /dev/net/tun read/write");
    tuntap->fd = fd;
    return fd;
}
示例#2
0
int
mlvpn_tuntap_alloc(struct tuntap_s *tuntap)
{
    char devname[8];
    int fd;
    int i;

    /* TODO: handle this by command line/config file ! */
    /* FreeBSD/OpenBSD (and others maybe) supports each tun on different device. */
    /* examples: /dev/tun0, /dev/tun2 (man 2 if_tun) */
    for (i=0; i < 32; i++)
    {
        snprintf(devname, 5, "%s%d",
            tuntap->type == MLVPN_TUNTAPMODE_TAP ? "tap" : "tun", i);
        snprintf(tuntap->devname, 10, "/dev/%s", devname);

        if ((fd = priv_open_tun(tuntap->type, tuntap->devname)) > 0 )
            break;
    }

    if (fd <= 0)
    {
        _FATAL("[tuntap] unable to open any /dev/%s0 to 32 read/write. "
               "Check permissions.\n",
            tuntap->type == MLVPN_TUNTAPMODE_TAP ? "tap" : "tun");
        return fd;
    }
    tuntap->fd = fd;

    /* geting the actual tun%d inside devname
     * is required for hooks to work properly */
    strlcpy(tuntap->devname, devname, MLVPN_IFNAMSIZ-1);

    char *hook_args[3] = {tuntap->devname, "tuntap_up", NULL};
    mlvpn_hook(MLVPN_HOOK_TUNTAP, 2, hook_args);
    return tuntap->fd;
}