24 RCSID(
"$Id: 3be14b864946e15203c61e19d318cd8ad323c9a2 $")
26 #include <freeradius-devel/server/base.h>
27 #include <freeradius-devel/server/module_rlm.h>
28 #include <freeradius-devel/io/pair.h>
29 #include <freeradius-devel/util/udp_queue.h>
30 #include <freeradius-devel/dhcpv4/dhcpv4.h>
32 #include <freeradius-devel/unlang/module.h>
120 if (
inst->config.ipaddr.af == AF_UNSPEC) {
125 if (
inst->config.ipaddr.af != AF_INET) {
126 cf_log_err(
conf,
"DHCPv4 can only use IPv4 addresses in 'ipaddr'");
130 if (!
inst->config.port) {
210 int code, port, rcode;
219 REDEBUG(
"Relayed packets MUST have a Gateway-IP-Address attribute");
230 }
else if (original) {
231 xid = ntohl(original->
xid);
244 code =
vp->vp_uint32;
250 code = request->packet->code;
258 port =
vp->vp_uint16;
267 if (!
vp || (
vp->vp_ip.af != AF_INET)) {
268 RDEBUG(
"No &control.Net.Dst.IP, cannot relay packet");
277 RPEDEBUG(
"Failed encoding DHCPV4 request");
285 if (packet->opcode == 1) {
287 if (original->
hops < 255) packet->hops = original->
hops + 1;
289 if (packet->hops < 255) packet->hops++;
335 .thread_inst_type =
"rlm_dhcpv4_thread_t",
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
#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_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,...
#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.
#define cf_log_err(_cf, _fmt,...)
#define DEFAULT_PACKET_SIZE
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.
void *_CONST data
Module instance's parsed configuration.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
CONF_SECTION *_CONST conf
Module's instance configuration.
void unlang_interpret_mark_runnable(request_t *request)
Mark a request as resumable.
void log_request_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 fr_pair_list_t.
#define REXDENT()
Exdent (unindent) R* messages by one level.
#define RPEDEBUG(fmt,...)
#define RINDENT()
Indent R* messages by one level.
@ L_DBG_LVL_1
Highest priority debug messages (-x).
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
void * thread
Thread specific instance data.
void * rctx
Resume ctx that a module previously set.
fr_event_list_t * el
Event list to register any IO handlers and timers against.
dl_module_inst_t const * inst
Dynamic loader API handle for the module.
void * thread
Thread instance data.
dl_module_inst_t const * inst
Dynamic loader API handle for the module.
Temporary structure to hold arguments for module calls.
Temporary structure to hold arguments for instantiation calls.
Temporary structure to hold arguments for thread_instantiation calls.
Specifies a module method identifier.
module_t common
Common fields presented by all modules.
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find a pair with a matching fr_dict_attr_t, by walking the nested fr_dict_attr_t tree.
static const conf_parser_t config[]
char const * dhcp_message_types[]
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 RETURN_MODULE_NOOP
rlm_rcode_t
Return codes indicating the result of the module call.
static void dhcpv4_queue_resume(bool sent, void *rctx)
uint32_t max_packet_size
Maximum packet size.
fr_dict_attr_autoload_t rlm_dhcpv4_dict_attr[]
static fr_dict_attr_t const * attr_packet_type
static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Send packets outbound.
static fr_dict_attr_t const * attr_net_dst_port
static fr_dict_t const * dict_freeradius
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Bootstrap the module.
static fr_dict_attr_t const * attr_gateway_ip_address
static fr_dict_t const * dict_dhcpv4
uint8_t * buffer
for encoding packets
uint32_t buffer_size
Maximum packet size.
static unlang_action_t dhcpv4_resume(rlm_rcode_t *p_result, module_ctx_t const *mctx, UNUSED request_t *request)
fr_dict_autoload_t rlm_dhcpv4_dict[]
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
Instantiate thread data for the submodule.
fr_udp_queue_config_t config
UDP queue config.
static fr_dict_attr_t const * attr_net_dst_ip
static fr_dict_attr_t const * attr_transaction_id
static const conf_parser_t module_config[]
fr_udp_queue_t * uq
udp queue handler
static fr_dict_attr_t const * attr_message_type
#define MODULE_NAME_TERMINATOR
unlang_action_t unlang_module_yield(request_t *request, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
if(!subtype_vp) goto fail
eap_aka_sim_process_conf_t * inst
Stores an attribute, a value and various bits of other data.
int fr_udp_queue_write(TALLOC_CTX *ctx, fr_udp_queue_t *uq, uint8_t const *packet, size_t packet_len, fr_ipaddr_t const *ipaddr, int port, void *rctx)
Write packet to socket, OR enqueue it if we get EAGAIN.
fr_udp_queue_t * fr_udp_queue_alloc(TALLOC_CTX *ctx, fr_udp_queue_config_t const *config, fr_event_list_t *el, fr_udp_queue_resume_t resume)
Allocate an outbound UDP queue.
#define FR_PROTO_HEX_DUMP(_data, _data_len, _fmt,...)
char const * fr_strerror(void)
Get the last library error.