]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add "set priority" API
authorAlan T. DeKok <aland@freeradius.org>
Tue, 24 Apr 2018 22:51:34 +0000 (18:51 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 25 Apr 2018 16:53:44 +0000 (12:53 -0400)
to abstract that from the protocol agnostic IO handler

src/lib/io/application.h
src/modules/proto_radius/proto_radius.c

index 7c7e4fd1949e5897afd6dad7a63826c2cf34276e..9ed84e2226a2f7d00d3d212c77c1e2fd8bf24b43 100644 (file)
@@ -43,6 +43,18 @@ typedef int (*fr_app_bootstrap_t)( void *instance, CONF_SECTION *cs);
  */
 typedef void (*fr_app_process_set_t)(void const *instance, REQUEST *request);
 
+/** Set the priority of a packet
+ *
+ * @param[in] instance of the #fr_app_t.
+ * @param[in] buffer   raw packet
+ * @param[in] buflen   length of the packet
+ * @return
+ *     -1 - error, drop the packet
+ *     0  - no error, but we still drop the packet
+ *     *  - the priority of this packet
+ */
+typedef int (*fr_app_priority_get_t)(void const *instance, uint8_t const *buffer, size_t buflen);
+
 /** Called by the network thread to pass an event list for the module to use for timer events
  */
 typedef void (*fr_app_event_list_set_t)(void *instance, fr_event_list_t *el, void *nr);
@@ -67,6 +79,7 @@ typedef struct {
                                                        ///< Here for convenience, so that encode operations common
                                                        ///< to all #fr_app_io_t can be performed by the #fr_app_t.
        fr_app_process_set_t            process_set;
+       fr_app_priority_get_t           priority;       //!< function to get priority of a packet
 } fr_app_t;
 
 /** Public structure describing an application (protocol) specialisation
index b18742731e947bdc97fd47849003dcff352d2ba2..c7a3b00cd35744d5c9f9d3e253f903a73c1560b1 100644 (file)
@@ -505,6 +505,34 @@ static void mod_process_set(void const *instance, REQUEST *request)
 }
 
 
+static int mod_priority(void const *instance, uint8_t const *buffer, UNUSED size_t buflen)
+{
+       proto_radius_t const *inst = talloc_get_type_abort_const(instance, proto_radius_t);
+
+       rad_assert(buffer[0] > 0);
+       rad_assert(buffer[0] < FR_MAX_PACKET_CODE);
+
+       /*
+        *      Disallowed packet
+        */
+       if (!inst->priorities[buffer[0]]) {
+               DEBUG("proto_radius - Ignoring unsupported packet code %d", buffer[0]);
+               return -1;
+       }
+
+       /*
+        *      @todo - if we cared, we could also return -1 for "this
+        *      is a bad packet".  But that's really only for
+        *      mod_inject, as we assume that app_io->read() always
+        *      returns good packets.
+        */
+
+       /*
+        *      Return the configured priority.
+        */
+       return inst->priorities[buffer[0]];
+}
+
 /** Open listen sockets/connect to external event source
  *
  * @param[in] instance Ctx data for this application.
@@ -935,5 +963,6 @@ fr_app_t proto_radius = {
        .open           = mod_open,
        .decode         = mod_decode,
        .encode         = mod_encode,
-       .process_set    = mod_process_set
+       .process_set    = mod_process_set,
+       .priority       = mod_priority
 };