Skip to contentSkip to conversation

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

PATCH Superseded Zhang Chen 3 participants 6 messages Mar 15, 2016 Networking

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Zhang Chen

author
#0 lore raw

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
author
#1 lore raw

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
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 +181 -0

181 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 v9 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 | 92 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 95 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 +92 -0

92 lines not on this page · raw message

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

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

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 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
#4 lore raw
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:
- add qmp("{ 'execute' : 'query-status'}")
before iov_send() and change pipe
to socket in test-filter-mirror.c

Want to merge the series, but it doesn't build on my laptop (and another machine).

Quoted 7 lines

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);

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

.

author
#5 lore raw
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:
- add qmp("{ 'execute' : 'query-status'}")
before iov_send() and change pipe
to socket in test-filter-mirror.c

Want to merge the series, but it doesn't build on my laptop (and another machine).

Quoted 7 lines

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 2 lines

I think he doesn't use the newest commit.
After the commit 2744d920, we should include qemu/osdep.h first

Thanks, I will fix in now~
zhangchen

Quoted 56 lines

Thanks
Wen Congyang

Quoted 49 lines
Quoted 44 lines

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(-)
Quoted 3 lines

create mode 100644 net/filter-mirror.c
create mode 100644 tests/test-filter-mirror.c

Quoted 2 lines

.

.

Signature · 2 lines
Thanks
zhangchen