Skip to content

Commit

Permalink
bpf: drop: add UNKNOWN_ID and TRACE_EP_ID_UNKNOWN for drop notifications
Browse files Browse the repository at this point in the history
Clarify the magic 0 values in send_drop_notify*(), and make it easier to
discover incomplete drop notifications.

Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
  • Loading branch information
julianwiedmann committed May 16, 2024
1 parent ed26bd9 commit f9fbcb2
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 37 deletions.
6 changes: 3 additions & 3 deletions bpf/bpf_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ do_netdev(struct __ctx_buff *ctx, __u16 proto, const bool from_host)
if (magic == MARK_MAGIC_PROXY_EGRESS_EPID) {
/* extracted identity is actually the endpoint ID */
ret = tail_call_egress_policy(ctx, (__u16)identity);
return send_drop_notify_error(ctx, 0, ret, CTX_ACT_DROP,
return send_drop_notify_error(ctx, UNKNOWN_ID, ret, CTX_ACT_DROP,
METRIC_EGRESS);
}
#endif
Expand Down Expand Up @@ -1222,7 +1222,7 @@ handle_netdev(struct __ctx_buff *ctx, const bool from_host)
break;
}
#endif
return send_drop_notify(ctx, sec_label, id, 0, ret,
return send_drop_notify(ctx, sec_label, id, TRACE_EP_ID_UNKNOWN, ret,
CTX_ACT_DROP, METRIC_EGRESS);
#else
send_trace_notify(ctx, TRACE_TO_STACK, HOST_ID, UNKNOWN_ID,
Expand Down Expand Up @@ -1702,7 +1702,7 @@ to_host_from_lxc(struct __ctx_buff *ctx __maybe_unused)

out:
if (IS_ERR(ret))
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_INGRESS);
return ret;
}
Expand Down
12 changes: 8 additions & 4 deletions bpf/bpf_lxc.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ int tail_handle_ipv6_cont(struct __ctx_buff *ctx)
int ret = handle_ipv6_from_lxc(ctx, &dst_sec_identity, &ext_err);

if (IS_ERR(ret))
return send_drop_notify_ext(ctx, SECLABEL_IPV6, dst_sec_identity, 0, ret, ext_err,
return send_drop_notify_ext(ctx, SECLABEL_IPV6, dst_sec_identity,
TRACE_EP_ID_UNKNOWN, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);

#ifdef ENABLE_CUSTOM_CALLS
Expand Down Expand Up @@ -1347,7 +1348,8 @@ int tail_handle_ipv4_cont(struct __ctx_buff *ctx)
int ret = handle_ipv4_from_lxc(ctx, &dst_sec_identity, &ext_err);

if (IS_ERR(ret))
return send_drop_notify_ext(ctx, SECLABEL_IPV4, dst_sec_identity, 0, ret, ext_err,
return send_drop_notify_ext(ctx, SECLABEL_IPV4, dst_sec_identity,
TRACE_EP_ID_UNKNOWN, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);

#ifdef ENABLE_CUSTOM_CALLS
Expand Down Expand Up @@ -1513,7 +1515,8 @@ int cil_from_container(struct __ctx_buff *ctx)

out:
if (IS_ERR(ret))
return send_drop_notify_ext(ctx, sec_label, 0, 0, ret, ext_err,
return send_drop_notify_ext(ctx, sec_label, UNKNOWN_ID,
TRACE_EP_ID_UNKNOWN, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);
return ret;
}
Expand Down Expand Up @@ -2399,7 +2402,8 @@ int handle_policy_egress(struct __ctx_buff *ctx)

out:
if (IS_ERR(ret))
return send_drop_notify_ext(ctx, sec_label, 0, 0, ret, ext_err,
return send_drop_notify_ext(ctx, sec_label, UNKNOWN_ID,
TRACE_EP_ID_UNKNOWN, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);

return ret;
Expand Down
10 changes: 5 additions & 5 deletions bpf/bpf_overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ int tail_handle_arp(struct __ctx_buff *ctx)

key_size = TUNNEL_KEY_WITHOUT_SRC_IP;
if (unlikely(ctx_get_tunnel_key(ctx, &key, key_size, 0) < 0))
return send_drop_notify_error(ctx, 0, DROP_NO_TUNNEL_KEY, CTX_ACT_DROP,
return send_drop_notify_error(ctx, UNKNOWN_ID, DROP_NO_TUNNEL_KEY, CTX_ACT_DROP,
METRIC_INGRESS);

if (!arp_validate(ctx, &mac, &smac, &sip, &tip) || !__lookup_ip4_endpoint(tip))
Expand All @@ -508,9 +508,9 @@ int tail_handle_arp(struct __ctx_buff *ctx)

ret = arp_prepare_response(ctx, &mac, tip, &smac, sip);
if (unlikely(ret != 0))
return send_drop_notify_error(ctx, 0, ret, CTX_ACT_DROP, METRIC_EGRESS);
return send_drop_notify_error(ctx, UNKNOWN_ID, ret, CTX_ACT_DROP, METRIC_EGRESS);
if (info->tunnel_endpoint) {
ret = __encap_and_redirect_with_nodeid(ctx, 0, info->tunnel_endpoint,
ret = __encap_and_redirect_with_nodeid(ctx, UNKNOWN_ID, info->tunnel_endpoint,
LOCAL_NODE_ID, WORLD_IPV4_ID,
WORLD_IPV4_ID, &trace);
if (IS_ERR(ret))
Expand All @@ -521,7 +521,7 @@ int tail_handle_arp(struct __ctx_buff *ctx)

ret = DROP_UNKNOWN_L3;
drop_err:
return send_drop_notify_error(ctx, 0, ret, CTX_ACT_DROP, METRIC_EGRESS);
return send_drop_notify_error(ctx, UNKNOWN_ID, ret, CTX_ACT_DROP, METRIC_EGRESS);

pass_to_stack:
send_trace_notify(ctx, TRACE_TO_STACK, UNKNOWN_ID, UNKNOWN_ID,
Expand Down Expand Up @@ -780,7 +780,7 @@ int cil_to_overlay(struct __ctx_buff *ctx)
out:
#endif
if (IS_ERR(ret))
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);
return ret;
}
Expand Down
8 changes: 4 additions & 4 deletions bpf/bpf_xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ int tail_lb_ipv4(struct __ctx_buff *ctx)

out:
if (IS_ERR(ret))
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_INGRESS);

return bpf_xdp_exit(ctx, ret);
Expand All @@ -205,7 +205,7 @@ static __always_inline int check_v4_lb(struct __ctx_buff *ctx)
int ret;

ret = tail_call_internal(ctx, CILIUM_CALL_IPV4_FROM_NETDEV, &ext_err);
return send_drop_notify_error_ext(ctx, 0, ret, ext_err, CTX_ACT_DROP,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err, CTX_ACT_DROP,
METRIC_INGRESS);
}
#else
Expand Down Expand Up @@ -274,7 +274,7 @@ int tail_lb_ipv6(struct __ctx_buff *ctx)
return bpf_xdp_exit(ctx, ret);

drop_err:
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_INGRESS);
}

Expand All @@ -284,7 +284,7 @@ static __always_inline int check_v6_lb(struct __ctx_buff *ctx)
int ret;

ret = tail_call_internal(ctx, CILIUM_CALL_IPV6_FROM_NETDEV, &ext_err);
return send_drop_notify_error_ext(ctx, 0, ret, ext_err, CTX_ACT_DROP,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err, CTX_ACT_DROP,
METRIC_INGRESS);
}
#else
Expand Down
2 changes: 1 addition & 1 deletion bpf/lib/arp.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ arp_respond(struct __ctx_buff *ctx, union macaddr *smac, __be32 sip,
return ctx_redirect(ctx, ctx_get_ifindex(ctx), direction);

error:
return send_drop_notify_error(ctx, 0, ret, CTX_ACT_DROP, METRIC_EGRESS);
return send_drop_notify_error(ctx, UNKNOWN_ID, ret, CTX_ACT_DROP, METRIC_EGRESS);
}


Expand Down
2 changes: 1 addition & 1 deletion bpf/lib/encrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ do_decrypt(struct __ctx_buff *ctx, __u16 proto)
return CTX_ACT_OK;

if (!node_id)
return send_drop_notify_error(ctx, 0, DROP_NO_NODE_ID,
return send_drop_notify_error(ctx, UNKNOWN_ID, DROP_NO_NODE_ID,
CTX_ACT_DROP,
METRIC_INGRESS);
set_ipsec_decrypt_mark(ctx, node_id);
Expand Down
4 changes: 2 additions & 2 deletions bpf/lib/icmp6.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ int tail_icmp6_send_time_exceeded(struct __ctx_buff *ctx __maybe_unused)

ret = __icmp6_send_time_exceeded(ctx, nh_off);
if (IS_ERR(ret))
return send_drop_notify_error(ctx, 0, ret, CTX_ACT_DROP,
return send_drop_notify_error(ctx, UNKNOWN_ID, ret, CTX_ACT_DROP,
direction);
return ret;
}
Expand Down Expand Up @@ -341,7 +341,7 @@ int tail_icmp6_handle_ns(struct __ctx_buff *ctx)

ret = __icmp6_handle_ns(ctx, nh_off);
if (IS_ERR(ret))
return send_drop_notify_error(ctx, 0, ret, CTX_ACT_DROP, direction);
return send_drop_notify_error(ctx, UNKNOWN_ID, ret, CTX_ACT_DROP, direction);
return ret;
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions bpf/lib/mcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ int tail_mcast_ep_delivery(struct __ctx_buff *ctx)
for_each_map_elem(sub_map, __mcast_ep_delivery, &cb_ctx, 0);

return send_drop_notify(ctx,
0,
0,
0,
UNKNOWN_ID,
UNKNOWN_ID,
TRACE_EP_ID_UNKNOWN,
DROP_MULTICAST_HANDLED,
CTX_ACT_DROP,
METRIC_INGRESS);
Expand Down
29 changes: 15 additions & 14 deletions bpf/lib/nodeport.h
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ static __always_inline int dsr_reply_icmp6(struct __ctx_buff *ctx,
return ctx_redirect(ctx, ctx_get_ifindex(ctx), 0);
drop_err:
#endif
return send_drop_notify_error(ctx, 0, code, CTX_ACT_DROP,
return send_drop_notify_error(ctx, UNKNOWN_ID, code, CTX_ACT_DROP,
METRIC_EGRESS);
}

Expand Down Expand Up @@ -762,7 +762,7 @@ int tail_nodeport_ipv6_dsr(struct __ctx_buff *ctx)
return ret;
}
drop_err:
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);
}

Expand Down Expand Up @@ -871,7 +871,7 @@ int tail_nat_ipv46(struct __ctx_buff *ctx)
return ret;
}
drop_err:
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);
}

Expand Down Expand Up @@ -902,7 +902,7 @@ int tail_nat_ipv64(struct __ctx_buff *ctx)
return ret;
}
drop_err:
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);
}
#endif /* ENABLE_NAT_46X64_GATEWAY */
Expand Down Expand Up @@ -1063,7 +1063,8 @@ int tail_nodeport_rev_dnat_ingress_ipv6(struct __ctx_buff *ctx)
cilium_capture_out(ctx);
return ret;
drop:
return send_drop_notify_error_ext(ctx, 0, ret, ext_err, CTX_ACT_DROP, METRIC_EGRESS);
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);
}

__section_tail(CILIUM_MAP_CALLS, CILIUM_CALL_IPV6_NODEPORT_NAT_INGRESS)
Expand Down Expand Up @@ -1268,7 +1269,7 @@ int tail_nodeport_nat_egress_ipv6(struct __ctx_buff *ctx)
return ret;
}
drop_err:
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);
}

Expand Down Expand Up @@ -1557,7 +1558,7 @@ int tail_handle_snat_fwd_ipv6(struct __ctx_buff *ctx)

ret = nodeport_snat_fwd_ipv6(ctx, &saddr, &trace, &ext_err);
if (IS_ERR(ret))
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);

/* contrary to tail_handle_snat_fwd_ipv4, we don't check for
Expand Down Expand Up @@ -1627,7 +1628,7 @@ int tail_handle_nat_fwd_ipv6(struct __ctx_buff *ctx)

ret = handle_nat_fwd_ipv6(ctx, &trace, &ext_err);
if (IS_ERR(ret))
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);

if (ret == CTX_ACT_OK)
Expand Down Expand Up @@ -2253,7 +2254,7 @@ static __always_inline int dsr_reply_icmp4(struct __ctx_buff *ctx,
return ctx_redirect(ctx, ctx_get_ifindex(ctx), 0);
drop_err:
#endif
return send_drop_notify_error(ctx, 0, code, CTX_ACT_DROP,
return send_drop_notify_error(ctx, UNKNOWN_ID, code, CTX_ACT_DROP,
METRIC_EGRESS);
}

Expand Down Expand Up @@ -2310,7 +2311,7 @@ int tail_nodeport_ipv4_dsr(struct __ctx_buff *ctx)
return ret;
}
drop_err:
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);
}

Expand Down Expand Up @@ -2571,7 +2572,7 @@ int tail_nodeport_rev_dnat_ingress_ipv4(struct __ctx_buff *ctx)
return ret;

drop_err:
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);
}

Expand Down Expand Up @@ -2797,7 +2798,7 @@ int tail_nodeport_nat_egress_ipv4(struct __ctx_buff *ctx)
return ret;
}
drop_err:
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);
}

Expand Down Expand Up @@ -3175,7 +3176,7 @@ int tail_handle_snat_fwd_ipv4(struct __ctx_buff *ctx)

ret = nodeport_snat_fwd_ipv4(ctx, cluster_id, &saddr, &trace, &ext_err);
if (IS_ERR(ret))
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);

/* Don't emit a trace event if the packet has been redirected to another
Expand Down Expand Up @@ -3248,7 +3249,7 @@ int tail_handle_nat_fwd_ipv4(struct __ctx_buff *ctx)

ret = handle_nat_fwd_ipv4(ctx, &trace, &ext_err);
if (IS_ERR(ret))
return send_drop_notify_error_ext(ctx, 0, ret, ext_err,
return send_drop_notify_error_ext(ctx, UNKNOWN_ID, ret, ext_err,
CTX_ACT_DROP, METRIC_EGRESS);

if (ret == CTX_ACT_OK)
Expand Down

0 comments on commit f9fbcb2

Please sign in to comment.