From: Alan T. DeKok Date: Fri, 27 Aug 2021 14:40:29 +0000 (-0400) Subject: pass fr_io_track_t to track_create function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5c018026f19b094b4e03f0e0b21ce18f48baf2e;p=thirdparty%2Ffreeradius-server.git pass fr_io_track_t to track_create function so that we can free old tracking entries by just talloc_free'ing them --- diff --git a/src/lib/io/base.h b/src/lib/io/base.h index 8d9d90b1cb9..70a5ba8a166 100644 --- a/src/lib/io/base.h +++ b/src/lib/io/base.h @@ -257,6 +257,8 @@ typedef int (*fr_io_data_inject_t)(fr_listen_t *li,uint8_t *buffer, size_t buffe */ typedef void (*fr_io_data_vnode_t)(fr_listen_t *li, uint32_t fflags); +typedef struct fr_io_track_s fr_io_track_t; /* in master.h */ + /** Convert a raw packet to a tracking structure * * For passing to fr_io_track_cmp_t @@ -264,14 +266,14 @@ typedef void (*fr_io_data_vnode_t)(fr_listen_t *li, uint32_t fflags); * @param[in] instance the context for this function * @param[in] thread_instance the thread instance for this function * @param[in] client the client associated with this packet - * @param[in] ctx The parent talloc ctx + * @param[in] track The parent tracking structure * @param[in] packet The packet being summarized * @param[in] packet_len Length of the packet being summarized * @return * - NULL on error * - !NULL the packet tracking structure */ -typedef void *(*fr_io_track_create_t)(void const *instance, void *thread_instance, RADCLIENT *client, TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_len); +typedef void *(*fr_io_track_create_t)(void const *instance, void *thread_instance, RADCLIENT *client, fr_io_track_t *track, uint8_t const *packet, size_t packet_len); /** Compare two tracking structures for storing in a duplicate detection tree. * diff --git a/src/lib/io/master.h b/src/lib/io/master.h index e41949006c2..ef595c709ee 100644 --- a/src/lib/io/master.h +++ b/src/lib/io/master.h @@ -37,7 +37,7 @@ extern "C" { typedef struct fr_io_client_s fr_io_client_t; -typedef struct { +typedef struct fr_io_track_s { fr_rb_node_t node; //!< rbtree node in the tracking tree. fr_event_timer_t const *ev; //!< when we clean up this tracking entry fr_time_t timestamp; //!< when this packet was received diff --git a/src/listen/dhcpv4/proto_dhcpv4_udp.c b/src/listen/dhcpv4/proto_dhcpv4_udp.c index 6e53ab05a7a..134869375d5 100644 --- a/src/listen/dhcpv4/proto_dhcpv4_udp.c +++ b/src/listen/dhcpv4/proto_dhcpv4_udp.c @@ -581,9 +581,9 @@ static int mod_fd_set(fr_listen_t *li, int fd) static void *mod_track_create(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client, - TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_len) + fr_io_track_t *track, uint8_t const *packet, size_t packet_len) { - proto_dhcpv4_track_t *track; + proto_dhcpv4_track_t *t; dhcp_packet_t const *dhcp = (dhcp_packet_t const *) packet; uint8_t const *option; @@ -593,12 +593,12 @@ static void *mod_track_create(UNUSED void const *instance, UNUSED void *thread_i return NULL; } - track = talloc_zero(ctx, proto_dhcpv4_track_t); - if (!track) return NULL; + t = talloc_zero(track, proto_dhcpv4_track_t); + if (!t) return NULL; - memcpy(&track->xid, &dhcp->xid, sizeof(track->xid)); + memcpy(&t->xid, &dhcp->xid, sizeof(t->xid)); - track->message_type = option[2]; + t->message_type = option[2]; /* * Track most packets by chaddr. For lease queries, that @@ -608,15 +608,15 @@ static void *mod_track_create(UNUSED void const *instance, UNUSED void *thread_i * exist according to RFC 4388 Section 6.3 */ if (option[2] != FR_DHCP_LEASE_QUERY) { - if (dhcp->hlen == 6) memcpy(&track->chaddr, &dhcp->chaddr, 6); + if (dhcp->hlen == 6) memcpy(&t->chaddr, &dhcp->chaddr, 6); } - track->broadcast = ((dhcp->flags & FR_FLAGS_VALUE_BROADCAST) != 0); - track->hops = dhcp->hops; - memcpy(&track->ciaddr, &dhcp->ciaddr, sizeof(track->ciaddr)); - memcpy(&track->giaddr, &dhcp->giaddr, sizeof(track->giaddr)); + t->broadcast = ((dhcp->flags & FR_FLAGS_VALUE_BROADCAST) != 0); + t->hops = dhcp->hops; + memcpy(&t->ciaddr, &dhcp->ciaddr, sizeof(t->ciaddr)); + memcpy(&t->giaddr, &dhcp->giaddr, sizeof(t->giaddr)); - return track; + return t; } static int mod_track_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client, diff --git a/src/listen/dhcpv6/proto_dhcpv6_udp.c b/src/listen/dhcpv6/proto_dhcpv6_udp.c index 5c05a41ffc1..17d350fc817 100644 --- a/src/listen/dhcpv6/proto_dhcpv6_udp.c +++ b/src/listen/dhcpv6/proto_dhcpv6_udp.c @@ -380,11 +380,11 @@ static int mod_fd_set(fr_listen_t *li, int fd) } static void *mod_track_create(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client, - TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_len) + fr_io_track_t *track, uint8_t const *packet, size_t packet_len) { - proto_dhcpv6_track_t *track; + proto_dhcpv6_track_t *t; uint8_t const *option; - size_t track_size = sizeof(*track); + size_t t_size = sizeof(*t); size_t option_len; /* @@ -417,17 +417,17 @@ static void *mod_track_create(UNUSED void const *instance, UNUSED void *thread_i option_len = (option[2] << 8) | option[3]; - track = (proto_dhcpv6_track_t *) talloc_zero_array(ctx, uint8_t, track_size + option_len); - if (!track) return NULL; + t = (proto_dhcpv6_track_t *) talloc_zero_array(track, uint8_t, t_size + option_len); + if (!t) return NULL; - talloc_set_name_const(track, "proto_dhcpv6_track_t"); + talloc_set_name_const(t, "proto_dhcpv6_track_t"); - memcpy(&track->header, packet, 4); /* packet code + 24-bit transaction ID */ + memcpy(&t->header, packet, 4); /* packet code + 24-bit transaction ID */ - memcpy(&track->client_id[0], option + 4, option_len); - track->client_id_len = option_len; + memcpy(&t->client_id[0], option + 4, option_len); + t->client_id_len = option_len; - return track; + return t; } diff --git a/src/listen/radius/proto_radius_udp.c b/src/listen/radius/proto_radius_udp.c index 6b0877aac3e..9daab494f5d 100644 --- a/src/listen/radius/proto_radius_udp.c +++ b/src/listen/radius/proto_radius_udp.c @@ -379,10 +379,10 @@ static int mod_fd_set(fr_listen_t *li, int fd) return 0; } -static void *mod_track_create(void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client, - TALLOC_CTX *ctx, uint8_t const *packet, UNUSED size_t packet_len) +static void *mod_track_create(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client, + fr_io_track_t *track, uint8_t const *packet, UNUSED size_t packet_len) { - return talloc_memdup(ctx, packet, RADIUS_HEADER_LENGTH); + return talloc_memdup(track, packet, RADIUS_HEADER_LENGTH); } static int mod_track_compare(void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client, diff --git a/src/listen/tacacs/proto_tacacs_tcp.c b/src/listen/tacacs/proto_tacacs_tcp.c index 03a033a289b..b41be30e394 100644 --- a/src/listen/tacacs/proto_tacacs_tcp.c +++ b/src/listen/tacacs/proto_tacacs_tcp.c @@ -319,43 +319,42 @@ static int mod_fd_set(fr_listen_t *li, int fd) } static void *mod_track_create(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client, - TALLOC_CTX *ctx, uint8_t const *buffer, UNUSED size_t buffer_len) + fr_io_track_t *track, uint8_t const *buffer, UNUSED size_t buffer_len) { fr_tacacs_packet_t const *pkt = (fr_tacacs_packet_t const *) buffer; - proto_tacacs_track_t *track; + proto_tacacs_track_t *t; - track = talloc_zero(ctx, proto_tacacs_track_t); + t = talloc_zero(track, proto_tacacs_track_t); + if (!t) return NULL; - if (!track) return NULL; - - talloc_set_name_const(track, "proto_tacacs_track_t"); + talloc_set_name_const(t, "proto_tacacs_track_t"); switch (pkt->hdr.type) { case FR_TAC_PLUS_AUTHEN: if (packet_is_authen_start_request(pkt)) { - track->type = FR_PACKET_TYPE_VALUE_AUTHENTICATION_START; + t->type = FR_PACKET_TYPE_VALUE_AUTHENTICATION_START; } else { - track->type = FR_PACKET_TYPE_VALUE_AUTHENTICATION_CONTINUE; + t->type = FR_PACKET_TYPE_VALUE_AUTHENTICATION_CONTINUE; } break; case FR_TAC_PLUS_AUTHOR: - track->type = FR_PACKET_TYPE_VALUE_AUTHORIZATION_REQUEST; + t->type = FR_PACKET_TYPE_VALUE_AUTHORIZATION_REQUEST; break; case FR_TAC_PLUS_ACCT: - track->type = FR_PACKET_TYPE_VALUE_ACCOUNTING_REQUEST; + t->type = FR_PACKET_TYPE_VALUE_ACCOUNTING_REQUEST; break; default: - talloc_free(track); + talloc_free(t); fr_assert(0); return NULL; } - track->session_id = pkt->hdr.session_id; + t->session_id = pkt->hdr.session_id; - return track; + return t; } static int mod_track_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client, diff --git a/src/listen/vmps/proto_vmps_udp.c b/src/listen/vmps/proto_vmps_udp.c index 42f7d7abf99..6c2bb63fa60 100644 --- a/src/listen/vmps/proto_vmps_udp.c +++ b/src/listen/vmps/proto_vmps_udp.c @@ -349,26 +349,26 @@ static int mod_fd_set(fr_listen_t *li, int fd) } static void *mod_track_create(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client, - TALLOC_CTX *ctx, uint8_t const *buffer, size_t buffer_len) + fr_io_track_t *track, uint8_t const *buffer, size_t buffer_len) { - proto_vmps_track_t *track; + proto_vmps_track_t *t; if (buffer_len < 4) { ERROR("VMPS packet is too small. (%zu < 4)", buffer_len); return NULL; } - track = talloc_zero(ctx, proto_vmps_track_t); + t = talloc_zero(track, proto_vmps_track_t); - if (!track) return NULL; + if (!t) return NULL; - talloc_set_name_const(track, "proto_vmps_track_t"); + talloc_set_name_const(t, "proto_vmps_track_t"); - memcpy(&track->transaction_id, buffer, sizeof(track->transaction_id)); + memcpy(&t->transaction_id, buffer, sizeof(t->transaction_id)); - track->opcode = buffer[1]; + t->opcode = buffer[1]; - return track; + return t; } static int mod_track_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client,