History

bpf: add helpers to access tunnel metadata

Introduce helpers to let eBPF programs attached to TC manipulate tunnel metadata: bpf_skb_[gs]et_tunnel_key(skb, key, size, flags) skb: pointer to skb key: pointer to 'struct bpf_tunnel_key' size: size of 'struct bpf_tunnel_key' flags: room for future extensions First eBPF program that uses these helpers will allocate per_cpu metadata_dst structures that will be used on TX. On RX metadata_dst is allocated by tunnel driver. Typical usage for TX: struct bpf_tunnel_key tkey; ... populate tkey ... bpf_skb_set_tunnel_key(skb, &tkey, sizeof(tkey), 0); bpf_clone_redirect(skb, vxlan_dev_ifindex, 0); RX: struct bpf_tunnel_key tkey = {}; bpf_skb_get_tunnel_key(skb, &tkey, sizeof(tkey), 0); ... lookup or redirect based on tkey ... 'struct bpf_tunnel_key' will be extended in the future by adding elements to the end and the 'size' argument will indicate which fields are populated, thereby keeping backwards compatibility. The 'flags' argument may be used as well when the 'size' is not enough or to indicate completely different layout of bpf_tunnel_key.

Alexei Starovoitov committed 11 years ago

Commit d3aa45c1 parent 55d7de94 files · +124 −6Browse files

Showing the changes to include/uapi (1 of 4 files). Show all

Unified · Split

include/uapi/linux/bpf.h+17−0
@@ -258,6 +258,18 @@ enum bpf_func_id { · 257 unmodified lines
258258 BPF_FUNC_get_cgroup_classid,
259259 BPF_FUNC_skb_vlan_push, /* bpf_skb_vlan_push(skb, vlan_proto, vlan_tci) */
260260 BPF_FUNC_skb_vlan_pop, /* bpf_skb_vlan_pop(skb) */
261+
262+ /**
263+ * bpf_skb_[gs]et_tunnel_key(skb, key, size, flags)
264+ * retrieve or populate tunnel metadata
265+ * @skb: pointer to skb
266+ * @key: pointer to 'struct bpf_tunnel_key'
267+ * @size: size of 'struct bpf_tunnel_key'
268+ * @flags: room for future extensions
269+ * Retrun: 0 on success
270+ */
271+ BPF_FUNC_skb_get_tunnel_key,
272+ BPF_FUNC_skb_set_tunnel_key,
261273 __BPF_FUNC_MAX_ID,
262274 };
263275
@@ -280,4 +292,9 @@ struct __sk_buff { · 16 unmodified lines
280292 __u32 cb[5];
281293 };
282294
295+struct bpf_tunnel_key {
296+ __u32 tunnel_id;
297+ __u32 remote_ipv4;
298+};
299+
283300 #endif /* _UAPI__LINUX_BPF_H__ */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t