Commit Graph

16 Commits

Author SHA1 Message Date
Jesper Dangaard Brouer
88b05144a2 nat64-bpf: rename bpf_map__resize() to bpf_map__set_max_entries()
Libbpf API change:
 
 Discourage bpf_map__resize(), which is an alias to more clearly
 named bpf_map__set_max_entries()

See: https://github.com/libbpf/libbpf/issues/304

And API migration guide:
 https://github.com/libbpf/libbpf/wiki/Libbpf:-the-road-to-v1.0#libbpfh-high-level-apis

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
2022-09-02 14:34:11 +02:00
Toke Høiland-Jørgensen
24cea38474 nat64-bpf: Use logging helpers and add verbose option
Use the newly-added logging helpers from logging.h and add a -v option to
increase the effective log level.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
2022-04-20 13:25:27 +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
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