summaryrefslogtreecommitdiff
path: root/ospfd/ospfd.c
diff options
context:
space:
mode:
Diffstat (limited to 'ospfd/ospfd.c')
-rw-r--r--ospfd/ospfd.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index 86a3293d71..79af4a55fb 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -308,12 +308,6 @@ static struct ospf *ospf_new(u_short instance, const char *name)
new->lsa_refresh_interval, &new->t_lsa_refresher);
new->lsa_refresher_started = monotime(NULL);
- if ((ospf_sock_init(new)) < 0) {
- zlog_err(
- "ospf_new: fatal error: ospf_sock_init was unable to open "
- "a socket");
- exit(1);
- }
if ((new->ibuf = stream_new(OSPF_MAX_PACKET_SIZE + 1)) == NULL) {
zlog_err(
"ospf_new: fatal error: stream_new(%u) failed allocating ibuf",
@@ -321,7 +315,6 @@ static struct ospf *ospf_new(u_short instance, const char *name)
exit(1);
}
new->t_read = NULL;
- thread_add_read(master, ospf_read, new, new->fd, &new->t_read);
new->oi_write_q = list_new();
new->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT;
@@ -332,6 +325,16 @@ static struct ospf *ospf_new(u_short instance, const char *name)
QOBJ_REG(new, ospf);
+ new->fd = -1;
+ if ((ospf_sock_init(new)) < 0) {
+ if (new->vrf_id != VRF_UNKNOWN)
+ zlog_warn(
+ "%s: ospf_sock_init is unable to open a socket",
+ __func__);
+ return new;
+ }
+ thread_add_read(master, ospf_read, new, new->fd, &new->t_read);
+
return new;
}
@@ -2049,7 +2052,8 @@ static int ospf_vrf_delete(struct vrf *vrf)
static int ospf_vrf_enable(struct vrf *vrf)
{
struct ospf *ospf = NULL;
- vrf_id_t old_vrf_id = VRF_DEFAULT;
+ vrf_id_t old_vrf_id;
+ int ret = 0;
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: VRF %s id %u enabled",
@@ -2070,13 +2074,15 @@ static int ospf_vrf_enable(struct vrf *vrf)
zlog_err("ospf_sock_init: could not raise privs, %s",
safe_strerror(errno));
}
- if (ospf_bind_vrfdevice(ospf, ospf->fd) < 0)
- return 0;
+ ret = ospf_sock_init(ospf);
if (ospfd_privs.change(ZPRIVS_LOWER)) {
zlog_err("ospf_sock_init: could not lower privs, %s",
safe_strerror(errno));
}
-
+ if (ret < 0 || ospf->fd <= 0)
+ return 0;
+ thread_add_read(master, ospf_read, ospf,
+ ospf->fd, &ospf->t_read);
ospf->oi_running = 1;
ospf_zebra_vrf_register(ospf);
ospf_router_id_update(ospf);
@@ -2111,6 +2117,9 @@ static int ospf_vrf_disable(struct vrf *vrf)
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: ospf old_vrf_id %d unlinked",
__PRETTY_FUNCTION__, old_vrf_id);
+ thread_cancel(ospf->t_read);
+ close(ospf->fd);
+ ospf->fd = -1;
}
/* Note: This is a callback, the VRF will be deleted by the caller. */