Skip to content

Commit b465334

Browse files
Kirill Tkhaidavem330
authored andcommitted
net: Allow to show socket-specific information in /proc/[pid]/fdinfo/[fd]
This adds .show_fdinfo to socket_file_ops, so protocols will be able to print their specific data in fdinfo. Signed-off-by: Kirill Tkhai <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6b8350a commit b465334

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/linux/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ struct proto_ops {
171171
int (*compat_getsockopt)(struct socket *sock, int level,
172172
int optname, char __user *optval, int __user *optlen);
173173
#endif
174+
void (*show_fdinfo)(struct seq_file *m, struct socket *sock);
174175
int (*sendmsg) (struct socket *sock, struct msghdr *m,
175176
size_t total_len);
176177
/* Notes for implementing recvmsg:

net/socket.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ static ssize_t sock_sendpage(struct file *file, struct page *page,
128128
static ssize_t sock_splice_read(struct file *file, loff_t *ppos,
129129
struct pipe_inode_info *pipe, size_t len,
130130
unsigned int flags);
131+
static void sock_show_fdinfo(struct seq_file *m, struct file *f);
131132

132133
/*
133134
* Socket files have a set of 'special' operations as well as the generic file ones. These don't appear
@@ -150,6 +151,9 @@ static const struct file_operations socket_file_ops = {
150151
.sendpage = sock_sendpage,
151152
.splice_write = generic_splice_sendpage,
152153
.splice_read = sock_splice_read,
154+
#ifdef CONFIG_PROC_FS
155+
.show_fdinfo = sock_show_fdinfo,
156+
#endif
153157
};
154158

155159
/*
@@ -993,6 +997,14 @@ static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from)
993997
return res;
994998
}
995999

1000+
static void sock_show_fdinfo(struct seq_file *m, struct file *f)
1001+
{
1002+
struct socket *sock = f->private_data;
1003+
1004+
if (sock->ops->show_fdinfo)
1005+
sock->ops->show_fdinfo(m, sock);
1006+
}
1007+
9961008
/*
9971009
* Atomic setting of ioctl hooks to avoid race
9981010
* with module unload.

0 commit comments

Comments
 (0)