From 706b6a6040c06e2895863939b7396e8e5adaf6f3 Mon Sep 17 00:00:00 2001 From: hudazaan Date: Thu, 13 Aug 2026 16:08:54 +0000 Subject: [PATCH] fix: handle IPv6 waypoint addresses in service routing Signed-off-by: hudazaan --- bpf/include/common.h | 8 ++++++++ bpf/kmesh/workload/include/backend.h | 2 +- bpf/kmesh/workload/include/frontend.h | 2 +- bpf/kmesh/workload/include/service.h | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bpf/include/common.h b/bpf/include/common.h index 95249f8b6..fa9a1dc7e 100644 --- a/bpf/include/common.h +++ b/bpf/include/common.h @@ -89,6 +89,14 @@ static inline bool is_ipv4_mapped_addr(__u32 ip6[4]) return ip6[0] == 0 && ip6[1] == 0 && ip6[2] == 0xFFFF0000; } +static inline bool is_ip_addr_zero(const struct ip_addr *addr) +{ + if (!addr) + return true; + + return addr->ip4 == 0 && addr->ip6[0] == 0 && addr->ip6[1] == 0 && addr->ip6[2] == 0 && addr->ip6[3] == 0; +} + #define V4_MAPPED_REVERSE(v4_mapped) \ do { \ (v4_mapped)[0] = (v4_mapped)[3]; \ diff --git a/bpf/kmesh/workload/include/backend.h b/bpf/kmesh/workload/include/backend.h index 7d3759c2d..e18540fc2 100644 --- a/bpf/kmesh/workload/include/backend.h +++ b/bpf/kmesh/workload/include/backend.h @@ -60,7 +60,7 @@ backend_manager(struct kmesh_context *kmesh_ctx, backend_value *backend_v, __u32 ctx_buff_t *ctx = (ctx_buff_t *)kmesh_ctx->ctx; __u32 i, user_port = ctx->user_port; - if (backend_v->waypoint_port != 0) { + if (backend_v->waypoint_port != 0 && !is_ip_addr_zero(&backend_v->wp_addr)) { BPF_LOG( DEBUG, BACKEND, diff --git a/bpf/kmesh/workload/include/frontend.h b/bpf/kmesh/workload/include/frontend.h index a16492983..4ef97237b 100644 --- a/bpf/kmesh/workload/include/frontend.h +++ b/bpf/kmesh/workload/include/frontend.h @@ -36,7 +36,7 @@ static inline int frontend_manager(struct kmesh_context *kmesh_ctx, frontend_val if (direct_backend) { // in this case, we donot check the healthy status of the backend, just let it go // For pod direct access, if a pod has waypoint captured, we will redirect to waypoint, otherwise we do nothing. - if (backend_v->waypoint_port != 0) { + if (backend_v->waypoint_port != 0 && !is_ip_addr_zero(&backend_v->wp_addr)) { BPF_LOG( DEBUG, FRONTEND, diff --git a/bpf/kmesh/workload/include/service.h b/bpf/kmesh/workload/include/service.h index 491189430..fa10cdcc2 100644 --- a/bpf/kmesh/workload/include/service.h +++ b/bpf/kmesh/workload/include/service.h @@ -107,7 +107,7 @@ static inline int service_manager(struct kmesh_context *kmesh_ctx, __u32 service { int ret = 0; - if (service_v->wp_addr.ip4 != 0 && service_v->waypoint_port != 0) { + if (!is_ip_addr_zero(&service_v->wp_addr) && service_v->waypoint_port != 0) { BPF_LOG( DEBUG, SERVICE,