Skip to content

Helper function bpf_skb_change_type

v4.8

Definition

Copyright (c) 2015 The Libbpf Authors. All rights reserved.

Change the packet type for the packet associated to skb. This comes down to setting skb->pkt_type to type, except the eBPF program does not have a write access to skb\ ->pkt_type beside this helper. Using a helper here allows for graceful handling of errors.

The major use case is to change incoming _skb_s to PACKET_HOST in a programmatic way instead of having to recirculate via redirect(..., BPF_F_INGRESS), for example.

Note that type only allows certain values. At this time, they are:

PACKET_HOST

    Packet is for us.

PACKET_BROADCAST

    Send packet to all.

PACKET_MULTICAST

    Send packet to group.

PACKET_OTHERHOST

    Send packet to someone else.

Returns

0 on success, or a negative error in case of failure.

static long (* const bpf_skb_change_type)(struct __sk_buff *skb, __u32 type) = (void *) 32;

Usage

Docs could be improved

This part of the docs is incomplete, contributions are very welcome

Program types

This helper call can be used in the following program types:

Example

Docs could be improved

This part of the docs is incomplete, contributions are very welcome