Skip to content

Commit 2812487

Browse files
committed
m
1 parent 042349c commit 2812487

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

felix/bpf-gpl/qos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static CALI_BPF_INLINE int qos_enforce_packet_rate(struct cali_tc_ctx *ctx)
108108
return TC_ACT_SHOT;
109109
}
110110

111-
static CALI_BPF_INLINE bool qos_dscp_need_update(struct cali_tc_ctx *ctx)
111+
static CALI_BPF_INLINE bool qos_dscp_needs_update(struct cali_tc_ctx *ctx)
112112
{
113113
return ((ctx->state->flags & CALI_ST_CLUSTER_EXTERNAL) && EGRESS_DSCP >= 0);
114114
}

felix/bpf-gpl/routes.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ static CALI_BPF_INLINE bool rt_addr_is_external(ipv46_addr_t *addr)
123123
return cali_rt_flags_external(cali_rt_lookup_flags(addr));
124124
}
125125

126+
static CALI_BPF_INLINE bool rt_addr_is_host_or_in_pool(ipv46_addr_t *addr)
127+
{
128+
__u32 flags = cali_rt_lookup_flags(addr);
129+
return cali_rt_flags_host(flags) || cali_rt_flags_is_in_pool(flags);
130+
}
131+
126132
// Don't perform SNAT if either:
127133
// - packet is destined to an address in an IP pool;
128134
// - packet is destined to local host; or
@@ -136,5 +142,4 @@ static CALI_BPF_INLINE bool rt_flags_should_perform_nat_outgoing(enum cali_rt_fl
136142
}
137143
return true;
138144
}
139-
140145
#endif /* __CALI_ROUTES_H__ */

felix/bpf-gpl/tc.c

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,10 @@ static CALI_BPF_INLINE void calico_tc_process_ct_lookup(struct cali_tc_ctx *ctx)
548548
ctx->state->flags |= CALI_ST_NAT_OUTGOING;
549549
}
550550
}
551-
// Check if traffic is leaving cluster. It might need to set DSCP.
552-
if (cali_rt_flags_is_in_pool(r->flags)) {
553-
if (rt_addr_is_external(&ctx->state->post_nat_ip_dst)) {
554-
CALI_DEBUG("Outside cluster dest " IP_FMT "", debug_ip(ctx->state->post_nat_ip_dst));
555-
ctx->state->flags |= CALI_ST_CLUSTER_EXTERNAL;
556-
}
551+
// Check if traffic is leaving cluster. We might need to set DSCP later.
552+
if (cali_rt_flags_is_in_pool(r->flags) && rt_addr_is_external(&ctx->state->post_nat_ip_dst)) {
553+
CALI_DEBUG("Outside cluster dest " IP_FMT "", debug_ip(ctx->state->post_nat_ip_dst));
554+
ctx->state->flags |= CALI_ST_CLUSTER_EXTERNAL;
557555
}
558556
/* If 3rd party CNI is used and dest is outside cluster. See commit fc711b192f for details. */
559557
if (!(cali_rt_flags_is_in_pool(r->flags))) {
@@ -565,25 +563,16 @@ static CALI_BPF_INLINE void calico_tc_process_ct_lookup(struct cali_tc_ctx *ctx)
565563
}
566564
}
567565

568-
// If either destination is outside cluster, set flag as might need to update DSCP later.
569-
if (CALI_F_TO_HEP) {
570-
struct cali_rt *r = cali_rt_lookup(&ctx->state->ip_src);
571-
if (r && cali_rt_flags_host(r->flags)) {
572-
if (rt_addr_is_external(&ctx->state->post_nat_ip_dst)) {
573-
CALI_DEBUG("Outside cluster dest " IP_FMT "", debug_ip(ctx->state->post_nat_ip_dst));
574-
ctx->state->flags |= CALI_ST_CLUSTER_EXTERNAL;
575-
}
576-
}
566+
// If either source or destination is outside cluster, set flag as might need to update DSCP later.
567+
if ((CALI_F_TO_HEP) && (rt_addr_is_local_host(&ctx->state->ip_src)) &&
568+
(rt_addr_is_external(&ctx->state->post_nat_ip_dst))) {
569+
CALI_DEBUG("Outside cluster dest " IP_FMT "", debug_ip(ctx->state->post_nat_ip_dst));
570+
ctx->state->flags |= CALI_ST_CLUSTER_EXTERNAL;
577571
}
578-
// If source is outside cluster, set flag as might need to update DSCP later.
579-
if (CALI_F_FROM_HEP) {
580-
struct cali_rt *r = cali_rt_lookup(&ctx->state->post_nat_ip_dst);
581-
if (r && (cali_rt_flags_host(r->flags) || cali_rt_flags_is_in_pool(r->flags))) {
582-
if (rt_addr_is_external(&ctx->state->ip_src)) {
583-
CALI_DEBUG("Outside cluster source " IP_FMT "", debug_ip(ctx->state->ip_src));
584-
ctx->state->flags |= CALI_ST_CLUSTER_EXTERNAL;
585-
}
586-
}
572+
if ((CALI_F_FROM_HEP) && (rt_addr_is_host_or_in_pool(&ctx->state->post_nat_ip_dst)) &&
573+
(rt_addr_is_external(&ctx->state->ip_src))) {
574+
CALI_DEBUG("Outside cluster source " IP_FMT "", debug_ip(ctx->state->ip_src));
575+
ctx->state->flags |= CALI_ST_CLUSTER_EXTERNAL;
587576
}
588577

589578
/* [SMC] I had to add this revalidation when refactoring the conntrack code to use the context and
@@ -1357,7 +1346,7 @@ int calico_tc_skb_accepted_entrypoint(struct __sk_buff *skb)
13571346
deny_reason(ctx, CALI_REASON_DROPPED_BY_QOS);
13581347
goto deny;
13591348
}
1360-
if ((CALI_F_FROM_WEP || CALI_F_TO_HEP) && qos_dscp_need_update(ctx) && !qos_dscp_set(ctx)) {
1349+
if ((CALI_F_FROM_WEP || CALI_F_TO_HEP) && qos_dscp_needs_update(ctx) && !qos_dscp_set(ctx)) {
13611350
goto deny;
13621351
}
13631352
ctx->fwd = calico_tc_skb_accepted(ctx);

0 commit comments

Comments
 (0)