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