From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNbn7-0003VC-RA for qemu-devel@nongnu.org; Mon, 25 Jan 2016 02:42:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNbn3-00037s-0M for qemu-devel@nongnu.org; Mon, 25 Jan 2016 02:42:25 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:60692) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNbn2-00037k-A5 for qemu-devel@nongnu.org; Mon, 25 Jan 2016 02:42:20 -0500 References: <1453451811-11860-1-git-send-email-zhang.zhanghailiang@huawei.com> <1453451811-11860-5-git-send-email-zhang.zhanghailiang@huawei.com> <56A5B0AB.906@redhat.com> From: Hailiang Zhang Message-ID: <56A5D1CA.1060501@huawei.com> Date: Mon, 25 Jan 2016 15:42:02 +0800 MIME-Version: 1.0 In-Reply-To: <56A5B0AB.906@redhat.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH RFC 4/7] 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: 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:20, Jason Wang wrote: > > > On 01/22/2016 04:36 PM, zhanghailiang wrote: >> Signed-off-by: zhanghailiang > > Commit log please. > I will add it in next version, thanks. >> --- >> include/net/filter.h | 5 +++++ >> net/filter.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 68 insertions(+) >> >> diff --git a/include/net/filter.h b/include/net/filter.h >> index d797ee4..c7bd8f9 100644 >> --- a/include/net/filter.h >> +++ b/include/net/filter.h >> @@ -81,4 +81,9 @@ static inline bool qemu_need_skip_netfilter(NetFilterState *nf) >> >> void netfilter_print_info(NetFilterState *nf, char *output_str, int size); >> >> +void netdev_add_filter(const char *netdev_id, >> + const char *filter_type, >> + const char *id, >> + Error **errp); >> + >> #endif /* QEMU_NET_FILTER_H */ >> diff --git a/net/filter.c b/net/filter.c >> index f4933cc..4d96301 100644 >> --- a/net/filter.c >> +++ b/net/filter.c >> @@ -16,6 +16,10 @@ >> #include "qom/object_interfaces.h" >> #include "qemu/iov.h" >> #include "qapi/string-output-visitor.h" >> +#include "qapi/qmp/qdict.h" >> +#include "qapi/qmp-output-visitor.h" >> +#include "qapi/qmp-input-visitor.h" >> +#include "monitor/monitor.h" >> >> ssize_t qemu_netfilter_receive(NetFilterState *nf, >> NetFilterDirection direction, >> @@ -232,6 +236,65 @@ static void netfilter_complete(UserCreatable *uc, Error **errp) >> QTAILQ_INSERT_TAIL(&nf->netdev->filters, nf, next); >> } >> >> +/* >> +* This will be used by COLO or MC FT, for which they will need >> +* to buffer the packets of VM's net devices, Here we add a default >> +* buffer filter for each netdev. The name of default buffer filter is >> +* 'nop' >> +*/ >> +void netdev_add_filter(const char *netdev_id, >> + const char *filter_type, >> + const char *id, >> + Error **errp) >> +{ >> + QmpOutputVisitor *qov; >> + QmpInputVisitor *qiv; >> + Visitor *ov, *iv; >> + QObject *obj = NULL; >> + QDict *qdict; >> + void *dummy = NULL; >> + NetClientState *nc = qemu_find_netdev(netdev_id); >> + Error *err = NULL; >> + >> + /* FIXME: Not support multiple queues */ >> + if (!nc || nc->queue_index > 1) { >> + return; >> + } >> + /* Not support vhost-net */ >> + if (get_vhost_net(nc)) { >> + return; >> + } >> + >> + qov = qmp_output_visitor_new(); >> + ov = qmp_output_get_visitor(qov); >> + visit_start_struct(ov, &dummy, NULL, NULL, 0, &err); >> + if (err) { >> + goto out; >> + } >> + visit_type_str(ov, &nc->name, "netdev", &err); >> + if (err) { >> + goto out; >> + } >> + visit_end_struct(ov, &err); >> + if (err) { >> + goto out; >> + } >> + obj = qmp_output_get_qobject(qov); >> + g_assert(obj != NULL); >> + qdict = qobject_to_qdict(obj); >> + qmp_output_visitor_cleanup(qov); >> + >> + qiv = qmp_input_visitor_new(obj); >> + iv = qmp_input_get_visitor(qiv); >> + object_add(filter_type, id, qdict, iv, &err); >> + qmp_input_visitor_cleanup(qiv); >> + qobject_decref(obj); >> +out: >> + if (err) { >> + error_propagate(errp, err); >> + } >> +} >> + >> static void netfilter_finalize(Object *obj) >> { >> NetFilterState *nf = NETFILTER(obj); > > > . >