Skip to content

Commit

Permalink
bgpd: allow table-direct on different VRFs
Browse files Browse the repository at this point in the history
Allow table-direct to be configured in different VRFs.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  • Loading branch information
rzalamena committed Dec 30, 2024
1 parent 4925693 commit 29af299
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 44 deletions.
37 changes: 1 addition & 36 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -17496,12 +17496,6 @@ DEFUN (bgp_redistribute_ipv4_ospf,
if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
protocol = ZEBRA_ROUTE_OSPF;
else {
if (bgp->vrf_id != VRF_DEFAULT) {
vty_out(vty,
"%% Only default BGP instance can use '%s'\n",
argv[idx_ospf_table]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
if (strncmp(argv[idx_ospf_table]->arg, "table-direct",
strlen("table-direct")) == 0) {
protocol = ZEBRA_ROUTE_TABLE_DIRECT;
Expand Down Expand Up @@ -17555,12 +17549,6 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap,
if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
protocol = ZEBRA_ROUTE_OSPF;
else {
if (bgp->vrf_id != VRF_DEFAULT) {
vty_out(vty,
"%% Only default BGP instance can use '%s'\n",
argv[idx_ospf_table]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
if (strncmp(argv[idx_ospf_table]->arg, "table-direct",
strlen("table-direct")) == 0) {
protocol = ZEBRA_ROUTE_TABLE_DIRECT;
Expand Down Expand Up @@ -17618,12 +17606,6 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric,
if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
protocol = ZEBRA_ROUTE_OSPF;
else {
if (bgp->vrf_id != VRF_DEFAULT) {
vty_out(vty,
"%% Only default BGP instance can use '%s'\n",
argv[idx_ospf_table]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
if (strncmp(argv[idx_ospf_table]->arg, "table-direct",
strlen("table-direct")) == 0) {
protocol = ZEBRA_ROUTE_TABLE_DIRECT;
Expand Down Expand Up @@ -17688,12 +17670,6 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
protocol = ZEBRA_ROUTE_OSPF;
else {
if (bgp->vrf_id != VRF_DEFAULT) {
vty_out(vty,
"%% Only default BGP instance can use '%s'\n",
argv[idx_ospf_table]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
if (strncmp(argv[idx_ospf_table]->arg, "table-direct",
strlen("table-direct")) == 0) {
protocol = ZEBRA_ROUTE_TABLE_DIRECT;
Expand Down Expand Up @@ -17763,12 +17739,7 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
protocol = ZEBRA_ROUTE_OSPF;
else {
if (bgp->vrf_id != VRF_DEFAULT) {
vty_out(vty,
"%% Only default BGP instance can use '%s'\n",
argv[idx_ospf_table]->arg);
return CMD_WARNING_CONFIG_FAILED;
} else if (strncmp(argv[idx_ospf_table]->arg, "table-direct",
if (strncmp(argv[idx_ospf_table]->arg, "table-direct",
strlen("table-direct")) == 0) {
protocol = ZEBRA_ROUTE_TABLE_DIRECT;
if (instance == RT_TABLE_MAIN ||
Expand Down Expand Up @@ -17832,12 +17803,6 @@ DEFUN (no_bgp_redistribute_ipv4_ospf,
if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
protocol = ZEBRA_ROUTE_OSPF;
else {
if (bgp->vrf_id != VRF_DEFAULT) {
vty_out(vty,
"%% Only default BGP instance can use '%s'\n",
argv[idx_ospf_table]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
if (strncmp(argv[idx_ospf_table]->arg, "table-direct",
strlen("table-direct")) == 0) {
protocol = ZEBRA_ROUTE_TABLE_DIRECT;
Expand Down
39 changes: 31 additions & 8 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -2045,11 +2045,22 @@ int bgp_redistribute_set(struct bgp *bgp, afi_t afi, int type,

/* Return if already redistribute flag is set. */
if (instance) {
if (redist_check_instance(&zclient->mi_redist[afi][type],
instance))
return CMD_WARNING;
if (type == ZEBRA_ROUTE_TABLE_DIRECT) {
struct redist_table_direct table = {
.table_id = instance,
.vrf_id = bgp->vrf_id,
};
if (redist_lookup_table_direct(&zclient->mi_redist[afi][type], &table) != NULL)
return CMD_WARNING;

redist_add_table_direct(&zclient->mi_redist[afi][type], &table);
} else {
if (redist_check_instance(&zclient->mi_redist[afi][type],
instance))
return CMD_WARNING;

redist_add_instance(&zclient->mi_redist[afi][type], instance);
redist_add_instance(&zclient->mi_redist[afi][type], instance);
}
} else {
if (vrf_bitmap_check(&zclient->redist[afi][type], bgp->vrf_id))
return CMD_WARNING;
Expand Down Expand Up @@ -2177,10 +2188,22 @@ int bgp_redistribute_unreg(struct bgp *bgp, afi_t afi, int type,

/* Return if zebra connection is disabled. */
if (instance) {
if (!redist_check_instance(&zclient->mi_redist[afi][type],
instance))
return CMD_WARNING;
redist_del_instance(&zclient->mi_redist[afi][type], instance);
if (type == ZEBRA_ROUTE_TABLE_DIRECT) {
struct redist_table_direct table = {
.table_id = instance,
.vrf_id = bgp->vrf_id,
};
if (redist_lookup_table_direct(&zclient->mi_redist[afi][type], &table) == NULL)
return CMD_WARNING;

redist_del_table_direct(&zclient->mi_redist[afi][type], &table);
} else {
if (!redist_check_instance(&zclient->mi_redist[afi][type],
instance))
return CMD_WARNING;

redist_del_instance(&zclient->mi_redist[afi][type], instance);
}
} else {
if (!vrf_bitmap_check(&zclient->redist[afi][type], bgp->vrf_id))
return CMD_WARNING;
Expand Down

0 comments on commit 29af299

Please sign in to comment.