Skip to content

Commit bd72375

Browse files
authored
Merge pull request #785 from kmesh-bot/cherry-pick-765-to-release-0.4
[release-0.4] correctly store origin dst addr in map_of_dst_info at ipv4-mapped ipv…
2 parents fa18ef2 + 0729d10 commit bd72375

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

bpf/kmesh/workload/cgroup_sock.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,25 @@ static inline int sock_traffic_control(struct kmesh_context *kmesh_ctx)
1515
{
1616
int ret;
1717
frontend_value *frontend_v = NULL;
18+
frontend_key frontend_k = {0};
1819
struct bpf_sock_addr *ctx = kmesh_ctx->ctx;
20+
struct ip_addr orig_dst_addr = {0};
1921

2022
if (ctx->protocol != IPPROTO_TCP)
2123
return 0;
2224

23-
DECLARE_FRONTEND_KEY(ctx, &kmesh_ctx->orig_dst_addr, frontend_k);
25+
if (ctx->family == AF_INET) {
26+
orig_dst_addr.ip4 = kmesh_ctx->orig_dst_addr.ip4;
27+
frontend_k.addr.ip4 = orig_dst_addr.ip4;
28+
} else if (ctx->family == AF_INET6) {
29+
IP6_COPY(orig_dst_addr.ip6, kmesh_ctx->orig_dst_addr.ip6);
30+
// Java applications use IPv6 for communication. In the IPv4 network environment, the control plane delivers the
31+
// IPv4 address to the bpf map but obtains the IPv4 mapped address from the bpf prog context. Therefore, address
32+
// translation is required before and after traffic manager.
33+
if (is_ipv4_mapped_addr(orig_dst_addr.ip6))
34+
V4_MAPPED_REVERSE(orig_dst_addr.ip6);
35+
bpf_memcpy(frontend_k.addr.ip6, orig_dst_addr.ip6, IPV6_ADDR_LEN);
36+
}
2437

2538
BPF_LOG(
2639
DEBUG,
@@ -106,11 +119,6 @@ int cgroup_connect6_prog(struct bpf_sock_addr *ctx)
106119

107120
BPF_LOG(DEBUG, KMESH, "enter cgroup/connect6\n");
108121

109-
// Java applications use IPv6 for communication. In the IPv4 network environment, the control plane delivers the
110-
// IPv4 address to the bpf map but obtains the IPv4 mapped address from the bpf prog context. Therefore, address
111-
// translation is required before and after traffic manager.
112-
if (is_ipv4_mapped_addr(kmesh_ctx.orig_dst_addr.ip6))
113-
V4_MAPPED_REVERSE(kmesh_ctx.orig_dst_addr.ip6);
114122
int ret = sock_traffic_control(&kmesh_ctx);
115123
if (ret) {
116124
BPF_LOG(ERR, KMESH, "sock_traffic_control failed: %d\n", ret);
@@ -133,4 +141,4 @@ int cgroup_connect6_prog(struct bpf_sock_addr *ctx)
133141
}
134142

135143
char _license[] SEC("license") = "Dual BSD/GPL";
136-
int _version SEC("version") = 1;
144+
int _version SEC("version") = 1;

0 commit comments

Comments
 (0)