I can reach a host through two different gateways (I have redundant
Internet connection using 2 interfaces). I know it's useless to have two
default routes, but how can I force certain UDP packets to use one of
the interfaces I choose?
For example, I want to send a UDP packet via "eth1" and the next one via
"ppp0". How can I do that?
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.100.101 * 255.255.255.255 UH 0 0 0 ppp0
10.0.0.0 * 255.0.0.0 U 0 0 0 eth1
default 217.201.206.152 0.0.0.0 UG 0 0 0 ppp0
default 10.1.1.10 0.0.0.0 UG 0 0 0 eth1
eth1 Link encap:Ethernet HWaddr 00:05:1B:00:56:E1
inet addr:10.1.1.119 Bcast:10.255.255.255 Mask:255.0.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:492267 errors:0 dropped:0 overruns:0 frame:0
TX packets:4787 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:656294260 (625.8 MiB) TX bytes:1097504 (1.0 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:136 (136.0 iB) TX bytes:136 (136.0 iB)
ppp0 Link encap:Point-Point Protocol
inet addr:217.201.206.152 P-t-P:192.168.100.101 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:30 errors:0 dropped:0 overruns:0 frame:0
TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:2870 (2.8 kiB) TX bytes:4419 (4.3 kiB)
Thanks for any hint,
Udo
--
> For example, I want to send a UDP packet via "eth1" and the next
> one via "ppp0". How can I do that?
Create a route for each. Only works if you know the IP range though.
> Thanks for any hint,
I suggest you try asking a networking newsgroup, not an application
development one.
Regards,
Björn
--
BOFH excuse #182:
endothermal recalibration
How? The destination host is always the same.
> I suggest you try asking a networking newsgroup, not an application
> development one.
I asked a similar question in comp.os.linux.networking, but I thought that
maybe something can be done at application level (some special API
function).
--
Udo
>> Create a route for each. Only works if you know the IP range
>> though.
> How? The destination host is always the same.
Then it's not possible using route.
> I asked a similar question in comp.os.linux.networking, but I
> thought that maybe something can be done at application level
> (some special API function).
Because network filtering is done in kernelspace (netfilter), and
not userspace, you could also try to ask in a kernel NG. Your
problem could perhaps be solved by writing a module, or, if you're
lucky, by using the iptables "mangle" functions.
Regards,
Björn
--
BOFH excuse #5:
static from plastic slide rules
--
Thirteen at a table is unlucky only when the hostess has only twelve chops.
-- Groucho Marx
> Udo Giacomozzi wrote:
>
>> Bjoern Schliessmann wrote:
>>
>>> Create a route for each. Only works if you know the IP range
>>> though.
>>
>> How? The destination host is always the same.
>
> Then why do you want to use different routes? You can delete one
> route when you want to use the other.
Perhaps he wants to do bandwidth aggregation?
I've checked the Linux Channel Bonding documentation:
http://prdownloads.sourceforge.net/bonding/bonding.txt?download
but I don't think that's what the original poster wants.
Because the routes are based on wireless links that go easily up and down
because the system is mobile.
Being a somewhat time critical application I need to know which
interface/route is currently working and I need to be able to use both
interfaces/routes at the same time.
For example, having a GPRS link and a WLAN link I send the same UDP
packet through both interfaces, hoping that at least one works. I can't
desribe this more in detail because it would go beyond the scope of this
thread.
Anyway, each uplink is controlled by an individual process and so I can
simply add and delete routes...
It seems that with iproute2 rules it should be possible to route based on
the source address. I'm currently checking this (my kernel is not yet
configured for netfilter).
Udo
--
> Anyway, each uplink is controlled by an individual process and so I
> can simply add and delete routes...
That should say "can not" of course ;-)
Udo
> Udo Giacomozzi wrote:
>> Bjoern Schliessmann
>
>>> Create a route for each. Only works if you know the IP range
>>> though.
>
>> How? The destination host is always the same.
>
> Then it's not possible using route.
I'm currently checking the advanced features of iproute2. The "Linux
Advanced Routing & Traffic Control HOWTO" says that you can:
- Do routing based on user id (yes!), MAC address, source IP address, port,
type of service, time of day or content
Udo
--
> - Do routing based on user id (yes!), MAC address, source IP
> address, port, type of service, time of day or content
Oh, nice. Good speed then. :)
Regards,
Björn
--
BOFH excuse #29:
It works the way the Wang did, what's the problem
> Oh, nice. Good speed then. :)
:-)
--
bind(2) the socket to the IP address of the respective interface.
What if he wants to send two packets on the Ethernet interface, then
one packet on the WiFi interface, and so on?
Then you create two sockets.
> bind(2) the socket to the IP address of the respective interface.
Tried that. The packet source address changes, but the interface is still
the same. More precisely, the packet has the IP address of the ethernet
interface (10.1.1.119) but gets routed over the GPRS interface (217.x.x.x)
and thus does not go anywhere.
Verified with tcpdump.
However, I think that's the way to go. iproute2 should allow to route based
on the source IP address - still have to check that.
--
Udo
>> What if he wants to send two packets on the Ethernet interface, then
>> one packet on the WiFi interface, and so on?
That's exactly what I need to do :-)
> Then you create two sockets.
I have. But the source address does not affect routing.
At least it does not with my 2.4 kernel.
--
Udo
Hmm. Is that code available online somewhere?
PS: I'll be away till wednesday next week, so please don't mind if I can't
reply earlier...
--
Udo
> Being a somewhat time critical application I need to know which
> interface/route is currently working and I need to be able to use
> both interfaces/routes at the same time.
>
> For example, having a GPRS link and a WLAN link I send the same UDP
> packet through both interfaces, hoping that at least one works. I
> can't desribe this more in detail because it would go beyond the
> scope of this thread.
The "broadcast" policy in the bonding driver might be able to do that?
broadcast or 3
Broadcast policy: transmits everything on all slave
interfaces. This mode provides fault tolerance.
> It seems that with iproute2 rules it should be possible to route
> based on the source address. I'm currently checking this (my kernel
> is not yet configured for netfilter).
I think this article covers what you're looking for:
Overcoming Asymmetric Routing on Multi-Homed Servers
http://www.linuxjournal.com/article/7291
Regards.
> The "broadcast" policy in the bonding driver might be able to do that?
Not exactly. I have to use different strategies based on the situation
because I need to ensure:
1 - best possible availability
2 - shortest possible transmit delay
3 - minimum use of a interface, when it is unnecessary (for uplinks with
limited bandwith shared by multiple devices)
So I give my uplinks different priorities. When the highest priority
fails, the same packet is sent again with both the 1st *and* the 2nd
priority. If also that fails, use one more uplink and so on. In any case
uplinks with higher priority will always send a copy of the same packet.
This way I immediately know when a higher priority uplink gets online
again. Each request sent over a certain uplink is acknowledged using the
same interface (so each packet copy gets it's own ACK).
You see, I need to manually choose the interfaces to use.
> I think this article covers what you're looking for:
>
> Overcoming Asymmetric Routing on Multi-Homed Servers
> http://www.linuxjournal.com/article/7291
Yeah, it's pretty close, thanks. It's also using iprouting2 which I had
not yet the possibility to test (a certain configuration is not being
accepted by the kernel).
I'll let you know.
--
Udo
You don't want a packet to take a broken link, but you don't want a
route out a broken link either. So fix the routes and the packets will
DTRT.
It's not that easy. For example with GPRS the link can still be up even if
the packets can't reach the base station (in fact I have to reset the PPP
link manually when I notice packets don't get acknowledged).
Links can go physically up and down within minutes or less without the
kernel noticing that. My software can detect it however, and needs to find
a working route as fast as possible and should use various routes in
parallel to find the best one for the moment.
I *really* need to bypass the kernel routing, for a variety of reasons.
--
Udo