blob: 9db13900f97e0ce103d96d8e98ca7d776fca223b [file] [log] [blame]
Pablo Camarillofb380952016-12-07 18:34:18 +01001/*
2 * sr_steering.c: ipv6 segment routing steering into SR policy
3 *
4 * Copyright (c) 2016 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @file
20 * @brief Packet steering into SR Policies
21 *
22 * This file is in charge of handling the FIB appropiatly to steer packets
23 * through SR Policies as defined in 'sr_policy_rewrite.c'. Notice that here
24 * we are only doing steering. SR policy application is done in
25 * sr_policy_rewrite.c
26 *
27 * Supports:
28 * - Steering of IPv6 traffic Destination Address based
29 * - Steering of IPv4 traffic Destination Address based
30 * - Steering of L2 frames, interface based (sw interface)
31 */
32
33#include <vlib/vlib.h>
34#include <vnet/vnet.h>
Pablo Camarillo5d73eec2017-04-24 17:51:56 +020035#include <vnet/srv6/sr.h>
Pablo Camarillofb380952016-12-07 18:34:18 +010036#include <vnet/ip/ip.h>
Pablo Camarillo5d73eec2017-04-24 17:51:56 +020037#include <vnet/srv6/sr_packet.h>
Pablo Camarillofb380952016-12-07 18:34:18 +010038#include <vnet/ip/ip6_packet.h>
39#include <vnet/fib/ip6_fib.h>
40#include <vnet/dpo/dpo.h>
41
42#include <vppinfra/error.h>
43#include <vppinfra/elog.h>
44
45/**
46 * @brief Steer traffic L2 and L3 traffic through a given SR policy
47 *
48 * @param is_del
49 * @param bsid is the bindingSID of the SR Policy (alt to sr_policy_index)
50 * @param sr_policy is the index of the SR Policy (alt to bsid)
51 * @param table_id is the VRF where to install the FIB entry for the BSID
52 * @param prefix is the IPv4/v6 address for L3 traffic type
53 * @param mask_width is the mask for L3 traffic type
54 * @param sw_if_index is the incoming interface for L2 traffic
55 * @param traffic_type describes the type of traffic
56 *
57 * @return 0 if correct, else error
58 */
59int
60sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
61 u32 table_id, ip46_address_t * prefix, u32 mask_width,
62 u32 sw_if_index, u8 traffic_type)
63{
64 ip6_sr_main_t *sm = &sr_main;
Pablo Camarillo4521afa2017-03-16 10:43:05 +010065 sr_steering_key_t key;
Pablo Camarillofb380952016-12-07 18:34:18 +010066 ip6_sr_steering_policy_t *steer_pl;
67 fib_prefix_t pfx = { 0 };
68
69 ip6_sr_policy_t *sr_policy = 0;
70 uword *p = 0;
71
Dave Barachb7b92992018-10-17 10:38:51 -040072 clib_memset (&key, 0, sizeof (sr_steering_key_t));
Pablo Camarillofb380952016-12-07 18:34:18 +010073
74 /* Compute the steer policy key */
Pablo Camarilloadcaaf12017-03-29 07:54:40 -070075 if (traffic_type == SR_STEER_IPV4 || traffic_type == SR_STEER_IPV6)
Pablo Camarillofb380952016-12-07 18:34:18 +010076 {
77 key.l3.prefix.as_u64[0] = prefix->as_u64[0];
78 key.l3.prefix.as_u64[1] = prefix->as_u64[1];
79 key.l3.mask_width = mask_width;
80 key.l3.fib_table = (table_id != (u32) ~ 0 ? table_id : 0);
81 }
Pablo Camarilloadcaaf12017-03-29 07:54:40 -070082 else if (traffic_type == SR_STEER_L2)
Pablo Camarillofb380952016-12-07 18:34:18 +010083 {
84 key.l2.sw_if_index = sw_if_index;
85
86 /* Sanitise the SW_IF_INDEX */
87 if (pool_is_free_index (sm->vnet_main->interface_main.sw_interfaces,
88 sw_if_index))
89 return -3;
90
91 vnet_sw_interface_t *sw =
92 vnet_get_sw_interface (sm->vnet_main, sw_if_index);
93 if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
94 return -3;
95 }
Pablo Camarilloadcaaf12017-03-29 07:54:40 -070096 else
97 return -1;
Pablo Camarillofb380952016-12-07 18:34:18 +010098
99 key.traffic_type = traffic_type;
100
101 /* Search for the item */
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100102 p = mhash_get (&sm->sr_steer_policies_hash, &key);
Pablo Camarillofb380952016-12-07 18:34:18 +0100103
104 if (p)
105 {
106 /* Retrieve Steer Policy function */
107 steer_pl = pool_elt_at_index (sm->steer_policies, p[0]);
108
109 if (is_del)
110 {
111 if (steer_pl->classify.traffic_type == SR_STEER_IPV6)
112 {
113 /* Remove FIB entry */
114 pfx.fp_proto = FIB_PROTOCOL_IP6;
115 pfx.fp_len = steer_pl->classify.l3.mask_width;
116 pfx.fp_addr.ip6 = steer_pl->classify.l3.prefix.ip6;
117
Neale Ranns107e7d42017-04-11 09:55:19 -0700118 fib_table_entry_delete (fib_table_find
Pablo Camarillofb380952016-12-07 18:34:18 +0100119 (FIB_PROTOCOL_IP6,
Neale Ranns107e7d42017-04-11 09:55:19 -0700120 steer_pl->classify.l3.fib_table),
121 &pfx, FIB_SOURCE_SR);
Pablo Camarillofb380952016-12-07 18:34:18 +0100122 }
123 else if (steer_pl->classify.traffic_type == SR_STEER_IPV4)
124 {
125 /* Remove FIB entry */
126 pfx.fp_proto = FIB_PROTOCOL_IP4;
127 pfx.fp_len = steer_pl->classify.l3.mask_width;
128 pfx.fp_addr.ip4 = steer_pl->classify.l3.prefix.ip4;
129
Neale Ranns107e7d42017-04-11 09:55:19 -0700130 fib_table_entry_delete (fib_table_find
Pablo Camarillofb380952016-12-07 18:34:18 +0100131 (FIB_PROTOCOL_IP4,
132 steer_pl->classify.l3.fib_table), &pfx,
133 FIB_SOURCE_SR);
134 }
135 else if (steer_pl->classify.traffic_type == SR_STEER_L2)
136 {
137 /* Remove HW redirection */
Ahmed Abdelsalama6b93ea2019-10-08 16:27:34 +0000138 int ret = vnet_feature_enable_disable ("device-input",
139 "sr-pl-rewrite-encaps-l2",
140 sw_if_index, 0, 0, 0);
141
142 if (ret != 0)
143 return -1;
144
Pablo Camarillofb380952016-12-07 18:34:18 +0100145 sm->sw_iface_sr_policies[sw_if_index] = ~(u32) 0;
146
147 /* Remove promiscous mode from interface */
148 vnet_main_t *vnm = vnet_get_main ();
John Lo5b960c62020-05-13 01:38:12 -0400149 vnet_hw_interface_t *hi =
150 vnet_get_sup_hw_interface (vnm, sw_if_index);
151 /* Make sure it is main interface */
152 if (hi->sw_if_index == sw_if_index)
153 ethernet_set_flags (vnm, hi->hw_if_index, 0);
Pablo Camarillofb380952016-12-07 18:34:18 +0100154 }
155
156 /* Delete SR steering policy entry */
157 pool_put (sm->steer_policies, steer_pl);
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100158 mhash_unset (&sm->sr_steer_policies_hash, &key, NULL);
159
160 /* If no more SR policies or steering policies */
161 if (!pool_elts (sm->sr_policies) && !pool_elts (sm->steer_policies))
162 {
Neale Ranns15002542017-09-10 04:39:11 -0700163 fib_table_unlock (sm->fib_table_ip6,
164 FIB_PROTOCOL_IP6, FIB_SOURCE_SR);
165 fib_table_unlock (sm->fib_table_ip4,
166 FIB_PROTOCOL_IP6, FIB_SOURCE_SR);
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100167 sm->fib_table_ip6 = (u32) ~ 0;
168 sm->fib_table_ip4 = (u32) ~ 0;
169 }
170
Kris Michielsen91074432017-06-22 13:00:20 +0200171 return 0;
Pablo Camarillofb380952016-12-07 18:34:18 +0100172 }
173 else /* It means user requested to update an existing SR steering policy */
174 {
175 /* Retrieve SR steering policy */
176 if (bsid)
177 {
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100178 p = mhash_get (&sm->sr_policies_index_hash, bsid);
Pablo Camarillofb380952016-12-07 18:34:18 +0100179 if (p)
180 sr_policy = pool_elt_at_index (sm->sr_policies, p[0]);
181 else
182 return -2;
183 }
184 else
185 sr_policy = pool_elt_at_index (sm->sr_policies, sr_policy_index);
186
187 if (!sr_policy)
188 return -2;
189
190 steer_pl->sr_policy = sr_policy - sm->sr_policies;
191
192 /* Remove old FIB/hw redirection and create a new one */
193 if (steer_pl->classify.traffic_type == SR_STEER_IPV6)
194 {
195 /* Remove FIB entry */
196 pfx.fp_proto = FIB_PROTOCOL_IP6;
197 pfx.fp_len = steer_pl->classify.l3.mask_width;
198 pfx.fp_addr.ip6 = steer_pl->classify.l3.prefix.ip6;
199
Neale Ranns107e7d42017-04-11 09:55:19 -0700200 fib_table_entry_delete (fib_table_find
Pablo Camarillofb380952016-12-07 18:34:18 +0100201 (FIB_PROTOCOL_IP6,
Neale Ranns107e7d42017-04-11 09:55:19 -0700202 steer_pl->classify.l3.fib_table),
203 &pfx, FIB_SOURCE_SR);
Pablo Camarillofb380952016-12-07 18:34:18 +0100204
205 /* Create a new one */
206 goto update_fib;
Pablo Camarillofb380952016-12-07 18:34:18 +0100207 }
208 else if (steer_pl->classify.traffic_type == SR_STEER_IPV4)
209 {
210 /* Remove FIB entry */
211 pfx.fp_proto = FIB_PROTOCOL_IP4;
212 pfx.fp_len = steer_pl->classify.l3.mask_width;
213 pfx.fp_addr.ip4 = steer_pl->classify.l3.prefix.ip4;
214
Neale Ranns107e7d42017-04-11 09:55:19 -0700215 fib_table_entry_delete (fib_table_find
Pablo Camarillofb380952016-12-07 18:34:18 +0100216 (FIB_PROTOCOL_IP4,
Neale Ranns107e7d42017-04-11 09:55:19 -0700217 steer_pl->classify.l3.fib_table),
218 &pfx, FIB_SOURCE_SR);
Pablo Camarillofb380952016-12-07 18:34:18 +0100219
220 /* Create a new one */
221 goto update_fib;
222 }
223 else if (steer_pl->classify.traffic_type == SR_STEER_L2)
224 {
225 /* Update L2-HW redirection */
226 goto update_fib;
227 }
228 }
229 }
230 else
231 /* delete; steering policy does not exist; complain */
232 if (is_del)
233 return -4;
234
235 /* Retrieve SR policy */
236 if (bsid)
237 {
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100238 p = mhash_get (&sm->sr_policies_index_hash, bsid);
Pablo Camarillofb380952016-12-07 18:34:18 +0100239 if (p)
240 sr_policy = pool_elt_at_index (sm->sr_policies, p[0]);
241 else
242 return -2;
243 }
244 else
245 sr_policy = pool_elt_at_index (sm->sr_policies, sr_policy_index);
246
247 /* Create a new steering policy */
248 pool_get (sm->steer_policies, steer_pl);
Dave Barachb7b92992018-10-17 10:38:51 -0400249 clib_memset (steer_pl, 0, sizeof (*steer_pl));
Pablo Camarillofb380952016-12-07 18:34:18 +0100250
251 if (traffic_type == SR_STEER_IPV4 || traffic_type == SR_STEER_IPV6)
252 {
Dave Barach178cf492018-11-13 16:34:13 -0500253 clib_memcpy_fast (&steer_pl->classify.l3.prefix, prefix,
254 sizeof (ip46_address_t));
Pablo Camarillofb380952016-12-07 18:34:18 +0100255 steer_pl->classify.l3.mask_width = mask_width;
256 steer_pl->classify.l3.fib_table =
257 (table_id != (u32) ~ 0 ? table_id : 0);
258 steer_pl->classify.traffic_type = traffic_type;
259 }
260 else if (traffic_type == SR_STEER_L2)
261 {
262 steer_pl->classify.l2.sw_if_index = sw_if_index;
263 steer_pl->classify.traffic_type = traffic_type;
264 }
265 else
266 {
267 /* Incorrect API usage. Should never get here */
268 pool_put (sm->steer_policies, steer_pl);
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100269 mhash_unset (&sm->sr_steer_policies_hash, &key, NULL);
Pablo Camarillofb380952016-12-07 18:34:18 +0100270 return -1;
271 }
272 steer_pl->sr_policy = sr_policy - sm->sr_policies;
273
274 /* Create and store key */
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100275 mhash_set (&sm->sr_steer_policies_hash, &key, steer_pl - sm->steer_policies,
276 NULL);
Pablo Camarillofb380952016-12-07 18:34:18 +0100277
278 if (traffic_type == SR_STEER_L2)
279 {
280 if (!sr_policy->is_encap)
281 goto cleanup_error_encap;
282
283 if (vnet_feature_enable_disable
Pablo Camarilloadcaaf12017-03-29 07:54:40 -0700284 ("device-input", "sr-pl-rewrite-encaps-l2", sw_if_index, 1, 0, 0))
Pablo Camarillofb380952016-12-07 18:34:18 +0100285 goto cleanup_error_redirection;
286
287 /* Set promiscous mode on interface */
288 vnet_main_t *vnm = vnet_get_main ();
John Lo5b960c62020-05-13 01:38:12 -0400289 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
290 /* Make sure it is main interface */
291 if (hi->sw_if_index == sw_if_index)
292 ethernet_set_flags (vnm, hi->hw_if_index,
293 ETHERNET_INTERFACE_FLAG_ACCEPT_ALL);
Pablo Camarillofb380952016-12-07 18:34:18 +0100294 }
295 else if (traffic_type == SR_STEER_IPV4)
296 if (!sr_policy->is_encap)
297 goto cleanup_error_encap;
298
299update_fib:
300 /* FIB API calls - Recursive route through the BindingSID */
301 if (traffic_type == SR_STEER_IPV6)
302 {
303 pfx.fp_proto = FIB_PROTOCOL_IP6;
304 pfx.fp_len = steer_pl->classify.l3.mask_width;
305 pfx.fp_addr.ip6 = steer_pl->classify.l3.prefix.ip6;
306
Neale Ranns107e7d42017-04-11 09:55:19 -0700307 fib_table_entry_path_add (fib_table_find (FIB_PROTOCOL_IP6,
308 (table_id !=
309 (u32) ~ 0 ?
310 table_id : 0)),
shwethabb18e0de2017-03-29 11:36:37 +0000311 &pfx, FIB_SOURCE_SR,
312 FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT,
Neale Rannsda78f952017-05-24 09:15:43 -0700313 DPO_PROTO_IP6,
Pablo Camarillofb380952016-12-07 18:34:18 +0100314 (ip46_address_t *) & sr_policy->bsid, ~0,
315 sm->fib_table_ip6, 1, NULL,
316 FIB_ROUTE_PATH_FLAG_NONE);
317 }
318 else if (traffic_type == SR_STEER_IPV4)
319 {
320 pfx.fp_proto = FIB_PROTOCOL_IP4;
321 pfx.fp_len = steer_pl->classify.l3.mask_width;
322 pfx.fp_addr.ip4 = steer_pl->classify.l3.prefix.ip4;
323
Neale Ranns107e7d42017-04-11 09:55:19 -0700324 fib_table_entry_path_add (fib_table_find (FIB_PROTOCOL_IP4,
325 (table_id !=
326 (u32) ~ 0 ?
327 table_id : 0)),
shwethabb18e0de2017-03-29 11:36:37 +0000328 &pfx, FIB_SOURCE_SR,
329 FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT,
Neale Rannsda78f952017-05-24 09:15:43 -0700330 DPO_PROTO_IP6,
Pablo Camarillofb380952016-12-07 18:34:18 +0100331 (ip46_address_t *) & sr_policy->bsid, ~0,
332 sm->fib_table_ip4, 1, NULL,
333 FIB_ROUTE_PATH_FLAG_NONE);
334 }
335 else if (traffic_type == SR_STEER_L2)
336 {
337 if (sw_if_index < vec_len (sm->sw_iface_sr_policies))
338 sm->sw_iface_sr_policies[sw_if_index] = steer_pl->sr_policy;
339 else
340 {
341 vec_resize (sm->sw_iface_sr_policies,
342 (pool_len (sm->vnet_main->interface_main.sw_interfaces)
343 - vec_len (sm->sw_iface_sr_policies)));
344 sm->sw_iface_sr_policies[sw_if_index] = steer_pl->sr_policy;
345 }
346 }
347
348 return 0;
349
350cleanup_error_encap:
351 pool_put (sm->steer_policies, steer_pl);
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100352 mhash_unset (&sm->sr_steer_policies_hash, &key, NULL);
Pablo Camarillofb380952016-12-07 18:34:18 +0100353 return -5;
354
355cleanup_error_redirection:
356 pool_put (sm->steer_policies, steer_pl);
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100357 mhash_unset (&sm->sr_steer_policies_hash, &key, NULL);
Pablo Camarillofb380952016-12-07 18:34:18 +0100358 return -3;
359}
360
361static clib_error_t *
362sr_steer_policy_command_fn (vlib_main_t * vm, unformat_input_t * input,
363 vlib_cli_command_t * cmd)
364{
365 vnet_main_t *vnm = vnet_get_main ();
366
367 int is_del = 0;
368
369 ip46_address_t prefix;
370 u32 dst_mask_width = 0;
371 u32 sw_if_index = (u32) ~ 0;
372 u8 traffic_type = 0;
373 u32 fib_table = (u32) ~ 0;
374
375 ip6_address_t bsid;
376 u32 sr_policy_index = (u32) ~ 0;
377
378 u8 sr_policy_set = 0;
379
Dave Barachb7b92992018-10-17 10:38:51 -0400380 clib_memset (&prefix, 0, sizeof (ip46_address_t));
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100381
Pablo Camarillofb380952016-12-07 18:34:18 +0100382 int rv;
383 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
384 {
385 if (unformat (input, "del"))
386 is_del = 1;
387 else if (!traffic_type
388 && unformat (input, "l3 %U/%d", unformat_ip6_address,
389 &prefix.ip6, &dst_mask_width))
390 traffic_type = SR_STEER_IPV6;
391 else if (!traffic_type
392 && unformat (input, "l3 %U/%d", unformat_ip4_address,
393 &prefix.ip4, &dst_mask_width))
394 traffic_type = SR_STEER_IPV4;
395 else if (!traffic_type
396 && unformat (input, "l2 %U", unformat_vnet_sw_interface, vnm,
397 &sw_if_index))
398 traffic_type = SR_STEER_L2;
399 else if (!sr_policy_set
Francois Clad4abc5c32018-02-01 14:51:33 +0100400 && unformat (input, "via index %d", &sr_policy_index))
Pablo Camarillofb380952016-12-07 18:34:18 +0100401 sr_policy_set = 1;
402 else if (!sr_policy_set
Francois Clad4abc5c32018-02-01 14:51:33 +0100403 && unformat (input, "via bsid %U",
Pablo Camarillofb380952016-12-07 18:34:18 +0100404 unformat_ip6_address, &bsid))
405 sr_policy_set = 1;
406 else if (fib_table == (u32) ~ 0
407 && unformat (input, "fib-table %d", &fib_table));
408 else
409 break;
410 }
411
412 if (!traffic_type)
413 return clib_error_return (0, "No L2/L3 traffic specified");
414 if (!sr_policy_set)
415 return clib_error_return (0, "No SR policy specified");
416
417 /* Make sure that the prefixes are clean */
418 if (traffic_type == SR_STEER_IPV4)
419 {
420 u32 mask =
421 (dst_mask_width ? (0xFFFFFFFFu >> (32 - dst_mask_width)) : 0);
422 prefix.ip4.as_u32 &= mask;
423 }
424 else if (traffic_type == SR_STEER_IPV6)
425 {
426 ip6_address_t mask;
427 ip6_address_mask_from_width (&mask, dst_mask_width);
428 ip6_address_mask (&prefix.ip6, &mask);
429 }
430
431 rv =
432 sr_steering_policy (is_del, (sr_policy_index == ~(u32) 0 ? &bsid : NULL),
433 sr_policy_index, fib_table, &prefix, dst_mask_width,
434 sw_if_index, traffic_type);
435
436 switch (rv)
437 {
438 case 0:
439 break;
440 case 1:
441 return 0;
442 case -1:
443 return clib_error_return (0, "Incorrect API usage.");
444 case -2:
445 return clib_error_return (0,
446 "The requested SR policy could not be located. Review the BSID/index.");
447 case -3:
448 return clib_error_return (0,
449 "Unable to do SW redirect. Incorrect interface.");
450 case -4:
451 return clib_error_return (0,
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100452 "The requested SR steering policy could not be deleted.");
Pablo Camarillofb380952016-12-07 18:34:18 +0100453 case -5:
454 return clib_error_return (0,
455 "The SR policy is not an encapsulation one.");
456 default:
457 return clib_error_return (0, "BUG: sr steer policy returns %d", rv);
458 }
459 return 0;
460}
461
462/* *INDENT-OFF* */
463VLIB_CLI_COMMAND (sr_steer_policy_command, static) = {
464 .path = "sr steer",
Francois Clad4abc5c32018-02-01 14:51:33 +0100465 .short_help = "sr steer (del) [l3 <ip_addr/mask>|l2 <sf_if>] "
466 "via [index <sr_policy_index>|bsid <bsid_ip6_addr>] "
Pablo Camarillofb380952016-12-07 18:34:18 +0100467 "(fib-table <fib_table_index>)",
468 .long_help =
469 "\tSteer a L2 or L3 traffic through an existing SR policy.\n"
470 "\tExamples:\n"
471 "\t\tsr steer l3 2001::/64 via sr_policy index 5\n"
472 "\t\tsr steer l3 2001::/64 via sr_policy bsid 2010::9999:1\n"
473 "\t\tsr steer l2 GigabitEthernet0/5/0 via sr_policy index 5\n"
474 "\t\tsr steer del l3 2001::/64 via sr_policy index 5\n",
475 .function = sr_steer_policy_command_fn,
476};
477/* *INDENT-ON* */
478
479static clib_error_t *
480show_sr_steering_policies_command_fn (vlib_main_t * vm,
481 unformat_input_t * input,
482 vlib_cli_command_t * cmd)
483{
484 ip6_sr_main_t *sm = &sr_main;
485 ip6_sr_steering_policy_t **steer_policies = 0;
486 ip6_sr_steering_policy_t *steer_pl;
487
488 vnet_main_t *vnm = vnet_get_main ();
489
490 ip6_sr_policy_t *pl = 0;
491 int i;
492
493 vlib_cli_output (vm, "SR steering policies:");
494 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100495 pool_foreach (steer_pl, sm->steer_policies) {vec_add1(steer_policies, steer_pl);}
Pablo Camarillofb380952016-12-07 18:34:18 +0100496 /* *INDENT-ON* */
497 vlib_cli_output (vm, "Traffic\t\tSR policy BSID");
498 for (i = 0; i < vec_len (steer_policies); i++)
499 {
500 steer_pl = steer_policies[i];
501 pl = pool_elt_at_index (sm->sr_policies, steer_pl->sr_policy);
502 if (steer_pl->classify.traffic_type == SR_STEER_L2)
503 {
504 vlib_cli_output (vm, "L2 %U\t%U",
505 format_vnet_sw_if_index_name, vnm,
506 steer_pl->classify.l2.sw_if_index,
507 format_ip6_address, &pl->bsid);
508 }
509 else if (steer_pl->classify.traffic_type == SR_STEER_IPV4)
510 {
511 vlib_cli_output (vm, "L3 %U/%d\t%U",
512 format_ip4_address,
513 &steer_pl->classify.l3.prefix.ip4,
514 steer_pl->classify.l3.mask_width,
515 format_ip6_address, &pl->bsid);
516 }
517 else if (steer_pl->classify.traffic_type == SR_STEER_IPV6)
518 {
519 vlib_cli_output (vm, "L3 %U/%d\t%U",
520 format_ip6_address,
521 &steer_pl->classify.l3.prefix.ip6,
522 steer_pl->classify.l3.mask_width,
523 format_ip6_address, &pl->bsid);
524 }
525 }
526 return 0;
527}
528
529/* *INDENT-OFF* */
530VLIB_CLI_COMMAND (show_sr_steering_policies_command, static) = {
Francois Clad4abc5c32018-02-01 14:51:33 +0100531 .path = "show sr steering-policies",
532 .short_help = "show sr steering-policies",
Pablo Camarillofb380952016-12-07 18:34:18 +0100533 .function = show_sr_steering_policies_command_fn,
534};
535/* *INDENT-ON* */
536
537clib_error_t *
538sr_steering_init (vlib_main_t * vm)
539{
540 ip6_sr_main_t *sm = &sr_main;
541
542 /* Init memory for function keys */
Pablo Camarillo4521afa2017-03-16 10:43:05 +0100543 mhash_init (&sm->sr_steer_policies_hash, sizeof (uword),
544 sizeof (sr_steering_key_t));
Pablo Camarillofb380952016-12-07 18:34:18 +0100545
546 sm->sw_iface_sr_policies = 0;
547
548 sm->vnet_main = vnet_get_main ();
549
550 return 0;
551}
552
Pablo Camarilloadcaaf12017-03-29 07:54:40 -0700553/* *INDENT-OFF* */
Pablo Camarillofb380952016-12-07 18:34:18 +0100554VLIB_INIT_FUNCTION (sr_steering_init);
Pablo Camarilloadcaaf12017-03-29 07:54:40 -0700555/* *INDENT-ON* */
Pablo Camarillofb380952016-12-07 18:34:18 +0100556
Pablo Camarilloadcaaf12017-03-29 07:54:40 -0700557/* *INDENT-OFF* */
558VNET_FEATURE_INIT (sr_pl_rewrite_encaps_l2, static) =
Pablo Camarillofb380952016-12-07 18:34:18 +0100559{
Pablo Camarilloadcaaf12017-03-29 07:54:40 -0700560 .arc_name = "device-input",
561 .node_name = "sr-pl-rewrite-encaps-l2",
562 .runs_before = VNET_FEATURES ("ethernet-input"),
563};
564/* *INDENT-ON* */
Pablo Camarillofb380952016-12-07 18:34:18 +0100565
566/*
567* fd.io coding-style-patch-verification: ON
568*
569* Local Variables:
570* eval: (c-set-style "gnu")
571* End:
572*/