From 25aaadf063c447def3442f30390334cb3ada37db Mon Sep 17 00:00:00 2001 From: Li Zhijian Date: Tue, 26 Jan 2016 13:00:22 +0800 Subject: net: always walk through filters in reverse if traffic is egress Previously, if we attach more than one filters for a single netdev, both ingress and egress traffic will go through net filters in same order like: ingress: netdev ->filter1 ->filter2 ->...filter[n] ->emulated device egress: emulated device ->filter1 ->filter2 ->...filter[n] ->netdev. This is against the natural feeling and will complicate filters configuration since in some scenes, we hope filters handle the egress traffic in a reverse order. For example, in colo-proxy (will be implemented later), we have a redirector filter and a colo-rewriter filter, we need the filter behave like: ingress(->)/egress(<-): chardev<->redirector<->colo-rewriter<->emulated device Since both buffer filter and dump do not require strict order of filters, this patch switches to always let egress traffic walk through net filters in reverse to simplify the possible filters configuration in the future. Signed-off-by: Wen Congyang Signed-off-by: Li Zhijian Reviewed-by: Yang Hongyang Signed-off-by: Jason Wang --- net/net.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'net/net.c') diff --git a/net/net.c b/net/net.c index 87dd3568dc..c929c41a10 100644 --- a/net/net.c +++ b/net/net.c @@ -580,11 +580,21 @@ static ssize_t filter_receive_iov(NetClientState *nc, ssize_t ret = 0; NetFilterState *nf = NULL; - QTAILQ_FOREACH(nf, &nc->filters, next) { - ret = qemu_netfilter_receive(nf, direction, sender, flags, iov, - iovcnt, sent_cb); - if (ret) { - return ret; + if (direction == NET_FILTER_DIRECTION_TX) { + QTAILQ_FOREACH(nf, &nc->filters, next) { + ret = qemu_netfilter_receive(nf, direction, sender, flags, iov, + iovcnt, sent_cb); + if (ret) { + return ret; + } + } + } else { + QTAILQ_FOREACH_REVERSE(nf, &nc->filters, NetFilterHead, next) { + ret = qemu_netfilter_receive(nf, direction, sender, flags, iov, + iovcnt, sent_cb); + if (ret) { + return ret; + } } } -- cgit v1.2.3