The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
proto_dhcpv6_udp.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: 3781706c2ea85223718671f9ea139f3d8afbdce2 $
19 * @file proto_dhcpv6_udp.c
20 * @brief DHCPv6 handler for UDP.
21 *
22 * @copyright 2020 Network RADIUS SAS (legal@networkradius.com)
23 */
24#define LOG_PREFIX "proto_dhcpv6_udp"
25
26#include <freeradius-devel/server/protocol.h>
27#include <freeradius-devel/util/udp.h>
28#include <freeradius-devel/util/trie.h>
29#include <freeradius-devel/io/application.h>
30#include <freeradius-devel/io/listen.h>
31#include <freeradius-devel/io/schedule.h>
32#include <freeradius-devel/protocol/dhcpv6/freeradius.internal.h>
33#include "proto_dhcpv6.h"
34
36
37typedef struct {
38 char const *name; //!< socket name
39 int sockfd;
40
41 fr_io_address_t *connection; //!< for connected sockets.
42
43 fr_stats_t stats; //!< statistics for this socket
45
46typedef struct {
47 CONF_SECTION *cs; //!< our configuration
48
49 fr_ipaddr_t ipaddr; //!< IP address to listen on.
50
51 fr_ipaddr_t src_ipaddr; //!< IP address to source replies
52
53 char const *interface; //!< Interface to bind to.
54 char const *port_name; //!< Name of the port for getservent().
55 fr_ethernet_t ethernet; //!< ethernet address associated with the interface
56
57 uint32_t recv_buff; //!< How big the kernel's receive buffer should be.
58
59 uint32_t hop_limit; //!< for multicast addresses
60 uint32_t max_packet_size; //!< for message ring buffer.
61 uint32_t max_attributes; //!< Limit maximum decodable attributes.
62
63 uint16_t port; //!< Port to listen on.
64
65 bool multicast; //!< whether or not we listen for multicast packets
66
67 bool recv_buff_is_set; //!< Whether we were provided with a receive
68 //!< buffer value.
69 bool dynamic_clients; //!< whether we have dynamic clients
70
71 fr_client_list_t *clients; //!< local clients
72 fr_client_t *default_client; //!< default 0/0 client
73
74 fr_trie_t *trie; //!< for parsed networks
75 fr_ipaddr_t *allow; //!< allowed networks for dynamic clients
76 fr_ipaddr_t *deny; //!< denied networks for dynamic clients
78
79
86
87
91
93
94 { FR_CONF_OFFSET("interface", proto_dhcpv6_udp_t, interface) },
95 { FR_CONF_OFFSET("port_name", proto_dhcpv6_udp_t, port_name) },
96
97 { FR_CONF_OFFSET("port", proto_dhcpv6_udp_t, port), .dflt = "547" },
98 { FR_CONF_OFFSET_IS_SET("recv_buff", FR_TYPE_UINT32, 0, proto_dhcpv6_udp_t, recv_buff) },
99
100 { FR_CONF_OFFSET("hop_limit", proto_dhcpv6_udp_t, hop_limit) },
101
102 { FR_CONF_OFFSET("dynamic_clients", proto_dhcpv6_udp_t, dynamic_clients) } ,
103 { FR_CONF_POINTER("networks", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) networks_config },
104
105 { FR_CONF_OFFSET("max_packet_size", proto_dhcpv6_udp_t, max_packet_size), .dflt = "8192" } ,
106 { FR_CONF_OFFSET("max_attributes", proto_dhcpv6_udp_t, max_attributes), .dflt = STRINGIFY(DHCPV6_MAX_ATTRIBUTES) } ,
107
109};
110
111static fr_dict_t const *dict_dhcpv6;
112
118
122
125 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_dhcpv6},
126 { .out = &attr_client_id, .name = "Client-ID", .type = FR_TYPE_STRUCT, .dict = &dict_dhcpv6},
127 { .out = &attr_relay_message, .name = "Relay-Message", .type = FR_TYPE_GROUP, .dict = &dict_dhcpv6 },
129};
130
131static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len,
132 size_t *leftover)
133{
135 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
136 fr_io_address_t *address, **address_p;
137
138 int flags;
139 ssize_t data_size;
140 size_t packet_len;
141 uint32_t xid;
142 fr_dhcpv6_packet_t *packet;
143
144 *leftover = 0; /* always for UDP */
145
146 /*
147 * Where the addresses should go. This is a special case
148 * for proto_dhcpv6.
149 */
150 address_p = (fr_io_address_t **)packet_ctx;
151 address = *address_p;
152
153 /*
154 * Tell udp_recv if we're connected or not.
155 */
156 flags = UDP_FLAGS_CONNECTED * (thread->connection != NULL);
157
158 data_size = udp_recv(thread->sockfd, flags, &address->socket, buffer, buffer_len, recv_time_p);
159 if (data_size < 0) {
160 RATE_LIMIT_GLOBAL(PERROR, "Read error (%zd)", data_size);
161 return data_size;
162 }
163
164 if ((size_t) data_size < sizeof(fr_dhcpv6_packet_t)) {
165 RATE_LIMIT_GLOBAL(WARN, "Insufficient data - ignoring");
166 return 0;
167 }
168
169 packet_len = data_size;
170
171 /*
172 * We've seen a server reply to this port, but the giaddr
173 * is *not* our address. Drop it.
174 */
175 packet = (fr_dhcpv6_packet_t *) buffer;
176 if (!packet->code || (packet->code >= FR_DHCPV6_CODE_MAX)) {
177 RATE_LIMIT_GLOBAL(WARN, "Unsupported packet code %d - ignoring", packet->code);
178 return 0;
179 }
180
181 /*
182 * RFC 8415 Section 18.4 forbids certain types of packets
183 * from being received on a unicast address.
184 */
185 if (!inst->multicast) {
186 if ((packet->code == FR_DHCPV6_SOLICIT) ||
187 (packet->code == FR_DHCPV6_REBIND) ||
188 (packet->code == FR_DHCPV6_CONFIRM)) {
189 RATE_LIMIT_GLOBAL(WARN, "Unicast packet %s - ignoring", fr_dhcpv6_packet_names[packet->code]);
190 return 0;
191 }
192 } /* else it was multicast... remember that */
193
194 /*
195 * @todo - make this take "&packet_len", as the DHCPv4
196 * packet may be smaller than the parent UDP packet.
197 */
198 if (fr_dhcpv6_ok(buffer, data_size, inst->max_attributes) <= 0) {
199 RATE_LIMIT_GLOBAL(PWARN, "Invalid packet - ignoring");
200 return 0;
201 }
202
203 /*
204 * proto_dhcpv6 sets the priority
205 */
206
207 xid = fr_nbo_to_uint24(packet->transaction_id);
208
209 /*
210 * Print out what we received.
211 */
212 DEBUG2("Received %s XID %08x length %d %s", fr_dhcpv6_packet_names[packet->code], xid,
213 (int) packet_len, thread->name);
214
215 return packet_len;
216}
217
218static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, UNUSED fr_time_t request_time,
219 uint8_t *buffer, size_t buffer_len, UNUSED size_t written)
220{
222 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
223
224 fr_io_track_t *track = talloc_get_type_abort(packet_ctx, fr_io_track_t);
225 fr_socket_t socket;
226
227 int flags;
228 ssize_t data_size;
229
230 /*
231 * @todo - share a stats interface with the parent? or
232 * put the stats in the listener, so that proto_dhcpv6
233 * can update them, too.. <sigh>
234 */
235 thread->stats.total_responses++;
236
237 flags = UDP_FLAGS_CONNECTED * (thread->connection != NULL);
238
239 /*
240 * Send packets to the originator, EXCEPT that we always
241 * originate packets from our src_ipaddr.
242 */
243 fr_socket_addr_swap(&socket, &track->address->socket);
244 if (!fr_ipaddr_is_inaddr_any(&inst->src_ipaddr)) socket.inet.src_ipaddr = inst->src_ipaddr;
245
246 /*
247 * Figure out which kind of packet we're sending.
248 */
249 if (!thread->connection) {
250 // @todo - figure out where to send the packet
251 }
252
253 /*
254 * proto_dhcpv6 takes care of suppressing do-not-respond, etc.
255 */
256 data_size = udp_send(&socket, flags, buffer, buffer_len);
257
258 /*
259 * This socket is dead. That's an error...
260 */
261 if (data_size <= 0) return data_size;
262
263 return data_size;
264}
265
266
268{
269 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
270
271 thread->connection = connection;
272 return 0;
273}
274
275
276static void mod_network_get(int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, void *instance)
277{
278 proto_dhcpv6_udp_t *inst = talloc_get_type_abort(instance, proto_dhcpv6_udp_t);
279
280 *ipproto = IPPROTO_UDP;
281 *dynamic_clients = inst->dynamic_clients;
282 *trie = inst->trie;
283}
284
285
286/** Open a UDP listener for DHCPv6
287 *
288 */
289static int mod_open(fr_listen_t *li)
290{
292 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
293
294 int sockfd, rcode;
295 fr_ipaddr_t ipaddr = inst->ipaddr;
296 uint16_t port = inst->port;
297
298 li->fd = sockfd = fr_socket_server_udp(&inst->ipaddr, &port, inst->port_name, true);
299 if (sockfd < 0) {
300 cf_log_err(li->cs, "Failed opening UDP socket - %s", fr_strerror());
301 error:
302 return -1;
303 }
304
305 li->app_io_addr = fr_socket_addr_alloc_inet_src(li, IPPROTO_UDP, 0, &inst->ipaddr, port);
306
307 /*
308 * Set SO_REUSEPORT before bind, so that all packets can
309 * listen on the same destination IP address.
310 */
311 if (1) {
312 int on = 1;
313
314 if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)) < 0) {
315 cf_log_err(li->cs, "Failed to set socket 'reuseport' - %s", fr_syserror(errno));
316 close(sockfd);
317 return -1;
318 }
319 }
320
321#ifdef SO_RCVBUF
322 if (inst->recv_buff_is_set) {
323 int opt;
324
325 opt = inst->recv_buff;
326 if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(int)) < 0) {
327 cf_log_warn(li->cs, "Failed setting 'recv_buf' - %s", fr_syserror(errno));
328 }
329 }
330#endif
331
332 /*
333 * SUID up is really only needed if interface is set, OR port <1024.
334 */
335 rad_suid_up();
336 rcode = fr_socket_bind(sockfd, inst->interface, &ipaddr, &port);
338 if (rcode < 0) {
339 cf_log_err(li->cs, "Failed binding to socket - %s", fr_strerror());
340 cf_log_err(li->cs, DOC_ROOT_REF(troubleshooting/network/bind));
341 close_error:
342 close(sockfd);
343 goto error;
344 }
345
346 /*
347 * If the user specified a multicast address, then join
348 * that group.
349 */
350 if (inst->multicast) {
351 struct ipv6_mreq mreq;
352
353 mreq.ipv6mr_multiaddr = inst->ipaddr.addr.v6;
354 mreq.ipv6mr_interface = if_nametoindex(inst->interface);
355 if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) < 0) {
356 PERROR("Failed joining multicast group %pV ", fr_box_ipaddr(inst->ipaddr));
357 goto close_error;
358 }
359
360 if (inst->hop_limit) {
361 int hop_limit = inst->hop_limit;
362
363 if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
364 (char *) &hop_limit, sizeof(hop_limit)) < 0) {
365 ERROR("Failed to set multicast hop_limit: %s", fr_syserror(errno));
366 goto close_error;
367 }
368 }
369 }
370
371 thread->sockfd = sockfd;
372
373 fr_assert((cf_parent(inst->cs) != NULL) && (cf_parent(cf_parent(inst->cs)) != NULL)); /* listen { ... } */
374
376 NULL, 0,
377 &inst->ipaddr, inst->port,
378 inst->interface);
379 return 0;
380}
381
382
383/** Set the file descriptor for this socket.
384 *
385 */
386static int mod_fd_set(fr_listen_t *li, int fd)
387{
389 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
390
391 thread->sockfd = fd;
392
394 &thread->connection->socket.inet.src_ipaddr, thread->connection->socket.inet.src_port,
395 &inst->ipaddr, inst->port,
396 inst->interface);
397
398 return 0;
399}
400
401static void *mod_track_create(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED fr_client_t *client,
402 fr_io_track_t *track, uint8_t const *packet, size_t packet_len)
403{
405 uint8_t const *option;
406 size_t t_size = sizeof(*t);
407 size_t option_len;
408
409 /*
410 * Relay packets can be nested to almost any depth.
411 */
412 while (packet[0] == FR_DHCPV6_RELAY_FORWARD) {
413 if (packet_len < (2 + 32)) return NULL;
414
415 /*
416 * fr_dhcpv6_option_find() ensures that the
417 * option header and data are contained within
418 * the given packet.
419 */
420 option = fr_dhcpv6_option_find(packet + 2 + 32, packet + packet_len, attr_relay_message->attr);
421 if (!option) return NULL;
422
423 option_len = fr_nbo_to_uint16(option + 2);
424
425 packet = option + 4; /* skip option header */
426 packet_len = option_len;
427 }
428
429 if (packet_len <= 4) return NULL;
430
431 /*
432 * Search the packet options.
433 */
434 option = fr_dhcpv6_option_find(packet + 4, packet + packet_len, attr_client_id->attr);
435 if (!option) return NULL;
436
437 option_len = fr_nbo_to_uint16(option + 2);
438
439 if (option_len > ((packet - option) + packet_len)) return NULL;
440
441 t = (proto_dhcpv6_track_t *) talloc_zero_array(track, uint8_t, t_size + option_len);
442 if (!t) return NULL;
443
444 talloc_set_name_const(t, "proto_dhcpv6_track_t");
445
446 memcpy(&t->header, packet, 4); /* packet code + 24-bit transaction ID */
447
448 memcpy(&t->client_id[0], option + 4, option_len);
449 t->client_id_len = option_len;
450
451 return t;
452}
453
454
455static int mod_track_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED fr_client_t *client,
456 void const *one, void const *two)
457{
458 int ret;
459 proto_dhcpv6_track_t const *a = one;
460 proto_dhcpv6_track_t const *b = two;
461
462 ret = memcmp(&a->header, &b->header, sizeof(a->header));
463 if (ret != 0) return ret;
464
465 ret = (a->client_id_len < b->client_id_len) - (a->client_id_len > b->client_id_len);
466 if (ret != 0) return ret;
467
468 return memcmp(a->client_id, b->client_id, a->client_id_len);
469}
470
471
472static char const *mod_name(fr_listen_t *li)
473{
474 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
475
476 return thread->name;
477}
478
479
480static int mod_instantiate(module_inst_ctx_t const *mctx)
481{
482 proto_dhcpv6_udp_t *inst = talloc_get_type_abort(mctx->mi->data, proto_dhcpv6_udp_t);
483 size_t num;
484 CONF_ITEM *ci;
485 CONF_SECTION *server_cs;
486 fr_client_t *client;
487 CONF_SECTION *conf = mctx->mi->conf;
488
489 inst->cs = conf;
490
491 /*
492 * Complain if no "ipaddr" is set.
493 */
494 if (inst->ipaddr.af == AF_UNSPEC) {
495 if (!inst->interface) {
496 cf_log_err(conf, "No 'ipaddr' was specified in the 'udp' section");
497 return -1;
498 }
499
500 /*
501 * If there's a named interface, maybe we can
502 * find a link-local address for it. If so, just
503 * use that.
504 */
505 if (inst->interface &&
506 (fr_interface_to_ipaddr(inst->interface, &inst->ipaddr, AF_INET6, true) < 0)) {
507 cf_log_err(conf, "No 'ipaddr' specified, and we cannot determine one for interface '%s'",
508 inst->interface);
509 return -1;
510 }
511 }
512
513 if (inst->ipaddr.af != AF_INET6) {
514 cf_log_err(conf, "DHCPv6 cannot use IPv4 for 'ipaddr'");
515 return -1;
516 }
517
518 /*
519 * Remember if we're a multicast socket.
520 */
521 inst->multicast = (fr_ipaddr_is_multicast(&inst->ipaddr) == 1);
522
523 /*
524 * Set src_ipaddr to ipaddr if not otherwise specified
525 */
526 if (inst->src_ipaddr.af == AF_UNSPEC) {
527 if (!inst->multicast) {
528 inst->src_ipaddr = inst->ipaddr;
529
530 /*
531 * If the admin didn't specify an
532 * interface, then try to find one
533 * automatically. We only do this for
534 * link-local addresses.
535 */
536 if (!inst->interface) {
537 inst->interface = fr_ipaddr_to_interface(inst, &inst->ipaddr);
538 if (!inst->interface) {
539 interface_fail:
540 cf_log_err(conf, "No 'interface' specified, and we cannot "
541 "determine one for 'ipaddr = %pV'",
542 fr_box_ipaddr(inst->ipaddr));
543 return -1;
544 }
545 }
546
547 } else {
548 /*
549 * Multicast addresses MUST specify an interface.
550 */
551 if (!inst->interface) goto interface_fail;
552
553 if (fr_interface_to_ipaddr(inst->interface, &inst->src_ipaddr, AF_INET6, true) < 0) {
554 cf_log_err(conf, "No 'src_ipaddr' specified, and we cannot determine "
555 "one for 'ipaddr = %pV' and interface '%s'",
556 fr_box_ipaddr(inst->ipaddr), inst->interface);
557 return -1;
558 }
559 }
560 }
561
562 /*
563 * src_ipaddr must be of the same address family as "ipaddr"
564 */
565 if (inst->src_ipaddr.af != inst->ipaddr.af) {
566 cf_log_err(conf, "Both 'ipaddr' and 'src_ipaddr' must be from the same address family");
567 return -1;
568 }
569
570 /*
571 * Get the MAC address associated with this interface.
572 * It can be used to create a server ID.
573 */
574 if (inst->interface) fr_interface_to_ethernet(inst->interface, &inst->ethernet);
575
576 if (inst->recv_buff_is_set) {
577 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, >=, 32);
578 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, <=, INT_MAX);
579 }
580
581 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, >=, 4);
582 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, <=, 65536);
583
584 if (!inst->port) {
585 struct servent *s;
586
587 if (!inst->port_name) {
588 cf_log_err(conf, "No 'port' was specified in the 'udp' section");
589 return -1;
590 }
591
592 s = getservbyname(inst->port_name, "udp");
593 if (!s) {
594 cf_log_err(conf, "Unknown value for 'port_name = %s", inst->port_name);
595 return -1;
596 }
597
598 inst->port = ntohs(s->s_port);
599 }
600
601 /*
602 * Parse and create the trie for dynamic clients, even if
603 * there's no dynamic clients.
604 */
605 num = talloc_array_length(inst->allow);
606 if (!num) {
607 if (inst->dynamic_clients) {
608 cf_log_err(conf, "The 'allow' subsection MUST contain at least one 'network' entry when "
609 "'dynamic_clients = true'.");
610 return -1;
611 }
612 } else {
613 inst->trie = fr_master_io_network(inst, inst->ipaddr.af, inst->allow, inst->deny);
614 if (!inst->trie) {
615 cf_log_perr(conf, "Failed creating list of networks");
616 return -1;
617 }
618 }
619
620 ci = cf_section_to_item(mctx->mi->parent->conf); /* listen { ... } */
621 fr_assert(ci != NULL);
622 ci = cf_parent(ci);
623 fr_assert(ci != NULL);
624
625 server_cs = cf_item_to_section(ci);
626
627 /*
628 * Look up local clients, if they exist.
629 *
630 * @todo - ensure that we only parse clients which are
631 * for IPPROTO_UDP, and don't require a "secret".
632 */
633 if (cf_section_find_next(server_cs, NULL, "client", CF_IDENT_ANY)) {
634 inst->clients = client_list_parse_section(server_cs, IPPROTO_UDP, false);
635 if (!inst->clients) {
636 cf_log_err(conf, "Failed creating local clients");
637 return -1;
638 }
639 }
640
641 /*
642 * Create a fake client.
643 */
644 client = inst->default_client = talloc_zero(inst, fr_client_t);
645 if (!inst->default_client) return 0;
646
647 client->ipaddr = (fr_ipaddr_t ) {
648 .af = AF_INET6,
649 };
650
651 client->src_ipaddr = client->ipaddr;
652
653 client->longname = client->shortname = client->secret = talloc_strdup(client, "default");
654 client->nas_type = talloc_strdup(client, "other");
655
656 return 0;
657}
658
660{
662
663 /*
664 * Prefer local clients.
665 */
666 if (inst->clients) {
667 fr_client_t *client;
668
669 client = client_find(inst->clients, ipaddr, ipproto);
670 if (client) return client;
671 }
672
673 return inst->default_client;
674}
675
677 .common = {
678 .magic = MODULE_MAGIC_INIT,
679 .name = "dhcpv6_udp",
681 .inst_size = sizeof(proto_dhcpv6_udp_t),
682 .thread_inst_size = sizeof(proto_dhcpv6_udp_thread_t),
683 .instantiate = mod_instantiate
684 },
685 .default_message_size = 4096,
686 .track_duplicates = true,
687
688 .open = mod_open,
689 .read = mod_read,
690 .write = mod_write,
691 .fd_set = mod_fd_set,
692 .track_create = mod_track_create,
693 .track_compare = mod_track_compare,
694 .connection_set = mod_connection_set,
695 .network_get = mod_network_get,
696 .client_find = mod_client_find,
697 .get_name = mod_name,
698};
static int const char char buffer[256]
Definition acutest.h:578
char const * fr_app_io_socket_name(TALLOC_CTX *ctx, fr_app_io_t const *app_io, fr_ipaddr_t const *src_ipaddr, int src_port, fr_ipaddr_t const *dst_ipaddr, int dst_port, char const *interface)
Definition app_io.c:32
module_t common
Common fields to all loadable modules.
Definition app_io.h:34
Public structure describing an I/O path for a protocol.
Definition app_io.h:33
#define STRINGIFY(x)
Definition build.h:197
#define UNUSED
Definition build.h:317
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:660
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
Definition cf_parse.h:520
#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:283
#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:337
#define FR_CONF_OFFSET_IS_SET(_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:297
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition cf_parse.h:449
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:426
#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:241
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:597
Common header for all CONF_* types.
Definition cf_priv.h:49
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
Definition cf_util.c:737
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:683
CONF_SECTION * cf_section_find_next(CONF_SECTION const *cs, CONF_SECTION const *prev, char const *name1, char const *name2)
Return the next matching section.
Definition cf_util.c:1048
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:288
#define cf_parent(_cf)
Definition cf_util.h:101
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:295
#define cf_log_warn(_cf, _fmt,...)
Definition cf_util.h:289
#define CF_IDENT_ANY
Definition cf_util.h:78
#define ERROR(fmt,...)
Definition dhcpclient.c:41
static int sockfd
Definition dhcpclient.c:56
@ FR_DHCPV6_REBIND
Definition dhcpv6.h:73
@ FR_DHCPV6_CONFIRM
Definition dhcpv6.h:71
@ FR_DHCPV6_SOLICIT
Definition dhcpv6.h:68
@ FR_DHCPV6_CODE_MAX
Definition dhcpv6.h:103
@ FR_DHCPV6_RELAY_FORWARD
Definition dhcpv6.h:79
#define DHCPV6_MAX_ATTRIBUTES
Definition dhcpv6.h:52
uint8_t transaction_id[3]
Definition dhcpv6.h:116
subtype values for DHCPv4 and DHCPv6
Definition dhcpv6.h:114
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:294
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:307
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:313
Specifies an attribute which must be present for the module to function.
Definition dict.h:293
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:306
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
int fr_interface_to_ipaddr(char const *interface, fr_ipaddr_t *ipaddr, int af, bool link_local)
Definition inet.c:1581
int fr_ipaddr_is_multicast(fr_ipaddr_t const *ipaddr)
Determine if an address is a multicast address.
Definition inet.c:95
int fr_ipaddr_is_inaddr_any(fr_ipaddr_t const *ipaddr)
Determine if an address is the INADDR_ANY address for its address family.
Definition inet.c:63
char * fr_ipaddr_to_interface(TALLOC_CTX *ctx, fr_ipaddr_t *ipaddr)
Definition inet.c:1538
int fr_interface_to_ethernet(char const *interface, fr_ethernet_t *ethernet)
Definition inet.c:1626
int af
Address family.
Definition inet.h:64
Struct to represent an ethernet address.
Definition inet.h:45
IPv4/6 prefix.
fr_socket_t socket
src/dst ip and port.
Definition base.h:336
CONF_SECTION * cs
of this listener
Definition listen.h:41
fr_socket_t * app_io_addr
for tracking duplicate sockets
Definition listen.h:36
void const * app_io_instance
I/O path configuration context.
Definition listen.h:33
void * thread_instance
thread / socket context
Definition listen.h:34
int fd
file descriptor for this socket - set by open
Definition listen.h:28
fr_ipaddr_t ipaddr
IPv4/IPv6 address of the host.
Definition client.h:83
char const * secret
Secret PSK.
Definition client.h:90
fr_ipaddr_t src_ipaddr
IPv4/IPv6 address to send responses from (family must match ipaddr).
Definition client.h:84
char const * nas_type
Type of client (arbitrary).
Definition client.h:131
char const * longname
Client identifier.
Definition client.h:87
char const * shortname
Client nickname.
Definition client.h:88
Describes a host allowed to send packets to the server.
Definition client.h:80
#define PERROR(_fmt,...)
Definition log.h:228
#define PWARN(_fmt,...)
Definition log.h:227
#define RATE_LIMIT_GLOBAL(_log, _fmt,...)
Rate limit messages using a global limiting entry.
Definition log.h:653
uint64_t total_responses
Definition stats.h:38
void rad_suid_up(void)
Definition util.c:767
void rad_suid_down(void)
Definition util.c:771
ssize_t udp_recv(int sockfd, int flags, fr_socket_t *socket_out, void *data, size_t data_len, fr_time_t *when)
Read a UDP packet.
Definition udp.c:144
int udp_send(fr_socket_t const *sock, int flags, void *data, size_t data_len)
Send a packet via a UDP socket.
Definition udp.c:42
fr_trie_t * fr_master_io_network(TALLOC_CTX *ctx, int af, fr_ipaddr_t *allow, fr_ipaddr_t *deny)
Create a trie from arrays of allow / deny IP addresses.
Definition master.c:2975
fr_io_address_t const * address
of this packet.. shared between multiple packets
Definition master.h:55
unsigned short uint16_t
@ FR_TYPE_COMBO_IP_PREFIX
IPv4 or IPv6 address prefix depending on length.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
@ FR_TYPE_GROUP
A grouping of other attributes.
unsigned int uint32_t
long int ssize_t
unsigned char uint8_t
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
static uint16_t fr_nbo_to_uint16(uint8_t const data[static sizeof(uint16_t)])
Read an unsigned 16bit integer from wire format (big endian)
Definition nbo.h:146
static uint32_t fr_nbo_to_uint24(uint8_t const data[static 3])
Read an unsigned 24bit integer from wire format (big endian)
Definition nbo.h:157
bool dynamic_clients
whether we have dynamic clients
fr_ipaddr_t ipaddr
IP address to listen on.
static fr_dict_attr_t const * attr_packet_type
static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len, size_t *leftover)
uint32_t max_attributes
Limit maximum decodable attributes.
fr_ipaddr_t * allow
allowed networks for dynamic clients
fr_dict_attr_autoload_t proto_dhcpv6_udp_dict_attr[]
fr_ethernet_t ethernet
ethernet address associated with the interface
uint32_t max_packet_size
for message ring buffer.
char const * interface
Interface to bind to.
char const * port_name
Name of the port for getservent().
fr_io_address_t * connection
for connected sockets.
fr_client_t * default_client
default 0/0 client
static fr_client_t * mod_client_find(fr_listen_t *li, fr_ipaddr_t const *ipaddr, int ipproto)
static int mod_open(fr_listen_t *li)
Open a UDP listener for DHCPv6.
static const conf_parser_t udp_listen_config[]
static fr_dict_attr_t const * attr_relay_message
uint32_t hop_limit
for multicast addresses
static void mod_network_get(int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, void *instance)
static void * mod_track_create(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED fr_client_t *client, fr_io_track_t *track, uint8_t const *packet, size_t packet_len)
static const conf_parser_t networks_config[]
bool multicast
whether or not we listen for multicast packets
fr_stats_t stats
statistics for this socket
static fr_dict_t const * dict_dhcpv6
fr_client_list_t * clients
local clients
uint32_t recv_buff
How big the kernel's receive buffer should be.
static int mod_track_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED fr_client_t *client, void const *one, void const *two)
CONF_SECTION * cs
our configuration
static int mod_connection_set(fr_listen_t *li, fr_io_address_t *connection)
uint16_t port
Port to listen on.
bool recv_buff_is_set
Whether we were provided with a receive buffer value.
fr_trie_t * trie
for parsed networks
static fr_dict_attr_t const * attr_client_id
static int mod_fd_set(fr_listen_t *li, int fd)
Set the file descriptor for this socket.
static char const * mod_name(fr_listen_t *li)
static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, UNUSED fr_time_t request_time, uint8_t *buffer, size_t buffer_len, UNUSED size_t written)
static int mod_instantiate(module_inst_ctx_t const *mctx)
fr_ipaddr_t src_ipaddr
IP address to source replies.
fr_ipaddr_t * deny
denied networks for dynamic clients
fr_app_io_t proto_dhcpv6_udp
char const * name
socket name
fr_dict_autoload_t proto_dhcpv6_udp_dict[]
bool fr_dhcpv6_ok(uint8_t const *packet, size_t packet_len, uint32_t max_attributes)
See if the data pointed to by PTR is a valid DHCPv6 packet.
Definition base.c:231
uint8_t const * fr_dhcpv6_option_find(uint8_t const *start, uint8_t const *end, unsigned int option)
Definition base.c:247
char const * fr_dhcpv6_packet_names[FR_DHCPV6_CODE_MAX]
Definition base.c:72
#define fr_assert(_expr)
Definition rad_assert.h:38
static int ipproto
#define DEBUG2(fmt,...)
#define WARN(fmt,...)
static rs_t * conf
Definition radsniff.c:53
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:349
void * data
Module's instance data.
Definition module.h:291
module_instance_t const * parent
Parent module's instance (if any).
Definition module.h:357
conf_parser_t const * config
How to convert a CONF_SECTION to a module instance.
Definition module.h:206
int fr_socket_server_udp(fr_ipaddr_t const *src_ipaddr, uint16_t *src_port, char const *port_name, bool async)
Open an IPv4/IPv6 unconnected UDP socket.
Definition socket.c:846
int fr_socket_bind(int sockfd, char const *ifname, fr_ipaddr_t *src_ipaddr, uint16_t *src_port)
Bind a UDP/TCP v4/v6 socket to a given ipaddr src port, and interface.
Definition socket.c:200
fr_client_t * client_find(fr_client_list_t const *clients, fr_ipaddr_t const *ipaddr, int proto)
Definition client.c:373
fr_client_list_t * client_list_parse_section(CONF_SECTION *section, int proto, TLS_UNUSED bool tls_required)
Definition client.c:478
Group of clients.
Definition client.c:50
eap_aka_sim_process_conf_t * inst
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
#define talloc_get_type_abort_const
Definition talloc.h:113
#define talloc_strdup(_ctx, _str)
Definition talloc.h:145
"server local" time.
Definition time.h:69
#define UDP_FLAGS_CONNECTED
Definition udp.h:38
static fr_socket_t * fr_socket_addr_alloc_inet_src(TALLOC_CTX *ctx, int proto, int ifindex, fr_ipaddr_t const *ipaddr, int port)
A variant of fr_socket_addr_init_inet_src will also allocates a fr_socket_t.
Definition socket.h:244
static void fr_socket_addr_swap(fr_socket_t *dst, fr_socket_t const *src)
Swap src/dst information of a fr_socket_t.
Definition socket.h:121
Holds information necessary for binding or connecting to a socket.
Definition socket.h:63
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:553
#define DOC_ROOT_REF(_x)
Definition version.h:90
#define fr_box_ipaddr(_val)
Definition value.h:317