Commit Graph

547 Commits

Author SHA1 Message Date
3b200d0153 nat64: reinstate atomic operations
Turns out the atomics just needed to operate on a 64-bit variable, we
didn't actually need a newer compiler.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-09-30 23:11:15 +02:00
b6a3775b6a nat64: Fix header rewrites
Endianness fixes for IP header length, need to also rewrite Ethernet
protocol. Also use direct packet access instead of skb_store_bytes().

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-09-30 22:35:59 +02:00
666219515f nat64: Add license declaration to BPF file
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-09-30 22:35:59 +02:00
cff5001225 nat64: Fix LPM lookup from kernel side
Needs the same struct for lookup as the userspace side does, so share the
struct definition.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-09-30 22:35:59 +02:00
c6ee3bf574 Fix default NAT64 address
Typoed the RFC prefix.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-09-30 16:59:32 +02:00
ede4270320 nat64-bpf: Initial version
This adds an initial version of a NAT64 translator in BPF. It compiles and
loads, but doesn't actually appear to work yet.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-09-29 01:46:09 +02:00
c7e3acf5d0 common.mk: support generating skeletons for BPF object files
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-09-29 01:44:49 +02:00
9d975cdf29 BTF-playground: Add btf_module_read.c example
This is based on kernel selftests/bpf:

 tools/testing/selftests/bpf/prog_tests/btf_module.c

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-09-10 18:16:18 +02:00
851e0f35de BTF-playground: Add Makefile
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-09-10 18:15:37 +02:00
8016cec65c lib: update libbpf submodule version
Remember that xdp-project have fork of libbpf we use
 https://github.com/xdp-project/libbpf

Synced to this libbpf via running command:
 git submodule update --remote

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-09-10 17:44:00 +02:00
c690c0d7d0 headers: Update linux/btf.h to contain BTF_KIND_FLOAT
This was added in kernel commit:
 8fd886911a6a ("bpf: Add BTF_KIND_FLOAT to uapi") (Author: Ilya Leoshkevich)

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-09-10 17:06:58 +02:00
bdbc2aa6ee ktrace-CO-RE/ktrace01_kern: kprobe changed name to .isra.0
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-09-10 13:45:42 +02:00
7a845a0901 ktrace-CO-RE: Fix compile failure due to missing vmlinux_arch.h
Fixes pull request #24

I had forgot to git add headers/vmlinux/vmlinux_arch.h in PR#24
which caused compile failures for ktrace-CO-RE.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-08-25 08:48:51 +02:00
8230f5de9c lib: update libbpf submodule version
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-07-05 15:09:43 +02:00
4a84222578 Merge pull request #24 from netoptimizer/ktrace01-CO-RE.public
BPF example with ktrace and CO-RE
2021-06-24 21:05:00 +02:00
0542d8a7a3 ktrace-CO-RE/ktrace01: Add --debug option to userspace loader
Use this --debug to better understand what libbpf does of
CO-RE relocation tricks and lookup of BTF-IDs.

Example output:

 [...]
 libbpf: loading kernel BTF '/sys/kernel/btf/vmlinux': 0
 libbpf: map 'ktrace01.data': created successfully, fd=4
 libbpf: sec 'kprobe/udp_send_skb': found 4 CO-RE relocations
 libbpf: prog 'udp_send_skb': relo #0: kind <byte_off> (0), spec is [2] struct pt_regs.di (0:14 @ offset 112)
 libbpf: CO-RE relocating [0] struct pt_regs: found target candidate [176] struct pt_regs in [vmlinux]
 libbpf: prog 'udp_send_skb': relo #0: matching candidate #0 [176] struct pt_regs.di (0:14 @ offset 112)
 libbpf: prog 'udp_send_skb': relo #0: patched insn #0 (LDX/ST/STX) off 112 -> 112
 libbpf: prog 'udp_send_skb': relo #1: kind <byte_off> (0), spec is [7] struct sk_buff___local.hash (0:1 @ offset 4)
 libbpf: CO-RE relocating [0] struct sk_buff___local: found target candidate [2965] struct sk_buff in [vmlinux]
 [...]

Notice how the BTF-ID of 'struct sk_buff' is resolved to be 2965.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-06-24 17:55:58 +02:00
2390b4b110 ktrace-CO-RE: Find running kernels BTF_ID for struct sk_buff
Using bpf_core_type_id_kernel to find kernels BTF_ID for SKB.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-06-24 14:34:31 +02:00
a84f197e7e Merge pull request #16 from simosund/pping_Better_output
Pping better output
2021-06-24 14:28:19 +02:00
e0298638bd iktrace-CO-RE/ktrace01_kern.c: use attribute preserve_access_index
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-06-24 13:12:43 +02:00
7a05622440 ktrace-CO-RE: ktrace01 userspace side cleanup program
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-06-24 11:40:43 +02:00
4dc38c35b9 ktrace-CO-RE: ktrace01_kern.c print more info from SKB
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-06-24 09:02:19 +02:00
32fc35f527 pping: Update README with info on output formats
Update README, mainly add a new section with a brief descriptions and
some examples of the output formats.

Also, update the files and maps list to reflect recent changes (BPF
programs can now push flow-events, and the map rtt_events has been
renamed to just events.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:26 +02:00
d85329f728 pping: Refactor output code
Simplify the three output functions by breaking them up into smaller
helper functions. Also introduce the pping_event union, which can hold
either an rtt_event or flow_event.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:26 +02:00
1975367a3a pping: Add end-of-flow message from userspace map cleanup
Make the flow_timeout function call the current output function to
simulate a flow-closing event. Also some other minor cleanup/fixes.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:26 +02:00
543f75c9d8 pping: Add support for "flow events"
Add "flow events" (flow opening or closing so far) which will trigger
a printout of message.

Note: The ppviz format will only print out the traditional rtt events
as the format does not include opening/closing messages.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:26 +02:00
399c9dc935 pping: Refactor json code and format
Use a JSON-writer library from iproute instead of complicated printf
statement. Also output timestamp, rtt and min_rtt as integers in
nanoseconds, rather than floats in seconds.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:26 +02:00
148d4a26f3 pping: Change order of format_ip_address parameters
Change order of parameters for format_ip_address to follow the
convention of the printf functions where buffer is placed first,
instead of the conventions of the inet_ntop functions where buffer is
placed last.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
f96cfb7d7c pping: Track nr sent/received packets and bytes
Add per-flow tracking of number of packets and bytes
sent/received. Add these to the JSON output format.

Also update README regarding concurrency issue when updating these
statistics.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
fb454cd716 pping: Update README with info on concurrency issues
Also, remove comments about concurrency issues from code in
pping_kern.c as it is now documented in README.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
d92109b3c8 pping: Replace -j and -m options with -F/--format
The format option can take the values "standard" (default), "json" and
ppviz (new name for "machine-friendly").

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
3011bbb0b8 pping: Add "machine friendly" format
Add Kathie's "machine friendly" as an optional output format when
passing '-m' or '--machine-friendly' to pping. This format can be used
together with Kathie's ppviz tool to visaulize the output.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
0ed39800d0 pping: Add JSON output format
Add the option to output in JSON format by passing '-j' or '--json' to
pping. Include the protocol in the JSON format, and fix so kernel-side
actually stores the protocol in the flow_address struct.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
b4a810b09b pping: Add timestamp and min-RTT to output
To add timestamp to output, push the timestamp when packet was
processed from kernel as part of the rtt-event. Also keep track of
minimum encountered RTT for each flow in kernel, and also push that as
part of the RTT-event.

Additionally, avoid pushing RTT messages at all if no flow-state
information can be found (due to ex. being deleted from egress side),
as no valid min-RTT can then be given. Furthermore, no longer delete
flow-information once seeing the FIN-flag on egress in order to keep
useful flow-state around for RTT-messages longer. Due to the
FIN-handshake process, it is sufficient if the ingress program deletes
the flow-state upon seeing FIN. However, still delete flow-state from
either ingress or egress upon seeing RST flag, as RST does not have a
handshake process allowing for delayed deletion.

While minimum RTT could also be tracked from the userspace process,
userspace is not aware of when the flow is closed so would have to add
additional logic to keep track of minimum RTT for each flow and
periodically clean them up. Furthermore, keeping RTT statistics in the
flow-state map is useful for implementing future features, such as an
RTT-based sampling interval. It would also be useful in case pping is
changed to no longer have a long-running userspace process printing
out all the calculated RTTs, but instead simply occasionally looks up
the RTT from the flow-state map.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
0c8df86a5e Merge branch 'dhcp-relay-pr' 2021-06-21 22:52:31 +02:00
cb9fc3025a Add DHCP relay program.
Initial working version of DHCP relay using XDP is created. Currently, this code
has user program and a xdp ebpf program. User program takes network interface and
dhcp relay server IP as inputs and store it in a map. XDP program filters the
incoming DHCP requests and inserts option 82 in the DHCP request packets and
overwrites the destination IP to that of DHCP relay server IP.An optional argu
-ment for user program is also provided to unload the xdp program.

README file provides to instructions to build and load the xdp program.

Signed-off-by: Sachin Tiptur <sachin.tiptur.satyanarayana.gupta@hof-university.de>
[ whitespace fixes ]
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-06-21 22:51:57 +02:00
9fe9b5efd2 preserve-dscp: Add a warning about data leakage to the README
There's a reason why Wireguard doesn't preserve DSCP marks across the
encapsulation, so let's make sure we warn about bypassing this in the
README.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-06-18 01:30:36 +02:00
7bb3c6ac91 Add preserve-dscp example for preserving a DSCP mark over encapsulation
This is a fun example showing how to use BPF to preserve DSCP values across
an encapsulating interface, such as Wireguard. It relies on the
encapsulation layer preserving the skb->hash value across the
encapsulation, which is commonly the case on kernel encapsulation
protocols (including Wireguard), and uses a pair of TC BPF programs and a
map to re-match the packets after encapsulation and add back the DSCP
value.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-06-18 00:56:08 +02:00
dabfe929ae xdp/parsing_helpers: Check IP protocol version when parsing
Add a check that the protocol version field matches the expected value when
parsing IPv4 and IPv6 headers. This makes it possible to parse an IP header
that we don't know the version of (such as on interfaces that don't use an
Ethernet header).

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-06-18 00:56:08 +02:00
21d5dc3961 ktrace-CO-RE: Cleanup ktrace01_kern.c
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-06-17 13:10:59 +02:00
942f028cce include/bpf: extend __bpf_memcpy() by another 8 bytes
Seems we need to copy a few more bytes at once for the DHCP relay daemon,
so let's extend __bpf_memcpy to handle copies of up to 288 bytes.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-06-15 00:12:53 +02:00
599646aa64 ktrace-CO-RE: Add bpf_printk statement in code
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-06-11 18:20:47 +02:00
566a14cb47 ktrace-CO-RE: Doc how I used bpftrace as pre-investigate tool
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-06-11 18:19:46 +02:00
13339a9760 ktrace-CO-RE: read /sys/kernel/debug/tracing/trace_pipe
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-06-11 18:18:36 +02:00
e26e1b970e ktrace-CO-RE: Cleanup
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-06-11 17:12:38 +02:00
5561e4c475 Merge pull request #20 from simosund/pping_add_presentation
Add pping presentations
2021-06-08 23:35:59 +02:00
fc31c8f27d pping: Add presentation from Bufferbloat meeting 2021-06-08
Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-08 23:18:57 +02:00
54c0d52dd8 ktrace-CO-RE: README explain CPU architecture challenges
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-06-02 10:39:12 +02:00
b0536ce4ec lib: Add lib/util for adding utility library code
Add the directory and Makefile rules to prepare for storing library
functions in lib/util like we do in xdp-tools. With this, library code can
be added by just dropping the .c and .h into lib/util and updating
lib/util/util.mk with the object name.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-06-01 17:16:24 +02:00
ff5fef3dc9 headers/vmlinux: Add more archs powerpc and arm64
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-06-01 17:05:28 +02:00
3bc8e68636 configure: check for bpf_tc_attach() in libbpf
We want to be able to use the new bpf_tc_attach() function for attaching TC
programs, so check for it in configure.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-06-01 17:03:18 +02:00