25#define LOG_PREFIX "process_dhcpv4"
27#include <freeradius-devel/io/application.h>
28#include <freeradius-devel/server/protocol.h>
29#include <freeradius-devel/server/module_method.h>
30#include <freeradius-devel/util/dict.h>
31#include <freeradius-devel/util/debug.h>
32#include <freeradius-devel/dhcpv4/dhcpv4.h>
59#ifdef WITH_IFINDEX_NAME_RESOLUTION
60 char if_name[IFNAMSIZ];
67#ifdef WITH_IFINDEX_NAME_RESOLUTION
71 received ?
"Received" :
"Sending",
74 packet->
socket.inet.src_ipaddr.
af == AF_INET6 ?
"[" :
"",
76 packet->
socket.inet.src_ipaddr.
af == AF_INET6 ?
"]" :
"",
77 packet->
socket.inet.src_port,
78 packet->
socket.inet.dst_ipaddr.
af == AF_INET6 ?
"[" :
"",
80 packet->
socket.inet.dst_ipaddr.
af == AF_INET6 ?
"]" :
"",
81 packet->
socket.inet.dst_port
82#ifdef WITH_IFINDEX_NAME_RESOLUTION
83 , packet->
socket.inet.ifindex ?
"via " :
"",
84 packet->
socket.inet.ifindex ? fr_ifname_from_ifindex(if_name, packet->
socket.inet.ifindex) :
"",
85 packet->
socket.inet.ifindex ?
" " :
""
89 if (received || request->parent) {
123#define FR_DHCP_PROCESS_CODE_VALID(_x) (FR_DHCP_PACKET_CODE_VALID(_x) || (_x == FR_DHCP_DO_NOT_RESPOND))
125#define PROCESS_PACKET_TYPE fr_dhcpv4_packet_code_t
126#define PROCESS_CODE_MAX FR_DHCP_CODE_MAX
127#define PROCESS_CODE_DO_NOT_RESPOND FR_DHCP_DO_NOT_RESPOND
128#define PROCESS_PACKET_CODE_VALID FR_DHCP_PROCESS_CODE_VALID
129#define PROCESS_INST process_dhcpv4_t
130#define PROCESS_CODE_DYNAMIC_CLIENT FR_DHCP_ACK
131#include <freeradius-devel/server/process.h>
139 REDEBUG(
"%s packet does not have YIADDR. The client will not receive an IP address.",
143 return CALL_RESUME(send_generic);
161 .recv = recv_generic,
162 .resume = resume_recv_generic,
163 .section_offset = PROCESS_CONF_OFFSET(discover),
179 .send = send_generic,
180 .resume = resume_check_yiaddr,
181 .section_offset = PROCESS_CONF_OFFSET(offer),
198 .recv = recv_generic,
199 .resume = resume_recv_generic,
200 .section_offset = PROCESS_CONF_OFFSET(request),
216 .recv = recv_generic,
217 .resume = resume_recv_generic,
218 .section_offset = PROCESS_CONF_OFFSET(request),
235 .send = send_generic,
236 .resume = resume_check_yiaddr,
237 .section_offset = PROCESS_CONF_OFFSET(ack),
253 .send = send_generic,
254 .resume = resume_send_generic,
255 .section_offset = PROCESS_CONF_OFFSET(nak),
272 .recv = recv_generic,
273 .resume = resume_recv_generic,
274 .section_offset = PROCESS_CONF_OFFSET(inform),
291 .recv = recv_generic,
292 .resume = resume_recv_generic,
293 .section_offset = PROCESS_CONF_OFFSET(release),
310 .recv = recv_generic,
311 .resume = resume_recv_generic,
312 .section_offset = PROCESS_CONF_OFFSET(lease_query),
329 .send = send_generic,
330 .resume = resume_send_generic,
331 .section_offset = PROCESS_CONF_OFFSET(lease_unassigned),
348 .send = send_generic,
349 .resume = resume_send_generic,
350 .section_offset = PROCESS_CONF_OFFSET(lease_unknown),
367 .send = send_generic,
368 .resume = resume_send_generic,
369 .section_offset = PROCESS_CONF_OFFSET(lease_active),
386 .send = send_generic,
387 .resume = resume_send_generic,
388 .section_offset = PROCESS_CONF_OFFSET(do_not_respond),
394 fr_process_state_t
const *state;
401 request->component =
"dhcpv4";
402 request->module = NULL;
405 UPDATE_STATE(packet);
408 REDEBUG(
"Invalid packet type (%u)", request->packet->code);
415 return new_client(p_result, mctx, request);
418 return state->recv(p_result, mctx, request);
430 .offset = PROCESS_CONF_OFFSET(discover),
435 .offset = PROCESS_CONF_OFFSET(offer),
445 .offset = PROCESS_CONF_OFFSET(request),
451 .offset = PROCESS_CONF_OFFSET(ack),
456 .offset = PROCESS_CONF_OFFSET(nak),
466 .offset = PROCESS_CONF_OFFSET(decline),
477 .offset = PROCESS_CONF_OFFSET(release),
482 .offset = PROCESS_CONF_OFFSET(inform),
488 .offset = PROCESS_CONF_OFFSET(lease_query),
493 .offset = PROCESS_CONF_OFFSET(lease_unassigned),
498 .offset = PROCESS_CONF_OFFSET(lease_unknown),
503 .offset = PROCESS_CONF_OFFSET(lease_active),
509 .offset = PROCESS_CONF_OFFSET(do_not_respond),
512 DYNAMIC_CLIENT_SECTIONS,
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
A section grouping multiple CONF_PAIR.
@ FR_DHCP_LEASE_UNASSIGNED
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.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
fr_dict_attr_t const * attr_packet_type
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.
void log_request(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *fmt,...)
Marshal variadic log arguments into a va_list and pass to normal logging functions.
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.
@ L_DBG_LVL_1
Highest priority debug messages (-x).
@ L_DBG
Only displayed when debugging is enabled.
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
unlang_mod_actions_t const mod_actions_postauth
unlang_mod_action_t actions[RLM_MODULE_NUMCODES]
module_instance_t const * mi
Instance of the module being instantiated.
Temporary structure to hold arguments for module calls.
section_name_t module_method_ippool_mark
section_name_t module_method_ippool_extend
section_name_t module_method_ippool_release
section_name_t module_method_ippool_allocate
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.
static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
static const virtual_server_compile_t compile_list[]
static fr_process_state_t const process_state[]
#define PROCESS_PACKET_CODE_VALID
CONF_SECTION * lease_query
CONF_SECTION * lease_unassigned
static void dhcpv4_packet_debug(request_t *request, fr_packet_t *packet, fr_pair_list_t *list, bool received)
CONF_SECTION * do_not_respond
fr_process_module_t process_dhcpv4
static fr_dict_attr_t const * attr_yiaddr
CONF_SECTION * force_renew
CONF_SECTION * new_client
fr_dict_attr_autoload_t process_dhcpv4_dict_attr[]
static fr_dict_t const * dict_dhcpv4
fr_dict_autoload_t process_dhcpv4_dict[]
CONF_SECTION * add_client
CONF_SECTION * lease_active
process_dhcpv4_sections_t sections
CONF_SECTION * deny_client
CONF_SECTION * lease_unknown
static fr_dict_attr_t const * attr_message_type
#define PROCESS_TRACE
Trace each state function as it's entered.
module_t common
Common fields for all loadable modules.
Common public symbol definition for all process modules.
char const * dhcp_message_types[]
#define RETURN_MODULE_FAIL
rlm_rcode_t
Return codes indicating the result of the module call.
@ RLM_MODULE_INVALID
The module considers the request invalid.
@ RLM_MODULE_OK
The module is OK, continue.
@ RLM_MODULE_FAIL
Module failed, don't reply.
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
@ RLM_MODULE_REJECT
Immediately reject the request.
@ RLM_MODULE_NOTFOUND
User not found.
@ RLM_MODULE_UPDATED
OK (pairs modified).
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
#define request_is_dynamic_client(_x)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
size_t inst_size
Size of the module's instance data.
void * data
Module's instance data.
Stores an attribute, a value and various bits of other data.
#define talloc_get_type_abort_const
unsigned int code
Packet code (type).
fr_socket_t socket
This packet was received on.
int id
Packet ID (used to link requests/responses).
int af
AF_INET, AF_INET6, or AF_UNIX.
#define fr_box_ipaddr(_val)
#define COMPILE_TERMINATOR
section_name_t const * section
Identifier for the section.
Processing sections which are allowed in this virtual server.