Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 15 | |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 16 | /** |
| 17 | * @file |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 18 | * @brief Segment Routing data structures definitions |
| 19 | * |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 20 | */ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 21 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 22 | #ifndef included_vnet_srv6_h |
| 23 | #define included_vnet_srv6_h |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 24 | |
| 25 | #include <vnet/vnet.h> |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 26 | #include <vnet/srv6/sr_packet.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | #include <vnet/ip/ip6_packet.h> |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 28 | #include <vnet/ethernet/ethernet.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 29 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 33 | #define IPv6_DEFAULT_HEADER_LENGTH 40 |
| 34 | #define IPv6_DEFAULT_HOP_LIMIT 64 |
| 35 | #define IPv6_DEFAULT_MAX_MASK_WIDTH 128 |
| 36 | |
| 37 | #define SR_BEHAVIOR_END 1 |
| 38 | #define SR_BEHAVIOR_X 2 |
| 39 | #define SR_BEHAVIOR_D_FIRST 3 /* Unused. Separator in between regular and D */ |
| 40 | #define SR_BEHAVIOR_DX2 4 |
| 41 | #define SR_BEHAVIOR_DX6 5 |
| 42 | #define SR_BEHAVIOR_DX4 6 |
| 43 | #define SR_BEHAVIOR_DT6 7 |
| 44 | #define SR_BEHAVIOR_DT4 8 |
| 45 | #define SR_BEHAVIOR_LAST 9 /* Must always be the last one */ |
| 46 | |
| 47 | #define SR_STEER_L2 2 |
| 48 | #define SR_STEER_IPV4 4 |
| 49 | #define SR_STEER_IPV6 6 |
| 50 | |
| 51 | #define SR_FUNCTION_SIZE 4 |
| 52 | #define SR_ARGUMENT_SIZE 4 |
| 53 | |
| 54 | #define SR_SEGMENT_LIST_WEIGHT_DEFAULT 1 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 56 | /** |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 57 | * @brief SR Segment List (SID list) |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 58 | */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 59 | typedef struct |
| 60 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 61 | ip6_address_t *segments; /**< SIDs (key) */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 62 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 63 | u32 weight; /**< SID list weight (wECMP / UCMP) */ |
| 64 | |
| 65 | u8 *rewrite; /**< Precomputed rewrite header */ |
| 66 | u8 *rewrite_bsid; /**< Precomputed rewrite header for bindingSID */ |
| 67 | |
| 68 | dpo_id_t bsid_dpo; /**< DPO for Encaps/Insert for BSID */ |
| 69 | dpo_id_t ip6_dpo; /**< DPO for Encaps/Insert IPv6 */ |
| 70 | dpo_id_t ip4_dpo; /**< DPO for Encaps IPv6 */ |
| 71 | } ip6_sr_sl_t; |
| 72 | |
| 73 | /* SR policy types */ |
| 74 | #define SR_POLICY_TYPE_DEFAULT 0 |
| 75 | #define SR_POLICY_TYPE_SPRAY 1 |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 76 | /** |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 77 | * @brief SR Policy |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 78 | */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 79 | typedef struct |
| 80 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 81 | u32 *segments_lists; /**< SID lists indexes (vector) */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 82 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 83 | ip6_address_t bsid; /**< BindingSID (key) */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 84 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 85 | u8 type; /**< Type (default is 0) */ |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 86 | /* SR Policy specific DPO */ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 87 | /* IF Type = DEFAULT Then Load Balancer DPO among SID lists */ |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 88 | /* IF Type = SPRAY then Spray DPO with all SID lists */ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 89 | dpo_id_t bsid_dpo; /**< SR Policy specific DPO - BSID */ |
| 90 | dpo_id_t ip4_dpo; /**< SR Policy specific DPO - IPv6 */ |
| 91 | dpo_id_t ip6_dpo; /**< SR Policy specific DPO - IPv4 */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 92 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 93 | u32 fib_table; /**< FIB table */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 95 | u8 is_encap; /**< Mode (0 is SRH insert, 1 Encaps) */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 96 | } ip6_sr_policy_t; |
| 97 | |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 98 | /** |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 99 | * @brief SR LocalSID |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 100 | */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 101 | typedef struct |
| 102 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 103 | ip6_address_t localsid; /**< LocalSID IPv6 address */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 104 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 105 | char end_psp; /**< Combined with End.PSP? */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 106 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 107 | u16 behavior; /**< Behavior associated to this localsid */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 108 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 109 | union |
| 110 | { |
| 111 | u32 sw_if_index; /**< xconnect only */ |
| 112 | u32 vrf_index; /**< vrf only */ |
| 113 | }; |
| 114 | |
| 115 | u32 fib_table; /**< FIB table where localsid is registered */ |
| 116 | |
| 117 | u32 vlan_index; /**< VLAN tag (not an index) */ |
| 118 | |
| 119 | ip46_address_t next_hop; /**< Next_hop for xconnect usage only */ |
| 120 | |
| 121 | u32 nh_adj; /**< Next_adj for xconnect usage only */ |
| 122 | |
| 123 | void *plugin_mem; /**< Memory to be used by the plugin callback functions */ |
| 124 | } ip6_sr_localsid_t; |
| 125 | |
| 126 | typedef int (sr_plugin_callback_t) (ip6_sr_localsid_t * localsid); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 127 | |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 128 | /** |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 129 | * @brief SR LocalSID behavior registration |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 130 | */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 131 | typedef struct |
| 132 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 133 | u16 sr_localsid_function_number; /**< SR LocalSID plugin function (>SR_BEHAVIOR_LAST) */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 134 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 135 | u8 *function_name; /**< Function name. (key). */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 136 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 137 | u8 *keyword_str; /**< Behavior keyword (i.e. End.X) */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 138 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 139 | u8 *def_str; /**< Behavior definition (i.e. Endpoint with cross-connect) */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 140 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 141 | u8 *params_str; /**< Behavior parameters (i.e. <oif> <IP46next_hop>) */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 142 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 143 | dpo_type_t dpo; /**< DPO type registration */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 144 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 145 | format_function_t *ls_format; /**< LocalSID format function */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 146 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 147 | unformat_function_t *ls_unformat; /**< LocalSID unformat function */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 148 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 149 | sr_plugin_callback_t *creation; /**< Function within plugin that will be called after localsid creation*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 150 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 151 | sr_plugin_callback_t *removal; /**< Function within plugin that will be called before localsid removal */ |
| 152 | } sr_localsid_fn_registration_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 153 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 154 | /** |
| 155 | * @brief Steering db key |
| 156 | * |
| 157 | * L3 is IPv4/IPv6 + mask |
| 158 | * L2 is sf_if_index + vlan |
| 159 | */ |
| 160 | typedef struct |
| 161 | { |
| 162 | union |
| 163 | { |
| 164 | struct |
| 165 | { |
| 166 | ip46_address_t prefix; /**< IP address of the prefix */ |
| 167 | u32 mask_width; /**< Mask width of the prefix */ |
| 168 | u32 fib_table; /**< VRF of the prefix */ |
| 169 | } l3; |
| 170 | struct |
| 171 | { |
| 172 | u32 sw_if_index; /**< Incoming software interface */ |
| 173 | } l2; |
| 174 | }; |
| 175 | u8 traffic_type; /**< Traffic type (IPv4, IPv6, L2) */ |
Pablo Camarillo | 4521afa | 2017-03-16 10:43:05 +0100 | [diff] [blame] | 176 | u8 padding[3]; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 177 | } sr_steering_key_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 178 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 179 | typedef struct |
| 180 | { |
| 181 | sr_steering_key_t classify; /**< Traffic classification */ |
| 182 | u32 sr_policy; /**< SR Policy index */ |
| 183 | } ip6_sr_steering_policy_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 184 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 185 | /** |
| 186 | * @brief Segment Routing main datastructure |
| 187 | */ |
| 188 | typedef struct |
| 189 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 190 | /* L2-input -> SR rewrite next index */ |
| 191 | u32 l2_sr_policy_rewrite_index; |
| 192 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 193 | /* SR SID lists */ |
| 194 | ip6_sr_sl_t *sid_lists; |
| 195 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 196 | /* SRv6 policies */ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 197 | ip6_sr_policy_t *sr_policies; |
| 198 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 199 | /* Hash table mapping BindingSID to SRv6 policy */ |
Pablo Camarillo | 4521afa | 2017-03-16 10:43:05 +0100 | [diff] [blame] | 200 | mhash_t sr_policies_index_hash; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 201 | |
| 202 | /* Pool of SR localsid instances */ |
| 203 | ip6_sr_localsid_t *localsids; |
| 204 | |
Pablo Camarillo | 4521afa | 2017-03-16 10:43:05 +0100 | [diff] [blame] | 205 | /* Hash table mapping LOC:FUNC to SR LocalSID instance */ |
| 206 | mhash_t sr_localsids_index_hash; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 207 | |
| 208 | /* Pool of SR steer policies instances */ |
| 209 | ip6_sr_steering_policy_t *steer_policies; |
| 210 | |
Pablo Camarillo | 4521afa | 2017-03-16 10:43:05 +0100 | [diff] [blame] | 211 | /* Hash table mapping steering rules to SR steer instance */ |
| 212 | mhash_t sr_steer_policies_hash; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 213 | |
| 214 | /* L2 steering ifaces - sr_policies */ |
| 215 | u32 *sw_iface_sr_policies; |
| 216 | |
| 217 | /* Spray DPO */ |
| 218 | dpo_type_t sr_pr_spray_dpo_type; |
| 219 | |
| 220 | /* Plugin functions */ |
| 221 | sr_localsid_fn_registration_t *plugin_functions; |
| 222 | |
| 223 | /* Find plugin function by name */ |
| 224 | uword *plugin_functions_by_key; |
| 225 | |
| 226 | /* Counters */ |
| 227 | vlib_combined_counter_main_t sr_ls_valid_counters; |
| 228 | vlib_combined_counter_main_t sr_ls_invalid_counters; |
| 229 | |
| 230 | /* SR Policies FIBs */ |
| 231 | u32 fib_table_ip6; |
| 232 | u32 fib_table_ip4; |
| 233 | |
| 234 | /* convenience */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 235 | vlib_main_t *vlib_main; |
| 236 | vnet_main_t *vnet_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 237 | } ip6_sr_main_t; |
| 238 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 239 | extern ip6_sr_main_t sr_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 240 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 241 | extern vlib_node_registration_t sr_policy_rewrite_encaps_node; |
| 242 | extern vlib_node_registration_t sr_policy_rewrite_insert_node; |
| 243 | extern vlib_node_registration_t sr_localsid_node; |
| 244 | extern vlib_node_registration_t sr_localsid_d_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 245 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 246 | extern void sr_dpo_lock (dpo_id_t * dpo); |
| 247 | extern void sr_dpo_unlock (dpo_id_t * dpo); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 248 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 249 | extern int |
| 250 | sr_localsid_register_function (vlib_main_t * vm, u8 * fn_name, |
| 251 | u8 * keyword_str, u8 * def_str, |
| 252 | u8 * params_str, dpo_type_t * dpo, |
| 253 | format_function_t * ls_format, |
| 254 | unformat_function_t * ls_unformat, |
| 255 | sr_plugin_callback_t * creation_fn, |
| 256 | sr_plugin_callback_t * removal_fn); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 257 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 258 | extern int |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 259 | sr_policy_add (ip6_address_t * bsid, ip6_address_t * segments, |
| 260 | u32 weight, u8 behavior, u32 fib_table, u8 is_encap); |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 261 | extern int |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 262 | sr_policy_mod (ip6_address_t * bsid, u32 index, u32 fib_table, |
| 263 | u8 operation, ip6_address_t * segments, u32 sl_index, |
| 264 | u32 weight); |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 265 | extern int sr_policy_del (ip6_address_t * bsid, u32 index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 266 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 267 | extern int |
| 268 | sr_cli_localsid (char is_del, ip6_address_t * localsid_addr, |
| 269 | char end_psp, u8 behavior, u32 sw_if_index, |
| 270 | u32 vlan_index, u32 fib_table, ip46_address_t * nh_addr, |
| 271 | void *ls_plugin_mem); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 272 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 273 | extern int |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 274 | sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index, |
| 275 | u32 table_id, ip46_address_t * prefix, u32 mask_width, |
| 276 | u32 sw_if_index, u8 traffic_type); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 277 | |
Shwetha Bhandari | 78372a9 | 2017-01-18 12:43:54 +0530 | [diff] [blame] | 278 | /** |
| 279 | * @brief SR rewrite string computation for SRH insertion (inline) |
| 280 | * |
| 281 | * @param sl is a vector of IPv6 addresses composing the Segment List |
| 282 | * |
| 283 | * @return precomputed rewrite string for SRH insertion |
| 284 | */ |
| 285 | static inline u8 * |
shwethab | e146f13 | 2017-03-09 16:58:26 +0000 | [diff] [blame] | 286 | ip6_sr_compute_rewrite_string_insert (ip6_address_t * sl) |
Shwetha Bhandari | 78372a9 | 2017-01-18 12:43:54 +0530 | [diff] [blame] | 287 | { |
| 288 | ip6_sr_header_t *srh; |
| 289 | ip6_address_t *addrp, *this_address; |
| 290 | u32 header_length = 0; |
| 291 | u8 *rs = NULL; |
| 292 | |
| 293 | header_length = 0; |
| 294 | header_length += sizeof (ip6_sr_header_t); |
| 295 | header_length += (vec_len (sl) + 1) * sizeof (ip6_address_t); |
| 296 | |
| 297 | vec_validate (rs, header_length - 1); |
| 298 | |
| 299 | srh = (ip6_sr_header_t *) rs; |
| 300 | srh->type = ROUTING_HEADER_TYPE_SR; |
| 301 | srh->segments_left = vec_len (sl); |
| 302 | srh->first_segment = vec_len (sl); |
| 303 | srh->length = ((sizeof (ip6_sr_header_t) + |
| 304 | ((vec_len (sl) + 1) * sizeof (ip6_address_t))) / 8) - 1; |
| 305 | srh->flags = 0x00; |
| 306 | srh->reserved = 0x0000; |
| 307 | addrp = srh->segments + vec_len (sl); |
| 308 | vec_foreach (this_address, sl) |
| 309 | { |
| 310 | clib_memcpy (addrp->as_u8, this_address->as_u8, sizeof (ip6_address_t)); |
| 311 | addrp--; |
| 312 | } |
| 313 | return rs; |
| 314 | } |
| 315 | |
| 316 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 317 | #endif /* included_vnet_sr_h */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 318 | |
| 319 | /* |
| 320 | * fd.io coding-style-patch-verification: ON |
| 321 | * |
| 322 | * Local Variables: |
| 323 | * eval: (c-set-style "gnu") |
| 324 | * End: |
| 325 | */ |