blob: c2867eb7508b67e0e9a166e7223320b066e805cc [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
Tetsuya Murakamiec9cb962020-03-23 16:10:28 -070046#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 Camarillofb380952016-12-07 18:34:18 +010049
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 Warnickecb9cada2015-12-08 15:45:58 -070058
Tetsuya Murakami1b81e6e2019-11-06 11:05:51 -080059typedef struct
60{
61 ip6_header_t ip;
62 ip6_sr_header_t sr;
63} __attribute__ ((packed)) ip6srv_combo_header_t;
Tetsuya Murakami1b81e6e2019-11-06 11:05:51 -080064
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070065/**
Pablo Camarillofb380952016-12-07 18:34:18 +010066 * @brief SR Segment List (SID list)
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070067 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070068typedef struct
69{
Pablo Camarillofb380952016-12-07 18:34:18 +010070 ip6_address_t *segments; /**< SIDs (key) */
Ed Warnickecb9cada2015-12-08 15:45:58 -070071
Pablo Camarillofb380952016-12-07 18:34:18 +010072 u32 weight; /**< SID list weight (wECMP / UCMP) */
73
74 u8 *rewrite; /**< Precomputed rewrite header */
75 u8 *rewrite_bsid; /**< Precomputed rewrite header for bindingSID */
Ahmed Abdelsalamad8b82d2021-08-24 15:59:39 +000076 u8 policy_type;
Pablo Camarillofb380952016-12-07 18:34:18 +010077
Tetsuya Murakami6b354912021-01-31 16:38:56 -080078 u32 egress_fib_table; /**< Egress FIB table for encap packet */
79
Pablo Camarillofb380952016-12-07 18:34:18 +010080 dpo_id_t bsid_dpo; /**< DPO for Encaps/Insert for BSID */
81 dpo_id_t ip6_dpo; /**< DPO for Encaps/Insert IPv6 */
82 dpo_id_t ip4_dpo; /**< DPO for Encaps IPv6 */
Tetsuya Murakami70d8ef82019-12-04 18:57:46 -080083
84 u16 plugin;
85 void *plugin_mem;
Pablo Camarillofb380952016-12-07 18:34:18 +010086} ip6_sr_sl_t;
87
88/* SR policy types */
89#define SR_POLICY_TYPE_DEFAULT 0
90#define SR_POLICY_TYPE_SPRAY 1
Ahmed Abdelsalam9cca6942022-06-06 15:54:02 +000091#define SR_POLICY_TYPE_TEF 2
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070092/**
Pablo Camarillofb380952016-12-07 18:34:18 +010093 * @brief SR Policy
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -070094 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -070095typedef struct
96{
Pablo Camarillofb380952016-12-07 18:34:18 +010097 u32 *segments_lists; /**< SID lists indexes (vector) */
Ed Warnickecb9cada2015-12-08 15:45:58 -070098
Pablo Camarillofb380952016-12-07 18:34:18 +010099 ip6_address_t bsid; /**< BindingSID (key) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700100
Pablo Camarillofb380952016-12-07 18:34:18 +0100101 u8 type; /**< Type (default is 0) */
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200102 /* SR Policy specific DPO */
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +0200103 /* IF Type = DEFAULT Then Load-Balancer DPO among SID lists */
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200104 /* IF Type = SPRAY then Spray DPO with all SID lists */
Pablo Camarillofb380952016-12-07 18:34:18 +0100105 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 Warnickecb9cada2015-12-08 15:45:58 -0700108
Pablo Camarillofb380952016-12-07 18:34:18 +0100109 u32 fib_table; /**< FIB table */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110
Pablo Camarillofb380952016-12-07 18:34:18 +0100111 u8 is_encap; /**< Mode (0 is SRH insert, 1 Encaps) */
Tetsuya Murakami70d8ef82019-12-04 18:57:46 -0800112
Takeru Hayasakac4c205b2022-12-30 16:41:44 +0900113 ip6_address_t encap_src;
114
Tetsuya Murakami70d8ef82019-12-04 18:57:46 -0800115 u16 plugin;
116 void *plugin_mem;
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700117} ip6_sr_policy_t;
118
Tetsuya Murakami70d8ef82019-12-04 18:57:46 -0800119typedef int (sr_p_plugin_callback_t) (ip6_sr_policy_t * sr);
120
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700121/**
Pablo Camarillofb380952016-12-07 18:34:18 +0100122 * @brief SR LocalSID
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700123 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700124typedef struct
125{
Pablo Camarillofb380952016-12-07 18:34:18 +0100126 ip6_address_t localsid; /**< LocalSID IPv6 address */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700127
Pablo Camarillo79bfd272019-12-18 17:13:13 +0000128 u16 localsid_prefix_len;
Tetsuya Murakami1b81e6e2019-11-06 11:05:51 -0800129
Pablo Camarillofb380952016-12-07 18:34:18 +0100130 char end_psp; /**< Combined with End.PSP? */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700131
Francesco Lombardo38659d82021-07-30 15:54:01 +0200132 u8 behavior; /**< Behavior associated to this localsid */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700133
Pablo Camarillofb380952016-12-07 18:34:18 +0100134 union
135 {
136 u32 sw_if_index; /**< xconnect only */
137 u32 vrf_index; /**< vrf only */
138 };
139
140 u32 fib_table; /**< FIB table where localsid is registered */
141
142 u32 vlan_index; /**< VLAN tag (not an index) */
143
144 ip46_address_t next_hop; /**< Next_hop for xconnect usage only */
145
146 u32 nh_adj; /**< Next_adj for xconnect usage only */
147
Tetsuya Murakamiec9cb962020-03-23 16:10:28 -0700148 ip6_address_t usid_block;
149 ip6_address_t usid_block_mask;
150
151 u8 usid_index;
152 u8 usid_len;
153
154 u8 usid_next_index;
155 u8 usid_next_len;
156
Pablo Camarillofb380952016-12-07 18:34:18 +0100157 void *plugin_mem; /**< Memory to be used by the plugin callback functions */
158} ip6_sr_localsid_t;
159
160typedef int (sr_plugin_callback_t) (ip6_sr_localsid_t * localsid);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700161
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700162/**
Pablo Camarillofb380952016-12-07 18:34:18 +0100163 * @brief SR LocalSID behavior registration
Keith Burns (alagalah)7214cf12016-08-08 15:56:50 -0700164 */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700165typedef struct
166{
Pablo Camarillofb380952016-12-07 18:34:18 +0100167 u16 sr_localsid_function_number; /**< SR LocalSID plugin function (>SR_BEHAVIOR_LAST) */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700168
Pablo Camarillofb380952016-12-07 18:34:18 +0100169 u8 *function_name; /**< Function name. (key). */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700170
Pablo Camarillofb380952016-12-07 18:34:18 +0100171 u8 *keyword_str; /**< Behavior keyword (i.e. End.X) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700172
Pablo Camarillofb380952016-12-07 18:34:18 +0100173 u8 *def_str; /**< Behavior definition (i.e. Endpoint with cross-connect) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700174
Pablo Camarillofb380952016-12-07 18:34:18 +0100175 u8 *params_str; /**< Behavior parameters (i.e. <oif> <IP46next_hop>) */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700176
Tetsuya Murakami1b81e6e2019-11-06 11:05:51 -0800177 u8 prefix_length;
178
Pablo Camarillofb380952016-12-07 18:34:18 +0100179 dpo_type_t dpo; /**< DPO type registration */
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700180
Pablo Camarillofb380952016-12-07 18:34:18 +0100181 format_function_t *ls_format; /**< LocalSID format function */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700182
Pablo Camarillofb380952016-12-07 18:34:18 +0100183 unformat_function_t *ls_unformat; /**< LocalSID unformat function */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700184
Pablo Camarillofb380952016-12-07 18:34:18 +0100185 sr_plugin_callback_t *creation; /**< Function within plugin that will be called after localsid creation*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700186
Pablo Camarillofb380952016-12-07 18:34:18 +0100187 sr_plugin_callback_t *removal; /**< Function within plugin that will be called before localsid removal */
188} sr_localsid_fn_registration_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700189
Pablo Camarillofb380952016-12-07 18:34:18 +0100190/**
Tetsuya Murakami70d8ef82019-12-04 18:57:46 -0800191 * @brief SR Policy behavior registration
192 */
193typedef struct
194{
195 u16 sr_policy_function_number; /**< SR Policy plugin function */
196
197 u8 *function_name; /**< Function name. (key). */
198
199 u8 *keyword_str; /**< Behavior keyword (i.e. End.X) */
200
201 u8 *def_str; /**< Behavior definition (i.e. Endpoint with cross-connect) */
202
203 u8 *params_str; /**< Behavior parameters (i.e. <oif> <IP46next_hop>) */
204
205 u8 prefix_length;
206
207 dpo_type_t dpo; /**< DPO type registration */
208
209 format_function_t *ls_format; /**< LocalSID format function */
210
211 unformat_function_t *ls_unformat; /**< LocalSID unformat function */
212
213 sr_p_plugin_callback_t *creation; /**< Function within plugin that will be called after localsid creation*/
214
215 sr_p_plugin_callback_t *removal; /**< Function within plugin that will be called before localsid removal */
216} sr_policy_fn_registration_t;
217
218/**
Pablo Camarillofb380952016-12-07 18:34:18 +0100219 * @brief Steering db key
220 *
221 * L3 is IPv4/IPv6 + mask
222 * L2 is sf_if_index + vlan
223 */
224typedef struct
225{
226 union
227 {
228 struct
229 {
230 ip46_address_t prefix; /**< IP address of the prefix */
231 u32 mask_width; /**< Mask width of the prefix */
232 u32 fib_table; /**< VRF of the prefix */
233 } l3;
234 struct
235 {
236 u32 sw_if_index; /**< Incoming software interface */
237 } l2;
238 };
239 u8 traffic_type; /**< Traffic type (IPv4, IPv6, L2) */
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100240 u8 padding[3];
Pablo Camarillofb380952016-12-07 18:34:18 +0100241} sr_steering_key_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700242
Pablo Camarillofb380952016-12-07 18:34:18 +0100243typedef struct
244{
245 sr_steering_key_t classify; /**< Traffic classification */
246 u32 sr_policy; /**< SR Policy index */
247} ip6_sr_steering_policy_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700248
Tetsuya Murakamiec9cb962020-03-23 16:10:28 -0700249typedef struct
250{
251 ip6_address_t address;
252 u16 pref_len;
253 u8 padding[2];
254} sr_localsid_key_t;
255
Pablo Camarillofb380952016-12-07 18:34:18 +0100256/**
257 * @brief Segment Routing main datastructure
258 */
259typedef struct
260{
Pablo Camarillofb380952016-12-07 18:34:18 +0100261 /* L2-input -> SR rewrite next index */
262 u32 l2_sr_policy_rewrite_index;
263
Pablo Camarillofb380952016-12-07 18:34:18 +0100264 /* SR SID lists */
265 ip6_sr_sl_t *sid_lists;
266
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200267 /* SRv6 policies */
Pablo Camarillofb380952016-12-07 18:34:18 +0100268 ip6_sr_policy_t *sr_policies;
269
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200270 /* Hash table mapping BindingSID to SRv6 policy */
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100271 mhash_t sr_policies_index_hash;
Pablo Camarillofb380952016-12-07 18:34:18 +0100272
273 /* Pool of SR localsid instances */
274 ip6_sr_localsid_t *localsids;
275
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100276 /* Hash table mapping LOC:FUNC to SR LocalSID instance */
277 mhash_t sr_localsids_index_hash;
Pablo Camarillofb380952016-12-07 18:34:18 +0100278
279 /* Pool of SR steer policies instances */
280 ip6_sr_steering_policy_t *steer_policies;
281
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100282 /* Hash table mapping steering rules to SR steer instance */
283 mhash_t sr_steer_policies_hash;
Pablo Camarillofb380952016-12-07 18:34:18 +0100284
285 /* L2 steering ifaces - sr_policies */
286 u32 *sw_iface_sr_policies;
287
288 /* Spray DPO */
289 dpo_type_t sr_pr_spray_dpo_type;
290
291 /* Plugin functions */
292 sr_localsid_fn_registration_t *plugin_functions;
293
294 /* Find plugin function by name */
295 uword *plugin_functions_by_key;
296
Tetsuya Murakami70d8ef82019-12-04 18:57:46 -0800297 /* Plugin functions for Policy */
298 sr_policy_fn_registration_t *policy_plugin_functions;
299
300 /* Find plugin function by name */
301 uword *policy_plugin_functions_by_key;
302
Pablo Camarillofb380952016-12-07 18:34:18 +0100303 /* Counters */
304 vlib_combined_counter_main_t sr_ls_valid_counters;
305 vlib_combined_counter_main_t sr_ls_invalid_counters;
306
307 /* SR Policies FIBs */
308 u32 fib_table_ip6;
309 u32 fib_table_ip4;
310
311 /* convenience */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700312 vlib_main_t *vlib_main;
313 vnet_main_t *vnet_main;
Filip Tehlare2fc0032021-06-22 13:00:40 +0000314 u16 msg_id_base;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700315} ip6_sr_main_t;
316
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200317extern ip6_sr_main_t sr_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700318
Pablo Camarillofb380952016-12-07 18:34:18 +0100319extern vlib_node_registration_t sr_policy_rewrite_encaps_node;
320extern vlib_node_registration_t sr_policy_rewrite_insert_node;
321extern vlib_node_registration_t sr_localsid_node;
322extern vlib_node_registration_t sr_localsid_d_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700323
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200324extern void sr_dpo_lock (dpo_id_t * dpo);
325extern void sr_dpo_unlock (dpo_id_t * dpo);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700326
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200327extern int
328sr_localsid_register_function (vlib_main_t * vm, u8 * fn_name,
329 u8 * keyword_str, u8 * def_str,
Tetsuya Murakami1b81e6e2019-11-06 11:05:51 -0800330 u8 * params_str, u8 prefix_length,
331 dpo_type_t * dpo,
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200332 format_function_t * ls_format,
333 unformat_function_t * ls_unformat,
334 sr_plugin_callback_t * creation_fn,
335 sr_plugin_callback_t * removal_fn);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700336
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200337extern int
Tetsuya Murakami70d8ef82019-12-04 18:57:46 -0800338sr_policy_register_function (vlib_main_t * vm, u8 * fn_name,
339 u8 * keyword_str, u8 * def_str,
340 u8 * params_str, u8 prefix_length,
341 dpo_type_t * dpo,
342 format_function_t * ls_format,
343 unformat_function_t * ls_unformat,
344 sr_p_plugin_callback_t * creation_fn,
345 sr_p_plugin_callback_t * removal_fn);
346
Ahmed Abdelsalamad8b82d2021-08-24 15:59:39 +0000347extern int sr_policy_add (ip6_address_t *bsid, ip6_address_t *segments,
Takeru Hayasakac4c205b2022-12-30 16:41:44 +0900348 ip6_address_t *encap_src, u32 weight, u8 type,
349 u32 fib_table, u8 is_encap, u16 plugin,
350 void *plugin_mem);
351extern int sr_policy_mod (ip6_address_t *bsid, u32 index, u32 fib_table,
352 u8 operation, ip6_address_t *segments,
353 ip6_address_t *encap_src, u32 sl_index, u32 weight);
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200354extern int sr_policy_del (ip6_address_t * bsid, u32 index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700355
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200356extern int
Pablo Camarillo79bfd272019-12-18 17:13:13 +0000357sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
358 u16 localsid_prefix_len, char end_psp, u8 behavior,
359 u32 sw_if_index, u32 vlan_index, u32 fib_table,
Tetsuya Murakamiec9cb962020-03-23 16:10:28 -0700360 ip46_address_t * nh_addr, int usid_len, void *ls_plugin_mem);
Pablo Camarillofb380952016-12-07 18:34:18 +0100361
Pablo Camarillo5d73eec2017-04-24 17:51:56 +0200362extern int
Pablo Camarillofb380952016-12-07 18:34:18 +0100363sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
364 u32 table_id, ip46_address_t * prefix, u32 mask_width,
365 u32 sw_if_index, u8 traffic_type);
Keith Burns (alagalah)52fc44d2016-03-25 09:38:50 -0700366
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100367extern void sr_set_source (ip6_address_t * address);
Ahmed Abdelsalam448bc812020-11-09 14:04:07 +0000368extern ip6_address_t *sr_get_encaps_source ();
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100369
Ignas Bačiuseeb5fb32019-10-03 17:15:38 +0300370extern void sr_set_hop_limit (u8 hop_limit);
371extern u8 sr_get_hop_limit (void);
372
Shwetha Bhandari78372a92017-01-18 12:43:54 +0530373/**
374 * @brief SR rewrite string computation for SRH insertion (inline)
375 *
376 * @param sl is a vector of IPv6 addresses composing the Segment List
377 *
378 * @return precomputed rewrite string for SRH insertion
379 */
380static inline u8 *
shwethabe146f132017-03-09 16:58:26 +0000381ip6_sr_compute_rewrite_string_insert (ip6_address_t * sl)
Shwetha Bhandari78372a92017-01-18 12:43:54 +0530382{
383 ip6_sr_header_t *srh;
384 ip6_address_t *addrp, *this_address;
385 u32 header_length = 0;
386 u8 *rs = NULL;
387
388 header_length = 0;
389 header_length += sizeof (ip6_sr_header_t);
390 header_length += (vec_len (sl) + 1) * sizeof (ip6_address_t);
391
392 vec_validate (rs, header_length - 1);
393
394 srh = (ip6_sr_header_t *) rs;
395 srh->type = ROUTING_HEADER_TYPE_SR;
396 srh->segments_left = vec_len (sl);
Ahmed Abdelsalambe837042019-06-20 11:18:57 +0000397 srh->last_entry = vec_len (sl);
Shwetha Bhandari78372a92017-01-18 12:43:54 +0530398 srh->length = ((sizeof (ip6_sr_header_t) +
399 ((vec_len (sl) + 1) * sizeof (ip6_address_t))) / 8) - 1;
400 srh->flags = 0x00;
Ahmed Abdelsalambe837042019-06-20 11:18:57 +0000401 srh->tag = 0x0000;
Shwetha Bhandari78372a92017-01-18 12:43:54 +0530402 addrp = srh->segments + vec_len (sl);
403 vec_foreach (this_address, sl)
404 {
Dave Barach178cf492018-11-13 16:34:13 -0500405 clib_memcpy_fast (addrp->as_u8, this_address->as_u8,
406 sizeof (ip6_address_t));
Shwetha Bhandari78372a92017-01-18 12:43:54 +0530407 addrp--;
408 }
409 return rs;
410}
411
Ed Warnickecb9cada2015-12-08 15:45:58 -0700412#endif /* included_vnet_sr_h */
Keith Burns (alagalah)06c5ffd2016-08-06 08:32:45 -0700413
414/*
415 * fd.io coding-style-patch-verification: ON
416 *
417 * Local Variables:
418 * eval: (c-set-style "gnu")
419 * End:
420 */