Skip to content

Commit

Permalink
Rename channel to conduit
Browse files Browse the repository at this point in the history
In preparation for adding v4 channels, which will be different
  • Loading branch information
alandekok committed Nov 7, 2016
1 parent e27b273 commit 12a4f83
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 93 deletions.
52 changes: 26 additions & 26 deletions src/include/channel.h → src/include/conduit.h
Expand Up @@ -13,44 +13,44 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef _FR_CHANNEL_H
#define _FR_CHANNEL_H
#ifndef _FR_CONDUIT_H
#define _FR_CONDUIT_H
/**
* $Id$
*
* @file include/channel.h
* @brief API to provide distinct communication channels for the radmin protocol.
* @file include/conduit.h
* @brief API to provide distinct communication conduits for the radmin protocol.
*
* @copyright 2015 Alan DeKok <aland@deployingradius.com>
*/
RCSIDH(channel_h, "$Id$")
RCSIDH(conduit_h, "$Id$")

#ifdef __cplusplus
extern "C" {
#endif

typedef enum fr_channel_type_t {
FR_CHANNEL_STDIN = 0,
FR_CHANNEL_STDOUT,
FR_CHANNEL_STDERR,
FR_CHANNEL_CMD_STATUS,
FR_CHANNEL_INIT_ACK,
FR_CHANNEL_AUTH_CHALLENGE,
FR_CHANNEL_AUTH_RESPONSE,
FR_CHANNEL_WANT_MORE,
FR_CHANNEL_NOTIFY
} fr_channel_type_t;
typedef enum fr_conduit_type_t {
FR_CONDUIT_STDIN = 0,
FR_CONDUIT_STDOUT,
FR_CONDUIT_STDERR,
FR_CONDUIT_CMD_STATUS,
FR_CONDUIT_INIT_ACK,
FR_CONDUIT_AUTH_CHALLENGE,
FR_CONDUIT_AUTH_RESPONSE,
FR_CONDUIT_WANT_MORE,
FR_CONDUIT_NOTIFY
} fr_conduit_type_t;

typedef enum fr_channel_result_t {
FR_CHANNEL_FAIL = 0,
FR_CHANNEL_SUCCESS
} fr_channel_result_t;
typedef enum fr_conduit_result_t {
FR_CONDUIT_FAIL = 0,
FR_CONDUIT_SUCCESS
} fr_conduit_result_t;

typedef enum fr_channel_notify_t {
typedef enum fr_conduit_notify_t {
FR_NOTIFY_NONE = 0,
FR_NOTIFY_BUFFERED,
FR_NOTIFY_UNBUFFERED
} fr_channel_notify_t;
} fr_conduit_notify_t;

#define COMMAND_BUFFER_SIZE (1024)

Expand All @@ -62,11 +62,11 @@ typedef struct fr_cs_buffer_t {
char buffer[COMMAND_BUFFER_SIZE];
} fr_cs_buffer_t;

ssize_t fr_channel_drain(int fd, fr_channel_type_t *pchannel, void *inbuf, size_t buflen, uint8_t **outbuf, ssize_t *have_read);
ssize_t fr_channel_read(int fd, fr_channel_type_t *pchannel, void *buffer, size_t buflen);
ssize_t fr_channel_write(int fd, fr_channel_type_t channel, void const *buffer, size_t buflen);
ssize_t fr_conduit_drain(int fd, fr_conduit_type_t *pconduit, void *inbuf, size_t buflen, uint8_t **outbuf, ssize_t *have_read);
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);

#ifdef __cplusplus
}
#endif
#endif /* _FR_CHANNEL_H */
#endif /* _FR_CONDUIT_H */
44 changes: 22 additions & 22 deletions src/main/command.c
Expand Up @@ -25,7 +25,7 @@

#include <freeradius-devel/parser.h>
#include <freeradius-devel/md5.h>
#include <freeradius-devel/channel.h>
#include <freeradius-devel/conduit.h>
#include <freeradius-devel/state.h>

#include <libgen.h>
Expand Down Expand Up @@ -58,8 +58,8 @@ typedef int (*fr_command_func_t)(rad_listen_t *, int, char *argv[]);
#define FR_READ (1)
#define FR_WRITE (2)

#define CMD_FAIL FR_CHANNEL_FAIL
#define CMD_OK FR_CHANNEL_SUCCESS
#define CMD_FAIL FR_CONDUIT_FAIL
#define CMD_OK FR_CONDUIT_SUCCESS

struct fr_command_table_t {
char const *command;
Expand Down Expand Up @@ -772,7 +772,7 @@ static int command_socket_write(void *cookie, char const *buffer, int len)

pthread_mutex_lock(&debug_mutex);

r = fr_channel_write(listener->fd, FR_CHANNEL_STDOUT, buffer, len);
r = fr_conduit_write(listener->fd, FR_CONDUIT_STDOUT, buffer, len);

pthread_mutex_unlock(&debug_mutex);

Expand All @@ -796,7 +796,7 @@ static ssize_t CC_HINT(format (printf, 2, 3)) cprintf(rad_listen_t *listener, ch

if (listener->status == RAD_LISTEN_STATUS_EOL) return 0;

r = fr_channel_write(listener->fd, FR_CHANNEL_STDOUT, buffer, len);
r = fr_conduit_write(listener->fd, FR_CONDUIT_STDOUT, buffer, len);
if (r <= 0) command_close_socket(listener);

/*
Expand All @@ -817,7 +817,7 @@ static ssize_t CC_HINT(format (printf, 2, 3)) cprintf_error(rad_listen_t *listen

if (listener->status == RAD_LISTEN_STATUS_EOL) return 0;

r = fr_channel_write(listener->fd, FR_CHANNEL_STDERR, buffer, len);
r = fr_conduit_write(listener->fd, FR_CONDUIT_STDERR, buffer, len);
if (r <= 0) command_close_socket(listener);

/*
Expand Down Expand Up @@ -1397,7 +1397,7 @@ static int command_debug_socket(rad_listen_t *listener, int argc, char *argv[])
/*
* Tell radmin to go into buffered mode.
*/
(void) fr_channel_write(listener->fd, FR_CHANNEL_NOTIFY, &notify, sizeof(notify));
(void) fr_conduit_write(listener->fd, FR_CONDUIT_NOTIFY, &notify, sizeof(notify));

command_debug_off();
return CMD_OK;
Expand Down Expand Up @@ -1431,7 +1431,7 @@ static int command_debug_socket(rad_listen_t *listener, int argc, char *argv[])
/*
* Tell radmin to go into unbuffered mode.
*/
(void) fr_channel_write(listener->fd, FR_CHANNEL_NOTIFY, &notify, sizeof(notify));
(void) fr_conduit_write(listener->fd, FR_CONDUIT_NOTIFY, &notify, sizeof(notify));

return CMD_OK;
}
Expand Down Expand Up @@ -3419,12 +3419,12 @@ static int command_domain_recv_co(rad_listen_t *listener, fr_cs_buffer_t *co)
uint32_t status;
ssize_t r, len;
int argc;
fr_channel_type_t channel;
fr_conduit_type_t conduit;
char *my_argv[MAX_ARGV], **argv;
fr_command_table_t *table;
uint8_t *command;

r = fr_channel_drain(listener->fd, &channel, co->buffer, sizeof(co->buffer) - 1, &command, &co->offset);
r = fr_conduit_drain(listener->fd, &conduit, co->buffer, sizeof(co->buffer) - 1, &command, &co->offset);
if ((r < 0) && ((errno == EINTR) || (errno == EAGAIN))) return 0;

if (r <= 0) {
Expand All @@ -3436,7 +3436,7 @@ static int command_domain_recv_co(rad_listen_t *listener, fr_cs_buffer_t *co)
/*
* We need more data. Go read it.
*/
if (channel == FR_CHANNEL_WANT_MORE) {
if (conduit == FR_CONDUIT_WANT_MORE) {
return 0;
}

Expand Down Expand Up @@ -3542,7 +3542,7 @@ static int command_domain_recv_co(rad_listen_t *listener, fr_cs_buffer_t *co)
*/
co->offset = 0;

r = fr_channel_write(listener->fd, FR_CHANNEL_CMD_STATUS, &status, sizeof(status));
r = fr_conduit_write(listener->fd, FR_CONDUIT_CMD_STATUS, &status, sizeof(status));
if (r <= 0) goto do_close;

return 0;
Expand All @@ -3554,7 +3554,7 @@ static int command_tcp_recv(rad_listen_t *this)
ssize_t r;
listen_socket_t *sock = this->data;
fr_cs_buffer_t *co = (void *) sock->packet;
fr_channel_type_t channel;
fr_conduit_type_t conduit;

if (!co) {
do_close:
Expand All @@ -3566,19 +3566,19 @@ static int command_tcp_recv(rad_listen_t *this)
uint8_t *data;
uint8_t expected[16];

r = fr_channel_drain(this->fd, &channel, co->buffer, sizeof(co->buffer) - 1, &data, &co->offset);
r = fr_conduit_drain(this->fd, &conduit, co->buffer, sizeof(co->buffer) - 1, &data, &co->offset);
if ((r < 0) && ((errno == EINTR) || (errno == EAGAIN))) return 0;

if (r <= 0) goto do_close;

/*
* We need more data. Go read it.
*/
if (channel == FR_CHANNEL_WANT_MORE) {
if (conduit == FR_CONDUIT_WANT_MORE) {
return 0;
}

if ((r != sizeof(expected)) || (channel != FR_CHANNEL_AUTH_RESPONSE)) goto do_close;
if ((r != sizeof(expected)) || (conduit != FR_CONDUIT_AUTH_RESPONSE)) goto do_close;

fr_hmac_md5(expected, (void const *) sock->client->secret,
strlen(sock->client->secret),
Expand Down Expand Up @@ -3619,13 +3619,13 @@ static int command_magic_recv(rad_listen_t *this, fr_cs_buffer_t *co, bool chall
int i;
ssize_t r;
uint32_t magic;
fr_channel_type_t channel;
fr_conduit_type_t conduit;
uint8_t *data;

/*
* Start off by reading 4 bytes of magic, followed by 4 bytes of zero.
*/
r = fr_channel_drain(this->fd, &channel, co->buffer, sizeof(co->buffer) - 1, &data, &co->offset);
r = fr_conduit_drain(this->fd, &conduit, co->buffer, sizeof(co->buffer) - 1, &data, &co->offset);
if ((r < 0) && ((errno == EINTR) || (errno == EAGAIN))) return 0;

if (r <= 0) {
Expand All @@ -3639,11 +3639,11 @@ static int command_magic_recv(rad_listen_t *this, fr_cs_buffer_t *co, bool chall
/*
* We need more data. Go read it.
*/
if (channel == FR_CHANNEL_WANT_MORE) {
if (conduit == FR_CONDUIT_WANT_MORE) {
return 0;
}

if ((r != 8) || (channel != FR_CHANNEL_INIT_ACK)) goto do_close;
if ((r != 8) || (conduit != FR_CONDUIT_INIT_ACK)) goto do_close;

magic = htonl(0xf7eead16);
if (memcmp(&magic, data, sizeof(magic)) != 0) {
Expand All @@ -3654,7 +3654,7 @@ static int command_magic_recv(rad_listen_t *this, fr_cs_buffer_t *co, bool chall
/*
* Ack the magic + 4 bytes of zero back.
*/
r = fr_channel_write(this->fd, FR_CHANNEL_INIT_ACK, data, 8);
r = fr_conduit_write(this->fd, FR_CONDUIT_INIT_ACK, data, 8);
if (r <= 0) {
ERROR("Failed writing magic: %s", fr_syserror(errno));
goto do_close;
Expand All @@ -3665,7 +3665,7 @@ static int command_magic_recv(rad_listen_t *this, fr_cs_buffer_t *co, bool chall
co->buffer[i] = fr_rand();
}

r = fr_channel_write(this->fd, FR_CHANNEL_AUTH_CHALLENGE, co->buffer, 16);
r = fr_conduit_write(this->fd, FR_CONDUIT_AUTH_CHALLENGE, co->buffer, 16);
if (r <= 0) {
ERROR("Failed writing auth challenge: %s", fr_syserror(errno));
goto do_close;
Expand Down
38 changes: 19 additions & 19 deletions src/main/channel.c → src/main/conduit.c
@@ -1,5 +1,5 @@
/*
* radmin.c RADIUS Administration tool.
* conduit.c channels for communicating with radmin
*
* Version: $Id$
*
Expand All @@ -24,12 +24,12 @@
RCSID("$Id$")

#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/channel.h>
#include <freeradius-devel/conduit.h>

typedef struct rchannel_t {
uint32_t channel;
typedef struct rconduit_t {
uint32_t conduit;
uint32_t length;
} rchannel_t;
} rconduit_t;


static ssize_t lo_read(int fd, void *inbuf, size_t buflen)
Expand All @@ -56,14 +56,14 @@ static ssize_t lo_read(int fd, void *inbuf, size_t buflen)


/*
* A non-blocking copy of fr_channel_read().
* A non-blocking copy of fr_conduit_read().
*/
ssize_t fr_channel_drain(int fd, fr_channel_type_t *pchannel, void *inbuf, size_t buflen, uint8_t **outbuf, ssize_t *have_read)
ssize_t fr_conduit_drain(int fd, fr_conduit_type_t *pconduit, void *inbuf, size_t buflen, uint8_t **outbuf, ssize_t *have_read)
{
ssize_t r;
size_t data_len;
uint8_t *buffer = inbuf;
rchannel_t hdr;
rconduit_t hdr;
size_t offset = *have_read;

/*
Expand All @@ -78,7 +78,7 @@ ssize_t fr_channel_drain(int fd, fr_channel_type_t *pchannel, void *inbuf, size_
* Ensure that we read the header first.
*/
if (offset < sizeof(hdr)) {
*pchannel = FR_CHANNEL_WANT_MORE;
*pconduit = FR_CONDUIT_WANT_MORE;

r = lo_read(fd, buffer + offset, sizeof(hdr) - offset);
if (r <= 0) return r;
Expand Down Expand Up @@ -115,22 +115,22 @@ ssize_t fr_channel_drain(int fd, fr_channel_type_t *pchannel, void *inbuf, size_
offset += r;

if (offset == buflen) {
*pchannel = ntohl(hdr.channel);
*pconduit = ntohl(hdr.conduit);
*outbuf = buffer + sizeof(hdr);
return data_len;
}

*pchannel = FR_CHANNEL_WANT_MORE;
*pconduit = FR_CONDUIT_WANT_MORE;
*have_read = offset;
return offset;
}

ssize_t fr_channel_read(int fd, fr_channel_type_t *pchannel, void *inbuf, size_t buflen)
ssize_t fr_conduit_read(int fd, fr_conduit_type_t *pconduit, void *inbuf, size_t buflen)
{
ssize_t r;
size_t data_len;
uint8_t *buffer = inbuf;
rchannel_t hdr;
rconduit_t hdr;

/*
* Read the header
Expand All @@ -141,11 +141,11 @@ ssize_t fr_channel_read(int fd, fr_channel_type_t *pchannel, void *inbuf, size_t
/*
* Read the data into the buffer.
*/
*pchannel = ntohl(hdr.channel);
*pconduit = ntohl(hdr.conduit);
data_len = ntohl(hdr.length);

#if 0
fprintf(stderr, "CHANNEL R %zu length %zu\n", *pchannel, data_len);
fprintf(stderr, "CONDUIT R %zu length %zu\n", *pconduit, data_len);
#endif

/*
Expand Down Expand Up @@ -205,17 +205,17 @@ static ssize_t lo_write(int fd, void const *inbuf, size_t buflen)
return buflen;
}

ssize_t fr_channel_write(int fd, fr_channel_type_t channel, void const *inbuf, size_t buflen)
ssize_t fr_conduit_write(int fd, fr_conduit_type_t conduit, void const *inbuf, size_t buflen)
{
ssize_t r;
rchannel_t hdr;
rconduit_t hdr;
uint8_t const *buffer = inbuf;

hdr.channel = htonl(channel);
hdr.conduit = htonl(conduit);
hdr.length = htonl(buflen);

#if 0
fprintf(stderr, "CHANNEL W %zu length %zu\n", channel, buflen);
fprintf(stderr, "CONDUIT W %zu length %zu\n", conduit, buflen);
#endif

/*
Expand Down
2 changes: 1 addition & 1 deletion src/main/radiusd.mk
@@ -1,7 +1,7 @@
TARGET := radiusd
SOURCES := acct.c \
auth.c \
channel.c \
conduit.c \
client.c \
crypt.c \
files.c \
Expand Down

0 comments on commit 12a4f83

Please sign in to comment.