-
Notifications
You must be signed in to change notification settings - Fork 176
Feat/improve bpf logging #1623
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
base: main
Are you sure you want to change the base?
Feat/improve bpf logging #1623
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,7 +165,8 @@ static int match_dst_ports(Istio__Security__Match *match, struct xdp_info *info, | |
| if (match->n_not_destination_ports != 0) { | ||
| notPorts = KMESH_GET_PTR_VAL(match->not_destination_ports, void *); | ||
| if (!notPorts) { | ||
| BPF_LOG(ERR, AUTH, "failed to retrieve not_destination_ports pointer"); | ||
| BPF_LOG(ERR, AUTH, "failed to retrieve not_destination_ports pointer for src=[%s:%u]\n", | ||
| ip2str((__u32 *)&tuple_info->ipv4.saddr, (info->iph->version == 4)), dport); | ||
| return UNMATCHED; | ||
Aaravanand00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| #pragma unroll | ||
|
|
@@ -186,7 +187,8 @@ static int match_dst_ports(Istio__Security__Match *match, struct xdp_info *info, | |
|
|
||
| ports = KMESH_GET_PTR_VAL(match->destination_ports, void *); | ||
| if (!ports) { | ||
| BPF_LOG(ERR, AUTH, "failed to retrieve destination_ports pointer"); | ||
| BPF_LOG(ERR, AUTH, "failed to retrieve destination_ports pointer for src=[%s:%u]\n", | ||
| ip2str((__u32 *)&tuple_info->ipv4.saddr, (info->iph->version == 4)), dport); | ||
| return UNMATCHED; | ||
Aaravanand00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| #pragma unroll | ||
|
|
@@ -620,13 +622,14 @@ int policy_check(struct xdp_md *ctx) | |
| int i; | ||
|
|
||
| if (construct_tuple_key(ctx, &tuple_key, &info) != PARSER_SUCC) { | ||
| BPF_LOG(ERR, AUTH, "failed to get tuple key in rule_check"); | ||
| BPF_LOG(ERR, AUTH, "failed to get tuple key in rule_check\n"); | ||
| return XDP_PASS; | ||
| } | ||
|
|
||
| match_ctx = bpf_map_lookup_elem(&kmesh_tc_args, &tuple_key); | ||
| if (!match_ctx) { | ||
| BPF_LOG(ERR, AUTH, "failed to retrieve match_context from map"); | ||
| BPF_LOG(ERR, AUTH, "failed to retrieve match_context from map for src=[%s:%u]\n", | ||
| ip2str((__u32 *)&tuple_key.ipv4.saddr, (info.iph->version == 4)), tuple_key.ipv4.sport); | ||
Aaravanand00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return XDP_PASS; | ||
|
Comment on lines
+631
to
633
|
||
| } | ||
| for (i = 0; i < MAX_MEMBER_NUM_PER_POLICY; i++) { | ||
|
|
@@ -655,7 +658,10 @@ int policy_check(struct xdp_md *ctx) | |
| } | ||
|
|
||
| if (matched) { | ||
| BPF_LOG(DEBUG, AUTH, "policy %s matched", match_ctx->policy_name); | ||
| BPF_LOG(INFO, AUTH, "policy %s matched, src=[%s:%u], dst=[%s:%u]\n", | ||
| match_ctx->policy_name, | ||
| ip2str_idx((__u32 *)&tuple_key.ipv4.saddr, (info.iph->version == 4), 0), tuple_key.ipv4.sport, | ||
| ip2str_idx((__u32 *)&tuple_key.ipv4.daddr, (info.iph->version == 4), 1), tuple_key.ipv4.dport); | ||
Aaravanand00 marked this conversation as resolved.
Show resolved
Hide resolved
Aaravanand00 marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+661
to
+664
|
||
| if (info.iph->version == IPV4_VERSION) { | ||
| BPF_LOG(DEBUG, AUTH, "src ip: %s, src port:%u", ip2str(&tuple_key.ipv4.saddr, true), tuple_key.ipv4.sport); | ||
| BPF_LOG( | ||
|
|
@@ -666,11 +672,13 @@ int policy_check(struct xdp_md *ctx) | |
| DEBUG, AUTH, "dst ip: %s, dst port:%u\n", ip2str(tuple_key.ipv6.daddr, false), tuple_key.ipv6.dport); | ||
| } | ||
| if (bpf_map_delete_elem(&kmesh_tc_args, &tuple_key) != 0) { | ||
| BPF_LOG(ERR, AUTH, "failed to delete tail call context from map"); | ||
| BPF_LOG(ERR, AUTH, "failed to delete tail call context from map for src=[%s:%u]\n", | ||
| ip2str((__u32 *)&tuple_key.ipv4.saddr, (info.iph->version == 4)), tuple_key.ipv4.sport); | ||
| } | ||
|
Comment on lines
674
to
677
|
||
| __u32 auth_result = match_ctx->action == ISTIO__SECURITY__ACTION__DENY ? AUTH_DENY : AUTH_ALLOW; | ||
| if (bpf_map_update_elem(&map_of_auth_result, &tuple_key, &auth_result, BPF_ANY) != 0) { | ||
| BPF_LOG(ERR, AUTH, "failed to update auth result in map_of_auth_result"); | ||
| BPF_LOG(ERR, AUTH, "failed to update auth result in map_of_auth_result for src=[%s:%u]\n", | ||
| ip2str((__u32 *)&tuple_key.ipv4.saddr, (info.iph->version == 4)), tuple_key.ipv4.sport); | ||
Aaravanand00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
Comment on lines
678
to
682
|
||
| return match_ctx->action == ISTIO__SECURITY__ACTION__DENY ? XDP_DROP : XDP_PASS; | ||
| } | ||
|
|
@@ -681,7 +689,8 @@ int policy_check(struct xdp_md *ctx) | |
|
|
||
| ret = bpf_map_update_elem(&kmesh_tc_args, &tuple_key, match_ctx, BPF_ANY); | ||
| if (ret < 0) { | ||
| BPF_LOG(ERR, AUTH, "failed to update map, error: %d", ret); | ||
| BPF_LOG(ERR, AUTH, "failed to update match_ctx in map for src=[%s:%u], error: %d\n", | ||
| ip2str((__u32 *)&tuple_key.ipv4.saddr, (info.iph->version == 4)), tuple_key.ipv4.sport, ret); | ||
| return XDP_PASS; | ||
Aaravanand00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| bpf_tail_call(ctx, &map_of_xdp_tailcall, TAIL_CALL_POLICIES_CHECK); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,7 +146,9 @@ static inline void enable_encoding_metadata(struct bpf_sock_ops *skops) | |
| extract_skops_to_tuple(skops, &tuple_info); | ||
| err = bpf_sock_hash_update(skops, &map_of_kmesh_socket, &tuple_info, BPF_ANY); | ||
| if (err) | ||
| BPF_LOG(ERR, SOCKOPS, "enable encoding metadata failed!, err is %d", err); | ||
| BPF_LOG(ERR, SOCKOPS, "enable encoding metadata failed for src=[%s:%u], dst=[%s:%u], err is %d\n", | ||
| ip2str_idx((__u32 *)&tuple_info.ipv4.saddr, (skops->family == AF_INET), 0), bpf_ntohs(tuple_info.ipv4.sport), | ||
| ip2str_idx((__u32 *)&tuple_info.ipv4.daddr, (skops->family == AF_INET), 1), bpf_ntohs(tuple_info.ipv4.dport), err); | ||
Aaravanand00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| SEC("sockops") | ||
|
|
@@ -164,7 +166,9 @@ int sockops_prog(struct bpf_sock_ops *skops) | |
| break; | ||
| observe_on_connect_established(skops->sk, OUTBOUND); | ||
| if (bpf_sock_ops_cb_flags_set(skops, BPF_SOCK_OPS_STATE_CB_FLAG) != 0) | ||
| BPF_LOG(ERR, SOCKOPS, "set sockops cb failed!\n"); | ||
| BPF_LOG(ERR, SOCKOPS, "set sockops cb failed for src=[%s:%u], dst=[%s:%u]\n", | ||
| ip2str_idx((__u32 *)&skops->local_ip4, (skops->family == AF_INET), 0), skops->local_port, | ||
| ip2str_idx((__u32 *)&skops->remote_ip4, (skops->family == AF_INET), 1), bpf_ntohs(GET_SKOPS_REMOTE_PORT(skops))); | ||
|
Comment on lines
+169
to
+171
|
||
| struct bpf_sock *sk = (struct bpf_sock *)skops->sk; | ||
| if (!sk) { | ||
| break; | ||
|
|
@@ -184,7 +188,9 @@ int sockops_prog(struct bpf_sock_ops *skops) | |
| break; | ||
| observe_on_connect_established(skops->sk, INBOUND); | ||
| if (bpf_sock_ops_cb_flags_set(skops, BPF_SOCK_OPS_STATE_CB_FLAG) != 0) | ||
| BPF_LOG(ERR, SOCKOPS, "set sockops cb failed!\n"); | ||
| BPF_LOG(ERR, SOCKOPS, "set sockops cb failed for src=[%s:%u], dst=[%s:%u]\n", | ||
| ip2str_idx((__u32 *)&skops->local_ip4, (skops->family == AF_INET), 0), skops->local_port, | ||
| ip2str_idx((__u32 *)&skops->remote_ip4, (skops->family == AF_INET), 1), bpf_ntohs(GET_SKOPS_REMOTE_PORT(skops))); | ||
Aaravanand00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| auth_ip_tuple(skops); | ||
| break; | ||
| case BPF_SOCK_OPS_STATE_CB: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.