From: Florian Westphal <fw@strlen.de>
To: Phil Sutter <phil@nwl.cc>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>,
netfilter-devel@vger.kernel.org, Florian Westphal <fw@strlen.de>
Subject: Re: [nft PATCH RFC] monitor: Support printing processes which caused the event
Date: Wed, 10 May 2017 13:27:24 +0200 [thread overview]
Message-ID: <20170510112724.GD16263@breakpoint.cc> (raw)
In-Reply-To: <20170510105510.891-1-phil@nwl.cc>
Phil Sutter <phil@nwl.cc> wrote:
> This adds support for printing the process ID and name for changes which
> 'nft monitor' reports:
>
> | nft -a -p monitor
> | add chain ip t2 bla3 # pid 11616 (nft)
This prints something else, see below.
> diff --git a/src/netlink.c b/src/netlink.c
> index 7e7261fe1e1d4..67a2f2a901ebe 100644
> --- a/src/netlink.c
> +++ b/src/netlink.c
> @@ -2068,6 +2068,40 @@ next:
> nftnl_expr_iter_destroy(nlrei);
> }
>
> +static const char *pid2name(uint32_t pid)
> +{
> + static char buf[512];
> + int fd, rc;
> + char *p;
> +
> + snprintf(buf, sizeof(buf), "/proc/%u/cmdline", pid);
> + fd = open(buf, O_RDONLY);
> + if (fd == -1)
> + return "";
> +
> + rc = read(fd, buf, sizeof(buf));
This should do a
buf[sizeof(buf) - 1] = 0;
to be on safe side.
> +static void print_pid(const struct nlmsghdr *nlh)
> +{
> + const char *name;
> +
> + if (!pid_output)
> + return;
> + printf(" # pid %u", nlh->nlmsg_pid);
nlmsg_pid is the netlink portid.
While most programs set it to their process id there is no guarantee.
Its just a (unique) 32 bit identifier.
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.
next prev parent reply other threads:[~2017-05-10 11:27 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 [this message]
2017-05-10 11:38 ` Pablo Neira Ayuso
2017-05-10 11:57 ` Florian Westphal
2017-05-10 14:39 ` Phil Sutter
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=20170510112724.GD16263@breakpoint.cc \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
/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.