ipfix.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. /* ... */
  61. #define IPFIX_icmpTypeCodeIPv6 139
  62. /* ... */
  63. #define IPFIX_meteringProcessId 143
  64. /* ... */
  65. #define IPFIX_flowStartSeconds 150
  66. #define IPFIX_flowEndSeconds 151
  67. #define IPFIX_flowStartMilliSeconds 152
  68. #define IPFIX_flowEndMilliSeconds 153
  69. #define IPFIX_flowStartMicroSeconds 154
  70. #define IPFIX_flowEndMicroSeconds 155
  71. #define IPFIX_flowStartNanoSeconds 156
  72. #define IPFIX_flowEndNanoSeconds 157
  73. /* ... */
  74. #define IPFIX_systemInitTimeMilliseconds 160
  75. /* ... */
  76. #define IPFIX_SOFTFLOWD_MAX_PACKET_SIZE 1428
  77. struct IPFIX_HEADER {
  78. u_int16_t version, length;
  79. u_int32_t export_time; /* in seconds */
  80. u_int32_t sequence, od_id;
  81. } __packed;
  82. struct IPFIX_SET_HEADER {
  83. u_int16_t set_id, length;
  84. } __packed;
  85. struct IPFIX_TEMPLATE_RECORD_HEADER {
  86. u_int16_t template_id, count;
  87. } __packed;
  88. struct IPFIX_TEMPLATE_SET_HEADER {
  89. struct IPFIX_SET_HEADER c;
  90. struct IPFIX_TEMPLATE_RECORD_HEADER r;
  91. } __packed;
  92. struct IPFIX_FIELD_SPECIFIER {
  93. u_int16_t ie, length;
  94. } __packed;
  95. struct IPFIX_OPTION_TEMPLATE_SET_HEADER {
  96. struct IPFIX_SET_HEADER c;
  97. union {
  98. struct {
  99. struct IPFIX_TEMPLATE_RECORD_HEADER r;
  100. u_int16_t scope_count;
  101. } i;
  102. struct {
  103. u_int16_t template_id;
  104. u_int16_t scope_length;
  105. u_int16_t option_length;
  106. } n;
  107. } u;
  108. } __packed;
  109. struct IPFIX_VENDOR_FIELD_SPECIFIER {
  110. u_int16_t ie, length;
  111. u_int32_t pen;
  112. } __packed;
  113. #define REVERSE_PEN 29305
  114. struct ntp_time_t {
  115. uint32_t second;
  116. uint32_t fraction;
  117. };
  118. /* Prototypes for functions to send NetFlow packets */
  119. int send_nflow9 (struct SENDPARAMETER sp);
  120. int send_ipfix (struct SENDPARAMETER sp);
  121. int send_ipfix_bi (struct SENDPARAMETER sp);
  122. /* Force a resend of the flow template */
  123. void ipfix_resend_template (void);
  124. int ipfix_init_fields (struct IPFIX_FIELD_SPECIFIER *dst, u_int * index,
  125. const struct IPFIX_FIELD_SPECIFIER *src,
  126. u_int field_number);
  127. void conv_unix_to_ntp (struct timeval tv, struct ntp_time_t *ntp);
  128. struct timeval conv_ntp_to_unix (struct ntp_time_t ntp);
  129. #endif /* _IPFIX_H */