Skip to content

Commit

Permalink
zebra: Fix missing VRF flag
Browse files Browse the repository at this point in the history
When `ip link del vrf1`, `zebra` have wrongly forgot it is a vrf type.
It thought it is a normal interface.

```
ZEBRA: [KMXEB-K771Y] netlink_parse_info: netlink-listen (NS 0) type RTM_DELLINK(17), len=588, seq=0, pid=0
ZEBRA: [TDJW2-B9KJW] RTM_DELLINK for vrf1(93) <- Wrongly as normal interface, not vrf
ZEBRA: [WEEJX-M4HA0] interface vrf1 vrf vrf1(93) index 93 is now inactive.
ZEBRA: [NXAHW-290AC] MESSAGE: ZEBRA_INTERFACE_DELETE vrf1 vrf vrf1(93)
ZEBRA: [H97XA-ABB3A] MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL vrf1 VRF Id 93 -> 0
ZEBRA: [HP8PZ-7D6D2] MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD vrf1 VRF Id 93 -> 0 <-
ZEBRA: [Y6R2N-EF2N4] interface vrf1 is being deleted from the system
ZEBRA: [KNFMR-AFZ53] RTM_DELLINK for VRF vrf1(93)
ZEBRA: [P0CZ5-RF5FH] VRF vrf1 id 93 is now inactive
ZEBRA: [XC3P3-1DG4D] MESSAGE: ZEBRA_VRF_DELETE vrf1
ZEBRA: [ZMS2F-6K837] VRF vrf1 id 4294967295 deleted
OSPF: [JKWE3-97M3J] Zebra: interface add vrf1 vrf default[0] index 0 flags 480 metric 0 mtu 65575 speed 0 <- Wrongly add interface
```

It triggers problems on clients.

It will kept as an normal interface in 'show run' after even completely removed,
as said in PR #13388. The clients will accept this wrong interface as normal,
not vrf type:

```
interface vrf1
exit
```
Or

```
interface vrf1
 ip ospf network broadcast
exit
```

The root cause is that the `ifp->status`'s `ZEBRA_INTERFACE_VRF_LOOPBACK`
flag of this vrf is cleared too early. After that clear, `zebra` ( and
then clients ) will take it as normal interface. So, move it from "vrf1"
to "default" VRF, then an unexpected interface with wrong `ifp->status`
is created.

Two changes to fix it:

1. Put the deletion of this flag at the last.
   Aim at that clients can get correct `ifp->status`.

2. Skip the procedure of switching VRF for interfaces of vrf type
   Don't send `ZEBRA_INTERFACE_ADD` to clients when deleting vrf.

Signed-off-by: anlan_cs <[email protected]>
  • Loading branch information
anlancs committed Apr 29, 2023
1 parent 34a8441 commit 6c9cf5b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 0 additions & 2 deletions zebra/if_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2323,8 +2323,6 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
zlog_debug("RTM_DELLINK for %s(%u)", name,
ifp->ifindex);

UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK);

if (IS_ZEBRA_IF_BOND(ifp))
zebra_l2if_update_bond(ifp, false);
if (IS_ZEBRA_IF_BOND_SLAVE(ifp))
Expand Down
5 changes: 5 additions & 0 deletions zebra/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,8 @@ void if_delete_update(struct interface **pifp)
if (ifp->vrf->vrf_id && !vrf_is_backend_netns())
if_handle_vrf_change(ifp, VRF_DEFAULT);

UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK);

/* Reset some zebra interface params to default values. */
zif = ifp->info;
if (zif) {
Expand Down Expand Up @@ -840,6 +842,9 @@ void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id)
/* This is to issue an UPDATE or a DELETE, as appropriate. */
zebra_interface_vrf_update_del(ifp, vrf_id);

if (if_is_vrf(ifp))
return;

/* update VRF */
if_update_to_new_vrf(ifp, vrf_id);

Expand Down

0 comments on commit 6c9cf5b

Please sign in to comment.