24 #define LOG_PREFIX "proto_dns_udp"
26 #include <freeradius-devel/server/protocol.h>
27 #include <freeradius-devel/server/cf_util.h>
28 #include <freeradius-devel/util/udp.h>
29 #include <freeradius-devel/util/table.h>
30 #include <freeradius-devel/util/trie.h>
31 #include <freeradius-devel/io/application.h>
32 #include <freeradius-devel/io/listen.h>
33 #include <freeradius-devel/io/schedule.h>
34 #include <freeradius-devel/protocol/dns/freeradius.internal.h>
138 address = *address_p;
156 packet_len = data_size;
184 (
int) packet_len, thread->
name);
230 if (data_size <= 0)
return data_size;
250 *dynamic_clients =
false;
269 PERROR(
"Failed opening UDP socket");
283 if (setsockopt(
sockfd, SOL_SOCKET, SO_REUSEPORT, &on,
sizeof(on)) < 0) {
297 PERROR(
"Failed binding socket");
354 if (
inst->ipaddr.af == AF_UNSPEC) {
355 if (!
inst->interface) {
356 cf_log_err(
conf,
"No 'ipaddr' was specified in the 'udp' section");
365 if (
inst->interface &&
367 cf_log_err(
conf,
"No 'ipaddr' specified, and we cannot determine one for interface '%s'",
373 if (
inst->recv_buff_is_set) {
385 num = talloc_array_length(
inst->allow);
405 if (!
inst->clients) {
415 if (!
inst->default_client)
return 0;
424 client->
nas_type = talloc_strdup(client,
"other");
440 if (client)
return client;
443 return inst->default_client;
455 .default_message_size = 576,
456 .track_duplicates =
false,
static int const char char buffer[256]
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)
module_t common
Common fields to all loadable modules.
Public structure describing an I/O path for a protocol.
#define CONF_PARSER_TERMINATOR
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
#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
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
#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,...
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
#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
Defines a CONF_PAIR to C data type mapping.
A section grouping multiple CONF_PAIR.
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.
#define cf_log_err(_cf, _fmt,...)
#define cf_log_perr(_cf, _fmt,...)
#define cf_section_find_parent(_cf, _name1, _name2)
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Specifies an attribute which must be present for the module to function.
Specifies a dictionary which must be loaded/loadable for the module to function.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
int fr_interface_to_ipaddr(char const *interface, fr_ipaddr_t *ipaddr, int af, bool link_local)
fr_socket_t socket
src/dst ip and port.
fr_socket_t * app_io_addr
for tracking duplicate sockets
void const * app_io_instance
I/O path configuration context.
void * thread_instance
thread / socket context
int fd
file descriptor for this socket - set by open
fr_ipaddr_t ipaddr
IPv4/IPv6 address of the host.
char const * secret
Secret PSK.
fr_ipaddr_t src_ipaddr
IPv4/IPv6 address to send responses from (family must match ipaddr).
char const * nas_type
Type of client (arbitrary).
char const * longname
Client identifier.
char const * shortname
Client nickname.
Describes a host allowed to send packets to the server.
#define RATE_LIMIT_GLOBAL(_log, _fmt,...)
Rate limit messages using a global limiting entry.
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.
int udp_send(fr_socket_t const *sock, int flags, void *data, size_t data_len)
Send a packet via a UDP socket.
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.
fr_io_address_t const * address
of this packet.. shared between multiple packets
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_COMBO_IP_PREFIX
IPv4 or IPv6 address prefix depending on length.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
module_instance_t * mi
Instance of the module being instantiated.
Temporary structure to hold arguments for instantiation calls.
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)
uint32_t max_attributes
Limit maximum decodable attributes.
static fr_dict_attr_t const * attr_packet_type
fr_io_address_t * connection
for connected sockets.
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)
uint16_t port
Port to listen on.
static fr_client_t * mod_client_find(fr_listen_t *li, fr_ipaddr_t const *ipaddr, int ipproto)
CONF_SECTION * cs
our configuration
fr_client_list_t * clients
local clients
fr_ipaddr_t * allow
allowed networks for dynamic clients
fr_client_t * default_client
default 0/0 client
fr_app_io_t proto_dns_udp
char const * name
socket name
fr_stats_t stats
statistics for this socket
bool recv_buff_is_set
Whether we were provided with a receive buffer value.
fr_dict_attr_autoload_t proto_dns_udp_dict_attr[]
uint32_t max_packet_size
for message ring buffer.
char const * interface
Interface to bind to.
static int mod_open(fr_listen_t *li)
Open a UDP listener for DHCPv6.
static const conf_parser_t udp_listen_config[]
static void mod_network_get(int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, void *instance)
fr_ipaddr_t ipaddr
IP address to listen on.
fr_ipaddr_t * deny
denied networks for dynamic clients
static char const * mod_name(fr_listen_t *li)
static const conf_parser_t networks_config[]
fr_dict_autoload_t proto_dns_udp_dict[]
fr_trie_t * trie
for parsed networks
uint32_t recv_buff
How big the kernel's receive buffer should be.
static fr_dict_t const * dict_dns
static int mod_connection_set(fr_listen_t *li, fr_io_address_t *connection)
static int mod_fd_set(fr_listen_t *li, int fd)
Set the file descriptor for this socket.
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)
char const * fr_dns_packet_names[FR_DNS_CODE_MAX]
bool fr_dns_packet_ok(uint8_t const *packet, size_t packet_len, bool query, fr_dns_decode_fail_t *reason)
fr_table_num_ordered_t fr_dns_reason_fail_table[]
#define DNS_MAX_ATTRIBUTES
CONF_SECTION * conf
Module's instance configuration.
void * data
Module's instance data.
fr_uint_t total_responses
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.
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.
fr_client_t * client_find(fr_client_list_t const *clients, fr_ipaddr_t const *ipaddr, int proto)
fr_client_list_t * client_list_parse_section(CONF_SECTION *section, int proto, TLS_UNUSED bool tls_required)
eap_aka_sim_process_conf_t * inst
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
#define talloc_get_type_abort_const
#define UDP_FLAGS_CONNECTED
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.
static void fr_socket_addr_swap(fr_socket_t *dst, fr_socket_t const *src)
Swap src/dst information of a fr_socket_t.
Holds information necessary for binding or connecting to a socket.