Thread (8 messages) 8 messages, 3 authors, 2021-03-05

Re: [PATCH bpf-next v5 2/2] bpf, xdp: restructure redirect actions

flat view

From: Daniel Borkmann <daniel@iogearbox.net>
Date: 2021-03-05 22:57:07
Also in: bpf

On 3/5/21 6:11 PM, Björn Töpel wrote:
On 2021-03-05 16:44, Daniel Borkmann wrote:
quoted
On 2/27/21 1:21 PM, Björn Töpel wrote:
[...]
quoted
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 008691fd3b58..a7752badc2ec 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -646,11 +646,20 @@ struct bpf_redirect_info {
      u32 flags;
      u32 tgt_index;
      void *tgt_value;
-    struct bpf_map *map;
+    u32 map_id;
+    u32 tgt_type;
      u32 kern_flags;
      struct bpf_nh_params nh;
  };
+enum xdp_redirect_type {
+    XDP_REDIR_UNSET,
+    XDP_REDIR_DEV_IFINDEX,
[...]
quoted
+    XDP_REDIR_DEV_MAP,
+    XDP_REDIR_CPU_MAP,
+    XDP_REDIR_XSK_MAP,
Did you eval whether for these maps we can avoid the redundant def above by just
passing in map->map_type as ri->tgt_type and inferring the XDP_REDIR_UNSET from
invalid map_id of 0 (given the idr will never allocate such)?
I'll take a stab at it!
Sounds good, thanks! If it doesn't simplify or gets worse, we can always stick to
the one here.
quoted
[...]
quoted
@@ -4068,10 +4039,9 @@ BPF_CALL_2(bpf_xdp_redirect, u32, ifindex, u64, flags)
      if (unlikely(flags))
          return XDP_ABORTED;
-    ri->flags = flags;
-    ri->tgt_index = ifindex;
-    ri->tgt_value = NULL;
-    WRITE_ONCE(ri->map, NULL);
+    ri->tgt_type = XDP_REDIR_DEV_IFINDEX;
+    ri->tgt_index = 0;
+    ri->tgt_value = (void *)(long)ifindex;
nit: Bit ugly to pass this in /read out this way, maybe union if we cannot use
tgt_index?
Dito!


Thanks for the input! I'll get back with a v6!


Björn

quoted
quoted
      return XDP_REDIRECT;
  }
diff --git a/net/xdp/xskmap.c b/net/xdp/xskmap.c
index 711acb3636b3..2c58d88aa69d 100644
--- a/net/xdp/xskmap.c
+++ b/net/xdp/xskmap.c
@@ -87,7 +87,6 @@ static void xsk_map_free(struct bpf_map *map)
  {
      struct xsk_map *m = container_of(map, struct xsk_map, map);
-    bpf_clear_redirect_map(map);
      synchronize_net();
      bpf_map_area_free(m);
  }
@@ -229,7 +228,8 @@ static int xsk_map_delete_elem(struct bpf_map *map, void *key)
  static int xsk_map_redirect(struct bpf_map *map, u32 ifindex, u64 flags)
  {
-    return __bpf_xdp_redirect_map(map, ifindex, flags, __xsk_map_lookup_elem);
+    return __bpf_xdp_redirect_map(map, ifindex, flags, __xsk_map_lookup_elem,
+                      XDP_REDIR_XSK_MAP);
  }
  void xsk_map_try_sock_delete(struct xsk_map *map, struct xdp_sock *xs,
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help