The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
radius1_test.c
Go to the documentation of this file.
1/*
2 * radius_test.c Tests for channels
3 *
4 * Version: $Id: 3c2c6a5c5c16782519381bc226f376e366c3bfc5 $
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 *
20 * @copyright 2016 Alan DeKok (aland@freeradius.org)
21 */
22
23RCSID("$Id: 3c2c6a5c5c16782519381bc226f376e366c3bfc5 $")
24
25#include <freeradius-devel/io/control.h>
26#include <freeradius-devel/io/listen.h>
27#include <freeradius-devel/io/worker.h>
28#include <freeradius-devel/radius/defs.h>
29#include <freeradius-devel/util/debug.h>
30#include <freeradius-devel/util/md5.h>
31#include <freeradius-devel/util/syserror.h>
32
33#ifdef HAVE_GETOPT_H
34# include <getopt.h>
35#endif
36
37#include <signal.h>
38
39
40#define MAX_MESSAGES (2048)
41#define MAX_CONTROL_PLANE (1024)
42#define MAX_KEVENTS (10)
43#define MAX_WORKERS (1024)
44
45#define MPRINT1 if (debug_lvl) printf
46#define MPRINT2 if (debug_lvl > 1) printf
47
48
49typedef struct {
50 int id; //!< ID of the worker 0..N
51 pthread_t pthread_id; //!< pthread ID of the worker
52 fr_worker_t *worker; //!< pointer to the worker
53 fr_channel_t *ch; //!< channel for communicating with the worker
55
56typedef struct {
57 uint8_t vector[16];
59
60 struct sockaddr_storage src;
61 socklen_t salen;
63
64static int debug_lvl = 0;
65static int max_control_plane = 0;
66static int num_workers = 1;
67static bool quiet = false;
68
71static char const *secret = "testing123";
72
74
75static NEVER_RETURNS void usage(void)
76{
77 fprintf(stderr, "usage: radius_test [OPTS]\n");
78 fprintf(stderr, " -c <control-plane> Size of the control plane queue.\n");
79 fprintf(stderr, " -i <address>[:port] Set IP address and optional port.\n");
80 fprintf(stderr, " -q quiet - suppresses worker stats.\n");
81 fprintf(stderr, " -s <secret> Set shared secret.\n");
82 fprintf(stderr, " -w N Create N workers. Default is 1.\n");
83 fprintf(stderr, " -x Debugging mode.\n");
84
85 fr_exit_now(EXIT_FAILURE);
86}
87
88static rlm_rcode_t test_process(UNUSED void const *instance, request_t *request, fr_io_action_t action)
89{
90 MPRINT1("\t\tPROCESS --- request %"PRIu64" action %d\n", request->number, action);
92}
93
94
95static int test_decode(UNUSED void const *instance, request_t *request, uint8_t *const data, size_t data_len)
96{
97 fr_packet_ctx_t const *pc = talloc_get_type_abort_const(request->async->listen->app_instance,
99
100 request->number = pc->id;
101 request->async->process = test_process;
102
103 if (!debug_lvl) return 0;
104
105 MPRINT1("\t\tDECODE <<< request %"PRIu64" - %p data %p size %zd\n", request->number, pc, data, data_len);
106
107 return 0;
108}
109
110static ssize_t test_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)
111{
112 fr_md5_ctx_t *md5_ctx;
113 fr_packet_ctx_t const *pc = talloc_get_type_abort_const(request->async->listen->app_instance,
115
116 MPRINT1("\t\tENCODE >>> request %"PRIu64" - data %p %p room %zd\n",
117 request->number, pc, buffer, buffer_len);
118
120 buffer[1] = pc->id;
121 buffer[2] = 0;
122 buffer[3] = 20;
123
124 memcpy(buffer + 4, pc->vector, 16);
125
126 md5_ctx = fr_md5_ctx_alloc_from_list();
127 fr_md5_update(md5_ctx, buffer, 20);
128 fr_md5_update(md5_ctx, (uint8_t const *) secret, strlen(secret));
129 fr_md5_final(buffer + 4, md5_ctx);
131
132 return 20;
133}
134
135static size_t test_nak(void const *instance, UNUSED void *packet_ctx, uint8_t *const packet, size_t packet_len, UNUSED uint8_t *reply, UNUSED size_t reply_len)
136{
137 MPRINT1("\t\tNAK !!! request %d - data %p %p size %zd\n", packet[1], instance, packet, packet_len);
138
139 return 10;
140}
141
143 .name = "worker-test",
144 .default_message_size = 4096,
145 .nak = test_nak,
146 .encode = test_encode,
147 .decode = test_decode
148};
149
150static void *worker_thread(void *arg)
151{
152 TALLOC_CTX *ctx;
153 fr_worker_t *worker;
156
157 sw = (fr_schedule_worker_t *) arg;
158
159 MPRINT1("\tWorker %d started.\n", sw->id);
160
161 MEM(ctx = talloc_init_const("worker"));
162
163 el = fr_event_list_alloc(ctx, NULL, NULL);
164 if (!el) {
165 fprintf(stderr, "radius_test: Failed to create the event list\n");
166 fr_exit_now(EXIT_FAILURE);
167 }
168
169 worker = sw->worker = fr_worker_create(ctx, el, "test", &default_log, L_DBG_LVL_MAX);
170 if (!worker) {
171 fprintf(stderr, "radius_test: Failed to create the worker\n");
172 fr_exit_now(EXIT_FAILURE);
173 }
174
175 MPRINT1("\tWorker %d looping.\n", sw->id);
176 fr_worker(worker);
177
178 sw->worker = NULL;
179 MPRINT1("\tWorker %d exiting.\n", sw->id);
180
181 talloc_free(ctx);
182 return NULL;
183}
184
185
186static void send_reply(int sockfd, fr_channel_data_t *reply)
187{
188 fr_packet_ctx_t *pc = talloc_get_type_abort(reply->packet_ctx, fr_packet_ctx_t);
189
190 MPRINT1("Master got reply %d size %zd\n", pc->id, reply->m.data_size);
191
192 if (sendto(sockfd, reply->m.data, reply->m.data_size, 0, (struct sockaddr *) &pc->src, pc->salen) < 0) {
193 fprintf(stderr, "Failed sending reply: %s\n", fr_syserror(errno));
194 fr_exit_now(EXIT_FAILURE);
195 }
196
197 talloc_free(pc);
198
199 fr_message_done(&reply->m);
200}
201
202
203static void master_process(TALLOC_CTX *ctx)
204{
205 bool running;
206 int rcode, i, num_events, which_worker;
207 int num_outstanding;
209 fr_channel_t *ch;
211 pthread_attr_t pthread_attr;
213 struct kevent events[MAX_KEVENTS];
214 int kq_master;
217 fr_listen_t listen = { .app_io = &app_io };
218 int sockfd;
219
220 MPRINT1("Master started.\n");
221
222 ms = fr_message_set_create(ctx, MAX_MESSAGES, sizeof(fr_channel_data_t), MAX_MESSAGES * 1024, false);
223 if (!ms) {
224 fprintf(stderr, "Failed creating message set\n");
225 fr_exit_now(EXIT_FAILURE);
226 }
227
228 /*
229 * Create the KQ and associated sockets.
230 */
231 kq_master = kqueue();
232 fr_assert(kq_master >= 0);
233
235 fr_assert(aq_master != NULL);
236
238 fr_assert(control_master != NULL);
239
241 if (sockfd < 0) {
242 fr_perror("radius_test: Failed creating socket");
243 fr_exit_now(EXIT_FAILURE);
244 }
245
246 if (fr_socket_bind(sockfd, NULL, &my_ipaddr, &my_port) < 0) {
247 fr_perror("radius_test: Failed binding to socket");
248 fr_exit_now(EXIT_FAILURE);
249 }
250
251 /*
252 * Set up the KQ filter for reading.
253 */
254 EV_SET(&events[0], sockfd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, NULL);
255 if (kevent(kq_master, events, 1, NULL, 0, NULL) < 0) {
256 fr_perror("Failed setting KQ for EVFILT_READ");
257 fr_exit_now(EXIT_FAILURE);
258 }
259
260 /*
261 * Create the worker threads.
262 */
263 (void) pthread_attr_init(&pthread_attr);
264 (void) pthread_attr_setdetachstate(&pthread_attr, PTHREAD_CREATE_JOINABLE);
265
266 for (i = 0; i < num_workers; i++) {
267 workers[i].id = i;
268 (void) pthread_create(&workers[i].pthread_id, &pthread_attr, worker_thread, &workers[i]);
269 }
270
271 MPRINT1("Master created %d workers.\n", num_workers);
272
273 /*
274 * Busy loop because that's fine for the test
275 */
276 num_outstanding = 0;
277 while (num_outstanding < num_workers) {
278 for (i = 0; i < num_workers; i++) {
279 if (!workers[i].worker) continue;
280 if (workers[i].ch != NULL) continue;
281
282 /*
283 * Create the channel and signal the
284 * worker that it is open
285 */
286 MPRINT1("Master creating channel to worker %d.\n", num_workers);
288 fr_assert(workers[i].ch != NULL);
289
290 (void) fr_channel_master_ctx_add(workers[i].ch, &workers[i]);
291
292 num_outstanding++;
293 }
294 }
295
296 MPRINT1("Master created all channels.\n");
297
298 which_worker = 0;
299 running = true;
300
301 while (running) {
302 bool control_plane_signal;
303 fr_time_t now;
304 fr_channel_data_t *cd, *reply;
305
306 MPRINT1("Master waiting on events.\n");
307
308 num_events = kevent(kq_master, NULL, 0, events, MAX_KEVENTS, NULL);
309 MPRINT1("Master kevent returned %d\n", num_events);
310
311 if (num_events < 0) {
312 if (errno == EINTR) continue;
313
314 fprintf(stderr, "Failed waiting for kevent: %s\n", fr_syserror(errno));
315 fr_exit_now(EXIT_FAILURE);
316 }
317
318 if (num_events == 0) continue;
319
320 control_plane_signal = false;
321
322 /*
323 * Service the events.
324 *
325 * @todo this should NOT take a channel pointer
326 */
327 for (i = 0; i < num_events; i++) {
328 uint8_t *packet, *attr, *end;
329 size_t total_len;
330 ssize_t data_size;
331 fr_packet_ctx_t *packet_ctx;
332
333 if (events[i].filter == EVFILT_USER) {
335 control_plane_signal = true;
336 break;
337 }
338
339 fr_assert(events[i].filter == EVFILT_READ);
340
341 cd = (fr_channel_data_t *) fr_message_reserve(ms, 4096);
342 fr_assert(cd != NULL);
343
344 packet_ctx = talloc(ctx, fr_packet_ctx_t);
345 fr_assert(packet_ctx != NULL);
346 packet_ctx->salen = sizeof(packet_ctx->src);
347
348 cd->priority = 0;
349 cd->packet_ctx = packet_ctx;
350 cd->listen = &listen;
351
352 data_size = recvfrom(sockfd, cd->m.data, cd->m.rb_size, 0,
353 (struct sockaddr *) &packet_ctx->src, &packet_ctx->salen);
354 MPRINT1("Master got packet size %zd\n", data_size);
355 if (data_size <= 20) {
356 MPRINT1("Master ignoring packet (data length %zd)\n", data_size);
357
358 discard:
359 fr_message_done(&cd->m); /* yeah, reuse it for the next packet... */
360 continue;
361 }
362
363 /*
364 * Verify the packet before doing anything more with it.
365 */
366 packet = cd->m.data;
367 if (packet[0] != FR_RADIUS_CODE_ACCESS_REQUEST) {
368 MPRINT1("Master ignoring packet code %u\n", packet[0]);
369 goto discard;
370 }
371
372 total_len = fr_nbo_to_uint16(packet + 2);
373 if (total_len < 20) {
374 MPRINT1("Master ignoring packet (header length %zu)\n", total_len);
375 goto discard;
376 }
377 if (total_len > (size_t) data_size) {
378 MPRINT1("Master ignoring truncated packet (read %zd, says %zu)\n",
379 data_size, total_len);
380 goto discard;
381 }
382
383 attr = packet + 20;
384 end = packet + data_size;
385 while (attr < end) {
386 if ((end - attr) < 2) goto discard;
387 if (attr[0] == 0) goto discard;
388 if (attr[1] < 2) goto discard;
389 if ((attr + attr[1]) > end) goto discard;
390
391 attr += attr[1];
392 }
393
394 (void) fr_message_alloc(ms, &cd->m, total_len);
395
396 MPRINT1("Master sending packet size %zd to worker %d\n", cd->m.data_size, which_worker);
397 cd->m.when = fr_time();
398
399 packet_ctx->id = packet[1];
400 memcpy(packet_ctx->vector, packet + 4, 16);
401
402 rcode = fr_channel_send_request(workers[which_worker].ch, cd, &reply);
403 if (rcode < 0) {
404 fprintf(stderr, "Failed sending request: %s\n", fr_syserror(errno));
405 fr_exit_now(EXIT_FAILURE);
406 }
407 which_worker++;
408 if (which_worker >= num_workers) which_worker = 0;
409
410 fr_assert(rcode == 0);
411 if (reply) send_reply(sockfd, reply);
412 }
413
414 if (!control_plane_signal) continue;
415
416 now = fr_time();
417
418 MPRINT1("Master servicing control-plane\n");
419
420 while (true) {
421 uint32_t id;
422 size_t data_size;
423 char data[256];
424
425 data_size = fr_control_message_pop(aq_master, &id, data, sizeof(data));
426 if (!data_size) break;
427
429
430 ce = fr_channel_service_message(now, &ch, data, data_size);
431 MPRINT1("Master got channel event %d\n", ce);
432
433 switch (ce) {
435 MPRINT1("Master got data ready signal\n");
436
437 reply = fr_channel_recv_reply(ch);
438 if (!reply) {
439 MPRINT1("Master SIGNAL WITH NO DATA!\n");
440 continue;
441 }
442
443 do {
444 send_reply(sockfd, reply);
445 } while ((reply = fr_channel_recv_reply(ch)) != NULL);
446 break;
447
448 case FR_CHANNEL_CLOSE:
449 sw = fr_channel_master_ctx_get(ch);
450 fr_assert(sw != NULL);
451
452 MPRINT1("Master received close ack signal for worker %d\n", sw->id);
453
454 (void) pthread_kill(sw->pthread_id, SIGTERM);
455 running = false;
456 break;
457
458 case FR_CHANNEL_NOOP:
459 break;
460
461 default:
462 fprintf(stderr, "Master got unexpected CE %d\n", ce);
463
464 /*
465 * Not written yet!
466 */
467 fr_assert(0 == 1);
468 break;
469 } /* switch over signal returned */
470 } /* drain the control plane */
471 } /* loop until told to exit */
472
473 MPRINT1("Master exiting.\n");
474
475 fr_time_t last_checked = fr_time();
476
477 /*
478 * Busy-wait for the workers to exit;
479 */
480 do {
481 fr_time_t now = fr_time();
482
483 num_outstanding = num_workers;
484
485 for (i = 0; i < num_workers; i++) {
486 if (!workers[i].worker) num_outstanding--;
487 }
488
489 if ((now - last_checked) > (NSEC / 10)) {
490 MPRINT1("still num_outstanding %d\n", num_outstanding);
491 }
492
493 } while (num_outstanding > 0);
494
495 /*
496 * Force all messages to be garbage collected
497 */
498 MPRINT2("GC\n");
500
501 if (debug_lvl > 1) fr_message_set_debug(stdout, ms);
502
503 /*
504 * After the garbage collection, all messages marked "done" MUST also be marked "free".
505 */
507 MPRINT2("Master messages used = %d\n", rcode);
508 fr_assert(rcode == 0);
509 close(sockfd);
510}
511
512static void sig_ignore(int sig)
513{
514 (void) signal(sig, sig_ignore);
515}
516
517int main(int argc, char *argv[])
518{
519 int c;
520 TALLOC_CTX *autofree = talloc_autofree_context();
521 uint16_t port16 = 0;
522
524
526
527 memset(&my_ipaddr, 0, sizeof(my_ipaddr));
528 my_ipaddr.af = AF_INET;
529 my_ipaddr.prefix = 32;
530 my_ipaddr.addr.v4.s_addr = htonl(INADDR_LOOPBACK);
531 my_port = 1812;
532
533 while ((c = getopt(argc, argv, "c:hi:qs:w:x")) != -1) switch (c) {
534 case 'x':
535 debug_lvl++;
536 break;
537
538 case 'c':
539 max_control_plane = atoi(optarg);
540 break;
541
542 case 'i':
543 if (fr_inet_pton_port(&my_ipaddr, &port16, optarg, -1, AF_INET, true, false) < 0) {
544 fr_perror("Failed parsing ipaddr");
545 fr_exit_now(EXIT_FAILURE);
546 }
547 my_port = port16;
548 break;
549
550 case 'q':
551 quiet = true;
552 break;
553
554 case 's':
555 secret = optarg;
556 break;
557
558 case 'w':
559 num_workers = atoi(optarg);
560 if ((num_workers <= 0) || (num_workers >= MAX_WORKERS)) usage();
561 break;
562
563 case 'h':
564 default:
565 usage();
566 }
567
568 if (!max_control_plane) {
571 }
572
573#if 0
574 argc -= (optind - 1);
575 argv += (optind - 1);
576#endif
577
578 signal(SIGTERM, sig_ignore);
579
580 if (debug_lvl) {
581 setvbuf(stdout, NULL, _IONBF, 0);
582 }
583
585
586 fr_exit_now(EXIT_SUCCESS);
587}
static int const char char buffer[256]
Definition acutest.h:576
size_t default_message_size
Usually maximum message size.
Definition app_io.h:39
Public structure describing an I/O path for a protocol.
Definition app_io.h:33
fr_atomic_queue_t * fr_atomic_queue_alloc(TALLOC_CTX *ctx, size_t size)
Create fixed-size atomic queue.
Structure to hold the atomic queue.
static TALLOC_CTX * autofree
Definition fuzzer.c:44
#define RCSID(id)
Definition build.h:506
#define NEVER_RETURNS
Should be placed before the function return type.
Definition build.h:334
#define UNUSED
Definition build.h:336
bool fr_channel_recv_reply(fr_channel_t *ch)
Receive a reply message from the channel.
Definition channel.c:406
int fr_channel_send_request(fr_channel_t *ch, fr_channel_data_t *cd)
Send a request message into the channel.
Definition channel.c:304
fr_channel_event_t fr_channel_service_message(fr_time_t when, fr_channel_t **p_channel, void const *data, size_t data_size)
Service a control-plane message.
Definition channel.c:683
int fr_channel_service_kevent(fr_channel_t *ch, fr_control_t *c, UNUSED struct kevent const *kev)
Service a control-plane event.
Definition channel.c:786
A full channel, which consists of two ends.
Definition channel.c:142
fr_message_t m
the message header
Definition channel.h:107
fr_channel_event_t
Definition channel.h:69
@ FR_CHANNEL_NOOP
Definition channel.h:76
@ FR_CHANNEL_CLOSE
Definition channel.h:74
@ FR_CHANNEL_DATA_READY_REQUESTOR
Definition channel.h:72
void * packet_ctx
Packet specific context for holding client information, and other proto_* specific information that n...
Definition channel.h:144
fr_listen_t * listen
for tracking packet transport, etc.
Definition channel.h:148
#define FR_CONTROL_ID_CHANNEL
Definition channel.h:67
uint32_t priority
Priority of this packet.
Definition channel.h:142
Channel information which is added to a message.
Definition channel.h:106
static fr_atomic_queue_t * aq_master
static fr_control_t * control_master
static int kq_master
#define MEM(x)
Definition debug.h:46
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
Definition debug.h:236
@ FR_RADIUS_CODE_ACCESS_REQUEST
RFC2865 - Access-Request.
Definition defs.h:33
@ FR_RADIUS_CODE_ACCESS_ACCEPT
RFC2865 - Access-Accept.
Definition defs.h:34
static int sockfd
Definition dhcpclient.c:55
talloc_free(hp)
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)
Definition inet.c:944
uint8_t prefix
Prefix length - Between 0-32 for IPv4 and 0-128 for IPv6.
Definition inet.h:68
int af
Address family.
Definition inet.h:63
union fr_ipaddr_t::@137 addr
IPv4/6 prefix.
fr_control_t * fr_control_create(TALLOC_CTX *ctx, fr_event_list_t *el, fr_atomic_queue_t *aq, size_t num_callbacks)
Create a control-plane signaling path.
Definition control.c:152
ssize_t fr_control_message_pop(fr_atomic_queue_t *aq, uint32_t *p_id, void *data, size_t data_size)
Pop control-plane message.
Definition control.c:403
The control structure.
Definition control.c:76
fr_app_io_t const * app_io
I/O path functions.
Definition listen.h:32
#define fr_time()
Definition event.c:60
fr_event_list_t * fr_event_list_alloc(TALLOC_CTX *ctx, fr_event_status_cb_t status, void *status_uctx)
Initialise a new event list.
Definition event.c:2506
Stores all information relating to an event list.
Definition event.c:377
int fr_log_init_legacy(fr_log_t *log, bool daemonize)
Initialise file descriptors based on logging destination.
Definition log.c:901
fr_log_t default_log
Definition log.c:288
@ L_DBG_LVL_MAX
Lowest priority debug messages (-xxxxx | -Xxxx).
Definition log.h:71
void fr_md5_ctx_free_from_list(fr_md5_ctx_t **ctx)
Free function for MD5 digest ctx.
Definition md5.c:515
fr_md5_ctx_t * fr_md5_ctx_alloc_from_list(void)
Allocation function for MD5 digest context.
Definition md5.c:470
#define fr_md5_final(_out, _ctx)
Finalise the ctx, producing the digest.
Definition md5.h:90
void fr_md5_ctx_t
Definition md5.h:25
#define fr_md5_update(_ctx, _in, _inlen)
Ingest plaintext into the digest.
Definition md5.h:83
unsigned short uint16_t
unsigned int uint32_t
long int ssize_t
unsigned char uint8_t
fr_message_set_t * fr_message_set_create(TALLOC_CTX *ctx, int num_messages, size_t message_size, size_t ring_buffer_size, bool unlimited_size)
Create a message set.
Definition message.c:127
int fr_message_done(fr_message_t *m)
Mark a message as done.
Definition message.c:195
fr_message_t * fr_message_alloc(fr_message_set_t *ms, fr_message_t *m, size_t actual_packet_size)
Allocate packet data for a message.
Definition message.c:1000
int fr_message_set_messages_used(fr_message_set_t *ms)
Count the number of used messages.
Definition message.c:1224
void fr_message_set_gc(fr_message_set_t *ms)
Garbage collect the message set.
Definition message.c:1250
void fr_message_set_debug(FILE *fp, fr_message_set_t *ms)
Print debug information about the message set.
Definition message.c:1274
fr_message_t * fr_message_reserve(fr_message_set_t *ms, size_t reserve_size)
Reserve a message.
Definition message.c:946
A Message set, composed of message headers and ring buffer data.
Definition message.c:94
size_t rb_size
cache-aligned size in the ring buffer
Definition message.h:51
fr_time_t when
when this message was sent
Definition message.h:47
uint8_t * data
pointer to the data in the ring buffer
Definition message.h:49
size_t data_size
size of the data in the ring buffer
Definition message.h:50
static uint16_t fr_nbo_to_uint16(uint8_t const data[static sizeof(uint16_t)])
Read an unsigned 16bit integer from wire format (big endian)
Definition nbo.h:146
#define fr_assert(_expr)
Definition rad_assert.h:37
static int max_control_plane
uint8_t vector[16]
int main(int argc, char *argv[])
#define MAX_KEVENTS
static void * worker_thread(void *arg)
#define MAX_MESSAGES
static rlm_rcode_t test_process(UNUSED void const *instance, request_t *request, fr_io_action_t action)
static fr_schedule_worker_t workers[MAX_WORKERS]
static int test_decode(UNUSED void const *instance, request_t *request, uint8_t *const data, size_t data_len)
static ssize_t test_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)
struct sockaddr_storage src
static size_t test_nak(void const *instance, UNUSED void *packet_ctx, uint8_t *const packet, size_t packet_len, UNUSED uint8_t *reply, UNUSED size_t reply_len)
#define MAX_CONTROL_PLANE
#define MAX_WORKERS
static char const * secret
socklen_t salen
#define MPRINT2
#define MPRINT1
static uint16_t my_port
static fr_ipaddr_t my_ipaddr
static void sig_ignore(int sig)
static bool quiet
static fr_app_io_t app_io
static int num_workers
static NEVER_RETURNS void usage(void)
static void send_reply(int sockfd, fr_channel_data_t *reply)
static int debug_lvl
static fr_event_list_t * events
Definition radsniff.c:58
#define RETURN_UNLANG_OK
Definition rcode.h:64
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:44
Signals that can be sent to a request.
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.
Definition socket.c:846
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.
Definition socket.c:200
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
#define talloc_get_type_abort_const
Definition talloc.h:110
static TALLOC_CTX * talloc_init_const(char const *name)
Allocate a top level chunk with a constant name.
Definition talloc.h:120
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
Definition talloc.h:48
int fr_time_start(void)
Initialize the local time.
Definition time.c:150
#define NSEC
Definition time.h:379
"server local" time.
Definition time.h:69
static fr_event_list_t * el
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
Definition strerror.c:732
static fr_slen_t data
Definition value.h:1340
fr_channel_t * fr_worker_channel_create(fr_worker_t *worker, TALLOC_CTX *ctx, fr_control_t *master)
Create a channel to the worker.
Definition worker.c:1620
void fr_worker(fr_worker_t *worker)
The main loop and entry point of the stand-alone worker thread.
Definition worker.c:1502
A worker which takes packets from a master, and processes them.
Definition worker.c:90
int id
ID of the worker 0..N.
fr_channel_t * ch
channel for communicating with the worker
pthread_t pthread_id
pthread ID of the worker
static void master_process(void)
fr_worker_t * worker
the worker data structure
Definition schedule.c:54
Scheduler specific information for worker threads.
Definition schedule.c:46