The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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: 6aa05aaa2b2a06345c991e0d1cd6eb0a210dd9d7 $
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/util/debug.h>
26 
27 static fr_dict_t const *dict_test;
28 
31  { .out = &dict_test, .proto = "test" },
32  { NULL }
33 };
34 
36 
39  { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_test},
40  { NULL }
41 };
42 
43 typedef struct {
44  uint64_t nothing; // so that the next field isn't at offset 0
45 
49 
50 typedef struct {
51  bool test;
52 
55 
56 typedef enum {
61 #define FR_TEST_CODE_MAX (2)
62 
63 #define FR_TEST_PACKET_CODE_VALID(_code) ((_code == FR_TEST_REQUEST) || (_code == FR_TEST_REPLY))
64 
65 #define PROCESS_PACKET_TYPE fr_test_packet_code_t
66 #define PROCESS_CODE_MAX FR_TEST_CODE_MAX
67 #define PROCESS_PACKET_CODE_VALID FR_TEST_PACKET_CODE_VALID
68 #define PROCESS_INST process_test_t
69 #include <freeradius-devel/server/process.h>
70 
71 static fr_process_state_t const process_state[] = {
72  [ FR_TEST_REQUEST ] = {
73  .default_reply = FR_TEST_REPLY,
74  .rcode = RLM_MODULE_NOOP,
75  .recv = recv_generic,
76  .resume = resume_recv_generic,
77  .section_offset = offsetof(process_test_sections_t, recv_request),
78  },
79  [ FR_TEST_REPLY ] = {
80  .default_reply = FR_TEST_REPLY,
81  .rcode = RLM_MODULE_NOOP,
82  .send = send_generic,
83  .resume = resume_send_generic,
84  .section_offset = offsetof(process_test_sections_t, send_reply),
85  },
86 };
87 
88 static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
89 {
90  fr_process_state_t const *state;
91 
93 
95  fr_assert(PROCESS_PACKET_CODE_VALID(request->packet->code));
96 
97  request->component = "test";
98  request->module = NULL;
99  fr_assert(request->dict == dict_test);
100 
101  UPDATE_STATE(packet);
102 
103  return state->recv(p_result, mctx, request);
104 }
105 
107  {
108  .name = "recv",
109  .name2 = "Request",
110  .component = MOD_POST_AUTH,
111  .offset = PROCESS_CONF_OFFSET(recv_request),
112  },
113  {
114  .name = "send",
115  .name2 = "Reply",
116  .component = MOD_POST_AUTH,
117  .offset = PROCESS_CONF_OFFSET(send_reply),
118  },
119 
121 };
122 
123 
126  .common = {
127  .magic = MODULE_MAGIC_INIT,
128  .name = "test",
129  .inst_size = sizeof(process_test_t),
130  },
131  .process = mod_process,
132  .compile_list = compile_list,
133  .dict = &dict_test,
134 };
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:89
@ MOD_POST_AUTH
7 methods index for postauth section.
Definition: components.h:37
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition: dict.h:250
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition: dict.h:263
Specifies an attribute which must be present for the module to function.
Definition: dict.h:249
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition: dict.h:262
void *_CONST data
Module instance's parsed configuration.
Definition: dl_module.h:165
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:65
@ FR_TYPE_UINT32
32 Bit unsigned integer.
Definition: merged_model.c:99
dl_module_inst_t const * inst
Dynamic loader API handle for the module.
Definition: module_ctx.h:42
Temporary structure to hold arguments for module calls.
Definition: module_ctx.h:41
static fr_dict_attr_t const * attr_packet_type
Definition: base.c:35
static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition: base.c:88
bool test
Definition: base.c:51
fr_dict_autoload_t process_test_dict[]
Definition: base.c:30
static fr_dict_t const * dict_test
Definition: base.c:27
fr_process_module_t process_test
Definition: base.c:125
static const virtual_server_compile_t compile_list[]
Definition: base.c:106
CONF_SECTION * recv_request
Definition: base.c:46
uint64_t nothing
Definition: base.c:44
CONF_SECTION * send_reply
Definition: base.c:47
static fr_process_state_t const process_state[]
Definition: base.c:71
fr_test_packet_code_t
Definition: base.c:56
@ FR_TEST_REQUEST
Definition: base.c:58
@ FR_TEST_REPLY
Definition: base.c:59
@ FR_TEST_INVALID
Definition: base.c:57
fr_dict_attr_autoload_t process_test_dict_attr[]
Definition: base.c:38
process_test_sections_t sections
Definition: base.c:53
#define PROCESS_PACKET_CODE_VALID
Definition: base.c:67
#define PROCESS_TRACE
Trace each state function as it's entered.
Definition: process.h:65
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
static void send_reply(int sockfd, fr_channel_data_t *reply)
Definition: radius1_test.c:190
rlm_rcode_t
Return codes indicating the result of the module call.
Definition: rcode.h:40
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition: rcode.h:48
fr_assert(0)
#define talloc_get_type_abort_const
Definition: talloc.h:270
#define COMPILE_TERMINATOR
char const * name
Name of the processing section, such as "recv" or "send".
Processing sections which are allowed in this virtual server.