From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46424) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRW4n-00054h-PL for qemu-devel@nongnu.org; Thu, 04 Feb 2016 21:24:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRW4k-0006Xd-Gu for qemu-devel@nongnu.org; Thu, 04 Feb 2016 21:24:49 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:11687) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRW4k-0006X9-05 for qemu-devel@nongnu.org; Thu, 04 Feb 2016 21:24:46 -0500 References: <1454328077-18820-1-git-send-email-zhang.zhanghailiang@huawei.com> <1454328077-18820-3-git-send-email-zhang.zhanghailiang@huawei.com> <56B01F31.40102@easystack.cn> From: Hailiang Zhang Message-ID: <56B407E0.6060900@huawei.com> Date: Fri, 5 Feb 2016 10:24:32 +0800 MIME-Version: 1.0 In-Reply-To: <56B01F31.40102@easystack.cn> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 2/4] net/filter: Introduce a helper to add a filter to the netdev List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Yang Hongyang , qemu-devel@nongnu.org Cc: jasowang@redhat.com, peter.huangpeng@huawei.com, zhangchen.fnst@cn.fujitsu.com, dgilbert@redhat.com On 2016/2/2 11:14, Yang Hongyang wrote: > > > On 02/01/2016 08:01 PM, zhanghailiang wrote: >> We add a new helper function netdev_add_filter(), this function >> can help adding a filter object to a netdev. >> Besides, we add a is_default member for struct NetFilterState >> to indicate whether the filter is default or not. >> >> Signed-off-by: zhanghailiang >> --- >> v3: >> - Use object_new_with_props() instead of object_create() >> (Daniel's suggestion) >> v2: >> - Re-implement netdev_add_filter() by re-using object_create() >> (Jason's suggestion) >> --- >> include/net/filter.h | 7 +++++++ >> net/filter.c | 34 ++++++++++++++++++++++++++++++++++ >> 2 files changed, 41 insertions(+) >> >> diff --git a/include/net/filter.h b/include/net/filter.h >> index af3c53c..661abef 100644 >> --- a/include/net/filter.h >> +++ b/include/net/filter.h >> @@ -55,6 +55,7 @@ struct NetFilterState { >> char *netdev_id; >> NetClientState *netdev; >> NetFilterDirection direction; >> + bool is_default; > > You added a member, but seems did not initialize it. although the > default behavior of a struct init is 0, a explicit is_defuault=false > is better IMO. > OK, i will fix it in next version. >> bool enabled; >> QTAILQ_ENTRY(NetFilterState) next; >> }; >> @@ -74,4 +75,10 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, >> int iovcnt, >> void *opaque); >> >> +void netdev_add_filter(const char *netdev_id, >> + const char *filter_type, >> + const char *filter_id, >> + bool is_default, >> + Error **errp); >> + >> #endif /* QEMU_NET_FILTER_H */ >> diff --git a/net/filter.c b/net/filter.c >> index d08a2be..7f9df57 100644 >> --- a/net/filter.c >> +++ b/net/filter.c >> @@ -214,6 +214,40 @@ static void netfilter_complete(UserCreatable *uc, Error **errp) >> QTAILQ_INSERT_TAIL(&nf->netdev->filters, nf, next); >> } >> >> +void netdev_add_filter(const char *netdev_id, >> + const char *filter_type, >> + const char *filter_id, >> + bool is_default, >> + Error **errp) > > We could assume all calls to this API is adding default filter. > so is_default is useness. > Make sense, i will rename this API to netdev_add_default_filter() and drop the is_default parameter. Thanks, Hailiang >> +{ >> + NetClientState *nc = qemu_find_netdev(netdev_id); >> + Object *filter; >> + NetFilterState *nf; >> + Error *local_err = NULL; >> + >> + /* FIXME: Not support multiple queues */ >> + if (!nc || nc->queue_index > 1) { >> + return; >> + } >> + /* Not support vhost-net */ >> + if (get_vhost_net(nc)) { >> + return; >> + } >> + filter = object_new_with_props(filter_type, >> + object_get_objects_root(), >> + filter_id, >> + &local_err, >> + "netdev", netdev_id, >> + "status", is_default ? "disable" : "enable", >> + NULL); >> + if (local_err) { >> + error_propagate(errp, local_err); >> + return; >> + } >> + nf = NETFILTER(filter); >> + nf->is_default = is_default; >> +} >> + >> static void netfilter_finalize(Object *obj) >> { >> NetFilterState *nf = NETFILTER(obj); >> >