The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
rlm_radius.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 (at
5 * 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: ee500bd3864bbc86675278142dacdddfc2e79df2 $
19 * @file rlm_radius.c
20 * @brief A RADIUS client library.
21 *
22 * @copyright 2016 The FreeRADIUS server project
23 * @copyright 2016 Network RADIUS SAS
24 */
25RCSID("$Id: ee500bd3864bbc86675278142dacdddfc2e79df2 $")
26
27#include <freeradius-devel/io/application.h>
28#include <freeradius-devel/server/modpriv.h>
29#include <freeradius-devel/unlang/xlat_func.h>
30#include <freeradius-devel/util/debug.h>
31#include <freeradius-devel/util/dlist.h>
32
33#include "rlm_radius.h"
34
35static int mode_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
36static int type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
37static int status_check_type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
38static int status_check_update_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
40
47
48/*
49 * "update" is not required.
50 *
51 * RFC 5997 Section 3 does not require the administrator provide anything:
52 * a Status-Server MUST carry Message-Authenticator, which the module adds
53 * to every packet, MAY carry NAS-Identifier and a NAS address, and SHOULD
54 * NOT carry anything else. status_check_alloc() supplies the
55 * NAS-Identifier when the map is empty, so a conformant packet does not
56 * need additional attributes.
57 */
62 { FR_CONF_OFFSET("num_answers_to_alive", rlm_radius_t, num_answers_to_alive), .dflt = STRINGIFY(3) },
63
65};
66
67/*
68 * Retransmission intervals for the packets we support.
69 */
71 { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_ACCESS_REQUEST].irt), .dflt = STRINGIFY(2) },
72 { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrt), .dflt = STRINGIFY(16) },
73 { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrc), .dflt = STRINGIFY(5) },
74 { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrd), .dflt = STRINGIFY(30) },
76};
77
79 { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].irt), .dflt = STRINGIFY(2) },
80 { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrt), .dflt = STRINGIFY(5) },
81 { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrc), .dflt = STRINGIFY(1) },
82 { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrd), .dflt = STRINGIFY(30) },
84};
85
87 { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_STATUS_SERVER].irt), .dflt = STRINGIFY(2) },
88 { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_STATUS_SERVER].mrt), .dflt = STRINGIFY(5) },
89 { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_STATUS_SERVER].mrc), .dflt = STRINGIFY(5) },
90 { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_STATUS_SERVER].mrd), .dflt = STRINGIFY(30) },
92};
93
95 { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_COA_REQUEST].irt), .dflt = STRINGIFY(2) },
96 { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_COA_REQUEST].mrt), .dflt = STRINGIFY(16) },
97 { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_COA_REQUEST].mrc), .dflt = STRINGIFY(5) },
98 { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_COA_REQUEST].mrd), .dflt = STRINGIFY(30) },
100};
101
103 { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].irt), .dflt = STRINGIFY(2) },
104 { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrt), .dflt = STRINGIFY(16) },
105 { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrc), .dflt = STRINGIFY(5) },
106 { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrd), .dflt = STRINGIFY(30) },
108};
109
115
116/*
117 * We only parse the pool options if we're connected.
118 */
120 { FR_CONF_POINTER("status_check", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) status_check_config },
121
122 { FR_CONF_OFFSET_SUBSECTION("pool", 0, rlm_radius_t, trunk_conf, trunk_config ) },
123
124 { FR_CONF_POINTER("udp", 0, CONF_FLAG_SUBSECTION | CONF_FLAG_OPTIONAL, NULL), .subcs = (void const *) transport_config },
125
126 { FR_CONF_POINTER("tcp", 0, CONF_FLAG_SUBSECTION | CONF_FLAG_OPTIONAL, NULL), .subcs = (void const *) transport_config },
127
129};
130
131/*
132 * We only parse the pool options if we're connected.
133 */
134static conf_parser_t const pool_config[] = {
135 { FR_CONF_POINTER("status_check", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) status_check_config },
136
137 { FR_CONF_OFFSET_SUBSECTION("pool", 0, rlm_radius_t, trunk_conf, trunk_config ) },
138
140};
141
142/*
143 * A mapping of configuration file names to internal variables.
144 */
145static conf_parser_t const module_config[] = {
146 { FR_CONF_OFFSET_FLAGS("mode", CONF_FLAG_REQUIRED, rlm_radius_t, mode), .func = mode_parse, .dflt = "proxy" },
147
149
151 .func = type_parse },
152
153 { FR_CONF_OFFSET("max_packet_size", rlm_radius_t, max_packet_size), .dflt = "4096" },
154 { FR_CONF_OFFSET("max_send_coalesce", rlm_radius_t, max_send_coalesce), .dflt = "1024" },
155
156 { FR_CONF_OFFSET("max_attributes", rlm_radius_t, max_attributes), .dflt = STRINGIFY(RADIUS_MAX_ATTRIBUTES) },
157
158 { FR_CONF_OFFSET("require_message_authenticator", rlm_radius_t, require_message_authenticator),
159 .func = cf_table_parse_int,
161 .dflt = "no" },
162
163 { FR_CONF_OFFSET("track_load_balance", rlm_radius_t, track_load_balance), },
164
165 { FR_CONF_OFFSET("response_window", rlm_radius_t, response_window), .dflt = STRINGIFY(20) },
166
167 { FR_CONF_OFFSET("zombie_period", rlm_radius_t, zombie_period), .dflt = STRINGIFY(40) },
168
169 { FR_CONF_OFFSET("revive_interval", rlm_radius_t, revive_interval) },
170
171 { FR_CONF_OFFSET("home_server_lifetime", rlm_radius_t, home_server_lifetime) },
172
174};
175
177 [FR_RADIUS_CODE_ACCESS_REQUEST] = { FR_CONF_POINTER("Access-Request", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) auth_config },
178
179 [FR_RADIUS_CODE_ACCOUNTING_REQUEST] = { FR_CONF_POINTER("Accounting-Request", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) acct_config },
180 [FR_RADIUS_CODE_STATUS_SERVER] = { FR_CONF_POINTER("Status-Server", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) status_config },
181 [FR_RADIUS_CODE_COA_REQUEST] = { FR_CONF_POINTER("CoA-Request", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) coa_config },
182 [FR_RADIUS_CODE_DISCONNECT_REQUEST] = { FR_CONF_POINTER("Disconnect-Request", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) disconnect_config },
183};
184
185static fr_dict_t const *dict_radius;
186
189 { .out = &dict_radius, .proto = "radius" },
191};
192
198
208
211 { .out = &attr_chap_challenge, .name = "CHAP-Challenge", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
212 { .out = &attr_chap_password, .name = "CHAP-Password", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
213 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_radius },
214 { .out = &attr_proxy_state, .name = "Proxy-State", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
215 { .out = &attr_state, .name = "State", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
216
217 { .out = &attr_error_cause, .name = "Error-Cause", .type = FR_TYPE_UINT32, .dict = &dict_radius },
218 { .out = &attr_event_timestamp, .name = "Event-Timestamp", .type = FR_TYPE_DATE, .dict = &dict_radius},
219 { .out = &attr_extended_attribute_1, .name = "Extended-Attribute-1", .type = FR_TYPE_TLV, .dict = &dict_radius},
220 { .out = &attr_message_authenticator, .name = "Message-Authenticator", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
221 { .out = &attr_eap_message, .name = "EAP-Message", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
222 { .out = &attr_nas_identifier, .name = "NAS-Identifier", .type = FR_TYPE_STRING, .dict = &dict_radius},
223 { .out = &attr_original_packet_code, .name = "Extended-Attribute-1.Original-Packet-Code", .type = FR_TYPE_UINT32, .dict = &dict_radius},
224 { .out = &attr_response_length, .name = "Extended-Attribute-1.Response-Length", .type = FR_TYPE_UINT32, .dict = &dict_radius },
225 { .out = &attr_user_password, .name = "User-Password", .type = FR_TYPE_STRING, .dict = &dict_radius},
226
228};
229
230#include "bio.c"
231
233 { L("client"), RLM_RADIUS_MODE_CLIENT },
234 { L("dynamic-proxy"), RLM_RADIUS_MODE_XLAT_PROXY },
235 { L("proxy"), RLM_RADIUS_MODE_PROXY },
236 { L("replicate"), RLM_RADIUS_MODE_REPLICATE },
237 { L("unconnected-replicate"), RLM_RADIUS_MODE_UNCONNECTED_REPLICATE },
238};
240
241
242/** Set the mode of operation
243 *
244 * @param[in] ctx to allocate data in (instance of rlm_radius).
245 * @param[out] out Where to write the parsed data.
246 * @param[in] parent Base structure address.
247 * @param[in] ci #CONF_PAIR specifying the name of the type module.
248 * @param[in] rule unused.
249 * @return
250 * - 0 on success.
251 * - -1 on failure.
252 */
253static int mode_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent,
254 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
255{
256 char const *name = cf_pair_value(cf_item_to_pair(ci));
258 rlm_radius_t *inst = talloc_get_type_abort(parent, rlm_radius_t);
260
262
263 if (mode == RLM_RADIUS_MODE_INVALID) {
264 cf_log_err(ci, "Invalid mode name \"%s\"", name);
265 return -1;
266 }
267
268 *(rlm_radius_mode_t *) out = mode;
269
270 /*
271 * Normally we want connected sockets, in which case we push additional configuration for
272 * connected sockets.
273 */
274 switch (mode) {
275 default:
276 inst->fd_config.type = FR_BIO_FD_CONNECTED;
277
278 if (cf_section_rules_push(cs, connected_config) < 0) return -1;
279 break;
280
282 inst->fd_config.type = FR_BIO_FD_UNCONNECTED; /* reset later when the home server is allocated */
283
284 if (cf_section_rules_push(cs, pool_config) < 0) return -1;
285 break;
286
288 inst->fd_config.type = FR_BIO_FD_UNCONNECTED;
289 break;
290 }
291
292 return 0;
293}
294
295
296/** Set which types of packets we can parse
297 *
298 * @param[in] ctx to allocate data in (instance of rlm_radius).
299 * @param[out] out Where to write the parsed data.
300 * @param[in] parent Base structure address.
301 * @param[in] ci #CONF_PAIR specifying the name of the type module.
302 * @param[in] rule unused.
303 * @return
304 * - 0 on success.
305 * - -1 on failure.
306 */
307static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
308 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
309{
310 char const *type_str = cf_pair_value(cf_item_to_pair(ci));
312 fr_dict_enum_value_t const *type_enum;
313 uint32_t code;
314
315 /*
316 * Must be the RADIUS module
317 */
318 fr_assert(cs && (strcmp(cf_section_name1(cs), "radius") == 0));
319
320 /*
321 * Allow the process module to be specified by
322 * packet type.
323 */
324 type_enum = fr_dict_enum_by_name(attr_packet_type, type_str, -1);
325 if (!type_enum) {
326 invalid_code:
327 cf_log_err(ci, "Unknown or invalid RADIUS packet type '%s'", type_str);
328 return -1;
329 }
330
331 code = type_enum->value->vb_uint32;
332
333 /*
334 * Status-Server packets cannot be proxied.
335 */
336 if (code == FR_RADIUS_CODE_STATUS_SERVER) {
337 cf_log_err(ci, "Invalid setting of 'type = Status-Server'. Status-Server packets cannot be proxied.");
338 return -1;
339 }
340
341 if (!code ||
342 (code >= FR_RADIUS_CODE_MAX)) goto invalid_code;
343
344 if (!type_interval_config[code].name1) {
345 cf_log_err(ci, "Invalid packet type '%s' - cannot proxy a response packet", type_str);
346 return -1;
347 }
348
349 /*
350 * If we're doing async proxying, push the timers for the
351 * various packet types.
352 */
354
355 *(uint32_t *) out = code;
356
357 return 0;
358}
359
360/** Allow for Status-Server ping checks
361 *
362 * @param[in] ctx to allocate data in (instance of proto_radius).
363 * @param[out] out Where to write our parsed data.
364 * @param[in] parent Base structure address.
365 * @param[in] ci #CONF_PAIR specifying the name of the type module.
366 * @param[in] rule unused.
367 * @return
368 * - 0 on success.
369 * - -1 on failure.
370 */
371static int status_check_type_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
372 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
373{
374 char const *type_str = cf_pair_value(cf_item_to_pair(ci));
376 fr_dict_enum_value_t const *type_enum;
377 uint32_t code;
378
379 /*
380 * Allow the process module to be specified by
381 * packet type.
382 */
383 type_enum = fr_dict_enum_by_name(attr_packet_type, type_str, -1);
384 if (!type_enum) {
385 invalid_code:
386 cf_log_err(ci, "Unknown or invalid RADIUS packet type '%s'", type_str);
387 return -1;
388 }
389
390 code = type_enum->value->vb_uint32;
391
392 /*
393 * Cheat, and reuse the "type" array for allowed packet
394 * types.
395 */
396 if (!code ||
397 (code >= FR_RADIUS_CODE_MAX) ||
398 (!type_interval_config[code].name1)) goto invalid_code;
399
400 /*
401 * Add irt / mrt / mrd / mrc parsing, in the parent
402 * configuration section.
403 */
405
406 memcpy(out, &code, sizeof(code));
407
409
410 return 0;
411}
412
413static int status_check_verify(map_t *map, void *ctx)
414{
416 fr_dict_attr_t const *da;
417
419
420 if (unlang_fixup_update(map, NULL) < 0) return -1;
421
422 if (!map->rhs) return 0;
423
424 if (tmpl_is_xlat(map->rhs)) {
425 if (xlat_impure_func(tmpl_xlat(map->rhs))) {
426 invalid_xlat:
427 cf_log_err(map->ci, "Cannot assign dynamic values here");
428 return -1;
429 }
430 } else if (!tmpl_is_data(map->rhs)) {
431 goto invalid_xlat;
432 }
433
434 da = tmpl_attr_tail_da(map->lhs);
435
436 /*
437 * Ignore internal attributes.
438 */
439 if (da->flags.internal) {
440 cf_log_err(map->ci, "Cannot use internal attributes");
441 return -1;
442 }
443
444 /*
445 * Ignore signalling attributes. They shouldn't exist.
446 */
447 if ((da == attr_proxy_state) ||
449 cannot_use:
450 cf_log_err(map->ci, "Cannot use %s here.", da->name);
451 return -1;
452 }
453
454 /*
455 * Allow passwords only in Access-Request packets.
456 */
457 if ((inst->status_check != FR_RADIUS_CODE_ACCESS_REQUEST) &&
458 ((da == attr_user_password) || (da == attr_chap_password) || (da == attr_eap_message))) {
459 goto cannot_use;
460 }
461
462 return 0;
463}
464
465/** Allow the admin to set packet contents for Status-Server ping checks
466 *
467 * @param[in] ctx to allocate data in (instance of proto_radius).
468 * @param[out] out Where to write our parsed data
469 * @param[in] parent Base structure address.
470 * @param[in] ci #CONF_SECTION specifying the things to update
471 * @param[in] rule unused.
472 * @return
473 * - 0 on success.
474 * - -1 on failure.
475 */
476static int status_check_update_parse(TALLOC_CTX *ctx, void *out, void *parent,
477 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
478{
479 int rcode;
480 CONF_SECTION *cs;
481 char const *name2;
482 map_list_t *head = (map_list_t *)out;
483
485 map_list_init(head);
486
487 cs = cf_item_to_section(ci);
488 name2 = cf_section_name2(cs);
489 if (name2 && (strcmp(name2, "request") != 0)) {
490 cf_log_err(cs, "Only 'request' can be specified as the destination list");
491 return -1;
492 }
493
494 /*
495 * Compile the "update" section.
496 */
497 {
498 tmpl_rules_t parse_rules = {
499 .attr = {
501 .namespace = fr_dict_root(dict_radius),
502 .list_def = request_attr_request,
503 .list_presence = TMPL_ATTR_LIST_FORBID,
504 },
505 .literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
506 };
507
508 rcode = map_afrom_cs(ctx, head, cs, &parse_rules, &parse_rules, status_check_verify, parent, 128);
509 if (rcode < 0) return -1; /* message already printed */
510
511 /*
512 * status_check_alloc() supplies a NAS-Identifier when the
513 * map is empty, so an empty map needs no error here.
514 */
515 }
516
517 /*
518 * Rely on "bootstrap" to do sanity checks between 'type
519 * = Access-Request', and 'update' containing passwords.
520 */
521 return 0;
522}
523
524
525/** Do any RADIUS-layer fixups for proxying.
526 *
527 */
529{
530 fr_pair_t *vp;
531
532 /*
533 * If we received a Status-Server packet from the network, then don't proxy it.
534 *
535 * But we do sneakily allow virtual servers to originate and then send Status-Server packets.
536 */
537 if ((request->packet->code == FR_RADIUS_CODE_STATUS_SERVER) &&
538 ((request->packet->socket.af == AF_INET) || (request->packet->socket.af == AF_INET6))) {
539 RWDEBUG("Status-Server is reserved for internal use, and cannot be proxied.");
540 return 0;
541 }
542
543 if (!inst->allowed[request->packet->code]) {
544 REDEBUG("Packet code %s is disallowed by the configuration",
545 fr_radius_packet_name[request->packet->code]);
546 return -1;
547 }
548
549 /*
550 * Check for proxy loops.
551 *
552 * There should _never_ be two instances of the same Proxy-State in the packet.
553 */
554 if ((inst->mode == RLM_RADIUS_MODE_PROXY) && RDEBUG_ENABLED) {
555 unsigned int count = 0;
556 fr_dcursor_t cursor;
557
558 for (vp = fr_pair_dcursor_by_da_init(&cursor, &request->request_pairs, attr_proxy_state);
559 vp;
560 vp = fr_dcursor_next(&cursor)) {
561 if (vp->vp_length != sizeof(inst->common_ctx.proxy_state)) continue;
562
563 if (memcmp(vp->vp_octets, &inst->common_ctx.proxy_state,
564 sizeof(inst->common_ctx.proxy_state)) == 0) {
565
566 /*
567 * Cancel proxying when there are two instances of the same Proxy-State
568 * in the packet. This limitation could be configurable, but it likely
569 * doesn't make sense to make it configurable.
570 */
571 if (count == 1) {
572 RWARN("Canceling proxy due to loop of multiple %pV", vp);
573 return -1;
574 }
575
576 RWARN("Proxied packet contains our own %pV", vp);
577 RWARN("Check if there is a proxy loop. Perhaps the server has been configured to proxy to itself.");
578 count++;
579 }
580 }
581 }
582
583 if (request->packet->code != FR_RADIUS_CODE_ACCESS_REQUEST) return 0;
584
585 if (fr_pair_find_by_da(&request->request_pairs, NULL, attr_chap_password) &&
586 !fr_pair_find_by_da(&request->request_pairs, NULL, attr_chap_challenge)) {
588 fr_pair_value_memdup(vp, request->packet->vector, sizeof(request->packet->vector), true);
589 }
590
591 return 0;
592}
593
594
595/** Send packets outbound.
596 *
597 */
599{
601 bio_thread_t *thread = talloc_get_type_abort(mctx->thread, bio_thread_t);
602 fr_client_t *client;
603 int rcode;
604 bio_request_t *u = NULL;
605 fr_retry_config_t const *retry_config = NULL;
606
607 if (!request->packet->code) {
608 REDEBUG("You MUST specify a packet code");
610 }
611
612 if ((request->packet->code >= FR_RADIUS_CODE_MAX) ||
613 !fr_time_delta_ispos(inst->retry[request->packet->code].irt)) { /* can't be zero */
614 REDEBUG("Invalid packet code %u", request->packet->code);
616 }
617
618 /*
619 * Unconnected sockets use %radius.sendto.ipaddr(ip, port, secret)
620 */
622 (inst->mode == RLM_RADIUS_MODE_XLAT_PROXY)) {
623 REDEBUG("When using 'mode = %s', this module cannot be used in-place. "
624 "Instead, it must be called via a function call",
625 fr_table_str_by_value(mode_names, inst->mode, "<INVALID>"));
627 }
628
630 if (client && client->dynamic && !client->active) {
631 REDEBUG("Cannot proxy packets which define dynamic clients");
633 }
634
635 /*
636 * Push the request and it's data to the IO submodule.
637 *
638 * This may return YIELD, for "please yield", or it may
639 * return another code which indicates what happened to
640 * the request...
641 */
642 rcode = mod_enqueue(&u, &retry_config, inst, thread->ctx.trunk, request);
643 if (rcode == 0) RETURN_UNLANG_NOOP;
644 if (rcode < 0) RETURN_UNLANG_FAIL;
645
647}
648
649
650static int mod_instantiate(module_inst_ctx_t const *mctx)
651{
652 size_t i, num_types;
653 rlm_radius_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_radius_t);
654 CONF_SECTION *conf = mctx->mi->conf;
655
656 inst->name = mctx->mi->name;
657 inst->received_message_authenticator = talloc_zero(NULL, bool); /* Allocated outside of inst to default protection */
658
659 /*
660 * Replication is write-only, and append by default.
661 */
662 if (inst->mode == RLM_RADIUS_MODE_REPLICATE) {
663 if (inst->fd_config.filename && (inst->fd_config.flags != O_WRONLY)) {
664 cf_log_info(conf, "Setting 'flags = write-only' for writing to a file");
665 }
666 inst->fd_config.flags = O_WRONLY | O_APPEND;
667
668 } else if (inst->fd_config.filename) {
669 cf_log_err(conf, "When using an output 'filename', you MUST set 'mode = replicate'");
670 return -1;
671
672 } else {
673 /*
674 * All other IO is read+write.
675 */
676 inst->fd_config.flags = O_RDWR;
677 }
678
679 if (fr_bio_fd_check_config(&inst->fd_config) < 0) {
680 cf_log_perr(conf, "Invalid configuration");
681 return -1;
682 }
683
684 /*
685 * Clamp max_packet_size first before checking recv_buff and send_buff
686 */
687 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, >=, 64);
688 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, <=, 65535);
689
690 /*
691 * Check invalid configurations.
692 */
693 switch (inst->mode) {
694 default:
695 /*
696 * Filenames are write-only, and cannot get response packets.
697 */
698 if (inst->fd_config.filename) {
699 cf_log_err(conf, "Cannot set 'filename' here - it is only supported for 'mode=replicate'");
700 return -1;
701 }
702
703 /*
704 * When we expect replies, we need to be able to open multiple source ports. So the
705 * admin can't force a particular source port.
706 */
707 if (inst->fd_config.src_port) {
708 cf_log_err(conf, "Cannot 'src_port' here - it can only be set for replicating packets");
709 return -1;
710 }
711
712 /*
713 * Encorce limits per trunk, due to the 8-bit ID space.
714 */
715 FR_INTEGER_BOUND_CHECK("trunk.per_connection_max", inst->trunk_conf.max_req_per_conn, >=, 2);
716 FR_INTEGER_BOUND_CHECK("trunk.per_connection_max", inst->trunk_conf.max_req_per_conn, <=, 255);
717 FR_INTEGER_BOUND_CHECK("trunk.per_connection_target", inst->trunk_conf.target_req_per_conn, <=, inst->trunk_conf.max_req_per_conn / 2);
718
719 /*
720 * This only applies for XLAT_PROXY, but what the heck.
721 */
722 FR_TIME_DELTA_BOUND_CHECK("home_server_lifetime", inst->home_server_lifetime, >=, fr_time_delta_from_sec(10));
723 FR_TIME_DELTA_BOUND_CHECK("home_server_lifetime", inst->home_server_lifetime, <=, fr_time_delta_from_sec(3600));
724
725 /*
726 * No src_port range, we don't need to check any other settings.
727 */
728 if (!inst->fd_config.src_port_start && !inst->fd_config.src_port_end) break;
729
730 if (inst->fd_config.path) {
731 cf_log_err(conf, "Cannot set 'src_port_start' or 'src_port_end' for outgoing Unix sockets");
732 return -1;
733 }
734
735 /*
736 * Cross-check src_port, src_port_start, and src_port_end.
737 */
738 if (inst->fd_config.src_port_start) {
739 if (!inst->fd_config.src_port_end) {
740 cf_log_err(conf, "Range has 'src_port_start', but is missing 'src_port_end'");
741 return -1;
742 }
743
744 if (inst->fd_config.src_port_start >= inst->fd_config.src_port_end) {
745 cf_log_err(conf, "Range has invalid values for 'src_port_start' ... 'src_port_end'");
746 return -1;
747 }
748
749 } else if (inst->fd_config.src_port_end) {
750 cf_log_err(conf, "Range has 'src_port_end', but is missing 'src_port_start'");
751 return -1;
752 }
753
754 /*
755 * The source port range is split by worker - so there needs to be sufficient for at least
756 * one per worker.
757 */
758 if ((inst->fd_config.src_port_end - inst->fd_config.src_port_start + 1) < (int) main_config->max_workers) {
759 cf_log_perr(conf, "src_port_start / end range is not enough for %u worker threads",
761 return -1;
762 }
763
764 /*
765 * If there is a limited source port range, then set the reuse port flag. This lets us
766 * bind multiple sockets to the same port before we connect() them.
767 */
768 inst->fd_config.reuse_port = 1;
769 break;
770
772 /*
773 * Replication to dynamic filenames or dynamic unix sockets isn't supported.
774 */
775 if (inst->fd_config.filename || inst->fd_config.path) {
776 cf_log_err(conf, "Cannot set 'filename' or 'path' when using 'mode=unconnected-replicate'");
777 return -1;
778 }
779
780 /*
781 * Unconnected replicate has to use UDP.
782 */
783 if (inst->fd_config.socket_type != SOCK_DGRAM) {
784 cf_log_err(conf, "Cannot use TCP sockets with 'mode=unconnected-replicate'");
785 return -1;
786 }
787
789
791 /*
792 * We can force the source port, but then we have to set SO_REUSEPORT.
793 */
794 inst->fd_config.reuse_port = (inst->fd_config.src_port != 0);
795
796 /*
797 * Files and unix sockets are OK. The src_port can be set (or not), and that's fine.
798 */
799 if (inst->fd_config.src_port_start || inst->fd_config.src_port_end) {
800 cf_log_err(conf, "Cannot set 'src_port_start' or 'src_port_end' when replicating packets");
801 return -1;
802 }
803 break;
804 }
805
806 /*
807 * We allow what may otherwise be conflicting configurations, because the BIO code will pick one
808 * path, and the conflicts won't affect anything else. Only the src_port range is special.
809 */
810
811 FR_TIME_DELTA_BOUND_CHECK("response_window", inst->response_window, >=, fr_time_delta_from_sec(1));
812 FR_TIME_DELTA_BOUND_CHECK("response_window", inst->response_window, <=, fr_time_delta_from_sec(120));
813
814 FR_TIME_DELTA_BOUND_CHECK("zombie_period", inst->zombie_period, >=, fr_time_delta_from_sec(1));
815 FR_TIME_DELTA_BOUND_CHECK("zombie_period", inst->zombie_period, <=, fr_time_delta_from_sec(120));
816
817 if (!inst->status_check) {
818 FR_TIME_DELTA_BOUND_CHECK("revive_interval", inst->revive_interval, >=, fr_time_delta_from_sec(10));
819 FR_TIME_DELTA_BOUND_CHECK("revive_interval", inst->revive_interval, <=, fr_time_delta_from_sec(3600));
820 }
821
822 num_types = talloc_array_length(inst->types);
823 fr_assert(num_types > 0);
824
825 inst->timeout_retry = (fr_retry_config_t) {
826 .mrc = 1,
827 .mrd = inst->response_window,
828 };
829
830 inst->common_ctx = (fr_radius_ctx_t) {
831 .secret = inst->secret,
832 .secret_length = inst->secret ? talloc_strlen(inst->secret) : 0,
833 .proxy_state = ((uint64_t) fr_rand()) << 32 | fr_rand(),
834 };
835
836 /*
837 * Allow for O(1) lookup later...
838 */
839 for (i = 0; i < num_types; i++) {
840 uint32_t code;
841
842 code = inst->types[i];
843 fr_assert(code > 0);
845
846 if (inst->allowed[code]) {
847 cf_log_err(conf, "Duplicate 'type = %s'", fr_radius_packet_name[code]);
848 return -1;
849 }
850
851 inst->allowed[code] = true;
852 }
853
854 fr_assert(inst->status_check < FR_RADIUS_CODE_MAX);
855
856 /*
857 * If we're replicating, we don't care if the other end
858 * is alive.
859 */
860 if (inst->status_check) {
861 if (inst->mode == RLM_RADIUS_MODE_REPLICATE) {
862 cf_log_warn(conf, "Ignoring 'status_check = %s' due to 'mode = replicate'",
863 fr_radius_packet_name[inst->status_check]);
864 inst->status_check = false;
865
866 } else if ((inst->mode == RLM_RADIUS_MODE_UNCONNECTED_REPLICATE) ||
867 (inst->mode == RLM_RADIUS_MODE_XLAT_PROXY)) {
868 cf_log_warn(conf, "Ignoring 'status_check = %s' due to 'mode' setting",
869 fr_radius_packet_name[inst->status_check]);
870 inst->status_check = false;
871 }
872 }
873
874 /*
875 * If we have status checks, then do some sanity checks.
876 * Status-Server is always allowed. Otherwise, the
877 * status checks have to match one of the allowed
878 * packets.
879 */
880 if (inst->status_check) {
881 if (inst->status_check == FR_RADIUS_CODE_STATUS_SERVER) {
882 inst->allowed[inst->status_check] = true;
883
884 } else if (!inst->allowed[inst->status_check]) {
885 cf_log_err(conf, "Using 'status_check = %s' requires also 'type = %s'",
886 fr_radius_packet_name[inst->status_check], fr_radius_packet_name[inst->status_check]);
887 return -1;
888 }
889
890 /*
891 * @todo - check the contents of the "update"
892 * section, to be sure that (e.g.) Access-Request
893 * contains User-Name, etc.
894 */
895
896 if (inst->fd_config.filename) {
897 cf_log_info(conf, "Disabling status checks for output file %s", inst->fd_config.filename);
898 inst->status_check = 0;
899 }
900 }
901
902 /*
903 * Files and unix sockets can just have us call write().
904 */
905 if (inst->fd_config.filename || inst->fd_config.path) {
906 inst->max_send_coalesce = 1;
907 }
908
909 inst->trunk_conf.req_pool_headers = 4; /* One for the request, one for the buffer, one for the tracking binding, one for Proxy-State VP */
910 inst->trunk_conf.req_pool_size = 1024 + sizeof(fr_pair_t) + 20;
911
912 if (inst->trunk_conf.conn_triggers) {
914 char *server = NULL;
915
917 .module = mctx->mi->module->name,
918 .name = inst->name
919 };
920
921 /*
922 * Only client and proxy mode have fixed destinations
923 */
924 if ((inst->mode == RLM_RADIUS_MODE_CLIENT) || (inst->mode == RLM_RADIUS_MODE_PROXY)) {
925 fr_value_box_aprint(inst, &server, fr_box_ipaddr(inst->fd_config.dst_ipaddr), NULL);
926 args.server = server;
927 args.port = inst->fd_config.dst_port;
928 }
929
930 MEM(inst->trigger_args = fr_pair_list_alloc(inst));
931 if (module_trigger_args_build(inst->trigger_args, inst->trigger_args,
932 cf_section_find(conf, "pool", NULL), &args) < 0) return -1;
933 }
934
935 /*
936 * Only check the async timers when we're acting as a client.
937 */
938 if (inst->mode != RLM_RADIUS_MODE_CLIENT) {
939 return 0;
940 }
941
942 /*
943 * Set limits on retransmission timers
944 */
945 if (inst->allowed[FR_RADIUS_CODE_ACCESS_REQUEST]) {
946 FR_TIME_DELTA_BOUND_CHECK("Access-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].irt, >=, fr_time_delta_from_sec(1));
947 FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
948 FR_INTEGER_BOUND_CHECK("Access-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrc, >=, 1);
949 FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrd, >=, fr_time_delta_from_sec(5));
950
951 FR_TIME_DELTA_BOUND_CHECK("Access-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].irt, <=, fr_time_delta_from_sec(15));
952 FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrt, <=, fr_time_delta_from_sec(30));
953 FR_INTEGER_BOUND_CHECK("Access-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrc, <=, 10);
954 FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrd, <=, fr_time_delta_from_sec(90));
955 }
956
957 /*
958 * Note that RFC 5080 allows for Accounting-Request to
959 * have mrt=mrc=mrd = 0, which means "retransmit
960 * forever". We allow that, with the restriction that
961 * the server core will automatically free the request at
962 * request.timeout.
963 */
965 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].irt, >=, fr_time_delta_from_sec(1));
966#if 0
967 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
968 FR_INTEGER_BOUND_CHECK("Accounting-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrc, >=, 0);
969 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrd, >=, fr_time_delta_from_sec(0));
970#endif
971
972 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].irt, <=, fr_time_delta_from_sec(5));
973 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrt, <=, fr_time_delta_from_sec(30));
974 FR_INTEGER_BOUND_CHECK("Accounting-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrc, <=, 10);
975 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
976 }
977
978 /*
979 * Status-Server
980 */
981 if (inst->allowed[FR_RADIUS_CODE_STATUS_SERVER]) {
982 FR_TIME_DELTA_BOUND_CHECK("Status-Server.initial_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].irt, >=, fr_time_delta_from_sec(1));
983 FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrt, >=, fr_time_delta_from_sec(5));
984 FR_INTEGER_BOUND_CHECK("Status-Server.max_rtx_count", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrc, >=, 1);
985 FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_duration", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrd, >=, fr_time_delta_from_sec(5));
986
987 FR_TIME_DELTA_BOUND_CHECK("Status-Server.initial_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].irt, <=, fr_time_delta_from_sec(5));
988 FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrt, <=, fr_time_delta_from_sec(30));
989 FR_INTEGER_BOUND_CHECK("Status-Server.max_rtx_count", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrc, <=, 10);
990 FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_duration", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrd, <=, fr_time_delta_from_sec(30));
991 }
992
993 /*
994 * CoA
995 */
996 if (inst->allowed[FR_RADIUS_CODE_COA_REQUEST]) {
997 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].irt, >=, fr_time_delta_from_sec(1));
998 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
999 FR_INTEGER_BOUND_CHECK("CoA-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrc, >=, 1);
1000 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrd, >=, fr_time_delta_from_sec(5));
1001
1002 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].irt, <=, fr_time_delta_from_sec(5));
1003 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrt, <=, fr_time_delta_from_sec(60));
1004 FR_INTEGER_BOUND_CHECK("CoA-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrc, <=, 10);
1005 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
1006 }
1007
1008 /*
1009 * Disconnect
1010 */
1012 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].irt, >=, fr_time_delta_from_sec(1));
1013 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
1014 FR_INTEGER_BOUND_CHECK("Disconnect-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrc, >=, 1);
1015 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrd, >=, fr_time_delta_from_sec(5));
1016
1017 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].irt, <=, fr_time_delta_from_sec(5));
1018 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrt, <=, fr_time_delta_from_sec(30));
1019 FR_INTEGER_BOUND_CHECK("Disconnect-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrc, <=, 10);
1020 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
1021 }
1022
1023 return 0;
1024}
1025
1026static int mod_bootstrap(module_inst_ctx_t const *mctx)
1027{
1028 xlat_t *xlat;
1029 rlm_radius_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_radius_t);
1030
1031 switch (inst->mode) {
1033 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "sendto.ipaddr", xlat_radius_replicate, FR_TYPE_VOID);
1035 break;
1036
1038 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "sendto.ipaddr", xlat_radius_client, FR_TYPE_UINT32);
1040 break;
1041
1042 default:
1043 break;
1044 }
1045
1046 return 0;
1047}
1048
1049
1050static int mod_detach(module_detach_ctx_t const *mctx)
1051{
1052 rlm_radius_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_radius_t);
1053
1054 talloc_free(inst->received_message_authenticator);
1055 return 0;
1056}
1057
1058static int mod_load(void)
1059{
1060 if (fr_radius_global_init() < 0) {
1061 PERROR("Failed initialising protocol library");
1062 return -1;
1063 }
1064 return 0;
1065}
1066
1067static void mod_unload(void)
1068{
1070}
1071
1072/*
1073 * The module name should be the only globally exported symbol.
1074 * That is, everything else should be 'static'.
1075 *
1076 * If the module needs to temporarily modify it's instantiation
1077 * data, the type should be changed to MODULE_TYPE_THREAD_UNSAFE.
1078 * The server will then take care of ensuring that the module
1079 * is single-threaded.
1080 */
1083 .common = {
1084 .magic = MODULE_MAGIC_INIT,
1085 .name = "radius",
1086 .inst_size = sizeof(rlm_radius_t),
1088 .dict = &dict_radius,
1089
1090 .onload = mod_load,
1091 .unload = mod_unload,
1092
1093 .bootstrap = mod_bootstrap,
1094 .instantiate = mod_instantiate,
1095 .detach = mod_detach,
1096
1097 .thread_inst_size = sizeof(bio_thread_t),
1098 .thread_inst_type = "bio_thread_t",
1099 .thread_instantiate = mod_thread_instantiate,
1100 },
1101 .method_group = {
1102 .bindings = (module_method_binding_t[]){
1103 { .section = SECTION_NAME(CF_IDENT_ANY, CF_IDENT_ANY), .method = mod_process },
1105 },
1106 }
1107};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
va_list args
Definition acutest.h:917
static uint8_t request[4]
#define RCSID(id)
Definition build.h:560
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:228
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:391
#define STRINGIFY(x)
Definition build.h:216
#define UNUSED
Definition build.h:384
#define NUM_ELEMENTS(_t)
Definition build.h:406
int cf_table_parse_int(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic function for parsing conf pair values as int.
Definition cf_parse.c:1802
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:696
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:650
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
Definition cf_parse.h:556
#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
char const * name2
Second identifier for CONF_SECTION.
Definition cf_parse.h:635
#define cf_section_rules_push(_cs, _rule)
Definition cf_parse.h:728
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
Definition cf_parse.h:334
#define cf_section_rule_push(_cs, _rule)
Definition cf_parse.h:726
#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
#define FR_CONF_OFFSET_REF(_struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition cf_parse.h:321
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition cf_parse.h:309
#define FR_TIME_DELTA_BOUND_CHECK(_name, _var, _op, _bound)
Definition cf_parse.h:567
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition cf_parse.h:450
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition cf_parse.h:467
@ CONF_FLAG_SECRET
Only print value if debug level >= 3.
Definition cf_parse.h:454
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
Definition cf_parse.h:468
@ CONF_FLAG_OPTIONAL
subsection is pushed only if a non-optional matching one is pushed
Definition cf_parse.h:479
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:444
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _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:238
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:633
Common header for all CONF_* types.
Definition cf_priv.h:54
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:1393
char const * cf_section_name1(CONF_SECTION const *cs)
Return the first identifier of a CONF_SECTION.
Definition cf_util.c:1379
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
Definition cf_util.c:1235
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:671
bool cf_item_is_section(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_SECTION.
Definition cf_util.c:605
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition cf_util.c:651
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1746
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:340
#define cf_log_info(_cf, _fmt,...)
Definition cf_util.h:342
#define cf_parent(_cf)
Definition cf_util.h:115
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:347
#define cf_log_warn(_cf, _fmt,...)
Definition cf_util.h:341
#define CF_IDENT_ANY
Definition cf_util.h:80
fr_dict_t * dict
Definition common.c:31
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:288
#define MEM(x)
Definition debug.h:38
@ FR_RADIUS_CODE_ACCESS_REQUEST
RFC2865 - Access-Request.
Definition defs.h:33
@ FR_RADIUS_CODE_DISCONNECT_REQUEST
RFC3575/RFC5176 - Disconnect-Request.
Definition defs.h:46
@ FR_RADIUS_CODE_MAX
Maximum possible protocol code.
Definition defs.h:53
@ FR_RADIUS_CODE_STATUS_SERVER
RFC2865/RFC5997 - Status Server (request)
Definition defs.h:44
@ FR_RADIUS_CODE_COA_REQUEST
RFC3575/RFC5176 - CoA-Request.
Definition defs.h:49
@ FR_RADIUS_CODE_ACCOUNTING_REQUEST
RFC2866 - Accounting-Request.
Definition defs.h:36
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2720
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:316
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:329
fr_value_box_t const * value
Enum value (what name maps to).
Definition dict.h:281
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:335
fr_dict_enum_value_t const * fr_dict_enum_by_name(fr_dict_attr_t const *da, char const *name, ssize_t len)
Definition dict_util.c:3781
Specifies an attribute which must be present for the module to function.
Definition dict.h:315
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:328
Value of an enumerated attribute.
Definition dict.h:277
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
@ FR_BIO_FD_CONNECTED
connected client sockets (UDP or TCP)
Definition fd.h:63
@ FR_BIO_FD_UNCONNECTED
unconnected UDP / datagram only
Definition fd.h:60
const conf_parser_t fr_bio_fd_client_config[]
Definition fd_config.c:314
int fr_bio_fd_check_config(fr_bio_fd_config_t const *cfg)
Checks the configuration without modifying anything.
Definition fd_open.c:991
talloc_free(hp)
bool active
for dynamic clients
Definition client.h:114
bool dynamic
Whether the client was dynamically defined.
Definition client.h:113
Describes a host allowed to send packets to the server.
Definition client.h:80
#define PERROR(_fmt,...)
Definition log.h:233
#define RWDEBUG(fmt,...)
Definition log.h:378
#define RWARN(fmt,...)
Definition log.h:314
int map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION const *cs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, map_validate_t validate, void *uctx, unsigned int max)
Convert a config section into an attribute map.
Definition map.c:1168
main_config_t const * main_config
Main server configuration.
Definition main_config.c:56
uint32_t max_workers
for the scheduler
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_VOID
User data.
@ FR_TYPE_OCTETS
Raw octets.
unsigned int uint32_t
int unlang_fixup_update(map_t *map, void *ctx)
Validate and fixup a map that's part of an update section.
Definition compile.c:346
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
void * thread
Thread specific instance data.
Definition module_ctx.h:43
module_instance_t * mi
Module instance to detach.
Definition module_ctx.h:57
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
Temporary structure to hold arguments for detach calls.
Definition module_ctx.h:56
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
xlat_t * module_rlm_xlat_register(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, char const *name, xlat_func_t func, fr_type_t return_type)
Definition module_rlm.c:234
module_t common
Common fields presented by all modules.
Definition module_rlm.h:39
static int mod_enqueue(bio_request_t **p_u, fr_retry_config_t const **p_retry_config, rlm_radius_t const *inst, trunk_t *trunk, request_t *request)
Definition bio.c:2575
static void mod_retry(module_ctx_t const *mctx, request_t *request, fr_retry_t const *retry)
Handle module retries.
Definition bio.c:1556
bio_handle_ctx_t ctx
common struct for home servers and BIO handles
Definition bio.c:57
static xlat_action_t xlat_radius_replicate(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *args)
Definition bio.c:2834
static xlat_action_t xlat_radius_client(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *args)
Definition bio.c:2984
trunk_t * trunk
trunk handler
Definition bio.c:48
static xlat_arg_parser_t const xlat_radius_send_args[]
Definition bio.c:2824
Connect request_t to local tracking structure.
Definition bio.c:115
int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted)
Copy data into an "octets" data type.
Definition pair.c:2897
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
fr_pair_list_t * fr_pair_list_alloc(TALLOC_CTX *ctx)
Allocate a new pair list on the heap.
Definition pair.c:120
static const conf_parser_t config[]
Definition base.c:162
size_t fr_radius_require_ma_table_len
Definition base.c:93
int fr_radius_global_init(void)
Definition base.c:1313
void fr_radius_global_free(void)
Definition base.c:1337
fr_table_num_sorted_t const fr_radius_require_ma_table[]
Definition base.c:86
char const * fr_radius_packet_name[FR_RADIUS_CODE_MAX]
Definition base.c:115
Functions to support RADIUS bio handlers.
#define fr_assert(_expr)
Definition rad_assert.h:37
static fr_bio_fd_config_t fd_config
static char * secret
#define REDEBUG(fmt,...)
#define RDEBUG_ENABLED()
#define RADIUS_MAX_ATTRIBUTES
Definition radius.h:39
static rs_t * conf
Definition radsniff.c:52
uint32_t fr_rand(void)
Return a 32-bit random number.
Definition rand.c:104
#define RETURN_UNLANG_FAIL
Definition rcode.h:63
#define RETURN_UNLANG_NOOP
Definition rcode.h:69
fr_dict_attr_t const * request_attr_request
Definition request.c:43
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
static unlang_action_t mod_resume(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Resume a yielded module method after its delivery report has arrived.
Definition rlm_kafka.c:477
static conf_parser_t coa_config[]
Definition rlm_radius.c:94
static conf_parser_t disconnect_config[]
Definition rlm_radius.c:102
static int status_check_type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static int mod_detach(module_detach_ctx_t const *mctx)
static int mod_load(void)
static fr_dict_attr_t const * attr_packet_type
Definition rlm_radius.c:195
static fr_dict_attr_t const * attr_user_password
Definition rlm_radius.c:207
static fr_dict_attr_t const * attr_state
Definition rlm_radius.c:197
static fr_dict_attr_t const * attr_eap_message
Definition rlm_radius.c:203
static int type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static conf_parser_t const pool_config[]
Definition rlm_radius.c:134
static fr_dict_attr_t const * attr_chap_password
Definition rlm_radius.c:194
static int status_check_verify(map_t *map, void *ctx)
Definition rlm_radius.c:413
static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Send packets outbound.
Definition rlm_radius.c:598
static fr_dict_t const * dict_radius
Definition rlm_radius.c:185
static int mod_bootstrap(module_inst_ctx_t const *mctx)
static fr_dict_attr_t const * attr_chap_challenge
Definition rlm_radius.c:193
static conf_parser_t status_config[]
Definition rlm_radius.c:86
fr_dict_attr_autoload_t rlm_radius_dict_attr[]
Definition rlm_radius.c:210
static fr_dict_attr_t const * attr_extended_attribute_1
Definition rlm_radius.c:201
static fr_dict_attr_t const * attr_error_cause
Definition rlm_radius.c:199
static void mod_unload(void)
static fr_dict_attr_t const * attr_proxy_state
Definition rlm_radius.c:196
static int radius_fixups(rlm_radius_t const *inst, request_t *request)
Do any RADIUS-layer fixups for proxying.
Definition rlm_radius.c:528
static fr_dict_attr_t const * attr_nas_identifier
Definition rlm_radius.c:204
static conf_parser_t const type_interval_config[FR_RADIUS_CODE_MAX]
Definition rlm_radius.c:176
static conf_parser_t auth_config[]
Definition rlm_radius.c:70
static int mode_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
module_rlm_t rlm_radius
fr_dict_autoload_t rlm_radius_dict[]
Definition rlm_radius.c:188
static conf_parser_t const transport_config[]
Definition rlm_radius.c:110
static int status_check_update_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static fr_dict_attr_t const * attr_original_packet_code
Definition rlm_radius.c:205
static fr_dict_attr_t const * attr_event_timestamp
Definition rlm_radius.c:200
static conf_parser_t const status_check_update_config[]
Definition rlm_radius.c:58
static fr_dict_attr_t const * attr_response_length
Definition rlm_radius.c:206
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition rlm_radius.c:650
static conf_parser_t const status_check_config[]
Definition rlm_radius.c:41
static size_t mode_names_len
Definition rlm_radius.c:239
static fr_table_num_sorted_t mode_names[]
Definition rlm_radius.c:232
static conf_parser_t const module_config[]
Definition rlm_radius.c:145
static conf_parser_t const connected_config[]
Definition rlm_radius.c:119
static fr_dict_attr_t const * attr_message_authenticator
Definition rlm_radius.c:202
static conf_parser_t acct_config[]
Definition rlm_radius.c:78
struct rlm_radius_s rlm_radius_t
Definition rlm_radius.h:39
rlm_radius_mode_t
Definition rlm_radius.h:41
@ RLM_RADIUS_MODE_XLAT_PROXY
radius.sendto.ipaddr(), but we do look for a reply.
Definition rlm_radius.h:47
@ RLM_RADIUS_MODE_INVALID
Definition rlm_radius.h:42
@ RLM_RADIUS_MODE_PROXY
we proxy to one home server
Definition rlm_radius.h:43
@ RLM_RADIUS_MODE_REPLICATE
to a particular destination
Definition rlm_radius.h:45
@ RLM_RADIUS_MODE_UNCONNECTED_REPLICATE
radius.sendto.ipaddr(), but we don't look for a reply
Definition rlm_radius.h:46
@ RLM_RADIUS_MODE_CLIENT
we are a client to one home server
Definition rlm_radius.h:44
static char const * name
static conf_parser_t retry_config[]
Definition rlm_tacacs.c:38
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:39
char const * name
Instance name e.g. user_database.
Definition module.h:359
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:353
size_t inst_size
Size of the module's instance data.
Definition module.h:212
void * data
Module's instance data.
Definition module.h:295
void * boot
Data allocated during the boostrap phase.
Definition module.h:298
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition module.h:152
Named methods exported by a module.
Definition module.h:174
#define pair_append_request(_attr, _da)
Allocate and append a fr_pair_t to the request list.
Definition pair.h:37
#define tmpl_is_xlat(vpt)
Definition tmpl.h:217
#define tmpl_is_attr(vpt)
Definition tmpl.h:215
#define tmpl_xlat(_tmpl)
Definition tmpl.h:953
#define tmpl_is_data(vpt)
Definition tmpl.h:213
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Definition tmpl.h:346
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
Definition tmpl.h:824
@ TMPL_ATTR_LIST_FORBID
Attribute refs are forbidden from having a list.
Definition tmpl.h:270
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:343
fr_client_t * client_from_request(request_t *request)
Search up a list of requests trying to locate one which has a client.
Definition client.c:1158
return count
Definition module.c:155
unlang_action_t unlang_module_yield_to_retry(request_t *request, module_method_t resume, unlang_module_retry_t retry, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx, fr_retry_config_t const *retry_cfg)
Yield a request back to the interpreter, with retries.
Definition module.c:369
static void mod_signal(module_ctx_t const *mctx, request_t *request, UNUSED fr_signal_t action)
Cancel a call to a submodule.
eap_aka_sim_process_conf_t * inst
fr_pair_t * vp
eap_type_t type
The preferred EAP-Type of this instance of the EAP-SIM/AKA/AKA' state machine.
Value pair map.
Definition map.h:77
tmpl_t * lhs
Typically describes the attribute to add, modify or compare.
Definition map.h:78
tmpl_t * rhs
Typically describes a literal value or a src attribute to copy or compare.
Definition map.h:79
CONF_ITEM * ci
Config item that the map was created from.
Definition map.h:85
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
Definition tmpl.h:280
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
#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
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:804
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
#define talloc_get_type_abort_const
Definition talloc.h:117
static size_t talloc_strlen(char const *s)
Returns the length of a talloc array containing a string.
Definition talloc.h:143
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:590
#define fr_time_delta_ispos(_a)
Definition time.h:290
int module_trigger_args_build(TALLOC_CTX *ctx, fr_pair_list_t *list, CONF_SECTION const *cs, module_trigger_args_t *args)
Build trigger args pair list for modules.
Definition trigger.c:504
Common values used by modules when building trigger args.
Definition trigger.h:42
conf_parser_t const trunk_config[]
Config parser definitions to populate a trunk_conf_t.
Definition trunk.c:345
bool xlat_impure_func(xlat_exp_head_t const *head)
static fr_slen_t head
Definition xlat.h:410
#define fr_pair_dcursor_by_da_init(_cursor, _list, _da)
Initialise a cursor that will return only attributes matching the specified fr_dict_attr_t.
Definition pair.h:640
struct value_pair_s fr_pair_t
Definition pair.h:48
static fr_slen_t parent
Definition pair.h:864
static fr_slen_t fr_value_box_aprint(TALLOC_CTX *ctx, char **out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules) 1(fr_value_box_print
#define fr_box_ipaddr(_val)
Definition value.h:348
static fr_sbuff_err_t char ** out
Definition value.h:1061
int nonnull(2, 5))
#define FR_VALUE_BOX_SAFE_FOR_ANY
Definition value.h:178
int xlat_func_args_set(xlat_t *x, xlat_arg_parser_t const args[])
Register the arguments of an xlat.
Definition xlat_func.c:374