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

fix buf wrongly get subnet

parent 7835bcec
No related branches found
No related tags found
No related merge requests found
......@@ -31,16 +31,29 @@ def update_ebpf_file(file_path, subnet_ip, probability, alternate_ips):
with open(file_path, 'r') as f:
content = f.read()
# Update SUBNET_BASE (convert to subnet)
# Update SUBNET_BASE
subnet_hex = ip_to_subnet_hex(subnet_ip)
content = re.sub(r"(#define SUBNET_BASE __constant_htonl\()(0x[0-9A-Fa-f]+)(\))", fr"\1{subnet_hex}\3", content)
content = re.sub(
r'(#define SUBNET_BASE __constant_htonl\()0x[0-9A-Fa-f]+(\))',
rf'\g<1>{subnet_hex}\g<2>', # Using \g<n> for group references
content
)
# Update REPLACE_PROBABILITY
content = re.sub(r"(#define REPLACE_PROBABILITY )\d+", fr"\1{probability}", content)
content = re.sub(
r'(#define REPLACE_PROBABILITY )\d+',
rf'\g<1>{probability}', # Using \g<1> instead of \1
content
)
# Update ALTERNATE_IPS (in one line)
# Update ALTERNATE_IPS
alternate_hex = ', '.join(f'__constant_htonl({ip_to_hex(ip)})' for ip in alternate_ips)
content = re.sub(r"(const __be32 ALTERNATE_IPS\[\] = \{)([^\}]+)(\};)", fr"\1 {alternate_hex} \3", content, flags=re.DOTALL)
content = re.sub(
r'(const __be32 ALTERNATE_IPS\[\] = \{)[^}]*(};)',
rf'\g<1>{alternate_hex}\g<2>',
content,
flags=re.DOTALL
)
with open(file_path, 'w') as f:
f.write(content)
......@@ -110,4 +123,6 @@ def main():
if __name__ == "__main__":
main()
file_path = 'inter_op_ebpf.c'
update_ebpf_file(file_path, "123.168.1.1", 75, ["123.168.2.2", "123.168.3.3", "123.168.4.4"])
# main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment