From: Alan T. DeKok Date: Mon, 24 Jul 2017 20:06:48 +0000 (-0400) Subject: make it build and run X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3156d2a3c841f3feac12b334bbdb9a805830eac;p=thirdparty%2Ffreeradius-server.git make it build and run --- diff --git a/src/modules/rlm_radius/rlm_radius.c b/src/modules/rlm_radius/rlm_radius.c index eb9e8bd6676..4fe77310d4d 100644 --- a/src/modules/rlm_radius/rlm_radius.c +++ b/src/modules/rlm_radius/rlm_radius.c @@ -54,8 +54,6 @@ typedef struct rlm_radius_retry_t { uint32_t mrd; //!< Maximum retransmission duration } rlm_radius_retry_t; -typedef struct rlm_radius_client_io_ctx_t rlm_radius_client_io_ctx_t; - /* * Define a structure for our module configuration. */ @@ -67,7 +65,7 @@ typedef struct radius_instance { struct timeval idle_timeout; dl_instance_t *io_submodule; //!< As provided by the transport_parse - fr_radius_client_io_t *client_io; //!< Easy access to the client_io handle + fr_radius_client_io_t const *client_io; //!< Easy access to the client_io handle void *client_io_instance; //!< Easy access to the client_io instance CONF_SECTION *client_io_conf; //!< Easy access to the client_io's config section @@ -1049,6 +1047,10 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) FR_INTEGER_BOUND_CHECK("Disconnect-Request.mrc", inst->packets[FR_CODE_DISCONNECT_REQUEST].mrc, <=, 10); FR_INTEGER_BOUND_CHECK("Disconnect-Request.mrd", inst->packets[FR_CODE_DISCONNECT_REQUEST].mrd, <=, 30); + inst->client_io = (fr_radius_client_io_t const *) inst->io_submodule->module->common; + inst->client_io_instance = inst->io_submodule->data; + inst->client_io_conf = inst->io_submodule->conf; + rad_assert(inst->client_io->io_inst_size > 0); if (!inst->client_io->bootstrap) return 0; @@ -1161,9 +1163,13 @@ static int mod_thread_detach(void *thread) static int mod_thread_instantiate(CONF_SECTION const *cs, void *instance, fr_event_list_t *el, void *thread) { rlm_radius_t *inst = talloc_get_type_abort(instance, rlm_radius_t); - rlm_radius_thread_t *t = talloc_get_type_abort(thread, rlm_radius_thread_t); + rlm_radius_thread_t *t = thread; rlm_radius_connection_t *c; + (void) talloc_set_type(t, rlm_radius_thread_t); + + t->inst = instance; + c = talloc_zero(t, rlm_radius_connection_t); c->name = ""; c->inst = inst; @@ -1234,6 +1240,8 @@ rad_module_t rlm_radius = { .config = module_config, .bootstrap = mod_bootstrap, .instantiate = mod_instantiate, + + .thread_inst_size = sizeof(rlm_radius_thread_t), .thread_instantiate = mod_thread_instantiate, .thread_detach = mod_thread_detach, .methods = { diff --git a/src/modules/rlm_radius/rlm_radius.h b/src/modules/rlm_radius/rlm_radius.h index c32526dff2c..fcffb21494a 100644 --- a/src/modules/rlm_radius/rlm_radius.h +++ b/src/modules/rlm_radius/rlm_radius.h @@ -89,4 +89,6 @@ typedef struct fr_radius_client_io_t { */ bool rlm_radius_update_delay(struct timeval *start, uint32_t *rt, uint32_t *count, int code, void *client_io_ctx, struct timeval *now); +typedef struct rlm_radius_client_io_ctx_t rlm_radius_client_io_ctx_t; + #endif /* _RLM_RADIUS_H */ diff --git a/src/modules/rlm_radius/rlm_radius.mk b/src/modules/rlm_radius/rlm_radius.mk index 0819339e743..96f9a844def 100644 --- a/src/modules/rlm_radius/rlm_radius.mk +++ b/src/modules/rlm_radius/rlm_radius.mk @@ -1,3 +1,3 @@ TARGET := rlm_radius.a -SOURCES := rlm_radius.c track.c +SOURCES := rlm_radius.c diff --git a/src/modules/rlm_radius/rlm_radius_udp.c b/src/modules/rlm_radius/rlm_radius_udp.c index 0b77f9afaed..6c44b10a8a4 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.c +++ b/src/modules/rlm_radius/rlm_radius_udp.c @@ -1,8 +1,4 @@ // @todo - finish it! -// * track packets in RB tree when writing them -// * do ID allocation based on packet code -// * simple: just allow for any type of packet code. The rlm_radius will take care of giving us -// only the codes which are allowed // * implement remove(), which removes packets from the tracking tree // * don't make request_io_ctx talloc'd from rlm_radius_link_t, as the link can be used // * for other connections. it's simpler to just have one remove() func, than to muck with @@ -43,6 +39,7 @@ RCSID("$Id$") #include #include "rlm_radius.h" +#include "track.h" typedef struct rlm_radius_udp_t { fr_ipaddr_t dst_ipaddr; //!< IP of the home server @@ -70,7 +67,7 @@ typedef struct rlm_radius_udp_t { } rlm_radius_udp_t; -typedef struct udp_io_ctx_t { +struct rlm_radius_client_io_ctx_t { rlm_radius_udp_t const *inst; //!< our module instance uint32_t max_packet_size; //!< our max packet size. may be different from the parent... int fd; //!< file descriptor @@ -82,11 +79,11 @@ typedef struct udp_io_ctx_t { // @todo - track status-server, open, signaling, etc. - // @todo - track outstanding IDs, one per packet code... - uint8_t *buffer; //!< receive buffer size_t buflen; //!< receive buffer length -} udp_io_ctx_t; + + rlm_radius_id_t *id[FR_MAX_PACKET_CODE]; //!< ID tracking +}; typedef struct request_ctx_t { uint8_t header[20]; @@ -122,12 +119,39 @@ static const CONF_PARSER module_config[] = { static int mod_write(REQUEST *request, void *request_ctx, void *io_ctx) { - udp_io_ctx_t *io = talloc_get_type_abort(io_ctx, udp_io_ctx_t); + rlm_radius_client_io_ctx_t *io = talloc_get_type_abort(io_ctx, rlm_radius_client_io_ctx_t); request_ctx_t *track = (request_ctx_t *) request_ctx; /* not talloc'd */ ssize_t packet_len, data_size; + rlm_radius_request_t *rr; + + rad_assert(request->packet->code > 0); + rad_assert(request->packet->code < FR_MAX_PACKET_CODE); + + /* + * Create the tracking table if it doesn't already exist. + * + * @todo - move this into the "init" routine? where was can examine + * the rlm_radius_t, and create the relevant data structures. + */ + if (!io->id[request->packet->code]) { + io->id[request->packet->code] = rr_track_create(io_ctx); + if (!io->id[request->packet->code]) { + RDEBUG("Failed creating tracking table for code %d", request->packet->code); + return -1; + } + } + + /* + * Allocate an ID + */ + rr = rr_track_alloc(io->id[request->packet->code], request, request->packet->code, io, request_ctx); + if (!rr) { + RDEBUG("Failed allocating packet ID for code %d", request->packet->code); + return -1; + } packet_len = fr_radius_encode(io->buffer, io->buflen, NULL, io->inst->secret, strlen(io->inst->secret), - request->packet->code, 0, request->packet->vps); + rr->code, rr->id, request->packet->vps); if (packet_len < 0) { RDEBUG("Failed encoding packet: %s", fr_strerror()); @@ -137,12 +161,11 @@ static int mod_write(REQUEST *request, void *request_ctx, void *io_ctx) data_size = udp_send(io->fd, io->buffer, packet_len, 0, &io->dst_ipaddr, io->dst_port, -// address->if_index, - 0, + 0, /* if_index */ &io->src_ipaddr, io->src_port); // @todo - put the packet into an RB tree, too, so we can find replies... - memcpy(&track->header ,io->buffer, 20); + memcpy(&track->header, io->buffer, 20); if (data_size < packet_len) { rad_assert(0 == 1); @@ -156,7 +179,7 @@ static int mod_write(REQUEST *request, void *request_ctx, void *io_ctx) */ static char const *mod_get_name(TALLOC_CTX *ctx, void *io_ctx) { - udp_io_ctx_t *io = talloc_get_type_abort(io_ctx, udp_io_ctx_t); + rlm_radius_client_io_ctx_t *io = talloc_get_type_abort(io_ctx, rlm_radius_client_io_ctx_t); char src_buf[FR_IPADDR_STRLEN], dst_buf[FR_IPADDR_STRLEN]; fr_inet_ntop(dst_buf, sizeof(dst_buf), &io->dst_ipaddr); @@ -177,7 +200,7 @@ static char const *mod_get_name(TALLOC_CTX *ctx, void *io_ctx) */ static void mod_close(int fd, void *io_ctx) { - udp_io_ctx_t *io = talloc_get_type_abort(io_ctx, udp_io_ctx_t); + rlm_radius_client_io_ctx_t *io = talloc_get_type_abort(io_ctx, rlm_radius_client_io_ctx_t); if (shutdown(fd, SHUT_RDWR) < 0) DEBUG3("Shutdown on socket (%i) failed: %s", fd, fr_syserror(errno)); if (close(fd) < 0) DEBUG3("Closing socket (%i) failed: %s", fd, fr_syserror(errno)); @@ -190,7 +213,7 @@ static void mod_close(int fd, void *io_ctx) */ static fr_connection_state_t mod_open(UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED void *io_ctx) { -// udp_io_ctx_t_t *io = talloc_get_type_abort(io_ctx, udp_io_ctx_t); +// rlm_radius_client_io_ctx_t_t *io = talloc_get_type_abort(io_ctx, rlm_radius_client_io_ctx_t); // @todo - create the initial Status-Server for negotiation and send that @@ -204,7 +227,7 @@ static fr_connection_state_t mod_open(UNUSED fr_event_list_t *el, UNUSED int fd, static fr_connection_state_t mod_init(int *fd_out, void *io_ctx, void const *uctx) { int fd; - udp_io_ctx_t *io = talloc_get_type_abort(io_ctx, udp_io_ctx_t); + rlm_radius_client_io_ctx_t *io = talloc_get_type_abort(io_ctx, rlm_radius_client_io_ctx_t); rlm_radius_udp_t const *inst = talloc_get_type_abort(uctx, rlm_radius_udp_t); io->inst = inst; @@ -344,6 +367,7 @@ fr_radius_client_io_t rlm_radius_udp = { .magic = RLM_MODULE_INIT, .name = "radius_udp", .inst_size = sizeof(rlm_radius_udp_t), + .io_inst_size = sizeof(rlm_radius_client_io_ctx_t), .request_inst_size = sizeof(request_ctx_t), .config = module_config, .bootstrap = mod_bootstrap, diff --git a/src/modules/rlm_radius/rlm_radius_udp.mk b/src/modules/rlm_radius/rlm_radius_udp.mk index f4a46bb1704..fd0c25b7b47 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.mk +++ b/src/modules/rlm_radius/rlm_radius_udp.mk @@ -1,3 +1,3 @@ TARGET := rlm_radius_udp.a -SOURCES := rlm_radius_udp.c +SOURCES := rlm_radius_udp.c track.c