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, zhang.zhanghailiang@huawei.com,
	lizhijian@cn.fujitsu.com, dgilbert@redhat.com,
	mrhines@linux.vnet.ibm.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 07/12] netfilter: add an API to pass the packet to next filter
Date: Tue, 04 Aug 2015 13:00:40 +0800	[thread overview]
Message-ID: <55C046F8.5020406@redhat.com> (raw)
In-Reply-To: <1438590616-21142-8-git-send-email-yanghy@cn.fujitsu.com>



On 08/03/2015 04:30 PM, Yang Hongyang wrote:
> add an API qemu_netfilter_pass_to_next_iov() to pass the packet
> to next filter, and a wrapper qemu_netfilter_pass_to_next().
>
> Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>
> ---
>  include/net/filter.h | 12 ++++++++++++
>  include/net/net.h    |  1 +
>  net/filter.c         | 31 +++++++++++++++++++++++++++++++
>  net/net.c            | 13 +++++++++++++
>  4 files changed, 57 insertions(+)
>
> diff --git a/include/net/filter.h b/include/net/filter.h
> index 7f0c949..c2be970 100644
> --- a/include/net/filter.h
> +++ b/include/net/filter.h
> @@ -53,4 +53,16 @@ void qemu_del_net_filter(NetFilterState *nf);
>  void netfilter_add(QemuOpts *opts, Error **errp);
>  void qmp_netfilter_add(QDict *qdict, QObject **ret, Error **errp);
>  
> +/* pass the packet to the next filter */
> +void qemu_netfilter_pass_to_next_iov(NetFilterState *nf,
> +                                     NetClientState *sender,
> +                                     unsigned flags,
> +                                     const struct iovec *iov,
> +                                     int iovcnt);
> +void qemu_netfilter_pass_to_next(NetFilterState *nf,
> +                                 NetClientState *sender,
> +                                 unsigned flags,
> +                                 const uint8_t *data,
> +                                 size_t size);
> +
>  #endif /* QEMU_NET_FILTER_H */
> diff --git a/include/net/net.h b/include/net/net.h
> index 5c5c109..d3bfe12 100644
> --- a/include/net/net.h
> +++ b/include/net/net.h
> @@ -117,6 +117,7 @@ NetClientState *qemu_new_net_client(NetClientInfo *info,
>                                      const char *name);
>  int qemu_netdev_add_filter(NetClientState *nc, NetFilterState *nf);
>  void qemu_netdev_remove_filter(NetClientState *nc, NetFilterState *nf);
> +NetFilterState *qemu_netdev_next_filter(NetClientState *nc, NetFilterState *nf);
>  NICState *qemu_new_nic(NetClientInfo *info,
>                         NICConf *conf,
>                         const char *model,
> diff --git a/net/filter.c b/net/filter.c
> index bf113e9..84845b1 100644
> --- a/net/filter.c
> +++ b/net/filter.c
> @@ -131,6 +131,37 @@ void qmp_netfilter_del(const char *id, Error **errp)
>      qemu_opts_del(opts);
>  }
>  
> +void qemu_netfilter_pass_to_next_iov(NetFilterState *nf,
> +                                     NetClientState *sender,
> +                                     unsigned flags,
> +                                     const struct iovec *iov,
> +                                     int iovcnt)
> +{
> +    NetFilterState *next = qemu_netdev_next_filter(nf->netdev, nf);
> +
> +    while (next) {
> +        if (next->chain == nf->chain || next->chain == NET_FILTER_ALL) {
> +            next->info->receive_iov(next, sender, flags, iov, iovcnt);

If a packet is not held by one filter, we need pass it to next filter?

> +            return;
> +        }
> +        next = qemu_netdev_next_filter(next->netdev, next);
> +    }

If a packet has gone through all filters, we probably need to pass it
the receiver's incoming queue.

> +}

Looks like no real user for this helper?

> +
> +void qemu_netfilter_pass_to_next(NetFilterState *nf,
> +                                 NetClientState *sender,
> +                                 unsigned flags,
> +                                 const uint8_t *data,
> +                                 size_t size)
> +{
> +    struct iovec iov = {
> +        .iov_base = (void *)data,
> +        .iov_len = size
> +    };
> +
> +    return qemu_netfilter_pass_to_next_iov(nf, sender, flags, &iov, 1);
> +}
> +
>  typedef int (NetFilterInit)(const NetFilterOptions *opts,
>                              const char *name, int chain,
>                              NetClientState *netdev, Error **errp);
> diff --git a/net/net.c b/net/net.c
> index f774c39..e087763 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -339,6 +339,19 @@ void qemu_netdev_remove_filter(NetClientState *nc, NetFilterState *nf)
>      remove_filter(nc, filter);
>  }
>  
> +NetFilterState *qemu_netdev_next_filter(NetClientState *nc, NetFilterState *nf)
> +{
> +    Filter *filter = NULL;
> +
> +    QTAILQ_FOREACH(filter, &nc->filters, next) {
> +        if (filter->nf == nf) {
> +            break;
> +        }
> +    }

A little bit confused, can we just use net->next?

> +
> +    return QTAILQ_NEXT(filter, next)->nf;
> +}
> +
>  NICState *qemu_new_nic(NetClientInfo *info,
>                         NICConf *conf,
>                         const char *model,

  reply	other threads:[~2015-08-04  5:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1438590616-21142-1-git-send-email-yanghy@cn.fujitsu.com>
2015-08-03  8:30 ` [Qemu-devel] [PATCH v3 01/12] net: add a new object netfilter Yang Hongyang
2015-08-03  8:30 ` [Qemu-devel] [PATCH v3 02/12] init/cleanup of netfilter object Yang Hongyang
2015-08-03  8:30 ` [Qemu-devel] [PATCH v3 03/12] netfilter: add netfilter_{add|del} commands Yang Hongyang
2015-08-03  8:30 ` [Qemu-devel] [PATCH v3 04/12] net: add/remove filters from network backend Yang Hongyang
2015-08-04  4:56   ` Jason Wang
2015-08-04  5:39     ` Yang Hongyang
2015-08-04  5:53       ` Jason Wang
2015-08-04  6:03         ` Yang Hongyang
2015-08-03  8:30 ` [Qemu-devel] [PATCH v3 05/12] net: delete netfilter object when delete netdev Yang Hongyang
2015-08-03  8:30 ` [Qemu-devel] [PATCH v3 06/12] netfilter: hook packets before net queue send Yang Hongyang
2015-08-03  8:30 ` [Qemu-devel] [PATCH v3 07/12] netfilter: add an API to pass the packet to next filter Yang Hongyang
2015-08-04  5:00   ` Jason Wang [this message]
2015-08-04  5:50     ` Yang Hongyang
2015-08-03  8:30 ` [Qemu-devel] [PATCH v3 08/12] net/queue: export qemu_net_queue_append_iov Yang Hongyang
2015-08-03  8:30 ` [Qemu-devel] [PATCH v3 09/12] move out net queue structs define Yang Hongyang
2015-08-03  8:30 ` [Qemu-devel] [PATCH v3 10/12] netfilter: add a netbuffer filter Yang Hongyang
2015-08-04  5:03   ` Jason Wang
2015-08-04  6:05     ` Yang Hongyang
2015-08-04  6:30       ` Jason Wang
2015-08-04  7:57         ` Yang Hongyang
2015-08-03  8:30 ` [Qemu-devel] [PATCH v3 11/12] filter/buffer: update command description and help Yang Hongyang
2015-08-03  8:30 ` [Qemu-devel] [PATCH v3 12/12] tests: add test cases for netfilter object 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=55C046F8.5020406@redhat.com \
    --to=jasowang@redhat.com \
    --cc=dgilbert@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).