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: 0a24728fb710e77e157654309cd67e7c8f17ac1e $
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#include <freeradius-devel/unlang/interpret.h>
28
29static fr_dict_t const *dict_arp;
30
33 { .out = &dict_arp, .proto = "arp" },
34 { NULL }
35};
36
38
41 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_arp},
42 { NULL }
43};
44
55
61
62#define PROCESS_PACKET_TYPE fr_arp_packet_code_t
63#define PROCESS_CODE_MAX FR_ARP_CODE_MAX
64#define PROCESS_CODE_DO_NOT_RESPOND FR_ARP_DO_NOT_RESPOND
65#define PROCESS_PACKET_CODE_VALID FR_ARP_PACKET_CODE_VALID
66#define PROCESS_INST process_arp_t
67#include <freeradius-devel/server/process.h>
68
69static fr_process_state_t const process_state[] = {
70 [ FR_ARP_REQUEST ] = {
71 .packet_type = {
75
82 },
83 .default_rcode = RLM_MODULE_NOOP,
84 .recv = recv_generic,
85 .resume = resume_recv_generic,
86 .section_offset = PROCESS_CONF_OFFSET(request),
87 },
88 [ FR_ARP_REPLY ] = {
89 .packet_type = {
93
100 },
101 .default_rcode = RLM_MODULE_NOOP,
102 .result_rcode = RLM_MODULE_OK,
103 .send = send_generic,
104 .resume = resume_send_generic,
105 .section_offset = PROCESS_CONF_OFFSET(reply),
106 },
107
109 .packet_type = {
113
120 },
121 .default_rcode = RLM_MODULE_NOOP,
122 .recv = recv_generic,
123 .resume = resume_recv_generic,
124 .section_offset = PROCESS_CONF_OFFSET(reverse_request),
125 },
127 .packet_type = {
131
138 },
139 .default_rcode = RLM_MODULE_NOOP,
140 .result_rcode = RLM_MODULE_OK,
141 .send = send_generic,
142 .resume = resume_send_generic,
143 .section_offset = PROCESS_CONF_OFFSET(reverse_reply),
144 },
145
146 // @todo - recv reply, to look at other replies.
147
149 .packet_type = {
153
160 },
161 .default_rcode = RLM_MODULE_NOOP,
162 .result_rcode = RLM_MODULE_HANDLED,
163 .send = send_generic,
164 .resume = resume_send_generic,
165 .section_offset = PROCESS_CONF_OFFSET(do_not_respond),
166 },
167};
168
169/*
170 * Debug the packet if requested.
171 */
172static void arp_packet_debug(request_t *request, fr_packet_t const *packet, fr_pair_list_t const *list, bool received)
173{
174 if (!packet) return;
175 if (!RDEBUG_ENABLED) return;
176
177 log_request(L_DBG, L_DBG_LVL_1, request, __FILE__, __LINE__, "%s %s",
178 received ? "Received" : "Sending",
179 fr_arp_packet_codes[packet->code]);
180
181 if (received || request->parent) {
182 log_request_pair_list(L_DBG_LVL_1, request, NULL, list, NULL);
183 } else {
184 log_request_proto_pair_list(L_DBG_LVL_1, request, NULL, list, NULL);
185 }
186}
187
188static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
189{
190 fr_process_state_t const *state;
191
193
195 fr_assert(PROCESS_PACKET_CODE_VALID(request->packet->code));
196
197 request->component = "arp";
198 request->module = NULL;
199 fr_assert(request->proto_dict == dict_arp);
200
201 UPDATE_STATE(packet);
202
203 if (!state->recv) {
204 REDEBUG("Invalid packet type (%u)", request->packet->code);
206 }
207
208 arp_packet_debug(request, request->packet, &request->request_pairs, true);
209
210 return state->recv(p_result, mctx, request);
211}
212
213
215 {
216 .section = SECTION_NAME("recv", "Request"),
217 .actions = &mod_actions_postauth,
218 .offset = PROCESS_CONF_OFFSET(request),
219 },
220 {
221 .section = SECTION_NAME("send", "Reply"),
223 .offset = PROCESS_CONF_OFFSET(reply),
224 },
225 { /* we can listen for others ARP replies, too */
226 .section = SECTION_NAME("recv", "Reply"),
228 .offset = PROCESS_CONF_OFFSET(recv_reply),
229 },
230 {
231 .section = SECTION_NAME("recv", "Reverse-Request"),
233 .offset = PROCESS_CONF_OFFSET(reverse_request),
234 },
235 {
236 .section = SECTION_NAME("send", "Reverse-Reply"),
238 .offset = PROCESS_CONF_OFFSET(reverse_reply),
239 },
240 {
241 .section = SECTION_NAME("send", "Do-Not-Respond"),
243 .offset = PROCESS_CONF_OFFSET(do_not_respond),
244 },
246};
247
248
251 .common = {
252 .magic = MODULE_MAGIC_INIT,
253 .name = "arp",
255 MODULE_RCTX(process_rctx_t)
256 },
257 .process = mod_process,
258 .compile_list = compile_list,
259 .dict = &dict_arp,
260 .packet_type = &attr_packet_type
261};
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:274
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:287
Specifies an attribute which must be present for the module to function.
Definition dict.h:273
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:286
#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:93
unlang_mod_action_t actions[RLM_MODULE_NUMCODES]
Definition mod_action.h:64
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:57
uint64_t nothing
Definition base.c:46
process_arp_sections_t sections
Definition base.c:59
CONF_SECTION * request
Definition base.c:48
CONF_SECTION * reverse_reply
Definition base.c:52
static void arp_packet_debug(request_t *request, fr_packet_t const *packet, fr_pair_list_t const *list, bool received)
Definition base.c:172
fr_dict_autoload_t process_arp_dict[]
Definition base.c:32
static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition base.c:188
fr_dict_attr_autoload_t process_arp_dict_attr[]
Definition base.c:40
static const virtual_server_compile_t compile_list[]
Definition base.c:214
CONF_SECTION * reply
Definition base.c:49
static fr_process_state_t const process_state[]
Definition base.c:69
CONF_SECTION * recv_reply
Definition base.c:50
static fr_dict_t const * dict_arp
Definition base.c:29
CONF_SECTION * reverse_request
Definition base.c:51
fr_process_module_t process_arp
Definition base.c:250
#define PROCESS_PACKET_CODE_VALID
Definition base.c:65
CONF_SECTION * do_not_respond
Definition base.c:53
#define PROCESS_TRACE
Trace each state function as it's entered.
Definition process.h:55
#define PROCESS_CONF_OFFSET(_x)
Definition process.h:79
module_t common
Common fields for all loadable modules.
Common public symbol definition for all process modules.
#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_UNLANG_FAIL
Definition rcode.h:57
@ 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
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
Definition rcode.h:44
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:40
void * data
Module's instance data.
Definition module.h:291
#define MODULE_RCTX(_ctype)
Definition module.h:257
#define MODULE_INST(_ctype)
Definition module.h:255
#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.