]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
idiag: add a copy of linux/sock_diag.h
authorCong Wang <xiyou.wangcong@gmail.com>
Mon, 27 Oct 2014 16:50:17 +0000 (09:50 -0700)
committerThomas Haller <thaller@redhat.com>
Mon, 24 Nov 2014 12:21:15 +0000 (13:21 +0100)
When we test idiag on 3.4 kernel, we always get ERANGE.
This is because libnl has its own copy for SK_MEMINFO_*,
which is actually newer than 3.4, where SK_MEMINFO_VARS
is larger than kernel's.

We add a copy from latest kernel, so on older kernel
libnl should still compile. Note, for kernel < 3.6
we don't have SK_MEMINFO_BACKLOG, we have to relax
the minlen.

'sock_diag.h' comes from v3.17 kernel sources
(bfe01a5ba2490f299e1d2d5508cbbbadd897bbe9), file
'include/uapi/linux/sock_diag.h'.

Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: Thomas Haller <thaller@redhat.com>
include/Makefile.am
include/linux-private/linux/sock_diag.h [new file with mode: 0644]
include/netlink-private/types.h
include/netlink/idiag/idiagnl.h
lib/idiag/idiag_msg_obj.c

index 82684a167692ac8168d7ecf611c6ac73e869f772..d5ce186f61c81573d0da715ee5ecd2d927306772 100644 (file)
@@ -145,6 +145,7 @@ noinst_HEADERS = \
        linux-private/linux/netfilter/nfnetlink_queue.h \
        linux-private/linux/netlink.h \
        linux-private/linux/pkt_cls.h \
+       linux-private/linux/sock_diag.h \
        linux-private/linux/tc_act/tc_mirred.h \
        linux-private/linux/pkt_sched.h \
        linux-private/linux/rtnetlink.h \
diff --git a/include/linux-private/linux/sock_diag.h b/include/linux-private/linux/sock_diag.h
new file mode 100644 (file)
index 0000000..b00e29e
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef _UAPI__SOCK_DIAG_H__
+#define _UAPI__SOCK_DIAG_H__
+
+#include <linux/types.h>
+
+#define SOCK_DIAG_BY_FAMILY 20
+
+struct sock_diag_req {
+       __u8    sdiag_family;
+       __u8    sdiag_protocol;
+};
+
+enum {
+       SK_MEMINFO_RMEM_ALLOC,
+       SK_MEMINFO_RCVBUF,
+       SK_MEMINFO_WMEM_ALLOC,
+       SK_MEMINFO_SNDBUF,
+       SK_MEMINFO_FWD_ALLOC,
+       SK_MEMINFO_WMEM_QUEUED,
+       SK_MEMINFO_OPTMEM,
+       SK_MEMINFO_BACKLOG,
+
+       SK_MEMINFO_VARS,
+};
+
+#endif /* _UAPI__SOCK_DIAG_H__ */
index 4ba13f745ab50b0bb087c49a24b985b681b44f24..b4dc8acb5f2b094cbf8f6e9bb4fabfde106d4fcb 100644 (file)
@@ -1001,7 +1001,7 @@ struct idiagnl_msg {
        struct idiagnl_meminfo *    idiag_meminfo;
        struct idiagnl_vegasinfo *  idiag_vegasinfo;
        struct tcp_info             idiag_tcpinfo;
-       uint32_t                    idiag_skmeminfo[IDIAG_SK_MEMINFO_VARS];
+       uint32_t                    idiag_skmeminfo[SK_MEMINFO_VARS];
 };
 
 struct idiagnl_req {
index d7434cd78283e389e256ac5fca3f7ec0638cd33c..64bccd7e9e65ac02643adbe31cd6e592648dbfcc 100644 (file)
@@ -13,6 +13,7 @@
 #define NETLINK_IDIAGNL_H_
 
 #include <netlink/netlink.h>
+#include <linux/sock_diag.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -74,22 +75,16 @@ enum {
  */
 #define IDIAG_ATTR_ALL ((1<<IDIAG_ATTR_MAX)-1)
 
-/**
- * Socket memory info identifiers
- * @ingroup idiag
- */
-enum {
-       IDIAG_SK_MEMINFO_RMEM_ALLOC,
-       IDIAG_SK_MEMINFO_RCVBUF,
-       IDIAG_SK_MEMINFO_WMEM_ALLOC,
-       IDIAG_SK_MEMINFO_SNDBUF,
-       IDIAG_SK_MEMINFO_FWD_ALLOC,
-       IDIAG_SK_MEMINFO_WMEM_QUEUED,
-       IDIAG_SK_MEMINFO_OPTMEM,
-       IDIAG_SK_MEMINFO_BACKLOG,
-
-       IDIAG_SK_MEMINFO_VARS,
-};
+/* Keep these only for compatibility, DO NOT USE THEM */
+#define        IDIAG_SK_MEMINFO_RMEM_ALLOC SK_MEMINFO_RMEM_ALLOC
+#define        IDIAG_SK_MEMINFO_RCVBUF SK_MEMINFO_RCVBUF
+#define        IDIAG_SK_MEMINFO_WMEM_ALLOC SK_MEMINFO_WMEM_ALLOC
+#define        IDIAG_SK_MEMINFO_SNDBUF SK_MEMINFO_SNDBUF
+#define        IDIAG_SK_MEMINFO_FWD_ALLOC SK_MEMINFO_FWD_ALLOC
+#define        IDIAG_SK_MEMINFO_WMEM_QUEUED SK_MEMINFO_WMEM_QUEUED
+#define        IDIAG_SK_MEMINFO_OPTMEM SK_MEMINFO_OPTMEM
+#define        IDIAG_SK_MEMINFO_BACKLOG SK_MEMINFO_BACKLOG
+#define        IDIAG_SK_MEMINFO_VARS SK_MEMINFO_VARS
 
 /**
  * Socket timer indentifiers
index 92a98e918c524365d257d2a8b0dd65f19ddb1e4e..f1b5e2827df5beef23c1fe2b304783ac07b6e83c 100644 (file)
@@ -529,24 +529,24 @@ static void idiag_msg_dump_stats(struct nl_object *obj, struct nl_dump_params *p
 
        nl_dump(p, "skmeminfo:  [\n");
        nl_dump(p, "\trmem alloc: %d\n",
-                       msg->idiag_skmeminfo[IDIAG_SK_MEMINFO_RMEM_ALLOC]);
+                       msg->idiag_skmeminfo[SK_MEMINFO_RMEM_ALLOC]);
        nl_dump(p, "\trcv buf: %s\n",
-                       nl_size2str(msg->idiag_skmeminfo[IDIAG_SK_MEMINFO_RCVBUF],
+                       nl_size2str(msg->idiag_skmeminfo[SK_MEMINFO_RCVBUF],
                                buf, sizeof(buf)));
        nl_dump(p, "\twmem alloc: %d\n",
-                       msg->idiag_skmeminfo[IDIAG_SK_MEMINFO_WMEM_ALLOC]);
+                       msg->idiag_skmeminfo[SK_MEMINFO_WMEM_ALLOC]);
        nl_dump(p, "\tsnd buf: %s\n",
-                       nl_size2str(msg->idiag_skmeminfo[IDIAG_SK_MEMINFO_SNDBUF],
+                       nl_size2str(msg->idiag_skmeminfo[SK_MEMINFO_SNDBUF],
                                buf, sizeof(buf)));
        nl_dump(p, "\tfwd alloc: %d\n",
-                       msg->idiag_skmeminfo[IDIAG_SK_MEMINFO_FWD_ALLOC]);
+                       msg->idiag_skmeminfo[SK_MEMINFO_FWD_ALLOC]);
        nl_dump(p, "\twmem queued: %s\n",
-                       nl_size2str(msg->idiag_skmeminfo[IDIAG_SK_MEMINFO_WMEM_QUEUED],
+                       nl_size2str(msg->idiag_skmeminfo[SK_MEMINFO_WMEM_QUEUED],
                                buf, sizeof(buf)));
        nl_dump(p, "\topt mem: %d\n",
-                       msg->idiag_skmeminfo[IDIAG_SK_MEMINFO_OPTMEM]);
+                       msg->idiag_skmeminfo[SK_MEMINFO_OPTMEM]);
        nl_dump(p, "\tbacklog: %d\n",
-                       msg->idiag_skmeminfo[IDIAG_SK_MEMINFO_BACKLOG]);
+                       msg->idiag_skmeminfo[SK_MEMINFO_BACKLOG]);
        nl_dump(p, "]\n\n");
 }
 
@@ -586,7 +586,8 @@ static struct nla_policy ext_policy[IDIAG_ATTR_MAX] = {
        [IDIAG_ATTR_CONG]       = { .type = NLA_STRING },
        [IDIAG_ATTR_TOS]        = { .type = NLA_U8 },
        [IDIAG_ATTR_TCLASS]     = { .type = NLA_U8 },
-       [IDIAG_ATTR_SKMEMINFO]  = { .minlen = (sizeof(uint32_t) * IDIAG_SK_MEMINFO_VARS)  },
+       /* Older kernel doesn't have SK_MEMINFO_BACKLOG */
+       [IDIAG_ATTR_SKMEMINFO]  = { .minlen = (sizeof(uint32_t) * (SK_MEMINFO_OPTMEM + 1)) },
        [IDIAG_ATTR_SHUTDOWN]   = { .type = NLA_U8 },
 };