summaryrefslogtreecommitdiff
path: root/bgpd
diff options
context:
space:
mode:
authorRuss White <russ@riw.us>2025-01-28 10:24:00 -0500
committerGitHub <noreply@github.com>2025-01-28 10:24:00 -0500
commit7b6f686a9fd634cc00a4be63af05d41ac239f8ce (patch)
tree8ae651a644087b8596899d5d5aaf00825914533f /bgpd
parentee67699bd7e0175057ffab4c8c30c74b6c7cc844 (diff)
parent5846339eae91b83cf2c78cfab2e5c1a1013f456e (diff)
Merge pull request #17736 from opensourcerouting/table-direct
bgpd,lib,zebra: permit table-direct on VRFs
Diffstat (limited to 'bgpd')
-rw-r--r--bgpd/bgp_vty.c38
-rw-r--r--bgpd/bgp_zebra.c51
2 files changed, 44 insertions, 45 deletions
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 04b9ce5ea6..046b18f224 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -17575,12 +17575,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;
@@ -17634,12 +17628,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;
@@ -17697,12 +17685,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;
@@ -17767,12 +17749,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;
@@ -17842,13 +17818,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) {
@@ -17911,12 +17881,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;
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index 8e8616c155..179404a2ce 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -2042,11 +2042,34 @@ 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) {
+ /*
+ * When redistribution type is `table-direct` the
+ * instance means `table identification`.
+ *
+ * `table_id` support 32bit integers, however since
+ * `instance` is being overloaded to `table_id` it
+ * will only be possible to use the first 65535
+ * entries.
+ *
+ * Also the ZAPI must also support `int`
+ * (see `zebra_redistribute_add`).
+ */
+ 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;
@@ -2174,10 +2197,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;