bpf: add bpf_skb_change_type helper
This work adds a helper for changing skb->pkt_type in a controlled way. We only allow a subset of possible values and can extend that in future should other use cases come up. Doing this as a helper has the advantage that errors can be handeled gracefully and thus helper kept extensible. It's a write counterpart to pkt_type member we can already read from struct __sk_buff context. Major use case is to change incoming skbs to PACKET_HOST in a programmatic way instead of having to recirculate via redirect(..., BPF_F_INGRESS), for example. 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
6578171a7f
commit
d2485c4242
@@ -327,6 +327,15 @@ enum bpf_func_id {
|
||||
*/
|
||||
BPF_FUNC_skb_change_proto,
|
||||
|
||||
/**
|
||||
* bpf_skb_change_type(skb, type)
|
||||
* Change packet type of skb.
|
||||
* @skb: pointer to skb
|
||||
* @type: new skb->pkt_type type
|
||||
* Return: 0 on success or negative error
|
||||
*/
|
||||
BPF_FUNC_skb_change_type,
|
||||
|
||||
__BPF_FUNC_MAX_ID,
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user