blob: 2353b284363b72f8eca269cb405087fa790cf6b6 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 Camarillofb380952016-12-07 18:34:18 +010015
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070016/**
17 * @file
Pablo Camarillofb380952016-12-07 18:34:18 +010018 * @brief Segment Routing data structures definitions
19 *
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070020 */
Pablo Camarillofb380952016-12-07 18:34:18 +010021
Pablo Camarillo5d73eec2017-04-24 17:51:56 +020022#ifndef included_vnet_srv6_h
23#define included_vnet_srv6_h
Ed Warnickecb9cada2015-12-08 15:45:58 -070024
25#include <vnet/vnet.h>
Pablo Camarillo5d73eec2017-04-24 17:51:56 +020026#include <vnet/srv6/sr_packet.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070027#include <vnet/ip/ip6_packet.h>
Pablo Camarillofb380952016-12-07 18:34:18 +010028#include <vnet/ethernet/ethernet.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070029
Ed Warnickecb9cada2015-12-08 15:45:58 -070030#include <stdlib.h>
31#include <string.h>
32
Pablo Camarillofb380952016-12-07 18:34:18 +010033#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 Camarillo7a4e0922017-06-06 15:18:12 +020039#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 Camarillofb380952016-12-07 18:34:18 +010047
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 Warnickecb9cada2015-12-08 15:45:58 -070056
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070057/**
Pablo Camarillofb380952016-12-07 18:34:18 +010058 * @brief SR Segment List (SID list)
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070059 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070060typedef struct
61{
Pablo Camarillofb380952016-12-07 18:34:18 +010062 ip6_address_t *segments; /**< SIDs (key) */
Ed Warnickecb9cada2015-12-08 15:45:58 -070063
Pablo Camarillofb380952016-12-07 18:34:18 +010064 u32 weight; /**< SID list weight (wECMP / UCMP) */
65
66 u8 *rewrite; /**< Precomputed rewrite header */
67 u8 *rewrite_bsid; /**< Precomputed rewrite header for bindingSID */
68
69 dpo_id_t bsid_dpo; /**< DPO for Encaps/Insert for BSID */
70 dpo_id_t ip6_dpo; /**< DPO for Encaps/Insert IPv6 */
71 dpo_id_t ip4_dpo; /**< DPO for Encaps IPv6 */
72} ip6_sr_sl_t;
73
74/* SR policy types */
75#define SR_POLICY_TYPE_DEFAULT 0
76#define SR_POLICY_TYPE_SPRAY 1
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070077/**
Pablo Camarillofb380952016-12-07 18:34:18 +010078 * @brief SR Policy
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070079 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070080typedef struct
81{
Pablo Camarillofb380952016-12-07 18:34:18 +010082 u32 *segments_lists; /**< SID lists indexes (vector) */
Ed Warnickecb9cada2015-12-08 15:45:58 -070083
Pablo Camarillofb380952016-12-07 18:34:18 +010084 ip6_address_t bsid; /**< BindingSID (key) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070085
Pablo Camarillofb380952016-12-07 18:34:18 +010086 u8 type; /**< Type (default is 0) */
Pablo Camarillo5d73eec2017-04-24 17:51:56 +020087 /* SR Policy specific DPO */
Pablo Camarillofb380952016-12-07 18:34:18 +010088 /* IF Type = DEFAULT Then Load Balancer DPO among SID lists */
Pablo Camarillo5d73eec2017-04-24 17:51:56 +020089 /* IF Type = SPRAY then Spray DPO with all SID lists */
Pablo Camarillofb380952016-12-07 18:34:18 +010090 dpo_id_t bsid_dpo; /**< SR Policy specific DPO - BSID */
91 dpo_id_t ip4_dpo; /**< SR Policy specific DPO - IPv6 */
92 dpo_id_t ip6_dpo; /**< SR Policy specific DPO - IPv4 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070093
Pablo Camarillofb380952016-12-07 18:34:18 +010094 u32 fib_table; /**< FIB table */
Ed Warnickecb9cada2015-12-08 15:45:58 -070095
Pablo Camarillofb380952016-12-07 18:34:18 +010096 u8 is_encap; /**< Mode (0 is SRH insert, 1 Encaps) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -070097} ip6_sr_policy_t;
98
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070099/**
Pablo Camarillofb380952016-12-07 18:34:18 +0100100 * @brief SR LocalSID
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700101 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700102typedef struct
103{
Pablo Camarillofb380952016-12-07 18:34:18 +0100104 ip6_address_t localsid; /**< LocalSID IPv6 address */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700105
Pablo Camarillofb380952016-12-07 18:34:18 +0100106 char end_psp; /**< Combined with End.PSP? */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700107
Pablo Camarillofb380952016-12-07 18:34:18 +0100108 u16 behavior; /**< Behavior associated to this localsid */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700109
Pablo Camarillofb380952016-12-07 18:34:18 +0100110 union
111 {
112 u32 sw_if_index; /**< xconnect only */
113 u32 vrf_index; /**< vrf only */
114 };
115
116 u32 fib_table; /**< FIB table where localsid is registered */
117
118 u32 vlan_index; /**< VLAN tag (not an index) */
119
120 ip46_address_t next_hop; /**< Next_hop for xconnect usage only */
121
122 u32 nh_adj; /**< Next_adj for xconnect usage only */
123
124 void *plugin_mem; /**< Memory to be used by the plugin callback functions */
125} ip6_sr_localsid_t;
126
127typedef int (sr_plugin_callback_t) (ip6_sr_localsid_t * localsid);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700128
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700129/**
Pablo Camarillofb380952016-12-07 18:34:18 +0100130 * @brief SR LocalSID behavior registration
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700131 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700132typedef struct
133{
Pablo Camarillofb380952016-12-07 18:34:18 +0100134 u16 sr_localsid_function_number; /**< SR LocalSID plugin function (>SR_BEHAVIOR_LAST) */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700135
Pablo Camarillofb380952016-12-07 18:34:18 +0100136 u8 *function_name; /**< Function name. (key). */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700137
Pablo Camarillofb380952016-12-07 18:34:18 +0100138 u8 *keyword_str; /**< Behavior keyword (i.e. End.X) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700139
Pablo Camarillofb380952016-12-07 18:34:18 +0100140 u8 *def_str; /**< Behavior definition (i.e. Endpoint with cross-connect) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700141
Pablo Camarillofb380952016-12-07 18:34:18 +0100142 u8 *params_str; /**< Behavior parameters (i.e. <oif> <IP46next_hop>) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700143
Pablo Camarillofb380952016-12-07 18:34:18 +0100144 dpo_type_t dpo; /**< DPO type registration */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700145
Pablo Camarillofb380952016-12-07 18:34:18 +0100146 format_function_t *ls_format; /**< LocalSID format function */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700147
Pablo Camarillofb380952016-12-07 18:34:18 +0100148 unformat_function_t *ls_unformat; /**< LocalSID unformat function */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700149
Pablo Camarillofb380952016-12-07 18:34:18 +0100150 sr_plugin_callback_t *creation; /**< Function within plugin that will be called after localsid creation*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700151
Pablo Camarillofb380952016-12-07 18:34:18 +0100152 sr_plugin_callback_t *removal; /**< Function within plugin that will be called before localsid removal */
153} sr_localsid_fn_registration_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700154
Pablo Camarillofb380952016-12-07 18:34:18 +0100155/**
156 * @brief Steering db key
157 *
158 * L3 is IPv4/IPv6 + mask
159 * L2 is sf_if_index + vlan
160 */
161typedef struct
162{
163 union
164 {
165 struct
166 {
167 ip46_address_t prefix; /**< IP address of the prefix */
168 u32 mask_width; /**< Mask width of the prefix */
169 u32 fib_table; /**< VRF of the prefix */
170 } l3;
171 struct
172 {
173 u32 sw_if_index; /**< Incoming software interface */
174 } l2;
175 };
176 u8 traffic_type; /**< Traffic type (IPv4, IPv6, L2) */
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100177 u8 padding[3];
Pablo Camarillofb380952016-12-07 18:34:18 +0100178} sr_steering_key_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700179
Pablo Camarillofb380952016-12-07 18:34:18 +0100180typedef struct
181{
182 sr_steering_key_t classify; /**< Traffic classification */
183 u32 sr_policy; /**< SR Policy index */
184} ip6_sr_steering_policy_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700185
Pablo Camarillofb380952016-12-07 18:34:18 +0100186/**
187 * @brief Segment Routing main datastructure
188 */
189typedef struct
190{
Pablo Camarillofb380952016-12-07 18:34:18 +0100191 /* L2-input -> SR rewrite next index */
192 u32 l2_sr_policy_rewrite_index;
193
Pablo Camarillofb380952016-12-07 18:34:18 +0100194 /* SR SID lists */
195 ip6_sr_sl_t *sid_lists;
196
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200197 /* SRv6 policies */
Pablo Camarillofb380952016-12-07 18:34:18 +0100198 ip6_sr_policy_t *sr_policies;
199
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200200 /* Hash table mapping BindingSID to SRv6 policy */
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100201 mhash_t sr_policies_index_hash;
Pablo Camarillofb380952016-12-07 18:34:18 +0100202
203 /* Pool of SR localsid instances */
204 ip6_sr_localsid_t *localsids;
205
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100206 /* Hash table mapping LOC:FUNC to SR LocalSID instance */
207 mhash_t sr_localsids_index_hash;
Pablo Camarillofb380952016-12-07 18:34:18 +0100208
209 /* Pool of SR steer policies instances */
210 ip6_sr_steering_policy_t *steer_policies;
211
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100212 /* Hash table mapping steering rules to SR steer instance */
213 mhash_t sr_steer_policies_hash;
Pablo Camarillofb380952016-12-07 18:34:18 +0100214
215 /* L2 steering ifaces - sr_policies */
216 u32 *sw_iface_sr_policies;
217
218 /* Spray DPO */
219 dpo_type_t sr_pr_spray_dpo_type;
220
221 /* Plugin functions */
222 sr_localsid_fn_registration_t *plugin_functions;
223
224 /* Find plugin function by name */
225 uword *plugin_functions_by_key;
226
227 /* Counters */
228 vlib_combined_counter_main_t sr_ls_valid_counters;
229 vlib_combined_counter_main_t sr_ls_invalid_counters;
230
231 /* SR Policies FIBs */
232 u32 fib_table_ip6;
233 u32 fib_table_ip4;
234
235 /* convenience */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700236 vlib_main_t *vlib_main;
237 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700238} ip6_sr_main_t;
239
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200240extern ip6_sr_main_t sr_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700241
Pablo Camarillofb380952016-12-07 18:34:18 +0100242extern vlib_node_registration_t sr_policy_rewrite_encaps_node;
243extern vlib_node_registration_t sr_policy_rewrite_insert_node;
244extern vlib_node_registration_t sr_localsid_node;
245extern vlib_node_registration_t sr_localsid_d_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700246
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200247extern void sr_dpo_lock (dpo_id_t * dpo);
248extern void sr_dpo_unlock (dpo_id_t * dpo);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700249
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200250extern int
251sr_localsid_register_function (vlib_main_t * vm, u8 * fn_name,
252 u8 * keyword_str, u8 * def_str,
253 u8 * params_str, dpo_type_t * dpo,
254 format_function_t * ls_format,
255 unformat_function_t * ls_unformat,
256 sr_plugin_callback_t * creation_fn,
257 sr_plugin_callback_t * removal_fn);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700258
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200259extern int
Pablo Camarillofb380952016-12-07 18:34:18 +0100260sr_policy_add (ip6_address_t * bsid, ip6_address_t * segments,
261 u32 weight, u8 behavior, u32 fib_table, u8 is_encap);
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200262extern int
Pablo Camarillofb380952016-12-07 18:34:18 +0100263sr_policy_mod (ip6_address_t * bsid, u32 index, u32 fib_table,
264 u8 operation, ip6_address_t * segments, u32 sl_index,
265 u32 weight);
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200266extern int sr_policy_del (ip6_address_t * bsid, u32 index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700267
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200268extern int
269sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
270 char end_psp, u8 behavior, u32 sw_if_index,
271 u32 vlan_index, u32 fib_table, ip46_address_t * nh_addr,
272 void *ls_plugin_mem);
Pablo Camarillofb380952016-12-07 18:34:18 +0100273
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200274extern int
Pablo Camarillofb380952016-12-07 18:34:18 +0100275sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
276 u32 table_id, ip46_address_t * prefix, u32 mask_width,
277 u32 sw_if_index, u8 traffic_type);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700278
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100279extern void sr_set_source (ip6_address_t * address);
280
Shwetha Bhandari78372a92017-01-18 12:43:54 +0530281/**
282 * @brief SR rewrite string computation for SRH insertion (inline)
283 *
284 * @param sl is a vector of IPv6 addresses composing the Segment List
285 *
286 * @return precomputed rewrite string for SRH insertion
287 */
288static inline u8 *
shwethabe146f132017-03-09 16:58:26 +0000289ip6_sr_compute_rewrite_string_insert (ip6_address_t * sl)
Shwetha Bhandari78372a92017-01-18 12:43:54 +0530290{
291 ip6_sr_header_t *srh;
292 ip6_address_t *addrp, *this_address;
293 u32 header_length = 0;
294 u8 *rs = NULL;
295
296 header_length = 0;
297 header_length += sizeof (ip6_sr_header_t);
298 header_length += (vec_len (sl) + 1) * sizeof (ip6_address_t);
299
300 vec_validate (rs, header_length - 1);
301
302 srh = (ip6_sr_header_t *) rs;
303 srh->type = ROUTING_HEADER_TYPE_SR;
304 srh->segments_left = vec_len (sl);
305 srh->first_segment = vec_len (sl);
306 srh->length = ((sizeof (ip6_sr_header_t) +
307 ((vec_len (sl) + 1) * sizeof (ip6_address_t))) / 8) - 1;
308 srh->flags = 0x00;
309 srh->reserved = 0x0000;
310 addrp = srh->segments + vec_len (sl);
311 vec_foreach (this_address, sl)
312 {
Dave Barach178cf492018-11-13 16:34:13 -0500313 clib_memcpy_fast (addrp->as_u8, this_address->as_u8,
314 sizeof (ip6_address_t));
Shwetha Bhandari78372a92017-01-18 12:43:54 +0530315 addrp--;
316 }
317 return rs;
318}
319
320
Ed Warnickecb9cada2015-12-08 15:45:58 -0700321#endif /* included_vnet_sr_h */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700322
323/*
324 * fd.io coding-style-patch-verification: ON
325 *
326 * Local Variables:
327 * eval: (c-set-style "gnu")
328 * End:
329 */