bpf: add bpf_skb_change_proto helper
This patch adds a minimal helper for doing the groundwork of changing the skb->protocol in a controlled way. Currently supported is v4 to v6 and vice versa transitions, which allows f.e. for a minimal, static nat64 implementation where applications in containers that still require IPv4 can be transparently operated in an IPv6-only environment. For example, host facing veth of the container can transparently do the transitions in a programmatic way with the help of clsact qdisc and cls_bpf. Idea is to separate concerns for keeping complexity of the helper lower, which means that the programs utilize bpf_skb_change_proto(), bpf_skb_store_bytes() and bpf_lX_csum_replace() to get the job done, instead of doing everything in a single helper (and thus partially duplicating helper functionality). Also, bpf_skb_change_proto() shouldn't need to deal with raw packet data as this is done by other helpers. bpf_skb_proto_6_to_4() and bpf_skb_proto_4_to_6() unclone the skb to operate on a private one, push or pop additionally required header space and migrate the gso/gro meta data from the shared info. We do mark the gso type as dodgy so that headers are checked and segs recalculated by the gso/gro engine. The gso_size target is adapted as well. The flags argument added is currently reserved and can be used for future extensions. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
80b48c4457
commit
6578171a7f
@@ -313,6 +313,20 @@ enum bpf_func_id {
|
||||
*/
|
||||
BPF_FUNC_skb_get_tunnel_opt,
|
||||
BPF_FUNC_skb_set_tunnel_opt,
|
||||
|
||||
/**
|
||||
* bpf_skb_change_proto(skb, proto, flags)
|
||||
* Change protocol of the skb. Currently supported is
|
||||
* v4 -> v6, v6 -> v4 transitions. The helper will also
|
||||
* resize the skb. eBPF program is expected to fill the
|
||||
* new headers via skb_store_bytes and lX_csum_replace.
|
||||
* @skb: pointer to skb
|
||||
* @proto: new skb->protocol type
|
||||
* @flags: reserved
|
||||
* Return: 0 on success or negative error
|
||||
*/
|
||||
BPF_FUNC_skb_change_proto,
|
||||
|
||||
__BPF_FUNC_MAX_ID,
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user