Files
linux/include/uapi/linux
Martynas Pumputis dab4e1f06c bpf: Derive source IP addr via bpf_*_fib_lookup()
Extend the bpf_fib_lookup() helper by making it to return the source
IPv4/IPv6 address if the BPF_FIB_LOOKUP_SRC flag is set.

For example, the following snippet can be used to derive the desired
source IP address:

    struct bpf_fib_lookup p = { .ipv4_dst = ip4->daddr };

    ret = bpf_skb_fib_lookup(skb, p, sizeof(p),
            BPF_FIB_LOOKUP_SRC | BPF_FIB_LOOKUP_SKIP_NEIGH);
    if (ret != BPF_FIB_LKUP_RET_SUCCESS)
        return TC_ACT_SHOT;

    /* the p.ipv4_src now contains the source address */

The inability to derive the proper source address may cause malfunctions
in BPF-based dataplanes for hosts containing netdevs with more than one
routable IP address or for multi-homed hosts.

For example, Cilium implements packet masquerading in BPF. If an
egressing netdev to which the Cilium's BPF prog is attached has
multiple IP addresses, then only one [hardcoded] IP address can be used for
masquerading. This breaks connectivity if any other IP address should have
been selected instead, for example, when a public and private addresses
are attached to the same egress interface.

The change was tested with Cilium [1].

Nikolay Aleksandrov helped to figure out the IPv6 addr selection.

[1]: https://github.com/cilium/cilium/pull/28283

Signed-off-by: Martynas Pumputis <m@lambda.lt>
Link: https://lore.kernel.org/r/20231007081415.33502-2-m@lambda.lt
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
2023-10-09 16:28:35 -07:00
..
2023-05-14 16:05:28 +01:00
2021-01-25 18:44:44 +01:00
2023-05-30 15:20:08 +01:00
2021-11-01 13:36:08 +00:00
2022-08-11 10:31:19 -07:00
2022-06-07 10:20:42 -07:00
2023-08-21 14:54:48 +02:00
2021-11-26 16:48:59 +01:00
2023-04-22 14:41:30 -07:00
2023-01-20 09:33:22 +00:00
2023-03-06 15:49:07 -06:00
2023-09-17 11:50:20 +01:00
2022-04-04 08:55:23 +02:00
2023-03-16 21:20:32 -07:00
2023-08-16 12:39:38 +02:00
2021-10-07 13:51:11 +02:00
2022-08-10 13:49:50 +01:00
2021-02-08 13:01:24 +01:00
2022-03-11 08:28:05 -08:00
2021-11-15 07:53:10 -08:00
2021-06-03 15:31:34 -07:00
2022-09-20 09:13:38 +02:00
2021-03-10 09:34:06 +01:00
2023-03-23 17:25:46 +01:00
2023-06-09 16:25:16 -07:00
2023-08-14 18:48:02 +02:00
2023-04-27 19:15:11 -06:00
2022-09-07 16:46:03 +02:00
2021-07-06 10:37:46 -05:00
2023-01-26 10:52:18 +01:00
2023-08-04 16:20:39 +02:00
2023-09-16 13:42:34 +01:00
2022-11-17 11:04:23 -08:00
2021-01-07 16:17:32 +01:00
2022-09-27 17:29:09 -07:00
2023-06-05 09:36:35 +02:00
2023-03-23 17:25:46 +01:00
2023-06-09 16:13:01 +01:00
2021-06-12 13:16:45 -07:00
2022-12-05 10:30:47 +01:00