Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redistribute table bgp without copying data to the default routing table #14388

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 106 additions & 23 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -16846,10 +16846,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 @@ -16869,26 +16870,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 @@ -16904,6 +16918,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 @@ -16913,10 +16929,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 @@ -16925,20 +16951,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 @@ -16953,6 +16981,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 @@ -16962,10 +16992,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 @@ -16976,20 +17016,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 @@ -17009,6 +17051,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 @@ -17018,10 +17062,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 @@ -17035,10 +17089,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 @@ -17047,10 +17102,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 @@ -17070,6 +17126,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 @@ -17078,8 +17136,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 @@ -17096,10 +17164,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 @@ -17108,11 +17177,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 @@ -17125,6 +17195,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 @@ -17134,21 +17206,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
23 changes: 22 additions & 1 deletion doc/user/bgp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1309,10 +1309,31 @@ section for the specific AF to redistribute into. Protocol availability for
redistribution is determined by BGP AF; for example, you cannot redistribute
OSPFv3 into ``address-family ipv4 unicast`` as OSPFv3 supports IPv6.

.. clicmd:: redistribute <babel|connected|eigrp|isis|kernel|openfabric|ospf|ospf6|rip|ripng|sharp|static|table> [metric (0-4294967295)] [route-map WORD]
.. clicmd:: redistribute <babel|connected|eigrp|isis|kernel|openfabric|ospf|ospf6|rip|ripng|sharp|static> [metric (0-4294967295)] [route-map WORD]

Redistribute routes from other protocols into BGP.

.. clicmd:: redistribute <table|table-direct> (1-65535)] [metric (0-4294967295)] [route-map WORD]

Redistribute routes from a routing table ID into BGP. There are two
techniques for redistribution:

- Standard Table Redistribution ``table (1-65535)``:
- Routes from the specified routing table ID are imported into the
default routing table using the ``ip import-table ID`` command.
- These routes are identified by the protocol type "T[ID]" when
displayed with ``show (ip|ipv6) route``.
- The ``redistribute table ID`` command then integrates these routes
into BGP.

- Direct Table Redistribution ``table-direct (1-65535)``:
- This method directly imports routes from the designated routing table
ID into BGP, omitting the step of adding to the default routing table.
- This method is especially relevant when the specified table ID is
checked against routing by appending the appropriate `ip rules`.

Redistribute routes from a routing table number into BGP.

.. clicmd:: redistribute vnc-direct

Redistribute VNC direct (not via zebra) routes to BGP process.
Expand Down
4 changes: 4 additions & 0 deletions lib/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ int proto_redistnum(int afi, const char *s)
return ZEBRA_ROUTE_SHARP;
else if (strmatch(s, "openfabric"))
return ZEBRA_ROUTE_OPENFABRIC;
else if (strmatch(s, "table-direct"))
return ZEBRA_ROUTE_TABLE_DIRECT;
}
if (afi == AFI_IP6) {
if (strmatch(s, "kernel"))
Expand Down Expand Up @@ -603,6 +605,8 @@ int proto_redistnum(int afi, const char *s)
return ZEBRA_ROUTE_SHARP;
else if (strmatch(s, "openfabric"))
return ZEBRA_ROUTE_OPENFABRIC;
else if (strmatch(s, "table-direct"))
return ZEBRA_ROUTE_TABLE_DIRECT;
}
return -1;
}
Expand Down
Loading
Loading