From 230195db6a86b927f213fb42acc0d0baadec5de7 Mon Sep 17 00:00:00 2001 From: Mohsin Kazmi Date: Fri, 20 Jun 2025 17:06:22 +0000 Subject: [PATCH] ioam: remove use of local_next_by_ip_protocol struct 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 Change-Id: Iafd2a8416dd1f44ef7afd07c92915cd7dd6400a6 --- src/plugins/ioam/ip6/ioam_cache_node.c | 2 +- src/plugins/ioam/udp-ping/udp_ping_node.c | 60 +++++++++++++++++++------------ src/plugins/srv6-mobile/gtp6_d_di.c | 2 +- src/plugins/srv6-mobile/node.c | 8 ++--- src/vnet/srv6/sr_packet.h | 4 +-- 5 files changed, 45 insertions(+), 31 deletions(-) diff --git a/src/plugins/ioam/ip6/ioam_cache_node.c b/src/plugins/ioam/ip6/ioam_cache_node.c index 9859ee6fbf0..cef54637e83 100644 --- a/src/plugins/ioam/ip6/ioam_cache_node.c +++ b/src/plugins/ioam/ip6/ioam_cache_node.c @@ -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 + diff --git a/src/plugins/ioam/udp-ping/udp_ping_node.c b/src/plugins/ioam/udp-ping/udp_ping_node.c index fbc3b13971c..f7302e99f37 100644 --- a/src/plugins/ioam/udp-ping/udp_ping_node.c +++ b/src/plugins/ioam/udp-ping/udp_ping_node.c @@ -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", }, }; diff --git a/src/plugins/srv6-mobile/gtp6_d_di.c b/src/plugins/srv6-mobile/gtp6_d_di.c index 94bc684161d..2c78038d79d 100644 --- a/src/plugins/srv6-mobile/gtp6_d_di.c +++ b/src/plugins/srv6-mobile/gtp6_d_di.c @@ -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; diff --git a/src/plugins/srv6-mobile/node.c b/src/plugins/srv6-mobile/node.c index c8f619cf044..f47fd9dbb62 100644 --- a/src/plugins/srv6-mobile/node.c +++ b/src/plugins/srv6-mobile/node.c @@ -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; diff --git a/src/vnet/srv6/sr_packet.h b/src/vnet/srv6/sr_packet.h index cf9fcb70bcc..3320be78ca0 100644 --- a/src/vnet/srv6/sr_packet.h +++ b/src/vnet/srv6/sr_packet.h @@ -110,8 +110,8 @@ * */ -#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 -- 2.16.6