netlink-local.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * netlink-local.h Local Netlink Interface
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation version 2.1
  7. * of the License.
  8. *
  9. * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
  10. */
  11. #ifndef NETLINK_LOCAL_H_
  12. #define NETLINK_LOCAL_H_
  13. #ifndef _GNU_SOURCE
  14. #define _GNU_SOURCE
  15. #endif
  16. #include <stdio.h>
  17. #include <errno.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <unistd.h>
  21. #include <fcntl.h>
  22. #include <math.h>
  23. #include <time.h>
  24. #include <stdarg.h>
  25. #include <ctype.h>
  26. #include <sys/types.h>
  27. #include <sys/socket.h>
  28. #include <inttypes.h>
  29. #include <assert.h>
  30. #include <limits.h>
  31. #include <arpa/inet.h>
  32. #include <netdb.h>
  33. #ifndef SOL_NETLINK
  34. #define SOL_NETLINK 270
  35. #endif
  36. #include <linux/types.h>
  37. /* local header copies */
  38. #include <linux/if.h>
  39. #include <linux/if_arp.h>
  40. #include <linux/if_ether.h>
  41. #include <linux/pkt_sched.h>
  42. #include <linux/pkt_cls.h>
  43. #include <linux/gen_stats.h>
  44. #include <netlink/netlink.h>
  45. #include <netlink/handlers.h>
  46. #include <netlink/cache.h>
  47. #include <netlink/object-api.h>
  48. #include <netlink/cache-api.h>
  49. #include <netlink-types.h>
  50. struct trans_tbl {
  51. int i;
  52. const char *a;
  53. };
  54. #define __ADD(id, name) { .i = id, .a = #name },
  55. struct trans_list {
  56. int i;
  57. char *a;
  58. struct nl_list_head list;
  59. };
  60. #define NL_DEBUG 1
  61. #define NL_DBG(LVL,FMT,ARG...) \
  62. do {} while (0)
  63. #define BUG() \
  64. do { \
  65. fprintf(stderr, "BUG: %s:%d\n", \
  66. __FILE__, __LINE__); \
  67. assert(0); \
  68. } while (0)
  69. extern int __nl_read_num_str_file(const char *path,
  70. int (*cb)(long, const char *));
  71. extern int __trans_list_add(int, const char *, struct nl_list_head *);
  72. extern void __trans_list_clear(struct nl_list_head *);
  73. extern char *__type2str(int, char *, size_t, struct trans_tbl *, size_t);
  74. extern int __str2type(const char *, struct trans_tbl *, size_t);
  75. extern char *__list_type2str(int, char *, size_t, struct nl_list_head *);
  76. extern int __list_str2type(const char *, struct nl_list_head *);
  77. extern char *__flags2str(int, char *, size_t, struct trans_tbl *, size_t);
  78. extern int __str2flags(const char *, struct trans_tbl *, size_t);
  79. extern void dump_from_ops(struct nl_object *, struct nl_dump_params *);
  80. #ifdef disabled
  81. static inline struct nl_cache *dp_cache(struct nl_object *obj)
  82. {
  83. if (obj->ce_cache == NULL)
  84. return nl_cache_mngt_require(obj->ce_ops->oo_name);
  85. return obj->ce_cache;
  86. }
  87. #endif
  88. static inline int nl_cb_call(struct nl_cb *cb, int type, struct nl_msg *msg)
  89. {
  90. return cb->cb_set[type](msg, cb->cb_args[type]);
  91. }
  92. #define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
  93. #ifndef offsetof
  94. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  95. #endif
  96. #define __init __attribute__ ((constructor))
  97. #define __exit __attribute__ ((destructor))
  98. #undef __deprecated
  99. #define __deprecated __attribute__ ((deprecated))
  100. #define min(x,y) ({ \
  101. typeof(x) _x = (x); \
  102. typeof(y) _y = (y); \
  103. (void) (&_x == &_y); \
  104. _x < _y ? _x : _y; })
  105. #define max(x,y) ({ \
  106. typeof(x) _x = (x); \
  107. typeof(y) _y = (y); \
  108. (void) (&_x == &_y); \
  109. _x > _y ? _x : _y; })
  110. extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *,
  111. struct nlmsghdr *, struct nl_parser_param *);
  112. static inline char *nl_cache_name(struct nl_cache *cache)
  113. {
  114. return cache->c_ops ? cache->c_ops->co_name : "unknown";
  115. }
  116. #define GENL_FAMILY(id, name) \
  117. { \
  118. { id, NL_ACT_UNSPEC, name }, \
  119. END_OF_MSGTYPES_LIST, \
  120. }
  121. static inline int wait_for_ack(struct nl_sock *sk)
  122. {
  123. if (sk->s_flags & NL_NO_AUTO_ACK)
  124. return 0;
  125. else
  126. return nl_wait_for_ack(sk);
  127. }
  128. #endif