From: Pavel Emelyanov <xemul@parallels•com>
To: Linux Netdev List <netdev@vger•kernel.org>,
David Miller <davem@davemloft•net>,
Eric Dumazet <eric.dumazet@gmail•com>
Subject: [PATCH 2/2] unix: Add /proc/net/unix_peers file
Date: Thu, 01 Dec 2011 21:42:06 +0400 [thread overview]
Message-ID: <4ED7BC6E.3040600@parallels.com> (raw)
In-Reply-To: <4ED7BC37.2030805@parallels.com>
Currently it's not possible to find out what processes are connected
to each other via a unix socket. In the proposed proc file a socket
inode number and its peer inode number are shown. With these two at
hands it's possible to determine the unix connections endpoints.
Signed-off-by: Pavel Emelyanov <xemul@parallels•com>
---
net/unix/af_unix.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 4b83a9c..4ce425a 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2305,6 +2305,33 @@ static int unix_seq_show(struct seq_file *seq, void *v)
return 0;
}
+static int unix_peers_seq_show(struct seq_file *seq, void *v)
+{
+ struct sock *s = v, *peer;
+ unsigned long ino, peer_ino = 0;
+
+ if (v == SEQ_START_TOKEN)
+ return 0;
+
+ unix_state_lock(s);
+ ino = sock_i_ino(s);
+ peer = unix_peer(s);
+ if (peer)
+ sock_hold(peer);
+ unix_state_unlock(s);
+
+ if (peer) {
+ unix_state_lock(peer);
+ peer_ino = sock_i_ino(peer);
+ unix_state_unlock(peer);
+
+ sock_put(peer);
+ }
+
+ seq_printf(seq, "%5lu %5lu\n", ino, peer_ino);
+ return 0;
+}
+
static const struct seq_operations unix_seq_ops = {
.start = unix_seq_start,
.next = unix_seq_next,
@@ -2326,18 +2353,46 @@ static const struct file_operations unix_seq_fops = {
.release = seq_release_net,
};
+static const struct seq_operations unix_peers_seq_ops = {
+ .start = unix_seq_start,
+ .next = unix_seq_next,
+ .stop = unix_seq_stop,
+ .show = unix_peers_seq_show,
+};
+
+static int unix_peers_seq_open(struct inode *inode, struct file *file)
+{
+ return seq_open_net(inode, file, &unix_peers_seq_ops,
+ sizeof(struct unix_iter_state));
+}
+
+static const struct file_operations unix_peers_seq_fops = {
+ .owner = THIS_MODULE,
+ .open = unix_peers_seq_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = seq_release_net,
+};
+
static int unix_proc_create(struct net *net)
{
if (!proc_net_fops_create(net, "unix", 0, &unix_seq_fops))
goto out;
+ if (!proc_net_fops_create(net, "unix_peers", 0, &unix_peers_seq_fops))
+ goto out_peers;
+
return 0;
+
+out_peers:
+ proc_net_remove(net, "unix");
out:
return -ENOMEM;
}
static void unix_proc_destroy(struct net *net)
{
+ proc_net_remove(net, "unix_peers");
proc_net_remove(net, "unix");
}
#else
--
1.5.5.6
next prev parent reply other threads:[~2011-12-01 17:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-01 17:41 [PATCH 0/2] unix: Introduce /proc/net/unix_peers file Pavel Emelyanov
2011-12-01 17:41 ` [PATCH 1/2] unix: Reformat proc files creation Pavel Emelyanov
2011-12-01 17:42 ` Pavel Emelyanov [this message]
2011-12-04 18:25 ` [PATCH 2/2] unix: Add /proc/net/unix_peers file David Miller
2011-12-05 10:25 ` Pavel Emelyanov
2011-12-05 23:47 ` David Miller
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=4ED7BC6E.3040600@parallels.com \
--to=xemul@parallels$(echo .)com \
--cc=davem@davemloft$(echo .)net \
--cc=eric.dumazet@gmail$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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