]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
More dhcpclient fixes
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 7 Jan 2021 20:57:40 +0000 (20:57 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 7 Jan 2021 21:21:44 +0000 (21:21 +0000)
src/modules/proto_dhcpv4/dhcpclient.c
src/protocols/dhcpv4/dhcpv4.h
src/protocols/dhcpv4/packet.c

index 4879604fc97b5532b0307066bca1651af687f939..34dc4650999ed975af0eea6c97511d2e6d78bbb7 100644 (file)
@@ -253,12 +253,15 @@ static fr_radius_packet_t *fr_dhcpv4_recv_raw_loop(int lsockfd,
        fr_time_delta_t our_timeout;
        fr_radius_packet_t      *found = NULL;
        fr_radius_packet_t      *reply = NULL;
-       int             nb_reply = 0;
-       int             nb_offer = 0;
-       dc_offer_t      *offer_list = NULL;
-       fd_set          read_fd;
-       int             retval;
-       fr_cursor_t     cursor;
+       fr_pair_list_t          reply_vps;
+       int                     nb_reply = 0;
+       int                     nb_offer = 0;
+       dc_offer_t              *offer_list = NULL;
+       fd_set                  read_fd;
+       int                     retval;
+       fr_cursor_t             cursor;
+
+       fr_pair_list_init(&reply_vps);
 
        our_timeout = timeout;
 
@@ -301,7 +304,7 @@ static fr_radius_packet_t *fr_dhcpv4_recv_raw_loop(int lsockfd,
 
                        if (fr_debug_lvl > 1) fr_dhcpv4_print_hex(stdout, reply->data, reply->data_len);
 
-                       fr_cursor_init(&cursor, &reply->vps);
+                       fr_cursor_init(&cursor, &reply_vps);
                        if (fr_dhcpv4_decode(reply, reply->data, reply->data_len, &cursor, &reply->code) < 0) {
                                ERROR("Failed decoding reply");
                                return NULL;
@@ -310,9 +313,9 @@ static fr_radius_packet_t *fr_dhcpv4_recv_raw_loop(int lsockfd,
                        if (!found) found = reply;
 
                        if (reply->code == FR_DHCP_OFFER) {
-                               fr_pair_t *vp1 = fr_pair_find_by_da(&reply->vps,
+                               fr_pair_t *vp1 = fr_pair_find_by_da(&reply_vps,
                                                                     attr_dhcp_dhcp_server_identifier);
-                               fr_pair_t *vp2 = fr_pair_find_by_da(&reply->vps,
+                               fr_pair_t *vp2 = fr_pair_find_by_da(&reply_vps,
                                                                     attr_dhcp_your_ip_address);
 
                                if (vp1 && vp2) {
@@ -483,7 +486,7 @@ static int send_with_pcap(fr_radius_packet_t **reply, fr_radius_packet_t *packet
 }
 #endif /* HAVE_LIBPCAP */
 
-static void dhcp_packet_debug(fr_radius_packet_t *packet, bool received)
+static void dhcp_packet_debug(fr_radius_packet_t *packet, fr_pair_list_t *list, bool received)
 {
        fr_cursor_t     cursor;
        char            buffer[2048];
@@ -530,7 +533,7 @@ static void dhcp_packet_debug(fr_radius_packet_t *packet, bool received)
 #endif
               packet->data_len);
 
-       for (vp = fr_cursor_init(&cursor, &packet->vps);
+       for (vp = fr_cursor_init(&cursor, list);
             vp;
             vp = fr_cursor_next(&cursor)) {
                VP_VERIFY(vp);
@@ -726,7 +729,7 @@ int main(int argc, char **argv)
        /*
         *      Encode the packet
         */
-       if (fr_dhcpv4_packet_encode(packet) < 0) {
+       if (fr_dhcpv4_packet_encode(packet, &packet_vps) < 0) {
                ERROR("Failed encoding packet");
                fr_exit(EXIT_FAILURE);
        }
@@ -741,7 +744,7 @@ int main(int argc, char **argv)
                if (fr_debug_lvl > 1) fr_dhcpv4_print_hex(stdout, packet->data, packet->data_len);
 
                fr_dhcpv4_decode(packet, packet->data, packet->data_len, &cursor, &packet->code);
-               dhcp_packet_debug(packet, false);
+               dhcp_packet_debug(packet, &packet_vps, false);
        }
 
 #ifdef HAVE_LIBPCAP
@@ -760,7 +763,7 @@ int main(int argc, char **argv)
                        ERROR("Failed decoding packet");
                        ret = -1;
                }
-               dhcp_packet_debug(reply, true);
+               dhcp_packet_debug(reply, &reply_vps, true);
        }
 
        fr_dhcpv4_global_free();
index 776f17e89efb2be7e42ee4292dea1a2dc45d251a..7dda7e73edbf40e6d90cde7ecc4aa1bc7c81f18b 100644 (file)
@@ -171,7 +171,7 @@ uint8_t const       *fr_dhcpv4_packet_get_option(dhcp_packet_t const *packet, size_t p
 
 int            fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_cursor_t *cursor, unsigned int *code);
 
-int            fr_dhcpv4_packet_encode(fr_radius_packet_t *packet);
+int            fr_dhcpv4_packet_encode(fr_radius_packet_t *packet, fr_pair_list_t *list);
 
 #ifdef HAVE_LINUX_IF_PACKET_H
 /*
index 38ff870d2be3c34be6081497fc85901c7f115616..b01a2c25dcf3487bf9fd4cafad8904f81f65bff2 100644 (file)
@@ -391,7 +391,7 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_c
        return 0;
 }
 
-int fr_dhcpv4_packet_encode(fr_radius_packet_t *packet)
+int fr_dhcpv4_packet_encode(fr_radius_packet_t *packet, fr_pair_list_t *list)
 {
        ssize_t         len;
        fr_pair_t       *vp;
@@ -411,7 +411,7 @@ int fr_dhcpv4_packet_encode(fr_radius_packet_t *packet)
                packet->id = fr_rand();
        }
 
-       len = fr_dhcpv4_encode(packet->data, packet->data_len, NULL, packet->code, packet->id, &packet->vps);
+       len = fr_dhcpv4_encode(packet->data, packet->data_len, NULL, packet->code, packet->id, list);
        if (len < 0) return -1;
 
        packet->data_len = len;