The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
proto_cron_crontab.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: 685437b6f842bff4fd76579364207da534a9b9a2 $
19 * @file proto_cron_crontab.c
20 * @brief Generate crontab events.
21 *
22 * @copyright 2021 Network RADIUS SAS (legal@networkradius.com)
23 */
24#include <netdb.h>
25#include <fcntl.h>
26#include <freeradius-devel/io/application.h>
27#include <freeradius-devel/io/listen.h>
28#include <freeradius-devel/io/schedule.h>
29#include <freeradius-devel/util/skip.h>
30
31#include "proto_cron.h"
32
34
36
37typedef struct {
38 fr_event_list_t *el; //!< event list
39 fr_network_t *nr; //!< network handler
40
41 char const *name; //!< socket name
42
44
45 fr_timer_t *ev; //!< for writing statistics
46
47 fr_listen_t *parent; //!< master IO handler
48
49 fr_time_t recv_time; //!< when the timer hit.
50
51 bool suspended; //!< we suspend reading from the FD.
52 bool bootstrap; //!< get it started
54
55typedef struct {
56 unsigned int min;
57 unsigned int max;
58
60 size_t offset;
61
62 uint64_t fields;
64
67
68 CONF_SECTION *cs; //!< our configuration
69
70 char const *filename; //!< where to read input packet from
71 fr_pair_list_t pair_list; //!< for input packet
72
73 int code;
74 char const *spec; //!< crontab spec
75
77
78 fr_client_t *client; //!< static client
79
80 fr_dict_t const *dict; //!< our namespace.
81};
82
83
84static int time_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
85
94
95/*
96 * Parse a basic field with sanity checks.
97 */
98static int parse_field(CONF_ITEM *ci, char const **start, char const *name,
99 cron_tab_t *tab, unsigned int min, unsigned int max, size_t offset)
100{
101 char const *p;
102 char *end = NULL;
103 unsigned int num, next, step, last = 0;
104 bool last_is_set = false;
105 bool wildcard = false;
106 unsigned int i;
107 uint64_t fields = 0;
108
109 p = *start;
111
112 if (!*p) {
113 cf_log_err(ci, "Missing field for %s", name);
114 return -1;
115 }
116
117 tab->min = min;
118 tab->max = max;
119 tab->offset = offset;
120 tab->fields = 0;
121
122 /*
123 * See 'man 5 crontab' for the format.
124 */
125 while (p) {
126 /*
127 * Allow wildcards, but only once.
128 */
129 if (*p == '*') {
130 if (wildcard) {
131 cf_log_err(ci, "Cannot use two wildcards for %s at %s", name, p);
132 return -1;
133 }
134
135 end = UNCONST(char *, p) + 1;
136 wildcard = true;
137 num = min;
138 next = max;
139 goto check_step;
140 }
141
142 /*
143 * If there's already a "*", we can't have another one.
144 */
145 if (wildcard) {
146 cf_log_err(ci, "Cannot use wildcard and numbers for %s at %s", name, p);
147 return -1;
148 }
149
150 /*
151 * If it's not a wildcard, it MUST be a number,
152 * which is between min and max.
153 */
154 num = strtoul(p, &end, 10);
155 if ((num < min) || (num > max)) {
156 cf_log_err(ci, "Number is invalid or out of bounds (%d..%d) for %s at %s",
157 min, max, name, p);
158 return -1;
159 }
160
161 /*
162 * Don't allow the same number to be specified
163 * multiple times.
164 */
165 if (!last_is_set) {
166 last_is_set = true;
167
168 } else if (num <= last) {
169 cf_log_err(ci, "Number overlaps with previous value of %u, for %s at %s",
170 last, name, p);
171 return -1;
172 }
173 last = num;
174
175 /*
176 * Ranges are allowed, with potential steps
177 */
178 if (*end == '-') {
179 p = end + 1;
180 next = strtoul(p, &end, 10);
181 if (next <= num) {
182 cf_log_err(ci, "End of range number overlaps with previous value of %u, for %s at %s",
183 num, name, p);
184 return -1;
185 }
186
187 if (next > max) {
188 cf_log_err(ci, "End of range number is invalid or out of bounds (%d..%d) for %s at %s",
189 min, max, name, p);
190 return -1;
191 }
192
193 check_step:
194 last = next;
195
196 /*
197 * Allow /N
198 */
199 if (*end == '/') {
200 p = end + 1;
201
202 step = strtoul(p, &end, 10);
203 if (step >= max) {
204 cf_log_err(ci, "Step value is invalid or out of bounds for %s at %s", name, p);
205 return -1;
206 }
207 } else {
208 step = 1;
209 }
210
211 /*
212 * Set the necessary bits.
213 */
214 for (i = num; i <= next; i += step) {
215 fields |= ((uint64_t) 1) << i;
216 }
217 } /* end of range specifier */
218
219 /*
220 * We can specify multiple fields, separated by a comma.
221 */
222 if (*end == ',') {
223 fields |= ((uint64_t) 1) << num;
224 p = end + 1;
225 continue;
226 }
227
228 /*
229 * EOS or space is end of field.
230 */
231 if (!(!*end || isspace((uint8_t) *end))) {
232 cf_log_err(ci, "Unexpected text for %s at %s", name, end);
233 return -1;
234 }
235
236 /*
237 * We're at the end of the field, stop.
238 */
239 fields |= ((uint64_t) 1) << num;
240 break;
241 }
242
243 /*
244 * Set a wildcard, so we can skip a lot of the later
245 * logic.
246 */
247 tab->wildcard = true;
248 for (i = min; i <= max; i++) {
249 if ((fields & (((uint64_t) 1) << i)) == 0) {
250 tab->wildcard = false;
251 break;
252 }
253 }
254
255 tab->fields = fields;
256 *start = end;
257 return 0;
258}
259
260/*
261 * Special names, including our own extensions.
262 */
264 { L("annually"), "0 0 1 1 *" },
265 { L("daily"), "0 0 * * *" },
266 { L("hourly"), "0 * * * *" },
267 { L("midnight"), "0 0 * * *" },
268 { L("monthly"), "0 0 1 * *" },
269// { L("reboot"), "+" },
270 { L("weekly"), "0 0 * * 0" },
271 { L("yearly"), "0 0 1 1 *" },
272};
274
275/** Checks the syntax of a cron job
276 *
277 * @param[in] ctx to allocate data in (instance of proto_cron).
278 * @param[out] out Where to write a module_instance_t containing the module handle and instance.
279 * @param[in] parent Base structure address.
280 * @param[in] ci #CONF_PAIR specifying the name of the type module.
281 * @param[in] rule unused.
282 * @return
283 * - 0 on success.
284 * - -1 on failure.
285 */
286static int time_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
287{
288 proto_cron_crontab_t *inst = talloc_get_type_abort(parent, proto_cron_crontab_t);
289 CONF_PAIR *cp = cf_item_to_pair(ci);
290 char const *value = cf_pair_value(cp);
291 char const *p;
292
293 p = value;
294
295 /*
296 * Check for special names.
297 */
298 if (*p == '@') {
299 p = fr_table_value_by_str(time_names, p + 1, NULL);
300 if (!p) {
301 cf_log_err(ci, "Invalid time name '%s'", value);
302 return -1;
303 }
304
305 /*
306 * Over-write the special names with standard
307 * ones, so that the rest of the parser is simpler.
308 */
309 *((char const **) out) = p;
310 return 0;
311 }
312
313 *((char const **) out) = value;
314
315 memset(&inst->tab, 0, sizeof(inst->tab)); /* talloc_zeroed, but this shuts up the analuzer */
316
317 if (parse_field(ci, &p, "minute", &inst->tab[0], 0, 59, offsetof(struct tm, tm_min)) < 0) return -1;
318 if (parse_field(ci, &p, "hour", &inst->tab[1], 0, 23, offsetof(struct tm, tm_hour)) < 0) return -1;
319 if (parse_field(ci, &p, "day of month", &inst->tab[2], 1, 31, offsetof(struct tm, tm_mday)) < 0) return -1;
320 if (parse_field(ci, &p, "month", &inst->tab[3], 1,12, offsetof(struct tm, tm_mon)) < 0) return -1;
321 if (parse_field(ci, &p, "day of week", &inst->tab[4], 0, 6, offsetof(struct tm, tm_wday)) < 0) return -1;
322
324
325 if (*p) {
326 cf_log_err(ci, "Unexpected text after cron time specification");
327 return -1;
328 }
329
330 return 0;
331}
332
333static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len, size_t *leftover)
334{
336 proto_cron_crontab_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_cron_crontab_thread_t);
337 fr_io_address_t *address, **address_p;
338
339 *leftover = 0;
340
341 /*
342 * Suspend all activity on the FD, because we let the
343 * timers do their work.
344 */
345 if (!thread->suspended) {
346 static fr_event_update_t const pause_read[] = {
348 { 0 }
349 };
350
351 if (fr_event_filter_update(thread->el, li->fd, FR_EVENT_FILTER_IO, pause_read) < 0) {
352 fr_assert(0);
353 }
354
355 /*
356 * Don't read from it the first time.
357 */
358 thread->suspended = true;
359 return 0;
360 }
361
362 /*
363 * Where the addresses should go. This is a special case
364 * for proto_radius.
365 */
366 address_p = (fr_io_address_t **) packet_ctx;
367 address = *address_p;
368
369 memset(address, 0, sizeof(*address));
370 address->socket.inet.src_ipaddr.af = AF_INET;
371 address->socket.inet.dst_ipaddr.af = AF_INET;
372 address->radclient = inst->client;
373
374 *recv_time_p = thread->recv_time;
375
376 if (buffer_len < 1) {
377 DEBUG2("proto_cron_tab read buffer is too small for input packet");
378 return 0;
379 }
380
381 buffer[0] = 0;
382
383 /*
384 * Print out what we received.
385 */
386 DEBUG2("proto_cron_crontab - reading packet for %s",
387 thread->name);
388
389 return 1;
390}
391
392
393static ssize_t mod_write(UNUSED fr_listen_t *li, UNUSED void *packet_ctx, UNUSED fr_time_t request_time,
394 UNUSED uint8_t *buffer, size_t buffer_len, UNUSED size_t written)
395{
396 return buffer_len;
397}
398
399
400/** Open a crontab listener
401 *
402 */
403static int mod_open(fr_listen_t *li)
404{
406 proto_cron_crontab_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_cron_crontab_thread_t);
407
408 fr_ipaddr_t ipaddr;
409
410 /*
411 * We never read or write to this file, but we need a
412 * readable FD in order to bootstrap the process.
413 */
414 if (inst->filename == NULL) return -1;
415 li->fd = open(inst->filename, O_RDONLY);
416 if (li->fd < 0) {
417 cf_log_err(li->cs, "Failed opening %s - %s", inst->filename, fr_syserror(errno));
418 return -1;
419 }
420
421 memset(&ipaddr, 0, sizeof(ipaddr));
422 ipaddr.af = AF_INET;
423 li->app_io_addr = fr_socket_addr_alloc_inet_src(li, IPPROTO_UDP, 0, &ipaddr, 0);
424
425 fr_assert((cf_parent(inst->cs) != NULL) && (cf_parent(cf_parent(inst->cs)) != NULL)); /* listen { ... } */
426
427 thread->name = talloc_typed_asprintf(thread, "cron_crontab from filename %s", inst->filename);
428 thread->parent = talloc_parent(li);
429
430 return 0;
431}
432
433
434/** Decode the packet
435 *
436 */
437static int mod_decode(void const *instance, request_t *request, UNUSED uint8_t *const data, UNUSED size_t data_len)
438{
440 fr_io_track_t const *track = talloc_get_type_abort_const(request->async->packet_ctx, fr_io_track_t);
441 fr_io_address_t const *address = track->address;
442
443 /*
444 * Hacks for now until we have a lower-level decode routine.
445 */
446 if (inst->code) request->packet->code = inst->code;
447 request->packet->id = fr_rand() & 0xff;
448 request->reply->id = request->packet->id;
449
450 request->packet->data = talloc_zero_array(request->packet, uint8_t, 1);
451 request->packet->data_len = 1;
452
453 (void) fr_pair_list_copy(request->request_ctx, &request->request_pairs, &inst->pair_list);
454
455 /*
456 * Set the rest of the fields.
457 */
458 request->client = UNCONST(fr_client_t *, address->radclient);
459
460 request->packet->socket = address->socket;
461 fr_socket_addr_swap(&request->reply->socket, &address->socket);
462
463 REQUEST_VERIFY(request);
464
465 return 0;
466}
467
468/*
469 * Get the next time interval.
470 *
471 * Set the relevant "struct tm" field to its next value, and
472 * return "true"
473 *
474 * Set the relevant "struct tm" field to its minimum value, and
475 * return "false".
476 */
477static bool get_next(struct tm *tm, cron_tab_t const *tab)
478{
479 unsigned int i, num = *(int *) (((uint8_t *) tm) + tab->offset);
480
481 num++;
482
483 /*
484 * Simplified process for "do each thing".
485 */
486 if (tab->wildcard) {
487 if (num <= tab->max) goto done;
488 goto next;
489 }
490
491 /*
492 * See when the next time interval is.
493 */
494 for (i = num; i <= tab->max; i++) {
495 if ((tab->fields & (((uint64_t) 1) << i)) != 0) {
496 num = i;
497 break;
498 }
499 }
500
501 /*
502 * We ran out of time intervals. Reset this field to the
503 * minimum, and ask the caller to go to the next
504 * interval.
505 */
506 if (i > tab->max) {
507 next:
508 *(int *) (((uint8_t *) tm) + tab->offset) = tab->min;
509 return false;
510 }
511
512done:
513 *(int *) (((uint8_t *) tm) + tab->offset) = num;
514 return true;
515}
516
517/*
518 * Called when tm.tm_sec == 0. If it isn't zero, then it means
519 * that the timer is late, and we treat it as if tm.tm_sec == 0.
520 */
521static void do_cron(fr_timer_list_t *tl, fr_time_t now, void *uctx)
522{
523 proto_cron_crontab_thread_t *thread = uctx;
524 struct tm tm;
525 time_t start = time(NULL), end;
526
527 thread->recv_time = now;
528
529 localtime_r(&start, &tm);
530
531 /*
532 * For now, ignore "day of week". If the "day of week"
533 * is a wildcard, then ignore it. Otherwise, calculate
534 * next based on "day of month" and also "day of week",
535 * and then return the time which is closer.
536 */
537 tm.tm_sec = 0;
538 if (get_next(&tm, &thread->inst->tab[0])) goto set; /* minutes */
539 if (get_next(&tm, &thread->inst->tab[1])) goto set; /* hours */
540
541 /*
542 * If we're running it every day of the week, just pay
543 * attention to the day of the month.
544 */
545 if (thread->inst->tab[4].wildcard) {
546 if (get_next(&tm, &thread->inst->tab[2])) goto set; /* days */
547
548 if (get_next(&tm, &thread->inst->tab[3])) goto set; /* month */
549
550 /*
551 * We ran out of months, so we have to go to the next year.
552 */
553 tm.tm_year++;
554
555 } else {
556 /*
557 * Pick the earliest of "day of month" and "day of week".
558 */
559 struct tm m_tm = tm;
560 struct tm w_tm = tm;
561 int tm_wday = tm.tm_wday;
562 bool m_day = get_next(&m_tm, &thread->inst->tab[2]);
563 bool w_day = get_next(&w_tm, &thread->inst->tab[4]);
564 time_t m_time;
565 time_t w_time;
566
567 /*
568 * No more days this week. Go to the
569 * start of the next week.
570 */
571 if (!w_day) {
572 w_tm = tm;
573 w_tm.tm_mday += (6 - tm_wday);
574
575 (void) mktime(&w_tm); /* normalize it */
576
577 tm_wday = w_tm.tm_wday;
578#ifndef NDEBUG
579 w_day = get_next(&w_tm, &thread->inst->tab[4]);
580 fr_assert(w_day);
581#else
582 (void) get_next(&w_tm, &thread->inst->tab[4]);
583#endif
584 }
585
586 /*
587 * Next weekday is ignored by mktime(), so we
588 * have to update the day of the month with the
589 * new value.
590 *
591 * Note that mktime() will also normalize the
592 * values, so we can just add "28 + 5" for a day
593 * of the month, and mktime() will normalize that
594 * to the correct day for the next month.
595 */
596 fr_assert(tm.tm_wday > tm_wday);
597 w_tm.tm_mday += tm.tm_wday - tm_wday;
598
599 /*
600 * No more days this month, go to the next month,
601 * and potentially the next year.
602 */
603 if (!m_day && !get_next(&m_tm, &thread->inst->tab[3])) m_tm.tm_year++;
604
605 /*
606 * We now have 2 times, one for "day of month"
607 * and another for "day of week". Pick the
608 * earliest one.
609 */
610 m_time = mktime(&m_tm);
611 w_time = mktime(&w_tm);
612
613 if (m_time < w_time) {
614 end = m_time;
615 } else {
616 end = w_time;
617 }
618
619 goto use_time;
620 }
621
622set:
623 end = mktime(&tm);
624 fr_assert(end >= start);
625
626use_time:
627 if (DEBUG_ENABLED2) {
628 char buffer[256];
629
630 ctime_r(&end, buffer);
631 DEBUG("TIMER - virtual server %s next cron is at %s, in %ld seconds",
632 cf_section_name2(thread->inst->parent->server_cs), buffer, end - start);
633 }
634
635 if (fr_timer_at(thread, tl, &thread->ev, fr_time_add(now, fr_time_delta_from_sec(end - start)),
636 false, do_cron, thread) < 0) {
637 fr_assert(0);
638 }
639
640 /*
641 * Don't run the event the first time.
642 */
643 if (thread->bootstrap) {
644 thread->bootstrap = false;
645 return;
646 }
647
648 /*
649 * Now that we've set the timer, tell the network side to
650 * call our read routine.
651 */
652 fr_network_listen_read(thread->nr, thread->parent);
653}
654
655/** Close a virtual listener
656 *
657 * The fd only exists to bootstrap the listener, so closing it mostly means
658 * removing the timer that runs the jobs.
659 *
660 * @param[in] li the listener
661 * @return
662 * - 0 on success.
663 * - -1 if the timer could not be deleted. The fd is closed either way.
664 */
665static int mod_close(fr_listen_t *li)
666{
667 proto_cron_crontab_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_cron_crontab_thread_t);
668 int ret = 0;
669
670 if (thread->ev && (fr_timer_delete(&thread->ev) < 0)) {
671 PERROR("Failed deleting cron timer");
672 ret = -1;
673 }
674
675 close(li->fd);
676
677 return ret;
678}
679
680/** Set the event list for a new socket
681 *
682 * @param[in] li the listener
683 * @param[in] el the event list
684 * @param[in] nr context from the network side
685 */
687{
689 proto_cron_crontab_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_cron_crontab_thread_t);
690
691 thread->el = el;
692 thread->nr = nr;
693 thread->inst = inst;
694 thread->bootstrap = true;
695
696 do_cron(el->tl, fr_time(), thread);
697}
698
699static char const *mod_name(fr_listen_t *li)
700{
701 proto_cron_crontab_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_cron_crontab_thread_t);
702
703 return thread->name;
704}
705
712
713static int mod_instantiate(module_inst_ctx_t const *mctx)
714{
715 proto_cron_crontab_t *inst = talloc_get_type_abort(mctx->mi->data, proto_cron_crontab_t);
716 CONF_SECTION *conf = mctx->mi->conf;
717 fr_client_t *client;
718 fr_pair_t *vp;
719 FILE *fp;
720 bool done = false;
721
722 inst->parent = talloc_get_type_abort(mctx->mi->parent->data, proto_cron_t);
723 inst->cs = mctx->mi->conf;
725 if (!inst->dict) {
726 cf_log_err(conf, "Please define 'namespace' in this virtual server");
727 return -1;
728 }
729
730 fr_pair_list_init(&inst->pair_list);
731 MEM(inst->client = client = talloc_zero(inst, fr_client_t));
732
733 client->ipaddr.af = AF_INET;
734 client->src_ipaddr = client->ipaddr;
735
736 client->longname = client->shortname = inst->filename;
737 client->secret = talloc_strdup(client, "testing123");
738 client->nas_type = talloc_strdup(client, "load");
739 client->use_connected = false;
740
741 fp = fopen(inst->filename, "r");
742 if (!fp) {
743 cf_log_err(conf, "Failed opening %s - %s",
744 inst->filename, fr_syserror(errno));
745 return -1;
746 }
747
748 if (fr_pair_list_afrom_file(inst, inst->dict, &inst->pair_list, fp, &done, true) < 0) {
749 cf_log_perr(conf, "Failed reading %s", inst->filename);
750 fclose(fp);
751 return -1;
752 }
753
754 fclose(fp);
755
756 vp = fr_pair_find_by_da(&inst->pair_list, NULL, inst->parent->attr_packet_type);
757 if (vp) inst->code = vp->vp_uint32;
758
759 return 0;
760}
761
763 .common = {
764 .magic = MODULE_MAGIC_INIT,
765 .name = "cron_crontab",
767 .inst_size = sizeof(proto_cron_crontab_t),
768 .thread_inst_size = sizeof(proto_cron_crontab_thread_t),
769 .instantiate = mod_instantiate
770 },
771 .default_message_size = 4096,
772 .track_duplicates = false,
773
774 .open = mod_open,
775 .close = mod_close,
776 .read = mod_read,
777 .write = mod_write,
778 .event_list_set = mod_event_list_set,
779 .client_find = mod_client_find,
780 .get_name = mod_name,
781
782 .decode = mod_decode,
783};
static int const char char buffer[256]
Definition acutest.h:576
module_t common
Common fields to all loadable modules.
Definition app_io.h:34
Public structure describing an I/O path for a protocol.
Definition app_io.h:33
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
Definition build.h:186
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:228
#define UNUSED
Definition build.h:384
#define NUM_ELEMENTS(_t)
Definition build.h:406
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:669
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:623
#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
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
Definition cf_parse.h:447
@ CONF_FLAG_FILE_READABLE
File matching value must exist, and must be readable.
Definition cf_parse.h:435
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:606
Common header for all CONF_* types.
Definition cf_priv.h:54
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:77
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
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
Definition cf_util.c:749
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition cf_util.c:675
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1756
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:345
#define cf_parent(_cf)
Definition cf_util.h:118
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:352
static size_t min(size_t x, size_t y)
Definition dbuff.c:66
#define MEM(x)
Definition debug.h:36
#define DEBUG(fmt,...)
Definition dhcpclient.c:38
Test enumeration values.
Definition dict_test.h:92
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
@ FR_EVENT_FILTER_IO
Combined filter for read/write functions/.
Definition event.h:83
#define fr_event_filter_update(...)
Definition event.h:239
#define FR_EVENT_SUSPEND(_s, _f)
Temporarily remove the filter for a func from kevent.
Definition event.h:115
Callbacks for the FR_EVENT_FILTER_IO filter.
Definition event.h:188
Structure describing a modification to a filter's state.
Definition event.h:96
int af
Address family.
Definition inet.h:64
IPv4/6 prefix.
fr_socket_t socket
src/dst ip and port.
Definition base.h:336
fr_client_t const * radclient
old-style client definition
Definition base.h:338
void fr_network_listen_read(fr_network_t *nr, fr_listen_t *li)
Signal the network to read from a listener.
Definition network.c:335
fr_ipaddr_t ipaddr
IPv4/IPv6 address of the host.
Definition client.h:83
char const * secret
Secret PSK.
Definition client.h:90
fr_ipaddr_t src_ipaddr
IPv4/IPv6 address to send responses from (family must match ipaddr).
Definition client.h:84
char const * nas_type
Type of client (arbitrary).
Definition client.h:131
char const * longname
Client identifier.
Definition client.h:87
char const * shortname
Client nickname.
Definition client.h:88
bool use_connected
do we use connected sockets for this client
Definition client.h:121
Describes a host allowed to send packets to the server.
Definition client.h:80
#define PERROR(_fmt,...)
Definition log.h:233
#define DEBUG_ENABLED2
True if global debug level 1-2 messages are enabled.
Definition log.h:263
#define fr_time()
Definition event.c:60
Stores all information relating to an event list.
Definition event.c:377
CONF_SECTION * cs
of this listener
Definition listen.h:41
fr_socket_t * app_io_addr
for tracking duplicate sockets
Definition listen.h:36
void const * app_io_instance
I/O path configuration context.
Definition listen.h:33
void * thread_instance
thread / socket context
Definition listen.h:34
int fd
file descriptor for this socket - set by open
Definition listen.h:28
static fr_event_update_t pause_read[]
Definition master.c:166
fr_io_address_t const * address
of this packet.. shared between multiple packets
Definition master.h:55
long int ssize_t
unsigned char uint8_t
struct tm * localtime_r(time_t const *l_clock, struct tm *result)
Definition missing.c:162
char * ctime_r(time_t const *l_clock, char *l_buf)
Definition missing.c:181
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
int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
Definition pair.c:2326
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
Definition pair.c:707
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:46
int fr_pair_list_afrom_file(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_pair_list_t *out, FILE *fp, bool *pfiledone, bool allow_exec)
Read valuepairs from the fp up to End-Of-File.
Cron master protocol handler.
CONF_SECTION * server_cs
server CS for this listener
Definition proto_cron.h:38
static const conf_parser_t crontab_listen_config[]
fr_client_t * client
static client
char const * name
socket name
static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len, size_t *leftover)
static int mod_decode(void const *instance, request_t *request, UNUSED uint8_t *const data, UNUSED size_t data_len)
Decode the packet.
static size_t time_names_len
static void do_cron(fr_timer_list_t *tl, fr_time_t now, void *uctx)
fr_timer_t * ev
for writing statistics
char const * filename
where to read input packet from
fr_time_t recv_time
when the timer hit.
fr_event_list_t * el
event list
proto_cron_t * parent
unsigned int max
struct proto_cron_tab_s proto_cron_crontab_t
static int time_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static ssize_t mod_write(UNUSED fr_listen_t *li, UNUSED void *packet_ctx, UNUSED fr_time_t request_time, UNUSED uint8_t *buffer, size_t buffer_len, UNUSED size_t written)
fr_listen_t * parent
master IO handler
unsigned int min
static void mod_event_list_set(fr_listen_t *li, fr_event_list_t *el, void *nr)
Set the event list for a new socket.
static int mod_open(fr_listen_t *li)
Open a crontab listener.
fr_app_io_t proto_cron_crontab
bool suspended
we suspend reading from the FD.
static bool get_next(struct tm *tm, cron_tab_t const *tab)
static int parse_field(CONF_ITEM *ci, char const **start, char const *name, cron_tab_t *tab, unsigned int min, unsigned int max, size_t offset)
CONF_SECTION * cs
our configuration
char const * spec
crontab spec
proto_cron_crontab_t const * inst
static char const * mod_name(fr_listen_t *li)
static int mod_close(fr_listen_t *li)
Close a virtual listener.
static int mod_instantiate(module_inst_ctx_t const *mctx)
fr_network_t * nr
network handler
static fr_table_ptr_sorted_t time_names[]
fr_dict_t const * dict
our namespace.
static fr_client_t * mod_client_find(fr_listen_t *li, UNUSED fr_ipaddr_t const *ipaddr, UNUSED int ipproto)
fr_pair_list_t pair_list
for input packet
#define fr_assert(_expr)
Definition rad_assert.h:37
static int ipproto
#define DEBUG2(fmt,...)
static bool done
Definition radclient.c:80
static rs_t * conf
Definition radsniff.c:52
uint32_t fr_rand(void)
Return a 32-bit random number.
Definition rand.c:104
#define REQUEST_VERIFY(_x)
Definition request.h:310
static char const * name
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
#define fr_skip_whitespace(_p)
Skip whitespace ('\t', '\n', '\v', '\f', '\r', ' ')
Definition skip.h:36
eap_aka_sim_process_conf_t * inst
fr_pair_t * vp
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
#define fr_table_value_by_str(_table, _name, _def)
Convert a string to a value using a sorted or ordered table.
Definition table.h:685
An element in a lexicographically sorted array of name to ptr mappings.
Definition table.h:65
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_sec(int64_t sec)
Definition time.h:590
#define fr_time_add(_a, _b)
Add a time/time delta together.
Definition time.h:196
"server local" time.
Definition time.h:69
int fr_timer_delete(fr_timer_t **ev_p)
Delete a timer event and free its memory.
Definition timer.c:692
An event timer list.
Definition timer.c:49
A timer event.
Definition timer.c:83
#define fr_timer_at(...)
Definition timer.h:81
static fr_event_list_t * el
static fr_slen_t parent
Definition pair.h:858
static fr_socket_t * fr_socket_addr_alloc_inet_src(TALLOC_CTX *ctx, int proto, int ifindex, fr_ipaddr_t const *ipaddr, int port)
A variant of fr_socket_addr_init_inet_src will also allocates a fr_socket_t.
Definition socket.h:249
int af
AF_INET, AF_INET6, or AF_UNIX.
Definition socket.h:83
static void fr_socket_addr_swap(fr_socket_t *dst, fr_socket_t const *src)
Swap src/dst information of a fr_socket_t.
Definition socket.h:126
static fr_slen_t data
Definition value.h:1340
static size_t char ** out
Definition value.h:1030
fr_dict_t const * virtual_server_dict_by_child_ci(CONF_ITEM const *ci)
Return the namespace for a given virtual server specified by a CONF_ITEM within the virtual server.