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