The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
base.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: 67074ddc4138157206a95797c25763bb66ec2315 $
19 * @file src/process/arp/base.c
20 * @brief ARP processing.
21 *
22 * @copyright 2020 Network RADIUS SAS (legal@networkradius.com)
23 */
24#include <freeradius-devel/server/protocol.h>
25#include <freeradius-devel/util/debug.h>
26#include <freeradius-devel/arp/arp.h>
27
28static fr_dict_t const *dict_arp;
29
32 { .out = &dict_arp, .proto = "arp" },
33 { NULL }
34};
35
37
40 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_arp},
41 { NULL }
42};
43
54
60
61#define PROCESS_PACKET_TYPE fr_arp_packet_code_t
62#define PROCESS_CODE_MAX FR_ARP_CODE_MAX
63#define PROCESS_CODE_DO_NOT_RESPOND FR_ARP_DO_NOT_RESPOND
64#define PROCESS_PACKET_CODE_VALID FR_ARP_PACKET_CODE_VALID
65#define PROCESS_INST process_arp_t
66#include <freeradius-devel/server/process.h>
67
68static fr_process_state_t const process_state[] = {
69 [ FR_ARP_REQUEST ] = {
70 .packet_type = {
74
81 },
82 .rcode = RLM_MODULE_NOOP,
83 .recv = recv_generic,
84 .resume = resume_recv_generic,
85 .section_offset = PROCESS_CONF_OFFSET(request),
86 },
87 [ FR_ARP_REPLY ] = {
88 .packet_type = {
92
99 },
100 .rcode = RLM_MODULE_NOOP,
101 .send = send_generic,
102 .resume = resume_send_generic,
103 .section_offset = PROCESS_CONF_OFFSET(reply),
104 },
105
107 .packet_type = {
111
118 },
119 .rcode = RLM_MODULE_NOOP,
120 .recv = recv_generic,
121 .resume = resume_recv_generic,
122 .section_offset = PROCESS_CONF_OFFSET(reverse_request),
123 },
125 .packet_type = {
129
136 },
137 .rcode = RLM_MODULE_NOOP,
138 .send = send_generic,
139 .resume = resume_send_generic,
140 .section_offset = PROCESS_CONF_OFFSET(reverse_reply),
141 },
142
143 // @todo - recv reply, to look at other replies.
144
146 .packet_type = {
150
157 },
158 .rcode = RLM_MODULE_NOOP,
159 .send = send_generic,
160 .resume = resume_send_generic,
161 .section_offset = PROCESS_CONF_OFFSET(do_not_respond),
162 },
163};
164
165/*
166 * Debug the packet if requested.
167 */
168static void arp_packet_debug(request_t *request, fr_packet_t const *packet, fr_pair_list_t const *list, bool received)
169{
170 if (!packet) return;
171 if (!RDEBUG_ENABLED) return;
172
173 log_request(L_DBG, L_DBG_LVL_1, request, __FILE__, __LINE__, "%s %s",
174 received ? "Received" : "Sending",
175 fr_arp_packet_codes[packet->code]);
176
177 if (received || request->parent) {
178 log_request_pair_list(L_DBG_LVL_1, request, NULL, list, NULL);
179 } else {
180 log_request_proto_pair_list(L_DBG_LVL_1, request, NULL, list, NULL);
181 }
182}
183
184static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
185{
186 fr_process_state_t const *state;
187
189
191 fr_assert(PROCESS_PACKET_CODE_VALID(request->packet->code));
192
193 request->component = "arp";
194 request->module = NULL;
195 fr_assert(request->proto_dict == dict_arp);
196
197 UPDATE_STATE(packet);
198
199 if (!state->recv) {
200 REDEBUG("Invalid packet type (%u)", request->packet->code);
202 }
203
204 arp_packet_debug(request, request->packet, &request->request_pairs, true);
205
206 return state->recv(p_result, mctx, request);
207}
208
209
211 {
212 .section = SECTION_NAME("recv", "Request"),
213 .actions = &mod_actions_postauth,
214 .offset = PROCESS_CONF_OFFSET(request),
215 },
216 {
217 .section = SECTION_NAME("send", "Reply"),
219 .offset = PROCESS_CONF_OFFSET(reply),
220 },
221 { /* we can listen for others ARP replies, too */
222 .section = SECTION_NAME("recv", "Reply"),
224 .offset = PROCESS_CONF_OFFSET(recv_reply),
225 },
226 {
227 .section = SECTION_NAME("recv", "Reverse-Request"),
229 .offset = PROCESS_CONF_OFFSET(reverse_request),
230 },
231 {
232 .section = SECTION_NAME("send", "Reverse-Reply"),
234 .offset = PROCESS_CONF_OFFSET(reverse_reply),
235 },
236 {
237 .section = SECTION_NAME("send", "Do-Not-Respond"),
239 .offset = PROCESS_CONF_OFFSET(do_not_respond),
240 },
242};
243
244
247 .common = {
248 .magic = MODULE_MAGIC_INIT,
249 .name = "arp",
250 .inst_size = sizeof(process_arp_t)
251 },
252 .process = mod_process,
253 .compile_list = compile_list,
254 .dict = &dict_arp,
255 .packet_type = &attr_packet_type
256};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ FR_ARP_REVERSE_REQUEST
Definition arp.h:67
@ FR_ARP_REQUEST
Definition arp.h:65
@ FR_ARP_DO_NOT_RESPOND
Definition arp.h:70
@ FR_ARP_REVERSE_REPLY
Definition arp.h:68
@ FR_ARP_REPLY
Definition arp.h:66
char const * fr_arp_packet_codes[FR_ARP_CODE_MAX]
Definition base.c:63
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:273
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:286
Specifies an attribute which must be present for the module to function.
Definition dict.h:272
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:285
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
fr_dict_attr_t const * attr_packet_type
Definition base.c:93
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.
Definition log.c:852
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.
Definition log.c:610
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.
Definition log.c:828
@ L_DBG_LVL_1
Highest priority debug messages (-x).
Definition log.h:70
@ L_DBG
Only displayed when debugging is enabled.
Definition log.h:59
@ FR_TYPE_UINT32
32 Bit unsigned integer.
unlang_mod_actions_t const mod_actions_postauth
Definition mod_action.c:92
unlang_mod_action_t actions[RLM_MODULE_NUMCODES]
Definition mod_action.h:62
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
bool test
Definition base.c:56
static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition base.c:184
uint64_t nothing
Definition base.c:45
process_arp_sections_t sections
Definition base.c:58
CONF_SECTION * request
Definition base.c:47
CONF_SECTION * reverse_reply
Definition base.c:51
static void arp_packet_debug(request_t *request, fr_packet_t const *packet, fr_pair_list_t const *list, bool received)
Definition base.c:168
fr_dict_autoload_t process_arp_dict[]
Definition base.c:31
fr_dict_attr_autoload_t process_arp_dict_attr[]
Definition base.c:39
static const virtual_server_compile_t compile_list[]
Definition base.c:210
CONF_SECTION * reply
Definition base.c:48
static fr_process_state_t const process_state[]
Definition base.c:68
CONF_SECTION * recv_reply
Definition base.c:49
static fr_dict_t const * dict_arp
Definition base.c:28
CONF_SECTION * reverse_request
Definition base.c:50
fr_process_module_t process_arp
Definition base.c:246
#define PROCESS_PACKET_CODE_VALID
Definition base.c:64
CONF_SECTION * do_not_respond
Definition base.c:52
#define PROCESS_TRACE
Trace each state function as it's entered.
Definition process.h:66
module_t common
Common fields for all loadable modules.
Definition process.h:55
Common public symbol definition for all process modules.
Definition process.h:54
#define fr_assert(_expr)
Definition rad_assert.h:38
#define REDEBUG(fmt,...)
Definition radclient.h:52
#define RDEBUG_ENABLED()
Definition radclient.h:49
#define RETURN_MODULE_FAIL
Definition rcode.h:57
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:45
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:43
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:42
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
Definition rcode.h:46
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:41
@ RLM_MODULE_TIMEOUT
Module (or section) timed out.
Definition rcode.h:50
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:47
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:49
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:48
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:40
size_t inst_size
Size of the module's instance data.
Definition module.h:204
void * data
Module's instance data.
Definition module.h:272
#define talloc_get_type_abort_const
Definition talloc.h:287
unsigned int code
Packet code (type).
Definition packet.h:61
section_name_t const * section
Identifier for the section.
#define COMPILE_TERMINATOR
Processing sections which are allowed in this virtual server.