Skip to content

Commit

Permalink
More autoload fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed May 29, 2018
1 parent b196686 commit b45390b
Show file tree
Hide file tree
Showing 63 changed files with 767 additions and 351 deletions.
4 changes: 3 additions & 1 deletion src/include/unlang.h
Expand Up @@ -151,4 +151,6 @@ int unlang_stack_depth(REQUEST *request);

rlm_rcode_t unlang_stack_result(REQUEST *request);

int unlang_initialize(void);
int unlang_init(void);

void unlang_free(void);
2 changes: 1 addition & 1 deletion src/lib/soh/soh.c
Expand Up @@ -723,7 +723,7 @@ int fr_soh_init(void)
}

if (fr_dict_autoload(soh_dict) < 0) {
PERROR("Failed loading dictionary");
PERROR("Failed initialising protocol library");
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/tls/base.c
Expand Up @@ -499,7 +499,7 @@ int tls_init(void)
ENGINE_register_all_complete();

if (fr_dict_autoload(tls_dict) < 0) {
PERROR("Failed loading dictionary");
PERROR("Failed initialising protocol library");
tls_free();
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/util/mem.c
Expand Up @@ -96,7 +96,7 @@ RADIUS_PACKET *fr_radius_alloc_reply(TALLOC_CTX *ctx, RADIUS_PACKET *packet)
/** Free a RADIUS_PACKET
*
*/
void fr_radius_free(RADIUS_PACKET **radius_packet_ptr)
void fr_radius_packet_free(RADIUS_PACKET **radius_packet_ptr)
{
RADIUS_PACKET *radius_packet;

Expand Down
2 changes: 1 addition & 1 deletion src/main/mainconfig.c
Expand Up @@ -263,7 +263,7 @@ static int _module_dict_autoload(dl_t const *module, void *symbol, UNUSED void *

#if 0
if (fr_dict_autoload((fr_dict_autoload_t const *)symbol) < 0) {
WARN("Failed loading dictionary: %s", fr_strerror());
WARN("Failed initialising protocol library: %s", fr_strerror());
return 0;
}
#else
Expand Down
8 changes: 4 additions & 4 deletions src/main/radclient.c
Expand Up @@ -825,7 +825,7 @@ static void deallocate_id(rc_request_t *request)
* authentication vector.
*/
if (request->packet->data) TALLOC_FREE(request->packet->data);
if (request->reply) fr_radius_free(&request->reply);
if (request->reply) fr_radius_packet_free(&request->reply);
}

/*
Expand Down Expand Up @@ -1073,7 +1073,7 @@ static int recv_one_packet(int wait_time)
if (!packet_p) {
ERROR("Received reply to request we did not send. (id=%d socket %d)",
reply->id, reply->sockfd);
fr_radius_free(&reply);
fr_radius_packet_free(&reply);
return -1; /* got reply to packet we didn't send */
}
request = fr_packet2myptr(rc_request_t, packet, packet_p);
Expand Down Expand Up @@ -1163,8 +1163,8 @@ static int recv_one_packet(int wait_time)
}

packet_done:
fr_radius_free(&request->reply);
fr_radius_free(&reply); /* may be NULL */
fr_radius_packet_free(&request->reply);
fr_radius_packet_free(&reply); /* may be NULL */

return 0;
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/radiusd.c
Expand Up @@ -559,7 +559,7 @@ int main(int argc, char *argv[])
/*
* Initialise the interpreter, registering operations.
*/
if (unlang_initialize() < 0) exit(EXIT_FAILURE);
if (unlang_init() < 0) exit(EXIT_FAILURE);

/*
* Initialize Auth-Type, etc. in the virtual servers
Expand Down Expand Up @@ -851,6 +851,11 @@ int main(int argc, char *argv[])
*/
map_proc_free();

/*
* Free any resources used by the unlang interpreter.
*/
unlang_free();

#if defined(HAVE_OPENSSL_CRYPTO_H) && OPENSSL_VERSION_NUMBER < 0x10100000L
tls_free(); /* Cleanup any memory alloced by OpenSSL and placed into globals */
#endif
Expand Down
38 changes: 19 additions & 19 deletions src/main/radsniff.c
Expand Up @@ -1013,9 +1013,9 @@ static int _request_free(rs_request_t *request)
}
}

fr_radius_free(&request->packet);
fr_radius_free(&request->expect);
fr_radius_free(&request->linked);
fr_radius_packet_free(&request->packet);
fr_radius_packet_free(&request->expect);
fr_radius_packet_free(&request->linked);

return 0;
}
Expand Down Expand Up @@ -1362,7 +1362,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
if (conf->event_flags & RS_ERROR) {
rs_packet_print(NULL, count, RS_ERROR, event->in, current, &elapsed, NULL, false, false);
}
fr_radius_free(&current);
fr_radius_packet_free(&current);

return;
}
Expand All @@ -1388,7 +1388,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
if (conf->filter_response_code && (conf->filter_response_code != current->code)) {
drop_response:
RDEBUG2("Response dropped by filter");
fr_radius_free(&current);
fr_radius_packet_free(&current);

/* We now need to cleanup the original request too */
if (original) {
Expand All @@ -1406,7 +1406,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
fr_log_fp = log_fp;
if (ret != 0) {
REDEBUG("Failed verifying packet ID %d: %s", current->id, fr_strerror());
fr_radius_free(&current);
fr_radius_packet_free(&current);
return;
}
}
Expand All @@ -1424,7 +1424,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
RADIUS_MAX_ATTRIBUTES, false, conf->radius_secret);
fr_log_fp = log_fp;
if (ret != 0) {
fr_radius_free(&current);
fr_radius_packet_free(&current);
REDEBUG("Failed decoding");
return;
}
Expand All @@ -1451,7 +1451,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
status = RS_RTX;
original->rt_rsp++;

fr_radius_free(&original->linked);
fr_radius_packet_free(&original->linked);
fr_event_timer_delete(event->list, &original->event);
/*
* ...nope it's the first response to a request.
Expand Down Expand Up @@ -1487,7 +1487,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
* complexity, reduces max capture rate, and is generally a PITA.
*/
if (conf->filter_request) {
fr_radius_free(&current);
fr_radius_packet_free(&current);
RDEBUG2("Original request dropped by filter");
return;
}
Expand All @@ -1514,7 +1514,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
drop_request:

RDEBUG2("Request dropped by filter");
fr_radius_free(&current);
fr_radius_packet_free(&current);

return;
}
Expand All @@ -1533,7 +1533,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
fr_log_fp = log_fp;
if (ret != 0) {
REDEBUG("Failed verifying packet ID %d: %s", current->id, fr_strerror());
fr_radius_free(&current);
fr_radius_packet_free(&current);
return;
}
}
Expand All @@ -1556,7 +1556,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
fr_log_fp = log_fp;

if (ret != 0) {
fr_radius_free(&current);
fr_radius_packet_free(&current);
REDEBUG("Failed decoding");
return;
}
Expand All @@ -1571,7 +1571,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
if (!search.expect) {
REDEBUG("Failed allocating memory to hold expected reply");
rs_tv_add_ms(&header->ts, conf->stats.timeout, &stats->quiet);
fr_radius_free(&current);
fr_radius_packet_free(&current);
return;
}
search.expect->code = current->code;
Expand All @@ -1582,7 +1582,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
conf->link_da_num);
if (ret < 0) {
ERROR("Failed extracting RTX linking pairs from request");
fr_radius_free(&current);
fr_radius_packet_free(&current);
return;
}
}
Expand Down Expand Up @@ -1645,10 +1645,10 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
status = RS_RTX;
original->rt_req++;

fr_radius_free(&original->packet);
fr_radius_packet_free(&original->packet);

/* We may of seen the response, but it may of been lost upstream */
fr_radius_free(&original->linked);
fr_radius_packet_free(&original->linked);

original->packet = talloc_steal(original, current);

Expand All @@ -1657,7 +1657,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
rbtree_deletebydata(request_tree, original);
}

fr_radius_free(&original->expect);
fr_radius_packet_free(&original->expect);
original->expect = talloc_steal(original, search.expect);

/* Disarm the timer for the cleanup event for the original request */
Expand Down Expand Up @@ -1736,7 +1736,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt

default:
REDEBUG("Unsupported code %i", current->code);
fr_radius_free(&current);
fr_radius_packet_free(&current);

return;
}
Expand Down Expand Up @@ -1799,7 +1799,7 @@ static void rs_packet_process(uint64_t count, rs_event_t *event, struct pcap_pkt
* not be done by the event queue.
*/
if (response && !original) {
fr_radius_free(&current);
fr_radius_packet_free(&current);
}

captured++;
Expand Down
7 changes: 6 additions & 1 deletion src/main/unit_test_module.c
Expand Up @@ -895,7 +895,7 @@ int main(int argc, char *argv[])
/*
* Initialise the interpreter, registering operations.
*/
if (unlang_initialize() < 0) exit(EXIT_FAILURE);
if (unlang_init() < 0) exit(EXIT_FAILURE);

/*
* Initialize Auth-Type, etc. in the virtual servers
Expand Down Expand Up @@ -1184,6 +1184,11 @@ int main(int argc, char *argv[])
*/
map_proc_free();

/*
* Free any resources used by the unlang interpreter.
*/
unlang_free();

/*
* And now nothing should be left anywhere except the
* parsed configuration items.
Expand Down
2 changes: 1 addition & 1 deletion src/modules/proto_arp/proto_arp.c
Expand Up @@ -140,7 +140,7 @@ static int arp_socket_recv(rad_listen_t *listener)
DEBUG("ARP received on interface %s", sock->lsock.interface);

if (!request_receive(NULL, listener, packet, &sock->client, arp_process)) {
fr_radius_free(&packet);
fr_radius_packet_free(&packet);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/proto_dhcpv4/dhcpclient.c
Expand Up @@ -171,7 +171,7 @@ static RADIUS_PACKET *request_init(char const *filename)
*/
if (fr_pair_list_afrom_file(NULL, &request->vps, fp, &filedone) < 0) {
fr_perror("dhcpclient");
fr_radius_free(&request);
fr_radius_packet_free(&request);
if (fp != stdin) fclose(fp);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/proto_dhcpv4/old.c
Expand Up @@ -909,7 +909,7 @@ static int dhcp_socket_recv(rad_listen_t *listener)

if (!request_receive(NULL, listener, packet, &sock->dhcp_client, dhcp_process)) {
FR_STATS_INC(auth, total_packets_dropped);
fr_radius_free(&packet);
fr_radius_packet_free(&packet);
return 0;
}

Expand Down
12 changes: 6 additions & 6 deletions src/modules/proto_dhcpv4/proto_dhcpv4.c
Expand Up @@ -79,11 +79,11 @@ fr_dict_autoload_t proto_dhcpv4_dict[] = {
{ NULL }
};

static fr_dict_attr_t const *attr_dhcpv4_message_type;
static fr_dict_attr_t const *attr_dhcp_message_type;

extern fr_dict_attr_autoload_t proto_dhcpv4_dict_attr[];
fr_dict_attr_autoload_t proto_dhcpv4_dict_attr[] = {
{ .out = &attr_dhcpv4_message_type, .name = "DHCP-Message-Type", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4},
{ .out = &attr_dhcp_message_type, .name = "DHCP-Message-Type", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4},
{ NULL }
};

Expand Down Expand Up @@ -160,7 +160,7 @@ static int type_parse(TALLOC_CTX *ctx, void *out, CONF_ITEM *ci, UNUSED CONF_PAR
* Allow the process module to be specified by
* packet type.
*/
type_enum = fr_dict_enum_by_alias(attr_dhcpv4_message_type, type_str, -1);
type_enum = fr_dict_enum_by_alias(attr_dhcp_message_type, type_str, -1);
if (!type_enum) {
cf_log_err(ci, "Invalid type \"%s\"", type_str);
return -1;
Expand Down Expand Up @@ -616,7 +616,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf)
* Check that the packet type is known.
*/
packet_type = cf_section_name2(subcs);
dv = fr_dict_enum_by_alias(attr_dhcpv4_message_type, packet_type, -1);
dv = fr_dict_enum_by_alias(attr_dhcp_message_type, packet_type, -1);
if (!dv || ((dv->value->vb_uint32 > FR_DHCP_MAX) &&
(dv->value->vb_uint32 == FR_DHCP_MESSAGE_TYPE_VALUE_DHCP_DO_NOT_RESPOND))) {
cf_log_err(subcs, "Invalid DHCPV4 packet type in '%s %s {...}'",
Expand Down Expand Up @@ -749,7 +749,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf)
inst->io.server_cs = cf_item_to_section(cf_parent(conf));

rad_assert(dict_dhcpv4 != NULL);
rad_assert(attr_dhcpv4_message_type != NULL);
rad_assert(attr_dhcp_message_type != NULL);

/*
* Bootstrap the process modules
Expand Down Expand Up @@ -861,7 +861,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf)
static int mod_load(void)
{
if (fr_dhcpv4_init() < 0) {
PERROR("Failed initialising DHCP");
PERROR("Failed initialising protocol library");
return -1;
}

Expand Down
10 changes: 5 additions & 5 deletions src/modules/proto_dhcpv4/proto_dhcpv4_base.c
Expand Up @@ -39,11 +39,11 @@ fr_dict_autoload_t proto_dhcpv4_dict[] = {
{ NULL }
};

static fr_dict_attr_t const *attr_dhcpv4_message_type;
static fr_dict_attr_t const *attr_dhcp_message_type;

extern fr_dict_attr_autoload_t proto_dhcpv4_base_dict_attr[];
fr_dict_attr_autoload_t proto_dhcpv4_base_dict_attr[] = {
{ .out = &attr_dhcpv4_message_type, .name = "DHCP-Message-Type", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4},
{ .out = &attr_dhcp_message_type, .name = "DHCP-Message-Type", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4},
{ NULL }
};

Expand Down Expand Up @@ -90,7 +90,7 @@ static fr_io_final_t mod_process(UNUSED void const *instance, REQUEST *request,

request->component = "dhcpv4";

dv = fr_dict_enum_by_value(attr_dhcpv4_message_type, fr_box_uint8(request->packet->code));
dv = fr_dict_enum_by_value(attr_dhcp_message_type, fr_box_uint8(request->packet->code));
if (!dv) {
REDEBUG("Failed to find value for &request:DHCP-Message-Type");
return FR_IO_FAIL;
Expand Down Expand Up @@ -122,7 +122,7 @@ static fr_io_final_t mod_process(UNUSED void const *instance, REQUEST *request,
* Allow the admin to explicitly set the reply
* type.
*/
vp = fr_pair_find_by_da(request->reply->vps, attr_dhcpv4_message_type, TAG_ANY);
vp = fr_pair_find_by_da(request->reply->vps, attr_dhcp_message_type, TAG_ANY);
if (vp) {
request->reply->code = vp->vp_uint8;
} else switch (rcode) {
Expand Down Expand Up @@ -186,7 +186,7 @@ static fr_io_final_t mod_process(UNUSED void const *instance, REQUEST *request,
* the NAK section.
*/
if (request->reply->code != FR_DHCP_MESSAGE_TYPE_VALUE_DHCP_DO_NOT_RESPOND) {
dv = fr_dict_enum_by_value(attr_dhcpv4_message_type, fr_box_uint8(request->reply->code));
dv = fr_dict_enum_by_value(attr_dhcp_message_type, fr_box_uint8(request->reply->code));
RWDEBUG("Failed running 'send %s', trying 'send Do-Not-Respond'", dv->alias);

request->reply->code = FR_DHCP_MESSAGE_TYPE_VALUE_DHCP_DO_NOT_RESPOND;
Expand Down

0 comments on commit b45390b

Please sign in to comment.