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: 32cc198586d7ed6212c17418c4270c41ab5813a6 $
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/util/udp.h>
27#include <freeradius-devel/util/trie.h>
28#include <freeradius-devel/io/application.h>
29#include <freeradius-devel/io/listen.h>
30#include <freeradius-devel/io/schedule.h>
31#include <freeradius-devel/protocol/dhcpv6/freeradius.internal.h>
32#include "proto_dhcpv6.h"
33
35
36typedef struct {
37 char const *name; //!< socket name
38 int sockfd;
39
40 fr_io_address_t *connection; //!< for connected sockets.
41
42 fr_stats_t stats; //!< statistics for this socket
44
45typedef struct {
46 CONF_SECTION *cs; //!< our configuration
47 proto_dhcpv6_t const *parent; //!< parent instance
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 message which is not DHCPv6");
200 return 0;
201 }
202
203 /*
204 * If there is a Server-ID option configured, then it has to match.
205 */
206 if (inst->parent->server_id &&
208 .duid = inst->parent->server_id,
209 .duid_len = talloc_array_length(inst->parent->server_id),
210 }, false)) {
211 RATE_LIMIT_GLOBAL(PWARN, "Invalid packet - ignoring message which is malformed (%s)", fr_strerror());
212 return 0;
213 }
214
215 /*
216 * proto_dhcpv6 sets the priority
217 */
218
219 xid = fr_nbo_to_uint24(packet->transaction_id);
220
221 /*
222 * Print out what we received.
223 */
224 DEBUG2("Received %s XID %08x length %d %s", fr_dhcpv6_packet_names[packet->code], xid,
225 (int) packet_len, thread->name);
226
227 return packet_len;
228}
229
230static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, UNUSED fr_time_t request_time,
231 uint8_t *buffer, size_t buffer_len, UNUSED size_t written)
232{
234 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
235
236 fr_io_track_t *track = talloc_get_type_abort(packet_ctx, fr_io_track_t);
237 fr_socket_t socket;
238
239 int flags;
240 ssize_t data_size;
241
242 /*
243 * @todo - share a stats interface with the parent? or
244 * put the stats in the listener, so that proto_dhcpv6
245 * can update them, too.. <sigh>
246 */
247 thread->stats.total_responses++;
248
249 flags = UDP_FLAGS_CONNECTED * (thread->connection != NULL);
250
251 /*
252 * Send packets to the originator, EXCEPT that we always
253 * originate packets from our src_ipaddr.
254 */
255 fr_socket_addr_swap(&socket, &track->address->socket);
256 if (!fr_ipaddr_is_inaddr_any(&inst->src_ipaddr)) socket.inet.src_ipaddr = inst->src_ipaddr;
257
258 /*
259 * Figure out which kind of packet we're sending.
260 */
261 if (!thread->connection) {
262 // @todo - figure out where to send the packet
263 }
264
265 /*
266 * proto_dhcpv6 takes care of suppressing do-not-respond, etc.
267 */
268 data_size = udp_send(&socket, flags, buffer, buffer_len);
269
270 /*
271 * This socket is dead. That's an error...
272 */
273 if (data_size <= 0) return data_size;
274
275 return data_size;
276}
277
278
280{
281 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
282
283 thread->connection = connection;
284 return 0;
285}
286
287
288static void mod_network_get(int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, void *instance)
289{
290 proto_dhcpv6_udp_t *inst = talloc_get_type_abort(instance, proto_dhcpv6_udp_t);
291
292 *ipproto = IPPROTO_UDP;
293 *dynamic_clients = inst->dynamic_clients;
294 *trie = inst->trie;
295}
296
297
298/** Open a UDP listener for DHCPv6
299 *
300 */
301static int mod_open(fr_listen_t *li)
302{
304 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
305
306 int sockfd, rcode;
307 fr_ipaddr_t ipaddr = inst->ipaddr;
308 uint16_t port = inst->port;
309
310 li->fd = sockfd = fr_socket_server_udp(&inst->ipaddr, &port, inst->port_name, true);
311 if (sockfd < 0) {
312 cf_log_err(li->cs, "Failed opening UDP socket - %s", fr_strerror());
313 error:
314 return -1;
315 }
316
317 li->app_io_addr = fr_socket_addr_alloc_inet_src(li, IPPROTO_UDP, 0, &inst->ipaddr, port);
318
319 /*
320 * Set SO_REUSEPORT before bind, so that all packets can
321 * listen on the same destination IP address.
322 */
323 if (1) {
324 int on = 1;
325
326 if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)) < 0) {
327 cf_log_err(li->cs, "Failed to set socket 'reuseport' - %s", fr_syserror(errno));
328 close(sockfd);
329 return -1;
330 }
331 }
332
333#ifdef SO_RCVBUF
334 if (inst->recv_buff_is_set) {
335 int opt;
336
337 opt = inst->recv_buff;
338 if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(int)) < 0) {
339 cf_log_warn(li->cs, "Failed setting 'recv_buf' - %s", fr_syserror(errno));
340 }
341 }
342#endif
343
344 /*
345 * SUID up is really only needed if interface is set, OR port <1024.
346 */
347 rad_suid_up();
348 rcode = fr_socket_bind(sockfd, inst->interface, &ipaddr, &port);
350 if (rcode < 0) {
351 cf_log_err(li->cs, "Failed binding to socket - %s", fr_strerror());
352 cf_log_err(li->cs, DOC_ROOT_REF(troubleshooting/network/bind));
353 close_error:
354 close(sockfd);
355 goto error;
356 }
357
358 /*
359 * If the user specified a multicast address, then join
360 * that group.
361 */
362 if (inst->multicast) {
363 struct ipv6_mreq mreq;
364
365 mreq.ipv6mr_multiaddr = inst->ipaddr.addr.v6;
366 mreq.ipv6mr_interface = if_nametoindex(inst->interface);
367 if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) < 0) {
368 PERROR("Failed joining multicast group %pV ", fr_box_ipaddr(inst->ipaddr));
369 goto close_error;
370 }
371
372 if (inst->hop_limit) {
373 int hop_limit = inst->hop_limit;
374
375 if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
376 (char *) &hop_limit, sizeof(hop_limit)) < 0) {
377 ERROR("Failed to set multicast hop_limit: %s", fr_syserror(errno));
378 goto close_error;
379 }
380 }
381 }
382
383 thread->sockfd = sockfd;
384
385 fr_assert((cf_parent(inst->cs) != NULL) && (cf_parent(cf_parent(inst->cs)) != NULL)); /* listen { ... } */
386
388 NULL, 0,
389 &inst->ipaddr, inst->port,
390 inst->interface);
391 return 0;
392}
393
394
395/** Set the file descriptor for this socket.
396 *
397 */
398static int mod_fd_set(fr_listen_t *li, int fd)
399{
401 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
402
403 thread->sockfd = fd;
404
406 &thread->connection->socket.inet.src_ipaddr, thread->connection->socket.inet.src_port,
407 &inst->ipaddr, inst->port,
408 inst->interface);
409
410 return 0;
411}
412
413static void *mod_track_create(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED fr_client_t *client,
414 fr_io_track_t *track, uint8_t const *packet, size_t packet_len)
415{
417 uint8_t const *option;
418 size_t t_size = sizeof(*t);
419 size_t option_len;
420
421 /*
422 * Relay packets can be nested to almost any depth.
423 */
424 while (packet[0] == FR_DHCPV6_RELAY_FORWARD) {
425 if (packet_len < (2 + 32)) return NULL;
426
427 /*
428 * fr_dhcpv6_option_find() ensures that the
429 * option header and data are contained within
430 * the given packet.
431 */
432 option = fr_dhcpv6_option_find(packet + 2 + 32, packet + packet_len, attr_relay_message->attr);
433 if (!option) return NULL;
434
435 option_len = fr_nbo_to_uint16(option + 2);
436
437 packet = option + 4; /* skip option header */
438 packet_len = option_len;
439 }
440
441 if (packet_len <= 4) return NULL;
442
443 /*
444 * Search the packet options.
445 */
446 option = fr_dhcpv6_option_find(packet + 4, packet + packet_len, attr_client_id->attr);
447 if (!option) return NULL;
448
449 option_len = fr_nbo_to_uint16(option + 2);
450
451 if (option_len > ((packet - option) + packet_len)) return NULL;
452
453 t = (proto_dhcpv6_track_t *) talloc_zero_array(track, uint8_t, t_size + option_len);
454 if (!t) return NULL;
455
456 talloc_set_name_const(t, "proto_dhcpv6_track_t");
457
458 memcpy(&t->header, packet, 4); /* packet code + 24-bit transaction ID */
459
460 memcpy(&t->client_id[0], option + 4, option_len);
461 t->client_id_len = option_len;
462
463 return t;
464}
465
466
467static int mod_track_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED fr_client_t *client,
468 void const *one, void const *two)
469{
470 int ret;
471 proto_dhcpv6_track_t const *a = one;
472 proto_dhcpv6_track_t const *b = two;
473
474 ret = memcmp(&a->header, &b->header, sizeof(a->header));
475 if (ret != 0) return ret;
476
477 ret = (a->client_id_len < b->client_id_len) - (a->client_id_len > b->client_id_len);
478 if (ret != 0) return ret;
479
480 return memcmp(a->client_id, b->client_id, a->client_id_len);
481}
482
483
484static char const *mod_name(fr_listen_t *li)
485{
486 proto_dhcpv6_udp_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_dhcpv6_udp_thread_t);
487
488 return thread->name;
489}
490
491
492static int mod_instantiate(module_inst_ctx_t const *mctx)
493{
494 proto_dhcpv6_udp_t *inst = talloc_get_type_abort(mctx->mi->data, proto_dhcpv6_udp_t);
495 size_t num;
496 CONF_ITEM *ci;
497 CONF_SECTION *server_cs;
498 fr_client_t *client;
499 CONF_SECTION *conf = mctx->mi->conf;
500
501 inst->cs = conf;
502
503 /*
504 * Complain if no "ipaddr" is set.
505 */
506 if (inst->ipaddr.af == AF_UNSPEC) {
507 if (!inst->interface) {
508 cf_log_err(conf, "No 'ipaddr' was specified in the 'udp' section");
509 return -1;
510 }
511
512 /*
513 * If there's a named interface, maybe we can
514 * find a link-local address for it. If so, just
515 * use that.
516 */
517 if (inst->interface &&
518 (fr_interface_to_ipaddr(inst->interface, &inst->ipaddr, AF_INET6, true) < 0)) {
519 cf_log_err(conf, "No 'ipaddr' specified, and we cannot determine one for interface '%s'",
520 inst->interface);
521 return -1;
522 }
523 }
524
525 if (inst->ipaddr.af != AF_INET6) {
526 cf_log_err(conf, "DHCPv6 cannot use IPv4 for 'ipaddr'");
527 return -1;
528 }
529
530 /*
531 * Remember if we're a multicast socket.
532 */
533 inst->multicast = (fr_ipaddr_is_multicast(&inst->ipaddr) == 1);
534
535 /*
536 * Set src_ipaddr to ipaddr if not otherwise specified
537 */
538 if (inst->src_ipaddr.af == AF_UNSPEC) {
539 if (!inst->multicast) {
540 inst->src_ipaddr = inst->ipaddr;
541
542 /*
543 * If the admin didn't specify an
544 * interface, then try to find one
545 * automatically. We only do this for
546 * link-local addresses.
547 */
548 if (!inst->interface) {
549 inst->interface = fr_ipaddr_to_interface(inst, &inst->ipaddr);
550 if (!inst->interface) {
551 interface_fail:
552 cf_log_err(conf, "No 'interface' specified, and we cannot "
553 "determine one for 'ipaddr = %pV'",
554 fr_box_ipaddr(inst->ipaddr));
555 return -1;
556 }
557 }
558
559 } else {
560 /*
561 * Multicast addresses MUST specify an interface.
562 */
563 if (!inst->interface) goto interface_fail;
564
565 if (fr_interface_to_ipaddr(inst->interface, &inst->src_ipaddr, AF_INET6, true) < 0) {
566 cf_log_err(conf, "No 'src_ipaddr' specified, and we cannot determine "
567 "one for 'ipaddr = %pV' and interface '%s'",
568 fr_box_ipaddr(inst->ipaddr), inst->interface);
569 return -1;
570 }
571 }
572 }
573
574 /*
575 * src_ipaddr must be of the same address family as "ipaddr"
576 */
577 if (inst->src_ipaddr.af != inst->ipaddr.af) {
578 cf_log_err(conf, "Both 'ipaddr' and 'src_ipaddr' must be from the same address family");
579 return -1;
580 }
581
582 /*
583 * Get the MAC address associated with this interface.
584 * It can be used to create a server ID.
585 */
586 if (inst->interface) fr_interface_to_ethernet(inst->interface, &inst->ethernet);
587
588 if (inst->recv_buff_is_set) {
589 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, >=, 32);
590 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, <=, INT_MAX);
591 }
592
593 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, >=, 4);
594 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, <=, 65536);
595
596 if (!inst->port) {
597 struct servent *s;
598
599 if (!inst->port_name) {
600 cf_log_err(conf, "No 'port' was specified in the 'udp' section");
601 return -1;
602 }
603
604 s = getservbyname(inst->port_name, "udp");
605 if (!s) {
606 cf_log_err(conf, "Unknown value for 'port_name = %s", inst->port_name);
607 return -1;
608 }
609
610 inst->port = ntohs(s->s_port);
611 }
612
613 /*
614 * Parse and create the trie for dynamic clients, even if
615 * there's no dynamic clients.
616 */
617 num = talloc_array_length(inst->allow);
618 if (!num) {
619 if (inst->dynamic_clients) {
620 cf_log_err(conf, "The 'allow' subsection MUST contain at least one 'network' entry when "
621 "'dynamic_clients = true'.");
622 return -1;
623 }
624 } else {
625 inst->trie = fr_master_io_network(inst, inst->ipaddr.af, inst->allow, inst->deny);
626 if (!inst->trie) {
627 cf_log_perr(conf, "Failed creating list of networks");
628 return -1;
629 }
630 }
631
632 ci = cf_section_to_item(mctx->mi->parent->conf); /* listen { ... } */
633 fr_assert(ci != NULL);
634 ci = cf_parent(ci);
635 fr_assert(ci != NULL);
636
637 server_cs = cf_item_to_section(ci);
638
639 /*
640 * Look up local clients, if they exist.
641 *
642 * @todo - ensure that we only parse clients which are
643 * for IPPROTO_UDP, and don't require a "secret".
644 */
645 if (cf_section_find_next(server_cs, NULL, "client", CF_IDENT_ANY)) {
646 inst->clients = client_list_parse_section(server_cs, IPPROTO_UDP, false);
647 if (!inst->clients) {
648 cf_log_err(conf, "Failed creating local clients");
649 return -1;
650 }
651 }
652
653 /*
654 * Create a fake client.
655 */
656 client = inst->default_client = talloc_zero(inst, fr_client_t);
657 if (!inst->default_client) return -1;
658
659 client->ipaddr = (fr_ipaddr_t ) {
660 .af = AF_INET6,
661 };
662
663 client->src_ipaddr = client->ipaddr;
664
665 client->longname = client->shortname = client->secret = talloc_strdup(client, "default");
666 client->nas_type = talloc_strdup(client, "other");
667
669
670 return 0;
671}
672
674{
676
677 /*
678 * Prefer local clients.
679 */
680 if (inst->clients) {
681 return client_find(inst->clients, ipaddr, ipproto);
682 }
683
684 return inst->default_client;
685}
686
688 .common = {
689 .magic = MODULE_MAGIC_INIT,
690 .name = "dhcpv6_udp",
692 .inst_size = sizeof(proto_dhcpv6_udp_t),
693 .thread_inst_size = sizeof(proto_dhcpv6_udp_thread_t),
694 .instantiate = mod_instantiate
695 },
696 .default_message_size = 4096,
697 .track_duplicates = true,
698
699 .open = mod_open,
700 .read = mod_read,
701 .write = mod_write,
702 .fd_set = mod_fd_set,
703 .track_create = mod_track_create,
704 .track_compare = mod_track_compare,
705 .connection_set = mod_connection_set,
706 .network_get = mod_network_get,
707 .client_find = mod_client_find,
708 .get_name = mod_name,
709};
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:384
#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:749
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:695
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:1225
#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: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
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:233
#define PWARN(_fmt,...)
Definition log.h:232
#define RATE_LIMIT_GLOBAL(_log, _fmt,...)
Rate limit messages using a global limiting entry.
Definition log.h:658
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
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_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:3210
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:843
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:249
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:126
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