Commit Graph

640 Commits

Author SHA1 Message Date
1cadbe0ae7 pping: Make parsed protocols configurable
Add command-line flags for each protocol that pping should attempt to
parse and report RTTs for (currently -T/--tcp and -C/--icmp). If no
protocol is specified assume TCP. To clarify this, output a message
before start on how ePPing has been configured (stating output format,
tracked protocols and which interface to run on).

Additionally, as the ppviz format was only designed for TCP it does
not have any field for which protocol an entry belongs to. Therefore,
emit a warning in case the user selects the ppviz format with anything
other than TCP.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-02-10 16:02:24 +01:00
bd6ded5c21 pping: Add support for ICMP echo messages
Allow pping to passivly monitor RTT for ICMP echo request/reply
flows. Use the echo identifier as ports, and echo sequence as packet
identifier.

Additionally, add protocol to standard output format in order to be
able to distinguish between TCP and ICMP flows.

The ppviz format does not include protocol, making it impossible to
distinguish between TCP and ICMP traffic. Will add warning if ppviz
format is used together with ICMP traffic in the future.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-02-03 16:04:14 +01:00
af5e660d8e pping: Only match TSecr in ACKs
The echoed TCP timestamp (TSecr) is only valid if the ACK flag is
set. So make sure to only attempt to match on ACK packets.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-02-02 10:14:44 +01:00
c14f52a4d4 Merge pull request #38 from xdp-project/vestas06_tc_qdisc
TC policy example of overriding netstack TXQ
2022-02-01 15:35:35 +01:00
91432fe471 tc-policy: Update README with info on inspecting loaded BPF-progs
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-02-01 15:30:17 +01:00
71d1479d1d tc-policy: Add more advanced bpftrace script
Digging into the return value of netdev_pick_tx().
Want to be able to debug the case where a socket
selects another queue_id.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-02-01 14:49:47 +01:00
ba2c114db0 tc-policy: Take into account locally generated traffic
The BPF-prog "not_txq_zero" also needed to take into account
that skb->queue_mapping usually isn't set for locally
generated traffic.

I worry that sockets can set another queue id that could
override our (BPF choice) in netdev_pick_tx().
See sk_tx_queue_set() and sk_tx_queue_get().

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-02-01 13:28:20 +01:00
a3af1bb99c tc-policy: Implement new BPF section that disallow using TXQ zero
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-02-01 13:11:31 +01:00
741205e13c tc-policy: Mention XPS need to be disabled
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-02-01 12:40:14 +01:00
f33789e4c6 tc-policy: rename xps_setup.sh to xps_setup_ash.sh
This version of the XPS script have been modified to
work with the shell ash.  As bash was not avail on
the Yocto target host.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-02-01 12:33:49 +01:00
cf5ecd6999 tc-policy: Adjust README for GitHub rendering
The bpftrace oneliner was getting rendered wrong in GitHub html view.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-02-01 12:16:19 +01:00
e72d309789 tc-policy: Monitor TXQ usage with bpftrace script
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-02-01 11:56:32 +01:00
007c0b6883 Merge pull request #37 from simosund/pping_graceful_shutdown
pping: Add graceful shutdown on SIGTERM
2022-02-01 00:12:26 +01:00
520d2e6109 tc-policy: Add README documentation
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 21:40:18 +01:00
de5d65030c pping: Add graceful shutdown on SIGTERM
Also intercept SIGTERM (in addition the the previously intercepted
SIGINT) and perform graceful shutdown.

Perhaps it also makes sense to perform graceful shutdown on some
additional signals, like SIGHUP and SIGQUIT?

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-31 18:47:08 +01:00
1bc9b91e3f tc-policy: Verbose info when flushing TC-BPF programs
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 18:29:03 +01:00
c45bdfddfa tc-policy: No need to call bpf_tc_query after bpf_tc_attach
The attach_egress.prog_id have already been provided
after calling bpf_tc_attach.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 18:25:32 +01:00
a00ed96ed6 tc-policy: Be more verbose, but add --quiet option
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 17:29:52 +01:00
78515fdd2e tc-policy: Now --unload only remove our own TC-BPF prog
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 16:43:01 +01:00
665f26e06b tc-policy: Make more clear that destroying hook kill all progs
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 15:55:06 +01:00
9fba4b12ac tc-policy: Fix issue of too many TC-BPF filter prog attached multi
This seems to be a common occuring issue with tc cmdline.
And the C-code have inherited the issue in the API.

Trying to replace a TC-BPF prog often result in appending a new prog
(as a new tc filter instance).

Be careful to set both handle and prio and the replace flag.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 15:20:38 +01:00
5917dbff3f tc-policy: Add teardown --unload functionality
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 14:59:51 +01:00
17c3aa7661 tc-policy: Attach to TC egress hook as libbpf C-code
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 13:37:14 +01:00
9e5ab8f4fb tc-policy: Use bpftool skeleton header generate feature
The reason for going this route is that this allow us to
create a user binary that contains the BPF object file.
Thus, we can avoid having to load the BPF file from
a specific location or having to be in same dir as file.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 12:39:31 +01:00
dcdceea90c tc-policy: Add C-code boilerplate tc_txq_policy.c
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 12:10:45 +01:00
b1efd37ed5 tc-policy: Adapt XPS script to work with ash on Yocto
The Yocto build this is intended for doesn't have /bin/bash
adapt script.

External program "getopt" not avail.

The 'sort' tool is also different, as it comes from busybox.
Adapt the cmdline options for 'sort'.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 10:11:40 +01:00
fb84a226b0 tc-policy: Manuel setup steps via tc cmdline
Yocto build have a problem with loading this via tc

 # tc filter replace dev eth1 egress prio 0xC000 handle 1 bpf da obj tc_txq_policy_kern.o
 Continuing without mounted eBPF fs. Too old kernel?
 mkdir (null)/globals failed: No such file or directory
 Unable to load program

It can be worked around via mounting BPF file-system manually:

 # mount -t bpf bpf /sys/fs/bpf/

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 09:17:09 +01:00
ae52ac2140 tc-policy: Add script for disabling XPS
Taken from xdp-cpumap-tc git repo:
 https://github.com/xdp-project/xdp-cpumap-tc/blob/master/bin/xps_setup.sh

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-31 09:12:35 +01:00
8fbccb90ab tc-policy: Simple approach static map to TXq 4
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-28 17:25:08 +01:00
ceb3fd80e7 tc-policy: Add Makefile
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-28 16:37:06 +01:00
e1b18d7b12 AF_XDP-interaction: Fix another warning in complete_tx
warning: ‘return’ with no value, in function returning non-void

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-21 12:09:30 +01:00
96e5daf52c AF_XDP-interaction: Fix compiler warnings
warning: suggest parentheses around assignment used as truth value

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-21 12:05:09 +01:00
2135ae1c3a Merge pull request #36 from xdp-project/vestas04_AF_XDP_example
AF_XDP example: Improvements to wake-up accuracy
2022-01-21 11:54:54 +01:00
0c2ec8a1bd AF_XDP-interaction: Exclude first measurement min/max stats as no next_adj happened
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-19 12:18:27 +01:00
4ee53b1fd5 AF_XDP-interaction: Add cmdline options for specifying IPs
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-18 16:48:34 +01:00
9eefd4bd56 AF_XDP-interaction: Change IP for my testlab
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-18 16:33:17 +01:00
1a8a2b9188 AF_XDP-interaction: Add option for selecting batch pkts size
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-18 14:01:57 +01:00
e80da14433 Merge pull request #31 from simosund/pping_loader_improvements
PPing loader improvements
2022-01-17 19:27:40 +01:00
cfdf224d93 pping: Remove usage of deprecated libbpf API
The libbpf API has deprecated a number of functions used by the pping
loader. While a couple of functions have simply been renamed,
bpf_object__find_program_by_title has been completely deprecated in
favor of bpf_object__find_program_by_name. Therefore, change so that
BPF programs are found based on the C function names rather than
section names.

Also remove defines of section names as they are no longer used, and
change the section names in pping_kern.c to use "tc" instead of
"classifier/ingress" and "classifier/egress".

Finally replace the flags json_format and json_ppviz in pping_config
with a single enum for the different output formats. This makes the
logic for which output format to use clearer compared to relying on
multiple (supposedly) mutually exclusive flags (and implicitly
assuming standard format if neither flag was set).

One potential concern with this commit is that it introduces some
"magical strings". In case the function names in pping_kern.c are
changed it will require multiple changes in pping.c.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-17 18:43:04 +01:00
9ae5606e18 pping: Check bounds on passed float arguments
The rate-limit and cleanup-interval arguments were only verified to be
positive. Add a check for an upper bound to avoid user being able to
pass values that result in an internal overflow. The limits for both
rate-limit and cleanup-interval have been set to one week which should
be more then enough for any reasonable user.

Additionally, disable the period cleanup entirely if the value 0 is
passed to cleanup-interval.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-17 14:02:19 +01:00
cbfc3c9a9e pping: Improve XDP and tc attach/detach process
Make several changes to functions related to attaching and detaching
the BPF programs:
- Check the BPF program id when detaching programs to ensure that the
  correct programs are removed.
- When attaching tc-programs, keep track of if the clsact qdisc was
  created or existed previously. Attempt to delete the qdisc if it was
  created and attaching failed. If the --force argument was given, also
  attempt to delete qdisc on shutdown in case it did not previously
  exist.
- Rely on XDP flags to replace existing XDP program if --force is used
  rather than explicitly detaching any XDP program first.
- Print out hints for why pping might have failed attaching the XDP
  program.

Also, use libbpf_strerror instead of strerror to better display
libbpf-specific error codes, and for more reliable error handling in
general (don't need to ensure the error codes are positive).

Finally, change return codes of tc programs to TC_ACT_UNSPEC from
TC_ACT_OK to allow other TC-BPF programs to be used on the same
interface as pping.

Concerns with this commit:
- When attaching a tc program libbpf will emit a warning if the
  clsact qdisc already exists on the interface. The fact that the
  clsact already exists is not an issue, and is handled in tc_attach
  by checking for EEXIST, so the warning could be a bit
  misleading/confusing for the user.
- The tc_attach and xdp_attach functions attempt to return the u32
  prog_id in an int. In case the programs are assigned a very high
  id (> 2^31) this may cause it to be interpreted as an error instead.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-17 14:02:19 +01:00
2f5c3fc5b0 pping: Add tc ingress hook as alternative to XDP
For some machines, XDP may not be suitable due to ex. lack of XDP
support in NIC drivers or another program already being attached to
the XDP hook on the desired interface. Therefore, add an option to use
the tc-ingress hook instead of XDP to attach the pping ingress BPF
program on.

In practice, this adds an additional BPF program to the object file (a
TC ingress program). To avoid loading an unnecessary BPF program, also
explicitly disable autoloading for the ingress program not selected.

Also, change the tc programs to return TC_ACT_OK instead of
BPF_OK. While both should be compatible, the TC_ACT_* return codes
seem to be more commonly used for TC-BPF programs.

Concerns with this commit:
- The error messages for XDP attach failure has gotten slightly less
  descriptive. I plan to improve the code for attaching and detaching
  XDP programs in a separate commit, and will then address that.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-17 14:02:19 +01:00
bd29a246b9 pping: Use libbpf to attach tc program
libbpf v0.4 added an API for attaching/detaching TC-BPF programs. So
use the new API to attach the tc program instead of calling on an
external script (which uses the tc command line utility).

Avoid removing the clsact qdisc on program shutdown or error, as
there's currently no convenient way to ensure the qdisc isn't used by
other programs as well. This means pping will not completely clean up
after itself, but this is a safer alternative than always destroying
the qdsic as done by the external script, which may pull the rug out
underneath other programs using the qdisc.

Finally, remove the pin_dir member from the configuration as pping no
longer pins any programs or maps, and remove deleted tc loading
scripts from README.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-17 14:02:19 +01:00
2465e3e0df pping: Refactor cleanup code
Add cleanup code to load_attach_bpfprogs function, so it should always
unpin tc program, and additionally detach the tc and xdp programs in
case of any failure.

Also unpin tc program directly after attaching it (rather than on
program shutdown), so that multiple instances of pping can be run
simultaneously (on different interfaces).

Finally, rename some of the functions for attaching/detaching tc
programs to be more consistent with the xdp ones.

Note: Still need to keep a copy of most of the cleanup code in main as
well, as the tc and xdp programs also need to be detached on program
shutdown or if later functions fail.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2022-01-17 14:02:19 +01:00
c04f6934cf Update headers/linux/btf.h
Newer libbpf uses constants from the newer kernel header file, so
compilation breaks unless we have the newest version of the kernel header.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-01-17 13:12:53 +01:00
d36c5f9254 lsm-nobpf: Stop using deprecated helper
The bpf_program__next() helper was deprecated in favour of
bpf_object__next_program(), so switch to that.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-01-17 13:11:27 +01:00
8e9fc89bec libbpf: Update submodule version
Update the libbpf submodule to the latest version, and update the configure
script so we check for the newer bpf_object__next_program() helper (to fix
deprecation warnings).

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-01-17 13:11:27 +01:00
86b76f564f AF_XDP-interaction: workaround for detecting when AF_XDP is read for TX
I hope there exist a better API for determining when AF_XDP
is ready for transmitting packets.

This workaround keeps trying to send a single packet, and
check return value seen from sendto() syscall, until it
doesn't return an error.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-14 16:48:13 +01:00
6d6ac23f3b AF_XDP-interaction: warning if code completed more than possible
Give a print WARN if code/AF_XDP somehow have MORE packets to
complete from CQ than our counter for xsk->outstanding_tx packets.
This should not happen, but currently hunting for a TX issue.

The code (below) reset xsk->outstanding_tx, which were introduced
via a discussion on xdp-tutorial:
 https://github.com/xdp-project/xdp-tutorial/issues/180

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-14 14:33:11 +01:00
49c1efadf8 AF_XDP-interaction: Report warning when TX-kick via sendto fails
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-01-14 13:26:24 +01:00