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 |
Pablo Camarillo | 7a4e092 | 2017-06-06 15:18:12 +0200 | [diff] [blame] | 39 | #define SR_BEHAVIOR_T 3 |
| 40 | #define SR_BEHAVIOR_D_FIRST 4 /* Unused. Separator in between regular and D */ |
| 41 | #define SR_BEHAVIOR_DX2 5 |
| 42 | #define SR_BEHAVIOR_DX6 6 |
| 43 | #define SR_BEHAVIOR_DX4 7 |
| 44 | #define SR_BEHAVIOR_DT6 8 |
| 45 | #define SR_BEHAVIOR_DT4 9 |
| 46 | #define SR_BEHAVIOR_LAST 10 /* Must always be the last one */ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 47 | |
| 48 | #define SR_STEER_L2 2 |
| 49 | #define SR_STEER_IPV4 4 |
| 50 | #define SR_STEER_IPV6 6 |
| 51 | |
| 52 | #define SR_FUNCTION_SIZE 4 |
| 53 | #define SR_ARGUMENT_SIZE 4 |
| 54 | |
| 55 | #define SR_SEGMENT_LIST_WEIGHT_DEFAULT 1 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 57 | /* *INDENT-OFF* */ |
| 58 | typedef struct |
| 59 | { |
| 60 | ip6_header_t ip; |
| 61 | ip6_sr_header_t sr; |
| 62 | } __attribute__ ((packed)) ip6srv_combo_header_t; |
| 63 | /* *INDENT-ON* */ |
| 64 | |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 65 | /** |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 66 | * @brief SR Segment List (SID list) |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 67 | */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 68 | typedef struct |
| 69 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 70 | ip6_address_t *segments; /**< SIDs (key) */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 72 | u32 weight; /**< SID list weight (wECMP / UCMP) */ |
| 73 | |
| 74 | u8 *rewrite; /**< Precomputed rewrite header */ |
| 75 | u8 *rewrite_bsid; /**< Precomputed rewrite header for bindingSID */ |
| 76 | |
| 77 | dpo_id_t bsid_dpo; /**< DPO for Encaps/Insert for BSID */ |
| 78 | dpo_id_t ip6_dpo; /**< DPO for Encaps/Insert IPv6 */ |
| 79 | dpo_id_t ip4_dpo; /**< DPO for Encaps IPv6 */ |
Tetsuya Murakami | 70d8ef8 | 2019-12-04 18:57:46 -0800 | [diff] [blame] | 80 | |
| 81 | u16 plugin; |
| 82 | void *plugin_mem; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 83 | } ip6_sr_sl_t; |
| 84 | |
| 85 | /* SR policy types */ |
| 86 | #define SR_POLICY_TYPE_DEFAULT 0 |
| 87 | #define SR_POLICY_TYPE_SPRAY 1 |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 88 | /** |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 89 | * @brief SR Policy |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 90 | */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 91 | typedef struct |
| 92 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 93 | u32 *segments_lists; /**< SID lists indexes (vector) */ |
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 | ip6_address_t bsid; /**< BindingSID (key) */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 96 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 97 | u8 type; /**< Type (default is 0) */ |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 98 | /* SR Policy specific DPO */ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 99 | /* IF Type = DEFAULT Then Load Balancer DPO among SID lists */ |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 100 | /* IF Type = SPRAY then Spray DPO with all SID lists */ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 101 | dpo_id_t bsid_dpo; /**< SR Policy specific DPO - BSID */ |
| 102 | dpo_id_t ip4_dpo; /**< SR Policy specific DPO - IPv6 */ |
| 103 | dpo_id_t ip6_dpo; /**< SR Policy specific DPO - IPv4 */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 104 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 105 | u32 fib_table; /**< FIB table */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 106 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 107 | u8 is_encap; /**< Mode (0 is SRH insert, 1 Encaps) */ |
Tetsuya Murakami | 70d8ef8 | 2019-12-04 18:57:46 -0800 | [diff] [blame] | 108 | |
| 109 | u16 plugin; |
| 110 | void *plugin_mem; |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 111 | } ip6_sr_policy_t; |
| 112 | |
Tetsuya Murakami | 70d8ef8 | 2019-12-04 18:57:46 -0800 | [diff] [blame] | 113 | typedef int (sr_p_plugin_callback_t) (ip6_sr_policy_t * sr); |
| 114 | |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 115 | /** |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 116 | * @brief SR LocalSID |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 117 | */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 118 | typedef struct |
| 119 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 120 | ip6_address_t localsid; /**< LocalSID IPv6 address */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 121 | |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 122 | u16 localsid_len; |
| 123 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 124 | char end_psp; /**< Combined with End.PSP? */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 125 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 126 | u16 behavior; /**< Behavior associated to this localsid */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 127 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 128 | union |
| 129 | { |
| 130 | u32 sw_if_index; /**< xconnect only */ |
| 131 | u32 vrf_index; /**< vrf only */ |
| 132 | }; |
| 133 | |
| 134 | u32 fib_table; /**< FIB table where localsid is registered */ |
| 135 | |
| 136 | u32 vlan_index; /**< VLAN tag (not an index) */ |
| 137 | |
| 138 | ip46_address_t next_hop; /**< Next_hop for xconnect usage only */ |
| 139 | |
| 140 | u32 nh_adj; /**< Next_adj for xconnect usage only */ |
| 141 | |
| 142 | void *plugin_mem; /**< Memory to be used by the plugin callback functions */ |
| 143 | } ip6_sr_localsid_t; |
| 144 | |
| 145 | typedef int (sr_plugin_callback_t) (ip6_sr_localsid_t * localsid); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 146 | |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 147 | /** |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 148 | * @brief SR LocalSID behavior registration |
Keith Burns (alagalah) | 7214cf1 | 2016-08-08 15:56:50 -0700 | [diff] [blame] | 149 | */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 150 | typedef struct |
| 151 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 152 | u16 sr_localsid_function_number; /**< SR LocalSID plugin function (>SR_BEHAVIOR_LAST) */ |
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 | u8 *function_name; /**< Function name. (key). */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 155 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 156 | u8 *keyword_str; /**< Behavior keyword (i.e. End.X) */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 157 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 158 | u8 *def_str; /**< Behavior definition (i.e. Endpoint with cross-connect) */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 159 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 160 | u8 *params_str; /**< Behavior parameters (i.e. <oif> <IP46next_hop>) */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 161 | |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 162 | u8 prefix_length; |
| 163 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 164 | dpo_type_t dpo; /**< DPO type registration */ |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 165 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 166 | format_function_t *ls_format; /**< LocalSID format function */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 167 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 168 | unformat_function_t *ls_unformat; /**< LocalSID unformat function */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 169 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 170 | 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] | 171 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 172 | sr_plugin_callback_t *removal; /**< Function within plugin that will be called before localsid removal */ |
| 173 | } sr_localsid_fn_registration_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 174 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 175 | /** |
Tetsuya Murakami | 70d8ef8 | 2019-12-04 18:57:46 -0800 | [diff] [blame] | 176 | * @brief SR Policy behavior registration |
| 177 | */ |
| 178 | typedef struct |
| 179 | { |
| 180 | u16 sr_policy_function_number; /**< SR Policy plugin function */ |
| 181 | |
| 182 | u8 *function_name; /**< Function name. (key). */ |
| 183 | |
| 184 | u8 *keyword_str; /**< Behavior keyword (i.e. End.X) */ |
| 185 | |
| 186 | u8 *def_str; /**< Behavior definition (i.e. Endpoint with cross-connect) */ |
| 187 | |
| 188 | u8 *params_str; /**< Behavior parameters (i.e. <oif> <IP46next_hop>) */ |
| 189 | |
| 190 | u8 prefix_length; |
| 191 | |
| 192 | dpo_type_t dpo; /**< DPO type registration */ |
| 193 | |
| 194 | format_function_t *ls_format; /**< LocalSID format function */ |
| 195 | |
| 196 | unformat_function_t *ls_unformat; /**< LocalSID unformat function */ |
| 197 | |
| 198 | sr_p_plugin_callback_t *creation; /**< Function within plugin that will be called after localsid creation*/ |
| 199 | |
| 200 | sr_p_plugin_callback_t *removal; /**< Function within plugin that will be called before localsid removal */ |
| 201 | } sr_policy_fn_registration_t; |
| 202 | |
| 203 | /** |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 204 | * @brief Steering db key |
| 205 | * |
| 206 | * L3 is IPv4/IPv6 + mask |
| 207 | * L2 is sf_if_index + vlan |
| 208 | */ |
| 209 | typedef struct |
| 210 | { |
| 211 | union |
| 212 | { |
| 213 | struct |
| 214 | { |
| 215 | ip46_address_t prefix; /**< IP address of the prefix */ |
| 216 | u32 mask_width; /**< Mask width of the prefix */ |
| 217 | u32 fib_table; /**< VRF of the prefix */ |
| 218 | } l3; |
| 219 | struct |
| 220 | { |
| 221 | u32 sw_if_index; /**< Incoming software interface */ |
| 222 | } l2; |
| 223 | }; |
| 224 | u8 traffic_type; /**< Traffic type (IPv4, IPv6, L2) */ |
Pablo Camarillo | 4521afa | 2017-03-16 10:43:05 +0100 | [diff] [blame] | 225 | u8 padding[3]; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 226 | } sr_steering_key_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 227 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 228 | typedef struct |
| 229 | { |
| 230 | sr_steering_key_t classify; /**< Traffic classification */ |
| 231 | u32 sr_policy; /**< SR Policy index */ |
| 232 | } ip6_sr_steering_policy_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 234 | /** |
| 235 | * @brief Segment Routing main datastructure |
| 236 | */ |
| 237 | typedef struct |
| 238 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 239 | /* L2-input -> SR rewrite next index */ |
| 240 | u32 l2_sr_policy_rewrite_index; |
| 241 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 242 | /* SR SID lists */ |
| 243 | ip6_sr_sl_t *sid_lists; |
| 244 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 245 | /* SRv6 policies */ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 246 | ip6_sr_policy_t *sr_policies; |
| 247 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 248 | /* Hash table mapping BindingSID to SRv6 policy */ |
Pablo Camarillo | 4521afa | 2017-03-16 10:43:05 +0100 | [diff] [blame] | 249 | mhash_t sr_policies_index_hash; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 250 | |
| 251 | /* Pool of SR localsid instances */ |
| 252 | ip6_sr_localsid_t *localsids; |
| 253 | |
Pablo Camarillo | 4521afa | 2017-03-16 10:43:05 +0100 | [diff] [blame] | 254 | /* Hash table mapping LOC:FUNC to SR LocalSID instance */ |
| 255 | mhash_t sr_localsids_index_hash; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 256 | |
| 257 | /* Pool of SR steer policies instances */ |
| 258 | ip6_sr_steering_policy_t *steer_policies; |
| 259 | |
Pablo Camarillo | 4521afa | 2017-03-16 10:43:05 +0100 | [diff] [blame] | 260 | /* Hash table mapping steering rules to SR steer instance */ |
| 261 | mhash_t sr_steer_policies_hash; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 262 | |
| 263 | /* L2 steering ifaces - sr_policies */ |
| 264 | u32 *sw_iface_sr_policies; |
| 265 | |
| 266 | /* Spray DPO */ |
| 267 | dpo_type_t sr_pr_spray_dpo_type; |
| 268 | |
| 269 | /* Plugin functions */ |
| 270 | sr_localsid_fn_registration_t *plugin_functions; |
| 271 | |
| 272 | /* Find plugin function by name */ |
| 273 | uword *plugin_functions_by_key; |
| 274 | |
Tetsuya Murakami | 70d8ef8 | 2019-12-04 18:57:46 -0800 | [diff] [blame] | 275 | /* Plugin functions for Policy */ |
| 276 | sr_policy_fn_registration_t *policy_plugin_functions; |
| 277 | |
| 278 | /* Find plugin function by name */ |
| 279 | uword *policy_plugin_functions_by_key; |
| 280 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 281 | /* Counters */ |
| 282 | vlib_combined_counter_main_t sr_ls_valid_counters; |
| 283 | vlib_combined_counter_main_t sr_ls_invalid_counters; |
| 284 | |
| 285 | /* SR Policies FIBs */ |
| 286 | u32 fib_table_ip6; |
| 287 | u32 fib_table_ip4; |
| 288 | |
| 289 | /* convenience */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 290 | vlib_main_t *vlib_main; |
| 291 | vnet_main_t *vnet_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 292 | } ip6_sr_main_t; |
| 293 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 294 | extern ip6_sr_main_t sr_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 295 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 296 | extern vlib_node_registration_t sr_policy_rewrite_encaps_node; |
| 297 | extern vlib_node_registration_t sr_policy_rewrite_insert_node; |
| 298 | extern vlib_node_registration_t sr_localsid_node; |
| 299 | extern vlib_node_registration_t sr_localsid_d_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 300 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 301 | extern void sr_dpo_lock (dpo_id_t * dpo); |
| 302 | extern void sr_dpo_unlock (dpo_id_t * dpo); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 303 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 304 | extern int |
| 305 | sr_localsid_register_function (vlib_main_t * vm, u8 * fn_name, |
| 306 | u8 * keyword_str, u8 * def_str, |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 307 | u8 * params_str, u8 prefix_length, |
| 308 | dpo_type_t * dpo, |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 309 | format_function_t * ls_format, |
| 310 | unformat_function_t * ls_unformat, |
| 311 | sr_plugin_callback_t * creation_fn, |
| 312 | sr_plugin_callback_t * removal_fn); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 313 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 314 | extern int |
Tetsuya Murakami | 70d8ef8 | 2019-12-04 18:57:46 -0800 | [diff] [blame] | 315 | sr_policy_register_function (vlib_main_t * vm, u8 * fn_name, |
| 316 | u8 * keyword_str, u8 * def_str, |
| 317 | u8 * params_str, u8 prefix_length, |
| 318 | dpo_type_t * dpo, |
| 319 | format_function_t * ls_format, |
| 320 | unformat_function_t * ls_unformat, |
| 321 | sr_p_plugin_callback_t * creation_fn, |
| 322 | sr_p_plugin_callback_t * removal_fn); |
| 323 | |
| 324 | extern int |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 325 | sr_policy_add (ip6_address_t * bsid, ip6_address_t * segments, |
Tetsuya Murakami | 70d8ef8 | 2019-12-04 18:57:46 -0800 | [diff] [blame] | 326 | u32 weight, u8 behavior, u32 fib_table, u8 is_encap, |
| 327 | u16 plugin, void *plugin_mem); |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 328 | extern int sr_policy_mod (ip6_address_t * bsid, u32 index, u32 fib_table, |
| 329 | u8 operation, ip6_address_t * segments, |
| 330 | u32 sl_index, u32 weight); |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 331 | extern int sr_policy_del (ip6_address_t * bsid, u32 index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 332 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 333 | extern int |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 334 | sr_cli_localsid (char is_del, ip6_address_t * localsid_addr, u16 prefixlen, |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 335 | char end_psp, u8 behavior, u32 sw_if_index, |
| 336 | u32 vlan_index, u32 fib_table, ip46_address_t * nh_addr, |
| 337 | void *ls_plugin_mem); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 338 | |
Pablo Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 339 | extern int |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 340 | sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index, |
| 341 | u32 table_id, ip46_address_t * prefix, u32 mask_width, |
| 342 | u32 sw_if_index, u8 traffic_type); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 343 | |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 344 | extern void sr_set_source (ip6_address_t * address); |
| 345 | |
Ignas Bačius | eeb5fb3 | 2019-10-03 17:15:38 +0300 | [diff] [blame] | 346 | extern void sr_set_hop_limit (u8 hop_limit); |
| 347 | extern u8 sr_get_hop_limit (void); |
| 348 | |
Shwetha Bhandari | 78372a9 | 2017-01-18 12:43:54 +0530 | [diff] [blame] | 349 | /** |
| 350 | * @brief SR rewrite string computation for SRH insertion (inline) |
| 351 | * |
| 352 | * @param sl is a vector of IPv6 addresses composing the Segment List |
| 353 | * |
| 354 | * @return precomputed rewrite string for SRH insertion |
| 355 | */ |
| 356 | static inline u8 * |
shwethab | e146f13 | 2017-03-09 16:58:26 +0000 | [diff] [blame] | 357 | ip6_sr_compute_rewrite_string_insert (ip6_address_t * sl) |
Shwetha Bhandari | 78372a9 | 2017-01-18 12:43:54 +0530 | [diff] [blame] | 358 | { |
| 359 | ip6_sr_header_t *srh; |
| 360 | ip6_address_t *addrp, *this_address; |
| 361 | u32 header_length = 0; |
| 362 | u8 *rs = NULL; |
| 363 | |
| 364 | header_length = 0; |
| 365 | header_length += sizeof (ip6_sr_header_t); |
| 366 | header_length += (vec_len (sl) + 1) * sizeof (ip6_address_t); |
| 367 | |
| 368 | vec_validate (rs, header_length - 1); |
| 369 | |
| 370 | srh = (ip6_sr_header_t *) rs; |
| 371 | srh->type = ROUTING_HEADER_TYPE_SR; |
| 372 | srh->segments_left = vec_len (sl); |
Ahmed Abdelsalam | be83704 | 2019-06-20 11:18:57 +0000 | [diff] [blame] | 373 | srh->last_entry = vec_len (sl); |
Shwetha Bhandari | 78372a9 | 2017-01-18 12:43:54 +0530 | [diff] [blame] | 374 | srh->length = ((sizeof (ip6_sr_header_t) + |
| 375 | ((vec_len (sl) + 1) * sizeof (ip6_address_t))) / 8) - 1; |
| 376 | srh->flags = 0x00; |
Ahmed Abdelsalam | be83704 | 2019-06-20 11:18:57 +0000 | [diff] [blame] | 377 | srh->tag = 0x0000; |
Shwetha Bhandari | 78372a9 | 2017-01-18 12:43:54 +0530 | [diff] [blame] | 378 | addrp = srh->segments + vec_len (sl); |
| 379 | vec_foreach (this_address, sl) |
| 380 | { |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 381 | clib_memcpy_fast (addrp->as_u8, this_address->as_u8, |
| 382 | sizeof (ip6_address_t)); |
Shwetha Bhandari | 78372a9 | 2017-01-18 12:43:54 +0530 | [diff] [blame] | 383 | addrp--; |
| 384 | } |
| 385 | return rs; |
| 386 | } |
| 387 | |
| 388 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 389 | #endif /* included_vnet_sr_h */ |
Keith Burns (alagalah) | 06c5ffd | 2016-08-06 08:32:45 -0700 | [diff] [blame] | 390 | |
| 391 | /* |
| 392 | * fd.io coding-style-patch-verification: ON |
| 393 | * |
| 394 | * Local Variables: |
| 395 | * eval: (c-set-style "gnu") |
| 396 | * End: |
| 397 | */ |