Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | /* |
| 16 | * flow_report.c |
| 17 | */ |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 18 | #include <vppinfra/atomics.h> |
Ole Troan | a9855ef | 2018-05-02 12:45:10 +0200 | [diff] [blame] | 19 | #include <vnet/ipfix-export/flow_report.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | #include <vnet/api_errno.h> |
Florin Coras | b040f98 | 2020-10-20 14:59:43 -0700 | [diff] [blame] | 21 | #include <vnet/udp/udp.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 22 | |
Juraj Sloboda | 837fbb1 | 2016-07-06 23:11:47 -0700 | [diff] [blame] | 23 | flow_report_main_t flow_report_main; |
| 24 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 25 | static_always_inline u8 |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 26 | stream_index_valid (ipfix_exporter_t *exp, u32 index) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 27 | { |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 28 | return index < vec_len (exp->streams) && exp->streams[index].domain_id != ~0; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 31 | static_always_inline flow_report_stream_t * |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 32 | add_stream (ipfix_exporter_t *exp) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 33 | { |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 34 | u32 i; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 35 | for (i = 0; i < vec_len (exp->streams); i++) |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 36 | if (!stream_index_valid (exp, i)) |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 37 | return &exp->streams[i]; |
| 38 | u32 index = vec_len (exp->streams); |
| 39 | vec_validate (exp->streams, index); |
| 40 | return &exp->streams[index]; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 43 | static_always_inline void |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 44 | delete_stream (ipfix_exporter_t *exp, u32 index) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 45 | { |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 46 | ASSERT (index < vec_len (exp->streams)); |
| 47 | ASSERT (exp->streams[index].domain_id != ~0); |
| 48 | exp->streams[index].domain_id = ~0; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 51 | static i32 |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 52 | find_stream (ipfix_exporter_t *exp, u32 domain_id, u16 src_port) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 53 | { |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 54 | flow_report_stream_t *stream; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 55 | u32 i; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 56 | for (i = 0; i < vec_len (exp->streams); i++) |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 57 | if (stream_index_valid (exp, i)) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 58 | { |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 59 | stream = &exp->streams[i]; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 60 | if (domain_id == stream->domain_id) |
| 61 | { |
| 62 | if (src_port != stream->src_port) |
| 63 | return -2; |
| 64 | return i; |
| 65 | } |
| 66 | else if (src_port == stream->src_port) |
| 67 | { |
| 68 | return -2; |
| 69 | } |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 70 | } |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 71 | return -1; |
| 72 | } |
| 73 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 74 | int |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 75 | send_template_packet (flow_report_main_t *frm, ipfix_exporter_t *exp, |
| 76 | flow_report_t *fr, u32 *buffer_indexp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | { |
| 78 | u32 bi0; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 79 | vlib_buffer_t *b0; |
Paul Atkins | 0ea1485 | 2021-10-04 17:29:54 +0100 | [diff] [blame] | 80 | ip4_ipfix_template_packet_t *tp4; |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 81 | ip6_ipfix_template_packet_t *tp6; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 82 | ipfix_message_header_t *h; |
Paul Atkins | 0ea1485 | 2021-10-04 17:29:54 +0100 | [diff] [blame] | 83 | ip4_header_t *ip4; |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 84 | ip6_header_t *ip6; |
| 85 | void *ip; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 86 | udp_header_t *udp; |
| 87 | vlib_main_t *vm = frm->vlib_main; |
| 88 | flow_report_stream_t *stream; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 89 | |
| 90 | ASSERT (buffer_indexp); |
| 91 | |
| 92 | if (fr->update_rewrite || fr->rewrite == 0) |
| 93 | { |
Paul Atkins | 5140484 | 2021-10-04 15:43:56 +0100 | [diff] [blame] | 94 | if (ip_address_is_zero (&exp->ipfix_collector) || |
| 95 | ip_address_is_zero (&exp->src_address)) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 96 | { |
| 97 | vlib_node_set_state (frm->vlib_main, flow_report_process_node.index, |
| 98 | VLIB_NODE_STATE_DISABLED); |
| 99 | return -1; |
| 100 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | vec_free (fr->rewrite); |
| 102 | fr->update_rewrite = 1; |
| 103 | } |
| 104 | |
| 105 | if (fr->update_rewrite) |
| 106 | { |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 107 | fr->rewrite = fr->rewrite_callback ( |
Paul Atkins | c2d476b | 2021-10-04 16:29:52 +0100 | [diff] [blame] | 108 | exp, fr, exp->collector_port, fr->report_elements, |
| 109 | fr->n_report_elements, fr->stream_indexp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 110 | fr->update_rewrite = 0; |
| 111 | } |
| 112 | |
| 113 | if (vlib_buffer_alloc (vm, &bi0, 1) != 1) |
| 114 | return -1; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 115 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | b0 = vlib_get_buffer (vm, bi0); |
| 117 | |
Damjan Marion | 8934a04 | 2019-02-09 23:29:26 +0100 | [diff] [blame] | 118 | ASSERT (vec_len (fr->rewrite) < vlib_buffer_get_default_data_size (vm)); |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 119 | |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 120 | clib_memcpy_fast (b0->data, fr->rewrite, vec_len (fr->rewrite)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | b0->current_data = 0; |
| 122 | b0->current_length = vec_len (fr->rewrite); |
Damjan Marion | dac0352 | 2018-02-01 15:30:13 +0100 | [diff] [blame] | 123 | b0->flags |= (VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_FLOW_REPORT); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 125 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = exp->fib_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 126 | |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 127 | if (ip_addr_version (&exp->ipfix_collector) == AF_IP4) |
| 128 | { |
| 129 | tp4 = vlib_buffer_get_current (b0); |
| 130 | ip4 = (ip4_header_t *) &tp4->ip4; |
| 131 | ip = ip4; |
| 132 | udp = (udp_header_t *) (ip4 + 1); |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | tp6 = vlib_buffer_get_current (b0); |
| 137 | ip6 = (ip6_header_t *) &tp6->ip6; |
| 138 | ip = ip6; |
| 139 | udp = (udp_header_t *) (ip6 + 1); |
| 140 | } |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 141 | h = (ipfix_message_header_t *) (udp + 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 143 | /* FIXUP: message header export_time */ |
| 144 | h->export_time = (u32) |
| 145 | (((f64) frm->unix_time_0) + |
| 146 | (vlib_time_now (frm->vlib_main) - frm->vlib_time_0)); |
| 147 | h->export_time = clib_host_to_net_u32 (h->export_time); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 148 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 149 | stream = &exp->streams[fr->stream_index]; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 150 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | /* FIXUP: message header sequence_number. Templates do not increase it */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 152 | h->sequence_number = clib_host_to_net_u32 (stream->sequence_number); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 153 | |
| 154 | /* FIXUP: udp length */ |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 155 | if (ip_addr_version (&exp->ipfix_collector) == AF_IP4) |
| 156 | udp->length = clib_host_to_net_u16 (b0->current_length - sizeof (*ip4)); |
| 157 | else |
| 158 | udp->length = clib_host_to_net_u16 (b0->current_length - sizeof (*ip6)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 159 | |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 160 | if (exp->udp_checksum || ip_addr_version (&exp->ipfix_collector) == AF_IP6) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 161 | { |
| 162 | /* RFC 7011 section 10.3.2. */ |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 163 | |
| 164 | if (ip_addr_version (&exp->ipfix_collector) == AF_IP4) |
| 165 | udp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip); |
| 166 | else |
| 167 | { |
| 168 | int bogus = 0; |
| 169 | udp->checksum = |
| 170 | ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip, &bogus); |
| 171 | } |
| 172 | |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 173 | if (udp->checksum == 0) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 174 | udp->checksum = 0xffff; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 177 | *buffer_indexp = bi0; |
Juraj Sloboda | 0d2a8e7 | 2016-07-07 02:59:28 -0700 | [diff] [blame] | 178 | |
| 179 | fr->last_template_sent = vlib_time_now (vm); |
| 180 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | return 0; |
| 182 | } |
| 183 | |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 184 | u32 always_inline |
| 185 | ipfix_write_headers (ipfix_exporter_t *exp, void *data, void **ip, |
| 186 | udp_header_t **udp, u32 len) |
| 187 | { |
| 188 | if (ip_addr_version (&exp->ipfix_collector) == AF_IP4) |
| 189 | { |
| 190 | ip4_ipfix_template_packet_t *tp4; |
| 191 | ip4_header_t *ip4; |
| 192 | |
| 193 | tp4 = (ip4_ipfix_template_packet_t *) data; |
| 194 | ip4 = (ip4_header_t *) &tp4->ip4; |
| 195 | ip4->ip_version_and_header_length = 0x45; |
| 196 | ip4->ttl = 254; |
| 197 | ip4->protocol = IP_PROTOCOL_UDP; |
| 198 | ip4->flags_and_fragment_offset = 0; |
| 199 | ip4->src_address.as_u32 = exp->src_address.ip.ip4.as_u32; |
| 200 | ip4->dst_address.as_u32 = exp->ipfix_collector.ip.ip4.as_u32; |
| 201 | *ip = ip4; |
| 202 | *udp = (udp_header_t *) (ip4 + 1); |
| 203 | |
| 204 | (*udp)->length = clib_host_to_net_u16 (len - sizeof (*ip4)); |
| 205 | return sizeof (*ip4); |
| 206 | } |
| 207 | else |
| 208 | { |
| 209 | ip6_ipfix_template_packet_t *tp6; |
| 210 | ip6_header_t *ip6; |
| 211 | |
| 212 | tp6 = (ip6_ipfix_template_packet_t *) data; |
| 213 | ip6 = (ip6_header_t *) &tp6->ip6; |
| 214 | ip6->ip_version_traffic_class_and_flow_label = |
| 215 | clib_host_to_net_u32 (6 << 28); |
| 216 | ip6->hop_limit = 254; |
| 217 | ip6->protocol = IP_PROTOCOL_UDP; |
| 218 | ip6->src_address = exp->src_address.ip.ip6; |
| 219 | ip6->dst_address = exp->ipfix_collector.ip.ip6; |
| 220 | *ip = ip6; |
| 221 | *udp = (udp_header_t *) (ip6 + 1); |
| 222 | (*udp)->length = clib_host_to_net_u16 (len - sizeof (*ip6)); |
| 223 | return sizeof (*ip6); |
| 224 | } |
| 225 | } |
| 226 | |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 227 | u8 * |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 228 | vnet_flow_rewrite_generic_callback (ipfix_exporter_t *exp, flow_report_t *fr, |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 229 | u16 collector_port, |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 230 | ipfix_report_element_t *report_elts, |
| 231 | u32 n_elts, u32 *stream_indexp) |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 232 | { |
Paul Atkins | 0ea1485 | 2021-10-04 17:29:54 +0100 | [diff] [blame] | 233 | ip4_header_t *ip4; |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 234 | ip6_header_t *ip6; |
| 235 | void *ip; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 236 | udp_header_t *udp; |
| 237 | ipfix_message_header_t *h; |
| 238 | ipfix_set_header_t *s; |
| 239 | ipfix_template_header_t *t; |
| 240 | ipfix_field_specifier_t *f; |
| 241 | ipfix_field_specifier_t *first_field; |
| 242 | u8 *rewrite = 0; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 243 | flow_report_stream_t *stream; |
| 244 | int i; |
| 245 | ipfix_report_element_t *ep; |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 246 | u32 size; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 247 | |
| 248 | ASSERT (stream_indexp); |
| 249 | ASSERT (n_elts); |
| 250 | ASSERT (report_elts); |
| 251 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 252 | stream = &exp->streams[fr->stream_index]; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 253 | *stream_indexp = fr->stream_index; |
| 254 | |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 255 | if (ip_addr_version (&exp->ipfix_collector) == AF_IP4) |
| 256 | size = sizeof (ip4_ipfix_template_packet_t); |
| 257 | else |
| 258 | size = sizeof (ip6_ipfix_template_packet_t); |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 259 | /* allocate rewrite space */ |
| 260 | vec_validate_aligned (rewrite, |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 261 | size + n_elts * sizeof (ipfix_field_specifier_t) - 1, |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 262 | CLIB_CACHE_LINE_BYTES); |
| 263 | |
| 264 | /* create the packet rewrite string */ |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 265 | ipfix_write_headers (exp, rewrite, &ip, &udp, vec_len (rewrite)); |
| 266 | |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 267 | h = (ipfix_message_header_t *) (udp + 1); |
| 268 | s = (ipfix_set_header_t *) (h + 1); |
| 269 | t = (ipfix_template_header_t *) (s + 1); |
| 270 | first_field = f = (ipfix_field_specifier_t *) (t + 1); |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 271 | udp->src_port = clib_host_to_net_u16 (stream->src_port); |
| 272 | udp->dst_port = clib_host_to_net_u16 (collector_port); |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 273 | |
| 274 | /* FIXUP LATER: message header export_time */ |
| 275 | h->domain_id = clib_host_to_net_u32 (stream->domain_id); |
| 276 | |
| 277 | ep = report_elts; |
| 278 | |
| 279 | for (i = 0; i < n_elts; i++) |
| 280 | { |
| 281 | f->e_id_length = ipfix_e_id_length (0, ep->info_element, ep->size); |
| 282 | f++; |
| 283 | ep++; |
| 284 | } |
| 285 | |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 286 | ASSERT (f - first_field); |
| 287 | /* Field count in this template */ |
| 288 | t->id_count = ipfix_id_count (fr->template_id, f - first_field); |
| 289 | |
| 290 | /* set length in octets */ |
| 291 | s->set_id_length = |
| 292 | ipfix_set_id_length (2 /* set_id */ , (u8 *) f - (u8 *) s); |
| 293 | |
| 294 | /* message length in octets */ |
| 295 | h->version_length = version_length ((u8 *) f - (u8 *) h); |
| 296 | |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 297 | if (ip_addr_version (&exp->ipfix_collector) == AF_IP4) |
| 298 | { |
| 299 | ip4 = (ip4_header_t *) ip; |
| 300 | ip4->length = clib_host_to_net_u16 ((u8 *) f - (u8 *) ip4); |
| 301 | ip4->checksum = ip4_header_checksum (ip4); |
| 302 | } |
| 303 | else |
| 304 | { |
| 305 | ip6 = (ip6_header_t *) ip; |
| 306 | /* IPv6 payload length does not include the IPv6 header */ |
| 307 | ip6->payload_length = clib_host_to_net_u16 ((u8 *) f - (u8 *) udp); |
| 308 | } |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 309 | |
| 310 | return rewrite; |
| 311 | } |
| 312 | |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 313 | vlib_buffer_t * |
| 314 | vnet_ipfix_exp_get_buffer (vlib_main_t *vm, ipfix_exporter_t *exp, |
| 315 | flow_report_t *fr, u32 thread_index) |
| 316 | { |
| 317 | u32 bi0; |
| 318 | vlib_buffer_t *b0; |
| 319 | |
| 320 | if (fr->per_thread_data[thread_index].buffer) |
| 321 | return fr->per_thread_data[thread_index].buffer; |
| 322 | |
| 323 | if (vlib_buffer_alloc (vm, &bi0, 1) != 1) |
| 324 | return NULL; |
| 325 | |
| 326 | /* Initialize the buffer */ |
| 327 | b0 = fr->per_thread_data[thread_index].buffer = vlib_get_buffer (vm, bi0); |
| 328 | |
| 329 | b0->current_data = 0; |
| 330 | b0->current_length = exp->all_headers_size; |
| 331 | b0->flags |= (VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_FLOW_REPORT); |
| 332 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0; |
| 333 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = exp->fib_index; |
| 334 | fr->per_thread_data[thread_index].next_data_offset = b0->current_length; |
| 335 | |
| 336 | return b0; |
| 337 | } |
| 338 | |
| 339 | /* |
| 340 | * Send a buffer that is mostly populated. Has flow records but needs some |
| 341 | * header fields updated. |
| 342 | */ |
| 343 | void |
| 344 | vnet_ipfix_exp_send_buffer (vlib_main_t *vm, ipfix_exporter_t *exp, |
| 345 | flow_report_t *fr, flow_report_stream_t *stream, |
| 346 | u32 thread_index, vlib_buffer_t *b0) |
| 347 | { |
| 348 | flow_report_main_t *frm = &flow_report_main; |
| 349 | vlib_frame_t *f; |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 350 | ipfix_set_header_t *s; |
| 351 | ipfix_message_header_t *h; |
Mohsin Kazmi | 3626a7c | 2022-02-22 11:42:35 +0000 | [diff] [blame] | 352 | ip4_header_t *ip4 = 0; |
| 353 | ip6_header_t *ip6 = 0; |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 354 | void *ip; |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 355 | udp_header_t *udp; |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 356 | int ip_len; |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 357 | |
| 358 | /* nothing to send */ |
| 359 | if (fr->per_thread_data[thread_index].next_data_offset <= |
| 360 | exp->all_headers_size) |
| 361 | return; |
| 362 | |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 363 | ip_len = ipfix_write_headers (exp, (void *) vlib_buffer_get_current (b0), |
| 364 | &ip, &udp, b0->current_length); |
| 365 | |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 366 | h = (ipfix_message_header_t *) (udp + 1); |
| 367 | s = (ipfix_set_header_t *) (h + 1); |
| 368 | |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 369 | udp->src_port = clib_host_to_net_u16 (stream->src_port); |
| 370 | udp->dst_port = clib_host_to_net_u16 (exp->collector_port); |
| 371 | udp->checksum = 0; |
| 372 | |
| 373 | /* FIXUP: message header export_time */ |
| 374 | h->export_time = |
| 375 | (u32) (((f64) frm->unix_time_0) + (vlib_time_now (vm) - frm->vlib_time_0)); |
| 376 | h->export_time = clib_host_to_net_u32 (h->export_time); |
| 377 | h->domain_id = clib_host_to_net_u32 (stream->domain_id); |
| 378 | |
| 379 | /* |
| 380 | * RFC 7011: Section 3.2 |
| 381 | * |
| 382 | * Incremental sequence counter modulo 2^32 of all IPFIX Data Records |
| 383 | * sent in the current stream from the current Observation Domain by |
| 384 | * the Exporting Process |
| 385 | */ |
| 386 | h->sequence_number = |
| 387 | clib_atomic_fetch_add (&stream->sequence_number, |
| 388 | fr->per_thread_data[thread_index].n_data_records); |
| 389 | h->sequence_number = clib_host_to_net_u32 (h->sequence_number); |
| 390 | |
| 391 | /* |
| 392 | * For data records we use the template ID as the set ID. |
| 393 | * RFC 7011: 3.4.3 |
| 394 | */ |
| 395 | s->set_id_length = ipfix_set_id_length ( |
| 396 | fr->template_id, |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 397 | b0->current_length - (ip_len + sizeof (*udp) + sizeof (*h))); |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 398 | h->version_length = |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 399 | version_length (b0->current_length - (ip_len + sizeof (*udp))); |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 400 | |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 401 | if (ip_addr_version (&exp->ipfix_collector) == AF_IP4) |
| 402 | { |
| 403 | ip4 = (ip4_header_t *) ip; |
| 404 | ip4->length = clib_host_to_net_u16 (b0->current_length); |
| 405 | ip4->checksum = ip4_header_checksum (ip4); |
| 406 | udp->length = clib_host_to_net_u16 (b0->current_length - sizeof (*ip4)); |
| 407 | ASSERT (ip4_header_checksum_is_valid (ip4)); |
| 408 | } |
| 409 | else |
| 410 | { |
| 411 | ip6 = (ip6_header_t *) ip; |
| 412 | /* Ipv6 payload length does not include the IPv6 header */ |
| 413 | ip6->payload_length = |
| 414 | clib_host_to_net_u16 (b0->current_length - sizeof (*ip6)); |
| 415 | udp->length = clib_host_to_net_u16 (b0->current_length - sizeof (*ip6)); |
| 416 | } |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 417 | |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 418 | if (exp->udp_checksum || ip_addr_version (&exp->ipfix_collector) == AF_IP6) |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 419 | { |
| 420 | /* RFC 7011 section 10.3.2. */ |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 421 | if (ip_addr_version (&exp->ipfix_collector) == AF_IP4) |
| 422 | udp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip4); |
| 423 | else |
| 424 | { |
| 425 | int bogus = 0; |
| 426 | udp->checksum = |
| 427 | ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip6, &bogus); |
| 428 | } |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 429 | if (udp->checksum == 0) |
| 430 | udp->checksum = 0xffff; |
| 431 | } |
| 432 | |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 433 | /* Find or allocate a frame */ |
| 434 | f = fr->per_thread_data[thread_index].frame; |
| 435 | if (PREDICT_FALSE (f == 0)) |
| 436 | { |
| 437 | u32 *to_next; |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 438 | if (ip_addr_version (&exp->ipfix_collector) == AF_IP4) |
| 439 | f = vlib_get_frame_to_node (vm, ip4_lookup_node.index); |
| 440 | else |
| 441 | f = vlib_get_frame_to_node (vm, ip6_lookup_node.index); |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 442 | fr->per_thread_data[thread_index].frame = f; |
| 443 | u32 bi0 = vlib_get_buffer_index (vm, b0); |
| 444 | |
| 445 | /* Enqueue the buffer */ |
| 446 | to_next = vlib_frame_vector_args (f); |
| 447 | to_next[0] = bi0; |
| 448 | f->n_vectors = 1; |
| 449 | } |
| 450 | |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 451 | if (ip_addr_version (&exp->ipfix_collector) == AF_IP4) |
| 452 | vlib_put_frame_to_node (vm, ip4_lookup_node.index, f); |
| 453 | else |
| 454 | vlib_put_frame_to_node (vm, ip6_lookup_node.index, f); |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 455 | |
| 456 | fr->per_thread_data[thread_index].frame = NULL; |
| 457 | fr->per_thread_data[thread_index].buffer = NULL; |
| 458 | fr->per_thread_data[thread_index].next_data_offset = 0; |
| 459 | } |
| 460 | |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 461 | static void |
| 462 | flow_report_process_send (vlib_main_t *vm, flow_report_main_t *frm, |
| 463 | ipfix_exporter_t *exp, flow_report_t *fr, |
| 464 | u32 next_node, u32 template_bi) |
| 465 | { |
| 466 | vlib_frame_t *nf = 0; |
| 467 | u32 *to_next; |
| 468 | |
| 469 | nf = vlib_get_frame_to_node (vm, next_node); |
| 470 | nf->n_vectors = 0; |
| 471 | to_next = vlib_frame_vector_args (nf); |
| 472 | |
| 473 | if (template_bi != ~0) |
| 474 | { |
| 475 | to_next[0] = template_bi; |
| 476 | to_next++; |
| 477 | nf->n_vectors++; |
| 478 | } |
| 479 | |
| 480 | nf = fr->flow_data_callback (frm, exp, fr, nf, to_next, next_node); |
| 481 | if (nf) |
| 482 | vlib_put_frame_to_node (vm, next_node, nf); |
| 483 | } |
| 484 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 485 | static uword |
| 486 | flow_report_process (vlib_main_t * vm, |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 487 | vlib_node_runtime_t * rt, vlib_frame_t * f) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 488 | { |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 489 | flow_report_main_t *frm = &flow_report_main; |
| 490 | flow_report_t *fr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 491 | u32 ip4_lookup_node_index; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 492 | vlib_node_t *ip4_lookup_node; |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 493 | u32 ip6_lookup_node_index; |
| 494 | vlib_node_t *ip6_lookup_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 495 | u32 template_bi; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 496 | int send_template; |
Matthew Smith | baa1870 | 2021-04-28 11:48:39 -0500 | [diff] [blame] | 497 | f64 now, wait_time; |
| 498 | f64 def_wait_time = 5.0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 499 | int rv; |
| 500 | uword event_type; |
| 501 | uword *event_data = 0; |
| 502 | |
| 503 | /* Wait for Godot... */ |
| 504 | vlib_process_wait_for_event_or_clock (vm, 1e9); |
| 505 | event_type = vlib_process_get_events (vm, &event_data); |
| 506 | if (event_type != 1) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 507 | clib_warning ("bogus kickoff event received, %d", event_type); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 508 | vec_reset_length (event_data); |
| 509 | |
| 510 | /* Enqueue pkts to ip4-lookup */ |
| 511 | ip4_lookup_node = vlib_get_node_by_name (vm, (u8 *) "ip4-lookup"); |
| 512 | ip4_lookup_node_index = ip4_lookup_node->index; |
| 513 | |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 514 | /* Enqueue pkts to ip6-lookup */ |
| 515 | ip6_lookup_node = vlib_get_node_by_name (vm, (u8 *) "ip6-lookup"); |
| 516 | ip6_lookup_node_index = ip6_lookup_node->index; |
| 517 | |
Matthew Smith | baa1870 | 2021-04-28 11:48:39 -0500 | [diff] [blame] | 518 | wait_time = def_wait_time; |
| 519 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 520 | while (1) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 521 | { |
Matthew Smith | baa1870 | 2021-04-28 11:48:39 -0500 | [diff] [blame] | 522 | vlib_process_wait_for_event_or_clock (vm, wait_time); |
Dave Barach | 0f3b680 | 2016-12-23 15:15:48 -0500 | [diff] [blame] | 523 | event_type = vlib_process_get_events (vm, &event_data); |
| 524 | vec_reset_length (event_data); |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 525 | ipfix_exporter_t *exp; |
| 526 | pool_foreach (exp, frm->exporters) |
Paul Atkins | 292992e | 2021-09-21 21:08:14 +0100 | [diff] [blame] | 527 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 528 | |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 529 | /* 5s delay by default, possibly reduced by template intervals */ |
| 530 | wait_time = def_wait_time; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 531 | |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 532 | vec_foreach (fr, exp->reports) |
Paul Atkins | 292992e | 2021-09-21 21:08:14 +0100 | [diff] [blame] | 533 | { |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 534 | f64 next_template; |
| 535 | now = vlib_time_now (vm); |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 536 | |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 537 | /* Need to send a template packet? */ |
| 538 | send_template = |
| 539 | now > (fr->last_template_sent + exp->template_interval); |
| 540 | send_template += fr->last_template_sent == 0; |
| 541 | template_bi = ~0; |
| 542 | rv = 0; |
| 543 | |
| 544 | if (send_template) |
| 545 | rv = send_template_packet (frm, exp, fr, &template_bi); |
| 546 | |
| 547 | if (rv < 0) |
| 548 | continue; |
| 549 | |
| 550 | /* |
| 551 | * decide if template should be sent sooner than current wait |
| 552 | * time |
| 553 | */ |
| 554 | next_template = |
| 555 | (fr->last_template_sent + exp->template_interval) - now; |
| 556 | wait_time = clib_min (wait_time, next_template); |
| 557 | |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 558 | if (ip_addr_version (&exp->ipfix_collector) == AF_IP4) |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 559 | { |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 560 | flow_report_process_send ( |
| 561 | vm, frm, exp, fr, ip4_lookup_node_index, template_bi); |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 562 | } |
Paul Atkins | e494ad1 | 2021-10-05 08:51:48 +0100 | [diff] [blame] | 563 | else |
| 564 | { |
| 565 | flow_report_process_send ( |
| 566 | vm, frm, exp, fr, ip6_lookup_node_index, template_bi); |
| 567 | } |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 568 | } |
Paul Atkins | 292992e | 2021-09-21 21:08:14 +0100 | [diff] [blame] | 569 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 572 | return 0; /* not so much */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 575 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 576 | VLIB_REGISTER_NODE (flow_report_process_node) = { |
| 577 | .function = flow_report_process, |
| 578 | .type = VLIB_NODE_TYPE_PROCESS, |
| 579 | .name = "flow-report-process", |
| 580 | }; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 581 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 582 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 583 | int |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 584 | vnet_flow_report_add_del (ipfix_exporter_t *exp, |
| 585 | vnet_flow_report_add_del_args_t *a, u16 *template_id) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 586 | { |
| 587 | int i; |
| 588 | int found_index = ~0; |
| 589 | flow_report_t *fr; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 590 | flow_report_stream_t *stream; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 591 | u32 si; |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 592 | vlib_thread_main_t *tm = &vlib_thread_main; |
| 593 | flow_report_main_t *frm = &flow_report_main; |
| 594 | vlib_main_t *vm = frm->vlib_main; |
| 595 | int size; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 596 | |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 597 | si = find_stream (exp, a->domain_id, a->src_port); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 598 | if (si == -2) |
| 599 | return VNET_API_ERROR_INVALID_VALUE; |
| 600 | if (si == -1 && a->is_add == 0) |
| 601 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
| 602 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 603 | for (i = 0; i < vec_len (exp->reports); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 604 | { |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 605 | fr = vec_elt_at_index (exp->reports, i); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 606 | if (fr->opaque.as_uword == a->opaque.as_uword |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 607 | && fr->rewrite_callback == a->rewrite_callback |
| 608 | && fr->flow_data_callback == a->flow_data_callback) |
| 609 | { |
| 610 | found_index = i; |
| 611 | if (template_id) |
| 612 | *template_id = fr->template_id; |
| 613 | break; |
| 614 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | if (a->is_add == 0) |
| 618 | { |
| 619 | if (found_index != ~0) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 620 | { |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 621 | for (int i = 0; |
| 622 | i < vec_len (exp->reports[found_index].per_thread_data); i++) |
| 623 | { |
| 624 | u32 bi; |
| 625 | if (exp->reports[found_index].per_thread_data[i].buffer) |
| 626 | { |
| 627 | bi = vlib_get_buffer_index ( |
| 628 | vm, exp->reports[found_index].per_thread_data[i].buffer); |
| 629 | vlib_buffer_free (vm, &bi, 1); |
| 630 | } |
| 631 | } |
| 632 | vec_free (exp->reports[found_index].per_thread_data); |
| 633 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 634 | vec_delete (exp->reports, 1, found_index); |
| 635 | stream = &exp->streams[si]; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 636 | stream->n_reports--; |
| 637 | if (stream->n_reports == 0) |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 638 | delete_stream (exp, si); |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 639 | return 0; |
| 640 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 641 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
| 642 | } |
| 643 | |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 644 | if (found_index != ~0) |
| 645 | return VNET_API_ERROR_VALUE_EXIST; |
| 646 | |
| 647 | if (si == -1) |
| 648 | { |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 649 | stream = add_stream (exp); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 650 | stream->domain_id = a->domain_id; |
| 651 | stream->src_port = a->src_port; |
| 652 | stream->sequence_number = 0; |
| 653 | stream->n_reports = 0; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 654 | si = stream - exp->streams; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 655 | } |
| 656 | else |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 657 | stream = &exp->streams[si]; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 658 | |
| 659 | stream->n_reports++; |
| 660 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 661 | vec_add2 (exp->reports, fr, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 662 | |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 663 | fr->stream_index = si; |
| 664 | fr->template_id = 256 + stream->next_template_no; |
| 665 | stream->next_template_no = (stream->next_template_no + 1) % (65536 - 256); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 666 | fr->update_rewrite = 1; |
| 667 | fr->opaque = a->opaque; |
| 668 | fr->rewrite_callback = a->rewrite_callback; |
| 669 | fr->flow_data_callback = a->flow_data_callback; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 670 | fr->report_elements = a->report_elements; |
| 671 | fr->n_report_elements = a->n_report_elements; |
| 672 | fr->stream_indexp = a->stream_indexp; |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 673 | vec_validate (fr->per_thread_data, tm->n_threads); |
| 674 | /* Store the flow_report index back in the args struct */ |
| 675 | a->flow_report_index = fr - exp->reports; |
| 676 | |
| 677 | size = 0; |
| 678 | for (int i = 0; i < fr->n_report_elements; i++) |
| 679 | size += fr->report_elements[i].size; |
| 680 | fr->data_record_size = size; |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 681 | if (template_id) |
| 682 | *template_id = fr->template_id; |
| 683 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 687 | clib_error_t * |
| 688 | flow_report_add_del_error_to_clib_error (int error) |
Juraj Sloboda | 24648ad | 2016-09-06 04:43:52 -0700 | [diff] [blame] | 689 | { |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 690 | switch (error) |
| 691 | { |
| 692 | case 0: |
| 693 | return 0; |
| 694 | case VNET_API_ERROR_NO_SUCH_ENTRY: |
| 695 | return clib_error_return (0, "Flow report not found"); |
| 696 | case VNET_API_ERROR_VALUE_EXIST: |
| 697 | return clib_error_return (0, "Flow report already exists"); |
| 698 | case VNET_API_ERROR_INVALID_VALUE: |
| 699 | return clib_error_return (0, "Expecting either still unused values " |
| 700 | "for both domain_id and src_port " |
| 701 | "or already used values for both fields"); |
| 702 | default: |
| 703 | return clib_error_return (0, "vnet_flow_report_add_del returned %d", |
| 704 | error); |
| 705 | } |
Juraj Sloboda | 24648ad | 2016-09-06 04:43:52 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 708 | void |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 709 | vnet_flow_reports_reset (ipfix_exporter_t *exp) |
Juraj Sloboda | 618ab08 | 2016-07-06 06:11:00 -0700 | [diff] [blame] | 710 | { |
| 711 | flow_report_t *fr; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 712 | u32 i; |
| 713 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 714 | for (i = 0; i < vec_len (exp->streams); i++) |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 715 | if (stream_index_valid (exp, i)) |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 716 | exp->streams[i].sequence_number = 0; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 717 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 718 | vec_foreach (fr, exp->reports) |
Paul Atkins | 292992e | 2021-09-21 21:08:14 +0100 | [diff] [blame] | 719 | { |
| 720 | fr->update_rewrite = 1; |
| 721 | fr->last_template_sent = 0; |
| 722 | } |
Juraj Sloboda | 618ab08 | 2016-07-06 06:11:00 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 725 | void |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 726 | vnet_stream_reset (ipfix_exporter_t *exp, u32 stream_index) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 727 | { |
| 728 | flow_report_t *fr; |
| 729 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 730 | exp->streams[stream_index].sequence_number = 0; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 731 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 732 | vec_foreach (fr, exp->reports) |
| 733 | if (exp->reports->stream_index == stream_index) |
Paul Atkins | 292992e | 2021-09-21 21:08:14 +0100 | [diff] [blame] | 734 | { |
| 735 | fr->update_rewrite = 1; |
| 736 | fr->last_template_sent = 0; |
| 737 | } |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 740 | int |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 741 | vnet_stream_change (ipfix_exporter_t *exp, u32 old_domain_id, u16 old_src_port, |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 742 | u32 new_domain_id, u16 new_src_port) |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 743 | { |
Paul Atkins | 9e82781 | 2021-09-22 08:15:03 +0100 | [diff] [blame] | 744 | i32 stream_index = find_stream (exp, old_domain_id, old_src_port); |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 745 | |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 746 | if (stream_index < 0) |
| 747 | return 1; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 748 | flow_report_stream_t *stream = &exp->streams[stream_index]; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 749 | stream->domain_id = new_domain_id; |
| 750 | stream->src_port = new_src_port; |
| 751 | if (old_domain_id != new_domain_id || old_src_port != new_src_port) |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 752 | vnet_stream_reset (exp, stream_index); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 753 | return 0; |
| 754 | } |
| 755 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 756 | static clib_error_t * |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 757 | set_ipfix_exporter_command_fn (vlib_main_t * vm, |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 758 | unformat_input_t * input, |
| 759 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 760 | { |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 761 | flow_report_main_t *frm = &flow_report_main; |
Paul Atkins | 5140484 | 2021-10-04 15:43:56 +0100 | [diff] [blame] | 762 | ip_address_t collector = IP_ADDRESS_V4_ALL_0S, src = IP_ADDRESS_V4_ALL_0S; |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 763 | u16 collector_port = UDP_DST_PORT_ipfix; |
Juraj Sloboda | 86634f0 | 2016-07-01 06:12:58 -0700 | [diff] [blame] | 764 | u32 fib_id; |
| 765 | u32 fib_index = ~0; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 766 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 767 | u32 path_mtu = 512; // RFC 7011 section 10.3.3. |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 768 | u32 template_interval = 20; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 769 | u8 udp_checksum = 0; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 770 | ipfix_exporter_t *exp = pool_elt_at_index (frm->exporters, 0); |
Paul Atkins | 5140484 | 2021-10-04 15:43:56 +0100 | [diff] [blame] | 771 | u32 ip_header_size; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 772 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 773 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 774 | { |
Paul Atkins | 5140484 | 2021-10-04 15:43:56 +0100 | [diff] [blame] | 775 | if (unformat (input, "collector %U", unformat_ip4_address, |
| 776 | &collector.ip.ip4)) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 777 | ; |
Elias Rudberg | 2dca180 | 2020-05-27 01:03:46 +0200 | [diff] [blame] | 778 | else if (unformat (input, "port %U", unformat_udp_port, |
| 779 | &collector_port)) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 780 | ; |
Paul Atkins | 5140484 | 2021-10-04 15:43:56 +0100 | [diff] [blame] | 781 | else if (unformat (input, "src %U", unformat_ip4_address, &src.ip.ip4)) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 782 | ; |
| 783 | else if (unformat (input, "fib-id %u", &fib_id)) |
| 784 | { |
| 785 | ip4_main_t *im = &ip4_main; |
| 786 | uword *p = hash_get (im->fib_index_by_table_id, fib_id); |
| 787 | if (!p) |
| 788 | return clib_error_return (0, "fib ID %d doesn't exist\n", fib_id); |
| 789 | fib_index = p[0]; |
| 790 | } |
| 791 | else if (unformat (input, "path-mtu %u", &path_mtu)) |
| 792 | ; |
| 793 | else if (unformat (input, "template-interval %u", &template_interval)) |
| 794 | ; |
| 795 | else if (unformat (input, "udp-checksum")) |
| 796 | udp_checksum = 1; |
| 797 | else |
| 798 | break; |
| 799 | } |
| 800 | |
Paul Atkins | 5140484 | 2021-10-04 15:43:56 +0100 | [diff] [blame] | 801 | /* |
| 802 | * If the collector address is set then the src must be too. |
| 803 | * Collector address can be set to 0 to disable exporter |
| 804 | */ |
| 805 | if (!ip_address_is_zero (&collector) && ip_address_is_zero (&src)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 806 | return clib_error_return (0, "src address required"); |
Paul Atkins | 5140484 | 2021-10-04 15:43:56 +0100 | [diff] [blame] | 807 | if (collector.version != src.version) |
| 808 | return clib_error_return ( |
| 809 | 0, "src address and dest address must use same IP version"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 810 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 811 | if (path_mtu > 1450 /* vpp does not support fragmentation */ ) |
| 812 | return clib_error_return (0, "too big path-mtu value, maximum is 1450"); |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 813 | |
| 814 | if (path_mtu < 68) |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 815 | return clib_error_return (0, "too small path-mtu value, minimum is 68"); |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 816 | |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 817 | /* Calculate how much header data we need. */ |
Paul Atkins | 5140484 | 2021-10-04 15:43:56 +0100 | [diff] [blame] | 818 | if (collector.version == AF_IP4) |
| 819 | ip_header_size = sizeof (ip4_header_t); |
| 820 | else |
| 821 | ip_header_size = sizeof (ip6_header_t); |
| 822 | exp->all_headers_size = ip_header_size + sizeof (udp_header_t) + |
Paul Atkins | 19a5f23 | 2021-09-27 21:30:13 +0100 | [diff] [blame] | 823 | sizeof (ipfix_message_header_t) + |
| 824 | sizeof (ipfix_set_header_t); |
| 825 | |
Juraj Sloboda | 618ab08 | 2016-07-06 06:11:00 -0700 | [diff] [blame] | 826 | /* Reset report streams if we are reconfiguring IP addresses */ |
Paul Atkins | 5140484 | 2021-10-04 15:43:56 +0100 | [diff] [blame] | 827 | if (ip_address_cmp (&exp->ipfix_collector, &collector) || |
| 828 | ip_address_cmp (&exp->src_address, &src) || |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 829 | exp->collector_port != collector_port) |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 830 | vnet_flow_reports_reset (exp); |
Juraj Sloboda | 618ab08 | 2016-07-06 06:11:00 -0700 | [diff] [blame] | 831 | |
Paul Atkins | 5140484 | 2021-10-04 15:43:56 +0100 | [diff] [blame] | 832 | exp->ipfix_collector = collector; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 833 | exp->collector_port = collector_port; |
Paul Atkins | 5140484 | 2021-10-04 15:43:56 +0100 | [diff] [blame] | 834 | exp->src_address = src; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 835 | exp->fib_index = fib_index; |
| 836 | exp->path_mtu = path_mtu; |
| 837 | exp->template_interval = template_interval; |
| 838 | exp->udp_checksum = udp_checksum; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 839 | |
Paul Atkins | 5140484 | 2021-10-04 15:43:56 +0100 | [diff] [blame] | 840 | if (collector.ip.ip4.as_u32) |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 841 | vlib_cli_output (vm, |
| 842 | "Collector %U, src address %U, " |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 843 | "fib index %d, path MTU %u, " |
| 844 | "template resend interval %us, " |
| 845 | "udp checksum %s", |
Paul Atkins | bf9918a | 2021-12-01 13:13:16 +0000 | [diff] [blame] | 846 | format_ip4_address, &exp->ipfix_collector.ip.ip4, |
| 847 | format_ip4_address, &exp->src_address.ip.ip4, fib_index, |
| 848 | path_mtu, template_interval, |
| 849 | udp_checksum ? "enabled" : "disabled"); |
Ole Troan | 5c74973 | 2017-03-13 13:39:52 +0100 | [diff] [blame] | 850 | else |
| 851 | vlib_cli_output (vm, "IPFIX Collector is disabled"); |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 852 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 853 | /* Turn on the flow reporting process */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 854 | vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 855 | return 0; |
| 856 | } |
| 857 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 858 | /* *INDENT-OFF* */ |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 859 | VLIB_CLI_COMMAND (set_ipfix_exporter_command, static) = { |
| 860 | .path = "set ipfix exporter", |
| 861 | .short_help = "set ipfix exporter " |
| 862 | "collector <ip4-address> [port <port>] " |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 863 | "src <ip4-address> [fib-id <fib-id>] " |
| 864 | "[path-mtu <path-mtu>] " |
Ignas Bacius | f3a522f | 2020-02-18 12:33:09 +0200 | [diff] [blame] | 865 | "[template-interval <template-interval>] " |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 866 | "[udp-checksum]", |
| 867 | .function = set_ipfix_exporter_command_fn, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 868 | }; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 869 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 870 | |
Dave Barach | 0f3b680 | 2016-12-23 15:15:48 -0500 | [diff] [blame] | 871 | |
| 872 | static clib_error_t * |
| 873 | ipfix_flush_command_fn (vlib_main_t * vm, |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 874 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Dave Barach | 0f3b680 | 2016-12-23 15:15:48 -0500 | [diff] [blame] | 875 | { |
| 876 | /* poke the flow reporting process */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 877 | vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0); |
Dave Barach | 0f3b680 | 2016-12-23 15:15:48 -0500 | [diff] [blame] | 878 | return 0; |
| 879 | } |
| 880 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 881 | /* *INDENT-OFF* */ |
Dave Barach | 0f3b680 | 2016-12-23 15:15:48 -0500 | [diff] [blame] | 882 | VLIB_CLI_COMMAND (ipfix_flush_command, static) = { |
| 883 | .path = "ipfix flush", |
| 884 | .short_help = "flush the current ipfix data [for make test]", |
| 885 | .function = ipfix_flush_command_fn, |
| 886 | }; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 887 | /* *INDENT-ON* */ |
Dave Barach | 0f3b680 | 2016-12-23 15:15:48 -0500 | [diff] [blame] | 888 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 889 | static clib_error_t * |
| 890 | flow_report_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 891 | { |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 892 | flow_report_main_t *frm = &flow_report_main; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 893 | ipfix_exporter_t *exp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 894 | |
| 895 | frm->vlib_main = vm; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 896 | frm->vnet_main = vnet_get_main (); |
| 897 | frm->unix_time_0 = time (0); |
| 898 | frm->vlib_time_0 = vlib_time_now (frm->vlib_main); |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 899 | /* |
| 900 | * Make sure that we can always access the first exporter for |
| 901 | * backwards compatibility reasons. |
| 902 | */ |
| 903 | pool_alloc (frm->exporters, IPFIX_EXPORTERS_MAX); |
| 904 | pool_get (frm->exporters, exp); |
| 905 | /* Verify that this is at index 0 */ |
| 906 | ASSERT (frm->exporters == exp); |
| 907 | exp->fib_index = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 908 | return 0; |
| 909 | } |
| 910 | |
Dave Barach | f8d5068 | 2019-05-14 18:01:44 -0400 | [diff] [blame] | 911 | VLIB_INIT_FUNCTION (flow_report_init); |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 912 | /* |
| 913 | * fd.io coding-style-patch-verification: ON |
| 914 | * |
| 915 | * Local Variables: |
| 916 | * eval: (c-set-style "gnu") |
| 917 | * End: |
| 918 | */ |