Commit f996ee991c for qemu.org
commit f996ee991c1f234046fd9a81ca152a7c8cf7ce3a
Author: Peter Maydell <peter.maydell@linaro.org>
Date: Tue Nov 10 18:06:53 2026 +0000
tests/qtest: Make netfilter tests accept padded ethernet packets
Currently the various netfilter tests assume and assert that the data
they get from the filter is an exact match for the data that they
send in to it via the net socket backend. This happens to be the
case currently because the net socket backend fails to pad frames to
the ethernet minimum when the device expects that (unlike e.g. the
tap backend). When we fix the socket backend to honour the device's
request for padding, the netfilter will see padded packets for
devices that require them (which is most of them), and not for those
that don't (notably virtio-net).
This seems best considered as a test error: if you're using netfilter
to look at what a particular network device is receiving, you want to
actually see what it is receiving. And most real-world users of
filtering will be doing it with the backends like TAP that were
already doing pad-before-filter; it's only the oddball backends like
'socket' that forgot to pad.
Make the test cases accept as valid both padded and unpadded frames.
Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-id: 20261110180655.2072265-2-peter.maydell@linaro.org
diff --git a/tests/qtest/test-filter-buffer.c b/tests/qtest/test-filter-buffer.c
index 441cbb975c..418caccf00 100644
--- a/tests/qtest/test-filter-buffer.c
+++ b/tests/qtest/test-filter-buffer.c
@@ -11,6 +11,7 @@
#include "qobject/qdict.h"
#include "qemu/iov.h"
#include "qemu/sockets.h"
+#include "net/eth.h"
/*
* Test that changing interval at runtime affects packet release timing.
@@ -148,7 +149,8 @@ static void test_change_interval_timer(void)
ret = recv(recv_sock, &len, sizeof(len), 0);
g_assert_cmpint(ret, ==, sizeof(len));
len = ntohl(len);
- g_assert_cmpint(len, ==, sizeof(send_buf));
+ /* The snooped network device might or might not have asked for padding */
+ g_assert(len == sizeof(send_buf) || len == MAX(sizeof(send_buf), ETH_ZLEN));
ret = recv(recv_sock, recv_buf, len, 0);
g_assert_cmpint(ret, ==, len);
diff --git a/tests/qtest/test-filter-mirror.c b/tests/qtest/test-filter-mirror.c
index 723d2c2f29..9972712cb4 100644
--- a/tests/qtest/test-filter-mirror.c
+++ b/tests/qtest/test-filter-mirror.c
@@ -15,6 +15,7 @@
#include "qemu/sockets.h"
#include "qemu/error-report.h"
#include "qemu/main-loop.h"
+#include "net/eth.h"
static void test_mirror(void)
{
@@ -58,7 +59,8 @@ static void test_mirror(void)
g_assert_cmpint(ret, ==, sizeof(len));
len = ntohl(len);
- g_assert_cmpint(len, ==, sizeof(send_buf));
+ /* The snooped network device might or might not have asked for padding */
+ g_assert(len == sizeof(send_buf) || len == MAX(sizeof(send_buf), ETH_ZLEN));
recv_buf = g_malloc(len);
ret = recv(recv_sock[0], recv_buf, len, 0);
g_assert_cmpint(ret, ==, len);
diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter-redirector.c
index 5540c232c0..a4f9b73c72 100644
--- a/tests/qtest/test-filter-redirector.c
+++ b/tests/qtest/test-filter-redirector.c
@@ -57,6 +57,7 @@
#include "qemu/sockets.h"
#include "qemu/error-report.h"
#include "qemu/main-loop.h"
+#include "net/eth.h"
static void test_redirector_tx(void)
{
@@ -115,7 +116,8 @@ static void test_redirector_tx(void)
g_assert_cmpint(ret, ==, sizeof(len));
len = ntohl(len);
- g_assert_cmpint(len, ==, sizeof(send_buf));
+ /* The snooped network device might or might not have asked for padding */
+ g_assert(len == sizeof(send_buf) || len == MAX(sizeof(send_buf), ETH_ZLEN));
recv_buf = g_malloc(len);
ret = recv(recv_sock, recv_buf, len, 0);
g_assert_cmpint(ret, ==, len);