Skip to content

Commit

Permalink
Set src IP on more situations.
Browse files Browse the repository at this point in the history
If the admin set "ipaddr = *", and no "src_ipaddr = ...", then
we used to send packets from 0.0.0.0.  That's wrong.

We now look for server identifier or server IP address.
If one of those is found, we use that as the source IP
  • Loading branch information
alandekok committed Mar 13, 2014
1 parent ca12936 commit f783c14
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/dhcpd.c
Expand Up @@ -408,6 +408,19 @@ static int dhcp_process(REQUEST *request)
request->reply->src_ipaddr.af = AF_INET;
request->reply->src_ipaddr.ipaddr.ip4addr.s_addr = sock->src_ipaddr.ipaddr.ip4addr.s_addr;

/*
* They didn't set a proper src_ipaddr, but we want to
* send the packet with a source IP. If there's a server
* identifier, use it.
*/
if (request->reply->src_ipaddr.ipaddr.ip4addr.s_addr == INADDR_ANY) {
vp = pairfind(request->reply->vps, DHCP2ATTR(265)); /* DHCP-Server-IP-Address */
if (!vp) vp = pairfind(request->reply->vps, DHCP2ATTR(54)); /* DHCP-DHCP-Server-Identifier */
if (vp) {
request->reply->src_ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
}
}

request->reply->dst_port = request->packet->src_port;
request->reply->src_port = request->packet->dst_port;

Expand Down

0 comments on commit f783c14

Please sign in to comment.