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: f4793ccc83e38fc74cffb181ace7151704e5a616 $
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  .section = SECTION_NAME("recv", "Request"),
109  .actions = &mod_actions_postauth,
110  .offset = PROCESS_CONF_OFFSET(recv_request),
111  },
112  {
113  .section = SECTION_NAME("send", "Reply"),
114  .actions = &mod_actions_postauth,
115  .offset = PROCESS_CONF_OFFSET(send_reply),
116  },
117 
119 };
120 
121 
124  .common = {
125  .magic = MODULE_MAGIC_INIT,
126  .name = "test",
127  .inst_size = sizeof(process_test_t),
128  },
129  .process = mod_process,
130  .compile_list = compile_list,
131  .dict = &dict_test,
132 };
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:267
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition: dict.h:280
Specifies an attribute which must be present for the module to function.
Definition: dict.h:266
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition: dict.h:279
#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:91
@ FR_TYPE_UINT32
32 Bit unsigned integer.
Definition: merged_model.c:99
unlang_mod_actions_t const mod_actions_postauth
Definition: mod_action.c:88
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: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:123
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
#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:271
fr_assert(0)
#define talloc_get_type_abort_const
Definition: talloc.h:282
#define COMPILE_TERMINATOR
section_name_t const * section
Identifier for the section.
Processing sections which are allowed in this virtual server.