@@ -90,22 +90,64 @@ the ``data_meta`` pointer.
90
90
In the future, we'd like to support a case where an XDP program
91
91
can override some of the metadata used for building ``skbs ``.
92
92
93
- bpf_redirect_map
94
- ================
95
-
96
- ``bpf_redirect_map `` can redirect the frame to a different device.
97
- Some devices (like virtual ethernet links) support running a second XDP
98
- program after the redirect. However, the final consumer doesn't have
99
- access to the original hardware descriptor and can't access any of
100
- the original metadata. The same applies to XDP programs installed
101
- into devmaps and cpumaps.
102
-
103
- This means that for redirected packets only custom metadata is
104
- currently supported, which has to be prepared by the initial XDP program
105
- before redirect. If the frame is eventually passed to the kernel, the
106
- ``skb `` created from such a frame won't have any hardware metadata populated
107
- in its ``skb ``. If such a packet is later redirected into an ``XSK ``,
108
- that will also only have access to the custom metadata.
93
+ XDP_REDIRECT
94
+ ============
95
+
96
+ The ``XDP_REDIRECT `` action forwards an XDP frame to another net device or a CPU
97
+ (via cpumap/devmap) for further processing. It is invoked using BPF helpers like
98
+ ``bpf_redirect_map() `` or ``bpf_redirect() ``. When an XDP frame is redirected,
99
+ the recipient (e.g., an XDP program on a veth device, or the kernel stack via
100
+ cpumap) loses direct access to the original NIC's hardware descriptor and thus
101
+ its hardware metadata
102
+
103
+ By default, this loss of access means that if an ``xdp_frame `` is redirected and
104
+ then converted to an ``skb ``, its ``skb `` fields for hardware-derived metadata
105
+ (like ``skb->hash `` or VLAN info) are not populated from the original
106
+ packet. This can impact features like Generic Receive Offload (GRO). While XDP
107
+ programs can manually save custom data (e.g., using ``bpf_xdp_adjust_meta() ``),
108
+ propagating specific *hardware * RX hints to ``skb `` creation requires using the
109
+ kfuncs described below.
110
+
111
+ To enable propagating selected hardware RX hints, store BPF kfuncs allow an
112
+ XDP program on the initial NIC to read these hints and then explicitly
113
+ *store * them. The kfuncs place this metadata in locations associated with
114
+ the XDP packet buffer, making it available if an ``skb `` is later built or
115
+ the frame is otherwise processed. For instance, RX hash and VLAN tags are
116
+ stored within the XDP frame's addressable headroom, while RX timestamps are
117
+ typically written to an area corresponding to ``skb_shared_info ``.
118
+
119
+ **Crucially, the BPF programmer must call these "store" kfuncs to save the
120
+ desired hardware hints for propagation. ** The system does not do this
121
+ automatically. The NIC driver is responsible for ensuring sufficient headroom is
122
+ available; kfuncs may return ``-ENOSPC `` if space is inadequate for storing
123
+ these hints.
124
+
125
+ When these kfuncs are used to store hints before redirection:
126
+
127
+ * If the ``xdp_frame `` is converted to an ``skb ``, the networking stack can use
128
+ the stored hints to populate ``skb `` fields (e.g., ``skb->hash ``,
129
+ ``skb->vlan_tci ``, timestamps), aiding netstack features like GRO.
130
+ * When running a second XDP-program after the redirect. The veth driver supports
131
+ access to the previous stored metadata is accessed though the normal reader
132
+ kfuncs.
133
+
134
+ Kfuncs are available for storing RX hash (``bpf_xdp_store_rx_hash() ``),
135
+ VLAN information (``bpf_xdp_store_rx_vlan() ``), and hardware timestamps
136
+ (``bpf_xdp_store_rx_ts() ``). Consult the kfunc API documentation for usage
137
+ details, expected data, return codes, and relevant XDP flags that may
138
+ indicate success or metadata availability.
139
+
140
+ Kfuncs for **store ** operations:
141
+
142
+ .. kernel-doc :: net/core/xdp.c
143
+ :identifiers: bpf_xdp_store_rx_timestamp
144
+
145
+ .. kernel-doc :: net/core/xdp.c
146
+ :identifiers: bpf_xdp_store_rx_hash
147
+
148
+ .. kernel-doc :: net/core/xdp.c
149
+ :identifiers: bpf_xdp_store_rx_vlan_tag
150
+
109
151
110
152
bpf_tail_call
111
153
=============
0 commit comments