- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在我听说内核 3.8 linux 添加了多队列功能以使用标志 IFF_MULTI_QUEUE 调整 tap 设备后,我将内核升级到 3.10 并将其 header 放在/usr/src然后我改变了我的c代码,让一个线程在每次需要时打开一个新的队列文件描述符。但是线程只能打开 8 个队列(使用早于 3.8 的内核,它根本无法打开队列),之后我从 ioctl 中得到这个“参数太长”错误
ioctl(fd, TUNSETIFF, (void *)&ifr)
然后我写了另一个程序来测试在我的 ubuntu 12.10 linux box 中可以打开多少队列 fd
uname -r
3.10.0-031000-generic
一个更简单的程序中的内核版本。
//essential
#include <net/if.h>
#include <linux/if_tun.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <arpa/inet.h>
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>
#include <stdarg.h>
#include <netdb.h>
#define IFF_MULTI_QUEUE 0x0100
int tun_alloc_mq(char *dev, int queues, int *fds)
{
struct ifreq ifr;
int fd, err=-1, i;
char *clonedev = "/dev/net/tun";
if (!dev){
printf("dev");
return -1;
}
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_MULTI_QUEUE;
strcpy(ifr.ifr_name, dev);
int error=0;
for (i = 0; i < queues; i++) {
printf("loop %d\n",i);
if( (fd = open(clonedev , O_RDWR)) < 0 ) {
perror("Opening /dev/net/tun");
error=1;
break;
}
if(ioctl(fd, TUNSETIFF, (void *)&ifr) < 0 ) {
printf("first error\n");
error=1;
close(fd);
break;
}
}
if(error==1)
return -1;
return 0;
}
int main(int argc, char *argv[])
{
int* fdsx;
if(tun_alloc_mq("testmqtun0",20,fdsx)<0)
{
perror("tun");
exit(1);
}
return 0;
}
事实证明这也限制为 8 个。这是输出:
loop 0
loop 1
loop 2
loop 3
loop 4
loop 5
loop 6
loop 7
loop 8
first error
tun: Argument list too long
我在另一个 linux 机器上测试了它,它有相同的输出。那么从内核中的 tun 设备打开超过 8 个队列是否有限制?如果是这样,如何解决?请帮我解决这个问题
最佳答案
如果你想从一个tun接口(interface)获取超过8个队列的文件描述符,你可以将你的linux内核升级到4.0+,它支持256个队列。
关于c - 尝试从 tun 接口(interface)获取超过 8 个队列文件描述符时 ioctl 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17504076/
我已经在我的 Windows 7 机器上安装了 TAP-WIN32 Adapter V9。我想用 TUN 从接口(interface)读取 IP 数据包。我遵循了 C# 示例 http://www.v
TAP/TUN 设备的“目标地址”的目的是什么? Pytun让您轻松设置抽头/调谐设备的参数: tun = TapTunDevice(name='mytun') tun.addr = '10.66.6
我将尝试使用 openvpn 连接到 HideMyAss VPN 构建 docker 镜像。查看 Dockerfile: FROM ubuntu:16.04 RUN apt-get update RU
我使用 VpnService 创建了一个 TUN 设备.为什么 TUN 接口(interface)在我设备的其他网络接口(interface)中具有最高优先级? 更新 #1 这就是我配置 TUN 设备
将 IP 数据包(从用户空间)发送到 tun 设备和使用原始套接字有什么区别? 为了通过用户空间传输 IP 数据包。为什么我会使用一种方法而不是另一种方法? 原始套接字: s = socket(AF_
我正在关注http://backreference.org/2010/03/26/tuntap-interface-tutorial/ 当我以 root 身份运行以下代码时,它成功获取了一个 fd(通
我正在尝试拦截通过 TUN 接口(interface)的数据包。我想将原始数据包信息转换为可读信息,以便稍后使用。 我使用以下代码: int main(){ char tun_name[IFN
我在这里引用示例:https://www.kernel.org/doc/Documentation/networking/tuntap.txt (这很旧),但此处的链接表明同样的事情也应该有效:( h
我目前正在探索不同的网络接口(interface)并遇到了 tun/tap。我对创建套接字的一部分感到困惑。 我们能否在分配给 tun/tap 接口(interface)的 IP 地址上创建具有已知端
我想创建一个 TUN 界面我在 adb 中键入命令,如下所示 mkdir -p /dev/net busybox mknod /dev/net/tun1 c 10 200 chmod 666 /dev
我很难解决这个问题 - 我正在尝试编写一个程序来与 Linux 隧道驱动程序交互。在最基本的层面上,我只想创建一个能够通过网络隧道传输数据的应用程序。但是,对于如何正确设置隧道驱动程序以实现此目的,我
我在理解 tun/tap 设备的实际工作方式时遇到了一点问题,这是来自 wiki 的内容 How does Virtual network device actually work ? Virtual
我不清楚 tun/tap 如何界面正在工作。从维基百科,我得到了这个: 操作系统通过 TUN/TAP 设备发送的数据包被传递到用户空间程序,该程序将自身附加到设备上。用户空间程序也可以将数据包传递到
短版 .是否有 Linux API 允许从文件描述符中读取(类似于 read())而不实际从操作系统缓冲区中删除数据?某种方式将 read() 拆分为等价于 front() (读取而不删除)和 pop
我喜欢用 C++ 程序创建 TUN/TAP 接口(interface)。我在网上找到了一个直接的教程 http://backreference.org/2010/03/26/tuntap-interf
我正在尝试通过 TUN device 以编程方式构建和发送 IP 数据包. 我已经设置了 TUN 设备和正确的路由: # ip tuntap add mode tun tun0 # ip link s
我正在尝试使用 AX.25 封装创建 TUN 网络设备。有效的是:- 创 build 备- 将其封装设置为 ax25 什么不起作用是设置它的硬件地址。这在 ax.25 通信中至关重要,因为它用于唯一寻
我已使用 连接到现有的 Tap 设备 fd = open(...) 现在我想逐包读取它。如果我使用 read(fd,buffer,sizeof(buffer)); 我不会准确读取 1 个数据包。 我怎
我正在尝试使我用来通过 VPN 连接到我大学的网络的工具成为可能。问题是,我只能生成一个 tun/tap 设备。该工具本身不支持使用特定的网络接口(interface),但它支持使用 HTTP 代理。
我正在尝试使用 tun/tap 将 TCP 数据包读入结构, 因此 IFF_TUN 标志设置为使用 tun 设备(无以太网头)。 我有这样的结构(我不关心字节序问题): Tcp header : st
我是一名优秀的程序员,十分优秀!