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 <[email protected]>
  • Loading branch information
rzalamena committed Jan 23, 2025
1 parent 28a9ca3 commit 7bcb2f5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 45 deletions.
38 changes: 1 addition & 37 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -17598,12 +17598,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 @@ -17657,12 +17651,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 @@ -17720,12 +17708,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 @@ -17790,12 +17772,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 @@ -17865,13 +17841,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",
strlen("table-direct")) == 0) {
if (strncmp(argv[idx_ospf_table]->arg, "table-direct", strlen("table-direct")) == 0) {
protocol = ZEBRA_ROUTE_TABLE_DIRECT;
if (instance == RT_TABLE_MAIN ||
instance == RT_TABLE_LOCAL) {
Expand Down Expand Up @@ -17934,12 +17904,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 @@ -2042,11 +2042,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 @@ -2174,10 +2185,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 7bcb2f5

Please sign in to comment.