25 #include <freeradius-devel/server/protocol.h>
26 #include <freeradius-devel/util/udp.h>
27 #include <freeradius-devel/util/trie.h>
28 #include <freeradius-devel/bfd/bfd.h>
29 #include <freeradius-devel/io/application.h>
30 #include <freeradius-devel/io/listen.h>
31 #include <freeradius-devel/io/schedule.h>
121 bfd_packet_t *packet;
122 char const *
err = NULL;
133 address = *address_p;
142 PDEBUG2(
"proto_bfd_udp got read error");
147 DEBUG2(
"proto_bfd_udp got no data: ignoring");
156 DEBUG2(
"BFD %s - Received invalid packet on %s - unknown client %pV:%u",
inst->server_name, thread->
name,
162 packet_len = data_size;
165 DEBUG2(
"BFD %s - Received invalid packet on %s - %s",
inst->server_name, thread->
name,
err);
171 packet = (bfd_packet_t *) wrapper->
packet;
191 return sizeof(wrapper) + packet_len;
218 DEBUG(
"BFD %s peer %s sending %s",
238 *dynamic_clients =
inst->dynamic_clients;
256 PERROR(
"Failed opening UDP socket");
270 if (setsockopt(
sockfd, SOL_SOCKET, SO_REUSEPORT, &on,
sizeof(on)) < 0) {
277 if (
inst->recv_buff_is_set) {
280 opt =
inst->recv_buff;
281 if (setsockopt(
sockfd, SOL_SOCKET, SO_RCVBUF, &opt,
sizeof(
int)) < 0) {
288 if (
inst->send_buff_is_set) {
291 opt =
inst->send_buff;
292 if (setsockopt(
sockfd, SOL_SOCKET, SO_SNDBUF, &opt,
sizeof(
int)) < 0) {
303 if (setsockopt(
sockfd, IPPROTO_IP, IP_TTL, &opt,
sizeof(opt)) < 0) {
314 PERROR(
"Failed binding socket");
371 if (
inst->ipaddr.af == AF_UNSPEC) {
372 cf_log_err(
conf,
"No 'ipaddr' was specified in the 'udp' section");
376 if (
inst->recv_buff_is_set) {
381 if (
inst->send_buff_is_set) {
391 if (!
inst->port_name) {
396 s = getservbyname(
inst->port_name,
"udp");
402 inst->port = ntohl(s->s_port);
409 num = talloc_array_length(
inst->allow);
411 if (
inst->dynamic_clients) {
412 cf_log_err(
conf,
"The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'.");
448 if (peer->
inst)
continue;
478 if (
ipproto != IPPROTO_UDP)
return NULL;
526 .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 FR_BFD_HEADER_LENGTH
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
#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.
Common header for all CONF_* types.
A section grouping multiple CONF_PAIR.
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
void * cf_data_value(CONF_DATA const *cd)
Return the user assigned value of CONF_DATA.
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
#define cf_log_err(_cf, _fmt,...)
#define cf_data_find(_cf, _type, _name)
#define cf_log_perr(_cf, _fmt,...)
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
int fr_ipaddr_is_inaddr_any(fr_ipaddr_t const *ipaddr)
Determine if an address is the INADDR_ANY address for its address family.
int fr_ipaddr_to_sockaddr(struct sockaddr_storage *sa, socklen_t *salen, fr_ipaddr_t const *ipaddr, uint16_t port)
Convert our internal ip address representation to a sockaddr.
int8_t fr_ipaddr_cmp(fr_ipaddr_t const *a, fr_ipaddr_t const *b)
Compare two ip addresses.
fr_socket_t socket
src/dst ip and port.
fr_client_t const * radclient
old-style client definition
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.
fr_ipaddr_t src_ipaddr
IPv4/IPv6 address to send responses from (family must match ipaddr).
char const * shortname
Client nickname.
Describes a host allowed to send packets to the server.
#define PDEBUG2(_fmt,...)
Stores all information relating to an event list.
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.
void bfd_session_start(bfd_session_t *session)
int bfd_session_init(bfd_session_t *session)
bfd_state_change_t bfd_session_process(bfd_session_t *session, bfd_packet_t *bfd)
void bfd_session_admin_down(bfd_session_t *session)
int sockfd
cached for laziness
struct sockaddr_storage remote_sockaddr
cached for laziness
@ BFD_STATE_CHANGE_INVALID
@ BFD_STATE_CHANGE_ADMIN_DOWN
we are admin-down
@ BFD_STATE_CHANGE_NONE
no state change
fr_listen_t * listen
associated listener
bfd_session_state_t session_state
our view of the session state
@ BFD_WRAPPER_RECV_PACKET
fr_client_t client
might as well reuse this, others need it
char const * server_name
our name
bool only_state_changes
copied from proto_bfd_udp.c
uint16_t port
peer port where packets are sent to
void * inst
proto_bfd_udp instance using this session
fr_network_t * nr
network side of things
bfd_state_change_t state_change
struct sockaddr_storage local_sockaddr
cached for laziness
fr_event_list_t * el
event list
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.
char const * port_name
Name of the port for getservent().
bool dynamic_clients
whether we have dynamic clients
bool only_state_changes
on read(), only send packets which signal a state change
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)
static fr_client_t * mod_client_find(fr_listen_t *li, fr_ipaddr_t const *ipaddr, int ipproto)
uint16_t port
Port to listen on.
fr_stats_t stats
statistics for this socket
char const * name
socket name
CONF_SECTION * cs
our configuration
char const * server_name
virtual server name
char const * interface
Interface to bind to.
static void mod_event_list_set(fr_listen_t *li, fr_event_list_t *el, void *nr)
Set the event list for a new socket.
fr_io_address_t * connection
for connected sockets.
static int mod_open(fr_listen_t *li)
Open a UDP listener for RADIUS.
static const conf_parser_t udp_listen_config[]
bool send_buff_is_set
Whether we were provided with a send_buff.
static void mod_network_get(int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, void *instance)
static char const * mod_name(fr_listen_t *li)
static const conf_parser_t networks_config[]
fr_rb_tree_t * peers
our peers
bool recv_buff_is_set
Whether we were provided with a recv_buff.
uint32_t recv_buff
How big the kernel's receive buffer should be.
fr_ipaddr_t * allow
allowed networks for dynamic clients
fr_ipaddr_t ipaddr
IP address to listen on.
uint32_t send_buff
How big the kernel's send buffer should be.
fr_trie_t * trie
for parsed networks
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)
fr_app_io_t proto_bfd_udp
fr_ipaddr_t * deny
denied networks for dynamic clients
char const * fr_bfd_packet_names[FR_BFD_CODE_MAX]
bool fr_bfd_packet_ok(char const **err, uint8_t const *packet, size_t packet_len)
void * fr_rb_iter_next_inorder(fr_rb_iter_inorder_t *iter)
Return the next node.
void * fr_rb_iter_init_inorder(fr_rb_iter_inorder_t *iter, fr_rb_tree_t *tree)
Initialise an in-order iterator.
void * fr_rb_find(fr_rb_tree_t const *tree, void const *data)
Iterator structure for in-order traversal of an rbtree.
The main red black tree structure.
CONF_SECTION * conf
Module's instance configuration.
void * data
Module's instance data.
module_instance_t const * parent
Parent module's instance (if any).
fr_uint_t total_responses
fr_uint_t total_packets_dropped
fr_uint_t total_malformed_requests
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.
eap_aka_sim_process_conf_t * inst
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define talloc_get_type_abort_const
#define UDP_FLAGS_CONNECTED
int sendfromto(int fd, void *buf, size_t len, int flags, int ifindex, struct sockaddr *from, socklen_t from_len, struct sockaddr *to, socklen_t to_len)
Send packet via a file descriptor, setting the src address and outbound interface.
static fr_event_list_t * el
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.
#define fr_box_ipaddr(_val)