From: Arran Cudbard-Bell Date: Mon, 24 Feb 2020 19:15:24 +0000 (-0500) Subject: make the input file optional in the load generation module X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f31c6512f9131111b753bb3bfde366d71e60cb9d;p=thirdparty%2Ffreeradius-server.git make the input file optional in the load generation module --- diff --git a/src/modules/proto_radius/proto_radius_load.c b/src/modules/proto_radius/proto_radius_load.c index 1671a9229ca..f6f2df67245 100644 --- a/src/modules/proto_radius/proto_radius_load.c +++ b/src/modules/proto_radius/proto_radius_load.c @@ -223,7 +223,7 @@ static int mod_open(fr_listen_t *li) server_cs = cf_item_to_section(ci); - thread->name = talloc_typed_asprintf(thread, "load generation from file %s", inst->filename); + thread->name = talloc_typed_asprintf(thread, "load generation from file %s", inst->filename ? inst->filename : "none"); thread->parent = talloc_parent(li); DEBUG("Listening on radius address %s bound to virtual server %s", @@ -371,7 +371,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *cs) { proto_radius_load_t *inst = talloc_get_type_abort(instance, proto_radius_load_t); RADCLIENT *client; - FILE *fp; + bool done; VALUE_PAIR *vp, *vps = NULL; ssize_t packet_len; @@ -388,22 +388,26 @@ static int mod_instantiate(void *instance, CONF_SECTION *cs) client->nas_type = talloc_strdup(client, "load"); client->use_connected = false; - fp = fopen(inst->filename, "r"); - if (!fp) { - cf_log_err(cs, "Failed reading %s - %s", - inst->filename, fr_syserror(errno)); - return -1; - } + if (inst->filename) { + FILE *fp; + + fp = fopen(inst->filename, "r"); + if (!fp) { + cf_log_err(cs, "Failed reading %s - %s", + inst->filename, fr_syserror(errno)); + return -1; + } + + if (fr_pair_list_afrom_file(inst, dict_radius, &vps, fp, &done) < 0) { + cf_log_err(cs, "Failed reading %s - %s", + inst->filename, fr_strerror()); + fclose(fp); + return -1; + } - if (fr_pair_list_afrom_file(inst, dict_radius, &vps, fp, &done) < 0) { - cf_log_err(cs, "Failed reading %s - %s", - inst->filename, fr_strerror()); fclose(fp); - return -1; } - fclose(fp); - MEM(inst->packet = talloc_zero_array(inst, uint8_t, inst->max_packet_size)); vp = fr_pair_find_by_da(vps, attr_packet_type, TAG_ANY);