All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sargun Dhillon <sargun@sargun.me>
To: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	netdev <netdev@vger.kernel.org>,
	Christian Brauner <christian.brauner@ubuntu.com>
Subject: Re: Retrieving the network namespace of a socket
Date: Wed, 20 Oct 2021 16:34:18 +0000	[thread overview]
Message-ID: <20211020163417.GA21040@ircssh-2.c.rugged-nimbus-611.internal> (raw)
In-Reply-To: <CAHNKnsRFah6MRxECTLNwu+maN0o9jS9ENzSAiWS4v1247BqYdg@mail.gmail.com>

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.

  reply	other threads:[~2021-10-20 16:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-20  9:57 Retrieving the network namespace of a socket Sargun Dhillon
2021-10-20 14:03 ` Sergey Ryazanov
2021-10-20 16:34   ` Sargun Dhillon [this message]
2021-10-20 19:24     ` Sargun Dhillon
2021-10-21  9:20       ` Christian Brauner
2021-10-20 20:02     ` Sergey Ryazanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211020163417.GA21040@ircssh-2.c.rugged-nimbus-611.internal \
    --to=sargun@sargun.me \
    --cc=christian.brauner@ubuntu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ryazanov.s.a@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.