• Joanne Koong's avatar
    bpf: Add skb dynptrs · b5964b96
    Joanne Koong authored
    Add skb dynptrs, which are dynptrs whose underlying pointer points
    to a skb. The dynptr acts on skb data. skb dynptrs have two main
    benefits. One is that they allow operations on sizes that are not
    statically known at compile-time (eg variable-sized accesses).
    Another is that parsing the packet data through dynptrs (instead of
    through direct access of skb->data and skb->data_end) can be more
    ergonomic and less brittle (eg does not need manual if checking for
    being within bounds of data_end).
    
    For bpf prog types that don't support writes on skb data, the dynptr is
    read-only (bpf_dynptr_write() will return an error)
    
    For reads and writes through the bpf_dynptr_read() and bpf_dynptr_write()
    interfaces, reading and writing from/to data in the head as well as from/to
    non-linear paged buffers is supported. Data slices through the
    bpf_dynptr_data API are not supported; instead bpf_dynptr_slice() and
    bpf_dynptr_slice_rdwr() (added in subsequent commit) should be used.
    
    For examples of how skb dynptrs can be used, please see the attached
    selftests.
    Signed-off-by: default avatarJoanne Koong <joannelkoong@gmail.com>
    Link: https://lore.kernel.org/r/20230301154953.641654-8-joannelkoong@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    b5964b96
helpers.c 59.4 KB