utils.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * netlink/utils.h Utility Functions
  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-2012 Thomas Graf <tgraf@suug.ch>
  10. */
  11. #ifndef NETLINK_UTILS_H_
  12. #define NETLINK_UTILS_H_
  13. #include <netlink/netlink.h>
  14. #include <netlink/list.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /**
  19. * @name Probability Constants
  20. * @{
  21. */
  22. /**
  23. * Lower probability limit
  24. * @ingroup utils
  25. */
  26. #define NL_PROB_MIN 0x0
  27. /**
  28. * Upper probability limit nl_dump_type
  29. * @ingroup utils
  30. */
  31. #define NL_PROB_MAX 0xffffffff
  32. /** @} */
  33. enum {
  34. NL_BYTE_RATE,
  35. NL_BIT_RATE,
  36. };
  37. /* unit pretty-printing */
  38. extern double nl_cancel_down_bytes(unsigned long long, char **);
  39. extern double nl_cancel_down_bits(unsigned long long, char **);
  40. extern int nl_rate2str(unsigned long long, int, char *, size_t);
  41. extern double nl_cancel_down_us(uint32_t, char **);
  42. /* generic unit translations */
  43. extern long nl_size2int(const char *);
  44. extern char * nl_size2str(const size_t, char *, const size_t);
  45. extern long nl_prob2int(const char *);
  46. /* time translations */
  47. extern int nl_get_user_hz(void);
  48. extern int nl_get_psched_hz(void);
  49. extern uint32_t nl_us2ticks(uint32_t);
  50. extern uint32_t nl_ticks2us(uint32_t);
  51. extern int nl_str2msec(const char *, uint64_t *);
  52. extern char * nl_msec2str(uint64_t, char *, size_t);
  53. /* link layer protocol translations */
  54. extern char * nl_llproto2str(int, char *, size_t);
  55. extern int nl_str2llproto(const char *);
  56. /* ethernet protocol translations */
  57. extern char * nl_ether_proto2str(int, char *, size_t);
  58. extern int nl_str2ether_proto(const char *);
  59. /* IP protocol translations */
  60. extern char * nl_ip_proto2str(int, char *, size_t);
  61. extern int nl_str2ip_proto(const char *);
  62. /* Dumping helpers */
  63. extern void nl_new_line(struct nl_dump_params *);
  64. extern void nl_dump(struct nl_dump_params *, const char *, ...);
  65. extern void nl_dump_line(struct nl_dump_params *, const char *, ...);
  66. enum {
  67. NL_CAPABILITY_NONE,
  68. /**
  69. * rtnl_route_build_msg() no longer guesses the route scope
  70. * if explicitly set to RT_SCOPE_NOWHERE.
  71. * @ingroup utils
  72. */
  73. NL_CAPABILITY_ROUTE_BUILD_MSG_SET_SCOPE = 1,
  74. #define NL_CAPABILITY_ROUTE_BUILD_MSG_SET_SCOPE NL_CAPABILITY_ROUTE_BUILD_MSG_SET_SCOPE
  75. /**
  76. * rtnl_link_veth_get_peer() now returns a reference that is owned by the
  77. * caller and must be released by the caller with rtnl_link_put().
  78. */
  79. NL_CAPABILITY_ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE = 2,
  80. #define NL_CAPABILITY_ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE NL_CAPABILITY_ROUTE_LINK_VETH_GET_PEER_OWN_REFERENCE
  81. /**
  82. * rtnl_u32_add_action() and rtnl_basic_add_action() now grab a reference to act
  83. * caller are free to release its own
  84. */
  85. NL_CAPABILITY_ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE = 3,
  86. #define NL_CAPABILITY_ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE NL_CAPABILITY_ROUTE_LINK_CLS_ADD_ACT_OWN_REFERENCE
  87. /**
  88. * Indicate that the local port is unspecified until the user accesses
  89. * it (via nl_socket_get_local_port()) or until nl_connect(). More importantly,
  90. * if the port is left unspecified, nl_connect() will retry generating another
  91. * port when bind() fails with ADDRINUSE.
  92. */
  93. NL_CAPABILITY_NL_CONNECT_RETRY_GENERATE_PORT_ON_ADDRINUSE = 4,
  94. #define NL_CAPABILITY_NL_CONNECT_RETRY_GENERATE_PORT_ON_ADDRINUSE NL_CAPABILITY_NL_CONNECT_RETRY_GENERATE_PORT_ON_ADDRINUSE
  95. __NL_CAPABILITY_MAX
  96. #define NL_CAPABILITY_MAX (__NL_CAPABILITY_MAX - 1)
  97. };
  98. int nl_has_capability (int capability);
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif