aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnrico Loparco (eloparco) <eloparco@cisco.com>2021-06-23 00:23:23 +0200
committerEnrico Loparco (eloparco) <eloparco@cisco.com>2021-06-24 09:32:16 +0200
commit7c2dc50e82152fe4ef4a69a799a80b747e444a37 (patch)
treeb9995a3ec4e2da6d62785baacac8746f3c3a9676
parent05bcac416bcddaf05bd0437bd27a19933502baf2 (diff)
[HICN-710] Add support for new route creation
Signed-off-by: Enrico Loparco (eloparco) <eloparco@cisco.com> Change-Id: Ib3b6fa8260f3f2475ad5b6e4147c1f7116b11dc4
-rw-r--r--ctrl/libhicnctrl/includes/hicn/ctrl/api.h1
-rw-r--r--hicn-light/src/hicn/cli/hicnc.c5
-rw-r--r--hicn-light/src/hicn/config/command.h1
-rw-r--r--hicn-light/src/hicn/config/command_route.c3
-rw-r--r--hicn-light/src/hicn/config/parse.c44
-rw-r--r--hicn-light/src/hicn/core/address.c4
6 files changed, 34 insertions, 24 deletions
diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h
index ebb4ee007..ef52f8988 100644
--- a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h
+++ b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h
@@ -631,6 +631,7 @@ int hc_face_snprintf(char *s, size_t size, hc_face_t *face);
*----------------------------------------------------------------------------*/
typedef struct {
+ // TODO: Allow also symbolic name
face_id_t face_id; /* Kr. */
int family; /* Krw */
ip_address_t remote_addr; /* krw */
diff --git a/hicn-light/src/hicn/cli/hicnc.c b/hicn-light/src/hicn/cli/hicnc.c
index 2c1c3500e..2445f258c 100644
--- a/hicn-light/src/hicn/cli/hicnc.c
+++ b/hicn-light/src/hicn/cli/hicnc.c
@@ -150,6 +150,11 @@ main(int argc, char * const * argv)
fprintf(stderr, "Error running command");
goto ERR_CMD;
}
+ } else if (command.action == ACTION_CREATE && command.object.type == OBJECT_ROUTE) {
+ if (hc_route_create(s, &command.object.route) < 0) {
+ fprintf(stderr, "Error running command");
+ goto ERR_CMD;
+ }
}
exit(EXIT_SUCCESS);
diff --git a/hicn-light/src/hicn/config/command.h b/hicn-light/src/hicn/config/command.h
index c0e3e66e8..4cc770e0d 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 10
typedef int (*parser_hook_t)(void * arg);
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/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;
diff --git a/hicn-light/src/hicn/core/address.c b/hicn-light/src/hicn/core/address.c
index 10f65f2f3..cde89c888 100644
--- a/hicn-light/src/hicn/core/address.c
+++ b/hicn-light/src/hicn/core/address.c
@@ -26,10 +26,10 @@ address_from_ip_port(address_t * address, int family, ip_address_t * addr, uint1
memset(address, 0, sizeof(address_t));
switch(family) {
case AF_INET:
- *address = ADDRESS4(addr->v4.as_inaddr.s_addr, port);
+ *address = ADDRESS4(ntohl(addr->v4.as_inaddr.s_addr), ntohs(port));
break;
case AF_INET6:
- *address = ADDRESS6(addr->v6.as_in6addr, port);
+ *address = ADDRESS6(ntohl(addr->v6.as_in6addr), ntohs(port));
break;
default:
return -1;