Skip to content

Commit 0b19cc0

Browse files
Toshiaki Makitaborkmann
authored andcommitted
bpf: Make redirect_info accessible from modules
We are going to add kern_flags field in redirect_info for kernel internal use. In order to avoid function call to access the flags, make redirect_info accessible from modules. Also as it is now non-static, add prefix bpf_ to redirect_info. v6: - Fix sparse warning around EXPORT_SYMBOL. Signed-off-by: Toshiaki Makita <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent af87a3a commit 0b19cc0

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

include/linux/filter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,16 @@ struct sk_msg_buff {
537537
struct list_head list;
538538
};
539539

540+
struct bpf_redirect_info {
541+
u32 ifindex;
542+
u32 flags;
543+
struct bpf_map *map;
544+
struct bpf_map *map_to_flush;
545+
unsigned long map_owner;
546+
};
547+
548+
DECLARE_PER_CPU(struct bpf_redirect_info, bpf_redirect_info);
549+
540550
/* Compute the linear packet data range [data, data_end) which
541551
* will be accessed by various program types (cls_bpf, act_bpf,
542552
* lwt, ...). Subsystems allowing direct data access must (!)

net/core/filter.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,19 +2082,12 @@ static const struct bpf_func_proto bpf_clone_redirect_proto = {
20822082
.arg3_type = ARG_ANYTHING,
20832083
};
20842084

2085-
struct redirect_info {
2086-
u32 ifindex;
2087-
u32 flags;
2088-
struct bpf_map *map;
2089-
struct bpf_map *map_to_flush;
2090-
unsigned long map_owner;
2091-
};
2092-
2093-
static DEFINE_PER_CPU(struct redirect_info, redirect_info);
2085+
DEFINE_PER_CPU(struct bpf_redirect_info, bpf_redirect_info);
2086+
EXPORT_PER_CPU_SYMBOL_GPL(bpf_redirect_info);
20942087

20952088
BPF_CALL_2(bpf_redirect, u32, ifindex, u64, flags)
20962089
{
2097-
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
2090+
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
20982091

20992092
if (unlikely(flags & ~(BPF_F_INGRESS)))
21002093
return TC_ACT_SHOT;
@@ -2107,7 +2100,7 @@ BPF_CALL_2(bpf_redirect, u32, ifindex, u64, flags)
21072100

21082101
int skb_do_redirect(struct sk_buff *skb)
21092102
{
2110-
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
2103+
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
21112104
struct net_device *dev;
21122105

21132106
dev = dev_get_by_index_rcu(dev_net(skb->dev), ri->ifindex);
@@ -3200,7 +3193,7 @@ static int __bpf_tx_xdp_map(struct net_device *dev_rx, void *fwd,
32003193

32013194
void xdp_do_flush_map(void)
32023195
{
3203-
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
3196+
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
32043197
struct bpf_map *map = ri->map_to_flush;
32053198

32063199
ri->map_to_flush = NULL;
@@ -3245,7 +3238,7 @@ static inline bool xdp_map_invalid(const struct bpf_prog *xdp_prog,
32453238
static int xdp_do_redirect_map(struct net_device *dev, struct xdp_buff *xdp,
32463239
struct bpf_prog *xdp_prog)
32473240
{
3248-
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
3241+
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
32493242
unsigned long map_owner = ri->map_owner;
32503243
struct bpf_map *map = ri->map;
32513244
u32 index = ri->ifindex;
@@ -3285,7 +3278,7 @@ static int xdp_do_redirect_map(struct net_device *dev, struct xdp_buff *xdp,
32853278
int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,
32863279
struct bpf_prog *xdp_prog)
32873280
{
3288-
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
3281+
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
32893282
struct net_device *fwd;
32903283
u32 index = ri->ifindex;
32913284
int err;
@@ -3317,7 +3310,7 @@ static int xdp_do_generic_redirect_map(struct net_device *dev,
33173310
struct xdp_buff *xdp,
33183311
struct bpf_prog *xdp_prog)
33193312
{
3320-
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
3313+
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
33213314
unsigned long map_owner = ri->map_owner;
33223315
struct bpf_map *map = ri->map;
33233316
u32 index = ri->ifindex;
@@ -3368,7 +3361,7 @@ static int xdp_do_generic_redirect_map(struct net_device *dev,
33683361
int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb,
33693362
struct xdp_buff *xdp, struct bpf_prog *xdp_prog)
33703363
{
3371-
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
3364+
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
33723365
u32 index = ri->ifindex;
33733366
struct net_device *fwd;
33743367
int err = 0;
@@ -3399,7 +3392,7 @@ EXPORT_SYMBOL_GPL(xdp_do_generic_redirect);
33993392

34003393
BPF_CALL_2(bpf_xdp_redirect, u32, ifindex, u64, flags)
34013394
{
3402-
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
3395+
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
34033396

34043397
if (unlikely(flags))
34053398
return XDP_ABORTED;
@@ -3423,7 +3416,7 @@ static const struct bpf_func_proto bpf_xdp_redirect_proto = {
34233416
BPF_CALL_4(bpf_xdp_redirect_map, struct bpf_map *, map, u32, ifindex, u64, flags,
34243417
unsigned long, map_owner)
34253418
{
3426-
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
3419+
struct bpf_redirect_info *ri = this_cpu_ptr(&bpf_redirect_info);
34273420

34283421
if (unlikely(flags))
34293422
return XDP_ABORTED;

0 commit comments

Comments
 (0)