diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/srv6-mobile/node.c | 6 | ||||
-rw-r--r-- | src/plugins/srv6-un/CMakeLists.txt | 21 | ||||
-rw-r--r-- | src/plugins/srv6-un/node.c | 304 | ||||
-rw-r--r-- | src/plugins/srv6-un/un.c | 185 | ||||
-rw-r--r-- | src/plugins/srv6-un/un.h | 65 | ||||
-rw-r--r-- | src/vnet/srv6/sr.api | 2 | ||||
-rwxr-xr-x | src/vnet/srv6/sr.h | 10 | ||||
-rw-r--r-- | src/vnet/srv6/sr_api.c | 2 | ||||
-rwxr-xr-x | src/vnet/srv6/sr_localsid.c | 61 |
9 files changed, 620 insertions, 36 deletions
diff --git a/src/plugins/srv6-mobile/node.c b/src/plugins/srv6-mobile/node.c index efc92215cac..6eafefd3f5b 100644 --- a/src/plugins/srv6-mobile/node.c +++ b/src/plugins/srv6-mobile/node.c @@ -372,8 +372,8 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm, len0 = vlib_buffer_length_in_chain (vm, b0); - offset = ls0->localsid_len / 8; - shift = ls0->localsid_len % 8; + offset = ls0->localsid_prefix_len / 8; + shift = ls0->localsid_prefix_len % 8; gtpu_type = gtpu_type_get (tag); @@ -1169,7 +1169,7 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm, u16 offset, shift; u32 hdrlen = 0; - index = ls0->localsid_len; + index = ls0->localsid_prefix_len; index += 8; offset = index / 8; shift = index % 8; diff --git a/src/plugins/srv6-un/CMakeLists.txt b/src/plugins/srv6-un/CMakeLists.txt new file mode 100644 index 00000000000..9ecf0b3c8d0 --- /dev/null +++ b/src/plugins/srv6-un/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (c) 2018 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. + +add_vpp_plugin(SRv6uN + SOURCES + un.c + node.c + + INSTALL_HEADERS + un.h +) diff --git a/src/plugins/srv6-un/node.c b/src/plugins/srv6-un/node.c new file mode 100644 index 00000000000..caca18c56f2 --- /dev/null +++ b/src/plugins/srv6-un/node.c @@ -0,0 +1,304 @@ +/* + * 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 <vlib/vlib.h> +#include <vnet/vnet.h> +#include <vppinfra/error.h> +#include <srv6-un/un.h> + + +/******************************* Packet tracing *******************************/ +typedef struct +{ + u32 localsid_index; +} srv6_un_localsid_trace_t; + + +static u8 * +format_srv6_un_localsid_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 *); + srv6_un_localsid_trace_t *t = va_arg (*args, srv6_un_localsid_trace_t *); + + return format (s, "SRv6-uN-localsid: localsid_index %d", t->localsid_index); +} + +/********************************* Next nodes *********************************/ +typedef enum +{ + SRV6_UN_LOCALSID_NEXT_ERROR, + SRV6_UN_LOCALSID_NEXT_IP6LOOKUP, + SRV6_UN_LOCALSID_N_NEXT, +} srv6_un_localsid_next_t; + +/******************************* Local SID node *******************************/ + +/** + * @brief Graph node for applying SRv6 uN. + */ +static uword +srv6_un_localsid_fn (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * frame) +{ + ip6_sr_main_t *sm = &sr_main; + u32 n_left_from, next_index, *from, *to_next; + + from = vlib_frame_vector_args (frame); + n_left_from = frame->n_vectors; + next_index = node->cached_next_index; + + u32 thread_index = vm->thread_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); + + /* Quad - Loop */ + while (n_left_from >= 8 && n_left_to_next >= 4) + { + u32 bi0, bi1, bi2, bi3; + vlib_buffer_t *b0, *b1, *b2, *b3; + ip6_header_t *ip0, *ip1, *ip2, *ip3; + u32 next0, next1, next2, next3; + next0 = next1 = next2 = next3 = SRV6_UN_LOCALSID_NEXT_IP6LOOKUP; + ip6_sr_localsid_t *ls0, *ls1, *ls2, *ls3; + + /* Prefetch next iteration. */ + { + vlib_buffer_t *p4, *p5, *p6, *p7; + + p4 = vlib_get_buffer (vm, from[4]); + p5 = vlib_get_buffer (vm, from[5]); + p6 = vlib_get_buffer (vm, from[6]); + p7 = vlib_get_buffer (vm, from[7]); + + /* Prefetch the buffer header and packet for the N+4 loop iteration */ + vlib_prefetch_buffer_header (p4, LOAD); + vlib_prefetch_buffer_header (p5, LOAD); + vlib_prefetch_buffer_header (p6, LOAD); + vlib_prefetch_buffer_header (p7, LOAD); + + CLIB_PREFETCH (p4->data, CLIB_CACHE_LINE_BYTES, STORE); + CLIB_PREFETCH (p5->data, CLIB_CACHE_LINE_BYTES, STORE); + CLIB_PREFETCH (p6->data, CLIB_CACHE_LINE_BYTES, STORE); + CLIB_PREFETCH (p7->data, CLIB_CACHE_LINE_BYTES, STORE); + } + + to_next[0] = bi0 = from[0]; + to_next[1] = bi1 = from[1]; + to_next[2] = bi2 = from[2]; + to_next[3] = bi3 = from[3]; + from += 4; + to_next += 4; + n_left_from -= 4; + n_left_to_next -= 4; + + b0 = vlib_get_buffer (vm, bi0); + b1 = vlib_get_buffer (vm, bi1); + b2 = vlib_get_buffer (vm, bi2); + b3 = vlib_get_buffer (vm, bi3); + + ls0 = + pool_elt_at_index (sm->localsids, + vnet_buffer (b0)->ip.adj_index[VLIB_TX]); + ls1 = + pool_elt_at_index (sm->localsids, + vnet_buffer (b1)->ip.adj_index[VLIB_TX]); + ls2 = + pool_elt_at_index (sm->localsids, + vnet_buffer (b2)->ip.adj_index[VLIB_TX]); + ls3 = + pool_elt_at_index (sm->localsids, + vnet_buffer (b3)->ip.adj_index[VLIB_TX]); + + ip0 = vlib_buffer_get_current (b0); + ip1 = vlib_buffer_get_current (b1); + ip2 = vlib_buffer_get_current (b2); + ip3 = vlib_buffer_get_current (b3); + + /* Set Destination Address to Last Segment (index 0) */ + ip0->dst_address.as_u16[2] = ip0->dst_address.as_u16[3]; + ip0->dst_address.as_u16[3] = ip0->dst_address.as_u16[4]; + ip0->dst_address.as_u16[4] = ip0->dst_address.as_u16[5]; + ip0->dst_address.as_u16[5] = ip0->dst_address.as_u16[6]; + ip0->dst_address.as_u16[6] = ip0->dst_address.as_u16[7]; + ip0->dst_address.as_u16[7] = 0x0000; + + ip1->dst_address.as_u16[2] = ip1->dst_address.as_u16[3]; + ip1->dst_address.as_u16[3] = ip1->dst_address.as_u16[4]; + ip1->dst_address.as_u16[4] = ip1->dst_address.as_u16[5]; + ip1->dst_address.as_u16[5] = ip1->dst_address.as_u16[6]; + ip1->dst_address.as_u16[6] = ip1->dst_address.as_u16[7]; + ip1->dst_address.as_u16[7] = 0x0000; + + ip2->dst_address.as_u16[2] = ip2->dst_address.as_u16[3]; + ip2->dst_address.as_u16[3] = ip2->dst_address.as_u16[4]; + ip2->dst_address.as_u16[4] = ip2->dst_address.as_u16[5]; + ip2->dst_address.as_u16[5] = ip2->dst_address.as_u16[6]; + ip2->dst_address.as_u16[6] = ip2->dst_address.as_u16[7]; + ip2->dst_address.as_u16[7] = 0x0000; + + ip3->dst_address.as_u16[2] = ip3->dst_address.as_u16[3]; + ip3->dst_address.as_u16[3] = ip3->dst_address.as_u16[4]; + ip3->dst_address.as_u16[4] = ip3->dst_address.as_u16[5]; + ip3->dst_address.as_u16[5] = ip3->dst_address.as_u16[6]; + ip3->dst_address.as_u16[6] = ip3->dst_address.as_u16[7]; + ip3->dst_address.as_u16[7] = 0x0000; + + if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) + { + srv6_un_localsid_trace_t *tr = + vlib_add_trace (vm, node, b0, sizeof (*tr)); + tr->localsid_index = ls0 - sm->localsids; + } + + if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED)) + { + srv6_un_localsid_trace_t *tr = + vlib_add_trace (vm, node, b1, sizeof (*tr)); + tr->localsid_index = ls1 - sm->localsids; + } + + if (PREDICT_FALSE (b2->flags & VLIB_BUFFER_IS_TRACED)) + { + srv6_un_localsid_trace_t *tr = + vlib_add_trace (vm, node, b2, sizeof (*tr)); + tr->localsid_index = ls2 - sm->localsids; + } + + if (PREDICT_FALSE (b3->flags & VLIB_BUFFER_IS_TRACED)) + { + srv6_un_localsid_trace_t *tr = + vlib_add_trace (vm, node, b3, sizeof (*tr)); + tr->localsid_index = ls3 - sm->localsids; + } + + vlib_increment_combined_counter + (((next0 == + SRV6_UN_LOCALSID_NEXT_ERROR) ? + &(sm->sr_ls_invalid_counters) : + &(sm->sr_ls_valid_counters)), + thread_index, ls0 - sm->localsids, + 1, vlib_buffer_length_in_chain (vm, b0)); + + vlib_increment_combined_counter + (((next1 == + SRV6_UN_LOCALSID_NEXT_ERROR) ? + &(sm->sr_ls_invalid_counters) : + &(sm->sr_ls_valid_counters)), + thread_index, ls1 - sm->localsids, + 1, vlib_buffer_length_in_chain (vm, b1)); + + vlib_increment_combined_counter + (((next2 == + SRV6_UN_LOCALSID_NEXT_ERROR) ? + &(sm->sr_ls_invalid_counters) : + &(sm->sr_ls_valid_counters)), + thread_index, ls2 - sm->localsids, + 1, vlib_buffer_length_in_chain (vm, b2)); + + vlib_increment_combined_counter + (((next3 == + SRV6_UN_LOCALSID_NEXT_ERROR) ? + &(sm->sr_ls_invalid_counters) : + &(sm->sr_ls_valid_counters)), + thread_index, ls3 - sm->localsids, + 1, vlib_buffer_length_in_chain (vm, b3)); + + vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next, + n_left_to_next, bi0, bi1, bi2, bi3, + next0, next1, next2, next3); + } + + while (n_left_from > 0 && n_left_to_next > 0) + { + u32 bi0; + vlib_buffer_t *b0; + ip6_header_t *ip0 = 0; + u32 next0 = SRV6_UN_LOCALSID_NEXT_IP6LOOKUP; + ip6_sr_localsid_t *ls0; + 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); + ip0 = vlib_buffer_get_current (b0); + + /* Lookup the SR End behavior based on IP DA (adj) */ + ls0 = + pool_elt_at_index (sm->localsids, + vnet_buffer (b0)->ip.adj_index[VLIB_TX]); + + /* Set Destination Address to Last Segment (index 0) */ + ip0->dst_address.as_u16[2] = ip0->dst_address.as_u16[3]; + ip0->dst_address.as_u16[3] = ip0->dst_address.as_u16[4]; + ip0->dst_address.as_u16[4] = ip0->dst_address.as_u16[5]; + ip0->dst_address.as_u16[5] = ip0->dst_address.as_u16[6]; + ip0->dst_address.as_u16[6] = ip0->dst_address.as_u16[7]; + ip0->dst_address.as_u16[7] = 0x0000; + + if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) + { + srv6_un_localsid_trace_t *tr = + vlib_add_trace (vm, node, b0, sizeof (*tr)); + tr->localsid_index = ls0 - sm->localsids; + } + + /* This increments the SRv6 per LocalSID counters. */ + vlib_increment_combined_counter (((next0 == + SRV6_UN_LOCALSID_NEXT_ERROR) ? + &(sm->sr_ls_invalid_counters) : + &(sm->sr_ls_valid_counters)), + thread_index, ls0 - sm->localsids, + 1, vlib_buffer_length_in_chain (vm, + b0)); + + 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); + } + + return frame->n_vectors; +} + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (srv6_un_localsid_node) = { + .function = srv6_un_localsid_fn, + .name = "srv6-un-localsid", + .vector_size = sizeof (u32), + .format_trace = format_srv6_un_localsid_trace, + .type = VLIB_NODE_TYPE_INTERNAL, + .n_next_nodes = SRV6_UN_LOCALSID_N_NEXT, + .next_nodes = { + [SRV6_UN_LOCALSID_NEXT_IP6LOOKUP] = "ip6-lookup", + [SRV6_UN_LOCALSID_NEXT_ERROR] = "error-drop", + }, +}; +/* *INDENT-ON* */ + +/* +* fd.io coding-style-patch-verification: ON +* +* Local Variables: +* eval: (c-set-style "gnu") +* End: +*/ diff --git a/src/plugins/srv6-un/un.c b/src/plugins/srv6-un/un.c new file mode 100644 index 00000000000..7fd02e2c934 --- /dev/null +++ b/src/plugins/srv6-un/un.c @@ -0,0 +1,185 @@ +/* + * 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. + */ +/* + *------------------------------------------------------------------ + * un.c - SRv6 Masquerading Proxy (AM) function + *------------------------------------------------------------------ + */ + +#include <vnet/vnet.h> +#include <vnet/adj/adj.h> +#include <vnet/plugin/plugin.h> +#include <vpp/app/version.h> +#include <srv6-un/un.h> + +unsigned char function_name[] = "SRv6-uN"; +unsigned char keyword_str[] = "uN(32b+16b)"; +unsigned char def_str[] = "SRv6 uSID uN"; +unsigned char params_str[] = ""; +u8 prefix_length = 48; + +srv6_un_main_t srv6_un_main; + +/*****************************************/ +/* SRv6 LocalSID instantiation and removal functions */ +static int +srv6_un_localsid_creation_fn (ip6_sr_localsid_t * localsid) +{ + srv6_un_localsid_t *ls_mem = localsid->plugin_mem; + //Nothing to do here. + ls_mem->shift = 16; + return 0; +} + +static int +srv6_un_localsid_removal_fn (ip6_sr_localsid_t * localsid) +{ + //Nothing to do here. + + /* Clean up local SID memory */ + clib_mem_free (localsid->plugin_mem); + + return 0; +} + +/**********************************/ +/* SRv6 LocalSID format functions */ +/* + * Prints nicely the parameters of a localsid + * Example: print "Table 5" + */ +u8 * +format_srv6_un_localsid (u8 * s, va_list * args) +{ + srv6_un_localsid_t *ls_mem = va_arg (*args, void *); + + return (format (s, "Shift:\t\t%u", ls_mem->shift)); +} + +/* + * Process the parameters of a localsid + * Example: process from: + * sr localsid address cafe::1 behavior new_srv6_localsid 5 + * everything from behavior on... so in this case 'new_srv6_localsid 5' + * Notice that it MUST match the keyword_str and params_str defined above. + */ +uword +unformat_srv6_un_localsid (unformat_input_t * input, va_list * args) +{ + void **plugin_mem_p = va_arg (*args, void **); + srv6_un_localsid_t *ls_mem; + + if (unformat (input, "uN(32b+16b)")) + { + /* Allocate a portion of memory */ + ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1); + + /* Set to zero the memory */ + clib_memset (ls_mem, 0, sizeof *ls_mem); + + /* Dont forget to add it to the localsid */ + *plugin_mem_p = ls_mem; + return 1; + } + return 0; +} + +/*************************/ +/* SRv6 LocalSID FIB DPO */ +static u8 * +format_srv6_un_dpo (u8 * s, va_list * args) +{ + index_t index = va_arg (*args, index_t); + CLIB_UNUSED (u32 indent) = va_arg (*args, u32); + + return (format (s, "SR: shift-and-forward 16b:[%u]", index)); +} + +void +srv6_un_dpo_lock (dpo_id_t * dpo) +{ +} + +void +srv6_un_dpo_unlock (dpo_id_t * dpo) +{ +} + +const static dpo_vft_t srv6_un_vft = { + .dv_lock = srv6_un_dpo_lock, + .dv_unlock = srv6_un_dpo_unlock, + .dv_format = format_srv6_un_dpo, +}; + +const static char *const srv6_un_ip6_nodes[] = { + "srv6-un-localsid", + NULL, +}; + +const static char *const *const srv6_un_nodes[DPO_PROTO_NUM] = { + [DPO_PROTO_IP6] = srv6_un_ip6_nodes, +}; + +/**********************/ +static clib_error_t * +srv6_un_init (vlib_main_t * vm) +{ + srv6_un_main_t *sm = &srv6_un_main; + int rv = 0; + + sm->vlib_main = vm; + sm->vnet_main = vnet_get_main (); + + /* Create DPO */ + sm->srv6_un16_dpo_type = + dpo_register_new_type (&srv6_un_vft, srv6_un_nodes); + + /* Register SRv6 LocalSID */ + rv = sr_localsid_register_function (vm, + function_name, + keyword_str, + def_str, + params_str, + prefix_length, + &sm->srv6_un16_dpo_type, + format_srv6_un_localsid, + unformat_srv6_un_localsid, + srv6_un_localsid_creation_fn, + srv6_un_localsid_removal_fn); + if (rv < 0) + clib_error_return (0, "SRv6 LocalSID function could not be registered."); + else + sm->srv6_localsid_behavior_id = rv; + + return 0; +} + + +/* *INDENT-OFF* */ +VLIB_INIT_FUNCTION (srv6_un_init); + +VLIB_PLUGIN_REGISTER () = { + .version = VPP_BUILD_VER, + .description = "Segment Routing Shift And Forward uN 16b", +}; +/* *INDENT-ON* */ + +/* +* fd.io coding-style-patch-verification: ON +* +* Local Variables: +* eval: (c-set-style "gnu") +* End: +*/ diff --git a/src/plugins/srv6-un/un.h b/src/plugins/srv6-un/un.h new file mode 100644 index 00000000000..750e2350d74 --- /dev/null +++ b/src/plugins/srv6-un/un.h @@ -0,0 +1,65 @@ +/* + * 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_srv6_un_h__ +#define __included_srv6_un_h__ + +#include <vnet/vnet.h> +#include <vnet/ip/ip.h> +#include <vnet/srv6/sr.h> +#include <vnet/srv6/sr_packet.h> + +#include <vppinfra/error.h> +#include <vppinfra/elog.h> + +typedef struct +{ + u16 msg_id_base; /**< API message ID base */ + + vlib_main_t *vlib_main; /**< [convenience] vlib main */ + vnet_main_t *vnet_main; /**< [convenience] vnet main */ + + dpo_type_t srv6_un16_dpo_type; /**< DPO type */ + + u32 srv6_localsid_behavior_id; /**< SRv6 LocalSID behavior number */ +} srv6_un_main_t; + +/* + * This is the memory that will be stored per each localsid + * the user instantiates + */ +typedef struct +{ + u16 shift; +} srv6_un_localsid_t; + +extern srv6_un_main_t srv6_un_main; + +format_function_t format_srv6_un_localsid; +unformat_function_t unformat_srv6_un_localsid; + +void srv6_un_dpo_lock (dpo_id_t * dpo); +void srv6_un_dpo_unlock (dpo_id_t * dpo); + +extern vlib_node_registration_t srv6_un_localsid_node; + +#endif /* __included_srv6_un_h__ */ + +/* +* fd.io coding-style-patch-verification: ON +* +* Local Variables: +* eval: (c-set-style "gnu") +* End: +*/ diff --git a/src/vnet/srv6/sr.api b/src/vnet/srv6/sr.api index 1d696b0c897..543f3fd7d00 100644 --- a/src/vnet/srv6/sr.api +++ b/src/vnet/srv6/sr.api @@ -14,7 +14,7 @@ * limitations under the License. */ -option version = "1.2.0"; +option version = "1.2.1"; /** \brief SRv6 SID */ diff --git a/src/vnet/srv6/sr.h b/src/vnet/srv6/sr.h index 6a228c8fc23..f804b190135 100755 --- a/src/vnet/srv6/sr.h +++ b/src/vnet/srv6/sr.h @@ -119,7 +119,7 @@ typedef struct { ip6_address_t localsid; /**< LocalSID IPv6 address */ - u16 localsid_len; + u16 localsid_prefix_len; char end_psp; /**< Combined with End.PSP? */ @@ -331,10 +331,10 @@ extern int sr_policy_mod (ip6_address_t * bsid, u32 index, u32 fib_table, extern int sr_policy_del (ip6_address_t * bsid, u32 index); extern int -sr_cli_localsid (char is_del, ip6_address_t * localsid_addr, u16 prefixlen, - char end_psp, u8 behavior, u32 sw_if_index, - u32 vlan_index, u32 fib_table, ip46_address_t * nh_addr, - void *ls_plugin_mem); +sr_cli_localsid (char is_del, ip6_address_t * localsid_addr, + u16 localsid_prefix_len, char end_psp, u8 behavior, + u32 sw_if_index, u32 vlan_index, u32 fib_table, + ip46_address_t * nh_addr, void *ls_plugin_mem); extern int sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index, diff --git a/src/vnet/srv6/sr_api.c b/src/vnet/srv6/sr_api.c index 606eaa612ae..cd8182480a4 100644 --- a/src/vnet/srv6/sr_api.c +++ b/src/vnet/srv6/sr_api.c @@ -81,7 +81,7 @@ static void vl_api_sr_localsid_add_del_t_handler memcpy (&prefix.ip6, mp->nh_addr6, sizeof (prefix.ip6)); rv = sr_cli_localsid (mp->is_del, - (ip6_address_t *) & mp->localsid, 0, + (ip6_address_t *) & mp->localsid, 128, mp->end_psp, mp->behavior, ntohl (mp->sw_if_index), diff --git a/src/vnet/srv6/sr_localsid.c b/src/vnet/srv6/sr_localsid.c index 7b71b2e71de..2e8b10d2987 100755 --- a/src/vnet/srv6/sr_localsid.c +++ b/src/vnet/srv6/sr_localsid.c @@ -63,9 +63,10 @@ static dpo_type_t sr_localsid_d_dpo_type; * @return 0 on success, error otherwise. */ int -sr_cli_localsid (char is_del, ip6_address_t * localsid_addr, u16 prefixlen, - char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index, - u32 fib_table, ip46_address_t * nh_addr, void *ls_plugin_mem) +sr_cli_localsid (char is_del, ip6_address_t * localsid_addr, + u16 localsid_prefix_len, char end_psp, u8 behavior, + u32 sw_if_index, u32 vlan_index, u32 fib_table, + ip46_address_t * nh_addr, void *ls_plugin_mem) { ip6_sr_main_t *sm = &sr_main; uword *p; @@ -93,9 +94,9 @@ sr_cli_localsid (char is_del, ip6_address_t * localsid_addr, u16 prefixlen, pref_length = plugin->prefix_length; } - if (prefixlen != 0) + if (localsid_prefix_len != 0) { - pref_length = prefixlen; + pref_length = localsid_prefix_len; } /* Delete FIB entry */ @@ -152,9 +153,9 @@ sr_cli_localsid (char is_del, ip6_address_t * localsid_addr, u16 prefixlen, pfx.fp_addr.as_u64[0] = localsid_addr->as_u64[0]; pfx.fp_addr.as_u64[1] = localsid_addr->as_u64[1]; - if (prefixlen != 0) + if (pref_length != 0) { - pfx.fp_len = prefixlen; + pfx.fp_len = pref_length; } /* Lookup the FIB index associated to the table id provided */ @@ -172,11 +173,11 @@ sr_cli_localsid (char is_del, ip6_address_t * localsid_addr, u16 prefixlen, clib_memset (ls, 0, sizeof (*ls)); clib_memcpy (&ls->localsid, localsid_addr, sizeof (ip6_address_t)); + ls->localsid_prefix_len = pref_length; ls->end_psp = end_psp; ls->behavior = behavior; ls->nh_adj = (u32) ~ 0; ls->fib_table = fib_table; - ls->localsid_len = pfx.fp_len; switch (behavior) { case SR_BEHAVIOR_END: @@ -310,12 +311,12 @@ sr_cli_localsid_command_fn (vlib_main_t * vm, unformat_input_t * input, if (unformat (input, "del")) is_del = 1; else if (!address_set - && unformat (input, "address %U", unformat_ip6_address, - &resulting_address)) + && unformat (input, "address %U/%u", unformat_ip6_address, + &resulting_address, &prefix_len)) address_set = 1; else if (!address_set - && unformat (input, "prefix %U/%d", unformat_ip6_address, - &resulting_address, &prefix_len)) + && unformat (input, "address %U", unformat_ip6_address, + &resulting_address)) address_set = 1; else if (!address_set && unformat (input, "addr %U", unformat_ip6_address, @@ -489,47 +490,53 @@ show_sr_localsid_command_fn (vlib_main_t * vm, unformat_input_t * input, switch (ls->behavior) { case SR_BEHAVIOR_END: - vlib_cli_output (vm, "\tAddress: \t%U\n\tBehavior: \tEnd", - format_ip6_address, &ls->localsid); + vlib_cli_output (vm, "\tAddress: \t%U/%u\n\tBehavior: \tEnd", + format_ip6_address, &ls->localsid, + ls->localsid_prefix_len); break; case SR_BEHAVIOR_X: vlib_cli_output (vm, - "\tAddress: \t%U\n\tBehavior: \tX (Endpoint with Layer-3 cross-connect)" + "\tAddress: \t%U/%u\n\tBehavior: \tX (Endpoint with Layer-3 cross-connect)" "\n\tIface: \t%U\n\tNext hop: \t%U", format_ip6_address, &ls->localsid, + ls->localsid_prefix_len, format_vnet_sw_if_index_name, vnm, ls->sw_if_index, format_ip6_address, &ls->next_hop.ip6); break; case SR_BEHAVIOR_T: vlib_cli_output (vm, - "\tAddress: \t%U\n\tBehavior: \tT (Endpoint with specific IPv6 table lookup)" + "\tAddress: \t%U/%u\n\tBehavior: \tT (Endpoint with specific IPv6 table lookup)" "\n\tTable: \t%u", format_ip6_address, &ls->localsid, + ls->localsid_prefix_len, fib_table_get_table_id (ls->vrf_index, FIB_PROTOCOL_IP6)); break; case SR_BEHAVIOR_DX4: vlib_cli_output (vm, - "\tAddress: \t%U\n\tBehavior: \tDX4 (Endpoint with decapsulation and IPv4 cross-connect)" + "\tAddress: \t%U/%u\n\tBehavior: \tDX4 (Endpoint with decapsulation and IPv4 cross-connect)" "\n\tIface: \t%U\n\tNext hop: \t%U", format_ip6_address, &ls->localsid, + ls->localsid_prefix_len, format_vnet_sw_if_index_name, vnm, ls->sw_if_index, format_ip4_address, &ls->next_hop.ip4); break; case SR_BEHAVIOR_DX6: vlib_cli_output (vm, - "\tAddress: \t%U\n\tBehavior: \tDX6 (Endpoint with decapsulation and IPv6 cross-connect)" + "\tAddress: \t%U/%u\n\tBehavior: \tDX6 (Endpoint with decapsulation and IPv6 cross-connect)" "\n\tIface: \t%U\n\tNext hop: \t%U", format_ip6_address, &ls->localsid, + ls->localsid_prefix_len, format_vnet_sw_if_index_name, vnm, ls->sw_if_index, format_ip6_address, &ls->next_hop.ip6); break; case SR_BEHAVIOR_DX2: if (ls->vlan_index == (u32) ~ 0) vlib_cli_output (vm, - "\tAddress: \t%U\n\tBehavior: \tDX2 (Endpoint with decapulation and Layer-2 cross-connect)" + "\tAddress: \t%U/%u\n\tBehavior: \tDX2 (Endpoint with decapulation and Layer-2 cross-connect)" "\n\tIface: \t%U", format_ip6_address, - &ls->localsid, format_vnet_sw_if_index_name, vnm, + &ls->localsid, ls->localsid_prefix_len, + format_vnet_sw_if_index_name, vnm, ls->sw_if_index); else vlib_cli_output (vm, @@ -537,16 +544,17 @@ show_sr_localsid_command_fn (vlib_main_t * vm, unformat_input_t * input, break; case SR_BEHAVIOR_DT6: vlib_cli_output (vm, - "\tAddress: \t%U\n\tBehavior: \tDT6 (Endpoint with decapsulation and specific IPv6 table lookup)" + "\tAddress: \t%U/%u\n\tBehavior: \tDT6 (Endpoint with decapsulation and specific IPv6 table lookup)" "\n\tTable: %u", format_ip6_address, &ls->localsid, + ls->localsid_prefix_len, fib_table_get_table_id (ls->vrf_index, FIB_PROTOCOL_IP6)); break; case SR_BEHAVIOR_DT4: vlib_cli_output (vm, - "\tAddress: \t%U\n\tBehavior: \tDT4 (Endpoint with decapsulation and specific IPv4 table lookup)" + "\tAddress: \t%U/%u\n\tBehavior: \tDT4 (Endpoint with decapsulation and specific IPv4 table lookup)" "\n\tTable: \t%u", format_ip6_address, - &ls->localsid, + &ls->localsid, ls->localsid_prefix_len, fib_table_get_table_id (ls->vrf_index, FIB_PROTOCOL_IP4)); break; @@ -557,11 +565,12 @@ show_sr_localsid_command_fn (vlib_main_t * vm, unformat_input_t * input, pool_elt_at_index (sm->plugin_functions, ls->behavior - SR_BEHAVIOR_LAST); - vlib_cli_output (vm, "\tAddress: \t%U\n" + vlib_cli_output (vm, "\tAddress: \t%U/%u\n" "\tBehavior: \t%s (%s)\n\t%U", format_ip6_address, &ls->localsid, - plugin->keyword_str, plugin->def_str, - plugin->ls_format, ls->plugin_mem); + ls->localsid_prefix_len, plugin->keyword_str, + plugin->def_str, plugin->ls_format, + ls->plugin_mem); } else //Should never get here... |