net/filter-mirror:add filter-mirror and unit test
v6 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.
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 | 90 ++++++++++++++++++++++ vl.c | 3 +- 7 files changed, 282 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 v6 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 v6 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 | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 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 +90 -0
90 lines not on this page · raw message
Signature · 1 line
1.9.1
Jason Wang
AppliedQuoted 33 lines · Zhang Chen
Filter-mirror is a netfilter plugin.
It gives qemu the ability to mirror
packets to a chardev.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
Quoted 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 | 90 ++++++++++++++++++++++ vl.c | 3 +- 7 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 net/filter-mirror.c create mode 100644 tests/test-filter-mirror.c
Applied to -net with minor tweaks on commit log.
Thanks
Quoted 46 lines · Jason Wang
Quoted 33 lines · Zhang Chen
Filter-mirror is a netfilter plugin.
It gives qemu the ability to mirror
packets to a chardev.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 | 90 ++++++++++++++++++++++ vl.c | 3 +- 7 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 net/filter-mirror.c create mode 100644 tests/test-filter-mirror.c
Quoted 4 lines
Applied to -net with minor tweaks on commit log.
Thanks
Actually reverted, since I get:
tests/test-filter-mirror.o: In function `test_mirror':/home/devel/git/qemu/tests/test-filter-mirror.c:36: warning: the use of mktemp' is dangerous, better use mkstemp' or `mkdtemp'
Please fix this and send a V7.
Thanks
Quoted 53 lines · Jason Wang
Quoted 45 lines · Jason Wang
Quoted 41 lines · Zhang Chen
Filter-mirror is a netfilter plugin.
It gives qemu the ability to mirror
packets to a chardev.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 | 90 ++++++++++++++++++++++ vl.c | 3 +- 7 files changed, 282 insertions(+), 1 deletion(-)Quoted 3 lines
create mode 100644
net/filter-mirror.c
create mode 100644tests/test-filter-mirror.cQuoted 4 lines
Applied to -net with minor tweaks on commit log.
Thanks
Actually reverted, since I get:
Quoted 9 lines
tests/test-filter-mirror.o: In function `test_mirror':/home/devel/git/qemu/tests/test-filter-mirror.c:36: warning: the use ofmktemp' is dangerous, better usemkstemp' or `mkdtemp'Please fix this and send a V7.
Thanks
OK, I will fix it in V7
Thanks
zhangchen
Quoted 3 lines
.
Signature · 2 lines
Thanks zhangchen