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>
61#ifdef WITH_IFINDEX_NAME_RESOLUTION
62 char if_name[IFNAMSIZ];
69#ifdef WITH_IFINDEX_NAME_RESOLUTION
73 received ?
"Received" :
"Sending",
76 packet->
socket.inet.src_ipaddr.
af == AF_INET6 ?
"[" :
"",
78 packet->
socket.inet.src_ipaddr.
af == AF_INET6 ?
"]" :
"",
79 packet->
socket.inet.src_port,
80 packet->
socket.inet.dst_ipaddr.
af == AF_INET6 ?
"[" :
"",
82 packet->
socket.inet.dst_ipaddr.
af == AF_INET6 ?
"]" :
"",
83 packet->
socket.inet.dst_port
84#ifdef WITH_IFINDEX_NAME_RESOLUTION
85 , packet->
socket.inet.ifindex ?
"via " :
"",
86 packet->
socket.inet.ifindex ? fr_ifname_from_ifindex(if_name, packet->
socket.inet.ifindex) :
"",
87 packet->
socket.inet.ifindex ?
" " :
""
91 if (received || request->parent) {
125#define FR_DHCP_PROCESS_CODE_VALID(_x) (FR_DHCP_PACKET_CODE_VALID(_x) || (_x == FR_DHCP_DO_NOT_RESPOND))
127#define PROCESS_PACKET_TYPE fr_dhcpv4_packet_code_t
128#define PROCESS_CODE_MAX FR_DHCP_CODE_MAX
129#define PROCESS_CODE_DO_NOT_RESPOND FR_DHCP_DO_NOT_RESPOND
130#define PROCESS_PACKET_CODE_VALID FR_DHCP_PROCESS_CODE_VALID
131#define PROCESS_INST process_dhcpv4_t
132#define PROCESS_CODE_DYNAMIC_CLIENT FR_DHCP_ACK
133#include <freeradius-devel/server/process.h>
141 REDEBUG(
"%s packet does not have YIADDR. The client will not receive an IP address.",
159 return CALL_RESUME(send_generic);
178 .recv = recv_generic,
179 .resume = resume_recv_generic,
180 .section_offset = PROCESS_CONF_OFFSET(discover),
197 .send = send_generic,
198 .resume = resume_check_offer_ack_options,
199 .section_offset = PROCESS_CONF_OFFSET(offer),
217 .recv = recv_generic,
218 .resume = resume_recv_generic,
219 .section_offset = PROCESS_CONF_OFFSET(request),
236 .recv = recv_generic,
237 .resume = resume_recv_generic,
238 .section_offset = PROCESS_CONF_OFFSET(request),
256 .send = send_generic,
257 .resume = resume_check_offer_ack_options,
258 .section_offset = PROCESS_CONF_OFFSET(ack),
275 .send = send_generic,
276 .resume = resume_send_generic,
277 .section_offset = PROCESS_CONF_OFFSET(nak),
295 .recv = recv_generic,
296 .resume = resume_recv_generic,
297 .section_offset = PROCESS_CONF_OFFSET(inform),
315 .recv = recv_generic,
316 .resume = resume_recv_generic,
317 .section_offset = PROCESS_CONF_OFFSET(release),
335 .recv = recv_generic,
336 .resume = resume_recv_generic,
337 .section_offset = PROCESS_CONF_OFFSET(lease_query),
355 .send = send_generic,
356 .resume = resume_send_generic,
357 .section_offset = PROCESS_CONF_OFFSET(lease_unassigned),
375 .send = send_generic,
376 .resume = resume_send_generic,
377 .section_offset = PROCESS_CONF_OFFSET(lease_unknown),
395 .send = send_generic,
396 .resume = resume_send_generic,
397 .section_offset = PROCESS_CONF_OFFSET(lease_active),
415 .send = send_generic,
416 .resume = resume_send_generic,
417 .section_offset = PROCESS_CONF_OFFSET(do_not_respond),
423 fr_process_state_t
const *state;
430 request->component =
"dhcpv4";
431 request->module = NULL;
434 UPDATE_STATE(packet);
437 REDEBUG(
"Invalid packet type (%u)", request->packet->code);
444 return new_client(p_result, mctx, request);
447 return state->recv(p_result, mctx, request);
459 .offset = PROCESS_CONF_OFFSET(discover),
464 .offset = PROCESS_CONF_OFFSET(offer),
474 .offset = PROCESS_CONF_OFFSET(request),
480 .offset = PROCESS_CONF_OFFSET(ack),
485 .offset = PROCESS_CONF_OFFSET(nak),
495 .offset = PROCESS_CONF_OFFSET(decline),
506 .offset = PROCESS_CONF_OFFSET(release),
511 .offset = PROCESS_CONF_OFFSET(inform),
517 .offset = PROCESS_CONF_OFFSET(lease_query),
522 .offset = PROCESS_CONF_OFFSET(lease_unassigned),
527 .offset = PROCESS_CONF_OFFSET(lease_unknown),
532 .offset = PROCESS_CONF_OFFSET(lease_active),
538 .offset = PROCESS_CONF_OFFSET(do_not_respond),
541 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_TLV
Contains nested attributes.
@ 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
int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
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
static fr_dict_attr_t const * attr_dhcp_option_82
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_TIMEOUT
Module (or section) timed out.
@ 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.
#define pair_update_reply(_attr, _da)
Return or allocate a fr_pair_t in the reply list.
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)
section_name_t const * section
Identifier for the section.
#define COMPILE_TERMINATOR
Processing sections which are allowed in this virtual server.