netlink-local.h 3.5 KB

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