Internalize a few more things into the control code. Both control_state
authorclaudio <claudio@openbsd.org>
Tue, 19 Jan 2021 09:33:38 +0000 (09:33 +0000)
committerclaudio <claudio@openbsd.org>
Tue, 19 Jan 2021 09:33:38 +0000 (09:33 +0000)
and ctl_conns are not really needed outside of control.c

usr.sbin/ospfd/control.c
usr.sbin/ospfd/control.h
usr.sbin/ospfd/ospfe.c
usr.sbin/ospfd/ospfe.h

index b9824b5..c46e838 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: control.c,v 1.46 2020/09/16 20:50:10 remi Exp $ */
+/*     $OpenBSD: control.c,v 1.47 2021/01/19 09:33:38 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
 #include "log.h"
 #include "control.h"
 
+TAILQ_HEAD(ctl_conns, ctl_conn)        ctl_conns = TAILQ_HEAD_INITIALIZER(ctl_conns);
+
 #define        CONTROL_BACKLOG 5
 
 struct ctl_conn        *control_connbyfd(int);
 struct ctl_conn        *control_connbypid(pid_t);
 void            control_close(int);
 
+struct {
+       struct event    ev;
+       struct event    evt;
+       int             fd;
+} control_state;
+
 int
 control_check(char *path)
 {
@@ -108,8 +116,9 @@ control_init(char *path)
 }
 
 int
-control_listen(void)
+control_listen(int fd)
 {
+       control_state.fd = fd;
 
        if (listen(control_state.fd, CONTROL_BACKLOG) == -1) {
                log_warn("control_listen: listen");
index 02df299..563a623 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: control.h,v 1.8 2020/09/16 20:50:10 remi Exp $ */
+/*     $OpenBSD: control.h,v 1.9 2021/01/19 09:33:38 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
 #include <sys/time.h>
 #include <event.h>
 
-struct {
-       struct event    ev;
-       struct event    evt;
-       int             fd;
-} control_state;
-
 struct ctl_conn {
        TAILQ_ENTRY(ctl_conn)   entry;
        struct imsgev           iev;
@@ -36,7 +30,7 @@ struct ctl_conn {
 
 int    control_check(char *);
 int    control_init(char *);
-int    control_listen(void);
+int    control_listen(int);
 void   control_accept(int, short, void *);
 void   control_dispatch_imsg(int, short, void *);
 int    control_imsg_relay(struct imsg *);
index 9fca2e0..451899c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ospfe.c,v 1.108 2021/01/19 09:29:49 claudio Exp $ */
+/*     $OpenBSD: ospfe.c,v 1.109 2021/01/19 09:33:38 claudio Exp $ */
 
 /*
  * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -457,10 +457,8 @@ ospfe_dispatch_main(int fd, short event, void *bula)
                        if ((fd = imsg.fd) == -1)
                                fatalx("%s: expected to receive imsg control"
                                    "fd but didn't receive any", __func__);
-                       control_state.fd = fd;
                        /* Listen on control socket. */
-                       TAILQ_INIT(&ctl_conns);
-                       control_listen();
+                       control_listen(fd);
                        if (pledge("stdio inet mcast", NULL) == -1)
                                fatal("pledge");
                        break;
index 0e003eb..9e257e7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ospfe.h,v 1.47 2021/01/19 09:29:49 claudio Exp $ */
+/*     $OpenBSD: ospfe.h,v 1.48 2021/01/19 09:33:38 claudio Exp $ */
 
 /*
  * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@@ -26,8 +26,6 @@
 #include <netinet/in.h>
 #include <netinet/ip.h>
 
-TAILQ_HEAD(ctl_conns, ctl_conn)        ctl_conns;
-
 struct lsa_entry {
        TAILQ_ENTRY(lsa_entry)   entry;
        union {
@@ -95,6 +93,8 @@ struct nbr {
        u_int8_t                 dd_snapshot;   /* snapshot running */
 };
 
+struct ctl_conn;
+
 /* auth.c */
 int             auth_validate(void *buf, u_int16_t len, struct iface *,
                     struct nbr *);