ioam: remove use of local_next_by_ip_protocol struct 57/43257/2
authorMohsin Kazmi <[email protected]>
Fri, 20 Jun 2025 17:06:22 +0000 (17:06 +0000)
committerFlorin Coras <[email protected]>
Mon, 30 Jun 2025 20:11:32 +0000 (20:11 +0000)
Type: fix

ioam plugin is using data structure which is specific
to ip4 and ip6 lookup nodes.
This patch also use the IP_PROTOCOL defines instead of
custom define in srv6 code.

Signed-off-by: Mohsin Kazmi <[email protected]>
Change-Id: Iafd2a8416dd1f44ef7afd07c92915cd7dd6400a6

src/plugins/ioam/ip6/ioam_cache_node.c
src/plugins/ioam/udp-ping/udp_ping_node.c
src/plugins/srv6-mobile/gtp6_d_di.c
src/plugins/srv6-mobile/node.c
src/vnet/srv6/sr_packet.h

index 9859ee6..cef5463 100644 (file)
@@ -354,7 +354,7 @@ VLIB_NODE_FN (ip6_add_from_cache_hbh_node) (vlib_main_t * vm,
 
          /* Patch the protocol chain, insert the h-b-h (type 0) header */
          srh0->protocol = ip0->protocol;
-         hbh0->protocol = IPPROTO_IPV6_ROUTE;
+         hbh0->protocol = IP_PROTOCOL_IPV6_ROUTE;
          ip0->protocol = 0;
          new_l0 =
            clib_net_to_host_u16 (ip0->payload_length) + rewrite_len +
index fbc3b13..f7302e9 100644 (file)
@@ -34,6 +34,7 @@ typedef enum
   UDP_PING_NEXT_UDP_LOOKUP,
   UDP_PING_NEXT_ICMP,
   UDP_PING_NEXT_IP6_LOOKUP,
+  UDP_PING_NEXT_SRV6_LOCAL,
   UDP_PING_NEXT_IP6_DROP,
   UDP_PING_N_NEXT,
 } udp_ping_next_t;
@@ -517,9 +518,6 @@ udp_ping_local_analyse (vlib_node_runtime_t * node, vlib_buffer_t * b0,
                        ip6_header_t * ip0, ip6_hop_by_hop_header_t * hbh0,
                        u16 * next0)
 {
-  ip6_main_t *im = &ip6_main;
-  ip_lookup_main_t *lm = &im->lookup_main;
-
   *next0 = UDP_PING_NEXT_IP6_DROP;
 
   /*
@@ -578,32 +576,47 @@ udp_ping_local_analyse (vlib_node_runtime_t * node, vlib_buffer_t * b0,
    * remote address. So pass it to SR processing as it may be local packet
    * afterall
    */
-  if (PREDICT_FALSE (hbh0->protocol == IPPROTO_IPV6_ROUTE))
-    goto end;
-
-  /* Other case remove hbh-ioam headers */
-  u64 *copy_dst0, *copy_src0;
-  u16 new_l0;
+  if (PREDICT_FALSE (hbh0->protocol == IP_PROTOCOL_IPV6_ROUTE))
+    *next0 = UDP_PING_NEXT_SRV6_LOCAL;
+  else
+    {
+      /* Other case remove hbh-ioam headers */
+      u64 *copy_dst0, *copy_src0;
+      u16 new_l0;
 
-  vlib_buffer_advance (b0, (hbh0->length + 1) << 3);
+      vlib_buffer_advance (b0, (hbh0->length + 1) << 3);
 
-  new_l0 = clib_net_to_host_u16 (ip0->payload_length) -
-    ((hbh0->length + 1) << 3);
+      new_l0 =
+       clib_net_to_host_u16 (ip0->payload_length) - ((hbh0->length + 1) << 3);
 
-  ip0->payload_length = clib_host_to_net_u16 (new_l0);
+      ip0->payload_length = clib_host_to_net_u16 (new_l0);
 
-  ip0->protocol = hbh0->protocol;
+      ip0->protocol = hbh0->protocol;
 
-  copy_src0 = (u64 *) ip0;
-  copy_dst0 = copy_src0 + (hbh0->length + 1);
-  copy_dst0[4] = copy_src0[4];
-  copy_dst0[3] = copy_src0[3];
-  copy_dst0[2] = copy_src0[2];
-  copy_dst0[1] = copy_src0[1];
-  copy_dst0[0] = copy_src0[0];
+      copy_src0 = (u64 *) ip0;
+      copy_dst0 = copy_src0 + (hbh0->length + 1);
+      copy_dst0[4] = copy_src0[4];
+      copy_dst0[3] = copy_src0[3];
+      copy_dst0[2] = copy_src0[2];
+      copy_dst0[1] = copy_src0[1];
+      copy_dst0[0] = copy_src0[0];
 
-end:
-  *next0 = lm->local_next_by_ip_protocol[hbh0->protocol];
+      if (PREDICT_FALSE (hbh0->protocol == IP_PROTOCOL_ICMP6))
+       {
+         /* If next header is ICMP, then pass it to ICMP processing */
+         *next0 = UDP_PING_NEXT_ICMP;
+       }
+      else if (PREDICT_FALSE (hbh0->protocol == IP_PROTOCOL_UDP))
+       {
+         /* If next header is UDP, then pass it to UDP processing */
+         *next0 = UDP_PING_NEXT_UDP_LOOKUP;
+       }
+      else
+       {
+         /* If next header is not UDP or ICMP, then punt it */
+         *next0 = UDP_PING_NEXT_PUNT;
+       }
+    }
   return;
 }
 
@@ -804,6 +817,7 @@ VLIB_REGISTER_NODE (udp_ping_local, static) =
       [UDP_PING_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
       [UDP_PING_NEXT_ICMP] = "ip6-icmp-input",
       [UDP_PING_NEXT_IP6_LOOKUP] = "ip6-lookup",
+      [UDP_PING_NEXT_SRV6_LOCAL] = "sr-localsid-d",
       [UDP_PING_NEXT_IP6_DROP] = "ip6-drop",
     },
 };
index 94bc684..2c78038 100644 (file)
@@ -187,7 +187,7 @@ srv6_end_m_gtp6_d_di_init (vlib_main_t * vm)
   // IPv6 header (default)
   ip6->ip.ip_version_traffic_class_and_flow_label = 0x60;
   ip6->ip.hop_limit = 64;
-  ip6->ip.protocol = IPPROTO_IPV6_ROUTE;
+  ip6->ip.protocol = IP_PROTOCOL_IPV6_ROUTE;
 
   // SR header (default)
   ip6->sr.type = 4;
index c8f619c..f47fd9d 100644 (file)
@@ -374,7 +374,7 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e)
 
          len0 = vlib_buffer_length_in_chain (vm, b0);
 
-         if ((ip6srv0->ip.protocol == IPPROTO_IPV6_ROUTE &&
+         if ((ip6srv0->ip.protocol == IP_PROTOCOL_IPV6_ROUTE &&
               len0 <
                 sizeof (ip6srv_combo_header_t) + ip6srv0->sr.length * 8) ||
              (len0 < sizeof (ip6_header_t)))
@@ -402,7 +402,7 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e)
              void *p;
              uword plen;
 
-             if (ip6srv0->ip.protocol == IPPROTO_IPV6_ROUTE)
+             if (ip6srv0->ip.protocol == IP_PROTOCOL_IPV6_ROUTE)
                {
                  tag = ip6srv0->sr.tag;
                }
@@ -513,7 +513,7 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e)
                    }
                }
 
-             if (ip6srv0->ip.protocol == IPPROTO_IPV6_ROUTE)
+             if (ip6srv0->ip.protocol == IP_PROTOCOL_IPV6_ROUTE)
                {
                  vlib_buffer_advance (b0,
                                       (word) sizeof (ip6srv_combo_header_t) +
@@ -1384,7 +1384,7 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e)
 
          len0 = vlib_buffer_length_in_chain (vm, b0);
 
-         if ((ip6srv0->ip.protocol != IPPROTO_IPV6_ROUTE) ||
+         if ((ip6srv0->ip.protocol != IP_PROTOCOL_IPV6_ROUTE) ||
              (len0 < sizeof (ip6srv_combo_header_t) + 8 * ip6srv0->sr.length))
            {
              next0 = SRV6_END_M_GTP6_E_NEXT_DROP;
index cf9fcb7..3320be7 100644 (file)
  *
  */
 
-#ifndef IPPROTO_IPV6_ROUTE
-#define IPPROTO_IPV6_ROUTE        43
+#ifndef IP_PROTOCOL_IPV6_ROUTE
+#define IP_PROTOCOL_IPV6_ROUTE 43
 #endif
 
 #define ROUTING_HEADER_TYPE_SR    4