Commit Graph

326 Commits

Author SHA1 Message Date
Jesper Dangaard Brouer
5df5332f23 AF_XDP-interaction: config AF_XDP frame_headroom
The default frame_headroom seems to be zero as
define XSK_UMEM__DEFAULT_FRAME_HEADROOM is zero.

This patch does explicit xsk_umem_config setup.
Comment taken from kernel/samples/bpf/xdpsock_user.c.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-28 18:20:56 +02:00
Jesper Dangaard Brouer
359cc27c72 AF_XDP-interaction: use bpf_xdp_adjust_meta
This only works in skb-mode, other modes fail the bpf_xdp_adjust_meta
call and result in XDP_ABORTED.  This only occurred on mlx5.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-28 17:42:23 +02:00
Jesper Dangaard Brouer
9ef9104c61 AF_XDP-interaction: Fix strncpy warning in common_user_bpf_xdp.c
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-28 14:20:14 +02:00
Jesper Dangaard Brouer
45a7e3cab7 lib/Makefile: Enable compiler warnings to USER_TARGETS_OBJS
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-28 13:51:09 +02:00
Jesper Dangaard Brouer
6f0a1e3f01 AF_XDP-interaction: Use bpf_program__section_name
BPF program title (bpf_program__title) is getting deprecated
in libbpf use bpf_program__section_name() instead.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-28 13:35:12 +02:00
Jesper Dangaard Brouer
9e8218556c AF_XDP-interaction: Use new .maps section for BTF aware map definitions
In-practice only 'xdp_stats_map' definition gets associated BTF,
as it uses the proper '__type' construct.

The AF_XDP map BPF_MAP_TYPE_XSKMAP doesn't know about BTF yet.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-28 13:17:33 +02:00
Jesper Dangaard Brouer
3e65f68cdb AF_XDP-interaction: Make af_xdp_user default load af_xdp_kern.o
When not loading an XDP-prog the XSK library bits will load a
default XDP-prog.

In our use-case we always want to load our XDP-prog, which is
stored in af_xdp_kern.o.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-27 18:21:07 +02:00
Jesper Dangaard Brouer
0dc1b0eab5 AF_XDP-interaction: Started on newer .maps SEC usage but stopped
Something in fishy as it seems this BPF-object is not getting used.

Use old maps SEC defines until figuring out what is wrong,
but keep new dot-maps defines.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 17:00:48 +02:00
Jesper Dangaard Brouer
635a2f3ca4 MTU-tests: BPF-helper did make it upstream and in libbpf
The BPF-helper is now defined in bpf_helper_defs.h header:
 lib/libbpf-install/usr/include/bpf/bpf_helper_defs.h

Update and keep comment as a help for people doing kernel
devel on BPF and want to test BPF-helpers not yet upstream.

Accepted in kernel v5.12
 - commit 34b2021cc616 ("bpf: Add BPF-helper for MTU checking")
 - https://git.kernel.org/torvalds/c/34b2021cc616

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 16:10:57 +02:00
Jesper Dangaard Brouer
d4d325ddfc Introduce USER_TARGETS_OBJS_DEPS for extra dependencies
This USER_TARGETS_OBJS_DEPS allows makefiles to define
dependencies for USER_TARGETS_OBJS targets.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 16:02:25 +02:00
Jesper Dangaard Brouer
5d10995545 AF_XDP-interaction: Use USER_TARGETS_OBJS for common_* objects
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 15:31:33 +02:00
Jesper Dangaard Brouer
27b0efe3e2 AF_XDP-interaction: Add common_defines.h from XDP-tutorial
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 15:29:02 +02:00
Jesper Dangaard Brouer
e6c2d60cbf AF_XDP-interaction: Add common_user_bpf_xdp.c+h from XDP-tutorial
As example (advanced03-AF_XDP) we copied from XDP-tutorial depend on these.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 15:23:55 +02:00
Jesper Dangaard Brouer
118bb615b3 AF_XDP-interaction: Add common_params.c+h from XDP-tutorial
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 15:17:39 +02:00
Jesper Dangaard Brouer
e9002588ef lib: Extend Makefile common.mk with USER_TARGETS_OBJS
This allows including Makefile to define USER_TARGETS_OBJS
that contain code that USER_TARGETS depend on and needs
to be compiled as objects and later linked with.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-26 15:12:47 +02:00
Jesper Dangaard Brouer
7c7c1a9039 AF_XDP-interaction: Add Makefile
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-15 18:26:24 +02:00
Eelco Chaudron
68743eb1d3 AF_XDP-interaction: Import AF_XDP example from XDP-tutorial
https://github.com/xdp-project/xdp-tutorial/blob/master/advanced03-AF_XDP/

Give Eelco Chaudron credit as code Author.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-10-15 18:23:42 +02:00
Toke Høiland-Jørgensen
3321c338d5 Merge pull request #25 from xdp-project/nat64
Add nat64 example
2021-10-12 20:24:17 +02:00
Toke Høiland-Jørgensen
81f127ce42 configure: avoid bashisms
The variable substitution used to parse the clang version was a bashism, so
it broke on Debian/Ubuntu. So let's just use sed instead.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-10-11 17:21:32 +02:00
Toke Høiland-Jørgensen
a5765295ac configure: Support parsing weird clang versions
Seems some distributions will change the clang version output to be
something like 'Ubuntu clang version
12.0.1-++20210918042554+fed41342a82f-1~exp1~20210918143322.141'. Fix the
version parsing in configure to not barf on such weird version strings.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-10-11 14:23:52 +02:00
Toke Høiland-Jørgensen
e41e570869 nat64: Update README
Actually explain how to use and how the translator works.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-10-05 00:44:43 +02:00
Toke Høiland-Jørgensen
a5313d2f1b nat64: Handle ICMP rewriting
Add rewriting of ICMP headers to nat64. This is specified in RFC6145, and
the implementation here follows that. The support is only partial, in
particular, in that the payload of ICMP error messages is not rewritten,
even though the RFC specifies that they should be.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-10-05 00:19:28 +02:00
Toke Høiland-Jørgensen
ced3d8c4bc nat64: Set Don't Fragment bit in IPv4 packets
IPv6 doesn't support fragmentation, so make sure IPv4 packets are not
fragmented in-flight either.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-10-04 17:51:32 +02:00
Toke Høiland-Jørgensen
742924a076 nat64: Insert route and neighbour entry on setup/teardown
We insert a v4-via-v6 route on the interface to direct packets to the v4
subnet to the right interface, where it will be rewritten by the BPF
program. We also create a fake neighbour entry so the kernel won't do
neighbour resolution when sending the pre-rewrite packet. The egress BPF
program will use bpf_redirect_neigh() to do proper neighbour resolution for
the actual destination after rewriting the packet.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-10-04 17:13:00 +02:00
Toke Høiland-Jørgensen
457a9c99bf configure: check clang version
Check clang version on configure and bail if it's too old.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-10-04 13:43:29 +02:00
Toke Høiland-Jørgensen
4648814d26 nat64: Also translate DSCP and ECN fields
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-10-01 00:26:01 +02:00
Toke Høiland-Jørgensen
fc76452e1f nat64: Drop invalid v4 destinations
These include 0.0.0.0, loopback and multicast addresses.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-10-01 00:25:44 +02:00
Toke Høiland-Jørgensen
7ec0aabbb0 nat64: Drop fragmented v4 packets as well as those with options
In the other direction we also drop packets with options, which covers
fragmented packets.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-10-01 00:24:35 +02:00
Toke Høiland-Jørgensen
0c2dd5e5cf nat64: Add some debug output
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2021-09-30 23:40:16 +02:00
Toke Høiland-Jørgensen
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
Toke Høiland-Jørgensen
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
Toke Høiland-Jørgensen
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
Toke Høiland-Jørgensen
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
Toke Høiland-Jørgensen
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
Toke Høiland-Jørgensen
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
Toke Høiland-Jørgensen
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
Jesper Dangaard Brouer
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
Jesper Dangaard Brouer
851e0f35de BTF-playground: Add Makefile
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2021-09-10 18:15:37 +02:00
Jesper Dangaard Brouer
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
Jesper Dangaard Brouer
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
Jesper Dangaard Brouer
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
Jesper Dangaard Brouer
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
Toke Høiland-Jørgensen
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
Jesper Dangaard Brouer
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
Jesper Dangaard Brouer
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
Jesper Dangaard Brouer
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
Toke Høiland-Jørgensen
a84f197e7e Merge pull request #16 from simosund/pping_Better_output
Pping better output
2021-06-24 14:28:19 +02:00
Jesper Dangaard Brouer
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
Jesper Dangaard Brouer
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
Jesper Dangaard Brouer
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