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: f1bc54719b4891753f43cb3f2e35c6c3a63b9578 $
19 * @file src/process/test/base.c
20 * @brief Test state machine, which only does request and reply.
21 *
22 * @copyright 2020 Network RADIUS SAS (legal@networkradius.com)
23 */
24#include <freeradius-devel/server/protocol.h>
25#include <freeradius-devel/unlang/interpret.h>
26#include <freeradius-devel/util/debug.h>
27
28static fr_dict_t const *dict_test;
29
32 { .out = &dict_test, .proto = "test" },
33 { NULL }
34};
35
37
40 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_test},
41 { NULL }
42};
43
44typedef struct {
45 uint64_t nothing; // so that the next field isn't at offset 0
46
50
56
62#define FR_TEST_CODE_MAX (2)
63
64#define FR_TEST_PACKET_CODE_VALID(_code) ((_code == FR_TEST_REQUEST) || (_code == FR_TEST_REPLY))
65
66#define PROCESS_PACKET_TYPE fr_test_packet_code_t
67#define PROCESS_CODE_MAX FR_TEST_CODE_MAX
68#define PROCESS_PACKET_CODE_VALID FR_TEST_PACKET_CODE_VALID
69#define PROCESS_INST process_test_t
70#include <freeradius-devel/server/process.h>
71
72static fr_process_state_t const process_state[] = {
73 [ FR_TEST_REQUEST ] = {
74 .default_reply = FR_TEST_REPLY,
75 .default_rcode = RLM_MODULE_NOOP,
76 .recv = recv_generic,
77 .resume = resume_recv_generic,
78 .section_offset = offsetof(process_test_sections_t, recv_request),
79 },
80 [ FR_TEST_REPLY ] = {
81 .default_reply = FR_TEST_REPLY,
82 .default_rcode = RLM_MODULE_NOOP,
83 .result_rcode = RLM_MODULE_OK,
84 .send = send_generic,
85 .resume = resume_send_generic,
86 .section_offset = offsetof(process_test_sections_t, send_reply),
87 },
88};
89
90static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
91{
92 fr_process_state_t const *state;
93
95
97 fr_assert(PROCESS_PACKET_CODE_VALID(request->packet->code));
98
99 request->component = "test";
100 request->module = NULL;
101 fr_assert(request->proto_dict == dict_test);
102
103 UPDATE_STATE(packet);
104
105 return state->recv(p_result, mctx, request);
106}
107
109 {
110 .section = SECTION_NAME("recv", "Request"),
111 .actions = &mod_actions_postauth,
112 .offset = PROCESS_CONF_OFFSET(recv_request),
113 },
114 {
115 .section = SECTION_NAME("send", "Reply"),
118 },
119
121};
122
123
126 .common = {
127 .magic = MODULE_MAGIC_INIT,
128 .name = "test",
130 MODULE_RCTX(process_rctx_t)
131 },
132 .process = mod_process,
133 .compile_list = compile_list,
134 .dict = &dict_test,
135};
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: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
@ 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
static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition base.c:188
static const virtual_server_compile_t compile_list[]
Definition base.c:214
static fr_process_state_t const process_state[]
Definition base.c:69
#define PROCESS_PACKET_CODE_VALID
Definition base.c:65
bool test
Definition base.c:52
fr_dict_autoload_t process_test_dict[]
Definition base.c:31
static fr_dict_t const * dict_test
Definition base.c:28
fr_process_module_t process_test
Definition base.c:125
CONF_SECTION * recv_request
Definition base.c:47
CONF_SECTION * send_reply
Definition base.c:48
fr_test_packet_code_t
Definition base.c:57
@ FR_TEST_REQUEST
Definition base.c:59
@ FR_TEST_REPLY
Definition base.c:60
@ FR_TEST_INVALID
Definition base.c:58
fr_dict_attr_autoload_t process_test_dict_attr[]
Definition base.c:39
process_test_sections_t sections
Definition base.c:54
#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
static void send_reply(int sockfd, fr_channel_data_t *reply)
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:43
@ 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
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
section_name_t const * section
Identifier for the section.
#define COMPILE_TERMINATOR
Processing sections which are allowed in this virtual server.