idiag: add a copy of linux/sock_diag.h
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>
This commit is contained in:
parent
9c066b9271
commit
b54f6d8023
5 changed files with 49 additions and 26 deletions
|
@ -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 \
|
||||
|
|
26
include/linux-private/linux/sock_diag.h
Normal file
26
include/linux-private/linux/sock_diag.h
Normal file
|
@ -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__ */
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 },
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue