summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Graf <tgraf@redhat.com>2013-08-05 06:10:42 (GMT)
committerThomas Graf <tgraf@redhat.com>2013-08-05 06:10:42 (GMT)
commit8443c7e9f130cfea1c1d3db8b61e20c547e8da07 (patch)
tree0f38f695fad7ed3607defc6d040d2f1c17d59db4
parent57f1d9f03afe7dd7db678d762081d29e60d55b1b (diff)
parent2ef91dac2670f7747747c2d246e9efe37903cd99 (diff)
downloadlibnl-8443c7e9f130cfea1c1d3db8b61e20c547e8da07.zip
libnl-8443c7e9f130cfea1c1d3db8b61e20c547e8da07.tar.gz
libnl-8443c7e9f130cfea1c1d3db8b61e20c547e8da07.tar.bz2
Merge pull request #44 from sassanosystems/idiag
Idiag
-rw-r--r--lib/idiag/idiag_msg_obj.c46
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile.am5
-rw-r--r--src/idiag-socket-details.c90
4 files changed, 121 insertions, 21 deletions
diff --git a/lib/idiag/idiag_msg_obj.c b/lib/idiag/idiag_msg_obj.c
index 707868a..19e6c5b 100644
--- a/lib/idiag/idiag_msg_obj.c
+++ b/lib/idiag/idiag_msg_obj.c
@@ -659,33 +659,39 @@ int idiagnl_msg_parse(struct nlmsghdr *nlh, struct idiagnl_msg **result)
sizeof(msg->idiag_tcpinfo));
if (tb[IDIAG_ATTR_MEMINFO]) {
- msg->idiag_meminfo = idiagnl_meminfo_alloc();
- if (!msg->idiag_meminfo)
+ struct idiagnl_meminfo *minfo = idiagnl_meminfo_alloc();
+ struct inet_diag_meminfo *raw_minfo = NULL;
+
+ if (!minfo)
goto errout_nomem;
- /* This memcpy works only because struct idiagnl_meminfo lines
- * up perfectly with inet_diag_meminfo.
- *
- * If you change one or the other, this must also change.
- */
- nla_memcpy(msg->idiag_meminfo, tb[IDIAG_ATTR_MEMINFO],
- sizeof(msg->idiag_meminfo));
- idiagnl_meminfo_get(msg->idiag_meminfo);
+ raw_minfo = (struct inet_diag_meminfo *)
+ nla_data(tb[IDIAG_ATTR_MEMINFO]);
+
+ idiagnl_meminfo_set_rmem(minfo, raw_minfo->idiag_rmem);
+ idiagnl_meminfo_set_wmem(minfo, raw_minfo->idiag_wmem);
+ idiagnl_meminfo_set_fmem(minfo, raw_minfo->idiag_fmem);
+ idiagnl_meminfo_set_tmem(minfo, raw_minfo->idiag_tmem);
+
+ msg->idiag_meminfo = minfo;
}
if (tb[IDIAG_ATTR_VEGASINFO]) {
- msg->idiag_vegasinfo = idiagnl_vegasinfo_alloc();
- if (!msg->idiag_vegasinfo)
+ struct idiagnl_vegasinfo *vinfo = idiagnl_vegasinfo_alloc();
+ struct tcpvegas_info *raw_vinfo = NULL;
+
+ if (!vinfo)
goto errout_nomem;
- /* This memcpy works only because struct idiagnl_vegasinfo lines
- * up perfectly with inet_diag_vegasinfo.
- *
- * If you change one or the other, this must also change.
- */
- nla_memcpy(&msg->idiag_vegasinfo, tb[IDIAG_ATTR_VEGASINFO],
- sizeof(msg->idiag_vegasinfo));
- idiagnl_vegasinfo_get(msg->idiag_vegasinfo);
+ raw_vinfo = (struct tcpvegas_info *)
+ nla_data(tb[IDIAG_ATTR_VEGASINFO]);
+
+ idiagnl_vegasinfo_set_enabled(vinfo, raw_vinfo->tcpv_enabled);
+ idiagnl_vegasinfo_set_rttcnt(vinfo, raw_vinfo->tcpv_rttcnt);
+ idiagnl_vegasinfo_set_rtt(vinfo, raw_vinfo->tcpv_rtt);
+ idiagnl_vegasinfo_set_minrtt(vinfo, raw_vinfo->tcpv_minrtt);
+
+ msg->idiag_vegasinfo = vinfo;
}
if (tb[IDIAG_ATTR_SKMEMINFO])
diff --git a/src/.gitignore b/src/.gitignore
index 3e091cb..0b99435 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -42,3 +42,4 @@ nl-classid-lookup
nl-pktloc-lookup
nl-link-enslave
nl-link-release
+idiag-socket-details
diff --git a/src/Makefile.am b/src/Makefile.am
index 6541f6d..87dd871 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,7 +37,8 @@ noinst_PROGRAMS = \
nl-list-caches nl-list-sockets \
nl-util-addr \
nl-link-enslave \
- nl-link-release
+ nl-link-release \
+ idiag-socket-details
genl_ctrl_list_SOURCES = genl-ctrl-list.c
@@ -99,3 +100,5 @@ nl_util_addr_SOURCES = nl-util-addr.c
nl_pktloc_lookup_SOURCES = nl-pktloc-lookup.c
nl_classid_lookup_SOURCES = nl-classid-lookup.c
+
+idiag_socket_details_SOURCES = idiag-socket-details.c
diff --git a/src/idiag-socket-details.c b/src/idiag-socket-details.c
new file mode 100644
index 0000000..9568676
--- /dev/null
+++ b/src/idiag-socket-details.c
@@ -0,0 +1,90 @@
+/*
+ * src/idiag-socket-details.c List socket details
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2 of the License.
+ *
+ * Copyright (c) 2013 Sassano Systems LLC <joe@sassanosystems.com>
+ */
+
+#include <netlink/cli/utils.h>
+#include <netlink/idiag/idiagnl.h>
+#include <netlink/idiag/msg.h>
+#include <linux/netlink.h>
+
+static void print_usage(void)
+{
+ printf(
+"Usage: idiag-socket-details [OPTION]\n"
+"\n"
+"Options\n"
+" --summary Show socket detail summary.\n"
+" --details Show socket details on multiple lines.\n"
+" --stats Show full socket statistics.\n"
+" -h, --help Show this help.\n"
+" -v, --version Show versioning information.\n"
+ );
+ exit(0);
+}
+
+int main(int argc, char *argv[])
+{
+ struct nl_sock *sock;
+ struct nl_cache *idiag_cache;
+ struct nl_dump_params params = {
+ .dp_type = NL_DUMP_LINE,
+ .dp_nl_cb = NULL,
+ .dp_fd = stdout,
+ };
+ int err = 0;
+
+ sock = nl_cli_alloc_socket();
+ nl_cli_connect(sock, NETLINK_INET_DIAG);
+ for (;;) {
+ int c, optidx = 0;
+ enum {
+ ARG_SUMMARY = 257,
+ ARG_DETAILS = 258,
+ ARG_STATS = 259,
+ ARG_FAMILY,
+ };
+ static struct option long_opts[] = {
+ { "details", 0, 0, ARG_DETAILS },
+ { "summary", 0, 0, ARG_SUMMARY },
+ { "stats", 0, 0, ARG_STATS},
+ { "help", 0, 0, 'h' },
+ { "version", 0, 0, 'v' },
+ { 0, 0, 0, 0 }
+ };
+
+ c = getopt_long(argc, argv, "hv", long_opts, &optidx);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case '?': exit(NLE_INVAL);
+ case ARG_SUMMARY: params.dp_type = NL_DUMP_LINE; break;
+ case ARG_DETAILS: params.dp_type = NL_DUMP_DETAILS; break;
+ case ARG_STATS: params.dp_type = NL_DUMP_STATS; break;
+ case 'h': print_usage(); break;
+ case 'v': nl_cli_print_version(); break;
+ }
+ }
+
+ if ((err = idiagnl_msg_alloc_cache(sock, AF_INET, IDIAG_SS_ALL,
+ &idiag_cache))) {
+ nl_cli_fatal(err, "Unable to allocate idiag msg cache: %s",
+ nl_geterror(err));
+ }
+
+ nl_cache_mngt_provide(idiag_cache);
+
+ nl_cache_dump_filter(idiag_cache, &params, NULL);
+
+ nl_cache_mngt_unprovide(idiag_cache);
+ nl_cache_free(idiag_cache);
+ nl_socket_free(sock);
+
+ return 0;
+}