extern "C" {
#endif
+typedef struct fr_listen fr_listen_t;
+
/**
* Tell an async process function if it should run or exit.
*/
* know anything about how the data will be used (e.g. authorize,
* authenticate, etc. for Access-Request)
*
- *
* @param[in] data the raw packet data
* @param[in] data_len the length of the raw data
- * @param[in,out] request where the decoded VPs should be placed.
- * @param[in] instance the context for this function.
+ * @param[in] request where the decoded VPs should be placed.
* @return
* - <0 on error
* - 0 on success
*/
-typedef int (*fr_io_decode_t)(void const *instance, REQUEST *request, uint8_t *const data, size_t data_len);
+typedef int (*fr_io_decode_t)(REQUEST *request, uint8_t *const data, size_t data_len);
/** Encode data from a REQUEST into a raw packet.
*
* know anything about how the data will be used (e.g. reject delay
* on Access-Reject)
*
-
- * @param[in,out] request where the VPs to be encoded are located
- * @param[in] buffer the buffer where the raw packet will be written
+ * @param[in] request request where the VPs to be encoded are located
+ * @param[out] buffer the buffer where the raw packet will be written
* @param[in] buffer_len the length of the buffer
- * @param[in] instance the context for this function.
* @return
* - <0 on error
* - >=0 length of the encoded data in the buffer, will be <=buffer_len
*/
-typedef ssize_t (*fr_io_encode_t)(void const *instance, REQUEST *request, uint8_t *buffer, size_t buffer_len);
+typedef ssize_t (*fr_io_encode_t)(REQUEST *request, uint8_t *buffer, size_t buffer_len);
/** NAK a packet.
*
* need to call me again at a later point".
*
* @param[in] instance the context for this function
- * @param[in] request_time when the original request was received
* @param[in] packet_ctx Request specific data.
- * @param[in] buffer the buffer where the raw packet will be written from
+ * @param[in] request_time when the original request was received
+ * @param[in] buffer the buffer where the raw packet will be written from
* @param[in] buffer_len the length of the buffer
* @return
* - <0 on error
* - >=0 length of the data read or written.
*/
-typedef ssize_t (*fr_io_data_write_t)(void const *instance, fr_time_t request_time, void *packet_ctx, uint8_t *buffer, size_t buffer_len);
+typedef ssize_t (*fr_io_data_write_t)(void const *instance, void *packet_ctx, fr_time_t request_time,
+ uint8_t *buffer, size_t buffer_len);
/** Handle a close or error on the socket.
*
uint32_t priority;
void *packet_ctx;
- fr_listen_t const *io; //!< How we received this request,
+ fr_listen_t const *listen; //!< How we received this request,
//!< and how we'll send the reply.
};
#endif
* the reply is a NAK, don't write it to the
* network.
*/
- rcode = listen->app_io->write(listen->app_io_instance, cd->reply.request_time,
- cd->packet_ctx, cd->m.data, cd->m.data_size);
+ rcode = listen->app_io->write(listen->app_io_instance, cd->packet_ctx,
+ cd->reply.request_time, cd->m.data, cd->m.data_size);
if (rcode < 0) {
fr_network_socket_t my_socket, *s;
if (size) {
ssize_t encoded;
- encoded = request->async->io->encode(request->async->io->app_io_instance,
- request, reply->m.data, reply->m.rb_size);
+ encoded = request->async->listen->encode(request, reply->m.data, reply->m.rb_size);
if (encoded < 0) {
fr_log(worker->log, L_DBG, "\t%sfails encode", worker->name);
encoded = 0;
reply->reply.processing_time = request->async->tracking.running;
reply->reply.request_time = request->async->recv_time;
- reply->listen = request->async->io;
+ reply->listen = request->async->listen;
reply->packet_ctx = request->async->packet_ctx;
fr_log(worker->log, L_DBG, "(%"PRIu64") finished, sending reply", request->number);
request->async->el = worker->el;
request->number = worker->number++;
- request->async->io = cd->listen;
+ request->async->listen = cd->listen;
request->async->packet_ctx = cd->packet_ctx;
- listen = request->async->io;
+ listen = request->async->listen;
/*
* Now that the "request" structure has been initialized, go decode the packet.
*
* Note that this also sets the "async process" function.
*/
- rcode = listen->decode(listen->app_io_instance, request, cd->m.data, cd->m.data_size);
+ rcode = listen->decode(request, cd->m.data, cd->m.data_size);
if (rcode < 0) {
fr_log(worker->log, L_DBG, "\t%sFAILED decode of request %"PRIu64, worker->name, request->number);
talloc_free(ctx);
return;
case FR_IO_REPLY:
- size = request->async->io->app_io->default_message_size;
+ size = request->async->listen->app_io->default_message_size;
break;
}
if (!request) return;
rad_assert(request->async->process != NULL);
- rad_assert(request->async->io != NULL);
+ rad_assert(request->async->listen != NULL);
/*
* Run the request, and either track it as
/** Decode the packet, and set the request->process function
*
*/
-static int mod_decode(UNUSED void const *instance, REQUEST *request,
- uint8_t *const data, size_t data_len)
+static int mod_decode(REQUEST *request, uint8_t *const data, size_t data_len)
{
-// proto_radius_t *ctx = instance;
- char *secret;
-
- if (fr_radius_verify(data, NULL, (uint8_t const *) "testing123", 10) < 0) return -1;
+ proto_radius_t const *inst = talloc_get_type_abort(request->async->listen->app_instance, proto_radius_t);
+ RADCLIENT *client;
rad_assert(data[0] < FR_MAX_PACKET_CODE);
+ client = inst->app_io_private->client(inst->app_io, request->async->packet_ctx);
+ rad_assert(client);
+
/*
* Hacks for now until we have a lower-level decode routine.
*/
request->packet->data = talloc_memdup(request->packet, data, data_len);
request->packet->data_len = data_len;
-
- secret = talloc_strdup(request, "testing123");
-
- if (fr_radius_packet_decode(request->packet, NULL, secret) < 0) {
+ if (fr_radius_packet_decode(request->packet, NULL, client->secret) < 0) {
RDEBUG("Failed decoding packet: %s", fr_strerror());
return -1;
}
-// request->async_process = ctx->process[data[0]];
-
return 0;
}
-static ssize_t mod_encode(UNUSED void const *instance, REQUEST *request,
- uint8_t *buffer, size_t buffer_len)
+static ssize_t mod_encode(REQUEST *request, uint8_t *buffer, size_t buffer_len)
{
-// proto_radius_ctx_t *inst = instance;
size_t len;
- char *secret = talloc_strdup(request, "testing123");
- if (fr_radius_packet_encode(request->reply, request->packet, secret) < 0) {
+ proto_radius_t const *inst = talloc_get_type_abort(request->async->listen->app_instance, proto_radius_t);
+ RADCLIENT *client;
+
+ client = inst->app_io_private->client(inst->app_io, request->async->packet_ctx);
+ rad_assert(client);
+
+ if (fr_radius_packet_encode(request->reply, request->packet, client->secret) < 0) {
RDEBUG("Failed encoding RADIUS reply: %s", fr_strerror());
return -1;
}
- if (fr_radius_packet_sign(request->reply, request->packet, secret) < 0) {
+ if (fr_radius_packet_sign(request->reply, request->packet, client->secret) < 0) {
RDEBUG("Failed signing RADIUS reply: %s", fr_strerror());
return -1;
}
*/
typedef struct {
proto_radius_client_get_t client; //!< Retrieve the client the packet was
- ///< received from if any.
- ///< NULL field indicates unsupported.
+ ///< received from.
proto_radius_addr_get_t src; //!< Retrieve the src address of the packet.
proto_radius_addr_get_t dst; //!< Retrieve the dst address of the packet.
return 0;
}
-
-
tracking_status = fr_radius_tracking_entry_insert(&track, inst->ft, buffer, address.timestamp, &address);
switch (tracking_status) {
case FR_TRACKING_ERROR:
return packet_len;
}
-static ssize_t mod_write(void const *instance, fr_time_t request_time, void *packet_ctx, uint8_t *buffer, size_t buffer_len)
+static ssize_t mod_write(void const *instance, void *packet_ctx,
+ fr_time_t request_time, uint8_t *buffer, size_t buffer_len)
{
proto_radius_udp_t const *inst = talloc_get_type_abort(instance, proto_radius_udp_t);
fr_tracking_entry_t *track = packet_ctx;
}
-static int test_decode(void const *instance, REQUEST *request, uint8_t *const data, size_t data_len)
+static int test_decode(REQUEST *request, uint8_t *const data, size_t data_len)
{
- fr_radius_packet_ctx_t const *pc = talloc_get_type_abort(instance, fr_radius_packet_ctx_t);
+ fr_radius_packet_ctx_t const *pc = talloc_get_type_abort(request->async->listen->app_instance,
+ fr_radius_packet_ctx_t);
request->number = pc->id;
request->async->process = test_process;
return 0;
}
-static ssize_t test_encode(void const *instance, REQUEST *request, uint8_t *buffer, size_t buffer_len)
+static ssize_t test_encode(REQUEST *request, uint8_t *buffer, size_t buffer_len)
{
FR_MD5_CTX context;
- fr_radius_packet_ctx_t const *pc = talloc_get_type_abort(instance, fr_radius_packet_ctx_t);
+ fr_radius_packet_ctx_t const *pc = talloc_get_type_abort(request->async->listen->app_instance,
+ fr_radius_packet_ctx_t);
MPRINT1("\t\tENCODE >>> request %"PRIu64" - data %p %p room %zd\n",
request->number, pc, buffer, buffer_len);
return FR_IO_REPLY;
}
-static int test_decode(void const *instance, REQUEST *request, uint8_t *const data, size_t data_len)
+static int test_decode(REQUEST *request, uint8_t *const data, size_t data_len)
{
- fr_listen_test_t const *pc = instance;
+ fr_listen_test_t const *pc = request->async->listen->app_instance;
request->async->process = test_process;
return 0;
}
-static ssize_t test_encode(void const *instance, REQUEST *request, uint8_t *buffer, size_t buffer_len)
+static ssize_t test_encode(REQUEST *request, uint8_t *buffer, size_t buffer_len)
{
FR_MD5_CTX context;
- fr_listen_test_t const *pc = instance;
+ fr_listen_test_t const *pc = request->async->listen->app_instance;
MPRINT1("\t\tENCODE >>> request %"PRIu64"- data %p %p room %zd\n", request->number, pc, buffer, buffer_len);
}
-static ssize_t test_write(void const *ctx, UNUSED fr_time_t request_time, UNUSED void *packet_ctx, uint8_t *buffer, size_t buffer_len)
+static ssize_t test_write(void const *ctx, UNUSED void *packet_ctx, UNUSED fr_time_t request_time,
+ uint8_t *buffer, size_t buffer_len)
{
ssize_t data_size;
fr_listen_test_t *io_ctx = talloc_get_type_abort(ctx, fr_listen_test_t);
return FR_IO_REPLY;
}
-static int test_decode(void const *packet_ctx, REQUEST *request, uint8_t *const data, size_t data_len)
+static int test_decode(REQUEST *request, uint8_t *const data, size_t data_len)
{
uint32_t number;
request->async->process = test_process;
- MPRINT1("\t\tDECODE <<< request %"PRIu64" - %p data %p size %zd\n", request->number, packet_ctx, data, data_len);
+ MPRINT1("\t\tDECODE <<< request %"PRIu64" - %p data %p size %zd\n", request->number,
+ request->async->packet_ctx, data, data_len);
return 0;
}
-static ssize_t test_encode(void const *instance, REQUEST *request, uint8_t *const data, size_t data_len)
+static ssize_t test_encode(REQUEST *request, uint8_t *const data, size_t data_len)
{
- MPRINT1("\t\tENCODE >>> request %"PRIu64" - data %p %p size %zd\n", request->number, instance, data, data_len);
+ MPRINT1("\t\tENCODE >>> request %"PRIu64" - data %p %p size %zd\n", request->number,
+ request->async->listen->app_instance, data, data_len);
return data_len;
}