Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discovering DHCP servers using multicast (224.0.0.12) in GNU/Linux/C

This question might stem from a fundamental misunderstanding of IP multicast, so please correct me if I'm off base.

I'm trying to write C code to find the IP address of all the DHCP servers on the network. The use case is this:

  1. Client broadcasts DHCP discover.
  2. My proprietary relay agent picks up the packet, adds some essential information, and forwards it UNICAST to the DHCP server at a known IP address.

The problem I'm having is telling the relay agent where the DHCP server(s) is(are). I found that multicast address 224.0.0.12 is reserved by IANA for DHCP servers, so I figured I'd just configure the servers to listen for that multicast traffic. But whenever I configure a linux socket option to IP_ADD_MEMBERSHIP to 224.0.0.12, it uses IGMP, which is an entirely separate protocol which I don't want to have to implement.

Am I just misunderstanding how multicast works? Shouldn't I be able to send a ping from the relay agent to 224.0.0.12 and have it return a ping response from all DHCP servers?


Additional Info:

  • the interfaces on all the boxes do have MULTICAST listed when I do an ifconfig
  • I have added the multicast route using ip route add 224.0.0.0/4 dev eth0 on all boxes
like image 557
David Dombrowsky Avatar asked Nov 05 '22 00:11

David Dombrowsky


1 Answers

Perhaps you should do what clients do - broadcast (not multicast!) on the target network with a DHCPDISCOVER packet? I have a couple of running, working DHCP servers and none of them are listening on the 224 network.

You'll probably also want to either request your existing address, or send along a DHCPRELEASE for any offers you get back, so as not to tie up addresses in fake reservations on the servers.

like image 71
brepro Avatar answered Nov 07 '22 21:11

brepro