+ if ty == "0x8006" or ty == "0x800c":
+ spin_lock = "bpf_spin_lock(&rate->lock);"
+ spin_unlock = "bpf_spin_unlock(&rate->lock);"
+ first_action += f"const uint32_t ratelimitidx = {ratelimitcnt};\n"
+ first_action += "struct ratelimit *rate = bpf_map_lookup_elem(&rate_map, &ratelimitidx);\n"
+ ratelimitcnt += 1
+ else:
+ spin_lock = "/* No locking as we're per-CPU */"
+ spin_unlock = "/* No locking as we're per-CPU */"
+ if proto == 4:
+ if high_byte > 32:
+ continue
+ first_action += f"const uint32_t srcip = ip->saddr & MASK4({high_byte});\n"
+ first_action += f"void *rate_map = &v4_src_rate_{v4persrcratelimitcnt};\n"
+ v4persrcratelimitcnt += 1
+ else:
+ if high_byte > 128:
+ continue
+ first_action += f"const uint128_t srcip = ip6->saddr & MASK6({high_byte});\n"
+ first_action += f"void *rate_map = &v6_src_rate_{v6persrcratelimitcnt};\n"
+ v6persrcratelimitcnt += 1
+ first_action += f"struct percpu_ratelimit *rate = bpf_map_lookup_elem(rate_map, &srcip);\n"