From: Pavel Emelyanov <xemul@parallels•com>
To: David Miller <davem@davemloft•net>,
Linux Netdev List <netdev@vger•kernel.org>
Subject: [PATCH] iproute: Use SOCK_DIAG_BY_FAMILY messages
Date: Tue, 06 Dec 2011 22:02:00 +0400 [thread overview]
Message-ID: <4EDE5898.5090809@parallels.com> (raw)
In-Reply-To: <4EDE573A.6040607@parallels.com>
Applies to cd72dcf13c8a4948ee5706794714287eeff62c90 commit of the
git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git tree
Signed-off-by: Pavel Emelyanov <xemul@parallels•com>
---
diff --git a/include/linux/inet_diag.h b/include/linux/inet_diag.h
index de6f1fc..7b6113a 100644
--- a/include/linux/inet_diag.h
+++ b/include/linux/inet_diag.h
@@ -6,6 +6,7 @@
/* Just some random number */
#define TCPDIAG_GETSOCK 18
#define DCCPDIAG_GETSOCK 19
+#define SOCK_DIAG_BY_FAMILY 20
#define INET_DIAG_GETSOCK_MAX 24
@@ -22,7 +23,7 @@ struct inet_diag_sockid {
/* Request structure */
-struct inet_diag_req {
+struct inet_diag_req_compat {
__u8 idiag_family; /* Family of addresses. */
__u8 idiag_src_len;
__u8 idiag_dst_len;
@@ -34,6 +35,15 @@ struct inet_diag_req {
__u32 idiag_dbs; /* Tables to dump (NI) */
};
+struct inet_diag_req {
+ __u8 sdiag_family;
+ __u8 sdiag_protocol;
+ __u8 idiag_ext;
+ __u8 pad;
+ __u32 idiag_states;
+ struct inet_diag_sockid id;
+};
+
enum {
INET_DIAG_REQ_NONE,
INET_DIAG_REQ_BYTECODE,
diff --git a/misc/ss.c b/misc/ss.c
index 5ce40c0..49afd4a 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1474,7 +1474,7 @@ static int tcp_show_sock(struct nlmsghdr *nlh, struct filter *f)
return 0;
}
-static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
+static int __tcp_show_netlink(struct filter *f, FILE *dump_fp, int family, int socktype)
{
int fd;
struct sockaddr_nl nladdr;
@@ -1496,12 +1496,13 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
nladdr.nl_family = AF_NETLINK;
req.nlh.nlmsg_len = sizeof(req);
- req.nlh.nlmsg_type = socktype;
+ req.nlh.nlmsg_type = SOCK_DIAG_BY_FAMILY;
req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
req.nlh.nlmsg_pid = 0;
req.nlh.nlmsg_seq = 123456;
memset(&req.r, 0, sizeof(req.r));
- req.r.idiag_family = AF_INET;
+ req.r.sdiag_family = family;
+ req.r.sdiag_protocol = socktype;
req.r.idiag_states = f->states;
if (show_mem)
req.r.idiag_ext |= (1<<(INET_DIAG_MEMINFO-1));
@@ -1589,10 +1590,6 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
return 0;
}
if (!dump_fp) {
- if (!(f->families & (1<<r->idiag_family))) {
- h = NLMSG_NEXT(h, status);
- continue;
- }
err = tcp_show_sock(h, NULL);
if (err < 0)
return err;
@@ -1613,6 +1610,18 @@ skip_it:
return 0;
}
+static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
+{
+ int err = 0;
+
+ if (f->families & (1 << AF_INET))
+ err |= __tcp_show_netlink(f, dump_fp, AF_INET, socktype);
+ if (f->families & (1 << AF_INET6))
+ err |= __tcp_show_netlink(f, dump_fp, AF_INET6, socktype);
+
+ return err;
+}
+
static int tcp_show_netlink_file(struct filter *f)
{
FILE *fp;
@@ -2789,7 +2798,7 @@ int main(int argc, char *argv[])
exit(-1);
}
}
- tcp_show_netlink(¤t_filter, dump_fp, TCPDIAG_GETSOCK);
+ tcp_show_netlink(¤t_filter, dump_fp, IPPROTO_TCP);
fflush(dump_fp);
exit(0);
}
@@ -2857,8 +2866,8 @@ int main(int argc, char *argv[])
if (current_filter.dbs & (1<<UDP_DB))
udp_show(¤t_filter);
if (current_filter.dbs & (1<<TCP_DB))
- tcp_show(¤t_filter, TCPDIAG_GETSOCK);
+ tcp_show(¤t_filter, IPPROTO_TCP);
if (current_filter.dbs & (1<<DCCP_DB))
- tcp_show(¤t_filter, DCCPDIAG_GETSOCK);
+ tcp_show(¤t_filter, IPPROTO_DCCP);
return 0;
}
next prev parent reply other threads:[~2011-12-06 18:02 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-06 17:56 [PATCH 0/11] Generalize the inet_diag infrastructure Pavel Emelyanov
2011-12-06 17:56 ` [PATCH 1/11] inet_diag: Partly rename inet_ to sock_ Pavel Emelyanov
2011-12-06 18:24 ` Stephen Hemminger
2011-12-06 18:42 ` David Miller
2011-12-06 17:57 ` [PATCH 2/11] sock_diag: Introduce new message type Pavel Emelyanov
2011-12-06 17:57 ` [PATCH 3/11] inet_diag: Move byte-code finding up the call-stack Pavel Emelyanov
2011-12-06 17:58 ` [PATCH 5/11] sock_diag: Initial skeleton Pavel Emelyanov
2011-12-06 17:58 ` [PATCH 6/11] inet_diag: Introduce new inet_diag_req header Pavel Emelyanov
2011-12-06 17:58 ` [PATCH 7/11] inet_diag: Switch the _get_exact to work with new header Pavel Emelyanov
2011-12-06 17:58 ` [PATCH 8/11] inet_diag: Switch the _dump " Pavel Emelyanov
2011-12-06 17:59 ` [PATCH 9/11] inet_diag: Introduce socket family checks Pavel Emelyanov
2011-12-06 17:59 ` [PATCH 10/11] inet_diag: Cleanup type2proto last user Pavel Emelyanov
2011-12-06 17:59 ` [PATCH 11/11] sock_diag: Move the sock_ code to net/core/ Pavel Emelyanov
2011-12-06 18:02 ` Pavel Emelyanov [this message]
2012-01-20 21:05 ` [PATCH] iproute: Use SOCK_DIAG_BY_FAMILY messages Stephen Hemminger
[not found] ` <4EDE5797.6010603@parallels.com>
2011-12-06 18:05 ` [PATCH 4/11] inet_diag: Switch from _GETSOCK to IPPROTO_ numbers Pavel Emelyanov
2011-12-06 18:58 ` [PATCH 0/11] Generalize the inet_diag infrastructure 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=4EDE5898.5090809@parallels.com \
--to=xemul@parallels$(echo .)com \
--cc=davem@davemloft$(echo .)net \
--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