23 RCSID(
"$Id: de0c92bfd6ce94026406aa0f5c49729a6816d5d8 $")
25 #include <freeradius-devel/io/listen.h>
26 #include <freeradius-devel/io/schedule.h>
27 #include <freeradius-devel/radius/defs.h>
28 #include <freeradius-devel/util/debug.h>
29 #include <freeradius-devel/util/inet.h>
30 #include <freeradius-devel/util/md5.h>
31 #include <freeradius-devel/util/syserror.h>
33 #include <sys/event.h>
42 #define MPRINT1 if (debug_lvl) printf
47 struct sockaddr_storage src;
60 static char const *
secret =
"testing123";
65 MPRINT1(
"\t\tPROCESS --- request %"PRIu64
" action %d\n", request->number, action);
77 MPRINT1(
"\t\tDECODE <<< request %"PRIu64
" - %p data %p size %zd\n", request->number, pc,
data, data_len);
87 MPRINT1(
"\t\tENCODE >>> request %"PRIu64
"- data %p %p room %zd\n", request->number, pc,
buffer, buffer_len);
107 MPRINT1(
"\t\tNAK !!! request %d - data %p %p size %zd\n", packet[1], ctx, packet, packet_len);
118 fr_perror(
"radius_test: Failed creating socket");
123 fr_perror(
"radius_test: Failed binding to socket");
142 if (data_size <= 0)
return data_size;
167 if (data_size <= 0)
return data_size;
184 .name =
"schedule-test",
206 fprintf(stderr,
"usage: schedule_test [OPTS]\n");
207 fprintf(stderr,
" -n <num> Start num network threads\n");
208 fprintf(stderr,
" -i <address>[:port] Set IP address and optional port.\n");
209 fprintf(stderr,
" -s <secret> Set shared secret.\n");
210 fprintf(stderr,
" -x Debugging mode.\n");
215 int main(
int argc,
char *argv[])
218 int num_networks = 1;
239 while ((c = getopt(argc, argv,
"i:n:s:w:x")) != -1)
switch (c) {
249 num_networks = atoi(optarg);
250 if ((num_networks <= 0) || (num_networks > 16))
usage();
273 argc -= (optind - 1);
274 argv += (optind - 1);
282 fprintf(stderr,
"schedule_test: Failed to create scheduler\n");
292 EV_SET(&
events[0],
sockfd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, NULL);
294 fr_perror(
"Failed setting KQ for EVFILT_READ");
static int const char char buffer[256]
fr_io_open_t open
Open a new socket for listening, or accept/connect a new connection.
size_t default_message_size
Usually maximum message size.
Public structure describing an I/O path for a protocol.
Describes a new application (protocol)
#define NEVER_RETURNS
Should be placed before the function return type.
int fr_fault_setup(TALLOC_CTX *ctx, char const *cmd, char const *program)
Registers signal handlers to execute panic_action on fatal signal.
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
@ FR_RADIUS_CODE_ACCESS_ACCEPT
RFC2865 - Access-Accept.
int fr_inet_pton_port(fr_ipaddr_t *out, uint16_t *port_out, char const *value, ssize_t inlen, int af, bool resolve, bool mask)
Parses IPv4/6 address + port, to fr_ipaddr_t and integer (port)
uint8_t prefix
Prefix length - Between 0-32 for IPv4 and 0-128 for IPv6.
union fr_ipaddr_t::@130 addr
void const * app_io_instance
I/O path configuration context.
fr_app_io_t const * app_io
I/O path functions.
int fr_log_init_legacy(fr_log_t *log, bool daemonize)
Initialise file descriptors based on logging destination.
fr_md5_update_t fr_md5_update
fr_md5_final_t fr_md5_final
void fr_md5_ctx_free_from_list(fr_md5_ctx_t **ctx)
fr_md5_ctx_t * fr_md5_ctx_alloc_from_list(void)
static TALLOC_CTX * autofree
int main(int argc, char *argv[])
static ssize_t test_encode(void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)
static rlm_rcode_t test_process(UNUSED void const *instance, request_t *request, fr_io_action_t action)
static void entry_point_set(UNUSED void const *ctx, request_t *request)
static fr_time_t start_time
static ssize_t test_read(void *ctx, UNUSED void **packet_ctx, fr_time_t **recv_time, uint8_t *buffer, size_t buffer_len, size_t *leftover, uint32_t *priority, bool *is_dup)
static fr_test_packet_ctx_t tpc
struct sockaddr_storage src
static int test_open(void *ctx, UNUSED void const *master_ctx)
static char const * secret
static size_t test_nak(void const *ctx, UNUSED void *packet_ctx, uint8_t *const packet, size_t packet_len, UNUSED uint8_t *reply, UNUSED size_t reply_len)
static int test_fd(void const *ctx)
static ssize_t test_write(void *ctx, UNUSED void *packet_ctx, UNUSED fr_time_t request_time, uint8_t *buffer, size_t buffer_len, UNUSED size_t written)
static fr_ipaddr_t my_ipaddr
static int test_decode(void const *instance, request_t *request, uint8_t *const data, size_t data_len)
static fr_app_io_t app_io
static NEVER_RETURNS void usage(void)
static fr_event_list_t * events
rlm_rcode_t
Return codes indicating the result of the module call.
fr_schedule_t * fr_schedule_create(TALLOC_CTX *ctx, fr_event_list_t *el, fr_log_t *logger, fr_log_lvl_t lvl, fr_schedule_thread_instantiate_t worker_thread_instantiate, fr_schedule_thread_detach_t worker_thread_detach, fr_schedule_config_t *config)
Create a scheduler and spawn the child threads.
int fr_schedule_destroy(fr_schedule_t **sc_to_free)
Destroy a scheduler, and tell its child threads to exit.
fr_network_t * fr_schedule_listen_add(fr_schedule_t *sc, fr_listen_t *li)
Add a fr_listen_t to a scheduler.
int fr_socket_server_udp(fr_ipaddr_t const *src_ipaddr, uint16_t *src_port, char const *port_name, bool async)
Open an IPv4/IPv6 unconnected UDP socket.
int fr_socket_bind(int sockfd, char const *ifname, fr_ipaddr_t *src_ipaddr, uint16_t *src_port)
Bind a UDP/TCP v4/v6 socket to a given ipaddr src port, and interface.
#define fr_time()
Allow us to arbitrarily manipulate time.
bool colourise
Prefix log messages with VT100 escape codes to change text colour.
#define talloc_get_type_abort_const
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
int fr_time_start(void)
Initialize the local time.
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.