sr: show the hop-limit value used for SRv6 encapsulation
[vpp.git] / src / vnet / srv6 / sr_policy_rewrite.c
old mode 100755 (executable)
new mode 100644 (file)
index 9c4d0ec..a0b151d
@@ -41,9 +41,9 @@
 #include <vlib/vlib.h>
 #include <vnet/vnet.h>
 #include <vnet/srv6/sr.h>
-#include <vnet/ip/ip.h>
+#include <vnet/ip/ip4_inlines.h>
+#include <vnet/ip/ip6_inlines.h>
 #include <vnet/srv6/sr_packet.h>
-#include <vnet/ip/ip6_packet.h>
 #include <vnet/fib/ip6_fib.h>
 #include <vnet/dpo/dpo.h>
 #include <vnet/dpo/replicate_dpo.h>
@@ -119,6 +119,12 @@ sr_set_source (ip6_address_t * address)
   clib_memcpy_fast (&sr_pr_encaps_src, address, sizeof (sr_pr_encaps_src));
 }
 
+ip6_address_t *
+sr_get_encaps_source ()
+{
+  return &sr_pr_encaps_src;
+}
+
 static clib_error_t *
 set_sr_src_command_fn (vlib_main_t * vm, unformat_input_t * input,
                       vlib_cli_command_t * cmd)
@@ -1147,7 +1153,7 @@ show_sr_policies_command_fn (vlib_main_t * vm, unformat_input_t * input,
       }
       s = format (s, "\b\b > ");
       s = format (s, "weight: %u", segment_list->weight);
-      vlib_cli_output (vm, "  %s", s);
+      vlib_cli_output (vm, "  %v", s);
     }
     vlib_cli_output (vm, "-----------");
   }
@@ -1162,6 +1168,48 @@ VLIB_CLI_COMMAND (show_sr_policies_command, static) = {
 };
 /* *INDENT-ON* */
 
+/**
+ * @brief CLI to display onscreen the SR encaps source addr
+ */
+static clib_error_t *
+show_sr_encaps_source_command_fn (vlib_main_t * vm, unformat_input_t * input,
+                                 vlib_cli_command_t * cmd)
+{
+  vlib_cli_output (vm, "SR encaps source addr = %U", format_ip6_address,
+                  sr_get_encaps_source ());
+
+  return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (show_sr_encaps_source_command, static) = {
+  .path = "show sr encaps source addr",
+  .short_help = "show sr encaps source addr",
+  .function = show_sr_encaps_source_command_fn,
+};
+/* *INDENT-ON* */
+
+/**
+ * @brief CLI to display onscreen the hop-limit value used for SRv6 encapsulation
+ */
+static clib_error_t *
+show_sr_encaps_hop_limit_command_fn (vlib_main_t * vm,
+                                    unformat_input_t * input,
+                                    vlib_cli_command_t * cmd)
+{
+  vlib_cli_output (vm, "SR encaps hop-limit = %u", sr_get_hop_limit ());
+
+  return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (show_sr_encaps_hop_limit_command, static) = {
+  .path = "show sr encaps hop-limit",
+  .short_help = "show sr encaps hop-limit",
+  .function = show_sr_encaps_hop_limit_command_fn,
+};
+/* *INDENT-ON* */
+
 /*************************** SR rewrite graph node ****************************/
 /**
  * @brief Trace for the SR Policy Rewrite graph node
@@ -1967,34 +2015,34 @@ sr_policy_rewrite_encaps_l2 (vlib_main_t * vm, vlib_node_runtime_t * node,
          if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE)
            {
              sr0 = (void *) (ip0 + 1);
-             sr0->protocol = IP_PROTOCOL_IP6_NONXT;
+             sr0->protocol = IP_PROTOCOL_IP6_ETHERNET;
            }
          else
-           ip0->protocol = IP_PROTOCOL_IP6_NONXT;
+           ip0->protocol = IP_PROTOCOL_IP6_ETHERNET;
 
          if (ip1->protocol == IP_PROTOCOL_IPV6_ROUTE)
            {
              sr1 = (void *) (ip1 + 1);
-             sr1->protocol = IP_PROTOCOL_IP6_NONXT;
+             sr1->protocol = IP_PROTOCOL_IP6_ETHERNET;
            }
          else
-           ip1->protocol = IP_PROTOCOL_IP6_NONXT;
+           ip1->protocol = IP_PROTOCOL_IP6_ETHERNET;
 
          if (ip2->protocol == IP_PROTOCOL_IPV6_ROUTE)
            {
              sr2 = (void *) (ip2 + 1);
-             sr2->protocol = IP_PROTOCOL_IP6_NONXT;
+             sr2->protocol = IP_PROTOCOL_IP6_ETHERNET;
            }
          else
-           ip2->protocol = IP_PROTOCOL_IP6_NONXT;
+           ip2->protocol = IP_PROTOCOL_IP6_ETHERNET;
 
          if (ip3->protocol == IP_PROTOCOL_IPV6_ROUTE)
            {
              sr3 = (void *) (ip3 + 1);
-             sr3->protocol = IP_PROTOCOL_IP6_NONXT;
+             sr3->protocol = IP_PROTOCOL_IP6_ETHERNET;
            }
          else
-           ip3->protocol = IP_PROTOCOL_IP6_NONXT;
+           ip3->protocol = IP_PROTOCOL_IP6_ETHERNET;
 
          /* Which Traffic class and flow label do I set ? */
          //ip0->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32(0|((6&0xF)<<28)|((ip0_encap->tos&0xFF)<<20));
@@ -2105,10 +2153,10 @@ sr_policy_rewrite_encaps_l2 (vlib_main_t * vm, vlib_node_runtime_t * node,
          if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE)
            {
              sr0 = (void *) (ip0 + 1);
-             sr0->protocol = IP_PROTOCOL_IP6_NONXT;
+             sr0->protocol = IP_PROTOCOL_IP6_ETHERNET;
            }
          else
-           ip0->protocol = IP_PROTOCOL_IP6_NONXT;
+           ip0->protocol = IP_PROTOCOL_IP6_ETHERNET;
 
          if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE) &&
              PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))