Skip to content

Commit

Permalink
Merge branch 'bpf: Small nf_conn cleanups'
Browse files Browse the repository at this point in the history
Daniel Xu says:

====================

This patchset cleans up a few small things:

* Delete unused stub
* Rename variable to be more descriptive
* Fix some `extern` declaration warnings

Past discussion:
- v2: https://lore.kernel.org/bpf/cover.1663616584.git.dxu@dxuuu.xyz/

Changes since v2:
- Remove unused #include's
- Move #include <linux/filter.h> to .c
====================

Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
  • Loading branch information
Martin KaFai Lau committed Sep 20, 2022
2 parents c31b38c + fdf2149 commit bfa8fe9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
6 changes: 6 additions & 0 deletions include/linux/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,12 @@ struct sk_filter {

DECLARE_STATIC_KEY_FALSE(bpf_stats_enabled_key);

extern struct mutex nf_conn_btf_access_lock;
extern int (*nfct_btf_struct_access)(struct bpf_verifier_log *log, const struct btf *btf,
const struct btf_type *t, int off, int size,
enum bpf_access_type atype, u32 *next_btf_id,
enum bpf_type_flag *flag);

typedef unsigned int (*bpf_dispatcher_fn)(const void *ctx,
const struct bpf_insn *insnsi,
unsigned int (*bpf_func)(const void *,
Expand Down
19 changes: 0 additions & 19 deletions include/net/netfilter/nf_conntrack_bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@
#ifndef _NF_CONNTRACK_BPF_H
#define _NF_CONNTRACK_BPF_H

#include <linux/bpf.h>
#include <linux/btf.h>
#include <linux/kconfig.h>
#include <linux/mutex.h>

#if (IS_BUILTIN(CONFIG_NF_CONNTRACK) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) || \
(IS_MODULE(CONFIG_NF_CONNTRACK) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))

extern int register_nf_conntrack_bpf(void);
extern void cleanup_nf_conntrack_bpf(void);

extern struct mutex nf_conn_btf_access_lock;
extern int (*nfct_bsa)(struct bpf_verifier_log *log, const struct btf *btf,
const struct btf_type *t, int off, int size,
enum bpf_access_type atype, u32 *next_btf_id,
enum bpf_type_flag *flag);

#else

static inline int register_nf_conntrack_bpf(void)
Expand All @@ -31,16 +22,6 @@ static inline void cleanup_nf_conntrack_bpf(void)
{
}

static inline int nf_conntrack_btf_struct_access(struct bpf_verifier_log *log,
const struct btf *btf,
const struct btf_type *t, int off,
int size, enum bpf_access_type atype,
u32 *next_btf_id,
enum bpf_type_flag *flag)
{
return -EACCES;
}

#endif

#endif /* _NF_CONNTRACK_BPF_H */
18 changes: 9 additions & 9 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -8608,11 +8608,11 @@ static bool tc_cls_act_is_valid_access(int off, int size,
DEFINE_MUTEX(nf_conn_btf_access_lock);
EXPORT_SYMBOL_GPL(nf_conn_btf_access_lock);

int (*nfct_bsa)(struct bpf_verifier_log *log, const struct btf *btf,
const struct btf_type *t, int off, int size,
enum bpf_access_type atype, u32 *next_btf_id,
enum bpf_type_flag *flag);
EXPORT_SYMBOL_GPL(nfct_bsa);
int (*nfct_btf_struct_access)(struct bpf_verifier_log *log, const struct btf *btf,
const struct btf_type *t, int off, int size,
enum bpf_access_type atype, u32 *next_btf_id,
enum bpf_type_flag *flag);
EXPORT_SYMBOL_GPL(nfct_btf_struct_access);

static int tc_cls_act_btf_struct_access(struct bpf_verifier_log *log,
const struct btf *btf,
Expand All @@ -8628,8 +8628,8 @@ static int tc_cls_act_btf_struct_access(struct bpf_verifier_log *log,
flag);

mutex_lock(&nf_conn_btf_access_lock);
if (nfct_bsa)
ret = nfct_bsa(log, btf, t, off, size, atype, next_btf_id, flag);
if (nfct_btf_struct_access)
ret = nfct_btf_struct_access(log, btf, t, off, size, atype, next_btf_id, flag);
mutex_unlock(&nf_conn_btf_access_lock);

return ret;
Expand Down Expand Up @@ -8708,8 +8708,8 @@ static int xdp_btf_struct_access(struct bpf_verifier_log *log,
flag);

mutex_lock(&nf_conn_btf_access_lock);
if (nfct_bsa)
ret = nfct_bsa(log, btf, t, off, size, atype, next_btf_id, flag);
if (nfct_btf_struct_access)
ret = nfct_btf_struct_access(log, btf, t, off, size, atype, next_btf_id, flag);
mutex_unlock(&nf_conn_btf_access_lock);

return ret;
Expand Down
5 changes: 3 additions & 2 deletions net/netfilter/nf_conntrack_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <linux/bpf_verifier.h>
#include <linux/bpf.h>
#include <linux/btf.h>
#include <linux/filter.h>
#include <linux/mutex.h>
#include <linux/types.h>
#include <linux/btf_ids.h>
Expand Down Expand Up @@ -502,7 +503,7 @@ int register_nf_conntrack_bpf(void)
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_CLS, &nf_conntrack_kfunc_set);
if (!ret) {
mutex_lock(&nf_conn_btf_access_lock);
nfct_bsa = _nf_conntrack_btf_struct_access;
nfct_btf_struct_access = _nf_conntrack_btf_struct_access;
mutex_unlock(&nf_conn_btf_access_lock);
}

Expand All @@ -512,6 +513,6 @@ int register_nf_conntrack_bpf(void)
void cleanup_nf_conntrack_bpf(void)
{
mutex_lock(&nf_conn_btf_access_lock);
nfct_bsa = NULL;
nfct_btf_struct_access = NULL;
mutex_unlock(&nf_conn_btf_access_lock);
}

0 comments on commit bfa8fe9

Please sign in to comment.