19 class ASTAction(Enum):
27 def __init__(self, action, left, right=None):
29 if action == ASTAction.FALSE or action == ASTAction.TRUE:
30 assert left is None and right is None
34 assert action == ASTAction.EXPR or action == ASTAction.NOT
38 def write(self, expr_param, expr_param2=None):
39 if self.action == ASTAction.OR:
40 return "(" + self.left.write(expr_param, expr_param2) + ") || (" + self.right.write(expr_param, expr_param2) + ")"
41 if self.action == ASTAction.AND:
42 return "(" + self.left.write(expr_param, expr_param2) + ") && (" + self.right.write(expr_param, expr_param2) + ")"
43 if self.action == ASTAction.NOT:
44 return "!(" + self.left.write(expr_param, expr_param2) + ")"
45 if self.action == ASTAction.FALSE:
47 if self.action == ASTAction.TRUE:
49 if self.action == ASTAction.EXPR:
50 return self.left.write(expr_param, expr_param2)
52 def parse_ast(expr, parse_expr, comma_is_or):
55 comma_split = expr.split(",", 1)
56 or_split = expr.split("||", 1)
57 if len(comma_split) > 1 and not "||" in comma_split[0]:
58 # Confusingly, BIRD uses `,` as either || or &&, depending on the type
59 # of expression being parsed. Specifically, a `numbers-match` uses `,`
60 # as OR, whereas a `bitmask-match` uses `,` as AND.
62 return ASTNode(ASTAction.OR, parse_ast(comma_split[0], parse_expr, comma_is_or), parse_ast(comma_split[1], parse_expr, comma_is_or))
64 return ASTNode(ASTAction.AND, parse_ast(comma_split[0], parse_expr, comma_is_or), parse_ast(comma_split[1], parse_expr, comma_is_or))
66 assert not "," in or_split[0]
67 return ASTNode(ASTAction.OR, parse_ast(or_split[0], parse_expr, comma_is_or), parse_ast(or_split[1], parse_expr, comma_is_or))
69 and_split = expr.split("&&", 1)
70 if len(and_split) > 1:
71 return ASTNode(ASTAction.AND, parse_ast(and_split[0], parse_expr, comma_is_or), parse_ast(and_split[1], parse_expr, comma_is_or))
73 if expr.strip() == "true":
74 return ASTNode(ASTAction.TRUE, None)
75 if expr.strip() == "false":
76 return ASTNode(ASTAction.FALSE, None)
78 if expr.startswith("!"):
79 return ASTNode(ASTAction.NOT, parse_ast(expr[1:], parse_expr, comma_is_or))
81 return parse_expr(expr)
84 class NumbersAction(Enum):
91 def __init__(self, action, val):
95 def write(self, param, param2):
96 if param2 is not None:
97 return "(" + param + self.action.value + self.val + ") || (" + param2 + self.action.value + self.val + ")"
98 return param + self.action.value + self.val
100 def parse_numbers_expr(expr):
101 space_split = expr.split(" ")
102 if expr.startswith(">="):
103 assert len(space_split) == 2
104 return ASTNode(ASTAction.EXPR, NumbersExpr(NumbersAction.GTOE, space_split[1]))
105 if expr.startswith(">"):
106 assert len(space_split) == 2
107 return ASTNode(ASTAction.EXPR, NumbersExpr(NumbersAction.GT, space_split[1]))
108 if expr.startswith("<="):
109 assert len(space_split) == 2
110 return ASTNode(ASTAction.EXPR, NumbersExpr(NumbersAction.LTOE, space_split[1]))
111 if expr.startswith("<"):
112 assert len(space_split) == 2
113 return ASTNode(ASTAction.EXPR, NumbersExpr(NumbersAction.LT, space_split[1]))
115 rangesplit = expr.split("..")
116 assert len(rangesplit) == 2
117 #XXX: Are ranges really inclusive,inclusive?
118 left = ASTNode(ASTAction.EXPR, NumbersExpr(NumbersAction.GTOE, rangesplit[0]))
119 right = ASTNode(ASTAction.EXPR, NumbersExpr(NumbersAction.LTOE, rangesplit[1]))
120 return ASTNode(ASTAction.AND, left, right)
122 if expr.startswith("= "):
124 return ASTNode(ASTAction.EXPR, NumbersExpr(NumbersAction.EQ, expr))
126 class FragExpr(Enum):
132 def write(self, ipproto, _param2):
134 if self == FragExpr.IF:
135 return "(ip->frag_off & BE16(IP_MF|IP_OFFSET)) != 0"
136 elif self == FragExpr.FF:
137 return "((ip->frag_off & BE16(IP_MF)) != 0 && (ip->frag_off & BE16(IP_OFFSET)) == 0)"
138 elif self == FragExpr.DF:
139 return "(ip->frag_off & BE16(IP_DF)) != 0"
140 elif self == FragExpr.LF:
141 return "((ip->frag_off & BE16(IP_MF)) == 0 && (ip->frag_off & BE16(IP_OFFSET)) != 0)"
145 if self == FragExpr.IF:
146 return "frag6 != NULL"
147 elif self == FragExpr.FF:
148 return "(frag6 != NULL && (frag6->frag_off & BE16(IP6_MF)) != 0 && (frag6->frag_off & BE16(IP6_FRAGOFF)) == 0)"
149 elif self == FragExpr.DF:
150 assert False # No such thing in v6
151 elif self == FragExpr.LF:
152 return "(frag6 != NULL && (frag6->frag_off & BE16(IP6_MF)) == 0 && (frag6->frag_off & BE16(IP6_FRAGOFF)) != 0)"
156 def parse_frag_expr(expr):
157 if expr == "is_fragment":
158 return ASTNode(ASTAction.EXPR, FragExpr.IF)
159 elif expr == "first_fragment":
160 return ASTNode(ASTAction.EXPR, FragExpr.FF)
161 elif expr == "dont_fragment":
162 return ASTNode(ASTAction.EXPR, FragExpr.DF)
163 elif expr == "last_fragment":
164 return ASTNode(ASTAction.EXPR, FragExpr.LF)
169 def __init__(self, val):
175 def write(self, param, _param2):
176 return f"({param} & {self.mask}) == {self.match}"
178 def parse_bit_expr(expr):
179 return ASTNode(ASTAction.EXPR, BitExpr(expr))
183 def __init__(self, ty, offset, net, proto):
191 def ord(self, other):
192 assert self.ty == other.ty
193 assert self.proto == other.proto
194 if self.offset < other.offset:
196 if self.offset > other.offset:
199 if self.net.overlaps(other.net):
200 if self.net.prefixlen > other.net.prefixlen:
202 elif self.net.prefixlen < other.net.prefixlen:
205 if self.net < other.net:
208 assert self.net > other.net
213 def __lt__(self, other):
214 return self.ord(other) == ORD_LESS
216 def __eq__(self, other):
217 return type(other) == IpRule and self.ty == other.ty and self.offset == other.offset and self.net == other.net and self.proto == other.proto
221 assert self.offset == 0
222 return f"""if ((ip->{self.ty} & MASK4({self.net.prefixlen})) != BIGEND32({int(self.net.network_address)}ULL))
225 u32s = [(int(self.net.network_address) >> (3*32)) & 0xffffffff,
226 (int(self.net.network_address) >> (2*32)) & 0xffffffff,
227 (int(self.net.network_address) >> (1*32)) & 0xffffffff,
228 (int(self.net.network_address) >> (0*32)) & 0xffffffff]
230 mask = f"MASK6({self.net.prefixlen})"
232 mask = f"MASK6_OFFS({self.offset}, {self.net.prefixlen})"
233 return f"""if ((ip6->{self.ty} & {mask}) != (BIGEND128({u32s[0]}ULL, {u32s[1]}ULL, {u32s[2]}ULL, {u32s[3]}ULL) & {mask}))
235 def ip_to_rule(proto, inip, ty, offset):
237 assert offset is None
238 net = ipaddress.IPv4Network(inip.strip())
239 return IpRule(ty, offset, net, 4)
241 net = ipaddress.IPv6Network(inip.strip())
242 return IpRule(ty, offset, net, 6)
244 def fragment_to_rule(ipproto, rules):
245 ast = parse_ast(rules, parse_frag_expr, False)
246 return "if (!( " + ast.write(ipproto) + " )) break;"
248 def len_to_rule(rules):
249 ast = parse_ast(rules, parse_numbers_expr, True)
250 return "if (!( " + ast.write("(data_end - pktdata)") + " )) break;"
252 def proto_to_rule(ipproto, proto):
253 ast = parse_ast(proto, parse_numbers_expr, True)
256 return "if (!( " + ast.write("ip->protocol") + " )) break;"
258 return "if (!( " + ast.write("ip6->nexthdr") + " )) break;"
260 def icmp_type_to_rule(proto, ty):
261 ast = parse_ast(ty, parse_numbers_expr, True)
263 return "if (icmp == NULL) break;\nif (!( " + ast.write("icmp->type") + " )) break;"
265 return "if (icmpv6 == NULL) break;\nif (!( " + ast.write("icmpv6->icmp6_type") + " )) break;"
267 def icmp_code_to_rule(proto, code):
268 ast = parse_ast(code, parse_numbers_expr, True)
270 return "if (icmp == NULL) break;\nif (!( " + ast.write("icmp->code") + " )) break;"
272 return "if (icmpv6 == NULL) break;\nif (!( " + ast.write("icmpv6->icmp6_code") + " )) break;"
274 def dscp_to_rule(proto, rules):
275 ast = parse_ast(rules, parse_numbers_expr, True)
278 return "if (!( " + ast.write("((ip->tos & 0xfc) >> 2)") + " )) break;"
280 return "if (!( " + ast.write("((ip6->priority << 2) | ((ip6->flow_lbl[0] & 0xc0) >> 6))") + " )) break;"
282 def port_to_rule(ty, rules):
284 ast = parse_ast(rules, parse_numbers_expr, True)
285 return "if (sport == -1 || dport == -1) break;\nif (!( " + ast.write("sport", "dport") + " )) break;"
287 ast = parse_ast(rules, parse_numbers_expr, True)
288 return "if (" + ty + " == -1) break;\nif (!( " + ast.write(ty) + " )) break;"
290 def tcp_flags_to_rule(rules):
291 ast = parse_ast(rules, parse_bit_expr, False)
293 return f"""if (tcp == NULL) break;
294 if (!( {ast.write("(ntohs(tcp->flags) & 0xfff)")} )) break;"""
296 def flow_label_to_rule(rules):
297 ast = parse_ast(rules, parse_bit_expr, False)
299 return f"""if (ip6 == NULL) break;
300 if (!( {ast.write("((((uint32_t)(ip6->flow_lbl[0] & 0xf)) << 2*8) | (((uint32_t)ip6->flow_lbl[1]) << 1*8) | (uint32_t)ip6->flow_lbl[0])")} )) break;"""
302 class RuleAction(Enum):
307 def __init__(self, ty, action, inner):
311 if ty == RuleAction.ACTION:
313 assert type(action) == str
314 elif ty == RuleAction.LIST:
315 assert type(inner) == list
316 assert action is None
318 assert type(item) == RuleNode
320 assert ty == RuleAction.CONDITIONS
321 assert type(action) == list
322 assert type(inner) == RuleNode
324 def __lt__(self, other):
325 assert self.ty == RuleAction.CONDITIONS
326 assert other.ty == RuleAction.CONDITIONS
330 # RFC first has us sort by dest, then source, then other conditions. We don't implement the
331 # other conditions because doing so requires re-implementing the Flowspec wire format,
332 # which isn't trivial. However, we do implement the source/dest sorting in the hopes it
333 # allows us to group rules according to source/dest IP and hopefully LLVM optimizes out
336 selfdest = next(filter(lambda a : type(a) == IpRule and a.ty == "daddr", self.action), None)
337 otherdest = next(filter(lambda a : type(a) == IpRule and a.ty == "daddr", self.action), None)
338 if o == ORD_EQUAL and selfdest is not None and otherdest is not None:
339 o = selfdest.ord(otherdest)
342 selfsrc = next(filter(lambda a : type(a) == IpRule and a.ty == "saddr", self.action), None)
343 othersrc = next(filter(lambda a : type(a) == IpRule and a.ty == "saddr", self.action), None)
344 if selfsrc is not None and othersrc is None:
346 elif selfsrc is None and othersrc is not None:
348 elif selfsrc is not None and othersrc is not None:
349 o = selfsrc.ord(othersrc)
353 return self.action < other.action
355 def maybe_join(self, neighbor):
356 if self.ty == RuleAction.CONDITIONS and neighbor.ty == RuleAction.CONDITIONS:
357 overlapping_conditions = [x for x in self.action if x in neighbor.action]
358 if len(overlapping_conditions) != 0:
359 us = RuleNode(RuleAction.CONDITIONS, [x for x in self.action if x not in overlapping_conditions], self.inner)
360 them = RuleNode(RuleAction.CONDITIONS, [x for x in neighbor.action if x not in overlapping_conditions], neighbor.inner)
361 self.action = overlapping_conditions
362 if self.inner.ty == RuleAction.LIST and us.action == []:
363 self.inner.inner.append(them)
365 self.inner = RuleNode(RuleAction.LIST, None, [us, them])
371 # LLVM can be pretty bad at optimizing out common subexpressions. Thus, we have to do a
372 # pass here to toptimize out common subexpressions in back-to-back rules.
373 # See https://bugs.llvm.org/show_bug.cgi?id=52455
374 assert self.ty == RuleAction.LIST
378 for i in range(0, len(self.inner) - 1):
379 if self.inner[i].maybe_join(self.inner[i + 1]):
380 del self.inner[i + 1]
384 def write(self, out, pfx="\t"):
385 if self.ty == RuleAction.CONDITIONS:
386 out.write(pfx + "do {\\\n")
387 for cond in self.action:
388 out.write("\t" + pfx + str(cond).replace("\n", " \\\n\t" + pfx) + " \\\n")
389 self.inner.write(out, pfx)
390 out.write(pfx + "} while(0);\\\n")
391 elif self.ty == RuleAction.LIST:
392 for item in self.inner:
393 item.write(out, pfx + "\t")
395 out.write("\t" + pfx + self.action.strip().replace("\n", " \\\n\t" + pfx) + " \\\n")
397 with open("rules.h", "w") as out:
398 parse = argparse.ArgumentParser()
399 parse.add_argument("--ihl", dest="ihl", required=True, choices=["drop-options","accept-options","parse-options"])
400 parse.add_argument("--v6frag", dest="v6frag", required=True, choices=["drop-frags","ignore","parse-frags","ignore-parse-if-rule"])
401 parse.add_argument("--8021q", dest="vlan", required=True, choices=["drop-vlan","accept-vlan","parse-vlan"])
402 parse.add_argument("--require-8021q", dest="vlan_tag")
403 args = parse.parse_args(sys.argv[1:])
405 if args.ihl == "drop-options":
406 out.write("#define PARSE_IHL XDP_DROP\n")
407 elif args.ihl == "accept-options":
408 out.write("#define PARSE_IHL XDP_PASS\n")
409 elif args.ihl == "parse-options":
410 out.write("#define PARSE_IHL PARSE\n")
412 if args.v6frag == "drop-frags":
413 out.write("#define PARSE_V6_FRAG XDP_DROP\n")
414 elif args.v6frag == "ignore":
416 elif args.v6frag == "parse-frags":
417 out.write("#define PARSE_V6_FRAG PARSE\n")
419 if args.vlan == "drop-vlan":
420 out.write("#define PARSE_8021Q XDP_DROP\n")
421 elif args.vlan == "accept-vlan":
422 out.write("#define PARSE_8021Q XDP_PASS\n")
423 elif args.vlan == "parse-vlan":
424 out.write("#define PARSE_8021Q PARSE\n")
426 if args.vlan_tag is not None:
427 if args.vlan != "parse-vlan":
429 out.write("#define REQ_8021Q " + args.vlan_tag + "\n")
436 v4persrcratelimits = []
437 v5persrcratelimits = []
438 v6persrcratelimits = []
441 for line in sys.stdin.readlines():
443 if lastrule is not None:
444 print("Skipped rule due to lack of understood community tag: " + lastrule)
447 if "BGP.ext_community: " in line:
448 assert lastrule is not None
450 t = lastrule.split("{")
451 if t[0].strip() == "flow4":
453 elif t[0].strip() == "flow6":
463 rule = t[1].split("}")[0].strip()
464 for step in rule.split(";"):
465 if step.strip().startswith("src") or step.strip().startswith("dst"):
466 nets = step.strip()[3:].strip().split(" ")
468 assert nets[1] == "offset"
472 if step.strip().startswith("src"):
473 write_rule(ip_to_rule(proto, nets[0], "saddr", offset))
475 write_rule(ip_to_rule(proto, nets[0], "daddr", offset))
476 elif step.strip().startswith("proto") and proto == 4:
477 write_rule(proto_to_rule(4, step.strip()[6:]))
478 elif step.strip().startswith("next header") and proto == 6:
479 write_rule(proto_to_rule(6, step.strip()[12:]))
480 elif step.strip().startswith("icmp type"):
481 write_rule(icmp_type_to_rule(proto, step.strip()[10:]))
482 elif step.strip().startswith("icmp code"):
483 write_rule(icmp_code_to_rule(proto, step.strip()[10:]))
484 elif step.strip().startswith("sport") or step.strip().startswith("dport") or step.strip().startswith("port"):
485 write_rule(port_to_rule(step.strip().split(" ")[0], step.strip().split(" ", 1)[1]))
486 elif step.strip().startswith("length"):
487 write_rule(len_to_rule(step.strip()[7:]))
488 elif step.strip().startswith("dscp"):
489 write_rule(dscp_to_rule(proto, step.strip()[5:]))
490 elif step.strip().startswith("tcp flags"):
491 write_rule(tcp_flags_to_rule(step.strip()[10:]))
492 elif step.strip().startswith("label"):
493 write_rule(flow_label_to_rule(step.strip()[6:]))
494 elif step.strip().startswith("fragment"):
497 write_rule(fragment_to_rule(proto, step.strip()[9:]))
498 elif step.strip() == "":
508 # Now write the match handling!
512 for community in line.split("("):
513 if not community.startswith("generic, "):
515 blocks = community.split(",")
516 assert len(blocks) == 3
517 if len(blocks[1].strip()) != 10: # Should be 0x12345678
519 ty = blocks[1].strip()[:6]
520 high_byte = int(blocks[1].strip()[6:8], 16)
521 mid_byte = int(blocks[1].strip()[8:], 16)
522 low_bytes = int(blocks[2].strip(") \n"), 16)
523 if ty == "0x8006" or ty == "0x800c" or ty == "0x8306" or ty == "0x830c":
524 if first_action is not None:
525 # Two ratelimit actions, just drop the old one. RFC 8955 says we can.
527 exp = (low_bytes & (0xff << 23)) >> 23
529 first_action = "{stats_replace}\nreturn XDP_DROP;"
530 elif low_bytes & (1 << 31) != 0:
531 # Negative limit, just drop
532 first_action = "{stats_replace}\nreturn XDP_DROP;"
534 # NaN/INF. Just treat as INF and accept
536 elif exp < 127: # < 1
537 first_action = "{stats_replace}\nreturn XDP_DROP;"
538 elif exp >= 127 + 29: # We can't handle the precision required with ns this high
541 mantissa = low_bytes & ((1 << 23) - 1)
542 value = 1.0 + mantissa / (2**23)
543 value *= 2**(exp-127)
545 first_action = "int64_t time_masked = bpf_ktime_get_ns() & RATE_TIME_MASK;\n"
546 first_action += f"int64_t per_pkt_ns = (1000000000LL << RATE_BUCKET_INTEGER_BITS) / {math.floor(value)};\n"
547 if ty == "0x8006" or ty == "0x8306":
548 first_action += "uint64_t amt = data_end - pktdata;\n"
550 first_action += "uint64_t amt = 1;\n"
551 if ty == "0x8006" or ty == "0x800c":
552 first_action += f"const uint32_t ratelimitidx = {ratelimitcnt};\n"
553 first_action += "struct ratelimit *rate = bpf_map_lookup_elem(&rate_map, &ratelimitidx);\n"
555 first_action += "int matched = 0;\n"
556 first_action += "DO_RATE_LIMIT(bpf_spin_lock(&rate->lock), rate, time_masked, amt, per_pkt_ns, matched);\n"
557 first_action += "if (rate) { bpf_spin_unlock(&rate->lock); }\n"
562 first_action += f"const uint32_t srcip = ip->saddr & MASK4({mid_byte});\n"
563 first_action += f"void *rate_map = &v4_src_rate_{len(v4persrcratelimits)};\n"
564 first_action += f"int matched = check_v4_persrc_ratelimit(srcip, rate_map, {(high_byte + 1) * 4096}, time_masked, amt, per_pkt_ns);\n"
565 v4persrcratelimits.append((high_byte + 1) * 4096)
567 first_action += f"const uint64_t srcip = BE128BEHIGH64(ip6->saddr & MASK6({mid_byte}));\n"
568 first_action += f"void *rate_map = &v5_src_rate_{len(v5persrcratelimits)};\n"
569 first_action += f"int matched = check_v5_persrc_ratelimit(srcip, rate_map, {(high_byte + 1) * 4096}, time_masked, amt, per_pkt_ns);\n"
570 v5persrcratelimits.append((high_byte + 1) * 4096)
574 first_action += f"const uint128_t srcip = ip6->saddr & MASK6({mid_byte});\n"
575 first_action += f"void *rate_map = &v6_src_rate_{len(v6persrcratelimits)};\n"
576 first_action += f"int matched = check_v6_persrc_ratelimit(srcip, rate_map, {(high_byte + 1) * 4096}, time_masked, amt, per_pkt_ns);\n"
577 v6persrcratelimits.append((high_byte + 1) * 4096)
578 first_action += "if (matched) {\n"
579 first_action += "\t{stats_replace}\n"
580 first_action += "\treturn XDP_DROP;\n"
581 first_action += "}\n"
583 if low_bytes & 1 == 0:
584 last_action = "return XDP_PASS;"
585 if low_bytes & 2 == 2:
586 stats_action = f"const uint32_t ruleidx = STATIC_RULE_CNT + {stats_rulecnt};\n"
587 stats_action += "INCREMENT_MATCH(ruleidx);"
589 assert False # We do not implement the redirect action
591 if low_bytes & ~0b111111 != 0:
592 assert False # Invalid DSCP value
594 write_rule("int32_t chk = ~BE16(ip->check) & 0xffff;")
595 write_rule("uint8_t orig_tos = ip->tos;")
596 write_rule("ip->tos = (ip->tos & 3) | " + str(low_bytes << 2) + ";")
597 write_rule("chk = (chk - orig_tos + ip->tos);")
598 write_rule("if (unlikely(chk > 0xffff)) { chk -= 65535; }")
599 write_rule("else if (unlikely(chk < 0)) { chk += 65535; }")
600 write_rule("ip->check = ~BE16(chk);")
602 write_rule("ip6->priority = " + str(low_bytes >> 2) + ";")
603 write_rule("ip6->flow_lbl[0] = (ip6->flow_lbl[0] & 0x3f) | " + str((low_bytes & 3) << 6) + ";")
604 if first_action is not None:
605 write_rule(first_action.replace("{stats_replace}", stats_action))
606 if stats_action != "" and (first_action is None or "{stats_replace}" not in first_action):
607 write_rule(stats_action)
608 if last_action is not None:
609 write_rule(last_action)
611 rules6.append(RuleNode(RuleAction.CONDITIONS, conditions, RuleNode(RuleAction.ACTION, actions, None)))
613 rules4.append(RuleNode(RuleAction.CONDITIONS, conditions, RuleNode(RuleAction.ACTION, actions, None)))
614 if stats_action != "":
620 out.write(f"#define STATS_RULECNT {stats_rulecnt}\n")
621 if ratelimitcnt != 0:
622 out.write(f"#define RATE_CNT {ratelimitcnt}\n")
625 out.write("#define NEED_V4_PARSE\n")
626 out.write("#define RULES4 {\\\n")
627 # First sort the rules according to the RFC, then make it a single
628 # LIST rule and call flatten() to unify redundant conditions
630 rules4 = RuleNode(RuleAction.LIST, None, rules4)
636 out.write("#define NEED_V6_PARSE\n")
637 out.write("#define RULES6 {\\\n")
638 # First sort the rules according to the RFC, then make it a single
639 # LIST rule and call flatten() to unify redundant conditions
641 rules6 = RuleNode(RuleAction.LIST, None, rules6)
646 if args.v6frag == "ignore-parse-if-rule":
648 out.write("#define PARSE_V6_FRAG PARSE\n")
649 with open("maps.h", "w") as out:
650 for idx, limit in enumerate(v4persrcratelimits):
651 out.write(f"SRC_RATE_DEFINE(4, {idx}, {limit})\n")
652 for idx, limit in enumerate(v5persrcratelimits):
653 out.write(f"SRC_RATE_DEFINE(5, {idx}, {limit})\n")
654 for idx, limit in enumerate(v6persrcratelimits):
655 out.write(f"SRC_RATE_DEFINE(6, {idx}, {limit})\n")