net/filter-mirror:add filter-mirror and unit test
v9 cover net/filter-mirror:add filter-mirror and unit test
Filter-mirror is a netfilter plugin.
It gives qemu the ability to mirror
packets to a chardev.
v9:
- add qmp("{ 'execute' : 'query-status'}")
before iov_send() and change pipe
to socket in test-filter-mirror.c
v8:
- The outdev of filter-mirror test changed
from -chardev socket to -chardev pipe
v7:
- fix mktemp() to mkstemp()
v6:
- Address Jason's comments.
v5:
- Address Jason's comments.
v4:
- Address Jason's comments.
v3:
- Add filter-mirror unit test according
to Jason's comments
- Address zhanghailiang's comments.
- Address Jason's comments.
v2:
- Address zhanghailiang's comments.
- Address Eric Blake's comments.
- Address Yang Hongyang's comments.
- Address Dave's comments.
v1:
initial patch.
Zhang Chen (2):
net/filter-mirror:Add filter-mirror tests/test-filter-mirror:add filter-mirror unit test
net/Makefile.objs | 1 + net/filter-mirror.c | 181 +++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 5 ++ tests/.gitignore | 1 + tests/Makefile | 2 + tests/test-filter-mirror.c | 92 +++++++++++++++++++++++ vl.c | 3 +- 7 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 net/filter-mirror.c create mode 100644 tests/test-filter-mirror.c
Signature · 1 line
1.9.1
PATCH v9 1/2 net/filter-mirror:Add filter-mirror
Filter-mirror is a netfilter plugin.
It gives qemu the ability to mirror
packets to a chardev.
usage:
-netdev tap,id=hn0
-chardev socket,id=mirror0,host=ip_primary,port=X,server,nowait -filter-mirror,id=m0,netdev=hn0,queue=tx/rx/all,outdev=mirror0
--- net/Makefile.objs | 1 + net/filter-mirror.c | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 5 ++ vl.c | 3 +- 4 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 net/filter-mirror.c
net/Makefile.objs +1 -0
@@ -15,3 +15,4 @@ common-obj-$(CONFIG_VDE) += vde.o common-obj-$(CONFIG_NETMAP) += netmap.o common-obj-y += filter.o common-obj-y += filter-buffer.o +common-obj-y += filter-mirror.o
net/filter-mirror.c new file +181 -0
181 lines not on this page · raw message
qemu-options.hx +5 -0
@@ -3759,6 +3759,11 @@ queue @var{all|rx|tx} is an option that can be applied to any netfilter. @option{tx}: the filter is attached to the transmit queue of the netdev, where it will receive packets sent by the netdev. +@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid}[,queue=@var{all|rx|tx}] + +filter-mirror on netdev @var{netdevid},mirror net packet to chardev +@var{chardevid} + @item -object filter-dump,id=@var{id},netdev=@var{dev},file=@var{filename}][,maxlen=@var{len}] Dump the network traffic on netdev @var{dev} to the file specified by
vl.c +2 -1
@@ -2798,7 +2798,8 @@ static bool object_create_initial(const char *type)* they depend on netdevs already existing */ if (g_str_equal (type,"filter-buffer" ) || -g_str_equal (type,"filter-dump" )) { +g_str_equal (type,"filter-dump" ) || +g_str_equal (type,"filter-mirror" )) {return false; }
Signature · 1 line
1.9.1
PATCH v9 2/2 tests/test-filter-mirror:add filter-mirror unit test
In reply to Zhang ChenIn this unit test we will test the mirror function.
start qemu with:
-netdev socket,id=qtest-bn0,fd=sockfd
-device e1000,netdev=qtest-bn0,id=qtest-e0
-chardev socket,id=mirror0,path=/tmp/filter-mirror-test.sock,server,nowait
-object filter-mirror,id=qtest-f0,netdev=qtest-bn0,queue=tx,outdev=mirror0We inject packet to netdev socket id = qtest-bn0, filter-mirror will copy and mirror the packet to mirror0. we read packet from mirror0 and then compare to what we inject.
--- tests/.gitignore | 1 + tests/Makefile | 2 + tests/test-filter-mirror.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 tests/test-filter-mirror.c
tests/.gitignore +1 -0
@@ -63,5 +63,6 @@ test-write-threshold test-x86-cpuid test-xbzrle test-netfilter +test-filter-mirror *-test qapi-schema/*.test.*
tests/Makefile +2 -0
@@ -212,6 +212,7 @@ ifeq ($(CONFIG_VHOST_NET_TEST_i386),) check-qtest-x86_64-$(CONFIG_VHOST_NET_TEST_x86_64) += tests/vhost-user-test$(EXESUF) endif check-qtest-i386-y += tests/test-netfilter$(EXESUF) +check-qtest-i386-y += tests/test-filter-mirror$(EXESUF) check-qtest-x86_64-y = $(check-qtest-i386-y) gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
@@ -563,6 +564,7 @@ tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_hel tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y) tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-obj-y) tests/test-netfilter$(EXESUF): tests/test-netfilter.o $(qtest-obj-y) +tests/test-filter-mirror$(EXESUF): tests/test-filter-mirror.o $(qtest-obj-y) tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y) tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o
tests/test-filter-mirror.c new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
1.9.1
Quoted 8 lines · Zhang Chen
Filter-mirror is a netfilter plugin.
It gives qemu the ability to mirror
packets to a chardev.v9:
- addqmp("{ 'execute' : 'query-status'}")
beforeiov_send()and change pipe
to socket intest-filter-mirror.c
Want to merge the series, but it doesn't build on my laptop (and another machine).
CHK version_gen.h
CC net/filter-mirror.o
In file included from /home/devel/git/qemu/include/net/filter.h:12:0,
from net/filter-mirror.c:12:/home/devel/git/qemu/include/qom/object.h:300:39: error: unknown type name ‘Error’
Error **errp);
Quoted 47 lines
v8:
- The outdev of filter-mirror test changed
from -chardev socket to -chardev pipev7:
- fixmktemp()tomkstemp()v6:
- Address Jason's comments.v5:
- Address Jason's comments.v4:
- Address Jason's comments.v3:
- Add filter-mirror unit test according
to Jason's comments
- Address zhanghailiang's comments.
- Address Jason's comments.v2:
- Address zhanghailiang's comments.
- Address Eric Blake's comments.
- Address Yang Hongyang's comments.
- Address Dave's comments.v1:
initial patch.Zhang Chen (2):
net/filter-mirror:Add filter-mirror tests/test-filter-mirror:add filter-mirror unit testnet/Makefile.objs | 1 + net/filter-mirror.c | 181 +++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 5 ++ tests/.gitignore | 1 + tests/Makefile | 2 + tests/test-filter-mirror.c | 92 +++++++++++++++++++++++ vl.c | 3 +- 7 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 net/filter-mirror.c create mode 100644 tests/test-filter-mirror.c
Quoted 15 lines · Jason Wang
Quoted 8 lines · Zhang Chen
Filter-mirror is a netfilter plugin.
It gives qemu the ability to mirror
packets to a chardev.v9:
- addqmp("{ 'execute' : 'query-status'}")
beforeiov_send()and change pipe
to socket intest-filter-mirror.cWant to merge the series, but it doesn't build on my laptop (and another machine).
Quoted 7 lines
CHK
version_gen.h
CCnet/filter-mirror.o
In file included from/home/devel/git/qemu/include/net/filter.h:12:0,
fromnet/filter-mirror.c:12:/home/devel/git/qemu/include/qom/object.h:300:39: error: unknown type name ‘Error’Error **errp);
I think he doesn't use the newest commit.
After the commit 2744d920, we should include qemu/osdep.h first
Thanks
Wen Congyang
Quoted 53 lines
Quoted 37 lines
v8:
- The outdev of filter-mirror test changed
from -chardev socket to -chardev pipev7:
- fixmktemp()tomkstemp()v6:
- Address Jason's comments.v5:
- Address Jason's comments.v4:
- Address Jason's comments.v3:
- Add filter-mirror unit test according
to Jason's comments
- Address zhanghailiang's comments.
- Address Jason's comments.v2:
- Address zhanghailiang's comments.
- Address Eric Blake's comments.
- Address Yang Hongyang's comments.
- Address Dave's comments.v1:
initial patch.Zhang Chen (2):
net/filter-mirror:Add filter-mirror tests/test-filter-mirror:add filter-mirror unit testQuoted 11 lines
net/Makefile.objs | 1 + net/filter-mirror.c | 181 +++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 5 ++ tests/.gitignore | 1 + tests/Makefile | 2 + tests/test-filter-mirror.c | 92 +++++++++++++++++++++++ vl.c | 3 +- 7 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 net/filter-mirror.c create mode 100644 tests/test-filter-mirror.c.
Quoted 21 lines · Wen Congyang
Quoted 13 lines · Jason Wang
Quoted 8 lines · Zhang Chen
Filter-mirror is a netfilter plugin.
It gives qemu the ability to mirror
packets to a chardev.v9:
- addqmp("{ 'execute' : 'query-status'}")
beforeiov_send()and change pipe
to socket intest-filter-mirror.cWant to merge the series, but it doesn't build on my laptop (and another machine).
Quoted 7 lines
CHK
version_gen.h
CCnet/filter-mirror.o
In file included from/home/devel/git/qemu/include/net/filter.h:12:0,
fromnet/filter-mirror.c:12:/home/devel/git/qemu/include/qom/object.h:300:39: error: unknown type name ‘Error’Error **errp);
Quoted 2 lines
I think he doesn't use the newest commit.
After the commit2744d920, we should includeqemu/osdep.hfirst
Thanks, I will fix in now~
zhangchen
Quoted 56 lines
Thanks
Wen CongyangQuoted 49 lines
Quoted 44 lines
v8:
- The outdev of filter-mirror test changed
from -chardev socket to -chardev pipev7:
- fixmktemp()tomkstemp()v6:
- Address Jason's comments.v5:
- Address Jason's comments.v4:
- Address Jason's comments.v3:
- Add filter-mirror unit test according
to Jason's comments
- Address zhanghailiang's comments.
- Address Jason's comments.v2:
- Address zhanghailiang's comments.
- Address Eric Blake's comments.
- Address Yang Hongyang's comments.
- Address Dave's comments.v1:
initial patch.Zhang Chen (2):
net/filter-mirror:Add filter-mirror tests/test-filter-mirror:add filter-mirror unit testnet/Makefile.objs | 1 + net/filter-mirror.c | 181 +++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 5 ++ tests/.gitignore | 1 + tests/Makefile | 2 + tests/test-filter-mirror.c | 92 +++++++++++++++++++++++ vl.c | 3 +- 7 files changed, 284 insertions(+), 1 deletion(-)Quoted 3 lines
create mode 100644
net/filter-mirror.c
create mode 100644tests/test-filter-mirror.cQuoted 2 lines
.
.
Signature · 2 lines
Thanks zhangchen