[erlang-questions] Local IP address in UDP packets

Serge Aleynikov <>
Mon Oct 16 15:06:50 CEST 2006


Kenneth,

See in-line.

Kenneth Lundin (AS/EAB) wrote:
>> -----Original Message-----
>> From: Serge Aleynikov [mailto:] 
>> Sent: den 10 oktober 2006 18:08
>> To: Erlang Users' List
>> Subject: Local IP address in UDP packets
>>
>> Hi,
>>
>> We have a UDP server process that starts listening on the 
>> {0,0,0,0} address of a host with multiple IPs.  It needs to 
>> know the local destination IP address that a UDP packet was 
>> received on,
 >
> Why can't you explicitly receive on a specific IP address and by that
> knowing
> the IP address the UDP packet was received on?

A typical use case for this is as following.  Two hosts are configured 
with Virtual IP (VIP) balancing software (using a project like 
http://linux-ha.org).  This way a VIP can be migrated from one host to 
another based on network conditions or operator action.  It may not be 
possible to receive notifications from such a process indicating that a 
VIP was activated on current host.  Additionally, there might be 
multiple VIPs balanced between N hosts, where each VIP may get 
dynamically assigned to any host in the subnet.

I would like to have a UDP server listening on 0.0.0.0 address.  This 
way a turn up of a new VIP won't require to change any server properties 
nor restart the server - packets received on *any* IP address on that 
host (on a given port) will get delivered to the server process.  This 
adds a requirement to know which IP a packet was received on.

[...]
> We discussed this, here are our initial thoughts:
> - That the presence of an option ("local_address") changes the format of
> received packages
> is not good. In that case we would prefer to introduce a new generic
> format for received packages
> where data which is inly present if a certain option is set is put in a
> separate list with 
> optional data.  Like this : {udp_packet, Socket, IP, InPortNo, Packet,
> OptionalData}
> Optional data would in your example a) above look like this:
> [{toip,ToIp}].

I agree, this indeed sounds like a better idea.

> - On how many platforms can the option 'local_address' be supported?
> (Windows?, Linux, MacOSx?, Solaris?) 

Knowing the target local IP on reception of a packet seems to be 
available on many platforms (though via distinct stack-specific API).
We only checked that sending packets from a specific local IP is 
supported on Linux, and partially on Solaris (Solaris =< 10 doesn't 
allow to specify the local IP address.  This Solaris limitation seemed 
to be fixed in the OpenSolaris project, but we haven't checked if 
Solaris 11 fixes the issue as well).

> And what should happen on platforms that don't support the
> option?
> An error when the option is set? or silently swallow the option without
> any, ... no that is not good.

I think returning an error would be a better choice.

> - What is the real usecase when the option is needed? You explain above,
> but why do you want/need to do like that?

See above.

We are planning to patch inet_drv.c for enabling this feature some time 
this or next week.  If you are interested I can send you the patch.

Regards,

Serge



More information about the erlang-questions mailing list