ARP/NDP does not send solicitation when no source address is available
[vpp.git] / vnet / vnet / ip / ip6_forward.c
index 7c89221..b558787 100644 (file)
@@ -350,7 +350,7 @@ ip6_add_del_route_next_hop (ip6_main_t * im,
               ip6_adjacency_set_interface_route (vnm, adj, 
                                                  next_hop_sw_if_index, ~0);
               ip_call_add_del_adjacency_callbacks 
-                (lm, next_hop_sw_if_index, /* is_del */ 0);
+                (lm, nh_adj_index, /* is_del */ 0);
               hash_set (im->interface_route_adj_index_by_sw_if_index, 
                         next_hop_sw_if_index, nh_adj_index);
             }
@@ -378,6 +378,8 @@ ip6_add_del_route_next_hop (ip6_main_t * im,
             else
             {
              ip_adjacency_t add_adj;
+             memset (&add_adj, 0, sizeof(add_adj));
+             add_adj.n_adj = 1;
              add_adj.lookup_next_index = IP_LOOKUP_NEXT_INDIRECT;
              add_adj.indirect.next_hop.ip6.as_u64[0] = next_hop->as_u64[0];
              add_adj.indirect.next_hop.ip6.as_u64[1] = next_hop->as_u64[1];
@@ -653,6 +655,12 @@ void ip6_delete_matching_routes (ip6_main_t * im,
   ip6_maybe_remap_adjacencies (im, table_index_or_table_id, flags);
 }
 
+void
+ip6_forward_next_trace (vlib_main_t * vm,
+                        vlib_node_runtime_t * node,
+                        vlib_frame_t * frame,
+                        vlib_rx_or_tx_t which_adj_index);
+
 always_inline uword
 ip6_lookup_inline (vlib_main_t * vm,
                   vlib_node_runtime_t * node,
@@ -754,9 +762,9 @@ ip6_lookup_inline (vlib_main_t * vm,
 
          /* Only process the HBH Option Header if explicitly configured to do so */
           next0 = (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) && im->hbh_enabled &&
-           adj_index0 ? IP_LOOKUP_NEXT_HOP_BY_HOP : adj0->lookup_next_index;
+           adj_index0 ? IP6_LOOKUP_NEXT_HOP_BY_HOP : adj0->lookup_next_index;
           next1 = (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) && im->hbh_enabled &&
-           adj_index1 ? IP_LOOKUP_NEXT_HOP_BY_HOP : adj1->lookup_next_index;
+           adj_index1 ? IP6_LOOKUP_NEXT_HOP_BY_HOP : adj1->lookup_next_index;
 
           vnet_buffer (p0)->ip.flow_hash = 
             vnet_buffer(p1)->ip.flow_hash = 0;
@@ -885,7 +893,7 @@ ip6_lookup_inline (vlib_main_t * vm,
 
          /* Only process the HBH Option Header if explicitly configured to do so */
           next0 = (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) && im->hbh_enabled &&
-           adj_index0 ? IP_LOOKUP_NEXT_HOP_BY_HOP : adj0->lookup_next_index;
+           adj_index0 ? IP6_LOOKUP_NEXT_HOP_BY_HOP : adj0->lookup_next_index;
 
           vnet_buffer (p0)->ip.flow_hash = 0;
 
@@ -928,6 +936,9 @@ ip6_lookup_inline (vlib_main_t * vm,
       vlib_put_next_frame (vm, node, next, n_left_to_next);
     }
 
+  if (node->flags & VLIB_NODE_FLAG_TRACE)
+      ip6_forward_next_trace(vm, node, frame, VLIB_TX);
+
   return frame->n_vectors;
 }
 
@@ -1189,6 +1200,75 @@ ip6_sw_interface_admin_up_down (vnet_main_t * vnm,
 
 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_sw_interface_admin_up_down);
 
+/* Built-in ip6 unicast rx feature path definition */
+VNET_IP6_UNICAST_FEATURE_INIT (ip6_inacl, static) = {
+  .node_name = "ip6-inacl", 
+  .runs_before = {"ipsec-input-ip6", 0}, 
+  .feature_index = &ip6_main.ip6_unicast_rx_feature_check_access,
+};
+
+VNET_IP6_UNICAST_FEATURE_INIT (ip6_ipsec, static) = {
+  .node_name = "ipsec-input-ip6",
+  .runs_before = {"l2tp-decap", 0},
+  .feature_index = &ip6_main.ip6_unicast_rx_feature_ipsec,
+};
+
+VNET_IP6_UNICAST_FEATURE_INIT (ip6_l2tp, static) = {
+  .node_name = "l2tp-decap",
+  .runs_before = {"vpath-input-ip6", 0},
+  .feature_index = &ip6_main.ip6_unicast_rx_feature_l2tp_decap,
+};
+
+VNET_IP6_UNICAST_FEATURE_INIT (ip6_vpath, static) = {
+  .node_name = "vpath-input-ip6",
+  .runs_before = {"ip6-lookup", 0},
+  .feature_index = &ip6_main.ip6_unicast_rx_feature_vpath,
+};
+
+VNET_IP6_UNICAST_FEATURE_INIT (ip6_lookup, static) = {
+  .node_name = "ip6-lookup",
+  .runs_before = {0}, /* not before any other features */
+  .feature_index = &ip6_main.ip6_unicast_rx_feature_lookup,
+};
+
+/* Built-in ip6 multicast rx feature path definition (none now) */
+VNET_IP6_MULTICAST_FEATURE_INIT (ip4_vpath_mc, static) = {
+  .node_name = "vpath-input-ip6",
+  .runs_before = {"ip6-lookup", 0},
+  .feature_index = &ip6_main.ip6_multicast_rx_feature_vpath,
+};
+
+VNET_IP6_MULTICAST_FEATURE_INIT (ip6_lookup, static) = {
+  .node_name = "ip6-lookup",
+  .runs_before = {0}, /* not before any other features */
+  .feature_index = &ip6_main.ip6_multicast_rx_feature_lookup,
+};
+
+static char * feature_start_nodes[] = 
+  {"ip6-input"};
+
+static clib_error_t *
+ip6_feature_init (vlib_main_t * vm, ip6_main_t * im)
+{
+  ip_lookup_main_t * lm = &im->lookup_main;
+  clib_error_t * error;
+  vnet_cast_t cast;
+  
+  for (cast = 0; cast < VNET_N_CAST; cast++)
+    {
+      ip_config_main_t * cm = &lm->rx_config_mains[cast];
+      vnet_config_main_t * vcm = &cm->config_main;
+      
+      if ((error = ip_feature_init_cast (vm, cm, vcm, 
+                                         feature_start_nodes,
+                                         ARRAY_LEN(feature_start_nodes),
+                                         cast,
+                                         0 /* is_ip4 */)))
+        return error;
+    }
+  return 0;
+}
+
 clib_error_t *
 ip6_sw_interface_add_del (vnet_main_t * vnm,
                          u32 sw_if_index,
@@ -1198,41 +1278,31 @@ ip6_sw_interface_add_del (vnet_main_t * vnm,
   ip6_main_t * im = &ip6_main;
   ip_lookup_main_t * lm = &im->lookup_main;
   u32 ci, cast;
+  u32 feature_index;
 
   for (cast = 0; cast < VNET_N_CAST; cast++)
     {
       ip_config_main_t * cm = &lm->rx_config_mains[cast];
       vnet_config_main_t * vcm = &cm->config_main;
 
-      /* FIXME multicast. */
-      if (! vcm->node_index_by_feature_index)
-       {
-         char * start_nodes[] = { "ip6-input", };
-         char * feature_nodes[] = {
-           [IP6_RX_FEATURE_CHECK_ACCESS] = "ip6-inacl",
-            [IP6_RX_FEATURE_IPSEC] = "ipsec-input-ip6",
-           [IP6_RX_FEATURE_L2TPV3] = "l2tp-decap",
-           [IP6_RX_FEATURE_VPATH]  = "vpath-input-ip6",
-           [IP6_RX_FEATURE_LOOKUP] = "ip6-lookup",
-         };
-         vnet_config_init (vm, vcm,
-                           start_nodes, ARRAY_LEN (start_nodes),
-                           feature_nodes, ARRAY_LEN (feature_nodes));
-       }
-
       vec_validate_init_empty (cm->config_index_by_sw_if_index, sw_if_index, ~0);
       ci = cm->config_index_by_sw_if_index[sw_if_index];
 
+      if (cast == VNET_UNICAST)
+        feature_index = im->ip6_unicast_rx_feature_lookup;
+      else
+        feature_index = im->ip6_multicast_rx_feature_lookup;
+
       if (is_add)
        ci = vnet_config_add_feature (vm, vcm,
                                      ci,
-                                     IP6_RX_FEATURE_LOOKUP,
+                                      feature_index,
                                      /* config data */ 0,
                                      /* # bytes of config data */ 0);
       else
        ci = vnet_config_del_feature (vm, vcm,
                                      ci,
-                                     IP6_RX_FEATURE_LOOKUP,
+                                      feature_index,
                                      /* config data */ 0,
                                      /* # bytes of config data */ 0);
 
@@ -1251,12 +1321,16 @@ ip6_lookup (vlib_main_t * vm,
   return ip6_lookup_inline (vm, node, frame, /* is_indirect */ 0);
 }
 
+static u8 * format_ip6_lookup_trace (u8 * s, va_list * args);
+
 VLIB_REGISTER_NODE (ip6_lookup_node) = {
   .function = ip6_lookup,
   .name = "ip6-lookup",
   .vector_size = sizeof (u32),
 
-  .n_next_nodes = IP_LOOKUP_N_NEXT,
+  .format_trace = format_ip6_lookup_trace,
+
+  .n_next_nodes = IP6_LOOKUP_N_NEXT,
   .next_nodes = IP6_LOOKUP_NEXT_NODES,
 };
 
@@ -1275,9 +1349,9 @@ VLIB_REGISTER_NODE (ip6_indirect_node) = {
   .function = ip6_indirect,
   .name = "ip6-indirect",
   .vector_size = sizeof (u32),
-
-  .n_next_nodes = IP_LOOKUP_N_NEXT,
-  .next_nodes = IP6_LOOKUP_NEXT_NODES,
+  .sibling_of = "ip6-lookup",
+  .format_trace = format_ip6_lookup_trace,
+  .n_next_nodes = 0,
 };
 
 VLIB_NODE_FUNCTION_MULTIARCH (ip6_indirect_node, ip6_indirect)
@@ -1293,33 +1367,54 @@ typedef struct {
 } ip6_forward_next_trace_t;
 
 static u8 * format_ip6_forward_next_trace (u8 * s, va_list * args)
+{
+  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
+  ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
+  uword indent = format_get_indent (s);
+
+  s = format(s, "%U%U",
+             format_white_space, indent,
+             format_ip6_header, t->packet_data);
+  return s;
+}
+
+static u8 * format_ip6_lookup_trace (u8 * s, va_list * args)
 {
   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
   ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
   vnet_main_t * vnm = vnet_get_main();
   ip6_main_t * im = &ip6_main;
-  ip_adjacency_t * adj;
   uword indent = format_get_indent (s);
 
-  adj = ip_get_adjacency (&im->lookup_main, t->adj_index);
   s = format (s, "fib %d adj-idx %d : %U flow hash: 0x%08x",
-             t->fib_index, t->adj_index, format_ip_adjacency,
-             vnm, &im->lookup_main, t->adj_index, t->flow_hash);
-  switch (adj->lookup_next_index)
-    {
-    case IP_LOOKUP_NEXT_REWRITE:
-      s = format (s, "\n%U%U",
-                 format_white_space, indent,
-                 format_ip_adjacency_packet_data,
-                 vnm, &im->lookup_main, t->adj_index,
-                 t->packet_data, sizeof (t->packet_data));
-      break;
+              t->fib_index, t->adj_index, format_ip_adjacency,
+              vnm, &im->lookup_main, t->adj_index, t->flow_hash);
+  s = format(s, "\n%U%U",
+             format_white_space, indent,
+             format_ip6_header, t->packet_data);
+  return s;
+}
 
-    default:
-      break;
-    }
 
+static u8 * format_ip6_rewrite_trace (u8 * s, va_list * args)
+{
+  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
+  ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
+  vnet_main_t * vnm = vnet_get_main();
+  ip6_main_t * im = &ip6_main;
+  uword indent = format_get_indent (s);
+
+  s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x",
+              t->fib_index, t->adj_index, format_ip_adjacency,
+              vnm, &im->lookup_main, t->adj_index, t->flow_hash);
+  s = format (s, "\n%U%U",
+              format_white_space, indent,
+              format_ip_adjacency_packet_data,
+              vnm, &im->lookup_main, t->adj_index,
+              t->packet_data, sizeof (t->packet_data));
   return s;
 }
 
@@ -1335,7 +1430,7 @@ ip6_forward_next_trace (vlib_main_t * vm,
 
   n_left = frame->n_vectors;
   from = vlib_frame_vector_args (frame);
-  
+
   while (n_left >= 4)
     {
       u32 bi0, bi1;
@@ -1357,8 +1452,11 @@ ip6_forward_next_trace (vlib_main_t * vm,
          t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
          t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
           t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
-         t0->fib_index = vec_elt (im->fib_index_by_sw_if_index, 
-                             vnet_buffer(b0)->sw_if_index[VLIB_RX]);
+          t0->fib_index = (vnet_buffer(b0)->sw_if_index[VLIB_TX] != (u32)~0) ?
+              vnet_buffer(b0)->sw_if_index[VLIB_TX] :
+              vec_elt (im->fib_index_by_sw_if_index,
+                       vnet_buffer(b0)->sw_if_index[VLIB_RX]);
+
          clib_memcpy (t0->packet_data,
                  vlib_buffer_get_current (b0),
                  sizeof (t0->packet_data));
@@ -1368,8 +1466,11 @@ ip6_forward_next_trace (vlib_main_t * vm,
          t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
          t1->adj_index = vnet_buffer (b1)->ip.adj_index[which_adj_index];
           t1->flow_hash = vnet_buffer (b1)->ip.flow_hash;
-         t1->fib_index = vec_elt (im->fib_index_by_sw_if_index, 
-                             vnet_buffer(b1)->sw_if_index[VLIB_RX]);
+          t1->fib_index = (vnet_buffer(b1)->sw_if_index[VLIB_TX] != (u32)~0) ?
+              vnet_buffer(b1)->sw_if_index[VLIB_TX] :
+              vec_elt (im->fib_index_by_sw_if_index,
+                       vnet_buffer(b1)->sw_if_index[VLIB_RX]);
+
          clib_memcpy (t1->packet_data,
                  vlib_buffer_get_current (b1),
                  sizeof (t1->packet_data));
@@ -1393,8 +1494,11 @@ ip6_forward_next_trace (vlib_main_t * vm,
          t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
          t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
           t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
-         t0->fib_index = vec_elt (im->fib_index_by_sw_if_index, 
-                             vnet_buffer(b0)->sw_if_index[VLIB_RX]);
+          t0->fib_index = (vnet_buffer(b0)->sw_if_index[VLIB_TX] != (u32)~0) ?
+              vnet_buffer(b0)->sw_if_index[VLIB_TX] :
+              vec_elt (im->fib_index_by_sw_if_index,
+                       vnet_buffer(b0)->sw_if_index[VLIB_RX]);
+
          clib_memcpy (t0->packet_data,
                  vlib_buffer_get_current (b0),
                  sizeof (t0->packet_data));
@@ -1889,6 +1993,7 @@ typedef enum {
 typedef enum {
   IP6_DISCOVER_NEIGHBOR_ERROR_DROP,
   IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT,
+  IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS,
 } ip6_discover_neighbor_error_t;
 
 static uword
@@ -2019,8 +2124,13 @@ ip6_discover_neighbor (vlib_main_t * vm,
              * Choose source address based on destination lookup 
              * adjacency. 
              */
-           ip6_src_address_for_packet (im, p0, &h0->ip.src_address, 
-                                        sw_if_index0);
+           if (ip6_src_address_for_packet (im, p0, &h0->ip.src_address,
+                                               sw_if_index0)) {
+               //There is no address on the interface
+               p0->error = node->errors[IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS];
+               vlib_buffer_free(vm, &bi0, 1);
+               continue;
+           }
 
            /* 
              * Destination address is a solicited node multicast address.  
@@ -2071,6 +2181,8 @@ static char * ip6_discover_neighbor_error_strings[] = {
   [IP6_DISCOVER_NEIGHBOR_ERROR_DROP] = "address overflow drops",
   [IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT] 
   = "neighbor solicitations sent",
+  [IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS]
+    = "no source address for ND solicitation",
 };
 
 VLIB_REGISTER_NODE (ip6_discover_neighbor_node) = {
@@ -2428,7 +2540,7 @@ VLIB_REGISTER_NODE (ip6_rewrite_node) = {
   .name = "ip6-rewrite",
   .vector_size = sizeof (u32),
 
-  .format_trace = format_ip6_forward_next_trace,
+  .format_trace = format_ip6_rewrite_trace,
 
   .n_next_nodes = 1,
   .next_nodes = {
@@ -2438,19 +2550,16 @@ VLIB_REGISTER_NODE (ip6_rewrite_node) = {
 
 VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_node, ip6_rewrite_transit)
 
-VLIB_REGISTER_NODE (ip6_rewrite_local_node,static) = {
+VLIB_REGISTER_NODE (ip6_rewrite_local_node) = {
   .function = ip6_rewrite_local,
   .name = "ip6-rewrite-local",
   .vector_size = sizeof (u32),
 
   .sibling_of = "ip6-rewrite",
 
-  .format_trace = format_ip6_forward_next_trace,
+  .format_trace = format_ip6_rewrite_trace,
 
-  .n_next_nodes = 1,
-  .next_nodes = {
-    [IP6_REWRITE_NEXT_DROP] = "error-drop",
-  },
+  .n_next_nodes = 0,
 };
 
 VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_local_node, ip6_rewrite_local)
@@ -2641,7 +2750,7 @@ ip6_hop_by_hop (vlib_main_t * vm,
     out0:
       /* Has the classifier flagged this buffer for special treatment? */
       if ((error0 == 0) && (vnet_buffer(b0)->l2_classify.opaque_index == OI_DECAP))
-       next0 = IP_LOOKUP_NEXT_POP_HOP_BY_HOP;
+       next0 = IP6_LOOKUP_NEXT_POP_HOP_BY_HOP;
 
       if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) {
        ip6_hop_by_hop_trace_t *t = vlib_add_trace(vm, node, b0, sizeof (*t));
@@ -2666,13 +2775,13 @@ ip6_hop_by_hop (vlib_main_t * vm,
 VLIB_REGISTER_NODE (ip6_hop_by_hop_node) = {
   .function = ip6_hop_by_hop,
   .name = "ip6-hop-by-hop",
+  .sibling_of = "ip6-lookup",
   .vector_size = sizeof (u32),
   .format_trace = format_ip6_hop_by_hop_trace,
   .type = VLIB_NODE_TYPE_INTERNAL,
   .n_errors = ARRAY_LEN(ip6_hop_by_hop_error_strings),
   .error_strings = ip6_hop_by_hop_error_strings,
-  .n_next_nodes = IP_LOOKUP_N_NEXT,
-  .next_nodes = IP6_LOOKUP_NEXT_NODES,
+  .n_next_nodes = 0,
 };
 
 VLIB_NODE_FUNCTION_MULTIARCH (ip6_hop_by_hop_node, ip6_hop_by_hop)
@@ -2815,6 +2924,8 @@ ip6_lookup_init (vlib_main_t * vm)
                               "ip6 neighbor discovery");
   }
 
+  ip6_feature_init (vm, im);
+
   return 0;
 }