Commit Graph

163 Commits

Author SHA1 Message Date
3bd3333c69 pping: Update and linebreak TODO
Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-03-02 17:49:36 +01:00
1446e6edec pping: Load tc-bpf program with libbpf
Load and pin the tc-bpf program in pping.c using libbpf, and only
attach the pinned program using iproute. That way, can use features
that are not supported by the old iproute loader, even if iproute does
not have libbpf support.

To support this change, extend bpf_egress_loader with option to load
pinned program. Additionally, remove configure script and parts of
Makefile that are no longer needed. Furthermore, remove multiple
definitions of ts_start map, and place singular definition in
pping_helpers.h which is included by both BPF programs.

Also, some minor fixes based on Toke's review.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-03-02 17:40:51 +01:00
1282bce7d8 pping: Update sampling design document
Update SAMPLING_DESIGN.md, partly based on discussions during the
meeting with Red Hat on 2021-03-01.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-03-01 20:09:21 +01:00
cecd6b54f2 pping: Inital rate limit implementation
Add a per-flow rate limit, limiting how often new timestamp entries
can be created. As part of this, add per-flow state keeping track
of when last timestamp was created and last seen identifier for each
flow.

Additionally, remove timestamp entry as soon as RTT is
calculated, as last seen identifier is used to find first unique value
instead. Furthermore, remove packet_timestamp struct and only use
__u64 as timestamp, as used memeber is no longer needed.

This initial commit lacks cleanup of flow-state, user-configuration of
rate limit, mechanism to handle bursts etc.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-03-01 18:16:48 +01:00
6e5136092d pping: Update sampling design document
Add sections on per-flow state, graceful degradation and some
implementation considerations.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-26 12:38:53 +01:00
ae1d89c7c9 pping: Add document about sampling design
Add a document outlining my thoughts for how to implement
sampling. Intended both as a basis for discussion, as well as being a
form of documentation.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-25 19:00:41 +01:00
a9c276cb54 pping: Update TODO-list
Rewrite/regroup/reorder some points for the General pping
section. Also add some new points, add some additional comments to
existing points, and check in the "Skip pure ACKs" as complated.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-25 16:33:26 +01:00
97fdefa90d pping: Make the link to Kathie's original pping utility clearer
The link to the original pping utility was easy to miss, and we didn't
credit Kathie with its implementation. That was clearly an oversight, so
let's fix that.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-02-25 11:18:44 +01:00
7f1868ac5c Merge pull request #10 from simosund/pping_IPv6
pping: Add IPv6 support
2021-02-16 14:02:39 +01:00
a2c6b0618b pping: Use designated initialization for parsing_context
Change how intitalization of pctx is done in tc and xdp
programs. Also, len to pkt_len in parsing_context.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-16 13:16:12 +01:00
7fe1d282ae pping: Minor refactor of parsing_context
Refactor parsing_context to have a len member instead of
data_end_end. Also, refactor parse_tcp_identifier to take pointers
directly to the ports instead of the flow_address structs.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-16 12:34:19 +01:00
641080a8a6 Merge pull request #12 from xdp-project/refactor01-include-dir.public
Refactor include directories and doc repo via README files
2021-02-15 17:25:09 +01:00
a25992973d Adjustments to README based on Toke's review
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-15 17:18:38 +01:00
219e962832 pping: Avoid timestamping pure TCP ACKs
Add a parsing_context struct to keep track data, data_end and
currently parsed position, as well as handling the difference between
data_end for XDP and TC through data_end_end pointer.

Use parsing_context struct to detect pure TCP ACKs, and avoid creating
identifier for them on egress (to avoid creating timestamp
entries). This solves issue of calculating RTTs in inproper contexts.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-12 18:31:30 +01:00
b5fd346589 Move jhash out of headers/linux into include/
It is a bit strange we have this header file in this repo, but
it likely be very useful later.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-12 18:06:51 +01:00
d5031bfc92 headers/linux: add netlink.h from kernel source v5.11-rc7
This is included by linux/if_link.h.  Thus, we need it here if the
distro doesn't provide this include file.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-12 18:03:48 +01:00
10abd546ca headers/linux: update if_link.h and if_xdp.h from kernel v5.11-rc7
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-12 18:01:02 +01:00
27765e8449 headers/linux: update bpf.h from kernel source v5.11-rc7
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-12 17:55:17 +01:00
3a92b67a53 headers/linux: Add missing bpf_common.h
The include file linux/bpf_common.h was missing.  This is used/included
via linux/bpf.h.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-12 17:40:09 +01:00
7aee417036 Add README for headers/linux/ directory
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-12 17:22:12 +01:00
502663f354 pping: Update TODO.md
Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-12 12:09:37 +01:00
397b44cff7 pping: Refactor parse_packet_identifer
Remove the saddr and daddr parmeters from parse_packet_identifier, and
use the is_egress parmeter to perform the saddr/daddr swap inside the
function. Also, minor style fixes.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-12 11:40:43 +01:00
0264295d67 Add toplevel README describing project
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-09 19:32:41 +01:00
23ae3dcf45 Remove bpf_helper_defs.h as this comes via libbpf
The bpf_helper_defs.h is used by (ibbpf provided) bpf/bpf_helpers.h.
Thus, it doesn't belong under headers/ directory.

Remove file: headers/bpf/bpf_helper_defs.h

Fixes: f0fce8f62b ("Update kernel headers and libbpf version")
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-09 18:13:57 +01:00
3268ba87bb pping: Refactor TC and XDP programs
Refactor TC and XDP programs to reuse common logic for parsing
packets. Add functions for parsing packets for an identifier to
pping_helpers.h which both TC and XDP parts use. Also make it easier
to extend pping with support for new protocols, as only new parsing
functions have to be added and inserted into a single place.

Also add reserved members to end of structs in pping.h to indicate
padding.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-09 18:09:30 +01:00
9bf3ee7010 Add headers/README explaining use of directory
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-09 17:43:21 +01:00
5cf96508df Move parsing_helpers.h into new include directory
Adjust makefile construct to use the new include direcory.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-09 17:03:55 +01:00
d59095d39f Remove libxdp header files not used by any bpf-examples
When some bpf example use libxdp then these can be re-added, along
with description of why projects needs to include these files.

Files removed:
 headers/xdp/libxdp.h
 headers/xdp/prog_dispatcher.h
 headers/xdp/xdp_helpers.h

Fixes: 4513664ca3 ("Initial import with encap-forward example")
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-09 16:58:19 +01:00
bb48f0e8aa Remove header files not used by any bpf-examples
Files removed:
 headers/xdp/xdp_stats_kern.h
 headers/xdp/xdp_stats_kern_user.h

Fixes: 4513664ca3 ("Initial import with encap-forward example")
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-09 16:49:13 +01:00
fb01b49ec0 configure: add detection for missing header files for errno.h
It is fairly natural to include <errno.h> in BPF programs as some
helpers and hooks use these errno defines (like lsm-nobpf/).  Again we
discover that when compiling with clang option[1] "-target bpf" the OS
distros header files gets confused as __x86_64__ isn't define by clang
which in this case (on Fedora) cause include <gnu/stubs-32.h>.

The error looks like this:

$ make
    CLANG    lsm-nobpf-kern.o
In file included from lsm-nobpf-kern.c:6:
In file included from /usr/include/errno.h:25:
In file included from /usr/include/features.h:474:
/usr/include/gnu/stubs.h:7:11: fatal error: 'gnu/stubs-32.h' file not found
# include <gnu/stubs-32.h>
          ^~~~~~~~~~~~~~~~

This patch adds a compile test to configure script to help people
realize why compiling is failing on their systems.

[1] https://www.kernel.org/doc/html/latest/bpf/bpf_devel_QA.html#q-clang-flag-for-target-bpf

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-09 16:28:45 +01:00
e7071dfbfb Merge pull request #11 from xdp-project/traffic-pacing-edt-refactor02
Traffic pacing edt old refactor work
2021-02-09 14:44:43 +01:00
2c3644e62e traffic-pacing-edt: Prepare that rate can come from BPF-map
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-02-09 14:28:45 +01:00
b4dad87cad traffic-pacing-edt: whitespace cleanups
Signed-off-by: Jesper Dangaard Brouer <netoptimizer@brouer.com>
2021-02-09 14:28:45 +01:00
eafdf87d80 pping: Fix struct alginment issues
Move some members in network_tuple and rtt_event around to avoid holes.

Also remove some uncecessary parentheses before & operator, and add
local definitions of AF_INET and AF_INET6.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-09 13:00:28 +01:00
670df84bd9 pping: Add IPv6 support
Several changes to add IPv6 support:
- Change structs in pping.h
  - replace ipv4_flow with network_tuple
  - rename ts_key to packet_id
  - rename ts_timestamp to packet_timestamp
- Add map_ipv4_to_ipv4 in pping_helpers.h
  - Also remove obsolete fill_ipv4_flow
- Rewrite pping_kern*
  - parse either IPv4 or IPv6 header (depending on proto)
  - Use map_ipv4_to_ipv6 to store IPv4 address in network_tuple
Support printout of IPv6 addresses in pping.c
  - Add function format_ip_address as wrapper over inet_ntop
  - Change handle_rtt_event to first format IP-address strings in
    local buffers, then perform single printout

While some steps have been taken to be more general towards different
types of packet identifiers (not just the currently supported TCP
timestamps), significant refactorization of pping_kern* will still be
required. Also, pping_kern_xdp and pping_kern_tc also have large
sections of very similar code that can be refactored into functions.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-08 20:28:46 +01:00
ea11864db2 Merge pull request #7 from simosund/add_pping
Add pping
2021-02-04 23:44:44 +01:00
1bb5a44152 pping: Create pin-folder and check if root
Create the /sys/fs/bpf/tc folder if it does not exist. Also check if
pping is run as root, otherwise inform user that it must run as root.

Libbpf will attempt to create the /sys/fs/bpf/tc/globals directory
when pinning the map, however it will not do so recursivly (so will
fail if /sys/fs/bpf/tc does not exist). So as a temporary solution,
attempt to create /sys/fs/bpf/tc (however, if sys/fs/bpf is not
mounted this will still fail).

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:56:49 +01:00
c777287af2 pping: Minor refactor and whitespace fixes
Refactor tc_bpf_load and tc_bpf_clear to use a common run_program
function which does the fork+execv.

Enclose compound statement defines in parenthesis.

Removed argument CLOCK_MONOTONIC from callers to parameterless
function get_time_ns().

Also fix some weird spacing in pping_helpers.h, and fix some
formatting issues, using clang-format with the kernel source tree
.clang-format on the whole tree.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:52:40 +01:00
7410d5cc2c pping: Various minor fixes
Perform various fixes and tweaks:
- Rename several defines to make them more informative
- Remove unrolling of loop in BPF programs
- Reuse defines for program sections between userspace and kernel
  space programs
- Perform fork+exec to run bpf_egress_loader script instead of
  system()
- Add comment to copied scripts indicating I've modified them
- Add pping.h and pping_helpers.h as dependencies in Makefile

Also, add a brief description of what PPing is and how it works to
README

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:48:01 +01:00
71c6458712 pping: Fix incorrect printout of IP-address
Split the print statements for RTTs into two parts to avoid inet_ntoa
overwriting one of the IP-addresses (causing both source and
destitionation address to appear the same). Also flip the order of
source and destination to be the same as Pollere's pping.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:47:15 +01:00
8b42ba1e22 pping: TC-BPF use BTF map if iproute has libbpf
Copy setup from traffic-pacing-edt to use BTF-defined map if configure
detects that iproute2 has libbpf support, otherwise fall back on
bpf_elf_map. Also fix a minor bug with setting default value for SEC
in bpf_egress_loader.sh.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:45:59 +01:00
b920d72fe0 pping: Let libbpf pin map and clean up TC and map at end
Switch order so XDP program loads first, so the ts_start map is
automatically pinned by libbpf (solves issue with tc not preserving
the name of the map).

Unload the TCP-BPF program (or rather remove the entire clsact qdisc
it is attached to) using bpg_egress_loader script once program
exits. Also unpin ts_start map on program shutdown.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:44:33 +01:00
337126306b pping: Switch to BTF-defined maps for XDP program
Make loader use libbpf's existing functionality for reusing pinned
maps. The name for map not kept by tc, so cannot get fd of map by
name. Use fd of first encountered map as temporary workaround.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:44:06 +01:00
b1ce4ee69b pping: Format headers and fix TODO.md
Format the header files in the Linux kernel style (missed in previous
commit). Also fix a formating error in TODO.md that cause empty
checkboxes to not display correctly.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:43:39 +01:00
d3a5de62c4 pping: Format code and add SPDX lincense tags
Format the code using the .clang-format from the kernel source tree,
with a few manual tweaks here and there. Also, remove the TODO list
from comment of pping.c and instead put it in TODO.md.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:43:03 +01:00
1010e53065 pping: Share ts_start map, pping at working stage
Make tc pin the ts_start map when loading the TC-BPF program, and
rewrite XDP loader to reuse map pinned by tc.

Also add comment with TODO list in pping.c.

Testing pping by adding a delay through a netem qdisc in the test
environment shows that the reported RTT will approach 100ms for any
delay lower than 100ms, but the correct RTT for any delay over
100ms. Root cause is unknown, but Pollere's original pping
implementation (as well as a bpftrace based pping implementation)
shows the same issue. This issue has not been observed when running on
real interfaces without a netem qdisc.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:41:40 +01:00
954c66b0e8 pping: Add TC-BPF program for egress
Split and rename files so there is one userspace program (pping) and
two kernel-space ones (one for XDP and one for TC-BPF).

Copy the shell script for loading the TC-BPF program from
traffic-pacing-edt folder, but add support for loading a specific
section.

The XDP and TC-BPF programs do not share the ts_start map, so program
does not work.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:39:16 +01:00
45b138b6ab pping: Add perf-buffer
The XDP program pushes the calculated RTTs to userspace through the
perf-buffer and the userspace program polls it to print them out

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:38:23 +01:00
8628004b6c pping: Add high-level design of eBPF pping to README
Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:38:03 +01:00
135ae974e9 pping: Start pping implementation
Add a XDP program to parse TCP timestamps and a simple loader

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:37:15 +01:00