Skip to content

Commit 5313b0d

Browse files
giorio94brb
andcommitted
bpf: clear mark content before storing the cluster ID
Currently, the ctx_set_cluster_id_mark helper does not clear the mark before storing the cluster ID. However, the resulting value is not correct in case the same portions of the mark did already contain some value. For instance, this can happen if set_identity_mark got called before, which is now the case since 2660242 ("bpf: lxc: always set identity mark on forwarded egressing traffic"). Let's get this fixed by explicitly masking the mark before storing the cluster ID. Rather than wiping out the entire content, we preserve the "magic" part, which is not expected to interfere. Additionally, let's extend the related BPF test to assert that we correctly propagate the destination clusterID to bpf overlay (thanks Martynas). Co-authored-by: Martynas Pumputis <martynas@isovalent.com> Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
1 parent f3732f5 commit 5313b0d

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

bpf/lib/overloadable_skb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ ctx_set_cluster_id_mark(struct __sk_buff *ctx, __u32 cluster_id)
122122
__u32 cluster_id_lower = (cluster_id & 0xFF);
123123
__u32 cluster_id_upper = ((cluster_id & 0xFFFFFF00) << (8 + IDENTITY_LEN));
124124

125+
ctx->mark &= MARK_MAGIC_KEY_MASK;
125126
ctx->mark |= cluster_id_lower | cluster_id_upper | MARK_MAGIC_CLUSTER_ID;
126127
}
127128

bpf/tests/inter_cluster_snat_clusterip_client_lxc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
/* Set the LXC source address to be the address of pod one */
6161
ASSIGN_CONFIG(union v4addr, endpoint_ipv4, { .be32 = CLIENT_IP})
6262

63+
ASSIGN_CONFIG(__u32, security_label, 0x10042)
64+
6365
#include "lib/ipcache.h"
6466
#include "lib/lb.h"
6567
#include "lib/policy.h"
@@ -158,6 +160,7 @@ int lxc_to_overlay_syn_check(struct __ctx_buff *ctx)
158160
struct iphdr *l3;
159161
struct ipv4_ct_tuple tuple;
160162
struct ct_entry *entry;
163+
__u32 cluster_id;
161164

162165
test_init();
163166

@@ -232,6 +235,11 @@ int lxc_to_overlay_syn_check(struct __ctx_buff *ctx)
232235
if (!entry)
233236
test_fatal("couldn't find egress conntrack entry");
234237

238+
cluster_id = ctx_get_cluster_id_mark(ctx);
239+
if (cluster_id != BACKEND_CLUSTER_ID)
240+
test_fatal("ctx->mark cluster_id should be %u, got %u",
241+
BACKEND_CLUSTER_ID, cluster_id);
242+
235243
test_finish();
236244
}
237245

0 commit comments

Comments
 (0)