From 3e2cd52a6ae2345a44f39761beb5315a45832d95 Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Thu, 9 May 2019 11:26:31 +0200 Subject: [HICN-192] Add interface to administratively set a connection up and down MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8d00262fd8601328a50d0e2a6bef952031246818 Signed-off-by: Jordan Augé --- hicn-light/src/hicn/config/configuration.c | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'hicn-light/src/hicn/config/configuration.c') diff --git a/hicn-light/src/hicn/config/configuration.c b/hicn-light/src/hicn/config/configuration.c index 851e0a9a8..fa3a858c2 100644 --- a/hicn-light/src/hicn/config/configuration.c +++ b/hicn-light/src/hicn/config/configuration.c @@ -78,6 +78,44 @@ struct configuration { // ======================================================================================== +Connection * +getConnectionBySymbolicOrId(Configuration * config, const char * symbolicOrConnid) +{ + ConnectionTable *table = forwarder_GetConnectionTable(config->forwarder); + unsigned connid; + Connection *conn = NULL; + + /* Try to resolve an eventual symbolic name as input */ + if (utils_IsNumber(symbolicOrConnid)) { + connid = strtold(symbolicOrConnid, NULL); + + } else { + connid = symbolicNameTable_Get(config->symbolicNameTable, symbolicOrConnid); + if (connid == UINT32_MAX) { + if (logger_IsLoggable(config->logger, LoggerFacility_Config, + PARCLogLevel_Warning)) { + logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Error, + __func__, "Symbolic name '%s' could not be resolved", + symbolicOrConnid); + } + } + } + + /* Get connection by ID */ + conn = (Connection *)connectionTable_FindById( table, connid); + if (!conn) { + if (logger_IsLoggable(config->logger, LoggerFacility_Config, + PARCLogLevel_Warning)) { + logger_Log(config->logger, LoggerFacility_Config, PARCLogLevel_Error, + __func__, "ConnID not found, check list connections"); + } + } + + return conn; +} + +// ======================================================================================== + Configuration *configuration_Create(Forwarder *forwarder) { parcAssertNotNull(forwarder, "Parameter hicn-fwd must be non-null"); Configuration *config = parcMemory_AllocateAndClear(sizeof(Configuration)); @@ -383,6 +421,8 @@ struct iovec *configuration_ProcessCreateTunnel(Configuration *config, if (ops != NULL) { Connection *conn = connection_Create(ops); + connection_SetAdminState(conn, control->admin_state); + connectionTable_Add(forwarder_GetConnectionTable(config->forwarder), conn); symbolicNameTable_Add(config->symbolicNameTable, symbolicName, @@ -538,6 +578,8 @@ struct iovec *configuration_ProcessConnectionList(Configuration *config, listConnectionsCommand->connectionData.connectionType = ioOperations_GetConnectionType(connection_GetIoOperations(original)); + listConnectionsCommand->connectionData.admin_state = connection_GetAdminState(original); + if (addressGetType(localAddress) == ADDR_INET && addressGetType(remoteAddress) == ADDR_INET) { listConnectionsCommand->connectionData.ipType = ADDR_INET; @@ -970,6 +1012,20 @@ struct iovec *configuration_MapMeRetx(Configuration *config, return response; } +struct iovec *configuration_ConnectionSetAdminState(Configuration *config, + struct iovec *request) { + header_control_message *header = request[0].iov_base; + connection_set_admin_state_command *control = request[1].iov_base; + + Connection * conn = getConnectionBySymbolicOrId(config, control->symbolicOrConnid); + if (!conn) + return utils_CreateNack(header, control, sizeof(connection_set_admin_state_command)); + + connection_SetAdminState(conn, control->admin_state); + + return utils_CreateAck(header, control, sizeof(connection_set_admin_state_command)); +} + // =========================== // Main functions that deal with receiving commands, executing them, and sending // ACK/NACK @@ -1054,6 +1110,10 @@ struct iovec *configuration_DispatchCommand(Configuration *config, response = configuration_MapMeRetx(config, control); break; + case CONNECTION_SET_ADMIN_STATE: + response = configuration_ConnectionSetAdminState(config, control); + break; + default: break; } -- cgit 1.2.3-korg