25 #define LOG_PREFIX "proto_dhcpv4"
27 #include <freeradius-devel/io/listen.h>
28 #include <freeradius-devel/server/module_rlm.h>
29 #include <freeradius-devel/util/debug.h>
133 inst->allowed[dv->
value->vb_uint32] =
true;
150 inst->io.app_io_instance = mi->
data;
181 request->reply->id = request->packet->id;
183 request->packet->data = talloc_memdup(request->packet,
data, data_len);
184 request->packet->data_len = data_len;
202 request->packet->socket = address->
socket;
206 RPEDEBUG(
"Failed decoding 'Net.*' packet");
228 if ((buffer_len == 1) ||
230 (request->reply->code == 0) || (request->reply->code >=
FR_DHCP_CODE_MAX) ||
242 if (client->dynamic && !client->active) {
268 PERROR(
"Failed creating new client");
273 memcpy(
buffer, &new_client,
sizeof(new_client));
274 return sizeof(new_client);
278 REDEBUG(
"Output buffer is too small to hold a DHCPv4 packet.");
282 memset(
buffer, 0, buffer_len);
287 #define COPY(_x) reply->_x = original->_x
288 #define MEMCPY(_x) memcpy(&reply->_x, &original->_x, sizeof(reply->_x))
296 ntohl(original->
xid), &request->reply_pairs);
298 RPEDEBUG(
"Failed encoding DHCPV4 reply");
308 RDEBUG(
"Sending %s XID %08x length %zu via socket %s",
312 request->async->listen->name);
316 request->reply->data_len = data_len;
336 if (!
inst->priorities[code[2]])
return 0;
338 if (!
inst->allowed[code[2]])
return -1;
350 return inst->priorities[code[2]];
367 inst->io.app_instance = instance;
370 inst->max_packet_size,
inst->num_messages);
396 if (!
inst->io.submodule)
return 0;
413 if (!
inst->max_packet_size &&
inst->io.app_io)
inst->max_packet_size =
inst->io.app_io->default_message_size;
415 if (!
inst->num_messages)
inst->num_messages = 256;
450 PERROR(
"Failed initialising protocol library");
static int const char char buffer[256]
module_t common
Common fields to all loadable modules.
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 UNCONST(_type, _ptr)
Remove const qualification from a pointer.
int cf_table_parse_int(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic function for parsing conf pair values as int.
#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_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
#define FR_TIME_DELTA_BOUND_CHECK(_name, _var, _op, _bound)
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
@ 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.
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.
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.
#define cf_log_err(_cf, _fmt,...)
size_t channel_packet_priority_len
fr_table_num_sorted_t const channel_packet_priority[]
@ FR_DHCP_BULK_LEASE_QUERY
uint8_t const * fr_dhcpv4_packet_get_option(dhcp_packet_t const *packet, size_t packet_size, fr_dict_attr_t const *da)
Retrieve a DHCP option from a raw packet buffer.
int fr_dhcpv4_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, unsigned int *code)
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_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.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
fr_socket_t socket
src/dst ip and port.
fr_client_t const * radclient
old-style client definition
Describes a host allowed to send packets to the server.
void log_request_proto_pair_list(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
Print a list of protocol fr_pair_ts.
#define RPEDEBUG(fmt,...)
#define RHEXDUMP3(_data, _len, _fmt,...)
int fr_packet_pairs_from_packet(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_packet_t const *packet)
Allocate a "Net." struct with src/dst host and port.
@ L_DBG_LVL_1
Highest priority debug messages (-x).
fr_app_io_t fr_master_app_io
int fr_master_io_listen(fr_io_instance_t *inst, fr_schedule_t *sc, size_t default_message_size, size_t num_messages)
fr_io_address_t const * address
of this packet.. shared between multiple packets
bool do_not_respond
don't respond
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
#define MODULE_INST_CTX(_mi)
Wrapper to create a module_inst_ctx_t as a compound literal.
module_instance_t * mi
Instance of the module being instantiated.
Temporary structure to hold arguments for instantiation calls.
static uint32_t fr_nbo_to_uint32(uint8_t const data[static sizeof(uint32_t)])
Read an unsigned 32bit integer from wire format (big endian)
static int mod_load(void)
static fr_dict_attr_t const * attr_packet_type
static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)
static conf_parser_t const limit_config[]
static conf_parser_t const proto_dhcpv4_config[]
How to parse a DHCPV4 listen section.
static int type_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static void mod_unload(void)
static fr_dict_t const * dict_dhcpv4
fr_dict_attr_autoload_t proto_dhcpv4_dict_attr[]
static int mod_decode(UNUSED void const *instance, request_t *request, uint8_t *const data, size_t data_len)
Decode the packet.
static const conf_parser_t priority_config[]
static int transport_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
fr_dict_autoload_t proto_dhcpv4_dict[]
static int mod_instantiate(module_inst_ctx_t const *mctx)
Instantiate the application.
static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf)
Open listen sockets/connect to external event source.
static int mod_priority_set(void const *instance, uint8_t const *buffer, size_t buflen)
static fr_dict_attr_t const * attr_message_type
An instance of a proto_dhcpv4 listen section.
char const * dhcp_message_types[]
int fr_dhcpv4_global_init(void)
Resolve/cache attributes in the DHCP dictionary.
void fr_dhcpv4_global_free(void)
ssize_t fr_dhcpv4_encode(uint8_t *buffer, size_t buflen, dhcp_packet_t *original, int code, uint32_t xid, fr_pair_list_t *vps)
#define REQUEST_VERIFY(_x)
static int instantiate(module_inst_ctx_t const *mctx)
CONF_SECTION * conf
Module's instance configuration.
void * data
Module's instance data.
module_instantiate_t instantiate
Callback to allow the module to register any per-instance resources like sockets and file handles.
module_t * exported
Public module structure.
static const uchar sc[16]
fr_client_t * client_afrom_request(TALLOC_CTX *ctx, request_t *request)
Create a new client, consuming all attributes in the control list of the request.
int module_instantiate(module_instance_t *instance)
Manually complete module setup by calling its instantiate function.
eap_aka_sim_process_conf_t * inst
#define talloc_get_type_abort_const
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
unsigned int code
Packet code (type).
uint8_t * data
Packet data (body).
size_t data_len
Length of packet data.
static void fr_socket_addr_swap(fr_socket_t *dst, fr_socket_t const *src)
Swap src/dst information of a fr_socket_t.
static size_t char ** out
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.