The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
proto_detail_file.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: 48de2d484e66a4bb7c1b0282f458fbc2b43bbb6b $
19 * @file proto_detail_file.c
20 * @brief Detail handler for files
21 *
22 * @copyright 2017 The FreeRADIUS server project.
23 * @copyright 2017 Alan DeKok (aland@deployingradius.com)
24 */
25
26#include <freeradius-devel/io/application.h>
27#include <freeradius-devel/io/listen.h>
28#include <freeradius-devel/io/schedule.h>
29
30#include <freeradius-devel/server/main_config.h>
31
32#include <freeradius-devel/util/syserror.h>
33#include <freeradius-devel/util/misc.h>
34
35#include "proto_detail.h"
36
37#include <netdb.h>
38
39#include <fcntl.h>
40#include <sys/stat.h>
41
42#ifdef HAVE_GLOB_H
43#include <glob.h>
44#else
45#error proto_detail_file requires <glob.h>
46#endif
47
48DIAG_OFF(unused-macros)
49#if 0
50/*
51 * When we want detailed debugging here, without detailed server
52 * debugging.
53 */
54#define MPRINT DEBUG
55#else
56#define MPRINT DEBUG3
57#endif
58DIAG_ON(unused-macros)
59
60/*
61 * For talloc names, ".name = detail_file", and dl.c prepends "proto_", and appends "_t".
62 */
64
65/*
66 * @todo - this should really now be a different data structure
67 */
69
70static void work_init(proto_detail_file_thread_t *thread, bool triggered_by_delete);
71static void mod_vnode_delete(fr_event_list_t *el, int fd, UNUSED int fflags, void *ctx);
72
75
76 { FR_CONF_OFFSET("filename_work", proto_detail_file_t, filename_work ) },
77
78 { FR_CONF_OFFSET("poll_interval", proto_detail_file_t, poll_interval), .dflt = "5" },
79
80 { FR_CONF_OFFSET("immediate", proto_detail_file_t, immediate) },
81
83};
84
85
86/*
87 * All of the decoding is done by proto_detail and proto_detail_work
88 */
89static int mod_decode(void const *instance, request_t *request, uint8_t *const data, size_t data_len)
90{
92
93 return inst->parent->work_io->decode(inst->parent->work_io_instance, request, data, data_len);
94}
95
96#if 0
97static ssize_t mod_write(UNUSED fr_listen_t *li, UNUSED void *packet_ctx, UNUSED fr_time_t request_time,
98 UNUSED uint8_t *buffer, UNUSED size_t buffer_len, UNUSED size_t written)
99{
100#if 1
101 fr_assert(0);
102
103 return -1;
104#else
105 proto_detail_file_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_detail_file_thread_t);
106
107 return thread->listen->app_io->write(thread->listen, packet_ctx, request_time, buffer, buffer_len, written);
108#endif
109}
110#endif
111
113{
114 proto_detail_file_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_detail_file_thread_t);
115
116 bool has_worker = false;
117
118 pthread_mutex_lock(&thread->worker_mutex);
119 has_worker = (thread->num_workers != 0);
120 pthread_mutex_unlock(&thread->worker_mutex);
121
122 if (has_worker) return;
123
124 FR_TIMER_DISARM(thread->ev);
125
126 work_init(thread, false);
127}
128
129/** Open a detail listener
130 *
131 */
132static int mod_open(fr_listen_t *li)
133{
135 proto_detail_file_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_detail_file_thread_t);
136
137 if (inst->poll_interval == 0) {
138 int oflag;
139
140#ifdef O_EVTONLY
141 oflag = O_EVTONLY;
142#else
143 oflag = O_RDONLY;
144#endif
145 li->fd = thread->fd = open(inst->directory, oflag);
146 if (thread->fd < 0) {
147 cf_log_err(inst->cs, "Failed opening %s: %s", inst->directory, fr_syserror(errno));
148 return -1;
149 }
150 } else {
151 li->fd = thread->fd = -1;
152 li->non_socket_listener = true;
153 li->needs_full_setup = true;
154 }
155 thread->inst = inst;
156 thread->name = talloc_typed_asprintf(thread, "detail_file which will read files matching %s", inst->filename);
157 thread->vnode_fd = -1;
158 pthread_mutex_init(&thread->worker_mutex, NULL);
159
160 li->no_write_callback = true;
161
162 return 0;
163}
164
165/*
166 * The "detail.work" file doesn't exist. Let's see if we can rename one.
167 */
169{
170 proto_detail_file_t const *inst = thread->inst;
171 unsigned int i;
172 int found;
173 time_t chtime;
174 char const *filename;
175 glob_t files;
176 struct stat st;
177
178 DEBUG3("proto_detail (%s): polling for detail files in %s",
179 thread->name, inst->directory);
180
181 memset(&files, 0, sizeof(files));
182 if (glob(inst->filename, 0, NULL, &files) != 0) {
183 noop:
184 DEBUG3("proto_detail (%s): no matching files for %s",
185 thread->name, inst->filename);
186 globfree(&files);
187 return -1;
188 }
189
190 /*
191 * Loop over the glob'd files, looking for the
192 * oldest one.
193 */
194 chtime = 0;
195 found = -1;
196 for (i = 0; i < files.gl_pathc; i++) {
197 if (stat(files.gl_pathv[i], &st) < 0) continue;
198
199 if ((i == 0) || (st.st_ctime < chtime)) {
200 chtime = st.st_ctime;
201 found = i;
202 }
203 }
204
205 /*
206 * No matching files, reset the timer and continue.
207 */
208 if (found < 0) goto noop;
209
210 /*
211 * Rename detail to detail.work
212 */
213 filename = files.gl_pathv[found];
214
215 DEBUG("proto_detail (%s): Renaming %s -> %s", thread->name, filename, inst->filename_work);
216 if (rename(filename, inst->filename_work) < 0) {
217 ERROR("detail (%s): Failed renaming %s to %s: %s",
218 thread->name, filename, inst->filename_work, fr_syserror(errno));
219 goto noop;
220 }
221
222 globfree(&files); /* Shouldn't be using anything in files now */
223
224 /*
225 * The file should now exist, return the open'd FD.
226 */
227 return open(inst->filename_work, inst->mode);
228}
229
230/*
231 * Start polling again after a timeout.
232 */
233static void work_retry_timer(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
234{
235 proto_detail_file_thread_t *thread = talloc_get_type_abort(uctx, proto_detail_file_thread_t);
236
237 work_init(thread, false);
238}
239
240/*
241 * The "detail.work" file exists, and is open in the 'fd'.
242 */
243static int work_exists(proto_detail_file_thread_t *thread, int fd)
244{
245 proto_detail_file_t const *inst = thread->inst;
246 bool opened = false;
248 fr_listen_t *li = NULL;
249 struct stat st;
250
252
253 DEBUG3("proto_detail (%s): Trying to lock %s", thread->name, inst->filename_work);
254
255 /*
256 * "detail.work" exists, try to lock it.
257 */
258 if (rad_lockfd_nonblock(fd, 0) < 0) {
259 fr_time_delta_t delay;
260
261 DEBUG3("proto_detail (%s): Failed locking %s: %s",
262 thread->name, inst->filename_work, fr_syserror(errno));
263
264 close(fd);
265
266 delay = thread->lock_interval;
267
268 /*
269 * Set the next interval, and ensure that we
270 * don't do massive busy-polling.
271 */
277 }
278
279 DEBUG3("proto_detail (%s): Waiting %.6fs for lock on file %s",
280 thread->name, fr_time_delta_unwrap(delay) / (double)NSEC, inst->filename_work);
281
282 if (fr_timer_in(thread, thread->el->tl, &thread->ev, delay,
283 false, work_retry_timer, thread) < 0) {
284 ERROR("Failed inserting retry timer for %s", inst->filename_work);
285 }
286 return 0;
287 }
288
289 DEBUG3("proto_detail (%s): Obtained lock and starting to process file %s",
290 thread->name, inst->filename_work);
291
292 /*
293 * Ignore empty files.
294 */
295 if (fstat(fd, &st) < 0) {
296 ERROR("Failed opening %s: %s", inst->filename_work,
297 fr_syserror(errno));
298 unlink(inst->filename_work);
299 close(fd);
300 return 1;
301 }
302
303 if (!st.st_size) {
304 DEBUG3("proto_detail (%s): %s file is empty, ignoring it.",
305 thread->name, inst->filename_work);
306 unlink(inst->filename_work);
307 close(fd);
308 return 1;
309 }
310
311 /*
312 * This listener is allocated in a thread-specific
313 * context, so it doesn't need a destructor,
314 */
315 MEM(li = talloc_zero(NULL, fr_listen_t));
316
317 /*
318 * Create a new listener, and insert it into the
319 * scheduler. Shamelessly copied from proto_detail.c
320 * mod_open(), with changes.
321 *
322 * This listener is parented from the worker. So that
323 * when the worker goes away, so does the listener.
324 */
325 li->cs = inst->parent->work_io_conf;
326 li->app_io = inst->parent->work_io;
327
328 li->app = inst->parent->self;
329 li->app_instance = inst->parent;
330 li->server_cs = inst->parent->server_cs;
331
332 /*
333 * The worker may be in a different thread, so avoid
334 * talloc threading issues by using a NULL TALLOC_CTX.
335 */
336 MEM(li->thread_instance = work = talloc_zero(li, proto_detail_work_thread_t));
337
338 li->app_io_instance = inst->parent->work_io_instance;
339 work->inst = li->app_io_instance;
340 work->file_parent = thread;
341 work->ev = NULL;
342
343 li->fd = work->fd = dup(fd);
344 if (work->fd < 0) {
345 DEBUG("proto_detail (%s): Failed opening %s: %s",
346 thread->name, inst->filename_work, fr_syserror(errno));
347
348 close(fd);
349 talloc_free(li);
350 return -1;
351 }
352
353 /*
354 * Don't do anything until the file has been deleted.
355 *
356 * @todo - ensure that proto_detail_work is done the file...
357 * maybe by creating a new instance?
358 */
359 if (fr_event_filter_insert(thread, NULL, thread->el, fd, FR_EVENT_FILTER_VNODE,
360 &funcs, NULL, thread) < 0) {
361 PERROR("Failed adding work socket to event loop");
362 close(li->fd);
363 close(fd);
364 talloc_free(li);
365 return -1;
366 }
367
368 /*
369 * Remember this for later.
370 */
371 thread->vnode_fd = fd;
372
373 /*
374 * For us, this is the worker listener.
375 * For the worker, this is it's own parent
376 */
377 thread->listen = li;
378
379 work->filename_work = talloc_strdup(work, inst->filename_work);
380
381 /*
382 * Set configurable parameters for message ring buffer.
383 */
384 li->default_message_size = inst->parent->max_packet_size;
385 li->num_messages = inst->parent->num_messages;
386
387 /*
388 * Open the detail.work file.
389 */
390 if (li->app_io->open(li) < 0) {
391 ERROR("Failed opening %s", li->app_io->common.name);
392 goto error;
393 }
394 opened = true;
395
397 li->name = li->app_io->get_name(li);
398
399 if (!fr_schedule_listen_add(inst->parent->sc, li)) {
400 error:
401 if (fr_event_fd_delete(thread->el, thread->vnode_fd, FR_EVENT_FILTER_VNODE) < 0) {
402 PERROR("Failed removing DELETE callback when opening work file");
403 }
404 close(thread->vnode_fd);
405 thread->vnode_fd = -1;
406
407 if (opened) {
408 (void) li->app_io->close(li);
409 thread->listen = NULL;
410 li = NULL;
411 } else {
412 close(li->fd);
413 }
414
415 talloc_free(li);
416 return -1;
417 }
418
419 /*
420 * Tell the worker to clean itself up.
421 */
422 work->listen = li;
423
424 pthread_mutex_lock(&thread->worker_mutex);
425 thread->num_workers++;
426 pthread_mutex_unlock(&thread->worker_mutex);
427
428 return 0;
429}
430
431
432static void mod_vnode_delete(fr_event_list_t *el, int fd, UNUSED int fflags, void *ctx)
433{
434 proto_detail_file_thread_t *thread = talloc_get_type_abort(ctx, proto_detail_file_thread_t);
435 proto_detail_file_t const *inst = thread->inst;
436
437 DEBUG("proto_detail (%s): Deleted %s", thread->name, inst->filename_work);
438
439 /*
440 * Silently ignore notifications from the directory. We
441 * didn't ask for them, but libkqueue delivers them to
442 * us.
443 */
444 if (fd == thread->fd) return;
445
446 if (fd != thread->vnode_fd) {
447 ERROR("Received DELETE for FD %d, when we were expecting one on FD %d - ignoring it",
448 fd, thread->vnode_fd);
449 return;
450 }
451
453 PERROR("Failed removing DELETE callback after deletion");
454 }
455 close(fd);
456 thread->vnode_fd = -1;
457
458 /*
459 * Re-initialize the state machine.
460 *
461 * Note that a "delete" may be the result of an atomic
462 * "move", which both deletes the old file, and creates
463 * the new one.
464 */
465 work_init(thread, true);
466}
467
468
469/** Start processing a new work file
470 *
471 * @param[in] thread the thread instance.
472 * @param[in] triggered_by_delete true if this was triggered by a vnode_delete.
473 * When a new file is moved over a workfile
474 * vnode delete can serve as an indication
475 * that new data is available.
476 * It can also mean however, that the file
477 * has just been deleted, so we shouldn't
478 * treat this failure to open the new file
479 * as a fatal error.
480 */
481static void work_init(proto_detail_file_thread_t *thread, bool triggered_by_delete)
482{
483 proto_detail_file_t const *inst = thread->inst;
484 int fd, rcode;
485 bool has_worker;
486
487 pthread_mutex_lock(&thread->worker_mutex);
488 has_worker = (thread->num_workers != 0);
489 pthread_mutex_unlock(&thread->worker_mutex);
490
491 /*
492 * The worker is still processing the file, poll until
493 * it's done.
494 */
495 if (has_worker) {
496 DEBUG3("proto_detail (%s): worker %s is still alive, waiting for it to finish.",
497 thread->name, inst->filename_work);
498 goto delay;
499 }
500
501 fr_assert(thread->vnode_fd < 0);
502
503 /*
504 * See if there is a "detail.work" file. If not, try to
505 * rename an existing file to "detail.work".
506 */
507 DEBUG3("Trying to open %s", inst->filename_work);
508 fd = open(inst->filename_work, inst->mode);
509
510 /*
511 * If the work file didn't exist, try to rename detail* ->
512 * detail.work, and return the newly opened file.
513 */
514 if (fd < 0) {
515 if (errno != ENOENT) {
516 DEBUG("proto_detail (%s): Failed opening %s: %s",
517 thread->name, inst->filename_work,
518 fr_syserror(errno));
519 goto delay;
520 }
521
522retry:
523 fd = work_rename(thread);
524 }
525
526 /*
527 * The work file still doesn't exist. Go set up timers,
528 * or wait for an event which signals us that something
529 * in the directory changed.
530 */
531 if (fd < 0) {
532 /*
533 * Wait for the directory to change before
534 * looking for another "detail" file.
535 */
536 if (!inst->poll_interval) return;
537
538 /*
539 * File really was deleted, and didn't have
540 * anything moved over the top.
541 */
542 if (inst->immediate && triggered_by_delete) return;
543
544delay:
545 /*
546 * If we're processing one file and exiting, then the input file must exist.
547 */
548 if (inst->immediate && inst->parent->exit_when_done) {
549 ERROR("Input file does not exist");
550 fr_exit(EXIT_FAILURE);
551 }
552
553 /*
554 * Check every N seconds.
555 */
556 DEBUG3("Waiting %d.000000s for new files in %s", inst->poll_interval, thread->name);
557
558 if (fr_timer_in(thread, thread->el->tl, &thread->ev,
559 fr_time_delta_from_sec(inst->poll_interval),
560 false, work_retry_timer, thread) < 0) {
561 ERROR("Failed inserting poll timer for %s", inst->filename_work);
562 }
563 return;
564 }
565
567
568 /*
569 * It exists, go process it!
570 *
571 * We will get back to the main loop when the
572 * "detail.work" file is deleted.
573 */
574 rcode = work_exists(thread, fd);
575 if (rcode < 0) goto delay;
576
577 /*
578 * The file was empty, so we try to get another one.
579 */
580 if (rcode == 1) goto retry;
581
582 /*
583 * Otherwise the child is successfully processing the
584 * file.
585 */
586}
587
588
589/** Set the event list for a new IO instance
590 *
591 * @param[in] li the listener
592 * @param[in] el the event list
593 * @param[in] nr context from the network side
594 */
596{
598 proto_detail_file_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_detail_file_thread_t);
599
600 thread->el = el;
601
602 if (inst->immediate) {
603 work_init(thread, false);
604 return;
605 }
606
607 /*
608 * Delay for a bit, before reading the detail files.
609 * This gives the server time to call
610 * rad_suid_down_permanent(), and for /proc/PID to
611 * therefore change permissions, so that libkqueue can
612 * read it.
613 */
614 if (fr_timer_in(thread, thread->el->tl, &thread->ev,
615 fr_time_delta_from_sec(1), false, work_retry_timer, thread) < 0) {
616 ERROR("Failed inserting poll timer for %s", inst->filename_work);
617 }
618}
619
620
621static char const *mod_name(fr_listen_t *li)
622{
623 proto_detail_file_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_detail_file_thread_t);
624
625 return thread->name;
626}
627
628
630static pthread_mutex_t detail_file_mutex = PTHREAD_MUTEX_INITIALIZER;
631
632/** Compare two thread instances based on node pointer
633 *
634 * @param[in] one First thread specific xlat expansion instance.
635 * @param[in] two Second thread specific xlat expansion instance.
636 * @return CMP(one, two)
637 */
638static fr_cmp_ret_t _detail_file_cmp(void const *one, void const *two)
639{
640 proto_detail_file_t const *a = one, *b = two;
641
642 return CMP(strcmp(a->filename, b->filename), 0);
643}
644
645/*
646 * Check for multiple readers on the same set of files.
647 */
648static int mod_instantiate(module_inst_ctx_t const *mctx)
649{
650 proto_detail_file_t *inst = talloc_get_type_abort(mctx->mi->data, proto_detail_file_t);
651 CONF_SECTION *conf = mctx->mi->conf;
652
653 module_instance_t const *mi;
654 char *p;
655
656#ifdef __linux__
657 /*
658 * The kqueue API takes an FD, but inotify requires a filename.
659 * libkqueue uses /proc/PID/fd/# to look up the FD -> filename mapping.
660 *
661 * However, if you start the server as "root", and then swap to "radiusd",
662 * /proc/PID will be owned by "root" for security reasons. The only way
663 * to make /proc/PID owned by "radiusd" is to set the DUMPABLE flag.
664 *
665 * Instead of making the poor sysadmin figure this out,
666 * we check for this situation, and give them a
667 * descriptive message telling them what to do.
668 */
670 main_config->uid_is_set &&
671 main_config->server_uid != 0) {
672 cf_log_err(conf, "Cannot start detail file reader due to Linux limitations.");
673 cf_log_err(conf, "Please set 'allow_core_dumps = true' in the main configuration file.");
674 return -1;
675 }
676#endif
677
678 /*
679 * Find the module_instance_t holding our instance data
680 * so we can find out what the parent of our instance
681 * was.
682 */
683 mi = mctx->mi;
684
685#ifndef __linux__
686 /*
687 * Linux inotify works. So we allow poll_interval==0
688 */
689 FR_INTEGER_BOUND_CHECK("poll_interval", inst->poll_interval, >=, 1);
690#endif
691 FR_INTEGER_BOUND_CHECK("poll_interval", inst->poll_interval, <=, 3600);
692
693 inst->parent = talloc_get_type_abort(mi->parent->data, proto_detail_t);
694 inst->cs = conf;
695
696 inst->directory = p = talloc_strdup(inst, inst->filename);
697
698 p = strrchr(p, '/');
699 if (!p) {
700 cf_log_err(conf, "Filename must contain '/'");
701 return -1;
702 }
703
704 *p = '\0';
705
706 if (!inst->filename_work) {
707 inst->filename_work = talloc_typed_asprintf(inst, "%s/detail.work", inst->directory);
708 }
709
710 /*
711 * We need this for the lock.
712 */
713 inst->mode = O_RDWR;
714
715 if (inst->parent->exit_when_done && !inst->immediate) {
716 cf_log_warn(conf, "Ignoring 'exit_when_done' due to 'immediate' flag not being set");
717 inst->parent->exit_when_done = false;
718 }
719
720 pthread_mutex_lock(&detail_file_mutex);
721 if (!detail_file_tree) {
723 if (!detail_file_tree) {
724 pthread_mutex_unlock(&detail_file_mutex);
725 cf_log_err(conf, "Failed initializing detail_file");
726 return -1;
727 }
728 }
729
732
733 fr_rb_find((void **)&old, detail_file_tree, inst);
734 fr_assert(old);
735
736 pthread_mutex_unlock(&detail_file_mutex);
737 cf_log_err(conf, "Duplicate detail listener %s", inst->filename);
738 cf_log_err(conf, "Original detail listener is in virtual server %s", cf_section_name2(old->parent->server_cs));
739 return -1;
740 }
741 pthread_mutex_unlock(&detail_file_mutex);
742
743 return 0;
744}
745
746
747static int mod_close(fr_listen_t *li)
748{
750 proto_detail_file_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_detail_file_thread_t);
751
752 if (thread->nr) {
753 if (unlikely(fr_network_listen_delete(thread->nr, inst->parent->listen) < 0)) {
754 PERROR("Failed removing listener from network on detach");
755 }
756 }
757
758 /*
759 * @todo - have our OWN event loop for timers, and a
760 * "copy timer from -> to, which means we only have to
761 * delete our child event loop from the parent on close.
762 */
763 if (thread->fd >= 0) close(thread->fd);
764
765 if (thread->vnode_fd >= 0) {
766 if (thread->nr) {
767 if (unlikely(fr_network_listen_delete(thread->nr, inst->parent->listen) < 0)) {
768 PERROR("Failed removing listener from network on detach");
769 }
770 } else {
771 if (fr_event_fd_delete(thread->el, thread->vnode_fd, FR_EVENT_FILTER_VNODE) < 0) {
772 PERROR("Failed removing DELETE callback on detach");
773 }
774 }
775 close(thread->vnode_fd);
776 thread->vnode_fd = -1;
777 }
778
779 pthread_mutex_destroy(&thread->worker_mutex);
780
781 return 0;
782}
783
784
785/** Private interface for use by proto_detail_file
786 *
787 */
790 .common = {
791 .magic = MODULE_MAGIC_INIT,
792 .name = "detail_file",
794 .inst_size = sizeof(proto_detail_file_t),
795 .thread_inst_size = sizeof(proto_detail_file_thread_t),
796 .instantiate = mod_instantiate,
797 },
798 .default_message_size = 65536,
799 .default_reply_size = 32,
800
801 .open = mod_open,
802 .close = mod_close,
803 .vnode = mod_vnode_extend,
804 .decode = mod_decode,
805// .write = mod_write,
806 .event_list_set = mod_event_list_set,
807 .get_name = mod_name,
808};
static int const char char buffer[256]
Definition acutest.h:576
fr_io_close_t close
Close the transport.
Definition app_io.h:60
fr_io_open_t open
Open a new socket for listening, or accept/connect a new connection.
Definition app_io.h:43
module_t common
Common fields to all loadable modules.
Definition app_io.h:34
fr_io_data_write_t write
Write from a data buffer to a socket.
Definition app_io.h:48
fr_io_name_t get_name
get the socket name
Definition app_io.h:70
Public structure describing an I/O path for a protocol.
Definition app_io.h:33
#define DIAG_ON(_x)
Definition build.h:535
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
Definition build.h:113
#define unlikely(_x)
Definition build.h:455
#define UNUSED
Definition build.h:384
#define DIAG_OFF(_x)
Definition build.h:534
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:669
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
Definition cf_parse.h:529
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:280
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:268
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition cf_parse.h:429
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:606
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:106
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1362
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:345
#define cf_log_warn(_cf, _fmt,...)
Definition cf_util.h:346
#define fr_exit(_x)
Exit, producing a log message in debug builds.
Definition debug.h:220
#define MEM(x)
Definition debug.h:36
#define ERROR(fmt,...)
Definition dhcpclient.c:40
#define DEBUG(fmt,...)
Definition dhcpclient.c:38
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
@ FR_EVENT_FILTER_VNODE
Filter for vnode subfilters.
Definition event.h:84
#define fr_event_filter_insert(...)
Definition event.h:234
fr_event_fd_cb_t delete
The file was deleted.
Definition event.h:196
Callbacks for the FR_EVENT_FILTER_VNODE filter.
Definition event.h:195
talloc_free(hp)
int fr_network_listen_delete(fr_network_t *nr, fr_listen_t *li)
Delete a socket from a network.
Definition network.c:270
#define PERROR(_fmt,...)
Definition log.h:233
#define DEBUG3(_fmt,...)
Definition log.h:271
int fr_event_fd_delete(fr_event_list_t *el, int fd, fr_event_filter_t filter)
Remove a file descriptor from the event loop.
Definition event.c:1203
Stores all information relating to an event list.
Definition event.c:377
size_t num_messages
for the message ring buffer
Definition listen.h:57
CONF_SECTION * cs
of this listener
Definition listen.h:41
bool non_socket_listener
special internal listener that does not use sockets.
Definition listen.h:47
char const * name
printable name for this socket - set by open
Definition listen.h:29
void const * app_instance
Definition listen.h:39
size_t default_message_size
copied from app_io, but may be changed
Definition listen.h:56
fr_app_t const * app
Definition listen.h:38
void const * app_io_instance
I/O path configuration context.
Definition listen.h:33
CONF_SECTION * server_cs
CONF_SECTION of the server.
Definition listen.h:42
void * thread_instance
thread / socket context
Definition listen.h:34
bool no_write_callback
sometimes we don't need to do writes
Definition listen.h:46
int fd
file descriptor for this socket - set by open
Definition listen.h:28
bool needs_full_setup
Set to true to avoid the short cut when adding the listener.
Definition listen.h:48
fr_app_io_t const * app_io
I/O path functions.
Definition listen.h:32
main_config_t const * main_config
Main server configuration.
Definition main_config.c:56
bool allow_core_dumps
Whether the server is allowed to drop a core when receiving a fatal signal.
static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, fr_time_t request_time, uint8_t *buffer, size_t buffer_len, size_t written)
Definition master.c:2644
unsigned int uint32_t
long int ssize_t
unsigned char uint8_t
int rad_lockfd_nonblock(int fd, int lock_len)
Definition misc.c:129
fr_cmp_ret_t
Result of an ordering comparison.
Definition misc.h:50
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
Detail master protocol handler.
proto_detail_t * parent
The module that spawned us!
proto_detail_work_thread_t * file_parent
thread instance of the directory reader that spawned us
fr_time_delta_t lock_interval
interval between trying the locks.
fr_listen_t * listen
talloc_parent() is slow
char const * filename
file name, usually with wildcards
CONF_SECTION * server_cs
server CS for this listener
char const * name
debug name for printing
int num_workers
number of workers
fr_timer_t * ev
for detail file timers.
fr_event_list_t * el
for various timers
pthread_mutex_t worker_mutex
for the workers
char const * filename_work
work file name
proto_detail_work_t const * inst
instance data
int fd
file descriptor
int vnode_fd
file descriptor for vnode_delete
fr_network_t * nr
for Linux-specific callbacks
static void mod_vnode_extend(fr_listen_t *li, UNUSED uint32_t fflags)
static fr_cmp_ret_t _detail_file_cmp(void const *one, void const *two)
Compare two thread instances based on node pointer.
static const conf_parser_t file_listen_config[]
static void work_retry_timer(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
fr_app_io_t proto_detail_file
Private interface for use by proto_detail_file.
struct proto_detail_work_s proto_detail_file_t
static pthread_mutex_t detail_file_mutex
static int mod_decode(void const *instance, request_t *request, uint8_t *const data, size_t data_len)
static int work_rename(proto_detail_file_thread_t *thread)
static int mod_open(fr_listen_t *li)
Open a detail listener.
static fr_rb_tree_t * detail_file_tree
static void mod_event_list_set(fr_listen_t *li, fr_event_list_t *el, UNUSED void *nr)
Set the event list for a new IO instance.
static char const * mod_name(fr_listen_t *li)
static int mod_close(fr_listen_t *li)
static int mod_instantiate(module_inst_ctx_t const *mctx)
static void work_init(proto_detail_file_thread_t *thread, bool triggered_by_delete)
Start processing a new work file.
static void mod_vnode_delete(fr_event_list_t *el, int fd, UNUSED int fflags, void *ctx)
static int work_exists(proto_detail_file_thread_t *thread, int fd)
#define fr_assert(_expr)
Definition rad_assert.h:37
static rs_t * conf
Definition radsniff.c:52
int fr_rb_find(void **found, fr_rb_tree_t const *tree, void const *data)
Find an element in the tree, returning the data, not the node.
Definition rb.c:586
int fr_rb_insert(fr_rb_tree_t *tree, void const *data)
Insert data into a tree.
Definition rb.c:637
#define fr_rb_inline_talloc_alloc(_ctx, _type, _field, _data_cmp, _data_free)
Allocs a red black that verifies elements are of a specific talloc type.
Definition rb.h:244
The main red black tree structure.
Definition rb.h:71
fr_network_t * fr_schedule_listen_add(fr_schedule_t *sc, fr_listen_t *li)
Add a fr_listen_t to a scheduler.
Definition schedule.c:730
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:351
void * data
Module's instance data.
Definition module.h:293
module_instance_t const * parent
Parent module's instance (if any).
Definition module.h:359
conf_parser_t const * config
How to convert a CONF_SECTION to a module instance.
Definition module.h:206
Module instance data.
Definition module.h:287
eap_aka_sim_process_conf_t * inst
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
Definition talloc.c:546
#define talloc_get_type_abort_const
Definition talloc.h:117
#define talloc_strdup(_ctx, _str)
Definition talloc.h:149
static fr_time_delta_t fr_time_delta_from_msec(int64_t msec)
Definition time.h:575
static fr_time_delta_t fr_time_delta_add(fr_time_delta_t a, fr_time_delta_t b)
Definition time.h:255
static int64_t fr_time_delta_unwrap(fr_time_delta_t time)
Definition time.h:154
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:590
#define fr_time_delta_wrap(_time)
Definition time.h:152
#define NSEC
Definition time.h:379
static fr_time_delta_t fr_time_delta_div(fr_time_delta_t a, fr_time_delta_t b)
Definition time.h:267
#define fr_time_delta_gt(_a, _b)
Definition time.h:283
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"server local" time.
Definition time.h:69
An event timer list.
Definition timer.c:49
#define fr_timer_in(...)
Definition timer.h:87
#define FR_TIMER_DISARM(_ev)
Definition timer.h:91
static fr_event_list_t * el
static fr_slen_t data
Definition value.h:1340