bpf, sockmap: Return socket cookie on lookup from syscall
authorJakub Sitnicki <jakub@cloudflare.com>
Tue, 18 Feb 2020 17:10:18 +0000 (17:10 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 21 Feb 2020 21:29:45 +0000 (22:29 +0100)
commitc1cdf65da060a8e047a9f4433306fd6dac1f51a6
treeec77dc322cb1085437d4e63ee2c19d6958297ac4
parent6e830c2f6c9641217e22330cec1372acff78dcef
bpf, sockmap: Return socket cookie on lookup from syscall

Tooling that populates the SOCK{MAP,HASH} with sockets from user-space
needs a way to inspect its contents. Returning the struct sock * that the
map holds to user-space is neither safe nor useful. An approach established
by REUSEPORT_SOCKARRAY is to return a socket cookie (a unique identifier)
instead.

Since socket cookies are u64 values, SOCK{MAP,HASH} need to support such a
value size for lookup to be possible. This requires special handling on
update, though. Attempts to do a lookup on a map holding u32 values will be
met with ENOSPC error.

Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200218171023.844439-7-jakub@cloudflare.com
net/core/sock_map.c