]> git.proxmox.com Git - mirror_frr.git/blobdiff - ldpd/ldpe.c
eigrpd: eigrp usage of uint32_t to struct in_addr for router_id data
[mirror_frr.git] / ldpd / ldpe.c
index ce2441ca2f26001086b18ad3410dfcbe20185f71..c16d92f28b9821365f82591086ecce616e0cd19b 100644 (file)
@@ -109,7 +109,7 @@ ldpe(void)
        ldpd_process = PROC_LDP_ENGINE;
        log_procname = log_procnames[ldpd_process];
 
-       master = thread_master_create();
+       master = thread_master_create(NULL);
 
        /* setup signal handler */
        signal_init(master, array_size(ldpe_signals), ldpe_signals);
@@ -139,9 +139,20 @@ ldpe(void)
 void
 ldpe_init(struct ldpd_init *init)
 {
+#ifdef __OpenBSD__
+       /* This socket must be open before dropping privileges. */
+       global.pfkeysock = pfkey_init();
+       if (sysdep.no_pfkey == 0) {
+               pfkey_ev = NULL;
+               thread_add_read(master, ldpe_dispatch_pfkey, NULL, global.pfkeysock,
+                               &pfkey_ev);
+       }
+#endif
+
        /* drop privileges */
        ldpe_privs.user = init->user;
        ldpe_privs.group = init->group;
+       zprivs_preinit(&ldpe_privs);
        zprivs_init(&ldpe_privs);
 
        /* listen on ldpd control socket */
@@ -151,26 +162,13 @@ ldpe_init(struct ldpd_init *init)
        TAILQ_INIT(&ctl_conns);
        control_listen();
 
-#ifdef HAVE_PLEDGE
-       if (pledge("stdio cpath inet mcast recvfd", NULL) == -1)
-               fatal("pledge");
-#endif
-
        LIST_INIT(&global.addr_list);
-       RB_INIT(&global.adj_tree);
+       RB_INIT(global_adj_head, &global.adj_tree);
        TAILQ_INIT(&global.pending_conns);
        if (inet_pton(AF_INET, AllRouters_v4, &global.mcast_addr_v4) != 1)
                fatal("inet_pton");
        if (inet_pton(AF_INET6, AllRouters_v6, &global.mcast_addr_v6) != 1)
                fatal("inet_pton");
-#ifdef __OpenBSD__
-       global.pfkeysock = pfkey_init();
-       if (sysdep.no_pfkey == 0) {
-               pfkey_ev = NULL;
-               thread_add_read(master, ldpe_dispatch_pfkey, NULL, global.pfkeysock,
-                               &pfkey_ev);
-       }
-#endif
 
        /* mark sockets as closed */
        global.ipv4.ldp_disc_socket = -1;
@@ -194,15 +192,16 @@ ldpe_shutdown(void)
 
        /* close pipes */
        if (iev_lde) {
-               msgbuf_write(&iev_lde->ibuf.w);
                msgbuf_clear(&iev_lde->ibuf.w);
                close(iev_lde->ibuf.fd);
+               iev_lde->ibuf.fd = -1;
        }
-       msgbuf_write(&iev_main->ibuf.w);
        msgbuf_clear(&iev_main->ibuf.w);
        close(iev_main->ibuf.fd);
+       iev_main->ibuf.fd = -1;
        msgbuf_clear(&iev_main_sync->ibuf.w);
        close(iev_main_sync->ibuf.fd);
+       iev_main_sync->ibuf.fd = -1;
 
        control_cleanup(ctl_sock_path);
        config_clear(leconf);
@@ -219,10 +218,14 @@ ldpe_shutdown(void)
        /* remove addresses from global list */
        while ((if_addr = LIST_FIRST(&global.addr_list)) != NULL) {
                LIST_REMOVE(if_addr, entry);
+               assert(if_addr != LIST_FIRST(&global.addr_list));
                free(if_addr);
        }
-       while ((adj = RB_ROOT(&global.adj_tree)) != NULL)
+       while (!RB_EMPTY(global_adj_head, &global.adj_tree)) {
+               adj = RB_ROOT(global_adj_head, &global.adj_tree);
+
                adj_del(adj, S_SHUTDOWN);
+       }
 
        /* clean up */
        if (iev_lde)
@@ -239,12 +242,16 @@ ldpe_shutdown(void)
 int
 ldpe_imsg_compose_parent(int type, pid_t pid, void *data, uint16_t datalen)
 {
+       if (iev_main->ibuf.fd == -1)
+               return (0);
        return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen));
 }
 
 void
 ldpe_imsg_compose_parent_sync(int type, pid_t pid, void *data, uint16_t datalen)
 {
+       if (iev_main_sync->ibuf.fd == -1)
+               return;
        imsg_compose_event(iev_main_sync, type, 0, pid, -1, data, datalen);
        imsg_flush(&iev_main_sync->ibuf);
 }
@@ -253,6 +260,8 @@ int
 ldpe_imsg_compose_lde(int type, uint32_t peerid, pid_t pid, void *data,
     uint16_t datalen)
 {
+       if (iev_lde->ibuf.fd == -1)
+               return (0);
        return (imsg_compose_event(iev_lde, type, peerid, pid, -1,
            data, datalen));
 }
@@ -269,7 +278,7 @@ ldpe_dispatch_main(struct thread *thread)
        struct l2vpn_if         *lif, *nlif;
        struct l2vpn_pw         *pw, *npw;
        struct imsg              imsg;
-       int                      fd = THREAD_FD(thread);
+       int                      fd;
        struct imsgev           *iev = THREAD_ARG(thread);
        struct imsgbuf          *ibuf = &iev->ibuf;
        struct iface            *iface = NULL;
@@ -461,10 +470,10 @@ ldpe_dispatch_main(struct thread *thread)
                                fatal(NULL);
                        memcpy(nconf, imsg.data, sizeof(struct ldpd_conf));
 
-                       RB_INIT(&nconf->iface_tree);
-                       RB_INIT(&nconf->tnbr_tree);
-                       RB_INIT(&nconf->nbrp_tree);
-                       RB_INIT(&nconf->l2vpn_tree);
+                       RB_INIT(iface_head, &nconf->iface_tree);
+                       RB_INIT(tnbr_head, &nconf->tnbr_tree);
+                       RB_INIT(nbrp_head, &nconf->nbrp_tree);
+                       RB_INIT(l2vpn_head, &nconf->l2vpn_tree);
                        break;
                case IMSG_RECONF_IFACE:
                        if ((niface = malloc(sizeof(struct iface))) == NULL)
@@ -492,9 +501,9 @@ ldpe_dispatch_main(struct thread *thread)
                                fatal(NULL);
                        memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn));
 
-                       RB_INIT(&nl2vpn->if_tree);
-                       RB_INIT(&nl2vpn->pw_tree);
-                       RB_INIT(&nl2vpn->pw_inactive_tree);
+                       RB_INIT(l2vpn_if_head, &nl2vpn->if_tree);
+                       RB_INIT(l2vpn_pw_head, &nl2vpn->pw_tree);
+                       RB_INIT(l2vpn_pw_head, &nl2vpn->pw_inactive_tree);
 
                        RB_INSERT(l2vpn_head, &nconf->l2vpn_tree, nl2vpn);
                        break;
@@ -881,8 +890,8 @@ ldpe_adj_detail_ctl(struct ctl_conn *c)
                        continue;
 
                strlcpy(ictl.name, iface->name, sizeof(ictl.name));
-               if (RB_EMPTY(&iface->ipv4.adj_tree) &&
-                   RB_EMPTY(&iface->ipv6.adj_tree))
+               if (RB_EMPTY(ia_adj_head, &iface->ipv4.adj_tree) &&
+                   RB_EMPTY(ia_adj_head, &iface->ipv6.adj_tree))
                        ictl.no_adj = 1;
                imsg_compose_event(&c->iev, IMSG_CTL_SHOW_DISC_IFACE, 0, 0,
                    -1, &ictl, sizeof(ictl));
@@ -968,6 +977,7 @@ mapping_list_clr(struct mapping_head *mh)
 
        while ((me = TAILQ_FIRST(mh)) != NULL) {
                TAILQ_REMOVE(mh, me, entry);
+               assert(me != TAILQ_FIRST(mh));
                free(me);
        }
 }