linux/arch
Martynas Pumputis 602b0c1dbe net: retrieve netns cookie via getsocketopt
[ Upstream commit e8b9eab992 ]

It's getting more common to run nested container environments for
testing cloud software. One of such examples is Kind [1] which runs a
Kubernetes cluster in Docker containers on a single host. Each container
acts as a Kubernetes node, and thus can run any Pod (aka container)
inside the former. This approach simplifies testing a lot, as it
eliminates complicated VM setups.

Unfortunately, such a setup breaks some functionality when cgroupv2 BPF
programs are used for load-balancing. The load-balancer BPF program
needs to detect whether a request originates from the host netns or a
container netns in order to allow some access, e.g. to a service via a
loopback IP address. Typically, the programs detect this by comparing
netns cookies with the one of the init ns via a call to
bpf_get_netns_cookie(NULL). However, in nested environments the latter
cannot be used given the Kubernetes node's netns is outside the init ns.
To fix this, we need to pass the Kubernetes node netns cookie to the
program in a different way: by extending getsockopt() with a
SO_NETNS_COOKIE option, the orchestrator which runs in the Kubernetes
node netns can retrieve the cookie and pass it to the program instead.

Thus, this is following up on Eric's commit 3d368ab87c ("net:
initialize net->net_cookie at netns setup") to allow retrieval via
SO_NETNS_COOKIE.  This is also in line in how we retrieve socket cookie
via SO_COOKIE.

  [1] https://kind.sigs.k8s.io/

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Martynas Pumputis <m@lambda.lt>
Cc: Eric Dumazet <edumazet@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2021-07-19 10:04:44 +02:00
..
alpha net: retrieve netns cookie via getsocketopt 2021-07-19 10:04:44 +02:00
arc sched/core: Initialize the idle task with preemption disabled 2021-07-14 17:06:21 +02:00
arm sched/core: Initialize the idle task with preemption disabled 2021-07-14 17:06:21 +02:00
arm64 arm64: dts: marvell: armada-37xx: Fix reg for standard variant of UART 2021-07-14 17:07:46 +02:00
csky csky: syscache: Fixup duplicate cache flush 2021-07-14 17:07:48 +02:00
h8300 arch: rearrange headers inclusion order in asm/bitops for m68k, sh and h8300 2021-05-06 19:24:11 -07:00
hexagon Merge branch 'akpm' (patches from Andrew) 2021-05-07 00:34:51 -07:00
ia64 ia64: mca_drv: fix incorrect array size calculation 2021-07-14 17:06:38 +02:00
m68k m68k: atari: Fix ATARI_KBD_CORE kconfig unmet dependency warning 2021-07-14 17:06:43 +02:00
microblaze quota: Disable quotactl_path syscall 2021-05-17 14:39:56 +02:00
mips net: retrieve netns cookie via getsocketopt 2021-07-19 10:04:44 +02:00
nds32 tracing updates for 5.13 2021-05-03 11:19:54 -07:00
nios2 Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2021-05-02 09:14:01 -07:00
openrisc sched/core: Initialize the idle task with preemption disabled 2021-07-14 17:06:21 +02:00
parisc net: retrieve netns cookie via getsocketopt 2021-07-19 10:04:44 +02:00
powerpc powerpc/preempt: Don't touch the idle task's preempt_count during hotplug 2021-07-14 17:07:52 +02:00
riscv sched/core: Initialize the idle task with preemption disabled 2021-07-14 17:06:21 +02:00
s390 s390: preempt: Fix preempt_count initialization 2021-07-14 17:07:51 +02:00
sh sched/core: Initialize the idle task with preemption disabled 2021-07-14 17:06:21 +02:00
sparc net: retrieve netns cookie via getsocketopt 2021-07-19 10:04:44 +02:00
um Merge branch 'akpm' (patches from Andrew) 2021-05-07 00:34:51 -07:00
x86 bpf, x86: Fix extable offset calculation 2021-07-14 17:07:23 +02:00
xtensa sched/core: Initialize the idle task with preemption disabled 2021-07-14 17:06:21 +02:00
.gitignore .gitignore: prefix local generated files with a slash 2021-05-02 00:43:35 +09:00
Kconfig Add Landlock, a new LSM from Mickaël Salaün <mic@linux.microsoft.com> 2021-05-01 18:50:44 -07:00