All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Hongyang <yanghy@cn.fujitsu.com>
To: Jason Wang <jasowang@redhat.com>, qemu-devel@nongnu.org
Cc: thuth@redhat.com, mrhines@linux.vnet.ibm.com,
	stefanha@redhat.com, zhang.zhanghailiang@huawei.com,
	lizhijian@cn.fujitsu.com
Subject: Re: [Qemu-devel] [PATCH v6 02/10] init/cleanup of netfilter object
Date: Fri, 21 Aug 2015 00:41:58 +0800	[thread overview]
Message-ID: <55D60356.60603@cn.fujitsu.com> (raw)
In-Reply-To: <55C86C82.4030706@redhat.com>



On 08/10/2015 05:18 PM, Jason Wang wrote:
>
>
> On 08/07/2015 10:46 AM, 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 <yanghy@cn.fujitsu.com>
>> ---
>> v6: add multiqueue support (net_filter_init1)
>> v5: remove model from NetFilterState
>>      add a sent_cb param to receive_iov API
>> ---
>>   include/net/filter.h    |  42 +++++++++++++++
>>   include/net/net.h       |   1 +
>>   include/qemu/typedefs.h |   1 +
>>   net/filter.c            | 141 ++++++++++++++++++++++++++++++++++++++++++++++++
>>   net/net.c               |   1 +
>>   qapi-schema.json        |  37 +++++++++++++
>>   6 files changed, 223 insertions(+)
>>
>> diff --git a/include/net/filter.h b/include/net/filter.h
>> index 4242ded..7a858d8 100644
>> --- a/include/net/filter.h
> [...]
>> +static
>> +NetFilterInit * const net_filter_init_fun[NET_FILTER_OPTIONS_KIND_MAX] = {
>> +};
>> +
>> +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;
>> +    }
>
> Let's fail when vhost is used here.

I think you mean vhost-user here?

>
>> +
>> +    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;
>> +}
>> +
>> +static int net_init_filter(void *dummy, QemuOpts *opts, Error **errp)
>> +{
>> +    NetFilter *object = NULL;
>> +    Error *err = NULL;
>> +    int ret = -1;
>> +    OptsVisitor *ov = opts_visitor_new(opts);
>> +
>> +    visit_type_NetFilter(opts_get_visitor(ov), &object, NULL, &err);
>> +    opts_visitor_cleanup(ov);
>> +
>> +    if (!err) {
>> +        ret = net_filter_init1(object, &err);
>> +    }
>> +
>> +    if (object) {
>> +        QapiDeallocVisitor *dv = qapi_dealloc_visitor_new();
>> +
>> +        visit_type_NetFilter(qapi_dealloc_get_visitor(dv), &object, NULL, NULL);
>> +        qapi_dealloc_visitor_cleanup(dv);
>> +    }
>> +
>> +    error_propagate(errp, err);

should print out the error here instead of propagate it,otherwise the error msg
is lost.

>> +    return ret;
>> +}
>>
>>   int net_init_filters(void)
>>   {
>> +    QTAILQ_INIT(&net_filters);
>> +
>> +    if (qemu_opts_foreach(qemu_find_opts("netfilter"),
>> +                          net_init_filter, NULL, NULL)) {
>> +        return -1;
>> +    }
>> +
>>       return 0;
>>   }
>
> Then errors will be lost here?
>

Yes, good catch, thank you !

> .
>

-- 
Thanks,
Yang.

  reply	other threads:[~2015-08-20 16:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-07  2:46 [Qemu-devel] [PATCH v6 00/10] For QEMU 2.5: Add a netfilter object and netbuffer filter Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 01/10] net: add a new object netfilter Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 02/10] init/cleanup of netfilter object Yang Hongyang
2015-08-10  9:18   ` Jason Wang
2015-08-20 16:41     ` Yang Hongyang [this message]
2015-08-21  1:35       ` Jason Wang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 03/10] netfilter: add netfilter_{add|del} commands Yang Hongyang
2015-08-10  9:20   ` Jason Wang
2015-08-11  7:07   ` Wen Congyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 04/10] netfilter: hook packets before net queue send Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 05/10] move out net queue structs define Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 06/10] netfilter: add an API to pass the packet to next filter Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 07/10] net/queue: export qemu_net_queue_append_iov Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 08/10] netfilter: add a netbuffer filter Yang Hongyang
2015-08-10  9:21   ` Jason Wang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 09/10] filter/buffer: update command description and help Yang Hongyang
2015-08-07  2:46 ` [Qemu-devel] [PATCH v6 10/10] tests: add test cases for netfilter object Yang Hongyang
2015-08-11  7:12   ` Wen Congyang
2015-08-10  9:17 ` [Qemu-devel] [PATCH v6 00/10] For QEMU 2.5: Add a netfilter object and netbuffer filter Jason Wang
2015-08-14  1:26   ` Yang Hongyang

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=55D60356.60603@cn.fujitsu.com \
    --to=yanghy@cn.fujitsu.com \
    --cc=jasowang@redhat.com \
    --cc=lizhijian@cn.fujitsu.com \
    --cc=mrhines@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=zhang.zhanghailiang@huawei.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.