Skip to content

Commit

Permalink
Rename the initial state field (previously process) to 'entry_point'
Browse files Browse the repository at this point in the history
...to make it clear that it's the entry point to the function based state machines that we're meant to be creating, but seem to have ended up using switch statements instead.
  • Loading branch information
arr2036 committed May 25, 2018
1 parent c75401f commit 58dd62d
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 74 deletions.
12 changes: 6 additions & 6 deletions src/lib/io/application.h
Expand Up @@ -73,7 +73,7 @@ typedef int (*fr_app_open_t)(void *instance, fr_schedule_t *sc, CONF_SECTION *cs
* @param[in] instance of the #fr_app_t.
* @param[in] request To set the next state function for.
*/
typedef void (*fr_app_process_set_t)(void const *instance, REQUEST *request);
typedef void (*fr_app_entry_point_set_t)(void const *instance, REQUEST *request);

/** Set the priority of a packet
*
Expand Down Expand Up @@ -122,10 +122,10 @@ typedef struct {
///< Here for convenience, so that encode operations common
///< to all #fr_app_io_t can be performed by the #fr_app_t.

fr_app_process_set_t process_set; //!< Sets the entry point into the state machine provided
///< by the fr_app_process_t. We need a function this
///< as the #fr_app_process_t might change based on the
///< packet we received.
fr_app_entry_point_set_t entry_point_set; //!< Callback to Set the entry point into the state machine
///< provided by the fr_app_process_t.
///< We need a function this as the #fr_app_process_t might
///< change based on the packet we received.

fr_app_priority_get_t priority; //!< Assign a priority to the packet.
} fr_app_t;
Expand All @@ -140,7 +140,7 @@ typedef struct {

fr_app_bootstrap_t bootstrap;
fr_app_instantiate_t instantiate;
fr_io_process_t process; //!< Entry point into the protocol subtype's state machine.
fr_io_process_t entry_point; //!< Entry point into the protocol subtype's state machine.
} fr_app_process_t;

/** Public structure describing an I/O path for a protocol
Expand Down
2 changes: 1 addition & 1 deletion src/lib/io/listen.h
Expand Up @@ -42,7 +42,7 @@ struct fr_async_t {
fr_time_t recv_time;
fr_time_t *original_recv_time;
fr_event_list_t *el;
fr_io_process_t process;
fr_io_process_t process; //!< The current state function.
fr_time_tracking_t tracking;
fr_channel_t *channel;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/io/worker.c
Expand Up @@ -871,7 +871,7 @@ static REQUEST *fr_worker_get_request(fr_worker_t *worker, fr_time_t now)
* Call the main protocol handler to set the right async
* process function.
*/
listen->app->process_set(listen->app_instance, request);
listen->app->entry_point_set(listen->app_instance, request);

if (!request->async->process) {
RERROR("Protocol failed to set 'process' function");
Expand Down
2 changes: 1 addition & 1 deletion src/main/virtual_servers.c
Expand Up @@ -744,5 +744,5 @@ void fr_request_async_bootstrap(REQUEST *request, fr_event_list_t *el)

request->async->listen = NULL;
request->async->packet_ctx = NULL;
listener[0]->app->process_set(listener[0]->proto_module->data, request);
listener[0]->app->entry_point_set(listener[0]->proto_module->data, request);
}
28 changes: 14 additions & 14 deletions src/modules/proto_detail/proto_detail.c
Expand Up @@ -386,7 +386,7 @@ static ssize_t mod_encode(UNUSED void const *instance, REQUEST *request, uint8_t
return 1;
}

static void mod_process_set(void const *instance, REQUEST *request)
static void mod_entry_point_set(void const *instance, REQUEST *request)
{
proto_detail_t const *inst = talloc_get_type_abort_const(instance, proto_detail_t);
fr_app_process_t const *app_process;
Expand All @@ -397,7 +397,7 @@ static void mod_process_set(void const *instance, REQUEST *request)
app_process = (fr_app_process_t const *)inst->type_submodule->module->common;

request->server_cs = inst->server_cs;
request->async->process = app_process->process;
request->async->process = app_process->entry_point;
}

/** Open listen sockets/connect to external event source
Expand Down Expand Up @@ -688,16 +688,16 @@ static int mod_detach(void *instance)
}

fr_app_t proto_detail = {
.magic = RLM_MODULE_INIT,
.name = "detail",
.config = proto_detail_config,
.inst_size = sizeof(proto_detail_t),

.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.detach = mod_detach,
.open = mod_open,
.decode = mod_decode,
.encode = mod_encode,
.process_set = mod_process_set
.magic = RLM_MODULE_INIT,
.name = "detail",
.config = proto_detail_config,
.inst_size = sizeof(proto_detail_t),

.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.detach = mod_detach,
.open = mod_open,
.decode = mod_decode,
.encode = mod_encode,
.entry_point_set = mod_entry_point_set
};
2 changes: 1 addition & 1 deletion src/modules/proto_detail/proto_detail_process.c
Expand Up @@ -237,5 +237,5 @@ fr_app_process_t proto_detail_process = {
.name = "detail_process",
.inst_size = sizeof(proto_detail_process_t),
.instantiate = mod_instantiate,
.process = mod_process,
.entry_point = mod_process,
};
44 changes: 22 additions & 22 deletions src/modules/proto_dhcpv4/proto_dhcpv4.c
Expand Up @@ -413,7 +413,7 @@ static ssize_t mod_encode(void const *instance, REQUEST *request, uint8_t *buffe
return data_len;
}

static void mod_process_set(void const *instance, REQUEST *request)
static void mod_entry_point_set(void const *instance, REQUEST *request)
{
proto_dhcpv4_t const *inst = talloc_get_type_abort_const(instance, proto_dhcpv4_t);
fr_io_process_t process;
Expand All @@ -432,12 +432,12 @@ static void mod_process_set(void const *instance, REQUEST *request)

app_process = (fr_app_process_t const *) inst->dynamic_submodule->module->common;

request->async->process = app_process->process;
request->async->process = app_process->entry_point;
track->dynamic = 0;
return;
}

process = inst->process_by_code[request->packet->code];
process = inst->entry_point_by_code[request->packet->code];
if (!process) {
REDEBUG("proto_dhcpv4 - No module available to handle packet code %i", request->packet->code);
return;
Expand All @@ -447,7 +447,7 @@ static void mod_process_set(void const *instance, REQUEST *request)
}


static int mod_priority(void const *instance, uint8_t const *buffer, UNUSED size_t buflen)
static int mod_priority_set(void const *instance, uint8_t const *buffer, UNUSED size_t buflen)
{
proto_dhcpv4_t const *inst = talloc_get_type_abort_const(instance, proto_dhcpv4_t);

Expand All @@ -459,7 +459,7 @@ static int mod_priority(void const *instance, uint8_t const *buffer, UNUSED size
*/
if (!inst->priorities[buffer[0]]) return 0;

if (!inst->process_by_code[buffer[0]]) return -1;
if (!inst->entry_point_by_code[buffer[0]]) return -1;

/*
* @todo - if we cared, we could also return -1 for "this
Expand Down Expand Up @@ -666,7 +666,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf)
if (!fr_cond_assert(enumv)) return -1;

code = enumv->value->vb_uint32;
inst->process_by_code[code] = app_process->process; /* Store the process function */
inst->entry_point_by_code[code] = app_process->entry_point; /* Store the process function */

rad_assert(inst->code_allowed[code] == true);
i++;
Expand Down Expand Up @@ -780,7 +780,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf)
rad_assert(inst->io.server_cs); /* Ensure we don't leak memory */

process_p = talloc(inst->io.server_cs, fr_io_process_t);
*process_p = app_process->process;
*process_p = app_process->entry_point;

(void) cf_data_add(inst->io.server_cs, process_p, value, NULL);
}
Expand Down Expand Up @@ -874,19 +874,19 @@ static void mod_unload(void)
}

fr_app_t proto_dhcpv4 = {
.magic = RLM_MODULE_INIT,
.name = "dhcpv4",
.config = proto_dhcpv4_config,
.inst_size = sizeof(proto_dhcpv4_t),

.load = mod_load,
.unload = mod_unload,

.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.open = mod_open,
.decode = mod_decode,
.encode = mod_encode,
.process_set = mod_process_set,
.priority = mod_priority
.magic = RLM_MODULE_INIT,
.name = "dhcpv4",
.config = proto_dhcpv4_config,
.inst_size = sizeof(proto_dhcpv4_t),

.load = mod_load,
.unload = mod_unload,

.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.open = mod_open,
.decode = mod_decode,
.encode = mod_encode,
.entry_point_set = mod_entry_point_set,
.priority = mod_priority_set
};
2 changes: 1 addition & 1 deletion src/modules/proto_dhcpv4/proto_dhcpv4.h
Expand Up @@ -35,7 +35,7 @@ typedef struct proto_dhcpv4_t {
dl_instance_t **type_submodule; //!< Instance of the various types
dl_instance_t *dynamic_submodule; //!< proto_dhcpv4_dynamic_client
//!< only one instance per type allowed.
fr_io_process_t process_by_code[FR_DHCP_MAX]; //!< Lookup process entry point by code.
fr_io_process_t entry_point_by_code[FR_DHCP_MAX]; //!< Lookup process entry point by code.

uint32_t max_packet_size; //!< for message ring buffer.
uint32_t num_messages; //!< for message ring buffer.
Expand Down
2 changes: 1 addition & 1 deletion src/modules/proto_dhcpv4/proto_dhcpv4_base.c
Expand Up @@ -220,5 +220,5 @@ extern fr_app_process_t proto_dhcpv4_base;
fr_app_process_t proto_dhcpv4_base = {
.magic = RLM_MODULE_INIT,
.name = "dhcpv4_base",
.process = mod_process,
.entry_point = mod_process,
};
18 changes: 9 additions & 9 deletions src/modules/proto_radius/proto_radius.c
Expand Up @@ -485,7 +485,7 @@ static ssize_t mod_encode(void const *instance, REQUEST *request, uint8_t *buffe
return data_len;
}

static void mod_process_set(void const *instance, REQUEST *request)
static void mod_entry_point_set(void const *instance, REQUEST *request)
{
proto_radius_t const *inst = talloc_get_type_abort_const(instance, proto_radius_t);
fr_io_process_t process;
Expand All @@ -504,12 +504,12 @@ static void mod_process_set(void const *instance, REQUEST *request)

app_process = (fr_app_process_t const *) inst->dynamic_submodule->module->common;

request->async->process = app_process->process;
request->async->process = app_process->entry_point;
track->dynamic = 0;
return;
}

process = inst->process_by_code[request->packet->code];
process = inst->entry_point_by_code[request->packet->code];
if (!process) {
REDEBUG("proto_radius - No module available to handle packet code %i", request->packet->code);
return;
Expand All @@ -519,7 +519,7 @@ static void mod_process_set(void const *instance, REQUEST *request)
}


static int mod_priority(void const *instance, uint8_t const *buffer, UNUSED size_t buflen)
static int mod_priority_set(void const *instance, uint8_t const *buffer, UNUSED size_t buflen)
{
proto_radius_t const *inst = talloc_get_type_abort_const(instance, proto_radius_t);

Expand All @@ -531,7 +531,7 @@ static int mod_priority(void const *instance, uint8_t const *buffer, UNUSED size
*/
if (!inst->priorities[buffer[0]]) return 0;

if (!inst->process_by_code[buffer[0]]) return -1;
if (!inst->entry_point_by_code[buffer[0]]) return -1;

/*
* @todo - if we cared, we could also return -1 for "this
Expand Down Expand Up @@ -766,7 +766,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf)
if (!fr_cond_assert(enumv)) return -1;

code = enumv->value->vb_uint32;
inst->process_by_code[code] = app_process->process; /* Store the process function */
inst->entry_point_by_code[code] = app_process->entry_point; /* Store the process function */

rad_assert(inst->code_allowed[code] == true);
i++;
Expand Down Expand Up @@ -873,7 +873,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf)
rad_assert(inst->io.server_cs); /* Ensure we don't leak memory */

process_p = talloc(inst->io.server_cs, fr_io_process_t);
*process_p = app_process->process;
*process_p = app_process->entry_point;

(void) cf_data_add(inst->io.server_cs, process_p, value, NULL);
}
Expand Down Expand Up @@ -956,6 +956,6 @@ fr_app_t proto_radius = {
.open = mod_open,
.decode = mod_decode,
.encode = mod_encode,
.process_set = mod_process_set,
.priority = mod_priority
.entry_point_set = mod_entry_point_set,
.priority = mod_priority_set
};
3 changes: 2 additions & 1 deletion src/modules/proto_radius/proto_radius.h
Expand Up @@ -35,7 +35,8 @@ typedef struct proto_radius_t {
dl_instance_t **type_submodule; //!< Instance of the various types
dl_instance_t *dynamic_submodule; //!< proto_radius_dynamic_client
//!< only one instance per type allowed.
fr_io_process_t process_by_code[FR_MAX_PACKET_CODE]; //!< Lookup process entry point by code.
fr_io_process_t entry_point_by_code[FR_MAX_PACKET_CODE]; //!< Lookup process entry point by code.
void *process_instance_by_code[FR_MAX_PACKET_CODE]; //!< Lookup process instance by code.

uint32_t max_packet_size; //!< for message ring buffer.
uint32_t num_messages; //!< for message ring buffer.
Expand Down
2 changes: 1 addition & 1 deletion src/modules/proto_radius/proto_radius_acct.c
Expand Up @@ -189,5 +189,5 @@ extern fr_app_process_t proto_radius_acct;
fr_app_process_t proto_radius_acct = {
.magic = RLM_MODULE_INIT,
.name = "radius_acct",
.process = mod_process,
.entry_point = mod_process,
};
2 changes: 1 addition & 1 deletion src/modules/proto_radius/proto_radius_auth.c
Expand Up @@ -605,5 +605,5 @@ fr_app_process_t proto_radius_auth = {
.name = "radius_auth",
.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
.process = mod_process,
.entry_point = mod_process,
};
2 changes: 1 addition & 1 deletion src/modules/proto_radius/proto_radius_coa.c
Expand Up @@ -240,5 +240,5 @@ extern fr_app_process_t proto_radius_coa;
fr_app_process_t proto_radius_coa = {
.magic = RLM_MODULE_INIT,
.name = "radius_coa",
.process = mod_process,
.entry_point = mod_process,
};
2 changes: 1 addition & 1 deletion src/modules/proto_radius/proto_radius_dynamic_client.c
Expand Up @@ -239,5 +239,5 @@ fr_app_process_t proto_radius_dynamic_client = {
.magic = RLM_MODULE_INIT,
.name = "radius_dynamic_client",
.instantiate = mod_instantiate,
.process = mod_process,
.entry_point = mod_process,
};
2 changes: 1 addition & 1 deletion src/modules/proto_radius/proto_radius_status.c
Expand Up @@ -201,5 +201,5 @@ extern fr_app_process_t proto_radius_status;
fr_app_process_t proto_radius_status = {
.magic = RLM_MODULE_INIT,
.name = "radius_status",
.process = mod_process,
.entry_point = mod_process,
};
14 changes: 7 additions & 7 deletions src/modules/proto_vmps/proto_vmps.c
Expand Up @@ -371,7 +371,7 @@ static ssize_t mod_encode(void const *instance, REQUEST *request, uint8_t *buffe
return data_len;
}

static void mod_process_set(void const *instance, REQUEST *request)
static void mod_entry_point_set(void const *instance, REQUEST *request)
{
proto_vmps_t const *inst = talloc_get_type_abort_const(instance, proto_vmps_t);
fr_io_track_t *track = request->async->packet_ctx;
Expand All @@ -389,7 +389,7 @@ static void mod_process_set(void const *instance, REQUEST *request)

app_process = (fr_app_process_t const *) inst->dynamic_submodule->module->common;

request->async->process = app_process->process;
request->async->process = app_process->entry_point;
track->dynamic = 0;
return;
}
Expand All @@ -399,7 +399,7 @@ static void mod_process_set(void const *instance, REQUEST *request)
}


static int mod_priority(void const *instance, uint8_t const *buffer, UNUSED size_t buflen)
static int mod_priority_set(void const *instance, uint8_t const *buffer, UNUSED size_t buflen)
{
proto_vmps_t const *inst = talloc_get_type_abort_const(instance, proto_vmps_t);

Expand Down Expand Up @@ -605,7 +605,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf)
enumv = cf_data_value(cf_data_find(cp, fr_dict_enum_t, NULL));
if (!fr_cond_assert(enumv)) return -1;

inst->process = app_process->process; /* Store the process function */
inst->process = app_process->entry_point; /* Store the state function */

rad_assert(inst->code_allowed[enumv->value->vb_uint32] == true);
i++;
Expand Down Expand Up @@ -719,7 +719,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf)
rad_assert(inst->io.server_cs); /* Ensure we don't leak memory */

process_p = talloc(inst->io.server_cs, fr_io_process_t);
*process_p = app_process->process;
*process_p = app_process->entry_point;

(void) cf_data_add(inst->io.server_cs, process_p, value, NULL);
}
Expand Down Expand Up @@ -807,6 +807,6 @@ fr_app_t proto_vmps = {
.open = mod_open,
.decode = mod_decode,
.encode = mod_encode,
.process_set = mod_process_set,
.priority = mod_priority
.entry_point_set = mod_entry_point_set,
.priority = mod_priority_set
};
2 changes: 1 addition & 1 deletion src/modules/proto_vmps/proto_vmps_all.c
Expand Up @@ -197,5 +197,5 @@ extern fr_app_process_t proto_vmps_all;
fr_app_process_t proto_vmps_all = {
.magic = RLM_MODULE_INIT,
.name = "vmps_all",
.process = mod_process,
.entry_point = mod_process,
};

0 comments on commit 58dd62d

Please sign in to comment.