All of lore.kernel.org
 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, stefanha@redhat.com,
	zhang.zhanghailiang@huawei.com, mrhines@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH 09/12] netfilter: add a netbuffer filter
Date: Thu, 30 Jul 2015 13:13:13 +0800	[thread overview]
Message-ID: <55B9B269.3030709@redhat.com> (raw)
In-Reply-To: <1438167116-29270-10-git-send-email-yanghy@cn.fujitsu.com>



On 07/29/2015 06:51 PM, Yang Hongyang wrote:
> This filter is to buffer/release packets, this feature can be used
> when using macrocheckpoing, 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,interval=1000
>
> NOTE:
>  the scale of interval is microsecond.
>  API to release packets and interval support will be added
>  by the following 2 patches.
>
> Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
> ---
>  net/Makefile.objs   |   1 +
>  net/filter-buffer.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  net/filter.c        |   2 +
>  net/filters.h       |  17 +++++++
>  qapi-schema.json    |  13 +++++-
>  5 files changed, 159 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..628e66f
> --- /dev/null
> +++ b/net/filter-buffer.c
> @@ -0,0 +1,127 @@
> +/*
> + * 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/error-report.h"
> +
> +typedef struct FILTERBUFFERState {
> +    NetFilterState nf;
> +    NetClientState dummy; /* used to send buffered packets */

Why need this? Couldn't we just infer this from NetFilterState?

> +    NetQueue *incoming_queue;
> +    NetQueue *inflight_queue;
> +} FILTERBUFFERState;
> +
> +static void packet_send_completed(NetClientState *nc, ssize_t len)
> +{
> +    return;
> +}
> +
> +static void filter_buffer_flush(NetFilterState *nf)
> +{
> +    FILTERBUFFERState *s = DO_UPCAST(FILTERBUFFERState, nf, nf);
> +    NetQueue *queue = s->inflight_queue;
> +    NetPacket *packet;
> +
> +    while (queue && !QTAILQ_EMPTY(&queue->packets)) {
> +        packet = QTAILQ_FIRST(&queue->packets);
> +        QTAILQ_REMOVE(&queue->packets, packet, entry);
> +        queue->nq_count--;
> +
> +        if (packet->flags & QEMU_NET_PACKET_FLAG_RAW) {
> +            qemu_send_packet_raw(&s->dummy, packet->data, packet->size);
> +        } else {
> +            qemu_send_packet_async(&s->dummy, packet->data, packet->size,
> +                                   packet->sent_cb);
> +        }
> +
> +        /*
> +         * now that we pass the packet to sender->peer->incoming_queue, we
> +         * don't care the reture value here, because the peer's queue will
> +         * take care of this packet
> +         */
> +        g_free(packet);
> +    }
> +
> +    if (queue && QTAILQ_EMPTY(&queue->packets)) {

Under what condition queue->packet could be not empty here? And I don't
get the point that why a inflight_queue is needed.

> +        g_free(queue);
> +        s->inflight_queue = NULL;
> +    }
> +}
> +
> +/* filter APIs */
> +static ssize_t filter_buffer_receive(NetFilterState *nf,
> +                                     NetClientState *sender,
> +                                     unsigned flags,
> +                                     const uint8_t *data,
> +                                     size_t size)
> +{
> +    FILTERBUFFERState *s = DO_UPCAST(FILTERBUFFERState, nf, nf);
> +    NetQueue *queue = s->incoming_queue;
> +
> +    if (!sender->info) {
> +        /* This must be a dummy NetClientState, do nothing */
> +        return 0;
> +    }
> +
> +    if (sender->info->type == NET_CLIENT_OPTIONS_KIND_NIC) {
> +        /* we only buffer guest output packets */
> +        qemu_net_queue_append(queue, sender, flags, data, size,
> +                              packet_send_completed);

This may brings some confusion for user. Since the name is 'netbuffer'.
Maybe we can change the filter to be ingress or out or both? Like:

-device virtio-net-pci,id=virtio0
-netfilter buffer,id=filter0,dev=virtio0,interval=1000,type=out

Then we can just try to enqueue the packet when virtio-net-pci is sender?

> +        /* Now that we have buffered the packet, return sucess */
> +        return size;
> +    }
> +
> +    return 0;
> +}
> +
> +static void filter_buffer_cleanup(NetFilterState *nf)
> +{
> +    FILTERBUFFERState *s = DO_UPCAST(FILTERBUFFERState, nf, nf);
> +
> +    /* flush inflight packets */
> +    filter_buffer_flush(nf);
> +    /* flush incoming packets */
> +    s->inflight_queue = s->incoming_queue;
> +    s->incoming_queue = NULL;
> +    filter_buffer_flush(nf);
> +
> +    return;
> +}
> +
> +
> +static NetFilterInfo net_filter_buffer_info = {
> +    .type = NET_FILTER_OPTIONS_KIND_BUFFER,
> +    .size = sizeof(FILTERBUFFERState),
> +    .receive = filter_buffer_receive,
> +    .cleanup = filter_buffer_cleanup,
> +};
> +
> +int net_init_filter_buffer(const NetFilterOptions *opts, const char *name,
> +                           NetClientState *netdev, Error **errp)
> +{
> +    NetFilterState *nf;
> +    FILTERBUFFERState *s;
> +
> +    assert(opts->kind == NET_FILTER_OPTIONS_KIND_BUFFER);
> +
> +    nf = qemu_new_net_filter(&net_filter_buffer_info, netdev, "buffer", name);
> +    s = DO_UPCAST(FILTERBUFFERState, nf, nf);
> +    /*
> +     * we need the dummy NetClientState to send packets in order to avoid
> +     * receive packets again.
> +     * we are buffering guest output packets, our buffered packets should be
> +     * sent to real network backend, so dummy's peer should be that backend.
> +     */
> +    s->dummy.peer = netdev;
> +    s->incoming_queue = qemu_new_net_queue(nf);
> +
> +    return 0;
> +}
> diff --git a/net/filter.c b/net/filter.c
> index 50fb837..e741e2a 100644
> --- a/net/filter.c
> +++ b/net/filter.c
> @@ -18,6 +18,7 @@
>  
>  #include "net/filter.h"
>  #include "net/net.h"
> +#include "filters.h"
>  
>  static QTAILQ_HEAD(, NetFilterState) net_filters;
>  
> @@ -152,6 +153,7 @@ typedef int (NetFilterInit)(const NetFilterOptions *opts,
>  
>  static
>  NetFilterInit * const net_filter_init_fun[NET_FILTER_OPTIONS_KIND_MAX] = {
> +    [NET_FILTER_OPTIONS_KIND_BUFFER] = net_init_filter_buffer,
>  };
>  
>  static int net_filter_init1(const NetFilter *netfilter, Error **errp)
> diff --git a/net/filters.h b/net/filters.h
> new file mode 100644
> index 0000000..6c249b8
> --- /dev/null
> +++ b/net/filters.h
> @@ -0,0 +1,17 @@
> +/*
> + * 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_FILTERS_H
> +#define QEMU_NET_FILTERS_H
> +
> +#include "net/net.h"
> +#include "net/filter.h"
> +
> +int net_init_filter_buffer(const NetFilterOptions *opts, const char *name,
> +                           NetClientState *netdev, Error **errp);
> +
> +#endif /* QEMU_NET_FILTERS_H */
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 1fc6390..67e00a0 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -2577,6 +2577,16 @@
>  { 'command': 'netfilter_del', 'data': {'id': 'str'} }
>  
>  ##
> +# @NetFilterBufferOptions
> +#
> +# a netbuffer filter for network backend.
> +#
> +# Since 2.5
> +##
> +{ 'struct': 'NetFilterBufferOptions',
> +  'data': { } }
> +
> +##
>  # @NetFilterOptions
>  #
>  # A discriminated record of network filters.
> @@ -2585,7 +2595,8 @@
>  #
>  ##
>  { 'union': 'NetFilterOptions',
> -  'data': { } }
> +  'data': {
> +    'buffer':     'NetFilterBufferOptions'} }
>  
>  ##
>  # @NetFilter

  parent reply	other threads:[~2015-07-30  5:13 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-29 10:51 [Qemu-devel] [PATCH 00/12] For QEMU 2.5: Add a netfilter object and netbuffer filter Yang Hongyang
2015-07-29 10:51 ` [Qemu-devel] [PATCH 01/12] net: add a new object netfilter Yang Hongyang
2015-07-29 13:53   ` Thomas Huth
2015-07-29 14:05     ` Yang Hongyang
2015-07-29 14:20       ` Thomas Huth
2015-07-29 14:32         ` Yang Hongyang
2015-07-29 10:51 ` [Qemu-devel] [PATCH 02/12] init/cleanup of netfilter object Yang Hongyang
2015-07-29 13:33   ` Thomas Huth
2015-07-29 13:50     ` Yang Hongyang
2015-07-29 13:58       ` Thomas Huth
2015-07-29 14:08         ` Yang Hongyang
2015-07-29 10:51 ` [Qemu-devel] [PATCH 03/12] netfilter: add netfilter_{add|del} commands Yang Hongyang
2015-07-29 14:15   ` Thomas Huth
2015-07-29 14:28     ` Yang Hongyang
2015-07-29 14:30       ` Yang Hongyang
2015-07-29 10:51 ` [Qemu-devel] [PATCH 04/12] net: add/remove filters from network backend Yang Hongyang
2015-07-29 10:51 ` [Qemu-devel] [PATCH 05/12] netfilter: hook packets before receive Yang Hongyang
2015-07-30  4:51   ` Jason Wang
2015-07-30  7:22     ` Yang Hongyang
2015-07-29 10:51 ` [Qemu-devel] [PATCH 06/12] netfilter: provide a compat receive_iov Yang Hongyang
2015-07-29 10:51 ` [Qemu-devel] [PATCH 07/12] net/queue: export qemu_net_queue_append Yang Hongyang
2015-07-29 10:51 ` [Qemu-devel] [PATCH 08/12] move out net queue structs define Yang Hongyang
2015-07-29 10:51 ` [Qemu-devel] [PATCH 09/12] netfilter: add a netbuffer filter Yang Hongyang
2015-07-30  1:45   ` Li Zhijian
2015-07-30  1:53     ` Yang Hongyang
2015-07-30  5:13   ` Jason Wang [this message]
2015-07-30  6:47     ` Yang Hongyang
2015-07-30  8:40       ` Jason Wang
2015-07-30  9:04         ` Yang Hongyang
2015-07-30  9:33           ` Jason Wang
2015-07-30  9:49             ` Yang Hongyang
2015-07-30 10:14               ` Jason Wang
2015-07-30 10:28                 ` Yang Hongyang
2015-07-30 14:16                   ` Thomas Huth
2015-07-30 15:00                     ` Yang Hongyang
2015-07-30 13:46                 ` Yang Hongyang
2015-07-30  7:00     ` Yang Hongyang
2015-07-30  8:52       ` Jason Wang
2015-07-29 10:51 ` [Qemu-devel] [PATCH 10/12] netbuffer: add a public api filter_buffer_release_all Yang Hongyang
2015-07-30  5:25   ` Jason Wang
2015-07-30  5:50     ` Yang Hongyang
2015-07-30  8:42       ` Jason Wang
2015-07-30  8:53         ` Yang Hongyang
2015-07-30  8:50       ` Jason Wang
2015-07-30  9:06         ` Yang Hongyang
2015-07-29 10:51 ` [Qemu-devel] [PATCH 11/12] filter/buffer: add an interval option to buffer filter Yang Hongyang
2015-07-30  5:27   ` Jason Wang
2015-07-30  5:37     ` Yang Hongyang
2015-07-30  8:53       ` Jason Wang
2015-07-30  9:12         ` Yang Hongyang
2015-07-29 10:51 ` [Qemu-devel] [PATCH 12/12] filter/buffer: update command description and help Yang Hongyang
2015-07-29 12:56 ` [Qemu-devel] [PATCH 00/12] For QEMU 2.5: Add a netfilter object and netbuffer filter Thomas Huth
2015-07-29 13:39   ` Yang Hongyang
2015-07-29 13:48     ` Thomas Huth

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=55B9B269.3030709@redhat.com \
    --to=jasowang@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.