]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Allow giaddr to be updated when relaying
authorAlan T. DeKok <aland@freeradius.org>
Tue, 28 Jun 2011 13:38:33 +0000 (15:38 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 28 Jun 2011 15:39:41 +0000 (17:39 +0200)
src/main/dhcpd.c

index cca2cff646472bc7a8d273b32cdf72a65b352e72..f5ddf76e83d54f44ecd81c1cc8d50b09fb789675 100644 (file)
@@ -66,8 +66,6 @@ static int dhcp_process(REQUEST *request)
                VALUE_PAIR *giaddr;
                RADIUS_PACKET relayed;
                
-               request->reply->code = 0; /* don't reply to the client */
-
                /*
                 *      Find the original giaddr.
                 *      FIXME: Maybe look in the original packet?
@@ -80,12 +78,6 @@ static int dhcp_process(REQUEST *request)
                                RDEBUG("DHCP: Received packet with giaddr = 0 and containing relay option: Discarding packet");
                                return 1;
                        }
-
-                       /*
-                        *      FIXME: Add cache by XID.
-                        */
-                       RDEBUG("DHCP: Cannot yet relay packets with giaddr = 0");
-                       return 1;
                }
 
                if (request->packet->data[3] > 10) {
@@ -111,7 +103,19 @@ static int dhcp_process(REQUEST *request)
                relayed.vps = NULL;
 
                /*
-                *      The only field that changes is the number of hops
+                *      If we were told to re-write the giaddr, do so.
+                */
+               if (giaddr) {
+                       memcpy(relayed.data + 24, &giaddr->vp_ipaddr, 4);
+               }
+
+               /*
+                *      The only field that changes is the number of hops.
+                *
+                *      FIXME: Allow for re-writing of the entire
+                *      packet contents!  This should be as simple as
+                *      re-encoding the packet from
+                *      request->packet->vps!
                 */
                relayed.data[3]++; /* number of hops */
                
@@ -122,6 +126,9 @@ static int dhcp_process(REQUEST *request)
                 */
                fr_dhcp_send(&relayed);
                free(relayed.data);
+
+               request->reply->code = 0; /* don't reply to the client */
+
                return 1;
        }
 
@@ -292,9 +299,6 @@ static int dhcp_socket_send(rad_listen_t *listener, REQUEST *request)
        sock = listener->data;
        if (sock->suppress_responses) return 0;
 
-       /*
-        *      Don't send anything
-        */
        return fr_dhcp_send(request->reply);
 }