The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
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: 330a3cc501f68048b216c861c3a8830dc66a57d6 $
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 proto_dhcpv6_t const *parent; //!< parent instance
49
50 fr_ipaddr_t ipaddr; //!< IP address to listen on.
51
52 fr_ipaddr_t src_ipaddr; //!< IP address to source replies
53
54 char const *interface; //!< Interface to bind to.
55 char const *port_name; //!< Name of the port for getservent().
56 fr_ethernet_t ethernet; //!< ethernet address associated with the interface
57
58 uint32_t recv_buff; //!< How big the kernel's receive buffer should be.
59
60 uint32_t hop_limit; //!< for multicast addresses
61 uint32_t max_packet_size; //!< for message ring buffer.
62 uint32_t max_attributes; //!< Limit maximum decodable attributes.
63
64 uint16_t port; //!< Port to listen on.
65
66 bool multicast; //!< whether or not we listen for multicast packets
67
68 bool recv_buff_is_set; //!< Whether we were provided with a receive
69 //!< buffer value.
70 bool dynamic_clients; //!< whether we have dynamic clients
71
72 fr_client_list_t *clients; //!< local clients
73 fr_client_t *default_client; //!< default 0/0 client
74
75 fr_trie_t *trie; //!< for parsed networks
76 fr_ipaddr_t *allow; //!< allowed networks for dynamic clients
77 fr_ipaddr_t *deny; //!< denied networks for dynamic clients
79
80
87
88
92
94
95 { FR_CONF_OFFSET("interface", proto_dhcpv6_udp_t, interface) },
96 { FR_CONF_OFFSET("port_name", proto_dhcpv6_udp_t, port_name) },
97
98 { FR_CONF_OFFSET("port", proto_dhcpv6_udp_t, port), .dflt = "547" },
99 { FR_CONF_OFFSET_IS_SET("recv_buff", FR_TYPE_UINT32, 0, proto_dhcpv6_udp_t, recv_buff) },
100
101 { FR_CONF_OFFSET("hop_limit", proto_dhcpv6_udp_t, hop_limit) },
102
103 { FR_CONF_OFFSET("dynamic_clients", proto_dhcpv6_udp_t, dynamic_clients) } ,
104 { FR_CONF_POINTER("networks", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) networks_config },
105
106 { FR_CONF_OFFSET("max_packet_size", proto_dhcpv6_udp_t, max_packet_size), .dflt = "8192" } ,
107 { FR_CONF_OFFSET("max_attributes", proto_dhcpv6_udp_t, max_attributes), .dflt = STRINGIFY(DHCPV6_MAX_ATTRIBUTES) } ,
108
110};
111
112static fr_dict_t const *dict_dhcpv6;
113
119
123
126 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_dhcpv6},
127 { .out = &attr_client_id, .name = "Client-ID", .type = FR_TYPE_STRUCT, .dict = &dict_dhcpv6},
128 { .out = &attr_relay_message, .name = "Relay-Message", .type = FR_TYPE_GROUP, .dict = &dict_dhcpv6 },
130};
131
132static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len,
133 size_t *leftover)
134{
136 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
137 fr_io_address_t *address, **address_p;
138
139 int flags;
140 ssize_t data_size;
141 size_t packet_len;
142 uint32_t xid;
143 fr_dhcpv6_packet_t *packet;
144
145 *leftover = 0; /* always for UDP */
146
147 /*
148 * Where the addresses should go. This is a special case
149 * for proto_dhcpv6.
150 */
151 address_p = (fr_io_address_t **)packet_ctx;
152 address = *address_p;
153
154 /*
155 * Tell udp_recv if we're connected or not.
156 */
157 flags = UDP_FLAGS_CONNECTED * (thread->connection != NULL);
158
159 data_size = udp_recv(thread->sockfd, flags, &address->socket, buffer, buffer_len, recv_time_p);
160 if (data_size < 0) {
161 RATE_LIMIT_GLOBAL(PERROR, "Read error (%zd)", data_size);
162 return data_size;
163 }
164
165 if ((size_t) data_size < sizeof(fr_dhcpv6_packet_t)) {
166 RATE_LIMIT_GLOBAL(WARN, "Insufficient data - ignoring");
167 return 0;
168 }
169
170 packet_len = data_size;
171
172 /*
173 * We've seen a server reply to this port, but the giaddr
174 * is *not* our address. Drop it.
175 */
176 packet = (fr_dhcpv6_packet_t *) buffer;
177 if (!packet->code || (packet->code >= FR_DHCPV6_CODE_MAX)) {
178 RATE_LIMIT_GLOBAL(WARN, "Unsupported packet code %d - ignoring", packet->code);
179 return 0;
180 }
181
182 /*
183 * RFC 8415 Section 18.4 forbids certain types of packets
184 * from being received on a unicast address.
185 */
186 if (!inst->multicast) {
187 if ((packet->code == FR_DHCPV6_SOLICIT) ||
188 (packet->code == FR_DHCPV6_REBIND) ||
189 (packet->code == FR_DHCPV6_CONFIRM)) {
190 RATE_LIMIT_GLOBAL(WARN, "Unicast packet %s - ignoring", fr_dhcpv6_packet_names[packet->code]);
191 return 0;
192 }
193 } /* else it was multicast... remember that */
194
195 /*
196 * @todo - make this take "&packet_len", as the DHCPv4
197 * packet may be smaller than the parent UDP packet.
198 */
199 if (fr_dhcpv6_ok(buffer, data_size, inst->max_attributes) <= 0) {
200 RATE_LIMIT_GLOBAL(PWARN, "Invalid packet - ignoring message which is not DHCPv6");
201 return 0;
202 }
203
204 /*
205 * If there is a Server-ID option configured, then it has to match.
206 */
207 if (inst->parent->server_id &&
209 .duid = inst->parent->server_id,
210 .duid_len = talloc_array_length(inst->parent->server_id),
211 }, false)) {
212 RATE_LIMIT_GLOBAL(PWARN, "Invalid packet - ignoring message which is malformed (%s)", fr_strerror());
213 return 0;
214 }
215
216 /*
217 * proto_dhcpv6 sets the priority
218 */
219
220 xid = fr_nbo_to_uint24(packet->transaction_id);
221
222 /*
223 * Print out what we received.
224 */
225 DEBUG2("Received %s XID %08x length %d %s", fr_dhcpv6_packet_names[packet->code], xid,
226 (int) packet_len, thread->name);
227
228 return packet_len;
229}
230
231static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, UNUSED fr_time_t request_time,
232 uint8_t *buffer, size_t buffer_len, UNUSED size_t written)
233{
235 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
236
237 fr_io_track_t *track = talloc_get_type_abort(packet_ctx, fr_io_track_t);
238 fr_socket_t socket;
239
240 int flags;
241 ssize_t data_size;
242
243 /*
244 * @todo - share a stats interface with the parent? or
245 * put the stats in the listener, so that proto_dhcpv6
246 * can update them, too.. <sigh>
247 */
248 thread->stats.total_responses++;
249
250 flags = UDP_FLAGS_CONNECTED * (thread->connection != NULL);
251
252 /*
253 * Send packets to the originator, EXCEPT that we always
254 * originate packets from our src_ipaddr.
255 */
256 fr_socket_addr_swap(&socket, &track->address->socket);
257 if (!fr_ipaddr_is_inaddr_any(&inst->src_ipaddr)) socket.inet.src_ipaddr = inst->src_ipaddr;
258
259 /*
260 * Figure out which kind of packet we're sending.
261 */
262 if (!thread->connection) {
263 // @todo - figure out where to send the packet
264 }
265
266 /*
267 * proto_dhcpv6 takes care of suppressing do-not-respond, etc.
268 */
269 data_size = udp_send(&socket, flags, buffer, buffer_len);
270
271 /*
272 * This socket is dead. That's an error...
273 */
274 if (data_size <= 0) return data_size;
275
276 return data_size;
277}
278
279
281{
282 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
283
284 thread->connection = connection;
285 return 0;
286}
287
288
289static void mod_network_get(int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, void *instance)
290{
291 proto_dhcpv6_udp_t *inst = talloc_get_type_abort(instance, proto_dhcpv6_udp_t);
292
293 *ipproto = IPPROTO_UDP;
294 *dynamic_clients = inst->dynamic_clients;
295 *trie = inst->trie;
296}
297
298
299/** Open a UDP listener for DHCPv6
300 *
301 */
302static int mod_open(fr_listen_t *li)
303{
305 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
306
307 int sockfd, rcode;
308 fr_ipaddr_t ipaddr = inst->ipaddr;
309 uint16_t port = inst->port;
310
311 li->fd = sockfd = fr_socket_server_udp(&inst->ipaddr, &port, inst->port_name, true);
312 if (sockfd < 0) {
313 cf_log_err(li->cs, "Failed opening UDP socket - %s", fr_strerror());
314 error:
315 return -1;
316 }
317
318 li->app_io_addr = fr_socket_addr_alloc_inet_src(li, IPPROTO_UDP, 0, &inst->ipaddr, port);
319
320 /*
321 * Set SO_REUSEPORT before bind, so that all packets can
322 * listen on the same destination IP address.
323 */
324 if (1) {
325 int on = 1;
326
327 if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)) < 0) {
328 cf_log_err(li->cs, "Failed to set socket 'reuseport' - %s", fr_syserror(errno));
329 close(sockfd);
330 return -1;
331 }
332 }
333
334#ifdef SO_RCVBUF
335 if (inst->recv_buff_is_set) {
336 int opt;
337
338 opt = inst->recv_buff;
339 if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(int)) < 0) {
340 cf_log_warn(li->cs, "Failed setting 'recv_buf' - %s", fr_syserror(errno));
341 }
342 }
343#endif
344
345 /*
346 * SUID up is really only needed if interface is set, OR port <1024.
347 */
348 rad_suid_up();
349 rcode = fr_socket_bind(sockfd, inst->interface, &ipaddr, &port);
351 if (rcode < 0) {
352 cf_log_err(li->cs, "Failed binding to socket - %s", fr_strerror());
353 cf_log_err(li->cs, DOC_ROOT_REF(troubleshooting/network/bind));
354 close_error:
355 close(sockfd);
356 goto error;
357 }
358
359 /*
360 * If the user specified a multicast address, then join
361 * that group.
362 */
363 if (inst->multicast) {
364 struct ipv6_mreq mreq;
365
366 mreq.ipv6mr_multiaddr = inst->ipaddr.addr.v6;
367 mreq.ipv6mr_interface = if_nametoindex(inst->interface);
368 if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) < 0) {
369 PERROR("Failed joining multicast group %pV ", fr_box_ipaddr(inst->ipaddr));
370 goto close_error;
371 }
372
373 if (inst->hop_limit) {
374 int hop_limit = inst->hop_limit;
375
376 if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
377 (char *) &hop_limit, sizeof(hop_limit)) < 0) {
378 ERROR("Failed to set multicast hop_limit: %s", fr_syserror(errno));
379 goto close_error;
380 }
381 }
382 }
383
384 thread->sockfd = sockfd;
385
386 fr_assert((cf_parent(inst->cs) != NULL) && (cf_parent(cf_parent(inst->cs)) != NULL)); /* listen { ... } */
387
389 NULL, 0,
390 &inst->ipaddr, inst->port,
391 inst->interface);
392 return 0;
393}
394
395
396/** Set the file descriptor for this socket.
397 *
398 */
399static int mod_fd_set(fr_listen_t *li, int fd)
400{
402 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
403
404 thread->sockfd = fd;
405
407 &thread->connection->socket.inet.src_ipaddr, thread->connection->socket.inet.src_port,
408 &inst->ipaddr, inst->port,
409 inst->interface);
410
411 return 0;
412}
413
414static void *mod_track_create(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED fr_client_t *client,
415 fr_io_track_t *track, uint8_t const *packet, size_t packet_len)
416{
418 uint8_t const *option;
419 size_t t_size = sizeof(*t);
420 size_t option_len;
421
422 /*
423 * Relay packets can be nested to almost any depth.
424 */
425 while (packet[0] == FR_DHCPV6_RELAY_FORWARD) {
426 if (packet_len < (2 + 32)) return NULL;
427
428 /*
429 * fr_dhcpv6_option_find() ensures that the
430 * option header and data are contained within
431 * the given packet.
432 */
433 option = fr_dhcpv6_option_find(packet + 2 + 32, packet + packet_len, attr_relay_message->attr);
434 if (!option) return NULL;
435
436 option_len = fr_nbo_to_uint16(option + 2);
437
438 packet = option + 4; /* skip option header */
439 packet_len = option_len;
440 }
441
442 if (packet_len <= 4) return NULL;
443
444 /*
445 * Search the packet options.
446 */
447 option = fr_dhcpv6_option_find(packet + 4, packet + packet_len, attr_client_id->attr);
448 if (!option) return NULL;
449
450 option_len = fr_nbo_to_uint16(option + 2);
451
452 if (option_len > ((packet - option) + packet_len)) return NULL;
453
454 t = (proto_dhcpv6_track_t *) talloc_zero_array(track, uint8_t, t_size + option_len);
455 if (!t) return NULL;
456
457 talloc_set_name_const(t, "proto_dhcpv6_track_t");
458
459 memcpy(&t->header, packet, 4); /* packet code + 24-bit transaction ID */
460
461 memcpy(&t->client_id[0], option + 4, option_len);
462 t->client_id_len = option_len;
463
464 return t;
465}
466
467
468static int mod_track_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED fr_client_t *client,
469 void const *one, void const *two)
470{
471 int ret;
472 proto_dhcpv6_track_t const *a = one;
473 proto_dhcpv6_track_t const *b = two;
474
475 ret = memcmp(&a->header, &b->header, sizeof(a->header));
476 if (ret != 0) return ret;
477
478 ret = (a->client_id_len < b->client_id_len) - (a->client_id_len > b->client_id_len);
479 if (ret != 0) return ret;
480
481 return memcmp(a->client_id, b->client_id, a->client_id_len);
482}
483
484
485static char const *mod_name(fr_listen_t *li)
486{
487 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
488
489 return thread->name;
490}
491
492
493static int mod_instantiate(module_inst_ctx_t const *mctx)
494{
495 proto_dhcpv6_udp_t *inst = talloc_get_type_abort(mctx->mi->data, proto_dhcpv6_udp_t);
496 size_t num;
497 CONF_ITEM *ci;
498 CONF_SECTION *server_cs;
499 fr_client_t *client;
500 CONF_SECTION *conf = mctx->mi->conf;
501
502 inst->cs = conf;
503
504 /*
505 * Complain if no "ipaddr" is set.
506 */
507 if (inst->ipaddr.af == AF_UNSPEC) {
508 if (!inst->interface) {
509 cf_log_err(conf, "No 'ipaddr' was specified in the 'udp' section");
510 return -1;
511 }
512
513 /*
514 * If there's a named interface, maybe we can
515 * find a link-local address for it. If so, just
516 * use that.
517 */
518 if (inst->interface &&
519 (fr_interface_to_ipaddr(inst->interface, &inst->ipaddr, AF_INET6, true) < 0)) {
520 cf_log_err(conf, "No 'ipaddr' specified, and we cannot determine one for interface '%s'",
521 inst->interface);
522 return -1;
523 }
524 }
525
526 if (inst->ipaddr.af != AF_INET6) {
527 cf_log_err(conf, "DHCPv6 cannot use IPv4 for 'ipaddr'");
528 return -1;
529 }
530
531 /*
532 * Remember if we're a multicast socket.
533 */
534 inst->multicast = (fr_ipaddr_is_multicast(&inst->ipaddr) == 1);
535
536 /*
537 * Set src_ipaddr to ipaddr if not otherwise specified
538 */
539 if (inst->src_ipaddr.af == AF_UNSPEC) {
540 if (!inst->multicast) {
541 inst->src_ipaddr = inst->ipaddr;
542
543 /*
544 * If the admin didn't specify an
545 * interface, then try to find one
546 * automatically. We only do this for
547 * link-local addresses.
548 */
549 if (!inst->interface) {
550 inst->interface = fr_ipaddr_to_interface(inst, &inst->ipaddr);
551 if (!inst->interface) {
552 interface_fail:
553 cf_log_err(conf, "No 'interface' specified, and we cannot "
554 "determine one for 'ipaddr = %pV'",
555 fr_box_ipaddr(inst->ipaddr));
556 return -1;
557 }
558 }
559
560 } else {
561 /*
562 * Multicast addresses MUST specify an interface.
563 */
564 if (!inst->interface) goto interface_fail;
565
566 if (fr_interface_to_ipaddr(inst->interface, &inst->src_ipaddr, AF_INET6, true) < 0) {
567 cf_log_err(conf, "No 'src_ipaddr' specified, and we cannot determine "
568 "one for 'ipaddr = %pV' and interface '%s'",
569 fr_box_ipaddr(inst->ipaddr), inst->interface);
570 return -1;
571 }
572 }
573 }
574
575 /*
576 * src_ipaddr must be of the same address family as "ipaddr"
577 */
578 if (inst->src_ipaddr.af != inst->ipaddr.af) {
579 cf_log_err(conf, "Both 'ipaddr' and 'src_ipaddr' must be from the same address family");
580 return -1;
581 }
582
583 /*
584 * Get the MAC address associated with this interface.
585 * It can be used to create a server ID.
586 */
587 if (inst->interface) fr_interface_to_ethernet(inst->interface, &inst->ethernet);
588
589 if (inst->recv_buff_is_set) {
590 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, >=, 32);
591 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, <=, INT_MAX);
592 }
593
594 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, >=, 4);
595 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, <=, 65536);
596
597 if (!inst->port) {
598 struct servent *s;
599
600 if (!inst->port_name) {
601 cf_log_err(conf, "No 'port' was specified in the 'udp' section");
602 return -1;
603 }
604
605 s = getservbyname(inst->port_name, "udp");
606 if (!s) {
607 cf_log_err(conf, "Unknown value for 'port_name = %s", inst->port_name);
608 return -1;
609 }
610
611 inst->port = ntohs(s->s_port);
612 }
613
614 /*
615 * Parse and create the trie for dynamic clients, even if
616 * there's no dynamic clients.
617 */
618 num = talloc_array_length(inst->allow);
619 if (!num) {
620 if (inst->dynamic_clients) {
621 cf_log_err(conf, "The 'allow' subsection MUST contain at least one 'network' entry when "
622 "'dynamic_clients = true'.");
623 return -1;
624 }
625 } else {
626 inst->trie = fr_master_io_network(inst, inst->ipaddr.af, inst->allow, inst->deny);
627 if (!inst->trie) {
628 cf_log_perr(conf, "Failed creating list of networks");
629 return -1;
630 }
631 }
632
633 ci = cf_section_to_item(mctx->mi->parent->conf); /* listen { ... } */
634 fr_assert(ci != NULL);
635 ci = cf_parent(ci);
636 fr_assert(ci != NULL);
637
638 server_cs = cf_item_to_section(ci);
639
640 /*
641 * Look up local clients, if they exist.
642 *
643 * @todo - ensure that we only parse clients which are
644 * for IPPROTO_UDP, and don't require a "secret".
645 */
646 if (cf_section_find_next(server_cs, NULL, "client", CF_IDENT_ANY)) {
647 inst->clients = client_list_parse_section(server_cs, IPPROTO_UDP, false);
648 if (!inst->clients) {
649 cf_log_err(conf, "Failed creating local clients");
650 return -1;
651 }
652 }
653
654 /*
655 * Create a fake client.
656 */
657 client = inst->default_client = talloc_zero(inst, fr_client_t);
658 if (!inst->default_client) return -1;
659
660 client->ipaddr = (fr_ipaddr_t ) {
661 .af = AF_INET6,
662 };
663
664 client->src_ipaddr = client->ipaddr;
665
666 client->longname = client->shortname = client->secret = talloc_strdup(client, "default");
667 client->nas_type = talloc_strdup(client, "other");
668
670
671 return 0;
672}
673
675{
677
678 /*
679 * Prefer local clients.
680 */
681 if (inst->clients) {
682 return client_find(inst->clients, ipaddr, ipproto);
683 }
684
685 return inst->default_client;
686}
687
689 .common = {
690 .magic = MODULE_MAGIC_INIT,
691 .name = "dhcpv6_udp",
693 .inst_size = sizeof(proto_dhcpv6_udp_t),
694 .thread_inst_size = sizeof(proto_dhcpv6_udp_thread_t),
695 .instantiate = mod_instantiate
696 },
697 .default_message_size = 4096,
698 .track_duplicates = true,
699
700 .open = mod_open,
701 .read = mod_read,
702 .write = mod_write,
703 .fd_set = mod_fd_set,
704 .track_create = mod_track_create,
705 .track_compare = mod_track_compare,
706 .connection_set = mod_connection_set,
707 .network_get = mod_network_get,
708 .client_find = mod_client_find,
709 .get_name = mod_name,
710};
static int const char char buffer[256]
Definition acutest.h:576
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:216
#define UNUSED
Definition build.h:336
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:669
#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
#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 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:294
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition cf_parse.h:446
@ 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
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
Definition cf_util.c:746
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:692
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:1215
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:345
#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
#define ERROR(fmt,...)
Definition dhcpclient.c:40
static int sockfd
Definition dhcpclient.c:55
@ 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:292
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:305
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:311
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
#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:1580
int fr_ipaddr_is_multicast(fr_ipaddr_t const *ipaddr)
Determine if an address is a multicast address.
Definition inet.c:94
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:62
char * fr_ipaddr_to_interface(TALLOC_CTX *ctx, fr_ipaddr_t *ipaddr)
Definition inet.c:1537
int fr_interface_to_ethernet(char const *interface, fr_ethernet_t *ethernet)
Definition inet.c:1625
int af
Address family.
Definition inet.h:63
Struct to represent an ethernet address.
Definition inet.h:44
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:3181
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
An instance of a proto_dhcpv6 listen section.
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.
proto_dhcpv6_t const * parent
parent instance
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:237
uint8_t const * fr_dhcpv6_option_find(uint8_t const *start, uint8_t const *end, unsigned int option)
Definition base.c:253
char const * fr_dhcpv6_packet_names[FR_DHCPV6_CODE_MAX]
Definition base.c:74
bool fr_dhcpv6_verify(uint8_t const *packet, size_t packet_len, fr_dhcpv6_decode_ctx_t const *packet_ctx, bool from_server)
Verify the packet under some various circumstances.
Definition base.c:604
#define fr_assert(_expr)
Definition rad_assert.h:37
static int ipproto
#define DEBUG2(fmt,...)
#define WARN(fmt,...)
static rs_t * conf
Definition radsniff.c:52
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:351
void * data
Module's instance data.
Definition module.h:293
module_instance_t const * parent
Parent module's instance (if any).
Definition module.h:359
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:370
fr_client_list_t * client_list_parse_section(CONF_SECTION *section, int proto, TLS_UNUSED bool tls_required)
Definition client.c:475
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:117
#define talloc_strdup(_ctx, _str)
Definition talloc.h:149
"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:241
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:118
Holds information necessary for binding or connecting to a socket.
Definition socket.h:60
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:558
#define DOC_ROOT_REF(_x)
Definition version.h:90
#define fr_box_ipaddr(_val)
Definition value.h:317