From ce244039639df2685d285020a723850400b26ed4 Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Fri, 14 Oct 2022 10:37:53 +0200 Subject: fix(libhicnctrl): new create/face&route command fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I49d80a741672c4f9da75e36cc816fc53f37ac158 Ticket: HICN-808 Signed-off-by: Jordan Augé --- ctrl/libhicnctrl/src/commands/command_face.c | 32 ++++++-- ctrl/libhicnctrl/src/commands/command_listener.c | 13 +++- ctrl/libhicnctrl/src/commands/command_route.c | 95 +++++++++++++++++++++++- 3 files changed, 129 insertions(+), 11 deletions(-) (limited to 'ctrl/libhicnctrl/src/commands') diff --git a/ctrl/libhicnctrl/src/commands/command_face.c b/ctrl/libhicnctrl/src/commands/command_face.c index 2ea0f5cc3..f60bef18d 100644 --- a/ctrl/libhicnctrl/src/commands/command_face.c +++ b/ctrl/libhicnctrl/src/commands/command_face.c @@ -43,11 +43,11 @@ .offset = offsetof(hc_face_t, remote_port), \ } -#define interface \ - { \ - .name = "interface", .help = "Interface on which to bind", \ - .type = TYPE_INTERFACE_NAME, \ - .offset = offsetof(hc_face_t, netdevice) + offsetof(netdevice_t, name), \ +#define interface \ + { \ + .name = "interface", .help = "Interface on which to bind", \ + .type = TYPE_INTERFACE_NAME, \ + .offset = offsetof(hc_face_t, netdevice.name), \ } #define symbolic_or_id \ @@ -64,6 +64,7 @@ int on_face_create(hc_face_t* face) { return 0; } +#if 0 static command_parser_t command_face_create3 = { .action = ACTION_CREATE, .object_type = OBJECT_TYPE_FACE, @@ -73,7 +74,6 @@ static command_parser_t command_face_create3 = { }; COMMAND_REGISTER(command_face_create3); -#if 0 static const command_parser_t command_face_create4 = { .action = ACTION_CREATE, .object = OBJECT_TYPE_FACE, @@ -85,6 +85,24 @@ static const command_parser_t command_face_create4 = { COMMAND_REGISTER(command_face_create4); #endif +static const command_parser_t command_face_create3 = { + .action = ACTION_CREATE, + .object_type = OBJECT_TYPE_FACE, + .nparams = 3, + .parameters = {type_tcp_udp, remote_address, remote_port}, + .post_hook = (parser_hook_t)on_face_create, +}; +COMMAND_REGISTER(command_face_create3); + +static const command_parser_t command_face_create4 = { + .action = ACTION_CREATE, + .object_type = OBJECT_TYPE_FACE, + .nparams = 4, + .parameters = {type_tcp_udp, remote_address, remote_port, interface}, + .post_hook = (parser_hook_t)on_face_create, +}; +COMMAND_REGISTER(command_face_create4); + static const command_parser_t command_face_create5 = { .action = ACTION_CREATE, .object_type = OBJECT_TYPE_FACE, @@ -127,4 +145,4 @@ static const command_parser_t command_face_remove1 = { .nparams = 1, .parameters = {symbolic_or_id}, }; -COMMAND_REGISTER(command_face_remove1); \ No newline at end of file +COMMAND_REGISTER(command_face_remove1); diff --git a/ctrl/libhicnctrl/src/commands/command_listener.c b/ctrl/libhicnctrl/src/commands/command_listener.c index c11742bba..cfcd22f48 100644 --- a/ctrl/libhicnctrl/src/commands/command_listener.c +++ b/ctrl/libhicnctrl/src/commands/command_listener.c @@ -90,7 +90,16 @@ static const command_parser_t command_listener_create4 = { COMMAND_REGISTER(command_listener_create4); #endif -static const command_parser_t command_listener_create6 = { +static const command_parser_t command_listener_create4 = { + .action = ACTION_CREATE, + .object_type = OBJECT_TYPE_LISTENER, + .nparams = 4, + .parameters = {protocol_tcp_udp, symbolic, local_address, local_port}, + .post_hook = (parser_hook_t)on_listener_create, +}; +COMMAND_REGISTER(command_listener_create4); + +static const command_parser_t command_listener_create5 = { .action = ACTION_CREATE, .object_type = OBJECT_TYPE_LISTENER, .nparams = 5, @@ -98,7 +107,7 @@ static const command_parser_t command_listener_create6 = { interface}, .post_hook = (parser_hook_t)on_listener_create, }; -COMMAND_REGISTER(command_listener_create6); +COMMAND_REGISTER(command_listener_create5); static const command_parser_t command_listener_list = { .action = ACTION_LIST, diff --git a/ctrl/libhicnctrl/src/commands/command_route.c b/ctrl/libhicnctrl/src/commands/command_route.c index 8e7db8192..5db710111 100644 --- a/ctrl/libhicnctrl/src/commands/command_route.c +++ b/ctrl/libhicnctrl/src/commands/command_route.c @@ -1,5 +1,6 @@ #include #include +#include "../objects/route.h" /* Parameters */ @@ -27,15 +28,105 @@ .type = TYPE_INT(1, 255), .offset = offsetof(hc_route_t, cost), \ } +/* Face parameters */ + +#define type_tcp_udp \ + { \ + .name = "type", .help = "face type [tcp | udp]", \ + .type = TYPE_ENUM(face_type), .offset = offsetof(hc_route_t, face.type), \ + } + +#define local_address \ + { \ + .name = "local_addr", .help = "local IP address on which to bind.", \ + .type = TYPE_IP_ADDRESS, .offset = offsetof(hc_route_t, face.local_addr), \ + .offset2 = offsetof(hc_route_t, face.family), \ + } + +#define local_port \ + { \ + .name = "local_port", .help = "Local port.", \ + .type = TYPE_UINT16(1, UINT16_MAX), \ + .offset = offsetof(hc_route_t, face.local_port), \ + } + +#define remote_address \ + { \ + .name = "remote_address", \ + .help = "The IPv4 or IPv6 or hostname of the remote system.", \ + .type = TYPE_IP_ADDRESS, .offset = offsetof(hc_route_t, face.remote_addr), \ + .offset2 = offsetof(hc_route_t, face.family), \ + } + +#define remote_port \ + { \ + .name = "remote_port", .help = "Remote port.", \ + .type = TYPE_UINT16(1, UINT16_MAX), \ + .offset = offsetof(hc_route_t, face.remote_port), \ + } + +#define interface \ + { \ + .name = "interface", .help = "Interface on which to bind", \ + .type = TYPE_INTERFACE_NAME, \ + .offset = offsetof(hc_route_t, face.netdevice.name), \ + } + /* Commands */ +int on_route_create(hc_route_t* route) { + if (hc_route_has_face(route)) { + route->face.admin_state = FACE_STATE_UP; + route->face.id = INVALID_FACE_ID; + } + return 0; +} -static const command_parser_t command_route_create = { +static const command_parser_t command_route_create3 = { .action = ACTION_CREATE, .object_type = OBJECT_TYPE_ROUTE, .nparams = 3, .parameters = {symbolic_or_id, prefix, cost}, }; -COMMAND_REGISTER(command_route_create); +COMMAND_REGISTER(command_route_create3); + +static const command_parser_t command_route_create5 = { + .action = ACTION_CREATE, + .object_type = OBJECT_TYPE_ROUTE, + .nparams = 5, + .parameters = {prefix, cost, type_tcp_udp, remote_address, remote_port}, + .post_hook = (parser_hook_t)on_route_create, +}; +COMMAND_REGISTER(command_route_create5); + +static const command_parser_t command_route_create6 = { + .action = ACTION_CREATE, + .object_type = OBJECT_TYPE_ROUTE, + .nparams = 6, + .parameters = {prefix, cost, type_tcp_udp, remote_address, remote_port, + interface}, + .post_hook = (parser_hook_t)on_route_create, +}; +COMMAND_REGISTER(command_route_create6); + +static const command_parser_t command_route_create7 = { + .action = ACTION_CREATE, + .object_type = OBJECT_TYPE_ROUTE, + .nparams = 7, + .parameters = {prefix, cost, type_tcp_udp, local_address, local_port, + remote_address, remote_port}, + .post_hook = (parser_hook_t)on_route_create, +}; +COMMAND_REGISTER(command_route_create7); + +static const command_parser_t command_route_create8 = { + .action = ACTION_CREATE, + .object_type = OBJECT_TYPE_ROUTE, + .nparams = 8, + .parameters = {prefix, cost, type_tcp_udp, local_address, local_port, + remote_address, remote_port, interface}, + .post_hook = (parser_hook_t)on_route_create, +}; +COMMAND_REGISTER(command_route_create8); static const command_parser_t command_route_list = { .action = ACTION_LIST, -- cgit 1.2.3-korg