Skip to content

Commit

Permalink
vrrp: check ifindex != 0 before using the interface
Browse files Browse the repository at this point in the history
If an interface is deleted, it is identified by the ifindex being
set to 0, so we must ignore any interfaces with a 0 ifindex.

Signed-off-by: Quentin Armitage <[email protected]>
  • Loading branch information
pqarmitage committed Jul 26, 2024
1 parent 39a12b6 commit da0448a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions keepalived/vrrp/vrrp_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ if_get_by_ifindex(ifindex_t ifindex)
{
interface_t *ifp;

if (!ifindex)
return NULL;

list_for_each_entry(ifp, &if_queue, e_list) {
if (ifp->ifindex == ifindex)
return ifp;
Expand Down Expand Up @@ -528,6 +531,23 @@ dump_if(FILE *fp, const interface_t *ifp)

conf_write(fp, " Name = %s", ifp->ifname);
conf_write(fp, " index = %u%s", ifp->ifindex, ifp->ifindex ? "" : " (deleted)");

if (!ifp->ifindex) {
/* This duplicates code below, but it is simpler, and clearer,
* than having lost of "if (ifp->ifindex)" tests */
#ifdef _HAVE_VRRP_VMAC_
if (ifp->is_ours)
conf_write(fp, " I/f created by keepalived");
#endif

if (!list_empty(&ifp->tracking_vrrp)) {
conf_write(fp, " Tracking VRRP instances :");
if_tracking_vrrp_dump_list(fp, &ifp->tracking_vrrp);
}

return;
}

conf_write(fp, " IPv4 address = %s",
ifp->sin_addr.s_addr ? inet_ntop2(ifp->sin_addr.s_addr) : "(none)");
if (!list_empty(&ifp->sin_addr_l)) {
Expand Down
1 change: 1 addition & 0 deletions keepalived/vrrp/vrrp_iproute.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ format_iproute(const ip_route_t *route, char *buf, size_t buf_len)

if (route->set &&
!route->dont_track &&
route->configured_ifindex &&
(!route->oif || route->oif->ifindex != route->configured_ifindex)) {
if ((ifp = if_get_by_ifindex(route->configured_ifindex))) {
if ((op += (size_t)snprintf(op, (size_t)(buf_end - op), " [dev %s]", ifp->ifname)) >= buf_end - 1)
Expand Down

0 comments on commit da0448a

Please sign in to comment.