From: Alan T. DeKok Date: Fri, 1 Jun 2018 17:38:39 +0000 (-0400) Subject: more cleanups X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb07abbe20c1940fbee584fbc664fc0ed8d0942d;p=thirdparty%2Ffreeradius-server.git more cleanups --- diff --git a/src/modules/proto_control/conduit.c b/src/modules/proto_control/conduit.c index 533d695f5c0..deb9dbffcdc 100644 --- a/src/modules/proto_control/conduit.c +++ b/src/modules/proto_control/conduit.c @@ -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; diff --git a/src/modules/proto_control/conduit.h b/src/modules/proto_control/conduit.h index 7440dd39f50..43eb0633e44 100644 --- a/src/modules/proto_control/conduit.h +++ b/src/modules/proto_control/conduit.h @@ -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); diff --git a/src/modules/proto_control/proto_control.h b/src/modules/proto_control/proto_control.h index 58bfc3e21b3..f9e433aa272 100644 --- a/src/modules/proto_control/proto_control.h +++ b/src/modules/proto_control/proto_control.h @@ -24,6 +24,7 @@ * @copyright 2018 Alan DeKok */ #include +#include "conduit.h" /** An instance of a proto_control listen section * diff --git a/src/modules/proto_control/proto_control_tcp.c b/src/modules/proto_control/proto_control_tcp.c index 30e7cff189f..73e3e2001b9 100644 --- a/src/modules/proto_control/proto_control_tcp.c +++ b/src/modules/proto_control/proto_control_tcp.c @@ -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. - */ - 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; } diff --git a/src/modules/proto_control/proto_control_unix.c b/src/modules/proto_control/proto_control_unix.c index 0754e64c09d..550ac542695 100644 --- a/src/modules/proto_control/proto_control_unix.c +++ b/src/modules/proto_control/proto_control_unix.c @@ -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; }