Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-0.3] fix authz on server listening on both ipv4 and ipv6 port #279

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading