Skip to content

Commit

Permalink
vrrp: fix vmac creation issue due a race condition
Browse files Browse the repository at this point in the history
The VMAC interface sometimes does not reappear when its associated link
interface is quickly re-added after being deleted, a situation caused by
a race condition.

This problem manifests during the operations of cleanup_lost_interface()
This function checks for VMAC interfaces on top of the removed link
interface. It deletes these VMAC interfaces if they are present.
Subsequently, Netlink is invoked to refresh the information of all
interfaces, and this is followed by the cleaning of the link interface
 data in memory.

The problem occurs when Netlink, queried within
cleanup_lost_interface(), detects that the link interface has
reappeared. Although the interface data in memory is updated
accordingly, cleanup_lost_interface() unconditionally clears this
refreshed information. As a result, the data regarding the link
interface is lost, preventing the re-creation of its associated
VMAC interfaces.

Fix the VMAC creation issue by adding a 'cleaning flag' that is set at
the start of the cleanup process. This flag says whether to proceed with
the interface data cleanup. If the interface is refreshed during the
Netlink polling, the flag is unset, thereby preventing the subsequent
clearing of the updated interface information.

Signed-off-by: Louis Scalbert <[email protected]>
  • Loading branch information
louis-6wind committed Feb 22, 2024
1 parent 2bb8cee commit d8d79f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions keepalived/core/keepalived_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,8 @@ netlink_if_link_populate(interface_t *ifp, struct rtattr *tb[], struct ifinfomsg
if (FLAGS_UP(ifi->ifi_flags))
ifp->seen_up = true;

ifp->cleaning = false;

return true;
}

Expand Down
1 change: 1 addition & 0 deletions keepalived/include/vrrp_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ typedef struct _interface {
otherwise the physical interface */
bool is_ours; /* keepalived created the interface */
bool deleting; /* Set when we are deleting the interface */
bool cleaning; /* Set when we are cleaning the interface */
bool seen_interface; /* The interface has existed at some point since we started */
bool changeable_type; /* The interface type or underlying interface can be changed */
#ifdef _HAVE_VRF_
Expand Down
7 changes: 7 additions & 0 deletions keepalived/vrrp/vrrp_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,8 @@ cleanup_lost_interface(interface_t *ifp)
tracking_obj_t *top;
vrrp_t *vrrp;

ifp->cleaning = true;

list_for_each_entry(top, &ifp->tracking_vrrp, e_list) {
vrrp = top->obj.vrrp;

Expand Down Expand Up @@ -1474,6 +1476,10 @@ cleanup_lost_interface(interface_t *ifp)
down_instance(vrrp);
}

if (!ifp->cleaning)
/* interface has been refreshed. Do not clean */
return;

interface_down(ifp);

ifp->ifindex = 0;
Expand All @@ -1487,6 +1493,7 @@ cleanup_lost_interface(interface_t *ifp)
ifp->vrf_master_ifp = NULL;
ifp->vrf_master_ifindex = 0;
#endif
ifp->cleaning = false;
}

static void
Expand Down

0 comments on commit d8d79f3

Please sign in to comment.