]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
more cleanups
authorAlan T. DeKok <aland@freeradius.org>
Fri, 1 Jun 2018 17:38:39 +0000 (13:38 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 1 Jun 2018 17:38:39 +0000 (13:38 -0400)
src/modules/proto_control/conduit.c
src/modules/proto_control/conduit.h
src/modules/proto_control/proto_control.h
src/modules/proto_control/proto_control_tcp.c
src/modules/proto_control/proto_control_unix.c

index 533d695f5c0288110437b5ec3b7b1c6583915c7f..deb9dbffcdcfefcd175c267dd82c36a7aba84112 100644 (file)
@@ -55,7 +55,7 @@ static ssize_t lo_read(int fd, void *out, size_t outlen)
  *     A non-blocking copy of fr_conduit_read().
  */
 ssize_t fr_conduit_read_async(int fd, fr_conduit_type_t *pconduit, void *out, size_t outlen,
-                             ssize_t *leftover)
+                             size_t *leftover)
 {
        ssize_t r;
        size_t data_len;
index 7440dd39f50ebf4dcde53630a3d81495664011f9..43eb0633e4499c623c4d73ec6af5615840263736 100644 (file)
@@ -68,7 +68,7 @@ typedef struct fr_conduit_hdr_t {
 } fr_conduit_hdr_t;
 
 
-ssize_t fr_conduit_read_async(int fd, fr_conduit_type_t *pconduit, void *inbuf, size_t buflen, ssize_t *have_read);
+ssize_t fr_conduit_read_async(int fd, fr_conduit_type_t *pconduit, void *inbuf, size_t buflen, size_t *leftover);
 ssize_t fr_conduit_read(int fd, fr_conduit_type_t *pconduit, void *buffer, size_t buflen);
 ssize_t fr_conduit_write(int fd, fr_conduit_type_t conduit, void const *buffer, size_t buflen);
 
index 58bfc3e21b3d0d8982b23dd016c17933d055dd3e..f9e433aa2727b4949374185c776a9f6c7cd7ce35 100644 (file)
@@ -24,6 +24,7 @@
  * @copyright 2018 Alan DeKok <aland@freeradius.org>
  */
 #include <freeradius-devel/io/master.h>
+#include "conduit.h"
 
 /** An instance of a proto_control listen section
  *
index 30e7cff189f4e30d613486de5f63f80f12b2dca6..73e3e2001b9916eabfcbb63ff1951816ed0dd8c5 100644 (file)
@@ -102,16 +102,16 @@ static ssize_t mod_read(void *instance, UNUSED void **packet_ctx, fr_time_t **re
 {
        proto_control_tcp_t             *inst = talloc_get_type_abort(instance, proto_control_tcp_t);
        ssize_t                         data_size;
-       size_t                          packet_len = -1;
 
        fr_time_t                       *recv_time_p;
+       fr_conduit_type_t               conduit;
 
        recv_time_p = *recv_time;
 
        /*
         *      Read data into the buffer.
         */
-       data_size = read(inst->sockfd, buffer + *leftover, buffer_len - *leftover);
+       data_size = fr_conduit_read_async(inst->sockfd, &conduit, buffer, buffer_len, leftover);
        if (data_size < 0) {
                DEBUG2("proto_control_tcp got read error %zd: %s", data_size, fr_strerror());
                return data_size;
@@ -125,37 +125,12 @@ static ssize_t mod_read(void *instance, UNUSED void **packet_ctx, fr_time_t **re
         */
 
        /*
-        *      TCP read of zero means the socket is dead.
+        *      Not enough for a full packet, ask the caller to read more.
         */
-       if (!data_size) {
-               DEBUG2("proto_control_tcp - other side closed the socket.");
-               return -1;
-       }
-
-       // @todo - check authentication, etc. on the socket.
-       // we will need a state machine for this..
-
-       /*
-        *      Not enough for one packet.  Tell the caller that we need to read more.
-        */
-       if (data_size < 20) {
-               *leftover = data_size;
+       if (conduit == FR_CONDUIT_WANT_MORE) {
                return 0;
        }
 
-#if 0
-       /*
-        *      If it's not a RADIUS packet, ignore it.
-        */
-       if (!fr_radius_ok(buffer, &packet_len, inst->max_attributes, false, &reason)) {
-               /*
-                *      @todo - check for F5 load balancer packets.  <sigh>
-                */
-               DEBUG2("proto_control_tcp got a packet which isn't RADIUS");
-               inst->stats.total_malformed_requests++;
-               return -1;
-       }
-#endif
 
        // @todo - maybe convert timestamp?
        *recv_time_p = fr_time();
@@ -167,11 +142,10 @@ static ssize_t mod_read(void *instance, UNUSED void **packet_ctx, fr_time_t **re
        /*
         *      Print out what we received.
         */
-       DEBUG2("proto_control_tcp - Received %s ID %d length %d %s",
-              fr_packet_codes[buffer[0]], buffer[1],
-              (int) packet_len, inst->name);
+       DEBUG2("proto_control_tcp - Received command packet length on %s",
+              inst->name);
 
-       return packet_len;
+       return data_size;
 }
 
 
@@ -189,25 +163,6 @@ static ssize_t mod_write(void *instance, void *packet_ctx,
         */
        inst->stats.total_responses++;
 
-       /*
-        *      This handles the race condition where we get a DUP,
-        *      but the original packet replies before we're run.
-        *      i.e. this packet isn't marked DUP, so we have to
-        *      discover it's a dup later...
-        *
-        *      As such, if there's already a reply, then we ignore
-        *      the encoded reply (which is probably going to be a
-        *      NAK), and instead just ignore the DUP and don't reply.
-        */
-       if (track->reply_len) {
-               return buffer_len;
-       }
-
-       /*
-        *      We only write RADIUS packets.
-        */
-       rad_assert(buffer_len >= 20);
-
        /*
         *      Only write replies if they're RADIUS packets.
         *      sometimes we want to NOT send a reply...
@@ -222,14 +177,6 @@ static ssize_t mod_write(void *instance, void *packet_ctx,
         */
        if (data_size <= 0) return data_size;
 
-       /*
-        *      Root through the reply to determine any
-        *      connection-level negotiation data.
-        */
-       if (track->packet[0] == FR_CODE_STATUS_SERVER) {
-//             status_check_reply(inst, buffer, buffer_len);
-       }
-
        return data_size;
 }
 
index 0754e64c09d5231a4488bf85d0410e034a930bb0..550ac542695944175565e22a92167b676ffb305c 100644 (file)
@@ -145,11 +145,10 @@ static ssize_t mod_read(void *instance, UNUSED void **packet_ctx, fr_time_t **re
 }
 
 
-static ssize_t mod_write(void *instance, void *packet_ctx,
+static ssize_t mod_write(void *instance, UNUSED void *packet_ctx,
                         UNUSED fr_time_t request_time, uint8_t *buffer, size_t buffer_len)
 {
        proto_control_unix_t            *inst = talloc_get_type_abort(instance, proto_control_unix_t);
-       fr_io_track_t                   *track = talloc_get_type_abort(packet_ctx, fr_io_track_t);
        ssize_t                         data_size;
 
        /*
@@ -159,25 +158,6 @@ static ssize_t mod_write(void *instance, void *packet_ctx,
         */
        inst->stats.total_responses++;
 
-       /*
-        *      This handles the race condition where we get a DUP,
-        *      but the original packet replies before we're run.
-        *      i.e. this packet isn't marked DUP, so we have to
-        *      discover it's a dup later...
-        *
-        *      As such, if there's already a reply, then we ignore
-        *      the encoded reply (which is probably going to be a
-        *      NAK), and instead just ignore the DUP and don't reply.
-        */
-       if (track->reply_len) {
-               return buffer_len;
-       }
-
-       /*
-        *      We only write RADIUS packets.
-        */
-       rad_assert(buffer_len >= 20);
-
        /*
         *      Only write replies if they're RADIUS packets.
         *      sometimes we want to NOT send a reply...
@@ -192,14 +172,6 @@ static ssize_t mod_write(void *instance, void *packet_ctx,
         */
        if (data_size <= 0) return data_size;
 
-       /*
-        *      Root through the reply to determine any
-        *      connection-level negotiation data.
-        */
-       if (track->packet[0] == FR_CODE_STATUS_SERVER) {
-//             status_check_reply(inst, buffer, buffer_len);
-       }
-
        return data_size;
 }