25 #include <freeradius-devel/io/application.h>
26 #include <freeradius-devel/io/listen.h>
27 #include <freeradius-devel/io/schedule.h>
28 #include <freeradius-devel/radius/radius.h>
29 #include <freeradius-devel/util/pair_legacy.h>
31 #include <freeradius-devel/server/dl_module.h>
32 #include <freeradius-devel/server/module.h>
33 #include <freeradius-devel/server/module_rlm.h>
49 #define MPRINT(x, ...)
129 cf_log_err(ci,
"Please define 'namespace' in this virtual server");
134 if (!
inst->attr_packet_type) {
135 cf_log_err(ci,
"Failed to find 'Packet-Type' attribute");
150 inst->code = type_enum->
value->vb_uint32;
165 if (strcmp(
inst->io_submodule->module->dl->name,
"proto_detail_work") != 0) {
168 char const *inst_name;
170 inst->work_submodule = NULL;
178 "work", NULL,
false);
180 cf_log_err(mi->
conf,
"Failed to create configuration for worker");
196 "work", inst_name, 0);
197 if (
inst->work_submodule == NULL) {
200 TALLOC_FREE(
inst->work_submodule);
207 inst->work_io_instance =
inst->work_submodule->data;
208 inst->work_io_conf =
inst->work_submodule->conf;
225 time_t timestamp = 0;
230 request->dict =
inst->dict;
231 request->packet->code =
inst->code;
236 request->packet->socket.fd = -1;
237 request->packet->socket.inet.src_ipaddr.af = AF_INET;
238 request->packet->socket.inet.src_ipaddr.addr.v4.s_addr = htonl(INADDR_NONE);
239 request->packet->socket.inet.dst_ipaddr = request->packet->socket.inet.src_ipaddr;
241 request->reply->socket.inet.src_ipaddr = request->packet->socket.inet.src_ipaddr;
242 request->reply->socket.inet.dst_ipaddr = request->packet->socket.inet.src_ipaddr;
244 end =
data + data_len;
248 if (sscanf((
char const *)
data,
"%*s %*s %*d %*d:%*d:%*d %d", &num) != 1) {
249 REDEBUG(
"Malformed header '%s'", (
char const *)
data);
256 for (p =
data; p < end; p++) {
274 if ((end - p) < 2)
break;
281 if ((*p !=
'\0') && (*p !=
'\t')) {
282 REDEBUG(
"Malformed line %d", lineno);
295 if (
strncasecmp((
char const *) p,
"Request-Authenticator", 21) == 0)
goto next;
302 if (
strncasecmp((
char const *) p,
"Timestamp = ", 12) == 0) {
305 timestamp = atoi((
char const *) p);
318 if (
strncasecmp((
char const *) p,
"Donestamp", 9) == 0) {
357 .
ctx = request->request_ctx,
369 RWDEBUG(
"Ignoring line %d - :%s", lineno, p);
377 request->packet->socket.inet.src_ipaddr =
vp->vp_ip;
379 request->packet->socket.inet.dst_ipaddr =
vp->vp_ip;
381 request->packet->socket.inet.src_port =
vp->vp_uint16;
383 request->packet->socket.inet.dst_port =
vp->vp_uint16;
386 if (!request->dict) {
395 while ((p < end) && (*p)) p++;
401 return inst->app_io->decode(
inst->app_io_instance, request,
data, data_len);
406 if (buffer_len < 1)
return -1;
408 *
buffer = request->reply->code;
419 return inst->priority;
463 if (
inst->app_io->open(li) < 0) {
476 if (strcmp(
inst->io_submodule->module->dl->name,
"proto_detail_work") == 0) {
504 DEBUG(
"Listening on %s bound to virtual server %s",
537 if (!
inst->io_submodule) {
538 cf_log_err(
conf,
"Virtual server for detail files requires a 'transport' configuration");
546 inst->app_io_instance =
inst->io_submodule->data;
547 inst->app_io_conf =
inst->io_submodule->conf;
553 if (!
inst->max_packet_size)
inst->max_packet_size =
inst->app_io->default_message_size;
555 if (!
inst->num_messages)
inst->num_messages = 2;
static int const char char buffer[256]
module_t common
Common fields to all loadable modules.
fr_io_name_t get_name
get the socket name
Public structure describing an I/O path for a protocol.
module_t common
Common fields provided by all modules.
Describes a new application (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
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
#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.
Configuration AVP similar to a fr_pair_t.
A section grouping multiple CONF_PAIR.
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
CONF_SECTION * cf_section_dup(TALLOC_CTX *ctx, CONF_SECTION *parent, CONF_SECTION const *cs, char const *name1, char const *name2, bool copy_meta)
Duplicate a configuration section.
#define cf_log_err(_cf, _fmt,...)
#define cf_log_perr(_cf, _fmt,...)
static int fr_dcursor_append(fr_dcursor_t *cursor, void *v)
Insert a single item at the end of the list.
static void * fr_dcursor_tail(fr_dcursor_t *cursor)
Wind cursor to the tail item in the list.
static void fr_dcursor_free_list(fr_dcursor_t *cursor)
Free the current item and all items after it.
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
fr_dict_t const * fr_dict_by_protocol_num(unsigned int num)
Lookup a protocol by its number.
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.
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
fr_value_box_t const * value
Enum value (what name maps to).
fr_dict_enum_value_t * fr_dict_enum_by_name(fr_dict_attr_t const *da, char const *name, ssize_t len)
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.
Value of an enumerated attribute.
@ DL_MODULE_TYPE_SUBMODULE
Driver (or method in the case of EAP)
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
size_t num_messages
for the message ring buffer
bool non_socket_listener
special internal listener that does not use sockets.
char const * name
printable name for this socket - set by open
void const * app_instance
size_t default_message_size
copied from app_io, but may be changed
void const * app_io_instance
I/O path configuration context.
int fr_io_listen_free(fr_listen_t *li)
CONF_SECTION * server_cs
CONF_SECTION of the server.
void * thread_instance
thread / socket context
fr_app_io_t const * app_io
I/O path functions.
#define RHEXDUMP3(_data, _len, _fmt,...)
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
int strncasecmp(char *s1, char *s2, int n)
module_instance_t * mi
Instance of the module being instantiated.
Temporary structure to hold arguments for instantiation calls.
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
fr_slen_t fr_pair_list_afrom_substr(fr_pair_parse_t const *root, fr_pair_parse_t *relative, fr_sbuff_t *in)
Parse a fr_pair_list_t from a substring.
struct fr_pair_parse_s fr_pair_parse_t
static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)
static fr_dict_attr_t const * attr_protocol
static int type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static int mod_open(void *instance, fr_schedule_t *sc, CONF_SECTION *conf)
Open listen sockets/connect to external event source.
static fr_dict_attr_t const * attr_packet_src_port
static fr_dict_t const * dict_freeradius
static int mod_decode(void const *instance, request_t *request, uint8_t *const data, size_t data_len)
Decode the packet, and set the request->process function.
static fr_dict_attr_t const * attr_packet_original_timestamp
static int mod_priority_set(void const *instance, UNUSED uint8_t const *buffer, UNUSED size_t buflen)
fr_dict_attr_autoload_t proto_detail_dict_attr[]
fr_dict_autoload_t proto_detail_dict[]
static int transport_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static fr_dict_attr_t const * attr_packet_dst_ip_address
static int mod_instantiate(module_inst_ctx_t const *mctx)
Instantiate the application.
static fr_dict_attr_t const * attr_packet_src_ip_address
static fr_dict_attr_t const * attr_packet_dst_port
static conf_parser_t const proto_detail_config[]
How to parse a Detail listen section.
Detail master protocol handler.
static int instantiate(module_inst_ctx_t const *mctx)
#define FR_SBUFF_IN(_start, _len_or_end)
fr_network_t * fr_schedule_directory_add(fr_schedule_t *sc, fr_listen_t *li)
Add a directory NOTE_EXTEND to a scheduler.
fr_network_t * fr_schedule_listen_add(fr_schedule_t *sc, fr_listen_t *li)
Add a fr_listen_t to a scheduler.
CONF_SECTION * conf
Module's instance configuration.
void * data
Module's instance data.
module_list_t * ml
Module list this instance belongs to.
size_t thread_inst_size
Size of the module's thread-specific instance data.
static const uchar sc[16]
fr_slen_t module_instance_name_from_conf(char const **name, CONF_SECTION *conf)
Avoid boilerplate when setting the module instance name.
int module_instance_conf_parse(module_instance_t *mi, CONF_SECTION *conf)
Covert a CONF_SECTION into parsed module instance data.
module_instance_t * module_instance_alloc(module_list_t *ml, module_instance_t const *parent, dl_module_type_t type, char const *mod_name, char const *inst_name, module_instance_state_t init_state)
Allocate a new module and add it to a module list for later bootstrap/instantiation.
MEM(pair_append_request(&vp, attr_eap_aka_sim_identity) >=0)
eap_aka_sim_process_conf_t * inst
fr_aka_sim_id_type_t type
Stores an attribute, a value and various bits of other data.
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
#define talloc_get_type_abort_const
static fr_unix_time_t fr_unix_time_from_sec(int64_t sec)
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
Appends a list of fr_pair_t from a temporary list to a destination list.
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
static size_t char ** out
fr_dict_t const * virtual_server_dict_by_child_ci(CONF_ITEM const *ci)
Return the namespace for a given virtual server specified by a CONF_ITEM within the virtual server.
int virtual_server_listen_transport_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic conf_parser_t func for loading drivers.
module_instance_t * virtual_server_listener_by_data(void const *data)
Resolve proto data to a module instance.