mfib: migrate old MULTIARCH macros to VLIB_NODE_FN
[vpp.git] / src / vnet / mfib / mfib_forward.c
index 5fe0a57..c5e1dfc 100644 (file)
@@ -42,7 +42,7 @@ format_mfib_forward_lookup_trace (u8 * s, va_list * args)
 }
 
 /* Common trace function for all ip4-forward next nodes. */
-void
+static void
 mfib_forward_lookup_trace (vlib_main_t * vm,
                            vlib_node_runtime_t * node,
                            vlib_frame_t * frame)
@@ -165,9 +165,9 @@ mfib_forward_lookup (vlib_main_t * vm,
                 fib_index0 = vec_elt (ip6_main.mfib_index_by_sw_if_index,
                                       vnet_buffer(p0)->sw_if_index[VLIB_RX]);
                 ip0 = vlib_buffer_get_current (p0);
-                mfei0 = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index0),
-                                               &ip0->src_address,
-                                               &ip0->dst_address);
+                mfei0 = ip6_mfib_table_fwd_lookup(ip6_mfib_get(fib_index0),
+                                                  &ip0->src_address,
+                                                  &ip0->dst_address);
             }
 
             vnet_buffer (p0)->ip.adj_index[VLIB_TX] = mfei0;
@@ -184,16 +184,14 @@ mfib_forward_lookup (vlib_main_t * vm,
     return frame->n_vectors;
 }
 
-static uword
-ip4_mfib_forward_lookup (vlib_main_t * vm,
+VLIB_NODE_FN (ip4_mfib_forward_lookup_node) (vlib_main_t * vm,
                          vlib_node_runtime_t * node,
                          vlib_frame_t * frame)
 {
     return (mfib_forward_lookup (vm, node, frame, 1));
 }
 
-VLIB_REGISTER_NODE (ip4_mfib_forward_lookup_node, static) = {
-    .function = ip4_mfib_forward_lookup,
+VLIB_REGISTER_NODE (ip4_mfib_forward_lookup_node) = {
     .name = "ip4-mfib-forward-lookup",
     .vector_size = sizeof (u32),
 
@@ -205,19 +203,14 @@ VLIB_REGISTER_NODE (ip4_mfib_forward_lookup_node, static) = {
     },
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_mfib_forward_lookup_node,
-                              ip4_mfib_forward_lookup)
-
-static uword
-ip6_mfib_forward_lookup (vlib_main_t * vm,
+VLIB_NODE_FN (ip6_mfib_forward_lookup_node) (vlib_main_t * vm,
                          vlib_node_runtime_t * node,
                          vlib_frame_t * frame)
 {
     return (mfib_forward_lookup (vm, node, frame, 0));
 }
 
-VLIB_REGISTER_NODE (ip6_mfib_forward_lookup_node, static) = {
-    .function = ip6_mfib_forward_lookup,
+VLIB_REGISTER_NODE (ip6_mfib_forward_lookup_node) = {
     .name = "ip6-mfib-forward-lookup",
     .vector_size = sizeof (u32),
 
@@ -229,9 +222,6 @@ VLIB_REGISTER_NODE (ip6_mfib_forward_lookup_node, static) = {
     },
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_mfib_forward_lookup_node,
-                              ip6_mfib_forward_lookup)
-
 
 typedef struct mfib_forward_rpf_trace_t_ {
     u32 entry_index;
@@ -252,8 +242,8 @@ format_mfib_forward_rpf_trace (u8 * s, va_list * args)
     mfib_forward_rpf_trace_t * t = va_arg (*args, mfib_forward_rpf_trace_t *);
 
     s = format (s, "entry %d", t->entry_index);
-    s = format (s, " %d", t->sw_if_index);
-    s = format (s, " %U", format_mfib_itf_flags, t->itf_flags);
+    s = format (s, " itf %d", t->sw_if_index);
+    s = format (s, " flags %U", format_mfib_itf_flags, t->itf_flags);
 
     return s;
 }
@@ -300,8 +290,8 @@ mfib_forward_itf_signal (vlib_main_t *vm,
 {
     mfib_itf_flags_t old_flags;
 
-    old_flags = __sync_fetch_and_or(&mfi->mfi_flags,
-                                    MFIB_ITF_FLAG_SIGNAL_PRESENT);
+    old_flags = clib_atomic_fetch_or(&mfi->mfi_flags,
+                                    MFIB_ITF_FLAG_SIGNAL_PRESENT);
 
     if (!(old_flags & MFIB_ITF_FLAG_SIGNAL_PRESENT))
     {
@@ -342,7 +332,12 @@ mfib_forward_rpf (vlib_main_t * vm,
 {
     u32 n_left_from, n_left_to_next, * from, * to_next;
     mfib_forward_rpf_next_t next;
+    vlib_node_runtime_t *error_node;
 
+    if (is_v4)
+        error_node = vlib_node_get_runtime (vm, ip4_input_node.index);
+    else
+        error_node = vlib_node_get_runtime (vm, ip6_input_node.index);
     from = vlib_frame_vector_args (frame);
     n_left_from = frame->n_vectors;
     next = MFIB_FORWARD_RPF_NEXT_DROP;
@@ -361,6 +356,7 @@ mfib_forward_rpf (vlib_main_t * vm,
             u32 pi0, next0;
             mfib_itf_flags_t iflags0;
             mfib_entry_flags_t eflags0;
+            u8 error0;
 
             pi0 = from[0];
             to_next[0] = pi0;
@@ -369,6 +365,7 @@ mfib_forward_rpf (vlib_main_t * vm,
             n_left_to_next -= 1;
             n_left_from -= 1;
 
+            error0 = IP4_ERROR_NONE;
             b0 = vlib_get_buffer (vm, pi0);
             mfei0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
             mfe0 = mfib_entry_get(mfei0);
@@ -380,13 +377,27 @@ mfib_forward_rpf (vlib_main_t * vm,
              * for the case of throughput traffic that is not replicated
              * to the host stack nor sets local flags
              */
-            if (PREDICT_TRUE(NULL != mfi0))
+
+            /*
+             * If the mfib entry has a configured RPF-ID check that
+             * in preference to an interface based RPF
+             */
+            if (MFIB_RPF_ID_NONE != mfe0->mfe_rpf_id)
             {
-                iflags0 = mfi0->mfi_flags;
+                iflags0 = (mfe0->mfe_rpf_id == vnet_buffer(b0)->ip.rpf_id ?
+                           MFIB_ITF_FLAG_ACCEPT :
+                           MFIB_ITF_FLAG_NONE);
             }
             else
             {
-                iflags0 = MFIB_ITF_FLAG_NONE;
+                if (PREDICT_TRUE(NULL != mfi0))
+                {
+                    iflags0 = mfi0->mfi_flags;
+                }
+                else
+                {
+                    iflags0 = MFIB_ITF_FLAG_NONE;
+                }
             }
             eflags0 = mfe0->mfe_flags;
 
@@ -430,23 +441,25 @@ mfib_forward_rpf (vlib_main_t * vm,
             else
             {
                 next0 = MFIB_FORWARD_RPF_NEXT_DROP;
+                error0 = IP4_ERROR_RPF_FAILURE;
             }
 
+            b0->error = error0 ? error_node->errors[error0] : 0;
+
             if (b0->flags & VLIB_BUFFER_IS_TRACED)
             {
                 mfib_forward_rpf_trace_t *t0;
 
-                t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
+                t0 = vlib_add_trace (vm, node, b0, sizeof (*t0));
                 t0->entry_index = mfei0;
+                t0->itf_flags = iflags0;
                 if (NULL == mfi0)
                 {
                     t0->sw_if_index = ~0;
-                    t0->itf_flags = MFIB_ITF_FLAG_NONE;
                 }
                 else
                 {
                     t0->sw_if_index = mfi0->mfi_sw_if_index;
-                    t0->itf_flags = mfi0->mfi_flags;
                 }
             }
             vlib_validate_buffer_enqueue_x1 (vm, node, next,
@@ -460,8 +473,7 @@ mfib_forward_rpf (vlib_main_t * vm,
     return frame->n_vectors;
 }
 
-static uword
-ip4_mfib_forward_rpf (vlib_main_t * vm,
+VLIB_NODE_FN (ip4_mfib_forward_rpf_node) (vlib_main_t * vm,
                       vlib_node_runtime_t * node,
                       vlib_frame_t * frame)
 {
@@ -469,8 +481,7 @@ ip4_mfib_forward_rpf (vlib_main_t * vm,
 }
 
 
-VLIB_REGISTER_NODE (ip4_mfib_forward_rpf_node, static) = {
-    .function = ip4_mfib_forward_rpf,
+VLIB_REGISTER_NODE (ip4_mfib_forward_rpf_node) = {
     .name = "ip4-mfib-forward-rpf",
     .vector_size = sizeof (u32),
 
@@ -478,15 +489,11 @@ VLIB_REGISTER_NODE (ip4_mfib_forward_rpf_node, static) = {
 
     .n_next_nodes = MFIB_FORWARD_RPF_N_NEXT,
     .next_nodes = {
-        [MFIB_FORWARD_RPF_NEXT_DROP] = "error-drop",
+        [MFIB_FORWARD_RPF_NEXT_DROP] = "ip4-drop",
     },
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_mfib_forward_rpf_node,
-                              ip4_mfib_forward_rpf)
-
-static uword
-ip6_mfib_forward_rpf (vlib_main_t * vm,
+VLIB_NODE_FN (ip6_mfib_forward_rpf_node) (vlib_main_t * vm,
                       vlib_node_runtime_t * node,
                       vlib_frame_t * frame)
 {
@@ -494,8 +501,7 @@ ip6_mfib_forward_rpf (vlib_main_t * vm,
 }
 
 
-VLIB_REGISTER_NODE (ip6_mfib_forward_rpf_node, static) = {
-    .function = ip6_mfib_forward_rpf,
+VLIB_REGISTER_NODE (ip6_mfib_forward_rpf_node) = {
     .name = "ip6-mfib-forward-rpf",
     .vector_size = sizeof (u32),
 
@@ -503,10 +509,7 @@ VLIB_REGISTER_NODE (ip6_mfib_forward_rpf_node, static) = {
 
     .n_next_nodes = MFIB_FORWARD_RPF_N_NEXT,
     .next_nodes = {
-        [MFIB_FORWARD_RPF_NEXT_DROP] = "error-drop",
+        [MFIB_FORWARD_RPF_NEXT_DROP] = "ip6-drop",
     },
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_mfib_forward_rpf_node,
-                              ip6_mfib_forward_rpf)
-