zebra: table_id election with the vrf backend

As table_id for VRF with netns backend is main table ( RT_TABLE_MAIN or
zebrad.rtm_table_default), this makes possible to return the table id
that wants to be configured for those cases. ( in addition to default
VRF). In other cases ( VRF Lite presumably), then vrf table_id is
returned.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
This commit is contained in:
Philippe Guibert 2018-03-28 10:46:14 +02:00
parent b3b086026b
commit e9748a8901
3 changed files with 61 additions and 8 deletions

View File

@ -49,7 +49,9 @@ void static_install_route(afi_t afi, safi_t safi, struct prefix *p,
struct vrf *nh_vrf; struct vrf *nh_vrf;
/* Lookup table. */ /* Lookup table. */
table = zebra_vrf_table(afi, safi, si->vrf_id); table = zebra_vrf_table_with_table_id(afi, safi,
si->vrf_id,
si->table_id);
if (!table) if (!table)
return; return;
@ -170,10 +172,20 @@ void static_install_route(afi_t afi, safi_t safi, struct prefix *p,
re->metric = 0; re->metric = 0;
re->mtu = 0; re->mtu = 0;
re->vrf_id = si->vrf_id; re->vrf_id = si->vrf_id;
re->table = if (!vrf_is_backend_netns()) {
(si->vrf_id != VRF_DEFAULT) re->table =
(si->vrf_id != VRF_DEFAULT)
? (zebra_vrf_lookup_by_id(si->vrf_id))->table_id ? (zebra_vrf_lookup_by_id(si->vrf_id))->table_id
: zebrad.rtm_table_default; : zebrad.rtm_table_default;
} else {
struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(si->vrf_id);
if (zvrf->table_id != RT_TABLE_MAIN ||
zvrf->table_id != zebrad.rtm_table_default)
re->table = zvrf->table_id;
else
re->table = zebrad.rtm_table_default;
}
re->nexthop_num = 0; re->nexthop_num = 0;
re->tag = si->tag; re->tag = si->tag;
@ -290,7 +302,9 @@ void static_uninstall_route(afi_t afi, safi_t safi, struct prefix *p,
struct prefix nh_p; struct prefix nh_p;
/* Lookup table. */ /* Lookup table. */
table = zebra_vrf_table(afi, safi, si->vrf_id); table = zebra_vrf_table_with_table_id(afi, safi,
si->vrf_id,
si->table_id);
if (!table) if (!table)
return; return;

View File

@ -328,7 +328,9 @@ int zebra_vrf_has_config(struct zebra_vrf *zvrf)
} }
/* Lookup the routing table in a VRF based on both VRF-Id and table-id. /* Lookup the routing table in a VRF based on both VRF-Id and table-id.
* NOTE: Table-id is relevant only in the Default VRF. * NOTE: Table-id is relevant on two modes:
* - case VRF backend is default : on default VRF only
* - case VRF backend is netns : on all VRFs
*/ */
struct route_table *zebra_vrf_table_with_table_id(afi_t afi, safi_t safi, struct route_table *zebra_vrf_table_with_table_id(afi_t afi, safi_t safi,
vrf_id_t vrf_id, vrf_id_t vrf_id,
@ -346,6 +348,13 @@ struct route_table *zebra_vrf_table_with_table_id(afi_t afi, safi_t safi,
else else
table = zebra_vrf_other_route_table(afi, table_id, table = zebra_vrf_other_route_table(afi, table_id,
vrf_id); vrf_id);
} else if (vrf_is_backend_netns()) {
if (table_id == RT_TABLE_MAIN
|| table_id == zebrad.rtm_table_default)
table = zebra_vrf_table(afi, safi, vrf_id);
else
table = zebra_vrf_other_route_table(afi, table_id,
vrf_id);
} else } else
table = zebra_vrf_table(afi, safi, vrf_id); table = zebra_vrf_table(afi, safi, vrf_id);
@ -434,7 +443,8 @@ struct zebra_vrf *zebra_vrf_alloc(void)
zebra_vxlan_init_tables(zvrf); zebra_vxlan_init_tables(zvrf);
zebra_mpls_init_tables(zvrf); zebra_mpls_init_tables(zvrf);
zebra_pw_init(zvrf); zebra_pw_init(zvrf);
zvrf->table_id = RT_TABLE_MAIN;
/* by default table ID is default one */
return zvrf; return zvrf;
} }
@ -501,9 +511,16 @@ struct route_table *zebra_vrf_other_route_table(afi_t afi, uint32_t table_id,
if (afi >= AFI_MAX) if (afi >= AFI_MAX)
return NULL; return NULL;
if ((vrf_id == VRF_DEFAULT) && (table_id != RT_TABLE_MAIN) if ((table_id != RT_TABLE_MAIN)
&& (table_id != zebrad.rtm_table_default)) { && (table_id != zebrad.rtm_table_default)) {
return zebra_ns_get_table(zns, zvrf, table_id, afi); if (zvrf->table_id == RT_TABLE_MAIN ||
zvrf->table_id == zebrad.rtm_table_default) {
/* this VRF use default table
* so in all cases, it does not use specific table
* so it is possible to configure tables in this VRF
*/
return zebra_ns_get_table(zns, zvrf, table_id, afi);
}
} }
return zvrf->table[afi][SAFI_UNICAST]; return zvrf->table[afi][SAFI_UNICAST];

View File

@ -355,6 +355,23 @@ static int zebra_static_route_leak(
mask_str, src_str, gate_str, ifname, flag_str, tag_str, mask_str, src_str, gate_str, ifname, flag_str, tag_str,
distance_str, label_str, table_str); distance_str, label_str, table_str);
} }
if (table_str) {
/* table configured. check consistent with vrf config
*/
if (zvrf->table_id != RT_TABLE_MAIN &&
zvrf->table_id != zebrad.rtm_table_default) {
if (vty)
vty_out(vty,
"%% Table %s overlaps vrf table %u\n",
table_str, zvrf->table_id);
else
zlog_warn(
"%s: Table %s overlaps vrf table %u",
__PRETTY_FUNCTION__,
table_str, zvrf->table_id);
return CMD_WARNING_CONFIG_FAILED;
}
}
/* Administrative distance. */ /* Administrative distance. */
if (distance_str) if (distance_str)
@ -2644,6 +2661,11 @@ int static_config(struct vty *vty, struct zebra_vrf *zvrf, afi_t afi,
vty_out(vty, " nexthop-vrf %s", si->nh_vrfname); vty_out(vty, " nexthop-vrf %s", si->nh_vrfname);
} }
/* table ID from VRF overrides configured
*/
if (si->table_id && zvrf->table_id == RT_TABLE_MAIN)
vty_out(vty, " table %u", si->table_id);
vty_out(vty, "\n"); vty_out(vty, "\n");
write = 1; write = 1;