ipfix.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright 2019 Hitoshi Irino <irino@sfc.wide.ad.jp> All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  14. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  15. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifndef _IPFIX_H
  25. #define _IPFIX_H
  26. #include "softflowd.h"
  27. #define IPFIX_TEMPLATE_SET_ID 2
  28. #define IPFIX_OPTION_TEMPLATE_SET_ID 3
  29. #define IPFIX_MIN_RECORD_SET_ID 256
  30. /* Flowset record ies the we care about */
  31. #define IPFIX_octetDeltaCount 1
  32. #define IPFIX_packetDeltaCount 2
  33. /* ... */
  34. #define IPFIX_protocolIdentifier 4
  35. #define IPFIX_ipClassOfService 5
  36. /* ... */
  37. #define IPFIX_tcpControlBits 6
  38. #define IPFIX_sourceTransportPort 7
  39. #define IPFIX_sourceIPv4Address 8
  40. /* ... */
  41. #define IPFIX_ingressInterface 10
  42. #define IPFIX_destinationTransportPort 11
  43. #define IPFIX_destinationIPv4Address 12
  44. /* ... */
  45. #define IPFIX_egressInterface 14
  46. /* ... */
  47. #define IPFIX_flowEndSysUpTime 21
  48. #define IPFIX_flowStartSysUpTime 22
  49. /* ... */
  50. #define IPFIX_sourceIPv6Address 27
  51. #define IPFIX_destinationIPv6Address 28
  52. /* ... */
  53. #define IPFIX_icmpTypeCodeIPv4 32
  54. /* ... */
  55. #define IPFIX_sourceMacAddress 56
  56. #define IPFIX_postDestinationMacAddress 57
  57. #define IPFIX_vlanId 58
  58. #define IPFIX_postVlanId 59
  59. #define IPFIX_ipVersion 60
  60. #define IPFIX_flowDirection 61
  61. #define IPFIX_mplsTopLabelStackSection 70
  62. /* ... */
  63. #define IPFIX_interfaceName 82
  64. /* ... */
  65. #define IPFIX_flowEndReason 136
  66. /* ... */
  67. #define IPFIX_icmpTypeCodeIPv6 139
  68. /* ... */
  69. #define IPFIX_meteringProcessId 143
  70. /* ... */
  71. #define IPFIX_flowStartSeconds 150
  72. #define IPFIX_flowEndSeconds 151
  73. #define IPFIX_flowStartMilliSeconds 152
  74. #define IPFIX_flowEndMilliSeconds 153
  75. #define IPFIX_flowStartMicroSeconds 154
  76. #define IPFIX_flowEndMicroSeconds 155
  77. #define IPFIX_flowStartNanoSeconds 156
  78. #define IPFIX_flowEndNanoSeconds 157
  79. /* ... */
  80. #define IPFIX_systemInitTimeMilliseconds 160
  81. /* ... */
  82. // flow end reason for ipfix ie 136
  83. #define IPFIX_flowEndReason_idleTimeout 0x01
  84. #define IPFIX_flowEndReason_activeTimeout 0x02
  85. #define IPFIX_flowEndReason_endOfFlow 0x03
  86. #define IPFIX_flowEndReason_forceEnd 0x04
  87. #define IPFIX_flowEndReason_lackOfResource 0x05
  88. #define IPFIX_SOFTFLOWD_MAX_PACKET_SIZE 1428
  89. #define IPFIX_mplsLabelStackSection_SIZE 3
  90. struct IPFIX_HEADER {
  91. u_int16_t version, length;
  92. u_int32_t export_time; /* in seconds */
  93. u_int32_t sequence, od_id;
  94. } __packed;
  95. struct IPFIX_SET_HEADER {
  96. u_int16_t set_id, length;
  97. } __packed;
  98. struct IPFIX_TEMPLATE_RECORD_HEADER {
  99. u_int16_t template_id, count;
  100. } __packed;
  101. struct IPFIX_TEMPLATE_SET_HEADER {
  102. struct IPFIX_SET_HEADER c;
  103. struct IPFIX_TEMPLATE_RECORD_HEADER r;
  104. } __packed;
  105. struct IPFIX_FIELD_SPECIFIER {
  106. u_int16_t ie, length;
  107. } __packed;
  108. struct IPFIX_OPTION_TEMPLATE_SET_HEADER {
  109. struct IPFIX_SET_HEADER c;
  110. union {
  111. struct {
  112. struct IPFIX_TEMPLATE_RECORD_HEADER r;
  113. u_int16_t scope_count;
  114. } i;
  115. struct {
  116. u_int16_t template_id;
  117. u_int16_t scope_length;
  118. u_int16_t option_length;
  119. } n;
  120. } u;
  121. } __packed;
  122. struct IPFIX_VENDOR_FIELD_SPECIFIER {
  123. u_int16_t ie, length;
  124. u_int32_t pen;
  125. } __packed;
  126. #define REVERSE_PEN 29305
  127. struct ntp_time_t {
  128. uint32_t second;
  129. uint32_t fraction;
  130. };
  131. /* Prototypes for functions to send NetFlow packets */
  132. int send_nflow9 (struct SENDPARAMETER sp);
  133. int send_ipfix (struct SENDPARAMETER sp);
  134. int send_ipfix_bi (struct SENDPARAMETER sp);
  135. /* Force a resend of the flow template */
  136. void ipfix_resend_template (void);
  137. int ipfix_init_fields (struct IPFIX_FIELD_SPECIFIER *dst, u_int * index,
  138. const struct IPFIX_FIELD_SPECIFIER *src,
  139. u_int field_number);
  140. void conv_unix_to_ntp (struct timeval tv, struct ntp_time_t *ntp);
  141. struct timeval conv_ntp_to_unix (struct ntp_time_t ntp);
  142. #endif /* _IPFIX_H */