@@ -366,6 +366,9 @@ static CALI_BPF_INLINE void calico_tc_process_ct_lookup(struct cali_tc_ctx *ctx)
366366 if (ctx -> state -> ct_result .flags & CALI_CT_FLAG_NAT_OUT ) {
367367 ctx -> state -> flags |= CALI_ST_NAT_OUTGOING ;
368368 }
369+ if (ctx -> state -> ct_result .flags & CALI_CT_FLAG_CLUSTER_EXTERNAL ) {
370+ ctx -> state -> flags |= CALI_ST_CLUSTER_EXTERNAL ;
371+ }
369372
370373 if (CALI_F_TO_HOST && !CALI_F_NAT_IF &&
371374 (ct_result_rc (ctx -> state -> ct_result .rc ) == CALI_CT_ESTABLISHED ||
@@ -545,17 +548,33 @@ static CALI_BPF_INLINE void calico_tc_process_ct_lookup(struct cali_tc_ctx *ctx)
545548 ctx -> state -> flags |= CALI_ST_NAT_OUTGOING ;
546549 }
547550 }
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 ;
555+ }
548556 /* If 3rd party CNI is used and dest is outside cluster. See commit fc711b192f for details. */
549- if (!(r -> flags & CALI_RT_IN_POOL )) {
557+ if (!(cali_rt_flags_is_in_pool ( r -> flags ) )) {
550558 CALI_DEBUG ("Source " IP_FMT " not in IP pool" , debug_ip (ctx -> state -> ip_src ));
551- r = cali_rt_lookup (& ctx -> state -> post_nat_ip_dst );
552- if (!r || !(r -> flags & (CALI_RT_WORKLOAD | CALI_RT_HOST ))) {
559+ if (rt_addr_is_external (& ctx -> state -> post_nat_ip_dst )) {
553560 CALI_DEBUG ("Outside cluster dest " IP_FMT "" , debug_ip (ctx -> state -> post_nat_ip_dst ));
554561 ctx -> state -> flags |= CALI_ST_SKIP_FIB ;
555562 }
556563 }
557564 }
558565
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 ;
571+ }
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 ;
576+ }
577+
559578 /* [SMC] I had to add this revalidation when refactoring the conntrack code to use the context and
560579 * adding possible packet pulls in the VXLAN logic. I believe it is spurious but the verifier is
561580 * not clever enough to spot that we'd have already bailed out if one of the pulls failed. */
@@ -1327,7 +1346,7 @@ int calico_tc_skb_accepted_entrypoint(struct __sk_buff *skb)
13271346 deny_reason (ctx , CALI_REASON_DROPPED_BY_QOS );
13281347 goto deny ;
13291348 }
1330- if ((CALI_F_FROM_WEP || CALI_F_TO_HEP ) && EGRESS_DSCP >= 0 && !qos_set_dscp (ctx )) {
1349+ if ((CALI_F_FROM_WEP || CALI_F_TO_HEP ) && qos_dscp_needs_update ( ctx ) && !qos_dscp_set (ctx )) {
13311350 goto deny ;
13321351 }
13331352 ctx -> fwd = calico_tc_skb_accepted (ctx );
@@ -1408,6 +1427,9 @@ int calico_tc_skb_new_flow_entrypoint(struct __sk_buff *skb)
14081427 if (state -> flags & CALI_ST_NAT_OUTGOING ) {
14091428 ct_ctx_nat -> flags |= CALI_CT_FLAG_NAT_OUT ;
14101429 }
1430+ if (state -> flags & CALI_ST_CLUSTER_EXTERNAL ) {
1431+ ct_ctx_nat -> flags |= CALI_CT_FLAG_CLUSTER_EXTERNAL ;
1432+ }
14111433 if (CALI_F_TO_HOST && state -> flags & CALI_ST_SKIP_FIB ) {
14121434 ct_ctx_nat -> flags |= CALI_CT_FLAG_SKIP_FIB ;
14131435 }
0 commit comments