Coder Social home page Coder Social logo

Comments (3)

cfc4n avatar cfc4n commented on July 2, 2024 1
    u64 flags = BPF_F_CURRENT_CPU;
    flags |= (u64)skb->len << 32;
    size_t pkt_size = TC_PACKET_MIN_SIZE;
    bpf_perf_event_output(skb, &skb_events, flags, &event, pkt_size);

重点是flags参数, 以及 bpf_perf_event_output 函数的使用。

long bpf_perf_event_output(void *ctx, struct bpf_map *map, u64
flags, void *data, u64 size)

          Description
                 Write raw data blob into a special BPF perf event
                 held by map of type BPF_MAP_TYPE_PERF_EVENT_ARRAY.
                 This perf event must have the following attributes:
                 PERF_SAMPLE_RAW as sample_type, PERF_TYPE_SOFTWARE
                 as type, and PERF_COUNT_SW_BPF_OUTPUT as config.

                 The flags are used to indicate the index in map for
                 which the value must be put, masked with
                 BPF_F_INDEX_MASK.  Alternatively, flags can be set
                 to BPF_F_CURRENT_CPU to indicate that the index of
                 the current CPU core should be used.

                 The value to write, of size, is passed through eBPF
                 stack and pointed by data.

                 The context of the program ctx needs also be passed
                 to the helper.

                 On user space, a program willing to read the values
                 needs to call perf_event_open() on the perf event
                 (either for one or for all CPUs) and to store the
                 file descriptor into the map. This must be done
                 before the eBPF program can send data into it. An
                 example is available in file
                 samples/bpf/trace_output_user.c in the Linux kernel
                 source tree (the eBPF program counterpart is in
                 samples/bpf/trace_output_kern.c).

                 bpf_perf_event_output() achieves better performance
                 than bpf_trace_printk() for sharing data with user
                 space, and is much better suitable for streaming
                 data from eBPF programs.

                 Note that this helper is not restricted to tracing
                 use cases and can be used with programs attached to
                 TC or XDP as well, where it allows for passing data
                 to user space listeners. Data can be:

                 • Only custom structs,

                 • Only the packet payload, or

                 • A combination of both.

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

Linux Kernel demo : https://elixir.bootlin.com/linux/v5.4/source/samples/bpf/xdp_sample_pkts_kern.c

from ecapture.

cfc4n avatar cfc4n commented on July 2, 2024

还有其他问题吗?

from ecapture.

caffe-in avatar caffe-in commented on July 2, 2024

没有了,谢谢您慷慨的解答'◡'

from ecapture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.