From: Arnaldo Carvalho de Melo <acme@redhat.com>
To: david@lang.hm
Cc: netdev@vger.kernel.org
Subject: Re: ip_nonlocal_bind and sendto (fwd)
Date: Fri, 27 Feb 2009 11:50:15 -0300 [thread overview]
Message-ID: <20090227145015.GG22152@ghostprotocols.net> (raw)
In-Reply-To: <alpine.DEB.1.10.0902270119060.7158@asgard.lang.hm>
Em Fri, Feb 27, 2009 at 01:20:07AM -0800, david@lang.hm escreveu:
> I've got a need to forge the source IP of UDP packets (a stupid syslog
> receiver app that I need to deal with)
>
> I know that this can be done with raw sockets, but with the
> IP_nonlocal_bind option I thought that it may be possible to do this
> without dealing with raw sockets
>
> so I have an app that does the socket call, followed by the bind call
> without any errors, but when I issue the sendto call it generates error
> 22 (invalid parameter) if the source IP doesn't exist on the local box
> somewhere.
>
> is this the kernel that is doing whatever check is failing? or is glibc
> wrapping the kernel syscall and doing some additional checking?
>
> if it is the kernel that's throwing the error, is there some way of
> disabling this check? or do I have to go to raw sockets?
Follow:
udp_sendmsg
ip_route_output_flow
__ip_route_output_key
And then look at this line:
rth->fl.fl4_src == flp->fl4_src &&
It'll fail and so another function will be called:
ip_route_output_slow
Many, many details later, this comment:
Because we are allowed to send to iface
even if it has NO routes and NO assigned
addresses. When oif is specified, routing
tables are looked up with only one purpose:
to catch if destination is gatewayed, rather than
direct. Moreover, if MSG_DONTROUTE is set,
we send packet, ignoring both routing tables
and ifaddr state. --ANK
So try using:
setsockopt(udp_sock, SOL_SOCKET, SO_BINDTODEVICE, "eth0", 5);
Replacing "eth0" with the interface you want your forged packets to fly by.
The device name will be transformed into an index and stored in
sk->sk_bound_dev_if, that later, at udp_sendmsg time, will get stashed into
that oif field and then that comment will hold.
Caveat emptor: I never tried this, this is just after 5 minutes code inspection 8)
- Arnaldo
next prev parent reply other threads:[~2009-02-27 14:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-27 9:20 ip_nonlocal_bind and sendto (fwd) david
2009-02-27 14:50 ` Arnaldo Carvalho de Melo [this message]
2009-02-27 17:50 ` david
2009-02-27 22:07 ` david
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=20090227145015.GG22152@ghostprotocols.net \
--to=acme@redhat.com \
--cc=david@lang.hm \
--cc=netdev@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).