Skip to content

Commit

Permalink
pim: Fix autorp group joins
Browse files Browse the repository at this point in the history
Group joining got broken when moving the autorp socket to open/close
as needed. This fixes it so autorp group joining is properly handled
as part of opening the socket.

Signed-off-by: Nathan Bahr <[email protected]>
  • Loading branch information
nabahr committed Feb 21, 2025
1 parent eb6f49f commit 0d3eb37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
28 changes: 13 additions & 15 deletions pimd/pim_autorp.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ static void autorp_read(struct event *evt)
static bool pim_autorp_socket_enable(struct pim_autorp *autorp)
{
int fd;
struct interface *ifp;

/* Return early if socket is already enabled */
if (autorp->sock != -1)
Expand All @@ -990,6 +991,11 @@ static bool pim_autorp_socket_enable(struct pim_autorp *autorp)

autorp->sock = fd;

/* Join autorp groups on all pim enabled interfaces in the VRF */
FOR_ALL_INTERFACES (autorp->pim->vrf, ifp) {
pim_autorp_add_ifp(ifp);
}

if (PIM_DEBUG_AUTORP)
zlog_debug("%s: AutoRP socket enabled (fd=%u)", __func__, fd);

Expand All @@ -1002,6 +1008,7 @@ static bool pim_autorp_socket_disable(struct pim_autorp *autorp)
if (autorp->sock == -1)
return true;

/* No need to leave the autorp groups explicitly, they are left when the socket is closed */
if (close(autorp->sock)) {
zlog_warn("Failure closing autorp socket: fd=%d errno=%d: %s", autorp->sock, errno,
safe_strerror(errno));
Expand Down Expand Up @@ -1428,10 +1435,10 @@ void pim_autorp_add_ifp(struct interface *ifp)
{
/* Add a new interface for autorp
* When autorp is enabled, we must join the autorp groups on all
* pim/multicast interfaces. When autorp first starts, if finds all
* current multicast interfaces and joins on them. If a new interface
* comes up or is configured for multicast after autorp is running, then
* this method will add it for autorp->
* pim/multicast interfaces. When autorp becomes enabled, it finds all
* current pim enabled interfaces and joins the autorp groups on them.
* Any new interfaces added after autorp is enabled will use this function
* to join the autorp groups
* This is called even when adding a new pim interface that is not yet
* active, so make sure the check, it'll call in again once the interface is up.
*/
Expand All @@ -1441,7 +1448,8 @@ void pim_autorp_add_ifp(struct interface *ifp)
pim_ifp = ifp->info;
if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE) && pim_ifp && pim_ifp->pim_enable) {
pim = pim_ifp->pim;
if (pim && pim->autorp && pim->autorp->do_discovery) {
if (pim && pim->autorp &&
(pim->autorp->do_discovery || pim->autorp->send_rp_discovery)) {
if (PIM_DEBUG_AUTORP)
zlog_debug("%s: Adding interface %s to AutoRP, joining AutoRP groups",
__func__, ifp->name);
Expand Down Expand Up @@ -1477,7 +1485,6 @@ void pim_autorp_rm_ifp(struct interface *ifp)

void pim_autorp_start_discovery(struct pim_instance *pim)
{
struct interface *ifp;
struct pim_autorp *autorp = pim->autorp;

/* Make sure the socket is open and ready */
Expand All @@ -1490,25 +1497,16 @@ void pim_autorp_start_discovery(struct pim_instance *pim)
autorp->do_discovery = true;
autorp_read_on(autorp);

FOR_ALL_INTERFACES (autorp->pim->vrf, ifp) {
pim_autorp_add_ifp(ifp);
}

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

void pim_autorp_stop_discovery(struct pim_instance *pim)
{
struct interface *ifp;
struct pim_autorp *autorp = pim->autorp;

if (autorp->do_discovery) {
FOR_ALL_INTERFACES (autorp->pim->vrf, ifp) {
pim_autorp_rm_ifp(ifp);
}

autorp->do_discovery = false;
autorp_read_off(autorp);

Expand Down
7 changes: 2 additions & 5 deletions pimd/pim_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1901,9 +1901,7 @@ static int pim_ifp_up(struct interface *ifp)
}

#if PIM_IPV == 4
if (pim->autorp && pim->autorp->do_discovery && pim_ifp &&
pim_ifp->pim_enable)
pim_autorp_add_ifp(ifp);
pim_autorp_add_ifp(ifp);
#endif

pim_cand_addrs_changed();
Expand Down Expand Up @@ -2020,8 +2018,7 @@ void pim_pim_interface_delete(struct interface *ifp)
return;

#if PIM_IPV == 4
if (pim_ifp->pim_enable)
pim_autorp_rm_ifp(ifp);
pim_autorp_rm_ifp(ifp);
#endif

pim_ifp->pim_enable = false;
Expand Down

0 comments on commit 0d3eb37

Please sign in to comment.