diff options
author | tobhe <tobhe@cvs.openbsd.org> | 2020-08-24 21:00:22 +0000 |
---|---|---|
committer | tobhe <tobhe@cvs.openbsd.org> | 2020-08-24 21:00:22 +0000 |
commit | 7dc2f45728f7aa5d8b52c0259e1ed64716eacaec (patch) | |
tree | 63b29fbf5fdb8619a5d22bb4a00de14aff6c7580 /sbin | |
parent | 8ec869142e449278df8915e7a30aaac009576a73 (diff) |
Reduce the amount of boilerplate code and imsgs for config options by
grouping fixed-size values in 'struct iked_static' which is sent in
a single message.
ok patrick@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/iked/config.c | 92 | ||||
-rw-r--r-- | sbin/iked/iked.c | 12 | ||||
-rw-r--r-- | sbin/iked/iked.h | 29 | ||||
-rw-r--r-- | sbin/iked/ikev2.c | 12 | ||||
-rw-r--r-- | sbin/iked/types.h | 7 |
5 files changed, 35 insertions, 117 deletions
diff --git a/sbin/iked/config.c b/sbin/iked/config.c index be68ee542a2..a4cc98d37fc 100644 --- a/sbin/iked/config.c +++ b/sbin/iked/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.62 2020/08/23 19:16:07 tobhe Exp $ */ +/* $OpenBSD: config.c,v 1.63 2020/08/24 21:00:21 tobhe Exp $ */ /* * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de> @@ -856,72 +856,25 @@ config_getcompile(struct iked *env) } int -config_setmobike(struct iked *env) +config_setstatic(struct iked *env) { - unsigned int boolval; - - boolval = env->sc_mobike; - proc_compose(&env->sc_ps, PROC_IKEV2, IMSG_CTL_MOBIKE, - &boolval, sizeof(boolval)); - return (0); -} - -int -config_getmobike(struct iked *env, struct imsg *imsg) -{ - unsigned int boolval; - - IMSG_SIZE_CHECK(imsg, &boolval); - memcpy(&boolval, imsg->data, sizeof(boolval)); - env->sc_mobike = boolval; - log_debug("%s: %smobike", __func__, env->sc_mobike ? "" : "no "); - return (0); -} - -int -config_setfragmentation(struct iked *env) -{ - unsigned int boolval; - - boolval = env->sc_frag; - proc_compose(&env->sc_ps, PROC_IKEV2, IMSG_CTL_FRAGMENTATION, - &boolval, sizeof(boolval)); - return (0); -} - -int -config_getfragmentation(struct iked *env, struct imsg *imsg) -{ - unsigned int boolval; - - IMSG_SIZE_CHECK(imsg, &boolval); - memcpy(&boolval, imsg->data, sizeof(boolval)); - env->sc_frag = boolval; - log_debug("%s: %sfragmentation", __func__, env->sc_frag ? "" : "no "); - return (0); -} - -int -config_setenforcesingleikesa(struct iked *env) -{ - unsigned int boolval; - - boolval = env->sc_enforcesingleikesa; - proc_compose(&env->sc_ps, PROC_IKEV2, IMSG_CTL_ENFORCESINGLEIKESA, - &boolval, sizeof(boolval)); + proc_compose(&env->sc_ps, PROC_IKEV2, IMSG_CTL_STATIC, + &env->sc_static, sizeof(env->sc_static)); return (0); } int -config_getenforcesingleikesa(struct iked *env, struct imsg *imsg) +config_getstatic(struct iked *env, struct imsg *imsg) { - unsigned int boolval; + IMSG_SIZE_CHECK(imsg, &env->sc_static); + memcpy(&env->sc_static, imsg->data, sizeof(env->sc_static)); - IMSG_SIZE_CHECK(imsg, &boolval); - memcpy(&boolval, imsg->data, sizeof(boolval)); - env->sc_enforcesingleikesa = boolval; log_debug("%s: %senforcesingleikesa", __func__, env->sc_enforcesingleikesa ? "" : "no "); + log_debug("%s: %sfragmentation", __func__, env->sc_frag ? "" : "no "); + log_debug("%s: %smobike", __func__, env->sc_mobike ? "" : "no "); + log_debug("%s: nattport %u", __func__, env->sc_nattport); + return (0); } @@ -1052,29 +1005,6 @@ config_setkeys(struct iked *env) } int -config_setnattport(struct iked *env) -{ - in_port_t nattport; - - nattport = env->sc_nattport; - proc_compose(&env->sc_ps, PROC_IKEV2, IMSG_CTL_NATTPORT, - &nattport, sizeof(nattport)); - return (0); -} - -int -config_getnattport(struct iked *env, struct imsg *imsg) -{ - in_port_t nattport; - - IMSG_SIZE_CHECK(imsg, &nattport); - memcpy(&nattport, imsg->data, sizeof(nattport)); - env->sc_nattport = nattport; - log_debug("%s: nattport %u", __func__, env->sc_nattport); - return (0); -} - -int config_getkey(struct iked *env, struct imsg *imsg) { size_t len; diff --git a/sbin/iked/iked.c b/sbin/iked/iked.c index 98a60f86b2d..82db9f8c6da 100644 --- a/sbin/iked/iked.c +++ b/sbin/iked/iked.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iked.c,v 1.46 2020/08/23 19:16:07 tobhe Exp $ */ +/* $OpenBSD: iked.c,v 1.47 2020/08/24 21:00:21 tobhe Exp $ */ /* * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de> @@ -263,10 +263,7 @@ parent_configure(struct iked *env) if (pledge("stdio rpath proc dns inet route sendfd", NULL) == -1) fatal("pledge"); - config_setmobike(env); - config_setenforcesingleikesa(env); - config_setfragmentation(env); - config_setnattport(env); + config_setstatic(env); config_setcoupled(env, env->sc_decoupled ? 0 : 1); config_setocsp(env); /* Must be last */ @@ -298,10 +295,7 @@ parent_reload(struct iked *env, int reset, const char *filename) /* Re-compile policies and skip steps */ config_setcompile(env, PROC_IKEV2); - config_setmobike(env); - config_setenforcesingleikesa(env); - config_setfragmentation(env); - config_setnattport(env); + config_setstatic(env); config_setcoupled(env, env->sc_decoupled ? 0 : 1); config_setocsp(env); /* Must be last */ diff --git a/sbin/iked/iked.h b/sbin/iked/iked.h index e17ef687933..9c81021802f 100644 --- a/sbin/iked/iked.h +++ b/sbin/iked/iked.h @@ -1,4 +1,4 @@ -/* $OpenBSD: iked.h,v 1.160 2020/08/23 19:16:08 tobhe Exp $ */ +/* $OpenBSD: iked.h,v 1.161 2020/08/24 21:00:21 tobhe Exp $ */ /* * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de> @@ -679,6 +679,13 @@ enum natt_mode { NATT_FORCE, /* send/recv with only NAT-T port */ }; +struct iked_static { + int st_enforcesingleikesa; + uint8_t st_frag; /* fragmentation */ + uint8_t st_mobike; /* MOBIKE */ + in_port_t st_nattport; +}; + struct iked { char sc_conffile[PATH_MAX]; @@ -686,10 +693,13 @@ struct iked { enum natt_mode sc_nattmode; uint8_t sc_passive; uint8_t sc_decoupled; - in_port_t sc_nattport; - uint8_t sc_mobike; /* MOBIKE */ - uint8_t sc_frag; /* fragmentation */ + struct iked_static sc_static; + +#define sc_enforcesingleikesa sc_static.st_enforcesingleikesa +#define sc_frag sc_static.st_frag +#define sc_mobike sc_static.st_mobike +#define sc_nattport sc_static.st_nattport struct iked_policies sc_policies; struct iked_policy *sc_defaultcon; @@ -724,7 +734,6 @@ struct iked { struct iked_addrpool sc_addrpool; struct iked_addrpool6 sc_addrpool6; - int sc_enforcesingleikesa; }; struct iked_socket { @@ -793,14 +802,8 @@ int config_setocsp(struct iked *); int config_getocsp(struct iked *, struct imsg *); int config_setkeys(struct iked *); int config_getkey(struct iked *, struct imsg *); -int config_setmobike(struct iked *); -int config_getmobike(struct iked *, struct imsg *); -int config_setenforcesingleikesa(struct iked *); -int config_getenforcesingleikesa(struct iked *, struct imsg *); -int config_setfragmentation(struct iked *); -int config_getfragmentation(struct iked *, struct imsg *); -int config_setnattport(struct iked *); -int config_getnattport(struct iked *, struct imsg *); +int config_setstatic(struct iked *); +int config_getstatic(struct iked *, struct imsg *); /* policy.c */ void policy_init(struct iked *); diff --git a/sbin/iked/ikev2.c b/sbin/iked/ikev2.c index ab621991f0b..83f7f6c1d14 100644 --- a/sbin/iked/ikev2.c +++ b/sbin/iked/ikev2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ikev2.c,v 1.247 2020/08/23 19:16:08 tobhe Exp $ */ +/* $OpenBSD: ikev2.c,v 1.248 2020/08/24 21:00:21 tobhe Exp $ */ /* * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de> @@ -238,14 +238,6 @@ ikev2_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) IKED_INITIATOR_INITIAL); } return (0); - case IMSG_CTL_MOBIKE: - return (config_getmobike(env, imsg)); - case IMSG_CTL_ENFORCESINGLEIKESA: - return (config_getenforcesingleikesa(env, imsg)); - case IMSG_CTL_FRAGMENTATION: - return (config_getfragmentation(env, imsg)); - case IMSG_CTL_NATTPORT: - return (config_getnattport(env, imsg)); case IMSG_UDP_SOCKET: return (config_getsocket(env, imsg, ikev2_msg_cb)); case IMSG_PFKEY_SOCKET: @@ -258,6 +250,8 @@ ikev2_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg) return (config_getuser(env, imsg)); case IMSG_COMPILE: return (config_getcompile(env)); + case IMSG_CTL_STATIC: + return (config_getstatic(env, imsg)); default: break; } diff --git a/sbin/iked/types.h b/sbin/iked/types.h index 03d8fbc6deb..67d173e5252 100644 --- a/sbin/iked/types.h +++ b/sbin/iked/types.h @@ -1,4 +1,4 @@ -/* $OpenBSD: types.h,v 1.38 2020/08/23 19:16:08 tobhe Exp $ */ +/* $OpenBSD: types.h,v 1.39 2020/08/24 21:00:21 tobhe Exp $ */ /* * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de> @@ -99,12 +99,9 @@ enum imsg_type { IMSG_CTL_DECOUPLE, IMSG_CTL_ACTIVE, IMSG_CTL_PASSIVE, - IMSG_CTL_MOBIKE, - IMSG_CTL_ENFORCESINGLEIKESA, - IMSG_CTL_FRAGMENTATION, - IMSG_CTL_NATTPORT, IMSG_CTL_RESET_ID, IMSG_CTL_SHOW_SA, + IMSG_CTL_STATIC, IMSG_COMPILE, IMSG_UDP_SOCKET, IMSG_PFKEY_SOCKET, |