Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/bfcli/opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ static const char * const _bfc_object_strs[] = {
"ruleset", // BFC_OBJECT_RULESET
"chain", // BFC_OBJECT_CHAIN
};
static_assert(ARRAY_SIZE(_bfc_object_strs) == _BFC_OBJECT_MAX,
"missing entries in bfc_object strings array");
static_assert_enum_mapping(_bfc_object_strs, _BFC_OBJECT_MAX);

static const char *bfc_object_to_str(enum bfc_object object)
{
Expand Down Expand Up @@ -77,8 +76,7 @@ static const char * const _bfc_action_strs[] = {
"update-set", // BFC_ACTION_UPDATE_SET
"flush", // BFC_ACTION_FLUSH
};
static_assert(ARRAY_SIZE(_bfc_action_strs) == _BFC_ACTION_MAX,
"missing entries in bfc_action strings array");
static_assert_enum_mapping(_bfc_action_strs, _BFC_ACTION_MAX);

static const char *bfc_action_to_str(enum bfc_action action)
{
Expand Down
3 changes: 1 addition & 2 deletions src/bpfilter/cgen/elfstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

#include "cgen/rawstubs.h"

static_assert(ARRAY_SIZE(_bf_rawstubs) == _BF_ELFSTUB_MAX,
"_bf_rawstubs doesn't contain as many entries as bf_elfstub_id");
static_assert_enum_mapping(_bf_rawstubs, _BF_ELFSTUB_MAX);

#define _free_bf_printk_str_ __attribute__((cleanup(_bf_printk_str_free)))

Expand Down
2 changes: 1 addition & 1 deletion src/bpfilter/cgen/fixup.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static const char *_bf_fixup_type_to_str(enum bf_fixup_type type)
};

assert(0 <= type && type < _BF_FIXUP_TYPE_MAX);
static_assert(ARRAY_SIZE(str) == _BF_FIXUP_TYPE_MAX);
static_assert_enum_mapping(str, _BF_FIXUP_TYPE_MAX);

return str[type];
}
Expand Down
3 changes: 1 addition & 2 deletions src/bpfilter/cgen/prog/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ static const char *_bf_map_type_to_str(enum bf_map_type type)
[BF_MAP_TYPE_SET] = "BF_MAP_TYPE_SET",
};

static_assert(ARRAY_SIZE(type_strs) == _BF_MAP_TYPE_MAX,
"missing entries in _bf_map_type_strs array");
static_assert_enum_mapping(type_strs, _BF_MAP_TYPE_MAX);
assert(0 <= type && type < _BF_MAP_TYPE_MAX);

return type_strs[type];
Expand Down
3 changes: 1 addition & 2 deletions src/bpfilter/cgen/program.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ static const struct bf_flavor_ops *bf_flavor_ops_get(enum bf_flavor flavor)
[BF_FLAVOR_CGROUP] = &bf_flavor_ops_cgroup,
};

static_assert(ARRAY_SIZE(flavor_ops) == _BF_FLAVOR_MAX,
"missing entries in bf_flavor_ops array");
static_assert_enum_mapping(flavor_ops, _BF_FLAVOR_MAX);

return flavor_ops[flavor];
}
Expand Down
4 changes: 2 additions & 2 deletions src/bpfilter/cgen/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ struct bf_runtime
__u8 bf_aligned(8) scratch[64];
};

_Static_assert(sizeof(struct bf_runtime) % 8 == 0,
"bf_runtime should be aligned to 8 bytes");
static_assert(sizeof(struct bf_runtime) % 8 == 0,
"bf_runtime should be aligned to 8 bytes");

extern void *bpf_dynptr_slice(const struct bpf_dynptr *, __u32, void *, __u32);
extern int bpf_dynptr_from_xdp(struct xdp_md *, __u64, struct bpf_dynptr *);
3 changes: 1 addition & 2 deletions src/bpfilter/opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ static const char *_bf_verbose_strs[] = {
[BF_VERBOSE_BYTECODE] = "bytecode",
};

static_assert(ARRAY_SIZE(_bf_verbose_strs) == _BF_VERBOSE_MAX,
"missing entries in _bf_verbose_strs array");
static_assert_enum_mapping(_bf_verbose_strs, _BF_VERBOSE_MAX);

enum bf_verbose bf_verbose_from_str(const char *str)
{
Expand Down
3 changes: 1 addition & 2 deletions src/bpfilter/xlate/front.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const struct bf_front_ops *bf_front_ops_get(enum bf_front front)
};

// We need to have an entry for each value in `bf_front` enumeration.
static_assert(ARRAY_SIZE(fronts) == _BF_FRONT_MAX,
"missing entries in fronts array");
static_assert_enum_mapping(fronts, _BF_FRONT_MAX);

return fronts[front];
}
3 changes: 1 addition & 2 deletions src/libbpfilter/flavor.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const char *bf_flavor_to_str(enum bf_flavor flavor)
[BF_FLAVOR_XDP] = "BF_FLAVOR_XDP",
[BF_FLAVOR_CGROUP] = "BF_FLAVOR_CGROUP",
};
static_assert(ARRAY_SIZE(flavor_str) == _BF_FLAVOR_MAX,
"missing entries in flavor_str array");
static_assert_enum_mapping(flavor_str, _BF_FLAVOR_MAX);

if (flavor < 0 || flavor >= _BF_FLAVOR_MAX)
return "<bf_flavor unknown>";
Expand Down
3 changes: 1 addition & 2 deletions src/libbpfilter/front.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const char *bf_front_to_str(enum bf_front front)
[BF_FRONT_NFT] = "BF_FRONT_NFT",
[BF_FRONT_CLI] = "BF_FRONT_CLI",
};
static_assert(ARRAY_SIZE(names) == _BF_FRONT_MAX,
"missing fronts in bf_front_to_str()");
static_assert_enum_mapping(names, _BF_FRONT_MAX);

if (front < 0 || front >= _BF_FRONT_MAX)
return "<bf_front unknown>";
Expand Down
15 changes: 5 additions & 10 deletions src/libbpfilter/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ static const char *_bf_hook_strs[] = {
[BF_HOOK_NF_POST_ROUTING] = "BF_HOOK_NF_POST_ROUTING",
[BF_HOOK_TC_EGRESS] = "BF_HOOK_TC_EGRESS",
};
static_assert(ARRAY_SIZE(_bf_hook_strs) == _BF_HOOK_MAX,
"missing entries in bf_hook strings array");
static_assert_enum_mapping(_bf_hook_strs, _BF_HOOK_MAX);

const char *bf_hook_to_str(enum bf_hook hook)
{
Expand Down Expand Up @@ -76,8 +75,7 @@ enum bf_flavor bf_hook_to_flavor(enum bf_hook hook)
[BF_HOOK_TC_EGRESS] = BF_FLAVOR_TC,
};

static_assert(ARRAY_SIZE(flavors) == _BF_HOOK_MAX,
"missing entries in bf_flavor array");
static_assert_enum_mapping(flavors, _BF_HOOK_MAX);

return flavors[hook];
}
Expand All @@ -97,8 +95,7 @@ enum bf_bpf_attach_type bf_hook_to_bpf_attach_type(enum bf_hook hook)
[BF_HOOK_TC_EGRESS] = BF_BPF_TCX_ENGRESS,
};

static_assert(ARRAY_SIZE(attach_types) == _BF_HOOK_MAX,
"missing entries in bpf_attach_type array");
static_assert_enum_mapping(attach_types, _BF_HOOK_MAX);

return attach_types[hook];
}
Expand All @@ -118,8 +115,7 @@ enum bf_bpf_prog_type bf_hook_to_bpf_prog_type(enum bf_hook hook)
[BF_HOOK_TC_EGRESS] = BF_BPF_PROG_TYPE_SCHED_CLS,
};

static_assert(ARRAY_SIZE(prog_types) == _BF_HOOK_MAX,
"missing entries in bpf_prog_type array");
static_assert_enum_mapping(prog_types, _BF_HOOK_MAX);

return prog_types[hook];
}
Expand Down Expand Up @@ -383,8 +379,7 @@ static struct bf_hookopts_ops
.dump = _bf_hookopts_priorities_dump},
};

static_assert(ARRAY_SIZE(_bf_hookopts_ops) == _BF_HOOKOPTS_MAX,
"missing entries in bf_hookopts_ops array");
static_assert_enum_mapping(_bf_hookopts_ops, _BF_HOOKOPTS_MAX);

#define _bf_hookopts_is_required(type, flavor) \
(_bf_hookopts_ops[type].required_by & BF_FLAG(flavor))
Expand Down
2 changes: 0 additions & 2 deletions src/libbpfilter/include/bpfilter/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ extern const char *strerrordesc_np(int errnum);
#define bf_aligned(x) __attribute__((aligned(x)))
#define bf_unused __attribute__((unused))

#define bf_static_assert(expr, msg) _Static_assert((expr), msg)
Comment thread
yaakov-stein marked this conversation as resolved.

#define BF_STR(s) _BF_STR(s)
#define _BF_STR(s) #s

Expand Down
3 changes: 1 addition & 2 deletions src/libbpfilter/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ static const char *_bf_log_level_strs[] = {
[BF_LOG_DBG] = "debug", [BF_LOG_INFO] = "info", [BF_LOG_WARN] = "warning",
[BF_LOG_ERR] = "error", [BF_LOG_ABORT] = "abort",
};
static_assert(ARRAY_SIZE(_bf_log_level_strs) == _BF_LOG_MAX,
"missing entries in _bf_log_level_strs strings array");
static_assert_enum_mapping(_bf_log_level_strs, _BF_LOG_MAX);

const char *bf_log_level_to_str(enum bf_log_level level)
{
Expand Down
13 changes: 3 additions & 10 deletions src/libbpfilter/matcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -1545,8 +1545,7 @@ static const char *_bf_matcher_type_strs[] = {
[BF_MATCHER_SET] = "<set>",
};

static_assert(ARRAY_SIZE(_bf_matcher_type_strs) == _BF_MATCHER_TYPE_MAX,
"missing entries in the matcher type array");
static_assert_enum_mapping(_bf_matcher_type_strs, _BF_MATCHER_TYPE_MAX);

const char *bf_matcher_type_to_str(enum bf_matcher_type type)
{
Expand Down Expand Up @@ -1577,7 +1576,7 @@ static const char *_bf_matcher_ops_strs[] = {
[BF_MATCHER_IN] = "in", [BF_MATCHER_RANGE] = "range",
};

static_assert(ARRAY_SIZE(_bf_matcher_ops_strs) == _BF_MATCHER_OP_MAX);
static_assert_enum_mapping(_bf_matcher_ops_strs, _BF_MATCHER_OP_MAX);

const char *bf_matcher_op_to_str(enum bf_matcher_op op)
{
Expand Down Expand Up @@ -1606,7 +1605,7 @@ static const char *_bf_tcp_flags_strs[] = {
[BF_TCP_PSH] = "psh", [BF_TCP_ACK] = "ack", [BF_TCP_URG] = "urg",
[BF_TCP_ECE] = "ece", [BF_TCP_CWR] = "cwr",
};
static_assert(ARRAY_SIZE(_bf_tcp_flags_strs) == _BF_TCP_MAX);
static_assert_enum_mapping(_bf_tcp_flags_strs, _BF_TCP_MAX);

const char *bf_tcp_flag_to_str(enum bf_tcp_flag flag)
{
Expand Down Expand Up @@ -1668,8 +1667,6 @@ static const char *_bf_ipproto_strs[UINT8_MAX + 1] = {
[IPPROTO_DSTOPTS] = "dst", [IPPROTO_ICMPV6] = "icmpv6",
[IPPROTO_MH] = "mh",
Comment thread
yaakov-stein marked this conversation as resolved.
};
static_assert(ARRAY_SIZE(_bf_ipproto_strs) == (UINT8_MAX + 1),
Comment thread
qdeslandes marked this conversation as resolved.
"missing entries in IP protocols strings array");

const char *bf_ipproto_to_str(uint8_t ipproto)
{
Expand Down Expand Up @@ -1711,8 +1708,6 @@ static const char *_bf_icmp_type_strs[UINT8_MAX + 1] = {
[ICMP_ADDRESS] = "address-mask-request",
[ICMP_ADDRESSREPLY] = "address-mask-reply",
};
static_assert(ARRAY_SIZE(_bf_icmp_type_strs) == (UINT8_MAX + 1),
"missing entries in ICMP types strings array");

const char *bf_icmp_type_to_str(uint8_t type)
{
Expand Down Expand Up @@ -1755,8 +1750,6 @@ static const char *_bf_icmpv6_type_strs[UINT8_MAX + 1] = {
[ICMPV6_ND_NEIGHADVERT] = "nd-neighbor-advert",
[ICMPV6_MLD2_REPORT] = "mld2-listener-report",
};
static_assert(ARRAY_SIZE(_bf_icmpv6_type_strs) == (UINT8_MAX + 1),
"missing entries in ICMPv6 types strings array");

const char *bf_icmpv6_type_to_str(uint8_t type)
{
Expand Down
4 changes: 2 additions & 2 deletions src/libbpfilter/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ void bf_rpack_free(bf_rpack_t **pack)
#define MP_NODE(node) (*(mpack_node_t *)&(node))
#define BF_NODE(node) (*(bf_rpack_node_t *)(mpack_node_t[]) {node})

_Static_assert(sizeof(bf_rpack_node_t) >= sizeof(mpack_node_t),
"bf_rpack_node_t too small for mpack_node_t");
static_assert(sizeof(bf_rpack_node_t) >= sizeof(mpack_node_t),
"bf_rpack_node_t too small for mpack_node_t");

bf_rpack_node_t bf_rpack_root(const bf_rpack_t *pack)
{
Expand Down
3 changes: 1 addition & 2 deletions src/libbpfilter/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ const char *bf_request_cmd_to_str(enum bf_request_cmd cmd)
[BF_REQ_CUSTOM] = "BF_REQ_CUSTOM",
};

static_assert(ARRAY_SIZE(cmd_strs) == _BF_REQ_CMD_MAX,
"missing entries in bf_request_cmd array");
static_assert_enum_mapping(cmd_strs, _BF_REQ_CMD_MAX);

return cmd_strs[cmd];
}
4 changes: 2 additions & 2 deletions src/libbpfilter/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ int bf_set_new(struct bf_set **set, const char *name, enum bf_matcher_type *key,
assert(set);
assert(key);

bf_static_assert(_BF_MATCHER_TYPE_MAX < 8 * sizeof(uint32_t),
"matcher type bitmask won't fit in 32 bits");
static_assert(_BF_MATCHER_TYPE_MAX < 8 * sizeof(uint32_t),
"matcher type bitmask won't fit in 32 bits");

if (n_comps == 0)
return bf_err_r(-EINVAL, "at least 1 key component is required");
Expand Down
6 changes: 2 additions & 4 deletions src/libbpfilter/verdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ static const char *_bf_redirect_dir_strs[] = {
[BF_REDIRECT_INGRESS] = "in",
[BF_REDIRECT_EGRESS] = "out",
};
static_assert(ARRAY_SIZE(_bf_redirect_dir_strs) == _BF_REDIRECT_DIR_MAX,
"missing entries in the redirect dir array");
static_assert_enum_mapping(_bf_redirect_dir_strs, _BF_REDIRECT_DIR_MAX);

const char *bf_redirect_dir_to_str(enum bf_redirect_dir dir)
{
Expand Down Expand Up @@ -46,8 +45,7 @@ static const char *_bf_verdict_strs[] = {
[BF_VERDICT_REDIRECT] = "REDIRECT",
[BF_VERDICT_CONTINUE] = "CONTINUE",
};
static_assert(ARRAY_SIZE(_bf_verdict_strs) == _BF_VERDICT_MAX,
"missing entries in the verdict array");
static_assert_enum_mapping(_bf_verdict_strs, _BF_VERDICT_MAX);

const char *bf_verdict_to_str(enum bf_verdict verdict)
{
Expand Down
Loading