aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2016-09-06 22:26:03 +0200
committerDave Barach <openvpp@barachs.net>2016-09-07 00:49:29 +0000
commitd4798a394a337ad11c306309bb68611251b4e593 (patch)
treed8eac2ce82f6d36dd7e60d2896493ef6d144724a
parent5d447a9f64afd4ebed1b126b0faa5732563f81fe (diff)
Avoid use of node index 0 by registering null-node
In some cases it is convenient to use 0 as an invalid node index so here we make sure that index 0 is not used. Change-Id: I5af6bef6769d56086ceb343423185f22843732bd Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r--vlib/vlib/node.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/vlib/vlib/node.c b/vlib/vlib/node.c
index 4b8e3f74bb9..e18567b4184 100644
--- a/vlib/vlib/node.c
+++ b/vlib/vlib/node.c
@@ -449,11 +449,40 @@ vlib_register_node (vlib_main_t * vm, vlib_node_registration_t * r)
return r->index;
}
+static uword
+null_node_fn (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+ u16 n_vectors = frame->n_vectors;
+
+ vlib_node_increment_counter (vm, node->node_index, 0, n_vectors);
+ vlib_buffer_free (vm, vlib_frame_args (frame), n_vectors);
+ vlib_frame_free (vm, node, frame);
+
+ return n_vectors;
+}
+
void
vlib_register_all_static_nodes (vlib_main_t * vm)
{
vlib_node_registration_t *r;
+ static char *null_node_error_strings[] = {
+ "blackholed packets",
+ };
+
+ static vlib_node_registration_t null_node_reg = {
+ .function = null_node_fn,
+ .vector_size = sizeof (u32),
+ .name = "null-node",
+ .n_errors = 1,
+ .error_strings = null_node_error_strings,
+ };
+
+ /* make sure that node index 0 is not used by
+ real node */
+ register_node (vm, &null_node_reg);
+
r = vm->node_main.node_registrations;
while (r)
{