forked from Mirror/frr
pimd: Close AutoRP socket when not needed
Don't leave the socket open if we are not enabled for discovery or announcements. Signed-off-by: Nathan Bahr <nbahr@atcorp.com>
This commit is contained in:
parent
2982edcaa3
commit
5d102a0a70
|
@ -113,6 +113,12 @@ static void pim_autorp_free(struct pim_autorp *autorp)
|
||||||
XFREE(MTYPE_PIM_AUTORP_ANNOUNCE, autorp->announce_pkt);
|
XFREE(MTYPE_PIM_AUTORP_ANNOUNCE, autorp->announce_pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
static bool pim_autorp_join_groups(struct interface *ifp)
|
static bool pim_autorp_join_groups(struct interface *ifp)
|
||||||
{
|
{
|
||||||
struct pim_interface *pim_ifp;
|
struct pim_interface *pim_ifp;
|
||||||
|
@ -670,10 +676,19 @@ static void autorp_send_discovery(struct event *evt)
|
||||||
&(autorp->send_discovery_timer));
|
&(autorp->send_discovery_timer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool pim_autorp_socket_enable(struct pim_autorp *autorp);
|
||||||
|
static bool pim_autorp_socket_disable(struct pim_autorp *autorp);
|
||||||
|
|
||||||
static void autorp_send_discovery_on(struct pim_autorp *autorp)
|
static void autorp_send_discovery_on(struct pim_autorp *autorp)
|
||||||
{
|
{
|
||||||
int interval = 5;
|
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__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Send the first discovery shortly after being enabled.
|
/* Send the first discovery shortly after being enabled.
|
||||||
* If the configured interval is less than 5 seconds, then just use that.
|
* If the configured interval is less than 5 seconds, then just use that.
|
||||||
*/
|
*/
|
||||||
|
@ -695,6 +710,10 @@ static void autorp_send_discovery_off(struct pim_autorp *autorp)
|
||||||
if (PIM_DEBUG_AUTORP)
|
if (PIM_DEBUG_AUTORP)
|
||||||
zlog_debug("%s: AutoRP discovery sending disabled", __func__);
|
zlog_debug("%s: AutoRP discovery sending disabled", __func__);
|
||||||
event_cancel(&(autorp->send_discovery_timer));
|
event_cancel(&(autorp->send_discovery_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__);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool autorp_recv_discovery(struct pim_autorp *autorp, uint8_t rpcnt, uint16_t holdtime,
|
static bool autorp_recv_discovery(struct pim_autorp *autorp, uint8_t rpcnt, uint16_t holdtime,
|
||||||
|
@ -949,6 +968,10 @@ static bool pim_autorp_socket_enable(struct pim_autorp *autorp)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
/* Return early if socket is already enabled */
|
||||||
|
if (autorp->sock != -1)
|
||||||
|
return true;
|
||||||
|
|
||||||
frr_with_privs (&pimd_privs) {
|
frr_with_privs (&pimd_privs) {
|
||||||
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
@ -975,6 +998,10 @@ static bool pim_autorp_socket_enable(struct pim_autorp *autorp)
|
||||||
|
|
||||||
static bool pim_autorp_socket_disable(struct pim_autorp *autorp)
|
static bool pim_autorp_socket_disable(struct pim_autorp *autorp)
|
||||||
{
|
{
|
||||||
|
/* Return early if socket is already disabled */
|
||||||
|
if (autorp->sock == -1)
|
||||||
|
return true;
|
||||||
|
|
||||||
if (close(autorp->sock)) {
|
if (close(autorp->sock)) {
|
||||||
zlog_warn("Failure closing autorp socket: fd=%d errno=%d: %s", autorp->sock, errno,
|
zlog_warn("Failure closing autorp socket: fd=%d errno=%d: %s", autorp->sock, errno,
|
||||||
safe_strerror(errno));
|
safe_strerror(errno));
|
||||||
|
@ -1453,6 +1480,12 @@ void pim_autorp_start_discovery(struct pim_instance *pim)
|
||||||
struct interface *ifp;
|
struct interface *ifp;
|
||||||
struct pim_autorp *autorp = pim->autorp;
|
struct pim_autorp *autorp = pim->autorp;
|
||||||
|
|
||||||
|
/* Make sure the socket is open and ready */
|
||||||
|
if (!pim_autorp_socket_enable(autorp)) {
|
||||||
|
zlog_err("%s: AutoRP failed to open socket", __func__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!autorp->do_discovery) {
|
if (!autorp->do_discovery) {
|
||||||
autorp->do_discovery = true;
|
autorp->do_discovery = true;
|
||||||
autorp_read_on(autorp);
|
autorp_read_on(autorp);
|
||||||
|
@ -1482,6 +1515,10 @@ void pim_autorp_stop_discovery(struct pim_instance *pim)
|
||||||
if (PIM_DEBUG_AUTORP)
|
if (PIM_DEBUG_AUTORP)
|
||||||
zlog_debug("%s: AutoRP Discovery stopped", __func__);
|
zlog_debug("%s: AutoRP Discovery stopped", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pim_autorp_init(struct pim_instance *pim)
|
void pim_autorp_init(struct pim_instance *pim)
|
||||||
|
@ -1510,12 +1547,6 @@ void pim_autorp_init(struct pim_instance *pim)
|
||||||
|
|
||||||
pim->autorp = autorp;
|
pim->autorp = autorp;
|
||||||
|
|
||||||
if (!pim_autorp_socket_enable(autorp)) {
|
|
||||||
zlog_warn("%s: AutoRP failed to initialize, feature will not work correctly",
|
|
||||||
__func__);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PIM_DEBUG_AUTORP)
|
if (PIM_DEBUG_AUTORP)
|
||||||
zlog_debug("%s: AutoRP Initialized", __func__);
|
zlog_debug("%s: AutoRP Initialized", __func__);
|
||||||
|
|
||||||
|
|
|
@ -608,26 +608,14 @@ int pim_process_no_rp_plist_cmd(struct vty *vty, const char *rp_str,
|
||||||
|
|
||||||
int pim_process_autorp_cmd(struct vty *vty)
|
int pim_process_autorp_cmd(struct vty *vty)
|
||||||
{
|
{
|
||||||
char xpath[XPATH_MAXLEN];
|
nb_cli_enqueue_change(vty, "./discovery-enabled", NB_OP_MODIFY, "true");
|
||||||
|
return nb_cli_apply_changes(vty, "%s", FRR_PIM_AUTORP_XPATH);
|
||||||
snprintf(xpath, sizeof(xpath), "%s/%s", FRR_PIM_AUTORP_XPATH,
|
|
||||||
"discovery-enabled");
|
|
||||||
|
|
||||||
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, "true");
|
|
||||||
|
|
||||||
return nb_cli_apply_changes(vty, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int pim_process_no_autorp_cmd(struct vty *vty)
|
int pim_process_no_autorp_cmd(struct vty *vty)
|
||||||
{
|
{
|
||||||
char xpath[XPATH_MAXLEN];
|
nb_cli_enqueue_change(vty, "./discovery-enabled", NB_OP_MODIFY, "false");
|
||||||
|
return nb_cli_apply_changes(vty, "%s", FRR_PIM_AUTORP_XPATH);
|
||||||
snprintf(xpath, sizeof(xpath), "%s/%s", FRR_PIM_AUTORP_XPATH,
|
|
||||||
"discovery-enabled");
|
|
||||||
|
|
||||||
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
|
|
||||||
|
|
||||||
return nb_cli_apply_changes(vty, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int pim_process_autorp_candidate_rp_cmd(struct vty *vty, bool no, const char *rpaddr_str,
|
int pim_process_autorp_candidate_rp_cmd(struct vty *vty, bool no, const char *rpaddr_str,
|
||||||
|
|
Loading…
Reference in a new issue