nat: static mappings in flow hash
[vpp.git] / src / plugins / nat / lib / ipfix_logging.c
index 2fb8912..27a0b92 100644 (file)
@@ -51,7 +51,7 @@ typedef struct
   u8 nat_event;
   u32 src_ip;
   u32 nat_src_ip;
-  nat_protocol_t nat_proto;
+  ip_protocol_t proto;
   u16 src_port;
   u16 nat_src_port;
   u32 vrf_id;
@@ -536,8 +536,8 @@ nat_ipfix_header_create (flow_report_main_t * frm,
 }
 
 static inline void
-nat_ipfix_send (u32 thread_index, flow_report_main_t * frm,
-                vlib_frame_t * f, vlib_buffer_t * b0, u16 template_id)
+nat_ipfix_send (flow_report_main_t *frm, vlib_frame_t *f, vlib_buffer_t *b0,
+               u16 template_id)
 {
   ip4_ipfix_template_packet_t *tp;
   ipfix_message_header_t *h = 0;
@@ -577,9 +577,8 @@ nat_ipfix_send (u32 thread_index, flow_report_main_t * frm,
 
 static void
 nat_ipfix_logging_nat44_ses (u32 thread_index, u8 nat_event, u32 src_ip,
-                              u32 nat_src_ip, nat_protocol_t nat_proto,
-                              u16 src_port, u16 nat_src_port, u32 fib_index,
-                              int do_flush)
+                            u32 nat_src_ip, ip_protocol_t proto, u16 src_port,
+                            u16 nat_src_port, u32 fib_index, int do_flush)
 {
   nat_ipfix_logging_main_t *silm = &nat_ipfix_logging_main;
   nat_ipfix_per_thread_data_t *sitd = &silm->per_thread_data[thread_index];
@@ -590,12 +589,9 @@ nat_ipfix_logging_nat44_ses (u32 thread_index, u8 nat_event, u32 src_ip,
   u32 offset;
   vlib_main_t *vm = vlib_get_main ();
   u64 now;
-  u8 proto;
   u16 template_id;
   u32 vrf_id;
 
-  proto = nat_proto_to_ip_proto (nat_proto);
-
   now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
   now += silm->milisecond_time_0;
 
@@ -613,7 +609,6 @@ nat_ipfix_logging_nat44_ses (u32 thread_index, u8 nat_event, u32 src_ip,
        }
 
       b0 = sitd->nat44_session_buffer = vlib_get_buffer (vm, bi0);
-      VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
       offset = 0;
     }
   else
@@ -674,7 +669,7 @@ nat_ipfix_logging_nat44_ses (u32 thread_index, u8 nat_event, u32 src_ip,
       template_id = clib_atomic_fetch_or (
         &silm->nat44_session_template_id,
         0);
-      nat_ipfix_send (thread_index, frm, f, b0, template_id);
+      nat_ipfix_send (frm, f, b0, template_id);
       sitd->nat44_session_frame = 0;
       sitd->nat44_session_buffer = 0;
       offset = 0;
@@ -714,7 +709,6 @@ nat_ipfix_logging_addr_exhausted (u32 thread_index, u32 pool_id, int do_flush)
        }
 
       b0 = sitd->addr_exhausted_buffer = vlib_get_buffer (vm, bi0);
-      VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
       offset = 0;
     }
   else
@@ -758,7 +752,7 @@ nat_ipfix_logging_addr_exhausted (u32 thread_index, u32 pool_id, int do_flush)
       template_id = clib_atomic_fetch_or (
           &silm->addr_exhausted_template_id,
           0);
-      nat_ipfix_send (thread_index, frm, f, b0, template_id);
+      nat_ipfix_send (frm, f, b0, template_id);
       sitd->addr_exhausted_frame = 0;
       sitd->addr_exhausted_buffer = 0;
       offset = 0;
@@ -780,7 +774,7 @@ nat_ipfix_logging_max_entries_per_usr (u32 thread_index,
   vlib_main_t *vm = vlib_get_main ();
   u64 now;
   u8 nat_event = QUOTA_EXCEEDED;
-  u32 quota_event = MAX_ENTRIES_PER_USER;
+  u32 quota_event = clib_host_to_net_u32 (MAX_ENTRIES_PER_USER);
   u16 template_id;
 
   now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
@@ -800,7 +794,6 @@ nat_ipfix_logging_max_entries_per_usr (u32 thread_index,
        }
 
       b0 = sitd->max_entries_per_user_buffer = vlib_get_buffer (vm, bi0);
-      VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
       offset = 0;
     }
   else
@@ -835,6 +828,7 @@ nat_ipfix_logging_max_entries_per_usr (u32 thread_index,
       clib_memcpy_fast (b0->data + offset, &quota_event, sizeof (quota_event));
       offset += sizeof (quota_event);
 
+      limit = clib_host_to_net_u32 (limit);
       clib_memcpy_fast (b0->data + offset, &limit, sizeof (limit));
       offset += sizeof (limit);
 
@@ -850,7 +844,7 @@ nat_ipfix_logging_max_entries_per_usr (u32 thread_index,
       template_id = clib_atomic_fetch_or (
           &silm->max_entries_per_user_template_id,
           0);
-      nat_ipfix_send (thread_index, frm, f, b0, template_id);
+      nat_ipfix_send (frm, f, b0, template_id);
       sitd->max_entries_per_user_frame = 0;
       sitd->max_entries_per_user_buffer = 0;
       offset = 0;
@@ -871,7 +865,7 @@ nat_ipfix_logging_max_ses (u32 thread_index, u32 limit, int do_flush)
   vlib_main_t *vm = vlib_get_main ();
   u64 now;
   u8 nat_event = QUOTA_EXCEEDED;
-  u32 quota_event = MAX_SESSION_ENTRIES;
+  u32 quota_event = clib_host_to_net_u32 (MAX_SESSION_ENTRIES);
   u16 template_id;
 
   now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
@@ -891,7 +885,6 @@ nat_ipfix_logging_max_ses (u32 thread_index, u32 limit, int do_flush)
        }
 
       b0 = sitd->max_sessions_buffer = vlib_get_buffer (vm, bi0);
-      VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
       offset = 0;
     }
   else
@@ -926,6 +919,7 @@ nat_ipfix_logging_max_ses (u32 thread_index, u32 limit, int do_flush)
       clib_memcpy_fast (b0->data + offset, &quota_event, sizeof (quota_event));
       offset += sizeof (quota_event);
 
+      limit = clib_host_to_net_u32 (limit);
       clib_memcpy_fast (b0->data + offset, &limit, sizeof (limit));
       offset += sizeof (limit);
 
@@ -938,7 +932,7 @@ nat_ipfix_logging_max_ses (u32 thread_index, u32 limit, int do_flush)
       template_id = clib_atomic_fetch_or (
         &silm->max_sessions_template_id,
         0);
-      nat_ipfix_send (thread_index, frm, f, b0, template_id);
+      nat_ipfix_send (frm, f, b0, template_id);
       sitd->max_sessions_frame = 0;
       sitd->max_sessions_buffer = 0;
       offset = 0;
@@ -959,7 +953,7 @@ nat_ipfix_logging_max_bib (u32 thread_index, u32 limit, int do_flush)
   vlib_main_t *vm = vlib_get_main ();
   u64 now;
   u8 nat_event = QUOTA_EXCEEDED;
-  u32 quota_event = MAX_BIB_ENTRIES;
+  u32 quota_event = clib_host_to_net_u32 (MAX_BIB_ENTRIES);
   u16 template_id;
 
   now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
@@ -979,7 +973,6 @@ nat_ipfix_logging_max_bib (u32 thread_index, u32 limit, int do_flush)
        }
 
       b0 = sitd->max_bibs_buffer = vlib_get_buffer (vm, bi0);
-      VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
       offset = 0;
     }
   else
@@ -1014,6 +1007,7 @@ nat_ipfix_logging_max_bib (u32 thread_index, u32 limit, int do_flush)
       clib_memcpy_fast (b0->data + offset, &quota_event, sizeof (quota_event));
       offset += sizeof (quota_event);
 
+      limit = clib_host_to_net_u32 (limit);
       clib_memcpy_fast (b0->data + offset, &limit, sizeof (limit));
       offset += sizeof (limit);
 
@@ -1026,7 +1020,7 @@ nat_ipfix_logging_max_bib (u32 thread_index, u32 limit, int do_flush)
       template_id = clib_atomic_fetch_or (
         &silm->max_bibs_template_id,
         0);
-      nat_ipfix_send (thread_index, frm, f, b0, template_id);
+      nat_ipfix_send (frm, f, b0, template_id);
       sitd->max_bibs_frame = 0;
       sitd->max_bibs_buffer = 0;
       offset = 0;
@@ -1068,7 +1062,6 @@ nat_ipfix_logging_nat64_bibe (u32 thread_index, u8 nat_event,
        }
 
       b0 = sitd->nat64_bib_buffer = vlib_get_buffer (vm, bi0);
-      VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
       offset = 0;
     }
   else
@@ -1128,7 +1121,7 @@ nat_ipfix_logging_nat64_bibe (u32 thread_index, u8 nat_event,
       template_id = clib_atomic_fetch_or (
         &silm->nat64_bib_template_id,
         0);
-      nat_ipfix_send (thread_index, frm, f, b0, template_id);
+      nat_ipfix_send (frm, f, b0, template_id);
       sitd->nat64_bib_frame = 0;
       sitd->nat64_bib_buffer = 0;
       offset = 0;
@@ -1172,7 +1165,6 @@ nat_ipfix_logging_nat64_ses (u32 thread_index, u8 nat_event,
        }
 
       b0 = sitd->nat64_ses_buffer = vlib_get_buffer (vm, bi0);
-      VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
       offset = 0;
     }
   else
@@ -1244,7 +1236,7 @@ nat_ipfix_logging_nat64_ses (u32 thread_index, u8 nat_event,
       template_id = clib_atomic_fetch_or (
         &silm->nat64_ses_template_id,
         0);
-      nat_ipfix_send (thread_index, frm, f, b0, template_id);
+      nat_ipfix_send (frm, f, b0, template_id);
       sitd->nat64_ses_frame = 0;
       sitd->nat64_ses_buffer = 0;
       offset = 0;
@@ -1288,12 +1280,12 @@ nat_ipfix_flush_from_main (void)
 
   if (PREDICT_FALSE (!silm->worker_vms))
     {
-      for (i = 1; i < vec_len (vlib_mains); i++)
-        {
-          worker_vm = vlib_mains[i];
-          if (worker_vm)
-            vec_add1 (silm->worker_vms, worker_vm);
-        }
+      for (i = 1; i < vlib_get_n_threads (); i++)
+       {
+         worker_vm = vlib_get_main_by_index (i);
+         if (worker_vm)
+           vec_add1 (silm->worker_vms, worker_vm);
+       }
     }
 
   /* Trigger flush for each worker thread */
@@ -1311,54 +1303,34 @@ nat_ipfix_flush_from_main (void)
 
 /**
  * @brief Generate NAT44 session create event
- *
- * @param thread_index thread index
- * @param src_ip       source IPv4 address
- * @param nat_src_ip   transaltes source IPv4 address
- * @param nat_proto   NAT transport protocol
- * @param src_port     source port
- * @param nat_src_port translated source port
- * @param vrf_id       VRF ID
  */
 void
-nat_ipfix_logging_nat44_ses_create (u32 thread_index,
-                                     u32 src_ip,
-                                    u32 nat_src_ip,
-                                    nat_protocol_t nat_proto,
-                                    u16 src_port,
-                                    u16 nat_src_port, u32 fib_index)
+nat_ipfix_logging_nat44_ses_create (u32 thread_index, u32 src_ip,
+                                   u32 nat_src_ip, ip_protocol_t proto,
+                                   u16 src_port, u16 nat_src_port,
+                                   u32 fib_index)
 {
   skip_if_disabled ();
 
   nat_ipfix_logging_nat44_ses (thread_index, NAT44_SESSION_CREATE, src_ip,
-                                nat_src_ip, nat_proto, src_port, nat_src_port,
-                               fib_index, 0);
+                              nat_src_ip, proto, src_port, nat_src_port,
+                              fib_index, 0);
 }
 
 /**
  * @brief Generate NAT44 session delete event
- *
- * @param thread_index thread index
- * @param src_ip       source IPv4 address
- * @param nat_src_ip   transaltes source IPv4 address
- * @param nat_proto   NAT transport protocol
- * @param src_port     source port
- * @param nat_src_port translated source port
- * @param vrf_id       VRF ID
  */
 void
-nat_ipfix_logging_nat44_ses_delete (u32 thread_index,
-                                     u32 src_ip,
-                                    u32 nat_src_ip,
-                                    nat_protocol_t nat_proto,
-                                    u16 src_port,
-                                    u16 nat_src_port, u32 fib_index)
+nat_ipfix_logging_nat44_ses_delete (u32 thread_index, u32 src_ip,
+                                   u32 nat_src_ip, ip_protocol_t proto,
+                                   u16 src_port, u16 nat_src_port,
+                                   u32 fib_index)
 {
   skip_if_disabled ();
 
   nat_ipfix_logging_nat44_ses (thread_index, NAT44_SESSION_DELETE, src_ip,
-                                nat_src_ip, nat_proto, src_port, nat_src_port,
-                               fib_index, 0);
+                              nat_src_ip, proto, src_port, nat_src_port,
+                              fib_index, 0);
 }
 
 /**