Sending raw ip on multihomed host

This is a discussion on Sending raw ip on multihomed host within the Linux Networking forums, part of the Linux Forums category; This is a "getlocaladdr" problem. I've implemented a "virtual applikation server" that will take packets ...


Go Back   Usenet Forums > Linux Forums > Linux Networking

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-10-2004
Robin
 
Posts: n/a
Default Sending raw ip on multihomed host

This is a "getlocaladdr" problem.

I've implemented a "virtual applikation server" that will take packets and
send them to another host based on port numbers, thus working as both
client and server to make a session work (like a man in the middle)..

The problem is to support this funktionality on a multihomed host (a host
with more than one network card).. since I don't know what source address
to use when sending packets.

I'm using a raw socket like this for sending:
m_sock = socket(PF_INET, SOCK_RAW, htons(IPPROTO_RAW));
// -------------> Also tried AF_INET
const int on = 1;
setsockopt(m_sock, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on));

According to man page the following holds for raw sockets with IP_HDRINCL
+------------------------------------------------------------------+
|IP Header fields modified on sending when IP_HDRINCL is specified |
+------------------------------------------------------------------+
| Sending fragments with IP_HDRINCL is not supported currently. |
+--------------------------+---------------------------------------+
|IP Checksum |Always filled in. |
+--------------------------+---------------------------------------+
|Source Address |Filled in when zero. |
+--------------------------+---------------------------------------+
|Packet Id |Filled in when passed as 0. |
+--------------------------+---------------------------------------+
|Total Length |Always filled in. |
+--------------------------+---------------------------------------+

But the kernel don't fill in the source when i zero it out in the header.
I'm using the following sendto.

sockaddr_in toAddr = packet.getDestinationHost();
toAddr.sin_family = AF_INET;
return sendto(m_sock,
(void *) packet.getBuffer(), /* "const void* msg" */
packet.get_ip_len(),
0,
(sockaddr *) &toAddr,
sizeof(struct sockaddr_in)); /* "socklen_t tolen" */

It works fine when I specify the correct source address in the packet so I
must be doing atleast some of it right..

I zero it out like this...

in_addr sourceAddr;
bzero(&sourceAddr, sizeof(in_addr));
_packet.set_ip_src(sourceAddr);

but the address wont be filled in after send... I guess that I actually send
a packet with source address = 0.0.0.0

I would be so very happy if someone could point out what I'm doing wrong or
help me in some other way to dynamicly find out the correct source IP based
on the destination address..
I've considered to just send the packet out on all networks just to be safe
but that just doesn't seem right.

I'm using Mandrake 9.0: Kernel 2.4.19(Patched with IPDIVERT); Glibc 2.2.5

Thanks
Reply With Quote
  #2 (permalink)  
Old 02-11-2004
Cameron Kerr
 
Posts: n/a
Default Re: Sending raw ip on multihomed host

Robin <romeomajk@sundsvall.nu> wrote:
> This is a "getlocaladdr" problem.
>
> I've implemented a "virtual applikation server" that will take packets and
> send them to another host based on port numbers, thus working as both
> client and server to make a session work (like a man in the middle)..


You know about the Linux Virtual Server component of 2.6 kernels?

> The problem is to support this funktionality on a multihomed host (a host
> with more than one network card).. since I don't know what source address
> to use when sending packets.


Follow this psuedocode:

for every network device that is UP:
create a socket for this device
store the devices source address
add it to a list of sockets to select on.
select on all of the sockets waiting for readablity
use the stored address for the source address.

Alternatively, you may be able to use recvmsg and sendmsg, but I don't
know if that would work with raw IP

--
Cameron Kerr
cameron.kerr@paradise.net.nz : http://nzgeeks.org/cameron/
Empowered by Perl!
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:31 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0