Skip to content

Commit 7c5db7e

Browse files
Jakub Kicinskidavem330
authored andcommitted
netdevsim: don't compile BPF code if syscall not enabled
We should not compile netdevsim/bpf.c if BPF syscall is not enabled. Otherwise bpf core would have to provide wrappers for all functions offload drivers may call, even though system will never see a BPF object. Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Quentin Monnet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent caf9522 commit 7c5db7e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

drivers/net/netdevsim/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ obj-$(CONFIG_NETDEVSIM) += netdevsim.o
44

55
netdevsim-objs := \
66
netdev.o \
7-
bpf.o \
7+
8+
ifeq ($(CONFIG_BPF_SYSCALL),y)
9+
netdevsim-objs += \
10+
bpf.o
11+
endif

drivers/net/netdevsim/netdevsim.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,40 @@ struct netdevsim {
6868

6969
extern struct dentry *nsim_ddir;
7070

71+
#ifdef CONFIG_BPF_SYSCALL
7172
int nsim_bpf_init(struct netdevsim *ns);
7273
void nsim_bpf_uninit(struct netdevsim *ns);
7374
int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf);
7475
int nsim_bpf_disable_tc(struct netdevsim *ns);
7576
int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
7677
void *type_data, void *cb_priv);
78+
#else
79+
static inline int nsim_bpf_init(struct netdevsim *ns)
80+
{
81+
return 0;
82+
}
83+
84+
static inline void nsim_bpf_uninit(struct netdevsim *ns)
85+
{
86+
}
87+
88+
static inline int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
89+
{
90+
return bpf->command == XDP_QUERY_PROG ? 0 : -EOPNOTSUPP;
91+
}
92+
93+
static inline int nsim_bpf_disable_tc(struct netdevsim *ns)
94+
{
95+
return 0;
96+
}
97+
98+
static inline int
99+
nsim_bpf_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
100+
void *cb_priv)
101+
{
102+
return -EOPNOTSUPP;
103+
}
104+
#endif
77105

78106
static inline struct netdevsim *to_nsim(struct device *ptr)
79107
{

0 commit comments

Comments
 (0)