From: Alan T. DeKok Date: Sun, 20 Nov 2016 03:20:01 +0000 (-0500) Subject: added replies to RADIUS tracking table X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2648e2c00e50f07e4e07a727040fb55b57836b8e;p=thirdparty%2Ffreeradius-server.git added replies to RADIUS tracking table --- diff --git a/src/util/channel.h b/src/util/channel.h index 386ec160475..736cc7b9b76 100644 --- a/src/util/channel.h +++ b/src/util/channel.h @@ -78,13 +78,14 @@ typedef struct fr_channel_data_t { union { struct { - uint64_t *start_time; //!< time original request started (network -> worker) + fr_time_t *start_time; //!< time original request started (network -> worker) uint32_t priority; //!< priority of this packet. 0=high, 65535=low. } request; struct { fr_time_t cpu_time; //!< total CPU time, including predicted work, (only worker -> network) fr_time_t processing_time; //!< actual processing time for this packet (only worker -> network) + fr_time_t request_time; //!< timestamp of the request packet } reply; }; diff --git a/src/util/track.c b/src/util/track.c index 2f1e835deff..39db692c1c3 100644 --- a/src/util/track.c +++ b/src/util/track.c @@ -22,6 +22,7 @@ RCSID("$Id$") #include +#include /* * RADIUS-specific tracking table. @@ -73,19 +74,28 @@ int fr_radius_tracking_entry_delete(fr_tracking_t *ft, uint8_t id) #ifndef NDEBUG (void) talloc_get_type_abort(ft, fr_tracking_t); #endif + entry = &ft->packet[id]; if (entry->timestamp == 0) return -1; entry->timestamp = 0; ft->num_entries--; + /* + * Mark the reply (if any) as done. + */ + if (entry->reply) { + fr_message_done(&entry->reply->m); + entry->reply = NULL; + } + return 0; } /** Insert a (possibly new) packet and a timestamp * * @param[in] ft the tracking table - * @param[in] packet the RADIUS packet to insert + * @param[in] packet the packet to insert * @param[in] timestamp when this packet was received * @param[out] p_entry pointer to newly inserted entry. * @return @@ -140,3 +150,35 @@ fr_tracking_status_t fr_radius_tracking_entry_insert(fr_tracking_t *ft, uint8_t return FR_TRACKING_DIFFERENT; } + +/** Insert a (possibly new) packet and a timestamp + * + * @param[in] ft the tracking table + * @param[in] id the ID of the entry which this reply is for + * @param[in] cd the reply message + * @return + * - <0 on error + * - 0 on success + */ +int fr_radius_tracking_entry_reply(fr_tracking_t *ft, uint8_t id, + fr_channel_data_t *cd) +{ + fr_tracking_entry_t *entry; + +#ifndef NDEBUG + (void) talloc_get_type_abort(ft, fr_tracking_t); +#endif + + entry = &ft->packet[id]; + + if (entry->timestamp != cd->reply.request_time) { + fr_message_done(&cd->m); + return 0; + } + + rad_assert(entry->reply == NULL); + + entry->reply = cd; + + return 0; +} diff --git a/src/util/track.h b/src/util/track.h index b75032ec29a..9f39a616a9b 100644 --- a/src/util/track.h +++ b/src/util/track.h @@ -25,8 +25,7 @@ */ RCSIDH(track_h, "$Id$") -#include -#include +#include #ifdef __cplusplus extern "C" { @@ -39,8 +38,9 @@ typedef struct fr_tracking_t fr_tracking_t; * information required to track RADIUS packets. */ typedef struct fr_tracking_entry_t { - fr_time_t timestamp; //!< when received - uint8_t data[18]; //!< 2 byte length + authentication vector + fr_time_t timestamp; //!< when received + fr_channel_data_t *reply; //!< the reply (if any) + uint8_t data[18]; //!< 2 byte length + authentication vector } fr_tracking_entry_t; /** @@ -57,6 +57,8 @@ fr_tracking_t *fr_radius_tracking_create(TALLOC_CTX *ctx); int fr_radius_tracking_entry_delete(fr_tracking_t *ft, uint8_t id) CC_HINT(nonnull); fr_tracking_status_t fr_radius_tracking_entry_insert(fr_tracking_t *ft, uint8_t *packet, fr_time_t timestamp, fr_tracking_entry_t **p_entry) CC_HINT(nonnull); +int fr_radius_tracking_entry_reply(fr_tracking_t *ft, uint8_t id, + fr_channel_data_t *cd) CC_HINT(nonnull); #ifdef __cplusplus }