Skip to contentSkip to conversation

net/filter-mirror:add filter-mirror and unit test

PATCH Applied Zhang Chen 2 participants 4 messages Mar 15, 2016 – Mar 16, 2016 Networking

lore
Share & tools
lore

Zhang Chen

author
#0 lore raw

v10 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.

v10:
- add include "qemu/osdep.h"

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        | 182 +++++++++++++++++++++++++++++++++++++++++++++
 qemu-options.hx            |   5 ++
 tests/.gitignore           |   1 +
 tests/Makefile             |   2 +
 tests/test-filter-mirror.c |  93 +++++++++++++++++++++++
 vl.c                       |   3 +-
 7 files changed, 286 insertions(+), 1 deletion(-)
 create mode 100644 net/filter-mirror.c
 create mode 100644 tests/test-filter-mirror.c
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v10 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 | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 qemu-options.hx     |   5 ++
 vl.c                |   3 +-
 4 files changed, 190 insertions(+), 1 deletion(-)
 create mode 100644 net/filter-mirror.c
net/Makefile.objs +1 -0
index 5fa2f97..b7c22fd 100644
@@ -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 +182 -0

182 lines not on this page · raw message

qemu-options.hx +5 -0
index 2f0465e..ca27863 100644
@@ -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
index 175ebcc..d68533a 100644
@@ -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
author
#2 lore raw

PATCH v10 2/2 tests/test-filter-mirror:add filter-mirror unit test

In reply to Zhang Chen

In 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=mirror0

We 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 | 93 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+)
 create mode 100644 tests/test-filter-mirror.c
tests/.gitignore +1 -0
index 787c95c..10df017 100644
@@ -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
index 650e654..e56c514 100644
@@ -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 +93 -0

93 lines not on this page · raw message

Signature · 1 line
1.9.1
Applied
#3 lore raw
In reply to Zhang Chen
Quoted 48 lines · Zhang Chen

Filter-mirror is a netfilter plugin.
It gives qemu the ability to mirror
packets to a chardev.

v10:
- add include "qemu/osdep.h"

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

Quoted 11 lines
 net/Makefile.objs          |   1 +
 net/filter-mirror.c        | 182 +++++++++++++++++++++++++++++++++++++++++++++
 qemu-options.hx            |   5 ++
 tests/.gitignore           |   1 +
 tests/Makefile             |   2 +
 tests/test-filter-mirror.c |  93 +++++++++++++++++++++++
 vl.c                       |   3 +-
 7 files changed, 286 insertions(+), 1 deletion(-)
 create mode 100644 net/filter-mirror.c
 create mode 100644 tests/test-filter-mirror.c

Applied to -net.

Thanks