From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTW5h-0000JI-Ak for qemu-devel@nongnu.org; Sun, 23 Aug 2015 10:17:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZTW5c-0003F6-M3 for qemu-devel@nongnu.org; Sun, 23 Aug 2015 10:17:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60095) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZTW5c-0003Et-Ea for qemu-devel@nongnu.org; Sun, 23 Aug 2015 10:17:40 -0400 Message-ID: <55D9D5F1.6020107@redhat.com> Date: Sun, 23 Aug 2015 10:17:21 -0400 From: Thomas Huth MIME-Version: 1.0 References: <1440132205-7814-1-git-send-email-yanghy@cn.fujitsu.com> <1440132205-7814-3-git-send-email-yanghy@cn.fujitsu.com> In-Reply-To: <1440132205-7814-3-git-send-email-yanghy@cn.fujitsu.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v7 RESEND 02/11] init/cleanup of netfilter object List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Yang Hongyang , qemu-devel@nongnu.org Cc: zhang.zhanghailiang@huawei.com, lizhijian@cn.fujitsu.com, jasowang@redhat.com, mrhines@linux.vnet.ibm.com, stefanha@redhat.com On 21/08/15 00:43, Yang Hongyang wrote: > QTAILQ_ENTRY global_list but used by filter layer, so that we can > manage all filters together. > QTAILQ_ENTRY next used by netdev, filter belongs to the specific netdev is > in this queue. > This is mostly the same with init/cleanup of netdev object. > > Signed-off-by: Yang Hongyang > --- > v7: add check for vhost [...] > diff --git a/net/filter.c b/net/filter.c > index 4e40f08..9183cd8 100644 > --- a/net/filter.c > +++ b/net/filter.c > @@ -6,10 +6,158 @@ > */ > > #include "qemu-common.h" > +#include "qapi-visit.h" > +#include "qapi/qmp/qerror.h" > +#include "qemu/error-report.h" > +#include "qapi-visit.h" > +#include "qapi/opts-visitor.h" > +#include "qapi/dealloc-visitor.h" > +#include "qemu/config-file.h" > + > #include "net/filter.h" > +#include "net/net.h" Don't you need to include "net/vhost_net.h" here, too, to get the prototype of get_vhost_nest() for using it in the function below? > +static int net_filter_init1(const NetFilter *netfilter, Error **errp) > +{ > + NetClientState *ncs[MAX_QUEUE_NUM]; > + const char *name = netfilter->id; > + const char *netdev_id = netfilter->netdev; > + const char *chain_str = NULL; > + const NetFilterOptions *opts = netfilter->opts; > + int chain, queues, i; > + > + if (!net_filter_init_fun[opts->kind]) { > + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type", > + "a net filter type"); > + return -1; > + } > + > + if (netfilter->has_chain) { > + chain_str = netfilter->chain; > + if (!strcmp(chain_str, "in")) { > + chain = NET_FILTER_IN; > + } else if (!strcmp(chain_str, "out")) { > + chain = NET_FILTER_OUT; > + } else if (!strcmp(chain_str, "all")) { > + chain = NET_FILTER_ALL; > + } else { > + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "chain", > + "netfilter chain (in/out/all)"); > + return -1; > + } > + } else { > + /* default */ > + chain = NET_FILTER_ALL; > + } > + > + queues = qemu_find_net_clients_except(netdev_id, ncs, > + NET_CLIENT_OPTIONS_KIND_NIC, > + MAX_QUEUE_NUM); > + if (queues < 1) { > + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "netdev", > + "a network backend id"); > + return -1; > + } > + > + if (get_vhost_net(ncs[0])) { > + error_setg(errp, "vhost is not supported"); > + return -1; > + } > + > + for (i = 0; i < queues; i++) { > + if (net_filter_init_fun[opts->kind](opts, name, > + chain, ncs[i], errp) < 0) { > + if (errp && !*errp) { > + error_setg(errp, QERR_DEVICE_INIT_FAILED, > + NetFilterOptionsKind_lookup[opts->kind]); > + } > + return -1; > + } > + } > + > + return 0; > +} Thomas