XFREE(MTYPE_PIM_AUTORP_ANNOUNCE, autorp->announce_pkt);
}
+static bool autorp_is_pim_interface(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp = ifp->info;
+
+ return CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE) && pim_ifp && pim_ifp->pim_enable &&
+ !pim_ifp->pim_passive_enable;
+}
+
+static bool pim_autorp_should_enable_socket(struct pim_autorp *autorp)
+{
+ struct interface *ifp;
+
+ /* Only enable the socket if there are any PIM enabled interfaces */
+ FOR_ALL_INTERFACES (autorp->pim->vrf, ifp) {
+ if (autorp_is_pim_interface(ifp))
+ return true;
+ }
+ return false;
+}
+
static bool pim_autorp_should_close(struct pim_autorp *autorp)
{
- /* If discovery or mapping agent is active, then we need the socket open */
- return !autorp->do_discovery && !autorp->send_rp_discovery;
+ /* If discovery or mapping agent is active, then we need the socket open. We also want to leave
+ * the socket open if there are any pim interfaces and we have an announcement packet to send.
+ */
+ return !autorp->do_discovery && !autorp->send_rp_discovery &&
+ !(pim_autorp_should_enable_socket(autorp) && autorp->announce_timer != NULL);
}
static bool pim_autorp_join_groups(struct interface *ifp)
int interval = 5;
/* Make sure the socket is open and ready */
- if (!pim_autorp_socket_enable(autorp)) {
- zlog_err("%s: AutoRP failed to open socket", __func__);
+ if (pim_autorp_should_enable_socket(autorp)) {
+ if (!pim_autorp_socket_enable(autorp)) {
+ zlog_err("%s: AutoRP failed to open socket", __func__);
+ return;
+ }
+ } else {
+ if (PIM_DEBUG_AUTORP)
+ zlog_debug("%s: No PIM interfaces, not enabling socket", __func__);
return;
}
return;
}
+static void pim_autorp_new_announcement(struct pim_instance *pim);
static bool pim_autorp_socket_enable(struct pim_autorp *autorp)
{
int fd;
if (PIM_DEBUG_AUTORP)
zlog_debug("%s: AutoRP socket enabled (fd=%u)", __func__, fd);
+ if (autorp->do_discovery)
+ autorp_read_on(autorp);
+
+ if (autorp->send_rp_discovery)
+ autorp_send_discovery_on(autorp);
+
+ /* Try to build a new announcement to make sure the send timer is enabled */
+ pim_autorp_new_announcement(autorp->pim);
+
return true;
}
+static void autorp_announcement_off(struct pim_autorp *autorp);
static bool pim_autorp_socket_disable(struct pim_autorp *autorp)
{
/* Return early if socket is already disabled */
return false;
}
+ autorp_send_discovery_off(autorp);
+ autorp_announcement_off(autorp);
autorp_read_off(autorp);
autorp->sock = -1;
/* Only send on active interfaces with full pim enabled, non-passive
* and have a primary address set.
*/
- if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE) && pim_ifp &&
- pim_ifp->pim_enable && !pim_ifp->pim_passive_enable &&
+ if (autorp_is_pim_interface(ifp) &&
!pim_addr_is_any(pim_ifp->primary_address)) {
if (setsockopt(autorp->sock, IPPROTO_IP, IP_MULTICAST_IF,
&(pim_ifp->primary_address),
if (PIM_DEBUG_AUTORP)
zlog_debug("%s: AutoRP announcement sending disabled", __func__);
event_cancel(&(autorp->announce_timer));
+
+ /* Close the socket if we need to */
+ if (pim_autorp_should_close(autorp) && !pim_autorp_socket_disable(autorp))
+ zlog_warn("%s: AutoRP failed to close socket", __func__);
}
/* Pack the groups of the RP
autorp->announce_pkt_sz += sizeof(struct autorp_pkt_hdr);
/* Only turn on the announcement timer if we have a packet to send */
- if (autorp->announce_pkt_sz >= MIN_AUTORP_PKT_SZ)
+ if (autorp->announce_pkt_sz >= MIN_AUTORP_PKT_SZ) {
+ /* We are sending an announcement, but discovery could be off, so make sure the socket is open */
+ if (pim_autorp_should_enable_socket(autorp)) {
+ if (!pim_autorp_socket_enable(autorp)) {
+ zlog_err("%s: AutoRP failed to open socket", __func__);
+ return;
+ }
+ } else {
+ if (PIM_DEBUG_AUTORP)
+ zlog_debug("%s: No PIM interfaces, not enabling socket", __func__);
+ return;
+ }
autorp_announcement_on(autorp);
+ }
}
void pim_autorp_prefix_list_update(struct pim_instance *pim, struct prefix_list *plist)
struct pim_interface *pim_ifp;
pim_ifp = ifp->info;
- if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE) && pim_ifp && pim_ifp->pim_enable) {
+ if (autorp_is_pim_interface(ifp)) {
pim = pim_ifp->pim;
- if (pim && pim->autorp &&
- (pim->autorp->do_discovery || pim->autorp->send_rp_discovery)) {
+ if (pim && pim->autorp && !pim_autorp_should_close(pim->autorp)) {
+ /* Make sure the socket is open and ready */
+ if (!pim_autorp_socket_enable(pim->autorp)) {
+ zlog_err("%s: AutoRP failed to open socket", __func__);
+ return;
+ }
+
if (PIM_DEBUG_AUTORP)
zlog_debug("%s: Adding interface %s to AutoRP, joining AutoRP groups",
__func__, ifp->name);
*/
struct pim_instance *pim;
struct pim_interface *pim_ifp;
+ struct pim_autorp *autorp = NULL;
pim_ifp = ifp->info;
if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE) && pim_ifp) {
pim = pim_ifp->pim;
if (pim && pim->autorp) {
+ autorp = pim->autorp;
if (PIM_DEBUG_AUTORP)
zlog_debug("%s: Removing interface %s from AutoRP, leaving AutoRP groups",
__func__, ifp->name);
safe_strerror(errno));
}
}
+
+ if (autorp != NULL && !pim_autorp_should_enable_socket(autorp)) {
+ /* Removed the last pim enabled interface, close the socket */
+ pim_autorp_socket_disable(autorp);
+ }
}
void pim_autorp_start_discovery(struct pim_instance *pim)
autorp->do_discovery = true;
/* Make sure the socket is open and ready */
- if (!pim_autorp_socket_enable(autorp)) {
- zlog_err("%s: AutoRP failed to open socket", __func__);
+ if (pim_autorp_should_enable_socket(autorp)) {
+ if (!pim_autorp_socket_enable(autorp)) {
+ zlog_err("%s: AutoRP failed to open socket", __func__);
+ return;
+ }
+ } else {
+ if (PIM_DEBUG_AUTORP)
+ zlog_debug("%s: No PIM interfaces, not enabling socket", __func__);
return;
}