Skip to content

Commit

Permalink
bgpd: add redistribute table-direct support
Browse files Browse the repository at this point in the history
Add the 'redistribute table-direct' command under the bgp address-family
node. Handle the table-direct support wherever needed in the BGP code.

Signed-off-by: Philippe Guibert <[email protected]>
  • Loading branch information
pguibert6WIND committed Oct 18, 2023
1 parent 3dc065d commit b6d2f9a
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 24 deletions.
129 changes: 106 additions & 23 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -16820,10 +16820,11 @@ ALIAS_HIDDEN(

DEFUN (bgp_redistribute_ipv4_ospf,
bgp_redistribute_ipv4_ospf_cmd,
"redistribute <ospf|table> (1-65535)",
"redistribute <ospf|table|table-direct> (1-65535)",
"Redistribute information from another routing protocol\n"
"Open Shortest Path First (OSPFv2)\n"
"Non-main Kernel Routing Table\n"
"Non-main Kernel Routing Table - Direct\n"
"Instance ID/Table ID\n")
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
Expand All @@ -16843,26 +16844,39 @@ DEFUN (bgp_redistribute_ipv4_ospf,
argv[idx_ospf_table]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
protocol = ZEBRA_ROUTE_TABLE;
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) {
vty_out(vty,
"%% 'table-direct', can not use %u routing table\n",
instance);
return CMD_WARNING_CONFIG_FAILED;
}
} else
protocol = ZEBRA_ROUTE_TABLE;
}

bgp_redist_add(bgp, AFI_IP, protocol, instance);
return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false);
}

ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd,
"redistribute <ospf|table> (1-65535)",
"redistribute <ospf|table|table-direct> (1-65535)",
"Redistribute information from another routing protocol\n"
"Open Shortest Path First (OSPFv2)\n"
"Non-main Kernel Routing Table\n"
"Non-main Kernel Routing Table - Direct\n"
"Instance ID/Table ID\n")

DEFUN (bgp_redistribute_ipv4_ospf_rmap,
bgp_redistribute_ipv4_ospf_rmap_cmd,
"redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
"redistribute <ospf|table|table-direct> (1-65535) route-map RMAP_NAME",
"Redistribute information from another routing protocol\n"
"Open Shortest Path First (OSPFv2)\n"
"Non-main Kernel Routing Table\n"
"Non-main Kernel Routing Table - Direct\n"
"Instance ID/Table ID\n"
"Route map reference\n"
"Pointer to route-map entries\n")
Expand All @@ -16878,6 +16892,8 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap,
struct route_map *route_map =
route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);

instance = strtoul(argv[idx_number]->arg, NULL, 10);

if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
protocol = ZEBRA_ROUTE_OSPF;
else {
Expand All @@ -16887,10 +16903,20 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap,
argv[idx_ospf_table]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
protocol = ZEBRA_ROUTE_TABLE;
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) {
vty_out(vty,
"%% 'table-direct', can not use %u routing table\n",
instance);
return CMD_WARNING_CONFIG_FAILED;
}
} else
protocol = ZEBRA_ROUTE_TABLE;
}

instance = strtoul(argv[idx_number]->arg, NULL, 10);
red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
changed =
bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map);
Expand All @@ -16899,20 +16925,22 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap,

ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap,
bgp_redistribute_ipv4_ospf_rmap_hidden_cmd,
"redistribute <ospf|table> (1-65535) route-map RMAP_NAME",
"redistribute <ospf|table|table-direct> (1-65535) route-map RMAP_NAME",
"Redistribute information from another routing protocol\n"
"Open Shortest Path First (OSPFv2)\n"
"Non-main Kernel Routing Table\n"
"Non-main Kernel Routing Table - Direct\n"
"Instance ID/Table ID\n"
"Route map reference\n"
"Pointer to route-map entries\n")

DEFUN (bgp_redistribute_ipv4_ospf_metric,
bgp_redistribute_ipv4_ospf_metric_cmd,
"redistribute <ospf|table> (1-65535) metric (0-4294967295)",
"redistribute <ospf|table|table-direct> (1-65535) metric (0-4294967295)",
"Redistribute information from another routing protocol\n"
"Open Shortest Path First (OSPFv2)\n"
"Non-main Kernel Routing Table\n"
"Non-main Kernel Routing Table - Direct\n"
"Instance ID/Table ID\n"
"Metric for redistributed routes\n"
"Default metric\n")
Expand All @@ -16927,6 +16955,8 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric,
int protocol;
bool changed;

instance = strtoul(argv[idx_number]->arg, NULL, 10);

if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
protocol = ZEBRA_ROUTE_OSPF;
else {
Expand All @@ -16936,10 +16966,20 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric,
argv[idx_ospf_table]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
protocol = ZEBRA_ROUTE_TABLE;
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) {
vty_out(vty,
"%% 'table-direct', can not use %u routing table\n",
instance);
return CMD_WARNING_CONFIG_FAILED;
}
} else
protocol = ZEBRA_ROUTE_TABLE;
}

instance = strtoul(argv[idx_number]->arg, NULL, 10);
metric = strtoul(argv[idx_number_2]->arg, NULL, 10);

red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
Expand All @@ -16950,20 +16990,22 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric,

ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric,
bgp_redistribute_ipv4_ospf_metric_hidden_cmd,
"redistribute <ospf|table> (1-65535) metric (0-4294967295)",
"redistribute <ospf|table|table-direct> (1-65535) metric (0-4294967295)",
"Redistribute information from another routing protocol\n"
"Open Shortest Path First (OSPFv2)\n"
"Non-main Kernel Routing Table\n"
"Non-main Kernel Routing Table - Direct\n"
"Instance ID/Table ID\n"
"Metric for redistributed routes\n"
"Default metric\n")

DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
bgp_redistribute_ipv4_ospf_rmap_metric_cmd,
"redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
"redistribute <ospf|table|table-direct> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
"Redistribute information from another routing protocol\n"
"Open Shortest Path First (OSPFv2)\n"
"Non-main Kernel Routing Table\n"
"Non-main Kernel Routing Table - Direct\n"
"Instance ID/Table ID\n"
"Route map reference\n"
"Pointer to route-map entries\n"
Expand All @@ -16983,6 +17025,8 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
struct route_map *route_map =
route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);

instance = strtoul(argv[idx_number]->arg, NULL, 10);

if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
protocol = ZEBRA_ROUTE_OSPF;
else {
Expand All @@ -16992,10 +17036,20 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
argv[idx_ospf_table]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
protocol = ZEBRA_ROUTE_TABLE;
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) {
vty_out(vty,
"%% 'table-direct', can not use %u routing table\n",
instance);
return CMD_WARNING_CONFIG_FAILED;
}
} else
protocol = ZEBRA_ROUTE_TABLE;
}

instance = strtoul(argv[idx_number]->arg, NULL, 10);
metric = strtoul(argv[idx_number_2]->arg, NULL, 10);

red = bgp_redist_add(bgp, AFI_IP, protocol, instance);
Expand All @@ -17009,10 +17063,11 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
ALIAS_HIDDEN(
bgp_redistribute_ipv4_ospf_rmap_metric,
bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd,
"redistribute <ospf|table> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
"redistribute <ospf|table|table-direct> (1-65535) route-map RMAP_NAME metric (0-4294967295)",
"Redistribute information from another routing protocol\n"
"Open Shortest Path First (OSPFv2)\n"
"Non-main Kernel Routing Table\n"
"Non-main Kernel Routing Table - Direct\n"
"Instance ID/Table ID\n"
"Route map reference\n"
"Pointer to route-map entries\n"
Expand All @@ -17021,10 +17076,11 @@ ALIAS_HIDDEN(

DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
bgp_redistribute_ipv4_ospf_metric_rmap_cmd,
"redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
"redistribute <ospf|table|table-direct> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
"Redistribute information from another routing protocol\n"
"Open Shortest Path First (OSPFv2)\n"
"Non-main Kernel Routing Table\n"
"Non-main Kernel Routing Table - Direct\n"
"Instance ID/Table ID\n"
"Metric for redistributed routes\n"
"Default metric\n"
Expand All @@ -17044,6 +17100,8 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
struct route_map *route_map =
route_map_lookup_warn_noexist(vty, argv[idx_word]->arg);

instance = strtoul(argv[idx_number]->arg, NULL, 10);

if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
protocol = ZEBRA_ROUTE_OSPF;
else {
Expand All @@ -17052,8 +17110,18 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
"%% Only default BGP instance can use '%s'\n",
argv[idx_ospf_table]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
protocol = ZEBRA_ROUTE_TABLE;
} else 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) {
vty_out(vty,
"%% 'table-direct', can not use %u routing table\n",
instance);
return CMD_WARNING_CONFIG_FAILED;
}
} else
protocol = ZEBRA_ROUTE_TABLE;
}

instance = strtoul(argv[idx_number]->arg, NULL, 10);
Expand All @@ -17070,10 +17138,11 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
ALIAS_HIDDEN(
bgp_redistribute_ipv4_ospf_metric_rmap,
bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd,
"redistribute <ospf|table> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
"redistribute <ospf|table|table-direct> (1-65535) metric (0-4294967295) route-map RMAP_NAME",
"Redistribute information from another routing protocol\n"
"Open Shortest Path First (OSPFv2)\n"
"Non-main Kernel Routing Table\n"
"Non-main Kernel Routing Table - Direct\n"
"Instance ID/Table ID\n"
"Metric for redistributed routes\n"
"Default metric\n"
Expand All @@ -17082,11 +17151,12 @@ ALIAS_HIDDEN(

DEFUN (no_bgp_redistribute_ipv4_ospf,
no_bgp_redistribute_ipv4_ospf_cmd,
"no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
"no redistribute <ospf|table|table-direct> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
NO_STR
"Redistribute information from another routing protocol\n"
"Open Shortest Path First (OSPFv2)\n"
"Non-main Kernel Routing Table\n"
"Non-main Kernel Routing Table - Direct\n"
"Instance ID/Table ID\n"
"Metric for redistributed routes\n"
"Default metric\n"
Expand All @@ -17099,6 +17169,8 @@ DEFUN (no_bgp_redistribute_ipv4_ospf,
unsigned short instance;
int protocol;

instance = strtoul(argv[idx_number]->arg, NULL, 10);

if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
protocol = ZEBRA_ROUTE_OSPF;
else {
Expand All @@ -17108,21 +17180,32 @@ DEFUN (no_bgp_redistribute_ipv4_ospf,
argv[idx_ospf_table]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
protocol = ZEBRA_ROUTE_TABLE;
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) {
vty_out(vty,
"%% 'table-direct', can not use %u routing table\n",
instance);
return CMD_WARNING_CONFIG_FAILED;
}
} else
protocol = ZEBRA_ROUTE_TABLE;
}

instance = strtoul(argv[idx_number]->arg, NULL, 10);
bgp_redistribute_unset(bgp, AFI_IP, protocol, instance);
return CMD_SUCCESS;
}

ALIAS_HIDDEN(
no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
"no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
"no redistribute <ospf|table|table-direct> (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]",
NO_STR
"Redistribute information from another routing protocol\n"
"Open Shortest Path First (OSPFv2)\n"
"Non-main Kernel Routing Table\n"
"Non-main Kernel Routing Table - Direct\n"
"Instance ID/Table ID\n"
"Metric for redistributed routes\n"
"Default metric\n"
Expand Down
3 changes: 2 additions & 1 deletion bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,8 @@ void bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type,
struct listnode *node, *nnode;
struct bgp_redist *red;

if (type != ZEBRA_ROUTE_TABLE || instance != 0)
if ((type != ZEBRA_ROUTE_TABLE && type != ZEBRA_ROUTE_TABLE_DIRECT) ||
instance != 0)
return _bgp_redistribute_unset(bgp, afi, type, instance);

/* walk over instance */
Expand Down

0 comments on commit b6d2f9a

Please sign in to comment.