add support for Mikrotik ROSv7 filters (#72)

* add support for Mikrotik ROSv7 filters

* Rework Mikrotik ROSv7 option

- Use same option key with a modifier
- avoid some code duplication

* update doc

Co-authored-by: Denis <denis@jig-ai.ledeuns.net>
This commit is contained in:
Denis Fondras
2022-11-05 12:06:54 +01:00
committed by GitHub
parent 233380d4e9
commit 2921348a98
5 changed files with 67 additions and 14 deletions

View File

@@ -1717,7 +1717,7 @@ bgpq4_print_nokia_md_ipprefixlist(FILE *f, struct bgpq_expander *b)
}
static void
bgpq4_print_kprefix(struct sx_radix_node *n, void *ff)
bgpq4_print_k6prefix(struct sx_radix_node *n, void *ff)
{
char prefix[128];
FILE *f = (FILE*)ff;
@@ -1745,16 +1745,52 @@ bgpq4_print_kprefix(struct sx_radix_node *n, void *ff)
checkSon:
if (n->son)
bgpq4_print_kprefix(n->son, ff);
bgpq4_print_k6prefix(n->son, ff);
}
static void
bgpq4_print_k7prefix(struct sx_radix_node *n, void *ff)
{
char prefix[128];
FILE *f = (FILE*)ff;
if (!f)
f = stdout;
if (n->isGlue)
goto checkSon;
sx_prefix_snprintf_sep(n->prefix, prefix, sizeof(prefix), "/");
if (n->isAggregate)
fprintf(f,"/routing filter rule add chain=\""
"%s-%s\" rule=\"if (dst in %s && dst-len in %d-%d) {accept}\"\n",
bname ? bname : "NN",
n->prefix->family == AF_INET ? "V4" : "V6",
prefix, n->aggregateLow, n->aggregateHi);
else
fprintf(f,"/routing filter rule add chain=\""
"%s-%s\" rule=\"if (dst=%s) {accept}\"\n",
bname ? bname : "NN",
n->prefix->family == AF_INET ? "V4" : "V6",
prefix);
checkSon:
if (n->son)
bgpq4_print_k7prefix(n->son, ff);
}
static void
bgpq4_print_mikrotik_prefixlist(FILE *f, struct bgpq_expander *b)
{
bname = b->name ? b->name : "NN";
void *cbfunc = bgpq4_print_k6prefix;
if (b->vendor == V_MIKROTIK7)
cbfunc = bgpq4_print_k7prefix;
if (!sx_radix_tree_empty(b->tree)) {
sx_radix_tree_foreach(b->tree, bgpq4_print_kprefix, f);
sx_radix_tree_foreach(b->tree, cbfunc, f);
} else {
fprintf(f, "# generated prefix-list %s is empty\n", bname);
}
@@ -1797,7 +1833,8 @@ bgpq4_print_prefixlist(FILE *f, struct bgpq_expander *b)
case V_HUAWEI_XPL:
bgpq4_print_huawei_xpl_prefixlist(f, b);
break;
case V_MIKROTIK:
case V_MIKROTIK6:
case V_MIKROTIK7:
bgpq4_print_mikrotik_prefixlist(f, b);
break;
case V_ARISTA: