diff options
Diffstat (limited to 'hicn-light/src/hicn/config')
-rw-r--r-- | hicn-light/src/hicn/config/command.h | 5 | ||||
-rw-r--r-- | hicn-light/src/hicn/config/command_route.c | 3 | ||||
-rw-r--r-- | hicn-light/src/hicn/config/configuration.c | 38 | ||||
-rw-r--r-- | hicn-light/src/hicn/config/configuration.h | 1 | ||||
-rw-r--r-- | hicn-light/src/hicn/config/parse.c | 44 |
5 files changed, 51 insertions, 40 deletions
diff --git a/hicn-light/src/hicn/config/command.h b/hicn-light/src/hicn/config/command.h index c0e3e66e8..ddeb94b03 100644 --- a/hicn-light/src/hicn/config/command.h +++ b/hicn-light/src/hicn/config/command.h @@ -13,6 +13,7 @@ /* Update sscanf accordingly in parse_cmd.c */ #define MAX_PARAMETERS 10 +#define MAX_SCANF_PARAM_LEN 100 typedef int (*parser_hook_t)(void * arg); @@ -125,7 +126,7 @@ typedef struct { }, \ } /* We need to allocate room for the intermediate string */ -#define TYPE_FMT_ENUM "%ms" +#define TYPE_FMT_ENUM "%s" #define TYPE_POLICY_STATE(TAG) (parser_type_t) { \ .name = TYPENAME_POLICY_STATE, \ @@ -134,7 +135,7 @@ typedef struct { }, \ } /* We need to allocate room for the intermediate string */ -#define TYPE_FMT_POLICY_STATE "%ms" +#define TYPE_FMT_POLICY_STATE "%s" /** * \brief Register a protocol diff --git a/hicn-light/src/hicn/config/command_route.c b/hicn-light/src/hicn/config/command_route.c index b357cb036..2c20ad193 100644 --- a/hicn-light/src/hicn/config/command_route.c +++ b/hicn-light/src/hicn/config/command_route.c @@ -1,3 +1,4 @@ +#include <math.h> #include "command.h" /* Parameters */ @@ -5,7 +6,7 @@ static const command_parameter_t symbolic_or_id = { .name = "symbolic_or_id", .help = "The symbolic name for an egress, or the egress route id (see 'help list routes')", - .type = TYPE_SYMBOLIC_OR_ID, + .type = TYPE_INT(1, pow(2, 16) - 1), .offset = offsetof(hc_route_t, face_id), }; diff --git a/hicn-light/src/hicn/config/configuration.c b/hicn-light/src/hicn/config/configuration.c index f5ed231b2..f56ce73ce 100644 --- a/hicn-light/src/hicn/config/configuration.c +++ b/hicn-light/src/hicn/config/configuration.c @@ -21,8 +21,6 @@ * @endcode */ -#include <hicn/ctrl/commands.h> - #ifndef _WIN32 #include <arpa/inet.h> #include <unistd.h> @@ -53,13 +51,13 @@ #define DEFAULT_COST 1 #define DEFAULT_PORT 1234 -#define make_ack(msg) ((msg_header_t *)msg)->header.messageType = ACK_LIGHT -#define make_nack(msg) ((msg_header_t *)msg)->header.messageType = NACK_LIGHT +#define make_ack(msg) ((msg_header_t *)msg)->header.message_type = ACK_LIGHT +#define make_nack(msg) ((msg_header_t *)msg)->header.message_type = NACK_LIGHT #define msg_malloc_list(msg, N) \ do { \ msg = malloc(sizeof((msg)->header) + N * sizeof((msg)->payload)); \ - (msg)->header.messageType = RESPONSE_LIGHT; \ + (msg)->header.message_type = RESPONSE_LIGHT; \ (msg)->header.length = (uint16_t)(N); \ } while(0); @@ -73,7 +71,7 @@ do { \ * * prefix_str -> strategy_type */ -KHASH_INIT(strategy_map, const char *, unsigned, 0, str_hash, str_hash_eq); +KHASH_MAP_INIT_STR(strategy_map, unsigned); struct configuration_s { forwarder_t * forwarder; @@ -200,23 +198,33 @@ configuration_on_listener_add(configuration_t * config, uint8_t * packet, /* Verify that the listener DOES NOT exist */ listener_t * listener = listener_table_get_by_name(table, control->symbolic); - if (listener) + if (listener) { + DEBUG("Listener %s already exists", control->symbolic); goto NACK; + } address_t address; if (address_from_ip_port(&address, control->family, &control->address, control->port) < 0) { WARN("Unsupported address type for HICN (ingress id %u): " "must be either IPV4 or IPV6", ingress_id); - return false; + goto NACK; } - // NOTE: interface_name is expected NULL for hICN listener - face_type_t face_type = get_face_type_from_listener_type((hc_connection_type_t) control->listenerType); + if (!face_type_is_defined(control->type)) { + WARN("[configuration_on_listener_add] Invalid listener type"); + goto NACK; + } + + // XXX validate that we use face_type everywhere, as we use the untyped + // uint8_t for the control protocol + face_type_t face_type = get_face_type_from_listener_type((hc_connection_type_t) control->type); if (!face_type_is_defined(face_type)) goto NACK; - listener = listener_create(face_type, &address, control->interfaceName, control->symbolic, forwarder); + // NOTE: interface_name is expected NULL for hICN listener + + listener = listener_create(face_type, &address, control->interface_name, control->symbolic, forwarder); if (!listener) goto NACK; @@ -378,10 +386,9 @@ configuration_on_connection_add(configuration_t * config, uint8_t * packet, const char *symbolic_name = control->symbolic; - face_type_t face_type; - if (!face_type_is_defined(control->type)) + face_type_t face_type = get_face_type_from_listener_type((hc_connection_type_t) control->type); + if (!face_type_is_defined(face_type)) goto NACK; - face_type = (face_type_t)control->type; connection_table_t * table = forwarder_get_connection_table(config->forwarder); if (connection_table_get_by_name(table, symbolic_name)) { @@ -1422,7 +1429,7 @@ configuration_receive_command(configuration_t * config, msgbuf_t * msgbuf) case COMMAND_TYPE_ROUTE_LIST: case COMMAND_TYPE_POLICY_LIST: /* Free replies that have been allocated (not NACK's) */ - if (((msg_header_t *)reply)->header.messageType != NACK_LIGHT) + if (((msg_header_t *)reply)->header.message_type != NACK_LIGHT) free(reply); break; default: @@ -1450,4 +1457,3 @@ face_type_t get_face_type_from_listener_type(hc_connection_type_t listener_type) } return face_type; } - diff --git a/hicn-light/src/hicn/config/configuration.h b/hicn-light/src/hicn/config/configuration.h index 1cf772b42..91f851a59 100644 --- a/hicn-light/src/hicn/config/configuration.h +++ b/hicn-light/src/hicn/config/configuration.h @@ -29,6 +29,7 @@ #include "../core/msgbuf.h" #include "../core/strategy.h" #include <hicn/ctrl/api.h> +#include <hicn/ctrl/commands.h> typedef struct configuration_s configuration_t; diff --git a/hicn-light/src/hicn/config/parse.c b/hicn-light/src/hicn/config/parse.c index 4959b7cde..b26227c1a 100644 --- a/hicn-light/src/hicn/config/parse.c +++ b/hicn-light/src/hicn/config/parse.c @@ -33,8 +33,6 @@ #include "command.h" -static void * sscanf_params[MAX_PARAMETERS]; - const char * action_str[] = { #define _(x) [ACTION_ ## x] = #x, foreach_action @@ -114,6 +112,11 @@ parser_type_fmt(const parser_type_t * type) int parser_type_func(const parser_type_t * type, void * src, void *dst, void * dst2, void * dst3) { + ip_address_t addr; + char *addr_str; + char *len_str; + int len; + switch(type->name) { case TYPENAME_INT: *(int*)dst = *(int*)src; @@ -133,19 +136,25 @@ parser_type_func(const parser_type_t * type, void * src, void *dst, void * dst2, case TYPENAME_SYMBOLIC_OR_ID: break; case TYPENAME_IP_ADDRESS: - *(ip_address_t*)dst = IP_ADDRESS_EMPTY; // XXX - *(int*)dst2 = AF_INET; + ip_address_pton((char *)src, &addr); + + *(ip_address_t*)dst = addr; + *(int*)dst2 = ip_address_get_family((char *)src); break; case TYPENAME_IP_PREFIX: - *(ip_address_t*)dst = IP_ADDRESS_EMPTY; // XXX - *(int*)dst2 = 128; - *(int*)dst3 = AF_INET; + addr_str = strtok((char *)src, "/"); + len_str = strtok(NULL, " "); + ip_address_pton((char *)src, &addr); + len = atoi(len_str); + + *(ip_address_t*)dst = addr; + *(int*)dst2 = len; + *(int*)dst3 = ip_address_get_family(addr_str); break; case TYPENAME_ENUM: /* Enum index from string */ assert(type->enum_.from_str); - const char * str = *(const char **)src; - *(int*)dst = type->enum_.from_str(str); + *(int*)dst = type->enum_.from_str((char *)src); break; case TYPENAME_POLICY_STATE: { @@ -172,10 +181,9 @@ parse_params(const command_parser_t * parser, const char * params_s, char fmt[1024]; int n; size_t size = 0; - char * pos = fmt; - - int must_free[MAX_PARAMETERS]; + /* Update MAX_PARAMETERS accordingly in command.h */ + char sscanf_params[MAX_PARAMETERS][MAX_SCANF_PARAM_LEN]; unsigned count = 0; for (unsigned i = 0; i < parser->nparams; i++) { @@ -185,8 +193,6 @@ parse_params(const command_parser_t * parser, const char * params_s, WARN("Ignored parameter %s with unknown type formatter", p->name); continue; } - must_free[count] = (strcmp(fmt, "%ms") == 0), - n = snprintf(pos, 1024 - size, "%s", fmt); pos += n; @@ -198,21 +204,17 @@ parse_params(const command_parser_t * parser, const char * params_s, } *pos = '\0'; - void ** sp = sscanf_params; - /* Update MAX_PARAMETERS accordingly in command.h */ - sscanf(params_s, fmt, &sp[0], &sp[1], &sp[2], &sp[3], &sp[4], &sp[5], - &sp[6], &sp[7], &sp[8], &sp[9]); + sscanf(params_s, fmt, sscanf_params[0], sscanf_params[1], sscanf_params[2], sscanf_params[3], sscanf_params[4], sscanf_params[5], + sscanf_params[6], sscanf_params[7], sscanf_params[8], sscanf_params[9]); for (unsigned i = 0; i < count; i++) { const command_parameter_t * p = &parser->parameters[i]; - if (parser_type_func(&p->type, &sp[i], &command->object.as_uint8 + p->offset, + if (parser_type_func(&p->type, sscanf_params[i], &command->object.as_uint8 + p->offset, &command->object.as_uint8 + p->offset2, &command->object.as_uint8 + p->offset3) < 0) { ERROR("Error during parsing of parameter '%s' value\n", p->name); goto ERR; } - if (must_free[i]) - free(sp[i]); } return 0; |