diff options
Diffstat (limited to 'src/vnet')
26 files changed, 253 insertions, 3002 deletions
diff --git a/src/vnet/CMakeLists.txt b/src/vnet/CMakeLists.txt index fb8d294009d..ad5f44846cc 100644 --- a/src/vnet/CMakeLists.txt +++ b/src/vnet/CMakeLists.txt @@ -813,24 +813,6 @@ list(APPEND VNET_API_FILES ) ############################################################################## -# mpls segment routing -############################################################################## - -list(APPEND VNET_SOURCES - srmpls/sr_mpls_policy.c - srmpls/sr_mpls_steering.c - srmpls/sr_mpls_api.c -) - -list(APPEND VNET_HEADERS - srmpls/sr_mpls.h -) - -list(APPEND VNET_API_FILES - srmpls/sr_mpls.api -) - -############################################################################## # IPFIX / netflow v10 ############################################################################## list(APPEND VNET_SOURCES @@ -1460,7 +1442,6 @@ add_vat_test_library(vnet ip/ip_test.c arp/arp_test.c ip6-nd/ip6_nd_test.c - srmpls/sr_mpls_test.c session/session_test.c l2/l2_test.c ipsec/ipsec_test.c diff --git a/src/vnet/dev/format.c b/src/vnet/dev/format.c index ed83a0eba95..f599c0f8b85 100644 --- a/src/vnet/dev/format.c +++ b/src/vnet/dev/format.c @@ -101,7 +101,7 @@ format_vnet_dev_port_info (u8 *s, va_list *args) u32 indent = format_get_indent (s); s = format (s, "Hardware Address is %U", format_vnet_dev_hw_addr, - &port->attr.hw_addr); + &port->primary_hw_addr); s = format (s, ", %u RX queues (max %u), %u TX queues (max %u)", pool_elts (port->rx_queues), port->attr.max_rx_queues, pool_elts (port->tx_queues), port->attr.max_tx_queues); diff --git a/src/vnet/ethernet/node.c b/src/vnet/ethernet/node.c index e2558eeca41..03cbdde1c2b 100644 --- a/src/vnet/ethernet/node.c +++ b/src/vnet/ethernet/node.c @@ -982,8 +982,31 @@ eth_input_process_frame (vlib_main_t * vm, vlib_node_runtime_t * node, else { for (int j = 0; j < 16; j++) - if (next[j] == 0) - slowpath_indices[n_slowpath++] = i + j; + { + if (next[j] == 0) + slowpath_indices[n_slowpath++] = i + j; + else if (dmac_check && main_is_l3 && dmacs_bad[i + j]) + { + next[j] = 0; + slowpath_indices[n_slowpath++] = i + j; + } + } + } + } + else + { + if (dmac_check && main_is_l3) + { + u8x16 dmac_bad = u8x16_load_unaligned (&dmacs_bad[i]); + if (!u8x16_is_all_zero (dmac_bad)) + { + for (int j = 0; j < 16; j++) + if (dmacs_bad[i + j]) + { + next[j] = 0; + slowpath_indices[n_slowpath++] = i + j; + } + } } } @@ -994,7 +1017,12 @@ eth_input_process_frame (vlib_main_t * vm, vlib_node_runtime_t * node, continue; } #endif - if (main_is_l3 && etype[0] == et_ip4) + if (dmac_check && main_is_l3 && dmacs_bad[i]) + { + next[0] = 0; + slowpath_indices[n_slowpath++] = i; + } + else if (main_is_l3 && etype[0] == et_ip4) next[0] = next_ip4; else if (main_is_l3 && etype[0] == et_ip6) next[0] = next_ip6; @@ -1052,7 +1080,7 @@ eth_input_process_frame (vlib_main_t * vm, vlib_node_runtime_t * node, } else { - /* untagged packet with not well known etyertype */ + /* untagged packet with not well known ethertype */ if (last_unknown_etype != etype) { last_unknown_etype = etype; diff --git a/src/vnet/gso/gso.h b/src/vnet/gso/gso.h index 883a4941ee2..dee5da5c70b 100644 --- a/src/vnet/gso/gso.h +++ b/src/vnet/gso/gso.h @@ -39,13 +39,13 @@ gso_init_bufs_from_template_base (vlib_buffer_t **bufs, vlib_buffer_t *b0, u32 flags, u16 n_bufs, u16 hdr_sz) { u32 i = n_bufs; - while (i >= 4) + while (i >= 6) { /* prefetches */ CLIB_PREFETCH (bufs[2], 2 * CLIB_CACHE_LINE_BYTES, LOAD); CLIB_PREFETCH (bufs[3], 2 * CLIB_CACHE_LINE_BYTES, LOAD); - vlib_prefetch_buffer_data (bufs[2], LOAD); - vlib_prefetch_buffer_data (bufs[3], LOAD); + vlib_prefetch_buffer_data (bufs[4], LOAD); + vlib_prefetch_buffer_data (bufs[5], LOAD); /* copying objects from cacheline 0 */ bufs[0]->current_data = 0; @@ -70,10 +70,26 @@ gso_init_bufs_from_template_base (vlib_buffer_t **bufs, vlib_buffer_t *b0, bufs[0]->total_length_not_including_first_buffer = 0; bufs[1]->total_length_not_including_first_buffer = 0; + clib_memcpy_fast (&bufs[0]->opaque2, &b0->opaque2, sizeof (b0->opaque2)); + clib_memcpy_fast (&bufs[1]->opaque2, &b0->opaque2, sizeof (b0->opaque2)); + /* copying data */ clib_memcpy_fast (bufs[0]->data, vlib_buffer_get_current (b0), hdr_sz); clib_memcpy_fast (bufs[1]->data, vlib_buffer_get_current (b0), hdr_sz); + /* header offset fixup */ + vnet_buffer (bufs[0])->l2_hdr_offset -= b0->current_data; + vnet_buffer (bufs[0])->l3_hdr_offset -= b0->current_data; + vnet_buffer (bufs[0])->l4_hdr_offset -= b0->current_data; + vnet_buffer2 (bufs[0])->outer_l3_hdr_offset -= b0->current_data; + vnet_buffer2 (bufs[0])->outer_l4_hdr_offset -= b0->current_data; + + vnet_buffer (bufs[1])->l2_hdr_offset -= b0->current_data; + vnet_buffer (bufs[1])->l3_hdr_offset -= b0->current_data; + vnet_buffer (bufs[1])->l4_hdr_offset -= b0->current_data; + vnet_buffer2 (bufs[1])->outer_l3_hdr_offset -= b0->current_data; + vnet_buffer2 (bufs[1])->outer_l4_hdr_offset -= b0->current_data; + bufs += 2; i -= 2; } @@ -92,10 +108,18 @@ gso_init_bufs_from_template_base (vlib_buffer_t **bufs, vlib_buffer_t *b0, /* copying objects from cacheline 1 */ bufs[0]->trace_handle = b0->trace_handle; bufs[0]->total_length_not_including_first_buffer = 0; + clib_memcpy_fast (&bufs[0]->opaque2, &b0->opaque2, sizeof (b0->opaque2)); /* copying data */ clib_memcpy_fast (bufs[0]->data, vlib_buffer_get_current (b0), hdr_sz); + /* header offset fixup */ + vnet_buffer (bufs[0])->l2_hdr_offset -= b0->current_data; + vnet_buffer (bufs[0])->l3_hdr_offset -= b0->current_data; + vnet_buffer (bufs[0])->l4_hdr_offset -= b0->current_data; + vnet_buffer2 (bufs[0])->outer_l3_hdr_offset -= b0->current_data; + vnet_buffer2 (bufs[0])->outer_l4_hdr_offset -= b0->current_data; + bufs++; i--; } @@ -103,28 +127,41 @@ gso_init_bufs_from_template_base (vlib_buffer_t **bufs, vlib_buffer_t *b0, static_always_inline void gso_fixup_segmented_buf (vlib_main_t *vm, vlib_buffer_t *b0, u32 next_tcp_seq, - int is_l2, int is_ip6, generic_header_offset_t *gho, - clib_ip_csum_t *c, u8 tcp_flags) + int is_l2, u8 oflags, u16 hdr_sz, u16 l4_hdr_sz, + clib_ip_csum_t *c, u8 tcp_flags, u8 is_prefetch, + vlib_buffer_t *b1) { - ip4_header_t *ip4 = - (ip4_header_t *) (vlib_buffer_get_current (b0) + gho->l3_hdr_offset + - gho->outer_hdr_sz); - ip6_header_t *ip6 = - (ip6_header_t *) (vlib_buffer_get_current (b0) + gho->l3_hdr_offset + - gho->outer_hdr_sz); - tcp_header_t *tcp = - (tcp_header_t *) (vlib_buffer_get_current (b0) + gho->l4_hdr_offset + - gho->outer_hdr_sz); + i16 l3_hdr_offset = vnet_buffer (b0)->l3_hdr_offset; + i16 l4_hdr_offset = vnet_buffer (b0)->l4_hdr_offset; + + ip4_header_t *ip4 = (ip4_header_t *) (b0->data + l3_hdr_offset); + ip6_header_t *ip6 = (ip6_header_t *) (b0->data + l3_hdr_offset); + tcp_header_t *tcp = (tcp_header_t *) (b0->data + l4_hdr_offset); tcp->flags = tcp_flags; tcp->seq_number = clib_host_to_net_u32 (next_tcp_seq); c->odd = 0; - if (is_ip6) + if (oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM) + { + ip4->length = + clib_host_to_net_u16 (b0->current_length - hdr_sz + + (l4_hdr_offset - l3_hdr_offset) + l4_hdr_sz); + ip4->checksum = 0; + ip4->checksum = ip4_header_checksum (ip4); + vnet_buffer_offload_flags_clear (b0, (VNET_BUFFER_OFFLOAD_F_IP_CKSUM | + VNET_BUFFER_OFFLOAD_F_TCP_CKSUM)); + c->sum += clib_mem_unaligned (&ip4->src_address, u32); + c->sum += clib_mem_unaligned (&ip4->dst_address, u32); + c->sum += clib_host_to_net_u32 ( + (clib_net_to_host_u16 (ip4->length) - ip4_header_bytes (ip4)) + + (ip4->protocol << 16)); + } + else { - ip6->payload_length = clib_host_to_net_u16 ( - b0->current_length - gho->l4_hdr_offset - gho->outer_hdr_sz); + ip6->payload_length = + clib_host_to_net_u16 (b0->current_length - hdr_sz + l4_hdr_sz); vnet_buffer_offload_flags_clear (b0, VNET_BUFFER_OFFLOAD_F_TCP_CKSUM); ip6_psh_t psh = { 0 }; u32 *p = (u32 *) &psh; @@ -135,24 +172,15 @@ gso_fixup_segmented_buf (vlib_main_t *vm, vlib_buffer_t *b0, u32 next_tcp_seq, for (int i = 0; i < 10; i++) c->sum += p[i]; } - else - { - ip4->length = clib_host_to_net_u16 ( - b0->current_length - gho->l3_hdr_offset - gho->outer_hdr_sz); - if (gho->gho_flags & GHO_F_IP4) - ip4->checksum = ip4_header_checksum (ip4); - vnet_buffer_offload_flags_clear (b0, (VNET_BUFFER_OFFLOAD_F_IP_CKSUM | - VNET_BUFFER_OFFLOAD_F_TCP_CKSUM)); - c->sum += clib_mem_unaligned (&ip4->src_address, u32); - c->sum += clib_mem_unaligned (&ip4->dst_address, u32); - c->sum += clib_host_to_net_u32 ( - (clib_net_to_host_u16 (ip4->length) - ip4_header_bytes (ip4)) + - (ip4->protocol << 16)); - } - clib_ip_csum_chunk (c, (u8 *) tcp, gho->l4_hdr_sz); + + if (is_prefetch) + CLIB_PREFETCH (vlib_buffer_get_current (b1) + hdr_sz, + CLIB_CACHE_LINE_BYTES, LOAD); + + clib_ip_csum_chunk (c, (u8 *) tcp, l4_hdr_sz); tcp->checksum = clib_ip_csum_fold (c); - if (!is_l2 && ((gho->gho_flags & GHO_F_TUNNEL) == 0)) + if (!is_l2 && ((oflags & VNET_BUFFER_OFFLOAD_F_TNL_MASK) == 0)) { u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; @@ -169,16 +197,20 @@ gso_fixup_segmented_buf (vlib_main_t *vm, vlib_buffer_t *b0, u32 next_tcp_seq, static_always_inline u32 gso_segment_buffer_inline (vlib_main_t *vm, vnet_interface_per_thread_data_t *ptd, - vlib_buffer_t *b, generic_header_offset_t *gho, - int is_l2, int is_ip6) + vlib_buffer_t *b, int is_l2) { vlib_buffer_t **bufs = 0; u32 n_tx_bytes = 0; + + u8 oflags = vnet_buffer (b)->oflags; + i16 l4_hdr_offset = vnet_buffer (b)->l4_hdr_offset; u16 gso_size = vnet_buffer2 (b)->gso_size; + u16 l4_hdr_sz = vnet_buffer2 (b)->gso_l4_hdr_sz; + u8 tcp_flags = 0, tcp_flags_no_fin_psh = 0; u32 default_bflags = b->flags & ~(VNET_BUFFER_F_GSO | VLIB_BUFFER_NEXT_PRESENT); - u16 hdr_sz = gho->hdr_sz + gho->outer_hdr_sz; + u16 hdr_sz = (l4_hdr_offset - b->current_data) + l4_hdr_sz; u32 next_tcp_seq = 0, tcp_seq = 0; u32 data_size = vlib_buffer_length_in_chain (vm, b) - hdr_sz; u16 size = @@ -200,9 +232,8 @@ gso_segment_buffer_inline (vlib_main_t *vm, vec_validate (bufs, n_bufs - 1); vlib_get_buffers (vm, ptd->split_buffers, bufs, n_bufs); - tcp_header_t *tcp = - (tcp_header_t *) (vlib_buffer_get_current (b) + gho->l4_hdr_offset + - gho->outer_hdr_sz); + tcp_header_t *tcp = (tcp_header_t *) (b->data + l4_hdr_offset); + tcp_seq = next_tcp_seq = clib_net_to_host_u32 (tcp->seq_number); /* store original flags for last packet and reset FIN and PSH */ tcp_flags = tcp->flags; @@ -247,11 +278,11 @@ gso_segment_buffer_inline (vlib_main_t *vm, if (0 == dst_left && data_size) { vlib_prefetch_buffer_header (bufs[i + 1], LOAD); - vlib_prefetch_buffer_data (bufs[i + 1], LOAD); n_tx_bytes += bufs[i]->current_length; - gso_fixup_segmented_buf (vm, bufs[i], tcp_seq, is_l2, is_ip6, gho, - &c, tcp_flags_no_fin_psh); + gso_fixup_segmented_buf (vm, bufs[i], tcp_seq, is_l2, oflags, hdr_sz, + l4_hdr_sz, &c, tcp_flags_no_fin_psh, 1, + bufs[i + 1]); i++; dst_left = size; dst_ptr = vlib_buffer_get_current (bufs[i]) + hdr_sz; @@ -264,8 +295,8 @@ gso_segment_buffer_inline (vlib_main_t *vm, ASSERT ((i + 1) == n_alloc); n_tx_bytes += bufs[i]->current_length; - gso_fixup_segmented_buf (vm, bufs[i], tcp_seq, is_l2, is_ip6, gho, &c, - tcp_flags); + gso_fixup_segmented_buf (vm, bufs[i], tcp_seq, is_l2, oflags, hdr_sz, + l4_hdr_sz, &c, tcp_flags, 0, NULL); vec_free (bufs); return n_tx_bytes; diff --git a/src/vnet/gso/node.c b/src/vnet/gso/node.c index 910f1585e7f..c1d4459476e 100644 --- a/src/vnet/gso/node.c +++ b/src/vnet/gso/node.c @@ -80,113 +80,108 @@ format_gso_trace (u8 * s, va_list * args) return s; } -static_always_inline u16 -tso_segment_ipip_tunnel_fixup (vlib_main_t * vm, - vnet_interface_per_thread_data_t * ptd, - vlib_buffer_t * sb0, - generic_header_offset_t * gho) +static_always_inline void +tso_segment_ipip_tunnel_fixup (vlib_main_t *vm, + vnet_interface_per_thread_data_t *ptd, + vlib_buffer_t *sb0) { u16 n_tx_bufs = vec_len (ptd->split_buffers); - u16 i = 0, n_tx_bytes = 0; + u16 i = 0; while (i < n_tx_bufs) { vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[i]); + i16 outer_l3_hdr_offset = vnet_buffer2 (b0)->outer_l3_hdr_offset; + i16 l3_hdr_offset = vnet_buffer (b0)->l3_hdr_offset; - ip4_header_t *ip4 = - (ip4_header_t *) (vlib_buffer_get_current (b0) + - gho->outer_l3_hdr_offset); - ip6_header_t *ip6 = - (ip6_header_t *) (vlib_buffer_get_current (b0) + - gho->outer_l3_hdr_offset); + ip4_header_t *ip4 = (ip4_header_t *) (b0->data + outer_l3_hdr_offset); + ip6_header_t *ip6 = (ip6_header_t *) (b0->data + outer_l3_hdr_offset); - if (gho->gho_flags & GHO_F_OUTER_IP4) + if (vnet_buffer (b0)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM) { - ip4->length = - clib_host_to_net_u16 (b0->current_length - - gho->outer_l3_hdr_offset); + ip4->length = clib_host_to_net_u16 ( + b0->current_length - (outer_l3_hdr_offset - b0->current_data)); ip4->checksum = ip4_header_checksum (ip4); + vnet_buffer_offload_flags_clear ( + b0, VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM | + VNET_BUFFER_OFFLOAD_F_TNL_IPIP); } - else if (gho->gho_flags & GHO_F_OUTER_IP6) + else { - ip6->payload_length = - clib_host_to_net_u16 (b0->current_length - - gho->outer_l4_hdr_offset); + ip6->payload_length = clib_host_to_net_u16 ( + b0->current_length - (l3_hdr_offset - b0->current_data)); + vnet_buffer_offload_flags_clear (b0, VNET_BUFFER_OFFLOAD_F_TNL_IPIP); } - n_tx_bytes += gho->outer_hdr_sz; i++; } - return n_tx_bytes; } static_always_inline void -tso_segment_vxlan_tunnel_headers_fixup (vlib_main_t * vm, vlib_buffer_t * b, - generic_header_offset_t * gho) +tso_segment_vxlan_tunnel_headers_fixup (vlib_main_t *vm, vlib_buffer_t *b) { - u8 proto = 0; ip4_header_t *ip4 = 0; ip6_header_t *ip6 = 0; udp_header_t *udp = 0; + i16 outer_l3_hdr_offset = vnet_buffer2 (b)->outer_l3_hdr_offset; + i16 outer_l4_hdr_offset = vnet_buffer2 (b)->outer_l4_hdr_offset; - ip4 = - (ip4_header_t *) (vlib_buffer_get_current (b) + gho->outer_l3_hdr_offset); - ip6 = - (ip6_header_t *) (vlib_buffer_get_current (b) + gho->outer_l3_hdr_offset); - udp = - (udp_header_t *) (vlib_buffer_get_current (b) + gho->outer_l4_hdr_offset); + ip4 = (ip4_header_t *) (b->data + outer_l3_hdr_offset); + ip6 = (ip6_header_t *) (b->data + outer_l3_hdr_offset); + udp = (udp_header_t *) (b->data + outer_l4_hdr_offset); - if (gho->gho_flags & GHO_F_OUTER_IP4) + if (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM) { - proto = ip4->protocol; - ip4->length = - clib_host_to_net_u16 (b->current_length - gho->outer_l3_hdr_offset); + ip4->length = clib_host_to_net_u16 ( + b->current_length - (outer_l3_hdr_offset - b->current_data)); ip4->checksum = ip4_header_checksum (ip4); + if (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_UDP_CKSUM) + { + udp->length = clib_host_to_net_u16 ( + b->current_length - (outer_l4_hdr_offset - b->current_data)); + // udp checksum is 0, in udp tunnel + udp->checksum = 0; + } + vnet_buffer_offload_flags_clear ( + b, VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM | + VNET_BUFFER_OFFLOAD_F_OUTER_UDP_CKSUM | + VNET_BUFFER_OFFLOAD_F_TNL_VXLAN); } - else if (gho->gho_flags & GHO_F_OUTER_IP6) - { - proto = ip6->protocol; - ip6->payload_length = - clib_host_to_net_u16 (b->current_length - gho->outer_l4_hdr_offset); - } - if (proto == IP_PROTOCOL_UDP) + else { - int bogus; - udp->length = - clib_host_to_net_u16 (b->current_length - gho->outer_l4_hdr_offset); - udp->checksum = 0; - if (gho->gho_flags & GHO_F_OUTER_IP6) + ip6->payload_length = clib_host_to_net_u16 ( + b->current_length - (outer_l4_hdr_offset - b->current_data)); + + if (vnet_buffer (b)->oflags & VNET_BUFFER_OFFLOAD_F_OUTER_UDP_CKSUM) { + int bogus; + udp->length = ip6->payload_length; + // udp checksum is 0, in udp tunnel + udp->checksum = 0; udp->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus); + vnet_buffer_offload_flags_clear ( + b, VNET_BUFFER_OFFLOAD_F_OUTER_UDP_CKSUM | + VNET_BUFFER_OFFLOAD_F_TNL_VXLAN); } - else if (gho->gho_flags & GHO_F_OUTER_IP4) - { - udp->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4); - } - /* FIXME: it should be OUTER_UDP_CKSUM */ - vnet_buffer_offload_flags_clear (b, VNET_BUFFER_OFFLOAD_F_UDP_CKSUM); } } -static_always_inline u16 -tso_segment_vxlan_tunnel_fixup (vlib_main_t * vm, - vnet_interface_per_thread_data_t * ptd, - vlib_buffer_t * sb0, - generic_header_offset_t * gho) +static_always_inline void +tso_segment_vxlan_tunnel_fixup (vlib_main_t *vm, + vnet_interface_per_thread_data_t *ptd, + vlib_buffer_t *sb0) { u16 n_tx_bufs = vec_len (ptd->split_buffers); - u16 i = 0, n_tx_bytes = 0; + u16 i = 0; while (i < n_tx_bufs) { vlib_buffer_t *b0 = vlib_get_buffer (vm, ptd->split_buffers[i]); - tso_segment_vxlan_tunnel_headers_fixup (vm, b0, gho); - n_tx_bytes += gho->outer_hdr_sz; + tso_segment_vxlan_tunnel_headers_fixup (vm, b0); i++; } - return n_tx_bytes; } static_always_inline u16 @@ -682,32 +677,10 @@ vnet_gso_node_inline (vlib_main_t * vm, to_next -= 1; n_left_to_next += 1; /* undo the counting. */ - generic_header_offset_t gho = { 0 }; u32 n_tx_bytes = 0; - u32 inner_is_ip6 = is_ip6; - - vnet_generic_header_offset_parser (b[0], &gho, is_l2, - is_ip4, is_ip6); - - if (PREDICT_FALSE (gho.gho_flags & GHO_F_TUNNEL)) - { - if (PREDICT_FALSE - (gho.gho_flags & (GHO_F_GRE_TUNNEL | - GHO_F_GENEVE_TUNNEL))) - { - /* not supported yet */ - drop_one_buffer_and_count (vm, vnm, node, from - 1, - hi->sw_if_index, - GSO_ERROR_UNHANDLED_TYPE); - b += 1; - continue; - } - inner_is_ip6 = (gho.gho_flags & GHO_F_IP6) != 0; - } - - n_tx_bytes = gso_segment_buffer_inline (vm, ptd, b[0], &gho, - is_l2, inner_is_ip6); + n_tx_bytes = + gso_segment_buffer_inline (vm, ptd, b[0], is_l2); if (PREDICT_FALSE (n_tx_bytes == 0)) { @@ -718,19 +691,15 @@ vnet_gso_node_inline (vlib_main_t * vm, continue; } - - if (PREDICT_FALSE (gho.gho_flags & GHO_F_VXLAN_TUNNEL)) + if (PREDICT_FALSE (vnet_buffer (b[0])->oflags & + VNET_BUFFER_OFFLOAD_F_TNL_VXLAN)) { - n_tx_bytes += - tso_segment_vxlan_tunnel_fixup (vm, ptd, b[0], &gho); + tso_segment_vxlan_tunnel_fixup (vm, ptd, b[0]); } - else - if (PREDICT_FALSE - (gho.gho_flags & (GHO_F_IPIP_TUNNEL | - GHO_F_IPIP6_TUNNEL))) + else if (PREDICT_FALSE (vnet_buffer (b[0])->oflags & + VNET_BUFFER_OFFLOAD_F_TNL_IPIP)) { - n_tx_bytes += - tso_segment_ipip_tunnel_fixup (vm, ptd, b[0], &gho); + tso_segment_ipip_tunnel_fixup (vm, ptd, b[0]); } u16 n_tx_bufs = vec_len (ptd->split_buffers); @@ -744,7 +713,6 @@ vnet_gso_node_inline (vlib_main_t * vm, { sbi0 = to_next[0] = from_seg[0]; sb0 = vlib_get_buffer (vm, sbi0); - vnet_buffer_offload_flags_clear (sb0, 0x7F); ASSERT (sb0->current_length > 0); to_next += 1; from_seg += 1; diff --git a/src/vnet/interface_api.c b/src/vnet/interface_api.c index 2995836672d..c727e519138 100644 --- a/src/vnet/interface_api.c +++ b/src/vnet/interface_api.c @@ -1020,21 +1020,19 @@ vl_api_sw_interface_set_interface_name_t_handler ( { vl_api_sw_interface_set_interface_name_reply_t *rmp; vnet_main_t *vnm = vnet_get_main (); - u32 sw_if_index = ntohl (mp->sw_if_index); - vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); clib_error_t *error; int rv = 0; + VALIDATE_SW_IF_INDEX (mp); + + u32 sw_if_index = ntohl (mp->sw_if_index); + vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); + if (mp->name[0] == 0) { rv = VNET_API_ERROR_INVALID_VALUE; goto out; } - if (si == 0) - { - rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; - goto out; - } error = vnet_rename_interface (vnm, si->hw_if_index, (char *) mp->name); if (error) @@ -1044,6 +1042,7 @@ vl_api_sw_interface_set_interface_name_t_handler ( } out: + BAD_SW_IF_INDEX_LABEL; REPLY_MACRO (VL_API_SW_INTERFACE_SET_INTERFACE_NAME_REPLY); } diff --git a/src/vnet/ip-neighbor/ip_neighbor.c b/src/vnet/ip-neighbor/ip_neighbor.c index d340037a15d..614b78489cd 100644 --- a/src/vnet/ip-neighbor/ip_neighbor.c +++ b/src/vnet/ip-neighbor/ip_neighbor.c @@ -460,6 +460,7 @@ ip_neighbor_destroy (ip_neighbor_t * ipn) af = ip_neighbor_get_af (ipn); IP_NEIGHBOR_DBG ("free: %U", format_ip_neighbor, + vlib_time_now (vlib_get_main ()), ip_neighbor_get_index (ipn)); ip_neighbor_publish (ip_neighbor_get_index (ipn), @@ -944,20 +945,20 @@ ip_neighbor_show_sorted_i (vlib_main_t * vm, vlib_cli_command_t * cmd, ip_address_family_t af) { ip_neighbor_elt_t *elt, *head; + f64 now; head = pool_elt_at_index (ip_neighbor_elt_pool, ip_neighbor_list_head[af]); + now = vlib_time_now (vm); - - vlib_cli_output (vm, "%=12s%=40s%=6s%=20s%=24s", "Time", "IP", - "Flags", "Ethernet", "Interface"); + vlib_cli_output (vm, "%=12s%=40s%=6s%=20s%=24s", "Age", "IP", "Flags", + "Ethernet", "Interface"); /* the list is time sorted, newest first, so start from the back * and work forwards. Stop when we get to one that is alive */ - clib_llist_foreach_reverse(ip_neighbor_elt_pool, - ipne_anchor, head, elt, - ({ - vlib_cli_output (vm, "%U", format_ip_neighbor, elt->ipne_index); - })); + clib_llist_foreach_reverse (ip_neighbor_elt_pool, ipne_anchor, head, elt, ({ + vlib_cli_output (vm, "%U", format_ip_neighbor, + now, elt->ipne_index); + })); return (NULL); } @@ -969,6 +970,7 @@ ip_neighbor_show_i (vlib_main_t * vm, { index_t *ipni, *ipnis = NULL; u32 sw_if_index; + f64 now; /* Filter entries by interface if given. */ sw_if_index = ~0; @@ -976,14 +978,15 @@ ip_neighbor_show_i (vlib_main_t * vm, &sw_if_index); ipnis = ip_neighbor_entries (sw_if_index, af); + now = vlib_time_now (vm); if (ipnis) - vlib_cli_output (vm, "%=12s%=40s%=6s%=20s%=24s", "Time", "IP", - "Flags", "Ethernet", "Interface"); + vlib_cli_output (vm, "%=12s%=40s%=6s%=20s%=24s", "Age", "IP", "Flags", + "Ethernet", "Interface"); vec_foreach (ipni, ipnis) { - vlib_cli_output (vm, "%U", format_ip_neighbor, *ipni); + vlib_cli_output (vm, "%U", format_ip_neighbor, now, *ipni); } vec_free (ipnis); @@ -1573,13 +1576,12 @@ ip_neighbour_age_out (index_t ipni, f64 now, f64 * wait) if (ttl > ipndb_age) { - IP_NEIGHBOR_DBG ("aged: %U @%f - %f > %d", - format_ip_neighbor, ipni, now, - ipn->ipn_time_last_updated, ipndb_age); + IP_NEIGHBOR_DBG ("aged: %U @%f - %f > %d", format_ip_neighbor, now, ipni, + now, ipn->ipn_time_last_updated, ipndb_age); if (ipn->ipn_n_probes > 2) { /* 3 strikes and yea-re out */ - IP_NEIGHBOR_DBG ("dead: %U", format_ip_neighbor, ipni); + IP_NEIGHBOR_DBG ("dead: %U", format_ip_neighbor, now, ipni); *wait = 1; return (IP_NEIGHBOR_AGE_DEAD); } diff --git a/src/vnet/ip-neighbor/ip_neighbor_types.c b/src/vnet/ip-neighbor/ip_neighbor_types.c index 39039a48249..a6f3c26d42f 100644 --- a/src/vnet/ip-neighbor/ip_neighbor_types.c +++ b/src/vnet/ip-neighbor/ip_neighbor_types.c @@ -68,19 +68,18 @@ format_ip_neighbor_watcher (u8 * s, va_list * va) u8 * format_ip_neighbor (u8 * s, va_list * va) { + f64 now = va_arg (*va, f64); index_t ipni = va_arg (*va, index_t); ip_neighbor_t *ipn; ipn = ip_neighbor_get (ipni); - return (format (s, "%=12U%=40U%=6U%=20U%U", - format_vlib_time, vlib_get_main (), - ipn->ipn_time_last_updated, - format_ip_address, &ipn->ipn_key->ipnk_ip, - format_ip_neighbor_flags, ipn->ipn_flags, - format_mac_address_t, &ipn->ipn_mac, - format_vnet_sw_if_index_name, vnet_get_main (), - ipn->ipn_key->ipnk_sw_if_index)); + return ( + format (s, "%=12U%=40U%=6U%=20U%U", format_vlib_time, vlib_get_main (), + now - ipn->ipn_time_last_updated, format_ip_address, + &ipn->ipn_key->ipnk_ip, format_ip_neighbor_flags, ipn->ipn_flags, + format_mac_address_t, &ipn->ipn_mac, format_vnet_sw_if_index_name, + vnet_get_main (), ipn->ipn_key->ipnk_sw_if_index)); } static void diff --git a/src/vnet/ip/icmp4.c b/src/vnet/ip/icmp4.c index 452817dd9c1..fa4a0e12276 100644 --- a/src/vnet/ip/icmp4.c +++ b/src/vnet/ip/icmp4.c @@ -341,7 +341,7 @@ ip4_icmp_error (vlib_main_t * vm, /* Prefer a source address from "offending interface" */ if (!ip4_sas_by_sw_if_index (sw_if_index0, &out_ip0->dst_address, &out_ip0->src_address)) - { /* interface has no IP6 address - should not happen */ + { /* interface has no IP4 address - should not happen */ next0 = IP4_ICMP_ERROR_NEXT_DROP; error0 = ICMP4_ERROR_DROP; } diff --git a/src/vnet/ip/ip.c b/src/vnet/ip/ip.c index d045c2f37c1..586f7dfbc85 100644 --- a/src/vnet/ip/ip.c +++ b/src/vnet/ip/ip.c @@ -201,7 +201,8 @@ ip_feature_enable_disable (ip_address_family_t af, } int -ip_flow_hash_set (ip_address_family_t af, u32 table_id, u32 flow_hash_config) +ip_flow_hash_set (ip_address_family_t af, u32 table_id, + flow_hash_config_t flow_hash_config) { fib_protocol_t fproto; u32 fib_index; diff --git a/src/vnet/ipip/ipip_api.c b/src/vnet/ipip/ipip_api.c index dcd3ec875df..2cb7bdf8dae 100644 --- a/src/vnet/ipip/ipip_api.c +++ b/src/vnet/ipip/ipip_api.c @@ -125,22 +125,23 @@ send_ipip_tunnel_details (ipip_tunnel_t * t, vl_api_ipip_tunnel_dump_t * mp) ipip_main_t *im = &ipip_main; vl_api_ipip_tunnel_details_t *rmp; bool is_ipv6 = t->transport == IPIP_TRANSPORT_IP6 ? true : false; + ip46_type_t ip_type = is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4; fib_table_t *ft; ft = fib_table_get (t->fib_index, (is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4)); - REPLY_MACRO_DETAILS2(VL_API_IPIP_TUNNEL_DETAILS, - ({ - ip_address_encode (&t->tunnel_src, IP46_TYPE_ANY, &rmp->tunnel.src); - ip_address_encode (&t->tunnel_dst, IP46_TYPE_ANY, &rmp->tunnel.dst); - rmp->tunnel.table_id = htonl (ft->ft_table_id); - rmp->tunnel.instance = htonl (t->user_instance); - rmp->tunnel.sw_if_index = htonl (t->sw_if_index); - rmp->tunnel.dscp = ip_dscp_encode(t->dscp); - rmp->tunnel.flags = tunnel_encap_decap_flags_encode(t->flags); - rmp->tunnel.mode = ipip_tunnel_mode_encode (t->mode); - })); + REPLY_MACRO_DETAILS2 ( + VL_API_IPIP_TUNNEL_DETAILS, ({ + ip_address_encode (&t->tunnel_src, ip_type, &rmp->tunnel.src); + ip_address_encode (&t->tunnel_dst, ip_type, &rmp->tunnel.dst); + rmp->tunnel.table_id = htonl (ft->ft_table_id); + rmp->tunnel.instance = htonl (t->user_instance); + rmp->tunnel.sw_if_index = htonl (t->sw_if_index); + rmp->tunnel.dscp = ip_dscp_encode (t->dscp); + rmp->tunnel.flags = tunnel_encap_decap_flags_encode (t->flags); + rmp->tunnel.mode = ipip_tunnel_mode_encode (t->mode); + })); } static void diff --git a/src/vnet/ipsec/ipsec_itf.c b/src/vnet/ipsec/ipsec_itf.c index 6e66d10660b..b86bf6a110c 100644 --- a/src/vnet/ipsec/ipsec_itf.c +++ b/src/vnet/ipsec/ipsec_itf.c @@ -381,6 +381,7 @@ ipsec_itf_create_cli (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; + tunnel_mode_t mode = TUNNEL_MODE_P2P; u32 instance, sw_if_index; clib_error_t *error; mac_address_t mac; @@ -396,6 +397,8 @@ ipsec_itf_create_cli (vlib_main_t * vm, { if (unformat (line_input, "instance %d", &instance)) ; + else if (unformat (line_input, "p2mp")) + mode = TUNNEL_MODE_MP; else { error = clib_error_return (0, "unknown input: %U", @@ -410,7 +413,7 @@ ipsec_itf_create_cli (vlib_main_t * vm, return error; } - rv = ipsec_itf_create (instance, TUNNEL_MODE_P2P, &sw_if_index); + rv = ipsec_itf_create (instance, mode, &sw_if_index); if (rv) return clib_error_return (0, "iPSec interface create failed"); @@ -425,13 +428,13 @@ ipsec_itf_create_cli (vlib_main_t * vm, * * @cliexpar * The following two command syntaxes are equivalent: - * @cliexcmd{ipsec itf create [instance <instance>]} + * @cliexcmd{ipsec itf create [instance <instance>] [p2mp]} * Example of how to create a ipsec interface: * @cliexcmd{ipsec itf create} ?*/ VLIB_CLI_COMMAND (ipsec_itf_create_command, static) = { .path = "ipsec itf create", - .short_help = "ipsec itf create [instance <instance>]", + .short_help = "ipsec itf create [instance <instance>] [p2mp]", .function = ipsec_itf_create_cli, }; diff --git a/src/vnet/pg/input.c b/src/vnet/pg/input.c index f81485de65f..321472c4d85 100644 --- a/src/vnet/pg/input.c +++ b/src/vnet/pg/input.c @@ -1578,7 +1578,7 @@ fill_buffer_offload_flags (vlib_main_t *vm, u32 *buffers, u32 n_buffers, (VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_L2_HDR_OFFSET_VALID | VNET_BUFFER_F_L3_HDR_OFFSET_VALID | VNET_BUFFER_F_L4_HDR_OFFSET_VALID); - if (buffer_oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM) + if (buffer_oflags & VNET_BUFFER_OFFLOAD_F_IP_CKSUM || gso_enabled) oflags |= VNET_BUFFER_OFFLOAD_F_IP_CKSUM; } else if (PREDICT_TRUE (ethertype == ETHERNET_TYPE_IP6)) @@ -1596,7 +1596,7 @@ fill_buffer_offload_flags (vlib_main_t *vm, u32 *buffers, u32 n_buffers, if (l4_proto == IP_PROTOCOL_TCP) { - if (buffer_oflags & VNET_BUFFER_OFFLOAD_F_TCP_CKSUM) + if (buffer_oflags & VNET_BUFFER_OFFLOAD_F_TCP_CKSUM || gso_enabled) oflags |= VNET_BUFFER_OFFLOAD_F_TCP_CKSUM; /* only set GSO flag for chained buffers */ diff --git a/src/vnet/session/application.h b/src/vnet/session/application.h index 5fea61bdab4..c68a911230f 100644 --- a/src/vnet/session/application.h +++ b/src/vnet/session/application.h @@ -342,7 +342,7 @@ session_error_t app_worker_start_listen (app_worker_t *app_wrk, int app_worker_stop_listen (app_worker_t * app_wrk, app_listener_t * al); int app_worker_init_accepted (session_t * s); int app_worker_listened_notify (app_worker_t *app_wrk, session_handle_t alsh, - u32 opaque, int err); + u32 opaque, session_error_t err); int app_worker_unlisten_reply (app_worker_t *app_wrk, session_handle_t sh, u32 opaque, session_error_t err); int app_worker_accept_notify (app_worker_t * app_wrk, session_t * s); diff --git a/src/vnet/session/application_interface.c b/src/vnet/session/application_interface.c index 86f3dcdece6..a62f914d43a 100644 --- a/src/vnet/session/application_interface.c +++ b/src/vnet/session/application_interface.c @@ -106,8 +106,8 @@ parse_uri (char *uri, session_endpoint_cfg_t *sep) return 0; } -int -vnet_bind_uri (vnet_listen_args_t * a) +session_error_t +vnet_bind_uri (vnet_listen_args_t *a) { session_endpoint_cfg_t sep = SESSION_ENDPOINT_CFG_NULL; int rv; diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c index e1a93a6e250..67e7ee39001 100644 --- a/src/vnet/session/session.c +++ b/src/vnet/session/session.c @@ -273,7 +273,7 @@ session_cleanup_notify (session_t * s, session_cleanup_ntf_t ntf) app_worker_t *app_wrk; app_wrk = app_worker_get_if_valid (s->app_wrk_index); - if (!app_wrk) + if (PREDICT_FALSE (!app_wrk)) { if (ntf == SESSION_CLEANUP_TRANSPORT) return; @@ -1600,11 +1600,28 @@ void session_detach_app (session_t *s) { if (s->session_state < SESSION_STATE_TRANSPORT_CLOSING) - session_close (s); - else if (s->session_state < SESSION_STATE_TRANSPORT_CLOSED) - session_set_state (s, SESSION_STATE_APP_CLOSED); - else if (s->session_state < SESSION_STATE_CLOSED) - session_set_state (s, SESSION_STATE_CLOSED); + { + session_close (s); + } + else if (s->session_state < SESSION_STATE_TRANSPORT_DELETED) + { + transport_connection_t *tc; + + /* Transport is closing but it's not yet deleted. Confirm close and + * subsequently detach transport from session and enqueue a session + * cleanup notification. Transport closed and cleanup notifications are + * going to be dropped by session layer apis */ + transport_close (session_get_transport_proto (s), s->connection_index, + s->thread_index); + tc = session_get_transport (s); + tc->s_index = SESSION_INVALID_INDEX; + session_set_state (s, SESSION_STATE_TRANSPORT_DELETED); + session_cleanup_notify (s, SESSION_CLEANUP_SESSION); + } + else + { + session_cleanup_notify (s, SESSION_CLEANUP_SESSION); + } s->flags |= SESSION_F_APP_CLOSED; s->app_wrk_index = APP_INVALID_INDEX; diff --git a/src/vnet/srmpls/FEATURE.yaml b/src/vnet/srmpls/FEATURE.yaml deleted file mode 100644 index c5b958224c7..00000000000 --- a/src/vnet/srmpls/FEATURE.yaml +++ /dev/null @@ -1,9 +0,0 @@ ---- -name: Segment Routing for MPLS -maintainer: Pablo Camarillo <pcamaril@cisco.com> -features: - - SR Policy support - - Automated steering (SR steering based on NextHop/Color) -description: "SR-MPLS" -state: production -properties: [API, CLI, MULTITHREAD] diff --git a/src/vnet/srmpls/dir.dox b/src/vnet/srmpls/dir.dox deleted file mode 100644 index 76ec1d6a41b..00000000000 --- a/src/vnet/srmpls/dir.dox +++ /dev/null @@ -1,22 +0,0 @@ -/* - * - * Copyright (c) 2013 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. - */ -/** - @dir - @brief Segment Routing MPLS code - - An implementation of Segment Routing for the MPLS dataplane. - -*/
\ No newline at end of file diff --git a/src/vnet/srmpls/sr_doc.rst b/src/vnet/srmpls/sr_doc.rst deleted file mode 100644 index ed847fa0d42..00000000000 --- a/src/vnet/srmpls/sr_doc.rst +++ /dev/null @@ -1,215 +0,0 @@ -.. _srmpls_doc: - -SR-MPLS: Segment Routing for MPLS -================================= - -This is a memo intended to contain documentation of the VPP SR-MPLS -implementation. Everything that is not directly obvious should come -here. For any feedback on content that should be explained please -mailto:pcamaril@cisco.com - -Segment Routing ---------------- - -Segment routing is a network technology focused on addressing the -limitations of existing IP and Multiprotocol Label Switching (MPLS) -networks in terms of simplicity, scale, and ease of operation. It is a -foundation for application engineered routing as it prepares the -networks for new business models where applications can control the -network behavior. - -Segment routing seeks the right balance between distributed intelligence -and centralized optimization and programming. It was built for the -software-defined networking (SDN) era. - -Segment routing enhances packet forwarding behavior by enabling a -network to transport unicast packets through a specific forwarding path, -different from the normal path that a packet usually takes (IGP shortest -path or BGP best path). This capability benefits many use cases, and one -can build those specific paths based on application requirements. - -Segment routing uses the source routing paradigm. A node, usually a -router but also a switch, a trusted server, or a virtual forwarder -running on a hypervisor, steers a packet through an ordered list of -instructions, called segments. A segment can represent any instruction, -topological or service-based. A segment can have a local semantic to a -segment-routing node or global within a segment-routing network. Segment -routing allows an operator to enforce a flow through any topological -path and service chain while maintaining per-flow state only at the -ingress node to the segment-routing network. Segment routing also -supports equal-cost multipath (ECMP) by design. - -Segment routing can operate with either an MPLS or an IPv6 data plane. -All the currently available MPLS services, such as Layer 3 VPN (L3VPN), -L2VPN (Virtual Private Wire Service [VPWS], Virtual Private LAN Services -[VPLS], Ethernet VPN [E-VPN], and Provider Backbone Bridging Ethernet -VPN [PBB-EVPN]), can run on top of a segment-routing transport network. - -**The implementation of Segment Routing in VPP covers both the IPv6 data -plane (SRv6) as well as the MPLS data plane (SR-MPLS). This page -contains the SR-MPLS documentation.** - -Segment Routing terminology ---------------------------- - -- SegmentID (SID): is an MPLS label. -- Segment List (SL) (SID List): is the sequence of SIDs that the packet - will traverse. -- SR Policy: is a set of candidate paths (SID list+weight). An SR - policy is uniquely identified by its Binding SID and associated with - a weighted set of Segment Lists. In case several SID lists are - defined, traffic steered into the policy is unevenly load-balanced - among them according to their respective weights. -- BindingSID: a BindingSID is a SID (only one) associated one-one with - an SR Policy. If a packet arrives with MPLS label corresponding to a - BindingSID, then the SR policy will be applied to such packet. - (BindingSID is popped first.) - -SR-MPLS features in VPP ------------------------ - -The SR-MPLS implementation is focused on the SR policies, as well on its -steering. Others SR-MPLS features, such as for example AdjSIDs, can be -achieved using the regular VPP MPLS implementation. - -The Segment Routing Policy -(*draft-filsfils-spring-segment-routing-policy*) defines SR Policies. - -Creating a SR Policy --------------------- - -An SR Policy is defined by a Binding SID and a weighted set of Segment -Lists. - -A new SR policy is created with a first SID list using: - -:: - - sr mpls policy add bsid 40001 next 16001 next 16002 next 16003 (weight 5) - -- The weight parameter is only used if more than one SID list is - associated with the policy. - -An SR policy is deleted with: - -:: - - sr mpls policy del bsid 40001 - -The existing SR policies are listed with: - -:: - - show sr mpls policies - -Adding/Removing SID Lists from an SR policy -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -An additional SID list is associated with an existing SR policy with: - -:: - - sr mpls policy mod bsid 40001 add sl next 16001 next 16002 next 16003 (weight 3) - -Conversely, a SID list can be removed from an SR policy with: - -:: - - sr mpls policy mod bsid 4001 del sl index 1 - -Note that this CLI cannot be used to remove the last SID list of a -policy. Instead the SR policy delete CLI must be used. - -The weight of a SID list can also be modified with: - -:: - - sr mpls policy mod bsid 40001 mod sl index 1 weight 4 - -SR Policies: Spray policies -~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Spray policies are a specific type of SR policies where the packet is -replicated on all the SID lists, rather than load-balanced among them. - -SID list weights are ignored with this type of policies. - -A Spray policy is instantiated by appending the keyword **spray** to a -regular SR-MPLS policy command, as in: - -:: - - sr mpls policy add bsid 40002 next 16001 next 16002 next 16003 spray - -Spray policies are used for removing multicast state from a network core -domain, and instead send a linear unicast copy to every access node. The -last SID in each list accesses the multicast tree within the access -node. - -Steering packets into a SR Policy ---------------------------------- - -Segment Routing supports three methods of steering traffic into an SR -policy. - -Local steering -~~~~~~~~~~~~~~ - -In this variant incoming packets match a routing policy which directs -them on a local SR policy. - -In order to achieve this behavior the user needs to create an ‘sr -steering policy via sr policy bsid’. - -:: - - sr mpls steer l3 2001::/64 via sr policy bsid 40001 - sr mpls steer l3 2001::/64 via sr policy bsid 40001 fib-table 3 - sr mpls steer l3 10.0.0.0/16 via sr policy bsid 40001 - sr mpls steer l3 10.0.0.0/16 via sr policy bsid 40001 vpn-label 500 - -Remote steering -~~~~~~~~~~~~~~~ - -In this variant incoming packets have an active SID matching a local -BSID at the head-end. - -In order to achieve this behavior the packets should simply arrive with -an active SID equal to the Binding SID of a locally instantiated SR -policy. - -Automated steering -~~~~~~~~~~~~~~~~~~ - -In this variant incoming packets match a BGP/Service route which -recurses on the BSID of a local policy. - -In order to achieve this behavior the user first needs to color the SR -policies. He can do so by using the CLI: - -:: - - sr mpls policy te bsid xxxxx endpoint x.x.x.x color 12341234 - -Notice that an SR policy can have a single endpoint and a single color. -Notice that the *endpoint* value is an IP46 address and the color a u32. - -Then, for any BGP/Service route the user has to use the API to steer -prefixes: - -:: - - sr steer l3 2001::/64 via next-hop 2001::1 color 1234 co 2 - sr steer l3 2001::/64 via next-hop 2001::1 color 1234 co 2 vpn-label 500 - -Notice that *co* refers to the CO-bits (values [0|1|2|3]). - -Notice also that a given prefix might be steered over several colors -(same next-hop and same co-bit value). In order to add new colors just -execute the API several times (or with the del parameter to delete the -color). - -This variant is meant to be used in conjunction with a control plane -agent that uses the underlying binary API bindings of -*sr_mpls_steering_policy_add*/*sr_mpls_steering_policy_del* for any BGP -service route received. diff --git a/src/vnet/srmpls/sr_mpls.api b/src/vnet/srmpls/sr_mpls.api deleted file mode 100644 index 742f135d493..00000000000 --- a/src/vnet/srmpls/sr_mpls.api +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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. - */ - -option version = "3.0.0"; - -import "vnet/interface_types.api"; -import "vnet/ip/ip_types.api"; -import "vnet/srv6/sr_types.api"; - -/** \brief MPLS SR policy add - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param bsid - is the bindingSID of the SR Policy. MPLS label (20bit) - @param weight - is the weight of the sid list. optional. - @param is_spray - is the type of the SR policy. (0.Default // 1.Spray) - @param segments - vector of labels (20bit) composing the segment list -*/ -autoreply define sr_mpls_policy_add -{ - u32 client_index; - u32 context; - u32 bsid; - u32 weight; - bool is_spray; - u8 n_segments; - u32 segments[n_segments]; -}; - -/** \brief MPLS SR policy modification - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param bsid is the bindingSID of the SR Policy. MPLS label (20bit) - @param sr_policy_index is the index of the SR policy - @param fib_table is the VRF where to install the FIB entry for the BSID - @param operation is the operation to perform (among the top ones) - @param segments is a vector of MPLS labels composing the segment list - @param sl_index is the index of the Segment List to modify/delete - @param weight is the weight of the sid list. optional. - @param is_encap Mode. Encapsulation or SRH insertion. -*/ -autoreply define sr_mpls_policy_mod -{ - u32 client_index; - u32 context; - u32 bsid; - vl_api_sr_policy_op_t operation; - u32 sl_index; - u32 weight; - u8 n_segments; - u32 segments[n_segments]; -}; - -/** \brief MPLS SR policy deletion - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param bsid is the bindingSID of the SR Policy. MPLS label (20bit) -*/ -autoreply define sr_mpls_policy_del -{ - u32 client_index; - u32 context; - u32 bsid; -}; - -/** \brief MPLS SR steering add/del - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_del - @param bsid - is the bindingSID of the SR Policy (~0 is no bsid) - @param table_id - is the VRF where to install the FIB entry for the BSID - @param prefix - is the IPv4/v6 address for L3 traffic type. - @param mask_width - is the mask for L3 traffic type - @param next_hop - describes the next_hop (in case no BSID) - @param color - describes the color - @param co_bits - are the CO_bits of the steering policy - @param vpn_label - is an additonal last VPN label. (~0 is no label) -*/ -autoreply define sr_mpls_steering_add_del -{ - u32 client_index; - u32 context; - bool is_del[default = false]; - u32 bsid; - u32 table_id; - vl_api_prefix_t prefix; - u32 mask_width; - vl_api_address_t next_hop; - u32 color; - u8 co_bits; - u32 vpn_label; -}; - -/** \brief MPLS SR steering add/del - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param bsid is the bindingSID of the SR Policy - @param endpoint is the endpoint of the SR policy - @param color is the color of the sr policy -*/ -autoreply define sr_mpls_policy_assign_endpoint_color -{ - u32 client_index; - u32 context; - u32 bsid; - vl_api_address_t endpoint; - u32 color; -}; - -/* - * fd.io coding-style-patch-verification: ON Local Variables: eval: - * (c-set-style "gnu") End: - */ diff --git a/src/vnet/srmpls/sr_mpls.h b/src/vnet/srmpls/sr_mpls.h deleted file mode 100644 index a8f9494428f..00000000000 --- a/src/vnet/srmpls/sr_mpls.h +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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. - */ - -/** - * @file - * @brief Segment Routing MPLS data structures definitions - * - */ - -#ifndef included_vnet_srmpls_h -#define included_vnet_srmpls_h - -#include <vnet/vnet.h> -#include <vnet/mpls/packet.h> -#include <vnet/fib/mpls_fib.h> -#include <vnet/ip/ip.h> -#include <vnet/ip/lookup.h> -#include <vnet/dpo/dpo.h> -#include <vnet/dpo/replicate_dpo.h> - -#include <stdlib.h> -#include <string.h> - -/* SR policy types */ -#define SR_POLICY_TYPE_DEFAULT 0 -#define SR_POLICY_TYPE_SPRAY 1 - -#define SR_SEGMENT_LIST_WEIGHT_DEFAULT 1 - -#define SR_STEER_IPV4 4 -#define SR_STEER_IPV6 6 - -#define SR_TE_CO_BITS_00 0 -#define SR_TE_CO_BITS_01 1 -#define SR_TE_CO_BITS_10 2 -#define SR_TE_CO_BITS_11 3 - -/** - * @brief SR Segment List (SID list) - */ -typedef struct -{ - /* SIDs (key) */ - mpls_label_t *segments; - - /* SID list weight (wECMP / UCMP) */ - u32 weight; - -} mpls_sr_sl_t; - -typedef struct -{ - u32 *segments_lists; /**< Pool of SID lists indexes */ - - mpls_label_t bsid; /**< BindingSID (key) */ - - u8 type; /**< Type (default is 0) */ - /* SR Policy specific DPO */ - /* IF Type = DEFAULT Then Load-Balancer DPO among SID lists */ - /* IF Type = SPRAY then Spray DPO with all SID lists */ - - ip46_address_t endpoint; /**< Optional NH for SR TE */ - u8 endpoint_type; - u32 color; /**< Optional color for SR TE */ -} mpls_sr_policy_t; - -/** - * @brief Steering db key - * - * L3 is IPv4/IPv6 + mask - */ -typedef struct -{ - ip46_address_t prefix; /**< IP address of the prefix */ - u32 mask_width; /**< Mask width of the prefix */ - u32 fib_table; /**< VRF of the prefix */ - u8 traffic_type; /**< Traffic type (IPv4, IPv6, L2) */ - u8 padding[3]; -} sr_mpls_steering_key_t; - -typedef struct -{ - sr_mpls_steering_key_t classify; /**< Traffic classification */ - mpls_label_t bsid; /**< SR Policy index */ - ip46_address_t next_hop; /**< SR TE NH */ - char nh_type; - u32 *color; /**< Vector of SR TE colors */ - char co_bits; /**< Color-Only bits */ - mpls_label_t vpn_label; -} mpls_sr_steering_policy_t; - -/** - * @brief Segment Routing main datastructure - */ -typedef struct -{ - /* SR SID lists */ - mpls_sr_sl_t *sid_lists; - - /* SR MPLS policies */ - mpls_sr_policy_t *sr_policies; - - /* Hash table mapping BindingSID to SR MPLS policy */ - uword *sr_policies_index_hash; - - /* Pool of SR steer policies instances */ - mpls_sr_steering_policy_t *steer_policies; - - /* MHash table mapping steering rules to SR steer instance */ - mhash_t sr_steer_policies_hash; - - /** SR TE **/ - /* Hash table mapping (Color->Endpoint->BSID) for SR policies */ - mhash_t sr_policies_c2e2eclabel_hash; - /* SR TE (internal) fib table (Endpoint, Color) */ - u32 fib_table_EC; - /* Pool of (Endpoint, Color) hidden labels */ - u32 *ec_labels; - - /* convenience */ - vlib_main_t *vlib_main; - vnet_main_t *vnet_main; -} mpls_sr_main_t; - -extern mpls_sr_main_t sr_mpls_main; - -extern int -sr_mpls_policy_add (mpls_label_t bsid, mpls_label_t * segments, - u8 behavior, u32 weight); - -extern int -sr_mpls_policy_mod (mpls_label_t bsid, u8 operation, - mpls_label_t * segments, u32 sl_index, u32 weight); - -extern int sr_mpls_policy_del (mpls_label_t bsid); - -extern int -sr_mpls_policy_assign_endpoint_color (mpls_label_t bsid, - ip46_address_t * endpoint, - u8 endpoint_type, u32 color); - -extern int -sr_mpls_steering_policy_add (mpls_label_t bsid, u32 table_id, - ip46_address_t * prefix, u32 mask_width, - u8 traffic_type, ip46_address_t * next_hop, - u8 nh_type, u32 color, char co_bits, - mpls_label_t vpn_label); - -extern int -sr_mpls_steering_policy_del (ip46_address_t * prefix, - u32 mask_width, u8 traffic_type, u32 table_id, - u32 color); - -extern u32 find_or_create_internal_label (ip46_address_t endpoint, u32 color); - -extern void internal_label_lock (ip46_address_t endpoint, u32 color); - -extern void internal_label_unlock (ip46_address_t endpoint, u32 color); - -#endif /* included_vnet_sr_mpls_h */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: eval: (c-set-style "gnu") End: - */ diff --git a/src/vnet/srmpls/sr_mpls_api.c b/src/vnet/srmpls/sr_mpls_api.c deleted file mode 100644 index 920856acff6..00000000000 --- a/src/vnet/srmpls/sr_mpls_api.c +++ /dev/null @@ -1,258 +0,0 @@ -/* - * ------------------------------------------------------------------ - * sr_api.c - ipv6 segment routing 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 <vnet/vnet.h> -#include <vnet/srmpls/sr_mpls.h> -#include <vlibmemory/api.h> - -#include <vnet/interface.h> -#include <vnet/api_errno.h> -#include <vnet/feature/feature.h> -#include <vnet/ip/ip_types_api.h> - -#include <vnet/format_fns.h> -#include <vnet/srmpls/sr_mpls.api_enum.h> -#include <vnet/srmpls/sr_mpls.api_types.h> - - -#define vl_api_version(n, v) static u32 api_version = v; -#include <vnet/srmpls/sr_mpls.api.h> -#undef vl_api_version - -#define vl_endianfun -#include <vnet/srmpls/sr_mpls.api.h> -#undef vl_endianfun - -#define vl_calcsizefun -#include <vnet/srmpls/sr_mpls.api.h> -#undef vl_calcsizefun - -#define vl_printfun -#include <vnet/srmpls/sr_mpls.api.h> -#undef vl_printfun - -#define vl_msg_name_crc_list -#include <vnet/srmpls/sr_mpls.api.h> -#undef vl_msg_name_crc_list - -#define REPLY_MSG_ID_BASE msg_id_base -#include <vlibapi/api_helper_macros.h> - -#define foreach_vpe_api_msg \ -_(SR_MPLS_POLICY_DEL, sr_mpls_policy_del) \ -_(SR_MPLS_STEERING_ADD_DEL, sr_mpls_steering_add_del) \ -_(SR_MPLS_POLICY_ASSIGN_ENDPOINT_COLOR, sr_mpls_policy_assign_endpoint_color) - -static u16 msg_id_base; - -static void -vl_api_sr_mpls_policy_add_t_handler (vl_api_sr_mpls_policy_add_t * mp) -{ - vl_api_sr_mpls_policy_add_reply_t *rmp; - - mpls_label_t *segments = 0, *seg; - mpls_label_t this_address = 0; - - int i; - for (i = 0; i < mp->n_segments; i++) - { - vec_add2 (segments, seg, 1); - this_address = ntohl (mp->segments[i]); - clib_memcpy (seg, &this_address, sizeof (this_address)); - } - - int rv = 0; - rv = sr_mpls_policy_add (ntohl (mp->bsid), - segments, mp->is_spray, ntohl (mp->weight)); - vec_free (segments); - - REPLY_MACRO (VL_API_SR_MPLS_POLICY_ADD_REPLY); -} - -static void -vl_api_sr_mpls_policy_mod_t_handler (vl_api_sr_mpls_policy_mod_t * mp) -{ - vl_api_sr_mpls_policy_mod_reply_t *rmp; - - mpls_label_t *segments = 0, *seg; - mpls_label_t this_address = 0; - - int i; - for (i = 0; i < mp->n_segments; i++) - { - vec_add2 (segments, seg, 1); - this_address = ntohl (mp->segments[i]); - clib_memcpy (seg, &this_address, sizeof (this_address)); - } - - int rv = 0; - rv = sr_mpls_policy_mod (ntohl (mp->bsid), - ntohl (mp->operation), segments, - ntohl (mp->sl_index), ntohl (mp->weight)); - vec_free (segments); - - REPLY_MACRO (VL_API_SR_MPLS_POLICY_MOD_REPLY); -} - -static void -vl_api_sr_mpls_policy_del_t_handler (vl_api_sr_mpls_policy_del_t * mp) -{ - vl_api_sr_mpls_policy_del_reply_t *rmp; - int rv = 0; - rv = sr_mpls_policy_del (ntohl (mp->bsid)); - - REPLY_MACRO (VL_API_SR_MPLS_POLICY_DEL_REPLY); -} - -static void vl_api_sr_mpls_steering_add_del_t_handler - (vl_api_sr_mpls_steering_add_del_t * mp) -{ - vl_api_sr_mpls_steering_add_del_reply_t *rmp; - fib_prefix_t prefix; - ip46_address_t next_hop; - clib_memset (&prefix, 0, sizeof (ip46_address_t)); - - ip_prefix_decode (&mp->prefix, &prefix); - ip_address_decode (&mp->next_hop, &next_hop); - - int rv = 0; - if (mp->is_del) - rv = sr_mpls_steering_policy_del (&prefix.fp_addr, - prefix.fp_len, - ip46_address_is_ip4 (&prefix.fp_addr) ? - SR_STEER_IPV4 : SR_STEER_IPV6, - ntohl (mp->table_id), - ntohl (mp->color)); - else - rv = sr_mpls_steering_policy_add (ntohl (mp->bsid), - ntohl (mp->table_id), - &prefix.fp_addr, - prefix.fp_len, - ip46_address_is_ip4 (&prefix.fp_addr) ? - SR_STEER_IPV4 : SR_STEER_IPV6, - &next_hop, - ip46_address_is_ip4 (&next_hop) ? - SR_STEER_IPV4 : SR_STEER_IPV6, - ntohl (mp->color), mp->co_bits, - ntohl (mp->vpn_label)); - - REPLY_MACRO (VL_API_SR_MPLS_STEERING_ADD_DEL_REPLY); -} - -static void vl_api_sr_mpls_policy_assign_endpoint_color_t_handler - (vl_api_sr_mpls_policy_assign_endpoint_color_t * mp) -{ - vl_api_sr_mpls_policy_assign_endpoint_color_reply_t *rmp; - int rv = 0; - - ip46_address_t endpoint; - clib_memset (&endpoint, 0, sizeof (ip46_address_t)); - ip_address_decode (&mp->endpoint, &endpoint); - - rv = sr_mpls_policy_assign_endpoint_color (ntohl (mp->bsid), - &endpoint, - ip46_address_is_ip4 (&endpoint) ? - SR_STEER_IPV4 : SR_STEER_IPV6, - ntohl (mp->color)); - - REPLY_MACRO (VL_API_SR_MPLS_POLICY_ASSIGN_ENDPOINT_COLOR_REPLY); -} - -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 + REPLY_MSG_ID_BASE); - foreach_vl_msg_name_crc_sr_mpls; -#undef _ -} - -static clib_error_t * -sr_mpls_api_hookup (vlib_main_t * vm) -{ - api_main_t *am = vlibapi_get_main (); - - u8 *name = format (0, "sr_mpls_%08x%c", api_version, 0); - REPLY_MSG_ID_BASE = - vl_msg_api_get_msg_ids ((char *) name, VL_MSG_SR_MPLS_LAST); - vec_free (name); - -#define _(N, n) \ - vl_msg_api_config (&(vl_msg_api_msg_config_t){ \ - .id = REPLY_MSG_ID_BASE + VL_API_##N, \ - .name = #n, \ - .handler = vl_api_##n##_t_handler, \ - .endian = vl_api_##n##_t_endian, \ - .format_fn = vl_api_##n##_t_format, \ - .size = sizeof (vl_api_##n##_t), \ - .traced = 1, \ - .tojson = vl_api_##n##_t_tojson, \ - .fromjson = vl_api_##n##_t_fromjson, \ - .calc_size = vl_api_##n##_t_calc_size, \ - }); - foreach_vpe_api_msg; -#undef _ - - /* - * Manually register the sr policy add msg, so we trace enough bytes - * to capture a typical segment list - */ - vl_msg_api_config (&(vl_msg_api_msg_config_t){ - .id = REPLY_MSG_ID_BASE + VL_API_SR_MPLS_POLICY_ADD, - .name = "sr_mpls_policy_add", - .handler = vl_api_sr_mpls_policy_add_t_handler, - .endian = vl_api_sr_mpls_policy_add_t_endian, - .format_fn = vl_api_sr_mpls_policy_add_t_format, - .size = 256, - .traced = 1, - .tojson = vl_api_sr_mpls_policy_add_t_tojson, - .fromjson = vl_api_sr_mpls_policy_add_t_fromjson, - .calc_size = vl_api_sr_mpls_policy_add_t_calc_size, - }); - /* - * Manually register the sr policy mod msg, so we trace enough bytes - * to capture a typical segment list - */ - vl_msg_api_config (&(vl_msg_api_msg_config_t){ - .id = REPLY_MSG_ID_BASE + VL_API_SR_MPLS_POLICY_MOD, - .name = "sr_mpls_policy_mod", - .handler = vl_api_sr_mpls_policy_mod_t_handler, - .endian = vl_api_sr_mpls_policy_mod_t_endian, - .format_fn = vl_api_sr_mpls_policy_mod_t_format, - .size = 256, - .traced = 1, - .tojson = vl_api_sr_mpls_policy_mod_t_tojson, - .fromjson = vl_api_sr_mpls_policy_mod_t_fromjson, - .calc_size = vl_api_sr_mpls_policy_mod_t_calc_size, - }); - - /* - * Set up the (msg_name, crc, message-id) table - */ - setup_message_id_table (am); - - return 0; -} - -VLIB_API_INIT_FUNCTION (sr_mpls_api_hookup); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: eval: (c-set-style "gnu") End: - */ diff --git a/src/vnet/srmpls/sr_mpls_policy.c b/src/vnet/srmpls/sr_mpls_policy.c deleted file mode 100644 index 41cb71601e9..00000000000 --- a/src/vnet/srmpls/sr_mpls_policy.c +++ /dev/null @@ -1,903 +0,0 @@ -/* - * sr_mpls_policy.c: SR-MPLS policies - * - * 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. - */ - -/** - * @file - * @brief SR MPLS policy creation and application - * - * Create an SR policy. - * An SR policy can be either of 'default' type or 'spray' type - * An SR policy has attached a list of SID lists. - * In case the SR policy is a default one it will load balance among them. - * An SR policy has associated a BindingSID. - * In case any packet arrives with MPLS_label == BindingSID then the SR policy - * associated to such bindingSID will be applied to such packet. - * Also, a BSID can be associated with a (Next-Hop, Color) - * - */ - -#include <vlib/vlib.h> -#include <vnet/vnet.h> -#include <vnet/srmpls/sr_mpls.h> -#include <vnet/fib/mpls_fib.h> -#include <vnet/dpo/dpo.h> -#include <vnet/ip/ip.h> - -#include <vppinfra/error.h> -#include <vppinfra/elog.h> - -mpls_sr_main_t sr_mpls_main; - -/*************************** SR LB helper functions **************************/ -/** - * @brief Creates a Segment List and adds it to an SR policy - * - * Creates a Segment List and adds it to the SR policy. Notice that the SL are - * not necessarily unique. Hence there might be two Segment List within the - * same SR Policy with exactly the same segments and same weight. - * - * @param sr_policy is the SR policy where the SL will be added - * @param sl is a vector of IPv6 addresses composing the Segment List - * @param weight is the weight of the SegmentList (for load-balancing purposes) - * @param is_encap represents the mode (SRH insertion vs Encapsulation) - * - * @return pointer to the just created segment list - */ -static inline mpls_sr_sl_t * -create_sl (mpls_sr_policy_t * sr_policy, mpls_label_t * sl, u32 weight) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - mpls_sr_sl_t *segment_list; - u32 ii; - - pool_get (sm->sid_lists, segment_list); - clib_memset (segment_list, 0, sizeof (*segment_list)); - - vec_add1 (sr_policy->segments_lists, segment_list - sm->sid_lists); - - /* Fill in segment list */ - segment_list->weight = - (weight != (u32) ~ 0 ? weight : SR_SEGMENT_LIST_WEIGHT_DEFAULT); - segment_list->segments = vec_dup (sl); - - mpls_eos_bit_t eos; - FOR_EACH_MPLS_EOS_BIT (eos) - { - fib_route_path_t path = { - .frp_proto = DPO_PROTO_MPLS, - .frp_sw_if_index = ~0, - .frp_fib_index = 0, - .frp_weight = segment_list->weight, - .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, - .frp_label_stack = NULL, - .frp_local_label = sl[0], - }; - - if (vec_len (sl) > 1) - { - vec_validate (path.frp_label_stack, vec_len (sl) - 2); - for (ii = 1; ii < vec_len (sl); ii++) - { - path.frp_label_stack[ii - 1].fml_value = sl[ii]; - } - } - else - { - /* - * add an impliciet NULL label to allow non-eos recursion - */ - fib_mpls_label_t lbl = { - .fml_value = MPLS_IETF_IMPLICIT_NULL_LABEL, - }; - vec_add1 (path.frp_label_stack, lbl); - } - - fib_route_path_t *paths = NULL; - vec_add1 (paths, path); - - fib_prefix_t pfx = { - .fp_len = 21, - .fp_proto = FIB_PROTOCOL_MPLS, - .fp_label = sr_policy->bsid, - .fp_eos = eos, - .fp_payload_proto = DPO_PROTO_MPLS, - }; - - fib_table_entry_path_add2 (0, - &pfx, - FIB_SOURCE_SR, - (sr_policy->type == SR_POLICY_TYPE_DEFAULT ? - FIB_ENTRY_FLAG_NONE : - FIB_ENTRY_FLAG_MULTICAST), paths); - vec_free (paths); - } - - return segment_list; -} - -/******************************* SR rewrite API *******************************/ -/* - * Three functions for handling sr policies: -> sr_mpls_policy_add -> - * sr_mpls_policy_del -> sr_mpls_policy_mod All of them are API. CLI function - * on sr_policy_command_fn - */ - -/** - * @brief Create a new SR policy - * - * @param bsid is the bindingSID of the SR Policy - * @param segments is a vector of MPLS labels composing the segment list - * @param behavior is the behavior of the SR policy. (default//spray) - * @param fib_table is the VRF where to install the FIB entry for the BSID - * @param weight is the weight of this specific SID list - * - * @return 0 if correct, else error - */ -int -sr_mpls_policy_add (mpls_label_t bsid, mpls_label_t * segments, - u8 behavior, u32 weight) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - mpls_sr_policy_t *sr_policy = 0; - uword *p; - - if (!sm->sr_policies_index_hash) - sm->sr_policies_index_hash = hash_create (0, sizeof (mpls_label_t)); - - /* MPLS SR policies cannot be created unless the MPLS table is present */ - if (~0 == fib_table_find (FIB_PROTOCOL_MPLS, MPLS_FIB_DEFAULT_TABLE_ID)) - return (VNET_API_ERROR_NO_SUCH_TABLE); - - /* Search for existing keys (BSID) */ - p = hash_get (sm->sr_policies_index_hash, bsid); - if (p) - { - /* Add SR policy that already exists; complain */ - return -12; - } - /* Add an SR policy object */ - pool_get (sm->sr_policies, sr_policy); - clib_memset (sr_policy, 0, sizeof (*sr_policy)); - - /* the first policy needs to lock the MPLS table so it doesn't - * disappear with policies in it */ - if (1 == pool_elts (sm->sr_policies)) - fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS, - MPLS_FIB_DEFAULT_TABLE_ID, - FIB_SOURCE_SR); - sr_policy->bsid = bsid; - sr_policy->type = behavior; - sr_policy->endpoint_type = 0; - ip6_address_set_zero (&sr_policy->endpoint.ip6); - sr_policy->color = (u32) ~ 0; - - /* Copy the key */ - hash_set (sm->sr_policies_index_hash, bsid, sr_policy - sm->sr_policies); - - /* Create a segment list and add the index to the SR policy */ - create_sl (sr_policy, segments, weight); - - return 0; -} - -/** - * @brief Delete a SR policy - * - * @param bsid is the bindingSID of the SR Policy - * @param index is the index of the SR policy - * - * @return 0 if correct, else error - */ -int -sr_mpls_policy_del (mpls_label_t bsid) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - mpls_sr_policy_t *sr_policy = 0; - mpls_sr_sl_t *segment_list; - mpls_eos_bit_t eos; - u32 *sl_index; - uword *p; - - if (!sm->sr_policies_index_hash) - sm->sr_policies_index_hash = hash_create (0, sizeof (mpls_label_t)); - - p = hash_get (sm->sr_policies_index_hash, bsid); - if (p) - sr_policy = pool_elt_at_index (sm->sr_policies, p[0]); - else - return -1; - - /* Clean SID Lists */ - vec_foreach (sl_index, sr_policy->segments_lists) - { - segment_list = pool_elt_at_index (sm->sid_lists, *sl_index); - - fib_route_path_t path = { - .frp_proto = DPO_PROTO_MPLS, - .frp_sw_if_index = ~0, - .frp_fib_index = 0, - .frp_weight = segment_list->weight, - .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, - .frp_local_label = segment_list->segments[0], - }; - - vec_add (path.frp_label_stack, segment_list + 1, - vec_len (segment_list) - 1); - - fib_route_path_t *paths = NULL; - vec_add1 (paths, path); - - /* remove each of the MPLS routes */ - FOR_EACH_MPLS_EOS_BIT (eos) - { - fib_prefix_t pfx = { - .fp_len = 21, - .fp_proto = FIB_PROTOCOL_MPLS, - .fp_label = sr_policy->bsid, - .fp_eos = eos, - .fp_payload_proto = DPO_PROTO_MPLS, - }; - - fib_table_entry_path_remove2 (0, &pfx, FIB_SOURCE_SR, paths); - } - vec_free (paths); - vec_free (segment_list->segments); - pool_put_index (sm->sid_lists, *sl_index); - } - - /* If there is still traces of TE, make sure locks are released */ - if (sr_policy->endpoint_type != 0 && sr_policy->color != (u32) ~ 0) - { - sr_mpls_policy_assign_endpoint_color (bsid, NULL, 0, (u32) ~ 0); - } - - /* Remove SR policy entry */ - hash_unset (sm->sr_policies_index_hash, sr_policy->bsid); - pool_put (sm->sr_policies, sr_policy); - - if (0 == pool_elts (sm->sr_policies)) - fib_table_unlock (MPLS_FIB_DEFAULT_TABLE_ID, - FIB_PROTOCOL_MPLS, FIB_SOURCE_SR); - - return 0; -} - -/** - * @brief Modify an existing SR policy - * - * The possible modifications are adding a new Segment List, modifying an - * existing Segment List (modify the weight only) and delete a given - * Segment List from the SR Policy. - * - * @param bsid is the bindingSID of the SR Policy - * @param fib_table is the VRF where to install the FIB entry for the BSID - * @param operation is the operation to perform (among the top ones) - * @param segments is a vector of IPv6 address composing the segment list - * @param sl_index is the index of the Segment List to modify/delete - * @param weight is the weight of the sid list. optional. - * - * @return 0 ok, >0 index of SL, <0 error - */ -int -sr_mpls_policy_mod (mpls_label_t bsid, u8 operation, - mpls_label_t * segments, u32 sl_index, u32 weight) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - mpls_sr_policy_t *sr_policy = 0; - mpls_sr_sl_t *segment_list; - u32 *sl_index_iterate; - uword *p; - - if (!sm->sr_policies_index_hash) - sm->sr_policies_index_hash = hash_create (0, sizeof (mpls_label_t)); - - p = hash_get (sm->sr_policies_index_hash, bsid); - if (p) - sr_policy = pool_elt_at_index (sm->sr_policies, p[0]); - else - return -1; - - if (operation == 1) - { /* Add SR List to an existing SR policy */ - /* Create the new SL */ - segment_list = create_sl (sr_policy, segments, weight); - return segment_list - sm->sid_lists; - } - else if (operation == 2) - { /* Delete SR List from an existing SR - * policy */ - /* Check that currently there are more than one SID list */ - if (vec_len (sr_policy->segments_lists) == 1) - return -21; - - /* - * Check that the SR list does exist and is assigned to the - * sr policy - */ - vec_foreach (sl_index_iterate, sr_policy->segments_lists) - if (*sl_index_iterate == sl_index) - break; - - if (*sl_index_iterate != sl_index) - return -22; - - /* Remove the lucky SR list that is being kicked out */ - segment_list = pool_elt_at_index (sm->sid_lists, sl_index); - - mpls_eos_bit_t eos; - fib_route_path_t path = { - .frp_proto = DPO_PROTO_MPLS, - .frp_sw_if_index = ~0, - .frp_fib_index = 0, - .frp_weight = segment_list->weight, - .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, - .frp_local_label = segment_list->segments[0], - }; - - vec_add (path.frp_label_stack, segment_list + 1, - vec_len (segment_list) - 1); - - fib_route_path_t *paths = NULL; - vec_add1 (paths, path); - - FOR_EACH_MPLS_EOS_BIT (eos) - { - fib_prefix_t pfx = { - .fp_len = 21, - .fp_proto = FIB_PROTOCOL_MPLS, - .fp_label = sr_policy->bsid, - .fp_eos = eos, - .fp_payload_proto = DPO_PROTO_MPLS, - }; - - fib_table_entry_path_remove2 (0, &pfx, FIB_SOURCE_SR, paths); - } - - vec_free (paths); - vec_free (segment_list->segments); - pool_put_index (sm->sid_lists, sl_index); - vec_del1 (sr_policy->segments_lists, - sl_index_iterate - sr_policy->segments_lists); - } - else if (operation == 3) - { /* Modify the weight of an existing - * SR List */ - /* Find the corresponding SL */ - vec_foreach (sl_index_iterate, sr_policy->segments_lists) - if (*sl_index_iterate == sl_index) - break; - - if (*sl_index_iterate != sl_index) - return -32; - - /* Change the weight */ - segment_list = pool_elt_at_index (sm->sid_lists, sl_index); - - /* Update LB */ - mpls_eos_bit_t eos; - fib_route_path_t path = { - .frp_proto = DPO_PROTO_MPLS, - .frp_sw_if_index = ~0, - .frp_fib_index = 0, - .frp_weight = segment_list->weight, - .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, - .frp_local_label = segment_list->segments[0], - }; - - vec_add (path.frp_label_stack, segment_list + 1, - vec_len (segment_list) - 1); - - fib_route_path_t *paths = NULL; - vec_add1 (paths, path); - - FOR_EACH_MPLS_EOS_BIT (eos) - { - fib_prefix_t pfx = { - .fp_len = 21, - .fp_proto = FIB_PROTOCOL_MPLS, - .fp_label = sr_policy->bsid, - .fp_eos = eos, - .fp_payload_proto = DPO_PROTO_MPLS, - }; - - fib_table_entry_path_remove2 (0, &pfx, FIB_SOURCE_SR, paths); - } - - segment_list->weight = weight; - - path.frp_weight = segment_list->weight; - - vec_free (paths); - paths = NULL; - vec_add1 (paths, path); - - FOR_EACH_MPLS_EOS_BIT (eos) - { - fib_prefix_t pfx = { - .fp_len = 21, - .fp_proto = FIB_PROTOCOL_MPLS, - .fp_label = sr_policy->bsid, - .fp_eos = eos, - .fp_payload_proto = DPO_PROTO_MPLS, - }; - - fib_table_entry_path_add2 (0, - &pfx, - FIB_SOURCE_SR, - (sr_policy->type == - SR_POLICY_TYPE_DEFAULT ? - FIB_ENTRY_FLAG_NONE : - FIB_ENTRY_FLAG_MULTICAST), paths); - } - } - return 0; -} - -/** - * @brief CLI for 'sr mpls policies' command family - */ -static clib_error_t * -sr_mpls_policy_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - int rv = -1; - char is_del = 0, is_add = 0, is_mod = 0; - char policy_set = 0; - mpls_label_t bsid, next_label; - u32 sl_index = (u32) ~ 0; - u32 weight = (u32) ~ 0; - mpls_label_t *segments = 0; - u8 operation = 0; - u8 is_spray = 0; - - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (!is_add && !is_mod && !is_del && unformat (input, "add")) - is_add = 1; - else if (!is_add && !is_mod && !is_del && unformat (input, "del")) - is_del = 1; - else if (!is_add && !is_mod && !is_del && unformat (input, "mod")) - is_mod = 1; - else if (!policy_set - && unformat (input, "bsid %U", unformat_mpls_unicast_label, - &bsid)) - policy_set = 1; - else if (unformat (input, "weight %d", &weight)); - else if (unformat - (input, "next %U", unformat_mpls_unicast_label, &next_label)) - { - vec_add (segments, &next_label, 1); - } - else if (unformat (input, "add sl")) - operation = 1; - else if (unformat (input, "del sl index %d", &sl_index)) - operation = 2; - else if (unformat (input, "mod sl index %d", &sl_index)) - operation = 3; - else if (unformat (input, "spray")) - is_spray = 1; - else - break; - } - - if (!is_add && !is_mod && !is_del) - return clib_error_return (0, "Incorrect CLI"); - - if (!policy_set) - return clib_error_return (0, "No SR policy BSID or index specified"); - - if (is_add) - { - if (vec_len (segments) == 0) - return clib_error_return (0, "No Segment List specified"); - - rv = sr_mpls_policy_add (bsid, segments, - (is_spray ? SR_POLICY_TYPE_SPRAY : - SR_POLICY_TYPE_DEFAULT), weight); - vec_free (segments); - } - else if (is_del) - rv = sr_mpls_policy_del (bsid); - else if (is_mod) - { - if (!operation) - return clib_error_return (0, "No SL modification specified"); - if (operation != 1 && sl_index == (u32) ~ 0) - return clib_error_return (0, "No Segment List index specified"); - if (operation == 1 && vec_len (segments) == 0) - return clib_error_return (0, "No Segment List specified"); - if (operation == 3 && weight == (u32) ~ 0) - return clib_error_return (0, "No new weight for the SL specified"); - rv = sr_mpls_policy_mod (bsid, operation, segments, sl_index, weight); - vec_free (segments); - } - switch (rv) - { - case 0: - break; - case 1: - return 0; - case -12: - return clib_error_return (0, - "There is already a FIB entry for the BindingSID address.\n" - "The SR policy could not be created."); - case -21: - return clib_error_return (0, - "The selected SR policy only contains ONE segment list. " - "Please remove the SR policy instead"); - case -22: - return clib_error_return (0, - "Could not delete the segment list. " - "It is not associated with that SR policy."); - case -23: - return clib_error_return (0, - "Could not delete the segment list. " - "It is not associated with that SR policy."); - case -32: - return clib_error_return (0, - "Could not modify the segment list. " - "The given SL is not associated with such SR policy."); - case VNET_API_ERROR_NO_SUCH_TABLE: - return clib_error_return (0, "the Default MPLS table is not present"); - default: - return clib_error_return (0, "BUG: sr policy returns %d", rv); - } - return 0; -} - -VLIB_CLI_COMMAND(sr_mpls_policy_command, static)= -{ - .path = "sr mpls policy", - .short_help = "sr mpls policy [add||del||mod] bsid 2999 " - "next 10 next 20 next 30 (weight 1) (spray)", - .long_help = "TBD.\n", - .function = sr_mpls_policy_command_fn, -}; - -/** - * @brief CLI to display onscreen all the SR MPLS policies - */ -static clib_error_t * -show_sr_mpls_policies_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - mpls_sr_sl_t *segment_list = 0; - mpls_sr_policy_t *sr_policy = 0; - mpls_sr_policy_t **vec_policies = 0; - mpls_label_t *label; - u32 *sl_index; - u8 *s; - int i = 0; - - vlib_cli_output (vm, "SR MPLS policies:"); - - pool_foreach (sr_policy, sm->sr_policies) { - vec_add1(vec_policies, sr_policy); - } - - vec_foreach_index (i, vec_policies) - { - sr_policy = vec_policies[i]; - vlib_cli_output (vm, "[%u].-\tBSID: %U", - (u32) (sr_policy - sm->sr_policies), - format_mpls_unicast_label, sr_policy->bsid); - switch (sr_policy->endpoint_type) - { - case SR_STEER_IPV6: - vlib_cli_output (vm, "\tEndpoint: %U", format_ip6_address, - &sr_policy->endpoint.ip6); - vlib_cli_output (vm, "\tColor: %u", sr_policy->color); - break; - case SR_STEER_IPV4: - vlib_cli_output (vm, "\tEndpoint: %U", format_ip4_address, - &sr_policy->endpoint.ip4); - vlib_cli_output (vm, "\tColor: %u", sr_policy->color); - break; - default: - vlib_cli_output (vm, "\tTE disabled"); - } - vlib_cli_output (vm, "\tType: %s", - (sr_policy->type == - SR_POLICY_TYPE_DEFAULT ? "Default" : "Spray")); - vlib_cli_output (vm, "\tSegment Lists:"); - vec_foreach (sl_index, sr_policy->segments_lists) - { - s = NULL; - segment_list = pool_elt_at_index (sm->sid_lists, *sl_index); - s = format (s, "\t[%u].- ", *sl_index); - s = format (s, "< "); - vec_foreach (label, segment_list->segments) - { - s = format (s, "%U, ", format_mpls_unicast_label, *label); - } - s = format (s, "\b\b > "); - vlib_cli_output (vm, " %s", s); - } - vlib_cli_output (vm, "-----------"); - } - vec_free (vec_policies); - return 0; -} - -VLIB_CLI_COMMAND(show_sr_mpls_policies_command, static)= -{ - .path = "show sr mpls policies", - .short_help = "show sr mpls policies", - .function = show_sr_mpls_policies_command_fn, -}; - -/** - * @brief Update the Endpoint,Color tuple of an SR policy - * - * @param bsid is the bindingSID of the SR Policy - * @param endpoint represents the IP46 of the endpoint - * @param color represents the color (u32) - * - * To reset to NULL use ~0 as parameters. - * - * @return 0 if correct, else error - */ -int -sr_mpls_policy_assign_endpoint_color (mpls_label_t bsid, - ip46_address_t * endpoint, - u8 endpoint_type, u32 color) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - mpls_sr_policy_t *sr_policy = 0; - uword *endpoint_table, *p, *old_value; - - ip46_address_t any; - any.as_u64[0] = any.as_u64[1] = (u64) ~ 0; - - if (!sm->sr_policies_index_hash) - sm->sr_policies_index_hash = hash_create (0, sizeof (mpls_label_t)); - - p = hash_get (sm->sr_policies_index_hash, bsid); - if (p) - sr_policy = pool_elt_at_index (sm->sr_policies, p[0]); - else - return -1; - - /* If previous Endpoint, color existed, remove (NH,C) and (ANY,C) */ - if (sr_policy->endpoint_type) - { - endpoint_table = - mhash_get (&sm->sr_policies_c2e2eclabel_hash, &sr_policy->color); - if (!endpoint_table) - return -2; - old_value = - mhash_get ((mhash_t *) endpoint_table, &sr_policy->endpoint); - - /* CID 180995 This should never be NULL unless the two hash tables - * get out of sync */ - ALWAYS_ASSERT (old_value != NULL); - - fib_prefix_t pfx = { 0 }; - pfx.fp_proto = FIB_PROTOCOL_MPLS; - pfx.fp_len = 21; - pfx.fp_label = (u32) * old_value; - - mpls_eos_bit_t eos; - FOR_EACH_MPLS_EOS_BIT (eos) - { - pfx.fp_eos = eos; - fib_table_entry_path_remove (sm->fib_table_EC, - &pfx, - FIB_SOURCE_SR, - DPO_PROTO_MPLS, - NULL, - ~0, 0, 1, FIB_ROUTE_PATH_FLAG_NONE); - } - - old_value = mhash_get ((mhash_t *) endpoint_table, &any); - pfx.fp_label = (u32) * old_value; - - FOR_EACH_MPLS_EOS_BIT (eos) - { - pfx.fp_eos = eos; - fib_table_entry_path_remove (sm->fib_table_EC, - &pfx, - FIB_SOURCE_SR, - DPO_PROTO_MPLS, - NULL, - ~0, 0, 1, FIB_ROUTE_PATH_FLAG_NONE); - } - - /* Release the lock on (NH, Color) and (ANY, Color) */ - internal_label_unlock (sr_policy->endpoint, sr_policy->color); - internal_label_unlock (any, sr_policy->color); - - /* Reset the values on the SR policy */ - sr_policy->endpoint_type = 0; - sr_policy->endpoint.as_u64[0] = sr_policy->endpoint.as_u64[1] = - (u64) ~ 0; - sr_policy->color = (u32) ~ 0; - } - - if (endpoint_type) - { - sr_policy->endpoint_type = endpoint_type; - sr_policy->endpoint.as_u64[0] = endpoint->as_u64[0]; - sr_policy->endpoint.as_u64[1] = endpoint->as_u64[1]; - sr_policy->color = color; - - u32 label = find_or_create_internal_label (*endpoint, color); - internal_label_lock (*endpoint, sr_policy->color); - - /* If FIB doesnt exist, create them */ - if (sm->fib_table_EC == (u32) ~ 0) - { - sm->fib_table_EC = fib_table_create_and_lock (FIB_PROTOCOL_MPLS, - FIB_SOURCE_SR, - "SR-MPLS Traffic Engineering (NextHop,Color)"); - - fib_table_flush (sm->fib_table_EC, FIB_PROTOCOL_MPLS, - FIB_SOURCE_SPECIAL); - } - - fib_prefix_t pfx = { 0 }; - pfx.fp_proto = FIB_PROTOCOL_MPLS; - pfx.fp_len = 21; - - fib_route_path_t path = { - .frp_proto = DPO_PROTO_MPLS, - .frp_sw_if_index = ~0, - .frp_fib_index = 0, - .frp_weight = 1, - .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, - .frp_label_stack = 0 - }; - path.frp_local_label = sr_policy->bsid; - - //Add the entry to ANY,Color - u32 any_label = find_or_create_internal_label (any, color); - internal_label_lock (any, sr_policy->color); - - pfx.fp_eos = MPLS_EOS; - path.frp_eos = MPLS_EOS; - - fib_route_path_t *paths = NULL; - vec_add1 (paths, path); - - pfx.fp_label = label; - fib_table_entry_update (sm->fib_table_EC, - &pfx, - FIB_SOURCE_SR, - FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths); - - pfx.fp_label = any_label; - fib_table_entry_update (sm->fib_table_EC, - &pfx, - FIB_SOURCE_SR, - FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths); - - fib_mpls_label_t fml = { - .fml_value = MPLS_IETF_IMPLICIT_NULL_LABEL, - }; - - vec_add1 (path.frp_label_stack, fml); - pfx.fp_eos = MPLS_NON_EOS; - path.frp_eos = MPLS_NON_EOS; - - paths = NULL; - vec_add1 (paths, path); - - pfx.fp_label = label; - fib_table_entry_update (sm->fib_table_EC, - &pfx, - FIB_SOURCE_SR, - FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths); - - pfx.fp_label = any_label; - fib_table_entry_update (sm->fib_table_EC, - &pfx, - FIB_SOURCE_SR, - FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths); - } - return 0; -} - -/** - * @brief CLI to modify the Endpoint,Color of an SR policy - */ -static clib_error_t * -cli_sr_mpls_policy_ec_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - ip46_address_t endpoint; - u32 color = (u32) ~ 0; - mpls_label_t bsid; - u8 endpoint_type = 0; - char clear = 0, color_set = 0, bsid_set = 0; - - clib_memset (&endpoint, 0, sizeof (ip46_address_t)); - - int rv; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (!endpoint_type - && unformat (input, "endpoint %U", unformat_ip6_address, - &endpoint.ip6)) - endpoint_type = SR_STEER_IPV6; - else if (!endpoint_type - && unformat (input, "endpoint %U", unformat_ip4_address, - &endpoint.ip4)) - endpoint_type = SR_STEER_IPV4; - else if (!color_set && unformat (input, "color %u", &color)) - color_set = 1; - else if (!bsid_set - && unformat (input, "bsid %U", unformat_mpls_unicast_label, - &bsid)) - bsid_set = 1; - else if (!clear && unformat (input, "clear")) - clear = 1; - else - break; - } - - if (!bsid_set) - return clib_error_return (0, "No BSID specified"); - if (!endpoint_type && !clear) - return clib_error_return (0, "No Endpoint specified"); - if (!color_set && !clear) - return clib_error_return (0, "No Color set"); - - /* In case its a cleanup */ - if (clear) - { - ip6_address_set_zero (&endpoint.ip6); - color = (u32) ~ 0; - } - rv = - sr_mpls_policy_assign_endpoint_color (bsid, &endpoint, endpoint_type, - color); - - if (rv) - clib_error_return (0, "Error on Endpoint,Color"); - - return 0; -} - -VLIB_CLI_COMMAND(cli_sr_mpls_policy_ec_command, static)= -{ - .path = "sr mpls policy te", - .short_help = "sr mpls policy te bsid xxxxx endpoint x.x.x.x color 12341234", - .function = cli_sr_mpls_policy_ec_command_fn, -}; - -/********************* SR MPLS Policy initialization ***********************/ -/** - * @brief SR MPLS Policy initialization - */ -clib_error_t * -sr_mpls_policy_rewrite_init (vlib_main_t * vm) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - - /* Init memory for sr policy keys (bsid <-> ip6_address_t) */ - sm->sr_policies_index_hash = NULL; - sm->sr_policies_c2e2eclabel_hash.hash = NULL; - return 0; -} - -VLIB_INIT_FUNCTION (sr_mpls_policy_rewrite_init); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: eval: (c-set-style "gnu") End: - */ diff --git a/src/vnet/srmpls/sr_mpls_steering.c b/src/vnet/srmpls/sr_mpls_steering.c deleted file mode 100644 index e8920df542b..00000000000 --- a/src/vnet/srmpls/sr_mpls_steering.c +++ /dev/null @@ -1,897 +0,0 @@ -/* - * sr_steering.c: ipv6 segment routing steering into SR policy - * - * 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. - */ - -/** - * @file - * @brief Packet steering into SR-MPLS Policies - * - * This file is in charge of handling the FIB appropiatly to steer packets - * through SR Policies as defined in 'sr_mpls_policy.c'. Notice that here - * we are only doing steering. SR policy application is done in - * sr_policy_rewrite.c - * - * Supports: - * - Steering of IPv6 traffic Destination Address based through BSID - * - Steering of IPv4 traffic Destination Address based through BSID - * - Steering of IPv4 and IPv6 traffic through N,C (SR CP) - */ - -#include <vlib/vlib.h> -#include <vnet/vnet.h> -#include <vnet/srmpls/sr_mpls.h> -#include <vnet/ip/ip4_packet.h> -#include <vnet/ip/ip6_packet.h> -#include <vnet/fib/mpls_fib.h> - -#include <vppinfra/error.h> -#include <vppinfra/elog.h> - -#define SRMPLS_TE_OFFSET 50 - -/** - * @brief function to sort the colors in descending order - */ -int -sort_color_descent (const u32 * x, u32 * y) -{ - return *y - *x; -} - -/********************* Internal (NH, C) labels *******************************/ -/** - * @brief find the corresponding label for (endpoint, color) and lock it - * endpoint might be NULL or ANY - * NULL = 0, ANY=~0 - */ -u32 -find_or_create_internal_label (ip46_address_t endpoint, u32 color) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - uword *color_table, *result_label; - - if (!sm->sr_policies_c2e2eclabel_hash.hash) - mhash_init (&sm->sr_policies_c2e2eclabel_hash, sizeof (mhash_t), - sizeof (u32)); - - color_table = mhash_get (&sm->sr_policies_c2e2eclabel_hash, &color); - if (!color_table) - { - mhash_t color_t; - clib_memset (&color_t, 0, sizeof (mhash_t)); - mhash_init (&color_t, sizeof (u32), sizeof (ip46_address_t)); - mhash_set_mem (&sm->sr_policies_c2e2eclabel_hash, &color, - (uword *) & color_t, NULL); - color_table = mhash_get (&sm->sr_policies_c2e2eclabel_hash, &color); - } - - result_label = mhash_get ((mhash_t *) color_table, &endpoint); - - if (result_label) - return (u32) * result_label; - - /* Create and set a new internal label */ - u32 *new_internal_label = 0; - pool_get (sm->ec_labels, new_internal_label); - *new_internal_label = 0; - mhash_set ((mhash_t *) color_table, &endpoint, - (new_internal_label - sm->ec_labels) + SRMPLS_TE_OFFSET, NULL); - - return (new_internal_label - sm->ec_labels) + SRMPLS_TE_OFFSET; -} - -always_inline void -internal_label_lock_co (ip46_address_t endpoint, u32 color, char co_bits) -{ - ip46_address_t zero, any; - ip46_address_reset (&zero); - any.as_u64[0] = any.as_u64[1] = (u64) ~ 0; - switch (co_bits) - { - case SR_TE_CO_BITS_10: - internal_label_lock (endpoint, color); - internal_label_lock (zero, color); - internal_label_lock (any, color); - break; - case SR_TE_CO_BITS_01: - internal_label_lock (endpoint, color); - internal_label_lock (zero, color); - break; - case SR_TE_CO_BITS_00: - case SR_TE_CO_BITS_11: - internal_label_lock (endpoint, color); - break; - } -} - -/** - * @brief lock the label for (NH, C) - * endpoint might be NULL or ANY - * NULL = 0, ANY=~0 - */ -void -internal_label_lock (ip46_address_t endpoint, u32 color) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - uword *color_table, *result_label; - - if (!sm->sr_policies_c2e2eclabel_hash.hash) - return; - - color_table = mhash_get (&sm->sr_policies_c2e2eclabel_hash, &color); - if (!color_table) - return; - - result_label = mhash_get ((mhash_t *) color_table, &endpoint); - - if (!result_label) - return; - - /* Lock it */ - u32 *label_lock = - pool_elt_at_index (sm->ec_labels, *result_label - SRMPLS_TE_OFFSET); - (*label_lock)++; -} - - -always_inline void -internal_label_unlock_co (ip46_address_t endpoint, u32 color, char co_bits) -{ - ip46_address_t zero, any; - ip46_address_reset (&zero); - any.as_u64[0] = any.as_u64[1] = (u64) ~ 0; - switch (co_bits) - { - case SR_TE_CO_BITS_10: - internal_label_unlock (endpoint, color); - internal_label_unlock (zero, color); - internal_label_unlock (any, color); - break; - case SR_TE_CO_BITS_01: - internal_label_unlock (endpoint, color); - internal_label_unlock (zero, color); - break; - case SR_TE_CO_BITS_00: - case SR_TE_CO_BITS_11: - internal_label_unlock (endpoint, color); - break; - } -} - -/** - * @brief Release lock on label for (endpoint, color) - * endpoint might be NULL or ANY - * NULL = 0, ANY=~0 - */ -void -internal_label_unlock (ip46_address_t endpoint, u32 color) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - uword *color_table, *result_label; - - if (!sm->sr_policies_c2e2eclabel_hash.hash) - return; - - color_table = mhash_get (&sm->sr_policies_c2e2eclabel_hash, &color); - if (!color_table) - return; - - result_label = mhash_get ((mhash_t *) color_table, &endpoint); - - if (!result_label) - return; - - u32 *label_lock = - pool_elt_at_index (sm->ec_labels, *result_label - SRMPLS_TE_OFFSET); - (*label_lock)--; - - if (*label_lock == 0) - { - pool_put (sm->ec_labels, label_lock); - mhash_unset ((mhash_t *) color_table, &endpoint, NULL); - if (mhash_elts ((mhash_t *) color_table) == 0) - { - mhash_free ((mhash_t *) color_table); - mhash_unset (&sm->sr_policies_c2e2eclabel_hash, &color, NULL); - if (mhash_elts (&sm->sr_policies_c2e2eclabel_hash) == 0) - { - mhash_free (&sm->sr_policies_c2e2eclabel_hash); - sm->sr_policies_c2e2eclabel_hash.hash = NULL; - fib_table_unlock (sm->fib_table_EC, FIB_PROTOCOL_MPLS, - FIB_SOURCE_SR); - sm->fib_table_EC = (u32) ~ 0; - } - } - } -} - -/********************* steering computation *********************************/ -/** - * @brief function to update the FIB - */ -void -compute_sr_te_automated_steering_fib_entry (mpls_sr_steering_policy_t * - steer_pl) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - fib_prefix_t pfx = { 0 }; - - u32 *internal_labels = 0; - ip46_address_t zero, any; - ip46_address_reset (&zero); - any.as_u64[0] = any.as_u64[1] = (u64) ~ 0; - - u32 *color_i = NULL; - vec_foreach (color_i, steer_pl->color) - { - switch (steer_pl->co_bits) - { - case SR_TE_CO_BITS_10: - vec_add1 (internal_labels, - find_or_create_internal_label (steer_pl->next_hop, - *color_i)); - vec_add1 (internal_labels, - find_or_create_internal_label (zero, *color_i)); - vec_add1 (internal_labels, - find_or_create_internal_label (any, *color_i)); - break; - case SR_TE_CO_BITS_01: - vec_add1 (internal_labels, - find_or_create_internal_label (steer_pl->next_hop, - *color_i)); - vec_add1 (internal_labels, - find_or_create_internal_label (zero, *color_i)); - break; - case SR_TE_CO_BITS_00: - case SR_TE_CO_BITS_11: - vec_add1 (internal_labels, - find_or_create_internal_label (steer_pl->next_hop, - *color_i)); - break; - } - } - - /* Does hidden FIB already exist? */ - if (sm->fib_table_EC == (u32) ~ 0) - { - sm->fib_table_EC = fib_table_create_and_lock (FIB_PROTOCOL_MPLS, - FIB_SOURCE_SR, - "SR-MPLS Traffic Engineering (NextHop,Color)"); - - fib_table_flush (sm->fib_table_EC, FIB_PROTOCOL_MPLS, - FIB_SOURCE_SPECIAL); - } - - /* Add the corresponding FIB entries */ - fib_route_path_t path = { - .frp_proto = DPO_PROTO_MPLS, - .frp_eos = MPLS_EOS, - .frp_sw_if_index = ~0, - .frp_fib_index = sm->fib_table_EC, - .frp_weight = 1, - .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, - .frp_label_stack = 0 - }; - fib_route_path_t *paths = NULL; - - if (steer_pl->classify.traffic_type == SR_STEER_IPV6) - { - pfx.fp_proto = FIB_PROTOCOL_IP6; - pfx.fp_len = steer_pl->classify.mask_width; - pfx.fp_addr.ip6 = steer_pl->classify.prefix.ip6; - } - else if (steer_pl->classify.traffic_type == SR_STEER_IPV4) - { - pfx.fp_proto = FIB_PROTOCOL_IP4; - pfx.fp_len = steer_pl->classify.mask_width; - pfx.fp_addr.ip4 = steer_pl->classify.prefix.ip4; - } - - if (steer_pl->vpn_label != (u32) ~ 0) - { - fib_mpls_label_t fml = { - .fml_value = steer_pl->vpn_label, - }; - vec_add1 (path.frp_label_stack, fml); - path.frp_eos = MPLS_NON_EOS; - } - - u32 label_i; - vec_foreach_index (label_i, internal_labels) - { - path.frp_local_label = internal_labels[label_i]; - path.frp_preference = label_i; - vec_add1 (paths, path); - } - - /* Finally we must add to FIB IGP to N */ - clib_memcpy (&path.frp_addr, &steer_pl->next_hop, - sizeof (steer_pl->next_hop)); - path.frp_preference = vec_len (internal_labels); - path.frp_label_stack = NULL; - - if (steer_pl->nh_type == SR_STEER_IPV6) - { - path.frp_proto = DPO_PROTO_IP6; - path.frp_fib_index = - fib_table_find (FIB_PROTOCOL_IP6, - (steer_pl->classify.fib_table != - (u32) ~ 0 ? steer_pl->classify.fib_table : 0)); - } - else if (steer_pl->nh_type == SR_STEER_IPV4) - { - path.frp_proto = DPO_PROTO_IP4; - path.frp_fib_index = - fib_table_find (FIB_PROTOCOL_IP4, - (steer_pl->classify.fib_table != - (u32) ~ 0 ? steer_pl->classify.fib_table : 0)); - } - - vec_add1 (paths, path); - if (steer_pl->classify.traffic_type == SR_STEER_IPV6) - fib_table_entry_update (fib_table_find - (FIB_PROTOCOL_IP6, - (steer_pl->classify.fib_table != - (u32) ~ 0 ? steer_pl->classify.fib_table : 0)), - &pfx, FIB_SOURCE_SR, - FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths); - else if (steer_pl->classify.traffic_type == SR_STEER_IPV4) - fib_table_entry_update (fib_table_find - (FIB_PROTOCOL_IP4, - (steer_pl->classify.fib_table != - (u32) ~ 0 ? steer_pl->classify.fib_table : 0)), - &pfx, FIB_SOURCE_SR, - FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths); - - vec_free (paths); - paths = NULL; -} - -/** - * @brief Steer traffic L3 traffic through a given SR-MPLS policy - * - * @param is_del - * @param bsid is the bindingSID of the SR Policy (alt to sr_policy_index) - * @param sr_policy is the index of the SR Policy (alt to bsid) - * @param table_id is the VRF where to install the FIB entry for the BSID - * @param prefix is the IPv4/v6 address for L3 traffic type - * @param mask_width is the mask for L3 traffic type - * @param traffic_type describes the type of traffic - * @param next_hop SR TE Next-Hop - * @param nh_type is the AF of Next-Hop - * @param color SR TE color - * @param co_bits SR TE color-only bits - * - * @return 0 if correct, else error - */ -int -sr_mpls_steering_policy_add (mpls_label_t bsid, u32 table_id, - ip46_address_t * prefix, u32 mask_width, - u8 traffic_type, ip46_address_t * next_hop, - u8 nh_type, u32 color, char co_bits, - mpls_label_t vpn_label) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - sr_mpls_steering_key_t key; - mpls_sr_steering_policy_t *steer_pl; - fib_prefix_t pfx = { 0 }; - - mpls_sr_policy_t *sr_policy = 0; - uword *p = 0; - - clib_memset (&key, 0, sizeof (sr_mpls_steering_key_t)); - - if (traffic_type != SR_STEER_IPV4 && traffic_type != SR_STEER_IPV6) - return -1; - - /* Compute the steer policy key */ - key.prefix.as_u64[0] = prefix->as_u64[0]; - key.prefix.as_u64[1] = prefix->as_u64[1]; - key.mask_width = mask_width; - key.fib_table = (table_id != (u32) ~ 0 ? table_id : 0); - key.traffic_type = traffic_type; - - /* - * Search for steering policy. If already exists we are adding a new - * color. - */ - if (!sm->sr_steer_policies_hash.hash) - mhash_init (&sm->sr_steer_policies_hash, sizeof (uword), - sizeof (sr_mpls_steering_key_t)); - - p = mhash_get (&sm->sr_steer_policies_hash, &key); - if (p) - { - steer_pl = pool_elt_at_index (sm->steer_policies, p[0]); - if (steer_pl->bsid != (u32) ~ 0) - return -1; //Means we are rewritting the steering. Not allowed. - - /* Means we are adding a color. Check that NH match. */ - if (ip46_address_cmp (&steer_pl->next_hop, next_hop)) - return -2; - if (vec_search (steer_pl->color, color) != ~0) - return -3; - if (steer_pl->co_bits != co_bits) - return -4; /* CO colors should be the same */ - if (steer_pl->vpn_label != vpn_label) - return -5; /* VPN label should be the same */ - - /* Remove the steering and ReDo it */ - vec_add1 (steer_pl->color, color); - vec_sort_with_function (steer_pl->color, sort_color_descent); - compute_sr_te_automated_steering_fib_entry (steer_pl); - internal_label_lock_co (steer_pl->next_hop, color, steer_pl->co_bits); - return 0; - } - - /* Create a new steering policy */ - pool_get (sm->steer_policies, steer_pl); - clib_memset (steer_pl, 0, sizeof (*steer_pl)); - clib_memcpy (&steer_pl->classify.prefix, prefix, sizeof (ip46_address_t)); - clib_memcpy (&steer_pl->next_hop, next_hop, sizeof (ip46_address_t)); - steer_pl->nh_type = nh_type; - steer_pl->co_bits = co_bits; - steer_pl->classify.mask_width = mask_width; - steer_pl->classify.fib_table = (table_id != (u32) ~ 0 ? table_id : 0); - steer_pl->classify.traffic_type = traffic_type; - steer_pl->color = NULL; - steer_pl->vpn_label = vpn_label; - - /* Create and store key */ - mhash_set (&sm->sr_steer_policies_hash, &key, steer_pl - sm->steer_policies, - NULL); - - /* Local steering */ - if (bsid != (u32) ~ 0) - { - if (!sm->sr_policies_index_hash) - sm->sr_policies_index_hash = hash_create (0, sizeof (mpls_label_t)); - steer_pl->bsid = bsid; - p = hash_get (sm->sr_policies_index_hash, bsid); - if (!p) - return -1; - sr_policy = pool_elt_at_index (sm->sr_policies, p[0]); - - fib_route_path_t path = { - .frp_proto = DPO_PROTO_MPLS, - .frp_local_label = sr_policy->bsid, - .frp_eos = MPLS_EOS, - .frp_sw_if_index = ~0, - .frp_fib_index = 0, - .frp_weight = 1, - .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, - .frp_label_stack = 0 - }; - fib_route_path_t *paths = NULL; - - if (steer_pl->vpn_label != (u32) ~ 0) - { - fib_mpls_label_t fml = { - .fml_value = steer_pl->vpn_label, - }; - vec_add1 (path.frp_label_stack, fml); - } - - /* FIB API calls - Recursive route through the BindingSID */ - if (traffic_type == SR_STEER_IPV6) - { - pfx.fp_proto = FIB_PROTOCOL_IP6; - pfx.fp_len = steer_pl->classify.mask_width; - pfx.fp_addr.ip6 = steer_pl->classify.prefix.ip6; - path.frp_fib_index = 0; - path.frp_preference = 0; - vec_add1 (paths, path); - fib_table_entry_path_add2 (fib_table_find - (FIB_PROTOCOL_IP6, - (table_id != (u32) ~ 0 ? table_id : 0)), - &pfx, FIB_SOURCE_SR, - FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths); - vec_free (paths); - } - else if (traffic_type == SR_STEER_IPV4) - { - pfx.fp_proto = FIB_PROTOCOL_IP4; - pfx.fp_len = steer_pl->classify.mask_width; - pfx.fp_addr.ip4 = steer_pl->classify.prefix.ip4; - path.frp_fib_index = 0; - path.frp_preference = 0; - vec_add1 (paths, path); - fib_table_entry_path_add2 (fib_table_find - (FIB_PROTOCOL_IP4, - (table_id != (u32) ~ 0 ? table_id : 0)), - &pfx, FIB_SOURCE_SR, - FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths); - vec_free (paths); - } - } - /* Automated steering */ - else - { - steer_pl->bsid = (u32) ~ 0; - vec_add1 (steer_pl->color, color); - compute_sr_te_automated_steering_fib_entry (steer_pl); - internal_label_lock_co (steer_pl->next_hop, color, steer_pl->co_bits); - } - return 0; -} - -/** - * @brief Delete steering rule for an SR-MPLS policy - * - * @param is_del - * @param bsid is the bindingSID of the SR Policy (alt to sr_policy_index) - * @param sr_policy is the index of the SR Policy (alt to bsid) - * @param table_id is the VRF where to install the FIB entry for the BSID - * @param prefix is the IPv4/v6 address for L3 traffic type - * @param mask_width is the mask for L3 traffic type - * @param traffic_type describes the type of traffic - * @param next_hop SR TE Next-HOP - * @param nh_type is the AF of Next-Hop - * @param color SR TE color - * - * @return 0 if correct, else error - */ -int -sr_mpls_steering_policy_del (ip46_address_t * prefix, u32 mask_width, - u8 traffic_type, u32 table_id, u32 color) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - sr_mpls_steering_key_t key; - mpls_sr_steering_policy_t *steer_pl; - fib_prefix_t pfx = { 0 }; - uword *p = 0; - - clib_memset (&key, 0, sizeof (sr_mpls_steering_key_t)); - - /* Compute the steer policy key */ - if (traffic_type != SR_STEER_IPV4 && traffic_type != SR_STEER_IPV6) - return -1; - - key.prefix.as_u64[0] = prefix->as_u64[0]; - key.prefix.as_u64[1] = prefix->as_u64[1]; - key.mask_width = mask_width; - key.fib_table = (table_id != (u32) ~ 0 ? table_id : 0); - key.traffic_type = traffic_type; - - if (!sm->sr_steer_policies_hash.hash) - mhash_init (&sm->sr_steer_policies_hash, sizeof (uword), - sizeof (sr_mpls_steering_key_t)); - - /* Search for the item */ - p = mhash_get (&sm->sr_steer_policies_hash, &key); - - if (!p) - return -1; - - /* Retrieve Steer Policy function */ - steer_pl = pool_elt_at_index (sm->steer_policies, p[0]); - - if (steer_pl->bsid == (u32) ~ 0) - { - /* Remove the color from the color vector */ - vec_del1 (steer_pl->color, vec_search (steer_pl->color, color)); - - if (vec_len (steer_pl->color)) - { - /* Reorder Colors */ - vec_sort_with_function (steer_pl->color, sort_color_descent); - compute_sr_te_automated_steering_fib_entry (steer_pl); - /* Remove all the locks for this ones... */ - internal_label_unlock_co (steer_pl->next_hop, color, - steer_pl->co_bits); - return 0; - } - else - { - vec_free (steer_pl->color); - /* Remove FIB entry */ - if (steer_pl->classify.traffic_type == SR_STEER_IPV6) - { - pfx.fp_proto = FIB_PROTOCOL_IP6; - pfx.fp_len = steer_pl->classify.mask_width; - pfx.fp_addr.ip6 = steer_pl->classify.prefix.ip6; - fib_table_entry_delete (fib_table_find - (FIB_PROTOCOL_IP6, - steer_pl->classify.fib_table), &pfx, - FIB_SOURCE_SR); - } - else if (steer_pl->classify.traffic_type == SR_STEER_IPV4) - { - pfx.fp_proto = FIB_PROTOCOL_IP4; - pfx.fp_len = steer_pl->classify.mask_width; - pfx.fp_addr.ip4 = steer_pl->classify.prefix.ip4; - fib_table_entry_delete (fib_table_find - (FIB_PROTOCOL_IP4, - steer_pl->classify.fib_table), &pfx, - FIB_SOURCE_SR); - } - /* Remove all the locks for this ones... */ - internal_label_unlock_co (steer_pl->next_hop, color, - steer_pl->co_bits); - } - } - else //Remove by BSID - { - if (steer_pl->classify.traffic_type == SR_STEER_IPV6) - { - pfx.fp_proto = FIB_PROTOCOL_IP6; - pfx.fp_len = steer_pl->classify.mask_width; - pfx.fp_addr.ip6 = steer_pl->classify.prefix.ip6; - fib_table_entry_delete (fib_table_find - (FIB_PROTOCOL_IP6, - steer_pl->classify.fib_table), &pfx, - FIB_SOURCE_SR); - } - else if (steer_pl->classify.traffic_type == SR_STEER_IPV4) - { - pfx.fp_proto = FIB_PROTOCOL_IP4; - pfx.fp_len = steer_pl->classify.mask_width; - pfx.fp_addr.ip4 = steer_pl->classify.prefix.ip4; - fib_table_entry_delete (fib_table_find - (FIB_PROTOCOL_IP4, - steer_pl->classify.fib_table), &pfx, - FIB_SOURCE_SR); - } - } - /* Delete SR steering policy entry */ - pool_put (sm->steer_policies, steer_pl); - mhash_unset (&sm->sr_steer_policies_hash, &key, NULL); - if (mhash_elts (&sm->sr_steer_policies_hash) == 0) - { - mhash_free (&sm->sr_steer_policies_hash); - sm->sr_steer_policies_hash.hash = NULL; - } - return 0; -} - -static clib_error_t * -sr_mpls_steer_policy_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - int is_del = 0; - - ip46_address_t prefix, nh; - u32 dst_mask_width = 0; - u8 traffic_type = 0; - u8 nh_type = 0; - u32 fib_table = (u32) ~ 0, color = (u32) ~ 0; - u32 co_bits = 0; - - mpls_label_t bsid, vpn_label = (u32) ~ 0; - - u8 sr_policy_set = 0; - - clib_memset (&prefix, 0, sizeof (ip46_address_t)); - clib_memset (&nh, 0, sizeof (ip46_address_t)); - - int rv; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "del")) - is_del = 1; - else if (!traffic_type - && unformat (input, "l3 %U/%d", unformat_ip6_address, - &prefix.ip6, &dst_mask_width)) - traffic_type = SR_STEER_IPV6; - else if (!traffic_type - && unformat (input, "l3 %U/%d", unformat_ip4_address, - &prefix.ip4, &dst_mask_width)) - traffic_type = SR_STEER_IPV4; - else if (!sr_policy_set - && unformat (input, "via sr policy bsid %U", - unformat_mpls_unicast_label, &bsid)) - sr_policy_set = 1; - else if (!sr_policy_set - && unformat (input, "via next-hop %U color %d co %d", - unformat_ip4_address, &nh.ip4, &color, &co_bits)) - { - sr_policy_set = 1; - nh_type = SR_STEER_IPV4; - } - else if (!sr_policy_set - && unformat (input, "via next-hop %U color %d co %d", - unformat_ip6_address, &nh.ip6, &color, &co_bits)) - { - sr_policy_set = 1; - nh_type = SR_STEER_IPV6; - } - else if (fib_table == (u32) ~ 0 - && unformat (input, "fib-table %d", &fib_table)); - else if (unformat (input, "vpn-label %U", - unformat_mpls_unicast_label, &vpn_label)); - else - break; - } - - if (!traffic_type) - return clib_error_return (0, "No L3 traffic specified"); - if (!sr_policy_set) - return clib_error_return (0, "No SR policy specified"); - - /* Make sure that the prefixes are clean */ - if (traffic_type == SR_STEER_IPV4) - { - u32 mask = - (dst_mask_width ? (0xFFFFFFFFu >> (32 - dst_mask_width)) : 0); - prefix.ip4.as_u32 &= mask; - } - else if (traffic_type == SR_STEER_IPV6) - { - ip6_address_t mask; - ip6_address_mask_from_width (&mask, dst_mask_width); - ip6_address_mask (&prefix.ip6, &mask); - } - - if (nh_type) - bsid = (u32) ~ 0; - - if (is_del) - rv = - sr_mpls_steering_policy_del (&prefix, dst_mask_width, - traffic_type, fib_table, color); - - else - rv = - sr_mpls_steering_policy_add (bsid, fib_table, &prefix, dst_mask_width, - traffic_type, &nh, nh_type, color, co_bits, - vpn_label); - - switch (rv) - { - case 0: - break; - case 1: - return 0; - case -1: - return clib_error_return (0, "Incorrect API usage."); - case -2: - return clib_error_return (0, "The Next-Hop does not match."); - case -3: - return clib_error_return (0, "The color already exists."); - case -4: - return clib_error_return (0, "The co-bits do not match."); - case -5: - return clib_error_return (0, "The VPN-labels do not match."); - default: - return clib_error_return (0, "BUG: sr steer policy returns %d", rv); - } - return 0; -} - -VLIB_CLI_COMMAND(sr_mpls_steer_policy_command, static)= -{ - .path = "sr mpls steer", - .short_help = "sr mpls steer (del) l3 <ip_addr/mask> " - "via [sr policy bsid <mpls_label> || next-hop <ip46_addr> color <u32> co <0|1|2|3> ](fib-table <fib_table_index>)(vpn-label 500)", - .long_help = - "\tSteer L3 traffic through an existing SR policy.\n" - "\tExamples:\n" - "\t\tsr steer l3 2001::/64 via sr_policy bsid 29999\n" - "\t\tsr steer del l3 2001::/64 via sr_policy bsid 29999\n" - "\t\tsr steer l3 2001::/64 via next-hop 1.1.1.1 color 1234 co 0\n" - "\t\tsr steer l3 2001::/64 via next-hop 2001::1 color 1234 co 2 vpn-label 500\n", - .function = sr_mpls_steer_policy_command_fn, -}; - -static clib_error_t * -show_sr_mpls_steering_policies_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - mpls_sr_steering_policy_t **steer_policies = 0; - mpls_sr_steering_policy_t *steer_pl; - - int i; - - vlib_cli_output (vm, "SR MPLS steering policies:"); - pool_foreach (steer_pl, sm->steer_policies) { - vec_add1(steer_policies, steer_pl); - } - for (i = 0; i < vec_len (steer_policies); i++) - { - vlib_cli_output (vm, "=========================="); - steer_pl = steer_policies[i]; - if (steer_pl->classify.traffic_type == SR_STEER_IPV4) - { - vlib_cli_output (vm, "Prefix: %U/%d via:", - format_ip4_address, - &steer_pl->classify.prefix.ip4, - steer_pl->classify.mask_width); - } - else if (steer_pl->classify.traffic_type == SR_STEER_IPV6) - { - vlib_cli_output (vm, "Prefix: %U/%d via:", - format_ip6_address, - &steer_pl->classify.prefix.ip6, - steer_pl->classify.mask_width); - } - - if (steer_pl->bsid != (u32) ~ 0) - { - vlib_cli_output (vm, "· BSID %U", - format_mpls_unicast_label, steer_pl->bsid); - } - else - { - if (steer_pl->nh_type == SR_STEER_IPV4) - { - vlib_cli_output (vm, "· Next-hop %U", - format_ip4_address, &steer_pl->next_hop.ip4); - } - else if (steer_pl->nh_type == SR_STEER_IPV6) - { - vlib_cli_output (vm, "· Next-hop %U", - format_ip6_address, &steer_pl->next_hop.ip6); - } - - u32 *color_i = 0; - u8 *s = NULL; - s = format (s, "[ "); - vec_foreach (color_i, steer_pl->color) - { - s = format (s, "%d, ", *color_i); - } - s = format (s, "\b\b ]"); - vlib_cli_output (vm, "· Color %s", s); - - switch (steer_pl->co_bits) - { - case SR_TE_CO_BITS_00: - vlib_cli_output (vm, "· CO-bits: 00"); - break; - case SR_TE_CO_BITS_01: - vlib_cli_output (vm, "· CO-bits: 01"); - break; - case SR_TE_CO_BITS_10: - vlib_cli_output (vm, "· CO-bits: 10"); - break; - case SR_TE_CO_BITS_11: - vlib_cli_output (vm, "· CO-bits: 11"); - break; - } - } - } - return 0; -} - -VLIB_CLI_COMMAND(show_sr_mpls_steering_policies_command, static)= -{ - .path = "show sr mpls steering policies", - .short_help = "show sr mpls steering policies", - .function = show_sr_mpls_steering_policies_command_fn, -}; - -clib_error_t * -sr_mpls_steering_init (vlib_main_t * vm) -{ - mpls_sr_main_t *sm = &sr_mpls_main; - - /* Init memory for function keys */ - sm->sr_steer_policies_hash.hash = NULL; - - sm->fib_table_EC = (u32) ~ 0; - sm->ec_labels = 0; - - return 0; -} - -VLIB_INIT_FUNCTION(sr_mpls_steering_init); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: eval: (c-set-style "gnu") End: - */ diff --git a/src/vnet/srmpls/sr_mpls_test.c b/src/vnet/srmpls/sr_mpls_test.c deleted file mode 100644 index e5d68462443..00000000000 --- a/src/vnet/srmpls/sr_mpls_test.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - *------------------------------------------------------------------ - * Copyright (c) 2021 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 <vat/vat.h> -#include <vlibapi/api.h> -#include <vlibmemory/api.h> -#include <vppinfra/error.h> -#include <vpp/api/types.h> - -#define __plugin_msg_base sr_mpls_test_main.msg_id_base -#include <vlibapi/vat_helper_macros.h> - -/* Declare message IDs */ -#include <vnet/format_fns.h> -#include <vnet/srmpls/sr_mpls.api_enum.h> -#include <vnet/srmpls/sr_mpls.api_types.h> - -#define vl_endianfun /* define message structures */ -#include <vnet/srmpls/sr_mpls.api.h> -#undef vl_endianfun - -typedef struct -{ - /* API message ID base */ - u16 msg_id_base; - u32 ping_id; - vat_main_t *vat_main; -} sr_mpls_test_main_t; - -static sr_mpls_test_main_t sr_mpls_test_main; - -static int -api_sr_mpls_policy_mod (vat_main_t *vam) -{ - return -1; -} - -static int -api_sr_mpls_steering_add_del (vat_main_t *vam) -{ - return -1; -} - -static int -api_sr_mpls_policy_assign_endpoint_color (vat_main_t *vam) -{ - return -1; -} - -static int -api_sr_mpls_policy_add (vat_main_t *vam) -{ - unformat_input_t *i = vam->input; - vl_api_sr_mpls_policy_add_t *mp; - u32 bsid = 0; - u32 weight = 1; - u8 type = 0; - u8 n_segments = 0; - u32 sid; - u32 *segments = NULL; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "bsid %d", &bsid)) - ; - else if (unformat (i, "weight %d", &weight)) - ; - else if (unformat (i, "spray")) - type = 1; - else if (unformat (i, "next %d", &sid)) - { - n_segments += 1; - vec_add1 (segments, htonl (sid)); - } - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } - } - - if (bsid == 0) - { - errmsg ("bsid not set"); - return -99; - } - - if (n_segments == 0) - { - errmsg ("no sid in segment stack"); - return -99; - } - - /* Construct the API message */ - M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments); - - mp->bsid = htonl (bsid); - mp->weight = htonl (weight); - mp->is_spray = type; - mp->n_segments = n_segments; - memcpy (mp->segments, segments, sizeof (u32) * n_segments); - vec_free (segments); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_sr_mpls_policy_del (vat_main_t *vam) -{ - unformat_input_t *i = vam->input; - vl_api_sr_mpls_policy_del_t *mp; - u32 bsid = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "bsid %d", &bsid)) - ; - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } - } - - if (bsid == 0) - { - errmsg ("bsid not set"); - return -99; - } - - /* Construct the API message */ - M (SR_MPLS_POLICY_DEL, mp); - - mp->bsid = htonl (bsid); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -#include <vnet/srmpls/sr_mpls.api_test.c> - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/srv6/sr_api.c b/src/vnet/srv6/sr_api.c index da774c4325f..a44c3098112 100644 --- a/src/vnet/srv6/sr_api.c +++ b/src/vnet/srv6/sr_api.c @@ -163,7 +163,7 @@ vl_api_sr_policy_add_v2_t_handler (vl_api_sr_policy_add_v2_t *mp) mp->type, ntohl (mp->fib_table), mp->is_encap, 0, NULL); vec_free (segments); - REPLY_MACRO (VL_API_SR_POLICY_ADD_REPLY); + REPLY_MACRO (VL_API_SR_POLICY_ADD_V2_REPLY); } static void |