sr: add "set sr encaps hop-limit" command 12/22512/9
authorIgnas Bačius <ignas@noia.network>
Thu, 3 Oct 2019 14:15:38 +0000 (17:15 +0300)
committerDamjan Marion <dmarion@me.com>
Wed, 23 Oct 2019 07:52:22 +0000 (07:52 +0000)
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

src/plugins/srv6-as/as.c
src/vnet/srv6/sr.api
src/vnet/srv6/sr.h
src/vnet/srv6/sr_api.c
src/vnet/srv6/sr_policy.md
src/vnet/srv6/sr_policy_rewrite.c

index 3a47604..99e6851 100644 (file)
@@ -64,7 +64,7 @@ prepare_rewrite (ip6_address_t src_addr, ip6_address_t * sid_list,
   iph->src_address = src_addr;
   iph->dst_address = sid_list[0];
   iph->payload_length = sr_hdr_len;
-  iph->hop_limit = IPv6_DEFAULT_HOP_LIMIT;
+  iph->hop_limit = sr_get_hop_limit ();
 
   if (num_sids > 1)
     {
index e989ffe..1d696b0 100644 (file)
@@ -137,6 +137,18 @@ autoreply define sr_set_encap_source
   u8 encaps_source[16];
 };
 
+/** \brief IPv6 SR Set SRv6 encapsulation hop-limit
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param hop_limit is the hop-limit value to set
+*/
+autoreply define sr_set_encap_hop_limit
+{
+  u32 client_index;
+  u32 context;
+  u8 hop_limit;
+};
+
 /** \brief IPv6 SR steering add/del
     @param client_index - opaque cookie to identify the sender
     @param context - sender context, to match reply w/ request
index 9ca0348..2e2d439 100755 (executable)
@@ -278,6 +278,9 @@ sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
 
 extern void sr_set_source (ip6_address_t * address);
 
+extern void sr_set_hop_limit (u8 hop_limit);
+extern u8 sr_get_hop_limit (void);
+
 /**
  * @brief SR rewrite string computation for SRH insertion (inline)
  *
index 32eff2e..f3738da 100644 (file)
@@ -50,6 +50,7 @@ _(SR_POLICY_MOD, sr_policy_mod)                         \
 _(SR_POLICY_DEL, sr_policy_del)                         \
 _(SR_STEERING_ADD_DEL, sr_steering_add_del)             \
 _(SR_SET_ENCAP_SOURCE, sr_set_encap_source)             \
+_(SR_SET_ENCAP_HOP_LIMIT, sr_set_encap_hop_limit)       \
 _(SR_LOCALSIDS_DUMP, sr_localsids_dump)                 \
 _(SR_POLICIES_DUMP, sr_policies_dump)                   \
 _(SR_STEERING_POL_DUMP, sr_steering_pol_dump)
@@ -178,6 +179,20 @@ vl_api_sr_set_encap_source_t_handler (vl_api_sr_set_encap_source_t * mp)
   REPLY_MACRO (VL_API_SR_SET_ENCAP_SOURCE_REPLY);
 }
 
+static void
+vl_api_sr_set_encap_hop_limit_t_handler (vl_api_sr_set_encap_hop_limit_t * mp)
+{
+  vl_api_sr_set_encap_hop_limit_reply_t *rmp;
+  int rv = 0;
+
+  if (mp->hop_limit == 0)
+    rv = VNET_API_ERROR_INVALID_VALUE;
+  else
+    sr_set_hop_limit (mp->hop_limit);
+
+  REPLY_MACRO (VL_API_SR_SET_ENCAP_HOP_LIMIT_REPLY);
+}
+
 static void vl_api_sr_steering_add_del_t_handler
   (vl_api_sr_steering_add_del_t * mp)
 {
index 521b846..2a7eb4c 100644 (file)
@@ -54,3 +54,7 @@ Spray policies are used for removing multicast state from a network core domain,
 In case the user decides to create an SR policy an IPv6 Source Address must be specified for the encapsulated traffic. In order to do so the user might use the following command:
     
     set sr encaps source addr XXXX::YYYY
+
+Default hop-limit for the encapsulating IPv6 header is 64. It is possible to specify custom hop-limit value from 1 to 255 using this command:
+
+    set sr encaps hop-limit N
index feac151..8d11da6 100755 (executable)
@@ -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)
     {