nat: use table ID for nat44 ipfix session events 87/29787/2
authorMatthew Smith <mgsmith@netgate.com>
Wed, 4 Nov 2020 23:07:44 +0000 (17:07 -0600)
committerOle Tr�an <otroan@employees.org>
Thu, 12 Nov 2020 15:16:46 +0000 (15:16 +0000)
Type: fix

IPfix messages about NAT44 session create/delete were being populated
with the FIB table index instead of the table ID. The table ID is the
correct identifier to report externally (NAT64 IPfix messages for BIB
and session create/delete use table ID, as does NAT syslogging). Convert
the table index to an ID before adding it to the IPfix NAT44 session
create/delete message data.

Change-Id: I0166384752b17ff3a8c55aa19fa2af7a8140791e
Signed-off-by: Matthew Smith <mgsmith@netgate.com>
src/plugins/nat/lib/ipfix_logging.c
src/plugins/nat/lib/ipfix_logging.h

index 60b3c1f..6a94469 100644 (file)
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 
+#include <vnet/fib/fib_table.h>
 #include <vnet/ipfix-export/flow_report.h>
 #include <vnet/ip/ip4.h>
 #include <vnet/udp/udp_local.h>
@@ -577,7 +578,7 @@ 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 vrf_id,
+                              u16 src_port, u16 nat_src_port, u32 fib_index,
                               int do_flush)
 {
   nat_ipfix_logging_main_t *silm = &nat_ipfix_logging_main;
@@ -591,6 +592,7 @@ nat_ipfix_logging_nat44_ses (u32 thread_index, u8 nat_event, u32 src_ip,
   u64 now;
   u8 proto;
   u16 template_id;
+  u32 vrf_id;
 
   proto = nat_proto_to_ip_proto (nat_proto);
 
@@ -658,6 +660,7 @@ nat_ipfix_logging_nat44_ses (u32 thread_index, u8 nat_event, u32 src_ip,
       clib_memcpy_fast (b0->data + offset, &nat_src_port, sizeof (nat_src_port));
       offset += sizeof (nat_src_port);
 
+      vrf_id = fib_table_get_table_id (fib_index, FIB_PROTOCOL_IP4);
       vrf_id = clib_host_to_net_u32 (vrf_id);
       clib_memcpy_fast (b0->data + offset, &vrf_id, sizeof (vrf_id));
       offset += sizeof (vrf_id);
@@ -1316,13 +1319,13 @@ nat_ipfix_logging_nat44_ses_create (u32 thread_index,
                                     u32 nat_src_ip,
                                     nat_protocol_t nat_proto,
                                     u16 src_port,
-                                    u16 nat_src_port, u32 vrf_id)
+                                    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,
-                               vrf_id, 0);
+                               fib_index, 0);
 }
 
 /**
@@ -1342,13 +1345,13 @@ nat_ipfix_logging_nat44_ses_delete (u32 thread_index,
                                     u32 nat_src_ip,
                                     nat_protocol_t nat_proto,
                                     u16 src_port,
-                                    u16 nat_src_port, u32 vrf_id)
+                                    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,
-                               vrf_id, 0);
+                               fib_index, 0);
 }
 
 /**
index b37c856..53aa86b 100644 (file)
@@ -118,12 +118,12 @@ 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 vrf_id);
+                                          u32 fib_index);
 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 vrf_id);
+                                          u32 fib_index);
 void nat_ipfix_logging_addresses_exhausted(u32 thread_index, u32 pool_id);
 void nat_ipfix_logging_max_entries_per_user(u32 thread_index,
                                              u32 limit, u32 src_ip);