<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body dir="ltr" bgcolor="#ffffff" text="#000000">
<p style="margin-bottom: 0cm; margin-top: 0pt;">Hello List,</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">A friend presented me
with a difficult problem which I don't have a solution for and I
thought someone here on the list might have an idea.</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">The problem is as
follows:</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">You have an application
running on a machine that has two network interfaces. One for
management and one for media.</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">You have a network
server application (it's a SIP UA but that doesn't matter much) that is
bound to an IP on the media network interface. Because the media and
management networks might be completely different, you use the
BIND_TO_DEVICE socket option om the server sockets so that the kernel
will only route traffic for that socket via that device.</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">Normally, the clients
that speak to the server are outside the machine and sit on the media
network, and everything works.</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">However, there is one
exception - you have a single client which runs on the machine itself
that needs to talk to the server. The client tries to connect to the
server IP, but since all IP traffic inside the machine is automatically
routed via the loopback network interface (lo), and since the server
forces the kernel to only route traffic via the media interface, we
have a routing failure and the client can't talk to the server.
However, if you were to remove the server BIND_TO_DEVICE and everything
works.</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">Required: a solution,
generic as possible, extra points for no need to change server and
client apps :-)</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">Already suggested and
reject by my friend:</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">
<blockquote type="cite">
<p style="margin: 0in 0in 0.0001pt;">OK, I found a solution. It does
require some work but it'll do the job:<o:p></o:p></p>
<p style="margin: 0in 0in 0.0001pt;"><o:p> </o:p></p>
<p style="margin: 0in 0in 0.0001pt;">You will need to hijack the
socket, bind, connect (for TCP) and sendto, recvfrom (for UDP) C
library calls.<o:p></o:p></p>
<p style="margin: 0in 0in 0.0001pt;">See <a
href="http://tuxology.net/2008/05/15/forcing-connections-through-a-specific-interface/">
http://tuxology.net/2008/05/15/forcing-connections-through-a-specific-interface/</a>
for an example of how to hijack the library calls.<o:p></o:p></p>
<p style="margin: 0in 0in 0.0001pt;"><o:p> </o:p></p>
<p style="margin: 0in 0in 0.0001pt;">Using these hijacked library
calls, whenever the application opens a socket, you create another
shadow socket which is not bound to the outside interface. Then for
each bind/connect/sendto and recvfrom call, use the appropriate socket
(bound to device or otherwise) according to the destination - external
or internal.<o:p></o:p></p>
<p style="margin: 0in 0in 0.0001pt;"><o:p> </o:p></p>
Since the hijacking is done by
writing an external library and forcing the application to load it by
setting an environment variable, no changes to the application is
required.</blockquote>
The reason for rejection is:</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">
<blockquote type="cite"><span style="color: rgb(31, 73, 125);">There
will be a clash if 2 instances of the application use the same port…</span></blockquote>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">The solver will win
fame and my eternal gratitude. :-)</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">Is there anyone up for
the challenge?</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;">Gilad<br>
</p>
<pre class="moz-signature" cols="72">--
Gilad Ben-Yossef
Chief Coffee Drinker & CTO
Codefidence Ltd.
Web: <a class="moz-txt-link-freetext" href="http://codefidence.com">http://codefidence.com</a>
Cell: +972-52-8260388
Tel: +972-8-9316883 ext. 201
Fax: +972-8-9316884
Email: <a class="moz-txt-link-abbreviated" href="mailto:gilad@codefidence.com">gilad@codefidence.com</a>
Check out our Open Source technology and training blog - <a class="moz-txt-link-freetext" href="http://tuxology.net">http://tuxology.net</a>
        "Now the world has gone to bed
         Darkness won't engulf my head
         I can see by infra-red
         How I hate the night."
</pre>
</body>
</html>