summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflorian <florian@openbsd.org>2019-05-14 14:51:31 +0000
committerflorian <florian@openbsd.org>2019-05-14 14:51:31 +0000
commit679647febaa1e2c4054bbc000ecab1ccc030e42e (patch)
treec6ca38ab6e1fee4c0b63efe02751202a951d55dd
parentRevert my recent sysupgrade changes; it broke unattended upgrades for (diff)
downloadwireguard-openbsd-679647febaa1e2c4054bbc000ecab1ccc030e42e.tar.xz
wireguard-openbsd-679647febaa1e2c4054bbc000ecab1ccc030e42e.zip
Move common config passing code into a function.
OK pamela
-rw-r--r--sbin/unwind/captiveportal.c65
-rw-r--r--sbin/unwind/frontend.c65
-rw-r--r--sbin/unwind/resolver.c65
-rw-r--r--sbin/unwind/unwind.c88
-rw-r--r--sbin/unwind/unwind.h3
5 files changed, 95 insertions, 191 deletions
diff --git a/sbin/unwind/captiveportal.c b/sbin/unwind/captiveportal.c
index bacc49877ea..0c7b0c1f207 100644
--- a/sbin/unwind/captiveportal.c
+++ b/sbin/unwind/captiveportal.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: captiveportal.c,v 1.11 2019/05/10 14:10:38 florian Exp $ */
+/* $OpenBSD: captiveportal.c,v 1.12 2019/05/14 14:51:31 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -218,7 +218,6 @@ void
captiveportal_dispatch_main(int fd, short event, void *bula)
{
static struct uw_conf *nconf;
- struct uw_forwarder *uw_forwarder;
struct imsg imsg;
struct imsgev *iev = bula;
struct imsgbuf *ibuf = &iev->ibuf;
@@ -306,73 +305,13 @@ captiveportal_dispatch_main(int fd, short event, void *bula)
event_add(&iev_frontend->ev, NULL);
break;
case IMSG_RECONF_CONF:
- if (nconf != NULL)
- fatalx("%s: IMSG_RECONF_CONF already in "
- "progress", __func__);
- if (IMSG_DATA_SIZE(imsg) != sizeof(struct uw_conf))
- fatalx("%s: IMSG_RECONF_CONF wrong length: %lu",
- __func__, IMSG_DATA_SIZE(imsg));
- if ((nconf = malloc(sizeof(struct uw_conf))) == NULL)
- fatal(NULL);
- memcpy(nconf, imsg.data, sizeof(struct uw_conf));
- nconf->captive_portal_host = NULL;
- nconf->captive_portal_path = NULL;
- nconf->captive_portal_expected_response = NULL;
- SIMPLEQ_INIT(&nconf->uw_forwarder_list);
- SIMPLEQ_INIT(&nconf->uw_dot_forwarder_list);
- break;
case IMSG_RECONF_CAPTIVE_PORTAL_HOST:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- if ((nconf->captive_portal_host = strdup(imsg.data)) ==
- NULL)
- fatal("%s: strdup", __func__);
- break;
case IMSG_RECONF_CAPTIVE_PORTAL_PATH:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- if ((nconf->captive_portal_path = strdup(imsg.data)) ==
- NULL)
- fatal("%s: strdup", __func__);
- break;
case IMSG_RECONF_CAPTIVE_PORTAL_EXPECTED_RESPONSE:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- if ((nconf->captive_portal_expected_response =
- strdup(imsg.data)) == NULL)
- fatal("%s: strdup", __func__);
- break;
case IMSG_RECONF_BLOCKLIST_FILE:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- if ((nconf->blocklist_file = strdup(imsg.data)) ==
- NULL)
- fatal("%s: strdup", __func__);
- break;
case IMSG_RECONF_FORWARDER:
- if (IMSG_DATA_SIZE(imsg) != sizeof(struct uw_forwarder))
- fatalx("%s: IMSG_RECONF_FORWARDER wrong length:"
- " %lu", __func__, IMSG_DATA_SIZE(imsg));
- if ((uw_forwarder = malloc(sizeof(struct
- uw_forwarder))) == NULL)
- fatal(NULL);
- memcpy(uw_forwarder, imsg.data, sizeof(struct
- uw_forwarder));
- SIMPLEQ_INSERT_TAIL(&nconf->uw_forwarder_list,
- uw_forwarder, entry);
- break;
case IMSG_RECONF_DOT_FORWARDER:
- if (IMSG_DATA_SIZE(imsg) != sizeof(struct uw_forwarder))
- fatalx("%s: IMSG_RECONF_DOT_FORWARDER wrong "
- "length: %lu", __func__,
- IMSG_DATA_SIZE(imsg));
- if ((uw_forwarder = malloc(sizeof(struct
- uw_forwarder))) == NULL)
- fatal(NULL);
- memcpy(uw_forwarder, imsg.data, sizeof(struct
- uw_forwarder));
- SIMPLEQ_INSERT_TAIL(&nconf->uw_dot_forwarder_list,
- uw_forwarder, entry);
+ imsg_receive_config(&imsg, &nconf);
break;
case IMSG_RECONF_END:
if (nconf == NULL)
diff --git a/sbin/unwind/frontend.c b/sbin/unwind/frontend.c
index 36ef983a6a8..fffb6fa3859 100644
--- a/sbin/unwind/frontend.c
+++ b/sbin/unwind/frontend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: frontend.c,v 1.20 2019/05/10 14:10:38 florian Exp $ */
+/* $OpenBSD: frontend.c,v 1.21 2019/05/14 14:51:31 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -275,7 +275,6 @@ void
frontend_dispatch_main(int fd, short event, void *bula)
{
static struct uw_conf *nconf;
- struct uw_forwarder *uw_forwarder;
struct imsg imsg;
struct imsgev *iev = bula;
struct imsgbuf *ibuf = &iev->ibuf;
@@ -364,73 +363,13 @@ frontend_dispatch_main(int fd, short event, void *bula)
event_add(&iev_captiveportal->ev, NULL);
break;
case IMSG_RECONF_CONF:
- if (nconf != NULL)
- fatalx("%s: IMSG_RECONF_CONF already in "
- "progress", __func__);
- if (IMSG_DATA_SIZE(imsg) != sizeof(struct uw_conf))
- fatalx("%s: IMSG_RECONF_CONF wrong length: %lu",
- __func__, IMSG_DATA_SIZE(imsg));
- if ((nconf = malloc(sizeof(struct uw_conf))) == NULL)
- fatal(NULL);
- memcpy(nconf, imsg.data, sizeof(struct uw_conf));
- nconf->captive_portal_host = NULL;
- nconf->captive_portal_path = NULL;
- nconf->captive_portal_expected_response = NULL;
- SIMPLEQ_INIT(&nconf->uw_forwarder_list);
- SIMPLEQ_INIT(&nconf->uw_dot_forwarder_list);
- break;
case IMSG_RECONF_CAPTIVE_PORTAL_HOST:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- if ((nconf->captive_portal_host = strdup(imsg.data)) ==
- NULL)
- fatal("%s: strdup", __func__);
- break;
case IMSG_RECONF_CAPTIVE_PORTAL_PATH:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- if ((nconf->captive_portal_path = strdup(imsg.data)) ==
- NULL)
- fatal("%s: strdup", __func__);
- break;
case IMSG_RECONF_CAPTIVE_PORTAL_EXPECTED_RESPONSE:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- if ((nconf->captive_portal_expected_response =
- strdup(imsg.data)) == NULL)
- fatal("%s: strdup", __func__);
- break;
case IMSG_RECONF_BLOCKLIST_FILE:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- if ((nconf->blocklist_file = strdup(imsg.data)) ==
- NULL)
- fatal("%s: strdup", __func__);
- break;
case IMSG_RECONF_FORWARDER:
- if (IMSG_DATA_SIZE(imsg) != sizeof(struct uw_forwarder))
- fatalx("%s: IMSG_RECONF_FORWARDER wrong length:"
- " %lu", __func__, IMSG_DATA_SIZE(imsg));
- if ((uw_forwarder = malloc(sizeof(struct
- uw_forwarder))) == NULL)
- fatal(NULL);
- memcpy(uw_forwarder, imsg.data, sizeof(struct
- uw_forwarder));
- SIMPLEQ_INSERT_TAIL(&nconf->uw_forwarder_list,
- uw_forwarder, entry);
- break;
case IMSG_RECONF_DOT_FORWARDER:
- if (IMSG_DATA_SIZE(imsg) != sizeof(struct uw_forwarder))
- fatalx("%s: IMSG_RECONF_DOT_FORWARDER wrong "
- "length: %lu", __func__,
- IMSG_DATA_SIZE(imsg));
- if ((uw_forwarder = malloc(sizeof(struct
- uw_forwarder))) == NULL)
- fatal(NULL);
- memcpy(uw_forwarder, imsg.data, sizeof(struct
- uw_forwarder));
- SIMPLEQ_INSERT_TAIL(&nconf->uw_dot_forwarder_list,
- uw_forwarder, entry);
+ imsg_receive_config(&imsg, &nconf);
break;
case IMSG_RECONF_END:
if (nconf == NULL)
diff --git a/sbin/unwind/resolver.c b/sbin/unwind/resolver.c
index 92c781c971b..24bf7e8ef23 100644
--- a/sbin/unwind/resolver.c
+++ b/sbin/unwind/resolver.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: resolver.c,v 1.39 2019/05/10 14:10:38 florian Exp $ */
+/* $OpenBSD: resolver.c,v 1.40 2019/05/14 14:51:31 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -485,7 +485,6 @@ void
resolver_dispatch_main(int fd, short event, void *bula)
{
static struct uw_conf *nconf;
- struct uw_forwarder *uw_forwarder;
struct imsg imsg;
struct imsgev *iev = bula;
struct imsgbuf *ibuf;
@@ -575,73 +574,13 @@ resolver_dispatch_main(int fd, short event, void *bula)
fatal("pledge");
break;
case IMSG_RECONF_CONF:
- if (nconf != NULL)
- fatalx("%s: IMSG_RECONF_CONF already in "
- "progress", __func__);
- if (IMSG_DATA_SIZE(imsg) != sizeof(struct uw_conf))
- fatalx("%s: IMSG_RECONF_CONF wrong length: %lu",
- __func__, IMSG_DATA_SIZE(imsg));
- if ((nconf = malloc(sizeof(struct uw_conf))) == NULL)
- fatal(NULL);
- memcpy(nconf, imsg.data, sizeof(struct uw_conf));
- nconf->captive_portal_host = NULL;
- nconf->captive_portal_path = NULL;
- nconf->captive_portal_expected_response = NULL;
- SIMPLEQ_INIT(&nconf->uw_forwarder_list);
- SIMPLEQ_INIT(&nconf->uw_dot_forwarder_list);
- break;
case IMSG_RECONF_CAPTIVE_PORTAL_HOST:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- if ((nconf->captive_portal_host = strdup(imsg.data)) ==
- NULL)
- fatal("%s: strdup", __func__);
- break;
case IMSG_RECONF_CAPTIVE_PORTAL_PATH:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- if ((nconf->captive_portal_path = strdup(imsg.data)) ==
- NULL)
- fatal("%s: strdup", __func__);
- break;
case IMSG_RECONF_CAPTIVE_PORTAL_EXPECTED_RESPONSE:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- if ((nconf->captive_portal_expected_response =
- strdup(imsg.data)) == NULL)
- fatal("%s: strdup", __func__);
- break;
case IMSG_RECONF_BLOCKLIST_FILE:
- /* make sure this is a string */
- ((char *)imsg.data)[IMSG_DATA_SIZE(imsg) - 1] = '\0';
- if ((nconf->blocklist_file = strdup(imsg.data)) ==
- NULL)
- fatal("%s: strdup", __func__);
- break;
case IMSG_RECONF_FORWARDER:
- if (IMSG_DATA_SIZE(imsg) != sizeof(struct uw_forwarder))
- fatalx("%s: IMSG_RECONF_FORWARDER wrong length:"
- " %lu", __func__, IMSG_DATA_SIZE(imsg));
- if ((uw_forwarder = malloc(sizeof(struct
- uw_forwarder))) == NULL)
- fatal(NULL);
- memcpy(uw_forwarder, imsg.data, sizeof(struct
- uw_forwarder));
- SIMPLEQ_INSERT_TAIL(&nconf->uw_forwarder_list,
- uw_forwarder, entry);
- break;
case IMSG_RECONF_DOT_FORWARDER:
- if (IMSG_DATA_SIZE(imsg) != sizeof(struct uw_forwarder))
- fatalx("%s: IMSG_RECONF_DOT_FORWARDER wrong "
- "length: %lu", __func__,
- IMSG_DATA_SIZE(imsg));
- if ((uw_forwarder = malloc(sizeof(struct
- uw_forwarder))) == NULL)
- fatal(NULL);
- memcpy(uw_forwarder, imsg.data, sizeof(struct
- uw_forwarder));
- SIMPLEQ_INSERT_TAIL(&nconf->uw_dot_forwarder_list,
- uw_forwarder, entry);
+ imsg_receive_config(&imsg, &nconf);
break;
case IMSG_RECONF_END:
if (nconf == NULL)
diff --git a/sbin/unwind/unwind.c b/sbin/unwind/unwind.c
index c6670d82696..6d381d99961 100644
--- a/sbin/unwind/unwind.c
+++ b/sbin/unwind/unwind.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: unwind.c,v 1.27 2019/05/13 23:13:24 florian Exp $ */
+/* $OpenBSD: unwind.c,v 1.28 2019/05/14 14:51:31 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -1022,3 +1022,89 @@ send_blocklist_fd(void)
else
log_warn("%s", main_conf->blocklist_file);
}
+
+void
+imsg_receive_config(struct imsg *imsg, struct uw_conf **xconf)
+{
+ struct uw_conf *nconf;
+ struct uw_forwarder *uw_forwarder;
+
+ nconf = *xconf;
+
+ switch (imsg->hdr.type) {
+ case IMSG_RECONF_CONF:
+ if (nconf != NULL)
+ fatalx("%s: IMSG_RECONF_CONF already in "
+ "progress", __func__);
+ if (IMSG_DATA_SIZE(*imsg) != sizeof(struct uw_conf))
+ fatalx("%s: IMSG_RECONF_CONF wrong length: %lu",
+ __func__, IMSG_DATA_SIZE(*imsg));
+ if ((*xconf = malloc(sizeof(struct uw_conf))) == NULL)
+ fatal(NULL);
+ nconf = *xconf;
+ memcpy(nconf, imsg->data, sizeof(struct uw_conf));
+ nconf->captive_portal_host = NULL;
+ nconf->captive_portal_path = NULL;
+ nconf->captive_portal_expected_response = NULL;
+ SIMPLEQ_INIT(&nconf->uw_forwarder_list);
+ SIMPLEQ_INIT(&nconf->uw_dot_forwarder_list);
+ break;
+ case IMSG_RECONF_CAPTIVE_PORTAL_HOST:
+ /* make sure this is a string */
+ ((char *)imsg->data)[IMSG_DATA_SIZE(*imsg) - 1] = '\0';
+ if ((nconf->captive_portal_host = strdup(imsg->data)) ==
+ NULL)
+ fatal("%s: strdup", __func__);
+ break;
+ case IMSG_RECONF_CAPTIVE_PORTAL_PATH:
+ /* make sure this is a string */
+ ((char *)imsg->data)[IMSG_DATA_SIZE(*imsg) - 1] = '\0';
+ if ((nconf->captive_portal_path = strdup(imsg->data)) ==
+ NULL)
+ fatal("%s: strdup", __func__);
+ break;
+ case IMSG_RECONF_CAPTIVE_PORTAL_EXPECTED_RESPONSE:
+ /* make sure this is a string */
+ ((char *)imsg->data)[IMSG_DATA_SIZE(*imsg) - 1] = '\0';
+ if ((nconf->captive_portal_expected_response =
+ strdup(imsg->data)) == NULL)
+ fatal("%s: strdup", __func__);
+ break;
+ case IMSG_RECONF_BLOCKLIST_FILE:
+ /* make sure this is a string */
+ ((char *)imsg->data)[IMSG_DATA_SIZE(*imsg) - 1] = '\0';
+ if ((nconf->blocklist_file = strdup(imsg->data)) ==
+ NULL)
+ fatal("%s: strdup", __func__);
+ break;
+ case IMSG_RECONF_FORWARDER:
+ if (IMSG_DATA_SIZE(*imsg) != sizeof(struct uw_forwarder))
+ fatalx("%s: IMSG_RECONF_FORWARDER wrong length:"
+ " %lu", __func__, IMSG_DATA_SIZE(*imsg));
+ if ((uw_forwarder = malloc(sizeof(struct
+ uw_forwarder))) == NULL)
+ fatal(NULL);
+ memcpy(uw_forwarder, imsg->data, sizeof(struct
+ uw_forwarder));
+ SIMPLEQ_INSERT_TAIL(&nconf->uw_forwarder_list,
+ uw_forwarder, entry);
+ break;
+ case IMSG_RECONF_DOT_FORWARDER:
+ if (IMSG_DATA_SIZE(*imsg) != sizeof(struct uw_forwarder))
+ fatalx("%s: IMSG_RECONF_DOT_FORWARDER wrong "
+ "length: %lu", __func__,
+ IMSG_DATA_SIZE(*imsg));
+ if ((uw_forwarder = malloc(sizeof(struct
+ uw_forwarder))) == NULL)
+ fatal(NULL);
+ memcpy(uw_forwarder, imsg->data, sizeof(struct
+ uw_forwarder));
+ SIMPLEQ_INSERT_TAIL(&nconf->uw_dot_forwarder_list,
+ uw_forwarder, entry);
+ break;
+ default:
+ log_debug("%s: error handling imsg %d", __func__,
+ imsg->hdr.type);
+ break;
+ }
+}
diff --git a/sbin/unwind/unwind.h b/sbin/unwind/unwind.h
index 1206260e512..f3100343b4a 100644
--- a/sbin/unwind/unwind.h
+++ b/sbin/unwind/unwind.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: unwind.h,v 1.16 2019/05/13 23:13:24 florian Exp $ */
+/* $OpenBSD: unwind.h,v 1.17 2019/05/14 14:51:31 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -167,6 +167,7 @@ void merge_config(struct uw_conf *, struct uw_conf *);
void imsg_event_add(struct imsgev *);
int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t,
int, void *, uint16_t);
+void imsg_receive_config(struct imsg *, struct uw_conf **);
struct uw_conf *config_new_empty(void);
void config_clear(struct uw_conf *);