From: Arran Cudbard-Bell Date: Fri, 22 Jun 2018 00:13:43 +0000 (-0400) Subject: Move server_id into proto_radius_auth X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d2daa57a746093aff1334fe7df6eb1bc368ea50;p=thirdparty%2Ffreeradius-server.git Move server_id into proto_radius_auth This is a super secret config option that is pretty RADIUS specific --- diff --git a/src/include/radiusd.h b/src/include/radiusd.h index 2956260af21..4739a20922b 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -126,10 +126,6 @@ typedef struct main_config { size_t talloc_pool_size; //!< Size of pool to allocate to hold each #REQUEST. - uint8_t state_server_id; //!< Sets a specific byte in the state to allow the - //!< authenticating server to be identified in packet - //!< captures. - bool write_pid; //!< write the PID file #ifdef HAVE_SETUID diff --git a/src/include/state.h b/src/include/state.h index 57bd8843584..66717c6b492 100644 --- a/src/include/state.h +++ b/src/include/state.h @@ -32,7 +32,8 @@ extern "C" { typedef struct fr_state_tree_t fr_state_tree_t; -fr_state_tree_t *fr_state_tree_init(TALLOC_CTX *ctx, fr_dict_attr_t const *da, uint32_t max_sessions, uint32_t timeout); +fr_state_tree_t *fr_state_tree_init(TALLOC_CTX *ctx, fr_dict_attr_t const *da, + uint32_t max_sessions, uint32_t timeout, uint8_t server_id); void fr_state_discard(fr_state_tree_t *state, REQUEST *request); diff --git a/src/main/mainconfig.c b/src/main/mainconfig.c index 976bc76dc28..0d4be005c4a 100644 --- a/src/main/mainconfig.c +++ b/src/main/mainconfig.c @@ -221,7 +221,6 @@ static const CONF_PARSER security_config[] = { #ifdef ENABLE_OPENSSL_VERSION_CHECK { FR_CONF_POINTER("allow_vulnerable_openssl", FR_TYPE_STRING, &main_config.allow_vulnerable_openssl), .dflt = "no" }, #endif - { FR_CONF_POINTER("server_id", FR_TYPE_UINT8, &main_config.state_server_id) }, CONF_PARSER_TERMINATOR }; diff --git a/src/main/state.c b/src/main/state.c index d25ab9fdd17..80333802b72 100644 --- a/src/main/state.c +++ b/src/main/state.c @@ -119,6 +119,8 @@ struct fr_state_tree_t { uint32_t timeout; //!< How long to wait before cleaning up state entires. pthread_mutex_t mutex; //!< Synchronisation mutex. + uint8_t server_id; //!< ID to use for load balancing. + fr_dict_attr_t const *da; //!< State attribute used. }; @@ -175,12 +177,13 @@ static int _state_tree_free(fr_state_tree_t *state) * @param[in] da Attribute used to store and retrieve state from. * @param[in] max_sessions we track state for. * @param[in] timeout How long to wait before cleaning up entries. + * @param[in] server_id ID byte to use in load-balancing operations. * @return * - A new state tree. * - NULL on failure. */ fr_state_tree_t *fr_state_tree_init(TALLOC_CTX *ctx, fr_dict_attr_t const *da, - uint32_t max_sessions, uint32_t timeout) + uint32_t max_sessions, uint32_t timeout, uint8_t server_id) { fr_state_tree_t *state; @@ -218,6 +221,7 @@ fr_state_tree_t *fr_state_tree_init(TALLOC_CTX *ctx, fr_dict_attr_t const *da, talloc_set_destructor(state, _state_tree_free); state->da = da; /* Remember which attribute we use to load/store state */ + state->tree = server_id; return state; } @@ -454,7 +458,7 @@ static fr_state_entry_t *state_entry_create(fr_state_tree_t *state, REQUEST *req * Allow a portion of the State attribute to be set, * this is useful for debugging purposes. */ - entry->state_comp.server_id = main_config.state_server_id; + entry->state_comp.server_id = state->server_id; vp = fr_pair_afrom_da(packet, state->da); fr_pair_value_memcpy(vp, entry->state, sizeof(entry->state)); diff --git a/src/main/unit_test_module.c b/src/main/unit_test_module.c index 08a6c4b2b9d..2d4573728b0 100644 --- a/src/main/unit_test_module.c +++ b/src/main/unit_test_module.c @@ -944,7 +944,7 @@ int main(int argc, char *argv[]) if (modules_thread_instantiate(thread_ctx, main_config.config, el) < 0) goto exit_failure; if (xlat_thread_instantiate(thread_ctx) < 0) goto exit_failure; - state = fr_state_tree_init(autofree, attr_state, 256, 10); + state = fr_state_tree_init(autofree, attr_state, 256, 10, 0); /* * Set the panic action (if required) diff --git a/src/modules/proto_radius/proto_radius_auth.c b/src/modules/proto_radius/proto_radius_auth.c index 6ee73cd9ae6..11f8a43a94e 100644 --- a/src/modules/proto_radius/proto_radius_auth.c +++ b/src/modules/proto_radius/proto_radius_auth.c @@ -48,12 +48,17 @@ typedef struct { uint32_t session_timeout; //!< Maximum time between the last response and next request. uint32_t max_session; //!< Maximum ongoing session allowed. + uint8_t state_server_id; //!< Sets a specific byte in the state to allow the + //!< authenticating server to be identified in packet + //!< captures. + fr_state_tree_t *state_tree; //!< State tree to link multiple requests/responses. } proto_radius_auth_t; static const CONF_PARSER session_config[] = { { FR_CONF_OFFSET("timeout", FR_TYPE_UINT32, proto_radius_auth_t, session_timeout), .dflt = "15" }, { FR_CONF_OFFSET("max", FR_TYPE_UINT32, proto_radius_auth_t, max_session), .dflt = "4096" }, + { FR_CONF_OFFSET("state_server_id", FR_TYPE_UINT8, proto_radius_auth_t, state_server_id) }, CONF_PARSER_TERMINATOR }; @@ -658,7 +663,8 @@ static int mod_instantiate(void *instance, CONF_SECTION *process_app_cs) } } - inst->state_tree = fr_state_tree_init(inst, attr_state, inst->max_session, inst->session_timeout); + inst->state_tree = fr_state_tree_init(inst, attr_state, inst->max_session, + inst->session_timeout, inst->state_server_id); return 0; }