qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Yang Hongyang <yanghy@cn.fujitsu.com>, qemu-devel@nongnu.org
Cc: thuth@redhat.com, mrhines@linux.vnet.ibm.com,
	stefanha@redhat.com, zhang.zhanghailiang@huawei.com,
	lizhijian@cn.fujitsu.com
Subject: Re: [Qemu-devel] [PATCH v6 08/10] netfilter: add a netbuffer filter
Date: Mon, 10 Aug 2015 17:21:15 +0800	[thread overview]
Message-ID: <55C86D0B.7010106@redhat.com> (raw)
In-Reply-To: <1438915585-30367-9-git-send-email-yanghy@cn.fujitsu.com>



On 08/07/2015 10:46 AM, Yang Hongyang wrote:
> This filter is to buffer/release packets, this feature can be used
> when using MicroCheckpointing, or other Remus like VM FT solutions, you
> can also use it to simulate the network delay.
> It has an interval option, if supplied, this filter will release
> packets by interval.
>
> Usage:
>  -netdev tap,id=bn0
>  -netfilter buffer,id=f0,netdev=bn0,chain=in,interval=1000
>
> NOTE:
>  the scale of interval is microsecond.
>
> Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
> ---
> v6: move the interval check earlier and some comment adjust
> v5: remove dummy sent_cb
>     change interval type from int64 to uint32
>     check interval!=0 when initialise
>     rename FILTERBUFFERState to FilterBufferState
> v4: remove bh
>     pass the packet to next filter instead of receiver
> v3: check packet's sender and sender->peer when flush it
> ---
>  net/Makefile.objs   |   1 +
>  net/filter-buffer.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  net/filter.c        |   2 +
>  net/filters.h       |  17 +++++++
>  qapi-schema.json    |  18 +++++++-
>  5 files changed, 163 insertions(+), 1 deletion(-)
>  create mode 100644 net/filter-buffer.c
>  create mode 100644 net/filters.h
>
> diff --git a/net/Makefile.objs b/net/Makefile.objs
> index 914aec0..5fa2f97 100644
> --- a/net/Makefile.objs
> +++ b/net/Makefile.objs
> @@ -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
> diff --git a/net/filter-buffer.c b/net/filter-buffer.c
> new file mode 100644
> index 0000000..f26276c
> --- /dev/null
> +++ b/net/filter-buffer.c
> @@ -0,0 +1,126 @@
> +/*
> + * Copyright (c) 2015 FUJITSU LIMITED
> + * Author: Yang Hongyang <yanghy@cn.fujitsu.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> + * later.  See the COPYING file in the top-level directory.
> + */
> +
> +#include "net/filter.h"
> +#include "net/queue.h"
> +#include "filters.h"
> +#include "qemu-common.h"
> +#include "qemu/timer.h"
> +#include "qemu/iov.h"
> +#include "qapi/qmp/qerror.h"
> +
> +typedef struct FilterBufferState {
> +    NetFilterState nf;
> +    NetQueue *incoming_queue;
> +    uint32_t interval;
> +    QEMUTimer release_timer;
> +} FilterBufferState;
> +
> +static void filter_buffer_flush(NetFilterState *nf)
> +{
> +    FilterBufferState *s = DO_UPCAST(FilterBufferState, nf, nf);
> +    NetQueue *queue = s->incoming_queue;
> +    NetPacket *packet;
> +
> +    while (queue && !QTAILQ_EMPTY(&queue->packets)) {

Looks like no need to check queue here. And then you can switch to use
QTAILQ_FOREACH_SAFE() to save one line of QTAILF_FIRST().

> +        packet = QTAILQ_FIRST(&queue->packets);
> +        QTAILQ_REMOVE(&queue->packets, packet, entry);
> +        queue->nq_count--;
> +
> +        if (packet->sender && packet->sender->peer) {
> +            qemu_netfilter_pass_to_next(nf, packet);
> +        }
> +
> +        /*
> +         * now that we have passed the packet to next filter (or there's
> +         * no receiver). If it's queued by receiver's incoming_queue, there
> +         * will be a copy of the packet->data, so simply free this packet
> +         * now.
> +         */
> +        g_free(packet);

In the future, we may consider to avoid the extra copy. This could be
done on top of this series.

  reply	other threads:[~2015-08-10  9:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-07  2:46 [Qemu-devel] [PATCH v6 00/10] For QEMU 2.5: Add a netfilter object and netbuffer filter Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 01/10] net: add a new object netfilter Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 02/10] init/cleanup of netfilter object Yang Hongyang
2015-08-10  9:18   ` Jason Wang
2015-08-20 16:41     ` Yang Hongyang
2015-08-21  1:35       ` Jason Wang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 03/10] netfilter: add netfilter_{add|del} commands Yang Hongyang
2015-08-10  9:20   ` Jason Wang
2015-08-11  7:07   ` Wen Congyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 04/10] netfilter: hook packets before net queue send Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 05/10] move out net queue structs define Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 06/10] netfilter: add an API to pass the packet to next filter Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 07/10] net/queue: export qemu_net_queue_append_iov Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 08/10] netfilter: add a netbuffer filter Yang Hongyang
2015-08-10  9:21   ` Jason Wang [this message]
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 09/10] filter/buffer: update command description and help Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 10/10] tests: add test cases for netfilter object Yang Hongyang
2015-08-11  7:12   ` Wen Congyang
2015-08-10  9:17 ` [Qemu-devel] [PATCH v6 00/10] For QEMU 2.5: Add a netfilter object and netbuffer filter Jason Wang
2015-08-14  1:26   ` Yang Hongyang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55C86D0B.7010106@redhat.com \
    --to=jasowang@redhat.com \
    --cc=lizhijian@cn.fujitsu.com \
    --cc=mrhines@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=yanghy@cn.fujitsu.com \
    --cc=zhang.zhanghailiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).