From patchwork Sat Feb 6 09:28:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 8242251 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BF3FE9F3CD for ; Sat, 6 Feb 2016 09:48:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2426520204 for ; Sat, 6 Feb 2016 09:48:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 63B3420142 for ; Sat, 6 Feb 2016 09:48:01 +0000 (UTC) Received: from localhost ([::1]:52735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRzTE-0002Up-Pj for patchwork-qemu-devel@patchwork.kernel.org; Sat, 06 Feb 2016 04:48:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38402) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRzC0-0003GZ-M2 for qemu-devel@nongnu.org; Sat, 06 Feb 2016 04:30:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRzBz-0001cY-Q3 for qemu-devel@nongnu.org; Sat, 06 Feb 2016 04:30:12 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:26812) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRzBy-0001au-Nx for qemu-devel@nongnu.org; Sat, 06 Feb 2016 04:30:11 -0500 Received: from 172.24.1.48 (EHLO szxeml428-hub.china.huawei.com) ([172.24.1.48]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DEG12960; Sat, 06 Feb 2016 17:29:57 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.235.1; Sat, 6 Feb 2016 17:29:47 +0800 From: zhanghailiang To: Date: Sat, 6 Feb 2016 17:28:48 +0800 Message-ID: <1454750932-7556-37-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1454750932-7556-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1454750932-7556-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.56B5BD15.00C9, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 718de01716dd6bcae7517c38d7905664 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 58.251.152.64 Cc: xiecl.fnst@cn.fujitsu.com, lizhijian@cn.fujitsu.com, quintela@redhat.com, armbru@redhat.com, Jason Wang , yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, zhanghailiang , arei.gonglei@huawei.com, stefanha@redhat.com, amit.shah@redhat.com, zhangchen.fnst@cn.fujitsu.com, hongyang.yang@easystack.cn Subject: [Qemu-devel] [PATCH COLO-Frame v14 36/40] net/filter: Add a helper to traverse all the filters 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a new API qemu_foreach_netfilter(), it will traverse all the filters, and call the callback function. Signed-off-by: zhanghailiang Cc: Jason Wang Cc: Yang Hongyang --- v14: - New patch split from previous version. --- include/net/net.h | 4 ++++ net/net.c | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index f6f0194..d4e5100 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -125,6 +125,10 @@ NetClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id, const char *client_str); typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque); void qemu_foreach_nic(qemu_nic_foreach func, void *opaque); +typedef void (*qemu_netfilter_foreach)(NetFilterState *nf, void *opaque, + Error **errp); +void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, + Error **errp); int qemu_can_send_packet(NetClientState *nc); ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov, int iovcnt); diff --git a/net/net.c b/net/net.c index 36f8345..f5007e5 100644 --- a/net/net.c +++ b/net/net.c @@ -268,6 +268,30 @@ static char *assign_name(NetClientState *nc1, const char *model) return g_strdup_printf("%s.%d", model, id); } +void qemu_foreach_netfilter(qemu_netfilter_foreach func, void *opaque, + Error **errp) +{ + NetClientState *nc; + NetFilterState *nf; + + QTAILQ_FOREACH(nc, &net_clients, next) { + if (nc->info->type == NET_CLIENT_OPTIONS_KIND_NIC) { + continue; + } + + QTAILQ_FOREACH(nf, &nc->filters, next) { + if (func) { + Error *local_err = NULL; + + func(nf, opaque, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + } + } + } +} static void qemu_net_client_destructor(NetClientState *nc) { g_free(nc);