Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vrrp: check ifindex != 0 before using the interface #2456

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading