From 7cd468a3d7dee7d6c92f69a0bb7061ae208ec727 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Mon, 19 Dec 2016 23:05:39 +0100 Subject: Reorganize source tree to use single autotools instance Change-Id: I7b51f88292e057c6443b12224486f2d0c9f8ae23 Signed-off-by: Damjan Marion --- src/vnet/policer/node_funcs.c | 938 +++++++++++++++++++++++++ src/vnet/policer/police.h | 214 ++++++ src/vnet/policer/policer.c | 528 +++++++++++++++ src/vnet/policer/policer.h | 107 +++ src/vnet/policer/xlate.c | 1505 +++++++++++++++++++++++++++++++++++++++++ src/vnet/policer/xlate.h | 186 +++++ 6 files changed, 3478 insertions(+) create mode 100644 src/vnet/policer/node_funcs.c create mode 100644 src/vnet/policer/police.h create mode 100644 src/vnet/policer/policer.c create mode 100644 src/vnet/policer/policer.h create mode 100644 src/vnet/policer/xlate.c create mode 100644 src/vnet/policer/xlate.h (limited to 'src/vnet/policer') diff --git a/src/vnet/policer/node_funcs.c b/src/vnet/policer/node_funcs.c new file mode 100644 index 00000000..1f4997ff --- /dev/null +++ b/src/vnet/policer/node_funcs.c @@ -0,0 +1,938 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include +#include + +#define IP4_NON_DSCP_BITS 0x03 +#define IP4_DSCP_SHIFT 2 +#define IP6_NON_DSCP_BITS 0xf03fffff +#define IP6_DSCP_SHIFT 22 + +/* Dispatch functions meant to be instantiated elsewhere */ + +typedef struct +{ + u32 next_index; + u32 sw_if_index; + u32 policer_index; +} vnet_policer_trace_t; + +/* packet trace format function */ +static u8 * +format_policer_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 *); + vnet_policer_trace_t *t = va_arg (*args, vnet_policer_trace_t *); + + s = format (s, "VNET_POLICER: sw_if_index %d policer_index %d next %d", + t->sw_if_index, t->policer_index, t->next_index); + return s; +} + +#define foreach_vnet_policer_error \ +_(TRANSMIT, "Packets Transmitted") \ +_(DROP, "Packets Dropped") + +typedef enum +{ +#define _(sym,str) VNET_POLICER_ERROR_##sym, + foreach_vnet_policer_error +#undef _ + VNET_POLICER_N_ERROR, +} vnet_policer_error_t; + +static char *vnet_policer_error_strings[] = { +#define _(sym,string) string, + foreach_vnet_policer_error +#undef _ +}; + +static_always_inline void +vnet_policer_mark (vlib_buffer_t * b, u8 dscp) +{ + ethernet_header_t *eh; + ip4_header_t *ip4h; + ip6_header_t *ip6h; + u16 type; + + eh = (ethernet_header_t *) b->data; + type = clib_net_to_host_u16 (eh->type); + + if (PREDICT_TRUE (type == ETHERNET_TYPE_IP4)) + { + ip4h = (ip4_header_t *) & (b->data[sizeof (ethernet_header_t)]);; + ip4h->tos &= IP4_NON_DSCP_BITS; + ip4h->tos |= dscp << IP4_DSCP_SHIFT; + ip4h->checksum = ip4_header_checksum (ip4h); + } + else + { + if (PREDICT_TRUE (type == ETHERNET_TYPE_IP6)) + { + ip6h = (ip6_header_t *) & (b->data[sizeof (ethernet_header_t)]); + ip6h->ip_version_traffic_class_and_flow_label &= + clib_host_to_net_u32 (IP6_NON_DSCP_BITS); + ip6h->ip_version_traffic_class_and_flow_label |= + clib_host_to_net_u32 (dscp << IP6_DSCP_SHIFT); + } + } +} + +static_always_inline + u8 vnet_policer_police (vlib_main_t * vm, + vlib_buffer_t * b, + u32 policer_index, + u64 time_in_policer_periods, + policer_result_e packet_color) +{ + u8 act; + u32 len; + u32 col; + policer_read_response_type_st *pol; + vnet_policer_main_t *pm = &vnet_policer_main; + + len = vlib_buffer_length_in_chain (vm, b); + pol = &pm->policers[policer_index]; + col = vnet_police_packet (pol, len, packet_color, time_in_policer_periods); + act = pol->action[col]; + if (PREDICT_TRUE (act == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)) + vnet_policer_mark (b, pol->mark_dscp[col]); + + return act; +} + +static inline uword +vnet_policer_inline (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame, vnet_policer_index_t which) +{ + u32 n_left_from, *from, *to_next; + vnet_policer_next_t next_index; + vnet_policer_main_t *pm = &vnet_policer_main; + u64 time_in_policer_periods; + u32 transmitted = 0; + + time_in_policer_periods = + clib_cpu_time_now () >> POLICER_TICKS_PER_PERIOD_SHIFT; + + from = vlib_frame_vector_args (frame); + n_left_from = frame->n_vectors; + next_index = node->cached_next_index; + + while (n_left_from > 0) + { + u32 n_left_to_next; + + vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); + + while (n_left_from >= 4 && n_left_to_next >= 2) + { + u32 bi0, bi1; + vlib_buffer_t *b0, *b1; + u32 next0, next1; + u32 sw_if_index0, sw_if_index1; + u32 pi0 = 0, pi1 = 0; + u8 act0, act1; + + /* Prefetch next iteration. */ + { + vlib_buffer_t *b2, *b3; + + b2 = vlib_get_buffer (vm, from[2]); + b3 = vlib_get_buffer (vm, from[3]); + + vlib_prefetch_buffer_header (b2, LOAD); + vlib_prefetch_buffer_header (b3, LOAD); + } + + /* speculatively enqueue b0 and b1 to the current next frame */ + to_next[0] = bi0 = from[0]; + to_next[1] = bi1 = from[1]; + from += 2; + to_next += 2; + n_left_from -= 2; + n_left_to_next -= 2; + + b0 = vlib_get_buffer (vm, bi0); + b1 = vlib_get_buffer (vm, bi1); + + sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; + next0 = VNET_POLICER_NEXT_TRANSMIT; + + sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX]; + next1 = VNET_POLICER_NEXT_TRANSMIT; + + + if (which == VNET_POLICER_INDEX_BY_SW_IF_INDEX) + { + pi0 = pm->policer_index_by_sw_if_index[sw_if_index0]; + pi1 = pm->policer_index_by_sw_if_index[sw_if_index1]; + } + + if (which == VNET_POLICER_INDEX_BY_OPAQUE) + { + pi0 = vnet_buffer (b0)->policer.index; + pi1 = vnet_buffer (b1)->policer.index; + } + + if (which == VNET_POLICER_INDEX_BY_EITHER) + { + pi0 = vnet_buffer (b0)->policer.index; + pi0 = (pi0 != ~0) ? pi0 : + pm->policer_index_by_sw_if_index[sw_if_index0]; + pi1 = vnet_buffer (b1)->policer.index; + pi1 = (pi1 != ~0) ? pi1 : + pm->policer_index_by_sw_if_index[sw_if_index1]; + } + + act0 = vnet_policer_police (vm, b0, pi0, time_in_policer_periods, + POLICE_CONFORM /* no chaining */ ); + + act1 = vnet_policer_police (vm, b1, pi1, time_in_policer_periods, + POLICE_CONFORM /* no chaining */ ); + + if (PREDICT_FALSE (act0 == SSE2_QOS_ACTION_DROP)) /* drop action */ + { + next0 = VNET_POLICER_NEXT_DROP; + b0->error = node->errors[VNET_POLICER_ERROR_DROP]; + } + else /* transmit or mark-and-transmit action */ + { + transmitted++; + } + + if (PREDICT_FALSE (act1 == SSE2_QOS_ACTION_DROP)) /* drop action */ + { + next1 = VNET_POLICER_NEXT_DROP; + b1->error = node->errors[VNET_POLICER_ERROR_DROP]; + } + else /* transmit or mark-and-transmit action */ + { + transmitted++; + } + + + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE))) + { + if (b0->flags & VLIB_BUFFER_IS_TRACED) + { + vnet_policer_trace_t *t = + vlib_add_trace (vm, node, b0, sizeof (*t)); + t->sw_if_index = sw_if_index0; + t->next_index = next0; + } + if (b1->flags & VLIB_BUFFER_IS_TRACED) + { + vnet_policer_trace_t *t = + vlib_add_trace (vm, node, b1, sizeof (*t)); + t->sw_if_index = sw_if_index1; + t->next_index = next1; + } + } + + /* verify speculative enqueues, maybe switch current next frame */ + vlib_validate_buffer_enqueue_x2 (vm, node, next_index, + to_next, n_left_to_next, + bi0, bi1, next0, next1); + } + + while (n_left_from > 0 && n_left_to_next > 0) + { + u32 bi0; + vlib_buffer_t *b0; + u32 next0; + u32 sw_if_index0; + u32 pi0 = 0; + u8 act0; + + bi0 = from[0]; + to_next[0] = bi0; + from += 1; + to_next += 1; + n_left_from -= 1; + n_left_to_next -= 1; + + b0 = vlib_get_buffer (vm, bi0); + + sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; + next0 = VNET_POLICER_NEXT_TRANSMIT; + + if (which == VNET_POLICER_INDEX_BY_SW_IF_INDEX) + pi0 = pm->policer_index_by_sw_if_index[sw_if_index0]; + + if (which == VNET_POLICER_INDEX_BY_OPAQUE) + pi0 = vnet_buffer (b0)->policer.index; + + if (which == VNET_POLICER_INDEX_BY_EITHER) + { + pi0 = vnet_buffer (b0)->policer.index; + pi0 = (pi0 != ~0) ? pi0 : + pm->policer_index_by_sw_if_index[sw_if_index0]; + } + + act0 = vnet_policer_police (vm, b0, pi0, time_in_policer_periods, + POLICE_CONFORM /* no chaining */ ); + + if (PREDICT_FALSE (act0 == SSE2_QOS_ACTION_DROP)) /* drop action */ + { + next0 = VNET_POLICER_NEXT_DROP; + b0->error = node->errors[VNET_POLICER_ERROR_DROP]; + } + else /* transmit or mark-and-transmit action */ + { + transmitted++; + } + + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) + && (b0->flags & VLIB_BUFFER_IS_TRACED))) + { + vnet_policer_trace_t *t = + vlib_add_trace (vm, node, b0, sizeof (*t)); + t->sw_if_index = sw_if_index0; + t->next_index = next0; + t->policer_index = pi0; + } + + /* verify speculative enqueue, maybe switch current next frame */ + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, + to_next, n_left_to_next, + bi0, next0); + } + + vlib_put_next_frame (vm, node, next_index, n_left_to_next); + } + + vlib_node_increment_counter (vm, node->node_index, + VNET_POLICER_ERROR_TRANSMIT, transmitted); + return frame->n_vectors; +} + +uword +vnet_policer_by_sw_if_index (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * frame) +{ + return vnet_policer_inline (vm, node, frame, + VNET_POLICER_INDEX_BY_SW_IF_INDEX); +} + +uword +vnet_policer_by_opaque (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * frame) +{ + return vnet_policer_inline (vm, node, frame, VNET_POLICER_INDEX_BY_OPAQUE); +} + +uword +vnet_policer_by_either (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * frame) +{ + return vnet_policer_inline (vm, node, frame, VNET_POLICER_INDEX_BY_EITHER); +} + +void +vnet_policer_node_funcs_reference (void) +{ +} + + +#define TEST_CODE 1 + +#ifdef TEST_CODE + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (policer_by_sw_if_index_node, static) = { + .function = vnet_policer_by_sw_if_index, + .name = "policer-by-sw-if-index", + .vector_size = sizeof (u32), + .format_trace = format_policer_trace, + .type = VLIB_NODE_TYPE_INTERNAL, + + .n_errors = ARRAY_LEN(vnet_policer_error_strings), + .error_strings = vnet_policer_error_strings, + + .n_next_nodes = VNET_POLICER_N_NEXT, + + /* edit / add dispositions here */ + .next_nodes = { + [VNET_POLICER_NEXT_TRANSMIT] = "ethernet-input", + [VNET_POLICER_NEXT_DROP] = "error-drop", + }, +}; + +VLIB_NODE_FUNCTION_MULTIARCH (policer_by_sw_if_index_node, + vnet_policer_by_sw_if_index); +/* *INDENT-ON* */ + + +int +test_policer_add_del (u32 rx_sw_if_index, u8 * config_name, int is_add) +{ + vnet_policer_main_t *pm = &vnet_policer_main; + policer_read_response_type_st *template; + policer_read_response_type_st *policer; + vnet_hw_interface_t *rxhi; + uword *p; + + rxhi = vnet_get_sup_hw_interface (pm->vnet_main, rx_sw_if_index); + + /* Make sure caller didn't pass a vlan subif, etc. */ + if (rxhi->sw_if_index != rx_sw_if_index) + return VNET_API_ERROR_INVALID_SW_IF_INDEX; + + if (is_add) + { + + p = hash_get_mem (pm->policer_config_by_name, config_name); + + if (p == 0) + return -2; + + template = pool_elt_at_index (pm->policer_templates, p[0]); + + vnet_hw_interface_rx_redirect_to_node + (pm->vnet_main, rxhi->hw_if_index, policer_by_sw_if_index_node.index); + + pool_get_aligned (pm->policers, policer, CLIB_CACHE_LINE_BYTES); + + policer[0] = template[0]; + + vec_validate (pm->policer_index_by_sw_if_index, rx_sw_if_index); + pm->policer_index_by_sw_if_index[rx_sw_if_index] + = policer - pm->policers; + } + else + { + u32 pi; + vnet_hw_interface_rx_redirect_to_node (pm->vnet_main, + rxhi->hw_if_index, + ~0 /* disable */ ); + + pi = pm->policer_index_by_sw_if_index[rx_sw_if_index]; + pm->policer_index_by_sw_if_index[rx_sw_if_index] = ~0; + pool_put_index (pm->policers, pi); + } + + return 0; +} + +static clib_error_t * +test_policer_command_fn (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + vnet_policer_main_t *pm = &vnet_policer_main; + unformat_input_t _line_input, *line_input = &_line_input; + u32 rx_sw_if_index; + int rv; + u8 *config_name = 0; + int rx_set = 0; + int is_add = 1; + int is_show = 0; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "intfc %U", unformat_vnet_sw_interface, + pm->vnet_main, &rx_sw_if_index)) + rx_set = 1; + else if (unformat (line_input, "show")) + is_show = 1; + else if (unformat (line_input, "policer %s", &config_name)) + ; + else if (unformat (line_input, "del")) + is_add = 0; + else + break; + } + + if (rx_set == 0) + return clib_error_return (0, "interface not set"); + + if (is_show) + { + u32 pi = pm->policer_index_by_sw_if_index[rx_sw_if_index]; + policer_read_response_type_st *policer; + policer = pool_elt_at_index (pm->policers, pi); + + vlib_cli_output (vm, "%U", format_policer_instance, policer); + return 0; + } + + if (is_add && config_name == 0) + { + return clib_error_return (0, "policer config name required"); + } + + rv = test_policer_add_del (rx_sw_if_index, config_name, is_add); + + switch (rv) + { + case 0: + break; + + default: + return clib_error_return + (0, "WARNING: vnet_vnet_policer_add_del returned %d", rv); + } + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (test_patch_command, static) = { + .path = "test policer", + .short_help = + "intfc policer [del]", + .function = test_policer_command_fn, +}; +/* *INDENT-ON* */ + +#endif /* TEST_CODE */ + + +typedef struct +{ + u32 sw_if_index; + u32 next_index; + u32 table_index; + u32 offset; + u32 policer_index; +} policer_classify_trace_t; + +static u8 * +format_policer_classify_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 *); + policer_classify_trace_t *t = va_arg (*args, policer_classify_trace_t *); + + s = format (s, "POLICER_CLASSIFY: sw_if_index %d next %d table %d offset %d" + " policer_index %d", + t->sw_if_index, t->next_index, t->table_index, t->offset, + t->policer_index); + return s; +} + +#define foreach_policer_classify_error \ +_(MISS, "Policer classify misses") \ +_(HIT, "Policer classify hits") \ +_(CHAIN_HIT, "Polcier classify hits after chain walk") \ +_(DROP, "Policer classify action drop") + +typedef enum +{ +#define _(sym,str) POLICER_CLASSIFY_ERROR_##sym, + foreach_policer_classify_error +#undef _ + POLICER_CLASSIFY_N_ERROR, +} policer_classify_error_t; + +static char *policer_classify_error_strings[] = { +#define _(sym,string) string, + foreach_policer_classify_error +#undef _ +}; + +static inline uword +policer_classify_inline (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame, + policer_classify_table_id_t tid) +{ + u32 n_left_from, *from, *to_next; + policer_classify_next_index_t next_index; + policer_classify_main_t *pcm = &policer_classify_main; + vnet_classify_main_t *vcm = pcm->vnet_classify_main; + f64 now = vlib_time_now (vm); + u32 hits = 0; + u32 misses = 0; + u32 chain_hits = 0; + u32 drop = 0; + u32 n_next_nodes; + u64 time_in_policer_periods; + + time_in_policer_periods = + clib_cpu_time_now () >> POLICER_TICKS_PER_PERIOD_SHIFT; + + n_next_nodes = node->n_next_nodes; + + from = vlib_frame_vector_args (frame); + n_left_from = frame->n_vectors; + + /* First pass: compute hashes */ + while (n_left_from > 2) + { + vlib_buffer_t *b0, *b1; + u32 bi0, bi1; + u8 *h0, *h1; + u32 sw_if_index0, sw_if_index1; + u32 table_index0, table_index1; + vnet_classify_table_t *t0, *t1; + + /* Prefetch next iteration */ + { + vlib_buffer_t *p1, *p2; + + p1 = vlib_get_buffer (vm, from[1]); + p2 = vlib_get_buffer (vm, from[2]); + + vlib_prefetch_buffer_header (p1, STORE); + CLIB_PREFETCH (p1->data, CLIB_CACHE_LINE_BYTES, STORE); + vlib_prefetch_buffer_header (p2, STORE); + CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE); + } + + bi0 = from[0]; + b0 = vlib_get_buffer (vm, bi0); + h0 = b0->data; + + bi1 = from[1]; + b1 = vlib_get_buffer (vm, bi1); + h1 = b1->data; + + sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; + table_index0 = + pcm->classify_table_index_by_sw_if_index[tid][sw_if_index0]; + + sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX]; + table_index1 = + pcm->classify_table_index_by_sw_if_index[tid][sw_if_index1]; + + t0 = pool_elt_at_index (vcm->tables, table_index0); + + t1 = pool_elt_at_index (vcm->tables, table_index1); + + vnet_buffer (b0)->l2_classify.hash = + vnet_classify_hash_packet (t0, (u8 *) h0); + + vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash); + + vnet_buffer (b1)->l2_classify.hash = + vnet_classify_hash_packet (t1, (u8 *) h1); + + vnet_classify_prefetch_bucket (t1, vnet_buffer (b1)->l2_classify.hash); + + vnet_buffer (b0)->l2_classify.table_index = table_index0; + + vnet_buffer (b1)->l2_classify.table_index = table_index1; + + from += 2; + n_left_from -= 2; + } + + while (n_left_from > 0) + { + vlib_buffer_t *b0; + u32 bi0; + u8 *h0; + u32 sw_if_index0; + u32 table_index0; + vnet_classify_table_t *t0; + + bi0 = from[0]; + b0 = vlib_get_buffer (vm, bi0); + h0 = b0->data; + + sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; + table_index0 = + pcm->classify_table_index_by_sw_if_index[tid][sw_if_index0]; + + t0 = pool_elt_at_index (vcm->tables, table_index0); + vnet_buffer (b0)->l2_classify.hash = + vnet_classify_hash_packet (t0, (u8 *) h0); + + vnet_buffer (b0)->l2_classify.table_index = table_index0; + vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash); + + from++; + n_left_from--; + } + + next_index = node->cached_next_index; + from = vlib_frame_vector_args (frame); + n_left_from = frame->n_vectors; + + while (n_left_from > 0) + { + u32 n_left_to_next; + + vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); + + /* Not enough load/store slots to dual loop... */ + while (n_left_from > 0 && n_left_to_next > 0) + { + u32 bi0; + vlib_buffer_t *b0; + u32 next0 = POLICER_CLASSIFY_NEXT_INDEX_DROP; + u32 table_index0; + vnet_classify_table_t *t0; + vnet_classify_entry_t *e0; + u64 hash0; + u8 *h0; + u8 act0; + + /* Stride 3 seems to work best */ + if (PREDICT_TRUE (n_left_from > 3)) + { + vlib_buffer_t *p1 = vlib_get_buffer (vm, from[3]); + vnet_classify_table_t *tp1; + u32 table_index1; + u64 phash1; + + table_index1 = vnet_buffer (p1)->l2_classify.table_index; + + if (PREDICT_TRUE (table_index1 != ~0)) + { + tp1 = pool_elt_at_index (vcm->tables, table_index1); + phash1 = vnet_buffer (p1)->l2_classify.hash; + vnet_classify_prefetch_entry (tp1, phash1); + } + } + + /* Speculatively enqueue b0 to the current next frame */ + bi0 = from[0]; + to_next[0] = bi0; + from += 1; + to_next += 1; + n_left_from -= 1; + n_left_to_next -= 1; + + b0 = vlib_get_buffer (vm, bi0); + h0 = b0->data; + table_index0 = vnet_buffer (b0)->l2_classify.table_index; + e0 = 0; + t0 = 0; + + if (tid == POLICER_CLASSIFY_TABLE_L2) + { + /* Feature bitmap update */ + vnet_buffer (b0)->l2.feature_bitmap &= + ~L2INPUT_FEAT_POLICER_CLAS; + /* Determine the next node */ + next0 = + feat_bitmap_get_next_node_index (pcm->feat_next_node_index, + vnet_buffer (b0)-> + l2.feature_bitmap); + } + else + vnet_get_config_data (pcm->vnet_config_main[tid], + &b0->current_config_index, &next0, + /* # bytes of config data */ 0); + + vnet_buffer (b0)->l2_classify.opaque_index = ~0; + + if (PREDICT_TRUE (table_index0 != ~0)) + { + hash0 = vnet_buffer (b0)->l2_classify.hash; + t0 = pool_elt_at_index (vcm->tables, table_index0); + e0 = vnet_classify_find_entry (t0, (u8 *) h0, hash0, now); + + if (e0) + { + act0 = vnet_policer_police (vm, + b0, + e0->next_index, + time_in_policer_periods, + e0->opaque_index); + if (PREDICT_FALSE (act0 == SSE2_QOS_ACTION_DROP)) + { + next0 = POLICER_CLASSIFY_NEXT_INDEX_DROP; + b0->error = node->errors[POLICER_CLASSIFY_ERROR_DROP]; + drop++; + } + hits++; + } + else + { + while (1) + { + if (PREDICT_TRUE (t0->next_table_index != ~0)) + { + t0 = pool_elt_at_index (vcm->tables, + t0->next_table_index); + } + else + { + next0 = (t0->miss_next_index < n_next_nodes) ? + t0->miss_next_index : next0; + misses++; + break; + } + + hash0 = vnet_classify_hash_packet (t0, (u8 *) h0); + e0 = + vnet_classify_find_entry (t0, (u8 *) h0, hash0, now); + if (e0) + { + act0 = vnet_policer_police (vm, + b0, + e0->next_index, + time_in_policer_periods, + e0->opaque_index); + if (PREDICT_FALSE (act0 == SSE2_QOS_ACTION_DROP)) + { + next0 = POLICER_CLASSIFY_NEXT_INDEX_DROP; + b0->error = + node->errors[POLICER_CLASSIFY_ERROR_DROP]; + drop++; + } + hits++; + chain_hits++; + break; + } + } + } + } + if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) + && (b0->flags & VLIB_BUFFER_IS_TRACED))) + { + policer_classify_trace_t *t = + vlib_add_trace (vm, node, b0, sizeof (*t)); + t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; + t->next_index = next0; + t->table_index = t0 ? t0 - vcm->tables : ~0; + t->offset = (e0 && t0) ? vnet_classify_get_offset (t0, e0) : ~0; + t->policer_index = e0 ? e0->next_index : ~0; + } + + /* Verify speculative enqueue, maybe switch current next frame */ + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, + n_left_to_next, bi0, next0); + } + + vlib_put_next_frame (vm, node, next_index, n_left_to_next); + } + + vlib_node_increment_counter (vm, node->node_index, + POLICER_CLASSIFY_ERROR_MISS, misses); + vlib_node_increment_counter (vm, node->node_index, + POLICER_CLASSIFY_ERROR_HIT, hits); + vlib_node_increment_counter (vm, node->node_index, + POLICER_CLASSIFY_ERROR_CHAIN_HIT, chain_hits); + vlib_node_increment_counter (vm, node->node_index, + POLICER_CLASSIFY_ERROR_DROP, drop); + + return frame->n_vectors; +} + +static uword +ip4_policer_classify (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * frame) +{ + return policer_classify_inline (vm, node, frame, + POLICER_CLASSIFY_TABLE_IP4); +} + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (ip4_policer_classify_node) = { + .function = ip4_policer_classify, + .name = "ip4-policer-classify", + .vector_size = sizeof (u32), + .format_trace = format_policer_classify_trace, + .n_errors = ARRAY_LEN(policer_classify_error_strings), + .error_strings = policer_classify_error_strings, + .n_next_nodes = POLICER_CLASSIFY_NEXT_INDEX_N_NEXT, + .next_nodes = { + [POLICER_CLASSIFY_NEXT_INDEX_DROP] = "error-drop", + }, +}; + +VLIB_NODE_FUNCTION_MULTIARCH (ip4_policer_classify_node, ip4_policer_classify); +/* *INDENT-ON* */ + +static uword +ip6_policer_classify (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * frame) +{ + return policer_classify_inline (vm, node, frame, + POLICER_CLASSIFY_TABLE_IP6); +} + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (ip6_policer_classify_node) = { + .function = ip6_policer_classify, + .name = "ip6-policer-classify", + .vector_size = sizeof (u32), + .format_trace = format_policer_classify_trace, + .n_errors = ARRAY_LEN(policer_classify_error_strings), + .error_strings = policer_classify_error_strings, + .n_next_nodes = POLICER_CLASSIFY_NEXT_INDEX_N_NEXT, + .next_nodes = { + [POLICER_CLASSIFY_NEXT_INDEX_DROP] = "error-drop", + }, +}; + +VLIB_NODE_FUNCTION_MULTIARCH (ip6_policer_classify_node, ip6_policer_classify); +/* *INDENT-ON* */ + +static uword +l2_policer_classify (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * frame) +{ + return policer_classify_inline (vm, node, frame, POLICER_CLASSIFY_TABLE_L2); +} + +VLIB_REGISTER_NODE (l2_policer_classify_node) = +{ + .function = l2_policer_classify,.name = "l2-policer-classify",.vector_size = + sizeof (u32),.format_trace = format_policer_classify_trace,.n_errors = + ARRAY_LEN (policer_classify_error_strings),.error_strings = + policer_classify_error_strings,.n_next_nodes = + POLICER_CLASSIFY_NEXT_INDEX_N_NEXT,.next_nodes = + { + [POLICER_CLASSIFY_NEXT_INDEX_DROP] = "error-drop",} +,}; + +VLIB_NODE_FUNCTION_MULTIARCH (l2_policer_classify_node, l2_policer_classify); + + +static clib_error_t * +policer_classify_init (vlib_main_t * vm) +{ + policer_classify_main_t *pcm = &policer_classify_main; + + pcm->vlib_main = vm; + pcm->vnet_main = vnet_get_main (); + pcm->vnet_classify_main = &vnet_classify_main; + + /* Initialize L2 feature next-node indexes */ + feat_bitmap_init_next_nodes (vm, + l2_policer_classify_node.index, + L2INPUT_N_FEAT, + l2input_get_feat_names (), + pcm->feat_next_node_index); + + return 0; +} + +VLIB_INIT_FUNCTION (policer_classify_init); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/vnet/policer/police.h b/src/vnet/policer/police.h new file mode 100644 index 00000000..34bcf9ca --- /dev/null +++ b/src/vnet/policer/police.h @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __POLICE_H__ +#define __POLICE_H__ + +typedef enum +{ + POLICE_CONFORM = 0, + POLICE_EXCEED = 1, + POLICE_VIOLATE = 2, +} policer_result_e; + +// This is the hardware representation of the policer. +// To be multithread-safe, the policer is accessed through a spin-lock +// on the lock field. (For a policer update operation, 24B needs to be +// modified and this would be a challenge to do with atomic instructions.) +// The structure is padded so that no other data is put into the same +// 64B cache-line. This reduces cache-thrashing between threads. +// +// A note on scale: +// The HW TSC tick is roughly one CPU clock cycle. +// This is shifted to create a larger period, with a goal to be around 50usec. +// The period time will vary based on CPU clock speed. +// CPU speeds of 1Ghz to 8Ghz are targetted. +// The shift amount is a constant 17 bits, resulting in a period between +// 16usec (8Ghz CPU) and 131usec (1Ghz CPU). +// The token_per_period computation takes into account the clock speed. +// +// The 32-bit bucket/limit supports about 850ms of burst on a 40GE port, +// or 340ms on a 100GE port. If a larger burst is configued, then the +// programmed value is simply capped at 2^32-1. If we needed to support +// more than that, the bucket and limit fields could be expanded. +// +// tokens_per_period should be > 1000 to support 0.1% granularity. +// To support lower rates (which would not meet this requirement), the packet +// length, bucket, and limit values can be scaled. The scale is a power of 2 +// so the multiplication can be implemented as a shift. The control plane +// computes the shift amount be the largest possible that still supports the +// burst size. This makes the rate accuracy as high as possible. +// +// The 64-bit last_update_time supports a 4Ghz CPU without rollover for 100 years +// +// The lock field should be used for a spin-lock on the struct. + +#define POLICER_TICKS_PER_PERIOD_SHIFT 17 +#define POLICER_TICKS_PER_PERIOD (1 << POLICER_TICKS_PER_PERIOD_SHIFT) + +typedef struct +{ + + u32 lock; // for exclusive access to the struct + + u32 single_rate; // 1 = single rate policer, 0 = two rate policer + u32 color_aware; // for hierarchical policing + u32 scale; // power-of-2 shift amount for lower rates + u8 action[3]; + u8 mark_dscp[3]; + u8 pad[2]; + + // Fields are marked as 2R if they are only used for a 2-rate policer, + // and MOD if they are modified as part of the update operation. + // 1 token = 1 byte. + + u32 cir_tokens_per_period; // # of tokens for each period + u32 pir_tokens_per_period; // 2R + + u32 current_limit; + u32 current_bucket; // MOD + u32 extended_limit; + u32 extended_bucket; // MOD + + u64 last_update_time; // MOD + u64 pad64; + +} policer_read_response_type_st; + +static inline policer_result_e +vnet_police_packet (policer_read_response_type_st * policer, + u32 packet_length, + policer_result_e packet_color, u64 time) +{ + u64 n_periods; + u64 current_tokens, extended_tokens; + policer_result_e result; + + // Scale packet length to support a wide range of speeds + packet_length = packet_length << policer->scale; + + // Compute the number of policer periods that have passed since the last + // operation. + n_periods = time - policer->last_update_time; + policer->last_update_time = time; + + // Since there is no background last-update-time adjustment, n_periods + // could grow large if the policer is idle for a long time. This could + // cause a 64-bit overflow when computing tokens_per_period * num_periods. + // It will overflow if log2(n_periods) + log2(tokens_per_period) > 64. + // + // To mitigate this, the policer configuration algorithm insures that + // tokens_per_period is less than 2^22, i.e. this is a 22 bit value not + // a 32-bit value. Thus overflow will only occur if n_periods > 64-22 or + // 42. 2^42 min-sized periods is 16us * 2^42, or 2 years. So this can + // rarely occur. If overflow does happen, the only effect will be that + // fewer tokens than the max burst will be added to the bucket for this + // packet. This constraint on tokens_per_period lets the ucode omit + // code to dynamically check for or prevent the overflow. + + if (policer->single_rate) + { + + // Compute number of tokens for this time period + current_tokens = + policer->current_bucket + n_periods * policer->cir_tokens_per_period; + if (current_tokens > policer->current_limit) + { + current_tokens = policer->current_limit; + } + + extended_tokens = + policer->extended_bucket + n_periods * policer->cir_tokens_per_period; + if (extended_tokens > policer->extended_limit) + { + extended_tokens = policer->extended_limit; + } + + // Determine color + + if ((!policer->color_aware || (packet_color == POLICE_CONFORM)) + && (current_tokens >= packet_length)) + { + policer->current_bucket = current_tokens - packet_length; + policer->extended_bucket = extended_tokens - packet_length; + result = POLICE_CONFORM; + } + else if ((!policer->color_aware || (packet_color != POLICE_VIOLATE)) + && (extended_tokens >= packet_length)) + { + policer->current_bucket = current_tokens; + policer->extended_bucket = extended_tokens - packet_length; + result = POLICE_EXCEED; + } + else + { + policer->current_bucket = current_tokens; + policer->extended_bucket = extended_tokens; + result = POLICE_VIOLATE; + } + + } + else + { + // Two-rate policer + + // Compute number of tokens for this time period + current_tokens = + policer->current_bucket + n_periods * policer->cir_tokens_per_period; + extended_tokens = + policer->extended_bucket + n_periods * policer->pir_tokens_per_period; + if (current_tokens > policer->current_limit) + { + current_tokens = policer->current_limit; + } + if (extended_tokens > policer->extended_limit) + { + extended_tokens = policer->extended_limit; + } + + // Determine color + + if ((policer->color_aware && (packet_color == POLICE_VIOLATE)) + || (extended_tokens < packet_length)) + { + policer->current_bucket = current_tokens; + policer->extended_bucket = extended_tokens; + result = POLICE_VIOLATE; + } + else if ((policer->color_aware && (packet_color == POLICE_EXCEED)) + || (current_tokens < packet_length)) + { + policer->current_bucket = current_tokens; + policer->extended_bucket = extended_tokens - packet_length; + result = POLICE_EXCEED; + } + else + { + policer->current_bucket = current_tokens - packet_length; + policer->extended_bucket = extended_tokens - packet_length; + result = POLICE_CONFORM; + } + } + return result; +} + +#endif // __POLICE_H__ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/vnet/policer/policer.c b/src/vnet/policer/policer.c new file mode 100644 index 00000000..290a6af5 --- /dev/null +++ b/src/vnet/policer/policer.c @@ -0,0 +1,528 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include + +clib_error_t * +policer_add_del (vlib_main_t * vm, + u8 * name, + sse2_qos_pol_cfg_params_st * cfg, + u32 * policer_index, u8 is_add) +{ + vnet_policer_main_t *pm = &vnet_policer_main; + policer_read_response_type_st test_policer; + policer_read_response_type_st *policer; + uword *p; + u32 pi; + int rv; + + p = hash_get_mem (pm->policer_config_by_name, name); + + if (is_add == 0) + { + if (p == 0) + { + vec_free (name); + return clib_error_return (0, "No such policer configuration"); + } + hash_unset_mem (pm->policer_config_by_name, name); + hash_unset_mem (pm->policer_index_by_name, name); + vec_free (name); + return 0; + } + + if (p != 0) + { + vec_free (name); + return clib_error_return (0, "Policer already exists"); + } + + /* Vet the configuration before adding it to the table */ + rv = sse2_pol_logical_2_physical (cfg, &test_policer); + + if (rv == 0) + { + policer_read_response_type_st *pp; + sse2_qos_pol_cfg_params_st *cp; + + pool_get (pm->configs, cp); + pool_get (pm->policer_templates, pp); + + ASSERT (cp - pm->configs == pp - pm->policer_templates); + + clib_memcpy (cp, cfg, sizeof (*cp)); + clib_memcpy (pp, &test_policer, sizeof (*pp)); + + hash_set_mem (pm->policer_config_by_name, name, cp - pm->configs); + pool_get_aligned (pm->policers, policer, CLIB_CACHE_LINE_BYTES); + policer[0] = pp[0]; + pi = policer - pm->policers; + hash_set_mem (pm->policer_index_by_name, name, pi); + *policer_index = pi; + } + else + { + vec_free (name); + return clib_error_return (0, "Config failed sanity check"); + } + + return 0; +} + +u8 * +format_policer_instance (u8 * s, va_list * va) +{ + policer_read_response_type_st *i + = va_arg (*va, policer_read_response_type_st *); + + s = format (s, "policer at %llx: %s rate, %s color-aware\n", + i, i->single_rate ? "single" : "dual", + i->color_aware ? "is" : "not"); + s = format (s, "cir %u tok/period, pir %u tok/period, scale %u\n", + i->cir_tokens_per_period, i->pir_tokens_per_period, i->scale); + s = format (s, "cur lim %u, cur bkt %u, ext lim %u, ext bkt %u\n", + i->current_limit, + i->current_bucket, i->extended_limit, i->extended_bucket); + s = format (s, "last update %llu\n", i->last_update_time); + return s; +} + +static u8 * +format_policer_round_type (u8 * s, va_list * va) +{ + sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *); + + if (c->rnd_type == SSE2_QOS_ROUND_TO_CLOSEST) + s = format (s, "closest"); + else if (c->rnd_type == SSE2_QOS_ROUND_TO_UP) + s = format (s, "up"); + else if (c->rnd_type == SSE2_QOS_ROUND_TO_DOWN) + s = format (s, "down"); + else + s = format (s, "ILLEGAL"); + return s; +} + + +static u8 * +format_policer_rate_type (u8 * s, va_list * va) +{ + sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *); + + if (c->rate_type == SSE2_QOS_RATE_KBPS) + s = format (s, "kbps"); + else if (c->rate_type == SSE2_QOS_RATE_PPS) + s = format (s, "pps"); + else + s = format (s, "ILLEGAL"); + return s; +} + +static u8 * +format_policer_type (u8 * s, va_list * va) +{ + sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *); + + if (c->rfc == SSE2_QOS_POLICER_TYPE_1R2C) + s = format (s, "1r2c"); + + else if (c->rfc == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697) + s = format (s, "1r3c"); + + else if (c->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698) + s = format (s, "2r3c-2698"); + + else if (c->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115) + s = format (s, "2r3c-4115"); + + else if (c->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1) + s = format (s, "2r3c-mef5cf1"); + else + s = format (s, "ILLEGAL"); + return s; +} + +static u8 * +format_dscp (u8 * s, va_list * va) +{ + u32 i = va_arg (*va, u32); + char *t = 0; + + switch (i) + { +#define _(v,f,str) case VNET_DSCP_##f: t = str; break; + foreach_vnet_dscp +#undef _ + default: + return format (s, "ILLEGAL"); + } + s = format (s, "%s", t); + return s; +} + +static u8 * +format_policer_action_type (u8 * s, va_list * va) +{ + sse2_qos_pol_action_params_st *a + = va_arg (*va, sse2_qos_pol_action_params_st *); + + if (a->action_type == SSE2_QOS_ACTION_DROP) + s = format (s, "drop"); + else if (a->action_type == SSE2_QOS_ACTION_TRANSMIT) + s = format (s, "transmit"); + else if (a->action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) + s = format (s, "mark-and-transmit %U", format_dscp, a->dscp); + else + s = format (s, "ILLEGAL"); + return s; +} + +u8 * +format_policer_config (u8 * s, va_list * va) +{ + sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *); + + s = format (s, "type %U cir %u eir %u cb %u eb %u\n", + format_policer_type, c, + c->rb.kbps.cir_kbps, + c->rb.kbps.eir_kbps, c->rb.kbps.cb_bytes, c->rb.kbps.eb_bytes); + s = format (s, "rate type %U, round type %U\n", + format_policer_rate_type, c, format_policer_round_type, c); + s = format (s, "conform action %U, exceed action %U, violate action %U\n", + format_policer_action_type, &c->conform_action, + format_policer_action_type, &c->exceed_action, + format_policer_action_type, &c->violate_action); + return s; +} + +static uword +unformat_policer_type (unformat_input_t * input, va_list * va) +{ + sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *); + + if (!unformat (input, "type")) + return 0; + + if (unformat (input, "1r2c")) + c->rfc = SSE2_QOS_POLICER_TYPE_1R2C; + else if (unformat (input, "1r3c")) + c->rfc = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697; + else if (unformat (input, "2r3c-2698")) + c->rfc = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698; + else if (unformat (input, "2r3c-4115")) + c->rfc = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115; + else if (unformat (input, "2r3c-mef5cf1")) + c->rfc = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1; + else + return 0; + return 1; +} + +static uword +unformat_policer_round_type (unformat_input_t * input, va_list * va) +{ + sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *); + + if (!unformat (input, "round")) + return 0; + + if (unformat (input, "closest")) + c->rnd_type = SSE2_QOS_ROUND_TO_CLOSEST; + else if (unformat (input, "up")) + c->rnd_type = SSE2_QOS_ROUND_TO_UP; + else if (unformat (input, "down")) + c->rnd_type = SSE2_QOS_ROUND_TO_DOWN; + else + return 0; + return 1; +} + +static uword +unformat_policer_rate_type (unformat_input_t * input, va_list * va) +{ + sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *); + + if (!unformat (input, "rate")) + return 0; + + if (unformat (input, "kbps")) + c->rate_type = SSE2_QOS_RATE_KBPS; + else if (unformat (input, "pps")) + c->rate_type = SSE2_QOS_RATE_PPS; + else + return 0; + return 1; +} + +static uword +unformat_policer_cir (unformat_input_t * input, va_list * va) +{ + sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *); + + if (unformat (input, "cir %u", &c->rb.kbps.cir_kbps)) + return 1; + return 0; +} + +static uword +unformat_policer_eir (unformat_input_t * input, va_list * va) +{ + sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *); + + if (unformat (input, "eir %u", &c->rb.kbps.eir_kbps)) + return 1; + return 0; +} + +static uword +unformat_policer_cb (unformat_input_t * input, va_list * va) +{ + sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *); + + if (unformat (input, "cb %u", &c->rb.kbps.cb_bytes)) + return 1; + return 0; +} + +static uword +unformat_policer_eb (unformat_input_t * input, va_list * va) +{ + sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *); + + if (unformat (input, "eb %u", &c->rb.kbps.eb_bytes)) + return 1; + return 0; +} + +static uword +unformat_dscp (unformat_input_t * input, va_list * va) +{ + u8 *r = va_arg (*va, u8 *); + + if (0); +#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f; + foreach_vnet_dscp +#undef _ + else + return 0; + return 1; +} + +static uword +unformat_policer_action_type (unformat_input_t * input, va_list * va) +{ + sse2_qos_pol_action_params_st *a + = va_arg (*va, sse2_qos_pol_action_params_st *); + + if (unformat (input, "drop")) + a->action_type = SSE2_QOS_ACTION_DROP; + else if (unformat (input, "transmit")) + a->action_type = SSE2_QOS_ACTION_TRANSMIT; + else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp)) + a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT; + else + return 0; + return 1; +} + +static uword +unformat_policer_action (unformat_input_t * input, va_list * va) +{ + sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *); + + if (unformat (input, "conform-action %U", unformat_policer_action_type, + &c->conform_action)) + return 1; + else if (unformat (input, "exceed-action %U", unformat_policer_action_type, + &c->exceed_action)) + return 1; + else if (unformat (input, "violate-action %U", unformat_policer_action_type, + &c->violate_action)) + return 1; + return 0; +} + +static uword +unformat_policer_classify_next_index (unformat_input_t * input, va_list * va) +{ + u32 *r = va_arg (*va, u32 *); + vnet_policer_main_t *pm = &vnet_policer_main; + uword *p; + u8 *match_name = 0; + + if (unformat (input, "%s", &match_name)) + ; + else + return 0; + + p = hash_get_mem (pm->policer_index_by_name, match_name); + + if (p == 0) + return 0; + + *r = p[0]; + + return 1; +} + +static uword +unformat_policer_classify_precolor (unformat_input_t * input, va_list * va) +{ + u32 *r = va_arg (*va, u32 *); + + if (unformat (input, "conform-color")) + *r = POLICE_CONFORM; + else if (unformat (input, "exceed-color")) + *r = POLICE_EXCEED; + else + return 0; + + return 1; +} + +#define foreach_config_param \ +_(eb) \ +_(cb) \ +_(eir) \ +_(cir) \ +_(rate_type) \ +_(round_type) \ +_(type) \ +_(action) + +static clib_error_t * +configure_policer_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + sse2_qos_pol_cfg_params_st c; + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1; + u8 *name = 0; + u32 pi; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + memset (&c, 0, sizeof (c)); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "name %s", &name)) + ; + else if (unformat (line_input, "color-aware")) + c.color_aware = 1; + +#define _(a) else if (unformat (line_input, "%U", unformat_policer_##a, &c)) ; + foreach_config_param +#undef _ + else + return clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + } + + unformat_free (line_input); + + return policer_add_del (vm, name, &c, &pi, is_add); +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (configure_policer_command, static) = { + .path = "configure policer", + .short_help = "configure policer name ", + .function = configure_policer_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +show_policer_command_fn (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + vnet_policer_main_t *pm = &vnet_policer_main; + hash_pair_t *p; + u32 pool_index; + u8 *match_name = 0; + u8 *name; + sse2_qos_pol_cfg_params_st *config; + policer_read_response_type_st *templ; + + (void) unformat (input, "name %s", &match_name); + + /* *INDENT-OFF* */ + hash_foreach_pair (p, pm->policer_config_by_name, + ({ + name = (u8 *) p->key; + if (match_name == 0 || !strcmp((char *) name, (char *) match_name)) + { + pool_index = p->value[0]; + config = pool_elt_at_index (pm->configs, pool_index); + templ = pool_elt_at_index (pm->policer_templates, pool_index); + vlib_cli_output (vm, "Name \"%s\" %U ", + name, format_policer_config, config); + vlib_cli_output (vm, "Template %U", + format_policer_instance, templ); + vlib_cli_output (vm, "-----------"); + } + })); + /* *INDENT-ON* */ + return 0; +} + + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (show_policer_command, static) = { + .path = "show policer", + .short_help = "show policer [name]", + .function = show_policer_command_fn, +}; +/* *INDENT-ON* */ + +clib_error_t * +policer_init (vlib_main_t * vm) +{ + vnet_policer_main_t *pm = &vnet_policer_main; + void vnet_policer_node_funcs_reference (void); + + vnet_policer_node_funcs_reference (); + + pm->vlib_main = vm; + pm->vnet_main = vnet_get_main (); + + pm->policer_config_by_name = hash_create_string (0, sizeof (uword)); + pm->policer_index_by_name = hash_create_string (0, sizeof (uword)); + + vnet_classify_register_unformat_policer_next_index_fn + (unformat_policer_classify_next_index); + vnet_classify_register_unformat_opaque_index_fn + (unformat_policer_classify_precolor); + + return 0; +} + +VLIB_INIT_FUNCTION (policer_init); + + + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/vnet/policer/policer.h b/src/vnet/policer/policer.h new file mode 100644 index 00000000..8e2d7c79 --- /dev/null +++ b/src/vnet/policer/policer.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __included_policer_h__ +#define __included_policer_h__ + +#include +#include + +#include +#include + +typedef struct +{ + /* policer pool, aligned */ + policer_read_response_type_st *policers; + + /* config + template h/w policer instance parallel pools */ + sse2_qos_pol_cfg_params_st *configs; + policer_read_response_type_st *policer_templates; + + /* Config by name hash */ + uword *policer_config_by_name; + + /* Policer by name hash */ + uword *policer_index_by_name; + + /* Policer by sw_if_index vector */ + u32 *policer_index_by_sw_if_index; + + /* convenience */ + vlib_main_t *vlib_main; + vnet_main_t *vnet_main; +} vnet_policer_main_t; + +vnet_policer_main_t vnet_policer_main; + +typedef enum +{ + VNET_POLICER_INDEX_BY_SW_IF_INDEX, + VNET_POLICER_INDEX_BY_OPAQUE, + VNET_POLICER_INDEX_BY_EITHER, +} vnet_policer_index_t; + +typedef enum +{ + VNET_POLICER_NEXT_TRANSMIT, + VNET_POLICER_NEXT_DROP, + VNET_POLICER_N_NEXT, +} vnet_policer_next_t; + +#define foreach_vnet_dscp \ + _(0 , CS0, "CS0") \ + _(8 , CS1, "CS1") \ + _(10, AF11, "AF11") \ + _(12, AF12, "AF12") \ + _(14, AF13, "AF13") \ + _(16, CS2, "CS2") \ + _(18, AF21, "AF21") \ + _(20, AF22, "AF22") \ + _(22, AF23, "AF23") \ + _(24, CS3, "CS3") \ + _(26, AF31, "AF31") \ + _(28, AF32, "AF32") \ + _(30, AF33, "AF33") \ + _(32, CS4, "CS4") \ + _(34, AF41, "AF41") \ + _(36, AF42, "AF42") \ + _(38, AF43, "AF43") \ + _(40, CS5, "CS5") \ + _(46, EF, "EF") \ + _(48, CS6, "CS6") \ + _(50, CS7, "CS7") + +typedef enum +{ +#define _(v,f,str) VNET_DSCP_##f = v, + foreach_vnet_dscp +#undef _ +} vnet_dscp_t; + +u8 *format_policer_instance (u8 * s, va_list * va); +clib_error_t *policer_add_del (vlib_main_t * vm, + u8 * name, + sse2_qos_pol_cfg_params_st * cfg, + u32 * policer_index, u8 is_add); + +#endif /* __included_policer_h__ */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/vnet/policer/xlate.c b/src/vnet/policer/xlate.c new file mode 100644 index 00000000..74a6eb23 --- /dev/null +++ b/src/vnet/policer/xlate.c @@ -0,0 +1,1505 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#define INTERNAL_SS 1 + +/* debugs */ +#define SSE2_QOS_DEBUG_ERROR(msg, args...) \ + fformat(stderr, msg "\n", ##args); + +#define SSE2_QOS_DEBUG_INFO(msg, args...) \ + fformat(stderr, msg "\n", ##args); + + +#define SSE2_QOS_TR_ERR(TpParms...) +// { +// } + +#define SSE2_QOS_TR_INFO(TpParms...) + +#ifndef MIN +#define MIN(x,y) (((x)<(y))?(x):(y)) +#endif + +#ifndef MAX +#define MAX(x,y) (((x)>(y))?(x):(y)) +#endif + +#define IPE_POLICER_FULL_WRITE_REQUEST_M40AH_OFFSET 0 +#define IPE_POLICER_FULL_WRITE_REQUEST_M40AH_MASK 8 +#define IPE_POLICER_FULL_WRITE_REQUEST_M40AH_SHIFT 24 + +#define IPE_POLICER_FULL_WRITE_REQUEST_TYPE_OFFSET 2 +#define IPE_POLICER_FULL_WRITE_REQUEST_TYPE_MASK 2 +#define IPE_POLICER_FULL_WRITE_REQUEST_TYPE_SHIFT 10 + +#define IPE_POLICER_FULL_WRITE_REQUEST_CMD_OFFSET 3 +#define IPE_POLICER_FULL_WRITE_REQUEST_CMD_MASK 2 +#define IPE_POLICER_FULL_WRITE_REQUEST_CMD_SHIFT 0 + +#define IPE_POLICER_FULL_WRITE_REQUEST_M40AL_OFFSET 4 +#define IPE_POLICER_FULL_WRITE_REQUEST_M40AL_MASK 32 +#define IPE_POLICER_FULL_WRITE_REQUEST_M40AL_SHIFT 0 + +#define IPE_POLICER_FULL_WRITE_REQUEST_RFC_OFFSET 8 +#define IPE_POLICER_FULL_WRITE_REQUEST_RFC_MASK 2 +#define IPE_POLICER_FULL_WRITE_REQUEST_RFC_SHIFT 30 + +#define IPE_POLICER_FULL_WRITE_REQUEST_AN_OFFSET 8 +#define IPE_POLICER_FULL_WRITE_REQUEST_AN_MASK 1 +#define IPE_POLICER_FULL_WRITE_REQUEST_AN_SHIFT 29 + +#define IPE_POLICER_FULL_WRITE_REQUEST_REXP_OFFSET 8 +#define IPE_POLICER_FULL_WRITE_REQUEST_REXP_MASK 4 +#define IPE_POLICER_FULL_WRITE_REQUEST_REXP_SHIFT 22 + +#define IPE_POLICER_FULL_WRITE_REQUEST_ARM_OFFSET 9 +#define IPE_POLICER_FULL_WRITE_REQUEST_ARM_MASK 11 +#define IPE_POLICER_FULL_WRITE_REQUEST_ARM_SHIFT 11 + +#define IPE_POLICER_FULL_WRITE_REQUEST_PRM_OFFSET 10 +#define IPE_POLICER_FULL_WRITE_REQUEST_PRM_MASK 11 +#define IPE_POLICER_FULL_WRITE_REQUEST_PRM_SHIFT 0 + +#define IPE_POLICER_FULL_WRITE_REQUEST_CBLE_OFFSET 12 +#define IPE_POLICER_FULL_WRITE_REQUEST_CBLE_MASK 5 +#define IPE_POLICER_FULL_WRITE_REQUEST_CBLE_SHIFT 27 + +#define IPE_POLICER_FULL_WRITE_REQUEST_CBLM_OFFSET 12 +#define IPE_POLICER_FULL_WRITE_REQUEST_CBLM_MASK 7 +#define IPE_POLICER_FULL_WRITE_REQUEST_CBLM_SHIFT 20 + +#define IPE_POLICER_FULL_WRITE_REQUEST_EBLE_OFFSET 13 +#define IPE_POLICER_FULL_WRITE_REQUEST_EBLE_MASK 5 +#define IPE_POLICER_FULL_WRITE_REQUEST_EBLE_SHIFT 15 + +#define IPE_POLICER_FULL_WRITE_REQUEST_EBLM_OFFSET 14 +#define IPE_POLICER_FULL_WRITE_REQUEST_EBLM_MASK 7 +#define IPE_POLICER_FULL_WRITE_REQUEST_EBLM_SHIFT 8 + +#define IPE_POLICER_FULL_WRITE_REQUEST_CB_OFFSET 16 +#define IPE_POLICER_FULL_WRITE_REQUEST_CB_MASK 31 +#define IPE_POLICER_FULL_WRITE_REQUEST_CB_SHIFT 0 + +#define IPE_POLICER_FULL_WRITE_REQUEST_EB_OFFSET 20 +#define IPE_POLICER_FULL_WRITE_REQUEST_EB_MASK 31 +#define IPE_POLICER_FULL_WRITE_REQUEST_EB_SHIFT 0 + +#define IPE_RFC_RFC2697 0x00000000 +#define IPE_RFC_RFC2698 0x00000001 +#define IPE_RFC_RFC4115 0x00000002 +#define IPE_RFC_MEF5CF1 0x00000003 + +/* End of constants copied from sse_ipe_desc_fmt.h */ + +/* Misc Policer specific definitions */ +#define SSE2_QOS_POLICER_FIXED_PKT_SIZE 256 + +// TODO check what can be provided by hw macro based on ASIC +#define SSE2_QOS_POL_TICKS_PER_SEC 1000LL /* 1 tick = 1 ms */ + +/* + * Default burst, in ms (byte format) + */ +#define SSE2_QOS_POL_DEF_BURST_BYTE 100 + +/* + * Minimum burst needs to be such that the largest packet size is accomodated + */ +// Do we need to get it from some lib? +#define SSE2_QOS_POL_MIN_BURST_BYTE 9*1024 + + +/* + * Flag to indicate if AN is employed or not + * 1 - TRUE, 0 - FALSE + */ +#define SSE2_QOS_POL_ALLOW_NEGATIVE 1 + +// Various Macros to take care of policer calculations + +#define SSE2_QOS_POL_COMM_BKT_MAX \ + (1<> 1)) / denominator); + break; + + case SSE2_QOS_ROUND_TO_UP: + *rounded_value = (numerator / denominator); + if ((*rounded_value * denominator) < numerator) + { + *rounded_value += 1; + } + break; + + case SSE2_QOS_ROUND_TO_DOWN: + *rounded_value = (numerator / denominator); + break; + + case SSE2_QOS_ROUND_INVALID: + default: + SSE2_QOS_DEBUG_ERROR ("Illegal round type"); + SSE2_QOS_TR_ERR (SSE2_QOS_TP_ERR_60, round_type); + rc = EINVAL; + break; + } + return (rc); +} + + +static int +sse2_pol_validate_cfg_params (sse2_qos_pol_cfg_params_st * cfg) +{ + u64 numer, denom, rnd_value; + u32 cir_hw, eir_hw; + int rc = 0; + + if ((cfg->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698) && + (cfg->rb.kbps.eir_kbps < cfg->rb.kbps.cir_kbps)) + { + SSE2_QOS_DEBUG_ERROR ("CIR (%u kbps) is greater than PIR (%u kbps)", + cfg->rb.kbps.cir_kbps, cfg->rb.kbps.eir_kbps); + SSE2_QOS_TR_ERR (SSE2_QOS_TP_ERR_39, cfg->rb.kbps.cir_kbps, + cfg->rb.kbps.eir_kbps); + return (EINVAL); + } + + /* + * convert rates to bytes-per-tick + */ + numer = (u64) (cfg->rb.kbps.cir_kbps); + denom = (u64) (8 * SSE2_QOS_POL_TICKS_PER_SEC) / 1000; + rc = sse2_qos_pol_round (numer, denom, &rnd_value, + (sse2_qos_round_type_en) cfg->rnd_type); + if (rc != 0) + { + SSE2_QOS_DEBUG_ERROR ("Unable to convert CIR to bytes/tick format"); + // Error traced + return (rc); + } + cir_hw = (u32) rnd_value; + + numer = (u64) (cfg->rb.kbps.eir_kbps); + rc = sse2_qos_pol_round (numer, denom, &rnd_value, + (sse2_qos_round_type_en) cfg->rnd_type); + if (rc != 0) + { + SSE2_QOS_DEBUG_ERROR ("Unable to convert EIR to bytes/tick format"); + // Error traced + return (rc); + } + eir_hw = (u32) rnd_value; + + if (cir_hw > SSE2_QOS_POL_AVG_RATE_MAX) + { + SSE2_QOS_DEBUG_ERROR ("hw cir (%u bytes/tick) is greater than the " + "max supported value (%u)", cir_hw, + SSE2_QOS_POL_AVG_RATE_MAX); + SSE2_QOS_TR_ERR (SSE2_QOS_TP_ERR_84, cir_hw, SSE2_QOS_POL_AVG_RATE_MAX); + return (EINVAL); + } + + if (eir_hw > SSE2_QOS_POL_PEAK_RATE_MAX) + { + SSE2_QOS_DEBUG_ERROR ("hw eir (%u bytes/tick) is greater than the " + "max supported value (%u). Capping it to the max. " + "supported value", eir_hw, + SSE2_QOS_POL_PEAK_RATE_MAX); + SSE2_QOS_TR_ERR (SSE2_QOS_TP_ERR_85, eir_hw, + SSE2_QOS_POL_PEAK_RATE_MAX); + return (EINVAL); + } + /* + * CIR = 0, with bc != 0 is not allowed + */ + if ((cfg->rb.kbps.cir_kbps == 0) && cfg->rb.kbps.cb_bytes) + { + SSE2_QOS_DEBUG_ERROR ("CIR = 0 with bc != 0"); + SSE2_QOS_TR_ERR (SSE2_QOS_TP_ERR_55); + return (EINVAL); + } + + if ((cfg->rb.kbps.eir_kbps == 0) && + (cfg->rfc > SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)) + { + SSE2_QOS_DEBUG_ERROR ("EIR = 0 for a 2R3C policer (rfc: %u)", cfg->rfc); + SSE2_QOS_TR_ERR (SSE2_QOS_TP_ERR_23, cfg->rb.kbps.eir_kbps, cfg->rfc); + return (EINVAL); + } + + if (cfg->rb.kbps.eir_kbps && + (cfg->rfc < SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)) + { + SSE2_QOS_DEBUG_ERROR ("EIR: %u kbps for a 1-rate policer (rfc: %u)", + cfg->rb.kbps.eir_kbps, cfg->rfc); + SSE2_QOS_TR_ERR (SSE2_QOS_TP_ERR_23, cfg->rb.kbps.eir_kbps, cfg->rfc); + return (EINVAL); + } + + if ((cfg->rfc == SSE2_QOS_POLICER_TYPE_1R2C) && cfg->rb.kbps.eb_bytes) + { + SSE2_QOS_DEBUG_ERROR ("For a 1R1B policer, EB burst cannot be > 0"); + SSE2_QOS_TR_ERR (SSE2_QOS_TP_ERR_56); + return (EINVAL); + } + + return (0); +} + +static void +sse2_qos_convert_value_to_exp_mant_fmt (u64 value, + u16 max_exp_value, + u16 max_mant_value, + sse2_qos_round_type_en type, + u8 * exp, u32 * mant) +{ + u64 rnd_value; + u64 temp_mant; + u8 temp_exp; + + /* + * Select the lowest possible exp, and the largest possible mant + */ + temp_exp = 0; + temp_mant = value; + while (temp_exp <= max_exp_value) + { + if (temp_mant <= max_mant_value) + { + break; + } + + temp_exp++; + rnd_value = 0; + (void) sse2_qos_pol_round ((u64) value, (u64) (1 << temp_exp), + &rnd_value, type); + temp_mant = rnd_value; + } + + if (temp_exp > max_exp_value) + { + /* + * CAP mant to its max value, and decrement exp + */ + temp_exp--; + temp_mant = max_mant_value; + } + + *exp = temp_exp; + *mant = (u32) temp_mant; + + SSE2_QOS_DEBUG_INFO ("value: 0x%llx, mant: %u, exp: %u", value, *mant, + *exp); + return; +} + +static int +sse2_pol_convert_cfg_rates_to_hw (sse2_qos_pol_cfg_params_st * cfg, + sse2_qos_pol_hw_params_st * hw) +{ + int rc = 0; + u32 cir_hw, eir_hw, hi_mant, hi_rate, cir_rnded, eir_rnded, eir_kbps; + u64 numer, denom, rnd_value; + u8 exp; + + /* + * convert rates to bytes-per-tick (tick is 1ms) + * For rate conversion, the denominator is gonna be the same + */ + denom = (u64) ((SSE2_QOS_POL_TICKS_PER_SEC * 8) / 1000); + numer = (u64) (cfg->rb.kbps.cir_kbps); + rc = sse2_qos_pol_round (numer, denom, &rnd_value, + (sse2_qos_round_type_en) cfg->rnd_type); + if (rc != 0) + { + SSE2_QOS_DEBUG_ERROR + ("Rounding error, rate: %d kbps, rounding_type: %d", + cfg->rb.kbps.cir_kbps, cfg->rnd_type); + // Error is traced + return (rc); + } + cir_hw = (u32) rnd_value; + + if (cfg->rb.kbps.cir_kbps && (cir_hw == 0)) + { + /* + * After rounding, cir_hw = 0. Bump it up + */ + cir_hw = 1; + } + + if (cfg->rfc == SSE2_QOS_POLICER_TYPE_1R2C) + { + eir_kbps = 0; + } + else if (cfg->rfc == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697) + { + eir_kbps = cfg->rb.kbps.cir_kbps; + } + else if (cfg->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115) + { + eir_kbps = cfg->rb.kbps.eir_kbps - cfg->rb.kbps.cir_kbps; + } + else + { + eir_kbps = cfg->rb.kbps.eir_kbps; + } + + numer = (u64) eir_kbps; + rc = sse2_qos_pol_round (numer, denom, &rnd_value, + (sse2_qos_round_type_en) cfg->rnd_type); + if (rc != 0) + { + SSE2_QOS_DEBUG_ERROR + ("Rounding error, rate: %d kbps, rounding_type: %d", eir_kbps, + cfg->rnd_type); + // Error is traced + return (rc); + } + eir_hw = (u32) rnd_value; + + if (eir_kbps && (eir_hw == 0)) + { + /* + * After rounding, eir_hw = 0. Bump it up + */ + eir_hw = 1; + } + + SSE2_QOS_DEBUG_INFO ("cir_hw: %u bytes/tick, eir_hw: %u bytes/tick", cir_hw, + eir_hw); + + if (cir_hw > eir_hw) + { + hi_rate = cir_hw; + } + else + { + hi_rate = eir_hw; + } + + if ((cir_hw == 0) && (eir_hw == 0)) + { + /* + * Both the rates are 0. Use exp = 15, and set the RFC to 4115. Also + * set AN = 0 + */ + exp = (u8) SSE2_QOS_POL_RATE_EXP_MAX; + hi_mant = 0; + hw->rfc = IPE_RFC_RFC4115; + hw->allow_negative = 0; + } + else + { + sse2_qos_convert_value_to_exp_mant_fmt (hi_rate, + (u16) SSE2_QOS_POL_RATE_EXP_MAX, + (u16) + SSE2_QOS_POL_AVG_RATE_MANT_MAX, + (sse2_qos_round_type_en) + cfg->rnd_type, &exp, &hi_mant); + } + + denom = (1ULL << exp); + if (hi_rate == eir_hw) + { + hw->peak_rate_man = (u16) hi_mant; + rc = sse2_qos_pol_round ((u64) cir_hw, denom, &rnd_value, + (sse2_qos_round_type_en) cfg->rnd_type); + hw->avg_rate_man = (u16) rnd_value; + } + else + { + hw->avg_rate_man = (u16) hi_mant; + rc = sse2_qos_pol_round ((u64) eir_hw, denom, &rnd_value, + (sse2_qos_round_type_en) cfg->rnd_type); + hw->peak_rate_man = (u16) rnd_value; + } + if (rc != 0) + { + SSE2_QOS_DEBUG_ERROR ("Rounding error"); + // Error is traced + return (rc); + } + hw->rate_exp = exp; + + if ((hw->avg_rate_man == 0) && (cfg->rb.kbps.cir_kbps)) + { + /* + * cir was reduced to 0 during rounding. Bump it up + */ + hw->avg_rate_man = 1; + SSE2_QOS_DEBUG_INFO ("CIR = 0 during rounding. Bump it up to %u " + "bytes/tick", (hw->avg_rate_man << hw->rate_exp)); + } + + if ((hw->peak_rate_man == 0) && eir_kbps) + { + /* + * eir was reduced to 0 during rounding. Bump it up + */ + hw->peak_rate_man = 1; + SSE2_QOS_DEBUG_INFO ("EIR = 0 during rounding. Bump it up to %u " + "bytes/tick", (hw->peak_rate_man << hw->rate_exp)); + } + + cir_rnded = (hw->avg_rate_man << hw->rate_exp); + eir_rnded = (hw->peak_rate_man << hw->rate_exp); + + SSE2_QOS_DEBUG_INFO ("Configured(rounded) values, cir: %u " + "kbps (mant: %u, exp: %u, rate: %u bytes/tick)", + cfg->rb.kbps.cir_kbps, hw->avg_rate_man, + hw->rate_exp, cir_rnded); + + SSE2_QOS_DEBUG_INFO ("Configured(rounded) values, eir: %u " + "kbps (mant: %u, exp: %u, rate: %u bytes/tick)", + cfg->rb.kbps.eir_kbps, hw->peak_rate_man, + hw->rate_exp, eir_rnded); + + return (rc); +} + +/***** + * NAME + * sse2_pol_get_bkt_max + * + * PARAMETERS + * rate_hw - either the averate rate or peak rate + * bkt_max - bit width in the current bucket or extended bucket + * + * RETURNS + * u64 - maximum token bytes for the current or extended bucket + * + * DESCRIPTION + * The current bucket or extended bucket fields are in units of either + * 1,2,4,8 bytes based on the average or peak rate respective to current + * or extended bucket. + * + * To get the actual maximum number of bytes that can be stored in the + * field, the value must be multiplied by the units of either 1,2,4,8 + * bytes based on the rate. + *****/ +u64 +sse2_pol_get_bkt_max (u64 rate_hw, u64 bkt_max) +{ + if (rate_hw <= RATE64) + { + return (bkt_max - 1); + } + else if (rate_hw <= RATE128) + { + return ((bkt_max * RATE_64TO128_UNIT) - RATE_64TO128_UNIT); + } + else if (rate_hw <= RATE256) + { + return ((bkt_max * RATE_128TO256_UNIT) - RATE_128TO256_UNIT); + } + /* rate must be over 256 */ + return ((bkt_max * RATE_OVER256_UNIT) - RATE_OVER256_UNIT); +} + +/***** + * NAME + * sse2_pol_get_bkt_value + * + * PARAMETERS + * rate_hw - either the averate rate or peak rate + * byte_value - bytes for this token bucket + * + * RETURNS + * u64 - unit value for the current or extended bucket field + * + * DESCRIPTION + * The current bucket or extended bucket fields are in units of either + * 1,2,4,8 bytes based on the average or peak rate respective to current + * or extended bucket. + * + * To get the units that can be stored in the field, the byte value must + * be divided by the units of either 1,2,4,8 bytes based on the rate. + *****/ +u64 +sse2_pol_get_bkt_value (u64 rate_hw, u64 byte_value) +{ + if (rate_hw <= RATE64) + { + return (byte_value); + } + else if (rate_hw <= RATE128) + { + return (byte_value / RATE_64TO128_UNIT); + } + else if (rate_hw <= RATE256) + { + return (byte_value / RATE_128TO256_UNIT); + } + /* rate must be over 256 */ + return (byte_value / RATE_OVER256_UNIT); +} + +static void +sse2_pol_rnd_burst_byte_fmt (u64 cfg_burst, + u16 max_exp_value, + u16 max_mant_value, + u32 max_bkt_value, + u32 rate_hw, + u8 * exp, u32 * mant, u32 * bkt_value) +{ + u64 bkt_max = max_bkt_value; + u64 bkt_limit_max; + u64 rnd_burst; + u64 temp_bkt_value; + + bkt_limit_max = ((u64) max_mant_value << (u64) max_exp_value); + bkt_max = sse2_pol_get_bkt_max (rate_hw, bkt_max); + bkt_max = MIN (bkt_max, bkt_limit_max); + if (!cfg_burst) + { + /* + * If configured burst = 0, compute the burst to be 100ms at a given + * rate. Note that for rate_hw = 0, exp = mant = 0. + */ + cfg_burst = (u64) rate_hw *(u64) SSE2_QOS_POL_DEF_BURST_BYTE; + } + + if (cfg_burst > bkt_max) + { + SSE2_QOS_DEBUG_ERROR ("burst 0x%llx bytes is greater than the max. " + "supported value 0x%llx bytes. Capping it to the " + "max", cfg_burst, bkt_max); + SSE2_QOS_TR_INFO (SSE2_QOS_TP_INFO_38, + (uint) cfg_burst, (uint) bkt_max); + cfg_burst = bkt_max; + } + + if (cfg_burst < SSE2_QOS_POL_MIN_BURST_BYTE) + { + /* + * Bump up the burst value ONLY if the cfg_burst is non-zero AND + * less than the min. supported value + */ + SSE2_QOS_DEBUG_INFO ("burst 0x%llx bytes is less than the min " + "supported value %u bytes. Rounding it up to " + "the min", cfg_burst, SSE2_QOS_POL_MIN_BURST_BYTE); + SSE2_QOS_TR_INFO (SSE2_QOS_TP_INFO_39, (uint) cfg_burst, + SSE2_QOS_POL_MIN_BURST_BYTE); + cfg_burst = SSE2_QOS_POL_MIN_BURST_BYTE; + } + + sse2_qos_convert_value_to_exp_mant_fmt (cfg_burst, + max_exp_value, + max_mant_value, + SSE2_QOS_ROUND_TO_DOWN, exp, mant); + + /* Bucket value is based on rate. */ + rnd_burst = ((u64) (*mant) << (u64) (*exp)); + temp_bkt_value = sse2_pol_get_bkt_value (rate_hw, rnd_burst); + *bkt_value = (u32) temp_bkt_value; +} + +static int +sse2_pol_convert_cfg_burst_to_hw (sse2_qos_pol_cfg_params_st * cfg, + sse2_qos_pol_hw_params_st * hw) +{ + u8 temp_exp; + u32 temp_mant, rate_hw; + u64 eb_bytes; + u32 bkt_value; + + /* + * compute Committed Burst + */ + SSE2_QOS_DEBUG_INFO ("Compute commit burst ..."); + rate_hw = (hw->avg_rate_man) << (hw->rate_exp); + sse2_pol_rnd_burst_byte_fmt (cfg->rb.kbps.cb_bytes, + (u16) SSE2_QOS_POL_COMM_BKT_LIMIT_EXP_MAX, + (u16) SSE2_QOS_POL_COMM_BKT_LIMIT_MANT_MAX, + (u32) SSE2_QOS_POL_COMM_BKT_MAX, + rate_hw, &temp_exp, &temp_mant, &bkt_value); + SSE2_QOS_DEBUG_INFO ("Committed burst, burst_limit: 0x%llx mant : %u, " + "exp: %u, rnded: 0x%llx cb:%u bytes", + cfg->rb.kbps.cb_bytes, temp_mant, temp_exp, + ((u64) temp_mant << (u64) temp_exp), bkt_value); + + hw->comm_bkt_limit_exp = temp_exp; + hw->comm_bkt_limit_man = (u8) temp_mant; + hw->comm_bkt = bkt_value; + + /* + * compute Exceed Burst + */ + SSE2_QOS_DEBUG_INFO ("Compute exceed burst ..."); + + if (cfg->rfc == SSE2_QOS_POLICER_TYPE_1R2C) + { + /* + * For 1R2C, hw uses 2R3C (RFC-4115). As such, the Exceed Bucket + * params are set to 0. Recommendation is to use EB_exp = max_exp (=15) + * and EB_mant = 0 + */ + hw->extd_bkt_limit_exp = (u8) SSE2_QOS_POL_EXTD_BKT_LIMIT_EXP_MAX; + hw->extd_bkt_limit_man = 0; + SSE2_QOS_DEBUG_INFO ("Excess burst, burst: 0x%llx mant: %u, " + "exp: %u, rnded: 0x%llx bytes", + cfg->rb.kbps.eb_bytes, hw->extd_bkt_limit_man, + hw->extd_bkt_limit_exp, + ((u64) hw->extd_bkt_limit_man << + (u64) hw->extd_bkt_limit_exp)); + SSE2_QOS_TR_INFO (SSE2_QOS_TP_INFO_20, (uint) cfg->rb.kbps.eb_bytes, + hw->extd_bkt_limit_man, hw->extd_bkt_limit_exp); + return (0); + } + + if (cfg->rfc == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697) + { + eb_bytes = cfg->rb.kbps.cb_bytes + cfg->rb.kbps.eb_bytes; + } + else if (cfg->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115) + { + eb_bytes = cfg->rb.kbps.eb_bytes - cfg->rb.kbps.cb_bytes; + } + else + { + eb_bytes = cfg->rb.kbps.eb_bytes; + } + + rate_hw = (hw->peak_rate_man) << (hw->rate_exp); + sse2_pol_rnd_burst_byte_fmt (eb_bytes, + (u16) SSE2_QOS_POL_EXTD_BKT_LIMIT_EXP_MAX, + (u16) SSE2_QOS_POL_EXTD_BKT_LIMIT_MANT_MAX, + (u32) SSE2_QOS_POL_EXTD_BKT_MAX, + rate_hw, &temp_exp, &temp_mant, &bkt_value); + + SSE2_QOS_DEBUG_INFO ("Excess burst, burst_limit: 0x%llx mant: %u, " + "exp: %u, rnded: 0x%llx eb:%u bytes", + cfg->rb.kbps.eb_bytes, temp_mant, temp_exp, + ((u64) temp_mant << (u64) temp_exp), bkt_value); + + hw->extd_bkt_limit_exp = (u8) temp_exp; + hw->extd_bkt_limit_man = (u8) temp_mant; + hw->extd_bkt = bkt_value; + + return (0); +} + + +/* + * Input: configured parameter values in 'cfg'. + * Output: h/w programmable parameter values in 'hw'. + * Return: success or failure code. + */ +static int +sse2_pol_convert_cfg_to_hw_params (sse2_qos_pol_cfg_params_st * cfg, + sse2_qos_pol_hw_params_st * hw) +{ + int rc = 0; + + /* + * clear the hw_params + */ + memset (hw, 0, sizeof (sse2_qos_pol_hw_params_st)); + + hw->allow_negative = SSE2_QOS_POL_ALLOW_NEGATIVE; + + if ((cfg->rfc == SSE2_QOS_POLICER_TYPE_1R2C) || + (cfg->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)) + { + hw->rfc = IPE_RFC_RFC4115; + } + else if (cfg->rfc == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697) + { + hw->rfc = IPE_RFC_RFC2697; + } + else if (cfg->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698) + { + hw->rfc = IPE_RFC_RFC2698; + } + else if (cfg->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1) + { + hw->rfc = IPE_RFC_MEF5CF1; + } + else + { + SSE2_QOS_DEBUG_ERROR ("Invalid RFC type %d\n", cfg->rfc); + SSE2_QOS_TR_ERR (SSE2_QOS_TP_ERR_61, cfg->rfc); + return (EINVAL); + } + + rc = sse2_pol_convert_cfg_rates_to_hw (cfg, hw); + if (rc != 0) + { + SSE2_QOS_DEBUG_ERROR ("Unable to convert config rates to hw. Error: %d", + rc); + // Error is traced + return (rc); + } + + rc = sse2_pol_convert_cfg_burst_to_hw (cfg, hw); + if (rc != 0) + { + SSE2_QOS_DEBUG_ERROR ("Unable to convert config burst to hw. Error: %d", + rc); + // Error is traced + return (rc); + } + + return 0; +} + + +u32 +sse2_qos_convert_pps_to_kbps (u32 rate_pps) +{ + // sse2_qos_ship_inc_counter(SSE2_QOS_SHIP_COUNTER_TYPE_API_CNT, + // SSE2_QOS_SHIP_CNT_POL_CONV_PPS_TO_KBPS); + + u64 numer, rnd_value = 0; + + numer = (u64) ((u64) rate_pps * + (u64) SSE2_QOS_POLICER_FIXED_PKT_SIZE * 8LL); + (void) sse2_qos_pol_round (numer, 1000LL, &rnd_value, + SSE2_QOS_ROUND_TO_CLOSEST); + + return ((u32) rnd_value); +} + +u32 +sse2_qos_convert_burst_ms_to_bytes (u32 burst_ms, u32 rate_kbps) +{ + u64 numer, rnd_value = 0; + + //sse2_qos_ship_inc_counter(SSE2_QOS_SHIP_COUNTER_TYPE_API_CNT, + // SSE2_QOS_SHIP_CNT_POL_CONV_BURST_MS_TO_BYTES); + + numer = (u64) ((u64) burst_ms * (u64) rate_kbps); + + (void) sse2_qos_pol_round (numer, 8LL, &rnd_value, + SSE2_QOS_ROUND_TO_CLOSEST); + + return ((u32) rnd_value); +} + + +/* + * Input: configured parameters in 'cfg'. + * Output: h/w parameters are returned in 'hw', + * Return: Status, success or failure code. + */ +int +sse2_pol_compute_hw_params (sse2_qos_pol_cfg_params_st * cfg, + sse2_qos_pol_hw_params_st * hw) +{ + int rc = 0; + + if (!cfg || !hw) + { + SSE2_QOS_DEBUG_ERROR ("Illegal parameters"); + return (-1); + } + + /* + * Validate the police config params being presented to RM + */ + rc = sse2_pol_validate_cfg_params (cfg); + if (rc != 0) + { + SSE2_QOS_DEBUG_ERROR ("Config parameter validation failed. Error: %d", + rc); + // Error is traced + return (-1); + } + + /* + * first round configured values to h/w supported values. This func + * also determines whether 'tick' or 'byte' format + */ + rc = sse2_pol_convert_cfg_to_hw_params (cfg, hw); + if (rc != 0) + { + SSE2_QOS_DEBUG_ERROR ("Unable to convert config params to hw params. " + "Error: %d", rc); + SSE2_QOS_TR_ERR (SSE2_QOS_TP_ERR_53, rc); + return (-1); + } + + return 0; +} + + +#if defined (INTERNAL_SS) || defined (X86) + +// For initializing the x86 policer format + +/* + * Return the number of hardware TSC timer ticks per second for the dataplane. + * This is approximately, but not exactly, the clock speed. + */ +static u64 +get_tsc_hz (void) +{ + f64 cpu_freq; + + cpu_freq = os_cpu_clock_frequency (); + return (u64) cpu_freq; +} + +/* + * Convert rates into bytes_per_period and scale. + * Return 0 if ok or 1 if error. + */ +static int +compute_policer_params (u64 hz, // CPU speed in clocks per second + u64 cir_rate, // in bytes per second + u64 pir_rate, // in bytes per second + u32 * current_limit, // in bytes, output may scale the input + u32 * extended_limit, // in bytes, output may scale the input + u32 * cir_bytes_per_period, + u32 * pir_bytes_per_period, u32 * scale) +{ + double period; + double internal_cir_bytes_per_period; + double internal_pir_bytes_per_period; + u32 max; + u32 scale_shift; + u32 scale_amount; + u32 __attribute__ ((unused)) orig_current_limit = *current_limit; + + // Compute period. For 1Ghz-to-8Ghz CPUs, the period will be in + // the range of 16 to 116 usec. + period = ((double) hz) / ((double) POLICER_TICKS_PER_PERIOD); + + // Determine bytes per period for each rate + internal_cir_bytes_per_period = (double) cir_rate / period; + internal_pir_bytes_per_period = (double) pir_rate / period; + + // Scale if possible. Scaling helps rate accuracy, but is contrained + // by the scaled rates and limits fitting in 32-bits. + // In addition, we need to insure the scaled rate is no larger than + // 2^22 tokens per period. This allows the dataplane to ignore overflow + // in the tokens-per-period multiplication since it could only + // happen if the policer were idle for more than a year. + // This is not really a constraint because 100Gbps at 1Ghz is only + // 1.6M tokens per period. +#define MAX_RATE_SHIFT 10 + max = MAX (*current_limit, *extended_limit); + max = MAX (max, (u32) internal_cir_bytes_per_period << MAX_RATE_SHIFT); + max = MAX (max, (u32) internal_pir_bytes_per_period << MAX_RATE_SHIFT); + scale_shift = __builtin_clz (max); + + scale_amount = 1 << scale_shift; + *scale = scale_shift; + + // Scale the limits + *current_limit = *current_limit << scale_shift; + *extended_limit = *extended_limit << scale_shift; + + // Scale the rates + internal_cir_bytes_per_period = + internal_cir_bytes_per_period * ((double) scale_amount); + internal_pir_bytes_per_period = + internal_pir_bytes_per_period * ((double) scale_amount); + + // Make sure the new rates are reasonable + // Only needed for very low rates with large bursts + if (internal_cir_bytes_per_period < 1.0) + { + internal_cir_bytes_per_period = 1.0; + } + if (internal_pir_bytes_per_period < 1.0) + { + internal_pir_bytes_per_period = 1.0; + } + + *cir_bytes_per_period = (u32) internal_cir_bytes_per_period; + *pir_bytes_per_period = (u32) internal_pir_bytes_per_period; + +// #define PRINT_X86_POLICE_PARAMS +#ifdef PRINT_X86_POLICE_PARAMS + { + u64 effective_BPS; + + // This value actually slightly conservative because it doesn't take into account + // the partial period at the end of a second. This really matters only for very low + // rates. + effective_BPS = + (((u64) (*cir_bytes_per_period * (u64) period)) >> *scale); + + printf ("hz=%llu, cir_rate=%llu, limit=%u => " + "periods-per-sec=%d usec-per-period=%d => " + "scale=%d cir_BPP=%u, scaled_limit=%u => " + "effective BPS=%llu, accuracy=%f\n", + // input values + (unsigned long long) hz, + (unsigned long long) cir_rate, orig_current_limit, + // computed values + (u32) (period), // periods per second + (u32) (1000.0 * 1000.0 / period), // in usec + *scale, *cir_bytes_per_period, *current_limit, + // accuracy + (unsigned long long) effective_BPS, + (double) cir_rate / (double) effective_BPS); + } +#endif + + return 0; // ok +} + + +/* + * Input: configured parameters in 'cfg'. + * Output: h/w parameters are returned in 'hw', + * Return: Status, success or failure code. + */ +int +x86_pol_compute_hw_params (sse2_qos_pol_cfg_params_st * cfg, + policer_read_response_type_st * hw) +{ + const int BYTES_PER_KBIT = (1000 / 8); + u64 hz; + u32 cap; + + if (!cfg || !hw) + { + SSE2_QOS_DEBUG_ERROR ("Illegal parameters"); + return (-1); + } + + hz = get_tsc_hz (); + hw->last_update_time = 0; + + // Cap the bursts to 32-bits. This allows up to almost one second of + // burst on a 40GE interface, which should be fine for x86. + cap = + (cfg->rb.kbps.cb_bytes > 0xFFFFFFFF) ? 0xFFFFFFFF : cfg->rb.kbps.cb_bytes; + hw->current_limit = cap; + cap = + (cfg->rb.kbps.eb_bytes > 0xFFFFFFFF) ? 0xFFFFFFFF : cfg->rb.kbps.eb_bytes; + hw->extended_limit = cap; + + if ((cfg->rb.kbps.cir_kbps == 0) && (cfg->rb.kbps.cb_bytes == 0) + && (cfg->rb.kbps.eb_bytes == 0)) + { + // This is a uninitialized, always-violate policer + hw->single_rate = 1; + hw->cir_tokens_per_period = 0; + return 0; + } + + if ((cfg->rfc == SSE2_QOS_POLICER_TYPE_1R2C) || + (cfg->rfc == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)) + { + // Single-rate policer + + hw->single_rate = 1; + + if ((cfg->rfc == SSE2_QOS_POLICER_TYPE_1R2C) && cfg->rb.kbps.eb_bytes) + { + SSE2_QOS_DEBUG_ERROR + ("Policer parameter validation failed -- 1R2C."); + return (-1); + } + + if ((cfg->rb.kbps.cir_kbps == 0) || + (cfg->rb.kbps.eir_kbps != 0) || + ((cfg->rb.kbps.cb_bytes == 0) && (cfg->rb.kbps.eb_bytes == 0))) + { + SSE2_QOS_DEBUG_ERROR ("Policer parameter validation failed -- 1R."); + return (-1); + } + + if (compute_policer_params (hz, + (u64) cfg->rb.kbps.cir_kbps * + BYTES_PER_KBIT, 0, &hw->current_limit, + &hw->extended_limit, + &hw->cir_tokens_per_period, + &hw->pir_tokens_per_period, &hw->scale)) + { + SSE2_QOS_DEBUG_ERROR ("Policer parameter computation failed."); + return (-1); + } + + } + else if ((cfg->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698) || + (cfg->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)) + { + // Two-rate policer + + if ((cfg->rb.kbps.cir_kbps == 0) || (cfg->rb.kbps.eir_kbps == 0) + || (cfg->rb.kbps.eir_kbps < cfg->rb.kbps.cir_kbps) + || (cfg->rb.kbps.cb_bytes == 0) || (cfg->rb.kbps.eb_bytes == 0)) + { + SSE2_QOS_DEBUG_ERROR ("Config parameter validation failed."); + return (-1); + } + + if (compute_policer_params (hz, + (u64) cfg->rb.kbps.cir_kbps * + BYTES_PER_KBIT, + (u64) cfg->rb.kbps.eir_kbps * + BYTES_PER_KBIT, &hw->current_limit, + &hw->extended_limit, + &hw->cir_tokens_per_period, + &hw->pir_tokens_per_period, &hw->scale)) + { + SSE2_QOS_DEBUG_ERROR ("Policer parameter computation failed."); + return (-1); + } + + } + else + { + SSE2_QOS_DEBUG_ERROR + ("Config parameter validation failed. RFC not supported"); + return (-1); + } + + hw->current_bucket = hw->current_limit; + hw->extended_bucket = hw->extended_limit; + + return 0; +} +#endif + + +/* + * Input: configured parameters in 'cfg'. + * Output: physical structure is returned in 'phys', + * Return: Status, success or failure code. + */ +int +sse2_pol_logical_2_physical (sse2_qos_pol_cfg_params_st * cfg, + policer_read_response_type_st * phys) +{ + int rc; + sse2_qos_pol_hw_params_st pol_hw; + sse2_qos_pol_cfg_params_st kbps_cfg; + + memset (phys, 0, sizeof (policer_read_response_type_st)); + memset (&kbps_cfg, 0, sizeof (sse2_qos_pol_cfg_params_st)); + + if (!cfg) + { + SSE2_QOS_DEBUG_ERROR ("Illegal parameters"); + return (-1); + } + + switch (cfg->rate_type) + { + case SSE2_QOS_RATE_KBPS: + /* copy all the data into kbps_cfg */ + kbps_cfg.rb.kbps.cir_kbps = cfg->rb.kbps.cir_kbps; + kbps_cfg.rb.kbps.eir_kbps = cfg->rb.kbps.eir_kbps; + kbps_cfg.rb.kbps.cb_bytes = cfg->rb.kbps.cb_bytes; + kbps_cfg.rb.kbps.eb_bytes = cfg->rb.kbps.eb_bytes; + break; + case SSE2_QOS_RATE_PPS: + kbps_cfg.rb.kbps.cir_kbps = + sse2_qos_convert_pps_to_kbps (cfg->rb.pps.cir_pps); + kbps_cfg.rb.kbps.eir_kbps = + sse2_qos_convert_pps_to_kbps (cfg->rb.pps.eir_pps); + kbps_cfg.rb.kbps.cb_bytes = sse2_qos_convert_burst_ms_to_bytes ((u32) + cfg-> + rb.pps.cb_ms, + kbps_cfg.rb. + kbps.cir_kbps); + kbps_cfg.rb.kbps.eb_bytes = + sse2_qos_convert_burst_ms_to_bytes ((u32) cfg->rb.pps.eb_ms, + kbps_cfg.rb.kbps.eir_kbps); + break; + default: + SSE2_QOS_DEBUG_ERROR ("Illegal rate type"); + return (-1); + } + + /* rate type is now converted to kbps */ + kbps_cfg.rate_type = SSE2_QOS_RATE_KBPS; + kbps_cfg.rnd_type = cfg->rnd_type; + kbps_cfg.rfc = cfg->rfc; + + phys->action[POLICE_CONFORM] = cfg->conform_action.action_type; + phys->mark_dscp[POLICE_CONFORM] = cfg->conform_action.dscp; + phys->action[POLICE_EXCEED] = cfg->exceed_action.action_type; + phys->mark_dscp[POLICE_EXCEED] = cfg->exceed_action.dscp; + phys->action[POLICE_VIOLATE] = cfg->violate_action.action_type; + phys->mark_dscp[POLICE_VIOLATE] = cfg->violate_action.dscp; + + phys->color_aware = cfg->color_aware; + +#if !defined (INTERNAL_SS) && !defined (X86) + // convert logical into hw params which involves qos calculations + rc = sse2_pol_compute_hw_params (&kbps_cfg, &pol_hw); + if (rc == -1) + { + SSE2_QOS_DEBUG_ERROR ("Unable to compute hw param. Error: %d", rc); + return (rc); + } + + // convert hw params into the physical + phys->rfc = pol_hw.rfc; + phys->an = pol_hw.allow_negative; + phys->rexp = pol_hw.rate_exp; + phys->arm = pol_hw.avg_rate_man; + phys->prm = pol_hw.peak_rate_man; + phys->cble = pol_hw.comm_bkt_limit_exp; + phys->cblm = pol_hw.comm_bkt_limit_man; + phys->eble = pol_hw.extd_bkt_limit_exp; + phys->eblm = pol_hw.extd_bkt_limit_man; + phys->cb = pol_hw.comm_bkt; + phys->eb = pol_hw.extd_bkt; + + /* for debugging purposes, the bucket token values can be overwritten */ + if (cfg->overwrite_bucket) + { + phys->cb = cfg->current_bucket; + phys->eb = cfg->extended_bucket; + } +#else + // convert logical into hw params which involves qos calculations + rc = x86_pol_compute_hw_params (&kbps_cfg, phys); + if (rc == -1) + { + SSE2_QOS_DEBUG_ERROR ("Unable to compute hw param. Error: %d", rc); + return (rc); + } + + /* for debugging purposes, the bucket token values can be overwritten */ + if (cfg->overwrite_bucket) + { + phys->current_bucket = cfg->current_bucket; + phys->extended_bucket = cfg->extended_bucket; + } + + // Touch to avoid compiler warning for X86 + pol_hw.allow_negative = pol_hw.allow_negative; + +#endif // if !defined (INTERNAL_SS) && !defined (X86) + + return 0; +} + + +static void +sse2_qos_convert_pol_bucket_to_hw_fmt (policer_read_response_type_st * bkt, + sse2_qos_pol_hw_params_st * hw_fmt) +{ + memset (hw_fmt, 0, sizeof (sse2_qos_pol_hw_params_st)); +#if !defined (INTERNAL_SS) && !defined (X86) + hw_fmt->rfc = (u8) bkt->rfc; + hw_fmt->allow_negative = (u8) bkt->an; + hw_fmt->rate_exp = (u8) bkt->rexp; + hw_fmt->avg_rate_man = (u16) bkt->arm; + hw_fmt->peak_rate_man = (u16) bkt->prm; + hw_fmt->comm_bkt_limit_man = (u8) bkt->cblm; + hw_fmt->comm_bkt_limit_exp = (u8) bkt->cble; + hw_fmt->extd_bkt_limit_man = (u8) bkt->eblm; + hw_fmt->extd_bkt_limit_exp = (u8) bkt->eble; + hw_fmt->extd_bkt = bkt->eb; + hw_fmt->comm_bkt = bkt->cb; +#endif // if !defined (INTERNAL_SS) && !defined (X86) +} + +/* + * Input: h/w programmable parameter values in 'hw' + * Output: configured parameter values in 'cfg' + * Return: Status, success or failure code. + */ +static int +sse2_pol_convert_hw_to_cfg_params (sse2_qos_pol_hw_params_st * hw, + sse2_qos_pol_cfg_params_st * cfg) +{ + u64 temp_rate; + + if ((hw == NULL) || (cfg == NULL)) + { + return EINVAL; + } + + if ((hw->rfc == IPE_RFC_RFC4115) && + !(hw->peak_rate_man << hw->rate_exp) && !(hw->extd_bkt_limit_man)) + { + /* + * For a 1R2C, we set EIR = 0, EB = 0 + */ + cfg->rfc = SSE2_QOS_POLICER_TYPE_1R2C; + } + else if (hw->rfc == IPE_RFC_RFC2697) + { + cfg->rfc = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697; + } + else if (hw->rfc == IPE_RFC_RFC2698) + { + cfg->rfc = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698; + } + else if (hw->rfc == IPE_RFC_RFC4115) + { + cfg->rfc = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115; + } + else if (hw->rfc == IPE_RFC_MEF5CF1) + { + cfg->rfc = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1; + } + else + { + return EINVAL; + } + + temp_rate = (((u64) hw->avg_rate_man << hw->rate_exp) * 8LL * + SSE2_QOS_POL_TICKS_PER_SEC) / 1000; + cfg->rb.kbps.cir_kbps = (u32) temp_rate; + + temp_rate = (((u64) hw->peak_rate_man << hw->rate_exp) * 8LL * + SSE2_QOS_POL_TICKS_PER_SEC) / 1000; + cfg->rb.kbps.eir_kbps = (u32) temp_rate; + + cfg->rb.kbps.cb_bytes = ((u64) hw->comm_bkt_limit_man << + (u64) hw->comm_bkt_limit_exp); + cfg->rb.kbps.eb_bytes = ((u64) hw->extd_bkt_limit_man << + (u64) hw->extd_bkt_limit_exp); + + if (cfg->rfc == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697) + { + /* + * For 1R3C in the hardware, EB = sum(CB, EB). Also, EIR = CIR. Restore + * values such that the configured params don't reflect this adjustment + */ + cfg->rb.kbps.eb_bytes = (cfg->rb.kbps.eb_bytes - cfg->rb.kbps.cb_bytes); + cfg->rb.kbps.eir_kbps = 0; + } + else if (cfg->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115) + { + /* + * For 4115 in the hardware is excess rate and burst, but EA provides + * peak-rate, so adjust it to be eir + */ + cfg->rb.kbps.eir_kbps += cfg->rb.kbps.cir_kbps; + cfg->rb.kbps.eb_bytes += cfg->rb.kbps.cb_bytes; + } + /* h/w conversion to cfg is in kbps */ + cfg->rate_type = SSE2_QOS_RATE_KBPS; + cfg->overwrite_bucket = 0; + cfg->current_bucket = hw->comm_bkt; + cfg->extended_bucket = hw->extd_bkt; + + SSE2_QOS_DEBUG_INFO ("configured params, cir: %u kbps, eir: %u kbps, cb " + "burst: 0x%llx bytes, eb burst: 0x%llx bytes", + cfg->rb.kbps.cir_kbps, cfg->rb.kbps.eir_kbps, + cfg->rb.kbps.cb_bytes, cfg->rb.kbps.eb_bytes); + SSE2_QOS_TR_INFO (SSE2_QOS_TP_INFO_22, cfg->rb.kbps.cir_kbps, + cfg->rb.kbps.eir_kbps, + (uint) cfg->rb.kbps.cb_bytes, + (uint) cfg->rb.kbps.eb_bytes); + + return 0; +} + +u32 +sse2_qos_convert_kbps_to_pps (u32 rate_kbps) +{ + u64 numer, denom, rnd_value = 0; + + // sse_qosrm_ship_inc_counter(SSE2_QOS_SHIP_COUNTER_TYPE_API_CNT, + // SSE2_QOS_SHIP_CNT_POL_CONV_KBPS_TO_PPS); + + numer = (u64) ((u64) rate_kbps * 1000LL); + denom = (u64) ((u64) SSE2_QOS_POLICER_FIXED_PKT_SIZE * 8LL); + + (void) sse2_qos_pol_round (numer, denom, &rnd_value, + SSE2_QOS_ROUND_TO_CLOSEST); + + return ((u32) rnd_value); +} + +u32 +sse2_qos_convert_burst_bytes_to_ms (u64 burst_bytes, u32 rate_kbps) +{ + u64 numer, denom, rnd_value = 0; + + //sse_qosrm_ship_inc_counter(SSE2_QOS_SHIP_COUNTER_TYPE_API_CNT, + // SSE2_QOS_SHIP_CNT_POL_CONV_BYTES_TO_BURST_MS); + + numer = burst_bytes * 8LL; + denom = (u64) rate_kbps; + + (void) sse2_qos_pol_round (numer, denom, &rnd_value, + SSE2_QOS_ROUND_TO_CLOSEST); + + return ((u32) rnd_value); +} + +/* + * Input: physical structure in 'phys', rate_type in cfg + * Output: configured parameters in 'cfg'. + * Return: Status, success or failure code. + */ +int +sse2_pol_physical_2_logical (policer_read_response_type_st * phys, + sse2_qos_pol_cfg_params_st * cfg) +{ + int rc; + sse2_qos_pol_hw_params_st pol_hw; + sse2_qos_pol_cfg_params_st kbps_cfg; + + memset (&pol_hw, 0, sizeof (sse2_qos_pol_hw_params_st)); + memset (&kbps_cfg, 0, sizeof (sse2_qos_pol_cfg_params_st)); + + if (!phys) + { + SSE2_QOS_DEBUG_ERROR ("Illegal parameters"); + return (-1); + } + + sse2_qos_convert_pol_bucket_to_hw_fmt (phys, &pol_hw); + + rc = sse2_pol_convert_hw_to_cfg_params (&pol_hw, &kbps_cfg); + if (rc != 0) + { + SSE2_QOS_DEBUG_ERROR ("Unable to convert hw params to config params. " + "Error: %d", rc); + return (-1); + } + + /* check what rate type is required */ + switch (cfg->rate_type) + { + case SSE2_QOS_RATE_KBPS: + /* copy all the data into kbps_cfg */ + cfg->rb.kbps.cir_kbps = kbps_cfg.rb.kbps.cir_kbps; + cfg->rb.kbps.eir_kbps = kbps_cfg.rb.kbps.eir_kbps; + cfg->rb.kbps.cb_bytes = kbps_cfg.rb.kbps.cb_bytes; + cfg->rb.kbps.eb_bytes = kbps_cfg.rb.kbps.eb_bytes; + break; + case SSE2_QOS_RATE_PPS: + cfg->rb.pps.cir_pps = + sse2_qos_convert_kbps_to_pps (kbps_cfg.rb.kbps.cir_kbps); + cfg->rb.pps.eir_pps = + sse2_qos_convert_kbps_to_pps (kbps_cfg.rb.kbps.eir_kbps); + cfg->rb.pps.cb_ms = + sse2_qos_convert_burst_bytes_to_ms (kbps_cfg.rb.kbps.cb_bytes, + kbps_cfg.rb.kbps.cir_kbps); + cfg->rb.pps.eb_ms = + sse2_qos_convert_burst_bytes_to_ms (kbps_cfg.rb.kbps.eb_bytes, + kbps_cfg.rb.kbps.eir_kbps); + break; + default: + SSE2_QOS_DEBUG_ERROR ("Illegal rate type"); + return (-1); + } + + /* cfg->rate_type remains what it was */ + cfg->rnd_type = kbps_cfg.rnd_type; + cfg->rfc = kbps_cfg.rfc; + cfg->overwrite_bucket = kbps_cfg.overwrite_bucket; + cfg->current_bucket = kbps_cfg.current_bucket; + cfg->extended_bucket = kbps_cfg.extended_bucket; + + return 0; +} + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/vnet/policer/xlate.h b/src/vnet/policer/xlate.h new file mode 100644 index 00000000..16742f80 --- /dev/null +++ b/src/vnet/policer/xlate.h @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*--------------------------------------------------------------------------- + * from gdp_logical_qos.h + *--------------------------------------------------------------------------- + */ + +#ifndef __included_xlate_h__ +#define __included_xlate_h__ + +#include + +/* + * edt: * enum sse2_qos_policer_type_en + * Defines type of policer to be allocated + */ +typedef enum sse2_qos_policer_type_en_ +{ + SSE2_QOS_POLICER_TYPE_1R2C = 0, + SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697 = 1, + SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698 = 2, + SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115 = 3, + SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1 = 4, + SSE2_QOS_POLICER_TYPE_MAX +} sse2_qos_policer_type_en; + +/* + * edt: * enum + * Enum used to define type of rounding used when calculating policer values + */ +typedef enum +{ + SSE2_QOS_ROUND_TO_CLOSEST = 0, + SSE2_QOS_ROUND_TO_UP, + SSE2_QOS_ROUND_TO_DOWN, + SSE2_QOS_ROUND_INVALID +} sse2_qos_round_type_en; + +/* + * edt: * enum + * Enum used to define type of rate for configuration, either pps or kbps. + * If kbps, then burst is in bytes, if pps, then burst is in ms. + * + * Default of zero is kbps, which is inline with how it is programmed + * in actual hardware. However, the warning is that this is reverse logic + * of units_in_bits field in sse2_static_policer_parameters_st, which is + * inline with sse_punt_drop.h. + */ +typedef enum +{ + SSE2_QOS_RATE_KBPS = 0, + SSE2_QOS_RATE_PPS, + SSE2_QOS_RATE_INVALID +} sse2_qos_rate_type_en; + +/* + * edt: * enum + * Defines type of policer actions. + */ +typedef enum +{ + SSE2_QOS_ACTION_DROP = 0, + SSE2_QOS_ACTION_TRANSMIT, + SSE2_QOS_ACTION_MARK_AND_TRANSMIT +} sse2_qos_action_type_en; + +/* + * edt * struct sse2_qos_pol_action_params_st + * This structure is used to hold user configured police action parameters. + * + * element: action_type + * Action type (see sse2_qos_action_type_en). + * elemtnt: dscp + * DSCP value to set when action is SSE2_QOS_ACTION_MARK_AND_TRANSMIT. + */ +typedef struct sse2_qos_pol_action_params_st_ +{ + u8 action_type; + u8 dscp; +} sse2_qos_pol_action_params_st; + +/* + * edt: * struct sse2_qos_pol_cfg_params_st + * + * Description: + * This structure is used to hold user configured policing parameters. + * + * element: cir_kbps + * CIR in kbps. + * element: eir_kbps + * EIR or PIR in kbps. + * element: cb_bytes + * Committed Burst in bytes. + * element: eb_bytes + * Excess or Peak Burst in bytes. + * element: cir_pps + * CIR in pps. + * element: eir_pps + * EIR or PIR in pps. + * element: cb_ms + * Committed Burst in milliseconds. + * element: eb_ms + * Excess or Peak Burst in milliseconds. + * element: rate_type + * Indicates the union if in kbps/bytes or pps/ms. + * element: rfc + * Policer algorithm - 1R2C, 1R3C (2697), 2R3C (2698) or 2R3C (4115). See + * sse_qos_policer_type_en + * element: rnd_type + * Rounding type (see sse_qos_round_type_en). Needed when policer values + * need to be rounded. Caller can decide on type of rounding used + */ +typedef struct sse2_qos_pol_cfg_params_st_ +{ + union + { + struct + { + u32 cir_kbps; + u32 eir_kbps; + u64 cb_bytes; + u64 eb_bytes; + } kbps; + struct + { + u32 cir_pps; + u32 eir_pps; + u64 cb_ms; + u64 eb_ms; + } pps; + } rb; /* rate burst config */ + u8 rate_type; /* sse2_qos_rate_type_en */ + u8 rnd_type; /* sse2_qos_round_type_en */ + u8 rfc; /* sse2_qos_policer_type_en */ + u8 color_aware; + u8 overwrite_bucket; /* for debugging purposes */ + u32 current_bucket; /* for debugging purposes */ + u32 extended_bucket; /* for debugging purposes */ + sse2_qos_pol_action_params_st conform_action; + sse2_qos_pol_action_params_st exceed_action; + sse2_qos_pol_action_params_st violate_action; +} sse2_qos_pol_cfg_params_st; + + +typedef struct sse2_qos_pol_hw_params_st_ +{ + u8 rfc; + u8 allow_negative; + u8 rate_exp; + u16 avg_rate_man; + u16 peak_rate_man; + u8 comm_bkt_limit_exp; + u8 comm_bkt_limit_man; + u8 extd_bkt_limit_exp; + u8 extd_bkt_limit_man; + u32 comm_bkt; + u32 extd_bkt; +} sse2_qos_pol_hw_params_st; + + +int +sse2_pol_logical_2_physical (sse2_qos_pol_cfg_params_st * cfg, + policer_read_response_type_st * phys); + + +#endif /* __included_xlate_h__ */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ -- cgit 1.2.3-korg From d9aad2940530e63aa3f91194e0997a2f9307433c Mon Sep 17 00:00:00 2001 From: Pavel Kotucek Date: Wed, 25 Jan 2017 08:45:38 +0100 Subject: API refactoring : policer Change-Id: Ia7d8b557bcdf45eb8e33bb3d297bc6f7ad321c72 Signed-off-by: Pavel Kotucek --- src/vnet.am | 8 +- src/vnet/policer/policer.api | 147 ++++++++++++++++++++++++++ src/vnet/policer/policer_api.c | 232 +++++++++++++++++++++++++++++++++++++++++ src/vnet/vnet_all_api_h.h | 1 + src/vpp/api/api.c | 138 ------------------------ src/vpp/api/vpe.api | 128 +---------------------- 6 files changed, 387 insertions(+), 267 deletions(-) create mode 100644 src/vnet/policer/policer.api create mode 100644 src/vnet/policer/policer_api.c (limited to 'src/vnet/policer') diff --git a/src/vnet.am b/src/vnet.am index 96cfa557..3d681a13 100644 --- a/src/vnet.am +++ b/src/vnet.am @@ -73,12 +73,16 @@ API_FILES += vnet/interface.api libvnet_la_SOURCES += \ vnet/policer/node_funcs.c \ vnet/policer/policer.c \ - vnet/policer/xlate.c + vnet/policer/xlate.c \ + vnet/policer/policer_api.c nobase_include_HEADERS += \ vnet/policer/police.h \ vnet/policer/policer.h \ - vnet/policer/xlate.h + vnet/policer/xlate.h \ + vnet/policer/policer.api.h + +API_FILES += vnet/policer/policer.api ######################################## # Cop - junk filter diff --git a/src/vnet/policer/policer.api b/src/vnet/policer/policer.api new file mode 100644 index 00000000..26c69032 --- /dev/null +++ b/src/vnet/policer/policer.api @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2015-2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** \brief Add/del policer + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add policer if non-zero, else delete + @param name - policer name + @param cir - CIR + @param eir - EIR + @param cb - Committed Burst + @param eb - Excess or Peak Burst + @param rate_type - rate type + @param round_type - rounding type + @param type - policer algorithm + @param color_aware - 0=color-blind, 1=color-aware + @param conform_action_type - conform action type + @param conform_dscp - DSCP for conform mar-and-transmit action + @param exceed_action_type - exceed action type + @param exceed_dscp - DSCP for exceed mar-and-transmit action + @param violate_action_type - violate action type + @param violate_dscp - DSCP for violate mar-and-transmit action +*/ +define policer_add_del +{ + u32 client_index; + u32 context; + + u8 is_add; + u8 name[64]; + u32 cir; + u32 eir; + u64 cb; + u64 eb; + u8 rate_type; + u8 round_type; + u8 type; + u8 color_aware; + u8 conform_action_type; + u8 conform_dscp; + u8 exceed_action_type; + u8 exceed_dscp; + u8 violate_action_type; + u8 violate_dscp; +}; + +/** \brief Add/del policer response + @param context - sender context, to match reply w/ request + @param retval - return value for request + @param policer_index - for add, returned index of the new policer +*/ +define policer_add_del_reply +{ + u32 context; + i32 retval; + u32 policer_index; +}; + +/** \brief Get list of policers + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param match_name_valid - if 0 request all policers otherwise use match_name + @param match_name - policer name +*/ +define policer_dump +{ + u32 client_index; + u32 context; + + u8 match_name_valid; + u8 match_name[64]; +}; + +/** \brief Policer operational state response. + @param context - sender context, to match reply w/ request + @param name - policer name + @param cir - CIR + @param eir - EIR + @param cb - Committed Burst + @param eb - Excess or Peak Burst + @param rate_type - rate type + @param round_type - rounding type + @param type - policer algorithm + @param conform_action_type - conform action type + @param conform_dscp - DSCP for conform mar-and-transmit action + @param exceed_action_type - exceed action type + @param exceed_dscp - DSCP for exceed mar-and-transmit action + @param violate_action_type - violate action type + @param violate_dscp - DSCP for violate mar-and-transmit action + @param single_rate - 1 = single rate policer, 0 = two rate policer + @param color_aware - for hierarchical policing + @param scale - power-of-2 shift amount for lower rates + @param cir_tokens_per_period - number of tokens for each period + @param pir_tokens_per_period - number of tokens for each period for 2-rate policer + @param current_limit - current limit + @param current_bucket - current bucket + @param extended_limit - extended limit + @param extended_bucket - extended bucket + @param last_update_time - last update time +*/ +define policer_details +{ + u32 context; + + u8 name[64]; + u32 cir; + u32 eir; + u64 cb; + u64 eb; + u8 rate_type; + u8 round_type; + u8 type; + u8 conform_action_type; + u8 conform_dscp; + u8 exceed_action_type; + u8 exceed_dscp; + u8 violate_action_type; + u8 violate_dscp; + u8 single_rate; + u8 color_aware; + u32 scale; + u32 cir_tokens_per_period; + u32 pir_tokens_per_period; + u32 current_limit; + u32 current_bucket; + u32 extended_limit; + u32 extended_bucket; + u64 last_update_time; +}; + +/* + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/vnet/policer/policer_api.c b/src/vnet/policer/policer_api.c new file mode 100644 index 00000000..fb5f08b8 --- /dev/null +++ b/src/vnet/policer/policer_api.c @@ -0,0 +1,232 @@ +/* + *------------------------------------------------------------------ + * policer_api.c - policer api + * + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------ + */ + +#include +#include + +#include +#include +#include + +#include + +#define vl_typedefs /* define message structures */ +#include +#undef vl_typedefs + +#define vl_endianfun /* define message structures */ +#include +#undef vl_endianfun + +/* instantiate all the print functions we know about */ +#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) +#define vl_printfun +#include +#undef vl_printfun + +#include + +#define foreach_vpe_api_msg \ +_(POLICER_ADD_DEL, policer_add_del) \ +_(POLICER_DUMP, policer_dump) + +static void +vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp) +{ + vlib_main_t *vm = vlib_get_main (); + vl_api_policer_add_del_reply_t *rmp; + int rv = 0; + u8 *name = NULL; + sse2_qos_pol_cfg_params_st cfg; + clib_error_t *error; + u32 policer_index; + + name = format (0, "%s", mp->name); + + memset (&cfg, 0, sizeof (cfg)); + cfg.rfc = mp->type; + cfg.rnd_type = mp->round_type; + cfg.rate_type = mp->rate_type; + cfg.rb.kbps.cir_kbps = mp->cir; + cfg.rb.kbps.eir_kbps = mp->eir; + cfg.rb.kbps.cb_bytes = mp->cb; + cfg.rb.kbps.eb_bytes = mp->eb; + cfg.conform_action.action_type = mp->conform_action_type; + cfg.conform_action.dscp = mp->conform_dscp; + cfg.exceed_action.action_type = mp->exceed_action_type; + cfg.exceed_action.dscp = mp->exceed_dscp; + cfg.violate_action.action_type = mp->violate_action_type; + cfg.violate_action.dscp = mp->violate_dscp; + cfg.color_aware = mp->color_aware; + + error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add); + + if (error) + rv = VNET_API_ERROR_UNSPECIFIED; + + /* *INDENT-OFF* */ + REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY, + ({ + if (rv == 0 && mp->is_add) + rmp->policer_index = ntohl(policer_index); + else + rmp->policer_index = ~0; + })); + /* *INDENT-ON* */ +} + +static void +send_policer_details (u8 * name, + sse2_qos_pol_cfg_params_st * config, + policer_read_response_type_st * templ, + unix_shared_memory_queue_t * q, u32 context) +{ + vl_api_policer_details_t *mp; + + mp = vl_msg_api_alloc (sizeof (*mp)); + memset (mp, 0, sizeof (*mp)); + mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS); + mp->context = context; + mp->cir = htonl (config->rb.kbps.cir_kbps); + mp->eir = htonl (config->rb.kbps.eir_kbps); + mp->cb = htonl (config->rb.kbps.cb_bytes); + mp->eb = htonl (config->rb.kbps.eb_bytes); + mp->rate_type = config->rate_type; + mp->round_type = config->rnd_type; + mp->type = config->rfc; + mp->conform_action_type = config->conform_action.action_type; + mp->conform_dscp = config->conform_action.dscp; + mp->exceed_action_type = config->exceed_action.action_type; + mp->exceed_dscp = config->exceed_action.dscp; + mp->violate_action_type = config->violate_action.action_type; + mp->violate_dscp = config->violate_action.dscp; + mp->single_rate = templ->single_rate ? 1 : 0; + mp->color_aware = templ->color_aware ? 1 : 0; + mp->scale = htonl (templ->scale); + mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period); + mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period); + mp->current_limit = htonl (templ->current_limit); + mp->current_bucket = htonl (templ->current_bucket); + mp->extended_limit = htonl (templ->extended_limit); + mp->extended_bucket = htonl (templ->extended_bucket); + mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time); + + strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1); + + vl_msg_api_send_shmem (q, (u8 *) & mp); +} + +static void +vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp) +{ + unix_shared_memory_queue_t *q; + vnet_policer_main_t *pm = &vnet_policer_main; + hash_pair_t *hp; + uword *p; + u32 pool_index; + u8 *match_name = 0; + u8 *name; + sse2_qos_pol_cfg_params_st *config; + policer_read_response_type_st *templ; + + q = vl_api_client_index_to_input_queue (mp->client_index); + if (q == 0) + return; + + if (mp->match_name_valid) + { + match_name = format (0, "%s%c", mp->match_name, 0); + } + + if (mp->match_name_valid) + { + p = hash_get_mem (pm->policer_config_by_name, match_name); + if (p) + { + pool_index = p[0]; + config = pool_elt_at_index (pm->configs, pool_index); + templ = pool_elt_at_index (pm->policer_templates, pool_index); + send_policer_details (match_name, config, templ, q, mp->context); + } + } + else + { + /* *INDENT-OFF* */ + hash_foreach_pair (hp, pm->policer_config_by_name, + ({ + name = (u8 *) hp->key; + pool_index = hp->value[0]; + config = pool_elt_at_index (pm->configs, pool_index); + templ = pool_elt_at_index (pm->policer_templates, pool_index); + send_policer_details(name, config, templ, q, mp->context); + })); + /* *INDENT-ON* */ + } +} + +/* + * policer_api_hookup + * Add vpe's API message handlers to the table. + * vlib has alread mapped shared memory and + * added the client registration handlers. + * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() + */ +#define vl_msg_name_crc_list +#include +#undef vl_msg_name_crc_list + +static void +setup_message_id_table (api_main_t * am) +{ +#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); + foreach_vl_msg_name_crc_policer; +#undef _ +} + +static clib_error_t * +policer_api_hookup (vlib_main_t * vm) +{ + api_main_t *am = &api_main; + +#define _(N,n) \ + vl_msg_api_set_handlers(VL_API_##N, #n, \ + vl_api_##n##_t_handler, \ + vl_noop_handler, \ + vl_api_##n##_t_endian, \ + vl_api_##n##_t_print, \ + sizeof(vl_api_##n##_t), 1); + foreach_vpe_api_msg; +#undef _ + /* + * Set up the (msg_name, crc, message-id) table + */ + setup_message_id_table (am); + + return 0; +} + +VLIB_API_INIT_FUNCTION (policer_api_hookup); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/vnet/vnet_all_api_h.h b/src/vnet/vnet_all_api_h.h index 9a75872d..801ec2d1 100644 --- a/src/vnet/vnet_all_api_h.h +++ b/src/vnet/vnet_all_api_h.h @@ -56,6 +56,7 @@ #include #include #include +#include /* * fd.io coding-style-patch-verification: ON diff --git a/src/vpp/api/api.c b/src/vpp/api/api.c index f929f566..60fd0199 100644 --- a/src/vpp/api/api.c +++ b/src/vpp/api/api.c @@ -66,7 +66,6 @@ #include #include #include -#include #include #include @@ -144,8 +143,6 @@ _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \ _(GET_NODE_GRAPH, get_node_graph) \ _(IOAM_ENABLE, ioam_enable) \ _(IOAM_DISABLE, ioam_disable) \ -_(POLICER_ADD_DEL, policer_add_del) \ -_(POLICER_DUMP, policer_dump) \ _(GET_NEXT_INDEX, get_next_index) \ _(PG_CREATE_INTERFACE, pg_create_interface) \ _(PG_CAPTURE, pg_capture) \ @@ -2027,141 +2024,6 @@ vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp) REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY); } -static void -vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp) -{ - vlib_main_t *vm = vlib_get_main (); - vl_api_policer_add_del_reply_t *rmp; - int rv = 0; - u8 *name = NULL; - sse2_qos_pol_cfg_params_st cfg; - clib_error_t *error; - u32 policer_index; - - name = format (0, "%s", mp->name); - - memset (&cfg, 0, sizeof (cfg)); - cfg.rfc = mp->type; - cfg.rnd_type = mp->round_type; - cfg.rate_type = mp->rate_type; - cfg.rb.kbps.cir_kbps = mp->cir; - cfg.rb.kbps.eir_kbps = mp->eir; - cfg.rb.kbps.cb_bytes = mp->cb; - cfg.rb.kbps.eb_bytes = mp->eb; - cfg.conform_action.action_type = mp->conform_action_type; - cfg.conform_action.dscp = mp->conform_dscp; - cfg.exceed_action.action_type = mp->exceed_action_type; - cfg.exceed_action.dscp = mp->exceed_dscp; - cfg.violate_action.action_type = mp->violate_action_type; - cfg.violate_action.dscp = mp->violate_dscp; - cfg.color_aware = mp->color_aware; - - error = policer_add_del (vm, name, &cfg, &policer_index, mp->is_add); - - if (error) - rv = VNET_API_ERROR_UNSPECIFIED; - - /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_POLICER_ADD_DEL_REPLY, - ({ - if (rv == 0 && mp->is_add) - rmp->policer_index = ntohl(policer_index); - else - rmp->policer_index = ~0; - })); - /* *INDENT-ON* */ -} - -static void -send_policer_details (u8 * name, - sse2_qos_pol_cfg_params_st * config, - policer_read_response_type_st * templ, - unix_shared_memory_queue_t * q, u32 context) -{ - vl_api_policer_details_t *mp; - - mp = vl_msg_api_alloc (sizeof (*mp)); - memset (mp, 0, sizeof (*mp)); - mp->_vl_msg_id = ntohs (VL_API_POLICER_DETAILS); - mp->context = context; - mp->cir = htonl (config->rb.kbps.cir_kbps); - mp->eir = htonl (config->rb.kbps.eir_kbps); - mp->cb = htonl (config->rb.kbps.cb_bytes); - mp->eb = htonl (config->rb.kbps.eb_bytes); - mp->rate_type = config->rate_type; - mp->round_type = config->rnd_type; - mp->type = config->rfc; - mp->conform_action_type = config->conform_action.action_type; - mp->conform_dscp = config->conform_action.dscp; - mp->exceed_action_type = config->exceed_action.action_type; - mp->exceed_dscp = config->exceed_action.dscp; - mp->violate_action_type = config->violate_action.action_type; - mp->violate_dscp = config->violate_action.dscp; - mp->single_rate = templ->single_rate ? 1 : 0; - mp->color_aware = templ->color_aware ? 1 : 0; - mp->scale = htonl (templ->scale); - mp->cir_tokens_per_period = htonl (templ->cir_tokens_per_period); - mp->pir_tokens_per_period = htonl (templ->pir_tokens_per_period); - mp->current_limit = htonl (templ->current_limit); - mp->current_bucket = htonl (templ->current_bucket); - mp->extended_limit = htonl (templ->extended_limit); - mp->extended_bucket = htonl (templ->extended_bucket); - mp->last_update_time = clib_host_to_net_u64 (templ->last_update_time); - - strncpy ((char *) mp->name, (char *) name, ARRAY_LEN (mp->name) - 1); - - vl_msg_api_send_shmem (q, (u8 *) & mp); -} - -static void -vl_api_policer_dump_t_handler (vl_api_policer_dump_t * mp) -{ - unix_shared_memory_queue_t *q; - vnet_policer_main_t *pm = &vnet_policer_main; - hash_pair_t *hp; - uword *p; - u32 pool_index; - u8 *match_name = 0; - u8 *name; - sse2_qos_pol_cfg_params_st *config; - policer_read_response_type_st *templ; - - q = vl_api_client_index_to_input_queue (mp->client_index); - if (q == 0) - return; - - if (mp->match_name_valid) - { - match_name = format (0, "%s%c", mp->match_name, 0); - } - - if (mp->match_name_valid) - { - p = hash_get_mem (pm->policer_config_by_name, match_name); - if (p) - { - pool_index = p[0]; - config = pool_elt_at_index (pm->configs, pool_index); - templ = pool_elt_at_index (pm->policer_templates, pool_index); - send_policer_details (match_name, config, templ, q, mp->context); - } - } - else - { - /* *INDENT-OFF* */ - hash_foreach_pair (hp, pm->policer_config_by_name, - ({ - name = (u8 *) hp->key; - pool_index = hp->value[0]; - config = pool_elt_at_index (pm->configs, pool_index); - templ = pool_elt_at_index (pm->policer_templates, pool_index); - send_policer_details(name, config, templ, q, mp->context); - })); - /* *INDENT-ON* */ - } -} - - static void vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp) { diff --git a/src/vpp/api/vpe.api b/src/vpp/api/vpe.api index 6e174009..24f48293 100644 --- a/src/vpp/api/vpe.api +++ b/src/vpp/api/vpe.api @@ -45,6 +45,7 @@ * FLOW APIs: see ... /src/vnet/flow/{flow.api, flow_api.c} * DHCP APIs: see ... /src/vnet/dhcp/{dhcpk.api, dhcp_api.c} * COP APIs: see ... /src/vnet/cop/{cop.api, cop_api.c} + * POLICER APIs: see ... /src/vnet/policer/{policer.api, policer_api.c} */ /** \brief Create a new subinterface with the given vlan id @@ -1063,133 +1064,6 @@ define ioam_disable_reply i32 retval; }; -/** \brief Add/del policer - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add policer if non-zero, else delete - @param name - policer name - @param cir - CIR - @param eir - EIR - @param cb - Committed Burst - @param eb - Excess or Peak Burst - @param rate_type - rate type - @param round_type - rounding type - @param type - policer algorithm - @param color_aware - 0=color-blind, 1=color-aware - @param conform_action_type - conform action type - @param conform_dscp - DSCP for conform mar-and-transmit action - @param exceed_action_type - exceed action type - @param exceed_dscp - DSCP for exceed mar-and-transmit action - @param violate_action_type - violate action type - @param violate_dscp - DSCP for violate mar-and-transmit action -*/ -define policer_add_del -{ - u32 client_index; - u32 context; - - u8 is_add; - u8 name[64]; - u32 cir; - u32 eir; - u64 cb; - u64 eb; - u8 rate_type; - u8 round_type; - u8 type; - u8 color_aware; - u8 conform_action_type; - u8 conform_dscp; - u8 exceed_action_type; - u8 exceed_dscp; - u8 violate_action_type; - u8 violate_dscp; -}; - -/** \brief Add/del policer response - @param context - sender context, to match reply w/ request - @param retval - return value for request - @param policer_index - for add, returned index of the new policer -*/ -define policer_add_del_reply -{ - u32 context; - i32 retval; - u32 policer_index; -}; - -/** \brief Get list of policers - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param match_name_valid - if 0 request all policers otherwise use match_name - @param match_name - policer name -*/ -define policer_dump -{ - u32 client_index; - u32 context; - - u8 match_name_valid; - u8 match_name[64]; -}; - -/** \brief Policer operational state response. - @param context - sender context, to match reply w/ request - @param name - policer name - @param cir - CIR - @param eir - EIR - @param cb - Committed Burst - @param eb - Excess or Peak Burst - @param rate_type - rate type - @param round_type - rounding type - @param type - policer algorithm - @param conform_action_type - conform action type - @param conform_dscp - DSCP for conform mar-and-transmit action - @param exceed_action_type - exceed action type - @param exceed_dscp - DSCP for exceed mar-and-transmit action - @param violate_action_type - violate action type - @param violate_dscp - DSCP for violate mar-and-transmit action - @param single_rate - 1 = single rate policer, 0 = two rate policer - @param color_aware - for hierarchical policing - @param scale - power-of-2 shift amount for lower rates - @param cir_tokens_per_period - number of tokens for each period - @param pir_tokens_per_period - number of tokens for each period for 2-rate policer - @param current_limit - current limit - @param current_bucket - current bucket - @param extended_limit - extended limit - @param extended_bucket - extended bucket - @param last_update_time - last update time -*/ -define policer_details -{ - u32 context; - - u8 name[64]; - u32 cir; - u32 eir; - u64 cb; - u64 eb; - u8 rate_type; - u8 round_type; - u8 type; - u8 conform_action_type; - u8 conform_dscp; - u8 exceed_action_type; - u8 exceed_dscp; - u8 violate_action_type; - u8 violate_dscp; - u8 single_rate; - u8 color_aware; - u32 scale; - u32 cir_tokens_per_period; - u32 pir_tokens_per_period; - u32 current_limit; - u32 current_bucket; - u32 extended_limit; - u32 extended_bucket; - u64 last_update_time; -}; - /** \brief Query relative index via node names @param client_index - opaque cookie to identify the sender @param context - sender context, to match reply w/ request -- cgit 1.2.3-korg From a9a20e7f69f4a91a4d5267ab5ce14125bdc7d6c6 Mon Sep 17 00:00:00 2001 From: Billy McFall Date: Wed, 15 Feb 2017 11:39:12 -0500 Subject: VPP-635: CLI Memory leak with invalid parameter In the CLI parsing, below is a common pattern: /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "x")) x = 1; : else return clib_error_return (0, "unknown input `%U'", format_unformat_error, line_input); } unformat_free (line_input); The 'else' returns if an unknown string is encountered. There a memory leak because the 'unformat_free(line_input)' is not called. There is a large number of instances of this pattern. Replaced the previous pattern with: /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "x")) x = 1; : else { error = clib_error_return (0, "unknown input `%U'", format_unformat_error, line_input); goto done: } } /* ...Remaining code... */ done: unformat_free (line_input); return error; } In multiple files, 'unformat_free (line_input);' was never called, so there was a memory leak whether an invalid string was entered or not. Also, there were multiple instance where: error = clib_error_return (0, "unknown input `%U'", format_unformat_error, line_input); used 'input' as the last parameter instead of 'line_input'. The result is that output did not contain the substring in error, instead just an empty string. Fixed all of those as well. There are a lot of file, and very mind numbing work, so tried to keep it to a pattern to avoid mistakes. Change-Id: I8902f0c32a47dd7fb3bb3471a89818571702f1d2 Signed-off-by: Billy McFall Signed-off-by: Dave Barach --- build-root/emacs-lisp/tunnel-c-skel.el | 19 ++- src/plugins/ila/ila.c | 25 ++- src/plugins/lb/cli.c | 99 ++++++----- src/plugins/sixrd/sixrd.c | 42 +++-- src/plugins/snat/snat.c | 139 +++++++++++----- src/vlib/threads_cli.c | 79 ++++++--- src/vlib/trace.c | 13 +- src/vlib/unix/cli.c | 22 ++- src/vnet/devices/af_packet/cli.c | 56 +++++-- src/vnet/devices/dpdk/cli.c | 290 +++++++++++++++++++++++---------- src/vnet/devices/dpdk/ipsec/cli.c | 15 +- src/vnet/devices/netmap/cli.c | 54 ++++-- src/vnet/devices/virtio/vhost-user.c | 62 +++++-- src/vnet/gre/interface.c | 35 ++-- src/vnet/ip/ip4_source_check.c | 6 +- src/vnet/ip/ip4_test.c | 15 +- src/vnet/ip/ip6_neighbor.c | 27 ++- src/vnet/ip/lookup.c | 34 ++-- src/vnet/ipsec-gre/interface.c | 34 ++-- src/vnet/ipsec/ipsec_cli.c | 177 +++++++++++++------- src/vnet/l2/l2_patch.c | 26 ++- src/vnet/l2/l2_xcrw.c | 34 +++- src/vnet/l2tp/l2tp.c | 39 +++-- src/vnet/lisp-cp/lisp_cli.c | 139 ++++++++++++---- src/vnet/lisp-gpe/interface.c | 58 +++++-- src/vnet/lisp-gpe/lisp_gpe.c | 13 +- src/vnet/map/map.c | 186 +++++++++++++++------ src/vnet/mpls/mpls.c | 2 + src/vnet/mpls/mpls_tunnel.c | 19 ++- src/vnet/pg/cli.c | 39 +++-- src/vnet/policer/node_funcs.c | 19 ++- src/vnet/policer/policer.c | 13 +- src/vnet/unix/tapcli.c | 57 +++++-- src/vnet/vxlan-gpe/vxlan_gpe.c | 62 +++++-- src/vnet/vxlan/vxlan.c | 81 ++++++--- src/vpp/app/l2t.c | 9 +- src/vpp/app/vpe_cli.c | 24 ++- 37 files changed, 1487 insertions(+), 576 deletions(-) (limited to 'src/vnet/policer') diff --git a/build-root/emacs-lisp/tunnel-c-skel.el b/build-root/emacs-lisp/tunnel-c-skel.el index aa260e53..a1b1757d 100644 --- a/build-root/emacs-lisp/tunnel-c-skel.el +++ b/build-root/emacs-lisp/tunnel-c-skel.el @@ -288,6 +288,7 @@ static clib_error_t * vlib_cli_command_t * cmd) { unformat_input_t _line_input, * line_input = &_line_input; + clib_error_t *error = 0; ip4_address_t src, dst; u8 is_add = 1; u8 src_set = 0; @@ -322,13 +323,19 @@ static clib_error_t * { encap_fib_index = fib_index_from_fib_id (tmp); if (encap_fib_index == ~0) - return clib_error_return (0, \"nonexistent encap fib id %d\", tmp); + { + unformat_free (line_input); + return clib_error_return (0, \"nonexistent encap fib id %d\", tmp); + } } else if (unformat (line_input, \"decap-vrf-id %d\", &tmp)) { decap_fib_index = fib_index_from_fib_id (tmp); if (decap_fib_index == ~0) - return clib_error_return (0, \"nonexistent decap fib id %d\", tmp); + { + unformat_free (line_input); + return clib_error_return (0, \"nonexistent decap fib id %d\", tmp); + } } else if (unformat (line_input, \"decap-next %U\", unformat_decap_next, &decap_next_index)) @@ -346,8 +353,12 @@ static clib_error_t * * in the " ENCAP_STACK " header */ else - return clib_error_return (0, \"parse error: '%U'\", - format_unformat_error, line_input); + { + error = clib_error_return (0, \"parse error: '%U'\", + format_unformat_error, line_input); + unformat_free (line_input); + return error; + } } unformat_free (line_input); diff --git a/src/plugins/ila/ila.c b/src/plugins/ila/ila.c index e0f3907f..52c7ea55 100644 --- a/src/plugins/ila/ila.c +++ b/src/plugins/ila/ila.c @@ -949,6 +949,7 @@ ila_entry_command_fn (vlib_main_t * vm, ila_add_del_entry_args_t args = { 0 }; u8 next_hop_set = 0; int ret; + clib_error_t *error = 0; args.type = ILA_TYPE_IID; args.csum_mode = ILA_CSUM_MODE_NO_ACTION; @@ -986,19 +987,29 @@ ila_entry_command_fn (vlib_main_t * vm, else if (unformat (line_input, "del")) args.is_del = 1; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (!next_hop_set) - return clib_error_return (0, "Specified a next hop"); + { + error = clib_error_return (0, "Specified a next hop"); + goto done; + } if ((ret = ila_add_del_entry (&args))) - return clib_error_return (0, "ila_add_del_entry returned error %d", ret); + { + error = clib_error_return (0, "ila_add_del_entry returned error %d", ret); + goto done; + } - return NULL; +done: + unformat_free (line_input); + + return error; } VLIB_CLI_COMMAND (ila_entry_command, static) = diff --git a/src/plugins/lb/cli.c b/src/plugins/lb/cli.c index b59c6426..6452a875 100644 --- a/src/plugins/lb/cli.c +++ b/src/plugins/lb/cli.c @@ -28,13 +28,16 @@ lb_vip_command_fn (vlib_main_t * vm, int ret; u32 gre4 = 0; lb_vip_type_t type; + clib_error_t *error = 0; if (!unformat_user (input, unformat_line_input, line_input)) return 0; - if (!unformat(line_input, "%U", unformat_ip46_prefix, &prefix, &plen, IP46_TYPE_ANY, &plen)) - return clib_error_return (0, "invalid vip prefix: '%U'", - format_unformat_error, line_input); + if (!unformat(line_input, "%U", unformat_ip46_prefix, &prefix, &plen, IP46_TYPE_ANY, &plen)) { + error = clib_error_return (0, "invalid vip prefix: '%U'", + format_unformat_error, line_input); + goto done; + } while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { @@ -46,13 +49,13 @@ lb_vip_command_fn (vlib_main_t * vm, gre4 = 1; else if (unformat(line_input, "encap gre6")) gre4 = 0; - else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + else { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (ip46_prefix_is_ip4(&prefix, plen)) { type = (gre4)?LB_VIP_TYPE_IP4_GRE4:LB_VIP_TYPE_IP4_GRE6; @@ -65,17 +68,25 @@ lb_vip_command_fn (vlib_main_t * vm, u32 index; if (!del) { if ((ret = lb_vip_add(&prefix, plen, type, new_len, &index))) { - return clib_error_return (0, "lb_vip_add error %d", ret); + error = clib_error_return (0, "lb_vip_add error %d", ret); + goto done; } else { vlib_cli_output(vm, "lb_vip_add ok %d", index); } } else { - if ((ret = lb_vip_find_index(&prefix, plen, &index))) - return clib_error_return (0, "lb_vip_find_index error %d", ret); - else if ((ret = lb_vip_del(index))) - return clib_error_return (0, "lb_vip_del error %d", ret); + if ((ret = lb_vip_find_index(&prefix, plen, &index))) { + error = clib_error_return (0, "lb_vip_find_index error %d", ret); + goto done; + } else if ((ret = lb_vip_del(index))) { + error = clib_error_return (0, "lb_vip_del error %d", ret); + goto done; + } } - return NULL; + +done: + unformat_free (line_input); + + return error; } VLIB_CLI_COMMAND (lb_vip_command, static) = @@ -96,16 +107,21 @@ lb_as_command_fn (vlib_main_t * vm, u32 vip_index; u8 del = 0; int ret; + clib_error_t *error = 0; if (!unformat_user (input, unformat_line_input, line_input)) return 0; - if (!unformat(line_input, "%U", unformat_ip46_prefix, &vip_prefix, &vip_plen, IP46_TYPE_ANY)) - return clib_error_return (0, "invalid as address: '%U'", - format_unformat_error, line_input); + if (!unformat(line_input, "%U", unformat_ip46_prefix, &vip_prefix, &vip_plen, IP46_TYPE_ANY)) { + error = clib_error_return (0, "invalid as address: '%U'", + format_unformat_error, line_input); + goto done; + } - if ((ret = lb_vip_find_index(&vip_prefix, vip_plen, &vip_index))) - return clib_error_return (0, "lb_vip_find_index error %d", ret); + if ((ret = lb_vip_find_index(&vip_prefix, vip_plen, &vip_index))) { + error = clib_error_return (0, "lb_vip_find_index error %d", ret); + goto done; + } while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { @@ -114,15 +130,15 @@ lb_as_command_fn (vlib_main_t * vm, } else if (unformat(line_input, "del")) { del = 1; } else { - vec_free(as_array); - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; } } if (!vec_len(as_array)) { - vec_free(as_array); - return clib_error_return (0, "No AS address provided"); + error = clib_error_return (0, "No AS address provided"); + goto done; } lb_garbage_collection(); @@ -130,18 +146,21 @@ lb_as_command_fn (vlib_main_t * vm, if (del) { if ((ret = lb_vip_del_ass(vip_index, as_array, vec_len(as_array)))) { - vec_free(as_array); - return clib_error_return (0, "lb_vip_del_ass error %d", ret); + error = clib_error_return (0, "lb_vip_del_ass error %d", ret); + goto done; } } else { if ((ret = lb_vip_add_ass(vip_index, as_array, vec_len(as_array)))) { - vec_free(as_array); - return clib_error_return (0, "lb_vip_add_ass error %d", ret); + error = clib_error_return (0, "lb_vip_add_ass error %d", ret); + goto done; } } +done: + unformat_free (line_input); vec_free(as_array); - return 0; + + return error; } VLIB_CLI_COMMAND (lb_as_command, static) = @@ -163,6 +182,7 @@ lb_conf_command_fn (vlib_main_t * vm, u32 per_cpu_sticky_buckets_log2 = 0; u32 flow_timeout = lbm->flow_timeout; int ret; + clib_error_t *error = 0; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -181,19 +201,24 @@ lb_conf_command_fn (vlib_main_t * vm, per_cpu_sticky_buckets = 1 << per_cpu_sticky_buckets_log2; } else if (unformat(line_input, "timeout %d", &flow_timeout)) ; - else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + else { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - lb_garbage_collection(); - if ((ret = lb_conf(&ip4, &ip6, per_cpu_sticky_buckets, flow_timeout))) - return clib_error_return (0, "lb_conf error %d", ret); + if ((ret = lb_conf(&ip4, &ip6, per_cpu_sticky_buckets, flow_timeout))) { + error = clib_error_return (0, "lb_conf error %d", ret); + goto done; + } - return NULL; +done: + unformat_free (line_input); + + return error; } VLIB_CLI_COMMAND (lb_conf_command, static) = diff --git a/src/plugins/sixrd/sixrd.c b/src/plugins/sixrd/sixrd.c index 71fc181f..67a9a3ad 100644 --- a/src/plugins/sixrd/sixrd.c +++ b/src/plugins/sixrd/sixrd.c @@ -192,6 +192,7 @@ sixrd_add_domain_command_fn (vlib_main_t *vm, u32 num_m_args = 0; /* Optional arguments */ u32 mtu = 0; + clib_error_t *error = 0; /* Get a line of input. */ if (!unformat_user(input, unformat_line_input, line_input)) @@ -205,19 +206,25 @@ sixrd_add_domain_command_fn (vlib_main_t *vm, num_m_args++; else if (unformat(line_input, "mtu %d", &mtu)) num_m_args++; - else - return clib_error_return(0, "unknown input `%U'", - format_unformat_error, input); + else { + error = clib_error_return(0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free(line_input); - if (num_m_args < 3) - return clib_error_return(0, "mandatory argument(s) missing"); + if (num_m_args < 3) { + error = clib_error_return(0, "mandatory argument(s) missing"); + goto done; + } sixrd_create_domain(&ip6_prefix, ip6_prefix_len, &ip4_prefix, ip4_prefix_len, &ip4_src, &sixrd_domain_index, mtu); - return 0; +done: + unformat_free (line_input); + + return error; } static clib_error_t * @@ -228,6 +235,7 @@ sixrd_del_domain_command_fn (vlib_main_t *vm, unformat_input_t _line_input, *line_input = &_line_input; u32 num_m_args = 0; u32 sixrd_domain_index; + clib_error_t *error = 0; /* Get a line of input. */ if (! unformat_user(input, unformat_line_input, line_input)) @@ -236,18 +244,24 @@ sixrd_del_domain_command_fn (vlib_main_t *vm, while (unformat_check_input(line_input) != UNFORMAT_END_OF_INPUT) { if (unformat(line_input, "index %d", &sixrd_domain_index)) num_m_args++; - else - return clib_error_return(0, "unknown input `%U'", - format_unformat_error, input); + else { + error = clib_error_return(0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free(line_input); - if (num_m_args != 1) - return clib_error_return(0, "mandatory argument(s) missing"); + if (num_m_args != 1) { + error = clib_error_return(0, "mandatory argument(s) missing"); + goto done; + } sixrd_delete_domain(sixrd_domain_index); - return 0; +done: + unformat_free (line_input); + + return error; } static u8 * diff --git a/src/plugins/snat/snat.c b/src/plugins/snat/snat.c index 73854a7a..8c2bacdb 100644 --- a/src/plugins/snat/snat.c +++ b/src/plugins/snat/snat.c @@ -1705,6 +1705,7 @@ add_address_command_fn (vlib_main_t * vm, int i, count; int is_add = 1; int rv = 0; + clib_error_t *error = 0; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -1721,19 +1722,27 @@ add_address_command_fn (vlib_main_t * vm, else if (unformat (line_input, "del")) is_add = 0; else - return clib_error_return (0, "unknown input '%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (sm->static_mapping_only) - return clib_error_return (0, "static mapping only mode"); + { + error = clib_error_return (0, "static mapping only mode"); + goto done; + } start_host_order = clib_host_to_net_u32 (start_addr.as_u32); end_host_order = clib_host_to_net_u32 (end_addr.as_u32); if (end_host_order < start_host_order) - return clib_error_return (0, "end address less than start address"); + { + error = clib_error_return (0, "end address less than start address"); + goto done; + } count = (end_host_order - start_host_order) + 1; @@ -1755,11 +1764,11 @@ add_address_command_fn (vlib_main_t * vm, switch (rv) { case VNET_API_ERROR_NO_SUCH_ENTRY: - return clib_error_return (0, "S-NAT address not exist."); - break; + error = clib_error_return (0, "S-NAT address not exist."); + goto done; case VNET_API_ERROR_UNSPECIFIED: - return clib_error_return (0, "S-NAT address used in static mapping."); - break; + error = clib_error_return (0, "S-NAT address used in static mapping."); + goto done; default: break; } @@ -1767,7 +1776,10 @@ add_address_command_fn (vlib_main_t * vm, increment_v4_address (&this_addr); } - return 0; +done: + unformat_free (line_input); + + return error; } VLIB_CLI_COMMAND (add_address_command, static) = { @@ -1807,10 +1819,12 @@ snat_feature_command_fn (vlib_main_t * vm, else if (unformat (line_input, "del")) is_del = 1; else - return clib_error_return (0, "unknown input '%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (vec_len (inside_sw_if_indices)) { @@ -1830,6 +1844,8 @@ snat_feature_command_fn (vlib_main_t * vm, } } +done: + unformat_free (line_input); vec_free (inside_sw_if_indices); vec_free (outside_sw_if_indices); @@ -1923,13 +1939,18 @@ add_static_mapping_command_fn (vlib_main_t * vm, else if (unformat (line_input, "del")) is_add = 0; else - return clib_error_return (0, "unknown input: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "unknown input: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (!addr_only && !proto_set) - return clib_error_return (0, "missing protocol"); + { + error = clib_error_return (0, "missing protocol"); + goto done; + } rv = snat_add_static_mapping(l_addr, e_addr, (u16) l_port, (u16) e_port, vrf_id, addr_only, sw_if_index, proto, is_add); @@ -1937,22 +1958,27 @@ add_static_mapping_command_fn (vlib_main_t * vm, switch (rv) { case VNET_API_ERROR_INVALID_VALUE: - return clib_error_return (0, "External port already in use."); - break; + error = clib_error_return (0, "External port already in use."); + goto done; case VNET_API_ERROR_NO_SUCH_ENTRY: if (is_add) - return clib_error_return (0, "External addres must be allocated."); + error = clib_error_return (0, "External addres must be allocated."); else - return clib_error_return (0, "Mapping not exist."); - break; + error = clib_error_return (0, "Mapping not exist."); + goto done; case VNET_API_ERROR_NO_SUCH_FIB: - return clib_error_return (0, "No such VRF id."); + error = clib_error_return (0, "No such VRF id."); + goto done; case VNET_API_ERROR_VALUE_EXIST: - return clib_error_return (0, "Mapping already exist."); + error = clib_error_return (0, "Mapping already exist."); + goto done; default: break; } +done: + unformat_free (line_input); + return error; } @@ -1985,6 +2011,7 @@ set_workers_command_fn (vlib_main_t * vm, unformat_input_t _line_input, *line_input = &_line_input; uword *bitmap = 0; int rv = 0; + clib_error_t *error = 0; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -1995,13 +2022,18 @@ set_workers_command_fn (vlib_main_t * vm, if (unformat (line_input, "%U", unformat_bitmap_list, &bitmap)) ; else - return clib_error_return (0, "unknown input '%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (bitmap == 0) - return clib_error_return (0, "List of workers must be specified."); + { + error = clib_error_return (0, "List of workers must be specified."); + goto done; + } rv = snat_set_workers(bitmap); @@ -2010,17 +2042,20 @@ set_workers_command_fn (vlib_main_t * vm, switch (rv) { case VNET_API_ERROR_INVALID_WORKER: - return clib_error_return (0, "Invalid worker(s)."); - break; + error = clib_error_return (0, "Invalid worker(s)."); + goto done; case VNET_API_ERROR_FEATURE_DISABLED: - return clib_error_return (0, + error = clib_error_return (0, "Supported only if 2 or more workes available."); - break; + goto done; default: break; } - return 0; +done: + unformat_free (line_input); + + return error; } /*? @@ -2047,6 +2082,7 @@ snat_ipfix_logging_enable_disable_command_fn (vlib_main_t * vm, u32 src_port = 0; u8 enable = 1; int rv = 0; + clib_error_t *error = 0; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -2061,17 +2097,25 @@ snat_ipfix_logging_enable_disable_command_fn (vlib_main_t * vm, else if (unformat (line_input, "disable")) enable = 0; else - return clib_error_return (0, "unknown input '%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); rv = snat_ipfix_logging_enable_disable (enable, domain_id, (u16) src_port); if (rv) - return clib_error_return (0, "ipfix logging enable failed"); + { + error = clib_error_return (0, "ipfix logging enable failed"); + goto done; + } - return 0; +done: + unformat_free (line_input); + + return error; } /*? @@ -2604,6 +2648,7 @@ snat_add_interface_address_command_fn (vlib_main_t * vm, u32 sw_if_index; int rv; int is_del = 0; + clib_error_t *error = 0; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -2617,8 +2662,11 @@ snat_add_interface_address_command_fn (vlib_main_t * vm, else if (unformat (line_input, "del")) is_del = 1; else - return clib_error_return (0, "unknown input '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "unknown input '%U'", + format_unformat_error, line_input); + goto done; + } } rv = snat_add_interface_address (sm, sw_if_index, is_del); @@ -2629,10 +2677,15 @@ snat_add_interface_address_command_fn (vlib_main_t * vm, break; default: - return clib_error_return (0, "snat_add_interface_address returned %d", - rv); + error = clib_error_return (0, "snat_add_interface_address returned %d", + rv); + goto done; } - return 0; + +done: + unformat_free (line_input); + + return error; } VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = { diff --git a/src/vlib/threads_cli.c b/src/vlib/threads_cli.c index 54cc1aed..36f8109e 100644 --- a/src/vlib/threads_cli.c +++ b/src/vlib/threads_cli.c @@ -163,21 +163,31 @@ trace_frame_queue (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "index %u", &index)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (enable > 1) - return clib_error_return (0, "expecting on or off"); + { + error = clib_error_return (0, "expecting on or off"); + goto done; + } if (vec_len (tm->frame_queue_mains) == 0) - return clib_error_return (0, "no worker handoffs exist"); + { + error = clib_error_return (0, "no worker handoffs exist"); + goto done; + } if (index > vec_len (tm->frame_queue_mains) - 1) - return clib_error_return (0, - "expecting valid worker handoff queue index"); + { + error = clib_error_return (0, + "expecting valid worker handoff queue index"); + goto done; + } fqm = vec_elt_at_index (tm->frame_queue_mains, index); @@ -185,7 +195,7 @@ trace_frame_queue (vlib_main_t * vm, unformat_input_t * input, if (num_fq == 0) { vlib_cli_output (vm, "No frame queues exist\n"); - return error; + goto done; } // Allocate storage for trace if necessary @@ -204,6 +214,10 @@ trace_frame_queue (vlib_main_t * vm, unformat_input_t * input, memset (fqh, 0, sizeof (*fqh)); fqm->vlib_frame_queues[fqix]->trace = enable; } + +done: + unformat_free (line_input); + return error; } @@ -432,28 +446,33 @@ test_frame_queue_nelts (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "index %u", &index)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (index > vec_len (tm->frame_queue_mains) - 1) - return clib_error_return (0, - "expecting valid worker handoff queue index"); + { + error = clib_error_return (0, + "expecting valid worker handoff queue index"); + goto done; + } fqm = vec_elt_at_index (tm->frame_queue_mains, index); if ((nelts != 4) && (nelts != 8) && (nelts != 16) && (nelts != 32)) { - return clib_error_return (0, "expecting 4,8,16,32"); + error = clib_error_return (0, "expecting 4,8,16,32"); + goto done; } num_fq = vec_len (fqm->vlib_frame_queues); if (num_fq == 0) { vlib_cli_output (vm, "No frame queues exist\n"); - return error; + goto done; } for (fqix = 0; fqix < num_fq; fqix++) @@ -461,6 +480,9 @@ test_frame_queue_nelts (vlib_main_t * vm, unformat_input_t * input, fqm->vlib_frame_queues[fqix]->nelts = nelts; } +done: + unformat_free (line_input); + return error; } @@ -499,15 +521,19 @@ test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "index %u", &index)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (index > vec_len (tm->frame_queue_mains) - 1) - return clib_error_return (0, - "expecting valid worker handoff queue index"); + { + error = clib_error_return (0, + "expecting valid worker handoff queue index"); + goto done; + } fqm = vec_elt_at_index (tm->frame_queue_mains, index); @@ -515,7 +541,7 @@ test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input, if (threshold == ~(u32) 0) { vlib_cli_output (vm, "expecting threshold value\n"); - return error; + goto done; } if (threshold == 0) @@ -525,7 +551,7 @@ test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input, if (num_fq == 0) { vlib_cli_output (vm, "No frame queues exist\n"); - return error; + goto done; } for (fqix = 0; fqix < num_fq; fqix++) @@ -533,6 +559,9 @@ test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input, fqm->vlib_frame_queues[fqix]->vector_threshold = threshold; } +done: + unformat_free (line_input); + return error; } diff --git a/src/vlib/trace.c b/src/vlib/trace.c index dcdb837f..6d487ae1 100644 --- a/src/vlib/trace.c +++ b/src/vlib/trace.c @@ -372,6 +372,7 @@ cli_add_trace_buffer (vlib_main_t * vm, vlib_trace_node_t *tn; u32 node_index, add; u8 verbose = 0; + clib_error_t *error = 0; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -384,8 +385,11 @@ cli_add_trace_buffer (vlib_main_t * vm, else if (unformat (line_input, "verbose")) verbose = 1; else - return clib_error_create ("expected NODE COUNT, got `%U'", - format_unformat_error, line_input); + { + error = clib_error_create ("expected NODE COUNT, got `%U'", + format_unformat_error, line_input); + goto done; + } } /* *INDENT-OFF* */ @@ -403,7 +407,10 @@ cli_add_trace_buffer (vlib_main_t * vm, })); /* *INDENT-ON* */ - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ diff --git a/src/vlib/unix/cli.c b/src/vlib/unix/cli.c index 69fca6ec..88e2453c 100644 --- a/src/vlib/unix/cli.c +++ b/src/vlib/unix/cli.c @@ -2835,6 +2835,7 @@ unix_cli_set_terminal_pager (vlib_main_t * vm, unix_cli_main_t *cm = &unix_cli_main; unix_cli_file_t *cf; unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = 0; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -2852,13 +2853,17 @@ unix_cli_set_terminal_pager (vlib_main_t * vm, "Pager limit set to %u lines; note, this is global.\n", um->cli_pager_buffer_limit); else - return clib_error_return (0, "unknown parameter: `%U`", - format_unformat_error, line_input); + { + error = clib_error_return (0, "unknown parameter: `%U`", + format_unformat_error, line_input); + goto done; + } } +done: unformat_free (line_input); - return 0; + return error; } /*? @@ -2886,6 +2891,7 @@ unix_cli_set_terminal_history (vlib_main_t * vm, unix_cli_file_t *cf; unformat_input_t _line_input, *line_input = &_line_input; u32 limit; + clib_error_t *error = 0; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -2901,8 +2907,11 @@ unix_cli_set_terminal_history (vlib_main_t * vm, else if (unformat (line_input, "limit %u", &cf->history_limit)) ; else - return clib_error_return (0, "unknown parameter: `%U`", - format_unformat_error, line_input); + { + error = clib_error_return (0, "unknown parameter: `%U`", + format_unformat_error, line_input); + goto done; + } /* If we reduced history size, or turned it off, purge the history */ limit = cf->has_history ? cf->history_limit : 0; @@ -2914,9 +2923,10 @@ unix_cli_set_terminal_history (vlib_main_t * vm, } } +done: unformat_free (line_input); - return 0; + return error; } /*? diff --git a/src/vnet/devices/af_packet/cli.c b/src/vnet/devices/af_packet/cli.c index 6baa26e1..d4aa7016 100644 --- a/src/vnet/devices/af_packet/cli.c +++ b/src/vnet/devices/af_packet/cli.c @@ -49,6 +49,7 @@ af_packet_create_command_fn (vlib_main_t * vm, unformat_input_t * input, u8 *hw_addr_ptr = 0; u32 sw_if_index; int r; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -63,29 +64,47 @@ af_packet_create_command_fn (vlib_main_t * vm, unformat_input_t * input, (line_input, "hw-addr %U", unformat_ethernet_address, hwaddr)) hw_addr_ptr = hwaddr; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (host_if_name == NULL) - return clib_error_return (0, "missing host interface name"); + { + error = clib_error_return (0, "missing host interface name"); + goto done; + } r = af_packet_create_if (vm, host_if_name, hw_addr_ptr, &sw_if_index); - vec_free (host_if_name); if (r == VNET_API_ERROR_SYSCALL_ERROR_1) - return clib_error_return (0, "%s (errno %d)", strerror (errno), errno); + { + error = clib_error_return (0, "%s (errno %d)", strerror (errno), errno); + goto done; + } if (r == VNET_API_ERROR_INVALID_INTERFACE) - return clib_error_return (0, "Invalid interface name"); + { + error = clib_error_return (0, "Invalid interface name"); + goto done; + } if (r == VNET_API_ERROR_SUBIF_ALREADY_EXISTS) - return clib_error_return (0, "Interface elready exists"); + { + error = clib_error_return (0, "Interface elready exists"); + goto done; + } vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index); - return 0; + +done: + vec_free (host_if_name); + unformat_free (line_input); + + return error; } /*? @@ -124,6 +143,7 @@ af_packet_delete_command_fn (vlib_main_t * vm, unformat_input_t * input, { unformat_input_t _line_input, *line_input = &_line_input; u8 *host_if_name = NULL; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -134,18 +154,26 @@ af_packet_delete_command_fn (vlib_main_t * vm, unformat_input_t * input, if (unformat (line_input, "name %s", &host_if_name)) ; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (host_if_name == NULL) - return clib_error_return (0, "missing host interface name"); + { + error = clib_error_return (0, "missing host interface name"); + goto done; + } af_packet_delete_if (vm, host_if_name); + +done: vec_free (host_if_name); + unformat_free (line_input); - return 0; + return error; } /*? diff --git a/src/vnet/devices/dpdk/cli.c b/src/vnet/devices/dpdk/cli.c index d133cfd9..1fc665ac 100644 --- a/src/vnet/devices/dpdk/cli.c +++ b/src/vnet/devices/dpdk/cli.c @@ -398,7 +398,7 @@ set_dpdk_if_desc (vlib_main_t * vm, unformat_input_t * input, u32 hw_if_index = (u32) ~ 0; u32 nb_rx_desc = (u32) ~ 0; u32 nb_tx_desc = (u32) ~ 0; - clib_error_t *rv; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -414,25 +414,37 @@ set_dpdk_if_desc (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "rx %d", &nb_rx_desc)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (hw_if_index == (u32) ~ 0) - return clib_error_return (0, "please specify valid interface name"); + { + error = clib_error_return (0, "please specify valid interface name"); + goto done; + } hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index); xd = vec_elt_at_index (dm->devices, hw->dev_instance); if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0) - return clib_error_return (0, "number of descriptors can be set only for " - "physical devices"); + { + error = + clib_error_return (0, + "number of descriptors can be set only for " + "physical devices"); + goto done; + } if ((nb_rx_desc == (u32) ~ 0 || nb_rx_desc == xd->nb_rx_desc) && (nb_tx_desc == (u32) ~ 0 || nb_tx_desc == xd->nb_tx_desc)) - return clib_error_return (0, "nothing changed"); + { + error = clib_error_return (0, "nothing changed"); + goto done; + } if (nb_rx_desc != (u32) ~ 0) xd->nb_rx_desc = nb_rx_desc; @@ -440,9 +452,12 @@ set_dpdk_if_desc (vlib_main_t * vm, unformat_input_t * input, if (nb_tx_desc != (u32) ~ 0) xd->nb_tx_desc = nb_tx_desc; - rv = dpdk_port_setup (dm, xd); + error = dpdk_port_setup (dm, xd); + +done: + unformat_free (line_input); - return rv; + return error; } /* *INDENT-OFF* */ @@ -523,6 +538,7 @@ set_dpdk_if_placement (vlib_main_t * vm, unformat_input_t * input, u32 queue = (u32) 0; u32 cpu = (u32) ~ 0; int i; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -538,18 +554,25 @@ set_dpdk_if_placement (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "thread %d", &cpu)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (hw_if_index == (u32) ~ 0) - return clib_error_return (0, "please specify valid interface name"); + { + error = clib_error_return (0, "please specify valid interface name"); + goto done; + } if (cpu < dm->input_cpu_first_index || cpu >= (dm->input_cpu_first_index + dm->input_cpu_count)) - return clib_error_return (0, "please specify valid thread id"); + { + error = clib_error_return (0, "please specify valid thread id"); + goto done; + } hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index); xd = vec_elt_at_index (dm->devices, hw->dev_instance); @@ -563,7 +586,7 @@ set_dpdk_if_placement (vlib_main_t * vm, unformat_input_t * input, queue == dq->queue_id) { if (cpu == i) /* nothing to do */ - return 0; + goto done; vec_del1(dm->devices_by_cpu[i], dq - dm->devices_by_cpu[i]); vec_add2(dm->devices_by_cpu[cpu], dq, 1); @@ -586,13 +609,18 @@ set_dpdk_if_placement (vlib_main_t * vm, unformat_input_t * input, vlib_node_set_state (vlib_mains[cpu], dpdk_input_node.index, VLIB_NODE_STATE_POLLING); - return 0; + goto done; } } /* *INDENT-ON* */ } - return clib_error_return (0, "not found"); + error = clib_error_return (0, "not found"); + +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -653,6 +681,7 @@ set_dpdk_if_hqos_placement (vlib_main_t * vm, unformat_input_t * input, u32 hw_if_index = (u32) ~ 0; u32 cpu = (u32) ~ 0; int i; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -666,18 +695,22 @@ set_dpdk_if_hqos_placement (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "thread %d", &cpu)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (hw_if_index == (u32) ~ 0) return clib_error_return (0, "please specify valid interface name"); if (cpu < dm->hqos_cpu_first_index || cpu >= (dm->hqos_cpu_first_index + dm->hqos_cpu_count)) - return clib_error_return (0, "please specify valid thread id"); + { + error = clib_error_return (0, "please specify valid thread id"); + goto done; + } hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index); xd = vec_elt_at_index (dm->devices, hw->dev_instance); @@ -689,7 +722,7 @@ set_dpdk_if_hqos_placement (vlib_main_t * vm, unformat_input_t * input, if (hw_if_index == dm->devices[dq->device].vlib_hw_if_index) { if (cpu == i) /* nothing to do */ - return 0; + goto done; vec_del1 (dm->devices_by_hqos_cpu[i], dq - dm->devices_by_hqos_cpu[i]); @@ -703,12 +736,17 @@ set_dpdk_if_hqos_placement (vlib_main_t * vm, unformat_input_t * input, vec_sort_with_function (dm->devices_by_hqos_cpu[cpu], dpdk_device_queue_sort); - return 0; + goto done; } } } - return clib_error_return (0, "not found"); + error = clib_error_return (0, "not found"); + +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -732,6 +770,7 @@ set_dpdk_if_hqos_pipe (vlib_main_t * vm, unformat_input_t * input, u32 pipe_id = (u32) ~ 0; u32 profile_id = (u32) ~ 0; int rv; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -749,14 +788,18 @@ set_dpdk_if_hqos_pipe (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "profile %d", &profile_id)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (hw_if_index == (u32) ~ 0) - return clib_error_return (0, "please specify valid interface name"); + { + error = clib_error_return (0, "please specify valid interface name"); + goto done; + } hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index); xd = vec_elt_at_index (dm->devices, hw->dev_instance); @@ -765,9 +808,15 @@ set_dpdk_if_hqos_pipe (vlib_main_t * vm, unformat_input_t * input, rte_sched_pipe_config (xd->hqos_ht->hqos, subport_id, pipe_id, profile_id); if (rv) - return clib_error_return (0, "pipe configuration failed"); + { + error = clib_error_return (0, "pipe configuration failed"); + goto done; + } - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -797,6 +846,7 @@ set_dpdk_if_hqos_subport (vlib_main_t * vm, unformat_input_t * input, .tc_period = 10, }; int rv; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -829,23 +879,33 @@ set_dpdk_if_hqos_subport (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "period %d", &p.tc_period)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (hw_if_index == (u32) ~ 0) - return clib_error_return (0, "please specify valid interface name"); + { + error = clib_error_return (0, "please specify valid interface name"); + goto done; + } hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index); xd = vec_elt_at_index (dm->devices, hw->dev_instance); rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport_id, &p); if (rv) - return clib_error_return (0, "subport configuration failed"); + { + error = clib_error_return (0, "subport configuration failed"); + goto done; + } - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -872,6 +932,7 @@ set_dpdk_if_hqos_tctbl (vlib_main_t * vm, unformat_input_t * input, u32 queue = (u32) ~ 0; u32 entry = (u32) ~ 0; u32 val, i; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -889,20 +950,33 @@ set_dpdk_if_hqos_tctbl (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "queue %d", &queue)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (hw_if_index == (u32) ~ 0) - return clib_error_return (0, "please specify valid interface name"); + { + error = clib_error_return (0, "please specify valid interface name"); + goto done; + } if (entry >= 64) - return clib_error_return (0, "invalid entry"); + { + error = clib_error_return (0, "invalid entry"); + goto done; + } if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE) - return clib_error_return (0, "invalid traffic class"); + { + error = clib_error_return (0, "invalid traffic class"); + goto done; + } if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS) - return clib_error_return (0, "invalid traffic class"); + { + error = clib_error_return (0, "invalid traffic class"); + goto done; + } hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index); xd = vec_elt_at_index (dm->devices, hw->dev_instance); @@ -911,7 +985,10 @@ set_dpdk_if_hqos_tctbl (vlib_main_t * vm, unformat_input_t * input, uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers"); /* Should never happen, shut up Coverity warning */ if (p == 0) - return clib_error_return (0, "no worker registrations?"); + { + error = clib_error_return (0, "no worker registrations?"); + goto done; + } vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0]; int worker_thread_first = tr->first_index; @@ -921,7 +998,10 @@ set_dpdk_if_hqos_tctbl (vlib_main_t * vm, unformat_input_t * input, for (i = 0; i < worker_thread_count; i++) xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val; - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -939,6 +1019,7 @@ set_dpdk_if_hqos_pktfield (vlib_main_t * vm, unformat_input_t * input, unformat_input_t _line_input, *line_input = &_line_input; vlib_thread_main_t *tm = vlib_get_thread_main (); dpdk_main_t *dm = &dpdk_main; + clib_error_t *error = NULL; /* Device specific data */ struct rte_eth_dev_info dev_info; @@ -984,15 +1065,19 @@ set_dpdk_if_hqos_pktfield (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "mask %llx", &mask)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - /* Get interface */ if (hw_if_index == (u32) ~ 0) - return clib_error_return (0, "please specify valid interface name"); + { + error = clib_error_return (0, "please specify valid interface name"); + goto done; + } hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index); xd = vec_elt_at_index (dm->devices, hw->dev_instance); @@ -1019,7 +1104,7 @@ set_dpdk_if_hqos_pktfield (vlib_main_t * vm, unformat_input_t * input, if (devconf->hqos_enabled == 0) { vlib_cli_output (vm, "HQoS disabled for this interface"); - return 0; + goto done; } n_subports_per_port = devconf->hqos.port.n_subports_per_port; @@ -1028,27 +1113,39 @@ set_dpdk_if_hqos_pktfield (vlib_main_t * vm, unformat_input_t * input, /* Validate packet field configuration: id, offset and mask */ if (id >= 3) - return clib_error_return (0, "invalid packet field id"); + { + error = clib_error_return (0, "invalid packet field id"); + goto done; + } switch (id) { case 0: if (dpdk_hqos_validate_mask (mask, n_subports_per_port) != 0) - return clib_error_return (0, "invalid subport ID mask " - "(n_subports_per_port = %u)", - n_subports_per_port); + { + error = clib_error_return (0, "invalid subport ID mask " + "(n_subports_per_port = %u)", + n_subports_per_port); + goto done; + } break; case 1: if (dpdk_hqos_validate_mask (mask, n_pipes_per_subport) != 0) - return clib_error_return (0, "invalid pipe ID mask " - "(n_pipes_per_subport = %u)", - n_pipes_per_subport); + { + error = clib_error_return (0, "invalid pipe ID mask " + "(n_pipes_per_subport = %u)", + n_pipes_per_subport); + goto done; + } break; case 2: default: if (dpdk_hqos_validate_mask (mask, tctbl_size) != 0) - return clib_error_return (0, "invalid TC table index mask " - "(TC table size = %u)", tctbl_size); + { + error = clib_error_return (0, "invalid TC table index mask " + "(TC table size = %u)", tctbl_size); + goto done; + } } /* Propagate packet field configuration to all workers */ @@ -1075,7 +1172,10 @@ set_dpdk_if_hqos_pktfield (vlib_main_t * vm, unformat_input_t * input, __builtin_ctzll (mask); } - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -1106,6 +1206,7 @@ show_dpdk_if_hqos (vlib_main_t * vm, unformat_input_t * input, dpdk_device_config_t *devconf = 0; vlib_thread_registration_t *tr; uword *p = 0; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -1117,14 +1218,18 @@ show_dpdk_if_hqos (vlib_main_t * vm, unformat_input_t * input, &hw_if_index)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (hw_if_index == (u32) ~ 0) - return clib_error_return (0, "please specify interface name!!"); + { + error = clib_error_return (0, "please specify interface name!!"); + goto done; + } hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index); xd = vec_elt_at_index (dm->devices, hw->dev_instance); @@ -1151,7 +1256,7 @@ show_dpdk_if_hqos (vlib_main_t * vm, unformat_input_t * input, if (devconf->hqos_enabled == 0) { vlib_cli_output (vm, "HQoS disabled for this interface"); - return 0; + goto done; } /* Detect the set of worker threads */ @@ -1159,7 +1264,10 @@ show_dpdk_if_hqos (vlib_main_t * vm, unformat_input_t * input, /* Should never happen, shut up Coverity warning */ if (p == 0) - return clib_error_return (0, "no worker registrations?"); + { + error = clib_error_return (0, "no worker registrations?"); + goto done; + } tr = (vlib_thread_registration_t *) p[0]; @@ -1284,7 +1392,10 @@ show_dpdk_if_hqos (vlib_main_t * vm, unformat_input_t * input, } #endif - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -1315,6 +1426,7 @@ show_dpdk_hqos_queue_stats (vlib_main_t * vm, unformat_input_t * input, u32 qindex; struct rte_sched_queue_stats stats; u16 qlen; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -1339,14 +1451,18 @@ show_dpdk_hqos_queue_stats (vlib_main_t * vm, unformat_input_t * input, ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (hw_if_index == (u32) ~ 0) - return clib_error_return (0, "please specify interface name!!"); + { + error = clib_error_return (0, "please specify interface name!!"); + goto done; + } hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index); xd = vec_elt_at_index (dm->devices, hw->dev_instance); @@ -1373,7 +1489,7 @@ show_dpdk_hqos_queue_stats (vlib_main_t * vm, unformat_input_t * input, if (devconf->hqos_enabled == 0) { vlib_cli_output (vm, "HQoS disabled for this interface"); - return 0; + goto done; } /* @@ -1386,7 +1502,10 @@ show_dpdk_hqos_queue_stats (vlib_main_t * vm, unformat_input_t * input, if (rte_sched_queue_read_stats (xd->hqos_ht->hqos, qindex, &stats, &qlen) != 0) - return clib_error_return (0, "failed to read stats"); + { + error = clib_error_return (0, "failed to read stats"); + goto done; + } vlib_cli_output (vm, "%=24s%=16s", "Stats Parameter", "Value"); vlib_cli_output (vm, "%=24s%=16d", "Packets", stats.n_pkts); @@ -1399,7 +1518,10 @@ show_dpdk_hqos_queue_stats (vlib_main_t * vm, unformat_input_t * input, vlib_cli_output (vm, "%=24s%=16d", "Bytes dropped", stats.n_bytes_dropped); - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ diff --git a/src/vnet/devices/dpdk/ipsec/cli.c b/src/vnet/devices/dpdk/ipsec/cli.c index 93df4a64..f9d3a5d0 100644 --- a/src/vnet/devices/dpdk/ipsec/cli.c +++ b/src/vnet/devices/dpdk/ipsec/cli.c @@ -111,6 +111,7 @@ lcore_cryptodev_map_fn (vlib_main_t * vm, unformat_input_t * input, { unformat_input_t _line_input, *line_input = &_line_input; u16 detail = 0; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -120,15 +121,19 @@ lcore_cryptodev_map_fn (vlib_main_t * vm, unformat_input_t * input, if (unformat (line_input, "verbose")) detail = 1; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - dpdk_ipsec_show_mapping (vm, detail); - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ diff --git a/src/vnet/devices/netmap/cli.c b/src/vnet/devices/netmap/cli.c index 6157f27c..71363294 100644 --- a/src/vnet/devices/netmap/cli.c +++ b/src/vnet/devices/netmap/cli.c @@ -37,6 +37,7 @@ netmap_create_command_fn (vlib_main_t * vm, unformat_input_t * input, u8 is_pipe = 0; u8 is_master = 0; u32 sw_if_index = ~0; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -57,30 +58,48 @@ netmap_create_command_fn (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "slave")) is_master = 0; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (host_if_name == NULL) - return clib_error_return (0, "missing host interface name"); + { + error = clib_error_return (0, "missing host interface name"); + goto done; + } r = netmap_create_if (vm, host_if_name, hw_addr_ptr, is_pipe, is_master, &sw_if_index); if (r == VNET_API_ERROR_SYSCALL_ERROR_1) - return clib_error_return (0, "%s (errno %d)", strerror (errno), errno); + { + error = clib_error_return (0, "%s (errno %d)", strerror (errno), errno); + goto done; + } if (r == VNET_API_ERROR_INVALID_INTERFACE) - return clib_error_return (0, "Invalid interface name"); + { + error = clib_error_return (0, "Invalid interface name"); + goto done; + } if (r == VNET_API_ERROR_SUBIF_ALREADY_EXISTS) - return clib_error_return (0, "Interface already exists"); + { + error = clib_error_return (0, "Interface already exists"); + goto done; + } vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index); - return 0; + +done: + unformat_free (line_input); + + return error; } /*? @@ -144,6 +163,7 @@ netmap_delete_command_fn (vlib_main_t * vm, unformat_input_t * input, { unformat_input_t _line_input, *line_input = &_line_input; u8 *host_if_name = NULL; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -154,17 +174,25 @@ netmap_delete_command_fn (vlib_main_t * vm, unformat_input_t * input, if (unformat (line_input, "name %s", &host_if_name)) ; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (host_if_name == NULL) - return clib_error_return (0, "missing host interface name"); + { + error = clib_error_return (0, "missing host interface name"); + goto done; + } netmap_delete_if (vm, host_if_name); - return 0; +done: + unformat_free (line_input); + + return error; } /*? diff --git a/src/vnet/devices/virtio/vhost-user.c b/src/vnet/devices/virtio/vhost-user.c index 315daa77..c43f6e67 100644 --- a/src/vnet/devices/virtio/vhost-user.c +++ b/src/vnet/devices/virtio/vhost-user.c @@ -2682,6 +2682,7 @@ vhost_user_connect_command_fn (vlib_main_t * vm, u32 custom_dev_instance = ~0; u8 hwaddr[6]; u8 *hw = NULL; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -2704,10 +2705,12 @@ vhost_user_connect_command_fn (vlib_main_t * vm, renumber = 1; } else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); vnet_main_t *vnm = vnet_get_main (); @@ -2716,14 +2719,18 @@ vhost_user_connect_command_fn (vlib_main_t * vm, is_server, &sw_if_index, feature_mask, renumber, custom_dev_instance, hw))) { - vec_free (sock_filename); - return clib_error_return (0, "vhost_user_create_if returned %d", rv); + error = clib_error_return (0, "vhost_user_create_if returned %d", rv); + goto done; } - vec_free (sock_filename); vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index); - return 0; + +done: + vec_free (sock_filename); + unformat_free (line_input); + + return error; } clib_error_t * @@ -2734,6 +2741,7 @@ vhost_user_delete_command_fn (vlib_main_t * vm, unformat_input_t _line_input, *line_input = &_line_input; u32 sw_if_index = ~0; vnet_main_t *vnm = vnet_get_main (); + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -2751,15 +2759,25 @@ vhost_user_delete_command_fn (vlib_main_t * vm, vnet_get_sup_hw_interface (vnm, sw_if_index); if (hwif == NULL || vhost_user_dev_class.index != hwif->dev_class_index) - return clib_error_return (0, "Not a vhost interface"); + { + error = clib_error_return (0, "Not a vhost interface"); + goto done; + } } else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); + vhost_user_delete_if (vnm, vm, sw_if_index); - return 0; + +done: + unformat_free (line_input); + + return error; } int @@ -3286,6 +3304,7 @@ vhost_thread_command_fn (vlib_main_t * vm, u32 sw_if_index; u8 del = 0; int rv; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -3295,9 +3314,9 @@ vhost_thread_command_fn (vlib_main_t * vm, (line_input, "%U %d", unformat_vnet_sw_interface, vnet_get_main (), &sw_if_index, &worker_thread_index)) { - unformat_free (line_input); - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; } if (unformat (line_input, "del")) @@ -3305,9 +3324,16 @@ vhost_thread_command_fn (vlib_main_t * vm, if ((rv = vhost_user_thread_placement (sw_if_index, worker_thread_index, del))) - return clib_error_return (0, "vhost_user_thread_placement returned %d", - rv); - return 0; + { + error = clib_error_return (0, "vhost_user_thread_placement returned %d", + rv); + goto done; + } + +done: + unformat_free (line_input); + + return error; } diff --git a/src/vnet/gre/interface.c b/src/vnet/gre/interface.c index d624587d..d4476ac4 100644 --- a/src/vnet/gre/interface.c +++ b/src/vnet/gre/interface.c @@ -491,6 +491,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm, u32 num_m_args = 0; u8 is_add = 1; u32 sw_if_index; + clib_error_t *error = NULL; /* Get a line of input. */ if (! unformat_user (input, unformat_line_input, line_input)) @@ -508,16 +509,24 @@ create_gre_tunnel_command_fn (vlib_main_t * vm, else if (unformat (line_input, "teb")) teb = 1; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (num_m_args < 2) - return clib_error_return (0, "mandatory argument(s) missing"); + { + error = clib_error_return (0, "mandatory argument(s) missing"); + goto done; + } if (memcmp (&src, &dst, sizeof(src)) == 0) - return clib_error_return (0, "src and dst are identical"); + { + error = clib_error_return (0, "src and dst are identical"); + goto done; + } memset (a, 0, sizeof (*a)); a->outer_fib_id = outer_fib_id; @@ -536,15 +545,21 @@ create_gre_tunnel_command_fn (vlib_main_t * vm, vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index); break; case VNET_API_ERROR_INVALID_VALUE: - return clib_error_return (0, "GRE tunnel already exists..."); + error = clib_error_return (0, "GRE tunnel already exists..."); + goto done; case VNET_API_ERROR_NO_SUCH_FIB: - return clib_error_return (0, "outer fib ID %d doesn't exist\n", - outer_fib_id); + error = clib_error_return (0, "outer fib ID %d doesn't exist\n", + outer_fib_id); + goto done; default: - return clib_error_return (0, "vnet_gre_add_del_tunnel returned %d", rv); + error = clib_error_return (0, "vnet_gre_add_del_tunnel returned %d", rv); + goto done; } - return 0; +done: + unformat_free (line_input); + + return error; } VLIB_CLI_COMMAND (create_gre_tunnel_command, static) = { diff --git a/src/vnet/ip/ip4_source_check.c b/src/vnet/ip/ip4_source_check.c index d461cc88..3af32f2e 100644 --- a/src/vnet/ip/ip4_source_check.c +++ b/src/vnet/ip/ip4_source_check.c @@ -399,6 +399,8 @@ set_ip_source_check (vlib_main_t * vm, vnet_feature_enable_disable ("ip4-unicast", feature_name, sw_if_index, is_del == 0, &config, sizeof (config)); done: + unformat_free (line_input); + return error; } @@ -531,7 +533,9 @@ ip_source_check_accept (vlib_main_t * vm, } done: - return (error); + unformat_free (line_input); + + return error; } /*? diff --git a/src/vnet/ip/ip4_test.c b/src/vnet/ip/ip4_test.c index 45d17113..73dabfdc 100644 --- a/src/vnet/ip/ip4_test.c +++ b/src/vnet/ip/ip4_test.c @@ -143,8 +143,11 @@ thrash (vlib_main_t * vm, else if (unformat (line_input, "verbose")) verbose = 1; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } } @@ -178,7 +181,7 @@ thrash (vlib_main_t * vm, if (p == 0) { vlib_cli_output (vm, "Couldn't map fib id %d to fib index\n", table_id); - return 0; + goto done; } table_index = p[0]; @@ -294,7 +297,11 @@ thrash (vlib_main_t * vm, pool_free (tm->route_pool); } - return 0; + +done: + unformat_free (line_input); + + return error; } /*? diff --git a/src/vnet/ip/ip6_neighbor.c b/src/vnet/ip/ip6_neighbor.c index 7229591e..6b53137f 100644 --- a/src/vnet/ip/ip6_neighbor.c +++ b/src/vnet/ip/ip6_neighbor.c @@ -2923,7 +2923,10 @@ ip6_neighbor_cmd (vlib_main_t * vm, unformat_input_t * main_input, else if (unformat (line_input, "ra-lifetime")) { if (!unformat (line_input, "%d", &ra_lifetime)) - return (error = unformat_parse_error (line_input)); + { + error = unformat_parse_error (line_input); + goto done; + } use_lifetime = 1; break; } @@ -2931,13 +2934,19 @@ ip6_neighbor_cmd (vlib_main_t * vm, unformat_input_t * main_input, { if (!unformat (line_input, "%d %d", &ra_initial_count, &ra_initial_interval)) - return (error = unformat_parse_error (line_input)); + { + error = unformat_parse_error (line_input); + goto done; + } break; } else if (unformat (line_input, "ra-interval")) { if (!unformat (line_input, "%d", &ra_max_interval)) - return (error = unformat_parse_error (line_input)); + { + error = unformat_parse_error (line_input); + goto done; + } if (!unformat (line_input, "%d", &ra_min_interval)) ra_min_interval = 0; @@ -2949,7 +2958,10 @@ ip6_neighbor_cmd (vlib_main_t * vm, unformat_input_t * main_input, break; } else - return (unformat_parse_error (line_input)); + { + error = unformat_parse_error (line_input); + goto done; + } } if (add_radv_info) @@ -3006,7 +3018,10 @@ ip6_neighbor_cmd (vlib_main_t * vm, unformat_input_t * main_input, else if (unformat (line_input, "no-onlink")) no_onlink = 1; else - return (unformat_parse_error (line_input)); + { + error = unformat_parse_error (line_input); + goto done; + } } ip6_neighbor_ra_prefix (vm, sw_if_index, @@ -3018,9 +3033,9 @@ ip6_neighbor_cmd (vlib_main_t * vm, unformat_input_t * main_input, off_link, no_autoconfig, no_onlink, is_no); } +done: unformat_free (line_input); -done: return error; } diff --git a/src/vnet/ip/lookup.c b/src/vnet/ip/lookup.c index 0ef0e7a6..807b87b6 100644 --- a/src/vnet/ip/lookup.c +++ b/src/vnet/ip/lookup.c @@ -568,8 +568,6 @@ vnet_ip_route_cmd (vlib_main_t * vm, } } - unformat_free (line_input); - if (vec_len (prefixs) == 0) { error = @@ -704,6 +702,7 @@ done: vec_free (dpos); vec_free (prefixs); vec_free (rpaths); + unformat_free (line_input); return error; } @@ -872,8 +871,6 @@ vnet_ip_mroute_cmd (vlib_main_t * vm, } } - unformat_free (line_input); - if (~0 == table_id) { /* @@ -970,6 +967,8 @@ vnet_ip_mroute_cmd (vlib_main_t * vm, (scount * gcount) / (timet[1] - timet[0])); done: + unformat_free (line_input); + return error; } @@ -1149,24 +1148,37 @@ probe_neighbor_address (vlib_main_t * vm, is_ip4 = 0; } else - return clib_error_return (0, "unknown input '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "unknown input '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (sw_if_index == ~0) - return clib_error_return (0, "Interface required, not set."); + { + error = clib_error_return (0, "Interface required, not set."); + goto done; + } if (address_set == 0) - return clib_error_return (0, "ip address required, not set."); + { + error = clib_error_return (0, "ip address required, not set."); + goto done; + } if (address_set > 1) - return clib_error_return (0, "Multiple ip addresses not supported."); + { + error = clib_error_return (0, "Multiple ip addresses not supported."); + goto done; + } if (is_ip4) error = ip4_probe_neighbor_wait (vm, &a4, sw_if_index, retry_count); else error = ip6_probe_neighbor_wait (vm, &a6, sw_if_index, retry_count); +done: + unformat_free (line_input); + return error; } diff --git a/src/vnet/ipsec-gre/interface.c b/src/vnet/ipsec-gre/interface.c index 3b6e4ac2..0772ce73 100644 --- a/src/vnet/ipsec-gre/interface.c +++ b/src/vnet/ipsec-gre/interface.c @@ -232,6 +232,7 @@ create_ipsec_gre_tunnel_command_fn (vlib_main_t * vm, vnet_ipsec_gre_add_del_tunnel_args_t _a, *a = &_a; int rv; u32 sw_if_index; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -250,16 +251,24 @@ create_ipsec_gre_tunnel_command_fn (vlib_main_t * vm, else if (unformat (line_input, "remote-sa %d", &rsa)) num_m_args++; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (num_m_args < 4) - return clib_error_return (0, "mandatory argument(s) missing"); + { + error = clib_error_return (0, "mandatory argument(s) missing"); + goto done; + } if (memcmp (&src, &dst, sizeof (src)) == 0) - return clib_error_return (0, "src and dst are identical"); + { + error = clib_error_return (0, "src and dst are identical"); + goto done; + } memset (a, 0, sizeof (*a)); a->is_add = is_add; @@ -277,14 +286,19 @@ create_ipsec_gre_tunnel_command_fn (vlib_main_t * vm, vnet_get_main (), sw_if_index); break; case VNET_API_ERROR_INVALID_VALUE: - return clib_error_return (0, "GRE tunnel already exists..."); + error = clib_error_return (0, "GRE tunnel already exists..."); + goto done; default: - return clib_error_return (0, - "vnet_ipsec_gre_add_del_tunnel returned %d", - rv); + error = clib_error_return (0, + "vnet_ipsec_gre_add_del_tunnel returned %d", + rv); + goto done; } - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ diff --git a/src/vnet/ipsec/ipsec_cli.c b/src/vnet/ipsec/ipsec_cli.c index 3c1e26f2..0e034402 100644 --- a/src/vnet/ipsec/ipsec_cli.c +++ b/src/vnet/ipsec/ipsec_cli.c @@ -32,6 +32,7 @@ set_interface_spd_command_fn (vlib_main_t * vm, u32 sw_if_index = (u32) ~ 0; u32 spd_id; int is_add = 1; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -43,14 +44,18 @@ set_interface_spd_command_fn (vlib_main_t * vm, else if (unformat (line_input, "del")) is_add = 0; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); - - unformat_free (line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } ipsec_set_interface_spd (vm, sw_if_index, spd_id, is_add); - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -72,7 +77,7 @@ ipsec_sa_add_del_command_fn (vlib_main_t * vm, ipsec_sa_t sa; int is_add = ~0; u8 *ck = 0, *ik = 0; - clib_error_t *err = 0; + clib_error_t *error = NULL; memset (&sa, 0, sizeof (sa)); @@ -90,8 +95,11 @@ ipsec_sa_add_del_command_fn (vlib_main_t * vm, else if (unformat (line_input, "esp")) sa.protocol = IPSEC_PROTOCOL_ESP; else if (unformat (line_input, "ah")) - //sa.protocol = IPSEC_PROTOCOL_AH; - return clib_error_return (0, "unsupported security protocol 'AH'"); + { + //sa.protocol = IPSEC_PROTOCOL_AH; + error = clib_error_return (0, "unsupported security protocol 'AH'"); + goto done; + } else if (unformat (line_input, "crypto-key %U", unformat_hex_string, &ck)) sa.crypto_key_len = vec_len (ck); @@ -102,8 +110,12 @@ ipsec_sa_add_del_command_fn (vlib_main_t * vm, { if (sa.crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 || sa.crypto_alg >= IPSEC_CRYPTO_N_ALG) - return clib_error_return (0, "unsupported crypto-alg: '%U'", - format_ipsec_crypto_alg, sa.crypto_alg); + { + error = clib_error_return (0, "unsupported crypto-alg: '%U'", + format_ipsec_crypto_alg, + sa.crypto_alg); + goto done; + } } else if (unformat (line_input, "integ-key %U", unformat_hex_string, &ik)) @@ -113,8 +125,12 @@ ipsec_sa_add_del_command_fn (vlib_main_t * vm, { if (sa.integ_alg < IPSEC_INTEG_ALG_SHA1_96 || sa.integ_alg >= IPSEC_INTEG_N_ALG) - return clib_error_return (0, "unsupported integ-alg: '%U'", - format_ipsec_integ_alg, sa.integ_alg); + { + error = clib_error_return (0, "unsupported integ-alg: '%U'", + format_ipsec_integ_alg, + sa.integ_alg); + goto done; + } } else if (unformat (line_input, "tunnel-src %U", unformat_ip4_address, &sa.tunnel_src_addr.ip4)) @@ -135,12 +151,13 @@ ipsec_sa_add_del_command_fn (vlib_main_t * vm, sa.is_tunnel_ip6 = 1; } else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (sa.crypto_key_len > sizeof (sa.crypto_key)) sa.crypto_key_len = sizeof (sa.crypto_key); @@ -156,14 +173,17 @@ ipsec_sa_add_del_command_fn (vlib_main_t * vm, if (is_add) { ASSERT (im->cb.check_support_cb); - err = im->cb.check_support_cb (&sa); - if (err) - return err; + error = im->cb.check_support_cb (&sa); + if (error) + goto done; } ipsec_add_del_sa (vm, &sa, is_add); - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -183,6 +203,7 @@ ipsec_spd_add_del_command_fn (vlib_main_t * vm, unformat_input_t _line_input, *line_input = &_line_input; u32 spd_id = ~0; int is_add = ~0; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -196,18 +217,25 @@ ipsec_spd_add_del_command_fn (vlib_main_t * vm, else if (unformat (line_input, "%u", &spd_id)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (spd_id == ~0) - return clib_error_return (0, "please specify SPD ID"); + { + error = clib_error_return (0, "please specify SPD ID"); + goto done; + } ipsec_add_del_spd (vm, spd_id, is_add); - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -230,6 +258,7 @@ ipsec_policy_add_del_command_fn (vlib_main_t * vm, int is_add = 0; int is_ip_any = 1; u32 tmp, tmp2; + clib_error_t *error = NULL; memset (&p, 0, sizeof (p)); p.lport.stop = p.rport.stop = ~0; @@ -262,7 +291,10 @@ ipsec_policy_add_del_command_fn (vlib_main_t * vm, &p.policy)) { if (p.policy == IPSEC_POLICY_ACTION_RESOLVE) - return clib_error_return (0, "unsupported action: 'resolve'"); + { + error = clib_error_return (0, "unsupported action: 'resolve'"); + goto done; + } } else if (unformat (line_input, "sa %u", &p.sa_id)) ; @@ -300,19 +332,24 @@ ipsec_policy_add_del_command_fn (vlib_main_t * vm, p.rport.stop = tmp2; } else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - ipsec_add_del_policy (vm, &p, is_add); if (is_ip_any) { p.is_ipv6 = 1; ipsec_add_del_policy (vm, &p, is_add); } - return 0; + +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -332,6 +369,7 @@ set_ipsec_sa_key_command_fn (vlib_main_t * vm, unformat_input_t _line_input, *line_input = &_line_input; ipsec_sa_t sa; u8 *ck = 0, *ik = 0; + clib_error_t *error = NULL; memset (&sa, 0, sizeof (sa)); @@ -349,12 +387,13 @@ set_ipsec_sa_key_command_fn (vlib_main_t * vm, if (unformat (line_input, "integ-key %U", unformat_hex_string, &ik)) sa.integ_key_len = vec_len (ik); else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (sa.crypto_key_len > sizeof (sa.crypto_key)) sa.crypto_key_len = sizeof (sa.crypto_key); @@ -369,7 +408,10 @@ set_ipsec_sa_key_command_fn (vlib_main_t * vm, ipsec_set_sa_key (vm, &sa); - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -649,6 +691,7 @@ create_ipsec_tunnel_command_fn (vlib_main_t * vm, ipsec_add_del_tunnel_args_t a; int rv; u32 num_m_args = 0; + clib_error_t *error = NULL; memset (&a, 0, sizeof (a)); a.is_add = 1; @@ -673,13 +716,18 @@ create_ipsec_tunnel_command_fn (vlib_main_t * vm, else if (unformat (line_input, "del")) a.is_add = 0; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (num_m_args < 4) - return clib_error_return (0, "mandatory argument(s) missing"); + { + error = clib_error_return (0, "mandatory argument(s) missing"); + goto done; + } rv = ipsec_add_del_tunnel_if (&a); @@ -689,16 +737,21 @@ create_ipsec_tunnel_command_fn (vlib_main_t * vm, break; case VNET_API_ERROR_INVALID_VALUE: if (a.is_add) - return clib_error_return (0, - "IPSec tunnel interface already exists..."); + error = clib_error_return (0, + "IPSec tunnel interface already exists..."); else - return clib_error_return (0, "IPSec tunnel interface not exists..."); + error = clib_error_return (0, "IPSec tunnel interface not exists..."); + goto done; default: - return clib_error_return (0, "ipsec_register_interface returned %d", - rv); + error = clib_error_return (0, "ipsec_register_interface returned %d", + rv); + goto done; } - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -720,6 +773,7 @@ set_interface_key_command_fn (vlib_main_t * vm, u32 hw_if_index = (u32) ~ 0; u32 alg; u8 *key = 0; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -748,25 +802,38 @@ set_interface_key_command_fn (vlib_main_t * vm, else if (unformat (line_input, "%U", unformat_hex_string, &key)) ; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (type == IPSEC_IF_SET_KEY_TYPE_NONE) - return clib_error_return (0, "unknown key type"); + { + error = clib_error_return (0, "unknown key type"); + goto done; + } if (alg > 0 && vec_len (key) == 0) - return clib_error_return (0, "key is not specified"); + { + error = clib_error_return (0, "key is not specified"); + goto done; + } if (hw_if_index == (u32) ~ 0) - return clib_error_return (0, "interface not specified"); + { + error = clib_error_return (0, "interface not specified"); + goto done; + } ipsec_set_interface_key (im->vnet_main, hw_if_index, type, alg, key); + +done: vec_free (key); + unformat_free (line_input); - return 0; + return error; } /* *INDENT-OFF* */ diff --git a/src/vnet/l2/l2_patch.c b/src/vnet/l2/l2_patch.c index 5e4691f4..ff3d2f3a 100644 --- a/src/vnet/l2/l2_patch.c +++ b/src/vnet/l2/l2_patch.c @@ -315,6 +315,7 @@ test_patch_command_fn (vlib_main_t * vm, int rx_set = 0; int tx_set = 0; int is_add = 1; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -335,10 +336,16 @@ test_patch_command_fn (vlib_main_t * vm, } if (rx_set == 0) - return clib_error_return (0, "rx interface not set"); + { + error = clib_error_return (0, "rx interface not set"); + goto done; + } if (tx_set == 0) - return clib_error_return (0, "tx interface not set"); + { + error = clib_error_return (0, "tx interface not set"); + goto done; + } rv = vnet_l2_patch_add_del (rx_sw_if_index, tx_sw_if_index, is_add); @@ -348,17 +355,24 @@ test_patch_command_fn (vlib_main_t * vm, break; case VNET_API_ERROR_INVALID_SW_IF_INDEX: - return clib_error_return (0, "rx interface not a physical port"); + error = clib_error_return (0, "rx interface not a physical port"); + goto done; case VNET_API_ERROR_INVALID_SW_IF_INDEX_2: - return clib_error_return (0, "tx interface not a physical port"); + error = clib_error_return (0, "tx interface not a physical port"); + goto done; default: - return clib_error_return + error = clib_error_return (0, "WARNING: vnet_l2_patch_add_del returned %d", rv); + goto done; } - return 0; + +done: + unformat_free (line_input); + + return error; } /*? diff --git a/src/vnet/l2/l2_xcrw.c b/src/vnet/l2/l2_xcrw.c index 70610a85..d08a5d8f 100644 --- a/src/vnet/l2/l2_xcrw.c +++ b/src/vnet/l2/l2_xcrw.c @@ -409,6 +409,7 @@ set_l2_xcrw_command_fn (vlib_main_t * vm, u8 *rw = 0; vnet_main_t *vnm = vnet_get_main (); int rv; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) @@ -416,8 +417,11 @@ set_l2_xcrw_command_fn (vlib_main_t * vm, if (!unformat (line_input, "%U", unformat_vnet_sw_interface, vnm, &l2_sw_if_index)) - return clib_error_return (0, "unknown input '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "unknown input '%U'", + format_unformat_error, line_input); + goto done; + } while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { @@ -436,7 +440,10 @@ set_l2_xcrw_command_fn (vlib_main_t * vm, } if (next_node_index == ~0) - return clib_error_return (0, "next node not specified"); + { + error = clib_error_return (0, "next node not specified"); + goto done; + } if (tx_fib_id != ~0) { @@ -448,7 +455,11 @@ set_l2_xcrw_command_fn (vlib_main_t * vm, p = hash_get (ip4_main.fib_index_by_table_id, tx_fib_id); if (p == 0) - return clib_error_return (0, "nonexistent tx_fib_id %d", tx_fib_id); + { + error = + clib_error_return (0, "nonexistent tx_fib_id %d", tx_fib_id); + goto done; + } tx_fib_index = p[0]; } @@ -463,16 +474,21 @@ set_l2_xcrw_command_fn (vlib_main_t * vm, break; case VNET_API_ERROR_INVALID_SW_IF_INDEX: - return clib_error_return (0, "%U not cross-connected", - format_vnet_sw_if_index_name, - vnm, l2_sw_if_index); + error = clib_error_return (0, "%U not cross-connected", + format_vnet_sw_if_index_name, + vnm, l2_sw_if_index); + goto done; + default: - return clib_error_return (0, "vnet_configure_l2_xcrw returned %d", rv); + error = clib_error_return (0, "vnet_configure_l2_xcrw returned %d", rv); + goto done; } +done: vec_free (rw); + unformat_free (line_input); - return 0; + return error; } /*? diff --git a/src/vnet/l2tp/l2tp.c b/src/vnet/l2tp/l2tp.c index a4531dab..2d323397 100644 --- a/src/vnet/l2tp/l2tp.c +++ b/src/vnet/l2tp/l2tp.c @@ -427,6 +427,7 @@ create_l2tpv3_tunnel_command_fn (vlib_main_t * vm, u32 sw_if_index; u32 encap_fib_id = ~0; u32 encap_fib_index = ~0; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -455,18 +456,22 @@ create_l2tpv3_tunnel_command_fn (vlib_main_t * vm, else if (unformat (line_input, "l2-sublayer-present")) l2_sublayer_present = 1; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (encap_fib_id != ~0) { uword *p; ip6_main_t *im = &ip6_main; if (!(p = hash_get (im->fib_index_by_table_id, encap_fib_id))) - return clib_error_return (0, "No fib with id %d", encap_fib_id); + { + error = clib_error_return (0, "No fib with id %d", encap_fib_id); + goto done; + } encap_fib_index = p[0]; } else @@ -475,9 +480,15 @@ create_l2tpv3_tunnel_command_fn (vlib_main_t * vm, } if (our_address_set == 0) - return clib_error_return (0, "our address not specified"); + { + error = clib_error_return (0, "our address not specified"); + goto done; + } if (client_address_set == 0) - return clib_error_return (0, "client address not specified"); + { + error = clib_error_return (0, "client address not specified"); + goto done; + } rv = create_l2tpv3_ipv6_tunnel (lm, &client_address, &our_address, local_session_id, remote_session_id, @@ -491,16 +502,22 @@ create_l2tpv3_tunnel_command_fn (vlib_main_t * vm, vnet_get_main (), sw_if_index); break; case VNET_API_ERROR_INVALID_VALUE: - return clib_error_return (0, "session already exists..."); + error = clib_error_return (0, "session already exists..."); + goto done; case VNET_API_ERROR_NO_SUCH_ENTRY: - return clib_error_return (0, "session does not exist..."); + error = clib_error_return (0, "session does not exist..."); + goto done; default: - return clib_error_return (0, "l2tp_session_add_del returned %d", rv); + error = clib_error_return (0, "l2tp_session_add_del returned %d", rv); + goto done; } - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ diff --git a/src/vnet/lisp-cp/lisp_cli.c b/src/vnet/lisp-cp/lisp_cli.c index 25d11c61..05df9fb6 100644 --- a/src/vnet/lisp-cp/lisp_cli.c +++ b/src/vnet/lisp-cp/lisp_cli.c @@ -25,6 +25,7 @@ lisp_show_adjacencies_command_fn (vlib_main_t * vm, vlib_cli_output (vm, "%s %40s\n", "leid", "reid"); unformat_input_t _line_input, *line_input = &_line_input; u32 vni = ~0; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -38,14 +39,14 @@ lisp_show_adjacencies_command_fn (vlib_main_t * vm, { vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, line_input); - return 0; + goto done; } } if (~0 == vni) { vlib_cli_output (vm, "error: no vni specified!"); - return 0; + goto done; } adjs = vnet_lisp_adjacencies_get_by_vni (vni); @@ -57,7 +58,10 @@ lisp_show_adjacencies_command_fn (vlib_main_t * vm, } vec_free (adjs); - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -77,6 +81,7 @@ lisp_add_del_map_server_command_fn (vlib_main_t * vm, u8 is_add = 1, ip_set = 0; ip_address_t ip; unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -94,14 +99,14 @@ lisp_add_del_map_server_command_fn (vlib_main_t * vm, { vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, line_input); - return 0; + goto done; } } if (!ip_set) { vlib_cli_output (vm, "map-server ip address not set!"); - return 0; + goto done; } rv = vnet_lisp_add_del_map_server (&ip, is_add); @@ -109,7 +114,10 @@ lisp_add_del_map_server_command_fn (vlib_main_t * vm, vlib_cli_output (vm, "failed to %s map-server!", is_add ? "add" : "delete"); - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -191,7 +199,7 @@ lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input, if (key && (0 == key_id)) { vlib_cli_output (vm, "invalid key_id!"); - return 0; + goto done;; } gid_address_copy (&a->eid, &eid); @@ -213,6 +221,8 @@ done: vec_free (locator_set_name); gid_address_free (&a->eid); vec_free (a->key); + unformat_free (line_input); + return error; } @@ -233,6 +243,7 @@ lisp_eid_table_map_command_fn (vlib_main_t * vm, u8 is_add = 1, is_l2 = 0; u32 vni = 0, dp_id = 0; unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -250,11 +261,16 @@ lisp_eid_table_map_command_fn (vlib_main_t * vm, is_l2 = 1; else { - return unformat_parse_error (line_input); + error = unformat_parse_error (line_input); + goto done; } } vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add); - return 0; + +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -479,7 +495,7 @@ lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input, != ip_prefix_version (leid_ippref))) { clib_warning ("remote and local EIDs are of different types!"); - return error; + goto done; } memset (a, 0, sizeof (a[0])); @@ -512,6 +528,7 @@ lisp_map_request_mode_command_fn (vlib_main_t * vm, { unformat_input_t _i, *i = &_i; map_request_mode_t mr_mode = _MR_MODE_MAX; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, i)) @@ -533,12 +550,15 @@ lisp_map_request_mode_command_fn (vlib_main_t * vm, if (_MR_MODE_MAX == mr_mode) { clib_warning ("No LISP map request mode entered!"); - return 0; + goto done; } vnet_lisp_set_map_request_mode (mr_mode); + done: - return 0; + unformat_free (i); + + return error; } /* *INDENT-OFF* */ @@ -630,7 +650,10 @@ lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm, else if (unformat (line_input, "disable")) is_add = 0; else - return clib_error_return (0, "parse error"); + { + error = clib_error_return (0, "parse error"); + goto done; + } } if (!locator_name_set) @@ -648,6 +671,8 @@ lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm, done: if (locator_set_name) vec_free (locator_set_name); + unformat_free (line_input); + return error; } @@ -771,6 +796,7 @@ lisp_show_eid_table_command_fn (vlib_main_t * vm, gid_address_t eid; u8 print_all = 1; u8 filter = 0; + clib_error_t *error = NULL; memset (&eid, 0, sizeof (eid)); @@ -787,8 +813,11 @@ lisp_show_eid_table_command_fn (vlib_main_t * vm, else if (unformat (line_input, "remote")) filter = 2; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s", @@ -818,7 +847,7 @@ lisp_show_eid_table_command_fn (vlib_main_t * vm, { mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid); if ((u32) ~ 0 == mi) - return 0; + goto done; mapit = pool_elt_at_index (lcm->mapping_pool, mi); locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, @@ -827,14 +856,17 @@ lisp_show_eid_table_command_fn (vlib_main_t * vm, if (filter && !((1 == filter && ls->local) || (2 == filter && !ls->local))) { - return 0; + goto done; } vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main, lcm, mapit, ls); } - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -853,6 +885,7 @@ lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input, unformat_input_t _line_input, *line_input = &_line_input; u8 is_enabled = 0; u8 is_set = 0; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -869,16 +902,24 @@ lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input, is_set = 1; else { - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; } } if (!is_set) - return clib_error_return (0, "state not set"); + { + error = clib_error_return (0, "state not set"); + goto done; + } vnet_lisp_enable_disable (is_enabled); - return 0; + +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -897,6 +938,7 @@ lisp_map_register_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t _line_input, *line_input = &_line_input; u8 is_enabled = 0; u8 is_set = 0; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -915,18 +957,22 @@ lisp_map_register_enable_disable_command_fn (vlib_main_t * vm, { vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, line_input); - return 0; + goto done; } } if (!is_set) { vlib_cli_output (vm, "state not set!"); - return 0; + goto done; } vnet_lisp_map_register_enable_disable (is_enabled); - return 0; + +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -945,6 +991,7 @@ lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t _line_input, *line_input = &_line_input; u8 is_enabled = 0; u8 is_set = 0; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -963,18 +1010,22 @@ lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm, { vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, line_input); - return 0; + goto done; } } if (!is_set) { vlib_cli_output (vm, "state not set!"); - return 0; + goto done; } vnet_lisp_rloc_probe_enable_disable (is_enabled); - return 0; + +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -1022,6 +1073,7 @@ lisp_show_eid_table_map_command_fn (vlib_main_t * vm, lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); uword *vni_table = 0; u8 is_l2 = 0; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -1040,14 +1092,17 @@ lisp_show_eid_table_map_command_fn (vlib_main_t * vm, is_l2 = 0; } else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } if (!vni_table) { vlib_cli_output (vm, "Error: expected l2|l3 param!\n"); - return 0; + goto done; } vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF"); @@ -1059,7 +1114,10 @@ lisp_show_eid_table_map_command_fn (vlib_main_t * vm, })); /* *INDENT-ON* */ - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ @@ -1131,6 +1189,8 @@ done: vec_free (locators); if (locator_set_name) vec_free (locator_set_name); + unformat_free (line_input); + return error; } @@ -1205,6 +1265,8 @@ lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm, done: vec_free (locators); vec_free (locator_set_name); + unformat_free (line_input); + return error; } @@ -1322,6 +1384,8 @@ lisp_add_del_map_resolver_command_fn (vlib_main_t * vm, } done: + unformat_free (line_input); + return error; } @@ -1372,11 +1436,11 @@ lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm, is_add ? "add" : "delete"); } +done: vec_free (locator_set_name); + unformat_free (line_input); -done: return error; - } /* *INDENT-OFF* */ @@ -1438,7 +1502,10 @@ lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm, else if (unformat (line_input, "disable")) is_add = 0; else - return clib_error_return (0, "parse error"); + { + error = clib_error_return (0, "parse error"); + goto done; + } } if (!ip_set) @@ -1454,6 +1521,8 @@ lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm, } done: + unformat_free (line_input); + return error; } diff --git a/src/vnet/lisp-gpe/interface.c b/src/vnet/lisp-gpe/interface.c index 2142e095..19ac22e7 100644 --- a/src/vnet/lisp-gpe/interface.c +++ b/src/vnet/lisp-gpe/interface.c @@ -794,6 +794,7 @@ lisp_gpe_add_del_iface_command_fn (vlib_main_t * vm, unformat_input_t * input, u32 table_id, vni, bd_id; u8 vni_is_set = 0, vrf_is_set = 0, bd_index_is_set = 0; u8 nsh_iface = 0; + clib_error_t *error = NULL; if (vnet_lisp_gpe_enable_disable_status () == 0) { @@ -828,8 +829,9 @@ lisp_gpe_add_del_iface_command_fn (vlib_main_t * vm, unformat_input_t * input, } else { - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; } } @@ -839,7 +841,8 @@ lisp_gpe_add_del_iface_command_fn (vlib_main_t * vm, unformat_input_t * input, { if (~0 == lisp_gpe_add_nsh_iface (&lisp_gpe_main)) { - return clib_error_return (0, "NSH interface not created"); + error = clib_error_return (0, "NSH interface not created"); + goto done; } } else @@ -850,21 +853,34 @@ lisp_gpe_add_del_iface_command_fn (vlib_main_t * vm, unformat_input_t * input, } if (vrf_is_set && bd_index_is_set) - return clib_error_return (0, - "Cannot set both vrf and brdige domain index!"); + { + error = clib_error_return + (0, "Cannot set both vrf and brdige domain index!"); + goto done; + } if (!vni_is_set) - return clib_error_return (0, "vni must be set!"); + { + error = clib_error_return (0, "vni must be set!"); + goto done; + } if (!vrf_is_set && !bd_index_is_set) - return clib_error_return (0, "vrf or bridge domain index must be set!"); + { + error = + clib_error_return (0, "vrf or bridge domain index must be set!"); + goto done; + } if (bd_index_is_set) { if (is_add) { if (~0 == lisp_gpe_tenant_l2_iface_add_or_lock (vni, bd_id)) - return clib_error_return (0, "L2 interface not created"); + { + error = clib_error_return (0, "L2 interface not created"); + goto done; + } } else lisp_gpe_tenant_l2_iface_unlock (vni); @@ -874,13 +890,35 @@ lisp_gpe_add_del_iface_command_fn (vlib_main_t * vm, unformat_input_t * input, if (is_add) { if (~0 == lisp_gpe_tenant_l3_iface_add_or_lock (vni, table_id)) - return clib_error_return (0, "L3 interface not created"); + { + error = clib_error_return (0, "L3 interface not created"); + goto done; + } } else lisp_gpe_tenant_l3_iface_unlock (vni); } - return (NULL); + if (nsh_iface) + { + if (is_add) + { + if (~0 == lisp_gpe_add_nsh_iface (&lisp_gpe_main)) + { + error = clib_error_return (0, "NSH interface not created"); + goto done; + } + else + { + lisp_gpe_del_nsh_iface (&lisp_gpe_main); + } + } + } + +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ diff --git a/src/vnet/lisp-gpe/lisp_gpe.c b/src/vnet/lisp-gpe/lisp_gpe.c index 1f8afdae..f2fbcbd5 100644 --- a/src/vnet/lisp-gpe/lisp_gpe.c +++ b/src/vnet/lisp-gpe/lisp_gpe.c @@ -218,6 +218,7 @@ lisp_gpe_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t _line_input, *line_input = &_line_input; u8 is_en = 1; vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -231,12 +232,18 @@ lisp_gpe_enable_disable_command_fn (vlib_main_t * vm, is_en = 0; else { - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; } } a->is_en = is_en; - return vnet_lisp_gpe_enable_disable (a); + error = vnet_lisp_gpe_enable_disable (a); + +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ diff --git a/src/vnet/map/map.c b/src/vnet/map/map.c index aeec6a94..a2d28118 100644 --- a/src/vnet/map/map.c +++ b/src/vnet/map/map.c @@ -465,6 +465,8 @@ map_security_check_command_fn (vlib_main_t * vm, { unformat_input_t _line_input, *line_input = &_line_input; map_main_t *mm = &map_main; + clib_error_t *error = NULL; + /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -476,11 +478,17 @@ map_security_check_command_fn (vlib_main_t * vm, else if (unformat (line_input, "on")) mm->sec_check = true; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } + +done: unformat_free (line_input); - return 0; + + return error; } static clib_error_t * @@ -490,6 +498,8 @@ map_security_check_frag_command_fn (vlib_main_t * vm, { unformat_input_t _line_input, *line_input = &_line_input; map_main_t *mm = &map_main; + clib_error_t *error = NULL; + /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -501,11 +511,17 @@ map_security_check_frag_command_fn (vlib_main_t * vm, else if (unformat (line_input, "on")) mm->sec_check_frag = true; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } + +done: unformat_free (line_input); - return 0; + + return error; } static clib_error_t * @@ -523,6 +539,7 @@ map_add_domain_command_fn (vlib_main_t * vm, u32 mtu = 0; u8 flags = 0; ip6_src_len = 128; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -559,20 +576,28 @@ map_add_domain_command_fn (vlib_main_t * vm, else if (unformat (line_input, "map-t")) flags |= MAP_DOMAIN_TRANSLATION; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (num_m_args < 3) - return clib_error_return (0, "mandatory argument(s) missing"); + { + error = clib_error_return (0, "mandatory argument(s) missing"); + goto done; + } map_create_domain (&ip4_prefix, ip4_prefix_len, &ip6_prefix, ip6_prefix_len, &ip6_src, ip6_src_len, ea_bits_len, psid_offset, psid_length, &map_domain_index, mtu, flags); - return 0; +done: + unformat_free (line_input); + + return error; } static clib_error_t * @@ -582,6 +607,7 @@ map_del_domain_command_fn (vlib_main_t * vm, unformat_input_t _line_input, *line_input = &_line_input; u32 num_m_args = 0; u32 map_domain_index; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -592,17 +618,25 @@ map_del_domain_command_fn (vlib_main_t * vm, if (unformat (line_input, "index %d", &map_domain_index)) num_m_args++; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (num_m_args != 1) - return clib_error_return (0, "mandatory argument(s) missing"); + { + error = clib_error_return (0, "mandatory argument(s) missing"); + goto done; + } map_delete_domain (map_domain_index); - return 0; +done: + unformat_free (line_input); + + return error; } static clib_error_t * @@ -613,6 +647,7 @@ map_add_rule_command_fn (vlib_main_t * vm, ip6_address_t tep; u32 num_m_args = 0; u32 psid = 0, map_domain_index; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -628,19 +663,29 @@ map_add_rule_command_fn (vlib_main_t * vm, if (unformat (line_input, "ip6-dst %U", unformat_ip6_address, &tep)) num_m_args++; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (num_m_args != 3) - return clib_error_return (0, "mandatory argument(s) missing"); + { + error = clib_error_return (0, "mandatory argument(s) missing"); + goto done; + } if (map_add_del_psid (map_domain_index, psid, &tep, 1) != 0) { - return clib_error_return (0, "Failing to add Mapping Rule"); + error = clib_error_return (0, "Failing to add Mapping Rule"); + goto done; } - return 0; + +done: + unformat_free (line_input); + + return error; } #if MAP_SKIP_IP6_LOOKUP @@ -653,6 +698,7 @@ map_pre_resolve_command_fn (vlib_main_t * vm, ip4_address_t ip4nh; ip6_address_t ip6nh; map_main_t *mm = &map_main; + clib_error_t *error = NULL; memset (&ip4nh, 0, sizeof (ip4nh)); memset (&ip6nh, 0, sizeof (ip6nh)); @@ -669,14 +715,19 @@ map_pre_resolve_command_fn (vlib_main_t * vm, if (unformat (line_input, "ip6-nh %U", unformat_ip6_address, &ip6nh)) mm->preresolve_ip6 = ip6nh; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); map_pre_resolve (&ip4nh, &ip6nh); - return 0; +done: + unformat_free (line_input); + + return error; } #endif @@ -688,6 +739,7 @@ map_icmp_relay_source_address_command_fn (vlib_main_t * vm, unformat_input_t _line_input, *line_input = &_line_input; ip4_address_t icmp_src_address; map_main_t *mm = &map_main; + clib_error_t *error = NULL; mm->icmp4_src_address.as_u32 = 0; @@ -701,12 +753,17 @@ map_icmp_relay_source_address_command_fn (vlib_main_t * vm, (line_input, "%U", unformat_ip4_address, &icmp_src_address)) mm->icmp4_src_address = icmp_src_address; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } + +done: unformat_free (line_input); - return 0; + return error; } static clib_error_t * @@ -717,6 +774,7 @@ map_icmp_unreachables_command_fn (vlib_main_t * vm, unformat_input_t _line_input, *line_input = &_line_input; map_main_t *mm = &map_main; int num_m_args = 0; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -730,16 +788,21 @@ map_icmp_unreachables_command_fn (vlib_main_t * vm, else if (unformat (line_input, "off")) mm->icmp6_enabled = false; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (num_m_args != 1) - return clib_error_return (0, "mandatory argument(s) missing"); + error = clib_error_return (0, "mandatory argument(s) missing"); - return 0; +done: + unformat_free (line_input); + + return error; } static clib_error_t * @@ -748,6 +811,7 @@ map_fragment_command_fn (vlib_main_t * vm, { unformat_input_t _line_input, *line_input = &_line_input; map_main_t *mm = &map_main; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -760,12 +824,17 @@ map_fragment_command_fn (vlib_main_t * vm, else if (unformat (line_input, "outer")) mm->frag_inner = false; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } + +done: unformat_free (line_input); - return 0; + return error; } static clib_error_t * @@ -775,6 +844,7 @@ map_fragment_df_command_fn (vlib_main_t * vm, { unformat_input_t _line_input, *line_input = &_line_input; map_main_t *mm = &map_main; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -787,12 +857,17 @@ map_fragment_df_command_fn (vlib_main_t * vm, else if (unformat (line_input, "off")) mm->frag_ignore_df = false; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } + +done: unformat_free (line_input); - return 0; + return error; } static clib_error_t * @@ -803,6 +878,7 @@ map_traffic_class_command_fn (vlib_main_t * vm, unformat_input_t _line_input, *line_input = &_line_input; map_main_t *mm = &map_main; u32 tc = 0; + clib_error_t *error = NULL; mm->tc_copy = false; @@ -817,12 +893,17 @@ map_traffic_class_command_fn (vlib_main_t * vm, else if (unformat (line_input, "%x", &tc)) mm->tc = tc & 0xff; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } + +done: unformat_free (line_input); - return 0; + return error; } static u8 * @@ -922,6 +1003,7 @@ show_map_domain_command_fn (vlib_main_t * vm, unformat_input_t * input, map_domain_t *d; bool counters = false; u32 map_domain_index = ~0; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -934,10 +1016,12 @@ show_map_domain_command_fn (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "index %d", &map_domain_index)) ; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); if (pool_elts (mm->domains) == 0) vlib_cli_output (vm, "No MAP domains are configured..."); @@ -952,15 +1036,19 @@ show_map_domain_command_fn (vlib_main_t * vm, unformat_input_t * input, { if (pool_is_free_index (mm->domains, map_domain_index)) { - return clib_error_return (0, "MAP domain does not exists %d", - map_domain_index); + error = clib_error_return (0, "MAP domain does not exists %d", + map_domain_index); + goto done; } d = pool_elt_at_index (mm->domains, map_domain_index); vlib_cli_output (vm, "%U", format_map_domain, d, counters); } - return 0; +done: + unformat_free (line_input); + + return error; } static clib_error_t * diff --git a/src/vnet/mpls/mpls.c b/src/vnet/mpls/mpls.c index 0e610e17..7ae4aa00 100644 --- a/src/vnet/mpls/mpls.c +++ b/src/vnet/mpls/mpls.c @@ -470,6 +470,8 @@ vnet_mpls_local_label (vlib_main_t * vm, } done: + unformat_free (line_input); + return error; } diff --git a/src/vnet/mpls/mpls_tunnel.c b/src/vnet/mpls/mpls_tunnel.c index 8d1e30a3..e488271d 100644 --- a/src/vnet/mpls/mpls_tunnel.c +++ b/src/vnet/mpls/mpls_tunnel.c @@ -535,6 +535,7 @@ vnet_create_mpls_tunnel_command_fn (vlib_main_t * vm, fib_route_path_t rpath, *rpaths = NULL; mpls_label_t out_label = MPLS_LABEL_INVALID, *labels = NULL; u32 sw_if_index; + clib_error_t *error = NULL; memset(&rpath, 0, sizeof(rpath)); @@ -595,8 +596,11 @@ vnet_create_mpls_tunnel_command_fn (vlib_main_t * vm, else if (unformat (line_input, "l2-only")) l2_only = 1; else - return clib_error_return (0, "unknown input '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "unknown input '%U'", + format_unformat_error, line_input); + goto done; + } } if (is_del) @@ -606,17 +610,22 @@ vnet_create_mpls_tunnel_command_fn (vlib_main_t * vm, else { if (0 == vec_len(labels)) - return clib_error_return (0, "No Output Labels '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "No Output Labels '%U'", + format_unformat_error, line_input); + goto done; + } vec_add1(rpaths, rpath); vnet_mpls_tunnel_add(rpaths, labels, l2_only, &sw_if_index); } +done: vec_free(labels); vec_free(rpaths); + unformat_free (line_input); - return (NULL); + return error; } /*? diff --git a/src/vnet/pg/cli.c b/src/vnet/pg/cli.c index f5896b43..3c249a7b 100644 --- a/src/vnet/pg/cli.c +++ b/src/vnet/pg/cli.c @@ -547,21 +547,30 @@ pg_capture_cmd_fn (vlib_main_t * vm, else { error = clib_error_create ("unknown input `%U'", - format_unformat_error, input); - return error; + format_unformat_error, line_input); + goto done; } } if (!hi) - return clib_error_return (0, "Please specify interface name"); + { + error = clib_error_return (0, "Please specify interface name"); + goto done; + } if (hi->dev_class_index != pg_dev_class.index) - return clib_error_return (0, "Please specify packet-generator interface"); + { + error = + clib_error_return (0, "Please specify packet-generator interface"); + goto done; + } if (!pcap_file_name && is_disable == 0) - return clib_error_return (0, "Please specify pcap file name"); + { + error = clib_error_return (0, "Please specify pcap file name"); + goto done; + } - unformat_free (line_input); pg_capture_args_t _a, *a = &_a; @@ -572,6 +581,10 @@ pg_capture_cmd_fn (vlib_main_t * vm, a->count = count; error = pg_capture (a); + +done: + unformat_free (line_input); + return error; } @@ -590,6 +603,7 @@ create_pg_if_cmd_fn (vlib_main_t * vm, pg_main_t *pg = &pg_main; unformat_input_t _line_input, *line_input = &_line_input; u32 if_id; + clib_error_t *error = NULL; if (!unformat_user (input, unformat_line_input, line_input)) return 0; @@ -600,14 +614,19 @@ create_pg_if_cmd_fn (vlib_main_t * vm, ; else - return clib_error_create ("unknown input `%U'", - format_unformat_error, input); + { + error = clib_error_create ("unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } + pg_interface_add_or_get (pg, if_id); + +done: unformat_free (line_input); - pg_interface_add_or_get (pg, if_id); - return 0; + return error; } /* *INDENT-OFF* */ diff --git a/src/vnet/policer/node_funcs.c b/src/vnet/policer/node_funcs.c index 1f4997ff..457dd09f 100644 --- a/src/vnet/policer/node_funcs.c +++ b/src/vnet/policer/node_funcs.c @@ -447,6 +447,7 @@ test_policer_command_fn (vlib_main_t * vm, int rx_set = 0; int is_add = 1; int is_show = 0; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -468,7 +469,10 @@ test_policer_command_fn (vlib_main_t * vm, } if (rx_set == 0) - return clib_error_return (0, "interface not set"); + { + error = clib_error_return (0, "interface not set"); + goto done; + } if (is_show) { @@ -477,12 +481,13 @@ test_policer_command_fn (vlib_main_t * vm, policer = pool_elt_at_index (pm->policers, pi); vlib_cli_output (vm, "%U", format_policer_instance, policer); - return 0; + goto done; } if (is_add && config_name == 0) { - return clib_error_return (0, "policer config name required"); + error = clib_error_return (0, "policer config name required"); + goto done; } rv = test_policer_add_del (rx_sw_if_index, config_name, is_add); @@ -493,11 +498,15 @@ test_policer_command_fn (vlib_main_t * vm, break; default: - return clib_error_return + error = clib_error_return (0, "WARNING: vnet_vnet_policer_add_del returned %d", rv); + goto done; } - return 0; +done: + unformat_free (line_input); + + return error; } /* *INDENT-OFF* */ diff --git a/src/vnet/policer/policer.c b/src/vnet/policer/policer.c index 290a6af5..cd754e29 100644 --- a/src/vnet/policer/policer.c +++ b/src/vnet/policer/policer.c @@ -413,6 +413,7 @@ configure_policer_command_fn (vlib_main_t * vm, u8 is_add = 1; u8 *name = 0; u32 pi; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -433,13 +434,19 @@ configure_policer_command_fn (vlib_main_t * vm, foreach_config_param #undef _ else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } + error = policer_add_del (vm, name, &c, &pi, is_add); + +done: unformat_free (line_input); - return policer_add_del (vm, name, &c, &pi, is_add); + return error; } /* *INDENT-OFF* */ diff --git a/src/vnet/unix/tapcli.c b/src/vnet/unix/tapcli.c index 48e81b50..25c930c6 100644 --- a/src/vnet/unix/tapcli.c +++ b/src/vnet/unix/tapcli.c @@ -1308,6 +1308,7 @@ tap_connect_command_fn (vlib_main_t * vm, int ip6_address_set = 0; u32 ip4_mask_width = 0; u32 ip6_mask_width = 0; + clib_error_t *error = NULL; if (tm->is_disabled) return clib_error_return (0, "device disabled..."); @@ -1336,12 +1337,18 @@ tap_connect_command_fn (vlib_main_t * vm, else if (unformat (line_input, "%s", &intfc_name)) ; else - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } } if (intfc_name == 0) - return clib_error_return (0, "interface name must be specified"); + { + error = clib_error_return (0, "interface name must be specified"); + goto done; + } memset (ap, 0, sizeof (*ap)); @@ -1367,48 +1374,64 @@ tap_connect_command_fn (vlib_main_t * vm, switch (rv) { case VNET_API_ERROR_SYSCALL_ERROR_1: - return clib_error_return (0, "Couldn't open /dev/net/tun"); + error = clib_error_return (0, "Couldn't open /dev/net/tun"); + goto done; case VNET_API_ERROR_SYSCALL_ERROR_2: - return clib_error_return (0, "Error setting flags on '%s'", intfc_name); - + error = clib_error_return (0, "Error setting flags on '%s'", intfc_name); + goto done; + case VNET_API_ERROR_SYSCALL_ERROR_3: - return clib_error_return (0, "Couldn't open provisioning socket"); + error = clib_error_return (0, "Couldn't open provisioning socket"); + goto done; case VNET_API_ERROR_SYSCALL_ERROR_4: - return clib_error_return (0, "Couldn't get if_index"); + error = clib_error_return (0, "Couldn't get if_index"); + goto done; case VNET_API_ERROR_SYSCALL_ERROR_5: - return clib_error_return (0, "Couldn't bind provisioning socket"); + error = clib_error_return (0, "Couldn't bind provisioning socket"); + goto done; case VNET_API_ERROR_SYSCALL_ERROR_6: - return clib_error_return (0, "Couldn't set device non-blocking flag"); + error = clib_error_return (0, "Couldn't set device non-blocking flag"); + goto done; case VNET_API_ERROR_SYSCALL_ERROR_7: - return clib_error_return (0, "Couldn't set device MTU"); + error = clib_error_return (0, "Couldn't set device MTU"); + goto done; case VNET_API_ERROR_SYSCALL_ERROR_8: - return clib_error_return (0, "Couldn't get interface flags"); + error = clib_error_return (0, "Couldn't get interface flags"); + goto done; case VNET_API_ERROR_SYSCALL_ERROR_9: - return clib_error_return (0, "Couldn't set intfc admin state up"); + error = clib_error_return (0, "Couldn't set intfc admin state up"); + goto done; case VNET_API_ERROR_SYSCALL_ERROR_10: - return clib_error_return (0, "Couldn't set intfc address/mask"); + error = clib_error_return (0, "Couldn't set intfc address/mask"); + goto done; case VNET_API_ERROR_INVALID_REGISTRATION: - return clib_error_return (0, "Invalid registration"); + error = clib_error_return (0, "Invalid registration"); + goto done; case 0: break; default: - return clib_error_return (0, "Unknown error: %d", rv); + error = clib_error_return (0, "Unknown error: %d", rv); + goto done; } vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index); - return 0; + +done: + unformat_free (line_input); + + return error; } VLIB_CLI_COMMAND (tap_connect_command, static) = { diff --git a/src/vnet/vxlan-gpe/vxlan_gpe.c b/src/vnet/vxlan-gpe/vxlan_gpe.c index b97510c4..2cba596f 100644 --- a/src/vnet/vxlan-gpe/vxlan_gpe.c +++ b/src/vnet/vxlan-gpe/vxlan_gpe.c @@ -454,6 +454,7 @@ vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm, u32 tmp; vnet_vxlan_gpe_add_del_tunnel_args_t _a, * a = &_a; u32 sw_if_index; + clib_error_t *error = NULL; /* Get a line of input. */ if (! unformat_user (input, unformat_line_input, line_input)) @@ -494,7 +495,10 @@ vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm, encap_fib_index = ip4_fib_index_from_table_id (tmp); if (encap_fib_index == ~0) - return clib_error_return (0, "nonexistent encap fib id %d", tmp); + { + error = clib_error_return (0, "nonexistent encap fib id %d", tmp); + goto done; + } } else if (unformat (line_input, "decap-vrf-id %d", &tmp)) { @@ -504,7 +508,10 @@ vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm, decap_fib_index = ip4_fib_index_from_table_id (tmp); if (decap_fib_index == ~0) - return clib_error_return (0, "nonexistent decap fib id %d", tmp); + { + error = clib_error_return (0, "nonexistent decap fib id %d", tmp); + goto done; + } } else if (unformat (line_input, "vni %d", &vni)) vni_set = 1; @@ -517,27 +524,43 @@ vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm, else if (unformat(line_input, "next-nsh")) protocol = VXLAN_GPE_PROTOCOL_NSH; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (local_set == 0) - return clib_error_return (0, "tunnel local address not specified"); + { + error = clib_error_return (0, "tunnel local address not specified"); + goto done; + } if (remote_set == 0) - return clib_error_return (0, "tunnel remote address not specified"); + { + error = clib_error_return (0, "tunnel remote address not specified"); + goto done; + } if (ipv4_set && ipv6_set) - return clib_error_return (0, "both IPv4 and IPv6 addresses specified"); + { + error = clib_error_return (0, "both IPv4 and IPv6 addresses specified"); + goto done; + } if ((ipv4_set && memcmp(&local.ip4, &remote.ip4, sizeof(local.ip4)) == 0) || (ipv6_set && memcmp(&local.ip6, &remote.ip6, sizeof(local.ip6)) == 0)) - return clib_error_return (0, "src and dst addresses are identical"); + { + error = clib_error_return (0, "src and dst addresses are identical"); + goto done; + } if (vni_set == 0) - return clib_error_return (0, "vni not specified"); + { + error = clib_error_return (0, "vni not specified"); + goto done; + } memset (a, 0, sizeof (*a)); @@ -558,20 +581,27 @@ vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm, vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index); break; case VNET_API_ERROR_INVALID_DECAP_NEXT: - return clib_error_return (0, "invalid decap-next..."); + error = clib_error_return (0, "invalid decap-next..."); + goto done; case VNET_API_ERROR_TUNNEL_EXIST: - return clib_error_return (0, "tunnel already exists..."); + error = clib_error_return (0, "tunnel already exists..."); + goto done; case VNET_API_ERROR_NO_SUCH_ENTRY: - return clib_error_return (0, "tunnel does not exist..."); + error = clib_error_return (0, "tunnel does not exist..."); + goto done; default: - return clib_error_return + error = clib_error_return (0, "vnet_vxlan_gpe_add_del_tunnel returned %d", rv); + goto done; } - return 0; +done: + unformat_free (line_input); + + return error; } VLIB_CLI_COMMAND (create_vxlan_gpe_tunnel_command, static) = { diff --git a/src/vnet/vxlan/vxlan.c b/src/vnet/vxlan/vxlan.c index 849fc25d..eedc16f8 100644 --- a/src/vnet/vxlan/vxlan.c +++ b/src/vnet/vxlan/vxlan.c @@ -657,6 +657,7 @@ vxlan_add_del_tunnel_command_fn (vlib_main_t * vm, int rv; vnet_vxlan_add_del_tunnel_args_t _a, * a = &_a; u32 tunnel_sw_if_index; + clib_error_t *error = NULL; /* Cant "universally zero init" (={0}) due to GCC bug 53119 */ memset(&src, 0, sizeof src); @@ -715,7 +716,10 @@ vxlan_add_del_tunnel_command_fn (vlib_main_t * vm, { encap_fib_index = fib_table_find (fib_ip_proto (ipv6_set), tmp); if (encap_fib_index == ~0) - return clib_error_return (0, "nonexistent encap-vrf-id %d", tmp); + { + error = clib_error_return (0, "nonexistent encap-vrf-id %d", tmp); + goto done; + } } else if (unformat (line_input, "decap-next %U", unformat_decap_next, &decap_next_index, ipv4_set)) @@ -723,41 +727,72 @@ vxlan_add_del_tunnel_command_fn (vlib_main_t * vm, else if (unformat (line_input, "vni %d", &vni)) { if (vni >> 24) - return clib_error_return (0, "vni %d out of range", vni); + { + error = clib_error_return (0, "vni %d out of range", vni); + goto done; + } } else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } } - unformat_free (line_input); - if (src_set == 0) - return clib_error_return (0, "tunnel src address not specified"); + { + error = clib_error_return (0, "tunnel src address not specified"); + goto done; + } if (dst_set == 0) - return clib_error_return (0, "tunnel dst address not specified"); + { + error = clib_error_return (0, "tunnel dst address not specified"); + goto done; + } if (grp_set && !ip46_address_is_multicast(&dst)) - return clib_error_return (0, "tunnel group address not multicast"); + { + error = clib_error_return (0, "tunnel group address not multicast"); + goto done; + } if (grp_set == 0 && ip46_address_is_multicast(&dst)) - return clib_error_return (0, "dst address must be unicast"); + { + error = clib_error_return (0, "dst address must be unicast"); + goto done; + } if (grp_set && mcast_sw_if_index == ~0) - return clib_error_return (0, "tunnel nonexistent multicast device"); + { + error = clib_error_return (0, "tunnel nonexistent multicast device"); + goto done; + } if (ipv4_set && ipv6_set) - return clib_error_return (0, "both IPv4 and IPv6 addresses specified"); + { + error = clib_error_return (0, "both IPv4 and IPv6 addresses specified"); + goto done; + } if (ip46_address_cmp(&src, &dst) == 0) - return clib_error_return (0, "src and dst addresses are identical"); + { + error = clib_error_return (0, "src and dst addresses are identical"); + goto done; + } if (decap_next_index == ~0) - return clib_error_return (0, "next node not found"); + { + error = clib_error_return (0, "next node not found"); + goto done; + } if (vni == 0) - return clib_error_return (0, "vni not specified"); + { + error = clib_error_return (0, "vni not specified"); + goto done; + } memset (a, 0, sizeof (*a)); @@ -779,17 +814,23 @@ vxlan_add_del_tunnel_command_fn (vlib_main_t * vm, break; case VNET_API_ERROR_TUNNEL_EXIST: - return clib_error_return (0, "tunnel already exists..."); + error = clib_error_return (0, "tunnel already exists..."); + goto done; case VNET_API_ERROR_NO_SUCH_ENTRY: - return clib_error_return (0, "tunnel does not exist..."); + error = clib_error_return (0, "tunnel does not exist..."); + goto done; default: - return clib_error_return + error = clib_error_return (0, "vnet_vxlan_add_del_tunnel returned %d", rv); + goto done; } - return 0; +done: + unformat_free (line_input); + + return error; } /*? @@ -912,6 +953,8 @@ set_ip_vxlan_bypass (u32 is_ip6, vnet_int_vxlan_bypass_mode (sw_if_index, is_ip6, is_enable); done: + unformat_free (line_input); + return error; } diff --git a/src/vpp/app/l2t.c b/src/vpp/app/l2t.c index 45dd2807..e1eda155 100644 --- a/src/vpp/app/l2t.c +++ b/src/vpp/app/l2t.c @@ -254,6 +254,7 @@ l2tp_session_add_command_fn (vlib_main_t * vm, u32 local_session_id = 1, remote_session_id = 1; int our_address_set = 0, client_address_set = 0; int l2_sublayer_present = 0; + clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -290,8 +291,12 @@ l2tp_session_add_command_fn (vlib_main_t * vm, else if (unformat (line_input, "l2-sublayer-present")) l2_sublayer_present = 1; else - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + unformat_free (line_input); + return error; + } } unformat_free (line_input); diff --git a/src/vpp/app/vpe_cli.c b/src/vpp/app/vpe_cli.c index a26bf71f..94bdc84c 100644 --- a/src/vpp/app/vpe_cli.c +++ b/src/vpp/app/vpe_cli.c @@ -36,6 +36,7 @@ virtual_ip_cmd_fn_command_fn (vlib_main_t * vm, mac_addr_t *mac_addrs = 0; u32 sw_if_index; u32 i; + clib_error_t *error = NULL; next_hops = NULL; rpaths = NULL; @@ -49,7 +50,11 @@ virtual_ip_cmd_fn_command_fn (vlib_main_t * vm, if (!unformat (line_input, "%U %U", unformat_ip4_address, &prefix.fp_addr.ip4, unformat_vnet_sw_interface, vnm, &sw_if_index)) - goto barf; + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { @@ -67,13 +72,18 @@ virtual_ip_cmd_fn_command_fn (vlib_main_t * vm, } else { - barf: - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; } } + if (vec_len (mac_addrs) == 0 || vec_len (mac_addrs) != vec_len (next_hops)) - goto barf; + { + error = clib_error_return (0, "unknown input `%U'", + format_unformat_error, line_input); + goto done; + } /* Create / delete special interface route /32's */ @@ -100,10 +110,12 @@ virtual_ip_cmd_fn_command_fn (vlib_main_t * vm, &prefix, FIB_SOURCE_CLI, FIB_ENTRY_FLAG_NONE, rpaths); +done: vec_free (mac_addrs); vec_free (next_hops); + unformat_free (line_input); - return 0; + return error; } /* *INDENT-OFF* */ -- cgit 1.2.3-korg From 59ed490ed7dd7376c3d3acabc4932133a4899d69 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Tue, 21 Mar 2017 11:51:54 +0100 Subject: policer: fix byte ordering in policer_details msg Change-Id: Id53131e8cd32bfd35739a7bd7cdbadf3a9f4d941 Signed-off-by: Marek Gradzki --- src/vat/api_format.c | 4 ++-- src/vnet/policer/policer_api.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/vnet/policer') diff --git a/src/vat/api_format.c b/src/vat/api_format.c index d34a97f6..37b7f93e 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -3630,8 +3630,8 @@ static void vl_api_policer_details_t_handler_json vat_json_object_add_string_copy (node, "name", mp->name); vat_json_object_add_uint (node, "cir", ntohl (mp->cir)); vat_json_object_add_uint (node, "eir", ntohl (mp->eir)); - vat_json_object_add_uint (node, "cb", ntohl (mp->cb)); - vat_json_object_add_uint (node, "eb", ntohl (mp->eb)); + vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb)); + vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb)); vat_json_object_add_string_copy (node, "rate_type", rate_type_str); vat_json_object_add_string_copy (node, "round_type", round_type_str); vat_json_object_add_string_copy (node, "type", type_str); diff --git a/src/vnet/policer/policer_api.c b/src/vnet/policer/policer_api.c index fb5f08b8..67fb9a4e 100644 --- a/src/vnet/policer/policer_api.c +++ b/src/vnet/policer/policer_api.c @@ -105,8 +105,8 @@ send_policer_details (u8 * name, mp->context = context; mp->cir = htonl (config->rb.kbps.cir_kbps); mp->eir = htonl (config->rb.kbps.eir_kbps); - mp->cb = htonl (config->rb.kbps.cb_bytes); - mp->eb = htonl (config->rb.kbps.eb_bytes); + mp->cb = clib_host_to_net_u64 (config->rb.kbps.cb_bytes); + mp->eb = clib_host_to_net_u64 (config->rb.kbps.eb_bytes); mp->rate_type = config->rate_type; mp->round_type = config->rnd_type; mp->type = config->rfc; -- cgit 1.2.3-korg From 8c55b37a2220cc9dc2f16470b77059841d37aa46 Mon Sep 17 00:00:00 2001 From: Marco Varlese Date: Wed, 31 May 2017 14:00:37 +0200 Subject: Fix for gcc7 When building VPP code with gcc7 a warning (threated as error) is encountered and the build fails. This patch addressed the compilation issue. Change-Id: I49af9288a84d91ec8145da07c00aefb5333ec418 Signed-off-by: Marco Varlese --- src/vnet/policer/xlate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/vnet/policer') diff --git a/src/vnet/policer/xlate.c b/src/vnet/policer/xlate.c index 74a6eb23..b1c055ed 100644 --- a/src/vnet/policer/xlate.c +++ b/src/vnet/policer/xlate.c @@ -1316,7 +1316,7 @@ sse2_pol_convert_hw_to_cfg_params (sse2_qos_pol_hw_params_st * hw, } if ((hw->rfc == IPE_RFC_RFC4115) && - !(hw->peak_rate_man << hw->rate_exp) && !(hw->extd_bkt_limit_man)) + (hw->peak_rate_man << hw->rate_exp) == 0 && !(hw->extd_bkt_limit_man)) { /* * For a 1R2C, we set EIR = 0, EB = 0 -- cgit 1.2.3-korg From beb0b2e346c63e21ffe892ae0e04b67bb10fba5e Mon Sep 17 00:00:00 2001 From: John Lo Date: Sat, 22 Jul 2017 00:21:36 -0400 Subject: Improve L2 Input/Output Feature Infrastructure and Usage Simplify L2 output feature infra to unify with L2 input feature infra using the newly improved feature bitmap mechanism. Updated all L2 features to use the more efficient infra functions. Change-Id: If8f463826b0af0717129befe92a27ea8cfc40449 Signed-off-by: John Lo --- src/plugins/acl/fa_node.c | 7 +-- src/vnet/ethernet/arp.c | 8 +-- src/vnet/l2/feat_bitmap.h | 18 +++++- src/vnet/l2/l2_classify.h | 8 +-- src/vnet/l2/l2_efp_filter.c | 54 +++--------------- src/vnet/l2/l2_input.c | 37 ++++++------- src/vnet/l2/l2_input_acl.c | 9 +-- src/vnet/l2/l2_input_classify.c | 22 +++----- src/vnet/l2/l2_input_vtr.c | 35 ++---------- src/vnet/l2/l2_learn.c | 14 +---- src/vnet/l2/l2_output.c | 115 +++++++++++++++++++++++---------------- src/vnet/l2/l2_output.h | 80 +-------------------------- src/vnet/l2/l2_output_acl.c | 24 ++------ src/vnet/l2/l2_output_classify.c | 30 +++------- src/vnet/l2/l2_rw.c | 27 +++------ src/vnet/policer/node_funcs.c | 11 +--- 16 files changed, 160 insertions(+), 339 deletions(-) (limited to 'src/vnet/policer') diff --git a/src/plugins/acl/fa_node.c b/src/plugins/acl/fa_node.c index 0bbc7423..c483044d 100644 --- a/src/plugins/acl/fa_node.c +++ b/src/plugins/acl/fa_node.c @@ -931,7 +931,6 @@ acl_fa_node_fn (vlib_main_t * vm, u32 pkts_acl_permit = 0; u32 pkts_restart_session_timer = 0; u32 trace_bitmap = 0; - u32 feature_bitmap0; acl_main_t *am = &acl_main; fa_5tuple_t fa_5tuple, kv_sess; clib_bihash_kv_40_8_t value_sess; @@ -977,8 +976,6 @@ acl_fa_node_fn (vlib_main_t * vm, sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; else sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; - if (is_l2_path) - feature_bitmap0 = vnet_buffer (b0)->l2.feature_bitmap; /* * Extract the L3/L4 matching info into a 5-tuple structure, @@ -1089,9 +1086,7 @@ acl_fa_node_fn (vlib_main_t * vm, if (action > 0) { if (is_l2_path) - next0 = - feat_bitmap_get_next_node_index (l2_feat_next_node_index, - feature_bitmap0); + next0 = vnet_l2_feature_next (b0, l2_feat_next_node_index, 0); else vnet_feature_next (sw_if_index0, &next0, b0); } diff --git a/src/vnet/ethernet/arp.c b/src/vnet/ethernet/arp.c index df681750..1bce3328 100644 --- a/src/vnet/ethernet/arp.c +++ b/src/vnet/ethernet/arp.c @@ -2291,12 +2291,8 @@ arp_term_l2bd (vlib_main_t * vm, next_l2_feature: { - u32 feature_bitmap0 = - vnet_buffer (p0)->l2.feature_bitmap & ~L2INPUT_FEAT_ARP_TERM; - vnet_buffer (p0)->l2.feature_bitmap = feature_bitmap0; - next0 = - feat_bitmap_get_next_node_index (arp_term_next_node_index, - feature_bitmap0); + next0 = vnet_l2_feature_next (p0, arp_term_next_node_index, + L2INPUT_FEAT_ARP_TERM); vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, n_left_to_next, pi0, next0); diff --git a/src/vnet/l2/feat_bitmap.h b/src/vnet/l2/feat_bitmap.h index c6e02ecc..5940ff7e 100644 --- a/src/vnet/l2/feat_bitmap.h +++ b/src/vnet/l2/feat_bitmap.h @@ -75,8 +75,8 @@ feat_bitmap_init_next_nodes (vlib_main_t * vm, u32 node_index, /* the current gr Return the graph node index for the feature corresponding to the first set bit in the bitmap. */ -always_inline - u32 feat_bitmap_get_next_node_index (u32 * next_nodes, u32 bitmap) +always_inline u32 +feat_bitmap_get_next_node_index (u32 * next_nodes, u32 bitmap) { u32 first_bit; @@ -85,6 +85,20 @@ always_inline return next_nodes[first_bit]; } +/** + Return the graph node index for the feature corresponding to the next + set bit after clearing the current feature bit in the feature_bitmap + of the current packet. +*/ +always_inline u32 +vnet_l2_feature_next (vlib_buffer_t * b, u32 * next_nodes, u32 feat_bit) +{ + vnet_buffer (b)->l2.feature_bitmap &= ~feat_bit; + u32 fb = vnet_buffer (b)->l2.feature_bitmap; + ASSERT (fb != 0); + return feat_bitmap_get_next_node_index (next_nodes, fb); +} + #endif /* included_vnet_l2_feat_bitmap_h */ /* diff --git a/src/vnet/l2/l2_classify.h b/src/vnet/l2/l2_classify.h index 184187ff..100c584a 100644 --- a/src/vnet/l2/l2_classify.h +++ b/src/vnet/l2/l2_classify.h @@ -68,15 +68,13 @@ typedef enum typedef struct _l2_classify_main { - /* Next nodes for each feature */ - u32 feat_next_node_index[32]; + /* Next nodes for L2 input and output features */ + u32 l2_inp_feat_next[32]; + u32 l2_out_feat_next[32]; /* Per-address-family classifier table vectors */ u32 *classify_table_index_by_sw_if_index[L2_INPUT_CLASSIFY_N_TABLES]; - /* Next nodes for features and output interfaces */ - l2_output_next_nodes_st next_nodes; - /* convenience variables */ vlib_main_t *vlib_main; vnet_main_t *vnet_main; diff --git a/src/vnet/l2/l2_efp_filter.c b/src/vnet/l2/l2_efp_filter.c index f9ba8f2f..faf78153 100644 --- a/src/vnet/l2/l2_efp_filter.c +++ b/src/vnet/l2/l2_efp_filter.c @@ -43,9 +43,8 @@ */ typedef struct { - - /* Next nodes for features and output interfaces */ - l2_output_next_nodes_st next_nodes; + /* Next nodes for L2 output features */ + u32 l2_out_feat_next[32]; /* convenience variables */ vlib_main_t *vlib_main; @@ -180,11 +179,6 @@ l2_efp_filter_node_fn (vlib_main_t * vm, vlib_node_t *n = vlib_get_node (vm, l2_efp_filter_node.index); u32 node_counter_base_index = n->error_heap_index; vlib_error_main_t *em = &vm->error_main; - u32 cached_sw_if_index = ~0; - u32 cached_next_index = ~0; - - /* invalidate cache to begin with */ - cached_sw_if_index = ~0; from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; /* number of packets to process */ @@ -203,7 +197,6 @@ l2_efp_filter_node_fn (vlib_main_t * vm, vlib_buffer_t *b0, *b1; u32 next0, next1; u32 sw_if_index0, sw_if_index1; - u32 feature_bitmap0, feature_bitmap1; u16 first_ethertype0, first_ethertype1; u16 outer_id0, inner_id0, outer_id1, inner_id1; u32 match_flags0, match_flags1; @@ -267,29 +260,11 @@ l2_efp_filter_node_fn (vlib_main_t * vm, em->counters[node_counter_base_index + L2_EFP_FILTER_ERROR_L2_EFP_FILTER] += 2; - /* Remove ourself from the feature bitmap */ - feature_bitmap0 = - vnet_buffer (b0)->l2.feature_bitmap & ~L2OUTPUT_FEAT_EFP_FILTER; - feature_bitmap1 = - vnet_buffer (b1)->l2.feature_bitmap & ~L2OUTPUT_FEAT_EFP_FILTER; - /* Determine next node */ - l2_output_dispatch (msm->vlib_main, - msm->vnet_main, - node, - l2_efp_filter_node.index, - &cached_sw_if_index, - &cached_next_index, - &msm->next_nodes, - b0, sw_if_index0, feature_bitmap0, &next0); - l2_output_dispatch (msm->vlib_main, - msm->vnet_main, - node, - l2_efp_filter_node.index, - &cached_sw_if_index, - &cached_next_index, - &msm->next_nodes, - b1, sw_if_index1, feature_bitmap1, &next1); + next0 = vnet_l2_feature_next (b0, msm->l2_out_feat_next, + L2OUTPUT_FEAT_EFP_FILTER); + next1 = vnet_l2_feature_next (b1, msm->l2_out_feat_next, + L2OUTPUT_FEAT_EFP_FILTER); /* perform the efp filter check on two packets */ @@ -394,7 +369,6 @@ l2_efp_filter_node_fn (vlib_main_t * vm, vlib_buffer_t *b0; u32 next0; u32 sw_if_index0; - u32 feature_bitmap0; u16 first_ethertype0; u16 outer_id0, inner_id0; u32 match_flags0; @@ -422,19 +396,9 @@ l2_efp_filter_node_fn (vlib_main_t * vm, em->counters[node_counter_base_index + L2_EFP_FILTER_ERROR_L2_EFP_FILTER] += 1; - /* Remove ourself from the feature bitmap */ - feature_bitmap0 = - vnet_buffer (b0)->l2.feature_bitmap & ~L2OUTPUT_FEAT_EFP_FILTER; - /* Determine next node */ - l2_output_dispatch (msm->vlib_main, - msm->vnet_main, - node, - l2_efp_filter_node.index, - &cached_sw_if_index, - &cached_next_index, - &msm->next_nodes, - b0, sw_if_index0, feature_bitmap0, &next0); + next0 = vnet_l2_feature_next (b0, msm->l2_out_feat_next, + L2OUTPUT_FEAT_EFP_FILTER); /* perform the efp filter check on one packet */ @@ -528,7 +492,7 @@ VLIB_NODE_FUNCTION_MULTIARCH (l2_efp_filter_node, l2_efp_filter_node_fn) l2_efp_filter_node.index, L2OUTPUT_N_FEAT, l2output_get_feat_names (), - mp->next_nodes.feat_next_node_index); + mp->l2_out_feat_next); return 0; } diff --git a/src/vnet/l2/l2_input.c b/src/vnet/l2/l2_input.c index aa156213..26c832ad 100644 --- a/src/vnet/l2/l2_input.c +++ b/src/vnet/l2/l2_input.c @@ -115,10 +115,7 @@ typedef enum static_always_inline void -classify_and_dispatch (vlib_main_t * vm, - vlib_node_runtime_t * node, - u32 thread_index, - l2input_main_t * msm, vlib_buffer_t * b0, u32 * next0) +classify_and_dispatch (l2input_main_t * msm, vlib_buffer_t * b0, u32 * next0) { /* * Load L2 input feature struct @@ -187,12 +184,7 @@ classify_and_dispatch (vlib_main_t * vm, } - if (config->xconnect) - { - /* Set the output interface */ - vnet_buffer (b0)->sw_if_index[VLIB_TX] = config->output_sw_if_index; - } - else + if (config->bridge) { /* Do bridge-domain processing */ bd_index0 = config->bd_index; @@ -220,6 +212,13 @@ classify_and_dispatch (vlib_main_t * vm, */ feat_mask = feat_mask & bd_config->feature_bitmap; } + else if (config->xconnect) + { + /* Set the output interface */ + vnet_buffer (b0)->sw_if_index[VLIB_TX] = config->output_sw_if_index; + } + else + feat_mask = L2INPUT_FEAT_DROP; /* mask out features from bitmap using packet type and bd config */ feature_bitmap = config->feature_bitmap & feat_mask; @@ -240,7 +239,6 @@ l2input_node_inline (vlib_main_t * vm, u32 n_left_from, *from, *to_next; l2input_next_t next_index; l2input_main_t *msm = &l2input_main; - u32 thread_index = vlib_get_thread_index (); from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; /* number of packets to process */ @@ -353,10 +351,10 @@ l2input_node_inline (vlib_main_t * vm, vlib_node_increment_counter (vm, l2input_node.index, L2INPUT_ERROR_L2INPUT, 4); - classify_and_dispatch (vm, node, thread_index, msm, b0, &next0); - classify_and_dispatch (vm, node, thread_index, msm, b1, &next1); - classify_and_dispatch (vm, node, thread_index, msm, b2, &next2); - classify_and_dispatch (vm, node, thread_index, msm, b3, &next3); + classify_and_dispatch (msm, b0, &next0); + classify_and_dispatch (msm, b1, &next1); + classify_and_dispatch (msm, b2, &next2); + classify_and_dispatch (msm, b3, &next3); /* verify speculative enqueues, maybe switch current next frame */ /* if next0==next1==next_index then nothing special needs to be done */ @@ -396,7 +394,7 @@ l2input_node_inline (vlib_main_t * vm, vlib_node_increment_counter (vm, l2input_node.index, L2INPUT_ERROR_L2INPUT, 1); - classify_and_dispatch (vm, node, thread_index, msm, b0, &next0); + classify_and_dispatch (msm, b0, &next0); /* verify speculative enqueue, maybe switch current next frame */ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, @@ -574,8 +572,8 @@ set_int_l2_mode (vlib_main_t * vm, vnet_main_t * vnet_main, /* */ } /* Make sure vector is big enough */ - vec_validate_init_empty (l2om->next_nodes.output_node_index_vec, - sw_if_index, L2OUTPUT_NEXT_DROP); + vec_validate_init_empty (l2om->output_node_index_vec, sw_if_index, + L2OUTPUT_NEXT_DROP); /* Initialize the l2-input configuration for the interface */ if (mode == MODE_L3) @@ -594,8 +592,7 @@ set_int_l2_mode (vlib_main_t * vm, vnet_main_t * vnet_main, /* */ /* Make sure any L2-output packet to this interface now in L3 mode is * dropped. This may happen if L2 FIB MAC entry is stale */ - l2om->next_nodes.output_node_index_vec[sw_if_index] = - L2OUTPUT_NEXT_BAD_INTF; + l2om->output_node_index_vec[sw_if_index] = L2OUTPUT_NEXT_BAD_INTF; } else { diff --git a/src/vnet/l2/l2_input_acl.c b/src/vnet/l2/l2_input_acl.c index 104fcd15..84030888 100644 --- a/src/vnet/l2/l2_input_acl.c +++ b/src/vnet/l2/l2_input_acl.c @@ -269,14 +269,11 @@ l2_inacl_node_fn (vlib_main_t * vm, e0 = 0; t0 = 0; - /* Feature bitmap update */ - vnet_buffer (b0)->l2.feature_bitmap &= ~L2INPUT_FEAT_ACL; - vnet_buffer (b0)->l2_classify.opaque_index = ~0; + /* Determine the next node */ - next0 = feat_bitmap_get_next_node_index (msm->feat_next_node_index, - vnet_buffer (b0)-> - l2.feature_bitmap); + next0 = vnet_l2_feature_next (b0, msm->feat_next_node_index, + L2INPUT_FEAT_ACL); if (PREDICT_TRUE (table_index0 != ~0)) { diff --git a/src/vnet/l2/l2_input_classify.c b/src/vnet/l2/l2_input_classify.c index 485b9abd..ee8042a0 100644 --- a/src/vnet/l2/l2_input_classify.c +++ b/src/vnet/l2/l2_input_classify.c @@ -152,7 +152,6 @@ l2_input_classify_node_fn (vlib_main_t * vm, vnet_classify_main_t *vcm = cm->vnet_classify_main; l2_input_classify_runtime_t *rt = (l2_input_classify_runtime_t *) node->runtime_data; - u32 feature_bitmap; u32 hits = 0; u32 misses = 0; u32 chain_hits = 0; @@ -354,13 +353,6 @@ l2_input_classify_node_fn (vlib_main_t * vm, e0 = 0; vnet_buffer (b0)->l2_classify.opaque_index = ~0; - /* Remove ourself from the feature bitmap */ - feature_bitmap = vnet_buffer (b0)->l2.feature_bitmap - & ~L2INPUT_FEAT_INPUT_CLASSIFY; - - /* save for next feature graph nodes */ - vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap; - if (PREDICT_TRUE (table_index0 != ~0)) { hash0 = vnet_buffer (b0)->l2_classify.hash; @@ -412,13 +404,13 @@ l2_input_classify_node_fn (vlib_main_t * vm, if (PREDICT_FALSE (next0 == 0)) b0->error = node->errors[L2_INPUT_CLASSIFY_ERROR_DROP]; + /* Determine the next node and remove ourself from bitmap */ if (PREDICT_TRUE (next0 == ~0)) - { - // Determine the next node - next0 = - feat_bitmap_get_next_node_index (cm->feat_next_node_index, - feature_bitmap); - } + next0 = vnet_l2_feature_next (b0, cm->l2_inp_feat_next, + L2INPUT_FEAT_INPUT_CLASSIFY); + else + vnet_buffer (b0)->l2.feature_bitmap &= + ~L2INPUT_FEAT_INPUT_CLASSIFY; if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && (b0->flags & VLIB_BUFFER_IS_TRACED))) @@ -496,7 +488,7 @@ l2_input_classify_init (vlib_main_t * vm) l2_input_classify_node.index, L2INPUT_N_FEAT, l2input_get_feat_names (), - cm->feat_next_node_index); + cm->l2_inp_feat_next); rt->l2cm = cm; rt->vcm = cm->vnet_classify_main; diff --git a/src/vnet/l2/l2_input_vtr.c b/src/vnet/l2/l2_input_vtr.c index ded23095..9470752f 100644 --- a/src/vnet/l2/l2_input_vtr.c +++ b/src/vnet/l2/l2_input_vtr.c @@ -111,7 +111,6 @@ l2_invtr_node_fn (vlib_main_t * vm, vlib_buffer_t *b0, *b1; u32 next0, next1; u32 sw_if_index0, sw_if_index1; - u32 feature_bitmap0, feature_bitmap1; /* Prefetch next iteration. */ { @@ -160,23 +159,11 @@ l2_invtr_node_fn (vlib_main_t * vm, sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX]; - /* process 2 packets */ - - /* Remove ourself from the feature bitmap */ - feature_bitmap0 = - vnet_buffer (b0)->l2.feature_bitmap & ~L2INPUT_FEAT_VTR; - feature_bitmap1 = - vnet_buffer (b1)->l2.feature_bitmap & ~L2INPUT_FEAT_VTR; - - /* save for next feature graph nodes */ - vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap0; - vnet_buffer (b1)->l2.feature_bitmap = feature_bitmap1; - /* Determine the next node */ - next0 = feat_bitmap_get_next_node_index (msm->feat_next_node_index, - feature_bitmap0); - next1 = feat_bitmap_get_next_node_index (msm->feat_next_node_index, - feature_bitmap1); + next0 = vnet_l2_feature_next (b0, msm->feat_next_node_index, + L2INPUT_FEAT_VTR); + next1 = vnet_l2_feature_next (b1, msm->feat_next_node_index, + L2INPUT_FEAT_VTR); l2_output_config_t *config0; l2_output_config_t *config1; @@ -264,7 +251,6 @@ l2_invtr_node_fn (vlib_main_t * vm, vlib_buffer_t *b0; u32 next0; u32 sw_if_index0; - u32 feature_bitmap0; /* speculatively enqueue b0 to the current next frame */ bi0 = from[0]; @@ -278,18 +264,9 @@ l2_invtr_node_fn (vlib_main_t * vm, sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; - /* process 1 packet */ - - /* Remove ourself from the feature bitmap */ - feature_bitmap0 = - vnet_buffer (b0)->l2.feature_bitmap & ~L2INPUT_FEAT_VTR; - - /* save for next feature graph nodes */ - vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap0; - /* Determine the next node */ - next0 = feat_bitmap_get_next_node_index (msm->feat_next_node_index, - feature_bitmap0); + next0 = vnet_l2_feature_next (b0, msm->feat_next_node_index, + L2INPUT_FEAT_VTR); l2_output_config_t *config0; config0 = vec_elt_at_index (l2output_main.configs, sw_if_index0); diff --git a/src/vnet/l2/l2_learn.c b/src/vnet/l2/l2_learn.c index b9904d3e..65406292 100644 --- a/src/vnet/l2/l2_learn.c +++ b/src/vnet/l2/l2_learn.c @@ -116,19 +116,9 @@ l2learn_process (vlib_node_runtime_t * node, u32 * bucket0, l2fib_entry_result_t * result0, u32 * next0, u8 timestamp) { - u32 feature_bitmap; - /* Set up the default next node (typically L2FWD) */ - - /* Remove ourself from the feature bitmap */ - feature_bitmap = vnet_buffer (b0)->l2.feature_bitmap & ~L2INPUT_FEAT_LEARN; - - /* Save for next feature graph nodes */ - vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap; - - /* Determine the next node */ - *next0 = feat_bitmap_get_next_node_index (msm->feat_next_node_index, - feature_bitmap); + *next0 = vnet_l2_feature_next (b0, msm->feat_next_node_index, + L2INPUT_FEAT_LEARN); /* Check mac table lookup result */ if (PREDICT_TRUE (result0->fields.sw_if_index == sw_if_index0)) diff --git a/src/vnet/l2/l2_output.c b/src/vnet/l2/l2_output.c index 51d5e145..b3537a35 100644 --- a/src/vnet/l2/l2_output.c +++ b/src/vnet/l2/l2_output.c @@ -98,6 +98,57 @@ split_horizon_violation (u8 shg1, u8 shg2) } } +/** Determine the next L2 node based on the output feature bitmap */ +static_always_inline void +l2_output_dispatch (vlib_buffer_t * b0, vlib_node_runtime_t * node, + u32 * cached_sw_if_index, u32 * cached_next_index, + u32 sw_if_index, u32 feature_bitmap, u32 * next0) +{ + /* + * The output feature bitmap always have at least the L2 output bit set + * for a normal L2 interface (or 0 if the interface is changed from L2 + * to L3 mode). So if the feature bitmap is 0 or just have L2 output bits set, + * we know there is no more feature and will just output packets on interface. + * Otherwise, get the index of the next feature node. + */ + if (PREDICT_FALSE ((feature_bitmap & ~L2OUTPUT_FEAT_OUTPUT) != 0)) + { + /* Save bitmap for the next feature graph nodes */ + vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap; + + /* Determine the next node */ + *next0 = + feat_bitmap_get_next_node_index (l2output_main.l2_out_feat_next, + feature_bitmap); + } + else + { + /* + * There are no features. Send packet to TX node for sw_if_index0 + * This is a little tricky in that the output interface next node indexes + * are not precomputed at init time. + */ + + if (sw_if_index == *cached_sw_if_index) + { + /* We hit in the one-entry cache. Use it. */ + *next0 = *cached_next_index; + } + else + { + /* Look up the output TX node for the sw_if_index */ + *next0 = vec_elt (l2output_main.output_node_index_vec, sw_if_index); + + if (PREDICT_FALSE (*next0 == L2OUTPUT_NEXT_DROP)) + b0->error = node->errors[L2OUTPUT_ERROR_MAPPING_DROP]; + + /* Update the one-entry cache */ + *cached_sw_if_index = sw_if_index; + *cached_next_index = *next0; + } + } +} + static_always_inline void l2output_vtr (vlib_node_runtime_t * node, l2_output_config_t * config, u32 feature_bitmap, vlib_buffer_t * b, u32 * next) @@ -239,41 +290,18 @@ l2output_node_inline (vlib_main_t * vm, vlib_node_runtime_t * node, feature_bitmap3 = config3->feature_bitmap; /* Determine next node */ - l2_output_dispatch (msm->vlib_main, - msm->vnet_main, - node, - l2output_node.index, - &cached_sw_if_index, - &cached_next_index, - &msm->next_nodes, - b0, sw_if_index0, feature_bitmap0, &next0); - - l2_output_dispatch (msm->vlib_main, - msm->vnet_main, - node, - l2output_node.index, - &cached_sw_if_index, - &cached_next_index, - &msm->next_nodes, - b1, sw_if_index1, feature_bitmap1, &next1); - - l2_output_dispatch (msm->vlib_main, - msm->vnet_main, - node, - l2output_node.index, - &cached_sw_if_index, - &cached_next_index, - &msm->next_nodes, - b2, sw_if_index2, feature_bitmap2, &next2); - - l2_output_dispatch (msm->vlib_main, - msm->vnet_main, - node, - l2output_node.index, - &cached_sw_if_index, - &cached_next_index, - &msm->next_nodes, - b3, sw_if_index3, feature_bitmap3, &next3); + l2_output_dispatch (b0, node, &cached_sw_if_index, + &cached_next_index, sw_if_index0, + feature_bitmap0, &next0); + l2_output_dispatch (b1, node, &cached_sw_if_index, + &cached_next_index, sw_if_index1, + feature_bitmap1, &next1); + l2_output_dispatch (b2, node, &cached_sw_if_index, + &cached_next_index, sw_if_index2, + feature_bitmap2, &next2); + l2_output_dispatch (b3, node, &cached_sw_if_index, + &cached_next_index, sw_if_index3, + feature_bitmap3, &next3); l2output_vtr (node, config0, feature_bitmap0, b0, &next0); l2output_vtr (node, config1, feature_bitmap1, b1, &next1); @@ -401,14 +429,9 @@ l2output_node_inline (vlib_main_t * vm, vlib_node_runtime_t * node, feature_bitmap0 = config0->feature_bitmap; /* Determine next node */ - l2_output_dispatch (msm->vlib_main, - msm->vnet_main, - node, - l2output_node.index, - &cached_sw_if_index, - &cached_next_index, - &msm->next_nodes, - b0, sw_if_index0, feature_bitmap0, &next0); + l2_output_dispatch (b0, node, &cached_sw_if_index, + &cached_next_index, sw_if_index0, + feature_bitmap0, &next0); l2output_vtr (node, config0, feature_bitmap0, b0, &next0); @@ -598,10 +621,10 @@ VLIB_NODE_FUNCTION_MULTIARCH (l2output_node, l2output_node_fn) l2output_node.index, L2OUTPUT_N_FEAT, l2output_get_feat_names (), - mp->next_nodes.feat_next_node_index); + mp->l2_out_feat_next); /* Initialize the output node mapping table */ - vec_validate_init_empty (mp->next_nodes.output_node_index_vec, 100, + vec_validate_init_empty (mp->output_node_index_vec, 100, L2OUTPUT_NEXT_DROP); return 0; @@ -621,7 +644,7 @@ l2output_create_output_node_mapping (vlib_main_t * vlib_main, /* dynamically create graph node arc */ u32 next = vlib_node_add_next (vlib_main, l2output_node.index, hw0->output_node_index); - l2output_main.next_nodes.output_node_index_vec[sw_if_index] = next; + l2output_main.output_node_index_vec[sw_if_index] = next; } /* Get a pointer to the config for the given interface */ diff --git a/src/vnet/l2/l2_output.h b/src/vnet/l2/l2_output.h index 82cefd2c..6da3e303 100644 --- a/src/vnet/l2/l2_output.h +++ b/src/vnet/l2/l2_output.h @@ -52,11 +52,6 @@ typedef struct } l2_output_config_t; - -/* - * The set of next nodes for features and interface output. - * Each output feature node should include this. - */ typedef struct { /* @@ -70,15 +65,7 @@ typedef struct * array of next node index for each output feature, indexed * by l2output_feat_t. Used to determine next feature node. */ - u32 feat_next_node_index[32]; - -} l2_output_next_nodes_st; - - -typedef struct -{ - /* Next nodes for features and output interfaces */ - l2_output_next_nodes_st next_nodes; + u32 l2_out_feat_next[32]; /* config vector indexed by sw_if_index */ l2_output_config_t *configs; @@ -163,71 +150,6 @@ void l2output_create_output_node_mapping (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_index); -/** Determine the next L2 node based on the output feature bitmap */ -always_inline void -l2_output_dispatch (vlib_main_t * vlib_main, - vnet_main_t * vnet_main, - vlib_node_runtime_t * node, - u32 node_index, - u32 * cached_sw_if_index, - u32 * cached_next_index, - l2_output_next_nodes_st * next_nodes, - vlib_buffer_t * b0, - u32 sw_if_index, u32 feature_bitmap, u32 * next0) -{ - /* - * The output feature bitmap always have at least the output feature bit set - * for a normal L2 interface (or all 0's if the interface is changed from L2 - * to L3 mode). So if next_nodes specified is that from the l2-output node and - * the bitmap is all clear except output feature bit, we know there is no more - * feature and will fall through to output packet. If next_nodes is from a L2 - * output feature node (and not l2-output), we always want to get the node for - * the next L2 output feature, including the last feature being interface- - * output node to output packet. - */ - if ((next_nodes != &l2output_main.next_nodes) - || ((feature_bitmap & ~L2OUTPUT_FEAT_OUTPUT) != 0)) - { - /* There are some features to execute */ - ASSERT (feature_bitmap != 0); - - /* Save bitmap for the next feature graph nodes */ - vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap; - - /* Determine the next node */ - *next0 = - feat_bitmap_get_next_node_index (next_nodes->feat_next_node_index, - feature_bitmap); - } - else - { - /* - * There are no features. Send packet to TX node for sw_if_index0 - * This is a little tricky in that the output interface next node indexes - * are not precomputed at init time. - */ - - if (sw_if_index == *cached_sw_if_index) - { - /* We hit in the one-entry cache. Use it. */ - *next0 = *cached_next_index; - } - else - { - /* Look up the output TX node for the sw_if_index */ - *next0 = vec_elt (l2output_main.next_nodes.output_node_index_vec, - sw_if_index); - - if (*next0 == L2OUTPUT_NEXT_DROP) - b0->error = node->errors[L2OUTPUT_ERROR_MAPPING_DROP]; - - /* Update the one-entry cache */ - *cached_sw_if_index = sw_if_index; - *cached_next_index = *next0; - } - } -} - /** Get a pointer to the config for the given interface */ l2_output_config_t *l2output_intf_config (u32 sw_if_index); diff --git a/src/vnet/l2/l2_output_acl.c b/src/vnet/l2/l2_output_acl.c index 1d1971a5..7d051326 100644 --- a/src/vnet/l2/l2_output_acl.c +++ b/src/vnet/l2/l2_output_acl.c @@ -34,8 +34,8 @@ typedef struct { - /* Next nodes for features and output interfaces */ - l2_output_next_nodes_st next_nodes; + /* Next nodes for L2 output features */ + u32 l2_out_feat_next[32]; /* convenience variables */ vlib_main_t *vlib_main; @@ -108,8 +108,6 @@ l2_outacl_node_fn (vlib_main_t * vm, vlib_node_t *n = vlib_get_node (vm, l2_outacl_node.index); u32 node_counter_base_index = n->error_heap_index; vlib_error_main_t *em = &vm->error_main; - u32 cached_sw_if_index = (u32) ~ 0; - u32 cached_next_index = (u32) ~ 0; from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; /* number of packets to process */ @@ -201,7 +199,6 @@ l2_outacl_node_fn (vlib_main_t * vm, u32 next0; u32 sw_if_index0; ethernet_header_t *h0; - u32 feature_bitmap0; /* speculatively enqueue b0 to the current next frame */ bi0 = from[0]; @@ -234,20 +231,9 @@ l2_outacl_node_fn (vlib_main_t * vm, * Dummy for now, just go to next feature node */ - - /* Remove ourself from the feature bitmap */ - feature_bitmap0 = - vnet_buffer (b0)->l2.feature_bitmap & ~L2OUTPUT_FEAT_ACL; - /* Determine next node */ - l2_output_dispatch (msm->vlib_main, - msm->vnet_main, - node, - l2_outacl_node.index, - &cached_sw_if_index, - &cached_next_index, - &msm->next_nodes, - b0, sw_if_index0, feature_bitmap0, &next0); + next0 = vnet_l2_feature_next (b0, msm->l2_out_feat_next, + L2OUTPUT_FEAT_ACL); /* verify speculative enqueue, maybe switch current next frame */ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, @@ -295,7 +281,7 @@ VLIB_NODE_FUNCTION_MULTIARCH (l2_outacl_node, l2_outacl_node_fn) l2_outacl_node.index, L2OUTPUT_N_FEAT, l2output_get_feat_names (), - mp->next_nodes.feat_next_node_index); + mp->l2_out_feat_next); return 0; } diff --git a/src/vnet/l2/l2_output_classify.c b/src/vnet/l2/l2_output_classify.c index 869b0656..a49abec2 100644 --- a/src/vnet/l2/l2_output_classify.c +++ b/src/vnet/l2/l2_output_classify.c @@ -144,14 +144,11 @@ l2_output_classify_node_fn (vlib_main_t * vm, vnet_classify_main_t *vcm = cm->vnet_classify_main; l2_output_classify_runtime_t *rt = (l2_output_classify_runtime_t *) node->runtime_data; - u32 feature_bitmap0; u32 hits = 0; u32 misses = 0; u32 chain_hits = 0; f64 now; u32 n_next_nodes; - u32 cached_sw_if_index = (u32) ~ 0; - u32 cached_next_index = (u32) ~ 0; u32 sw_if_index0; n_next_nodes = node->n_next_nodes; @@ -347,12 +344,6 @@ l2_output_classify_node_fn (vlib_main_t * vm, table_index0 = vnet_buffer (b0)->l2_classify.table_index; e0 = 0; vnet_buffer (b0)->l2_classify.opaque_index = ~0; - /* Remove ourself from the feature bitmap */ - feature_bitmap0 = vnet_buffer (b0)->l2.feature_bitmap - & ~L2OUTPUT_FEAT_OUTPUT_CLASSIFY; - - /* save for next feature graph nodes */ - vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap0; if (PREDICT_TRUE (table_index0 != ~0)) { @@ -405,20 +396,13 @@ l2_output_classify_node_fn (vlib_main_t * vm, if (PREDICT_FALSE (next0 == 0)) b0->error = node->errors[L2_OUTPUT_CLASSIFY_ERROR_DROP]; + /* Determine the next node and remove ourself from bitmap */ if (PREDICT_FALSE (next0 == ~0)) - { - sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; - - /* Determine next node */ - l2_output_dispatch (cm->vlib_main, - cm->vnet_main, - node, - l2_output_classify_node.index, - &cached_sw_if_index, - &cached_next_index, - &cm->next_nodes, - b0, sw_if_index0, feature_bitmap0, &next0); - } + next0 = vnet_l2_feature_next (b0, cm->l2_out_feat_next, + L2OUTPUT_FEAT_OUTPUT_CLASSIFY); + else + vnet_buffer (b0)->l2.feature_bitmap &= + ~L2OUTPUT_FEAT_OUTPUT_CLASSIFY; if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && (b0->flags & VLIB_BUFFER_IS_TRACED))) @@ -493,7 +477,7 @@ l2_output_classify_init (vlib_main_t * vm) l2_output_classify_node.index, L2OUTPUT_N_FEAT, l2output_get_feat_names (), - cm->next_nodes.feat_next_node_index); + cm->l2_out_feat_next); rt->l2cm = cm; rt->vcm = cm->vnet_classify_main; diff --git a/src/vnet/l2/l2_rw.c b/src/vnet/l2/l2_rw.c index c54509d0..fec04774 100644 --- a/src/vnet/l2/l2_rw.c +++ b/src/vnet/l2/l2_rw.c @@ -179,8 +179,8 @@ l2_rw_node_fn (vlib_main_t * vm, while (n_left_from >= 4 && n_left_to_next >= 2) { - u32 bi0, next0, sw_if_index0, feature_bitmap0, rwe_index0; - u32 bi1, next1, sw_if_index1, feature_bitmap1, rwe_index1; + u32 bi0, next0, sw_if_index0, rwe_index0; + u32 bi1, next1, sw_if_index1, rwe_index1; vlib_buffer_t *b0, *b1; ethernet_header_t *h0, *h1; l2_rw_config_t *config0, *config1; @@ -273,16 +273,10 @@ l2_rw_node_fn (vlib_main_t * vm, } /* Update feature bitmap and get next feature index */ - feature_bitmap0 = - vnet_buffer (b0)->l2.feature_bitmap & ~L2INPUT_FEAT_RW; - feature_bitmap1 = - vnet_buffer (b1)->l2.feature_bitmap & ~L2INPUT_FEAT_RW; - vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap0; - vnet_buffer (b1)->l2.feature_bitmap = feature_bitmap1; - next0 = feat_bitmap_get_next_node_index (rw->feat_next_node_index, - feature_bitmap0); - next1 = feat_bitmap_get_next_node_index (rw->feat_next_node_index, - feature_bitmap1); + next0 = vnet_l2_feature_next (b0, rw->feat_next_node_index, + L2INPUT_FEAT_RW); + next1 = vnet_l2_feature_next (b1, rw->feat_next_node_index, + L2INPUT_FEAT_RW); vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, n_left_to_next, @@ -291,7 +285,7 @@ l2_rw_node_fn (vlib_main_t * vm, while (n_left_from > 0 && n_left_to_next > 0) { - u32 bi0, next0, sw_if_index0, feature_bitmap0, rwe_index0; + u32 bi0, next0, sw_if_index0, rwe_index0; vlib_buffer_t *b0; ethernet_header_t *h0; l2_rw_config_t *config0; @@ -341,11 +335,8 @@ l2_rw_node_fn (vlib_main_t * vm, } /* Update feature bitmap and get next feature index */ - feature_bitmap0 = - vnet_buffer (b0)->l2.feature_bitmap & ~L2INPUT_FEAT_RW; - vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap0; - next0 = feat_bitmap_get_next_node_index (rw->feat_next_node_index, - feature_bitmap0); + next0 = vnet_l2_feature_next (b0, rw->feat_next_node_index, + L2INPUT_FEAT_RW); vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, n_left_to_next, diff --git a/src/vnet/policer/node_funcs.c b/src/vnet/policer/node_funcs.c index 457dd09f..fd031d02 100644 --- a/src/vnet/policer/node_funcs.c +++ b/src/vnet/policer/node_funcs.c @@ -736,14 +736,9 @@ policer_classify_inline (vlib_main_t * vm, if (tid == POLICER_CLASSIFY_TABLE_L2) { - /* Feature bitmap update */ - vnet_buffer (b0)->l2.feature_bitmap &= - ~L2INPUT_FEAT_POLICER_CLAS; - /* Determine the next node */ - next0 = - feat_bitmap_get_next_node_index (pcm->feat_next_node_index, - vnet_buffer (b0)-> - l2.feature_bitmap); + /* Feature bitmap update and determine the next node */ + next0 = vnet_l2_feature_next (b0, pcm->feat_next_node_index, + L2INPUT_FEAT_POLICER_CLAS); } else vnet_get_config_data (pcm->vnet_config_main[tid], -- cgit 1.2.3-korg From 913b87306642a1c2d59431e4d0639c7a8399808f Mon Sep 17 00:00:00 2001 From: Chaoyu Jin Date: Tue, 8 Aug 2017 13:36:23 -0700 Subject: Fix memory leaks found in policer code. 2nd commit is to fix style failures. 3rd commit is to remove unneccesary change based on review comment. Change-Id: I4d54d25c27e037b9d0438f8af416cf113763dc6d Signed-off-by: Chaoyu Jin --- src/vnet/policer/policer.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/vnet/policer') diff --git a/src/vnet/policer/policer.c b/src/vnet/policer/policer.c index cd754e29..5a7b7711 100644 --- a/src/vnet/policer/policer.c +++ b/src/vnet/policer/policer.c @@ -33,13 +33,26 @@ policer_add_del (vlib_main_t * vm, if (is_add == 0) { + /* free policer config and template */ if (p == 0) { vec_free (name); return clib_error_return (0, "No such policer configuration"); } + pool_put_index (pm->configs, p[0]); + pool_put_index (pm->policer_templates, p[0]); hash_unset_mem (pm->policer_config_by_name, name); + + /* free policer */ + p = hash_get_mem (pm->policer_index_by_name, name); + if (p == 0) + { + vec_free (name); + return clib_error_return (0, "No such policer"); + } + pool_put_index (pm->policers, p[0]); hash_unset_mem (pm->policer_index_by_name, name); + vec_free (name); return 0; } @@ -500,6 +513,27 @@ VLIB_CLI_COMMAND (show_policer_command, static) = { }; /* *INDENT-ON* */ +static clib_error_t * +show_policer_pools_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + vnet_policer_main_t *pm = &vnet_policer_main; + + vlib_cli_output (vm, "pool sizes: configs=%d templates=%d policers=%d", + pool_elts (pm->configs), + pool_elts (pm->policer_templates), + pool_elts (pm->policers)); + return 0; +} +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (show_policer_pools_command, static) = { + .path = "show policer pools", + .short_help = "show policer pools", + .function = show_policer_pools_command_fn, +}; +/* *INDENT-ON* */ + clib_error_t * policer_init (vlib_main_t * vm) { -- cgit 1.2.3-korg From 87318463aa3abfe22984f78c1b31db8a355fae76 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Tue, 22 Aug 2017 10:49:24 +0200 Subject: policer: remove unused code This is causing compiler error with gcc 7. Change-Id: Ia65ee9d80ab263c79e82ad805e5cc5a12af91f85 Signed-off-by: Damjan Marion --- src/vnet/policer/xlate.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/vnet/policer') diff --git a/src/vnet/policer/xlate.c b/src/vnet/policer/xlate.c index b1c055ed..af8bc5a9 100644 --- a/src/vnet/policer/xlate.c +++ b/src/vnet/policer/xlate.c @@ -1172,7 +1172,6 @@ sse2_pol_logical_2_physical (sse2_qos_pol_cfg_params_st * cfg, policer_read_response_type_st * phys) { int rc; - sse2_qos_pol_hw_params_st pol_hw; sse2_qos_pol_cfg_params_st kbps_cfg; memset (phys, 0, sizeof (policer_read_response_type_st)); @@ -1270,9 +1269,6 @@ sse2_pol_logical_2_physical (sse2_qos_pol_cfg_params_st * cfg, phys->extended_bucket = cfg->extended_bucket; } - // Touch to avoid compiler warning for X86 - pol_hw.allow_negative = pol_hw.allow_negative; - #endif // if !defined (INTERNAL_SS) && !defined (X86) return 0; -- cgit 1.2.3-korg