]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move fr_dhcpv6_decode() to use fr_cursor_t
authorNick Porter <nick@portercomputing.co.uk>
Tue, 20 Oct 2020 14:59:33 +0000 (15:59 +0100)
committerAlan DeKok <aland@freeradius.org>
Tue, 20 Oct 2020 17:29:15 +0000 (13:29 -0400)
src/modules/proto_dhcpv6/proto_dhcpv6.c
src/protocols/dhcpv6/base.c
src/protocols/dhcpv6/decode.c
src/protocols/dhcpv6/dhcpv6.h

index 1589430db3d29ac4f7a30d23877484a608625c04..8960a05abab22b891be6384636f88a03ca049654 100644 (file)
@@ -254,6 +254,7 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat
        fr_io_address_t const *address = track->address;
        RADCLIENT const *client;
        RADIUS_PACKET *packet = request->packet;
+       fr_cursor_t cursor;
 
        /*
         *      Set the request dictionary so that we can do
@@ -281,7 +282,8 @@ static int mod_decode(void const *instance, REQUEST *request, uint8_t *const dat
         *      That MUST be set and checked in the underlying
         *      transport, via a call to fr_dhcpv6_ok().
         */
-       if (fr_dhcpv6_decode(packet, packet->data, packet->data_len, &packet->vps) < 0) {
+       fr_cursor_init(&cursor, &packet->vps);
+       if (fr_dhcpv6_decode(packet, packet->data, packet->data_len, &cursor) < 0) {
                RPEDEBUG("Failed decoding packet");
                return -1;
        }
index a6195a09540c4c3860474e5e1302a224c62670ca..6944f2fb0afefdb174b2771de67ccb0c96f8ea4e 100644 (file)
@@ -594,16 +594,13 @@ bool fr_dhcpv6_verify(uint8_t const *packet, size_t packet_len, fr_dhcpv6_decode
 /** Decode a DHCPv6 packet
  *
  */
-ssize_t        fr_dhcpv6_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_len, VALUE_PAIR **vps)
+ssize_t        fr_dhcpv6_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_len, fr_cursor_t *cursor)
 {
        ssize_t                 slen;
-       fr_cursor_t             cursor;
        uint8_t const           *p, *end;
        fr_dhcpv6_decode_ctx_t  packet_ctx;
        VALUE_PAIR              *vp;
 
-       fr_cursor_init(&cursor, vps);
-
        /*
         *      Get the packet type.
         */
@@ -612,7 +609,7 @@ ssize_t     fr_dhcpv6_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_l
 
        vp->vp_uint32 = packet[0];
        vp->type = VT_DATA;
-       fr_cursor_append(&cursor, vp);
+       fr_cursor_append(cursor, vp);
 
        if ((packet[0] == FR_DHCPV6_RELAY_FORWARD) ||
            (packet[0] == FR_DHCPV6_RELAY_REPLY)) {
@@ -631,14 +628,14 @@ ssize_t   fr_dhcpv6_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_l
                if (fr_value_box_from_network(vp, &vp->data, vp->da->type, NULL, packet + 1, 1, true) < 0) {
                        goto fail;
                }
-               fr_cursor_append(&cursor, vp);
+               fr_cursor_append(cursor, vp);
 
                vp = fr_pair_afrom_da(ctx, attr_relay_link_address);
                if (!vp) goto fail;
                if (fr_value_box_from_network(vp, &vp->data, vp->da->type, NULL, packet + 2, 16, true) < 0) {
                        goto fail;
                }
-               fr_cursor_append(&cursor, vp);
+               fr_cursor_append(cursor, vp);
 
                vp = fr_pair_afrom_da(ctx, attr_relay_peer_address);
                if (!vp) goto fail;
@@ -646,7 +643,7 @@ ssize_t     fr_dhcpv6_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_l
                        goto fail;
                }
 
-               fr_cursor_append(&cursor, vp);
+               fr_cursor_append(cursor, vp);
 
                p = packet + 2 + 32;
                goto decode_options;
@@ -658,7 +655,8 @@ ssize_t     fr_dhcpv6_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_l
        vp = fr_pair_afrom_da(ctx, attr_transaction_id);
        if (!vp) {
        fail:
-               fr_pair_list_free(vps);
+               fr_cursor_head(cursor);
+               fr_cursor_free_list(cursor);
                return -1;
        }
 
@@ -668,7 +666,7 @@ ssize_t     fr_dhcpv6_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_l
        (void) fr_pair_value_memdup(vp, packet + 1, 3, false);
 
        vp->type = VT_DATA;
-       fr_cursor_append(&cursor, vp);
+       fr_cursor_append(cursor, vp);
 
 
        p = packet + 4;
@@ -682,9 +680,10 @@ decode_options:
         *      he doesn't, all hell breaks loose.
         */
        while (p < end) {
-               slen = fr_dhcpv6_decode_option(ctx, &cursor, dict_dhcpv6, p, (end - p), &packet_ctx);
+               slen = fr_dhcpv6_decode_option(ctx, cursor, dict_dhcpv6, p, (end - p), &packet_ctx);
                if (slen < 0) {
-                       fr_pair_list_free(vps);
+                       fr_cursor_head(cursor);
+                       fr_cursor_free_list(cursor);
                        talloc_free(packet_ctx.tmp_ctx);
                        return slen;
                }
@@ -694,7 +693,8 @@ decode_options:
                 *      all kinds of bad things happen.
                 */
                 if (!fr_cond_assert(slen <= (end - p))) {
-                        fr_pair_list_free(vps);
+                        fr_cursor_head(cursor);
+                        fr_cursor_free_list(cursor);
                         talloc_free(packet_ctx.tmp_ctx);
                         return -1;
                 }
index 00bc76b09ac60fdfcc6c01c8edf104e4bf54ee1d..5aca2d6bb82858c2f6a92432b5de8ba47493a7be 100644 (file)
@@ -539,11 +539,13 @@ static ssize_t decode_option(TALLOC_CTX *ctx, fr_cursor_t *cursor, fr_dict_t con
         */
        if (da == attr_relay_message) {
                VALUE_PAIR *vp;
+               fr_cursor_t cursor_group;
 
                vp = fr_pair_afrom_da(ctx, attr_relay_message);
                if (!vp) return PAIR_DECODE_FATAL_ERROR;
 
-               rcode = fr_dhcpv6_decode(ctx, data + 4, len, &vp->vp_group);
+               fr_cursor_init(&cursor_group, &vp->vp_group);
+               rcode = fr_dhcpv6_decode(ctx, data + 4, len, &cursor_group);
                if (rcode < 0) {
                        talloc_free(vp);
                        return rcode;
@@ -625,13 +627,15 @@ static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
 static ssize_t fr_dhcpv6_decode_proto(TALLOC_CTX *ctx, VALUE_PAIR **vps, uint8_t const *data, size_t data_len, UNUSED void *proto_ctx)
 {
        size_t packet_len = data_len;
+       fr_cursor_t cursor;
 //     fr_dhcpv6_decode_ctx_t  *test_ctx = talloc_get_type_abort(proto_ctx, fr_dhcpv6_decode_ctx_t);
 
        if (!fr_dhcpv6_ok(data, packet_len, 200)) return -1;
 
        *vps = NULL;
+       fr_cursor_init(&cursor, vps);
 
-       return fr_dhcpv6_decode(ctx, data, packet_len, vps);
+       return fr_dhcpv6_decode(ctx, data, packet_len, &cursor);
 }
 
 
index afbaa7a149b8ba9fb7deff02efde912f69e8efc5..c947498c1ddc10158e353abdc5bf843e448ee054 100644 (file)
@@ -140,7 +140,7 @@ ssize_t             fr_dhcpv6_encode(uint8_t *packet, size_t packet_len, uint8_t const *ori
                                 int msg_type, VALUE_PAIR *vps);
 
 ssize_t                fr_dhcpv6_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_len,
-                                VALUE_PAIR **vps);
+                                fr_cursor_t *cursor);
 
 int            fr_dhcpv6_reply_initialize(TALLOC_CTX *ctx, VALUE_PAIR **reply, uint8_t const *packet, size_t packet_len);