mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-15 01:37:53 +00:00
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>
(cherry picked from commit 5d102a0a70
)
This commit is contained in:
parent
05f9d44340
commit
6b0fe82906
@ -83,6 +83,12 @@ static void pim_autorp_free(struct pim_autorp *autorp)
|
||||
pim_autorp_rp_fini(&(autorp->candidate_rp_list));
|
||||
}
|
||||
|
||||
static bool pim_autorp_should_close(struct pim_autorp *autorp)
|
||||
{
|
||||
/* If discovery is active, then we need the socket open */
|
||||
return !autorp->do_discovery;
|
||||
}
|
||||
|
||||
static bool pim_autorp_join_groups(struct interface *ifp)
|
||||
{
|
||||
struct pim_interface *pim_ifp;
|
||||
@ -490,6 +496,10 @@ static bool pim_autorp_socket_enable(struct pim_autorp *autorp)
|
||||
{
|
||||
int fd;
|
||||
|
||||
/* Return early if socket is already enabled */
|
||||
if (autorp->sock != -1)
|
||||
return true;
|
||||
|
||||
frr_with_privs (&pimd_privs) {
|
||||
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||
if (fd < 0) {
|
||||
@ -516,6 +526,10 @@ static bool pim_autorp_socket_enable(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)) {
|
||||
zlog_warn("Failure closing autorp socket: fd=%d errno=%d: %s",
|
||||
autorp->sock, errno, safe_strerror(errno));
|
||||
@ -967,6 +981,12 @@ 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 */
|
||||
if (!pim_autorp_socket_enable(autorp)) {
|
||||
zlog_err("%s: AutoRP failed to open socket", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!autorp->do_discovery) {
|
||||
autorp->do_discovery = true;
|
||||
autorp_read_on(autorp);
|
||||
@ -996,6 +1016,10 @@ void pim_autorp_stop_discovery(struct pim_instance *pim)
|
||||
if (PIM_DEBUG_AUTORP)
|
||||
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)
|
||||
@ -1016,11 +1040,6 @@ void pim_autorp_init(struct pim_instance *pim)
|
||||
|
||||
pim->autorp = autorp;
|
||||
|
||||
if (!pim_autorp_socket_enable(autorp)) {
|
||||
zlog_err("%s: AutoRP failed to initialize, feature will not work correctly", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PIM_DEBUG_AUTORP)
|
||||
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)
|
||||
{
|
||||
char xpath[XPATH_MAXLEN];
|
||||
|
||||
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);
|
||||
nb_cli_enqueue_change(vty, "./discovery-enabled", NB_OP_MODIFY, "true");
|
||||
return nb_cli_apply_changes(vty, "%s", FRR_PIM_AUTORP_XPATH);
|
||||
}
|
||||
|
||||
int pim_process_no_autorp_cmd(struct vty *vty)
|
||||
{
|
||||
char xpath[XPATH_MAXLEN];
|
||||
|
||||
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);
|
||||
nb_cli_enqueue_change(vty, "./discovery-enabled", NB_OP_MODIFY, "false");
|
||||
return nb_cli_apply_changes(vty, "%s", FRR_PIM_AUTORP_XPATH);
|
||||
}
|
||||
|
||||
int pim_process_autorp_candidate_rp_cmd(struct vty *vty, bool no,
|
||||
|
Loading…
Reference in New Issue
Block a user