[HICN-385] fix route removal in hicnctrl, code uniformization in hicn-light control api 18/23318/3
authorJordan Augé <jordan.auge+fdio@cisco.com>
Thu, 7 Nov 2019 15:42:01 +0000 (16:42 +0100)
committerJordan Augé <jordan.auge+fdio@cisco.com>
Fri, 8 Nov 2019 00:36:45 +0000 (01:36 +0100)
Change-Id: Id097368dcde993775f206623195cc5aa57b4fe12
Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
31 files changed:
ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c
ctrl/libhicnctrl/includes/hicn/ctrl/api.h
ctrl/libhicnctrl/includes/hicn/ctrl/commands.h [changed mode: 0755->0644]
ctrl/libhicnctrl/src/api.c
ctrl/libhicnctrl/src/cli.c
hicn-light/src/hicn/config/configuration.c
hicn-light/src/hicn/config/configurationListeners.c
hicn-light/src/hicn/config/controlAddConnection.c
hicn-light/src/hicn/config/controlAddListener.c
hicn-light/src/hicn/config/controlAddPolicy.c
hicn-light/src/hicn/config/controlAddPunting.c
hicn-light/src/hicn/config/controlAddRoute.c
hicn-light/src/hicn/config/controlListPolicies.c
hicn-light/src/hicn/config/controlRemovePolicy.c
hicn-light/src/hicn/config/controlRemoveRoute.c
hicn-light/src/hicn/config/controlSetStrategy.c
hicn-light/src/hicn/core/name.c
hicn-light/src/hicn/core/name.h
hicn-light/src/hicn/core/nameBitvector.c
hicn-light/src/hicn/processor/fibEntry.c
hicn-light/src/hicn/socket/ops_linux.c
hicn-light/src/hicn/utils/commands.h
hicn-light/src/hicn/utils/utils.c
hicn-light/src/hicn/utils/utils.h
lib/includes/hicn/util/ip_address.h
lib/src/compat.c
lib/src/name.c
lib/src/util/ip_address.c
libtransport/src/hicn/transport/core/hicn_binary_api.c
libtransport/src/hicn/transport/core/prefix.cc
libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc

index 82d4a7e..75945bb 100644 (file)
@@ -257,7 +257,7 @@ int hl_on_event(interface_t * interface, const facelet_t * facelet)
             }
             INFO("Created face id=%d", hc_face.id);
 
-            /* Adding default routs e*/
+            /* Adding default routes */
 #if 1
             route = (hc_route_t) {
                 .face_id = hc_face.id,
index 62cf989..7b57a63 100644 (file)
@@ -69,6 +69,7 @@
 #include <stdint.h>
 
 #include <hicn/util/ip_address.h>
+#include <hicn/ctrl/commands.h>
 #include "face.h"
 
 #define HICN_DEFAULT_PORT 9695
@@ -380,8 +381,7 @@ int hc_sock_reset(hc_sock_t * s);
 #define NULLTERM 1
 #endif
 
-#define SYMBOLIC_NAME_LEN 16 /* NULL-terminated right ? */
-#define INTERFACE_LEN 16
+#define INTERFACE_LEN IFNAMSIZ
 #define MAXSZ_HC_NAME_ SYMBOLIC_NAME_LEN
 #define MAXSZ_HC_NAME MAXSZ_HC_NAME_ + NULLTERM
 
old mode 100755 (executable)
new mode 100644 (file)
index e69c939..a5bc15e
 #include <stdint.h>
 #include <stdlib.h>
 
+#include <hicn/util/ip_address.h>
 #ifdef WITH_POLICY
 #include <hicn/policy.h>
 #endif /* WITH_POLICY */
 
+#define SYMBOLIC_NAME_LEN 16
+
 typedef struct in6_addr ipv6_addr_t;
 typedef uint32_t ipv4_addr_t;
 
-union commandAddr {
-  ipv4_addr_t ipv4;
-  ipv6_addr_t ipv6;
-};
-
 typedef enum {
   REQUEST_LIGHT = 0xc0, // this is a command
   RESPONSE_LIGHT,
@@ -115,9 +113,9 @@ typedef struct {
 typedef enum { ETHER_MODE, IP_MODE, HICN_MODE } listener_mode;
 
 typedef struct {
-  char symbolic[16];
-  char interfaceName[16];
-  union commandAddr address;
+  char symbolic[SYMBOLIC_NAME_LEN];
+  char interfaceName[SYMBOLIC_NAME_LEN];
+  ip_address_t address;
   uint16_t port;
   // uint16_t etherType;
   uint8_t addressType;
@@ -125,15 +123,15 @@ typedef struct {
   uint8_t connectionType;
 } add_listener_command;
 
-// SIZE=40
+// SIZE=56
 
 //==========  [01]  ADD CONNECTION    ==========
 
 typedef struct {
-  char symbolic[16];
-  //char interfaceName[16];
-  union commandAddr remoteIp;
-  union commandAddr localIp;
+  char symbolic[SYMBOLIC_NAME_LEN];
+  //char interfaceName[SYMBOLIC_NAME_LEN];
+  ip_address_t remoteIp;
+  ip_address_t localIp;
   uint16_t remotePort;
   uint16_t localPort;
   uint8_t ipType;
@@ -168,17 +166,17 @@ typedef struct {
   uint32_t connid;
   uint8_t state;
   uint8_t admin_state;
-  char interfaceName[16];
-  char connectionName[16];
+  char interfaceName[SYMBOLIC_NAME_LEN];
+  char connectionName[SYMBOLIC_NAME_LEN];
 } list_connections_command;
 
-// SIZE=64
+// SIZE=80
 
 //==========  [03]  ADD ROUTE    ==========
 
 typedef struct {
-  char symbolicOrConnid[16];
-  union commandAddr address;
+  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+  ip_address_t address;
   uint16_t cost;
   uint8_t addressType;
   uint8_t len;
@@ -189,7 +187,7 @@ typedef struct {
 //==========  [04]  LIST ROUTE    ==========
 
 typedef struct {
-  union commandAddr address;
+  ip_address_t address;
   uint32_t connid;
   uint16_t cost;
   uint8_t addressType;
@@ -199,30 +197,29 @@ typedef struct {
 // SIZE=24
 
 //==========  [05]  REMOVE CONNECTION    ==========
-
 typedef struct {
-  char symbolicOrConnid[16];
+  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
 } remove_connection_command;
 
 //==========  [06]  REMOVE LISTENER    ==========
 typedef struct {
-  char symbolicOrListenerid[16];
+  char symbolicOrListenerid[SYMBOLIC_NAME_LEN];
 } remove_listener_command;
 
 // SIZE=16
 
-//==========  [06]  REMOVE ROUTE    ==========
+//==========  [07]  REMOVE ROUTE    ==========
 
 typedef struct {
-  char symbolicOrConnid[16];
-  union commandAddr address;
+  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+  ip_address_t address;
   uint8_t addressType;
   uint8_t len;
 } remove_route_command;
 
 // SIZE=36
 
-//==========  [07]  CACHE STORE    ==========
+//==========  [08]  CACHE STORE    ==========
 
 typedef struct {
   uint8_t activate;
@@ -230,7 +227,7 @@ typedef struct {
 
 // SIZE=1
 
-//==========  [08]  CACHE SERVE    ==========
+//==========  [09]  CACHE SERVE    ==========
 
 typedef struct {
   uint8_t activate;
@@ -238,20 +235,18 @@ typedef struct {
 
 // SIZE=1
 
-//==========  [09]  SET STRATEGY    ==========
+//==========  [10]  SET STRATEGY    ==========
 
 typedef enum {
   SET_STRATEGY_LOADBALANCER,
   SET_STRATEGY_RANDOM,
   SET_STRATEGY_RANDOM_PER_DASH_SEGMENT,
   SET_STRATEGY_LOADBALANCER_WITH_DELAY,
-  SET_STRATEGY_LOADBALANCER_BY_RATE,
-  SET_STRATEGY_LOADBALANCER_BEST_ROUTE,
   LAST_STRATEGY_VALUE
 } strategy_type;
 
 typedef struct {
-  union commandAddr address;
+  ip_address_t address;
   uint8_t strategyType;
   uint8_t addressType;
   uint8_t len;
@@ -262,7 +257,7 @@ typedef struct {
 //==========  [11]  SET WLDR    ==========
 
 typedef struct {
-  char symbolicOrConnid[16];
+  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
   uint8_t activate;
 } set_wldr_command;
 
@@ -271,8 +266,8 @@ typedef struct {
 //==========  [12]  ADD PUNTING    ==========
 
 typedef struct {
-  char symbolicOrConnid[16];
-  union commandAddr address;
+  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
+  ip_address_t address;
   uint8_t addressType;
   uint8_t len;
 } add_punting_command;
@@ -282,9 +277,9 @@ typedef struct {
 //==========  [13]  LIST LISTENER    ==========
 
 typedef struct {
-  union commandAddr address;
-  char listenerName[16];
-  char interfaceName[16];
+  ip_address_t address;
+  char listenerName[SYMBOLIC_NAME_LEN];
+  char interfaceName[SYMBOLIC_NAME_LEN];
   uint32_t connid;
   uint16_t port;
   uint8_t addressType;
@@ -310,7 +305,7 @@ typedef struct {
 // SIZE=1
 
 typedef struct {
-  char symbolicOrConnid[16];
+  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
   uint8_t admin_state;
   uint8_t pad8[3];
 } connection_set_admin_state_command;
@@ -318,27 +313,27 @@ typedef struct {
 #ifdef WITH_POLICY
 
 typedef struct {
-  union commandAddr address;
+  ip_address_t address;
   uint8_t addressType;
   uint8_t len;
   policy_t policy;
 } add_policy_command;
 
 typedef struct {
-  union commandAddr address;
+  ip_address_t address;
   uint8_t addressType;
   uint8_t len;
   policy_t policy;
 } list_policies_command;
 
 typedef struct {
-  union commandAddr address;
+  ip_address_t address;
   uint8_t addressType;
   uint8_t len;
 } remove_policy_command;
 
 typedef struct {
-  char symbolicOrConnid[16];
+  char symbolicOrConnid[SYMBOLIC_NAME_LEN];
   uint8_t admin_state;
   policy_tags_t tags;
 } update_connection_command;
index 783245e..2955e2e 100644 (file)
@@ -906,9 +906,7 @@ _hc_listener_create(hc_sock_t * s, hc_listener_t * listener, bool async)
             .seqNum = 0,
         },
         .payload = {
-            .address = {
-                .ipv6 = listener->local_addr.v6.as_in6addr,
-            },
+            .address = listener->local_addr,
             .port = htons(listener->local_port),
             .addressType = (u8)map_to_addr_type[listener->family],
             .listenerMode = (u8)map_to_listener_mode[listener->type],
@@ -1174,9 +1172,8 @@ _hc_connection_create(hc_sock_t * s, hc_connection_t * connection, bool async)
             .seqNum = 0,
         },
         .payload = {
-            /* we use IPv6 which is the longest address */
-            .remoteIp.ipv6 = connection->remote_addr.v6.as_in6addr,
-            .localIp.ipv6 = connection->local_addr.v6.as_in6addr,
+            .remoteIp = connection->remote_addr,
+            .localIp = connection->local_addr,
             .remotePort = htons(connection->remote_port),
             .localPort = htons(connection->local_port),
             .ipType = (u8)map_to_addr_type[connection->family],
@@ -1405,9 +1402,11 @@ hc_connection_parse(void * in, hc_connection_t * connection)
         .id = cmd->connid,
         .type = type,
         .family = family,
-        .local_addr = UNION_CAST(cmd->connectionData.localIp, ip_address_t),
+        .local_addr = cmd->connectionData.localIp,
+        //.local_addr = UNION_CAST(cmd->connectionData.localIp, ip_address_t),
         .local_port = ntohs(cmd->connectionData.localPort),
-        .remote_addr = UNION_CAST(cmd->connectionData.remoteIp, ip_address_t),
+        .remote_addr = cmd->connectionData.remoteIp,
+        //.remote_addr = UNION_CAST(cmd->connectionData.remoteIp, ip_address_t),
         .remote_port = ntohs(cmd->connectionData.remotePort),
         .admin_state = cmd->connectionData.admin_state,
 #ifdef WITH_POLICY
@@ -1521,8 +1520,7 @@ _hc_route_create(hc_sock_t * s, hc_route_t * route, bool async)
             .seqNum = 0,
         },
         .payload = {
-            /* we use IPv6 which is the longest address */
-            .address.ipv6 = route->remote_addr.v6.as_in6addr,
+            .address = route->remote_addr,
             .cost = route->cost,
             .addressType = (u8)map_to_addr_type[route->family],
             .len = route->len,
@@ -1577,8 +1575,7 @@ _hc_route_delete(hc_sock_t * s, hc_route_t * route, bool async)
             .seqNum = 0,
         },
         .payload = {
-            /* we use IPv6 which is the longest address */
-            .address.ipv6 = route->remote_addr.v6.as_in6addr,
+            .address = route->remote_addr,
             .addressType = (u8)map_to_addr_type[route->family],
             .len = route->len,
         }
@@ -2286,8 +2283,7 @@ _hc_punting_create(hc_sock_t * s, hc_punting_t * punting, bool async)
             .seqNum = 0,
         },
         .payload = {
-            /* we use IPv6 which is the longest address */
-            .address.ipv6 = punting->prefix.v6.as_in6addr,
+            .address = punting->prefix,
             .addressType = (u8)map_to_addr_type[punting->family],
             .len = punting->prefix_len,
         }
@@ -2567,8 +2563,7 @@ _hc_policy_create(hc_sock_t * s, hc_policy_t * policy, bool async)
             .seqNum = 0,
         },
         .payload = {
-            /* we use IPv6 which is the longest address */
-            .address.ipv6 = policy->remote_addr.v6.as_in6addr,
+            .address = policy->remote_addr,
             .addressType = (u8)map_to_addr_type[policy->family],
             .len = policy->len,
             .policy = policy->policy,
@@ -2617,8 +2612,7 @@ _hc_policy_delete(hc_sock_t * s, hc_policy_t * policy, bool async)
             .seqNum = 0,
         },
         .payload = {
-            /* we use IPv6 which is the longest address */
-            .address.ipv6 = policy->remote_addr.v6.as_in6addr,
+            .address = policy->remote_addr,
             .addressType = (u8)map_to_addr_type[policy->family],
             .len = policy->len,
         }
index 81400f8..a171f70 100644 (file)
@@ -48,41 +48,217 @@ foreach_object
 #undef _
 } hc_object_t;
 
+void
+usage_header()
+{
+    fprintf(stderr, "Usage:\n");
+}
+
+void
+usage_face_create(const char * prog, bool header, bool verbose)
+{
+
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -f TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", prog);
+    if (verbose)
+        fprintf(stderr, "    Create a face on specified address and port.\n");
+}
+
+void
+usage_face_delete(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -df ID\n", prog);
+    //fprintf(stderr, "%s -df NAME\n", prog);
+    fprintf(stderr, "%s -df TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", prog);
+    if (verbose)
+        fprintf(stderr, "    Delete a face...\n");
+}
+
+void
+usage_face_list(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -F\n", prog);
+    if (verbose)
+        fprintf(stderr, "    List all faces.\n");
+}
+
+void
+usage_face(const char * prog, bool header, bool verbose)
+{
+    usage_face_create(prog, header, verbose);
+    usage_face_delete(prog, header, verbose);
+    usage_face_list(prog, header, verbose);
+}
+
+void
+usage_route_create(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -r FACE_ID PREFIX [COST]\n", prog);
+    //fprintf(stderr, "%s -r [FACE_ID|NAME] PREFIX [COST]\n", prog);
+    if (verbose)
+        fprintf(stderr, "    Create a route...\n");
+}
+
+void
+usage_route_delete(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -dr FACE_ID PREFIX\n", prog);
+    //fprintf(stderr, "%s -dr [FACE_ID|NAME] PREFIX\n", prog);
+    if (verbose)
+        fprintf(stderr, "    Delete a route...\n");
+}
+
+void
+usage_route_list(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -R\n", prog);
+    if (verbose)
+        fprintf(stderr, "    List all routes.\n");
+}
+
+void
+usage_route(const char * prog, bool header, bool verbose)
+{
+    usage_route_create(prog, header, verbose);
+    usage_route_delete(prog, header, verbose);
+    usage_route_list(prog, header, verbose);
+}
+
+void
+usage_forwarding_strategy_create(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+}
+void
+usage_forwarding_strategy_delete(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+}
+
+void
+usage_forwarding_strategy_list(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -S\n", prog);
+    if (verbose)
+        fprintf(stderr, "    List all availble forwarding strategies.\n");
+}
+
+void
+usage_forwarding_strategy(const char * prog, bool header, bool verbose)
+{
+    usage_forwarding_strategy_create(prog, header, verbose);
+    usage_forwarding_strategy_delete(prog, header, verbose);
+    usage_forwarding_strategy_list(prog, header, verbose);
+}
+
+void
+usage_listener_create(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -l NAME TYPE LOCAL_ADDRESS LOCAL_PORT [INTERFACE_NAME]\n", prog);
+    if (verbose)
+        fprintf(stderr, "    Create a listener on specified address and port.\n");
+}
+
+void
+usage_listener_delete(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -dl ID\n", prog);
+    fprintf(stderr, "%s -dl NAME\n", prog);
+    fprintf(stderr, "%s -dl TYPE LOCAL_ADDRESS LOCAL_PORT [INTERFACE_NAME]\n", prog);
+    if (verbose)
+        fprintf(stderr, "    Delete a listener...\n");
+}
+
+void
+usage_listener_list(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -L\n", prog);
+    if (verbose)
+        fprintf(stderr, "    List all listeners.\n");
+}
+
+void
+usage_listener(const char * prog, bool header, bool verbose)
+{
+    usage_listener_create(prog, header, verbose);
+    usage_listener_delete(prog, header, verbose);
+    usage_listener_list(prog, header, verbose);
+}
+void
+usage_connection_create(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -c NAME TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", prog);
+    if (verbose)
+        fprintf(stderr, "    Create a connection on specified address and port.\n");
+}
+
+void
+usage_connection_delete(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -dc ID\n", prog);
+    fprintf(stderr, "%s -dc NAME\n", prog);
+    fprintf(stderr, "%s -dc TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", prog);
+    if (verbose)
+        fprintf(stderr, "    Delete a connection...\n");
+}
+
+void
+usage_connection_list(const char * prog, bool header, bool verbose)
+{
+    if (header)
+        usage_header();
+    fprintf(stderr, "%s -C\n", prog);
+    if (verbose)
+        fprintf(stderr, "    List all connections.\n");
+}
+
+void
+usage_connection(const char * prog, bool header, bool verbose)
+{
+    usage_connection_create(prog, header, verbose);
+    usage_connection_delete(prog, header, verbose);
+    usage_connection_list(prog, header, verbose);
+}
+
 void usage(const char * prog)
 {
     fprintf(stderr, "Usage: %s [ [-d] [-f|-l|-c|-r] PARAMETERS | [-F|-L|-C|-R] ]\n", prog);
     fprintf(stderr, "\n");
     fprintf(stderr, "High-level commands\n");
     fprintf(stderr, "\n");
-    fprintf(stderr, "%s -f <NAME> <TYPE> <LOCAL_ADDRESS> <LOCAL_PORT> <REMOTE_ADDRESS> <REMOTE_PORT>\n", prog);
-    fprintf(stderr, "    Create a face on specified address and port.\n");
-    fprintf(stderr, "%s -fc ...\n", prog);
-    fprintf(stderr, "    Delete a face...\n");
-    fprintf(stderr, "%s -F\n", prog);
-    fprintf(stderr, "    List all faces.\n");
-    fprintf(stderr, "%s -r ...>\n", prog);
-    fprintf(stderr, "    Create a route...\n");
-    fprintf(stderr, "%s -dr ...\n", prog);
-    fprintf(stderr, "    Delete a route...\n");
-    fprintf(stderr, "%s -R\n", prog);
-    fprintf(stderr, "    List all routes.\n");
-    fprintf(stderr, "%s -S\n", prog);
-    fprintf(stderr, "    List all availble forwarding strategies.\n");
+    usage_face(prog, false, true);
+    usage_route(prog, false, true);
+    usage_forwarding_strategy(prog, false, true);
     fprintf(stderr, "\n");
     fprintf(stderr, "Low level commands (hicn-light specific)\n");
     fprintf(stderr, "\n");
-    fprintf(stderr, "%s -l <NAME> <TYPE> <ADDRESS> <PORT> <INTERFACE_NAME>\n", prog);
-    fprintf(stderr, "    Create a listener on specified address and port.\n");
-    fprintf(stderr, "%s -dl ...\n", prog);
-    fprintf(stderr, "    Delete a listener...\n");
-    fprintf(stderr, "%s -L\n", prog);
-    fprintf(stderr, "    List all listeners.\n");
-    fprintf(stderr, "%s -c <NAME> <TYPE> <LOCAL_ADDRESS> <LOCAL_PORT> <REMOTE_ADDRESS> <REMOTE_PORT>\n", prog);
-    fprintf(stderr, "    Create a connection on specified address and port.\n");
-    fprintf(stderr, "%s -dc ...\n", prog);
-    fprintf(stderr, "    Delete a connection...\n");
-    fprintf(stderr, "%s -C\n", prog);
-    fprintf(stderr, "    List all connections.\n");
+    usage_listener(prog, false, true);
+    usage_connection(prog, false, true);
 }
 
 typedef struct {
@@ -147,7 +323,6 @@ parse_options(int argc, char *argv[], hc_command_t * command)
 {
     command->object = OBJECT_UNDEFINED;
     command->action = ACTION_CREATE;
-    int nargs = -1; /* unset */
     int opt;
     int family;
 
@@ -167,32 +342,26 @@ parse_options(int argc, char *argv[], hc_command_t * command)
                 break;
             case 'r':
                 command->object = OBJECT_ROUTE;
-                nargs = 0; // XXX
                 break;
             case 'F':
                 command->action = ACTION_LIST;
                 command->object = OBJECT_FACE;
-                nargs = 0;
                 break;
             case 'L':
                 command->action = ACTION_LIST;
                 command->object = OBJECT_LISTENER;
-                nargs = 0;
                 break;
             case 'C':
                 command->action = ACTION_LIST;
                 command->object = OBJECT_CONNECTION;
-                nargs = 0;
                 break;
             case 'R':
                 command->action = ACTION_LIST;
                 command->object = OBJECT_ROUTE;
-                nargs = 0;
                 break;
             case 'S':
                 command->action = ACTION_LIST;
                 command->object = OBJECT_STRATEGY;
-                nargs = 0;
                 break;
             default: /* "h" */
                 usage(argv[0]);
@@ -205,17 +374,13 @@ parse_options(int argc, char *argv[], hc_command_t * command)
         return -1;
     }
 
-    if (nargs == 0)
-        return 0;
-
     /* Parse and validate parameters for add/delete */
     switch(command->object) {
         case OBJECT_FACE:
             switch(command->action) {
                 case ACTION_CREATE:
                     if ((argc - optind != 6) && (argc - optind != 7)) {
-                        fprintf(stderr, "Usage:\n");
-                        fprintf(stderr, "%s -f TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", argv[0]);
+                        usage_face_create(argv[0], true, false); 
                         goto ERR_PARAM;
                     }
                     /* NAME will be autogenerated (and currently not used) */
@@ -242,10 +407,7 @@ parse_options(int argc, char *argv[], hc_command_t * command)
                     break;
                 case ACTION_DELETE:
                     if ((argc - optind != 1) && (argc - optind != 5) && (argc - optind != 6)) {
-                        fprintf(stderr, "Usage:\n");
-                        fprintf(stderr, "%s -ld ID\n", argv[0]);
-                        //fprintf(stderr, "%s -ld NAME\n", argv[0]);
-                        fprintf(stderr, "%s -ld TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", argv[0]);
+                        usage_face_delete(argv[0], true, false);
                         goto ERR_PARAM;
                     }
 
@@ -281,6 +443,14 @@ parse_options(int argc, char *argv[], hc_command_t * command)
                         }
                     }
                     break;
+
+                case ACTION_LIST:
+                    if (argc - optind != 0) {
+                        usage_face_list(argv[0], true, false);
+                        goto ERR_PARAM;
+                    }
+                    break;
+
                 default:
                     goto ERR_COMMAND;
                     break;
@@ -290,11 +460,51 @@ parse_options(int argc, char *argv[], hc_command_t * command)
         case OBJECT_ROUTE:
             switch(command->action) {
                 case ACTION_CREATE:
-                    goto ERR_COMMAND;
+                    if ((argc - optind != 2) && (argc - optind != 3)) {
+                        usage_route_create(argv[0], true, false);
+                        goto ERR_PARAM;
+                    }
+
+                    command->route.face_id = atoi(argv[optind++]);
+
+                    {
+                    ip_prefix_t prefix;
+                    ip_prefix_pton(argv[optind++], &prefix);
+                    command->route.family = prefix.family;
+                    command->route.remote_addr = prefix.address;
+                    command->route.len = prefix.len;
+                    }
+
+                    if (argc != optind) {
+                        printf("parse cost\n");
+                        command->route.cost = atoi(argv[optind++]);
+                    }
                     break;
+
                 case ACTION_DELETE:
-                    goto ERR_COMMAND;
+                    if (argc - optind != 2) {
+                        usage_route_delete(argv[0], true, false);
+                        goto ERR_PARAM;
+                    }
+
+                    command->route.face_id = atoi(argv[optind++]);
+
+                    {
+                    ip_prefix_t prefix;
+                    ip_prefix_pton(argv[optind++], &prefix);
+                    command->route.family = prefix.family;
+                    command->route.remote_addr = prefix.address;
+                    command->route.len = prefix.len;
+                    }
                     break;
+
+                case ACTION_LIST:
+                    if (argc - optind != 0) {
+                        usage_route_list(argv[0], true, false);
+                        goto ERR_PARAM;
+                    }
+                    break;
+
                 default:
                     goto ERR_COMMAND;
                     break;
@@ -304,6 +514,10 @@ parse_options(int argc, char *argv[], hc_command_t * command)
         case OBJECT_STRATEGY:
             switch(command->action) {
                 case ACTION_LIST:
+                    if (argc - optind != 0) {
+                        usage_forwarding_strategy_list(argv[0], true, false);
+                        goto ERR_PARAM;
+                    }
                     break;
                 default:
                     goto ERR_COMMAND;
@@ -315,8 +529,7 @@ parse_options(int argc, char *argv[], hc_command_t * command)
             switch(command->action) {
                 case ACTION_CREATE:
                     if ((argc - optind != 4) && (argc - optind != 5)) {
-                        fprintf(stderr, "Usage:\n");
-                        fprintf(stderr, "%s -l NAME TYPE LOCAL_ADDRESS LOCAL_PORT [INTERFACE_NAME]\n", argv[0]);
+                        usage_listener_create(argv[0], true, false);
                         goto ERR_PARAM;
                     }
                     snprintf(command->listener.name, SYMBOLIC_NAME_LEN, "%s", argv[optind++]);
@@ -336,10 +549,7 @@ parse_options(int argc, char *argv[], hc_command_t * command)
 
                 case ACTION_DELETE:
                     if ((argc - optind != 1) && (argc - optind != 3) && (argc - optind != 4)) {
-                        fprintf(stderr, "Usage:\n");
-                        fprintf(stderr, "%s -ld ID\n", argv[0]);
-                        fprintf(stderr, "%s -ld NAME\n", argv[0]);
-                        fprintf(stderr, "%s -ld TYPE LOCAL_ADDRESS LOCAL_PORT [INTERFACE_NAME]\n", argv[0]);
+                        usage_listener_delete(argv[0], true, false);
                         goto ERR_PARAM;
                     }
 
@@ -370,6 +580,13 @@ parse_options(int argc, char *argv[], hc_command_t * command)
                     }
                     break;
 
+                case ACTION_LIST:
+                    if (argc - optind != 0) {
+                        usage_listener_list(argv[0], true, false);
+                        goto ERR_PARAM;
+                    }
+                    break;
+
                 default:
                         goto ERR_COMMAND;
                     break;
@@ -381,8 +598,7 @@ parse_options(int argc, char *argv[], hc_command_t * command)
                 case ACTION_CREATE:
                     /* NAME TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT */
                     if ((argc - optind != 6) && (argc - optind != 7)) {
-                        fprintf(stderr, "Usage:\n");
-                        fprintf(stderr, "%s -c NAME TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", argv[0]);
+                        usage_connection_create(argv[0], true, false);
                         goto ERR_PARAM;
                     }
                     snprintf(command->connection.name, SYMBOLIC_NAME_LEN, "%s", argv[optind++]);
@@ -403,12 +619,10 @@ parse_options(int argc, char *argv[], hc_command_t * command)
                     command->connection.remote_port = atoi(argv[optind++]);
 
                     break;
+
                 case ACTION_DELETE:
                     if ((argc - optind != 1) && (argc - optind != 5) && (argc - optind != 6)) {
-                        fprintf(stderr, "Usage:\n");
-                        fprintf(stderr, "%s -ld ID\n", argv[0]);
-                        fprintf(stderr, "%s -ld NAME\n", argv[0]);
-                        fprintf(stderr, "%s -ld TYPE LOCAL_ADDRESS LOCAL_PORT REMOTE_ADDRESS REMOTE_PORT [INTERFACE_NAME]\n", argv[0]);
+                        usage_connection_delete(argv[0], true, false);
                         goto ERR_PARAM;
                     }
 
@@ -441,6 +655,14 @@ parse_options(int argc, char *argv[], hc_command_t * command)
                         command->connection.remote_port = atoi(argv[optind++]);
                     }
                     break;
+
+                case ACTION_LIST:
+                    if (argc - optind != 0) {
+                        usage_connection_list(argv[0], true, false);
+                        goto ERR_PARAM;
+                    }
+                    break;
+
                 default:
                     goto ERR_COMMAND;
                     break;
@@ -516,11 +738,17 @@ int main(int argc, char *argv[])
         case OBJECT_ROUTE:
             switch(command.action) {
                 case ACTION_CREATE:
-                    die(COMMAND, "Not implemented.");
+                    if (hc_route_create(s, &command.route) < 0)
+                        die(COMMAND, "Error creating route");
+                    printf("OK\n");
                     break;
+
                 case ACTION_DELETE:
-                    die(COMMAND, "Not implemented.");
+                    if (hc_route_delete(s, &command.route) < 0)
+                        die(COMMAND, "Error creating route");
+                    printf("OK\n");
                     break;
+
                 case ACTION_LIST:
                     if (hc_route_list(s, &data) < 0)
                         die(COMMAND, "Error getting routes.");
@@ -629,9 +857,6 @@ int main(int argc, char *argv[])
            break;
     }
 
-
-    /* ROUTES */
-
 ERR_COMMAND:
 ERR_CONNECT:
     hc_sock_free(s);
index c10b01c..0119256 100644 (file)
@@ -305,11 +305,11 @@ struct iovec *configuration_ProcessRegistrationList(Configuration *config,
       if (addressGetType(addressEntry) == ADDR_INET) {
         addressGetInet(addressEntry, &tmpAddr);
         listRouteCommand->addressType = ADDR_INET;
-        listRouteCommand->address.ipv4 = tmpAddr.sin_addr.s_addr;
+        listRouteCommand->address.v4.as_inaddr = tmpAddr.sin_addr;
       } else if (addressGetType(addressEntry) == ADDR_INET6) {
         addressGetInet6(addressEntry, &tmpAddr6);
         listRouteCommand->addressType = ADDR_INET6;
-        listRouteCommand->address.ipv6 = tmpAddr6.sin6_addr;
+        listRouteCommand->address.v6.as_in6addr = tmpAddr6.sin6_addr;
       }
       listRouteCommand->connid = numberSet_GetItem(nexthops, j);
       listRouteCommand->len = nameBitvector_GetLength(prefix);
@@ -370,14 +370,14 @@ struct iovec *configuration_ProcessCreateTunnel(Configuration *config,
 
   if (control->ipType == ADDR_INET) {
     source =
-        addressFromInaddr4Port(&control->localIp.ipv4, &control->localPort);
+        addressFromInaddr4Port(&control->localIp.v4.as_u32, &control->localPort);
     destination =
-        addressFromInaddr4Port(&control->remoteIp.ipv4, &control->remotePort);
+        addressFromInaddr4Port(&control->remoteIp.v4.as_u32, &control->remotePort);
   } else if (control->ipType == ADDR_INET6) {
     source =
-        addressFromInaddr6Port(&control->localIp.ipv6, &control->localPort);
+        addressFromInaddr6Port(&control->localIp.v6.as_in6addr, &control->localPort);
     destination =
-        addressFromInaddr6Port(&control->remoteIp.ipv6, &control->remotePort);
+        addressFromInaddr6Port(&control->remoteIp.v6.as_in6addr, &control->remotePort);
   } else {
     printf("Invalid IP type.\n");  // will generate a Nack
   }
@@ -714,14 +714,14 @@ struct iovec *configuration_ProcessConnectionList(Configuration *config,
       // get local port/address
       addressGetInet(localAddress, &tmpAddr);
       listConnectionsCommand->connectionData.localPort = tmpAddr.sin_port;
-      listConnectionsCommand->connectionData.localIp.ipv4 =
-          tmpAddr.sin_addr.s_addr;
+      listConnectionsCommand->connectionData.localIp.v4.as_inaddr =
+          tmpAddr.sin_addr;
       memset(&tmpAddr, 0, sizeof(tmpAddr));
       // get remote port/address
       addressGetInet(remoteAddress, &tmpAddr);
       listConnectionsCommand->connectionData.remotePort = tmpAddr.sin_port;
-      listConnectionsCommand->connectionData.remoteIp.ipv4 =
-          tmpAddr.sin_addr.s_addr;
+      listConnectionsCommand->connectionData.remoteIp.v4.as_inaddr =
+          tmpAddr.sin_addr;
 
     } else if (addressGetType(localAddress) == ADDR_INET6 &&
                addressGetType(remoteAddress) == ADDR_INET6) {
@@ -730,12 +730,12 @@ struct iovec *configuration_ProcessConnectionList(Configuration *config,
       // get local port/address
       addressGetInet6(localAddress, &tmpAddr6);
       listConnectionsCommand->connectionData.localPort = tmpAddr6.sin6_port;
-      listConnectionsCommand->connectionData.localIp.ipv6 = tmpAddr6.sin6_addr;
+      listConnectionsCommand->connectionData.localIp.v6.as_in6addr = tmpAddr6.sin6_addr;
       memset(&tmpAddr6, 0, sizeof(tmpAddr6));
       // get remote port/address
       addressGetInet6(remoteAddress, &tmpAddr6);
       listConnectionsCommand->connectionData.remotePort = tmpAddr6.sin6_port;
-      listConnectionsCommand->connectionData.remoteIp.ipv6 = tmpAddr6.sin6_addr;
+      listConnectionsCommand->connectionData.remoteIp.v6.as_in6addr = tmpAddr6.sin6_addr;
 
     }  // no need further else, control on the addressed already done at the
        // time of insertion in the connection table
@@ -789,7 +789,7 @@ struct iovec *configuration_ProcessListenersList(Configuration *config,
           (const Address *)listenerEntry->getListenAddress(listenerEntry),
           &tmpAddr);
       listListenersCommand->addressType = ADDR_INET;
-      listListenersCommand->address.ipv4 = tmpAddr.sin_addr.s_addr;
+      listListenersCommand->address.v4.as_inaddr = tmpAddr.sin_addr;
       listListenersCommand->port = tmpAddr.sin_port;
     } else if (addressGetType((const Address *)listenerEntry->getListenAddress(
                    listenerEntry)) == ADDR_INET6) {
@@ -797,7 +797,7 @@ struct iovec *configuration_ProcessListenersList(Configuration *config,
           (const Address *)listenerEntry->getListenAddress(listenerEntry),
           &tmpAddr6);
       listListenersCommand->addressType = ADDR_INET6;
-      listListenersCommand->address.ipv6 = tmpAddr6.sin6_addr;
+      listListenersCommand->address.v6.as_in6addr = tmpAddr6.sin6_addr;
       listListenersCommand->port = tmpAddr6.sin6_port;
     }
 
@@ -1209,11 +1209,11 @@ struct iovec *configuration_ProcessPolicyList(Configuration *config,
     if (addressGetType(addressEntry) == ADDR_INET) {
       addressGetInet(addressEntry, &tmpAddr);
       listPoliciesCommand->addressType = ADDR_INET;
-      listPoliciesCommand->address.ipv4 = tmpAddr.sin_addr.s_addr;
+      listPoliciesCommand->address.v4.as_inaddr = tmpAddr.sin_addr;
     } else if (addressGetType(addressEntry) == ADDR_INET6) {
       addressGetInet6(addressEntry, &tmpAddr6);
       listPoliciesCommand->addressType = ADDR_INET6;
-      listPoliciesCommand->address.ipv6 = tmpAddr6.sin6_addr;
+      listPoliciesCommand->address.v6.as_in6addr = tmpAddr6.sin6_addr;
     }
     listPoliciesCommand->len = nameBitvector_GetLength(prefix);
     listPoliciesCommand->policy = fibEntry_GetPolicy(entry);
index 8abbeb7..21bfe76 100644 (file)
@@ -364,7 +364,7 @@ bool _addHicn(Configuration *config, add_listener_command *control,
   switch (control->addressType) {
     case ADDR_INET: {
       localAddress =
-          addressFromInaddr4Port(&control->address.ipv4, &control->port);
+          addressFromInaddr4Port(&control->address.v4.as_u32, &control->port);
       success = _setupHicnListenerOnInet4(configuration_GetForwarder(config),
                                           symbolic, localAddress);
       break;
@@ -372,7 +372,7 @@ bool _addHicn(Configuration *config, add_listener_command *control,
 
     case ADDR_INET6: {
       localAddress =
-          addressFromInaddr6Port(&control->address.ipv6, &control->port);
+          addressFromInaddr6Port(&control->address.v6.as_in6addr, &control->port);
       success = _setupHicnListenerOnInet6(configuration_GetForwarder(config),
                                           symbolic, localAddress);
       break;
@@ -416,11 +416,11 @@ bool _addIP(Configuration *config, add_listener_command *control,
       if (control->connectionType == UDP_CONN) {
         success =
             _setupUdpListenerOnInet(configuration_GetForwarder(config), symbolic,
-                                    &control->address.ipv4, &control->port, control->interfaceName);
+                                    &control->address.v4.as_u32, &control->port, control->interfaceName);
       } else if (control->connectionType == TCP_CONN) {
         success =
             _setupTcpListenerOnInet(configuration_GetForwarder(config), symbolic,
-                                    &control->address.ipv4, &control->port, control->interfaceName);
+                                    &control->address.v4.as_u32, &control->port, control->interfaceName);
       }
       break;
     }
@@ -428,11 +428,11 @@ bool _addIP(Configuration *config, add_listener_command *control,
     case ADDR_INET6: {
       if (control->connectionType == UDP_CONN) {
         success = _setupUdpListenerOnInet6Light(
-            configuration_GetForwarder(config), symbolic, &control->address.ipv6,
+            configuration_GetForwarder(config), symbolic, &control->address.v6.as_in6addr,
             &control->port, control->interfaceName);
       } else if (control->connectionType == TCP_CONN) {
         success = _setupTcpListenerOnInet6Light(
-            configuration_GetForwarder(config), symbolic, &control->address.ipv6,
+            configuration_GetForwarder(config), symbolic, &control->address.v6.as_in6addr,
             &control->port, control->interfaceName, 0);
       }
       break;
@@ -522,12 +522,12 @@ struct iovec *configurationListeners_AddPunting(Configuration *config,
   bool success = false;
 
   if (control->addressType == ADDR_INET) {
-    Address *address = addressFromInaddr4Port(&control->address.ipv4, &port);
+    Address *address = addressFromInaddr4Port(&control->address.v4.as_u32, &port);
     Punting *punting = puntingCreate(symbolicOrConnid, address, len);
     success = _AddPuntingInet(config, punting, ingressId);
     addressDestroy(&address);
   } else if (control->addressType == ADDR_INET6) {
-    Address *address = addressFromInaddr6Port(&control->address.ipv6, &port);
+    Address *address = addressFromInaddr6Port(&control->address.v6.as_in6addr, &port);
     Punting *punting = puntingCreate(symbolicOrConnid, address, len);
     success = _AddPuntingInet6(config, punting, ingressId);
     addressDestroy(&address);
index eaa680b..e5af5a2 100644 (file)
@@ -228,15 +228,15 @@ static CommandReturn _controlAddConnection_CreateTunnel(
       parcMemory_AllocateAndClear(sizeof(add_connection_command));
 
   // check and set IP addresses
-  if (inet_pton(AF_INET, remote_ip, &addConnectionCommand->remoteIp.ipv4) ==
+  if (inet_pton(AF_INET, remote_ip, &addConnectionCommand->remoteIp.v4.as_u32) ==
           1 &&
-      inet_pton(AF_INET, local_ip, &addConnectionCommand->localIp.ipv4) == 1) {
+      inet_pton(AF_INET, local_ip, &addConnectionCommand->localIp.v4.as_u32) == 1) {
     addConnectionCommand->ipType = ADDR_INET;
 
   } else if (inet_pton(AF_INET6, remote_ip,
-                       &addConnectionCommand->remoteIp.ipv6) == 1 &&
+                       &addConnectionCommand->remoteIp.v6.as_in6addr) == 1 &&
              inet_pton(AF_INET6, local_ip,
-                       &addConnectionCommand->localIp.ipv6) == 1) {
+                       &addConnectionCommand->localIp.v6.as_in6addr) == 1) {
     addConnectionCommand->ipType = ADDR_INET6;
 
   } else {
index 1a94ff2..d4537b8 100644 (file)
@@ -106,11 +106,10 @@ static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops,
       parcMemory_AllocateAndClear(sizeof(add_listener_command));
 
   // check and set IP address
-  if (inet_pton(AF_INET, addr, &addListenerCommand->address.ipv4) == 1) {
+  if (inet_pton(AF_INET, addr, &addListenerCommand->address.v4.as_u32) == 1) {
     addListenerCommand->addressType = ADDR_INET;
 
-  } else if (inet_pton(AF_INET6, addr, &addListenerCommand->address.ipv6) ==
-             1) {
+  } else if (inet_pton(AF_INET6, addr, &addListenerCommand->address.v6.as_in6addr) == 1) {
     addListenerCommand->addressType = ADDR_INET6;
 
   } else {
index 9bca335..2912044 100644 (file)
@@ -104,7 +104,7 @@ static CommandReturn _controlAddPolicy_Execute(CommandParser *parser,
       parcMemory_AllocateAndClear(sizeof(add_policy_command));
 
   // check and set IP address
-  if (inet_pton(AF_INET, addr, &addPolicyCommand->address.ipv4) == 1) {
+  if (inet_pton(AF_INET, addr, &addPolicyCommand->address.v4.as_u32) == 1) {
     if (len > 32) {
       printf("ERROR: exceeded INET mask length, max=32\n");
       parcMemory_Deallocate(&addPolicyCommand);
@@ -112,7 +112,7 @@ static CommandReturn _controlAddPolicy_Execute(CommandParser *parser,
       return CommandReturn_Failure;
     }
     addPolicyCommand->addressType = ADDR_INET;
-  } else if (inet_pton(AF_INET6, addr, &addPolicyCommand->address.ipv6) == 1) {
+  } else if (inet_pton(AF_INET6, addr, &addPolicyCommand->address.v6.as_in6addr) == 1) {
     if (len > 128) {
       printf("ERROR: exceeded INET6 mask length, max=128\n");
       parcMemory_Deallocate(&addPolicyCommand);
index ff441f7..e3fb57c 100644 (file)
@@ -109,7 +109,7 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
       parcMemory_AllocateAndClear(sizeof(add_punting_command));
 
   // check and set IP address
-  if (inet_pton(AF_INET, addr, &addPuntingCommand->address.ipv4) == 1) {
+  if (inet_pton(AF_INET, addr, &addPuntingCommand->address.v4.as_u32) == 1) {
     if (len > 32) {
       printf("ERROR: exceeded INET mask length, max=32\n");
       parcMemory_Deallocate(&addPuntingCommand);
@@ -117,7 +117,7 @@ static CommandReturn _controlAddPunting_Execute(CommandParser *parser,
       return CommandReturn_Failure;
     }
     addPuntingCommand->addressType = ADDR_INET;
-  } else if (inet_pton(AF_INET6, addr, &addPuntingCommand->address.ipv6) == 1) {
+  } else if (inet_pton(AF_INET6, addr, &addPuntingCommand->address.v6.as_in6addr) == 1) {
     if (len > 128) {
       printf("ERROR: exceeded INET6 mask length, max=128\n");
       parcMemory_Deallocate(&addPuntingCommand);
index 086cf3a..8a1adf6 100644 (file)
@@ -113,7 +113,7 @@ static CommandReturn _controlAddRoute_Execute(CommandParser *parser,
       parcMemory_AllocateAndClear(sizeof(add_route_command));
 
   // check and set IP address
-  if (inet_pton(AF_INET, addr, &addRouteCommand->address.ipv4) == 1) {
+  if (inet_pton(AF_INET, addr, &addRouteCommand->address.v4.as_u32) == 1) {
     if (len > 32) {
       printf("ERROR: exceeded INET mask length, max=32\n");
       parcMemory_Deallocate(&addRouteCommand);
@@ -121,7 +121,7 @@ static CommandReturn _controlAddRoute_Execute(CommandParser *parser,
       return CommandReturn_Failure;
     }
     addRouteCommand->addressType = ADDR_INET;
-  } else if (inet_pton(AF_INET6, addr, &addRouteCommand->address.ipv6) == 1) {
+  } else if (inet_pton(AF_INET6, addr, &addRouteCommand->address.v6.as_in6addr) == 1) {
     if (len > 128) {
       printf("ERROR: exceeded INET6 mask length, max=128\n");
       parcMemory_Deallocate(&addRouteCommand);
index c70d8ba..9aff68c 100644 (file)
@@ -69,7 +69,6 @@ static CommandReturn _controlListPolicies_HelpExecute(CommandParser *parser,
 
 #define MAXSZ_STR_STAT 10
 #define MAXSZ_APP_NAME 25
-#define MAXSZ_PREFIX 25
 
 typedef struct {
   #define _(x, y) char x[MAXSZ_POLICY_TAG_STATE];
index 5102038..bd2e6e6 100644 (file)
@@ -96,7 +96,7 @@ static CommandReturn _controlRemovePolicy_Execute(CommandParser *parser,
       parcMemory_AllocateAndClear(sizeof(remove_policy_command));
 
   // check and set IP address
-  if (inet_pton(AF_INET, addr, &removePolicyCommand->address.ipv4) == 1) {
+  if (inet_pton(AF_INET, addr, &removePolicyCommand->address.v4.as_u32) == 1) {
     if (len > 32) {
       printf("ERROR: exceeded INET mask length, max=32\n");
       parcMemory_Deallocate(&removePolicyCommand);
@@ -104,7 +104,7 @@ static CommandReturn _controlRemovePolicy_Execute(CommandParser *parser,
       return CommandReturn_Failure;
     }
     removePolicyCommand->addressType = ADDR_INET;
-  } else if (inet_pton(AF_INET6, addr, &removePolicyCommand->address.ipv6) ==
+  } else if (inet_pton(AF_INET6, addr, &removePolicyCommand->address.v6.as_in6addr) ==
              1) {
     if (len > 128) {
       printf("ERROR: exceeded INET6 mask length, max=128\n");
index 0626886..0f46211 100644 (file)
@@ -104,7 +104,7 @@ static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
       parcMemory_AllocateAndClear(sizeof(remove_route_command));
 
   // check and set IP address
-  if (inet_pton(AF_INET, addr, &removeRouteCommand->address.ipv4) == 1) {
+  if (inet_pton(AF_INET, addr, &removeRouteCommand->address.v4.as_u32) == 1) {
     if (len > 32) {
       printf("ERROR: exceeded INET mask length, max=32\n");
       parcMemory_Deallocate(&removeRouteCommand);
@@ -112,7 +112,7 @@ static CommandReturn _controlRemoveRoute_Execute(CommandParser *parser,
       return CommandReturn_Failure;
     }
     removeRouteCommand->addressType = ADDR_INET;
-  } else if (inet_pton(AF_INET6, addr, &removeRouteCommand->address.ipv6) ==
+  } else if (inet_pton(AF_INET6, addr, &removeRouteCommand->address.v6.as_in6addr) ==
              1) {
     if (len > 128) {
       printf("ERROR: exceeded INET6 mask length, max=128\n");
index b296871..d8b326f 100644 (file)
@@ -123,7 +123,7 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
       parcMemory_AllocateAndClear(sizeof(set_strategy_command));
 
   // check and set IP address
-  if (inet_pton(AF_INET, addr, &setStrategyCommand->address.ipv4) == 1) {
+  if (inet_pton(AF_INET, addr, &setStrategyCommand->address.v4.as_u32) == 1) {
     if (len == UINT32_MAX) {
       printf("Netmask not specified: set to 32 by default\n");
       len = 32;
@@ -134,7 +134,7 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
       return CommandReturn_Failure;
     }
     setStrategyCommand->addressType = ADDR_INET;
-  } else if (inet_pton(AF_INET6, addr, &setStrategyCommand->address.ipv6) ==
+  } else if (inet_pton(AF_INET6, addr, &setStrategyCommand->address.v6.as_in6addr) ==
              1) {
     if (len == UINT32_MAX) {
       printf("Netmask not specified: set to 128 by default\n");
index f4ea7db..7ef3fcc 100644 (file)
@@ -112,15 +112,15 @@ Name *name_CreateFromPacket(const uint8_t *packet, MessagePacketType type) {
   return name;
 }
 
-Name *name_CreateFromAddress(address_type addressType, union commandAddr addr,
+Name *name_CreateFromAddress(address_type addressType, ip_address_t addr,
                              uint8_t len) {
   Name *name = parcMemory_AllocateAndClear(sizeof(Name));
   parcAssertNotNull(name, "parcMemory_AllocateAndClear(%zu) returned NULL",
                     sizeof(Name));
   if (addressType == ADDR_INET) {
-    name->content_name = nameBitvector_CreateFromInAddr(addr.ipv4, len);
+    name->content_name = nameBitvector_CreateFromInAddr(addr.v4.as_u32, len);
   } else if (addressType == ADDR_INET6) {
-    name->content_name = nameBitvector_CreateFromIn6Addr(&addr.ipv6, len);
+    name->content_name = nameBitvector_CreateFromIn6Addr(&addr.v6.as_in6addr, len);
   } else {
     parcTrapNotImplemented("Unkown packet type");
   }
index f2ae1f6..29c8439 100644 (file)
@@ -93,7 +93,7 @@ void name_setLen(Name *name, uint8_t len);
  * Creates a name from a Address
  *
  */
-Name *name_CreateFromAddress(address_type addressType, union commandAddr addr,
+Name *name_CreateFromAddress(address_type addressType, ip_address_t addr,
                              uint8_t len);
 
 #ifdef WITH_POLICY
index 9a73435..ab459b1 100644 (file)
@@ -266,7 +266,7 @@ void nameBitvector_clear(NameBitvector *a, uint8_t start_from){
 int nameBitvector_ToIPAddress(const NameBitvector *name,
                               ip_prefix_t *prefix) {
   if (name->IPversion == IPv4_TYPE) {
-    struct in_addr *addr = (struct in_addr *)(&prefix->address.buffer);
+    struct in_addr *addr = (struct in_addr *)(&prefix->address.v4.buffer);
     prefix->family = AF_INET;
     prefix->len = IPV4_ADDR_LEN_BITS;
 
@@ -283,7 +283,7 @@ int nameBitvector_ToIPAddress(const NameBitvector *name,
     addr->s_addr = (addr->s_addr | addr_1);
 
   } else {
-    struct in6_addr *addr = (struct in6_addr *)(&prefix->address.buffer);
+    struct in6_addr *addr = (struct in6_addr *)(&prefix->address.v6.buffer);
     prefix->family = AF_INET6;
     prefix->len = name->len;  // IPV6_ADDR_LEN_BITS;
 
index 28cf6b1..1aaa3ac 100644 (file)
@@ -58,7 +58,7 @@ struct fib_entry {
   const Forwarder * forwarder;
   policy_t policy;
   policy_counters_t policy_counters;
-  NumberSet *available_nexthops;
+//  NumberSet *available_nexthops;
 #ifdef WITH_MAPME
   /* In case of no multipath, this stores the previous decision taken by policy */
   unsigned previous_nexthop;
index 9663603..8bfc438 100644 (file)
@@ -574,7 +574,7 @@ int _nl_get_ip_addr(uint32_t interface_id, uint8_t address_family,
     if (address_family == AF_INET6) {
       if ((payload->ifa_index == interface_id) &&
           (payload->ifa_prefixlen < IPV6_ADDR_LEN * 8)) {
-        memcpy(prefix->address.buffer, RTA_DATA(payload + 1), IPV6_ADDR_LEN);
+        memcpy(prefix->address.v6.buffer, RTA_DATA(payload + 1), IPV6_ADDR_LEN);
         prefix->family = AF_INET6;
         prefix->len = IPV6_ADDR_LEN_BITS;
         return HICN_SOCKET_ERROR_NONE;
@@ -582,7 +582,7 @@ int _nl_get_ip_addr(uint32_t interface_id, uint8_t address_family,
     } else if (address_family == AF_INET) {
       if ((payload->ifa_index == interface_id) &&
           (payload->ifa_prefixlen < IPV4_ADDR_LEN * 8)) {
-        memcpy(prefix->address.buffer, RTA_DATA(payload + 1), IPV4_ADDR_LEN);
+        memcpy(prefix->address.v4.buffer, RTA_DATA(payload + 1), IPV4_ADDR_LEN);
         prefix->family = AF_INET;
         prefix->len = IPV4_ADDR_LEN_BITS;
         return HICN_SOCKET_ERROR_NONE;
@@ -621,10 +621,13 @@ int _nl_set_ip_addr(uint32_t interface_id, ip_prefix_t *prefix) {
   /* Set attributes = length/type/value */
   struct rtattr ifa_address = {RTA_LENGTH(ip_address_len(prefix->family)),
                                IFA_ADDRESS};
-  struct iovec iov[] = {
+  const void * address = ip_address_get_buffer(&prefix->address, prefix->family);
+  if (!address)
+      goto ERR_ADDRESS;
+  const struct iovec iov[] = {
       {&msg, sizeof(msg)},
       {&ifa_address, sizeof(ifa_address)},
-      {(void *)&prefix->address.buffer, sizeof(prefix->address.buffer)},
+      {(void*)address, ip_address_len(prefix->family)},
   };
   msg.hdr.nlmsg_len = iov_length(iov, ARRAY_SIZE(iov));
 
@@ -658,6 +661,7 @@ ERR_NL:
 ERR_RECV:
 ERR_SEND:
 ERR_SOCKET:
+ERR_ADDRESS:
   return -1;
 }
 
@@ -989,11 +993,14 @@ int _nl_del_lo_route(const ip_prefix_t *prefix) {
   uint32_t one = 1;
   struct rtattr a_dst = {RTA_LENGTH(ip_address_len(prefix->family)), RTA_DST};
   struct rtattr a_ifid_lo = {RTA_LENGTH(sizeof(uint32_t)), RTA_OIF};
-  struct iovec iov[] = {
+  const void * address = ip_address_get_buffer(&prefix->address, prefix->family);
+  if (!address)
+      goto ERR;
+  const struct iovec iov[] = {
       {&msg, sizeof(msg)},
       /* Ip address */
       {&a_dst, sizeof(a_dst)},
-      {(void *)&prefix->address.buffer, ip_address_len(prefix->family)},
+      {(void*)address, ip_address_len(prefix->family)},
       /* Interface id */
       {&a_ifid_lo, sizeof(a_ifid_lo)},
       {&one, sizeof(one)}};
@@ -1151,12 +1158,16 @@ int _nl_add_neigh_proxy(const ip_prefix_t *prefix,
   /* Message attributes = length/type/value */
   struct rtattr a_dst = {RTA_LENGTH(ip_address_len(prefix->family)), NDA_DST};
 
+  const void * address = ip_address_get_buffer(&prefix->address, prefix->family);
+  if (!address)
+      goto ERR;
+
   /* Iovec describing the packets */
-  struct iovec iov[] = {
+  const struct iovec iov[] = {
       {&msg, sizeof(msg)},
       /* Ip address */
       {&a_dst, sizeof(a_dst)},
-      {(void *)&prefix->address.buffer, sizeof(prefix->address.buffer)},
+      {(void*)address, ip_address_len(prefix->family)},
   };
   msg.hdr.nlmsg_len = iov_length(iov, ARRAY_SIZE(iov));
 
@@ -1229,12 +1240,16 @@ int _nl_add_in_route_table(const ip_prefix_t *prefix,
   struct rtattr a_dst = {RTA_LENGTH(ip_address_len(prefix->family)), RTA_DST};
   struct rtattr a_oif = {RTA_LENGTH(sizeof(uint32_t)), RTA_OIF};
 
+  const void * address = ip_address_get_buffer(&prefix->address, prefix->family);
+  if (!address)
+      goto ERR;
+
   /* Iovec describing the packets */
-  struct iovec iov[] = {
+  const struct iovec iov[] = {
       {&msg, sizeof(msg)},
       /* Destination prefix / ip address */
       {&a_dst, sizeof(a_dst)},
-      {(void *)&prefix->address.buffer, ip_address_len(prefix->family)},
+      {(void*)address, ip_address_len(prefix->family)},
       /* Output interface */
       {&a_oif, sizeof(a_oif)},
       {(void *)&interface_id, sizeof(uint32_t)},
@@ -1331,12 +1346,15 @@ int _nl_add_prio_rule(const ip_prefix_t *prefix, uint8_t address_family,
     struct rtattr a_src = {RTA_LENGTH(ip_address_len(prefix->family)), FRA_SRC};
     struct rtattr a_prio = {RTA_LENGTH(sizeof(uint32_t)), FRA_PRIORITY};
 
+    const void * address = ip_address_get_buffer(&prefix->address, prefix->family);
+    if (!address)
+        goto ERR;
     /* Iovec describing the packets */
-    struct iovec iov[] = {
+    const struct iovec iov[] = {
         {&msg, sizeof(msg)},
         /* Source prefix / prefix */
         {&a_src, sizeof(a_src)},
-        {(void *)&prefix->address.buffer, ip_address_len(prefix->family)},
+        {(void*)address, ip_address_len(prefix->family)},
         /* Priority */
         {&a_prio, sizeof(a_prio)},
         {(void *)&priority, sizeof(uint32_t)},
@@ -1432,12 +1450,16 @@ int _nl_del_prio_rule(const ip_prefix_t *prefix, uint8_t address_family,
     struct rtattr a_src = {RTA_LENGTH(ip_address_len(prefix->family)), FRA_SRC};
     struct rtattr a_prio = {RTA_LENGTH(sizeof(uint32_t)), FRA_PRIORITY};
 
+    const void * address = ip_address_get_buffer(&prefix->address, prefix->family);
+    if (!address)
+        goto ERR;
+
     /* Iovec describing the packets */
-    struct iovec iov[] = {
+    const struct iovec iov[] = {
         {&msg, sizeof(msg)},
         /* Source prefix / prefix */
         {&a_src, sizeof(a_src)},
-        {(void *)&prefix->address.buffer, ip_address_len(prefix->family)},
+        {(void*)address, ip_address_len(prefix->family)},
         /* Priority */
         {&a_prio, sizeof(a_prio)},
         {(void *)&priority, sizeof(uint32_t)},
index 60d4cd5..a5bc15e 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 
+#include <hicn/util/ip_address.h>
 #ifdef WITH_POLICY
 #include <hicn/policy.h>
 #endif /* WITH_POLICY */
 typedef struct in6_addr ipv6_addr_t;
 typedef uint32_t ipv4_addr_t;
 
-union commandAddr {
-  ipv4_addr_t ipv4;
-  ipv6_addr_t ipv6;
-};
-
 typedef enum {
   REQUEST_LIGHT = 0xc0, // this is a command
   RESPONSE_LIGHT,
@@ -119,7 +115,7 @@ typedef enum { ETHER_MODE, IP_MODE, HICN_MODE } listener_mode;
 typedef struct {
   char symbolic[SYMBOLIC_NAME_LEN];
   char interfaceName[SYMBOLIC_NAME_LEN];
-  union commandAddr address;
+  ip_address_t address;
   uint16_t port;
   // uint16_t etherType;
   uint8_t addressType;
@@ -134,8 +130,8 @@ typedef struct {
 typedef struct {
   char symbolic[SYMBOLIC_NAME_LEN];
   //char interfaceName[SYMBOLIC_NAME_LEN];
-  union commandAddr remoteIp;
-  union commandAddr localIp;
+  ip_address_t remoteIp;
+  ip_address_t localIp;
   uint16_t remotePort;
   uint16_t localPort;
   uint8_t ipType;
@@ -180,7 +176,7 @@ typedef struct {
 
 typedef struct {
   char symbolicOrConnid[SYMBOLIC_NAME_LEN];
-  union commandAddr address;
+  ip_address_t address;
   uint16_t cost;
   uint8_t addressType;
   uint8_t len;
@@ -191,7 +187,7 @@ typedef struct {
 //==========  [04]  LIST ROUTE    ==========
 
 typedef struct {
-  union commandAddr address;
+  ip_address_t address;
   uint32_t connid;
   uint16_t cost;
   uint8_t addressType;
@@ -216,7 +212,7 @@ typedef struct {
 
 typedef struct {
   char symbolicOrConnid[SYMBOLIC_NAME_LEN];
-  union commandAddr address;
+  ip_address_t address;
   uint8_t addressType;
   uint8_t len;
 } remove_route_command;
@@ -250,7 +246,7 @@ typedef enum {
 } strategy_type;
 
 typedef struct {
-  union commandAddr address;
+  ip_address_t address;
   uint8_t strategyType;
   uint8_t addressType;
   uint8_t len;
@@ -271,7 +267,7 @@ typedef struct {
 
 typedef struct {
   char symbolicOrConnid[SYMBOLIC_NAME_LEN];
-  union commandAddr address;
+  ip_address_t address;
   uint8_t addressType;
   uint8_t len;
 } add_punting_command;
@@ -281,7 +277,7 @@ typedef struct {
 //==========  [13]  LIST LISTENER    ==========
 
 typedef struct {
-  union commandAddr address;
+  ip_address_t address;
   char listenerName[SYMBOLIC_NAME_LEN];
   char interfaceName[SYMBOLIC_NAME_LEN];
   uint32_t connid;
@@ -311,27 +307,27 @@ typedef struct {
 typedef struct {
   char symbolicOrConnid[SYMBOLIC_NAME_LEN];
   uint8_t admin_state;
-  uint16_t pad16;
+  uint8_t pad8[3];
 } connection_set_admin_state_command;
 
 #ifdef WITH_POLICY
 
 typedef struct {
-  union commandAddr address;
+  ip_address_t address;
   uint8_t addressType;
   uint8_t len;
   policy_t policy;
 } add_policy_command;
 
 typedef struct {
-  union commandAddr address;
+  ip_address_t address;
   uint8_t addressType;
   uint8_t len;
   policy_t policy;
 } list_policies_command;
 
 typedef struct {
-  union commandAddr address;
+  ip_address_t address;
   uint8_t addressType;
   uint8_t len;
 } remove_policy_command;
@@ -358,7 +354,7 @@ static inline int payloadLengthDaemon(command_id id) {
     case ADD_ROUTE:
       return sizeof(add_route_command);
     case LIST_ROUTES:
-      return 0;  // list rout`es: payload always 0
+      return 0;  // list routes: payload always 0
     case REMOVE_CONNECTION:
       return sizeof(remove_connection_command);
     case REMOVE_LISTENER:
index 93a3efd..36596f9 100644 (file)
@@ -131,18 +131,18 @@ char *utils_BuildStringFromInet6(struct in6_addr *addr6, in_port_t *port) {
 }
 
 char *utils_CommandAddressToString(address_type addressType,
-                                   union commandAddr *address,
+                                   ip_address_t *address,
                                    in_port_t *port) {
   char *result;
 
   switch (addressType) {
     case ADDR_INET: {
-      result = utils_BuildStringFromInet(&address->ipv4, port);
+      result = utils_BuildStringFromInet(&address->v4.as_u32, port);
       break;
     }
 
     case ADDR_INET6: {
-      result = utils_BuildStringFromInet6(&address->ipv6, port);
+      result = utils_BuildStringFromInet6(&address->v6.as_in6addr, port);
       break;
     }
 
@@ -217,7 +217,7 @@ struct iovec *utils_SendRequest(ControlState *state, command_id command,
 }
 
 const char *utils_PrefixLenToString(address_type addressType,
-                                    union commandAddr *address,
+                                    ip_address_t *address,
                                     uint8_t *prefixLen) {
   char len[4];  // max size + 1
   sprintf(len, "%u", (unsigned)*prefixLen);
index ce8cb4e..1fe88e6 100644 (file)
@@ -50,7 +50,7 @@ struct iovec *utils_CreateNack(header_control_message *header, void *payload,
  *to be a `in_addr_t * or `a struct in6_addr *.
  */
 char *utils_CommandAddressToString(address_type addressType,
-                                   union commandAddr *address, in_port_t *port);
+                                   ip_address_t *address, in_port_t *port);
 
 /**
  *Given a command payload, it generates the header and send the request to the
@@ -64,7 +64,7 @@ struct iovec *utils_SendRequest(ControlState *state, command_id command,
  *form [add]:[port]/[len].
  */
 const char *utils_PrefixLenToString(address_type addressType,
-                                    union commandAddr *address,
+                                    ip_address_t *address,
                                     uint8_t *prefixLen);
 
-#endif
\ No newline at end of file
+#endif
index e39d085..33c0d9a 100644 (file)
@@ -69,6 +69,7 @@ typedef union {
         u32 pad[3];
         union {
                 struct in_addr as_inaddr;
+                u8 buffer[4];
                 u8 as_u8[4];
                 u16 as_u16[2];
                 u32 as_u32;
@@ -76,16 +77,19 @@ typedef union {
     };
     union {
         struct in6_addr as_in6addr;
+        u8 buffer[16];
         u8 as_u8[16];
         u16 as_u16[8];
         u32 as_u32[4];
         u64 as_u64[2];
     } v6;
+#if 0 /* removed as prone to error due to IPv4 padding */
     u8 buffer[IP_MAX_ADDR_LEN];
     u8 as_u8[IP_MAX_ADDR_LEN];
     u16 as_u16[IP_MAX_ADDR_LEN >> 1];
     u32 as_u32[IP_MAX_ADDR_LEN >> 2];
     u64 as_u64[IP_MAX_ADDR_LEN >> 3];
+#endif
 } ip_address_t;
 
 #define MAXSZ_IP4_ADDRESS_ INET_ADDRSTRLEN - 1
@@ -125,6 +129,7 @@ extern const ip_address_t IP_ADDRESS_EMPTY;
 
 int ip_address_get_family (const char * ip_address);
 int ip_address_len (int family);
+const u8 * ip_address_get_buffer(const ip_address_t * ip_address, int family);
 int ip_address_ntop (const ip_address_t * ip_address, char *dst,
         const size_t len, int family);
 int ip_address_pton (const char *ip_address_str, ip_address_t * ip_address);
index 8ec4c83..615175e 100644 (file)
@@ -323,25 +323,26 @@ int
 hicn_packet_get_locator (hicn_format_t format, const hicn_header_t * h,
                         ip_address_t * address, bool is_interest)
 {
-  const void *locator;
   int is_ipv4 = (format & HFO_INET);
   int is_ipv6 = (format & HFO_INET6) >> 1;
 
   if (is_ipv4)
     {
-      locator = is_interest ? &h->v4.ip.saddr : &h->v4.ip.daddr;
+      address->v4.as_inaddr = is_interest
+          ? h->v4.ip.saddr.as_inaddr
+          : h->v4.ip.daddr.as_inaddr;
     }
   else if (is_ipv6)
     {
-      locator = is_interest ? &h->v6.ip.saddr : &h->v6.ip.daddr;
+      address->v6.as_in6addr = is_interest
+          ? h->v6.ip.saddr.as_in6addr
+          : h->v6.ip.daddr.as_in6addr;
     }
   else
     {
       return HICN_LIB_ERROR_NOT_IMPLEMENTED;
     }
 
-  memcpy (address->as_u8, locator, is_ipv4 ? IPV4_ADDR_LEN : IPV6_ADDR_LEN);
-
   return HICN_LIB_ERROR_NONE;
 }
 
@@ -349,25 +350,28 @@ int
 hicn_packet_set_locator (hicn_format_t format, hicn_header_t * h,
                         const ip_address_t * address, bool is_interest)
 {
-  void *locator;
   int is_ipv4 = (format & HFO_INET);
   int is_ipv6 = (format & HFO_INET6) >> 1;
 
   if (is_ipv6)
     {
-      locator = is_interest ? &h->v6.ip.saddr : &h->v6.ip.daddr;
+        if (is_interest)
+            h->v6.ip.saddr.as_in6addr = address->v6.as_in6addr;
+        else
+            h->v6.ip.daddr.as_in6addr = address->v6.as_in6addr;
     }
   else if (is_ipv4)
     {
-      locator = is_interest ? &h->v4.ip.saddr : &h->v4.ip.daddr;
+        if (is_interest)
+            h->v4.ip.saddr.as_inaddr = address->v4.as_inaddr;
+        else
+            h->v4.ip.daddr.as_inaddr = address->v4.as_inaddr;
     }
   else
     {
       return HICN_LIB_ERROR_INVALID_PARAMETER;
     }
 
-  memcpy (locator, address->as_u8, is_ipv4 ? IPV4_ADDR_LEN : IPV6_ADDR_LEN);
-
   return HICN_LIB_ERROR_NONE;
 }
 
index 2e98a35..a623341 100644 (file)
  */
 
 #ifndef _WIN32
-#include <arpa/inet.h>         // inet_ptin
+#include <arpa/inet.h>          // inet_ptin
 #endif
 #include <errno.h>
 #include <stdio.h>
-#include <stdlib.h>            // strtoul
-#include <string.h>            // memcpy
+#include <stdlib.h>             // strtoul
+#include <string.h>             // memcpy
 
 #include <hicn/common.h>
 #include <hicn/error.h>
@@ -42,16 +42,16 @@ hicn_name_create (const char *ip_address, u32 id, hicn_name_t * name)
     {
     case AF_INET:
       if (name->type == HNT_UNSPEC)
-       {
-         name->type = HNT_CONTIGUOUS_V4;
-       }
+        {
+          name->type = HNT_CONTIGUOUS_V4;
+        }
       name->len = IPV4_ADDR_LEN;
       break;
     case AF_INET6:
       if (name->type == HNT_UNSPEC)
-       {
-         name->type = HNT_CONTIGUOUS_V6;
-       }
+        {
+          name->type = HNT_CONTIGUOUS_V6;
+        }
       name->len = IPV6_ADDR_LEN;
       break;
     default:
@@ -75,28 +75,25 @@ hicn_name_create (const char *ip_address, u32 id, hicn_name_t * name)
 
 int
 hicn_name_create_from_ip_prefix (const ip_prefix_t * prefix, u32 id,
-                                 hicn_name_t * name)
+                                  hicn_name_t * name)
 {
   switch (prefix->family)
     {
-    case AF_INET:
-           name->type = HNT_CONTIGUOUS_V4;
-      break;
-    case AF_INET6:
-           name->type = HNT_CONTIGUOUS_V6;
-      break;
-    default:
-      return HICN_LIB_ERROR_INVALID_IP_ADDRESS;
+      case AF_INET:
+        name->type = HNT_CONTIGUOUS_V4;
+        memcpy (name->buffer, prefix->address.v4.buffer,
+                ip_address_len(prefix->family));
+        break;
+      case AF_INET6:
+        name->type = HNT_CONTIGUOUS_V6;
+        memcpy (name->buffer, prefix->address.v6.buffer,
+                ip_address_len(prefix->family));
+        break;
+      default:
+        return HICN_LIB_ERROR_INVALID_IP_ADDRESS;
     }
 
   name->len = (u8) (prefix->len);
-  if ((name->type != HNT_CONTIGUOUS_V4) && (name->type != HNT_CONTIGUOUS_V6))
-    {
-      return HICN_LIB_ERROR_NOT_IMPLEMENTED;
-    }
-
-  memcpy (name->buffer, prefix->address.buffer,
-          ip_address_len(prefix->family));
   *(u32 *) (name->buffer + name->len) = id;
 
   return HICN_LIB_ERROR_NONE;
@@ -110,14 +107,14 @@ hicn_name_get_length (const hicn_name_t * name)
 
 int
 hicn_name_compare (const hicn_name_t * name_1, const hicn_name_t * name_2,
-                  bool consider_segment)
+                   bool consider_segment)
 {
   hicn_name_t *name1 = (hicn_name_t *) name_1;
   hicn_name_t *name2 = (hicn_name_t *) name_2;
 
   if ((name1->type == HNT_CONTIGUOUS_V4 && name2->type == HNT_CONTIGUOUS_V6)
       || (name1->type == HNT_CONTIGUOUS_V6
-         && name2->type == HNT_CONTIGUOUS_V4))
+          && name2->type == HNT_CONTIGUOUS_V4))
     {
       return -1;
     }
@@ -227,10 +224,10 @@ hicn_name_hash (const hicn_name_t * name, u32 * hash)
     case HNT_IOV_V4:
     case HNT_IOV_V6:
       *hash =
-       hash32 (name->iov.buffers[0].iov_base, name->iov.buffers[0].iov_len);
+        hash32 (name->iov.buffers[0].iov_base, name->iov.buffers[0].iov_len);
       *hash =
-       cumulative_hash32 (name->iov.buffers[1].iov_base,
-                          name->iov.buffers[1].iov_len, *hash);
+        cumulative_hash32 (name->iov.buffers[1].iov_base,
+                           name->iov.buffers[1].iov_len, *hash);
       break;
     default:
       return HICN_LIB_ERROR_NOT_IMPLEMENTED;
@@ -257,11 +254,11 @@ hicn_name_copy (hicn_name_t * dst, const hicn_name_t * src)
     case HNT_IOV_V4:
     case HNT_IOV_V6:
       dst->type =
-       src->type == HNT_IOV_V4 ? HNT_CONTIGUOUS_V4 : HNT_CONTIGUOUS_V6;
+        src->type == HNT_IOV_V4 ? HNT_CONTIGUOUS_V4 : HNT_CONTIGUOUS_V6;
       memcpy (dst->buffer, src->iov.buffers[0].iov_base,
-             src->iov.buffers[0].iov_len);
+              src->iov.buffers[0].iov_len);
       memcpy (dst->buffer + src->iov.buffers[0].iov_len,
-             src->iov.buffers[1].iov_base, src->iov.buffers[1].iov_len);
+              src->iov.buffers[1].iov_base, src->iov.buffers[1].iov_len);
       break;
     default:
       return HICN_LIB_ERROR_NOT_IMPLEMENTED;
@@ -272,7 +269,7 @@ hicn_name_copy (hicn_name_t * dst, const hicn_name_t * src)
 
 int
 hicn_name_copy_to_destination (u8 * dst, const hicn_name_t * src,
-                              bool copy_suffix)
+                               bool copy_suffix)
 {
   size_t length;
 
@@ -280,34 +277,34 @@ hicn_name_copy_to_destination (u8 * dst, const hicn_name_t * src,
     {
     case HNT_CONTIGUOUS_V4:
       if (copy_suffix)
-       {
-         length = HICN_V4_NAME_LEN;
-       }
+        {
+          length = HICN_V4_NAME_LEN;
+        }
       else
-       {
-         length = IPV4_ADDR_LEN;
-       }
+        {
+          length = IPV4_ADDR_LEN;
+        }
       memcpy (dst, src->buffer, length);
       break;
     case HNT_CONTIGUOUS_V6:
       if (copy_suffix)
-       {
-         length = HICN_V6_NAME_LEN;
-       }
+        {
+          length = HICN_V6_NAME_LEN;
+        }
       else
-       {
-         length = IPV6_ADDR_LEN;
-       }
+        {
+          length = IPV6_ADDR_LEN;
+        }
       memcpy (dst, src->buffer, length);
       break;
     case HNT_IOV_V4:
     case HNT_IOV_V6:
       memcpy (dst, src->iov.buffers[0].iov_base, src->iov.buffers[0].iov_len);
       if (copy_suffix)
-       {
-         memcpy (dst + src->iov.buffers[0].iov_len,
-                 src->iov.buffers[1].iov_base, src->iov.buffers[1].iov_len);
-       }
+        {
+          memcpy (dst + src->iov.buffers[0].iov_len,
+                  src->iov.buffers[1].iov_base, src->iov.buffers[1].iov_len);
+        }
       break;
     default:
       return HICN_LIB_ERROR_NOT_IMPLEMENTED;
@@ -351,7 +348,7 @@ hicn_name_set_seq_number (hicn_name_t * name, u32 seq_number)
 
 int
 hicn_name_to_sockaddr_address (const hicn_name_t * name,
-                              struct sockaddr *ip_address)
+                               struct sockaddr *ip_address)
 {
   struct sockaddr_in6 *tmp6 = (struct sockaddr_in6 *) ip_address;
   struct sockaddr_in *tmp4 = (struct sockaddr_in *) ip_address;
@@ -369,7 +366,7 @@ hicn_name_to_sockaddr_address (const hicn_name_t * name,
       tmp6->sin6_scope_id = 0;
       tmp6->sin6_port = DUMMY_PORT;
       memcpy (&tmp6->sin6_addr, name->iov.buffers[0].iov_base,
-             name->iov.buffers[0].iov_len);
+              name->iov.buffers[0].iov_len);
       break;
     case HNT_CONTIGUOUS_V4:
       tmp4->sin_family = AF_INET;
@@ -380,7 +377,7 @@ hicn_name_to_sockaddr_address (const hicn_name_t * name,
       tmp4->sin_family = AF_INET;
       tmp4->sin_port = DUMMY_PORT;
       memcpy (&tmp4->sin_addr, name->iov.buffers[0].iov_base,
-             name->iov.buffers[0].iov_len);
+              name->iov.buffers[0].iov_len);
       break;
     default:
       return HICN_LIB_ERROR_UNEXPECTED;
@@ -395,21 +392,21 @@ hicn_name_to_ip_prefix (const hicn_name_t * name, ip_prefix_t * prefix)
   switch (name->type)
     {
     case HNT_CONTIGUOUS_V6:
-      memcpy (&prefix->address.buffer, name->buffer, IPV6_ADDR_LEN);
+      memcpy (&prefix->address.v6.buffer, name->buffer, IPV6_ADDR_LEN);
       prefix->family = AF_INET6;
       break;
     case HNT_IOV_V6:
-      memcpy (&prefix->address.buffer, name->iov.buffers[0].iov_base,
-             name->iov.buffers[0].iov_len);
+      memcpy (&prefix->address.v6.buffer, name->iov.buffers[0].iov_base,
+              name->iov.buffers[0].iov_len);
       prefix->family = AF_INET6;
       break;
     case HNT_CONTIGUOUS_V4:
-      memcpy (&prefix->address.buffer, name->buffer, IPV4_ADDR_LEN);
+      memcpy (&prefix->address.v4.buffer, name->buffer, IPV4_ADDR_LEN);
       prefix->family = AF_INET;
       break;
     case HNT_IOV_V4:
-      memcpy (&prefix->address.buffer, name->iov.buffers[0].iov_base,
-             name->iov.buffers[0].iov_len);
+      memcpy (&prefix->address.v4.buffer, name->iov.buffers[0].iov_base,
+              name->iov.buffers[0].iov_len);
       prefix->family = AF_INET;
       break;
     default:
@@ -525,16 +522,16 @@ hicn_name_get_family (const hicn_name_t * name, int *family)
 
 int
 hicn_prefix_create_from_ip_prefix (const ip_prefix_t * ip_prefix,
-                                   hicn_prefix_t * prefix)
+                                    hicn_prefix_t * prefix)
 {
   switch (ip_prefix->family)
     {
     case AF_INET:
-      prefix->name.ip4.as_u32 = ip_prefix->address.as_u32[0];
+      prefix->name.ip4.as_u32 = ip_prefix->address.v4.as_u32;
       break;
     case AF_INET6:
-      prefix->name.ip6.as_u64[0] = ip_prefix->address.as_u64[0];
-      prefix->name.ip6.as_u64[1] = ip_prefix->address.as_u64[1];
+      prefix->name.ip6.as_u64[0] = ip_prefix->address.v6.as_u64[0];
+      prefix->name.ip6.as_u64[1] = ip_prefix->address.v6.as_u64[1];
       break;
     default:
       return HICN_LIB_ERROR_INVALID_IP_ADDRESS;
index d4fbcaa..938c0e4 100644 (file)
@@ -49,7 +49,7 @@ const ip_address_t IPV6_ANY = (ip_address_t) {
 };
 
 const ip_address_t IP_ADDRESS_EMPTY = {
-    .as_u64 = { 0 },
+    .v6.as_u64 = { 0 },
 };
 
 
@@ -87,7 +87,17 @@ int
 ip_address_ntop (const ip_address_t * ip_address, char *dst, const size_t len,
                int family)
 {
-  const char * s = inet_ntop (family, ip_address->buffer, dst, len);
+  const char * s;
+  switch(family) {
+    case AF_INET:
+      s = inet_ntop (AF_INET, ip_address->v4.buffer, dst, len);
+      break;
+    case AF_INET6:
+      s = inet_ntop (AF_INET6, ip_address->v6.buffer, dst, len);
+      break;
+    default:
+      return -1;
+  }
   return (s ? 1 : -1);
 }
 
@@ -103,35 +113,39 @@ ip_address_pton (const char *ip_address_str, ip_address_t * ip_address)
 
   family = ip_address_get_family (ip_address_str);
 
-  switch (family)
-    {
-    case AF_INET6:
-      pton_fd = inet_pton (AF_INET6, ip_address_str, &ip_address->buffer);
-      break;
+  switch (family) {
     case AF_INET:
-      pton_fd = inet_pton (AF_INET, ip_address_str, &ip_address->buffer);
+      pton_fd = inet_pton (AF_INET, ip_address_str, &ip_address->v4.buffer);
+      break;
+    case AF_INET6:
+      pton_fd = inet_pton (AF_INET6, ip_address_str, &ip_address->v6.buffer);
       break;
     default:
-      goto ERR;
+      return -1;
     }
 
   //   0 = not in presentation format
   // < 0 = other error (use perror)
   if (pton_fd <= 0)
-    {
-      goto ERR;
-    }
+    return -1;
 
   return 1;
-ERR:
-  return -1;
 }
 
 int
 ip_address_snprintf(char * s, size_t size, const ip_address_t * ip_address, int family)
 {
-    size_t len = family == AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN;
-    const char * rc = inet_ntop (family, ip_address->buffer, s, len);
+    const char * rc;
+    switch(family) {
+        case AF_INET:
+            rc = inet_ntop (AF_INET, ip_address->v4.buffer, s, INET_ADDRSTRLEN);
+            break;
+        case AF_INET6:
+            rc = inet_ntop (AF_INET6, ip_address->v6.buffer, s, INET6_ADDRSTRLEN);
+            break;
+        default:
+            return -1;
+    }
     return rc ? strlen(rc) : -1;
 }
 
@@ -148,12 +162,12 @@ ip_address_to_sockaddr(const ip_address_t * ip_address,
       tmp6->sin6_family = AF_INET6;
       tmp6->sin6_port = DUMMY_PORT;
       tmp6->sin6_scope_id = 0;
-      memcpy (&tmp6->sin6_addr, ip_address->buffer, IPV6_ADDR_LEN);
+      memcpy (&tmp6->sin6_addr, ip_address->v6.buffer, IPV6_ADDR_LEN);
       break;
     case AF_INET:
       tmp4->sin_family = AF_INET;
       tmp4->sin_port = DUMMY_PORT;
-      memcpy (&tmp4->sin_addr, ip_address->buffer, IPV4_ADDR_LEN);
+      memcpy (&tmp4->sin_addr, ip_address->v4.buffer, IPV4_ADDR_LEN);
       break;
     default:
       return -1;
@@ -204,14 +218,14 @@ ip_prefix_pton (const char *ip_address_str, ip_prefix_t * ip_prefix)
           ip_prefix->len = IPV6_ADDR_LEN_BITS;
       if (ip_prefix->len > IPV6_ADDR_LEN_BITS)
        goto ERR;
-      pton_fd = inet_pton (AF_INET6, addr, &ip_prefix->address.buffer);
+      pton_fd = inet_pton (AF_INET6, addr, &ip_prefix->address.v6.buffer);
       break;
     case AF_INET:
       if (ip_prefix->len == (u8)~0)
           ip_prefix->len = IPV4_ADDR_LEN_BITS;
       if (ip_prefix->len > IPV4_ADDR_LEN_BITS)
        goto ERR;
-      pton_fd = inet_pton (AF_INET, addr, &ip_prefix->address.buffer);
+      pton_fd = inet_pton (AF_INET, addr, &ip_prefix->address.v4.buffer);
       break;
     default:
       goto ERR;
@@ -233,7 +247,17 @@ int
 ip_prefix_ntop_short(const ip_prefix_t * ip_prefix, char *dst, size_t size)
 {
   char ip_s[MAXSZ_IP_ADDRESS];
-  const char * s = inet_ntop (ip_prefix->family, ip_prefix->address.buffer, ip_s, MAXSZ_IP_ADDRESS);
+  const char * s;
+  switch(ip_prefix->family) {
+    case AF_INET:
+      s = inet_ntop (AF_INET, ip_prefix->address.v4.buffer, ip_s, MAXSZ_IP_ADDRESS);
+      break;
+    case AF_INET6:
+      s = inet_ntop (AF_INET6, ip_prefix->address.v6.buffer, ip_s, MAXSZ_IP_ADDRESS);
+      break;
+    default:
+      return -1;
+  }
   if (!s)
       return -1;
   size_t n = snprintf(dst, size, "%s", ip_s);
@@ -245,7 +269,17 @@ int
 ip_prefix_ntop(const ip_prefix_t * ip_prefix, char *dst, size_t size)
 {
   char ip_s[MAXSZ_IP_ADDRESS];
-  const char * s = inet_ntop (ip_prefix->family, ip_prefix->address.buffer, ip_s, MAXSZ_IP_ADDRESS);
+  const char * s;
+  switch(ip_prefix->family) {
+    case AF_INET:
+      s = inet_ntop (AF_INET, ip_prefix->address.v4.buffer, ip_s, MAXSZ_IP_ADDRESS);
+      break;
+    case AF_INET6:
+      s = inet_ntop (AF_INET6, ip_prefix->address.v6.buffer, ip_s, MAXSZ_IP_ADDRESS);
+      break;
+    default:
+      return -1;
+  }
   if (!s)
       return -1;
   size_t n = snprintf(dst, size, "%s/%d", ip_s, ip_prefix->len);
@@ -259,6 +293,19 @@ ip_prefix_len (const ip_prefix_t * prefix)
     return prefix->len; // ip_address_len(&prefix->address, prefix->family);
 }
 
+const u8 *
+ip_address_get_buffer(const ip_address_t * ip_address, int family)
+{
+  switch(family) {
+    case AF_INET:
+      return ip_address->v4.buffer;
+    case AF_INET6:
+      return ip_address->v6.buffer;
+    default:
+      return NULL;
+  }
+}
+
 bool
 ip_prefix_empty (const ip_prefix_t * prefix)
 {
index 9f93953..aea2f09 100644 (file)
@@ -112,7 +112,7 @@ int hicn_binary_api_register_prod_app(
   CONTEXT_SAVE(context_store, api, mp)
 
   fib_prefix_t prefix;
-  memcpy(&prefix.fp_addr.as_u64, &input_params->prefix->address.as_u64, sizeof(ip46_address_t));
+  memcpy(&prefix.fp_addr, &input_params->prefix->address, sizeof(ip46_address_t));
   prefix.fp_len = input_params->prefix->len;
   prefix.fp_proto = ip46_address_is_ip4(&prefix.fp_addr) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
   ip_prefix_encode(&prefix, &mp->prefix);
@@ -185,7 +185,7 @@ int hicn_binary_api_register_route(
 
   CONTEXT_SAVE(context_store, api, mp)
   fib_prefix_t prefix;
-  memcpy(&prefix.fp_addr.as_u64, &input_params->prefix->address.as_u64, sizeof(ip46_address_t));
+  memcpy(&prefix.fp_addr, &input_params->prefix->address, sizeof(ip46_address_t));
   prefix.fp_len = input_params->prefix->len;
   mp->face_ids[0] = clib_host_to_net_u32(input_params->face_id);
   mp->n_faces = 1;
index b7ddce7..648c0a6 100644 (file)
@@ -77,7 +77,17 @@ void Prefix::buildPrefix(std::string &prefix, uint16_t prefix_length,
     throw errors::InvalidIpAddressException();
   }
 
-  int ret = inet_pton(family, prefix.c_str(), ip_prefix_.address.buffer);
+  int ret;
+  switch (family) {
+    case AF_INET:
+        ret = inet_pton(AF_INET, prefix.c_str(), ip_prefix_.address.v4.buffer);
+        break;
+    case AF_INET6:
+        ret = inet_pton(AF_INET6, prefix.c_str(), ip_prefix_.address.v6.buffer);
+        break;
+    default:
+      throw errors::InvalidIpAddressException();
+  }
 
   if (ret != 1) {
     throw errors::InvalidIpAddressException();
@@ -147,7 +157,7 @@ Name Prefix::getName() const {
 }
 
 Prefix &Prefix::setNetwork(std::string &network) {
-  if (!inet_pton(AF_INET6, network.c_str(), ip_prefix_.address.buffer)) {
+  if (!inet_pton(AF_INET6, network.c_str(), ip_prefix_.address.v6.buffer)) {
     throw errors::RuntimeException("The network name is not valid.");
   }
 
@@ -165,8 +175,8 @@ Name Prefix::makeRandomName() const {
 
     uint32_t hash_size_bits = IPV6_ADDR_LEN_BITS - ip_prefix_.len;
     uint64_t ip_address[2];
-    memcpy(ip_address, ip_prefix_.address.buffer, sizeof(uint64_t));
-    memcpy(ip_address + 1, ip_prefix_.address.buffer + 8, sizeof(uint64_t));
+    memcpy(ip_address, ip_prefix_.address.v6.buffer, sizeof(uint64_t));
+    memcpy(ip_address + 1, ip_prefix_.address.v6.buffer + 8, sizeof(uint64_t));
     std::string network(IPV6_ADDR_LEN * 3, 0);
 
     // Let's do the magic ;)
index 598b692..17239b8 100644 (file)
@@ -102,9 +102,9 @@ void VPPForwarderInterface::consumerConnection() {
     throw errors::RuntimeException(hicn_binary_api_get_error_string(ret));
   }
 
-  std::memcpy(inet_address_.v4.as_u8, output.src4->as_u8, IPV4_ADDR_LEN);
+  std::memcpy(inet_address_.v4.as_u8, output.src4->v4.as_u8, IPV4_ADDR_LEN);
 
-  std::memcpy(inet6_address_.v6.as_u8, output.src6->as_u8, IPV6_ADDR_LEN);
+  std::memcpy(inet6_address_.v6.as_u8, output.src6->v6.as_u8, IPV6_ADDR_LEN);
 }
 
 void VPPForwarderInterface::producerConnection() {
@@ -156,9 +156,8 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) {
     // memif_id, since this function should be called after the
     // memif creation.
     input.swif = sw_if_index_;
-    input.prefix->address.as_u64[0] = addr.address.as_u64[0];
-    input.prefix->address.as_u64[1] = addr.address.as_u64[1];
-    input.prefix->family = addr.family == AF_INET6 ? AF_INET6 : AF_INET;
+    input.prefix->address = addr.address;
+    input.prefix->family = addr.family;
     input.prefix->len = addr.len;
     input.cs_reserved = content_store_reserved_;
 
@@ -169,22 +168,14 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) {
       throw errors::RuntimeException(hicn_binary_api_get_error_string(ret));
     }
 
-    if (addr.family == AF_INET6) {
-      inet6_address_.v6.as_u64[0] = output.prod_addr->v6.as_u64[0];
-      inet6_address_.v6.as_u64[1] = output.prod_addr->v6.as_u64[1];
-    } else {
-      // The ipv4 is written in the last 4 bytes of the ipv6 address, so we need
-      // to copy from the byte 12
-      inet_address_.v4.as_u32 = output.prod_addr->v4.as_u32;
-    }
+    inet6_address_ = *output.prod_addr;
 
     face_id_ = output.face_id;
   } else {
     hicn_producer_set_route_params params;
     params.prefix = &producer_prefix;
-    params.prefix->address.as_u64[0] = addr.address.as_u64[0];
-    params.prefix->address.as_u64[1] = addr.address.as_u64[1];
-    params.prefix->family = addr.family == AF_INET6 ? AF_INET6 : AF_INET;
+    params.prefix->address = addr.address;
+    params.prefix->family = addr.family;
     params.prefix->len = addr.len;
     params.face_id = face_id_;