On Mon, Jul 13, 2020 at 10:47 AM Jakub Sitnicki <jakub@xxxxxxxxxxxxxx> wrote: > > Dependencies > ============ > > This patch series depends on: > > 1. 'bpf-multi-prog-prep' series in 'bpf' [0] > (commit 951f38cf0835 ("Merge branch 'bpf-multi-prog-prep'")) > 2. "bpf: Shift and mask loads narrower than context field size" patch > https://lore.kernel.org/bpf/20200710173123.427983-1-jakub@xxxxxxxxxxxxxx/ > [...] > > Overview > ======== > > This series proposes a new BPF program type named BPF_PROG_TYPE_SK_LOOKUP, > or BPF sk_lookup for short. > > BPF sk_lookup program runs when transport layer is looking up a listening > socket for a new connection request (TCP), or when looking up an > unconnected socket for a packet (UDP). > > This serves as a mechanism to overcome the limits of what bind() API allows > to express. Two use-cases driving this work are: > > (1) steer packets destined to an IP range, fixed port to a single socket > > 192.0.2.0/24, port 80 -> NGINX socket > > (2) steer packets destined to an IP address, any port to a single socket > > 198.51.100.1, any port -> L7 proxy socket > > In its context, program receives information about the packet that > triggered the socket lookup. Namely IP version, L4 protocol identifier, and > address 4-tuple. > > To select a socket BPF program fetches it from a map holding socket > references, like SOCKMAP or SOCKHASH, calls bpf_sk_assign(ctx, sk, ...) > helper to record the selection, and returns SK_PASS code. Transport layer > then uses the selected socket as a result of socket lookup. > > Alternatively, program can also fail the lookup (SK_DROP), or let the > lookup continue as usual (SK_PASS without selecting a socket). > > This lets the user match packets with listening (TCP) or receiving (UDP) > sockets freely at the last possible point on the receive path, where we > know that packets are destined for local delivery after undergoing > policing, filtering, and routing. > > Program is attached to a network namespace, similar to BPF flow_dissector. > We add a new attach type, BPF_SK_LOOKUP, for this. Multiple programs can be > attached at the same time, in which case their return values are aggregated > according the rules outlined in patch #4 description. > > Series structure > ================ > > Patches are organized as so: > > 1: enables multiple link-based prog attachments for bpf-netns > 2: introduces sk_lookup program type > 3-4: hook up the program to run on ipv4/tcp socket lookup > 5-6: hook up the program to run on ipv6/tcp socket lookup > 7-8: hook up the program to run on ipv4/udp socket lookup > 9-10: hook up the program to run on ipv6/udp socket lookup > 11-13: libbpf & bpftool support for sk_lookup > 14-16: verifier and selftests for sk_lookup > > Patches are also available on GH: > > https://github.com/jsitnicki/linux/commits/bpf-inet-lookup-v4 > > Follow-up work > ============== > > I'll follow up with below items, which IMHO don't block the review: > > - benchmark results for udp6 small packet flood scenario, > - user docs for new BPF prog type, Documentation/bpf/prog_sk_lookup.rst, > - timeout for accept() in tests after extending network_helper.[ch]. > Looks good to me overall. I've looked through networking-specific code and didn't spot anything, but I might be missing some subtleties, hopefully not, though. I left a few suggestions, please take a look, and if they make sense, apply them in the follow up(s). Thanks! For the series: Acked-by: Andrii Nakryiko <andriin@xxxxxx> > Thanks to the reviewers for their feedback to this patch series: > > Cc: Alexei Starovoitov <ast@xxxxxxxxxx> > Cc: Andrii Nakryiko <andriin@xxxxxx> > Cc: Lorenz Bauer <lmb@xxxxxxxxxxxxxx> > Cc: Marek Majkowski <marek@xxxxxxxxxxxxxx> > Cc: Martin KaFai Lau <kafai@xxxxxx> > Cc: Yonghong Song <yhs@xxxxxx> > > -jkbs > [...]