All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hailiang Zhang <zhang.zhanghailiang@huawei.com>
To: Yang Hongyang <hongyang.yang@easystack.cn>, qemu-devel@nongnu.org
Cc: jasowang@redhat.com, peter.huangpeng@huawei.com,
	zhangchen.fnst@cn.fujitsu.com, dgilbert@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 2/4] net/filter: Introduce a helper to add a filter to the netdev
Date: Fri, 5 Feb 2016 10:24:32 +0800	[thread overview]
Message-ID: <56B407E0.6060900@huawei.com> (raw)
In-Reply-To: <56B01F31.40102@easystack.cn>

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 <zhang.zhanghailiang@huawei.com>
>> ---
>> 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);
>>
>

  reply	other threads:[~2016-02-05  2:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-01 12:01 [Qemu-devel] [PATCH v3 0/4] Netfilter: Add each netdev a default filter zhanghailiang
2016-02-01 12:01 ` [Qemu-devel] [PATCH v3 1/4] net/filter: Add a 'status' property for filter object zhanghailiang
2016-02-01 12:01 ` [Qemu-devel] [PATCH v3 2/4] net/filter: Introduce a helper to add a filter to the netdev zhanghailiang
2016-02-02  3:14   ` Yang Hongyang
2016-02-05  2:24     ` Hailiang Zhang [this message]
2016-02-01 12:01 ` [Qemu-devel] [PATCH v3 3/4] filter-buffer: Accept zero interval zhanghailiang
2016-02-01 12:01 ` [Qemu-devel] [PATCH v3 4/4] net/filter: Add a default filter to each netdev zhanghailiang
2016-02-02  3:16   ` Yang Hongyang
2016-02-05  2:35     ` Hailiang Zhang
2016-02-02  3:11 ` [Qemu-devel] [PATCH v3 0/4] Netfilter: Add each netdev a default filter Yang Hongyang
2016-02-02 12:34   ` Hailiang Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56B407E0.6060900@huawei.com \
    --to=zhang.zhanghailiang@huawei.com \
    --cc=dgilbert@redhat.com \
    --cc=hongyang.yang@easystack.cn \
    --cc=jasowang@redhat.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhangchen.fnst@cn.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.