summaryrefslogtreecommitdiff
path: root/sbin/iked
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2015-12-07 12:46:38 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2015-12-07 12:46:38 +0000
commit970d2fcc9bb0f23ed4b330ca072618cb9eddce1f (patch)
treedc4b8e3344617b6febf80f083c9dd3102fe815d6 /sbin/iked
parent3b9a00405deae9c53af3c0fcc4d318aac491e97f (diff)
Sync proc.c, use shorter proc_compose[v]()
Diffstat (limited to 'sbin/iked')
-rw-r--r--sbin/iked/ca.c21
-rw-r--r--sbin/iked/config.c26
-rw-r--r--sbin/iked/iked.c5
-rw-r--r--sbin/iked/iked.h10
-rw-r--r--sbin/iked/ocsp.c12
-rw-r--r--sbin/iked/proc.c34
6 files changed, 55 insertions, 53 deletions
diff --git a/sbin/iked/ca.c b/sbin/iked/ca.c
index a03402a26d8..1e98ddb9af8 100644
--- a/sbin/iked/ca.c
+++ b/sbin/iked/ca.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ca.c,v 1.39 2015/10/22 15:55:18 reyk Exp $ */
+/* $OpenBSD: ca.c,v 1.40 2015/12/07 12:46:37 reyk Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -249,8 +249,7 @@ ca_setcert(struct iked *env, struct iked_sahdr *sh, struct iked_id *id,
iov[iovcnt].iov_len = len;
iovcnt++;
- if (proc_composev_imsg(&env->sc_ps, procid, -1,
- IMSG_CERT, -1, iov, iovcnt) == -1)
+ if (proc_composev(&env->sc_ps, procid, IMSG_CERT, iov, iovcnt) == -1)
return (-1);
return (0);
}
@@ -291,8 +290,7 @@ ca_setreq(struct iked *env, struct iked_sa *sa,
iov[iovcnt].iov_len = len;
iovcnt++;
- if (proc_composev_imsg(&env->sc_ps, procid, -1,
- IMSG_CERTREQ, -1, iov, iovcnt) == -1)
+ if (proc_composev(&env->sc_ps, procid, IMSG_CERTREQ, iov, iovcnt) == -1)
goto done;
sa_stateflags(sa, IKED_REQ_CERTREQ);
@@ -336,8 +334,7 @@ ca_setauth(struct iked *env, struct iked_sa *sa,
log_debug("%s: auth length %zu", __func__, ibuf_size(authmsg));
}
- if (proc_composev_imsg(&env->sc_ps, id, -1,
- IMSG_AUTH, -1, iov, iovcnt) == -1)
+ if (proc_composev(&env->sc_ps, id, IMSG_AUTH, iov, iovcnt) == -1)
return (-1);
return (0);
}
@@ -397,8 +394,7 @@ ca_getcert(struct iked *env, struct imsg *imsg)
iov[1].iov_base = &type;
iov[1].iov_len = sizeof(type);
- if (proc_composev_imsg(&env->sc_ps, PROC_IKEV2, -1,
- cmd, -1, iov, iovcnt) == -1)
+ if (proc_composev(&env->sc_ps, PROC_IKEV2, cmd, iov, iovcnt) == -1)
return (-1);
return (0);
}
@@ -644,8 +640,8 @@ ca_reload(struct iked *env)
ibuf_length(env->sc_certreq) == SHA_DIGEST_LENGTH ?
"" : "s");
- (void)proc_composev_imsg(&env->sc_ps, PROC_IKEV2, -1,
- IMSG_CERTREQ, -1, iov, iovcnt);
+ (void)proc_composev(&env->sc_ps, PROC_IKEV2, IMSG_CERTREQ,
+ iov, iovcnt);
}
/*
@@ -695,8 +691,7 @@ ca_reload(struct iked *env)
iov[0].iov_len = sizeof(env->sc_certreqtype);
if (iovcnt == 0)
iovcnt++;
- (void)proc_composev_imsg(&env->sc_ps, PROC_IKEV2, -1,
- IMSG_CERTREQ, -1, iov, iovcnt);
+ (void)proc_composev(&env->sc_ps, PROC_IKEV2, IMSG_CERTREQ, iov, iovcnt);
return (0);
}
diff --git a/sbin/iked/config.c b/sbin/iked/config.c
index 3ae127de25d..16502585894 100644
--- a/sbin/iked/config.c
+++ b/sbin/iked/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.40 2015/11/18 16:46:30 reyk Exp $ */
+/* $OpenBSD: config.c,v 1.41 2015/12/07 12:46:37 reyk Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -414,7 +414,7 @@ config_setcoupled(struct iked *env, unsigned int couple)
unsigned int type;
type = couple ? IMSG_CTL_COUPLE : IMSG_CTL_DECOUPLE;
- proc_compose_imsg(&env->sc_ps, PROC_IKEV2, -1, type, -1, NULL, 0);
+ proc_compose(&env->sc_ps, PROC_IKEV2, type, NULL, 0);
return (0);
}
@@ -432,7 +432,7 @@ config_setmode(struct iked *env, unsigned int passive)
unsigned int type;
type = passive ? IMSG_CTL_PASSIVE : IMSG_CTL_ACTIVE;
- proc_compose_imsg(&env->sc_ps, PROC_IKEV2, -1, type, -1, NULL, 0);
+ proc_compose(&env->sc_ps, PROC_IKEV2, type, NULL, 0);
return (0);
}
@@ -458,8 +458,7 @@ config_getmode(struct iked *env, unsigned int type)
int
config_setreset(struct iked *env, unsigned int mode, enum privsep_procid id)
{
- proc_compose_imsg(&env->sc_ps, id, -1,
- IMSG_CTL_RESET, -1, &mode, sizeof(mode));
+ proc_compose(&env->sc_ps, id, IMSG_CTL_RESET, &mode, sizeof(mode));
return (0);
}
@@ -515,7 +514,7 @@ config_setsocket(struct iked *env, struct sockaddr_storage *ss,
if ((s = udp_bind((struct sockaddr *)ss, port)) == -1)
return (-1);
proc_compose_imsg(&env->sc_ps, id, -1,
- IMSG_UDP_SOCKET, s, ss, sizeof(*ss));
+ IMSG_UDP_SOCKET, -1, s, ss, sizeof(*ss));
return (0);
}
@@ -571,7 +570,7 @@ config_setpfkey(struct iked *env, enum privsep_procid id)
if ((s = pfkey_socket()) == -1)
return (-1);
proc_compose_imsg(&env->sc_ps, id, -1,
- IMSG_PFKEY_SOCKET, s, NULL, 0);
+ IMSG_PFKEY_SOCKET, -1, s, NULL, 0);
return (0);
}
@@ -591,8 +590,7 @@ config_setuser(struct iked *env, struct iked_user *usr, enum privsep_procid id)
return (0);
}
- proc_compose_imsg(&env->sc_ps, id, -1,
- IMSG_CFG_USER, -1, usr, sizeof(*usr));
+ proc_compose(&env->sc_ps, id, IMSG_CFG_USER, usr, sizeof(*usr));
return (0);
}
@@ -662,8 +660,7 @@ config_setpolicy(struct iked *env, struct iked_policy *pol,
if (env->sc_opts & IKED_OPT_NOACTION)
return (0);
- if (proc_composev_imsg(&env->sc_ps, id, -1,
- IMSG_CFG_POLICY, -1, iov, iovcnt) == -1)
+ if (proc_composev(&env->sc_ps, id, IMSG_CFG_POLICY, iov, iovcnt) == -1)
return (-1);
return (0);
@@ -741,8 +738,7 @@ config_setcompile(struct iked *env, enum privsep_procid id)
if (env->sc_opts & IKED_OPT_NOACTION)
return (0);
- proc_compose_imsg(&env->sc_ps, id, -1,
- IMSG_COMPILE, -1, NULL, 0);
+ proc_compose(&env->sc_ps, id, IMSG_COMPILE, NULL, 0);
return (0);
}
@@ -764,8 +760,8 @@ config_setocsp(struct iked *env)
{
if (env->sc_opts & IKED_OPT_NOACTION)
return (0);
- proc_compose_imsg(&env->sc_ps, PROC_CERT, -1,
- IMSG_OCSP_URL, -1, env->sc_ocsp_url,
+ proc_compose(&env->sc_ps, PROC_CERT,
+ IMSG_OCSP_URL, env->sc_ocsp_url,
env->sc_ocsp_url ? strlen(env->sc_ocsp_url) : 0);
return (0);
diff --git a/sbin/iked/iked.c b/sbin/iked/iked.c
index 86f6a92138f..11b54ca930d 100644
--- a/sbin/iked/iked.c
+++ b/sbin/iked/iked.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: iked.c,v 1.29 2015/11/22 13:27:13 reyk Exp $ */
+/* $OpenBSD: iked.c,v 1.30 2015/12/07 12:46:37 reyk Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -383,8 +383,7 @@ parent_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg)
case IMSG_CTL_DECOUPLE:
case IMSG_CTL_ACTIVE:
case IMSG_CTL_PASSIVE:
- proc_compose_imsg(&env->sc_ps, PROC_IKEV2, -1,
- type, -1, NULL, 0);
+ proc_compose(&env->sc_ps, PROC_IKEV2, type, NULL, 0);
break;
case IMSG_CTL_RELOAD:
if (IMSG_DATA_SIZE(imsg) > 0)
diff --git a/sbin/iked/iked.h b/sbin/iked/iked.h
index 1a833acc66b..b1c31525a81 100644
--- a/sbin/iked/iked.h
+++ b/sbin/iked/iked.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: iked.h,v 1.94 2015/11/23 19:28:34 reyk Exp $ */
+/* $OpenBSD: iked.h,v 1.95 2015/12/07 12:46:37 reyk Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -870,9 +870,13 @@ int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
int imsg_composev_event(struct imsgev *, uint16_t, uint32_t,
pid_t, int, const struct iovec *, int);
int proc_compose_imsg(struct privsep *, enum privsep_procid, int,
- uint16_t, int, void *, uint16_t);
+ u_int16_t, u_int32_t, int, void *, u_int16_t);
+int proc_compose(struct privsep *, enum privsep_procid,
+ uint16_t, void *, uint16_t);
int proc_composev_imsg(struct privsep *, enum privsep_procid, int,
- uint16_t, int, const struct iovec *, int);
+ u_int16_t, u_int32_t, int, const struct iovec *, int);
+int proc_composev(struct privsep *, enum privsep_procid,
+ uint16_t, const struct iovec *, int);
int proc_forward_imsg(struct privsep *, struct imsg *,
enum privsep_procid, int);
struct imsgbuf *
diff --git a/sbin/iked/ocsp.c b/sbin/iked/ocsp.c
index 11f9349520e..827a501c0f0 100644
--- a/sbin/iked/ocsp.c
+++ b/sbin/iked/ocsp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ocsp.c,v 1.7 2015/11/23 19:28:34 reyk Exp $ */
+/* $OpenBSD: ocsp.c,v 1.8 2015/12/07 12:46:37 reyk Exp $ */
/*
* Copyright (c) 2014 Markus Friedl
@@ -186,10 +186,10 @@ ocsp_connect_finish(struct iked *env, int fd, struct ocsp_connect *oc)
iov[0].iov_base = oc->oc_path;
iov[0].iov_len = strlen(oc->oc_path);
ret = proc_composev_imsg(&env->sc_ps, PROC_CERT, -1,
- IMSG_OCSP_FD, fd, iov, iovcnt);
+ IMSG_OCSP_FD, -1, fd, iov, iovcnt);
} else {
ret = proc_compose_imsg(&env->sc_ps, PROC_CERT, -1,
- IMSG_OCSP_FD, -1, NULL, 0);
+ IMSG_OCSP_FD, -1, -1, NULL, 0);
if (fd >= 0)
close(fd);
}
@@ -243,8 +243,7 @@ ocsp_validate_cert(struct iked *env, struct iked_static_id *id,
TAILQ_INSERT_TAIL(&env->sc_ocsp, ioe, ioe_entry);
/* request connection to ocsp-responder */
- proc_compose_imsg(&env->sc_ps, PROC_PARENT, -1,
- IMSG_OCSP_FD, -1, NULL, 0);
+ proc_compose(&env->sc_ps, PROC_PARENT, IMSG_OCSP_FD, NULL, 0);
return (0);
err:
@@ -505,8 +504,7 @@ ocsp_validate_finish(struct iked_ocsp *ocsp, int valid)
iov[1].iov_len = sizeof(ocsp->ocsp_type);
cmd = valid ? IMSG_CERTVALID : IMSG_CERTINVALID;
- ret = proc_composev_imsg(&env->sc_ps, PROC_IKEV2, -1,
- cmd, -1, iov, iovcnt);
+ ret = proc_composev(&env->sc_ps, PROC_IKEV2, cmd, iov, iovcnt);
ocsp_free(ocsp);
return (ret);
diff --git a/sbin/iked/proc.c b/sbin/iked/proc.c
index 32e823e81f6..33b696f66df 100644
--- a/sbin/iked/proc.c
+++ b/sbin/iked/proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.c,v 1.27 2015/12/05 13:09:46 claudio Exp $ */
+/* $OpenBSD: proc.c,v 1.28 2015/12/07 12:46:37 reyk Exp $ */
/*
* Copyright (c) 2010 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -17,15 +17,10 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/types.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/wait.h>
-#include <sys/tree.h>
-
-#include <net/if.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
@@ -35,6 +30,7 @@
#include <signal.h>
#include <pwd.h>
#include <event.h>
+#include <imsg.h>
#include "iked.h"
@@ -580,14 +576,14 @@ proc_range(struct privsep *ps, enum privsep_procid id, int *n, int *m)
int
proc_compose_imsg(struct privsep *ps, enum privsep_procid id, int n,
- uint16_t type, int fd, void *data, uint16_t datalen)
+ uint16_t type, uint32_t peerid, int fd, void *data, uint16_t datalen)
{
int m;
proc_range(ps, id, &n, &m);
for (; n < m; n++) {
if (imsg_compose_event(&ps->ps_ievs[id][n],
- type, -1, 0, fd, data, datalen) == -1)
+ type, peerid, 0, fd, data, datalen) == -1)
return (-1);
}
@@ -595,26 +591,40 @@ proc_compose_imsg(struct privsep *ps, enum privsep_procid id, int n,
}
int
+proc_compose(struct privsep *ps, enum privsep_procid id,
+ uint16_t type, void *data, uint16_t datalen)
+{
+ return (proc_compose_imsg(ps, id, -1, type, -1, -1, data, datalen));
+}
+
+int
proc_composev_imsg(struct privsep *ps, enum privsep_procid id, int n,
- uint16_t type, int fd, const struct iovec *iov, int iovcnt)
+ uint16_t type, uint32_t peerid, int fd, const struct iovec *iov, int iovcnt)
{
int m;
proc_range(ps, id, &n, &m);
for (; n < m; n++)
if (imsg_composev_event(&ps->ps_ievs[id][n],
- type, -1, 0, fd, iov, iovcnt) == -1)
+ type, peerid, 0, fd, iov, iovcnt) == -1)
return (-1);
return (0);
}
int
+proc_composev(struct privsep *ps, enum privsep_procid id,
+ uint16_t type, const struct iovec *iov, int iovcnt)
+{
+ return (proc_composev_imsg(ps, id, -1, type, -1, -1, iov, iovcnt));
+}
+
+int
proc_forward_imsg(struct privsep *ps, struct imsg *imsg,
enum privsep_procid id, int n)
{
return (proc_compose_imsg(ps, id, n, imsg->hdr.type,
- imsg->fd, imsg->data, IMSG_DATA_SIZE(imsg)));
+ imsg->hdr.peerid, imsg->fd, imsg->data, IMSG_DATA_SIZE(imsg)));
}
struct imsgbuf *