Skip to content

Commit

Permalink
Merge pull request #279 from kmesh-bot/cherry-pick-272-to-release-0.3
Browse files Browse the repository at this point in the history
[release-0.3] fix authz on server listening on both ipv4 and ipv6 port
  • Loading branch information
kmesh-bot authored May 6, 2024
2 parents ba9dcf8 + 60c0e0b commit b1c4087
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bpf/kmesh/workload/sockops_tuple.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,15 @@ static inline bool conn_from_cni_sim_delete(struct bpf_sock_ops *skops)
(bpf_ntohl(skops->remote_port) == 0x3a2));
}

static inline bool ipv4_mapped_addr(__u32 ip6[4])
{
return ip6[0] == 0 && ip6[1] == 0 && ip6[2] == 0xFFFF0000;
}

SEC("sockops")
int record_tuple(struct bpf_sock_ops *skops)
{
// only support IPV4
if (skops->family != AF_INET)
if (skops->family != AF_INET && !ipv4_mapped_addr(skops->local_ip6))
return 0;
switch (skops->op) {
case BPF_SOCK_OPS_TCP_CONNECT_CB:
Expand All @@ -202,10 +205,11 @@ int record_tuple(struct bpf_sock_ops *skops)
auth_ip_tuple(skops);
break;
case BPF_SOCK_OPS_STATE_CB:
if(skops->args[1] == BPF_TCP_CLOSE || skops->args[1] == BPF_TCP_CLOSE_WAIT
|| skops->args[1] == BPF_TCP_FIN_WAIT1)
if (skops->args[1] == BPF_TCP_CLOSE || skops->args[1] == BPF_TCP_CLOSE_WAIT
|| skops->args[1] == BPF_TCP_FIN_WAIT1) {
clean_auth_map(skops);
clean_dstinfo_map(skops);
}
break;
default:
break;
Expand Down

0 comments on commit b1c4087

Please sign in to comment.