netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Damien Thébault" <damien.thebault@gmail.com>
To: "Patrick McHardy" <kaber@trash.net>
Cc: linux-net@vger.kernel.org, netfilter-devel@vger.kernel.org,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: conntrack doesn't always work when a bridge is used
Date: Fri, 11 Jan 2008 16:16:46 +0100	[thread overview]
Message-ID: <9a4a382a0801110716g206f0719o9f067fd7d7baeda5@mail.gmail.com> (raw)
In-Reply-To: <47876E4A.2010608@trash.net>

On Jan 11, 2008 2:25 PM, Patrick McHardy <kaber@trash.net> wrote:
> Patrick McHardy wrote:
> > Damien Thébault wrote:
> >> On the router, I'm using this script :
> >>
> >> ifconfig eth0 0.0.0.0 up
> >> brctl addbr br0
> >> brctl addif br0 eth0
> >> ifconfig br0 192.168.1.70 up
> >> ifconfig br0:0 192.168.2.70 up
> >> iptables -t nat -A POSTROUTING -d 192.168.2.0/24 -j MASQUERADE
> >> iptables -t nat -A PREROUTING -d 192.168.2.250 -j DNAT
> >> --to-destination 192.168.2.50
>
> >
> > Thanks. Its the DNAT rule thats causing this, the bridge netfilter code
> > calls dst_output directly for bridged dnated frames, causing these
> > hook invocations:
> >
> >                PREROUTING
> > dst_output()    POSTROUTING
> >                FORWARD
> >                POSTROUTING
> >
> >
> > which is obviously broken. I'll see if I can come up with a fix for this.
>
> It appears this has always been broken. Could you test this patch please?
>
> The bridge code only calls dst_output to get a new destination MAC
> address for the DNATed packet when the new destination is reachable
> on the same bridge, so this patch simply hands the packet to the
> neighbour output function without going through the IP stack.
>
>
>
> diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
> index c1757c7..362fe89 100644
> --- a/net/bridge/br_netfilter.c
> +++ b/net/bridge/br_netfilter.c
> @@ -285,12 +285,17 @@ static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
>         skb->nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
>
>         skb->dev = bridge_parent(skb->dev);
> -       if (!skb->dev)
> -               kfree_skb(skb);
> -       else {
> +       if (skb->dev) {
> +               struct dst_entry *dst = skb->dst;
> +
>                 nf_bridge_pull_encap_header(skb);
> -               skb->dst->output(skb);
> +
> +               if (dst->hh)
> +                       return neigh_hh_output(dst->hh, skb);
> +               else if (dst->neighbour)
> +                       return dst->neighbour->output(skb);
>         }
> +       kfree_skb(skb);
>         return 0;
>  }
>
>
>

I confirm that this patch solves the problem with this setup, thanks!

Does this mean that without this patch, DNAT doesn't work (correctly)
on a bridge?

-- 
Damien Thebault

  reply	other threads:[~2008-01-11 15:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <9a4a382a0712180648i7fc958edt6f0d9db83f574c77@mail.gmail.com>
2007-12-19 17:00 ` conntrack doesn't always work when a bridge is used Damien Thébault
2007-12-19 19:03   ` Patrick McHardy
2007-12-20  8:30     ` Damien Thébault
2007-12-20 10:06       ` Patrick McHardy
2007-12-20 11:06         ` Damien Thébault
2007-12-20 11:07           ` Patrick McHardy
2007-12-20 11:20             ` Damien Thébault
2007-12-20 11:25               ` Patrick McHardy
2007-12-20 13:21                 ` Damien Thébault
2007-12-20 16:08                   ` Damien Thébault
2007-12-22  7:56                   ` Patrick McHardy
2007-12-26  9:54                     ` Damien Thébault
2007-12-30 17:53                       ` Patrick McHardy
     [not found]                         ` <9a4a382a0801020118n4166e505l5eb84a9f07f620be@mail.gmail.com>
2008-01-11  8:10                           ` Damien Thébault
2008-01-11 12:24                             ` Patrick McHardy
2008-01-11 12:53                               ` Damien Thébault
2008-01-11 12:57                                 ` Patrick McHardy
2008-01-11 13:25                                   ` Patrick McHardy
2008-01-11 15:16                                     ` Damien Thébault [this message]
2008-01-11 17:33                                       ` Patrick McHardy
2007-12-28 14:39   ` Damien Thébault

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=9a4a382a0801110716g206f0719o9f067fd7d7baeda5@mail.gmail.com \
    --to=damien.thebault@gmail.com \
    --cc=davem@davemloft.net \
    --cc=kaber@trash.net \
    --cc=linux-net@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).