2 * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
3 * Copyright (c) 2017-2018 The strace developers.
6 * SPDX-License-Identifier: LGPL-2.1-or-later
9 #ifndef STRACE_NETLINK_H
10 # define STRACE_NETLINK_H
13 # include <sys/socket.h>
14 # include <linux/netlink.h>
16 # ifndef NETLINK_SOCK_DIAG
17 # define NETLINK_SOCK_DIAG 4
21 # define NLM_F_NONREC 0x100
24 # define NLM_F_CAPPED 0x100
28 # define NLMSG_HDRLEN ((unsigned int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
30 # ifndef NLMSG_MIN_TYPE
31 # define NLMSG_MIN_TYPE 0x10
35 # define NLA_ALIGN(len) (((len) + 3) & ~3)
39 # define NLA_HDRLEN ((unsigned int) NLA_ALIGN(sizeof(struct nlattr)))
41 # ifndef NLA_TYPE_MASK
42 # define NLA_F_NESTED (1 << 15)
43 # define NLA_F_NET_BYTEORDER (1 << 14)
44 # define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
48 is_nlmsg_ok(const struct nlmsghdr *const nlh, const ssize_t len)
50 return len >= (ssize_t) sizeof(*nlh)
51 && nlh->nlmsg_len >= sizeof(*nlh)
52 && (size_t) len >= nlh->nlmsg_len;
55 #endif /* !STRACE_NETLINK_H */