Skip to content

Commit

Permalink
datapath: Introduce helpers for __ctx_is checks
Browse files Browse the repository at this point in the history
Only macros in function body are updated so it doesn't
affect function definitions.

Fixes: #23008

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander authored and borkmann committed Jun 20, 2023
1 parent a188358 commit c1dffab
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
10 changes: 10 additions & 0 deletions bpf/include/bpf/ctx/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@ static __always_inline bool ctx_no_room(const void *needed, const void *limit)
return unlikely(needed > limit);
}

static __always_inline bool ctx_is_skb(void)
{
return __ctx_is == __ctx_skb;
}

static __always_inline bool ctx_is_xdp(void)
{
return __ctx_is == __ctx_xdp;
}

#endif /* __BPF_CTX_COMMON_H_ */
12 changes: 6 additions & 6 deletions bpf/lib/nodeport.h
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,9 @@ static __always_inline int nodeport_lb6(struct __ctx_buff *ctx,

#if defined(ENABLE_L7_LB)
if (lb6_svc_is_l7loadbalancer(svc) && svc->l7_lb_proxy_port > 0) {
#if __ctx_is == __ctx_xdp
return CTX_ACT_OK;
#endif
if (ctx_is_xdp())
return CTX_ACT_OK;

send_trace_notify(ctx, TRACE_TO_PROXY, src_sec_identity, 0,
bpf_ntohs((__u16)svc->l7_lb_proxy_port), 0,
TRACE_REASON_POLICY, monitor);
Expand Down Expand Up @@ -2318,13 +2318,13 @@ static __always_inline int nodeport_lb4(struct __ctx_buff *ctx,
return DROP_NOT_IN_SRC_RANGE;
#if defined(ENABLE_L7_LB)
if (lb4_svc_is_l7loadbalancer(svc) && svc->l7_lb_proxy_port > 0) {
#if __ctx_is == __ctx_xdp
/* We cannot redirect from the XDP layer to cilium_host.
* Therefore, let the bpf_host to handle the L7 ingress
* request.
*/
return CTX_ACT_OK;
#endif
if (ctx_is_xdp())
return CTX_ACT_OK;

send_trace_notify(ctx, TRACE_TO_PROXY, src_sec_identity, 0,
bpf_ntohs((__u16)svc->l7_lb_proxy_port), 0,
TRACE_REASON_POLICY, monitor);
Expand Down
2 changes: 1 addition & 1 deletion bpf/lib/pcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static __always_inline void __cilium_capture_out(struct __ctx_buff *ctx,
* below is a fallback definition for when the templating var is not defined.
*/
#ifndef capture_enabled
# define capture_enabled (__ctx_is == __ctx_xdp)
# define capture_enabled (ctx_is_xdp())
#endif /* capture_enabled */

struct capture_cache {
Expand Down
5 changes: 4 additions & 1 deletion bpf/lib/qm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

static inline void reset_queue_mapping(struct __ctx_buff *ctx __maybe_unused)
{
#if defined(RESET_QUEUES) && __ctx_is == __ctx_skb
#ifdef RESET_QUEUES
if (!ctx_is_skb())
return;

/* Workaround for GH-18311 where veth driver might have recorded
* veth's RX queue mapping instead of leaving it at 0. This can
* cause issues on the phys device where all traffic would only
Expand Down

0 comments on commit c1dffab

Please sign in to comment.