]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add priority to "read" routine
authorAlan T. DeKok <aland@freeradius.org>
Fri, 18 Aug 2017 08:05:52 +0000 (10:05 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 18 Aug 2017 08:05:52 +0000 (10:05 +0200)
so that we can process Status-Server as a higher priority than
Access-Request, which is in turn higher than Accounting-Request

src/lib/io/io.h
src/lib/io/network.c
src/modules/proto_radius/proto_radius_udp.c
src/tests/util/radius_schedule_test.c

index 924778e9e32b224ee51e4dd20879c89935401b52..b54a7b4b6c9816c42438aed3c00b023ea5383ddd 100644 (file)
@@ -170,11 +170,12 @@ typedef size_t (*fr_io_nak_t)(void const *instance, uint8_t *const packet, size_
  * @param[in,out] buffer       the buffer where the raw packet will be written to (or read from)
  * @param[in] buffer_len       the length of the buffer
  * @param[out] leftover                bytes left in the buffer after reading a full packet.
+ * @param[out] priority                priority of this packet (0 = low, 65535 = high)
  * @return
  *     - <0 on error
  *     - >=0 length of the data read or written.
  */
-typedef ssize_t (*fr_io_data_read_t)(void const *instance, void **packet_ctx, fr_time_t **recv_time, uint8_t *buffer, size_t buffer_len, size_t *leftover);
+typedef ssize_t (*fr_io_data_read_t)(void const *instance, void **packet_ctx, fr_time_t **recv_time, uint8_t *buffer, size_t buffer_len, size_t *leftover, uint32_t *priority);
 
 /** Write a socket.
  *
index 4d9882ff9e2421f219b4969df81e743ba5355687..5d045a1c6fbe8c4b70f10b1cbfa737f02c3b511f 100644 (file)
@@ -359,7 +359,7 @@ static void fr_network_read(UNUSED fr_event_list_t *el, int sockfd, UNUSED int f
         */
 next_message:
        data_size = s->listen->app_io->read(s->listen->app_io_instance, &cd->packet_ctx, &recv_time,
-                                           cd->m.data, cd->m.rb_size, &s->leftover);
+                                           cd->m.data, cd->m.rb_size, &s->leftover, &cd->priority);
        if (data_size == 0) {
 //             fr_log(nr->log, L_DBG_ERR, "got no data from transport read");
 
@@ -398,7 +398,7 @@ next_message:
        } else {
                cd->m.when = fr_time();
        }
-       cd->priority = 0;
+
        cd->listen = s->listen;
        cd->request.recv_time = recv_time;
 
index f2f0b70378f52ca897f9d219fa491e03c477fdf7..cba6543766225314182795cd6161e39262af4628 100644 (file)
@@ -172,7 +172,15 @@ static int mod_decode(UNUSED void const *instance, REQUEST *request, UNUSED uint
        return 0;
 }
 
-static ssize_t mod_read(void const *instance, void **packet_ctx, fr_time_t **recv_time, uint8_t *buffer, size_t buffer_len, size_t *leftover)
+static uint32_t priorities[FR_MAX_PACKET_CODE] = {
+       [FR_CODE_ACCESS_REQUEST] = (1 << 15),
+       [FR_CODE_ACCOUNTING_REQUEST] = (1 << 14),
+       [FR_CODE_COA_REQUEST] = (1 << 14) + 1,
+       [FR_CODE_DISCONNECT_REQUEST] = (1 << 14) + 1,
+       [FR_CODE_STATUS_SERVER] = (1 << 16),
+};
+
+static ssize_t mod_read(void const *instance, void **packet_ctx, fr_time_t **recv_time, uint8_t *buffer, size_t buffer_len, size_t *leftover, uint32_t *priority)
 {
        proto_radius_udp_t const        *inst = talloc_get_type_abort(instance, proto_radius_udp_t);
 
@@ -299,6 +307,7 @@ static ssize_t mod_read(void const *instance, void **packet_ctx, fr_time_t **rec
 
        *packet_ctx = track;
        *recv_time = &track->timestamp;
+       *priority = priorities[buffer[0]];
 
        return packet_len;
 }
index 2036ace84b918e44853c36d8762710b600b0d70e..f1cadadb11cd7527947e4425522421ed48af3086 100644 (file)
@@ -132,7 +132,7 @@ static int test_open(void *ctx)
 
 static fr_time_t start_time;
 
-static ssize_t test_read(void const *ctx, UNUSED void **packet_ctx, fr_time_t **recv_time, uint8_t *buffer, size_t buffer_len, size_t *leftover)
+static ssize_t test_read(void const *ctx, UNUSED void **packet_ctx, fr_time_t **recv_time, uint8_t *buffer, size_t buffer_len, size_t *leftover, uint32_t *priority)
 {
        ssize_t                 data_size;
        fr_listen_test_t        *io_ctx = talloc_get_type_abort(ctx, fr_listen_test_t);
@@ -151,6 +151,7 @@ static ssize_t test_read(void const *ctx, UNUSED void **packet_ctx, fr_time_t **
 
        start_time = fr_time();
        *recv_time = &start_time;
+       *priority = 0;
 
        return data_size;
 }