Subject: Re: tcp_diag for all network namespaces?

From: Martin KaFai Lau <[email-masked]>
Date: Thu, 19 Dec 2024 10:11:44 -0800

On 12/9/24 6:00 PM, Kuniyuki Iwashima wrote:
>> G'day,
>>
>> Short
>> Is there a way to extract tcp_diag socket data for all sockets from
>> all network name spaces please?
> I think there's no such interface.
> 
> I remember there was a similar request for TCP BPF iterator,
> but now it's difficult because each netns could have its own
> TCP hash table for established connections.

It would be nice to be able to iterate netns in bpf. There is a bpf task/file 
iterator that iterates tasks and all files under each task 
(tools/testing/selftests/bpf/progs/bpf_iter_task_file.c). The netns/sock 
iteration feels similar. The first step could be to allow bpf prog to iterate 
all netns first. Then it will allow bpf to inspect "struct net". There is also a 
newer open iterator approach in bpf which should be considered also.