Merge branch 'enum-strings'

Adds a compile check the number of enum strings and updates several of
these lists, in particular, the one in the pfkey-kernel plugin, where
strings for several new extensions on FreeBSD were missing.

Fixes #3210.
laforge/swu
Tobias Brunner 3 years ago
commit a0a03c25f7
  1. 5
      src/libcharon/plugins/kernel_netlink/kernel_netlink_net.c
  2. 39
      src/libcharon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c
  3. 2
      src/libcharon/plugins/smp/smp.c
  4. 3
      src/libstrongswan/plugins/pkcs11/pkcs11_library.c
  5. 6
      src/libstrongswan/tests/suites/test_enum.c
  6. 28
      src/libstrongswan/utils/enum.h
  7. 12
      src/libtnccs/plugins/tnccs_20/messages/ita/pb_mutual_capability_msg.c
  8. 2
      src/libtnccs/plugins/tnccs_20/messages/ita/pb_mutual_capability_msg.h
  9. 1
      src/libtpmtss/tpm_tss_tss2_names_v2.c

@ -90,14 +90,15 @@ ENUM(rt_msg_names, RTM_NEWLINK, RTM_GETRULE,
"RTM_NEWADDR",
"RTM_DELADDR",
"RTM_GETADDR",
"31",
"23",
"RTM_NEWROUTE",
"RTM_DELROUTE",
"RTM_GETROUTE",
"35",
"27",
"RTM_NEWNEIGH",
"RTM_DELNEIGH",
"RTM_GETNEIGH",
"31",
"RTM_NEWRULE",
"RTM_DELRULE",
"RTM_GETRULE",

@ -692,12 +692,27 @@ struct pfkey_msg_t
struct sadb_x_kmprivate *x_kmprivate; /* SADB_X_EXT_KMPRIVATE */
struct sadb_x_policy *x_policy; /* SADB_X_EXT_POLICY */
struct sadb_x_sa2 *x_sa2; /* SADB_X_EXT_SA2 */
#if defined(__linux__) || defined (__FreeBSD__)
struct sadb_x_nat_t_type *x_natt_type; /* SADB_X_EXT_NAT_T_TYPE */
struct sadb_x_nat_t_port *x_natt_sport; /* SADB_X_EXT_NAT_T_SPORT */
struct sadb_x_nat_t_port *x_natt_dport; /* SADB_X_EXT_NAT_T_DPORT */
#ifdef __linux__
struct sadb_address *x_natt_oa; /* SADB_X_EXT_NAT_T_OA */
struct sadb_x_sec_ctx *x_sec_ctx; /* SADB_X_EXT_SEC_CTX */
struct sadb_x_kmaddress *x_kmaddress; /* SADB_X_EXT_KMADDRESS */
#else
struct sadb_address *x_natt_oai; /* SADB_X_EXT_NAT_T_OAI */
struct sadb_address *x_natt_oar; /* SADB_X_EXT_NAT_T_OAR */
#ifdef SADB_X_EXT_NAT_T_FRAG
struct sadb_x_nat_t_frag *x_natt_frag; /* SADB_X_EXT_NAT_T_FRAG */
#ifdef SADB_X_EXT_SA_REPLAY
struct sadb_x_sa_replay *x_replay; /* SADB_X_EXT_SA_REPLAY */
struct sadb_address *x_new_addr_src; /* SADB_X_EXT_NEW_ADDRESS_SRC */
struct sadb_address *x_new_addr_dst; /* SADB_X_EXT_NEW_ADDRESS_DST */
#endif
#endif
#endif /* __linux__ */
#endif /* __linux__ || __FreeBSD__ */
} __attribute__((__packed__));
};
};
@ -723,12 +738,34 @@ ENUM(sadb_ext_type_names, SADB_EXT_RESERVED, SADB_EXT_MAX,
"SADB_X_EXT_KMPRIVATE",
"SADB_X_EXT_POLICY",
"SADB_X_EXT_SA2",
#ifdef __APPLE__
"SADB_EXT_SESSION_ID",
"SADB_EXT_SASTAT",
"SADB_X_EXT_IPSECIF",
"SADB_X_EXT_ADDR_RANGE_SRC_START",
"SADB_X_EXT_ADDR_RANGE_SRC_END",
"SADB_X_EXT_ADDR_RANGE_DST_START",
"SADB_X_EXT_ADDR_RANGE_DST_END",
"SADB_EXT_MIGRATE_ADDRESS_SRC",
"SADB_EXT_MIGRATE_ADDRESS_DST",
"SADB_X_EXT_MIGRATE_IPSECIF",
#else
"SADB_X_EXT_NAT_T_TYPE",
"SADB_X_EXT_NAT_T_SPORT",
"SADB_X_EXT_NAT_T_DPORT",
#ifdef __linux__
"SADB_X_EXT_NAT_T_OA",
"SADB_X_EXT_SEC_CTX",
"SADB_X_EXT_KMADDRESS"
"SADB_X_EXT_KMADDRESS",
#else
"SADB_X_EXT_NAT_T_OAI",
"SADB_X_EXT_NAT_T_OAR",
"SADB_X_EXT_NAT_T_FRAG",
"SADB_X_EXT_SA_REPLAY",
"SADB_X_EXT_NEW_ADDRESS_SRC",
"SADB_X_EXT_NEW_ADDRESS_DST",
#endif /* __linux__ */
#endif /* __APPLE__ */
);
/**

@ -56,7 +56,9 @@ ENUM(ike_sa_state_lower_names, IKE_CREATED, IKE_DELETING,
"created",
"connecting",
"established",
"passive",
"rekeying",
"rekeyed",
"deleting",
);

@ -49,7 +49,7 @@ ENUM_NEXT(ck_rv_names, CKR_ATTRIBUTE_READ_ONLY, CKR_ATTRIBUTE_VALUE_INVALID,
"ATTRIBUTE_VALUE_INVALID");
ENUM_NEXT(ck_rv_names, CKR_DATA_INVALID, CKR_DATA_LEN_RANGE,
CKR_ATTRIBUTE_VALUE_INVALID,
"DATA_INVALID"
"DATA_INVALID",
"DATA_LEN_RANGE");
ENUM_NEXT(ck_rv_names, CKR_DEVICE_ERROR, CKR_DEVICE_REMOVED,
CKR_DATA_LEN_RANGE,
@ -540,6 +540,7 @@ ENUM_NEXT(ck_attr_names, CKA_HW_FEATURE_TYPE, CKA_HAS_RESET,
"HAS_RESET");
ENUM_NEXT(ck_attr_names, CKA_PIXEL_X, CKA_BITS_PER_PIXEL, CKA_HAS_RESET,
"PIXEL_X",
"PIXEL_Y",
"RESOLUTION",
"CHAR_ROWS",
"CHAR_COLUMNS",

@ -28,9 +28,6 @@ enum {
CONT5,
} test_enum_cont;
/* can't be static */
enum_name_t *test_enum_cont_names;
ENUM_BEGIN(test_enum_cont_names, CONT1, CONT5,
"CONT1", "CONT2", "CONT3", "CONT4", "CONT5");
ENUM_END(test_enum_cont_names, CONT5);
@ -46,9 +43,6 @@ enum {
SPLIT5 = 255,
} test_enum_split;
/* can't be static */
enum_name_t *test_enum_split_names;
ENUM_BEGIN(test_enum_split_names, SPLIT1, SPLIT2,
"SPLIT1", "SPLIT2");
ENUM_NEXT(test_enum_split_names, SPLIT3, SPLIT4, SPLIT2,

@ -1,5 +1,5 @@
/*
* Copyright (C) 2009 Tobias Brunner
* Copyright (C) 2009-2019 Tobias Brunner
* Copyright (C) 2006-2008 Martin Willi
* HSR Hochschule fuer Technik Rapperswil
*
@ -59,10 +59,11 @@ typedef struct enum_name_t enum_name_t;
* by the numerical enum value.
*/
struct enum_name_t {
/** value of the first enum string */
int first;
/** value of the first enum string, values are expected to be (u_)int, using
* int64_t here instead, however, avoids warnings for large unsigned ints */
int64_t first;
/** value of the last enum string */
int last;
int64_t last;
/** next enum_name_t in list, or ENUM_FLAG_MAGIC */
enum_name_t *next;
/** array of strings containing names from first to last */
@ -77,7 +78,10 @@ struct enum_name_t {
* @param last enum value of the last enum string
* @param ... a list of strings
*/
#define ENUM_BEGIN(name, first, last, ...) static enum_name_t name##last = {first, last, NULL, { __VA_ARGS__ }}
#define ENUM_BEGIN(name, first, last, ...) \
static enum_name_t name##last = {first, last + \
BUILD_ASSERT(((last)-(first)+1) == countof(((char*[]){__VA_ARGS__}))), \
NULL, { __VA_ARGS__ }}
/**
* Continue a enum name list startetd with ENUM_BEGIN.
@ -88,7 +92,10 @@ struct enum_name_t {
* @param prev enum value of the "last" defined in ENUM_BEGIN/previous ENUM_NEXT
* @param ... a list of strings
*/
#define ENUM_NEXT(name, first, last, prev, ...) static enum_name_t name##last = {first, last, &name##prev, { __VA_ARGS__ }}
#define ENUM_NEXT(name, first, last, prev, ...) \
static enum_name_t name##last = {first, last + \
BUILD_ASSERT(((last)-(first)+1) == countof(((char*[]){__VA_ARGS__}))), \
&name##prev, { __VA_ARGS__ }}
/**
* Complete enum name list started with ENUM_BEGIN.
@ -109,7 +116,8 @@ struct enum_name_t {
* @param last enum value of the last enum string
* @param ... a list of strings
*/
#define ENUM(name, first, last, ...) ENUM_BEGIN(name, first, last, __VA_ARGS__); ENUM_END(name, last)
#define ENUM(name, first, last, ...) \
ENUM_BEGIN(name, first, last, __VA_ARGS__); ENUM_END(name, last)
/**
* Define a enum name with only one range for flags.
@ -125,8 +133,10 @@ struct enum_name_t {
* @param ... a list of strings
*/
#define ENUM_FLAGS(name, first, last, ...) \
static enum_name_t name##last = {first, last, ENUM_FLAG_MAGIC, { __VA_ARGS__ }}; \
ENUM_END(name, last)
static enum_name_t name##last = {first, last + \
BUILD_ASSERT((__builtin_ffs(last)-__builtin_ffs(first)+1) == \
countof(((char*[]){__VA_ARGS__}))), \
ENUM_FLAG_MAGIC, { __VA_ARGS__ }}; ENUM_END(name, last)
/**
* Convert a enum value to its string representation.

@ -19,11 +19,13 @@
#include <bio/bio_reader.h>
#include <utils/debug.h>
ENUM(pb_tnc_mutual_protocol_type_names, PB_MUTUAL_HALF_DUPLEX,
PB_MUTUAL_FULL_DUPLEX,
"half duplex",
"full duplex"
);
ENUM_BEGIN(pb_tnc_mutual_protocol_type_names, PB_MUTUAL_FULL_DUPLEX,
PB_MUTUAL_FULL_DUPLEX,
"full duplex");
ENUM_NEXT(pb_tnc_mutual_protocol_type_names, PB_MUTUAL_HALF_DUPLEX,
PB_MUTUAL_HALF_DUPLEX, PB_MUTUAL_FULL_DUPLEX,
"half duplex");
ENUM_END(pb_tnc_mutual_protocol_type_names, PB_MUTUAL_HALF_DUPLEX);
typedef struct private_pb_mutual_capability_msg_t private_pb_mutual_capability_msg_t;

@ -30,8 +30,8 @@ typedef struct pb_mutual_capability_msg_t pb_mutual_capability_msg_t;
* PB-TNC mutual protocol types
*/
enum pb_tnc_mutual_protocol_type_t {
PB_MUTUAL_FULL_DUPLEX = (1 << 30),
PB_MUTUAL_HALF_DUPLEX = (1 << 31),
PB_MUTUAL_FULL_DUPLEX = (1 << 30)
};
/**

@ -51,6 +51,7 @@ ENUM_NEXT(tpm_alg_id_names, TPM2_ALG_SM3_256, TPM2_ALG_ECMQV, TPM2_ALG_NULL,
"OAEP",
"ECDSA",
"ECDH",
"ECDAA",
"SM2",
"ECSCHNORR",
"ECMQV"

Loading…
Cancel
Save