【问题标题】:Does libpcap use the traffic control layer of linux?libpcap是否使用了linux的流量控制层?
【发布时间】:2020-06-04 12:54:08
【问题描述】:
我正在创建一个单独的网络堆栈,我正在使用 libpcap,或者特别是 pcap_inject 函数将数据包直接发送到链路层。但是,当我查看tc -s qdisc show dev eth0 命令时,我看到我发送的数据包正在计入从队列发送的数据包中。所以我的问题是,pcap_inject 会调用linux 的流量控制层来发送数据包吗?还是直接发给设备驱动?
提前致谢
【问题讨论】:
标签:
linux
network-programming
ethernet
libpcap
raw-ethernet
【解决方案1】:
pcap_inject 是否调用linux的流量控制层发送数据包?还是直接发给设备驱动?
它对a PF_PACKET socket 进行send() 调用。默认情况下,在这些套接字上发送的数据包会通过流量控制层;引用the PF_PACKET socket man page:
PACKET_QDISC_BYPASS (since Linux 3.14)
By default, packets sent through packet sockets pass through
the kernel's qdisc (traffic control) layer, which is fine for
the vast majority of use cases. For traffic generator appli‐
ances using packet sockets that intend to brute-force flood
the network—for example, to test devices under load in a simi‐
lar fashion to pktgen—this layer can be bypassed by setting
this integer option to 1. A side effect is that packet
buffering in the qdisc layer is avoided, which will lead to
increased drops when network device transmit queues are busy;
therefore, use at your own risk.
libpcap 不打开该选项。