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>
33 #include <freeradius-devel/protocol/vmps/vmps.h>
122 address = *address_p;
131 PDEBUG2(
"proto_vmps_udp got read error %zd", data_size);
136 DEBUG2(
"proto_vmps_udp got no data: ignoring");
140 packet_len = data_size;
143 DEBUG2(
"proto_vmps_udp got 'too short' packet size %zd", data_size);
148 if (packet_len >
inst->max_packet_size) {
149 DEBUG2(
"proto_vmps_udp got 'too long' packet size %zd > %u", data_size,
inst->max_packet_size);
155 DEBUG(
"proto_vmps_udp got invalid packet version %d",
buffer[0]);
160 if ((
buffer[1] != FR_PACKET_TYPE_VALUE_JOIN_REQUEST) &&
161 (
buffer[1] != FR_PACKET_TYPE_VALUE_RECONFIRM_REQUEST)) {
162 DEBUG(
"proto_vmps_udp got invalid packet code %d",
buffer[1]);
174 DEBUG2(
"proto_vmps_udp got a packet which isn't VMPS");
183 memcpy(&
id,
buffer + 4, 4);
189 DEBUG2(
"proto_vmps_udp - Received %d ID %08x length %d %s",
191 (
int) packet_len, thread->
name);
232 memcpy(&packet, &track->
reply,
sizeof(packet));
254 if (data_size <= 0)
return data_size;
274 *dynamic_clients =
inst->dynamic_clients;
293 PERROR(
"Failed opening UDP socket");
307 if (setsockopt(
sockfd, SOL_SOCKET, SO_REUSEPORT, &on,
sizeof(on)) < 0) {
315 PERROR(
"Failed binding socket");
354 if (buffer_len < 4) {
355 ERROR(
"VMPS packet is too small. (%zu < 4)", buffer_len);
363 talloc_set_name_const(t,
"proto_vmps_track_t");
373 void const *one,
void const *two)
383 if (ret != 0)
return ret;
404 if (
inst->ipaddr.af == AF_UNSPEC) {
405 cf_log_err(
conf,
"No 'ipaddr' was specified in the 'udp' section");
409 if (
inst->recv_buff_is_set) {
420 if (!
inst->port_name) {
425 s = getservbyname(
inst->port_name,
"udp");
431 inst->port = ntohl(s->s_port);
442 num = talloc_array_length(
inst->allow);
444 if (
inst->dynamic_clients) {
445 cf_log_err(
conf,
"The 'allow' subsection MUST contain at least one 'network' entry when 'dynamic_clients = true'.");
471 if (!
inst->clients) {
493 if (client)
return client;
515 .default_message_size = 4096,
516 .track_duplicates =
true,
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.
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.
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
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 MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
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
Describes a host allowed to send packets to the server.
#define PDEBUG2(_fmt,...)
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.
uint8_t * reply
reply packet (if any)
fr_io_address_t const * address
of this packet.. shared between multiple packets
size_t reply_len
length of reply, or 1 for "do not reply"
@ 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 * interface
Interface to bind to.
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)
char const * name
socket name
fr_ipaddr_t * deny
denied networks for dynamic clients
char const * port_name
Name of the port for getservent().
uint16_t port
Port to listen on.
fr_ipaddr_t ipaddr
IP address to listen on.
bool dynamic_clients
whether we have dynamic clients
static int mod_open(fr_listen_t *li)
Open a UDP listener for VMPS.
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 * allow
allowed networks for dynamic clients
static char const * mod_name(fr_listen_t *li)
static const conf_parser_t networks_config[]
uint32_t max_packet_size
for message ring buffer.
fr_client_list_t * clients
local clients
uint32_t recv_buff
How big the kernel's receive buffer should be.
fr_io_address_t * connection
for connected sockets.
bool recv_buff_is_set
Whether we were provided with a receive buffer value.
static int mod_track_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED fr_client_t *client, void const *one, void const *two)
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 *buffer, size_t buffer_len)
static int mod_connection_set(fr_listen_t *li, fr_io_address_t *connection)
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_stats_t stats
statistics for this socket
CONF_SECTION * cs
our configuration
fr_app_io_t proto_vmps_udp
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_unknown_types
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.
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 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.
bool fr_vmps_ok(uint8_t const *packet, size_t *packet_len)