summaryrefslogtreecommitdiffstats
path: root/src/vnet/srv6/sr_policy_rewrite.c
diff options
context:
space:
mode:
authorIgnas Bačius <ignas@noia.network>2019-10-03 17:15:38 +0300
committerDamjan Marion <dmarion@me.com>2019-10-23 07:52:22 +0000
commiteeb5fb3a50079e1af6e655694c6ff99ec2f9d070 (patch)
treeda14b1e36c66e6977e175cbe040892df57f828cf /src/vnet/srv6/sr_policy_rewrite.c
parentbd0a00a45637c1dde533ef6c3798418c2ab15009 (diff)
sr: add "set sr encaps hop-limit" command
Default hop-limit for the encapsulating IPv6 header is a compile-time constant. Add ability to specify custom hop-limit, in order to avoid packets being dropped with "hop limit exceeded in transit" response in certain network configurations. Type: feature Signed-off-by: Ignas Bačius <ignas@noia.network> Change-Id: I77f2b35c987cfd31801dc2744d31fb3c1984158f
Diffstat (limited to 'src/vnet/srv6/sr_policy_rewrite.c')
-rwxr-xr-xsrc/vnet/srv6/sr_policy_rewrite.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/vnet/srv6/sr_policy_rewrite.c b/src/vnet/srv6/sr_policy_rewrite.c
index feac151665a..8d11da67ddf 100755
--- a/src/vnet/srv6/sr_policy_rewrite.c
+++ b/src/vnet/srv6/sr_policy_rewrite.c
@@ -107,6 +107,7 @@ static dpo_type_t sr_pr_bsid_insert_dpo_type;
* @brief IPv6 SA for encapsulated packets
*/
static ip6_address_t sr_pr_encaps_src;
+static u8 sr_pr_encaps_hop_limit = IPv6_DEFAULT_HOP_LIMIT;
/******************* SR rewrite set encaps IPv6 source addr *******************/
/* Note: This is temporal. We don't know whether to follow this path or
@@ -141,6 +142,44 @@ VLIB_CLI_COMMAND (set_sr_src_command, static) = {
};
/* *INDENT-ON* */
+/******************** SR rewrite set encaps IPv6 hop-limit ********************/
+
+void
+sr_set_hop_limit (u8 hop_limit)
+{
+ sr_pr_encaps_hop_limit = hop_limit;
+}
+
+u8
+sr_get_hop_limit (void)
+{
+ return sr_pr_encaps_hop_limit;
+}
+
+static clib_error_t *
+set_sr_hop_limit_command_fn (vlib_main_t * vm, unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ int hop_limit = sr_get_hop_limit ();
+
+ if (unformat_check_input (input) == UNFORMAT_END_OF_INPUT)
+ return clib_error_return (0, "No value specified");
+ if (!unformat (input, "%d", &hop_limit))
+ return clib_error_return (0, "Invalid value");
+ if (hop_limit <= 0 || hop_limit > 255)
+ return clib_error_return (0, "Value out of range [1-255]");
+ sr_pr_encaps_hop_limit = (u8) hop_limit;
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (set_sr_hop_limit_command, static) = {
+ .path = "set sr encaps hop-limit",
+ .short_help = "set sr encaps hop-limit <value>",
+ .function = set_sr_hop_limit_command_fn,
+};
+/* *INDENT-ON* */
+
/*********************** SR rewrite string computation ************************/
/**
* @brief SR rewrite string computation for IPv6 encapsulation (inline)
@@ -175,7 +214,7 @@ compute_rewrite_encaps (ip6_address_t * sl)
iph->src_address.as_u64[1] = sr_pr_encaps_src.as_u64[1];
iph->payload_length = header_length - IPv6_DEFAULT_HEADER_LENGTH;
iph->protocol = IP_PROTOCOL_IPV6;
- iph->hop_limit = IPv6_DEFAULT_HOP_LIMIT;
+ iph->hop_limit = sr_pr_encaps_hop_limit;
if (vec_len (sl) > 1)
{