netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Florian Westphal <fw@strlen.de>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>, netfilter-devel@vger.kernel.org
Subject: Re: [nft PATCH RFC] monitor: Support printing processes which caused the event
Date: Wed, 10 May 2017 16:39:46 +0200	[thread overview]
Message-ID: <20170510143946.GX20805@orbyte.nwl.cc> (raw)
In-Reply-To: <20170510115748.GE16263@breakpoint.cc>

Hi,

On Wed, May 10, 2017 at 01:57:48PM +0200, Florian Westphal wrote:
> Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > On Wed, May 10, 2017 at 01:27:24PM +0200, Florian Westphal wrote:
> > > While most programs set it to their process id there is no guarantee.
> > > Its just a (unique) 32 bit identifier.
> > 
> > It's actually the kernel that decides what portID the socket gets
> > IIRC. For the first socket it uses the process ID, then for follow up
> > sockets, it just looks for a spare ID in the negative range of the 32
> > bit, if my memory serves well.
> 
> Argh, yes, of course...
> 
> > > Afaics one has to use /proc/net/netlink to map the portid to the inode
> > > and then walk /proc/*/fd/* to find the socket with that inode.
> > > 
> > > Perhaps there is a simpler way, maybe you can check what ss is doing
> > > and what info can be obtained via netlink diag.
> > 
> > I wouldn't be surprise if we need more kernel infrastructure to deal
> > with this. Parsing /proc for a netlink thing is definitely not ideal.
> 
> Yes.  From nft monitor point of view the most easy solution would be
> if the process id (or even the name?) would be sent back to userspace in a netlink
> attribute.  Do you think we can extend nf_tables to include
> get_task_comm() name and/or pid when/if we send update notifications?
> 
> (The pid is actually not that useful as process might have exited
> already).

The question is where to put it. Looking at the netlink message
structure, I see two options:

A) Extend struct nfgenmsg to contain PID and process name (a buffer of
   length TASK_COMM_LEN).
B) Add type-specific attributes for each type, like NFTA_RULE_PID and
   NFTA_RULE_PNAME.

The problem with A) is that it will break older user space expecting
sizeof(struct nfgenmsg) to be shorter. Additional attributes should not
be a problem here, but having to add them for each object type seems to
be a really ugly solution.

Cheers, Phil

  reply	other threads:[~2017-05-10 14:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-10 10:55 [nft PATCH RFC] monitor: Support printing processes which caused the event Phil Sutter
2017-05-10 11:27 ` Florian Westphal
2017-05-10 11:38   ` Pablo Neira Ayuso
2017-05-10 11:57     ` Florian Westphal
2017-05-10 14:39       ` Phil Sutter [this message]
2017-05-10 14:54         ` Florian Westphal
2017-05-10 15:11           ` Phil Sutter
2017-05-10 17:59             ` Florian Westphal
2017-05-11  6:41               ` Pablo Neira Ayuso
2017-05-11  6:59                 ` Florian Westphal
2017-05-11  8:27                   ` Phil Sutter
2017-05-11  9:58                     ` Pablo Neira Ayuso
2017-05-11  9:59                   ` Pablo Neira Ayuso
2017-05-10 11:34 ` Pablo Neira Ayuso
2017-05-10 12:52 ` Arturo Borrero Gonzalez
2017-05-10 14:02   ` Phil Sutter

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=20170510143946.GX20805@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --cc=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).