Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1.13] cocci: fix warnings related to const qualifiers and DROP_MISSED_TAIL_CALL #28279

Merged
merged 3 commits into from
Sep 27, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/lint-bpf-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ jobs:
uses: docker://cilium/coccicheck:2.4@sha256:24abe3fbb8e829fa41a68a3b76cb4df84fd5a87a7d1d6254c1c1fe5effb5bd1b
with:
entrypoint: ./contrib/coccinelle/check-cocci.sh
# Note: Setting COCCINELLE_HOME can be removed, here and in the
# messages in the .cocci files, next time we upgrade coccinelle.
# The issue was fixed, after v1.1.1 that we're using, in
# https://gitlab.inria.fr/coccinelle/coccinelle/-/commit/540888ff426e.
env:
COCCINELLE_HOME: /usr/local/lib/coccinelle

set_clang_dir:
name: Set clang directory
Expand Down
2 changes: 1 addition & 1 deletion bpf/lib/lb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ static __always_inline int lb4_rev_nat(struct __ctx_buff *ctx, int l3_off, int l
}

static __always_inline void
lb4_fill_key(struct lb4_key *key, struct ipv4_ct_tuple *tuple)
lb4_fill_key(struct lb4_key *key, const struct ipv4_ct_tuple *tuple)
{
/* FIXME: set after adding support for different L4 protocols in LB */
key->proto = 0;
Expand Down
5 changes: 3 additions & 2 deletions bpf/lib/nat.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ snat_v4_rev_nat_can_skip(const struct ipv4_nat_target *target, const struct ipv4
* - on CT_NEW (ie. the tuple is reversed)
*/
static __always_inline __maybe_unused int
snat_v4_create_dsr(struct ipv4_ct_tuple *tuple, __be32 to_saddr, __be16 to_sport,
snat_v4_create_dsr(const struct ipv4_ct_tuple *tuple, __be32 to_saddr,
__be16 to_sport,
__s8 *ext_err)
{
struct ipv4_ct_tuple tmp = *tuple;
Expand Down Expand Up @@ -1321,7 +1322,7 @@ snat_v6_rev_nat_can_skip(const struct ipv6_nat_target *target, const struct ipv6
}

static __always_inline __maybe_unused int
snat_v6_create_dsr(struct ipv6_ct_tuple *tuple, union v6addr *to_saddr,
snat_v6_create_dsr(const struct ipv6_ct_tuple *tuple, union v6addr *to_saddr,
__be16 to_sport, __s8 *ext_err)
{
struct ipv6_ct_tuple tmp = *tuple;
Expand Down
11 changes: 6 additions & 5 deletions bpf/lib/nodeport.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ static __always_inline int find_dsr_v6(struct __ctx_buff *ctx, __u8 nexthdr,

static __always_inline int
nodeport_extract_dsr_v6(struct __ctx_buff *ctx, struct ipv6hdr *ip6,
struct ipv6_ct_tuple *tuple, int l4_off,
const struct ipv6_ct_tuple *tuple, int l4_off,
union v6addr *addr, __be16 *port, bool *dsr)
{
struct dsr_opt_v6 opt __align_stack_8 = {};
Expand Down Expand Up @@ -1028,7 +1028,7 @@ static __always_inline int nodeport_lb6(struct __ctx_buff *ctx,
if (dsr) {
ctx_store_meta(ctx, CB_SRC_LABEL, src_identity);
ep_tail_call(ctx, CILIUM_CALL_IPV6_NODEPORT_DSR_INGRESS);
ret = DROP_MISSED_TAIL_CALL;
return DROP_MISSED_TAIL_CALL;
}

if (IS_ERR(ret))
Expand Down Expand Up @@ -1611,8 +1611,9 @@ static __always_inline int dsr_set_opt4(struct __ctx_buff *ctx,
#endif /* DSR_ENCAP_MODE */

static __always_inline int
nodeport_extract_dsr_v4(struct __ctx_buff *ctx, struct iphdr *ip4,
struct ipv4_ct_tuple *tuple, int l4_off, __be32 *addr,
nodeport_extract_dsr_v4(struct __ctx_buff *ctx, const struct iphdr *ip4,
const struct ipv4_ct_tuple *tuple, int l4_off,
__be32 *addr,
__be16 *port, bool *dsr)
{
struct ipv4_ct_tuple tmp = *tuple;
Expand Down Expand Up @@ -2261,7 +2262,7 @@ static __always_inline int nodeport_lb4(struct __ctx_buff *ctx,
if (dsr) {
ctx_store_meta(ctx, CB_SRC_LABEL, src_identity);
ep_tail_call(ctx, CILIUM_CALL_IPV4_NODEPORT_DSR_INGRESS);
ret = DROP_MISSED_TAIL_CALL;
return DROP_MISSED_TAIL_CALL;
}

if (IS_ERR(ret))
Expand Down
2 changes: 1 addition & 1 deletion bpf/lib/overloadable_skb.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static __always_inline void ctx_snat_done_set(struct __sk_buff *ctx)
ctx->mark |= MARK_MAGIC_SNAT_DONE;
}

static __always_inline bool ctx_snat_done(struct __sk_buff *ctx)
static __always_inline bool ctx_snat_done(const struct __sk_buff *ctx)
{
return (ctx->mark & MARK_MAGIC_SNAT_DONE) == MARK_MAGIC_SNAT_DONE;
}
Expand Down
2 changes: 1 addition & 1 deletion bpf/lib/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ combine_ports(__u16 dport, __u16 sport)
* ingress. Will modify 'tuple'! \
*/ \
static __always_inline int \
NAME(struct __ctx_buff *ctx, CT_TUPLE_TYPE * ct_tuple, __be16 proxy_port) \
NAME(struct __ctx_buff *ctx, const CT_TUPLE_TYPE * ct_tuple, __be16 proxy_port) \
{ \
struct bpf_sock_tuple *tuple = (struct bpf_sock_tuple *)ct_tuple; \
__u8 nexthdr = ct_tuple->nexthdr; \
Expand Down
2 changes: 1 addition & 1 deletion bpf/tests/tc_nodeport_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ int tc_drop_no_backend_setup(struct __ctx_buff *ctx)
}

CHECK("tc", "tc_drop_no_backend")
int tc_drop_no_backend_check(struct __ctx_buff *ctx)
int tc_drop_no_backend_check(const struct __ctx_buff *ctx)
{
__u32 expected_status = TC_ACT_SHOT;
__u32 *status_code;
Expand Down
2 changes: 1 addition & 1 deletion bpf/tests/wildcard_lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ int test_v4_check(__maybe_unused struct xdp_md *ctx)
test_finish();
}

static inline void __setup_v6_ipcache(union v6addr *HOST_IP6)
static inline void __setup_v6_ipcache(const union v6addr *HOST_IP6)
{
struct remote_endpoint_info cache_value = {};
struct ipcache_key cache_key = {};
Expand Down
8 changes: 5 additions & 3 deletions contrib/coccinelle/aligned.cocci
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ cnt += 1

if cnt > 0:
print("""Use the following command to fix the above issues:
docker run --rm --user 1000 --workdir /workspace -v `pwd`:/workspace \\
-it docker.io/cilium/coccicheck:2.3@sha256:56c7445e3d0cc37de49750f5dfd154786082c4be6bc17683c231c0445862233a spatch --sp-file contrib/coccinelle/aligned.cocci \\
--include-headers --very-quiet --in-place bpf/\n
docker run --rm --user 1000 --workdir /workspace -v `pwd`:/workspace \\
-e COCCINELLE_HOME=/usr/local/lib/coccinelle \\
-it docker.io/cilium/coccicheck:2.4@sha256:24abe3fbb8e829fa41a68a3b76cb4df84fd5a87a7d1d6254c1c1fe5effb5bd1b \\
spatch --include-headers --very-quiet --in-place bpf/ \\
--sp-file contrib/coccinelle/aligned.cocci\n
""")
8 changes: 5 additions & 3 deletions contrib/coccinelle/const.cocci
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ cnt += 1

if cnt > 0:
print("""Use the following command to fix the above issues:
docker run --rm --user 1000 --workdir /workspace -v `pwd`:/workspace \\
-it docker.io/cilium/coccicheck:2.3@sha256:56c7445e3d0cc37de49750f5dfd154786082c4be6bc17683c231c0445862233a spatch --sp-file contrib/coccinelle/const.cocci \\
--include-headers --very-quiet --in-place bpf/\n
docker run --rm --user 1000 --workdir /workspace -v `pwd`:/workspace \\
-e COCCINELLE_HOME=/usr/local/lib/coccinelle \\
-it docker.io/cilium/coccicheck:2.4@sha256:24abe3fbb8e829fa41a68a3b76cb4df84fd5a87a7d1d6254c1c1fe5effb5bd1b \\
spatch --include-headers --very-quiet --in-place bpf/ \\
--sp-file contrib/coccinelle/const.cocci\n
""")
8 changes: 5 additions & 3 deletions contrib/coccinelle/identity_is_node.cocci
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ if len(p2) > 0:

if cnt > 0:
print("""Use the following command to fix the above issues:
docker run --rm --user 1000 --workdir /workspace -v `pwd`:/workspace \\
-it docker.io/cilium/coccicheck:2.3@sha256:56c7445e3d0cc37de49750f5dfd154786082c4be6bc17683c231c0445862233a spatch --sp-file contrib/coccinelle/identity_is_node.cocci \\
--include-headers --very-quiet --in-place bpf/\n
docker run --rm --user 1000 --workdir /workspace -v `pwd`:/workspace \\
-e COCCINELLE_HOME=/usr/local/lib/coccinelle \\
-it docker.io/cilium/coccicheck:2.4@sha256:24abe3fbb8e829fa41a68a3b76cb4df84fd5a87a7d1d6254c1c1fe5effb5bd1b \\
spatch --include-headers --very-quiet --in-place bpf/ \\
--sp-file contrib/coccinelle/identity_is_node.cocci\n
""")
5 changes: 4 additions & 1 deletion contrib/coccinelle/tail_calls.cocci
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,8 @@ cnt += 1
if cnt > 0:
print("""Unlogged tail calls found. Please fix and use the following command to check:
docker run --rm --user 1000 --workdir /workspace -v `pwd`:/workspace \\
-it docker.io/cilium/coccicheck:2.3@sha256:56c7445e3d0cc37de49750f5dfd154786082c4be6bc17683c231c0445862233a make -C bpf coccicheck\n
-e COCCINELLE_HOME=/usr/local/lib/coccinelle \\
-it docker.io/cilium/coccicheck:2.3@sha256:56c7445e3d0cc37de49750f5dfd154786082c4be6bc17683c231c0445862233a \\
spatch --include-headers --very-quiet --in-place bpf/ \\
--sp-file contrib/coccinelle/tail_calls.cocci\n
""")
8 changes: 5 additions & 3 deletions contrib/coccinelle/zero_trace_reason.cocci
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ cnt += 1

if cnt > 0:
print("""Use the following command to fix the above issues:
docker run --rm --user 1000 --workdir /workspace -v `pwd`:/workspace \\
-it docker.io/cilium/coccicheck:2.3@sha256:56c7445e3d0cc37de49750f5dfd154786082c4be6bc17683c231c0445862233a spatch --sp-file contrib/coccinelle/zero_trace_reason.cocci \\
--include-headers --very-quiet --in-place bpf/\n
docker run --rm --user 1000 --workdir /workspace -v `pwd`:/workspace \\
-e COCCINELLE_HOME=/usr/local/lib/coccinelle \\
-it docker.io/cilium/coccicheck:2.3@sha256:56c7445e3d0cc37de49750f5dfd154786082c4be6bc17683c231c0445862233a \\
spatch --include-headers --very-quiet --in-place bpf/ \\
--sp-file contrib/coccinelle/zero_trace_reason.cocci\n
""")