The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
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: 03b64bd169bb67e345f3fcca97eaad3b3ef1ecec $
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: 03b64bd169bb67e345f3fcca97eaad3b3ef1ecec $")
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
42 { FR_CONF_OFFSET_TYPE_FLAGS("type", FR_TYPE_VOID, 0, rlm_radius_t, status_check),
44
45 { FR_CONF_OFFSET("num_answers_to_alive", rlm_radius_t, num_answers_to_alive), .dflt = STRINGIFY(3) },
46
48};
49
50/*
51 * "update" is not required.
52 *
53 * RFC 5997 Section 3 does not require the administrator provide anything:
54 * a Status-Server MUST carry Message-Authenticator, which the module adds
55 * to every packet, MAY carry NAS-Identifier and a NAS address, and SHOULD
56 * NOT carry anything else. status_check_alloc() supplies the
57 * NAS-Identifier when the map is empty, so a conformant packet does not
58 * need additional attributes.
59 */
67
68/*
69 * Retransmission intervals for the packets we support.
70 */
72 { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_ACCESS_REQUEST].irt), .dflt = STRINGIFY(2) },
73 { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrt), .dflt = STRINGIFY(16) },
74 { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrc), .dflt = STRINGIFY(5) },
75 { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrd), .dflt = STRINGIFY(30) },
77};
78
80 { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].irt), .dflt = STRINGIFY(2) },
81 { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrt), .dflt = STRINGIFY(5) },
82 { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrc), .dflt = STRINGIFY(1) },
83 { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrd), .dflt = STRINGIFY(30) },
85};
86
88 { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_STATUS_SERVER].irt), .dflt = STRINGIFY(2) },
89 { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_STATUS_SERVER].mrt), .dflt = STRINGIFY(5) },
90 { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_STATUS_SERVER].mrc), .dflt = STRINGIFY(5) },
91 { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_STATUS_SERVER].mrd), .dflt = STRINGIFY(30) },
93};
94
96 { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_COA_REQUEST].irt), .dflt = STRINGIFY(2) },
97 { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_COA_REQUEST].mrt), .dflt = STRINGIFY(16) },
98 { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_COA_REQUEST].mrc), .dflt = STRINGIFY(5) },
99 { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_COA_REQUEST].mrd), .dflt = STRINGIFY(30) },
101};
102
104 { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].irt), .dflt = STRINGIFY(2) },
105 { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrt), .dflt = STRINGIFY(16) },
106 { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrc), .dflt = STRINGIFY(5) },
107 { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrd), .dflt = STRINGIFY(30) },
109};
110
111#ifdef WITH_TLS
112/*
113 *
114 * The `alpn` subsection has no rules of its own, as fr_tls_alpn_parse() does that work. But we still need a
115 * place-holder.
116 */
117static conf_parser_t const radius_alpn_config[] = {
119};
120
121/** The rules for the `tls` subsection
122 *
123 * The rules include the rules of the TLS library, and add the `alpn` subsection, which only rlm_radius can
124 * add because only rlm_radius has the table. `virtual_server` is at offset 0 of #fr_tls_conf_t, so the
125 * rules of the library keep the offsets that they were written with.
126 */
127static conf_parser_t const radius_tls_config[] = {
128 { FR_CONF_OFFSET_REF(fr_tls_conf_t, virtual_server, fr_tls_client_config) },
129 { FR_CONF_OFFSET_SUBSECTION("alpn", CONF_FLAG_OK_MISSING, fr_tls_conf_t, alpn, radius_alpn_config),
130 .func = fr_tls_alpn_parse, .uctx = fr_radius_alpn_table },
132};
133#endif
134
135static conf_parser_t const udp_config[] = {
137
138#ifdef WITH_TLS
139 { FR_CONF_SUBSECTION_ALLOC("tls", CONF_FLAG_OK_MISSING, rlm_radius_t, tls_conf, radius_tls_config),
140 .subcs_type = "fr_tls_conf_t" },
141#endif
142
144};
145
146static conf_parser_t const tcp_config[] = {
148
149#ifdef WITH_TLS
150 { FR_CONF_SUBSECTION_ALLOC("tls", CONF_FLAG_OK_MISSING, rlm_radius_t, tls_conf, radius_tls_config),
151 .subcs_type = "fr_tls_conf_t" },
152#endif
153
155};
156
157/*
158 * We only parse the pool options if we're connected.
159 */
161 { FR_CONF_POINTER("status_check", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) status_check_config },
162
163 { FR_CONF_OFFSET_SUBSECTION("pool", 0, rlm_radius_t, trunk_conf, trunk_config ) },
164
165 { FR_CONF_POINTER("udp", 0, CONF_FLAG_SUBSECTION | CONF_FLAG_OPTIONAL, NULL), .subcs = (void const *) udp_config },
166
167 { FR_CONF_POINTER("tcp", 0, CONF_FLAG_SUBSECTION | CONF_FLAG_OPTIONAL, NULL), .subcs = (void const *) tcp_config },
168
170};
171
172#ifdef WITH_TLS
173/*
174 * The dynamic proxy takes the secret from the xlat arguments, and the "udp" section is otherwise parsed
175 * by fr_bio_fd_client_config. Every connection to every destination uses the same DTLS configuration.
176 */
177static conf_parser_t const udp_dynamic_config[] = {
178 { FR_CONF_SUBSECTION_ALLOC("tls", CONF_FLAG_OK_MISSING, rlm_radius_t, tls_conf, radius_tls_config),
179 .subcs_type = "fr_tls_conf_t" },
180
182};
183
184/*
185 * The same applies to the "tcp" section, which holds the RADIUS/TLS configuration.
186 */
187static conf_parser_t const tcp_dynamic_config[] = {
188 { FR_CONF_SUBSECTION_ALLOC("tls", CONF_FLAG_OK_MISSING, rlm_radius_t, tls_conf, radius_tls_config),
189 .subcs_type = "fr_tls_conf_t" },
190
192};
193#endif
194
195/*
196 * We only parse these options if we need a connection.
197 */
199 { FR_CONF_POINTER("status_check", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) status_check_config },
200
201 { FR_CONF_OFFSET_SUBSECTION("pool", 0, rlm_radius_t, trunk_conf, trunk_config ) },
202
203#ifdef WITH_TLS
204 { FR_CONF_POINTER("udp", 0, CONF_FLAG_SUBSECTION | CONF_FLAG_OPTIONAL, NULL), .subcs = (void const *) udp_dynamic_config },
205
206 { FR_CONF_POINTER("tcp", 0, CONF_FLAG_SUBSECTION | CONF_FLAG_OPTIONAL, NULL), .subcs = (void const *) tcp_dynamic_config },
207#endif
208
210};
211
212/*
213 * A mapping of configuration file names to internal variables.
214 */
215static conf_parser_t const module_config[] = {
216 { FR_CONF_OFFSET_FLAGS("mode", CONF_FLAG_REQUIRED, rlm_radius_t, mode), .func = mode_parse, .dflt = "proxy" },
217
219
221 .func = type_parse },
222
223 { FR_CONF_OFFSET("max_packet_size", rlm_radius_t, max_packet_size), .dflt = "4096" },
224 { FR_CONF_OFFSET("max_send_coalesce", rlm_radius_t, max_send_coalesce), .dflt = "1024" },
225
226 { FR_CONF_OFFSET("max_attributes", rlm_radius_t, max_attributes), .dflt = STRINGIFY(RADIUS_MAX_ATTRIBUTES) },
227
228 { FR_CONF_OFFSET("require_message_authenticator", rlm_radius_t, require_message_authenticator),
229 .func = cf_table_parse_uint8,
231 .dflt = "no" },
232
233 { FR_CONF_OFFSET("track_load_balance", rlm_radius_t, track_load_balance), },
234
235 { FR_CONF_OFFSET("response_window", rlm_radius_t, response_window) }, /* deprecated, see mod_instantiate() */
236
237 { FR_CONF_OFFSET("zombie_period", rlm_radius_t, zombie_period), .dflt = STRINGIFY(45) },
238
239 { FR_CONF_OFFSET("response_timeouts", rlm_radius_t, response_timeouts), .dflt = STRINGIFY(3) },
240
241 { FR_CONF_OFFSET("revive_interval", rlm_radius_t, revive_interval), .dflt = STRINGIFY(600) },
242
243 { FR_CONF_OFFSET("home_server_lifetime", rlm_radius_t, home_server_lifetime), .dflt = STRINGIFY(600) },
244
246};
247
249 [FR_RADIUS_CODE_ACCESS_REQUEST] = { FR_CONF_POINTER("Access-Request", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) auth_config },
250
251 [FR_RADIUS_CODE_ACCOUNTING_REQUEST] = { FR_CONF_POINTER("Accounting-Request", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) acct_config },
252 [FR_RADIUS_CODE_STATUS_SERVER] = { FR_CONF_POINTER("Status-Server", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) status_config },
253 [FR_RADIUS_CODE_COA_REQUEST] = { FR_CONF_POINTER("CoA-Request", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) coa_config },
254 [FR_RADIUS_CODE_DISCONNECT_REQUEST] = { FR_CONF_POINTER("Disconnect-Request", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) disconnect_config },
255};
256
257static fr_dict_t const *dict_radius;
258
261 { .out = &dict_radius, .proto = "radius" },
263};
264
270
284
287 { .out = &attr_chap_challenge, .name = "CHAP-Challenge", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
288 { .out = &attr_chap_password, .name = "CHAP-Password", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
289 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_radius },
290 { .out = &attr_proxy_state, .name = "Proxy-State", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
291 { .out = &attr_state, .name = "State", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
292
293 { .out = &attr_error_cause, .name = "Error-Cause", .type = FR_TYPE_UINT32, .dict = &dict_radius },
294 { .out = &attr_event_timestamp, .name = "Event-Timestamp", .type = FR_TYPE_DATE, .dict = &dict_radius},
295 { .out = &attr_extended_attribute_1, .name = "Extended-Attribute-1", .type = FR_TYPE_TLV, .dict = &dict_radius},
296 { .out = &attr_digest_attributes, .name = "Digest-Attributes", .type = FR_TYPE_TLV, .dict = &dict_radius},
297 { .out = &attr_digest_response, .name = "Digest-Response", .type = FR_TYPE_STRING, .dict = &dict_radius},
298 { .out = &attr_message_authenticator, .name = "Message-Authenticator", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
299 { .out = &attr_eap_message, .name = "EAP-Message", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
300 { .out = &attr_nas_identifier, .name = "NAS-Identifier", .type = FR_TYPE_STRING, .dict = &dict_radius},
301 { .out = &attr_original_packet_code, .name = "Extended-Attribute-1.Original-Packet-Code", .type = FR_TYPE_UINT32, .dict = &dict_radius},
302 { .out = &attr_reply_message, .name = "Reply-Message", .type = FR_TYPE_STRING, .dict = &dict_radius},
303 { .out = &attr_response_length, .name = "Extended-Attribute-1.Response-Length", .type = FR_TYPE_UINT32, .dict = &dict_radius },
304 { .out = &attr_user_name, .name = "User-Name", .type = FR_TYPE_STRING, .dict = &dict_radius},
305 { .out = &attr_user_password, .name = "User-Password", .type = FR_TYPE_STRING, .dict = &dict_radius},
306
308};
309
310#include "bio.c"
311
313 { L("client"), RLM_RADIUS_MODE_CLIENT },
314 { L("dynamic-proxy"), RLM_RADIUS_MODE_XLAT_PROXY },
315 { L("proxy"), RLM_RADIUS_MODE_PROXY },
316 { L("replicate"), RLM_RADIUS_MODE_REPLICATE },
317 { L("unconnected-replicate"), RLM_RADIUS_MODE_UNCONNECTED_REPLICATE },
318};
320
321
322/** Set the mode of operation
323 *
324 * @param[in] ctx to allocate data in (instance of rlm_radius).
325 * @param[out] out Where to write the parsed data.
326 * @param[in] parent Base structure address.
327 * @param[in] ci #CONF_PAIR specifying the name of the type module.
328 * @param[in] rule unused.
329 * @return
330 * - 0 on success.
331 * - -1 on failure.
332 */
333static int mode_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent,
334 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
335{
336 char const *name = cf_pair_value(cf_item_to_pair(ci));
338 rlm_radius_t *inst = talloc_get_type_abort(parent, rlm_radius_t);
340
342
343 if (mode == RLM_RADIUS_MODE_INVALID) {
344 cf_log_err(ci, "Invalid mode name \"%s\"", name);
345 return -1;
346 }
347
348 *(rlm_radius_mode_t *) out = mode;
349
350 /*
351 * Normally we want connected sockets, in which case we push additional configuration for
352 * connected sockets.
353 */
354 switch (mode) {
355 default:
356 inst->fd_config.type = FR_BIO_FD_CONNECTED;
357
358 if (cf_section_rules_push(cs, connected_config) < 0) return -1;
359 break;
360
362 inst->fd_config.type = FR_BIO_FD_UNCONNECTED; /* reset later when the home server is allocated */
363
364 if (cf_section_rules_push(cs, xlat_proxy_config) < 0) return -1;
365 break;
366
368 inst->fd_config.type = FR_BIO_FD_UNCONNECTED;
369 break;
370 }
371
372 return 0;
373}
374
375
376/** Set which types of packets we can parse
377 *
378 * @param[in] ctx to allocate data in (instance of rlm_radius).
379 * @param[out] out Where to write the parsed data.
380 * @param[in] parent Base structure address.
381 * @param[in] ci #CONF_PAIR specifying the name of the type module.
382 * @param[in] rule unused.
383 * @return
384 * - 0 on success.
385 * - -1 on failure.
386 */
387static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
388 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
389{
390 char const *type_str = cf_pair_value(cf_item_to_pair(ci));
392 fr_dict_enum_value_t const *type_enum;
393 uint32_t code;
394
395 /*
396 * Must be the RADIUS module
397 */
398 fr_assert(cs && (strcmp(cf_section_name1(cs), "radius") == 0));
399
400 /*
401 * Allow the process module to be specified by
402 * packet type.
403 */
404 type_enum = fr_dict_enum_by_name(attr_packet_type, type_str, -1);
405 if (!type_enum) {
406 invalid_code:
407 cf_log_err(ci, "Unknown or invalid RADIUS packet type '%s'", type_str);
408 return -1;
409 }
410
411 code = type_enum->value->vb_uint32;
412
413 /*
414 * Status-Server packets cannot be proxied.
415 */
416 if (code == FR_RADIUS_CODE_STATUS_SERVER) {
417 cf_log_err(ci, "Invalid setting of 'type = Status-Server'. Status-Server packets cannot be proxied.");
418 return -1;
419 }
420
421 if (!code ||
422 (code >= FR_RADIUS_CODE_MAX)) goto invalid_code;
423
424 if (!type_interval_config[code].name1) {
425 cf_log_err(ci, "Invalid packet type '%s' - cannot proxy a response packet", type_str);
426 return -1;
427 }
428
429 /*
430 * If we're doing async proxying, push the timers for the
431 * various packet types.
432 */
434
435 *(uint32_t *) out = code;
436
437 return 0;
438}
439
440/** Allow for Status-Server ping checks
441 *
442 * @param[in] ctx to allocate data in (instance of proto_radius).
443 * @param[out] out Where to write our parsed data.
444 * @param[in] parent Base structure address.
445 * @param[in] ci #CONF_PAIR specifying the name of the type module.
446 * @param[in] rule unused.
447 * @return
448 * - 0 on success.
449 * - -1 on failure.
450 */
451static int status_check_type_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
452 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
453{
454 char const *type_str = cf_pair_value(cf_item_to_pair(ci));
456 fr_dict_enum_value_t const *type_enum;
457 uint32_t code;
458
459 /*
460 * Allow the process module to be specified by
461 * packet type.
462 */
463 type_enum = fr_dict_enum_by_name(attr_packet_type, type_str, -1);
464 if (!type_enum) {
465 invalid_code:
466 cf_log_err(ci, "Unknown or invalid RADIUS packet type '%s'", type_str);
467 return -1;
468 }
469
470 code = type_enum->value->vb_uint32;
471
472 /*
473 * Cheat, and reuse the "type" array for allowed packet
474 * types.
475 */
476 if (!code ||
477 (code >= FR_RADIUS_CODE_MAX) ||
478 (!type_interval_config[code].name1)) goto invalid_code;
479
480 /*
481 * Add irt / mrt / mrd / mrc parsing, in the parent
482 * configuration section.
483 */
485
486 memcpy(out, &code, sizeof(code));
487
489
490 return 0;
491}
492
493static int status_check_verify(map_t *map, void *ctx)
494{
496 fr_dict_attr_t const *da;
497
499
500 if (unlang_fixup_update(map, NULL) < 0) return -1;
501
502 if (!map->rhs) return 0;
503
504 if (tmpl_is_xlat(map->rhs)) {
505 if (xlat_impure_func(tmpl_xlat(map->rhs))) {
506 invalid_xlat:
507 cf_log_err(map->ci, "Cannot assign dynamic values here");
508 return -1;
509 }
510 } else if (!tmpl_is_data(map->rhs)) {
511 goto invalid_xlat;
512 }
513
514 da = tmpl_attr_tail_da(map->lhs);
515
516 /*
517 * Ignore internal attributes.
518 */
519 if (da->flags.internal) {
520 cf_log_err(map->ci, "Cannot use internal attributes");
521 return -1;
522 }
523
524 /*
525 * Ignore signalling attributes. They shouldn't exist.
526 */
527 if ((da == attr_proxy_state) ||
529 cannot_use:
530 cf_log_err(map->ci, "Cannot use %s here.", da->name);
531 return -1;
532 }
533
534 /*
535 * Allow passwords only in Access-Request packets.
536 */
537 if ((inst->status_check != FR_RADIUS_CODE_ACCESS_REQUEST) &&
538 ((da == attr_user_password) || (da == attr_chap_password) || (da == attr_eap_message))) {
539 goto cannot_use;
540 }
541
542 /*
543 * RFC 5997 Section 5 says these MUST NOT be in Status-Server.
544 * The passwords are covered above.
545 */
546 if ((inst->status_check == FR_RADIUS_CODE_STATUS_SERVER) &&
547 ((da == attr_user_name) || (da == attr_reply_message) ||
548 (da == attr_digest_response) || (da == attr_digest_attributes) ||
549 (da->parent == attr_digest_attributes))) {
550 goto cannot_use;
551 }
552
553 return 0;
554}
555
556/** Allow the admin to set packet contents for Status-Server ping checks
557 *
558 * @param[in] ctx to allocate data in (instance of proto_radius).
559 * @param[out] out Where to write our parsed data
560 * @param[in] parent Base structure address.
561 * @param[in] ci #CONF_SECTION specifying the things to update
562 * @param[in] rule unused.
563 * @return
564 * - 0 on success.
565 * - -1 on failure.
566 */
567static int status_check_update_parse(TALLOC_CTX *ctx, void *out, void *parent,
568 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
569{
570 int rcode;
571 CONF_SECTION *cs;
572 char const *name2;
573 map_list_t *head = (map_list_t *)out;
574
576 map_list_init(head);
577
578 cs = cf_item_to_section(ci);
579 name2 = cf_section_name2(cs);
580 if (name2 && (strcmp(name2, "request") != 0)) {
581 cf_log_err(cs, "Only 'request' can be specified as the destination list");
582 return -1;
583 }
584
585 /*
586 * Compile the "update" section.
587 */
588 {
589 tmpl_rules_t parse_rules = {
590 .attr = {
592 .namespace = fr_dict_root(dict_radius),
593 .list_def = request_attr_request,
594 .list_presence = TMPL_ATTR_LIST_FORBID,
595 },
596 .literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
597 };
598
599 rcode = map_afrom_cs(ctx, head, cs, &parse_rules, &parse_rules, status_check_verify, parent, 128);
600 if (rcode < 0) return -1; /* message already printed */
601
602 /*
603 * status_check_alloc() supplies a NAS-Identifier when the
604 * map is empty, so an empty map needs no error here.
605 */
606 }
607
608 /*
609 * Rely on "bootstrap" to do sanity checks between 'type
610 * = Access-Request', and 'update' containing passwords.
611 */
612 return 0;
613}
614
615
616/** Do any RADIUS-layer fixups for proxying.
617 *
618 */
620{
621 fr_pair_t *vp;
622
623 /*
624 * If we received a Status-Server packet from the network, then don't proxy it.
625 *
626 * But we do sneakily allow virtual servers to originate and then send Status-Server packets.
627 */
628 if ((request->packet->code == FR_RADIUS_CODE_STATUS_SERVER) &&
629 ((request->packet->socket.af == AF_INET) || (request->packet->socket.af == AF_INET6))) {
630 RWDEBUG("Status-Server is reserved for internal use, and cannot be proxied.");
631 return 0;
632 }
633
634 if (!FR_RADIUS_PACKET_CODE_VALID(request->packet->code)) {
635 REDEBUG("Cannot proxy packet code %u, it is not a RADIUS packet code", request->packet->code);
636 return -1;
637 }
638
639 if (!inst->allowed[request->packet->code]) {
640 REDEBUG("Cannot proxy packet code %s - is disallowed by the configuration",
641 fr_radius_packet_name[request->packet->code]);
642 return 0;
643 }
644
645 /*
646 * Check for proxy loops.
647 *
648 * There should _never_ be two instances of the same Proxy-State in the packet.
649 */
650 if ((inst->mode == RLM_RADIUS_MODE_PROXY) && RDEBUG_ENABLED) {
651 unsigned int count = 0;
652 fr_dcursor_t cursor;
653
654 for (vp = fr_pair_dcursor_by_da_init(&cursor, &request->request_pairs, attr_proxy_state);
655 vp;
656 vp = fr_dcursor_next(&cursor)) {
657 if (vp->vp_length != sizeof(inst->common_ctx.proxy_state)) continue;
658
659 if (memcmp(vp->vp_octets, &inst->common_ctx.proxy_state,
660 sizeof(inst->common_ctx.proxy_state)) == 0) {
661
662 /*
663 * Cancel proxying when there are two instances of the same Proxy-State
664 * in the packet. This limitation could be configurable, but it likely
665 * doesn't make sense to make it configurable.
666 */
667 if (count == 1) {
668 RWARN("Canceling proxy due to loop of multiple %pV", vp);
669 return -1;
670 }
671
672 RWARN("Proxied packet contains our own %pV", vp);
673 RWARN("Check if there is a proxy loop. Perhaps the server has been configured to proxy to itself.");
674 count++;
675 }
676 }
677 }
678
679 if (request->packet->code != FR_RADIUS_CODE_ACCESS_REQUEST) return 0;
680
681 if (fr_pair_find_by_da(&request->request_pairs, NULL, attr_chap_password) &&
682 !fr_pair_find_by_da(&request->request_pairs, NULL, attr_chap_challenge)) {
684 fr_pair_value_memdup(vp, request->packet->vector, sizeof(request->packet->vector), true);
685 }
686
687 return 0;
688}
689
690
691/** Send packets outbound.
692 *
693 */
695{
697 bio_thread_t *thread = talloc_get_type_abort(mctx->thread, bio_thread_t);
698 fr_client_t *client;
699 int rcode;
700 unlang_action_t action;
701 bio_request_t *u = NULL;
702 fr_retry_config_t const *retry_config = NULL;
703
704 if (!request->packet->code) {
705 REDEBUG("You MUST specify a packet code");
707 }
708
709 if ((request->packet->code >= FR_RADIUS_CODE_MAX) ||
710 !fr_time_delta_ispos(inst->retry[request->packet->code].irt)) { /* can't be zero */
711 REDEBUG("Invalid packet code %u", request->packet->code);
713 }
714
715 /*
716 * Unconnected sockets use %radius.sendto.ipaddr(ip, port, secret)
717 */
719 (inst->mode == RLM_RADIUS_MODE_XLAT_PROXY)) {
720 REDEBUG("When using 'mode = %s', this module cannot be used in-place. "
721 "Instead, it must be called via a function call",
722 fr_table_str_by_value(mode_names, inst->mode, "<INVALID>"));
724 }
725
727 if (client && client->dynamic && !client->active) {
728 REDEBUG("Cannot proxy packets which define dynamic clients");
730 }
731
732 /*
733 * Push the request and it's data to the IO submodule.
734 *
735 * This may return YIELD, for "please yield", or it may
736 * return another code which indicates what happened to
737 * the request...
738 */
739 rcode = mod_enqueue(&u, &retry_config, inst, thread->ctx.trunk, request);
740 if (rcode == 0) RETURN_UNLANG_NOOP;
741 if (rcode < 0) RETURN_UNLANG_FAIL;
742
743 /*
744 * A replicated packet does not wait for a response, so it has no retry configuration, and no
745 * timer.
746 */
747 if (!retry_config) {
749 } else {
752 }
753
754 /*
755 * The request is not yielding, so mod_signal() will never be called. Remove the request from the
756 * trunk, as the trunk would otherwise send a request which nothing waits for.
757 */
758 if ((action == UNLANG_ACTION_FAIL) && u->treq) {
760 u->treq = NULL;
761 }
762
763 return action;
764}
765
766
767static int mod_instantiate(module_inst_ctx_t const *mctx)
768{
769 size_t i, num_types;
770 rlm_radius_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_radius_t);
771 fr_time_delta_t longest;
772 CONF_SECTION *conf = mctx->mi->conf;
773
774 inst->name = mctx->mi->name;
775 inst->received_message_authenticator = talloc_zero(NULL, bool); /* Allocated outside of inst to default protection */
776
777#ifdef WITH_TLS
778 /*
779 * TLS and DTLS need a connected socket, and a trunk to manage the connections. The dynamic proxy
780 * allocates a trunk of connected sockets for each destination, so it can also use TLS and DTLS.
781 */
782 if (inst->tls_conf) {
783 char const *fixed_secret;
784 CONF_SECTION *wrong_cs;
785
786 if ((inst->mode != RLM_RADIUS_MODE_PROXY) && (inst->mode != RLM_RADIUS_MODE_CLIENT) &&
787 (inst->mode != RLM_RADIUS_MODE_XLAT_PROXY)) {
788 cf_log_err(conf, "The 'tls' section can only be used with 'mode = proxy', 'mode = client', or 'mode = dynamic-proxy'");
789 return -1;
790 }
791
792 /*
793 * The 'tls' section is only parsed inside of the 'tcp' or 'udp' section. Make sure that
794 * the section matches the transport, as src/lib/tls/ uses the transport to select
795 * between TLS and DTLS.
796 */
797 wrong_cs = cf_section_find(conf, (inst->fd_config.socket_type == SOCK_DGRAM) ? "tcp" : "udp", NULL);
798 if (wrong_cs && cf_section_find(wrong_cs, "tls", NULL)) {
799 cf_log_err(conf, "The 'tls' section is in the '%s' section, which does not match 'transport = %s'",
800 cf_section_name1(wrong_cs),
801 (inst->fd_config.socket_type == SOCK_DGRAM) ? "udp" : "tcp");
802 return -1;
803 }
804
805 inst->tls_conf->socket_type = inst->fd_config.socket_type;
806
807 /*
808 * RFC 6614 Section 2.1 says that the port is 2083, and Section 2.3 (4) says that the secret
809 * is "radsec". RFC 7360 Section 3.1 says that the DTLS port is UDP/2083, and Section 2.1
810 * says that the secret is "radius/dtls".
811 */
812 if (!inst->fd_config.dst_port) inst->fd_config.dst_port = 2083;
813
814 fixed_secret = (inst->fd_config.socket_type == SOCK_DGRAM) ? "radius/dtls" : "radsec";
815
816 if (!inst->secret) {
817 MEM(inst->secret = talloc_strdup(inst, fixed_secret));
818
819 } else if (strcmp(inst->secret, fixed_secret) != 0) {
820 cf_log_warn(conf, "The RFC says that the secret should be '%s'. A different secret may not work.",
821 fixed_secret);
822 }
823 } else
824#endif
825 /*
826 * Only the connected modes parse the 'tcp' and 'udp' sections, see mode_parse().
827 */
828 if (!inst->secret && (inst->fd_config.type == FR_BIO_FD_CONNECTED)) {
829 if (cf_section_find(conf, "tcp", NULL)) {
830 cf_log_err(conf, "Missing 'secret' in the 'tcp' section");
831 return -1;
832 }
833
834 if (cf_section_find(conf, "udp", NULL)) {
835 cf_log_err(conf, "Missing 'secret' in the 'udp' section");
836 return -1;
837 }
838 }
839
840 /*
841 * Replication is write-only, and append by default.
842 */
843 if (inst->mode == RLM_RADIUS_MODE_REPLICATE) {
844 if (inst->fd_config.filename && (inst->fd_config.flags != O_WRONLY)) {
845 cf_log_info(conf, "Setting 'flags = write-only' for writing to a file");
846 }
847 inst->fd_config.flags = O_WRONLY | O_APPEND;
848
849 } else if (inst->fd_config.filename) {
850 cf_log_err(conf, "When using an output 'filename', you MUST set 'mode = replicate'");
851 return -1;
852
853 } else {
854 /*
855 * All other IO is read+write.
856 */
857 inst->fd_config.flags = O_RDWR;
858 }
859
860 /*
861 * Forbid the use of src_port* for TCP and TLS. The kernel picks the source port.
862 */
863 if ((inst->fd_config.socket_type == SOCK_STREAM) &&
864 (inst->fd_config.src_port || inst->fd_config.src_port_start || inst->fd_config.src_port_end)) {
865 cf_log_err(conf, "Cannot set 'src_port', 'src_port_start', or 'src_port_end' for TCP or TLS sockets");
866 return -1;
867 }
868
869 if (fr_bio_fd_check_config(&inst->fd_config) < 0) {
870 cf_log_perr(conf, "Invalid configuration");
871 return -1;
872 }
873
874 /*
875 * Clamp max_packet_size first before checking recv_buff and send_buff
876 */
877 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, >=, 4096);
878 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, <=, 65535);
879
880#ifdef WITH_TLS
881 if (inst->tls_conf) {
882 FR_INTEGER_BOUND_CHECK("tls.buffer_size", inst->tls_conf->buffer_size, >=, FR_RADIUS_TLS_BUFFER_SIZE_MIN);
883 FR_INTEGER_BOUND_CHECK("tls.buffer_size", inst->tls_conf->buffer_size, <=, FR_RADIUS_TLS_BUFFER_SIZE_MAX);
884 }
885#endif
886
887 /*
888 * Check invalid configurations.
889 */
890 switch (inst->mode) {
891 default:
892 /*
893 * Filenames are write-only, and cannot get response packets.
894 */
895 if (inst->fd_config.filename) {
896 cf_log_err(conf, "Cannot set 'filename' here - it is only supported for 'mode=replicate'");
897 return -1;
898 }
899
900 /*
901 * When we expect replies, we need to be able to open multiple source ports. So the
902 * admin can't force a particular source port.
903 */
904 if (inst->fd_config.src_port) {
905 cf_log_err(conf, "Cannot 'src_port' here - it can only be set for replicating packets");
906 return -1;
907 }
908
909 /*
910 * Encorce limits per trunk, due to the 8-bit ID space.
911 */
912 FR_INTEGER_BOUND_CHECK("trunk.per_connection_max", inst->trunk_conf.max_req_per_conn, >=, 2);
913 FR_INTEGER_BOUND_CHECK("trunk.per_connection_max", inst->trunk_conf.max_req_per_conn, <=, 255);
914 FR_INTEGER_BOUND_CHECK("trunk.per_connection_target", inst->trunk_conf.target_req_per_conn, <=, inst->trunk_conf.max_req_per_conn / 2);
915
916 /*
917 * This only applies for XLAT_PROXY, but what the heck.
918 */
919 FR_TIME_DELTA_BOUND_CHECK("home_server_lifetime", inst->home_server_lifetime, >=, fr_time_delta_from_sec(10));
920 FR_TIME_DELTA_BOUND_CHECK("home_server_lifetime", inst->home_server_lifetime, <=, fr_time_delta_from_sec(3600));
921
922 /*
923 * No src_port range, we don't need to check any other settings.
924 */
925 if (!inst->fd_config.src_port_start && !inst->fd_config.src_port_end) break;
926
927 if (inst->fd_config.path) {
928 cf_log_err(conf, "Cannot set 'src_port_start' or 'src_port_end' for outgoing Unix sockets");
929 return -1;
930 }
931
932 /*
933 * Cross-check src_port, src_port_start, and src_port_end.
934 */
935 if (inst->fd_config.src_port_start) {
936 if (!inst->fd_config.src_port_end) {
937 cf_log_err(conf, "Range has 'src_port_start', but is missing 'src_port_end'");
938 return -1;
939 }
940
941 if (inst->fd_config.src_port_start >= inst->fd_config.src_port_end) {
942 cf_log_err(conf, "Range has invalid values for 'src_port_start' ... 'src_port_end'");
943 return -1;
944 }
945
946 } else if (inst->fd_config.src_port_end) {
947 cf_log_err(conf, "Range has 'src_port_end', but is missing 'src_port_start'");
948 return -1;
949 }
950
951 /*
952 * The source port range is split by worker - so there needs to be sufficient for at least
953 * one per worker.
954 */
955 if ((inst->fd_config.src_port_end - inst->fd_config.src_port_start + 1) < (int) main_config->max_workers) {
956 cf_log_perr(conf, "src_port_start / end range is not enough for %u worker threads",
958 return -1;
959 }
960
961 /*
962 * If there is a limited source port range, then set the reuse port flag. This lets us
963 * bind multiple sockets to the same port before we connect() them.
964 */
965 inst->fd_config.reuse_port = 1;
966 break;
967
969 /*
970 * Replication to dynamic filenames or dynamic unix sockets isn't supported.
971 */
972 if (inst->fd_config.filename || inst->fd_config.path) {
973 cf_log_err(conf, "Cannot set 'filename' or 'path' when using 'mode=unconnected-replicate'");
974 return -1;
975 }
976
977 /*
978 * Unconnected replicate has to use UDP.
979 */
980 if (inst->fd_config.socket_type != SOCK_DGRAM) {
981 cf_log_err(conf, "Cannot use TCP sockets with 'mode=unconnected-replicate'");
982 return -1;
983 }
984
986
988 /*
989 * We can force the source port, but then we have to set SO_REUSEPORT.
990 */
991 inst->fd_config.reuse_port = (inst->fd_config.src_port != 0);
992
993 /*
994 * Files and unix sockets are OK. The src_port can be set (or not), and that's fine.
995 */
996 if (inst->fd_config.src_port_start || inst->fd_config.src_port_end) {
997 cf_log_err(conf, "Cannot set 'src_port_start' or 'src_port_end' when replicating packets");
998 return -1;
999 }
1000 break;
1001 }
1002
1003 /*
1004 * We allow what may otherwise be conflicting configurations, because the BIO code will pick one
1005 * path, and the conflicts won't affect anything else. Only the src_port range is special.
1006 */
1007
1008 /*
1009 * The timeout of a packet which waits for a response is now the "max_rtx_duration" of the packet
1010 * type. We can't make this DEPRECATED, because doing so would break existing systems. :(
1011 */
1012 if (fr_time_delta_ispos(inst->response_window)) {
1013 cf_log_warn(conf, "Ignoring 'response_window'. Use 'max_rtx_duration' in the subsection for each "
1014 "packet type instead");
1015
1016#define RESPONSE_WINDOW_FIX(_x) do { \
1017 if (fr_time_delta_ispos(inst->response_window) && fr_time_delta_eq(inst->retry[_x].mrd, fr_time_delta_wrap(0))) { \
1018 inst->retry[_x].mrd = inst->response_window; \
1019 } \
1020 } while (0)
1021 }
1022
1023 FR_TIME_DELTA_BOUND_CHECK("zombie_period", inst->zombie_period, >=, fr_time_delta_from_sec(1));
1024 FR_TIME_DELTA_BOUND_CHECK("zombie_period", inst->zombie_period, <=, fr_time_delta_from_sec(135));
1025
1026 FR_INTEGER_BOUND_CHECK("response_timeouts", inst->response_timeouts, >=, 1);
1027 FR_INTEGER_BOUND_CHECK("response_timeouts", inst->response_timeouts, <=, 10);
1028
1029 if (!inst->status_check) {
1030 FR_TIME_DELTA_BOUND_CHECK("revive_interval", inst->revive_interval, >=, fr_time_delta_from_sec(10));
1031 FR_TIME_DELTA_BOUND_CHECK("revive_interval", inst->revive_interval, <=, fr_time_delta_from_sec(3600));
1032 }
1033
1034 num_types = talloc_array_length(inst->types);
1035 fr_assert(num_types > 0);
1036
1037 inst->common_ctx = (fr_radius_ctx_t) {
1038 .secret = inst->secret,
1039 .secret_length = inst->secret ? talloc_strlen(inst->secret) : 0,
1040 .proxy_state = ((uint64_t) fr_rand()) << 32 | fr_rand(),
1041 };
1042
1043 /*
1044 * Allow for O(1) lookup later...
1045 */
1046 for (i = 0; i < num_types; i++) {
1047 uint32_t code;
1048
1049 code = inst->types[i];
1050 fr_assert(code > 0);
1052
1053 if (inst->allowed[code]) {
1054 cf_log_err(conf, "Duplicate 'type = %s'", fr_radius_packet_name[code]);
1055 return -1;
1056 }
1057
1058 inst->allowed[code] = true;
1059 }
1060
1061 fr_assert(inst->status_check < FR_RADIUS_CODE_MAX);
1062
1063 /*
1064 * If we're replicating, we don't care if the other end is alive.
1065 */
1066 if (inst->status_check) {
1067 if (inst->mode == RLM_RADIUS_MODE_REPLICATE) {
1068 cf_log_warn(conf, "Ignoring 'status_check = %s' due to 'mode = replicate'",
1069 fr_radius_packet_name[inst->status_check]);
1070 inst->status_check = false;
1071
1072 } else if ((inst->mode == RLM_RADIUS_MODE_UNCONNECTED_REPLICATE) ||
1073 (inst->mode == RLM_RADIUS_MODE_XLAT_PROXY)) {
1074 cf_log_warn(conf, "Ignoring 'status_check = %s' due to 'mode' setting",
1075 fr_radius_packet_name[inst->status_check]);
1076 inst->status_check = false;
1077 }
1078
1079 if (inst->status_check && inst->fd_config.filename) {
1080 cf_log_info(conf, "Disabling status checks for output file %s", inst->fd_config.filename);
1081 inst->status_check = false;
1082 }
1083
1084 /*
1085 * If we still have status checks, then do some sanity checks. Status-Server is always allowed
1086 * if it's the packet type we use. Otherwise, the status check packet type has to match one of
1087 * the allowed packet types.
1088 */
1089 if (inst->status_check) {
1090 if (inst->status_check == FR_RADIUS_CODE_STATUS_SERVER) {
1091 inst->allowed[inst->status_check] = true;
1092
1093 } else if (!inst->allowed[inst->status_check]) {
1094 cf_log_err(conf, "Using 'status_check = %s' requires also 'type = %s'",
1095 fr_radius_packet_name[inst->status_check], fr_radius_packet_name[inst->status_check]);
1096 return -1;
1097 }
1098 }
1099 }
1100
1101 /*
1102 * Files and unix sockets can just have us call write().
1103 */
1104 if (inst->fd_config.filename || inst->fd_config.path) {
1105 inst->max_send_coalesce = 1;
1106 }
1107
1108 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 */
1109 inst->trunk_conf.req_pool_size = 1024 + sizeof(fr_pair_t) + 20;
1110
1111 if (inst->trunk_conf.conn_triggers) {
1113 char *server = NULL;
1114
1116 .module = mctx->mi->module->name,
1117 .name = inst->name
1118 };
1119
1120 /*
1121 * Only client and proxy mode have fixed destinations
1122 */
1123 if ((inst->mode == RLM_RADIUS_MODE_CLIENT) || (inst->mode == RLM_RADIUS_MODE_PROXY)) {
1124 fr_value_box_aprint(inst, &server, fr_box_ipaddr(inst->fd_config.dst_ipaddr), NULL);
1125 args.server = server;
1126 args.port = inst->fd_config.dst_port;
1127 }
1128
1129 MEM(inst->trigger_args = fr_pair_list_alloc(inst));
1130 if (module_trigger_args_build(inst->trigger_args, inst->trigger_args,
1131 cf_section_find(conf, "pool", NULL), &args) < 0) return -1;
1132 }
1133
1134 /*
1135 * Validate timers for status checks.
1136 */
1137 if (inst->status_check) {
1138 connection_conf_t *conn_conf;
1139 fr_time_delta_t min_timeout;
1140 int64_t delta;
1141
1142 FR_INTEGER_BOUND_CHECK("num_answers_to_alive", inst->num_answers_to_alive, >=, 1);
1143 FR_INTEGER_BOUND_CHECK("num_answers_to_alive", inst->num_answers_to_alive, <=, 10);
1144
1145 /*
1146 * @todo - check the contents of the "update" section, to be sure that (e.g.)
1147 * Access-Request contains User-Name, etc.
1148 */
1150
1151 FR_TIME_DELTA_BOUND_CHECK("Status-Server.initial_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].irt, >=, fr_time_delta_from_sec(1));
1152 FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrt, >=, fr_time_delta_from_sec(5));
1153 FR_INTEGER_BOUND_CHECK("Status-Server.max_rtx_count", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrc, >=, 1);
1154 FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_duration", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrd, >=, fr_time_delta_from_sec(5));
1155
1156 FR_TIME_DELTA_BOUND_CHECK("Status-Server.initial_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].irt, <=, fr_time_delta_from_sec(5));
1157 FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrt, <=, fr_time_delta_from_sec(30));
1158 FR_INTEGER_BOUND_CHECK("Status-Server.max_rtx_count", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrc, <=, 10);
1159 FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_duration", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrd, <=, fr_time_delta_from_sec(30));
1160
1161 /*
1162 * Ensure that we don't give up before we received the number of expected replies.
1163 */
1164 FR_INTEGER_BOUND_CHECK("Status-Server.max_rtx_count", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrc, >=, inst->num_answers_to_alive);
1165
1166 /*
1167 * The status checks run while the connection is opening. The connection has to stay in
1168 * the "connecting" state long enough to send all of the status checks, otherwise the
1169 * connection timeout will fire before the status checks finish.
1170 */
1171 conn_conf = UNCONST(connection_conf_t *, inst->trunk_conf.conn_conf);
1173 delta += delta >> 2;
1174
1175 min_timeout = fr_time_delta_wrap(delta);
1176
1177 if (fr_time_delta_lt(conn_conf->connection_timeout, min_timeout)) {
1178 cf_log_warn(conf, "Increasing pool.connection.connect_timeout from %pVs to %pVs, to allow for status_check.max_rtx_duration",
1179 fr_box_time_delta(conn_conf->connection_timeout), fr_box_time_delta(min_timeout));
1180 conn_conf->connection_timeout = min_timeout;
1181 }
1182 }
1183
1184 /*
1185 * Replicated packets do not wait for a response, and do not use the retry timers.
1186 */
1188 return 0;
1189 }
1190
1191 /*
1192 * Set limits on retransmission timers
1193 */
1194 if (inst->allowed[FR_RADIUS_CODE_ACCESS_REQUEST]) {
1196
1197 FR_TIME_DELTA_BOUND_CHECK("Access-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].irt, >=, fr_time_delta_from_sec(1));
1198 FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
1199 FR_INTEGER_BOUND_CHECK("Access-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrc, >=, 1);
1200 FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrd, >=, fr_time_delta_from_sec(5));
1201
1202 FR_TIME_DELTA_BOUND_CHECK("Access-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].irt, <=, fr_time_delta_from_sec(15));
1203 FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrt, <=, fr_time_delta_from_sec(30));
1204 FR_INTEGER_BOUND_CHECK("Access-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrc, <=, 10);
1205 FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrd, <=, fr_time_delta_from_sec(90));
1206 }
1207
1208 /*
1209 * Note that RFC 5080 allows for Accounting-Request to have mrt=mrc=mrd = 0, which means
1210 * "retransmit forever". We allow that when we originate packets over UDP or DTLS, with the
1211 * restriction that the server core will automatically free the request at request.timeout.
1212 */
1215
1216 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].irt, >=, fr_time_delta_from_sec(1));
1217
1218 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].irt, <=, fr_time_delta_from_sec(5));
1219 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrt, <=, fr_time_delta_from_sec(30));
1220 FR_INTEGER_BOUND_CHECK("Accounting-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrc, <=, 10);
1221 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
1222 }
1223
1224 /*
1225 * CoA
1226 */
1227 if (inst->allowed[FR_RADIUS_CODE_COA_REQUEST]) {
1229
1230 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].irt, >=, fr_time_delta_from_sec(1));
1231 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
1232 FR_INTEGER_BOUND_CHECK("CoA-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrc, >=, 1);
1233 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrd, >=, fr_time_delta_from_sec(5));
1234
1235 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].irt, <=, fr_time_delta_from_sec(5));
1236 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrt, <=, fr_time_delta_from_sec(60));
1237 FR_INTEGER_BOUND_CHECK("CoA-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrc, <=, 10);
1238 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
1239 }
1240
1241 /*
1242 * Disconnect
1243 */
1246
1247 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].irt, >=, fr_time_delta_from_sec(1));
1248 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
1249 FR_INTEGER_BOUND_CHECK("Disconnect-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrc, >=, 1);
1250 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrd, >=, fr_time_delta_from_sec(5));
1251
1252 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].irt, <=, fr_time_delta_from_sec(5));
1253 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrt, <=, fr_time_delta_from_sec(30));
1254 FR_INTEGER_BOUND_CHECK("Disconnect-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrc, <=, 10);
1255 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
1256 }
1257
1258 /*
1259 * Enforce a zombie_period of 1.5x mrd. Otherwise, a long run of unanswered requests followed by
1260 * a single lost request will mark the connection as zombie.
1261 */
1262 longest = fr_time_delta_wrap(0);
1263
1264 for (i = 0; i < FR_RADIUS_CODE_MAX; i++) {
1265 if (!inst->allowed[i] || (i == FR_RADIUS_CODE_STATUS_SERVER)) continue;
1266
1267 if (fr_time_delta_gt(inst->retry[i].mrd, longest)) longest = inst->retry[i].mrd;
1268 }
1269 longest = fr_time_delta_add(longest, fr_time_delta_wrap(fr_time_delta_unwrap(longest) >> 1));
1270 FR_TIME_DELTA_BOUND_CHECK("zombie_period", inst->zombie_period, >=, longest);
1271
1272 /*
1273 * When we proxy, we don't retransmit. We do send dups if the NAS retransmits.
1274 * When we use a stream socket, we don't retransmit either.
1275 * In both cases we fail at `max_rtx_duration`.
1276 *
1277 * This behavior is enforced at run-time by simply setting mrc=1 when the module starts up.
1278 */
1279 if ((inst->mode == RLM_RADIUS_MODE_PROXY) || (inst->mode == RLM_RADIUS_MODE_XLAT_PROXY) ||
1280 (inst->fd_config.socket_type == SOCK_STREAM)) {
1281 for (i = 0; i < FR_RADIUS_CODE_MAX; i++) {
1282 if (i == FR_RADIUS_CODE_STATUS_SERVER) continue;
1283
1284 inst->retry[i].mrc = 1;
1285 }
1286
1287 /*
1288 * Every proxied Accounting-Request has a timer.
1289 */
1292 cf_log_warn(conf, "Rewriting \"Accounting-Request.max_rtx_duration = 0\" to \"30\"");
1294 }
1295
1296 /*
1297 * A zero "max_rtx_duration" means that we retransmit forever. fr_retry_init() ends the
1298 * retransmissions after one day.
1299 */
1300 } else if (inst->allowed[FR_RADIUS_CODE_ACCOUNTING_REQUEST] &&
1303 }
1304
1305 return 0;
1306}
1307
1308static int mod_bootstrap(module_inst_ctx_t const *mctx)
1309{
1310 xlat_t *xlat;
1311 rlm_radius_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_radius_t);
1312
1313 switch (inst->mode) {
1315 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "sendto.ipaddr", xlat_radius_replicate, FR_TYPE_VOID);
1316 if (!xlat) return -1;
1318 break;
1319
1321 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "sendto.ipaddr", xlat_radius_client, FR_TYPE_UINT32);
1322 if (!xlat) return -1;
1324 break;
1325
1326 default:
1327 break;
1328 }
1329
1330 return 0;
1331}
1332
1333
1334static int mod_detach(module_detach_ctx_t const *mctx)
1335{
1336 rlm_radius_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_radius_t);
1337
1338 talloc_free(inst->received_message_authenticator);
1339 return 0;
1340}
1341
1342static int mod_load(void)
1343{
1344 if (fr_radius_global_init() < 0) {
1345 PERROR("Failed initialising protocol library");
1346 return -1;
1347 }
1348 return 0;
1349}
1350
1351static void mod_unload(void)
1352{
1354}
1355
1356/*
1357 * The module name should be the only globally exported symbol.
1358 * That is, everything else should be 'static'.
1359 *
1360 * If the module needs to temporarily modify it's instantiation
1361 * data, the type should be changed to MODULE_TYPE_THREAD_UNSAFE.
1362 * The server will then take care of ensuring that the module
1363 * is single-threaded.
1364 */
1367 .common = {
1368 .magic = MODULE_MAGIC_INIT,
1369 .name = "radius",
1370 .inst_size = sizeof(rlm_radius_t),
1372 .dict = &dict_radius,
1373
1374 .onload = mod_load,
1375 .unload = mod_unload,
1376
1377 .bootstrap = mod_bootstrap,
1378 .instantiate = mod_instantiate,
1379 .detach = mod_detach,
1380
1381 .thread_inst_size = sizeof(bio_thread_t),
1382 .thread_inst_type = "bio_thread_t",
1383 .thread_instantiate = mod_thread_instantiate,
1384 .thread_detach = mod_thread_detach,
1385 },
1386 .method_group = {
1387 .bindings = (module_method_binding_t[]){
1388 { .section = SECTION_NAME(CF_IDENT_ANY, CF_IDENT_ANY), .method = mod_process },
1390 },
1391 }
1392};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_FAIL
Encountered an unexpected error.
Definition action.h:36
va_list args
Definition acutest.h:923
static uint8_t request[4]
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
Definition build.h:203
#define RCSID(id)
Definition build.h:609
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:245
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:422
#define STRINGIFY(x)
Definition build.h:233
#define UNUSED
Definition build.h:415
#define NUM_ELEMENTS(_t)
Definition build.h:443
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:722
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:666
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
Definition cf_parse.h:572
#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:651
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition cf_parse.h:466
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition cf_parse.h:483
@ CONF_FLAG_SECRET
Only print value if debug level >= 3.
Definition cf_parse.h:470
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
Definition cf_parse.h:484
@ CONF_FLAG_OPTIONAL
subsection is pushed only if a non-optional matching one is pushed
Definition cf_parse.h:495
@ CONF_FLAG_OK_MISSING
OK if it's missing.
Definition cf_parse.h:491
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:460
#define FR_CONF_SUBSECTION_ALLOC(_name, _flags, _struct, _field, _subcs)
conf_parser_t which allocates a struct and populates it from a subsection
Definition cf_parse.h:384
int cf_table_parse_uint8(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
#define cf_section_rules_push(_cs, _rule)
Definition cf_parse.h:754
#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:350
#define cf_section_rule_push(_cs, _rule)
Definition cf_parse.h:752
#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:337
#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:583
#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:649
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:1405
char const * cf_section_name1(CONF_SECTION const *cs)
Return the first identifier of a CONF_SECTION.
Definition cf_util.c:1391
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:1247
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:1758
#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:2725
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:3786
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
const conf_parser_t fr_bio_fd_client_config[]
Definition fd_config.c:352
@ FR_BIO_FD_CONNECTED
connected client sockets (UDP or TCP)
Definition fd.h:63
@ FR_BIO_FD_UNCONNECTED
unconnected UDP / datagram, but also allowed
Definition fd.h:60
int fr_bio_fd_check_config(fr_bio_fd_config_t const *cfg)
Checks the configuration without modifying anything.
Definition fd_open.c:996
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:3468
static void mod_retry(module_ctx_t const *mctx, request_t *request, fr_retry_t const *retry)
Handle module retries.
Definition bio.c:2347
bio_handle_ctx_t ctx
common struct for home servers and BIO handles
Definition bio.c:62
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:3757
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:3915
trunk_t * trunk
trunk handler
Definition bio.c:50
trunk_request_t * treq
Definition bio.c:158
static xlat_arg_parser_t const xlat_radius_send_args[]
Definition bio.c:3747
Connect request_t to local tracking structure.
Definition bio.c:157
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:2906
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:716
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:164
size_t fr_radius_require_ma_table_len
Definition base.c:97
int fr_radius_global_init(void)
Definition base.c:1379
void fr_radius_global_free(void)
Definition base.c:1403
fr_table_num_sorted_t const fr_radius_require_ma_table[]
Definition base.c:90
char const * fr_radius_packet_name[FR_RADIUS_CODE_MAX]
Definition base.c:119
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
#define FR_RADIUS_PACKET_CODE_VALID(_x)
Definition radius.h:51
static rs_t * conf
Definition radsniff.c:52
uint32_t fr_rand(void)
Return a 32-bit random number.
Definition rand.c:128
#define RETURN_UNLANG_FAIL
Definition rcode.h:69
#define RETURN_UNLANG_NOOP
Definition rcode.h:75
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 int mod_thread_detach(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:95
static conf_parser_t disconnect_config[]
Definition rlm_radius.c:103
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 conf_parser_t const udp_config[]
Definition rlm_radius.c:135
static fr_dict_attr_t const * attr_packet_type
Definition rlm_radius.c:267
static fr_dict_attr_t const * attr_user_password
Definition rlm_radius.c:283
static fr_dict_attr_t const * attr_digest_response
Definition rlm_radius.c:275
#define RESPONSE_WINDOW_FIX(_x)
static fr_dict_attr_t const * attr_state
Definition rlm_radius.c:269
static fr_dict_attr_t const * attr_eap_message
Definition rlm_radius.c:277
static int type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static fr_dict_attr_t const * attr_chap_password
Definition rlm_radius.c:266
static int status_check_verify(map_t *map, void *ctx)
Definition rlm_radius.c:493
static fr_dict_attr_t const * attr_digest_attributes
Definition rlm_radius.c:274
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:694
static fr_dict_t const * dict_radius
Definition rlm_radius.c:257
static int mod_bootstrap(module_inst_ctx_t const *mctx)
static fr_dict_attr_t const * attr_chap_challenge
Definition rlm_radius.c:265
static conf_parser_t status_config[]
Definition rlm_radius.c:87
fr_dict_attr_autoload_t rlm_radius_dict_attr[]
Definition rlm_radius.c:286
static fr_dict_attr_t const * attr_extended_attribute_1
Definition rlm_radius.c:273
static fr_dict_attr_t const * attr_reply_message
Definition rlm_radius.c:280
static fr_dict_attr_t const * attr_error_cause
Definition rlm_radius.c:271
static void mod_unload(void)
static fr_dict_attr_t const * attr_proxy_state
Definition rlm_radius.c:268
static int radius_fixups(rlm_radius_t const *inst, request_t *request)
Do any RADIUS-layer fixups for proxying.
Definition rlm_radius.c:619
static fr_dict_attr_t const * attr_nas_identifier
Definition rlm_radius.c:278
static conf_parser_t const type_interval_config[FR_RADIUS_CODE_MAX]
Definition rlm_radius.c:248
static conf_parser_t auth_config[]
Definition rlm_radius.c:71
static int mode_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static conf_parser_t const tcp_config[]
Definition rlm_radius.c:146
module_rlm_t rlm_radius
fr_dict_autoload_t rlm_radius_dict[]
Definition rlm_radius.c:260
static fr_dict_attr_t const * attr_user_name
Definition rlm_radius.c:282
static int status_check_update_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static conf_parser_t const xlat_proxy_config[]
Definition rlm_radius.c:198
static fr_dict_attr_t const * attr_original_packet_code
Definition rlm_radius.c:279
static fr_dict_attr_t const * attr_event_timestamp
Definition rlm_radius.c:272
static conf_parser_t const status_check_update_config[]
Definition rlm_radius.c:60
static fr_dict_attr_t const * attr_response_length
Definition rlm_radius.c:281
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition rlm_radius.c:767
static conf_parser_t const status_check_config[]
Definition rlm_radius.c:41
static size_t mode_names_len
Definition rlm_radius.c:319
static fr_table_num_sorted_t mode_names[]
Definition rlm_radius.c:312
static conf_parser_t const module_config[]
Definition rlm_radius.c:215
static conf_parser_t const connected_config[]
Definition rlm_radius.c:160
static fr_dict_attr_t const * attr_message_authenticator
Definition rlm_radius.c:276
static conf_parser_t acct_config[]
Definition rlm_radius.c:79
struct rlm_radius_s rlm_radius_t
Definition rlm_radius.h:46
rlm_radius_mode_t
Definition rlm_radius.h:48
@ RLM_RADIUS_MODE_XLAT_PROXY
radius.sendto.ipaddr(), but we do look for a reply.
Definition rlm_radius.h:54
@ RLM_RADIUS_MODE_INVALID
Definition rlm_radius.h:49
@ RLM_RADIUS_MODE_PROXY
we proxy to one home server
Definition rlm_radius.h:50
@ RLM_RADIUS_MODE_REPLICATE
to a particular destination
Definition rlm_radius.h:52
@ RLM_RADIUS_MODE_UNCONNECTED_REPLICATE
radius.sendto.ipaddr(), but we don't look for a reply
Definition rlm_radius.h:53
@ RLM_RADIUS_MODE_CLIENT
we are a client to one home server
Definition rlm_radius.h:51
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
fr_time_delta_t connection_timeout
How long to wait for the connection to open or for shutdown to close the connection.
Definition connection.h:97
char const * name
Instance name e.g. user_database.
Definition module.h:361
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:355
size_t inst_size
Size of the module's instance data.
Definition module.h:213
void * data
Module's instance data.
Definition module.h:297
void * boot
Data allocated during the boostrap phase.
Definition module.h:300
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition module.h:153
Named methods exported by a module.
Definition module.h:175
#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:955
@ TMPL_ATTR_LIST_FORBID
Attribute refs are forbidden from having a list.
Definition tmpl.h:270
#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:826
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:343
@ FR_SIGNAL_NONE
No signals.
Definition signal.h:39
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(request_t *request, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
Definition module.c:431
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
#define talloc_strdup(_ctx, _str)
Definition talloc.h:149
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_add(fr_time_delta_t a, fr_time_delta_t b)
Definition time.h:255
static int64_t fr_time_delta_unwrap(fr_time_delta_t time)
Definition time.h:154
#define fr_time_delta_lt(_a, _b)
Definition time.h:285
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:599
#define fr_time_delta_wrap(_time)
Definition time.h:152
#define fr_time_delta_ispos(_a)
Definition time.h:290
#define fr_time_delta_gt(_a, _b)
Definition time.h:283
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
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
void trunk_request_signal_cancel(trunk_request_t *treq)
Cancel a trunk request.
Definition trunk.c:2289
conf_parser_t const trunk_config[]
Config parser definitions to populate a trunk_conf_t.
Definition trunk.c:364
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
#define fr_box_time_delta(_val)
Definition value.h:397
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