interface.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * interface data access header
  3. *
  4. * $Id$
  5. */
  6. #ifndef NETSNMP_ACCESS_INTERFACE_H
  7. #define NETSNMP_ACCESS_INTERFACE_H
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /*
  12. * define flags to indicate the availability of certain data
  13. */
  14. #define NETSNMP_INTERFACE_FLAGS_ACTIVE 0x00000001
  15. #define NETSNMP_INTERFACE_FLAGS_HAS_BYTES 0x00000002
  16. #define NETSNMP_INTERFACE_FLAGS_HAS_DROPS 0x00000004
  17. #define NETSNMP_INTERFACE_FLAGS_HAS_MCAST_PKTS 0x00000008
  18. #define NETSNMP_INTERFACE_FLAGS_HAS_HIGH_BYTES 0x00000010
  19. #define NETSNMP_INTERFACE_FLAGS_HAS_HIGH_PACKETS 0x00000020
  20. #define NETSNMP_INTERFACE_FLAGS_HAS_HIGH_SPEED 0x00000040
  21. #define NETSNMP_INTERFACE_FLAGS_DYNAMIC_SPEED 0x00000080
  22. #define NETSNMP_INTERFACE_FLAGS_HAS_LASTCHANGE 0x00000100
  23. #define NETSNMP_INTERFACE_FLAGS_HAS_DISCONTINUITY 0x00000200
  24. #define NETSNMP_INTERFACE_FLAGS_HAS_IF_FLAGS 0x00000400
  25. #define NETSNMP_INTERFACE_FLAGS_CAN_DOWN_PROTOCOL 0x00000800
  26. #define NETSNMP_INTERFACE_FLAGS_HAS_IPV4 0x00001000
  27. #define NETSNMP_INTERFACE_FLAGS_HAS_IPV6 0x00002000
  28. #define NETSNMP_INTERFACE_FLAGS_HAS_V4_RETRANSMIT 0x00004000
  29. #define NETSNMP_INTERFACE_FLAGS_HAS_V4_REASMMAX 0x00008000
  30. #define NETSNMP_INTERFACE_FLAGS_HAS_V6_RETRANSMIT 0x00010000
  31. #define NETSNMP_INTERFACE_FLAGS_HAS_V6_REASMMAX 0x00020000
  32. #define NETSNMP_INTERFACE_FLAGS_HAS_V6_REACHABLE 0x00040000
  33. #define NETSNMP_INTERFACE_FLAGS_HAS_V6_IFID 0x00080000
  34. #define NETSNMP_INTERFACE_FLAGS_HAS_V6_FORWARDING 0x00100000
  35. /* Some platforms, e.g.Linux, do not provide standalone counter
  36. * for incoming unicast packets - they provide counter of all packets
  37. * + separate counter for the multicast ones.
  38. * That means the counter of all packets must watched and checked
  39. * for overflows to reconstruct its 64-bit value (i.e. as usual
  40. * for counter of unicast packets), and after its expansion to 64-bits,
  41. * nr.of multicast packets must be substracted to get nr. of unicast
  42. * packets.
  43. * This flag marks stats of such platforms. Nr. of all incoming packets,
  44. * provided by the platform, must be stored in
  45. * netsnmp_interface_stats.iall and netsnmp_interface_stats.iucast will
  46. * be automatically calculated later.
  47. */
  48. #define NETSNMP_INTERFACE_FLAGS_CALCULATE_UCAST 0x00200000
  49. /*************************************************************
  50. * constants for enums for the MIB node
  51. * ifAdminStatus (INTEGER / ASN_INTEGER)
  52. *
  53. * since a Textual Convention may be referenced more than once in a
  54. * MIB, protect againt redifinitions of the enum values.
  55. */
  56. #ifndef ifAdminStatus_ENUMS
  57. #define ifAdminStatus_ENUMS
  58. #define IFADMINSTATUS_UP 1
  59. #define IFADMINSTATUS_DOWN 2
  60. #define IFADMINSTATUS_TESTING 3
  61. #endif /* ifAdminStatus_ENUMS */
  62. /*************************************************************
  63. * constants for enums for the MIB node
  64. * ifOperStatus (INTEGER / ASN_INTEGER)
  65. *
  66. * since a Textual Convention may be referenced more than once in a
  67. * MIB, protect againt redifinitions of the enum values.
  68. */
  69. #ifndef ifOperStatus_ENUMS
  70. #define ifOperStatus_ENUMS
  71. #define IFOPERSTATUS_UP 1
  72. #define IFOPERSTATUS_DOWN 2
  73. #define IFOPERSTATUS_TESTING 3
  74. #define IFOPERSTATUS_UNKNOWN 4
  75. #define IFOPERSTATUS_DORMANT 5
  76. #define IFOPERSTATUS_NOTPRESENT 6
  77. #define IFOPERSTATUS_LOWERLAYERDOWN 7
  78. #endif /* ifOperStatus_ENUMS */
  79. /* nominal speed of network interface - used when the real speed is unknown */
  80. #define NOMINAL_LINK_SPEED 10000000
  81. /**---------------------------------------------------------------------*/
  82. /*
  83. * structure definitions
  84. *
  85. * NOTE: if you add fields, update code dealing with
  86. * stats in interface_common.c, particularly
  87. * netsnmp_access_interface_entry_update_stats()
  88. *
  89. */
  90. typedef struct netsnmp_interface_stats_s {
  91. /*
  92. * "Dynamic" fields
  93. * Cached versions of byte/packet counters, etc
  94. * (saved as a 'struct counter64' even if the
  95. * high order half isn't actually used)
  96. *
  97. */
  98. /** input */
  99. struct counter64 ibytes;
  100. /*
  101. * nr. of all packets (to calculate iucast, when underlying platform does
  102. * not provide it)
  103. */
  104. struct counter64 iall;
  105. struct counter64 iucast;
  106. struct counter64 imcast;
  107. struct counter64 ibcast;
  108. unsigned int ierrors;
  109. unsigned int idiscards;
  110. unsigned int iunknown_protos;
  111. unsigned int inucast;
  112. /** output */
  113. struct counter64 obytes;
  114. struct counter64 oucast;
  115. struct counter64 omcast;
  116. struct counter64 obcast;
  117. unsigned int oerrors;
  118. unsigned int odiscards;
  119. unsigned int oqlen;
  120. unsigned int collisions;
  121. unsigned int onucast;
  122. } netsnmp_interface_stats;
  123. /*
  124. *
  125. * NOTE: if you add fields, update code dealing with
  126. * them in interface_common.c, particularly
  127. * netsnmp_access_interface_entry_copy().
  128. */
  129. typedef struct netsnmp_interface_entry_s {
  130. netsnmp_index oid_index;
  131. u_int ns_flags; /* net-snmp flags */
  132. oid index;
  133. /*
  134. * "Static" information
  135. * Typically constant for a given interface
  136. */
  137. char *name;
  138. char *descr;
  139. int type;
  140. u_int speed;
  141. u_int speed_high;
  142. char *paddr;
  143. u_int paddr_len;
  144. u_int mtu;
  145. u_int retransmit_v4; /* milliseconds */
  146. u_int retransmit_v6; /* milliseconds */
  147. u_int reachable_time; /* ipv6 / milliseconds */
  148. u_long lastchange;
  149. time_t discontinuity;
  150. uint16_t reasm_max_v4; /* 0..65535 */
  151. uint16_t reasm_max_v6; /* 1500..65535 */
  152. char admin_status;
  153. char oper_status;
  154. /** booleans (not TruthValues!) */
  155. char promiscuous;
  156. char connector_present;
  157. char forwarding_v6;
  158. char v6_if_id_len;
  159. u_char v6_if_id[8];
  160. /*-----------------------------------------------
  161. * platform/arch/access specific data
  162. */
  163. u_int os_flags; /* iff NETSNMP_INTERFACE_FLAGS_HAS_IF_FLAGS */
  164. /*
  165. * statistics
  166. */
  167. netsnmp_interface_stats stats;
  168. /** old_stats is used in netsnmp_access_interface_entry_update_stats */
  169. netsnmp_interface_stats *old_stats;
  170. } netsnmp_interface_entry;
  171. /*
  172. * conf file overrides
  173. */
  174. typedef struct _conf_if_list {
  175. const char *name;
  176. int type;
  177. uint64_t speed;
  178. struct _conf_if_list *next;
  179. } netsnmp_conf_if_list;
  180. typedef netsnmp_conf_if_list conf_if_list; /* backwards compat */
  181. /**---------------------------------------------------------------------*/
  182. /*
  183. * ACCESS function prototypes
  184. */
  185. void init_interface(void);
  186. void netsnmp_access_interface_init(void);
  187. /*
  188. * ifcontainer init
  189. */
  190. netsnmp_container * netsnmp_access_interface_container_init(u_int init_flags);
  191. #define NETSNMP_ACCESS_INTERFACE_INIT_NOFLAGS 0x0000
  192. #define NETSNMP_ACCESS_INTERFACE_INIT_ADDL_IDX_BY_NAME 0x0001
  193. /*
  194. * ifcontainer load and free
  195. */
  196. netsnmp_container*
  197. netsnmp_access_interface_container_load(netsnmp_container* container,
  198. u_int load_flags);
  199. #define NETSNMP_ACCESS_INTERFACE_LOAD_NOFLAGS 0x0000
  200. #define NETSNMP_ACCESS_INTERFACE_LOAD_NO_STATS 0x0001
  201. #define NETSNMP_ACCESS_INTERFACE_LOAD_IP4_ONLY 0x0002
  202. #define NETSNMP_ACCESS_INTERFACE_LOAD_IP6_ONLY 0x0004
  203. void netsnmp_access_interface_container_free(netsnmp_container *container,
  204. u_int free_flags);
  205. #define NETSNMP_ACCESS_INTERFACE_FREE_NOFLAGS 0x0000
  206. #define NETSNMP_ACCESS_INTERFACE_FREE_DONT_CLEAR 0x0001
  207. /*
  208. * create/free an ifentry
  209. */
  210. netsnmp_interface_entry *
  211. netsnmp_access_interface_entry_create(const char *name, oid if_index);
  212. void netsnmp_access_interface_entry_free(netsnmp_interface_entry * entry);
  213. int
  214. netsnmp_access_interface_entry_set_admin_status(netsnmp_interface_entry * entry,
  215. int ifAdminStatus);
  216. /*
  217. * find entry in container
  218. */
  219. netsnmp_interface_entry *
  220. netsnmp_access_interface_entry_get_by_name(netsnmp_container *container,
  221. const char *name);
  222. netsnmp_interface_entry *
  223. netsnmp_access_interface_entry_get_by_index(netsnmp_container *container,
  224. oid index);
  225. /*
  226. * find ifIndex for given interface. 0 == not found.
  227. */
  228. oid netsnmp_access_interface_index_find(const char *name);
  229. /*
  230. * find name for given index
  231. */
  232. const char *netsnmp_access_interface_name_find(oid index);
  233. /*
  234. * copy interface entry data
  235. */
  236. int netsnmp_access_interface_entry_copy(netsnmp_interface_entry * lhs,
  237. netsnmp_interface_entry * rhs);
  238. /*
  239. * utility routines
  240. */
  241. void netsnmp_access_interface_entry_guess_speed(netsnmp_interface_entry *);
  242. void netsnmp_access_interface_entry_overrides(netsnmp_interface_entry *);
  243. netsnmp_conf_if_list *
  244. netsnmp_access_interface_entry_overrides_get(const char * name);
  245. /**---------------------------------------------------------------------*/
  246. #if defined( USING_IF_MIB_IFTABLE_IFTABLE_DATA_ACCESS_MODULE ) && \
  247. ! defined( NETSNMP_NO_BACKWARDS_COMPATABILITY )
  248. void
  249. Interface_Scan_Init(void);
  250. int
  251. Interface_Scan_Next(short *index, char *name, netsnmp_interface_entry **entry,
  252. void *dc);
  253. int
  254. Interface_Scan_NextInt(int *index, char *name, netsnmp_interface_entry **entry,
  255. void *dc);
  256. #endif
  257. /**---------------------------------------------------------------------*/
  258. #ifdef __cplusplus
  259. }
  260. #endif
  261. #endif /* NETSNMP_ACCESS_INTERFACE_H */