Peter Maydell <[email protected]> writes: > 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: [email protected] > Signed-off-by: Peter Maydell <[email protected]> > --- > tests/qtest/test-filter-buffer.c | 4 +++- > tests/qtest/test-filter-mirror.c | 4 +++- > tests/qtest/test-filter-redirector.c | 4 +++- > 3 files changed, 9 insertions(+), 3 deletions(-) > > diff --git a/tests/qtest/test-filter-buffer.c > b/tests/qtest/test-filter-buffer.c > index 441cbb975ca..418caccf00a 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 723d2c2f291..9972712cb49 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 5540c232c0b..a4f9b73c72a 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);
Reviewed-by: Fabiano Rosas <[email protected]>
