From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNaCs-0001E6-OR for qemu-devel@nongnu.org; Mon, 25 Jan 2016 01:00:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNaCq-0002Ap-RV for qemu-devel@nongnu.org; Mon, 25 Jan 2016 01:00:54 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:51044) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNaCq-00029h-7t for qemu-devel@nongnu.org; Mon, 25 Jan 2016 01:00:52 -0500 References: <1453451811-11860-1-git-send-email-zhang.zhanghailiang@huawei.com> <1453451811-11860-3-git-send-email-zhang.zhanghailiang@huawei.com> <56A5AD13.4030401@redhat.com> From: Hailiang Zhang Message-ID: <56A5BA07.8060408@huawei.com> Date: Mon, 25 Jan 2016 14:00:39 +0800 MIME-Version: 1.0 In-Reply-To: <56A5AD13.4030401@redhat.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH RFC 2/7] net/filter: Add a 'status' property for filter object List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Wang , qemu-devel@nongnu.org Cc: peter.huangpeng@huawei.com, zhangchen.fnst@cn.fujitsu.com, hongyang.yang@easystack.cn On 2016/1/25 13:05, Jason Wang wrote: > > > On 01/22/2016 04:36 PM, zhanghailiang wrote: >> With this property, users can control if this filter is 'enable' >> or 'disable'. The default behavior for filter is enabled. >> >> Signed-off-by: zhanghailiang > > Let's squash patch 3 into this for a complete implementation of 'status'. > OK, will do that, thanks. >> --- >> include/net/filter.h | 1 + >> net/filter.c | 36 ++++++++++++++++++++++++++++++++++++ >> 2 files changed, 37 insertions(+) >> >> diff --git a/include/net/filter.h b/include/net/filter.h >> index 8a20138..9ed5ec6 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 enabled; >> QTAILQ_ENTRY(NetFilterState) next; >> }; >> >> diff --git a/net/filter.c b/net/filter.c >> index 40254bd..f4933cc 100644 >> --- a/net/filter.c >> +++ b/net/filter.c >> @@ -117,8 +117,41 @@ static void netfilter_set_direction(Object *obj, int direction, Error **errp) >> nf->direction = direction; >> } >> >> +static char *netfilter_get_status(Object *obj, Error **errp) >> +{ >> + NetFilterState *nf = NETFILTER(obj); >> + >> + if (nf->enabled) { >> + return g_strdup("enable"); >> + } else { >> + return g_strdup("disable"); >> + } >> +} >> + >> +static void netfilter_set_status(Object *obj, const char *str, Error **errp) >> +{ >> + NetFilterState *nf = NETFILTER(obj); >> + >> + if (!strcmp(str, "enable")) { >> + nf->enabled = true; >> + } else if (!strcmp(str, "disable")) { >> + nf->enabled = false; >> + } else { >> + error_setg(errp, "Invalid value for netfilter status, " >> + "should be 'enable' or 'disable'"); >> + } >> +} >> + >> static void netfilter_init(Object *obj) >> { >> + NetFilterState *nf = NETFILTER(obj); >> + >> + /* >> + * If not configured with 'status' property, the default status >> + * for netfilter will be enabled. >> + */ >> + nf->enabled = true; >> + >> object_property_add_str(obj, "netdev", >> netfilter_get_netdev_id, netfilter_set_netdev_id, >> NULL); >> @@ -126,6 +159,9 @@ static void netfilter_init(Object *obj) >> NetFilterDirection_lookup, >> netfilter_get_direction, netfilter_set_direction, >> NULL); >> + object_property_add_str(obj, "status", >> + netfilter_get_status, netfilter_set_status, >> + NULL); >> } >> >> void netfilter_print_info(NetFilterState *nf, char *output_str, int size) > > > . >