It would save our time of thinking and reading the source (i.e.
eliminate the process of "what if the variable 'mobike' was 2 or more?
...aha it's just a bool").
This is still work in progress. I would continue if you maintainers are
positive on this proposal.
Index: sbin/iked/config.c
===
RCS file: /cvs/src/sbin/iked/config.c,v
retrieving revision 1.55
diff -u -r1.55 config.c
--- sbin/iked/config.c 24 Mar 2020 13:32:36 - 1.55
+++ sbin/iked/config.c 2 Apr 2020 15:45:44 -
@@ -22,6 +22,7 @@
#include
#include
+#include
#include
#include
#include
@@ -39,7 +40,7 @@
#include "ikev2.h"
struct iked_sa *
-config_new_sa(struct iked *env, int initiator)
+config_new_sa(struct iked *env, bool initiator)
{
struct iked_sa *sa;
@@ -451,7 +452,7 @@
*/
int
-config_setcoupled(struct iked *env, unsigned int couple)
+config_setcoupled(struct iked *env, bool couple)
{
unsigned int type;
@@ -465,11 +466,11 @@
config_getcoupled(struct iked *env, unsigned int type)
{
return (pfkey_couple(env->sc_pfkey, >sc_sas,
- type == IMSG_CTL_COUPLE ? 1 : 0));
+ type == IMSG_CTL_COUPLE));
}
int
-config_setmode(struct iked *env, unsigned int passive)
+config_setmode(struct iked *env, bool passive)
{
unsigned int type;
@@ -482,17 +483,17 @@
int
config_getmode(struct iked *env, unsigned int type)
{
- uint8_t old;
+ bool old;
unsigned char *mode[] = { "active", "passive" };
- old = env->sc_passive ? 1 : 0;
- env->sc_passive = type == IMSG_CTL_PASSIVE ? 1 : 0;
+ old = env->sc_passive;
+ env->sc_passive = (type == IMSG_CTL_PASSIVE);
if (old == env->sc_passive)
return (0);
log_debug("%s: mode %s -> %s", __func__,
- mode[old], mode[env->sc_passive]);
+ mode[old ? 1 : 0], mode[env->sc_passive ? 1 : 0]);
return (0);
}
@@ -848,22 +849,22 @@
int
config_setmobike(struct iked *env)
{
- unsigned int boolval;
+ bool val;
- boolval = env->sc_mobike;
+ val = env->sc_mobike;
proc_compose(>sc_ps, PROC_IKEV2, IMSG_CTL_MOBIKE,
- , sizeof(boolval));
+ , sizeof(val));
return (0);
}
int
config_getmobike(struct iked *env, struct imsg *imsg)
{
- unsigned int boolval;
+ bool mobike;
- IMSG_SIZE_CHECK(imsg, );
- memcpy(, imsg->data, sizeof(boolval));
- env->sc_mobike = boolval;
+ IMSG_SIZE_CHECK(imsg, );
+ memcpy(, imsg->data, sizeof(mobike));
+ env->sc_mobike = mobike;
log_debug("%s: %smobike", __func__, env->sc_mobike ? "" : "no ");
return (0);
}
@@ -871,22 +872,22 @@
int
config_setfragmentation(struct iked *env)
{
- unsigned int boolval;
+ bool fragmentation;
- boolval = env->sc_frag;
+ fragmentation = env->sc_frag;
proc_compose(>sc_ps, PROC_IKEV2, IMSG_CTL_FRAGMENTATION,
- , sizeof(boolval));
+ , sizeof(fragmentation));
return (0);
}
int
config_getfragmentation(struct iked *env, struct imsg *imsg)
{
- unsigned int boolval;
+ bool fragmentation;
- IMSG_SIZE_CHECK(imsg, );
- memcpy(, imsg->data, sizeof(boolval));
- env->sc_frag = boolval;
+ IMSG_SIZE_CHECK(imsg, );
+ memcpy(, imsg->data, sizeof(fragmentation));
+ env->sc_frag = fragmentation;
log_debug("%s: %sfragmentation", __func__, env->sc_frag ? "" : "no ");
return (0);
}
Index: sbin/iked/crypto.c
===
RCS file: /cvs/src/sbin/iked/crypto.c,v
retrieving revision 1.23
diff -u -r1.23 crypto.c
--- sbin/iked/crypto.c 14 Feb 2020 13:02:31 - 1.23
+++ sbin/iked/crypto.c 2 Apr 2020 15:45:44 -
@@ -21,6 +21,7 @@
#include
#include
+#include
#include
#include
#include
@@ -504,7 +505,7 @@
if (prf == NULL || prf->hash_priv == NULL)
fatalx("dsa_new: invalid PRF");
dsa.dsa_priv = prf->hash_priv;
- dsa.dsa_hmac = 1;
+ dsa.dsa_hmac = true;
break;
case IKEV2_AUTH_DSS_SIG:
dsa.dsa_priv = EVP_dss1();
Index: sbin/iked/iked.c
===
RCS file: /cvs/src/sbin/iked/iked.c,v
retrieving revision 1.41
diff -u -r1.41 iked.c
--- sbin/iked/iked.c16 Jan 2020 20:05:00 - 1.41
+++ sbin/iked/iked.c2 Apr 2020 15:45:44 -
@@ -22,6 +22,7 @@
#include
#include
+#include
#include
#include
#include
@@ -261,10 +262,10 @@
config_setmobike(env);
config_setfragmentation(env);
config_setnattport(env);
- config_setcoupled(env, env->sc_decoupled ? 0 : 1);
+ config_setcoupled(env, !env->sc_decoupled);
config_setocsp(env);
/* Must