]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
pass fr_io_track_t to track_create function
authorAlan T. DeKok <aland@freeradius.org>
Fri, 27 Aug 2021 14:40:29 +0000 (10:40 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 27 Aug 2021 15:20:18 +0000 (11:20 -0400)
so that we can free old tracking entries by just talloc_free'ing
them

src/lib/io/base.h
src/lib/io/master.h
src/listen/dhcpv4/proto_dhcpv4_udp.c
src/listen/dhcpv6/proto_dhcpv6_udp.c
src/listen/radius/proto_radius_udp.c
src/listen/tacacs/proto_tacacs_tcp.c
src/listen/vmps/proto_vmps_udp.c

index 8d9d90b1cb959b01a784af457dee449510d522fd..70a5ba8a166a88f26bbbfa237d0af522d145bedc 100644 (file)
@@ -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.
  *
index e41949006c2dd67808ac9011df1cf7a00f875957..ef595c709ee8e592a98c89ab3b92be60ea65911a 100644 (file)
@@ -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
index 6e53ab05a7a60e6ca327db974e2ce8dfb270f22c..134869375d515e6b3cc4f54856f25b80830ccf40 100644 (file)
@@ -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,
index 5c05a41ffc13ab095545286f1463f1f0cab3aeec..17d350fc8173a85cfc7db5c19f8a1b1b6c4343c4 100644 (file)
@@ -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;
 }
 
 
index 6b0877aac3ec62c3d3e7c1013c96dcda5c77b981..9daab494f5d69dde45c3e7435bbc374fdc19a4d7 100644 (file)
@@ -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,
index 03a033a289bbc718bbd60da963761f9da877215d..b41be30e39462e961c3c9b9fe1ee489bfed99b3a 100644 (file)
@@ -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,
index 42f7d7abf99f7a6dba715644cb794e6ee1e4fa2d..6c2bb63fa609cb3be5750f80782112ef477a7db7 100644 (file)
@@ -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,