Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1333014pxb; Wed, 20 Oct 2021 03:01:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQSk9LiU+jO0H3f3r3L4hWvCZNCIOPXxFCNrDl2sF/v1JruCS8tiPnmZyPalN9yinPTQkY X-Received: by 2002:a17:906:9414:: with SMTP id q20mr46082760ejx.241.1634724095057; Wed, 20 Oct 2021 03:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634724095; cv=none; d=google.com; s=arc-20160816; b=ItKDGovkrLn8RnyhZ+3w7gN6OHNYmc8/DhRaYzqHqriaTAXmKDl7qm8Fcb9V6MWSFb 9w02O0uyOSsrYn3gBAeNv+C1m4S5JzCSK3MYTndD+9TPyJ0MWvEMJZ6fWp+48id+u3ct 15+Jdm7bGmP8HKpbNPrX+uasFkIhnQZVMwlui0kzs8MnSc/Co8Jw9+Shn/dEmoKSYO+t MjVkPmuO12S7j032bZlbRYc4yxnwDnNy6Ms3E2nFRh9hU6Oud2FaZUQ90d67sza/NY3L PS0N7YSc3jMxMyLUBOyleovip+27HtkZ8e2HOSgNcwcgXBE14vlCAp6+tleenS1k6z8b COWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:to:from:date:dkim-signature; bh=pcKdTOkR/GZDEmuSn4ASMp6zAcofYzOxflxOqSu54Oc=; b=XObO0lACAb72YoP8OBKnOVt+cYHuc/tVXAr5WctkFHHDjTCI9AR+/33RRvQ4q/aZVA vg663abJStL8sdXd7sLpiw+xiV1ejWI6lirctZ6csRGiL2IwOJZG7LQBT1fKvBQSZFzQ k7Uy/wcX3fdnAOtsrlSrsUoas+0yPurobE1dOeGXLo5QGnrwRRDZqL22mizL/Js9pDdg m6C+4Z+DbV4zGhi1+xW+sE+4sB2GKwc+qbU4+KyI9JM3+sT9fu90vGEn5gOFEhB2b4SZ JcfE8zY9kRQMSL+WbKWTERAhgsP1np+2XKwvRQfsZrE3O8OREW6cK9w/GVBkiLaE9vZ+ Cm8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=pm0fpYdp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y4si2918763edc.473.2021.10.20.03.01.10; Wed, 20 Oct 2021 03:01:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=pm0fpYdp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230059AbhJTJ7Z (ORCPT + 99 others); Wed, 20 Oct 2021 05:59:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbhJTJ7Y (ORCPT ); Wed, 20 Oct 2021 05:59:24 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7740FC061746 for ; Wed, 20 Oct 2021 02:57:10 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id s17so23752387ioa.13 for ; Wed, 20 Oct 2021 02:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=pcKdTOkR/GZDEmuSn4ASMp6zAcofYzOxflxOqSu54Oc=; b=pm0fpYdpR7I6voVoXZMrSCsBruZhzXQPDxSgnDDvr6g3sIvG15ViHq8N4sJkzJfFwa w1s7RkdC7ZgPwNXpB5cCcQfKJVARxHJ7RAdCIrHPmC59oTjziufu2FBqLa4ztYP55UwJ g2vrmj+f74oqjFmbjr66CIC24oTSyIjGuZn6U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=pcKdTOkR/GZDEmuSn4ASMp6zAcofYzOxflxOqSu54Oc=; b=EWjUyGvVCbddLXlLPVjCUZwvGo3uvP/9zGLLrG0SKy4N8wwq+848ODCaeKnfc8Uxgo Cy4XDHhQl21fnM5Rt6KDb4tIzwUzx0M/ySG47T9oA5EO+WjIXUH/L5LvVYXZg/qmn2I3 o72RvK/83JT/bvZbXVbJF+a6sDgEf5nkkyzl3SHrNtUfNow+rpDGEI39QAodF33/ozCF 630rOOXKb7JwrY0as+AxjZRmuuWvdIePljj5fCRDEFEAIEBTP85sYluMWdk4FW7Bb76G bMxCuyhN+Y+4ctFO3dyzar3ZMSwMB9DJzpKGSTI2/8OdbgdwFaNi664CbpjKip6iTp9u rwfg== X-Gm-Message-State: AOAM532mbGBiI6XHKsSnNDv02uHmWgsuSo+52jk5kXSEFbh5Q5AHV7gY tiN0Z/1xbzXnx5nteb9eF5PEl2pbpK5muA== X-Received: by 2002:a02:c65a:: with SMTP id k26mr8060036jan.29.1634723829551; Wed, 20 Oct 2021 02:57:09 -0700 (PDT) Received: from ircssh-2.c.rugged-nimbus-611.internal (80.60.198.104.bc.googleusercontent.com. [104.198.60.80]) by smtp.gmail.com with ESMTPSA id z16sm838652iow.42.2021.10.20.02.57.09 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Oct 2021 02:57:09 -0700 (PDT) Date: Wed, 20 Oct 2021 09:57:07 +0000 From: Sargun Dhillon To: LKML , netdev , Christian Brauner Subject: Retrieving the network namespace of a socket Message-ID: <20211020095707.GA16295@ircssh-2.c.rugged-nimbus-611.internal> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. I was wondering if anyone had any suggestions on where to add this capability, or suggestions how on how it might look? It appears like using network namespace IDs is the thing to do -- I'm unsure of whether this API fits better into ioctl_ns, getsockopt, netlink, or even somewhere in proc. I'm curious what people think. I think that the "easiest" way would be to drop it into fdinfo in proc. Alternatively, I may have overlooked an existing API. -Thanks, Sargun