Skip to content

Commit

Permalink
pim: Fix vrf binding of autorp and mroute socket
Browse files Browse the repository at this point in the history
Bind the autorp socket to the vrf device.
Also fixed mroute socket to use vrf_bind instead of directly
setting the socket option.

Signed-off-by: Nathan Bahr <[email protected]>
(cherry picked from commit 7e181a7)
  • Loading branch information
nabahr authored and mergify[bot] committed Feb 24, 2025
1 parent 24dbcbb commit 76e4076
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
10 changes: 10 additions & 0 deletions pimd/pim_autorp.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,13 @@ static bool pim_autorp_socket_enable(struct pim_autorp *autorp)
return false;
}

if (vrf_bind(autorp->pim->vrf->vrf_id, fd, NULL)) {
zlog_warn("Could not bind autorp socket to vrf fd=%d: vrf_id=%d: errno=%d: %s",
fd, autorp->pim->vrf->vrf_id, errno, safe_strerror(errno));
close(fd);
return false;
}

if (!pim_autorp_setup(fd)) {
zlog_warn("Could not setup autorp socket fd=%d: errno=%d: %s", fd, errno,
safe_strerror(errno));
Expand Down Expand Up @@ -1549,7 +1556,10 @@ void pim_autorp_init(struct pim_instance *pim)

if (PIM_DEBUG_AUTORP)
zlog_debug("%s: AutoRP Initialized", __func__);
}

void pim_autorp_enable(struct pim_instance *pim)
{
/* Start AutoRP discovery by default on startup */
pim_autorp_start_discovery(pim);
}
Expand Down
1 change: 1 addition & 0 deletions pimd/pim_autorp.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ void pim_autorp_rm_ifp(struct interface *ifp);
void pim_autorp_start_discovery(struct pim_instance *pim);
void pim_autorp_stop_discovery(struct pim_instance *pim);
void pim_autorp_init(struct pim_instance *pim);
void pim_autorp_enable(struct pim_instance *pim);
void pim_autorp_finish(struct pim_instance *pim);
int pim_autorp_config_write(struct pim_instance *pim, struct vty *vty);
void pim_autorp_show_autorp(struct vty *vty, struct pim_instance *pim, const char *component,
Expand Down
4 changes: 4 additions & 0 deletions pimd/pim_instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ static int pim_vrf_enable(struct vrf *vrf)

pim_mroute_socket_enable(pim);

#if PIM_IPV == 4
pim_autorp_enable(pim);
#endif

FOR_ALL_INTERFACES (vrf, ifp) {
if (!ifp->info)
continue;
Expand Down
10 changes: 2 additions & 8 deletions pimd/pim_mroute.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,17 +876,11 @@ int pim_mroute_socket_enable(struct pim_instance *pim)
pim->vrf->name);
#endif

#ifdef SO_BINDTODEVICE
if (pim->vrf->vrf_id != VRF_DEFAULT
&& setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
pim->vrf->name, strlen(pim->vrf->name))) {
zlog_warn("Could not setsockopt SO_BINDTODEVICE: %s",
safe_strerror(errno));
if (vrf_bind(pim->vrf->vrf_id, fd, NULL)) {
zlog_warn("Could not bind to vrf: %s", safe_strerror(errno));
close(fd);
return -3;
}
#endif

}

pim->mroute_socket = fd;
Expand Down

0 comments on commit 76e4076

Please sign in to comment.