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: 52df43ab61f19a1921625b316a167c02b06902c5 $
19 * @file src/process/vmps/base.c
20 * @brief VMPS processing.
21 *
22 * @copyright 2018 The Freeradius server project.
23 * @copyright 2018 Alan DeKok (aland@deployingradius.com)
24 */
25#include <freeradius-devel/io/application.h>
26#include <freeradius-devel/server/protocol.h>
27#include <freeradius-devel/util/dict.h>
28#include <freeradius-devel/util/debug.h>
29#include <freeradius-devel/vmps/vmps.h>
30
31#include <freeradius-devel/protocol/vmps/vmps.h>
32
33static fr_dict_t const *dict_vmps;
34
37 { .out = &dict_vmps, .proto = "vmps" },
38 { NULL }
39};
40
42
45 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_vmps },
46 { NULL }
47};
48
58
62
63#define PROCESS_PACKET_TYPE fr_vmps_packet_code_t
64#define PROCESS_CODE_MAX FR_VMPS_CODE_MAX
65#define PROCESS_CODE_DO_NOT_RESPOND FR_VMPS_DO_NOT_RESPOND
66#define PROCESS_PACKET_CODE_VALID FR_VMPS_PACKET_CODE_VALID
67#define PROCESS_INST process_vmps_t
68#include <freeradius-devel/server/process.h>
69
70static fr_process_state_t const process_state[] = {
71 [FR_PACKET_TYPE_VALUE_JOIN_REQUEST] = {
72 .packet_type = {
73 [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_JOIN_RESPONSE,
74 [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_JOIN_RESPONSE,
75 [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_JOIN_RESPONSE,
76
77 [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
78 [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
79 [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
80 [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
81 [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
82 [RLM_MODULE_TIMEOUT] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND
83 },
84 .rcode = RLM_MODULE_NOOP,
85 .recv = recv_generic,
86 .resume = resume_recv_generic,
87 .section_offset = PROCESS_CONF_OFFSET(join_request),
88 },
89 [FR_PACKET_TYPE_VALUE_JOIN_RESPONSE] = {
90 .packet_type = {
91 [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_JOIN_RESPONSE,
92 [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_JOIN_RESPONSE,
93 [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_JOIN_RESPONSE,
94
95 [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
96 [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
97 [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
98 [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
99 [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
100 [RLM_MODULE_TIMEOUT] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND
101 },
102 .rcode = RLM_MODULE_NOOP,
103 .send = send_generic,
104 .resume = resume_send_generic,
105 .section_offset = PROCESS_CONF_OFFSET(join_response),
106 },
107
108 [FR_PACKET_TYPE_VALUE_RECONFIRM_REQUEST] = {
109 .packet_type = {
110 [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_RECONFIRM_RESPONSE,
111 [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_RECONFIRM_RESPONSE,
112 [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_RECONFIRM_RESPONSE,
113
114 [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
115 [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
116 [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
117 [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
118 [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
119 [RLM_MODULE_TIMEOUT] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND
120 },
121 .rcode = RLM_MODULE_NOOP,
122 .recv = recv_generic,
123 .resume = resume_recv_generic,
124 .section_offset = PROCESS_CONF_OFFSET(reconfirm_request),
125 },
126 [FR_PACKET_TYPE_VALUE_RECONFIRM_RESPONSE] = {
127 .packet_type = {
128 [RLM_MODULE_OK] = FR_PACKET_TYPE_VALUE_RECONFIRM_RESPONSE,
129 [RLM_MODULE_NOOP] = FR_PACKET_TYPE_VALUE_RECONFIRM_RESPONSE,
130 [RLM_MODULE_UPDATED] = FR_PACKET_TYPE_VALUE_RECONFIRM_RESPONSE,
131
132 [RLM_MODULE_REJECT] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
133 [RLM_MODULE_FAIL] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
134 [RLM_MODULE_INVALID] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
135 [RLM_MODULE_DISALLOW] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
136 [RLM_MODULE_NOTFOUND] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND,
137 [RLM_MODULE_TIMEOUT] = FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND
138 },
139 .rcode = RLM_MODULE_NOOP,
140 .send = send_generic,
141 .resume = resume_send_generic,
142 .section_offset = PROCESS_CONF_OFFSET(reconfirm_response),
143 },
144
146 .packet_type = {
151
158 },
159 .rcode = RLM_MODULE_NOOP,
160 .send = send_generic,
161 .resume = resume_send_generic,
162 .section_offset = PROCESS_CONF_OFFSET(do_not_respond),
163 },
164};
165
166
167/*
168 * Debug the packet if requested.
169 */
170static void vmps_packet_debug(request_t *request, fr_packet_t const *packet, fr_pair_list_t const *list, bool received)
171{
172#ifdef WITH_IFINDEX_NAME_RESOLUTION
173 char if_name[IFNAMSIZ];
174#endif
175
176 if (!packet) return;
177 if (!RDEBUG_ENABLED) return;
178
179 log_request(L_DBG, L_DBG_LVL_1, request, __FILE__, __LINE__, "%s %s XID %08x from %s%pV%s:%i to %s%pV%s:%i "
180#ifdef WITH_IFINDEX_NAME_RESOLUTION
181 "%s%s%s"
182#endif
183 "",
184 received ? "Received" : "Sending",
185 fr_vmps_packet_names[packet->code],
186 packet->id,
187 packet->socket.inet.src_ipaddr.af == AF_INET6 ? "[" : "",
188 fr_box_ipaddr(packet->socket.inet.src_ipaddr),
189 packet->socket.inet.src_ipaddr.af == AF_INET6 ? "]" : "",
190 packet->socket.inet.src_port,
191 packet->socket.inet.dst_ipaddr.af == AF_INET6 ? "[" : "",
192 fr_box_ipaddr(packet->socket.inet.dst_ipaddr),
193 packet->socket.inet.dst_ipaddr.af == AF_INET6 ? "]" : "",
194 packet->socket.inet.dst_port
195#ifdef WITH_IFINDEX_NAME_RESOLUTION
196 , packet->socket.inet.ifindex ? "via " : "",
197 packet->socket.inet.ifindex ? fr_ifname_from_ifindex(if_name, packet->socket.inet.ifindex) : "",
198 packet->socket.inet.ifindex ? " " : ""
199#endif
200 );
201
202 if (received || request->parent) {
203 log_request_pair_list(L_DBG_LVL_1, request, NULL, list, NULL);
204 } else {
205 log_request_proto_pair_list(L_DBG_LVL_1, request, NULL, list, NULL);
206 }
207}
208
209static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
210{
211 fr_process_state_t const *state;
212
214
216 fr_assert(PROCESS_PACKET_CODE_VALID(request->packet->code));
217
218 request->component = "vmps";
219 request->module = NULL;
220 fr_assert(request->proto_dict == dict_vmps);
221
222 UPDATE_STATE(packet);
223
224 if (!state->recv) {
225 REDEBUG("Invalid packet type (%u)", request->packet->code);
227 }
228
229 vmps_packet_debug(request, request->packet, &request->request_pairs, true);
230
231 return state->recv(p_result, mctx, request);
232}
233
235 {
236 .section = SECTION_NAME("recv", "Join-Request"),
237 .actions = &mod_actions_authorize,
238 .offset = PROCESS_CONF_OFFSET(join_request),
239 },
240 {
241 .section = SECTION_NAME("send", "Join-Response"),
243 .offset = PROCESS_CONF_OFFSET(join_response),
244 },
245 {
246 .section = SECTION_NAME("recv", "Reconfirm-Request"),
248 .offset = PROCESS_CONF_OFFSET(reconfirm_request),
249 },
250 {
251 .section = SECTION_NAME("send", "Reconfirm-Response"),
253 .offset = PROCESS_CONF_OFFSET(reconfirm_response),
254 },
255 {
256 .section = SECTION_NAME("send", "Do-Not-Respond"),
258 .offset = PROCESS_CONF_OFFSET(do_not_respond),
259 },
260
262};
263
264
267 .common = {
268 .magic = MODULE_MAGIC_INIT,
269 .name = "vmps",
270 .inst_size = sizeof(process_vmps_t)
271 },
272 .process = mod_process,
273 .compile_list = compile_list,
274 .dict = &dict_vmps,
275 .packet_type = &attr_packet_type
276};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
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_authorize
Definition mod_action.c:45
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
static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition base.c:184
static const virtual_server_compile_t compile_list[]
Definition base.c:210
static fr_process_state_t const process_state[]
Definition base.c:68
#define PROCESS_PACKET_CODE_VALID
Definition base.c:64
CONF_SECTION * do_not_respond
Definition base.c:56
CONF_SECTION * reconfirm_response
Definition base.c:55
fr_dict_autoload_t process_vmps_dict[]
Definition base.c:36
static void vmps_packet_debug(request_t *request, fr_packet_t const *packet, fr_pair_list_t const *list, bool received)
Definition base.c:170
process_vmps_sections_t sections
Definition base.c:60
fr_process_module_t process_vmps
Definition base.c:266
fr_dict_attr_autoload_t process_vmps_dict_attr[]
Definition base.c:44
CONF_SECTION * reconfirm_request
Definition base.c:54
CONF_SECTION * join_request
Definition base.c:52
CONF_SECTION * join_response
Definition base.c:53
static fr_dict_t const * dict_vmps
Definition base.c:33
#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
@ 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
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
fr_socket_t socket
This packet was received on.
Definition packet.h:57
int id
Packet ID (used to link requests/responses).
Definition packet.h:60
int af
AF_INET, AF_INET6, or AF_UNIX.
Definition socket.h:78
#define fr_box_ipaddr(_val)
Definition value.h:313
section_name_t const * section
Identifier for the section.
#define COMPILE_TERMINATOR
Processing sections which are allowed in this virtual server.
char const * fr_vmps_packet_names[FR_VMPS_CODE_MAX]
Definition vmps.c:75
@ FR_VMPS_DO_NOT_RESPOND
Definition vmps.h:55