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 d6668c5 commit 42b7f2b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/modules/proto_dhcp/dhcpd.c
Expand Up @@ -427,12 +427,25 @@ static int dhcp_process(REQUEST *request)
vp->vp_integer = 2; /* BOOTREPLY */

/*
* Prepare the reply packet for sending through dhcp_socket_send()
* Prepare the reply packet for sending through dhcp_socket_send()
*/
request->reply->dst_ipaddr.af = AF_INET;
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, 265, DHCP_MAGIC_VENDOR, TAG_ANY); /* DHCP-Server-IP-Address */
if (!vp) vp = pairfind(request->reply->vps, 54, DHCP_MAGIC_VENDOR, TAG_ANY); /* 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 All @@ -443,7 +456,7 @@ static int dhcp_process(REQUEST *request)
* packet to the client. i.e. the relay may have a
* public IP, but the gateway a private one.
*/
vp = pairfind(request->reply->vps, 272, DHCP_MAGIC_VENDOR, TAG_ANY); /* DHCP-Relay-IP-Address */

if (vp) {
RDEBUG("DHCP: Reply will be unicast to giaddr from original packet");
request->reply->dst_ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
Expand Down

0 comments on commit 42b7f2b

Please sign in to comment.