The PACKET_IGNORE_OUTGOING socket option is used unconditionally,
but it was only added to the uapi headers in Linux 4.20. The build
fails on distributions shipping older kernel headers, like RHEL 8
(kernel-headers-4.18.0-193.el8, gcc 8.5.0):
../drivers/net/af_packet/rte_eth_af_packet.c:
In function 'rte_pmd_init_internals':
../drivers/net/af_packet/rte_eth_af_packet.c:1057:41:
error: 'PACKET_IGNORE_OUTGOING' undeclared
(first use in this function); did you mean 'PACKET_OUTGOING'?
rc = setsockopt(qsockfd, SOL_PACKET, PACKET_IGNORE_OUTGOING,
^~~~~~~~~~~~~~~~~~~~~~
PACKET_OUTGOING
../drivers/net/af_packet/rte_eth_af_packet.c:1057:41:
note: each undeclared identifier is reported only once
for each function it appears in
Define the constant when the headers lack it, as is already done for
PACKET_FANOUT_FLAG_IGNORE_OUTGOING.
Kernels older than 4.20 also reject the option with ENOPROTOOPT,
which makes the probe of a single-queue port fail when
ignore_outgoing is enabled. In this case, fall back to filtering
outgoing packets in the PMD, as already done for multi-queue ports
on kernels without PACKET_FANOUT_FLAG_IGNORE_OUTGOING support.
DPDK documents Linux 5.4 as the minimum kernel, but the PMD already
tolerates older kernels for multi-queue ports. Do the same here
instead of failing the probe, for example on the 4.18 kernel of
RHEL 8.
Fixes: 3db7aa7868b2 ("net/af_packet: use kernel to filter single-queue Rx")
Signed-off-by: Bing Zhao <[email protected]>
---
doc/guides/nics/af_packet.rst | 1 +
drivers/net/af_packet/rte_eth_af_packet.c | 16 ++++++++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/doc/guides/nics/af_packet.rst b/doc/guides/nics/af_packet.rst
index 6282f1e18b..09e79ff392 100644
--- a/doc/guides/nics/af_packet.rst
+++ b/doc/guides/nics/af_packet.rst
@@ -45,6 +45,7 @@ of AF_PACKET for frame reception.
When ``ignore_outgoing`` is set, ``PACKET_IGNORE_OUTGOING`` is set for
single-queue ports,
which moves the filtering from the PMD to the kernel.
+This option requires Linux 4.20; on older kernels the PMD does the filtering.
For multi-queue ports ``PACKET_FANOUT_FLAG_IGNORE_OUTGOING`` is set
to achieve the same but this only works from Linux 6.2.
For earlier Linux versions, the PMD does the filtering for multi-queue ports.
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c
b/drivers/net/af_packet/rte_eth_af_packet.c
index 44f82c0309..fbaea57615 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -32,6 +32,11 @@
#include <unistd.h>
#include <poll.h>
+/* Added in Linux 4.20. Older kernels reject it with ENOPROTOOPT. */
+#ifndef PACKET_IGNORE_OUTGOING
+#define PACKET_IGNORE_OUTGOING 23
+#endif
+
/* Added in Linux 6.2. Older kernels ignore it. */
#ifndef PACKET_FANOUT_FLAG_IGNORE_OUTGOING
#define PACKET_FANOUT_FLAG_IGNORE_OUTGOING 0x4000
@@ -916,6 +921,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
int qsockfd = -1;
unsigned int i, q, rdsize;
int fanout_arg;
+ bool pmd_filter;
for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
pair = &kvlist->pairs[k_idx];
@@ -1053,10 +1059,16 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
#endif
}
+ pmd_filter = ignore_outgoing != 0 && nb_queues > 1;
if (ignore_outgoing != 0 && nb_queues == 1) {
rc = setsockopt(qsockfd, SOL_PACKET,
PACKET_IGNORE_OUTGOING,
&ignore_outgoing,
sizeof(ignore_outgoing));
- if (rc == -1) {
+ if (rc == -1 && errno == ENOPROTOOPT) {
+ PMD_LOG(INFO,
+ "%s: PACKET_IGNORE_OUTGOING not
supported by kernel, filtering in PMD",
+ name);
+ pmd_filter = true;
+ } else if (rc == -1) {
PMD_LOG_ERRNO(ERR,
"%s: could not set
PACKET_IGNORE_OUTGOING "
"on AF_PACKET socket for %s",
@@ -1083,7 +1095,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
rx_queue = &((*internals)->rx_queue[q]);
rx_queue->framecount = req->tp_frame_nr;
- rx_queue->ignore_outgoing = ignore_outgoing != 0 && nb_queues >
1;
+ rx_queue->ignore_outgoing = pmd_filter;
rx_queue->map = mmap(NULL, 2 * req->tp_block_size *
req->tp_block_nr,
PROT_READ | PROT_WRITE, MAP_SHARED |
MAP_LOCKED,
--
2.27.0