]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
added replies to RADIUS tracking table
authorAlan T. DeKok <aland@freeradius.org>
Sun, 20 Nov 2016 03:20:01 +0000 (22:20 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 20 Nov 2016 14:56:21 +0000 (09:56 -0500)
src/util/channel.h
src/util/track.c
src/util/track.h

index 386ec160475bada7a2d88a9bcd0570303c8c711b..736cc7b9b769c87b296168c517f90ac1cd47dadb 100644 (file)
@@ -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;
        };
 
index 2f1e835deff2181ae53add28011d25585d596287..39db692c1c364cd8cf72969dc2a4a4a2d0e1fc11 100644 (file)
@@ -22,6 +22,7 @@
 RCSID("$Id$")
 
 #include <freeradius-devel/util/track.h>
+#include <freeradius-devel/rad_assert.h>
 
 /*
  *     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;
+}
index b75032ec29af10b1df8f16009aa46ca5ff96f877..9f39a616a9bbdeadead27cbc97ca9b85dabaf982 100644 (file)
@@ -25,8 +25,7 @@
  */
 RCSIDH(track_h, "$Id$")
 
-#include <freeradius-devel/util/time.h>
-#include <talloc.h>
+#include <freeradius-devel/util/channel.h>
 
 #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
 }