From patchwork Fri Aug 21 04:43:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Hongyang X-Patchwork-Id: 509291 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 E8DD41402AC for ; Fri, 21 Aug 2015 14:46:58 +1000 (AEST) Received: from localhost ([::1]:39745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSeED-00006K-2o for incoming@patchwork.ozlabs.org; Fri, 21 Aug 2015 00:46:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSeBq-0004s1-K3 for qemu-devel@nongnu.org; Fri, 21 Aug 2015 00:44:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZSeBo-0000Xb-Vj for qemu-devel@nongnu.org; Fri, 21 Aug 2015 00:44:30 -0400 Received: from [59.151.112.132] (port=37214 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSeBo-0000Vb-18 for qemu-devel@nongnu.org; Fri, 21 Aug 2015 00:44:28 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="99874164" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Aug 2015 12:47:40 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t7L4iLmG013785; Fri, 21 Aug 2015 12:44:21 +0800 Received: from localhost (10.167.226.223) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 21 Aug 2015 12:44:25 +0800 From: Yang Hongyang To: Date: Fri, 21 Aug 2015 12:43:15 +0800 Message-ID: <1440132205-7814-2-git-send-email-yanghy@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1440132205-7814-1-git-send-email-yanghy@cn.fujitsu.com> References: <1440132205-7814-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, mrhines@linux.vnet.ibm.com, stefanha@redhat.com, Paolo Bonzini , Yang Hongyang Subject: [Qemu-devel] [PATCH v7 RESEND 01/11] net: add a new object netfilter 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 the framework for a new netfilter object and a new -netfilter CLI option as a basis for the following patches. Signed-off-by: Yang Hongyang CC: Paolo Bonzini CC: Eric Blake Reviewed-by: Thomas Huth --- include/net/filter.h | 15 +++++++++++++++ include/sysemu/sysemu.h | 1 + net/Makefile.objs | 1 + net/filter.c | 27 +++++++++++++++++++++++++++ qemu-options.hx | 1 + vl.c | 13 +++++++++++++ 6 files changed, 58 insertions(+) create mode 100644 include/net/filter.h create mode 100644 net/filter.c diff --git a/include/net/filter.h b/include/net/filter.h new file mode 100644 index 0000000..4242ded --- /dev/null +++ b/include/net/filter.h @@ -0,0 +1,15 @@ +/* + * 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_FILTER_H +#define QEMU_NET_FILTER_H + +#include "qemu-common.h" + +int net_init_filters(void); + +#endif /* QEMU_NET_FILTER_H */ diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 44570d1..15d6d00 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -212,6 +212,7 @@ extern QemuOptsList qemu_chardev_opts; extern QemuOptsList qemu_device_opts; extern QemuOptsList qemu_netdev_opts; extern QemuOptsList qemu_net_opts; +extern QemuOptsList qemu_netfilter_opts; extern QemuOptsList qemu_global_opts; extern QemuOptsList qemu_mon_opts; diff --git a/net/Makefile.objs b/net/Makefile.objs index ec19cb3..914aec0 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -13,3 +13,4 @@ common-obj-$(CONFIG_HAIKU) += tap-haiku.o common-obj-$(CONFIG_SLIRP) += slirp.o common-obj-$(CONFIG_VDE) += vde.o common-obj-$(CONFIG_NETMAP) += netmap.o +common-obj-y += filter.o diff --git a/net/filter.c b/net/filter.c new file mode 100644 index 0000000..4e40f08 --- /dev/null +++ b/net/filter.c @@ -0,0 +1,27 @@ +/* + * 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. + */ + +#include "qemu-common.h" +#include "net/filter.h" + +int net_init_filters(void) +{ + return 0; +} + +QemuOptsList qemu_netfilter_opts = { + .name = "netfilter", + .implied_opt_name = "type", + .head = QTAILQ_HEAD_INITIALIZER(qemu_netfilter_opts.head), + .desc = { + /* + * no elements => accept any params + * validation will happen later + */ + { /* end of list */ } + }, +}; diff --git a/qemu-options.hx b/qemu-options.hx index 77f5853..0d52d02 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1575,6 +1575,7 @@ DEF("net", HAS_ARG, QEMU_OPTION_net, "socket][,vlan=n][,option][,option][,...]\n" " old way to initialize a host network interface\n" " (use the -netdev option if possible instead)\n", QEMU_ARCH_ALL) +DEF("netfilter", HAS_ARG, QEMU_OPTION_netfilter, "", QEMU_ARCH_ALL) STEXI @item -net nic[,vlan=@var{n}][,macaddr=@var{mac}][,model=@var{type}] [,name=@var{name}][,addr=@var{addr}][,vectors=@var{v}] @findex -net diff --git a/vl.c b/vl.c index 584ca88..aee931a 100644 --- a/vl.c +++ b/vl.c @@ -75,6 +75,7 @@ int main(int argc, char **argv) #include "monitor/qdev.h" #include "sysemu/bt.h" #include "net/net.h" +#include "net/filter.h" #include "net/slirp.h" #include "monitor/monitor.h" #include "ui/console.h" @@ -2998,6 +2999,7 @@ int main(int argc, char **argv, char **envp) qemu_add_opts(&qemu_device_opts); qemu_add_opts(&qemu_netdev_opts); qemu_add_opts(&qemu_net_opts); + qemu_add_opts(&qemu_netfilter_opts); qemu_add_opts(&qemu_rtc_opts); qemu_add_opts(&qemu_global_opts); qemu_add_opts(&qemu_mon_opts); @@ -3284,6 +3286,13 @@ int main(int argc, char **argv, char **envp) exit(1); } break; + case QEMU_OPTION_netfilter: + opts = qemu_opts_parse_noisily(qemu_find_opts("netfilter"), + optarg, true); + if (!opts) { + exit(1); + } + break; #ifdef CONFIG_LIBISCSI case QEMU_OPTION_iscsi: opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"), @@ -4413,6 +4422,10 @@ int main(int argc, char **argv, char **envp) exit(1); } + if (net_init_filters() < 0) { + exit(1); + } + #ifdef CONFIG_TPM if (tpm_init() < 0) { exit(1);