misc: fix issues reported by clang-15
[vpp.git] / src / vnet / ipfix-export / flow_report_classify.c
index 15118f9..7e9fcfc 100644 (file)
@@ -15,6 +15,9 @@
 #include <vnet/ipfix-export/flow_report.h>
 #include <vnet/ipfix-export/flow_report_classify.h>
 #include <vnet/api_errno.h>
+#include <vnet/classify/vnet_classify.h>
+#include <vnet/ip/ip4.h>
+#include <vnet/udp/udp_local.h>
 
 /* Common prefix of tcp and udp headers
  * containing only source and destination port fields */
@@ -26,13 +29,10 @@ typedef struct
 flow_report_classify_main_t flow_report_classify_main;
 
 u8 *
-ipfix_classify_template_rewrite (flow_report_main_t * frm,
-                                flow_report_t * fr,
-                                ip4_address_t * collector_address,
-                                ip4_address_t * src_address,
+ipfix_classify_template_rewrite (ipfix_exporter_t *exp, flow_report_t *fr,
                                 u16 collector_port,
-                                ipfix_report_element_t * elts,
-                                u32 n_elts, u32 * stream_index)
+                                ipfix_report_element_t *elts, u32 n_elts,
+                                u32 *stream_index)
 {
   flow_report_classify_main_t *fcm = &flow_report_classify_main;
   vnet_classify_table_t *tblp;
@@ -58,7 +58,7 @@ ipfix_classify_template_rewrite (flow_report_main_t * frm,
   u8 *virt_mask;
   u8 *real_mask;
 
-  stream = &frm->streams[fr->stream_index];
+  stream = &exp->streams[fr->stream_index];
 
   ipfix_classify_table_t *table = &fcm->tables[flow_table_index];
 
@@ -106,8 +106,8 @@ ipfix_classify_template_rewrite (flow_report_main_t * frm,
   ip->ip_version_and_header_length = 0x45;
   ip->ttl = 254;
   ip->protocol = IP_PROTOCOL_UDP;
-  ip->src_address.as_u32 = src_address->as_u32;
-  ip->dst_address.as_u32 = collector_address->as_u32;
+  ip->src_address.as_u32 = exp->src_address.ip.ip4.as_u32;
+  ip->dst_address.as_u32 = exp->ipfix_collector.ip.ip4.as_u32;
   udp->src_port = clib_host_to_net_u16 (stream->src_port);
   udp->dst_port = clib_host_to_net_u16 (collector_port);
   udp->length = clib_host_to_net_u16 (vec_len (rewrite) - sizeof (*ip));
@@ -155,9 +155,9 @@ ipfix_classify_template_rewrite (flow_report_main_t * frm,
 }
 
 vlib_frame_t *
-ipfix_classify_send_flows (flow_report_main_t * frm,
-                          flow_report_t * fr,
-                          vlib_frame_t * f, u32 * to_next, u32 node_index)
+ipfix_classify_send_flows (flow_report_main_t *frm, ipfix_exporter_t *exp,
+                          flow_report_t *fr, vlib_frame_t *f, u32 *to_next,
+                          u32 node_index)
 {
   flow_report_classify_main_t *fcm = &flow_report_classify_main;
   vnet_classify_main_t *vcm = &vnet_classify_main;
@@ -179,7 +179,6 @@ ipfix_classify_send_flows (flow_report_main_t * frm,
   tcpudp_header_t *tcpudp;
   udp_header_t *udp;
   int field_index;
-  u32 records_this_buffer;
   u16 new_l0, old_l0;
   ip_csum_t sum0;
   vlib_main_t *vm = frm->vlib_main;
@@ -188,7 +187,7 @@ ipfix_classify_send_flows (flow_report_main_t * frm,
   u8 transport_protocol;
   u8 *virt_key;
 
-  stream = &frm->streams[fr->stream_index];
+  stream = &exp->streams[fr->stream_index];
 
   ipfix_classify_table_t *table = &fcm->tables[flow_table_index];
 
@@ -230,7 +229,7 @@ ipfix_classify_send_flows (flow_report_main_t * frm,
                  b0->current_length = copy_len;
                  b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
                  vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
-                 vnet_buffer (b0)->sw_if_index[VLIB_TX] = frm->fib_index;
+                 vnet_buffer (b0)->sw_if_index[VLIB_TX] = exp->fib_index;
 
                  tp = vlib_buffer_get_current (b0);
                  ip = (ip4_header_t *) & tp->ip4;
@@ -251,7 +250,6 @@ ipfix_classify_send_flows (flow_report_main_t * frm,
 
                  next_offset = (u32) (((u8 *) (s + 1)) - (u8 *) tp);
                  record_offset = next_offset;
-                 records_this_buffer = 0;
                }
 
              field_index = 0;
@@ -275,14 +273,13 @@ ipfix_classify_send_flows (flow_report_main_t * frm,
                                  sizeof (packets));
                next_offset += sizeof (packets);
              }
-             records_this_buffer++;
              stream->sequence_number++;
 
              /* Next record will have the same size as this record */
              u32 next_record_size = next_offset - record_offset;
              record_offset = next_offset;
 
-             if (next_offset + next_record_size > frm->path_mtu)
+             if (next_offset + next_record_size > exp->path_mtu)
                {
                  s->set_id_length = ipfix_set_id_length (fr->template_id,
                                                          next_offset -
@@ -311,7 +308,7 @@ ipfix_classify_send_flows (flow_report_main_t * frm,
                  udp->length =
                    clib_host_to_net_u16 (b0->current_length - sizeof (*ip));
 
-                 if (frm->udp_checksum)
+                 if (exp->udp_checksum)
                    {
                      /* RFC 7011 section 10.3.2. */
                      udp->checksum =
@@ -320,7 +317,7 @@ ipfix_classify_send_flows (flow_report_main_t * frm,
                        udp->checksum = 0xffff;
                    }
 
-                 ASSERT (ip->checksum == ip4_header_checksum (ip));
+                 ASSERT (ip4_header_checksum_is_valid (ip));
 
                  to_next[0] = bi0;
                  f->n_vectors++;
@@ -367,7 +364,7 @@ flush:
       ip->length = new_l0;
       udp->length = clib_host_to_net_u16 (b0->current_length - sizeof (*ip));
 
-      if (frm->udp_checksum)
+      if (exp->udp_checksum)
        {
          /* RFC 7011 section 10.3.2. */
          udp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip);
@@ -375,7 +372,7 @@ flush:
            udp->checksum = 0xffff;
        }
 
-      ASSERT (ip->checksum == ip4_header_checksum (ip));
+      ASSERT (ip4_header_checksum_is_valid (ip));
 
       to_next[0] = bi0;
       f->n_vectors++;
@@ -394,7 +391,7 @@ ipfix_classify_table_add_del_command_fn (vlib_main_t * vm,
                                         vlib_cli_command_t * cmd)
 {
   flow_report_classify_main_t *fcm = &flow_report_classify_main;
-  flow_report_main_t *frm = &flow_report_main;
+  ipfix_exporter_t *exp = &flow_report_main.exporters[0];
   vnet_flow_report_add_del_args_t args;
   ipfix_classify_table_t *table;
   int rv;
@@ -472,7 +469,7 @@ ipfix_classify_table_add_del_command_fn (vlib_main_t * vm,
   args.domain_id = fcm->domain_id;
   args.src_port = fcm->src_port;
 
-  rv = vnet_flow_report_add_del (frm, &args, NULL);
+  rv = vnet_flow_report_add_del (exp, &args, NULL);
 
   error = flow_report_add_del_error_to_clib_error (rv);
 
@@ -497,7 +494,7 @@ set_ipfix_classify_stream_command_fn (vlib_main_t * vm,
                                      vlib_cli_command_t * cmd)
 {
   flow_report_classify_main_t *fcm = &flow_report_classify_main;
-  flow_report_main_t *frm = &flow_report_main;
+  ipfix_exporter_t *exp = &flow_report_main.exporters[0];
   u32 domain_id = 1;
   u32 src_port = UDP_DST_PORT_ipfix;
 
@@ -515,7 +512,7 @@ set_ipfix_classify_stream_command_fn (vlib_main_t * vm,
   if (fcm->src_port != 0 &&
       (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
     {
-      int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
+      int rv = vnet_stream_change (exp, fcm->domain_id, fcm->src_port,
                                   domain_id, (u16) src_port);
       ASSERT (rv == 0);
     }