From: Andrey Savochkin <saw@saw.sw.com.sg>
To: "Nadav Har'El" <nyh@math.technion.ac.il>, linux-kernel@vger.kernel.org
Subject: Re: Bug in nonlocal-bind (transparent proxy)?
Date: Fri, 8 Jun 2001 01:44:43 -0400 [thread overview]
Message-ID: <20010608014443.A28407@saw.sw.com.sg> (raw)
In-Reply-To: <20010607170825.A18760@leeor.math.technion.ac.il>
In-Reply-To: <20010607170825.A18760@leeor.math.technion.ac.il>; from "Nadav Har'El" on Thu, Jun 07, 2001 at 05:08:25PM
Hi,
It's not a bug, it's willful.
On Thu, Jun 07, 2001 at 05:08:25PM +0300, Nadav Har'El wrote:
> I am writing a transparent-proxy-like application, that needs to be able to
> bind a TCP socket with a non-local address (i.e., the proxy contacts the
> origin-server, in the local network, pretending to be the original client.
> The reply will get back to the proxy because it acts as the default
> gateway, and the kernel needs to pass that reply to the socket).
>
> Bind()ing a non-local address worked fine in the 2.2 line of kernels if a
> certain compile-time option was enabled (TRANSPARENT_PROXY, or something
> like that). But it no longer seems to be working in the 2.4 kernels (I
> tried this on 2.4.2 coming from the Redhat 7.1 distribution).
>
> First, bind() simply refused to work when given a non-local address (returning
> EADDRNOTAVAIL). Reading the kernel's source I discovered that an undocumented
> "ip_nonlocal_bind" sysctl makes the kernel agree to do such a bind (this
> should really be in the bind() documentation...). Enabling this option
> allowed bind to work (it can even catch the case of two sockets trying to
> bind the same address), but the later connect() fails!
> I tryed reading the kernel sources to figure out what's wrong with the
> connect(), but failed to understand why it returns a EINVAL. I think this
> is a bug, and include below a short program to reproduce it:
>
> If you run the program below, connect() will fail with EINVAL (it will do
> so before even trying to output a packet). To see that nothing's actually
> wrong with the connect, change the #if 1 to #if 0, eliminating the bind(),
> and see that the connect works (or at least fails with a connection refused,
> as it should because of the random IP address).
> Note that you must run the program as root, and do
> echo 1 > /proc/sys/net/ipv4/ip_nonlocal_bind
> to get the bind() to work at all. But once you do that, and bind() works,
> how come connect() doesn't work?
>
> Thanks in advance for any insights or fixes!
To make a custom kernel where you can use non-local addresses more freely,
find source address checks in ip_route_output_slow() and get rid of all of
them except considering
MULTICAST(saddr) || BADCLASS(saddr) || ZERONET(saddr) ||
saddr == htonl(INADDR_BROADCAST)
as invalid.
Andrey
next prev parent reply other threads:[~2001-06-08 5:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-07 14:08 Nadav Har'El
2001-06-08 5:44 ` Andrey Savochkin [this message]
2001-06-08 8:02 ` Nadav Har'El
2001-06-08 8:25 ` David S. Miller
2001-09-03 10:12 ` Transparent proxy support in 2.4 - revisited Nadav Har'El
2001-09-03 10:44 ` Andrey Savochkin
2001-09-03 13:16 ` Nadav Har'El
2001-09-03 13:55 ` Andrey Savochkin
2001-09-03 16:43 ` Julio Sanchez Fernandez
2001-09-03 20:07 ` Nerijus Baliunas
2001-09-03 22:50 ` Alexey Kuznetsov
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=20010608014443.A28407@saw.sw.com.sg \
--to=saw@saw.sw.com.sg \
--cc=linux-kernel@vger.kernel.org \
--cc=nyh@math.technion.ac.il \
/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
all inboxes | Powered by JetHome®