From patchwork Mon Aug 3 08:30:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Hongyang X-Patchwork-Id: 503056 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9C9DA1402E2 for ; Mon, 3 Aug 2015 18:35:13 +1000 (AEST) Received: from localhost ([::1]:58056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMBDD-0004Tw-Rh for incoming@patchwork.ozlabs.org; Mon, 03 Aug 2015 04:35:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMB9C-0005vj-FR for qemu-devel@nongnu.org; Mon, 03 Aug 2015 04:31:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZMB9B-0007DW-4l for qemu-devel@nongnu.org; Mon, 03 Aug 2015 04:31:02 -0400 Received: from [59.151.112.132] (port=4678 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMB99-00071y-6z for qemu-devel@nongnu.org; Mon, 03 Aug 2015 04:31:01 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="99193375" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 03 Aug 2015 16:34:08 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t738SiwS024960; Mon, 3 Aug 2015 16:28:44 +0800 Received: from localhost (10.167.226.223) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Mon, 3 Aug 2015 16:30:37 +0800 From: Yang Hongyang To: Date: Mon, 3 Aug 2015 16:30:11 +0800 Message-ID: <1438590616-21142-8-git-send-email-yanghy@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438590616-21142-1-git-send-email-yanghy@cn.fujitsu.com> References: <1438590616-21142-1-git-send-email-yanghy@cn.fujitsu.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: thuth@redhat.com, zhang.zhanghailiang@huawei.com, lizhijian@cn.fujitsu.com, jasowang@redhat.com, dgilbert@redhat.com, mrhines@linux.vnet.ibm.com, stefanha@redhat.com, Yang Hongyang Subject: [Qemu-devel] [PATCH v3 07/12] netfilter: add an API to pass the packet to next filter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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); + return; + } + next = qemu_netdev_next_filter(next->netdev, next); + } +} + +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; + } + } + + return QTAILQ_NEXT(filter, next)->nf; +} + NICState *qemu_new_nic(NetClientInfo *info, NICConf *conf, const char *model,