lib, tests, zebra: keep table routes at vrf disabling

At VRF disabling, keep the route entries that was associated to its
table ID but not to the VRF itself. Kernel flushes these entries so we
need to reinstall them.

To do so, add a flag to mean that a route entry is owned by a table ID
and not by a VRF. If the VRF associated to the table ID is deleted, the
route entry must not be deleted.

Update to tests with new flag. 2057 is in hexa 0x809, meaning that the
new flag has been to some prefix.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
This commit is contained in:
Louis Scalbert 2024-09-23 17:23:51 +02:00
parent 97c159e882
commit c6afe42455
9 changed files with 48 additions and 29 deletions

View file

@ -1362,6 +1362,8 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api)
stream_putc(s, api->type);
stream_putw(s, api->instance);
if (CHECK_FLAG(api->message, ZAPI_MESSAGE_TABLEID))
SET_FLAG(api->flags, ZEBRA_FLAG_TABLEID);
stream_putl(s, api->flags);
stream_putl(s, api->message);
@ -1421,6 +1423,8 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api)
return -1;
}
if (CHECK_FLAG(api->message, ZAPI_MESSAGE_TABLEID))
SET_FLAG(api->flags, ZEBRA_FLAG_TABLEID);
if (zapi_nexthop_encode(s, api_nh, api->flags,
api->message)
!= 0)
@ -1460,6 +1464,9 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api)
return -1;
}
if (CHECK_FLAG(api->message, ZAPI_MESSAGE_TABLEID))
SET_FLAG(api->flags, ZEBRA_FLAG_TABLEID);
if (zapi_nexthop_encode(s, api_nh, api->flags,
api->message)
!= 0)

View file

@ -578,6 +578,12 @@ struct zapi_route {
* kernel (NLM_F_APPEND at the very least )
*/
#define ZEBRA_FLAG_OUTOFSYNC 0x400
/*
* This flag lets us know that the route entry is
* associated to the table ID and must remain when the
* table ID is de-associated from a VRF.
*/
#define ZEBRA_FLAG_TABLEID 0x800
/* The older XXX_MESSAGE flags live here */
uint32_t message;

View file

@ -68,7 +68,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -97,7 +97,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -126,7 +126,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -155,7 +155,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,

View file

@ -68,7 +68,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -97,7 +97,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -126,7 +126,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -155,7 +155,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -238,7 +238,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,

View file

@ -68,7 +68,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -97,7 +97,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -126,7 +126,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -155,7 +155,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,

View file

@ -68,7 +68,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -97,7 +97,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -126,7 +126,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -155,7 +155,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,

View file

@ -68,7 +68,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -97,7 +97,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -126,7 +126,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -155,7 +155,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -238,7 +238,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,

View file

@ -68,7 +68,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -97,7 +97,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -126,7 +126,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,
@ -155,7 +155,7 @@
"installed": true,
"table": 254,
"internalStatus": 16,
"internalFlags": 9,
"internalFlags": 2057,
"nexthops": [
{
"flags": 3,

View file

@ -191,13 +191,19 @@ static void zebra_vrf_disable_update_vrfid(struct zebra_vrf *zvrf, afi_t afi, sa
/* Assign the kernel route entries to the default VRF,
* even though they are not actually owned by it.
*
* Remove route nodes that have been created by FRR daemons.
* They are not needed if the VRF is disabled.
* Remove route nodes that were created by FRR daemons,
* unless they are associated with the table rather than the VRF.
* Routes associated with the VRF are not needed once the VRF is
* disabled.
*/
rn_delete = true;
RNODE_FOREACH_RE_SAFE (rn, re, nre) {
if (re->type == ZEBRA_ROUTE_KERNEL) {
if (re->type == ZEBRA_ROUTE_KERNEL ||
CHECK_FLAG(re->flags, ZEBRA_FLAG_TABLEID)) {
nexthop_vrf_update(rn, re, VRF_DEFAULT);
if (CHECK_FLAG(re->flags, ZEBRA_FLAG_TABLEID))
/* reinstall routes */
rib_install_kernel(rn, re, NULL);
rn_delete = false;
} else
rib_unlink(rn, re);