Skip to content
Snippets Groups Projects
Commit f2aa8a9d authored by NGUYEN Do Duc Anh's avatar NGUYEN Do Duc Anh
Browse files

ebpf do not allow to read a static array with a variable

parent f128b0f8
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@
#define SUBNET_BASE __constant_htonl(0xAC103C00)
#define REPLACE_PROBABILITY 90
const __be32 ALTERNATE_IPS[] = {__constant_htonl(0x7B640202)};
const __be32 ALTERNATE_IPS[] = {__constant_htonl(0x7B640202), __constant_htonl(0x7B640303)};
#define NUM_ALTERNATE_IPS (sizeof(ALTERNATE_IPS) / sizeof(ALTERNATE_IPS[0]))
BPF_ARRAY(alt_ip_index, __u32, 1); // Single-element array to store index
......@@ -295,7 +295,14 @@ int inter_op_ebpf(struct xdp_md *ctx)
{
// Replace destination IP
__u32 original_ip = ip->daddr;
__u32 new_ip = ALTERNATE_IPS[current_index];
__u32 new_ip;
for (int i = 0; i < NUM_ALTERNATE_IPS; i++) {
if (i == current_index) {
new_ip = ALTERNATE_IPS[i]; // Verifier allows (unrolled)
}
}
ip->daddr = new_ip;
// Optional: log the replacement
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment