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