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: 200d29f5e86d326ef3330cb6327354de1da45d60 $
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: 200d29f5e86d326ef3330cb6327354de1da45d60 $")
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_uint8,
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
212
215 { .out = &attr_chap_challenge, .name = "CHAP-Challenge", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
216 { .out = &attr_chap_password, .name = "CHAP-Password", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
217 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_radius },
218 { .out = &attr_proxy_state, .name = "Proxy-State", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
219 { .out = &attr_state, .name = "State", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
220
221 { .out = &attr_error_cause, .name = "Error-Cause", .type = FR_TYPE_UINT32, .dict = &dict_radius },
222 { .out = &attr_event_timestamp, .name = "Event-Timestamp", .type = FR_TYPE_DATE, .dict = &dict_radius},
223 { .out = &attr_extended_attribute_1, .name = "Extended-Attribute-1", .type = FR_TYPE_TLV, .dict = &dict_radius},
224 { .out = &attr_digest_attributes, .name = "Digest-Attributes", .type = FR_TYPE_TLV, .dict = &dict_radius},
225 { .out = &attr_digest_response, .name = "Digest-Response", .type = FR_TYPE_STRING, .dict = &dict_radius},
226 { .out = &attr_message_authenticator, .name = "Message-Authenticator", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
227 { .out = &attr_eap_message, .name = "EAP-Message", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
228 { .out = &attr_nas_identifier, .name = "NAS-Identifier", .type = FR_TYPE_STRING, .dict = &dict_radius},
229 { .out = &attr_original_packet_code, .name = "Extended-Attribute-1.Original-Packet-Code", .type = FR_TYPE_UINT32, .dict = &dict_radius},
230 { .out = &attr_reply_message, .name = "Reply-Message", .type = FR_TYPE_STRING, .dict = &dict_radius},
231 { .out = &attr_response_length, .name = "Extended-Attribute-1.Response-Length", .type = FR_TYPE_UINT32, .dict = &dict_radius },
232 { .out = &attr_user_name, .name = "User-Name", .type = FR_TYPE_STRING, .dict = &dict_radius},
233 { .out = &attr_user_password, .name = "User-Password", .type = FR_TYPE_STRING, .dict = &dict_radius},
234
236};
237
238#include "bio.c"
239
241 { L("client"), RLM_RADIUS_MODE_CLIENT },
242 { L("dynamic-proxy"), RLM_RADIUS_MODE_XLAT_PROXY },
243 { L("proxy"), RLM_RADIUS_MODE_PROXY },
244 { L("replicate"), RLM_RADIUS_MODE_REPLICATE },
245 { L("unconnected-replicate"), RLM_RADIUS_MODE_UNCONNECTED_REPLICATE },
246};
248
249
250/** Set the mode of operation
251 *
252 * @param[in] ctx to allocate data in (instance of rlm_radius).
253 * @param[out] out Where to write the parsed data.
254 * @param[in] parent Base structure address.
255 * @param[in] ci #CONF_PAIR specifying the name of the type module.
256 * @param[in] rule unused.
257 * @return
258 * - 0 on success.
259 * - -1 on failure.
260 */
261static int mode_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent,
262 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
263{
264 char const *name = cf_pair_value(cf_item_to_pair(ci));
266 rlm_radius_t *inst = talloc_get_type_abort(parent, rlm_radius_t);
268
270
271 if (mode == RLM_RADIUS_MODE_INVALID) {
272 cf_log_err(ci, "Invalid mode name \"%s\"", name);
273 return -1;
274 }
275
276 *(rlm_radius_mode_t *) out = mode;
277
278 /*
279 * Normally we want connected sockets, in which case we push additional configuration for
280 * connected sockets.
281 */
282 switch (mode) {
283 default:
284 inst->fd_config.type = FR_BIO_FD_CONNECTED;
285
286 if (cf_section_rules_push(cs, connected_config) < 0) return -1;
287 break;
288
290 inst->fd_config.type = FR_BIO_FD_UNCONNECTED; /* reset later when the home server is allocated */
291
292 if (cf_section_rules_push(cs, pool_config) < 0) return -1;
293 break;
294
296 inst->fd_config.type = FR_BIO_FD_UNCONNECTED;
297 break;
298 }
299
300 return 0;
301}
302
303
304/** Set which types of packets we can parse
305 *
306 * @param[in] ctx to allocate data in (instance of rlm_radius).
307 * @param[out] out Where to write the parsed data.
308 * @param[in] parent Base structure address.
309 * @param[in] ci #CONF_PAIR specifying the name of the type module.
310 * @param[in] rule unused.
311 * @return
312 * - 0 on success.
313 * - -1 on failure.
314 */
315static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
316 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
317{
318 char const *type_str = cf_pair_value(cf_item_to_pair(ci));
320 fr_dict_enum_value_t const *type_enum;
321 uint32_t code;
322
323 /*
324 * Must be the RADIUS module
325 */
326 fr_assert(cs && (strcmp(cf_section_name1(cs), "radius") == 0));
327
328 /*
329 * Allow the process module to be specified by
330 * packet type.
331 */
332 type_enum = fr_dict_enum_by_name(attr_packet_type, type_str, -1);
333 if (!type_enum) {
334 invalid_code:
335 cf_log_err(ci, "Unknown or invalid RADIUS packet type '%s'", type_str);
336 return -1;
337 }
338
339 code = type_enum->value->vb_uint32;
340
341 /*
342 * Status-Server packets cannot be proxied.
343 */
344 if (code == FR_RADIUS_CODE_STATUS_SERVER) {
345 cf_log_err(ci, "Invalid setting of 'type = Status-Server'. Status-Server packets cannot be proxied.");
346 return -1;
347 }
348
349 if (!code ||
350 (code >= FR_RADIUS_CODE_MAX)) goto invalid_code;
351
352 if (!type_interval_config[code].name1) {
353 cf_log_err(ci, "Invalid packet type '%s' - cannot proxy a response packet", type_str);
354 return -1;
355 }
356
357 /*
358 * If we're doing async proxying, push the timers for the
359 * various packet types.
360 */
362
363 *(uint32_t *) out = code;
364
365 return 0;
366}
367
368/** Allow for Status-Server ping checks
369 *
370 * @param[in] ctx to allocate data in (instance of proto_radius).
371 * @param[out] out Where to write our parsed data.
372 * @param[in] parent Base structure address.
373 * @param[in] ci #CONF_PAIR specifying the name of the type module.
374 * @param[in] rule unused.
375 * @return
376 * - 0 on success.
377 * - -1 on failure.
378 */
379static int status_check_type_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
380 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
381{
382 char const *type_str = cf_pair_value(cf_item_to_pair(ci));
384 fr_dict_enum_value_t const *type_enum;
385 uint32_t code;
386
387 /*
388 * Allow the process module to be specified by
389 * packet type.
390 */
391 type_enum = fr_dict_enum_by_name(attr_packet_type, type_str, -1);
392 if (!type_enum) {
393 invalid_code:
394 cf_log_err(ci, "Unknown or invalid RADIUS packet type '%s'", type_str);
395 return -1;
396 }
397
398 code = type_enum->value->vb_uint32;
399
400 /*
401 * Cheat, and reuse the "type" array for allowed packet
402 * types.
403 */
404 if (!code ||
405 (code >= FR_RADIUS_CODE_MAX) ||
406 (!type_interval_config[code].name1)) goto invalid_code;
407
408 /*
409 * Add irt / mrt / mrd / mrc parsing, in the parent
410 * configuration section.
411 */
413
414 memcpy(out, &code, sizeof(code));
415
417
418 return 0;
419}
420
421static int status_check_verify(map_t *map, void *ctx)
422{
424 fr_dict_attr_t const *da;
425
427
428 if (unlang_fixup_update(map, NULL) < 0) return -1;
429
430 if (!map->rhs) return 0;
431
432 if (tmpl_is_xlat(map->rhs)) {
433 if (xlat_impure_func(tmpl_xlat(map->rhs))) {
434 invalid_xlat:
435 cf_log_err(map->ci, "Cannot assign dynamic values here");
436 return -1;
437 }
438 } else if (!tmpl_is_data(map->rhs)) {
439 goto invalid_xlat;
440 }
441
442 da = tmpl_attr_tail_da(map->lhs);
443
444 /*
445 * Ignore internal attributes.
446 */
447 if (da->flags.internal) {
448 cf_log_err(map->ci, "Cannot use internal attributes");
449 return -1;
450 }
451
452 /*
453 * Ignore signalling attributes. They shouldn't exist.
454 */
455 if ((da == attr_proxy_state) ||
457 cannot_use:
458 cf_log_err(map->ci, "Cannot use %s here.", da->name);
459 return -1;
460 }
461
462 /*
463 * Allow passwords only in Access-Request packets.
464 */
465 if ((inst->status_check != FR_RADIUS_CODE_ACCESS_REQUEST) &&
466 ((da == attr_user_password) || (da == attr_chap_password) || (da == attr_eap_message))) {
467 goto cannot_use;
468 }
469
470 /*
471 * RFC 5997 Section 5 says these MUST NOT be in Status-Server.
472 * The passwords are covered above.
473 */
474 if ((inst->status_check == FR_RADIUS_CODE_STATUS_SERVER) &&
475 ((da == attr_user_name) || (da == attr_reply_message) ||
476 (da == attr_digest_response) || (da == attr_digest_attributes) ||
477 (da->parent == attr_digest_attributes))) {
478 goto cannot_use;
479 }
480
481 return 0;
482}
483
484/** Allow the admin to set packet contents for Status-Server ping checks
485 *
486 * @param[in] ctx to allocate data in (instance of proto_radius).
487 * @param[out] out Where to write our parsed data
488 * @param[in] parent Base structure address.
489 * @param[in] ci #CONF_SECTION specifying the things to update
490 * @param[in] rule unused.
491 * @return
492 * - 0 on success.
493 * - -1 on failure.
494 */
495static int status_check_update_parse(TALLOC_CTX *ctx, void *out, void *parent,
496 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
497{
498 int rcode;
499 CONF_SECTION *cs;
500 char const *name2;
501 map_list_t *head = (map_list_t *)out;
502
504 map_list_init(head);
505
506 cs = cf_item_to_section(ci);
507 name2 = cf_section_name2(cs);
508 if (name2 && (strcmp(name2, "request") != 0)) {
509 cf_log_err(cs, "Only 'request' can be specified as the destination list");
510 return -1;
511 }
512
513 /*
514 * Compile the "update" section.
515 */
516 {
517 tmpl_rules_t parse_rules = {
518 .attr = {
520 .namespace = fr_dict_root(dict_radius),
521 .list_def = request_attr_request,
522 .list_presence = TMPL_ATTR_LIST_FORBID,
523 },
524 .literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
525 };
526
527 rcode = map_afrom_cs(ctx, head, cs, &parse_rules, &parse_rules, status_check_verify, parent, 128);
528 if (rcode < 0) return -1; /* message already printed */
529
530 /*
531 * status_check_alloc() supplies a NAS-Identifier when the
532 * map is empty, so an empty map needs no error here.
533 */
534 }
535
536 /*
537 * Rely on "bootstrap" to do sanity checks between 'type
538 * = Access-Request', and 'update' containing passwords.
539 */
540 return 0;
541}
542
543
544/** Do any RADIUS-layer fixups for proxying.
545 *
546 */
548{
549 fr_pair_t *vp;
550
551 /*
552 * If we received a Status-Server packet from the network, then don't proxy it.
553 *
554 * But we do sneakily allow virtual servers to originate and then send Status-Server packets.
555 */
556 if ((request->packet->code == FR_RADIUS_CODE_STATUS_SERVER) &&
557 ((request->packet->socket.af == AF_INET) || (request->packet->socket.af == AF_INET6))) {
558 RWDEBUG("Status-Server is reserved for internal use, and cannot be proxied.");
559 return 0;
560 }
561
562 if (!inst->allowed[request->packet->code]) {
563 REDEBUG("Packet code %s is disallowed by the configuration",
564 fr_radius_packet_name[request->packet->code]);
565 return -1;
566 }
567
568 /*
569 * Check for proxy loops.
570 *
571 * There should _never_ be two instances of the same Proxy-State in the packet.
572 */
573 if ((inst->mode == RLM_RADIUS_MODE_PROXY) && RDEBUG_ENABLED) {
574 unsigned int count = 0;
575 fr_dcursor_t cursor;
576
577 for (vp = fr_pair_dcursor_by_da_init(&cursor, &request->request_pairs, attr_proxy_state);
578 vp;
579 vp = fr_dcursor_next(&cursor)) {
580 if (vp->vp_length != sizeof(inst->common_ctx.proxy_state)) continue;
581
582 if (memcmp(vp->vp_octets, &inst->common_ctx.proxy_state,
583 sizeof(inst->common_ctx.proxy_state)) == 0) {
584
585 /*
586 * Cancel proxying when there are two instances of the same Proxy-State
587 * in the packet. This limitation could be configurable, but it likely
588 * doesn't make sense to make it configurable.
589 */
590 if (count == 1) {
591 RWARN("Canceling proxy due to loop of multiple %pV", vp);
592 return -1;
593 }
594
595 RWARN("Proxied packet contains our own %pV", vp);
596 RWARN("Check if there is a proxy loop. Perhaps the server has been configured to proxy to itself.");
597 count++;
598 }
599 }
600 }
601
602 if (request->packet->code != FR_RADIUS_CODE_ACCESS_REQUEST) return 0;
603
604 if (fr_pair_find_by_da(&request->request_pairs, NULL, attr_chap_password) &&
605 !fr_pair_find_by_da(&request->request_pairs, NULL, attr_chap_challenge)) {
607 fr_pair_value_memdup(vp, request->packet->vector, sizeof(request->packet->vector), true);
608 }
609
610 return 0;
611}
612
613
614/** Send packets outbound.
615 *
616 */
618{
620 bio_thread_t *thread = talloc_get_type_abort(mctx->thread, bio_thread_t);
621 fr_client_t *client;
622 int rcode;
623 bio_request_t *u = NULL;
624 fr_retry_config_t const *retry_config = NULL;
625
626 if (!request->packet->code) {
627 REDEBUG("You MUST specify a packet code");
629 }
630
631 if ((request->packet->code >= FR_RADIUS_CODE_MAX) ||
632 !fr_time_delta_ispos(inst->retry[request->packet->code].irt)) { /* can't be zero */
633 REDEBUG("Invalid packet code %u", request->packet->code);
635 }
636
637 /*
638 * Unconnected sockets use %radius.sendto.ipaddr(ip, port, secret)
639 */
641 (inst->mode == RLM_RADIUS_MODE_XLAT_PROXY)) {
642 REDEBUG("When using 'mode = %s', this module cannot be used in-place. "
643 "Instead, it must be called via a function call",
644 fr_table_str_by_value(mode_names, inst->mode, "<INVALID>"));
646 }
647
649 if (client && client->dynamic && !client->active) {
650 REDEBUG("Cannot proxy packets which define dynamic clients");
652 }
653
654 /*
655 * Push the request and it's data to the IO submodule.
656 *
657 * This may return YIELD, for "please yield", or it may
658 * return another code which indicates what happened to
659 * the request...
660 */
661 rcode = mod_enqueue(&u, &retry_config, inst, thread->ctx.trunk, request);
662 if (rcode == 0) RETURN_UNLANG_NOOP;
663 if (rcode < 0) RETURN_UNLANG_FAIL;
664
666}
667
668
669static int mod_instantiate(module_inst_ctx_t const *mctx)
670{
671 size_t i, num_types;
672 rlm_radius_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_radius_t);
673 CONF_SECTION *conf = mctx->mi->conf;
674
675 inst->name = mctx->mi->name;
676 inst->received_message_authenticator = talloc_zero(NULL, bool); /* Allocated outside of inst to default protection */
677
678 /*
679 * Replication is write-only, and append by default.
680 */
681 if (inst->mode == RLM_RADIUS_MODE_REPLICATE) {
682 if (inst->fd_config.filename && (inst->fd_config.flags != O_WRONLY)) {
683 cf_log_info(conf, "Setting 'flags = write-only' for writing to a file");
684 }
685 inst->fd_config.flags = O_WRONLY | O_APPEND;
686
687 } else if (inst->fd_config.filename) {
688 cf_log_err(conf, "When using an output 'filename', you MUST set 'mode = replicate'");
689 return -1;
690
691 } else {
692 /*
693 * All other IO is read+write.
694 */
695 inst->fd_config.flags = O_RDWR;
696 }
697
698 if (fr_bio_fd_check_config(&inst->fd_config) < 0) {
699 cf_log_perr(conf, "Invalid configuration");
700 return -1;
701 }
702
703 /*
704 * Clamp max_packet_size first before checking recv_buff and send_buff
705 */
706 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, >=, 64);
707 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, <=, 65535);
708
709 /*
710 * Check invalid configurations.
711 */
712 switch (inst->mode) {
713 default:
714 /*
715 * Filenames are write-only, and cannot get response packets.
716 */
717 if (inst->fd_config.filename) {
718 cf_log_err(conf, "Cannot set 'filename' here - it is only supported for 'mode=replicate'");
719 return -1;
720 }
721
722 /*
723 * When we expect replies, we need to be able to open multiple source ports. So the
724 * admin can't force a particular source port.
725 */
726 if (inst->fd_config.src_port) {
727 cf_log_err(conf, "Cannot 'src_port' here - it can only be set for replicating packets");
728 return -1;
729 }
730
731 /*
732 * Encorce limits per trunk, due to the 8-bit ID space.
733 */
734 FR_INTEGER_BOUND_CHECK("trunk.per_connection_max", inst->trunk_conf.max_req_per_conn, >=, 2);
735 FR_INTEGER_BOUND_CHECK("trunk.per_connection_max", inst->trunk_conf.max_req_per_conn, <=, 255);
736 FR_INTEGER_BOUND_CHECK("trunk.per_connection_target", inst->trunk_conf.target_req_per_conn, <=, inst->trunk_conf.max_req_per_conn / 2);
737
738 /*
739 * This only applies for XLAT_PROXY, but what the heck.
740 */
741 FR_TIME_DELTA_BOUND_CHECK("home_server_lifetime", inst->home_server_lifetime, >=, fr_time_delta_from_sec(10));
742 FR_TIME_DELTA_BOUND_CHECK("home_server_lifetime", inst->home_server_lifetime, <=, fr_time_delta_from_sec(3600));
743
744 /*
745 * No src_port range, we don't need to check any other settings.
746 */
747 if (!inst->fd_config.src_port_start && !inst->fd_config.src_port_end) break;
748
749 if (inst->fd_config.path) {
750 cf_log_err(conf, "Cannot set 'src_port_start' or 'src_port_end' for outgoing Unix sockets");
751 return -1;
752 }
753
754 /*
755 * Cross-check src_port, src_port_start, and src_port_end.
756 */
757 if (inst->fd_config.src_port_start) {
758 if (!inst->fd_config.src_port_end) {
759 cf_log_err(conf, "Range has 'src_port_start', but is missing 'src_port_end'");
760 return -1;
761 }
762
763 if (inst->fd_config.src_port_start >= inst->fd_config.src_port_end) {
764 cf_log_err(conf, "Range has invalid values for 'src_port_start' ... 'src_port_end'");
765 return -1;
766 }
767
768 } else if (inst->fd_config.src_port_end) {
769 cf_log_err(conf, "Range has 'src_port_end', but is missing 'src_port_start'");
770 return -1;
771 }
772
773 /*
774 * The source port range is split by worker - so there needs to be sufficient for at least
775 * one per worker.
776 */
777 if ((inst->fd_config.src_port_end - inst->fd_config.src_port_start + 1) < (int) main_config->max_workers) {
778 cf_log_perr(conf, "src_port_start / end range is not enough for %u worker threads",
780 return -1;
781 }
782
783 /*
784 * If there is a limited source port range, then set the reuse port flag. This lets us
785 * bind multiple sockets to the same port before we connect() them.
786 */
787 inst->fd_config.reuse_port = 1;
788 break;
789
791 /*
792 * Replication to dynamic filenames or dynamic unix sockets isn't supported.
793 */
794 if (inst->fd_config.filename || inst->fd_config.path) {
795 cf_log_err(conf, "Cannot set 'filename' or 'path' when using 'mode=unconnected-replicate'");
796 return -1;
797 }
798
799 /*
800 * Unconnected replicate has to use UDP.
801 */
802 if (inst->fd_config.socket_type != SOCK_DGRAM) {
803 cf_log_err(conf, "Cannot use TCP sockets with 'mode=unconnected-replicate'");
804 return -1;
805 }
806
808
810 /*
811 * We can force the source port, but then we have to set SO_REUSEPORT.
812 */
813 inst->fd_config.reuse_port = (inst->fd_config.src_port != 0);
814
815 /*
816 * Files and unix sockets are OK. The src_port can be set (or not), and that's fine.
817 */
818 if (inst->fd_config.src_port_start || inst->fd_config.src_port_end) {
819 cf_log_err(conf, "Cannot set 'src_port_start' or 'src_port_end' when replicating packets");
820 return -1;
821 }
822 break;
823 }
824
825 /*
826 * We allow what may otherwise be conflicting configurations, because the BIO code will pick one
827 * path, and the conflicts won't affect anything else. Only the src_port range is special.
828 */
829
830 FR_TIME_DELTA_BOUND_CHECK("response_window", inst->response_window, >=, fr_time_delta_from_sec(1));
831 FR_TIME_DELTA_BOUND_CHECK("response_window", inst->response_window, <=, fr_time_delta_from_sec(120));
832
833 FR_TIME_DELTA_BOUND_CHECK("zombie_period", inst->zombie_period, >=, fr_time_delta_from_sec(1));
834 FR_TIME_DELTA_BOUND_CHECK("zombie_period", inst->zombie_period, <=, fr_time_delta_from_sec(120));
835
836 if (!inst->status_check) {
837 FR_TIME_DELTA_BOUND_CHECK("revive_interval", inst->revive_interval, >=, fr_time_delta_from_sec(10));
838 FR_TIME_DELTA_BOUND_CHECK("revive_interval", inst->revive_interval, <=, fr_time_delta_from_sec(3600));
839 }
840
841 num_types = talloc_array_length(inst->types);
842 fr_assert(num_types > 0);
843
844 inst->timeout_retry = (fr_retry_config_t) {
845 .mrc = 1,
846 .mrd = inst->response_window,
847 };
848
849 inst->common_ctx = (fr_radius_ctx_t) {
850 .secret = inst->secret,
851 .secret_length = inst->secret ? talloc_strlen(inst->secret) : 0,
852 .proxy_state = ((uint64_t) fr_rand()) << 32 | fr_rand(),
853 };
854
855 /*
856 * Allow for O(1) lookup later...
857 */
858 for (i = 0; i < num_types; i++) {
859 uint32_t code;
860
861 code = inst->types[i];
862 fr_assert(code > 0);
864
865 if (inst->allowed[code]) {
866 cf_log_err(conf, "Duplicate 'type = %s'", fr_radius_packet_name[code]);
867 return -1;
868 }
869
870 inst->allowed[code] = true;
871 }
872
873 fr_assert(inst->status_check < FR_RADIUS_CODE_MAX);
874
875 /*
876 * If we're replicating, we don't care if the other end
877 * is alive.
878 */
879 if (inst->status_check) {
880 if (inst->mode == RLM_RADIUS_MODE_REPLICATE) {
881 cf_log_warn(conf, "Ignoring 'status_check = %s' due to 'mode = replicate'",
882 fr_radius_packet_name[inst->status_check]);
883 inst->status_check = false;
884
885 } else if ((inst->mode == RLM_RADIUS_MODE_UNCONNECTED_REPLICATE) ||
886 (inst->mode == RLM_RADIUS_MODE_XLAT_PROXY)) {
887 cf_log_warn(conf, "Ignoring 'status_check = %s' due to 'mode' setting",
888 fr_radius_packet_name[inst->status_check]);
889 inst->status_check = false;
890 }
891 }
892
893 /*
894 * If we have status checks, then do some sanity checks.
895 * Status-Server is always allowed. Otherwise, the
896 * status checks have to match one of the allowed
897 * packets.
898 */
899 if (inst->status_check) {
900 if (inst->status_check == FR_RADIUS_CODE_STATUS_SERVER) {
901 inst->allowed[inst->status_check] = true;
902
903 } else if (!inst->allowed[inst->status_check]) {
904 cf_log_err(conf, "Using 'status_check = %s' requires also 'type = %s'",
905 fr_radius_packet_name[inst->status_check], fr_radius_packet_name[inst->status_check]);
906 return -1;
907 }
908
909 /*
910 * @todo - check the contents of the "update"
911 * section, to be sure that (e.g.) Access-Request
912 * contains User-Name, etc.
913 */
914
915 if (inst->fd_config.filename) {
916 cf_log_info(conf, "Disabling status checks for output file %s", inst->fd_config.filename);
917 inst->status_check = 0;
918 }
919 }
920
921 /*
922 * Files and unix sockets can just have us call write().
923 */
924 if (inst->fd_config.filename || inst->fd_config.path) {
925 inst->max_send_coalesce = 1;
926 }
927
928 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 */
929 inst->trunk_conf.req_pool_size = 1024 + sizeof(fr_pair_t) + 20;
930
931 if (inst->trunk_conf.conn_triggers) {
933 char *server = NULL;
934
936 .module = mctx->mi->module->name,
937 .name = inst->name
938 };
939
940 /*
941 * Only client and proxy mode have fixed destinations
942 */
943 if ((inst->mode == RLM_RADIUS_MODE_CLIENT) || (inst->mode == RLM_RADIUS_MODE_PROXY)) {
944 fr_value_box_aprint(inst, &server, fr_box_ipaddr(inst->fd_config.dst_ipaddr), NULL);
945 args.server = server;
946 args.port = inst->fd_config.dst_port;
947 }
948
949 MEM(inst->trigger_args = fr_pair_list_alloc(inst));
950 if (module_trigger_args_build(inst->trigger_args, inst->trigger_args,
951 cf_section_find(conf, "pool", NULL), &args) < 0) return -1;
952 }
953
954 /*
955 * Only check the async timers when we're acting as a client.
956 */
957 if (inst->mode != RLM_RADIUS_MODE_CLIENT) {
958 return 0;
959 }
960
961 /*
962 * Set limits on retransmission timers
963 */
964 if (inst->allowed[FR_RADIUS_CODE_ACCESS_REQUEST]) {
965 FR_TIME_DELTA_BOUND_CHECK("Access-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].irt, >=, fr_time_delta_from_sec(1));
966 FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
967 FR_INTEGER_BOUND_CHECK("Access-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrc, >=, 1);
968 FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrd, >=, fr_time_delta_from_sec(5));
969
970 FR_TIME_DELTA_BOUND_CHECK("Access-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].irt, <=, fr_time_delta_from_sec(15));
971 FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrt, <=, fr_time_delta_from_sec(30));
972 FR_INTEGER_BOUND_CHECK("Access-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrc, <=, 10);
973 FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrd, <=, fr_time_delta_from_sec(90));
974 }
975
976 /*
977 * Note that RFC 5080 allows for Accounting-Request to
978 * have mrt=mrc=mrd = 0, which means "retransmit
979 * forever". We allow that, with the restriction that
980 * the server core will automatically free the request at
981 * request.timeout.
982 */
984 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].irt, >=, fr_time_delta_from_sec(1));
985#if 0
986 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
987 FR_INTEGER_BOUND_CHECK("Accounting-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrc, >=, 0);
988 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrd, >=, fr_time_delta_from_sec(0));
989#endif
990
991 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].irt, <=, fr_time_delta_from_sec(5));
992 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrt, <=, fr_time_delta_from_sec(30));
993 FR_INTEGER_BOUND_CHECK("Accounting-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrc, <=, 10);
994 FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
995 }
996
997 /*
998 * Status-Server
999 */
1000 if (inst->allowed[FR_RADIUS_CODE_STATUS_SERVER]) {
1001 FR_TIME_DELTA_BOUND_CHECK("Status-Server.initial_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].irt, >=, fr_time_delta_from_sec(1));
1002 FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrt, >=, fr_time_delta_from_sec(5));
1003 FR_INTEGER_BOUND_CHECK("Status-Server.max_rtx_count", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrc, >=, 1);
1004 FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_duration", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrd, >=, fr_time_delta_from_sec(5));
1005
1006 FR_TIME_DELTA_BOUND_CHECK("Status-Server.initial_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].irt, <=, fr_time_delta_from_sec(5));
1007 FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrt, <=, fr_time_delta_from_sec(30));
1008 FR_INTEGER_BOUND_CHECK("Status-Server.max_rtx_count", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrc, <=, 10);
1009 FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_duration", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrd, <=, fr_time_delta_from_sec(30));
1010 }
1011
1012 /*
1013 * CoA
1014 */
1015 if (inst->allowed[FR_RADIUS_CODE_COA_REQUEST]) {
1016 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].irt, >=, fr_time_delta_from_sec(1));
1017 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
1018 FR_INTEGER_BOUND_CHECK("CoA-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrc, >=, 1);
1019 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrd, >=, fr_time_delta_from_sec(5));
1020
1021 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].irt, <=, fr_time_delta_from_sec(5));
1022 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrt, <=, fr_time_delta_from_sec(60));
1023 FR_INTEGER_BOUND_CHECK("CoA-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrc, <=, 10);
1024 FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
1025 }
1026
1027 /*
1028 * Disconnect
1029 */
1031 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].irt, >=, fr_time_delta_from_sec(1));
1032 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
1033 FR_INTEGER_BOUND_CHECK("Disconnect-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrc, >=, 1);
1034 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrd, >=, fr_time_delta_from_sec(5));
1035
1036 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].irt, <=, fr_time_delta_from_sec(5));
1037 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrt, <=, fr_time_delta_from_sec(30));
1038 FR_INTEGER_BOUND_CHECK("Disconnect-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrc, <=, 10);
1039 FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
1040 }
1041
1042 return 0;
1043}
1044
1045static int mod_bootstrap(module_inst_ctx_t const *mctx)
1046{
1047 xlat_t *xlat;
1048 rlm_radius_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_radius_t);
1049
1050 switch (inst->mode) {
1052 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "sendto.ipaddr", xlat_radius_replicate, FR_TYPE_VOID);
1054 break;
1055
1057 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "sendto.ipaddr", xlat_radius_client, FR_TYPE_UINT32);
1059 break;
1060
1061 default:
1062 break;
1063 }
1064
1065 return 0;
1066}
1067
1068
1069static int mod_detach(module_detach_ctx_t const *mctx)
1070{
1071 rlm_radius_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_radius_t);
1072
1073 talloc_free(inst->received_message_authenticator);
1074 return 0;
1075}
1076
1077static int mod_load(void)
1078{
1079 if (fr_radius_global_init() < 0) {
1080 PERROR("Failed initialising protocol library");
1081 return -1;
1082 }
1083 return 0;
1084}
1085
1086static void mod_unload(void)
1087{
1089}
1090
1091/*
1092 * The module name should be the only globally exported symbol.
1093 * That is, everything else should be 'static'.
1094 *
1095 * If the module needs to temporarily modify it's instantiation
1096 * data, the type should be changed to MODULE_TYPE_THREAD_UNSAFE.
1097 * The server will then take care of ensuring that the module
1098 * is single-threaded.
1099 */
1102 .common = {
1103 .magic = MODULE_MAGIC_INIT,
1104 .name = "radius",
1105 .inst_size = sizeof(rlm_radius_t),
1107 .dict = &dict_radius,
1108
1109 .onload = mod_load,
1110 .unload = mod_unload,
1111
1112 .bootstrap = mod_bootstrap,
1113 .instantiate = mod_instantiate,
1114 .detach = mod_detach,
1115
1116 .thread_inst_size = sizeof(bio_thread_t),
1117 .thread_inst_type = "bio_thread_t",
1118 .thread_instantiate = mod_thread_instantiate,
1119 },
1120 .method_group = {
1121 .bindings = (module_method_binding_t[]){
1122 { .section = SECTION_NAME(CF_IDENT_ANY, CF_IDENT_ANY), .method = mod_process },
1124 },
1125 }
1126};
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:923
static uint8_t request[4]
#define RCSID(id)
Definition build.h:603
#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:437
#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_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:460
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:2717
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:3778
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:314
@ 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
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: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:2992
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: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 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:211
static fr_dict_attr_t const * attr_digest_response
Definition rlm_radius.c:203
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:205
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:421
static fr_dict_attr_t const * attr_digest_attributes
Definition rlm_radius.c:202
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:617
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:214
static fr_dict_attr_t const * attr_extended_attribute_1
Definition rlm_radius.c:201
static fr_dict_attr_t const * attr_reply_message
Definition rlm_radius.c:208
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:547
static fr_dict_attr_t const * attr_nas_identifier
Definition rlm_radius.c:206
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 fr_dict_attr_t const * attr_user_name
Definition rlm_radius.c:210
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:207
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:209
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition rlm_radius.c:669
static conf_parser_t const status_check_config[]
Definition rlm_radius.c:41
static size_t mode_names_len
Definition rlm_radius.c:247
static fr_table_num_sorted_t mode_names[]
Definition rlm_radius.c:240
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:204
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: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_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:599
#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