lkml.org 
[lkml]   [2021]   [Oct]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Retrieving the network namespace of a socket
On Wed, Oct 20, 2021 at 05:03:56PM +0300, Sergey Ryazanov wrote:
> Hello Sargun,
>
> On Wed, Oct 20, 2021 at 12:57 PM Sargun Dhillon <sargun@sargun.me> wrote:
> > I'm working on a problem where I need to determine which network namespace a
> > given socket is in. I can currently bruteforce this by using INET_DIAG, and
> > enumerating namespaces and working backwards.
>
> Namespace is not a per-socket, but a per-process attribute. So each
> socket of a process belongs to the same namespace.
>
> Could you elaborate what kind of problem you are trying to solve?
> Maybe there is a more simple solution. for it.
>
> --
> Sergey

That's not entirely true. See the folowing code:

int main() {
int fd1, fd2;
fd1 = socket(AF_INET, SOCK_STREAM, 0);
assert(fd1 >= 0);
assert(unshare(CLONE_NEWNET) == 0);
fd2 = socket(AF_INET, SOCK_STREAM, 0);
assert(fd2 >= 0);
}

fd1 and fd2 have different sock_net.

The context for this is:
https://linuxplumbersconf.org/event/11/contributions/932/

We need to figure out, for a given socket, if it has reachability to a given IP.

\
 
 \ /
  Last update: 2021-10-20 18:35    [W:0.250 / U:0.656 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site