summaryrefslogtreecommitdiffstats
path: root/src/vnet/srv6
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/srv6')
-rw-r--r--src/vnet/srv6/sr.h8
-rw-r--r--src/vnet/srv6/sr_policy_rewrite.c85
2 files changed, 51 insertions, 42 deletions
diff --git a/src/vnet/srv6/sr.h b/src/vnet/srv6/sr.h
index d47c2132ee4..c84534c8ae7 100644
--- a/src/vnet/srv6/sr.h
+++ b/src/vnet/srv6/sr.h
@@ -75,6 +75,7 @@ typedef struct
u8 *rewrite; /**< Precomputed rewrite header */
u8 *rewrite_bsid; /**< Precomputed rewrite header for bindingSID */
+ u8 policy_type;
u32 egress_fib_table; /**< Egress FIB table for encap packet */
@@ -342,10 +343,9 @@ sr_policy_register_function (vlib_main_t * vm, u8 * fn_name,
sr_p_plugin_callback_t * creation_fn,
sr_p_plugin_callback_t * removal_fn);
-extern int
-sr_policy_add (ip6_address_t * bsid, ip6_address_t * segments,
- u32 weight, u8 behavior, u32 fib_table, u8 is_encap,
- u16 plugin, void *plugin_mem);
+extern int sr_policy_add (ip6_address_t *bsid, ip6_address_t *segments,
+ u32 weight, u8 type, u32 fib_table, u8 is_encap,
+ u16 plugin, void *plugin_mem);
extern int sr_policy_mod (ip6_address_t * bsid, u32 index, u32 fib_table,
u8 operation, ip6_address_t * segments,
u32 sl_index, u32 weight);
diff --git a/src/vnet/srv6/sr_policy_rewrite.c b/src/vnet/srv6/sr_policy_rewrite.c
index 79de7792061..95de43166a1 100644
--- a/src/vnet/srv6/sr_policy_rewrite.c
+++ b/src/vnet/srv6/sr_policy_rewrite.c
@@ -195,7 +195,7 @@ VLIB_CLI_COMMAND (set_sr_hop_limit_command, static) = {
* @return precomputed rewrite string for encapsulation
*/
static inline u8 *
-compute_rewrite_encaps (ip6_address_t * sl)
+compute_rewrite_encaps (ip6_address_t *sl, u8 type)
{
ip6_header_t *iph;
ip6_sr_header_t *srh;
@@ -255,7 +255,7 @@ compute_rewrite_encaps (ip6_address_t * sl)
* @return precomputed rewrite string for SRH insertion
*/
static inline u8 *
-compute_rewrite_insert (ip6_address_t * sl)
+compute_rewrite_insert (ip6_address_t *sl, u8 type)
{
ip6_sr_header_t *srh;
ip6_address_t *addrp, *this_address;
@@ -358,18 +358,19 @@ create_sl (ip6_sr_policy_t * sr_policy, ip6_address_t * sl, u32 weight,
(weight != (u32) ~ 0 ? weight : SR_SEGMENT_LIST_WEIGHT_DEFAULT);
segment_list->segments = vec_dup (sl);
+ segment_list->policy_type = sr_policy->type;
segment_list->egress_fib_table =
ip6_fib_index_from_table_id (sr_policy->fib_table);
if (is_encap)
{
- segment_list->rewrite = compute_rewrite_encaps (sl);
+ segment_list->rewrite = compute_rewrite_encaps (sl, sr_policy->type);
segment_list->rewrite_bsid = segment_list->rewrite;
}
else
{
- segment_list->rewrite = compute_rewrite_insert (sl);
+ segment_list->rewrite = compute_rewrite_insert (sl, sr_policy->type);
segment_list->rewrite_bsid = compute_rewrite_bsid (sl);
}
@@ -632,9 +633,9 @@ update_replicate (ip6_sr_policy_t * sr_policy)
* @return 0 if correct, else error
*/
int
-sr_policy_add (ip6_address_t * bsid, ip6_address_t * segments,
- u32 weight, u8 behavior, u32 fib_table, u8 is_encap,
- u16 plugin, void *ls_plugin_mem)
+sr_policy_add (ip6_address_t *bsid, ip6_address_t *segments, u32 weight,
+ u8 type, u32 fib_table, u8 is_encap, u16 plugin,
+ void *ls_plugin_mem)
{
ip6_sr_main_t *sm = &sr_main;
ip6_sr_policy_t *sr_policy = 0;
@@ -675,7 +676,7 @@ sr_policy_add (ip6_address_t * bsid, ip6_address_t * segments,
pool_get (sm->sr_policies, sr_policy);
clib_memset (sr_policy, 0, sizeof (*sr_policy));
clib_memcpy_fast (&sr_policy->bsid, bsid, sizeof (ip6_address_t));
- sr_policy->type = behavior;
+ sr_policy->type = type;
sr_policy->fib_table = (fib_table != (u32) ~ 0 ? fib_table : 0); //Is default FIB 0 ?
sr_policy->is_encap = is_encap;
@@ -936,7 +937,7 @@ sr_policy_command_fn (vlib_main_t * vm, unformat_input_t * input,
ip6_address_t *segments = 0, *this_seg;
u8 operation = 0;
char is_encap = 1;
- char is_spray = 0;
+ u8 type = SR_POLICY_TYPE_DEFAULT;
u16 behavior = 0;
void *ls_plugin_mem = 0;
@@ -975,7 +976,7 @@ sr_policy_command_fn (vlib_main_t * vm, unformat_input_t * input,
else if (unformat (input, "insert"))
is_encap = 0;
else if (unformat (input, "spray"))
- is_spray = 1;
+ type = SR_POLICY_TYPE_SPRAY;
else if (!behavior && unformat (input, "behavior"))
{
sr_policy_fn_registration_t *plugin = 0, **vec_plugins = 0;
@@ -1024,9 +1025,7 @@ sr_policy_command_fn (vlib_main_t * vm, unformat_input_t * input,
if (vec_len (segments) == 0)
return clib_error_return (0, "No Segment List specified");
- rv = sr_policy_add (&bsid, segments, weight,
- (is_spray ? SR_POLICY_TYPE_SPRAY :
- SR_POLICY_TYPE_DEFAULT), fib_table, is_encap,
+ rv = sr_policy_add (&bsid, segments, weight, type, fib_table, is_encap,
behavior, ls_plugin_mem);
vec_free (segments);
@@ -1137,9 +1136,15 @@ show_sr_policies_command_fn (vlib_main_t * vm, unformat_input_t * input,
vlib_cli_output (vm, "\tBehavior: %s",
(sr_policy->is_encap ? "Encapsulation" :
"SRH insertion"));
- vlib_cli_output (vm, "\tType: %s",
- (sr_policy->type ==
- SR_POLICY_TYPE_DEFAULT ? "Default" : "Spray"));
+ switch (sr_policy->type)
+ {
+ case SR_POLICY_TYPE_SPRAY:
+ vlib_cli_output (vm, "\tType: %s", "Spray");
+ break;
+ default:
+ vlib_cli_output (vm, "\tType: %s", "Default");
+ break;
+ }
vlib_cli_output (vm, "\tFIB table: %u",
(sr_policy->fib_table !=
(u32) ~ 0 ? sr_policy->fib_table : 0));
@@ -1236,9 +1241,9 @@ format_sr_policy_rewrite_trace (u8 * s, va_list * args)
* @brief IPv6 encapsulation processing as per RFC2473
*/
static_always_inline void
-encaps_processing_v6 (vlib_node_runtime_t * node,
- vlib_buffer_t * b0,
- ip6_header_t * ip0, ip6_header_t * ip0_encap)
+encaps_processing_v6 (vlib_node_runtime_t *node, vlib_buffer_t *b0,
+ ip6_header_t *ip0, ip6_header_t *ip0_encap,
+ u8 policy_type)
{
u32 new_l0;
u32 flow_label;
@@ -1373,10 +1378,10 @@ sr_policy_rewrite_encaps (vlib_main_t * vm, vlib_node_runtime_t * node,
ip2 = vlib_buffer_get_current (b2);
ip3 = vlib_buffer_get_current (b3);
- encaps_processing_v6 (node, b0, ip0, ip0_encap);
- encaps_processing_v6 (node, b1, ip1, ip1_encap);
- encaps_processing_v6 (node, b2, ip2, ip2_encap);
- encaps_processing_v6 (node, b3, ip3, ip3_encap);
+ encaps_processing_v6 (node, b0, ip0, ip0_encap, sl0->policy_type);
+ encaps_processing_v6 (node, b1, ip1, ip1_encap, sl1->policy_type);
+ encaps_processing_v6 (node, b2, ip2, ip2_encap, sl2->policy_type);
+ encaps_processing_v6 (node, b3, ip3, ip3_encap, sl3->policy_type);
vnet_buffer (b0)->sw_if_index[VLIB_TX] = sl0->egress_fib_table;
vnet_buffer (b1)->sw_if_index[VLIB_TX] = sl1->egress_fib_table;
@@ -1463,7 +1468,7 @@ sr_policy_rewrite_encaps (vlib_main_t * vm, vlib_node_runtime_t * node,
ip0 = vlib_buffer_get_current (b0);
- encaps_processing_v6 (node, b0, ip0, ip0_encap);
+ encaps_processing_v6 (node, b0, ip0, ip0_encap, sl0->policy_type);
vnet_buffer (b0)->sw_if_index[VLIB_TX] = sl0->egress_fib_table;
@@ -3087,10 +3092,9 @@ VLIB_REGISTER_NODE (sr_policy_rewrite_b_insert_node) = {
* @brief Function BSID encapsulation
*/
static_always_inline void
-end_bsid_encaps_srh_processing (vlib_node_runtime_t * node,
- vlib_buffer_t * b0,
- ip6_header_t * ip0,
- ip6_sr_header_t * sr0, u32 * next0)
+end_bsid_encaps_srh_processing (vlib_node_runtime_t *node, vlib_buffer_t *b0,
+ ip6_header_t *ip0, ip6_sr_header_t *sr0,
+ u32 *next0, u8 policy_type)
{
ip6_address_t *new_dst0;
@@ -3224,10 +3228,14 @@ sr_policy_rewrite_b_encaps (vlib_main_t * vm, vlib_node_runtime_t * node,
ip6_ext_header_find (vm, b3, ip3_encap, IP_PROTOCOL_IPV6_ROUTE,
NULL);
- end_bsid_encaps_srh_processing (node, b0, ip0_encap, sr0, &next0);
- end_bsid_encaps_srh_processing (node, b1, ip1_encap, sr1, &next1);
- end_bsid_encaps_srh_processing (node, b2, ip2_encap, sr2, &next2);
- end_bsid_encaps_srh_processing (node, b3, ip3_encap, sr3, &next3);
+ end_bsid_encaps_srh_processing (node, b0, ip0_encap, sr0, &next0,
+ sl0->policy_type);
+ end_bsid_encaps_srh_processing (node, b1, ip1_encap, sr1, &next1,
+ sl1->policy_type);
+ end_bsid_encaps_srh_processing (node, b2, ip2_encap, sr2, &next2,
+ sl2->policy_type);
+ end_bsid_encaps_srh_processing (node, b3, ip3_encap, sr3, &next3,
+ sl3->policy_type);
clib_memcpy_fast (((u8 *) ip0_encap) - vec_len (sl0->rewrite),
sl0->rewrite, vec_len (sl0->rewrite));
@@ -3248,10 +3256,10 @@ sr_policy_rewrite_b_encaps (vlib_main_t * vm, vlib_node_runtime_t * node,
ip2 = vlib_buffer_get_current (b2);
ip3 = vlib_buffer_get_current (b3);
- encaps_processing_v6 (node, b0, ip0, ip0_encap);
- encaps_processing_v6 (node, b1, ip1, ip1_encap);
- encaps_processing_v6 (node, b2, ip2, ip2_encap);
- encaps_processing_v6 (node, b3, ip3, ip3_encap);
+ encaps_processing_v6 (node, b0, ip0, ip0_encap, sl0->policy_type);
+ encaps_processing_v6 (node, b1, ip1, ip1_encap, sl1->policy_type);
+ encaps_processing_v6 (node, b2, ip2, ip2_encap, sl2->policy_type);
+ encaps_processing_v6 (node, b3, ip3, ip3_encap, sl3->policy_type);
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
{
@@ -3330,7 +3338,8 @@ sr_policy_rewrite_b_encaps (vlib_main_t * vm, vlib_node_runtime_t * node,
sr0 =
ip6_ext_header_find (vm, b0, ip0_encap, IP_PROTOCOL_IPV6_ROUTE,
NULL);
- end_bsid_encaps_srh_processing (node, b0, ip0_encap, sr0, &next0);
+ end_bsid_encaps_srh_processing (node, b0, ip0_encap, sr0, &next0,
+ sl0->policy_type);
clib_memcpy_fast (((u8 *) ip0_encap) - vec_len (sl0->rewrite),
sl0->rewrite, vec_len (sl0->rewrite));
@@ -3338,7 +3347,7 @@ sr_policy_rewrite_b_encaps (vlib_main_t * vm, vlib_node_runtime_t * node,
ip0 = vlib_buffer_get_current (b0);
- encaps_processing_v6 (node, b0, ip0, ip0_encap);
+ encaps_processing_v6 (node, b0, ip0, ip0_encap, sl0->policy_type);
if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE) &&
PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))