我想用多队列打开 tun,但是当我设置 IFF_ATTACH_QUEUE 时失败。
Linux 版本 4.15.0-62-generic (buildd@lcy01-amd64-024) (gcc 版本 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1))
int tun_alloc_mq(char *dev, int queues, int *fds)
{
struct ifreq ifr;
int fd, err, i;
if (!dev)
return -1;
memset(&ifr, 0, sizeof(ifr));
/* Flags: IFF_TUN - TUN device (no Ethernet headers)
* IFF_TAP - TAP device
*
* IFF_NO_PI - Do not provide packet information
* IFF_MULTI_QUEUE - Create a queue of multiqueue device
*/
ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_MULTI_QUEUE;
strcpy(ifr.ifr_name, dev);
for (i = 0; i < queues; i++) {
if ((fd = open("/dev/net/tun", O_RDWR)) < 0)
goto err;
err = ioctl(fd, TUNSETIFF, (void *)&ifr);
if (err) {
close(fd);
goto err;
}
fds[i] = fd;
}
return 0;
err:
for (--i; i >= 0; i--)
close(fds[i]);
return err;
}
int tun_set_queue(int fd, int enable)
{
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
//strcpy(ifr.ifr_name,"tun1");
if (enable)
ifr.ifr_flags = IFF_ATTACH_QUEUE;
else
ifr.ifr_flags = IFF_DETACH_QUEUE;
if(ioctl(fd, TUNSETQUEUE, (void *)&ifr) < 0)
{
printf("ioctl:%s\n",strerror(errno));
return -1;
}
return 0;
}
函数 tun_set_queue 将得到“ioctl:Invalid argument”