Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

netlink.h 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
  3. * Copyright (c) 2017-2018 The strace developers.
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: LGPL-2.1-or-later
  7. */
  8. #ifndef STRACE_NETLINK_H
  9. # define STRACE_NETLINK_H
  10. # include <stdbool.h>
  11. # include <sys/socket.h>
  12. # include <linux/netlink.h>
  13. # ifndef NETLINK_SOCK_DIAG
  14. # define NETLINK_SOCK_DIAG 4
  15. # endif
  16. # ifndef NLM_F_NONREC
  17. # define NLM_F_NONREC 0x100
  18. # endif
  19. # ifndef NLM_F_CAPPED
  20. # define NLM_F_CAPPED 0x100
  21. # endif
  22. # undef NLMSG_HDRLEN
  23. # define NLMSG_HDRLEN ((unsigned int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
  24. # ifndef NLMSG_MIN_TYPE
  25. # define NLMSG_MIN_TYPE 0x10
  26. # endif
  27. # ifndef NLA_ALIGN
  28. # define NLA_ALIGN(len) (((len) + 3) & ~3)
  29. # endif
  30. # undef NLA_HDRLEN
  31. # define NLA_HDRLEN ((unsigned int) NLA_ALIGN(sizeof(struct nlattr)))
  32. # ifndef NLA_TYPE_MASK
  33. # define NLA_F_NESTED (1 << 15)
  34. # define NLA_F_NET_BYTEORDER (1 << 14)
  35. # define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
  36. # endif
  37. static inline bool
  38. is_nlmsg_ok(const struct nlmsghdr *const nlh, const ssize_t len)
  39. {
  40. return len >= (ssize_t) sizeof(*nlh)
  41. && nlh->nlmsg_len >= sizeof(*nlh)
  42. && (size_t) len >= nlh->nlmsg_len;
  43. }
  44. #endif /* !STRACE_NETLINK_H */