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 | #ifndef __included_vnet_flow_report_h__ |
| 16 | #define __included_vnet_flow_report_h__ |
| 17 | |
| 18 | #include <vlib/vlib.h> |
| 19 | #include <vnet/vnet.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | #include <vnet/ethernet/ethernet.h> |
| 21 | #include <vnet/ethernet/packet.h> |
| 22 | #include <vnet/ip/ip_packet.h> |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 23 | #include <vnet/ip/ip_types.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 24 | #include <vnet/ip/ip4_packet.h> |
| 25 | #include <vnet/ip/ip6_packet.h> |
Florin Coras | b040f98 | 2020-10-20 14:59:43 -0700 | [diff] [blame] | 26 | #include <vnet/udp/udp_packet.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | #include <vlib/cli.h> |
| 28 | #include <vppinfra/error.h> |
| 29 | #include <vppinfra/hash.h> |
| 30 | #include <vppinfra/cache.h> |
| 31 | |
Ole Troan | a9855ef | 2018-05-02 12:45:10 +0200 | [diff] [blame] | 32 | #include <vnet/ipfix-export/ipfix_packet.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 33 | |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 34 | /* ipfix field definitions for a particular report */ |
| 35 | typedef struct |
| 36 | { |
| 37 | u32 info_element; |
| 38 | u32 size; |
| 39 | } ipfix_report_element_t; |
| 40 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 41 | /* Used to build the rewrite */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 42 | typedef struct |
| 43 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 44 | ip4_header_t ip4; |
| 45 | udp_header_t udp; |
| 46 | ipfix_template_packet_t ipfix; |
| 47 | } ip4_ipfix_template_packet_t; |
| 48 | |
| 49 | struct flow_report_main; |
| 50 | struct flow_report; |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 51 | struct ipfix_exporter; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 53 | typedef vlib_frame_t *(vnet_flow_data_callback_t) ( |
| 54 | struct flow_report_main *frm, struct ipfix_exporter *exp, |
| 55 | struct flow_report *, vlib_frame_t *, u32 *, u32); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 56 | |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 57 | typedef u8 *(vnet_flow_rewrite_callback_t) (struct ipfix_exporter *exp, |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 58 | struct flow_report *, |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 59 | ip4_address_t *, ip4_address_t *, |
| 60 | u16, ipfix_report_element_t *elts, |
| 61 | u32 n_elts, u32 *stream_index); |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 62 | |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 63 | u8 *vnet_flow_rewrite_generic_callback (struct ipfix_exporter *exp, |
| 64 | struct flow_report *, ip4_address_t *, |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 65 | ip4_address_t *, u16, |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 66 | ipfix_report_element_t *elts, |
| 67 | u32 n_elts, u32 *stream_index); |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 68 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 69 | typedef union |
| 70 | { |
| 71 | void *as_ptr; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 72 | uword as_uword; |
| 73 | } opaque_t; |
| 74 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 75 | typedef struct |
| 76 | { |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 77 | u32 domain_id; |
| 78 | u32 sequence_number; |
| 79 | u16 src_port; |
| 80 | u16 n_reports; |
| 81 | u16 next_template_no; |
| 82 | } flow_report_stream_t; |
| 83 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 84 | typedef struct flow_report |
| 85 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | /* ipfix rewrite, set by callback */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 87 | u8 *rewrite; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 88 | u16 template_id; |
| 89 | u32 stream_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 90 | f64 last_template_sent; |
| 91 | int update_rewrite; |
| 92 | |
| 93 | /* Bitmap of fields to send */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 94 | uword *fields_to_send; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 95 | |
| 96 | /* Opaque data */ |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 97 | opaque_t opaque; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 98 | |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 99 | /* build-the-template-packet rewrite callback */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 100 | vnet_flow_rewrite_callback_t *rewrite_callback; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 101 | ipfix_report_element_t *report_elements; |
| 102 | u32 n_report_elements; |
| 103 | u32 *stream_indexp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 104 | |
| 105 | /* Send-flow-data callback */ |
| 106 | vnet_flow_data_callback_t *flow_data_callback; |
| 107 | } flow_report_t; |
| 108 | |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 109 | /* |
| 110 | * The maximum number of ipfix exporters we can have at once |
| 111 | */ |
| 112 | #define IPFIX_EXPORTERS_MAX 5 |
| 113 | |
| 114 | /* |
| 115 | * We support multiple exporters. Each one has its own configured |
| 116 | * destination, and its own set of reports and streams. |
| 117 | */ |
| 118 | typedef struct ipfix_exporter |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 119 | { |
| 120 | flow_report_t *reports; |
| 121 | flow_report_stream_t *streams; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 122 | |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 123 | /* ipfix collector ip address, port, our ip address, fib index */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | ip4_address_t ipfix_collector; |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 125 | u16 collector_port; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 126 | ip4_address_t src_address; |
Juraj Sloboda | 86634f0 | 2016-07-01 06:12:58 -0700 | [diff] [blame] | 127 | u32 fib_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 128 | |
Juraj Sloboda | 5a49bb9 | 2016-07-07 03:23:15 -0700 | [diff] [blame] | 129 | /* Path MTU */ |
| 130 | u32 path_mtu; |
| 131 | |
| 132 | /* time interval in seconds after which to resend templates */ |
| 133 | u32 template_interval; |
| 134 | |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 135 | /* UDP checksum calculation enable flag */ |
| 136 | u8 udp_checksum; |
Paul Atkins | 9ec6449 | 2021-09-21 20:49:12 +0100 | [diff] [blame] | 137 | } ipfix_exporter_t; |
| 138 | |
| 139 | typedef struct flow_report_main |
| 140 | { |
| 141 | /* |
| 142 | * A pool of the exporters. Entry 0 is always there for backwards |
| 143 | * compatability reasons. Entries 1 and above have to be created by |
| 144 | * the users. |
| 145 | */ |
| 146 | ipfix_exporter_t *exporters; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 147 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 148 | /* time scale transform. Joy. */ |
| 149 | u32 unix_time_0; |
| 150 | f64 vlib_time_0; |
| 151 | |
| 152 | /* convenience variables */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 153 | vlib_main_t *vlib_main; |
| 154 | vnet_main_t *vnet_main; |
Filip Tehlar | 53dea27 | 2021-06-21 10:57:49 +0000 | [diff] [blame] | 155 | |
| 156 | u16 msg_id_base; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 157 | } flow_report_main_t; |
| 158 | |
Juraj Sloboda | 837fbb1 | 2016-07-06 23:11:47 -0700 | [diff] [blame] | 159 | extern flow_report_main_t flow_report_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 160 | |
Damjan Marion | b8abf87 | 2016-03-14 20:02:35 +0100 | [diff] [blame] | 161 | extern vlib_node_registration_t flow_report_process_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 162 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 163 | typedef struct |
| 164 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 165 | vnet_flow_data_callback_t *flow_data_callback; |
| 166 | vnet_flow_rewrite_callback_t *rewrite_callback; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 167 | ipfix_report_element_t *report_elements; |
| 168 | u32 n_report_elements; |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 169 | opaque_t opaque; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 170 | int is_add; |
| 171 | u32 domain_id; |
Juraj Sloboda | 483f668 | 2016-07-06 17:04:06 -0700 | [diff] [blame] | 172 | u16 src_port; |
Dave Barach | 2be4581 | 2018-05-13 08:50:25 -0400 | [diff] [blame] | 173 | u32 *stream_indexp; |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 174 | } vnet_flow_report_add_del_args_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 176 | int vnet_flow_report_add_del (ipfix_exporter_t *exp, |
| 177 | vnet_flow_report_add_del_args_t *a, |
| 178 | u16 *template_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 180 | clib_error_t *flow_report_add_del_error_to_clib_error (int error); |
Juraj Sloboda | 24648ad | 2016-09-06 04:43:52 -0700 | [diff] [blame] | 181 | |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 182 | void vnet_flow_reports_reset (ipfix_exporter_t *exp); |
Juraj Sloboda | 837fbb1 | 2016-07-06 23:11:47 -0700 | [diff] [blame] | 183 | |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 184 | void vnet_stream_reset (ipfix_exporter_t *exp, u32 stream_index); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 185 | |
Paul Atkins | 40f9a7a | 2021-09-22 10:06:23 +0100 | [diff] [blame] | 186 | int vnet_stream_change (ipfix_exporter_t *exp, u32 old_domain_id, |
| 187 | u16 old_src_port, u32 new_domain_id, u16 new_src_port); |
Juraj Sloboda | ffa652a | 2016-08-07 23:43:42 -0700 | [diff] [blame] | 188 | |
Paul Atkins | d747dd9 | 2021-09-22 14:56:17 +0100 | [diff] [blame] | 189 | /* |
| 190 | * Search all the exporters for one that has a matching destination address. |
| 191 | */ |
| 192 | ipfix_exporter_t *vnet_ipfix_exporter_lookup (ip4_address_t *ipfix_collector); |
| 193 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 194 | #endif /* __included_vnet_flow_report_h__ */ |
Swarup Nayak | 6bcac06 | 2017-11-26 23:11:40 +0530 | [diff] [blame] | 195 | |
| 196 | /* |
| 197 | * fd.io coding-style-patch-verification: ON |
| 198 | * |
| 199 | * Local Variables: |
| 200 | * eval: (c-set-style "gnu") |
| 201 | * End: |
| 202 | */ |