Skip to content

Commit

Permalink
bpf: mark all potentially unused parameters with __maybe_unused
Browse files Browse the repository at this point in the history
This allows to enable extra warnings/errors with -Wextra when compiling
bpf programs.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
  • Loading branch information
tklauser committed Mar 16, 2020
1 parent 59e50e8 commit 103f961
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 84 deletions.
2 changes: 1 addition & 1 deletion bpf/Makefile.bpf
Expand Up @@ -3,7 +3,7 @@ FLAGS := -I/usr/include/$(shell uname -m)-linux-gnu -I$(ROOT_DIR)/bpf/include -I
CLANG_FLAGS := ${FLAGS} -target bpf -emit-llvm
# eBPF verifier enforces unaligned access checks where necessary, so don't
# let clang complain too early.
CLANG_FLAGS += -Wall -Werror -Wno-address-of-packed-member -Wno-unknown-warning-option
CLANG_FLAGS += -Wall -Wextra -Werror -Wno-address-of-packed-member -Wno-unknown-warning-option
LLC_FLAGS := -march=bpf -mcpu=probe -mattr=dwarfris

LIB := $(shell find $(ROOT_DIR)/bpf -name '*.h')
Expand Down
14 changes: 8 additions & 6 deletions bpf/bpf_netdev.c
Expand Up @@ -54,7 +54,8 @@ static __always_inline int rewrite_dmac_to_host(struct __ctx_buff *ctx,
#endif

#if defined ENABLE_IPV4 || defined ENABLE_IPV6
static __always_inline __u32 finalize_sec_ctx(__u32 secctx, __u32 src_identity)
static __always_inline
__u32 finalize_sec_ctx(__u32 secctx, __u32 src_identity __maybe_unused)
{
#ifdef ENABLE_SECCTX_FROM_IPCACHE
/* If we could not derive the secctx from the packet itself but
Expand All @@ -69,7 +70,7 @@ static __always_inline __u32 finalize_sec_ctx(__u32 secctx, __u32 src_identity)
#endif

#ifdef ENABLE_IPV6
static __always_inline __u32 derive_sec_ctx(struct __ctx_buff *ctx,
static __always_inline __u32 derive_sec_ctx(struct __ctx_buff *ctx __maybe_unused,
const union v6addr *node_ip,
struct ipv6hdr *ip6, __u32 *identity)
{
Expand Down Expand Up @@ -261,8 +262,9 @@ int tail_handle_ipv6(struct __ctx_buff *ctx)
#endif /* ENABLE_IPV6 */

#ifdef ENABLE_IPV4
static __always_inline __u32 derive_ipv4_sec_ctx(struct __ctx_buff *ctx,
struct iphdr *ip4)
static __always_inline
__u32 derive_ipv4_sec_ctx(struct __ctx_buff *ctx __maybe_unused,
struct iphdr *ip4 __maybe_unused)
{
#ifdef FIXED_SRC_SECCTX
return FIXED_SRC_SECCTX;
Expand Down Expand Up @@ -596,7 +598,7 @@ static __always_inline int do_netdev_encrypt_encap(struct __ctx_buff *ctx)
return __encap_and_redirect_with_nodeid(ctx, tunnel_endpoint, seclabel, TRACE_PAYLOAD_LEN);
}

static __always_inline int do_netdev_encrypt(struct __ctx_buff *ctx, __u16 proto)
static __always_inline int do_netdev_encrypt(struct __ctx_buff *ctx, __u16 proto __maybe_unused)
{
return do_netdev_encrypt_encap(ctx);
}
Expand Down Expand Up @@ -695,7 +697,7 @@ int from_netdev(struct __ctx_buff *ctx)
}

__section("to-netdev")
int to_netdev(struct __ctx_buff *ctx)
int to_netdev(struct __ctx_buff *ctx __maybe_unused)
{
/* Cannot compile the section out entriely, test/bpf/verifier-test.sh
* workaround.
Expand Down
30 changes: 17 additions & 13 deletions bpf/bpf_sock.c
Expand Up @@ -167,10 +167,11 @@ static __always_inline int sock4_update_revnat(struct bpf_sock_addr *ctx,
&rval, 0);
}
#else
static __always_inline int sock4_update_revnat(struct bpf_sock_addr *ctx,
struct lb4_backend *backend,
struct lb4_key *lkey,
struct lb4_service *slave_svc)
static __always_inline
int sock4_update_revnat(struct bpf_sock_addr *ctx __maybe_unused,
struct lb4_backend *backend __maybe_unused,
struct lb4_key *lkey __maybe_unused,
struct lb4_service *slave_svc __maybe_unused)
{
return -1;
}
Expand All @@ -197,8 +198,8 @@ static __always_inline bool sock4_skip_xlate(struct lb4_service *svc,
}

static __always_inline
struct lb4_service *sock4_nodeport_wildcard_lookup(struct lb4_key *key,
const bool include_remote_hosts)
struct lb4_service *sock4_nodeport_wildcard_lookup(struct lb4_key *key __maybe_unused,
const bool include_remote_hosts __maybe_unused)
{
#ifdef ENABLE_NODEPORT
struct remote_endpoint_info *info;
Expand Down Expand Up @@ -489,10 +490,11 @@ static __always_inline int sock6_update_revnat(struct bpf_sock_addr *ctx,
&rval, 0);
}
#else
static __always_inline int sock6_update_revnat(struct bpf_sock_addr *ctx,
struct lb6_backend *backend,
struct lb6_key *lkey,
struct lb6_service *slave_svc)
static __always_inline
int sock6_update_revnat(struct bpf_sock_addr *ctx __maybe_unused,
struct lb6_backend *backend __maybe_unused,
struct lb6_key *lkey __maybe_unused,
struct lb6_service *slave_svc __maybe_unused)
{
return -1;
}
Expand All @@ -510,7 +512,7 @@ static __always_inline void ctx_get_v6_address(struct bpf_sock_addr *ctx,

#ifdef ENABLE_NODEPORT
static __always_inline void ctx_get_v6_src_address(struct bpf_sock *ctx,
union v6addr *addr)
union v6addr *addr)
{
addr->p1 = ctx->src_ip6[0];
addr->p2 = ctx->src_ip6[1];
Expand Down Expand Up @@ -549,7 +551,8 @@ sock6_skip_xlate(struct lb6_service *svc, union v6addr *address)
}

static __always_inline __maybe_unused struct lb6_service *
sock6_nodeport_wildcard_lookup(struct lb6_key *key, bool include_remote_hosts)
sock6_nodeport_wildcard_lookup(struct lb6_key *key __maybe_unused,
bool include_remote_hosts __maybe_unused)
{
#ifdef ENABLE_NODEPORT
struct remote_endpoint_info *info;
Expand Down Expand Up @@ -581,7 +584,8 @@ sock6_nodeport_wildcard_lookup(struct lb6_key *key, bool include_remote_hosts)
#endif /* ENABLE_NODEPORT */
}

static __always_inline int sock6_xlate_v4_in_v6(struct bpf_sock_addr *ctx)
static __always_inline
int sock6_xlate_v4_in_v6(struct bpf_sock_addr *ctx __maybe_unused)
{
#ifdef ENABLE_IPV4
struct bpf_sock_addr fake_ctx;
Expand Down
2 changes: 1 addition & 1 deletion bpf/include/bpf/ctx/skb.h
Expand Up @@ -47,7 +47,7 @@
#define ctx_adjust_meta ({ -ENOTSUPP; })

static __always_inline __maybe_unused int
ctx_redirect(struct __sk_buff *ctx, int ifindex, __u32 flags)
ctx_redirect(struct __sk_buff *ctx __maybe_unused, int ifindex, __u32 flags)
{
return redirect(ifindex, flags);
}
Expand Down
2 changes: 1 addition & 1 deletion bpf/include/bpf/ctx/xdp.h
Expand Up @@ -51,7 +51,7 @@ xdp_load_bytes(struct xdp_md *ctx, __u64 off, void *to, const __u64 len)

static __always_inline __maybe_unused int
xdp_store_bytes(struct xdp_md *ctx, __u64 off, const void *from,
const __u64 len, __u64 flags)
const __u64 len, __u64 flags __maybe_unused)
{
void *to;
int ret;
Expand Down
3 changes: 2 additions & 1 deletion bpf/lib/common.h
Expand Up @@ -625,7 +625,8 @@ struct ct_state {
__u16 backend_id; /* Backend ID in lb4_backends */
};

static __always_inline int redirect_peer(int ifindex, __u32 flags)
static __always_inline int redirect_peer(int ifindex __maybe_unused,
__u32 flags __maybe_unused)
{
/* If our datapath has proper redirect support, we make use
* of it here, otherwise we terminate tc processing by letting
Expand Down
22 changes: 14 additions & 8 deletions bpf/lib/dbg.h
Expand Up @@ -216,23 +216,29 @@ static __always_inline void cilium_dbg_capture(struct __ctx_buff *ctx, __u8 type
# define printk(fmt, ...) \
do { } while (0)

static __always_inline void cilium_dbg(struct __ctx_buff *ctx, __u8 type,
__u32 arg1, __u32 arg2)
static __always_inline
void cilium_dbg(struct __ctx_buff *ctx __maybe_unused, __u8 type __maybe_unused,
__u32 arg1 __maybe_unused, __u32 arg2 __maybe_unused)
{
}

static __always_inline void cilium_dbg3(struct __ctx_buff *ctx, __u8 type,
__u32 arg1, __u32 arg2, __u32 arg3)
static __always_inline
void cilium_dbg3(struct __ctx_buff *ctx __maybe_unused,
__u8 type __maybe_unused, __u32 arg1 __maybe_unused,
__u32 arg2 __maybe_unused, __u32 arg3 __maybe_unused)
{
}

static __always_inline void cilium_dbg_capture(struct __ctx_buff *ctx,
__u8 type, __u32 arg1)
static __always_inline
void cilium_dbg_capture(struct __ctx_buff *ctx __maybe_unused,
__u8 type __maybe_unused, __u32 arg1 __maybe_unused)
{
}

static __always_inline void cilium_dbg_capture2(struct __ctx_buff *ctx, __u8 type,
__u32 arg1, __u32 arg2)
static __always_inline
void cilium_dbg_capture2(struct __ctx_buff *ctx __maybe_unused,
__u8 type __maybe_unused, __u32 arg1 __maybe_unused,
__u32 arg2 __maybe_unused)
{
}

Expand Down
7 changes: 4 additions & 3 deletions bpf/lib/drop.h
Expand Up @@ -89,9 +89,10 @@ static __always_inline int send_drop_notify(struct __ctx_buff *ctx, __u32 src,
return exitcode;
}
#else
static __always_inline int send_drop_notify(struct __ctx_buff *ctx, __u32 src,
__u32 dst, __u32 dst_id, int reason,
int exitcode, __u8 direction)
static __always_inline
int send_drop_notify(struct __ctx_buff *ctx,__u32 src __maybe_unused,
__u32 dst __maybe_unused, __u32 dst_id __maybe_unused,
int reason, int exitcode, __u8 direction)
{
update_metrics(ctx_full_len(ctx), direction, -reason);
return exitcode;
Expand Down
3 changes: 2 additions & 1 deletion bpf/lib/encap.h
Expand Up @@ -53,7 +53,8 @@ encap_and_redirect_ipsec(struct __ctx_buff *ctx, __u32 tunnel_endpoint,
#endif /* ENABLE_IPSEC */

static __always_inline int
encap_remap_v6_host_address(struct __ctx_buff *ctx, const bool egress)
encap_remap_v6_host_address(struct __ctx_buff *ctx __maybe_unused,
const bool egress __maybe_unused)
{
#ifdef ENABLE_ENCAP_HOST_REMAP
struct csum_offset csum = {};
Expand Down
3 changes: 2 additions & 1 deletion bpf/lib/l3.h
Expand Up @@ -97,7 +97,8 @@ static __always_inline int ipv6_local_delivery(struct __ctx_buff *ctx, int l3_of

static __always_inline int ipv4_local_delivery(struct __ctx_buff *ctx, int l3_off,
__u32 seclabel, struct iphdr *ip4,
struct endpoint_info *ep, __u8 direction)
struct endpoint_info *ep,
__u8 direction __maybe_unused)
{
int ret;

Expand Down
40 changes: 22 additions & 18 deletions bpf/lib/lb.h
Expand Up @@ -86,7 +86,8 @@ struct bpf_elf_map __section_maps LB4_BACKEND_MAP = {
#define cilium_dbg_lb(a, b, c, d)
#endif

static __always_inline bool lb4_svc_is_nodeport(const struct lb4_service *svc)
static __always_inline
bool lb4_svc_is_nodeport(const struct lb4_service *svc __maybe_unused)
{
#ifdef ENABLE_NODEPORT
return svc->nodeport;
Expand All @@ -95,7 +96,8 @@ static __always_inline bool lb4_svc_is_nodeport(const struct lb4_service *svc)
#endif /* ENABLE_NODEPORT */
}

static __always_inline bool lb6_svc_is_nodeport(const struct lb6_service *svc)
static __always_inline
bool lb6_svc_is_nodeport(const struct lb6_service *svc __maybe_unused)
{
#ifdef ENABLE_NODEPORT
return svc->nodeport;
Expand All @@ -104,7 +106,8 @@ static __always_inline bool lb6_svc_is_nodeport(const struct lb6_service *svc)
#endif /* ENABLE_NODEPORT */
}

static __always_inline bool lb4_svc_is_external_ip(const struct lb4_service *svc)
static __always_inline
bool lb4_svc_is_external_ip(const struct lb4_service *svc __maybe_unused)
{
#ifdef ENABLE_EXTERNAL_IP
return svc->external;
Expand All @@ -113,7 +116,8 @@ static __always_inline bool lb4_svc_is_external_ip(const struct lb4_service *svc
#endif
}

static __always_inline bool lb6_svc_is_external_ip(const struct lb6_service *svc)
static __always_inline
bool lb6_svc_is_external_ip(const struct lb6_service *svc __maybe_unused)
{
#ifdef ENABLE_EXTERNAL_IP
return svc->external;
Expand Down Expand Up @@ -278,9 +282,9 @@ static __always_inline int lb6_rev_nat(struct __ctx_buff *ctx, int l4_off,
* - DROP_UNKNOWN_L4 if packet should be ignore (sent to stack)
* - Negative error code
*/
static __always_inline int lb6_extract_key(struct __ctx_buff *ctx,
static __always_inline int lb6_extract_key(struct __ctx_buff *ctx __maybe_unused,
struct ipv6_ct_tuple *tuple,
int l4_off,
int l4_off __maybe_unused,
struct lb6_key *key,
struct csum_offset *csum_off,
int dir)
Expand Down Expand Up @@ -332,7 +336,7 @@ struct lb6_service *__lb6_lookup_service(struct lb6_key *key)
}

static __always_inline
struct lb6_service *lb6_lookup_service(struct __ctx_buff *ctx,
struct lb6_service *lb6_lookup_service(struct __ctx_buff *ctx __maybe_unused,
struct lb6_key *key)
{
struct lb6_service *svc = __lb6_lookup_service(key);
Expand All @@ -350,7 +354,7 @@ static __always_inline struct lb6_backend *__lb6_lookup_backend(__u16 backend_id
}

static __always_inline struct lb6_backend *
lb6_lookup_backend(struct __ctx_buff *ctx, __u16 backend_id)
lb6_lookup_backend(struct __ctx_buff *ctx __maybe_unused, __u16 backend_id)
{
struct lb6_backend *backend;

Expand All @@ -369,7 +373,7 @@ struct lb6_service *__lb6_lookup_slave(struct lb6_key *key)
}

static __always_inline
struct lb6_service *lb6_lookup_slave(struct __ctx_buff *ctx,
struct lb6_service *lb6_lookup_slave(struct __ctx_buff *ctx __maybe_unused,
struct lb6_key *key, __u16 slave)
{
struct lb6_service *svc;
Expand Down Expand Up @@ -524,19 +528,19 @@ static __always_inline int lb6_local(void *map, struct __ctx_buff *ctx,
* additional map management.
*/
static __always_inline
struct lb6_service *__lb6_lookup_service(struct lb6_key *key)
struct lb6_service *__lb6_lookup_service(struct lb6_key *key __maybe_unused)
{
return NULL;
}

static __always_inline
struct lb6_service *__lb6_lookup_slave(struct lb6_key *key)
struct lb6_service *__lb6_lookup_slave(struct lb6_key *key __maybe_unused)
{
return NULL;
}

static __always_inline struct lb6_backend *
__lb6_lookup_backend(__u16 backend_id)
__lb6_lookup_backend(__u16 backend_id __maybe_unused)
{
return NULL;
}
Expand Down Expand Up @@ -649,9 +653,9 @@ static __always_inline int lb4_rev_nat(struct __ctx_buff *ctx, int l3_off, int l
* - DROP_UNKNOWN_L4 if packet should be ignore (sent to stack)
* - Negative error code
*/
static __always_inline int lb4_extract_key(struct __ctx_buff *ctx,
static __always_inline int lb4_extract_key(struct __ctx_buff *ctx __maybe_unused,
struct ipv4_ct_tuple *tuple,
int l4_off,
int l4_off __maybe_unused,
struct lb4_key *key,
struct csum_offset *csum_off,
int dir)
Expand Down Expand Up @@ -701,7 +705,7 @@ struct lb4_service *__lb4_lookup_service(struct lb4_key *key)
}

static __always_inline
struct lb4_service *lb4_lookup_service(struct __ctx_buff *ctx,
struct lb4_service *lb4_lookup_service(struct __ctx_buff *ctx __maybe_unused,
struct lb4_key *key)
{
struct lb4_service *svc = __lb4_lookup_service(key);
Expand All @@ -718,7 +722,7 @@ static __always_inline struct lb4_backend *__lb4_lookup_backend(__u16 backend_id
}

static __always_inline struct lb4_backend *
lb4_lookup_backend(struct __ctx_buff *ctx, __u16 backend_id)
lb4_lookup_backend(struct __ctx_buff *ctx __maybe_unused, __u16 backend_id)
{
struct lb4_backend *backend;

Expand All @@ -737,8 +741,8 @@ struct lb4_service *__lb4_lookup_slave(struct lb4_key *key)
}

static __always_inline
struct lb4_service *lb4_lookup_slave(struct __ctx_buff *ctx,
struct lb4_key *key, __u16 slave)
struct lb4_service *lb4_lookup_slave(struct __ctx_buff *ctx __maybe_unused,
struct lb4_key *key, __u16 slave)
{
struct lb4_service *svc;

Expand Down

0 comments on commit 103f961

Please sign in to comment.