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