For QEMU 2.5: Add a net filter and a netbuffer plugin based on the filter
cover For QEMU 2.5: Add a net filter and a netbuffer plugin based on the filter
This patch add a net filter between network backend and NIC devices. All packets will pass by this filter.
Also implement a netbuffer plugin for example, the netbuffer plugin could be used by VM FT solutions like Macrocheckpointing, to buffer/release packets.
Based on this, dump plugin could be easily implemented.
I've done some simple tests on this series,
backend, tap,user
NIC, e1000,virtio-net
There's still some missing functions to be done, I've posted this early in order to gain more comments, thank you!
TODO:
multiqueue support.
+--------------+ +-------------+ +----------+ | filter | |frontend(NIC)| | peer+--> | | | | network <--+backend <-------+ peer | | backend | | peer +-------> | +----------+ +--------------+ +-------------+
Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0
-netdev filter-<plugin>,id=p0,filter=f0
-device e1000,netdev=f0
NOTE:
You can attach multiple plugins to the filter, dynamically add/remove
filter and filter-<plugin>.
The netbuffer plugin:
Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0
-netdev filter-buffer,id=p0,filter=f0
-device e1000,netdev=f0
Will supply a public API to release the buffer. But there's no callers currently.
To test this feature, it's quite simple, just use netdev_add filter-buffer,id=p0,filter=f0
to buffer packets,netdev_del p0
will release packets.
You can also implement whatever plugin you needed based on this filter.
Yang Hongyang (9):
netdev: Add a net filter
virtio-net: add filter support
filter: remove plugins when remove filter
filter: remove filter before remove network backend
filter: add netbuffer plugin
introduce qemu_find_net_clients_by_model net/queue: export qemu_net_queue_append move out net queue structs define
add a public api to release buffer
hw/net/virtio-net.c | 17 ++- include/net/filter.h | 21 ++++ include/net/net.h | 5 + include/net/queue.h | 26 ++++ net/Makefile.objs | 2 + net/clients.h | 6 + net/filter-buffer.c | 185 ++++++++++++++++++++++++++++ net/filter.c | 331 +++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 51 +++++++- net/queue.c | 31 +---- qapi-schema.json | 40 ++++++- 11 files changed, 679 insertions(+), 36 deletions(-) create mode 100644 include/net/filter.h create mode 100644 net/filter-buffer.c create mode 100644 net/filter.c
Signature · 1 line
1.9.1
PATCH 1/9 netdev: Add a net filter
This patch add a net filter between network backend and NIC devices. All packets will pass by this filter.
TODO:
multiqueue support.
+--------------+ +-------------+ +----------+ | filter | |frontend(NIC)| | peer+--> | | | | network <--+backend <-------+ peer | | backend | | peer +-------> | +----------+ +--------------+ +-------------+
Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0
-netdev filter-<plugin>,id=p0,filter=f0
-device e1000,netdev=f0
NOTE:
You can attach multiple plugins to the filter, dynamically add/remove
filter and filter-<plugin>.
A filter without plugin supplied will do nothing except pass by all
packets, a plugin like dump for example, will dump all packets into a file. Or other plugins like a netbuffer plugin, will simply buffer the packets, release the packets when needed.
You can also implement whatever plugin you needed based on this filter.
--- include/net/filter.h | 18 +++ include/net/net.h | 3 + net/Makefile.objs | 1 + net/clients.h | 3 + net/filter.c | 317 +++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 20 +++- qapi-schema.json | 22 +++- 7 files changed, 377 insertions(+), 7 deletions(-) create mode 100644 include/net/filter.h create mode 100644 net/filter.c
include/net/filter.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Copyright (c) 2015 FUJITSU LIMITED +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#ifndef QEMU_NET_FILTER_H +#define QEMU_NET_FILTER_H + +#include "qemu-common.h" +//#include "qapi-types.h" + +NetClientState *filter_backend (NetClientState *nc); +int filter_add_plugin (NetClientState *nc,NetClientState *plugin); +int filter_del_plugin (NetClientState *nc,NetClientState *plugin); + +#endif /* QEMU_NET_FILTER_H */
include/net/net.h +3 -0
@@ -45,6 +45,8 @@ typedef void (NetPoll)(NetClientState *, bool enable);typedef int (NetCanReceive )(NetClientState *);typedef ssize_t (NetReceive )(NetClientState *,const uint8_t *,size_t );typedef ssize_t (NetReceiveIOV )(NetClientState *,const struct iovec *,int ); +typedef ssize_t (NetReceiveFilter )(NetClientState *,NetClientState *, +unsigned ,const uint8_t *,size_t );typedef void (NetCleanup ) (NetClientState *);typedef void (LinkStatusChanged )(NetClientState *);typedef void (NetClientDestructor )(NetClientState *);
@@ -64,6 +66,7 @@ typedef struct NetClientInfo {NetReceive *receive;NetReceive *receive_raw;NetReceiveIOV *receive_iov; +NetReceiveFilter *receive_filter;NetCanReceive *can_receive;NetCleanup *cleanup;LinkStatusChanged *link_status_changed;
net/Makefile.objs +1 -0
@@ -13,3 +13,4 @@ common-obj-$(CONFIG_HAIKU) += tap-haiku.o common-obj-$(CONFIG_SLIRP) += slirp.o common-obj-$(CONFIG_VDE) += vde.o common-obj-$(CONFIG_NETMAP) += netmap.o +common-obj-y += filter.o
net/clients.h +3 -0
@@ -62,4 +62,7 @@ int net_init_netmap(const NetClientOptions *opts, const char *name,int net_init_vhost_user (const NetClientOptions *opts,const char *name,NetClientState *peer,Error **errp); +int net_init_filter (const NetClientOptions *opts,const char *name, +NetClientState *peer,Error **errp); +#endif /* QEMU_NET_CLIENTS_H */
net/filter.c new file +317 -0
317 lines not on this page · raw message
net/net.c +15 -5
@@ -57,6 +57,7 @@ const char *host_net_devices[] = {"tap" ,"socket" ,"dump" , +"filter" , #ifdef CONFIG_NET_BRIDGE "bridge", #endif
@@ -396,7 +397,8 @@ void qemu_del_net_client(NetClientState *nc)assert (queues !=0 );/* If there is a peer NIC, delete and cleanup client, but do not free. */ -if (nc->peer && nc->peer->info->type ==NET_CLIENT_OPTIONS_KIND_NIC ) { +if (nc->peer && nc->peer->info->type ==NET_CLIENT_OPTIONS_KIND_NIC + && nc->info->type !=NET_CLIENT_OPTIONS_KIND_FILTER ) {NICState *nic =qemu_get_nic (nc->peer);if (nic->peer_deleted) {return ;
@@ -571,7 +573,9 @@ ssize_t qemu_deliver_packet(NetClientState *sender,return 0 ; } -if (flags &QEMU_NET_PACKET_FLAG_RAW && nc->info->receive_raw) { +if (nc->info->receive_filter) { + ret = nc->info->receive_filter (nc, sender, flags, data, size); + }else if (flags &QEMU_NET_PACKET_FLAG_RAW && nc->info->receive_raw) { ret = nc->info->receive_raw (nc, data, size); }else { ret = nc->info->receive (nc, data, size);
@@ -659,7 +663,8 @@ ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size) buf, size, NULL); } -static ssize_t nc_sendv_compat (NetClientState *nc,const struct iovec *iov, +static ssize_t nc_sendv_compat (NetClientState *nc,NetClientState *sender, +unsigned flags,const struct iovec *iov,int iovcnt) {uint8_t buffer[NET_BUFSIZE ];
@@ -667,7 +672,11 @@ static ssize_t nc_sendv_compat(NetClientState *nc, const struct iovec *iov, offset =iov_to_buf (iov, iovcnt,0 , buffer,sizeof (buffer)); -return nc->info->receive (nc, buffer, offset); +if (nc->info->receive_filter) { +return nc->info->receive_filter (nc, sender, flags, buffer, offset); + }else { +return nc->info->receive (nc, buffer, offset); + } } ssize_t qemu_deliver_packet_iov(NetClientState *sender,
@@ -690,7 +699,7 @@ ssize_t qemu_deliver_packet_iov(NetClientState *sender,if (nc->info->receive_iov) { ret = nc->info->receive_iov (nc, iov, iovcnt); }else { - ret =nc_sendv_compat (nc, iov, iovcnt); + ret =nc_sendv_compat (nc, sender, flags, iov, iovcnt); }if (ret ==0 ) {
@@ -886,6 +895,7 @@ static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(const char *name, NetClientState *peer, Error **errp) = { [NET_CLIENT_OPTIONS_KIND_NIC ] = net_init_nic, + [NET_CLIENT_OPTIONS_KIND_FILTER ] = net_init_filter, #ifdef CONFIG_SLIRP [NET_CLIENT_OPTIONS_KIND_USER ] = net_init_slirp, #endif
qapi-schema.json +20 -2
@@ -2063,7 +2063,7 @@ # Add a network backend. # # @type: the type of network backend. Current valid values are 'user', 'tap', -# 'vde', 'socket', 'dump' and 'bridge' +# 'vde', 'socket', 'dump' , 'bridge' and 'filter' # # @id: the name of the new network backend #
@@ -2474,6 +2474,23 @@ '*vhostforce': 'bool' } } ## +# @NetdevFilterOptions +# +# A net filter between network backend and NIC device +# +# @backend: the network backend. +# +# NOTE: used with filterplugin netdevs which provide filter rules. +# by default, if no filterplugin is supplied, the net filter will do +# nothing but pass all packets to network backend. +# +# Since 2.5 +## +{ 'struct': 'NetdevFilterOptions', + 'data': { + '*backend': 'str' } } + +## # @NetClientOptions # # A discriminated record of network device traits.
@@ -2496,7 +2513,8 @@ 'bridge': 'NetdevBridgeOptions', 'hubport': 'NetdevHubPortOptions', 'netmap': 'NetdevNetmapOptions', - 'vhost-user': 'NetdevVhostUserOptions' } } + 'vhost-user': 'NetdevVhostUserOptions', + 'filter': 'NetdevFilterOptions'} } ## # @NetLegacy
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 1/9] netdev: Add a net filter
Quoted 26 lines · Yang Hongyang
This patch add a net filter between network backend and NIC devices. All packets will pass by this filter.
TODO:
multiqueue support.+--------------+ +-------------+ +----------+ | filter | |frontend(NIC)| | peer+--> | | | | network <--+backend <-------+ peer | | backend | | peer +-------> | +----------+ +--------------+ +-------------+Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0
-netdev filter-<plugin>,id=p0,filter=f0
-device e1000,netdev=f0
NOTE:
You can attach multiple plugins to the filter, dynamically add/remove
filter and filter-<plugin>.
A filter without plugin supplied will do nothing except pass by all
packets, a plugin like dump for example, will dump all packets into a file. Or other plugins like a netbuffer plugin, will simply buffer the packets, release the packets when needed.
You can also implement whatever plugin you needed based on this filter.
Quoted 1 line
Signed-off-by Yang Hongyang <[email protected]>
Hi,
just a quick comment: Please make sure to check your patches with scripts/checkpatch.pl first before sending them for review - at least for this patch, the script complains:
ERROR: do not use C99 // comments
#59: FILE: include/net/filter.h:12:
+//#include "qapi-types.h"
WARNING: braces {} are necessary for all arms of this statement #424: FILE: net/filter.c:311:
+ if (plug->plugin == plugin)
[...]
total: 1 errors, 1 warnings, 463 lines checked
Thomas
Re: [Qemu-devel] [PATCH 1/9] netdev: Add a net filter
Quoted 39 lines · Thomas Huth
Quoted 26 lines · Yang Hongyang
This patch add a net filter between network backend and NIC devices. All packets will pass by this filter.
TODO:multiqueue support. +--------------+ +-------------+ +----------+ | filter | |frontend(NIC)| | peer+--> | | | | network <--+backend <-------+ peer | | backend | | peer +-------> | +----------+ +--------------+ +-------------+Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0 -netdev filter-<plugin>,id=p0,filter=f0 -device e1000,netdev=f0NOTE:
You can attach multiple plugins to the filter, dynamically add/remove
filter and filter-<plugin>.
A filter without plugin supplied will do nothing except pass by all
packets, a plugin like dump for example, will dump all packets into a file. Or other plugins like a netbuffer plugin, will simply buffer the packets, release the packets when needed.
You can also implement whatever plugin you needed based on this filter.Quoted 1 line
Signed-off-by Yang Hongyang <[email protected]>Hi,
just a quick comment: Please make sure to check your patches with
scripts/checkpatch.plfirst before sending them for review - at least for this patch, the script complains:ERROR: do not use C99 // comments
#59: FILE:include/net/filter.h:12:
+//#include "qapi-types.h"
Quoted 6 lines
WARNING: braces {} are necessary for all arms of this statement #424: FILE:
net/filter.c:311:
+ if (plug->plugin== plugin)
[...]total: 1 errors, 1 warnings, 463 lines checked
Sorry for not done so this time, will check next time. Thank you!
Quoted 6 lines
Thomas
.
Signature · 2 lines
Thanks, Yang.
PATCH 2/9 virtio-net: add filter support
In reply to Yang Hongyangvirtio-net explicity check for tap device, aupport for tap with filter attached.
--- hw/net/virtio-net.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
hw/net/virtio-net.c +13 -4
@@ -16,6 +16,7 @@#include "net/net.h" #include "net/checksum.h" #include "net/tap.h" +#include "net/filter.h" #include "qemu/error-report.h" #include "qemu/timer.h" #include "hw/virtio/virtio-net.h"
@@ -406,11 +407,15 @@ static int peer_attach(VirtIONet *n, int index)return 0 ; } -if (nc->peer->info->type !=NET_CLIENT_OPTIONS_KIND_TAP ) { +if (nc->peer->info->type ==NET_CLIENT_OPTIONS_KIND_FILTER ) { + nc =filter_backend (nc->peer); + } + +if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_TAP ) {return 0 ; } -return tap_enable (nc->peer); +return tap_enable (nc); }static int peer_detach (VirtIONet *n,int index)
@@ -421,11 +426,15 @@ static int peer_detach(VirtIONet *n, int index)return 0 ; } -if (nc->peer->info->type !=NET_CLIENT_OPTIONS_KIND_TAP ) { +if (nc->peer->info->type ==NET_CLIENT_OPTIONS_KIND_FILTER ) { + nc =filter_backend (nc->peer); + } + +if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_TAP ) {return 0 ; } -return tap_disable (nc->peer); +return tap_disable (nc); }static void virtio_net_set_queues (VirtIONet *n)
Signature · 1 line
1.9.1
PATCH 3/9 filter: remove plugins when remove filter
In reply to Yang Hongyang--- net/filter.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
net/filter.c +14 -0
@@ -11,6 +11,7 @@#include "qemu-common.h" #include "qemu/error-report.h" #include "net/filter.h" +#include "qemu/config-file.h" typedef struct FilterPlugin FilterPlugin ;struct FilterPlugin {
@@ -81,6 +82,19 @@ out:static void filter_cleanup (NetClientState *nc) {FILTERState *s =DO_UPCAST (FILTERState, nc, nc); +NetClientState *plugin =NULL ; +FilterPlugin *plug =NULL , *next =NULL ; +QemuOpts *opts; + + QLIST_FOREACH_SAFE(plug, &s->plugins, next, next) { + plugin = plug->plugin; + opts =qemu_opts_find (qemu_find_opts_err ("netdev" ,NULL ), + plugin->name); +assert (opts); + +qemu_del_net_client (plugin); +qemu_opts_del (opts); + }if (s->backend && nc->peer) {qemu_flush_queued_packets (nc);
Signature · 1 line
1.9.1
PATCH 4/9 filter: remove filter before remove network backend
In reply to Yang Hongyang--- net/net.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
net/net.c +11 -0
@@ -385,9 +385,20 @@ void qemu_del_net_client(NetClientState *nc) {NetClientState *ncs[MAX_QUEUE_NUM ];int queues, i; +QemuOpts *opts;assert (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC ); +if (nc->peer && + nc->peer->info->type ==NET_CLIENT_OPTIONS_KIND_FILTER ) { + opts =qemu_opts_find (qemu_find_opts_err ("netdev" ,NULL ), + nc->peer->name); +assert (opts); + +qemu_del_net_client (nc->peer); +qemu_opts_del (opts); + } +/* If the NetClientState belongs to a multiqueue backend, we will change all * other NetClientStates also. */
Signature · 1 line
1.9.1
PATCH 5/9 filter: add netbuffer plugin
In reply to Yang HongyangThis could be used by VM FT solutions like Macrocheckpointing, to buffer/release packets.
Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0
-netdev filter-buffer,id=p0,filter=f0
-device e1000,netdev=f0
Will supply a public API to release the buffer. But there's no callers currently.
To test this feature, it's quite simple, just use netdev_add filter-buffer,id=p0,filter=f0
to buffer packets,netdev_del p0
will release packets.
--- net/Makefile.objs | 1 + net/clients.h | 3 ++ net/filter-buffer.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 2 ++ qapi-schema.json | 20 +++++++++++++- 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 net/filter-buffer.c
net/Makefile.objs +1 -0
@@ -14,3 +14,4 @@ common-obj-$(CONFIG_SLIRP) += slirp.o common-obj-$(CONFIG_VDE) += vde.o common-obj-$(CONFIG_NETMAP) += netmap.o common-obj-y += filter.o +common-obj-y += filter-buffer.o
net/clients.h +3 -0
@@ -65,4 +65,7 @@ int net_init_vhost_user(const NetClientOptions *opts, const char *name,int net_init_filter (const NetClientOptions *opts,const char *name,NetClientState *peer,Error **errp); +int net_init_filter_buffer (const NetClientOptions *opts,const char *name, +NetClientState *peer,Error **errp); +#endif /* QEMU_NET_CLIENTS_H */
net/filter-buffer.c new file +80 -0
80 lines not on this page · raw message
net/net.c +2 -0
@@ -58,6 +58,7 @@ const char *host_net_devices[] = {"socket" ,"dump" ,"filter" , +"filter-buffer" , #ifdef CONFIG_NET_BRIDGE "bridge", #endif
@@ -907,6 +908,7 @@ static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])( NetClientState *peer, Error **errp) = { [NET_CLIENT_OPTIONS_KIND_NIC ] = net_init_nic, [NET_CLIENT_OPTIONS_KIND_FILTER ] = net_init_filter, + [NET_CLIENT_OPTIONS_KIND_FILTER_BUFFER ] = net_init_filter_buffer, #ifdef CONFIG_SLIRP [NET_CLIENT_OPTIONS_KIND_USER ] = net_init_slirp, #endif
qapi-schema.json +19 -1
@@ -2491,6 +2491,23 @@ '*backend': 'str' } } ## +# @NetdevFilterBufferOptions +# +# A net filter buffer plugin +# +# @filter: the network filter this plugin attached to. +# +# @interval: #optional release packets by interval, if no interval supplied, +# will release packets when filter_buffer_release been called. +# +# Since 2.5 +## +{ 'struct': 'NetdevFilterBufferOptions', + 'data': { + '*filter': 'str', + '*interval': 'int32' } } + +## # @NetClientOptions # # A discriminated record of network device traits.
@@ -2514,7 +2531,8 @@ 'hubport': 'NetdevHubPortOptions', 'netmap': 'NetdevNetmapOptions', 'vhost-user': 'NetdevVhostUserOptions', - 'filter': 'NetdevFilterOptions'} } + 'filter': 'NetdevFilterOptions', + 'filter-buffer': 'NetdevFilterBufferOptions' } } ## # @NetLegacy
Signature · 1 line
1.9.1
PATCH 6/9 introduce qemu_find_net_clients_by_model
In reply to Yang Hongyang--- include/net/net.h | 2 ++ net/net.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+)
include/net/net.h +2 -0
@@ -108,6 +108,8 @@ char *qemu_mac_strdup_printf(const uint8_t *macaddr);NetClientState *qemu_find_netdev (const char *id);int qemu_find_net_clients_except (const char *id,NetClientState **ncs,NetClientOptionsKind type,int max); +int qemu_find_net_clients_by_model (const char *model,NetClientState **ncs, +int max); NetClientState *qemu_new_net_client(NetClientInfo *info, NetClientState *peer, const char *model,
net/net.c +18 -0
@@ -780,6 +780,24 @@ int qemu_find_net_clients_except(const char *id, NetClientState **ncs,return ret; } +int qemu_find_net_clients_by_model (const char *model,NetClientState **ncs, +int max) +{ +NetClientState *nc; +int ret =0 ; + + QTAILQ_FOREACH(nc, &net_clients, next) { +if (!strcmp (nc->model, model)) { +if (ret < max) { + ncs[ret] = nc; + } + ret++; + } + } + +return ret; +} +static int nic_get_free_idx (void ) {int index;
Signature · 1 line
1.9.1
PATCH 7/9 net/queue: export qemu_net_queue_append
In reply to Yang Hongyang--- include/net/queue.h | 7 +++++++ net/queue.c | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-)
include/net/queue.h +7 -0
@@ -36,6 +36,13 @@ typedef void (NetPacketSent) (NetClientState *sender, ssize_t ret);NetQueue *qemu_new_net_queue (void *opaque); +void qemu_net_queue_append (NetQueue *queue, +NetClientState *sender, +unsigned flags, +const uint8_t *buf, +size_t size, +NetPacketSent *sent_cb); +void qemu_del_net_queue (NetQueue *queue); ssize_t qemu_net_queue_send(NetQueue *queue,
net/queue.c +6 -6
@@ -87,12 +87,12 @@ void qemu_del_net_queue(NetQueue *queue)g_free (queue); } -static void qemu_net_queue_append (NetQueue *queue, -NetClientState *sender, -unsigned flags, -const uint8_t *buf, -size_t size, -NetPacketSent *sent_cb) +void qemu_net_queue_append (NetQueue *queue, +NetClientState *sender, +unsigned flags, +const uint8_t *buf, +size_t size, +NetPacketSent *sent_cb) {NetPacket *packet;
Signature · 1 line
1.9.1
PATCH 8/9 move out net queue structs define
In reply to Yang Hongyang--- include/net/queue.h | 19 +++++++++++++++++++ net/queue.c | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-)
include/net/queue.h +19 -0
@@ -31,6 +31,25 @@ typedef struct NetQueue NetQueue;typedef void (NetPacketSent ) (NetClientState *sender,ssize_t ret); +struct NetPacket { +QTAILQ_ENTRY (NetPacket) entry; +NetClientState *sender; +unsigned flags; +int size; +NetPacketSent *sent_cb; +uint8_t data[0 ]; +}; + +struct NetQueue { +void *opaque; +uint32_t nq_maxlen; +uint32_t nq_count; + + QTAILQ_HEAD(packets, NetPacket) packets; + +unsigned delivering :1 ; +}; +#define QEMU_NET_PACKET_FLAG_NONE 0#define QEMU_NET_PACKET_FLAG_RAW (1<<0)
net/queue.c +0 -19
@@ -39,25 +39,6 @@* unbounded queueing. */ -struct NetPacket { -QTAILQ_ENTRY (NetPacket) entry; -NetClientState *sender; -unsigned flags; -int size; -NetPacketSent *sent_cb; -uint8_t data[0 ]; -}; - -struct NetQueue { -void *opaque; -uint32_t nq_maxlen; -uint32_t nq_count; - - QTAILQ_HEAD(packets, NetPacket) packets; - -unsigned delivering :1 ; -}; -NetQueue *qemu_new_net_queue (void *opaque) {NetQueue *queue;
Signature · 1 line
1.9.1
PATCH 9/9 add a public api to release buffer
In reply to Yang Hongyang--- include/net/filter.h | 3 ++ net/filter-buffer.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 109 insertions(+), 1 deletion(-)
include/net/filter.h +3 -0
@@ -15,4 +15,7 @@ NetClientState *filter_backend(NetClientState *nc);int filter_add_plugin (NetClientState *nc,NetClientState *plugin);int filter_del_plugin (NetClientState *nc,NetClientState *plugin); +/* filter buffer plugin */ +void filter_buffer_release_all (void ); +#endif /* QEMU_NET_FILTER_H */
net/filter-buffer.c +106 -1
150 lines not on this page · raw message
Signature · 1 line
1.9.1
Quoted 24 lines · Yang Hongyang
This patch add a net filter between network backend and NIC devices. All packets will pass by this filter.
Also implement a netbuffer plugin for example, the netbuffer plugin could be used by VM FT solutions like Macrocheckpointing, to buffer/release packets.
Based on this, dump plugin could be easily implemented.I've done some simple tests on this series,
backend, tap,user
NIC, e1000,virtio-netThere's still some missing functions to be done, I've posted this early in order to gain more comments, thank you!
TODO:
multiqueue support. +--------------+ +-------------+ +----------+ | filter | |frontend(NIC)| | peer+--> | | | | network <--+backend <-------+ peer | | backend | | peer +-------> | +----------+ +--------------+ +-------------+
Quoted 5 lines
Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0 -netdev filter-<plugin>,id=p0,filter=f0 -device e1000,netdev=f0
Have you considered Daniel's suggestion ? Using the bellow style:
-netfilter id=f0,plugin=dump
-netdev tap,id=bn0,filter=f0
-device e1000,netdev=bn0
Considering the filter as a new 'netdev' seems to be unreasonable, Whenever we add a new plugin, we have to add a new member to 'NetClientOptions', there will be lots of 'filter' objects in NetClientOptions area. Besides when we want to describe a net device with several filter plugin for VM, it will become like:
-netdev tap,id=bn0
-netdev filter,id=f0,backend=bn0
-netdev filter-<plugin-0>,id=p0,filter=f0
-netdev filter-<plugin-1>,id=p1,filter=f1
... ...
-device e1000,netdev=f0
Which is a little verbose for 'netdev' option.
We'd better come to an agreement on the command line style for net filter :)
Thanks,
zhanghailiang
Quoted 48 lines
NOTE:
You can attach multiple plugins to the filter, dynamically add/remove
filter and filter-<plugin>.The netbuffer plugin:
Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0
-netdev filter-buffer,id=p0,filter=f0
-device e1000,netdev=f0Will supply a public API to release the buffer. But there's no callers currently.
To test this feature, it's quite simple, just usenetdev_addfilter-buffer,id=p0,filter=f0
to buffer packets,netdev_delp0
will release packets.You can also implement whatever plugin you needed based on this filter.
Yang Hongyang (9):
netdev: Add a net filter
virtio-net: add filter support
filter: remove plugins when remove filter
filter: remove filter before remove network backend
filter: add netbuffer plugin
introduceqemu_find_net_clients_by_modelnet/queue: exportqemu_net_queue_appendmove out net queue structs define
add a public api to release bufferhw/net/virtio-net.c | 17 ++- include/net/filter.h | 21 ++++ include/net/net.h | 5 + include/net/queue.h | 26 ++++ net/Makefile.objs | 2 + net/clients.h | 6 + net/filter-buffer.c | 185 ++++++++++++++++++++++++++++ net/filter.c | 331 +++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 51 +++++++- net/queue.c | 31 +---- qapi-schema.json | 40 ++++++- 11 files changed, 679 insertions(+), 36 deletions(-)create mode 100644
include/net/filter.h
create mode 100644net/filter-buffer.c
create mode 100644net/filter.c
Thank you, and sorry to Daniel that I forgot to CC you...
On 07/25/2015 01:06 PM, zhanghailiang wrote:
[...]
Quoted 8 lines
Quoted 8 lines
+--------------+ +-------------+ +----------+ | filter | |frontend(NIC)| | peer+--> | | | | network <--+backend <-------+ peer | | backend | | peer +-------> | +----------+ +--------------+ +-------------+
Quoted 7 lines
Quoted 5 lines
Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0 -netdev filter-<plugin>,id=p0,filter=f0 -device e1000,netdev=f0Have you considered Daniel's suggestion ? Using the bellow style:
Yes, but by dig into the implementation, I think the current way is better, here is the reason:
1. The flexibility to easily dynamically add/remove/change filters on the fly. This is what Daniel was worrying about (please correct me if I didn't get your point) I think I addressed his main concern on this series. And you can specify any param to the filter plugin under existing netdev design.
2. Reuse as many existing code as we can. think about doing a standalone object, add/remove filters will duplicate the existing netdev_add/netdev_del code. the filter plugin need to implement at lease 3 functions, init/cleanup and receive_filter, this is also duplicate the existing netdev design, we already have the architecture to init/cleanup/receive_filter, why not use it?
3. A filter is a backend in my design, so it is absolutely reasonable to implement it as a netdev and it is easy to implement it as a netdev, if you implement it as a standalone object, how do you integrate it to the backend? A filter plugin might be able to be a standalone object, but just as I said on #2, as long as we can archive our goal under the existing design, why duplicate it?
4. Current implementation don't affact the existing code too much, it is a bolt-on feature.
Overall, we reuse the existing design, implemented a flexible and extensible net filter feature, so I think the current way is better.
Quoted 8 lines
-netfilter id=f0,plugin=dump -netdev tap,id=bn0,filter=f0 -device e1000,netdev=bn0Considering the filter as a new 'netdev' seems to be unreasonable, Whenever we add a new plugin, we have to add a new member to 'NetClientOptions', there will be lots of 'filter' objects in NetClientOptions area.
Why can't we extend this struct? I don't see any problem with this. Doing the other way is just to extend another struct.
Besides when we want to describe a net device with several filter plugin
Quoted 9 lines
for VM,
it will become like:-netdev tap,id=bn0 -netdev filter,id=f0,backend=bn0 -netdev filter-<plugin-0>,id=p0,filter=f0 -netdev filter-<plugin-1>,id=p1,filter=f1 ... ... -device e1000,netdev=f0Which is a little verbose for 'netdev' option.
It's just the name diffrence, using netfilter will be -netfilter ... -netfilter ...
using plugin=xxx will make us hard to extend the plugin params under existing netdev design thus will needs lots of extra effort to archive our goal, but we already have a simple way, do we? and do note that Daniel's concern was based on my initial RFC patch, which has a usage about "plugin=xxx", this series is totally different.
Quoted 1 line
We'd better come to an agreement on the command line style for net filter :)
This is my opinion, Daniel, what do you think?
Quoted 58 lines
Cc Daniel P. Berrange <[email protected]>Thanks,
zhanghailiangQuoted 44 lines
NOTE:
You can attach multiple plugins to the filter, dynamically add/remove
filter and filter-<plugin>.The netbuffer plugin:
Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0
-netdev filter-buffer,id=p0,filter=f0
-device e1000,netdev=f0Will supply a public API to release the buffer. But there's no callers currently.
To test this feature, it's quite simple, just usenetdev_addfilter-buffer,id=p0,filter=f0
to buffer packets,netdev_delp0
will release packets.You can also implement whatever plugin you needed based on this filter.
Yang Hongyang (9):
netdev: Add a net filter
virtio-net: add filter support
filter: remove plugins when remove filter
filter: remove filter before remove network backend
filter: add netbuffer plugin
introduceqemu_find_net_clients_by_modelnet/queue: exportqemu_net_queue_appendmove out net queue structs define
add a public api to release bufferhw/net/virtio-net.c | 17 ++- include/net/filter.h | 21 ++++ include/net/net.h | 5 + include/net/queue.h | 26 ++++ net/Makefile.objs | 2 + net/clients.h | 6 + net/filter-buffer.c | 185 ++++++++++++++++++++++++++++ net/filter.c | 331 +++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 51 +++++++- net/queue.c | 31 +---- qapi-schema.json | 40 ++++++- 11 files changed, 679 insertions(+), 36 deletions(-)Quoted 4 lines
create mode 100644
include/net/filter.h
create mode 100644net/filter-buffer.c
create mode 100644net/filter.c.
Signature · 2 lines
Thanks, Yang.
Quoted 72 lines · Yang Hongyang
Thank you, and sorry to Daniel that I forgot to CC you...
On 07/25/2015 01:06 PM, zhanghailiang wrote:
[...]Quoted 8 lines
Quoted 8 lines
+--------------+ +-------------+ +----------+ | filter | |frontend(NIC)| | peer+--> | | | | network <--+backend <-------+ peer | | backend | | peer +-------> | +----------+ +--------------+ +-------------+Quoted 7 lines
Quoted 5 lines
Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0
-netdev filter-<plugin>,id=p0,filter=f0
-device e1000,netdev=f0Have you considered Daniel's suggestion ? Using the bellow style:
Yes, but by dig into the implementation, I think the current way is better, here is the reason:
1. The flexibility to easily dynamically add/remove/change filters on the fly. This is what Daniel was worrying about (please correct me if I didn't get your point) I think I addressed his main concern on this series. And you can specify any param to the filter plugin under existing netdev design.
2. Reuse as many existing code as we can. think about doing a standalone object, add/remove filters will duplicate the existing netdev_add/netdev_del code. the filter plugin need to implement at lease 3 functions, init/cleanup and
receive_filter, this is also duplicate the existing netdev design, we already have the architecture toinit/cleanup/receive_filter, why not use it?3. A filter is a backend in my design, so it is absolutely reasonable to implement it as a netdev and it is easy to implement it as a netdev, if you implement it as a standalone object, how do you integrate it to the backend? A filter plugin might be able to be a standalone object, but just as I said on #2, as long as we can archive our goal under the existing design, why duplicate it?
4. Current implementation don't affact the existing code too much, it is a bolt-on feature.
Overall, we reuse the existing design, implemented a flexible and extensible net filter feature, so I think the current way is better.
Quoted 8 lines
-netfilter id=f0,plugin=dump
-netdev tap,id=bn0,filter=f0
-device e1000,netdev=bn0Considering the filter as a new 'netdev' seems to be unreasonable, Whenever we add a new plugin, we have to add a new member to 'NetClientOptions', there will be lots of 'filter' objects in NetClientOptions area.
Why can't we extend this struct? I don't see any problem with this. Doing the other way is just to extend another struct.
Besides when we want to describe a net device with several filter plugin
Quoted 9 lines
for VM,
it will become like:-netdev tap,id=bn0 -netdev filter,id=f0,backend=bn0 -netdev filter-<plugin-0>,id=p0,filter=f0 -netdev filter-<plugin-1>,id=p1,filter=f1 ... ... -device e1000,netdev=f0Which is a little verbose for 'netdev' option.
Quoted 8 lines
It's just the name diffrence, using netfilter will be -netfilter ... -netfilter ...
using plugin=xxx will make us hard to extend the plugin params under existing netdev design thus will needs lots of extra effort to archive our goal, but we already have a simple way, do we? and do note that Daniel's concern was based on my initial RFC patch, which has a usage about "plugin=xxx", this series is totally different.
The current -netdev / netdev_add/netdev_del interfaces have a fairly static view of the world. If you just want to setup filters at the time you setup the guest NIC that's fine, but if you want to be able to dynamically change the filters that are used, without altering the guest device or the real host backend, I think you're going to run into problems using -netdev. eg consider you have a pre-exisiting guest running and you want to add in a 'dump' filter to temporarily record traffic to a file, without having any impact on guest connectivity. I'm not seeing how you could achieve that with the proposed netdev approach, because you'd basically have to delete the existing NIC and add a new one from scratch.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Hi,
Thank you for the comment!
Quoted 1 line · Daniel P. Berrange
On Sun, Jul 26, 2015 at 10:13:55PM +0800, Yang Hongyang wrote:
[...]
Quoted 11 lines
Quoted 10 lines
Quoted 1 line
Which is a little verbose for 'netdev' option.
It's just the name diffrence, using netfilter will be -netfilter ... -netfilter ...
using plugin=xxx will make us hard to extend the plugin params under existing netdev design thus will needs lots of extra effort to archive our goal, but we already have a simple way, do we? and do note that Daniel's concern was based on my initial RFC patch, which has a usage about "plugin=xxx", this series is totally different.
Quoted 11 lines
The current -netdev / netdev_add/netdev_del interfaces have a fairly static view of the world. If you just want to setup filters at the time you setup the guest NIC that's fine, but if you want to be able to dynamically change the filters that are used, without altering the guest device or the real host backend, I think you're going to run into problems using -netdev. eg consider you have a pre-exisiting guest running and you want to add in a 'dump' filter to temporarily record traffic to a file, without having any impact on guest connectivity. I'm not seeing how you could achieve that with the proposed netdev approach, because you'd basically have to delete the existing NIC and add a new one from scratch.
We will modify the NIC's peer when using netdev_add to add the filter. The current netdev_add/netdev_del can be used while guest is running. just to make sure netdev's init/cleanup can do the right thing.
Quoted 4 lines
Regards,
Daniel
Signature · 2 lines
Thanks, Yang.
Quoted 61 lines · Yang Hongyang
This patch add a net filter between network backend and NIC devices. All packets will pass by this filter.
Also implement a netbuffer plugin for example, the netbuffer plugin could be used by VM FT solutions like Macrocheckpointing, to buffer/release packets.
Based on this, dump plugin could be easily implemented.I've done some simple tests on this series,
backend, tap,user
NIC, e1000,virtio-netThere's still some missing functions to be done, I've posted this early in order to gain more comments, thank you!
TODO:
multiqueue support.+--------------+ +-------------+ +----------+ | filter | |frontend(NIC)| | peer+--> | | | | network <--+backend <-------+ peer | | backend | | peer +-------> | +----------+ +--------------+ +-------------+Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0
-netdev filter-<plugin>,id=p0,filter=f0
-device e1000,netdev=f0
NOTE:
You can attach multiple plugins to the filter, dynamically add/remove
filter and filter-<plugin>.The netbuffer plugin:
Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0
-netdev filter-buffer,id=p0,filter=f0
-device e1000,netdev=f0Will supply a public API to release the buffer. But there's no callers currently.
To test this feature, it's quite simple, just usenetdev_addfilter-buffer,id=p0,filter=f0
to buffer packets,netdev_delp0
will release packets.You can also implement whatever plugin you needed based on this filter.
Yang Hongyang (9):
netdev: Add a net filter
virtio-net: add filter support
filter: remove plugins when remove filter
filter: remove filter before remove network backend
filter: add netbuffer plugin
introduceqemu_find_net_clients_by_modelnet/queue: exportqemu_net_queue_appendmove out net queue structs define
add a public api to release buffer
Quoted 16 lines
hw/net/virtio-net.c | 17 ++- include/net/filter.h | 21 ++++ include/net/net.h | 5 + include/net/queue.h | 26 ++++ net/Makefile.objs | 2 + net/clients.h | 6 + net/filter-buffer.c | 185 ++++++++++++++++++++++++++++ net/filter.c | 331 +++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 51 +++++++- net/queue.c | 31 +---- qapi-schema.json | 40 ++++++- 11 files changed, 679 insertions(+), 36 deletions(-) create mode 100644 include/net/filter.h create mode 100644 net/filter-buffer.c create mode 100644 net/filter.c
Hi:
Can you answer my question at
http://lists.gnu.org/archive/html/qemu-devel/2015-07/msg04653.html?
The main concern is why it must be a new kind of netdev?
Thanks
Quoted 81 lines · Jason Wang
Quoted 73 lines · Yang Hongyang
This patch add a net filter between network backend and NIC devices. All packets will pass by this filter.
Also implement a netbuffer plugin for example, the netbuffer plugin could be used by VM FT solutions like Macrocheckpointing, to buffer/release packets.
Based on this, dump plugin could be easily implemented.I've done some simple tests on this series,
backend, tap,user
NIC, e1000,virtio-netThere's still some missing functions to be done, I've posted this early in order to gain more comments, thank you!
TODO:
multiqueue support. +--------------+ +-------------+ +----------+ | filter | |frontend(NIC)| | peer+--> | | | | network <--+backend <-------+ peer | | backend | | peer +-------> | +----------+ +--------------+ +-------------+Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0 -netdev filter-<plugin>,id=p0,filter=f0 -device e1000,netdev=f0NOTE:
You can attach multiple plugins to the filter, dynamically add/remove
filter and filter-<plugin>.The netbuffer plugin:
Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0
-netdev filter-buffer,id=p0,filter=f0
-device e1000,netdev=f0Will supply a public API to release the buffer. But there's no callers currently.
To test this feature, it's quite simple, just usenetdev_addfilter-buffer,id=p0,filter=f0
to buffer packets,netdev_delp0
will release packets.You can also implement whatever plugin you needed based on this filter.
Yang Hongyang (9):
netdev: Add a net filter
virtio-net: add filter support
filter: remove plugins when remove filter
filter: remove filter before remove network backend
filter: add netbuffer plugin
introduceqemu_find_net_clients_by_modelnet/queue: exportqemu_net_queue_appendmove out net queue structs define
add a public api to release bufferhw/net/virtio-net.c | 17 ++- include/net/filter.h | 21 ++++ include/net/net.h | 5 + include/net/queue.h | 26 ++++ net/Makefile.objs | 2 + net/clients.h | 6 + net/filter-buffer.c | 185 ++++++++++++++++++++++++++++ net/filter.c | 331 +++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 51 +++++++- net/queue.c | 31 +---- qapi-schema.json | 40 ++++++- 11 files changed, 679 insertions(+), 36 deletions(-)Quoted 4 lines
create mode 100644
include/net/filter.h
create mode 100644net/filter-buffer.c
create mode 100644net/filter.c
Quoted 6 lines
Hi:
Can you answer my question at
http://lists.gnu.org/archive/html/qemu-devel/2015-07/msg04653.html?The main concern is why it must be a new kind of netdev?
Sorry, I missed that one... will reply in that thread.
Quoted 4 lines
Thanks
.
Signature · 2 lines
Thanks, Yang.
Sorry, please ignore this patchset.
As me and Jason came to an agreement of another way of implementation. refer to thread:
http://lists.nongnu.org/archive/html/qemu-devel/2015-07/msg05445.html
I will send another patchset later.
Quoted 77 lines · Yang Hongyang
This patch add a net filter between network backend and NIC devices. All packets will pass by this filter.
Also implement a netbuffer plugin for example, the netbuffer plugin could be used by VM FT solutions like Macrocheckpointing, to buffer/release packets.
Based on this, dump plugin could be easily implemented.I've done some simple tests on this series,
backend, tap,user
NIC, e1000,virtio-netThere's still some missing functions to be done, I've posted this early in order to gain more comments, thank you!
TODO:
multiqueue support. +--------------+ +-------------+ +----------+ | filter | |frontend(NIC)| | peer+--> | | | | network <--+backend <-------+ peer | | backend | | peer +-------> | +----------+ +--------------+ +-------------+Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0 -netdev filter-<plugin>,id=p0,filter=f0 -device e1000,netdev=f0NOTE:
You can attach multiple plugins to the filter, dynamically add/remove
filter and filter-<plugin>.The netbuffer plugin:
Usage:
-netdev tap,id=bn0 # you can use whatever backend as needed -netdev filter,id=f0,backend=bn0
-netdev filter-buffer,id=p0,filter=f0
-device e1000,netdev=f0Will supply a public API to release the buffer. But there's no callers currently.
To test this feature, it's quite simple, just usenetdev_addfilter-buffer,id=p0,filter=f0
to buffer packets,netdev_delp0
will release packets.You can also implement whatever plugin you needed based on this filter.
Yang Hongyang (9):
netdev: Add a net filter
virtio-net: add filter support
filter: remove plugins when remove filter
filter: remove filter before remove network backend
filter: add netbuffer plugin
introduceqemu_find_net_clients_by_modelnet/queue: exportqemu_net_queue_appendmove out net queue structs define
add a public api to release bufferhw/net/virtio-net.c | 17 ++- include/net/filter.h | 21 ++++ include/net/net.h | 5 + include/net/queue.h | 26 ++++ net/Makefile.objs | 2 + net/clients.h | 6 + net/filter-buffer.c | 185 ++++++++++++++++++++++++++++ net/filter.c | 331 +++++++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 51 +++++++- net/queue.c | 31 +---- qapi-schema.json | 40 ++++++- 11 files changed, 679 insertions(+), 36 deletions(-)create mode 100644
include/net/filter.h
create mode 100644net/filter-buffer.c
create mode 100644net/filter.c
Signature · 2 lines
Thanks, Yang.