From c4f2aac22b73ee75a07602e3b5eefeba63055987 Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Wed, 27 Jan 2021 18:56:40 +0000 Subject: [PATCH] DHCPv4: Still need to copy pairs to a local list so we can search for options --- src/protocols/dhcpv4/packet.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/protocols/dhcpv4/packet.c b/src/protocols/dhcpv4/packet.c index f3ec4bd36a..462339c793 100644 --- a/src/protocols/dhcpv4/packet.c +++ b/src/protocols/dhcpv4/packet.c @@ -112,8 +112,11 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d fr_pair_t *vp; fr_pair_t *maxms, *mtu, *netaddr; fr_value_box_t box; + fr_dcursor_t our_cursor; fr_pair_list_init(&head); + fr_dcursor_init(&our_cursor, &head); + if (data[1] > 1) { fr_strerror_printf("Packet is not Ethernet: %u", data[1]); @@ -131,8 +134,8 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d fr_strerror_const_push("Cannot decode packet due to internal error"); error: talloc_free(vp); - fr_dcursor_head(cursor); - fr_dcursor_free_list(cursor); + fr_dcursor_head(&our_cursor); + fr_dcursor_free_list(&our_cursor); return -1; } @@ -190,14 +193,14 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d if (!vp) continue; - fr_dcursor_append(cursor, vp); + fr_dcursor_append(&our_cursor, vp); } /* * Loop over the options. */ - fr_dcursor_head(cursor); + fr_dcursor_head(&our_cursor); /* * Nothing uses tail after this call, if it does in the future @@ -216,10 +219,10 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d while (p < end) { if (p[0] == 0) break; /* padding */ - len = fr_dhcpv4_decode_option(ctx, cursor, dict_dhcpv4, p, (end - p), NULL); + len = fr_dhcpv4_decode_option(ctx, &our_cursor, dict_dhcpv4, p, (end - p), NULL); if (len <= 0) { - fr_dcursor_head(cursor); - fr_dcursor_free_list(cursor); + fr_dcursor_head(&our_cursor); + fr_dcursor_free_list(&our_cursor); return len; } p += len; @@ -248,11 +251,11 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d while (p < end) { if (p[0] == 0) break; /* padding */ - len = fr_dhcpv4_decode_option(ctx, cursor, dict_dhcpv4, + len = fr_dhcpv4_decode_option(ctx, &our_cursor, dict_dhcpv4, p, end - p, NULL); if (len <= 0) { - fr_dcursor_head(cursor); - fr_dcursor_free_list(cursor); + fr_dcursor_head(&our_cursor); + fr_dcursor_free_list(&our_cursor); return len; } p += len; @@ -271,8 +274,8 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d len = fr_dhcpv4_decode_option(ctx, cursor, dict_dhcpv4, p, end - p, NULL); if (len <= 0) { - fr_dcursor_head(cursor); - fr_dcursor_free_list(cursor); + fr_dcursor_head(&our_cursor); + fr_dcursor_free_list(&our_cursor); return len; } p += len; @@ -360,7 +363,7 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d fr_value_box_cast(vp, &vp->data, vp->da->type, vp->da, &box); } - fr_dcursor_append(cursor, vp); + fr_dcursor_append(&our_cursor, vp); /* * Client can request a LARGER size, but not a smaller @@ -389,6 +392,7 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d * FIXME: Nuke attributes that aren't used in the normal * header for discover/requests. */ + fr_dcursor_merge(cursor, &our_cursor); return 0; } -- 2.47.2