qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Yang Hongyang <yanghy@cn.fujitsu.com>
To: qemu-devel@nongnu.org
Cc: thuth@redhat.com, zhang.zhanghailiang@huawei.com,
	lizhijian@cn.fujitsu.com, jasowang@redhat.com,
	mrhines@linux.vnet.ibm.com, stefanha@redhat.com,
	Yang Hongyang <yanghy@cn.fujitsu.com>
Subject: [Qemu-devel] [PATCH v5 06/10] netfilter: add an API to pass the packet to next filter
Date: Thu, 6 Aug 2015 18:21:51 +0800	[thread overview]
Message-ID: <1438856515-17422-7-git-send-email-yanghy@cn.fujitsu.com> (raw)
In-Reply-To: <1438856515-17422-1-git-send-email-yanghy@cn.fujitsu.com>

add an API qemu_netfilter_pass_to_next() to pass the packet
to next filter.

Signed-off-by: Yang Hongyang <yanghy@cn.fujitsu.com>

---
v5: fold params to NetPacket struct
---
 include/net/filter.h |  3 +++
 net/filter.c         | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/include/net/filter.h b/include/net/filter.h
index f15d83d..9278d40 100644
--- a/include/net/filter.h
+++ b/include/net/filter.h
@@ -57,4 +57,7 @@ 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 */
+ssize_t qemu_netfilter_pass_to_next(NetFilterState *nf, NetPacket *packet);
+
 #endif /* QEMU_NET_FILTER_H */
diff --git a/net/filter.c b/net/filter.c
index dfce544..84245a7 100644
--- a/net/filter.c
+++ b/net/filter.c
@@ -14,9 +14,11 @@
 #include "qapi/dealloc-visitor.h"
 #include "qemu/config-file.h"
 #include "qmp-commands.h"
+#include "qemu/iov.h"
 
 #include "net/filter.h"
 #include "net/net.h"
+#include "net/queue.h"
 
 static QTAILQ_HEAD(, NetFilterState) net_filters;
 
@@ -127,6 +129,37 @@ void qmp_netfilter_del(const char *id, Error **errp)
     qemu_opts_del(opts);
 }
 
+ssize_t qemu_netfilter_pass_to_next(NetFilterState *nf, NetPacket *packet)
+{
+    int ret = 0;
+    NetFilterState *next = QTAILQ_NEXT(nf, next);
+    struct iovec iov = {
+        .iov_base = (void *)packet->data,
+        .iov_len = packet->size
+    };
+
+    while (next) {
+        if (next->chain == nf->chain || next->chain == NET_FILTER_ALL) {
+            ret = next->info->receive_iov(next, packet->sender, packet->flags,
+                                          &iov, 1, packet->sent_cb);
+            if (ret) {
+                return ret;
+            }
+        }
+        next = QTAILQ_NEXT(next, next);
+    }
+
+    /* we have gone through all filters, pass it to receiver */
+    if (packet->sender && packet->sender->peer) {
+        return qemu_net_queue_send_iov(packet->sender->peer->incoming_queue,
+                                       packet->sender, packet->flags,
+                                       &iov, 1, packet->sent_cb);
+    }
+
+    /* no receiver, or sender is deleted, drop this packet, return success */
+    return packet->size;
+}
+
 typedef int (NetFilterInit)(const NetFilterOptions *opts,
                             const char *name, int chain,
                             NetClientState *netdev, Error **errp);
-- 
1.9.1

  parent reply	other threads:[~2015-08-06 10:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-06 10:21 [Qemu-devel] [PATCH v5 00/10] For QEMU 2.5: Add a netfilter object and netbuffer filter Yang Hongyang
2015-08-06 10:21 ` [Qemu-devel] [PATCH v5 01/10] net: add a new object netfilter Yang Hongyang
2015-08-06 10:21 ` [Qemu-devel] [PATCH v5 02/10] init/cleanup of netfilter object Yang Hongyang
2015-08-06 10:21 ` [Qemu-devel] [PATCH v5 03/10] netfilter: add netfilter_{add|del} commands Yang Hongyang
2015-08-06 10:21 ` [Qemu-devel] [PATCH v5 04/10] netfilter: hook packets before net queue send Yang Hongyang
2015-08-06 10:21 ` [Qemu-devel] [PATCH v5 05/10] move out net queue structs define Yang Hongyang
2015-08-06 10:21 ` Yang Hongyang [this message]
2015-08-06 10:21 ` [Qemu-devel] [PATCH v5 07/10] net/queue: export qemu_net_queue_append_iov Yang Hongyang
2015-08-06 10:21 ` [Qemu-devel] [PATCH v5 08/10] netfilter: add a netbuffer filter Yang Hongyang
2015-08-06 10:21 ` [Qemu-devel] [PATCH v5 09/10] filter/buffer: update command description and help Yang Hongyang
2015-08-06 10:21 ` [Qemu-devel] [PATCH v5 10/10] 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=1438856515-17422-7-git-send-email-yanghy@cn.fujitsu.com \
    --to=yanghy@cn.fujitsu.com \
    --cc=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=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).