[HICN-659] Fix udp-encap inconsistencies 98/30098/1
authorMauro Sardara <msardara@cisco.com>
Mon, 23 Nov 2020 17:28:42 +0000 (18:28 +0100)
committerMauro Sardara <msardara@cisco.com>
Mon, 23 Nov 2020 17:28:42 +0000 (18:28 +0100)
Independently of the type of tunnel, encapsulated packet
can be either v6 or v4, so we need to create 2 faces for each
version of the tunnel. Currently we are wrongly associating v4
tunnels with v4 packets and v6 tunnel with v6 packets.

Signed-off-by: Mauro Sardara <msardara@cisco.com>
Change-Id: I81e6e4b8b71ae7949d27065cc61b1b5b23db6a8d

hicn-plugin/src/route.c
libtransport/src/core/forwarder_interface.h

index b569d43..6db52f2 100644 (file)
@@ -261,6 +261,20 @@ sync_hicn_fib_entry(hicn_dpo_ctx_t *fib_entry)
   dpo_id_t temp = DPO_INVALID;
   const dpo_id_t *former_dpo = &temp;
   int index = 0;
+
+#define ADD_FACE(nh)                                                                    \
+  do {                                                                                  \
+    /* Careful, this adds a lock on the face if it exists */                            \
+    hicn_face_add(dpo, nh, sw_if, &face_id, 0);                                         \
+    vec_validate(vec_faces, index);                                                     \
+    vec_faces[index] = face_id;                                                         \
+    (index)++;                                                                          \
+                                                                                        \
+    /* Face creation can realloc load_balance_t? Seem the fib_tracking does so. */      \
+    dpo_loadbalance = fib_entry_contribute_ip_forwarding (fib_entry->fib_entry_index);  \
+    lb0 = load_balance_get(dpo_loadbalance->dpoi_index);                                \
+  } while (0)                                                                           \
+
   for (int j = 0; j < lb0->lb_n_buckets; j++) {
     const dpo_id_t * dpo = load_balance_get_bucket_i(lb0,j);
 
@@ -282,42 +296,33 @@ sync_hicn_fib_entry(hicn_dpo_ctx_t *fib_entry)
         ip_adjacency_t * adj = adj_get (dpo->dpoi_index);
         sw_if = adj->rewrite_header.sw_if_index;
         nh = get_address (&(adj->sub_type.nbr.next_hop), sw_if, fib_entry->proto);
+        ADD_FACE(nh);
       }
     else if (dpo->dpoi_type == dpo_type_udp_ip4 || dpo->dpoi_type == dpo_type_udp_ip6)
       {
         u8 proto = dpo->dpoi_type == dpo_type_udp_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
-        nh = calloc (1, sizeof(ip46_address_t));
+        ip46_address_t _nh = {0};
+        nh = &_nh;
         switch (dpo->dpoi_proto)
           {
           case FIB_PROTOCOL_IP6:
-            nh = calloc (1, sizeof(ip46_address_t));
-            ip46_address_set_ip6(nh, &localhost6);
-            break;
           case FIB_PROTOCOL_IP4:
-            nh = calloc (1, sizeof(ip46_address_t));
+            /**
+             * Independently of the type of tunnel, encapsulated packet
+             * can be either v6 or v4, so we need to create 2 faces for each
+             * version. Tunneled hicn packet MUST have locator set to the loopback
+             * address, so ::1 for IPv6 and 127.0.0.1 for IPv4.
+             */
+            ip46_address_set_ip6(nh, &localhost6);
+            ADD_FACE(nh);
             ip46_address_set_ip4(nh, &localhost4);
+            ADD_FACE(nh);
             break;
           default:
-            nh = calloc (1, sizeof(ip46_address_t));
+            continue;
           }
         udp_tunnel_add_existing (dpo->dpoi_index, proto);
       }
-    else //if (dpo_is_drop(dpo))
-      {
-        sw_if = dpo_get_urpf(dpo);
-        nh = calloc (1, sizeof(ip46_address_t));
-      }
-
-    /* Careful, this adds a lock on the face if it exists */
-    hicn_face_add(dpo, nh, sw_if, &face_id, 0);
-
-    vec_validate(vec_faces, index);
-    vec_faces[index] = face_id;
-    index++;
-
-    /* Face creation can realloc load_balance_t? Seem the fib_tracking does so. */
-    dpo_loadbalance = fib_entry_contribute_ip_forwarding (fib_entry->fib_entry_index);
-    lb0 = load_balance_get(dpo_loadbalance->dpoi_index);
   }
 
   const hicn_dpo_vft_t * strategy_vft = hicn_dpo_get_vft(fib_entry->dpo_type);
index 772cfbb..a94414d 100644 (file)
@@ -49,7 +49,10 @@ class ForwarderInterface {
         inet6_address_({}),
         mtu_(1500),
         output_interface_(""),
-        content_store_reserved_(standard_cs_reserved) {}
+        content_store_reserved_(standard_cs_reserved) {
+    inet_address_.v4.as_u32 = htonl(0x7f00001);
+    inet6_address_.v6.as_u8[15] = 0x01;
+  }
 
  public:
   virtual ~ForwarderInterface() {}