[erlang-questions] Problems with gen_udp on multi-homed hosts

Gregory Haskins gregory.haskins@REDACTED
Tue Nov 16 19:03:18 CET 2010


On 11/16/10 11:48 AM, Michael Santos wrote:
> On Tue, Nov 16, 2010 at 10:31:47AM -0500, Gregory Haskins wrote:
>> Hi All,
>>
>> I am trying to develop a custom DHCP server against 14B on that is
>> sitting on a multi-homed linux host.  I only want the server to
>> listen/respond on one of these interfaces, but I am having trouble
>> getting gen_udp to behave in a way I would expect.
>>
>> My system has the following interfaces:
>>
>> 3> inet:getiflist().
>> {ok,["lo","br0","virbr0"]}
>> 4> inet:ifget("virbr0", [addr]).
>> {ok,[{addr,{192,168,122,1}}]}
>> 5> inet:ifget("br0", [addr]).
>> {ok,[{addr,{151,155,230,24}}]}
>>
>> and I am interested in packets only on 192.168.122.1/virbr0.
>>
>> So if I gen_udp:open() _without_ {ip, ?ADDR} set, I can see the
>> broadcasts coming from 192.168.122.0/24 (as well as from the other
>> interfaces) as I would expect.  However, the {udp, Socket, ..} message I
>> get has a inet:sockname() of {0.0.0.0}, and if I try to reply with a
>> broadcast of {255.255.255.255} to the same socket, it goes out on the
>> "br0" interface.
> 
> Does it work if you send the packet out using a more specific broadcast
> address? e.g., 192.168.122.255

Hmm, good question.  I could try this, though I think the procket
reference you provide below is probably a better solution.

> 
>> So the obvious solution to me after googling was to use the {ip,
>> {192.168.122.1}} option on the open.  The open() call succeeds with this
>> option set, but I never see any packets (even though I have sniffed the
>> line and they are indeed being sent.  As a sanity check, I also set a
>> bogus IP in the open(), and it does indeed exception out, so it seems
>> like it is taking the option I set.
> 
> Not sure why this isn't working, maybe the packet is still going out
> your default interface.

Well, the problem I was describing was on the RX side.  I don't seem to
get any packets once the {ip, ..} option is set (even though my client
is basically making requests every few seconds regardless of the
server-side mode, and I can confirm I see the packets on the wire via
wireshark)

> 
>> I am running out of ideas outside of abandoning gen_udp() in favor of a
>> ports driver, and/or not writing the DHCP portion of my code in Erlang.
>>  Neither is particularly attractive, especially given that this seems
>> like a fairly straight forward sockets app and I would think it could be
>> made to work.
> 
> On Linux, you can try binding the socket to an interface [1].

Very cool.  I will take a look at procket.

> klaar added
> support to do this for his quite interesting dhcp server, edhcpd [2].

Cool, I wasnt aware of this project either.  I was using code from
http://code.google.com/p/erlang-dhcp-server as a base, but its fairly
old now.  Perhaps I should be looking at klaar's code instead, anyway.

You mentioned he is doing some interesting things?  Out of curiosity,
can you elaborate on what makes it interesting to you?  I noticed that
he is using gproc and mnesia (vs dets in the project referenced above)
so I assume at the very least this might be some kind of clustered DHCPd
impl?  Anything else interesting going on?

Thanks Michael, I appreciate the feedback and pointers.

Kind Regards,
-Greg

> 
> [1] https://github.com/msantos/procket
> [2] https://github.com/klaar/edhcpd
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 267 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20101116/4a7fe852/attachment.bin>


More information about the erlang-questions mailing list