diff options
author | Damjan Marion <damarion@cisco.com> | 2022-03-23 17:36:56 +0100 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2022-03-23 18:40:16 +0000 |
commit | f87acfaf739f7b6361d6299549a897b03b0cc8c6 (patch) | |
tree | 6107b984b0a4ae9b6365eb08e307b377b4266ba5 | |
parent | ba465b970e88d02467838bd9c272cb6d5cd653ec (diff) |
vppinfra: change vlib_register_node so it takes format string for node name
This allows specifying both c string and vector for node name
and removes need for crafting temporary string.
Type: improvement
Change-Id: I0b016cd70aeda0f68eb6f9171c5152f303be7369
Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r-- | src/plugins/hs_apps/http_cli.c | 6 | ||||
-rw-r--r-- | src/plugins/nat/pnat/tests/pnat_test.c | 3 | ||||
-rw-r--r-- | src/vlib/node.c | 29 | ||||
-rw-r--r-- | src/vlib/node_funcs.h | 3 | ||||
-rw-r--r-- | src/vlib/unix/cli.c | 4 | ||||
-rw-r--r-- | src/vnet/interface.c | 18 | ||||
-rw-r--r-- | src/vnet/srp/node.c | 8 |
7 files changed, 26 insertions, 45 deletions
diff --git a/src/plugins/hs_apps/http_cli.c b/src/plugins/hs_apps/http_cli.c index a4698c52caf..fec1427994c 100644 --- a/src/plugins/hs_apps/http_cli.c +++ b/src/plugins/hs_apps/http_cli.c @@ -262,7 +262,6 @@ alloc_cli_process (hcs_cli_args_t *args) vlib_main_t *vm = hcm->vlib_main; hcs_cli_args_t **save_args; vlib_node_t *n; - char *name; uword l; l = vec_len (hcm->free_http_cli_process_node_indices); @@ -281,10 +280,7 @@ alloc_cli_process (hcs_cli_args_t *args) .runtime_data_bytes = sizeof (void *), }; - name = (char *) format (0, "http-cli-%d", l); - r.name = name; - vlib_register_node (vm, &r); - vec_free (name); + vlib_register_node (vm, &r, "http-cli-%d", l); n = vlib_get_node (vm, r.index); } diff --git a/src/plugins/nat/pnat/tests/pnat_test.c b/src/plugins/nat/pnat/tests/pnat_test.c index e7d946941b9..f6579dc5ca9 100644 --- a/src/plugins/nat/pnat/tests/pnat_test.c +++ b/src/plugins/nat/pnat/tests/pnat_test.c @@ -569,7 +569,8 @@ int main(int argc, char **argv) { ip_checksum_init(vm); - u32 node_index = vlib_register_node(vm, &pnat_input_node); + u32 node_index = + vlib_register_node(vm, &pnat_input_node, "%s", pnat_input_node.name); node = vlib_node_get_runtime(vm, node_index); assert(node); diff --git a/src/vlib/node.c b/src/vlib/node.c index 2c408d6069a..c6a13fb15e0 100644 --- a/src/vlib/node.c +++ b/src/vlib/node.c @@ -328,11 +328,13 @@ vlib_node_get_preferred_node_fn_variant (vlib_main_t *vm, return fn; } -static void -register_node (vlib_main_t * vm, vlib_node_registration_t * r) +u32 +vlib_register_node (vlib_main_t *vm, vlib_node_registration_t *r, char *fmt, + ...) { vlib_node_main_t *nm = &vm->node_main; vlib_node_t *n; + va_list va; u32 size; int i; @@ -363,11 +365,9 @@ register_node (vlib_main_t * vm, vlib_node_registration_t * r) vec_add1 (nm->nodes, n); - /* Name is always a vector so it can be formatted with %v. */ - if (clib_mem_is_heap_object (vec_header (r->name))) - n->name = vec_dup ((u8 *) r->name); - else - n->name = format (0, "%s", r->name); + va_start (va, fmt); + n->name = va_format (0, fmt, &va); + va_end (va); if (!nm->node_by_name) nm->node_by_name = hash_create_vec ( /* size */ 32, @@ -566,13 +566,6 @@ register_node (vlib_main_t * vm, vlib_node_registration_t * r) vec_free (n->runtime_data); } #undef _ -} - -/* Register new packet processing node. */ -u32 -vlib_register_node (vlib_main_t * vm, vlib_node_registration_t * r) -{ - register_node (vm, r); return r->index; } @@ -636,19 +629,18 @@ vlib_register_all_static_nodes (vlib_main_t * vm) 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); + vlib_register_node (vm, &null_node_reg, "null-node"); r = vgm->node_registrations; while (r) { - register_node (vm, r); + vlib_register_node (vm, r, "%s", r->name); r = r->next_registration; } } @@ -850,14 +842,13 @@ vlib_process_create (vlib_main_t * vm, char *name, memset (&r, 0, sizeof (r)); - r.name = (char *) format (0, "%s", name, 0); r.function = f; r.process_log2_n_stack_bytes = log2_n_stack_bytes; r.type = VLIB_NODE_TYPE_PROCESS; vlib_worker_thread_barrier_sync (vm); - vlib_register_node (vm, &r); + vlib_register_node (vm, &r, "%s", name); vec_free (r.name); vlib_worker_thread_node_runtime_update (); diff --git a/src/vlib/node_funcs.h b/src/vlib/node_funcs.h index b864fec11a1..61a085730fd 100644 --- a/src/vlib/node_funcs.h +++ b/src/vlib/node_funcs.h @@ -1211,7 +1211,8 @@ void vlib_node_rename (vlib_main_t * vm, u32 node_index, char *fmt, ...); /* Register new packet processing node. Nodes can be registered dynamically via this call or statically via the VLIB_REGISTER_NODE macro. */ -u32 vlib_register_node (vlib_main_t * vm, vlib_node_registration_t * r); +u32 vlib_register_node (vlib_main_t *vm, vlib_node_registration_t *r, + char *fmt, ...); /* Register all node function variants */ void vlib_register_all_node_march_variants (vlib_main_t *vm); diff --git a/src/vlib/unix/cli.c b/src/vlib/unix/cli.c index 03baf3e58c1..c546948b536 100644 --- a/src/vlib/unix/cli.c +++ b/src/vlib/unix/cli.c @@ -2928,11 +2928,9 @@ unix_cli_file_add (unix_cli_main_t * cm, char *name, int fd) .process_log2_n_stack_bytes = 18, }; - r.name = name; - vlib_worker_thread_barrier_sync (vm); - vlib_register_node (vm, &r); + vlib_register_node (vm, &r, "%v", name); vec_free (name); n = vlib_get_node (vm, r.index); diff --git a/src/vnet/interface.c b/src/vnet/interface.c index 412c6755ea8..c44f2647ddf 100644 --- a/src/vnet/interface.c +++ b/src/vnet/interface.c @@ -874,7 +874,6 @@ vnet_register_interface (vnet_main_t * vnm, vnet_feature_config_main_t *fcm; vnet_config_main_t *cm; u32 hw_index, i; - char *tx_node_name = NULL, *output_node_name = NULL; vlib_node_t *if_out_node = vlib_get_node (vm, vnet_interface_output_node.index); @@ -926,9 +925,6 @@ vnet_register_interface (vnet_main_t * vnm, if (dev_class->tx_function == 0 && dev_class->tx_fn_registrations == 0) goto no_output_nodes; /* No output/tx nodes to create */ - tx_node_name = (char *) format (0, "%v-tx", hw->name); - output_node_name = (char *) format (0, "%v-output", hw->name); - /* If we have previously deleted interface nodes, re-use them. */ if (vec_len (im->deleted_hw_interface_nodes) > 0) { @@ -941,8 +937,8 @@ vnet_register_interface (vnet_main_t * vnm, hw->tx_node_index = hn->tx_node_index; hw->output_node_index = hn->output_node_index; - vlib_node_rename (vm, hw->tx_node_index, "%v", tx_node_name); - vlib_node_rename (vm, hw->output_node_index, "%v", output_node_name); + vlib_node_rename (vm, hw->tx_node_index, "%v-tx", hw->name); + vlib_node_rename (vm, hw->output_node_index, "%v-output", hw->name); foreach_vlib_main () { @@ -1016,7 +1012,6 @@ vnet_register_interface (vnet_main_t * vnm, r.vector_size = sizeof (u32); r.flags = VLIB_NODE_FLAG_IS_OUTPUT; - r.name = tx_node_name; if (dev_class->tx_fn_registrations) { r.function = 0; @@ -1025,14 +1020,13 @@ vnet_register_interface (vnet_main_t * vnm, else r.function = dev_class->tx_function; - hw->tx_node_index = vlib_register_node (vm, &r); + hw->tx_node_index = vlib_register_node (vm, &r, "%v-tx", hw->name); vlib_node_add_named_next_with_slot (vm, hw->tx_node_index, "error-drop", VNET_INTERFACE_TX_NEXT_DROP); r.flags = 0; - r.name = output_node_name; r.format_trace = format_vnet_interface_output_trace; if (if_out_node->node_fn_registrations) { @@ -1052,7 +1046,8 @@ vnet_register_interface (vnet_main_t * vnm, r.n_errors = ARRAY_LEN (e); r.error_strings = e; } - hw->output_node_index = vlib_register_node (vm, &r); + hw->output_node_index = + vlib_register_node (vm, &r, "%v-output", hw->name); vlib_node_add_named_next_with_slot (vm, hw->output_node_index, "error-drop", @@ -1095,9 +1090,6 @@ no_output_nodes: VNET_INTERFACE_SET_FLAGS_HELPER_IS_CREATE); vnet_hw_interface_set_flags_helper (vnm, hw_index, /* flags */ 0, VNET_INTERFACE_SET_FLAGS_HELPER_IS_CREATE); - vec_free (tx_node_name); - vec_free (output_node_name); - return hw_index; } diff --git a/src/vnet/srp/node.c b/src/vnet/srp/node.c index 12c14012b61..26c3f0b8c1f 100644 --- a/src/vnet/srp/node.c +++ b/src/vnet/srp/node.c @@ -878,9 +878,11 @@ static clib_error_t * srp_init (vlib_main_t * vm) sm->default_data_ttl = 255; sm->vlib_main = vm; - vlib_register_node (vm, &srp_ips_process_node); - vlib_register_node (vm, &srp_input_node); - vlib_register_node (vm, &srp_control_input_node); + vlib_register_node (vm, &srp_ips_process_node, "%s", + srp_ips_process_node.name); + vlib_register_node (vm, &srp_input_node, "%s", srp_input_node.name); + vlib_register_node (vm, &srp_control_input_node, "%s", + srp_control_input_node.name); srp_setup_node (vm, srp_input_node.index); return 0; |