2 * nat_ipfix_logging.c - NAT Events IPFIX logging
4 * Copyright (c) 2016 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vnet/ipfix-export/flow_report.h>
19 #include <vlibmemory/api.h>
20 #include <nat/nat_inlines.h>
21 #include <nat/nat_ipfix_logging.h>
23 snat_ipfix_logging_main_t snat_ipfix_logging_main;
25 #define NAT44_SESSION_CREATE_LEN 26
26 #define NAT_ADDRESSES_EXHAUTED_LEN 13
27 #define MAX_ENTRIES_PER_USER_LEN 21
28 #define MAX_SESSIONS_LEN 17
29 #define MAX_BIBS_LEN 17
30 #define MAX_FRAGMENTS_IP4_LEN 21
31 #define MAX_FRAGMENTS_IP6_LEN 33
32 #define NAT64_BIB_LEN 38
33 #define NAT64_SES_LEN 62
35 #define NAT44_SESSION_CREATE_FIELD_COUNT 8
36 #define NAT_ADDRESSES_EXHAUTED_FIELD_COUNT 3
37 #define MAX_ENTRIES_PER_USER_FIELD_COUNT 5
38 #define MAX_SESSIONS_FIELD_COUNT 4
39 #define MAX_BIBS_FIELD_COUNT 4
40 #define MAX_FRAGMENTS_FIELD_COUNT 5
41 #define NAT64_BIB_FIELD_COUNT 8
42 #define NAT64_SES_FIELD_COUNT 12
49 snat_protocol_t snat_proto;
53 } snat_ipfix_logging_nat44_ses_args_t;
58 } snat_ipfix_logging_addr_exhausted_args_t;
64 } snat_ipfix_logging_max_entries_per_user_args_t;
69 } nat_ipfix_logging_max_sessions_args_t;
74 } nat_ipfix_logging_max_bibs_args_t;
80 } nat_ipfix_logging_max_frags_ip4_args_t;
86 } nat_ipfix_logging_max_frags_ip6_args_t;
101 } nat_ipfix_logging_nat64_ses_args_t;
112 } nat_ipfix_logging_nat64_bib_args_t;
114 #define skip_if_disabled() \
116 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main; \
117 if (PREDICT_TRUE (!silm->enabled)) \
122 * @brief Create an IPFIX template packet rewrite string
124 * @param frm flow report main
125 * @param fr flow report
126 * @param collector_address collector address
127 * @param src_address source address
128 * @param collector_port collector
129 * @param event NAT event ID
130 * @param quota_event NAT quota exceeded event ID
132 * @returns template packet
135 snat_template_rewrite (flow_report_main_t * frm,
137 ip4_address_t * collector_address,
138 ip4_address_t * src_address,
140 nat_event_t event, quota_exceed_event_t quota_event)
142 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
145 ipfix_message_header_t *h;
146 ipfix_set_header_t *s;
147 ipfix_template_header_t *t;
148 ipfix_field_specifier_t *f;
149 ipfix_field_specifier_t *first_field;
151 ip4_ipfix_template_packet_t *tp;
153 flow_report_stream_t *stream;
155 stream = &frm->streams[fr->stream_index];
156 silm->stream_index = fr->stream_index;
158 if (event == NAT_ADDRESSES_EXHAUTED)
160 field_count = NAT_ADDRESSES_EXHAUTED_FIELD_COUNT;
161 silm->addr_exhausted_template_id = fr->template_id;
163 else if (event == NAT44_SESSION_CREATE)
165 field_count = NAT44_SESSION_CREATE_FIELD_COUNT;
166 silm->nat44_session_template_id = fr->template_id;
168 else if (event == NAT64_BIB_CREATE)
170 field_count = NAT64_BIB_FIELD_COUNT;
171 silm->nat64_bib_template_id = fr->template_id;
173 else if (event == NAT64_SESSION_CREATE)
175 field_count = NAT64_SES_FIELD_COUNT;
176 silm->nat64_ses_template_id = fr->template_id;
178 else if (event == QUOTA_EXCEEDED)
180 if (quota_event == MAX_ENTRIES_PER_USER)
182 field_count = MAX_ENTRIES_PER_USER_FIELD_COUNT;
183 silm->max_entries_per_user_template_id = fr->template_id;
185 else if (quota_event == MAX_SESSION_ENTRIES)
187 field_count = MAX_SESSIONS_FIELD_COUNT;
188 silm->max_sessions_template_id = fr->template_id;
190 else if (quota_event == MAX_BIB_ENTRIES)
192 field_count = MAX_BIBS_FIELD_COUNT;
193 silm->max_bibs_template_id = fr->template_id;
195 else if (quota_event == MAX_FRAGMENTS_PENDING_REASSEMBLY)
197 field_count = MAX_FRAGMENTS_FIELD_COUNT;
198 silm->max_frags_ip4_template_id = fr->template_id;
200 else if (quota_event == MAX_FRAGMENTS_PENDING_REASSEMBLY_IP6)
202 field_count = MAX_FRAGMENTS_FIELD_COUNT;
203 silm->max_frags_ip6_template_id = fr->template_id;
207 /* allocate rewrite space */
208 vec_validate_aligned (rewrite,
209 sizeof (ip4_ipfix_template_packet_t)
210 + field_count * sizeof (ipfix_field_specifier_t) - 1,
211 CLIB_CACHE_LINE_BYTES);
213 tp = (ip4_ipfix_template_packet_t *) rewrite;
214 ip = (ip4_header_t *) & tp->ip4;
215 udp = (udp_header_t *) (ip + 1);
216 h = (ipfix_message_header_t *) (udp + 1);
217 s = (ipfix_set_header_t *) (h + 1);
218 t = (ipfix_template_header_t *) (s + 1);
219 first_field = f = (ipfix_field_specifier_t *) (t + 1);
221 ip->ip_version_and_header_length = 0x45;
223 ip->protocol = IP_PROTOCOL_UDP;
224 ip->src_address.as_u32 = src_address->as_u32;
225 ip->dst_address.as_u32 = collector_address->as_u32;
226 udp->src_port = clib_host_to_net_u16 (stream->src_port);
227 udp->dst_port = clib_host_to_net_u16 (collector_port);
228 udp->length = clib_host_to_net_u16 (vec_len (rewrite) - sizeof (*ip));
230 /* FIXUP: message header export_time */
231 h->domain_id = clib_host_to_net_u32 (stream->domain_id);
233 /* Add TLVs to the template */
234 if (event == NAT_ADDRESSES_EXHAUTED)
236 f->e_id_length = ipfix_e_id_length (0, observationTimeMilliseconds, 8);
238 f->e_id_length = ipfix_e_id_length (0, natEvent, 1);
240 f->e_id_length = ipfix_e_id_length (0, natPoolId, 4);
243 else if (event == NAT44_SESSION_CREATE)
245 f->e_id_length = ipfix_e_id_length (0, observationTimeMilliseconds, 8);
247 f->e_id_length = ipfix_e_id_length (0, natEvent, 1);
249 f->e_id_length = ipfix_e_id_length (0, sourceIPv4Address, 4);
251 f->e_id_length = ipfix_e_id_length (0, postNATSourceIPv4Address, 4);
253 f->e_id_length = ipfix_e_id_length (0, protocolIdentifier, 1);
255 f->e_id_length = ipfix_e_id_length (0, sourceTransportPort, 2);
257 f->e_id_length = ipfix_e_id_length (0, postNAPTSourceTransportPort, 2);
259 f->e_id_length = ipfix_e_id_length (0, ingressVRFID, 4);
262 else if (event == NAT64_BIB_CREATE)
264 f->e_id_length = ipfix_e_id_length (0, observationTimeMilliseconds, 8);
266 f->e_id_length = ipfix_e_id_length (0, natEvent, 1);
268 f->e_id_length = ipfix_e_id_length (0, sourceIPv6Address, 16);
270 f->e_id_length = ipfix_e_id_length (0, postNATSourceIPv4Address, 4);
272 f->e_id_length = ipfix_e_id_length (0, protocolIdentifier, 1);
274 f->e_id_length = ipfix_e_id_length (0, sourceTransportPort, 2);
276 f->e_id_length = ipfix_e_id_length (0, postNAPTSourceTransportPort, 2);
278 f->e_id_length = ipfix_e_id_length (0, ingressVRFID, 4);
281 else if (event == NAT64_SESSION_CREATE)
283 f->e_id_length = ipfix_e_id_length (0, observationTimeMilliseconds, 8);
285 f->e_id_length = ipfix_e_id_length (0, natEvent, 1);
287 f->e_id_length = ipfix_e_id_length (0, sourceIPv6Address, 16);
289 f->e_id_length = ipfix_e_id_length (0, postNATSourceIPv4Address, 4);
291 f->e_id_length = ipfix_e_id_length (0, protocolIdentifier, 1);
293 f->e_id_length = ipfix_e_id_length (0, sourceTransportPort, 2);
295 f->e_id_length = ipfix_e_id_length (0, postNAPTSourceTransportPort, 2);
297 f->e_id_length = ipfix_e_id_length (0, destinationIPv6Address, 16);
299 f->e_id_length = ipfix_e_id_length (0, postNATDestinationIPv4Address, 4);
301 f->e_id_length = ipfix_e_id_length (0, destinationTransportPort, 2);
303 f->e_id_length = ipfix_e_id_length (0, postNAPTDestinationTransportPort,
306 f->e_id_length = ipfix_e_id_length (0, ingressVRFID, 4);
309 else if (event == QUOTA_EXCEEDED)
311 if (quota_event == MAX_ENTRIES_PER_USER)
313 f->e_id_length = ipfix_e_id_length (0, observationTimeMilliseconds,
316 f->e_id_length = ipfix_e_id_length (0, natEvent, 1);
318 f->e_id_length = ipfix_e_id_length (0, natQuotaExceededEvent, 4);
320 f->e_id_length = ipfix_e_id_length (0, maxEntriesPerUser, 4);
322 f->e_id_length = ipfix_e_id_length (0, sourceIPv4Address, 4);
325 else if (quota_event == MAX_SESSION_ENTRIES)
327 f->e_id_length = ipfix_e_id_length (0, observationTimeMilliseconds,
330 f->e_id_length = ipfix_e_id_length (0, natEvent, 1);
332 f->e_id_length = ipfix_e_id_length (0, natQuotaExceededEvent, 4);
334 f->e_id_length = ipfix_e_id_length (0, maxSessionEntries, 4);
337 else if (quota_event == MAX_BIB_ENTRIES)
339 f->e_id_length = ipfix_e_id_length (0, observationTimeMilliseconds,
342 f->e_id_length = ipfix_e_id_length (0, natEvent, 1);
344 f->e_id_length = ipfix_e_id_length (0, natQuotaExceededEvent, 4);
346 f->e_id_length = ipfix_e_id_length (0, maxBIBEntries, 4);
349 else if (quota_event == MAX_FRAGMENTS_PENDING_REASSEMBLY)
351 f->e_id_length = ipfix_e_id_length (0, observationTimeMilliseconds,
354 f->e_id_length = ipfix_e_id_length (0, natEvent, 1);
356 f->e_id_length = ipfix_e_id_length (0, natQuotaExceededEvent, 4);
358 f->e_id_length = ipfix_e_id_length (0, maxFragmentsPendingReassembly,
361 f->e_id_length = ipfix_e_id_length (0, sourceIPv4Address, 4);
364 else if (quota_event == MAX_FRAGMENTS_PENDING_REASSEMBLY_IP6)
366 f->e_id_length = ipfix_e_id_length (0, observationTimeMilliseconds,
369 f->e_id_length = ipfix_e_id_length (0, natEvent, 1);
371 f->e_id_length = ipfix_e_id_length (0, natQuotaExceededEvent, 4);
373 f->e_id_length = ipfix_e_id_length (0, maxFragmentsPendingReassembly,
376 f->e_id_length = ipfix_e_id_length (0, sourceIPv6Address, 16);
381 /* Back to the template packet... */
382 ip = (ip4_header_t *) & tp->ip4;
383 udp = (udp_header_t *) (ip + 1);
385 ASSERT (f - first_field);
386 /* Field count in this template */
387 t->id_count = ipfix_id_count (fr->template_id, f - first_field);
389 /* set length in octets */
391 ipfix_set_id_length (2 /* set_id */ , (u8 *) f - (u8 *) s);
393 /* message length in octets */
394 h->version_length = version_length ((u8 *) f - (u8 *) h);
396 ip->length = clib_host_to_net_u16 ((u8 *) f - (u8 *) ip);
397 ip->checksum = ip4_header_checksum (ip);
403 snat_template_rewrite_addr_exhausted (flow_report_main_t * frm,
405 ip4_address_t * collector_address,
406 ip4_address_t * src_address,
408 ipfix_report_element_t *elts,
409 u32 n_elts, u32 *stream_index)
411 return snat_template_rewrite (frm, fr, collector_address, src_address,
412 collector_port, NAT_ADDRESSES_EXHAUTED, 0);
416 snat_template_rewrite_nat44_session (flow_report_main_t * frm,
418 ip4_address_t * collector_address,
419 ip4_address_t * src_address,
421 ipfix_report_element_t *elts,
422 u32 n_elts, u32 *stream_index)
424 return snat_template_rewrite (frm, fr, collector_address, src_address,
425 collector_port, NAT44_SESSION_CREATE, 0);
429 snat_template_rewrite_max_entries_per_usr (flow_report_main_t * frm,
431 ip4_address_t * collector_address,
432 ip4_address_t * src_address,
434 ipfix_report_element_t *elts,
435 u32 n_elts, u32 *stream_index)
437 return snat_template_rewrite (frm, fr, collector_address, src_address,
438 collector_port, QUOTA_EXCEEDED,
439 MAX_ENTRIES_PER_USER);
443 nat_template_rewrite_max_sessions (flow_report_main_t * frm,
445 ip4_address_t * collector_address,
446 ip4_address_t * src_address,
448 ipfix_report_element_t *elts,
449 u32 n_elts, u32 *stream_index)
451 return snat_template_rewrite (frm, fr, collector_address, src_address,
452 collector_port, QUOTA_EXCEEDED,
453 MAX_SESSION_ENTRIES);
457 nat_template_rewrite_max_bibs (flow_report_main_t * frm,
459 ip4_address_t * collector_address,
460 ip4_address_t * src_address,
462 ipfix_report_element_t *elts,
463 u32 n_elts, u32 *stream_index)
465 return snat_template_rewrite (frm, fr, collector_address, src_address,
466 collector_port, QUOTA_EXCEEDED,
471 nat_template_rewrite_max_frags_ip4 (flow_report_main_t * frm,
473 ip4_address_t * collector_address,
474 ip4_address_t * src_address,
476 ipfix_report_element_t *elts,
477 u32 n_elts, u32 *stream_index)
479 return snat_template_rewrite (frm, fr, collector_address, src_address,
480 collector_port, QUOTA_EXCEEDED,
481 MAX_FRAGMENTS_PENDING_REASSEMBLY);
485 nat_template_rewrite_max_frags_ip6 (flow_report_main_t * frm,
487 ip4_address_t * collector_address,
488 ip4_address_t * src_address,
490 ipfix_report_element_t *elts,
491 u32 n_elts, u32 *stream_index)
493 return snat_template_rewrite (frm, fr, collector_address, src_address,
494 collector_port, QUOTA_EXCEEDED,
495 MAX_FRAGMENTS_PENDING_REASSEMBLY_IP6);
499 nat_template_rewrite_nat64_bib (flow_report_main_t * frm,
501 ip4_address_t * collector_address,
502 ip4_address_t * src_address,
504 ipfix_report_element_t *elts,
505 u32 n_elts, u32 *stream_index)
507 return snat_template_rewrite (frm, fr, collector_address, src_address,
508 collector_port, NAT64_BIB_CREATE, 0);
512 nat_template_rewrite_nat64_session (flow_report_main_t * frm,
514 ip4_address_t * collector_address,
515 ip4_address_t * src_address,
517 ipfix_report_element_t *elts,
518 u32 n_elts, u32 *stream_index)
520 return snat_template_rewrite (frm, fr, collector_address, src_address,
521 collector_port, NAT64_SESSION_CREATE, 0);
525 snat_ipfix_header_create (flow_report_main_t * frm,
526 vlib_buffer_t * b0, u32 * offset)
528 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
529 flow_report_stream_t *stream;
530 ip4_ipfix_template_packet_t *tp;
531 ipfix_message_header_t *h = 0;
532 ipfix_set_header_t *s = 0;
536 stream = &frm->streams[silm->stream_index];
538 b0->current_data = 0;
539 b0->current_length = sizeof (*ip) + sizeof (*udp) + sizeof (*h) +
541 b0->flags |= (VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_FLOW_REPORT);
542 vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
543 vnet_buffer (b0)->sw_if_index[VLIB_TX] = frm->fib_index;
544 tp = vlib_buffer_get_current (b0);
545 ip = (ip4_header_t *) & tp->ip4;
546 udp = (udp_header_t *) (ip + 1);
547 h = (ipfix_message_header_t *) (udp + 1);
548 s = (ipfix_set_header_t *) (h + 1);
550 ip->ip_version_and_header_length = 0x45;
552 ip->protocol = IP_PROTOCOL_UDP;
553 ip->flags_and_fragment_offset = 0;
554 ip->src_address.as_u32 = frm->src_address.as_u32;
555 ip->dst_address.as_u32 = frm->ipfix_collector.as_u32;
556 udp->src_port = clib_host_to_net_u16 (stream->src_port);
557 udp->dst_port = clib_host_to_net_u16 (frm->collector_port);
560 h->export_time = clib_host_to_net_u32 ((u32)
561 (((f64) frm->unix_time_0) +
562 (vlib_time_now (frm->vlib_main) -
564 h->sequence_number = clib_host_to_net_u32 (stream->sequence_number++);
565 h->domain_id = clib_host_to_net_u32 (stream->domain_id);
567 *offset = (u32) (((u8 *) (s + 1)) - (u8 *) tp);
571 snat_ipfix_send (flow_report_main_t * frm,
572 vlib_frame_t * f, vlib_buffer_t * b0, u16 template_id)
574 ip4_ipfix_template_packet_t *tp;
575 ipfix_message_header_t *h = 0;
576 ipfix_set_header_t *s = 0;
579 vlib_main_t *vm = frm->vlib_main;
581 tp = vlib_buffer_get_current (b0);
582 ip = (ip4_header_t *) & tp->ip4;
583 udp = (udp_header_t *) (ip + 1);
584 h = (ipfix_message_header_t *) (udp + 1);
585 s = (ipfix_set_header_t *) (h + 1);
587 s->set_id_length = ipfix_set_id_length (template_id,
589 (sizeof (*ip) + sizeof (*udp) +
591 h->version_length = version_length (b0->current_length -
592 (sizeof (*ip) + sizeof (*udp)));
594 ip->length = clib_host_to_net_u16 (b0->current_length);
595 ip->checksum = ip4_header_checksum (ip);
596 udp->length = clib_host_to_net_u16 (b0->current_length - sizeof (*ip));
598 if (frm->udp_checksum)
600 udp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip);
601 if (udp->checksum == 0)
602 udp->checksum = 0xffff;
605 ASSERT (ip->checksum == ip4_header_checksum (ip));
607 vlib_put_frame_to_node (vm, ip4_lookup_node.index, f);
611 snat_ipfix_logging_nat44_ses (u8 nat_event, u32 src_ip, u32 nat_src_ip,
612 snat_protocol_t snat_proto, u16 src_port,
613 u16 nat_src_port, u32 vrf_id, int do_flush)
615 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
616 flow_report_main_t *frm = &flow_report_main;
618 vlib_buffer_t *b0 = 0;
621 vlib_main_t *vm = frm->vlib_main;
623 vlib_buffer_free_list_t *fl;
629 proto = snat_proto_to_ip_proto (snat_proto);
631 now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
632 now += silm->milisecond_time_0;
634 b0 = silm->nat44_session_buffer;
636 if (PREDICT_FALSE (b0 == 0))
641 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
643 clib_warning ("can't allocate buffer for NAT IPFIX event");
647 b0 = silm->nat44_session_buffer = vlib_get_buffer (vm, bi0);
649 vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
650 vlib_buffer_init_for_free_list (b0, fl);
651 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
656 bi0 = vlib_get_buffer_index (vm, b0);
657 offset = silm->nat44_session_next_record_offset;
660 f = silm->nat44_session_frame;
661 if (PREDICT_FALSE (f == 0))
664 f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
665 silm->nat44_session_frame = f;
666 to_next = vlib_frame_vector_args (f);
671 if (PREDICT_FALSE (offset == 0))
672 snat_ipfix_header_create (frm, b0, &offset);
674 if (PREDICT_TRUE (do_flush == 0))
676 u64 time_stamp = clib_host_to_net_u64 (now);
677 clib_memcpy (b0->data + offset, &time_stamp, sizeof (time_stamp));
678 offset += sizeof (time_stamp);
680 clib_memcpy (b0->data + offset, &nat_event, sizeof (nat_event));
681 offset += sizeof (nat_event);
683 clib_memcpy (b0->data + offset, &src_ip, sizeof (src_ip));
684 offset += sizeof (src_ip);
686 clib_memcpy (b0->data + offset, &nat_src_ip, sizeof (nat_src_ip));
687 offset += sizeof (nat_src_ip);
689 clib_memcpy (b0->data + offset, &proto, sizeof (proto));
690 offset += sizeof (proto);
692 clib_memcpy (b0->data + offset, &src_port, sizeof (src_port));
693 offset += sizeof (src_port);
695 clib_memcpy (b0->data + offset, &nat_src_port, sizeof (nat_src_port));
696 offset += sizeof (nat_src_port);
698 clib_memcpy (b0->data + offset, &vrf_id, sizeof (vrf_id));
699 offset += sizeof (vrf_id);
701 b0->current_length += NAT44_SESSION_CREATE_LEN;
705 (do_flush || (offset + NAT44_SESSION_CREATE_LEN) > frm->path_mtu))
707 snat_ipfix_send (frm, f, b0, silm->nat44_session_template_id);
708 silm->nat44_session_frame = 0;
709 silm->nat44_session_buffer = 0;
712 silm->nat44_session_next_record_offset = offset;
716 snat_ipfix_logging_addr_exhausted (u32 pool_id, int do_flush)
718 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
719 flow_report_main_t *frm = &flow_report_main;
721 vlib_buffer_t *b0 = 0;
724 vlib_main_t *vm = frm->vlib_main;
726 vlib_buffer_free_list_t *fl;
727 u8 nat_event = NAT_ADDRESSES_EXHAUTED;
732 now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
733 now += silm->milisecond_time_0;
735 b0 = silm->addr_exhausted_buffer;
737 if (PREDICT_FALSE (b0 == 0))
742 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
744 clib_warning ("can't allocate buffer for NAT IPFIX event");
748 b0 = silm->addr_exhausted_buffer = vlib_get_buffer (vm, bi0);
750 vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
751 vlib_buffer_init_for_free_list (b0, fl);
752 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
757 bi0 = vlib_get_buffer_index (vm, b0);
758 offset = silm->addr_exhausted_next_record_offset;
761 f = silm->addr_exhausted_frame;
762 if (PREDICT_FALSE (f == 0))
765 f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
766 silm->addr_exhausted_frame = f;
767 to_next = vlib_frame_vector_args (f);
772 if (PREDICT_FALSE (offset == 0))
773 snat_ipfix_header_create (frm, b0, &offset);
775 if (PREDICT_TRUE (do_flush == 0))
777 u64 time_stamp = clib_host_to_net_u64 (now);
778 clib_memcpy (b0->data + offset, &time_stamp, sizeof (time_stamp));
779 offset += sizeof (time_stamp);
781 clib_memcpy (b0->data + offset, &nat_event, sizeof (nat_event));
782 offset += sizeof (nat_event);
784 clib_memcpy (b0->data + offset, &pool_id, sizeof (pool_id));
785 offset += sizeof (pool_id);
787 b0->current_length += NAT_ADDRESSES_EXHAUTED_LEN;
791 (do_flush || (offset + NAT_ADDRESSES_EXHAUTED_LEN) > frm->path_mtu))
793 snat_ipfix_send (frm, f, b0, silm->addr_exhausted_template_id);
794 silm->addr_exhausted_frame = 0;
795 silm->addr_exhausted_buffer = 0;
798 silm->addr_exhausted_next_record_offset = offset;
802 snat_ipfix_logging_max_entries_per_usr (u32 limit, u32 src_ip, int do_flush)
804 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
805 flow_report_main_t *frm = &flow_report_main;
807 vlib_buffer_t *b0 = 0;
810 vlib_main_t *vm = frm->vlib_main;
812 vlib_buffer_free_list_t *fl;
813 u8 nat_event = QUOTA_EXCEEDED;
814 u32 quota_event = MAX_ENTRIES_PER_USER;
819 now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
820 now += silm->milisecond_time_0;
822 b0 = silm->max_entries_per_user_buffer;
824 if (PREDICT_FALSE (b0 == 0))
829 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
831 clib_warning ("can't allocate buffer for NAT IPFIX event");
835 b0 = silm->max_entries_per_user_buffer = vlib_get_buffer (vm, bi0);
837 vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
838 vlib_buffer_init_for_free_list (b0, fl);
839 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
844 bi0 = vlib_get_buffer_index (vm, b0);
845 offset = silm->max_entries_per_user_next_record_offset;
848 f = silm->max_entries_per_user_frame;
849 if (PREDICT_FALSE (f == 0))
852 f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
853 silm->max_entries_per_user_frame = f;
854 to_next = vlib_frame_vector_args (f);
859 if (PREDICT_FALSE (offset == 0))
860 snat_ipfix_header_create (frm, b0, &offset);
862 if (PREDICT_TRUE (do_flush == 0))
864 u64 time_stamp = clib_host_to_net_u64 (now);
865 clib_memcpy (b0->data + offset, &time_stamp, sizeof (time_stamp));
866 offset += sizeof (time_stamp);
868 clib_memcpy (b0->data + offset, &nat_event, sizeof (nat_event));
869 offset += sizeof (nat_event);
871 clib_memcpy (b0->data + offset, "a_event, sizeof (quota_event));
872 offset += sizeof (quota_event);
874 clib_memcpy (b0->data + offset, &limit, sizeof (limit));
875 offset += sizeof (limit);
877 clib_memcpy (b0->data + offset, &src_ip, sizeof (src_ip));
878 offset += sizeof (src_ip);
880 b0->current_length += MAX_ENTRIES_PER_USER_LEN;
884 (do_flush || (offset + MAX_ENTRIES_PER_USER_LEN) > frm->path_mtu))
886 snat_ipfix_send (frm, f, b0, silm->max_entries_per_user_template_id);
887 silm->max_entries_per_user_frame = 0;
888 silm->max_entries_per_user_buffer = 0;
891 silm->max_entries_per_user_next_record_offset = offset;
895 nat_ipfix_logging_max_ses (u32 limit, int do_flush)
897 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
898 flow_report_main_t *frm = &flow_report_main;
900 vlib_buffer_t *b0 = 0;
903 vlib_main_t *vm = frm->vlib_main;
905 vlib_buffer_free_list_t *fl;
906 u8 nat_event = QUOTA_EXCEEDED;
907 u32 quota_event = MAX_SESSION_ENTRIES;
912 now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
913 now += silm->milisecond_time_0;
915 b0 = silm->max_sessions_buffer;
917 if (PREDICT_FALSE (b0 == 0))
922 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
924 clib_warning ("can't allocate buffer for NAT IPFIX event");
928 b0 = silm->max_sessions_buffer = vlib_get_buffer (vm, bi0);
930 vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
931 vlib_buffer_init_for_free_list (b0, fl);
932 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
937 bi0 = vlib_get_buffer_index (vm, b0);
938 offset = silm->max_sessions_next_record_offset;
941 f = silm->max_sessions_frame;
942 if (PREDICT_FALSE (f == 0))
945 f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
946 silm->max_sessions_frame = f;
947 to_next = vlib_frame_vector_args (f);
952 if (PREDICT_FALSE (offset == 0))
953 snat_ipfix_header_create (frm, b0, &offset);
955 if (PREDICT_TRUE (do_flush == 0))
957 u64 time_stamp = clib_host_to_net_u64 (now);
958 clib_memcpy (b0->data + offset, &time_stamp, sizeof (time_stamp));
959 offset += sizeof (time_stamp);
961 clib_memcpy (b0->data + offset, &nat_event, sizeof (nat_event));
962 offset += sizeof (nat_event);
964 clib_memcpy (b0->data + offset, "a_event, sizeof (quota_event));
965 offset += sizeof (quota_event);
967 clib_memcpy (b0->data + offset, &limit, sizeof (limit));
968 offset += sizeof (limit);
970 b0->current_length += MAX_SESSIONS_LEN;
974 (do_flush || (offset + MAX_SESSIONS_LEN) > frm->path_mtu))
976 snat_ipfix_send (frm, f, b0, silm->max_sessions_template_id);
977 silm->max_sessions_frame = 0;
978 silm->max_sessions_buffer = 0;
981 silm->max_sessions_next_record_offset = offset;
985 nat_ipfix_logging_max_bib (u32 limit, int do_flush)
987 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
988 flow_report_main_t *frm = &flow_report_main;
990 vlib_buffer_t *b0 = 0;
993 vlib_main_t *vm = frm->vlib_main;
995 vlib_buffer_free_list_t *fl;
996 u8 nat_event = QUOTA_EXCEEDED;
997 u32 quota_event = MAX_BIB_ENTRIES;
1002 now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
1003 now += silm->milisecond_time_0;
1005 b0 = silm->max_bibs_buffer;
1007 if (PREDICT_FALSE (b0 == 0))
1012 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
1014 clib_warning ("can't allocate buffer for NAT IPFIX event");
1018 b0 = silm->max_bibs_buffer = vlib_get_buffer (vm, bi0);
1020 vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
1021 vlib_buffer_init_for_free_list (b0, fl);
1022 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
1027 bi0 = vlib_get_buffer_index (vm, b0);
1028 offset = silm->max_bibs_next_record_offset;
1031 f = silm->max_bibs_frame;
1032 if (PREDICT_FALSE (f == 0))
1035 f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
1036 silm->max_bibs_frame = f;
1037 to_next = vlib_frame_vector_args (f);
1042 if (PREDICT_FALSE (offset == 0))
1043 snat_ipfix_header_create (frm, b0, &offset);
1045 if (PREDICT_TRUE (do_flush == 0))
1047 u64 time_stamp = clib_host_to_net_u64 (now);
1048 clib_memcpy (b0->data + offset, &time_stamp, sizeof (time_stamp));
1049 offset += sizeof (time_stamp);
1051 clib_memcpy (b0->data + offset, &nat_event, sizeof (nat_event));
1052 offset += sizeof (nat_event);
1054 clib_memcpy (b0->data + offset, "a_event, sizeof (quota_event));
1055 offset += sizeof (quota_event);
1057 clib_memcpy (b0->data + offset, &limit, sizeof (limit));
1058 offset += sizeof (limit);
1060 b0->current_length += MAX_BIBS_LEN;
1064 (do_flush || (offset + MAX_BIBS_LEN) > frm->path_mtu))
1066 snat_ipfix_send (frm, f, b0, silm->max_bibs_template_id);
1067 silm->max_bibs_frame = 0;
1068 silm->max_bibs_buffer = 0;
1071 silm->max_bibs_next_record_offset = offset;
1075 nat_ipfix_logging_max_frag_ip4 (u32 limit, u32 src, int do_flush)
1077 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
1078 flow_report_main_t *frm = &flow_report_main;
1080 vlib_buffer_t *b0 = 0;
1083 vlib_main_t *vm = frm->vlib_main;
1085 vlib_buffer_free_list_t *fl;
1086 u8 nat_event = QUOTA_EXCEEDED;
1087 u32 quota_event = MAX_FRAGMENTS_PENDING_REASSEMBLY;
1092 now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
1093 now += silm->milisecond_time_0;
1095 b0 = silm->max_frags_ip4_buffer;
1097 if (PREDICT_FALSE (b0 == 0))
1102 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
1104 clib_warning ("can't allocate buffer for NAT IPFIX event");
1108 b0 = silm->max_frags_ip4_buffer = vlib_get_buffer (vm, bi0);
1110 vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
1111 vlib_buffer_init_for_free_list (b0, fl);
1112 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
1117 bi0 = vlib_get_buffer_index (vm, b0);
1118 offset = silm->max_frags_ip4_next_record_offset;
1121 f = silm->max_frags_ip4_frame;
1122 if (PREDICT_FALSE (f == 0))
1125 f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
1126 silm->max_frags_ip4_frame = f;
1127 to_next = vlib_frame_vector_args (f);
1132 if (PREDICT_FALSE (offset == 0))
1133 snat_ipfix_header_create (frm, b0, &offset);
1135 if (PREDICT_TRUE (do_flush == 0))
1137 u64 time_stamp = clib_host_to_net_u64 (now);
1138 clib_memcpy (b0->data + offset, &time_stamp, sizeof (time_stamp));
1139 offset += sizeof (time_stamp);
1141 clib_memcpy (b0->data + offset, &nat_event, sizeof (nat_event));
1142 offset += sizeof (nat_event);
1144 clib_memcpy (b0->data + offset, "a_event, sizeof (quota_event));
1145 offset += sizeof (quota_event);
1147 clib_memcpy (b0->data + offset, &limit, sizeof (limit));
1148 offset += sizeof (limit);
1150 clib_memcpy (b0->data + offset, &src, sizeof (src));
1151 offset += sizeof (src);
1153 b0->current_length += MAX_FRAGMENTS_IP4_LEN;
1157 (do_flush || (offset + MAX_BIBS_LEN) > frm->path_mtu))
1159 snat_ipfix_send (frm, f, b0, silm->max_frags_ip4_template_id);
1160 silm->max_frags_ip4_frame = 0;
1161 silm->max_frags_ip4_buffer = 0;
1164 silm->max_frags_ip4_next_record_offset = offset;
1168 nat_ipfix_logging_max_frag_ip6 (u32 limit, ip6_address_t * src, int do_flush)
1170 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
1171 flow_report_main_t *frm = &flow_report_main;
1173 vlib_buffer_t *b0 = 0;
1176 vlib_main_t *vm = frm->vlib_main;
1178 vlib_buffer_free_list_t *fl;
1179 u8 nat_event = QUOTA_EXCEEDED;
1180 u32 quota_event = MAX_FRAGMENTS_PENDING_REASSEMBLY;
1185 now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
1186 now += silm->milisecond_time_0;
1188 b0 = silm->max_frags_ip6_buffer;
1190 if (PREDICT_FALSE (b0 == 0))
1195 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
1197 clib_warning ("can't allocate buffer for NAT IPFIX event");
1201 b0 = silm->max_frags_ip6_buffer = vlib_get_buffer (vm, bi0);
1203 vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
1204 vlib_buffer_init_for_free_list (b0, fl);
1205 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
1210 bi0 = vlib_get_buffer_index (vm, b0);
1211 offset = silm->max_frags_ip6_next_record_offset;
1214 f = silm->max_frags_ip6_frame;
1215 if (PREDICT_FALSE (f == 0))
1218 f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
1219 silm->max_frags_ip6_frame = f;
1220 to_next = vlib_frame_vector_args (f);
1225 if (PREDICT_FALSE (offset == 0))
1226 snat_ipfix_header_create (frm, b0, &offset);
1228 if (PREDICT_TRUE (do_flush == 0))
1230 u64 time_stamp = clib_host_to_net_u64 (now);
1231 clib_memcpy (b0->data + offset, &time_stamp, sizeof (time_stamp));
1232 offset += sizeof (time_stamp);
1234 clib_memcpy (b0->data + offset, &nat_event, sizeof (nat_event));
1235 offset += sizeof (nat_event);
1237 clib_memcpy (b0->data + offset, "a_event, sizeof (quota_event));
1238 offset += sizeof (quota_event);
1240 clib_memcpy (b0->data + offset, &limit, sizeof (limit));
1241 offset += sizeof (limit);
1243 clib_memcpy (b0->data + offset, src, sizeof (ip6_address_t));
1244 offset += sizeof (ip6_address_t);
1246 b0->current_length += MAX_FRAGMENTS_IP6_LEN;
1250 (do_flush || (offset + MAX_BIBS_LEN) > frm->path_mtu))
1252 snat_ipfix_send (frm, f, b0, silm->max_frags_ip6_template_id);
1253 silm->max_frags_ip6_frame = 0;
1254 silm->max_frags_ip6_buffer = 0;
1257 silm->max_frags_ip6_next_record_offset = offset;
1261 nat_ipfix_logging_nat64_bibe (u8 nat_event, ip6_address_t * src_ip,
1262 u32 nat_src_ip, u8 proto, u16 src_port,
1263 u16 nat_src_port, u32 vrf_id, int do_flush)
1265 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
1266 flow_report_main_t *frm = &flow_report_main;
1268 vlib_buffer_t *b0 = 0;
1271 vlib_main_t *vm = frm->vlib_main;
1273 vlib_buffer_free_list_t *fl;
1278 now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
1279 now += silm->milisecond_time_0;
1281 b0 = silm->nat64_bib_buffer;
1283 if (PREDICT_FALSE (b0 == 0))
1288 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
1290 clib_warning ("can't allocate buffer for NAT IPFIX event");
1294 b0 = silm->nat64_bib_buffer = vlib_get_buffer (vm, bi0);
1296 vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
1297 vlib_buffer_init_for_free_list (b0, fl);
1298 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
1303 bi0 = vlib_get_buffer_index (vm, b0);
1304 offset = silm->nat64_bib_next_record_offset;
1307 f = silm->nat64_bib_frame;
1308 if (PREDICT_FALSE (f == 0))
1311 f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
1312 silm->nat64_bib_frame = f;
1313 to_next = vlib_frame_vector_args (f);
1318 if (PREDICT_FALSE (offset == 0))
1319 snat_ipfix_header_create (frm, b0, &offset);
1321 if (PREDICT_TRUE (do_flush == 0))
1323 u64 time_stamp = clib_host_to_net_u64 (now);
1324 clib_memcpy (b0->data + offset, &time_stamp, sizeof (time_stamp));
1325 offset += sizeof (time_stamp);
1327 clib_memcpy (b0->data + offset, &nat_event, sizeof (nat_event));
1328 offset += sizeof (nat_event);
1330 clib_memcpy (b0->data + offset, src_ip, sizeof (ip6_address_t));
1331 offset += sizeof (ip6_address_t);
1333 clib_memcpy (b0->data + offset, &nat_src_ip, sizeof (nat_src_ip));
1334 offset += sizeof (nat_src_ip);
1336 clib_memcpy (b0->data + offset, &proto, sizeof (proto));
1337 offset += sizeof (proto);
1339 clib_memcpy (b0->data + offset, &src_port, sizeof (src_port));
1340 offset += sizeof (src_port);
1342 clib_memcpy (b0->data + offset, &nat_src_port, sizeof (nat_src_port));
1343 offset += sizeof (nat_src_port);
1345 clib_memcpy (b0->data + offset, &vrf_id, sizeof (vrf_id));
1346 offset += sizeof (vrf_id);
1348 b0->current_length += NAT64_BIB_LEN;
1352 (do_flush || (offset + NAT64_BIB_LEN) > frm->path_mtu))
1354 snat_ipfix_send (frm, f, b0, silm->nat64_bib_template_id);
1355 silm->nat64_bib_frame = 0;
1356 silm->nat64_bib_buffer = 0;
1359 silm->nat64_bib_next_record_offset = offset;
1363 nat_ipfix_logging_nat64_ses (u8 nat_event, ip6_address_t * src_ip,
1364 u32 nat_src_ip, u8 proto, u16 src_port,
1365 u16 nat_src_port, ip6_address_t * dst_ip,
1366 u32 nat_dst_ip, u16 dst_port, u16 nat_dst_port,
1367 u32 vrf_id, int do_flush)
1369 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
1370 flow_report_main_t *frm = &flow_report_main;
1372 vlib_buffer_t *b0 = 0;
1375 vlib_main_t *vm = frm->vlib_main;
1377 vlib_buffer_free_list_t *fl;
1382 now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3);
1383 now += silm->milisecond_time_0;
1385 b0 = silm->nat64_ses_buffer;
1387 if (PREDICT_FALSE (b0 == 0))
1392 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
1394 clib_warning ("can't allocate buffer for NAT IPFIX event");
1398 b0 = silm->nat64_ses_buffer = vlib_get_buffer (vm, bi0);
1400 vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
1401 vlib_buffer_init_for_free_list (b0, fl);
1402 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
1407 bi0 = vlib_get_buffer_index (vm, b0);
1408 offset = silm->nat64_ses_next_record_offset;
1411 f = silm->nat64_ses_frame;
1412 if (PREDICT_FALSE (f == 0))
1415 f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
1416 silm->nat64_ses_frame = f;
1417 to_next = vlib_frame_vector_args (f);
1422 if (PREDICT_FALSE (offset == 0))
1423 snat_ipfix_header_create (frm, b0, &offset);
1425 if (PREDICT_TRUE (do_flush == 0))
1427 u64 time_stamp = clib_host_to_net_u64 (now);
1428 clib_memcpy (b0->data + offset, &time_stamp, sizeof (time_stamp));
1429 offset += sizeof (time_stamp);
1431 clib_memcpy (b0->data + offset, &nat_event, sizeof (nat_event));
1432 offset += sizeof (nat_event);
1434 clib_memcpy (b0->data + offset, src_ip, sizeof (ip6_address_t));
1435 offset += sizeof (ip6_address_t);
1437 clib_memcpy (b0->data + offset, &nat_src_ip, sizeof (nat_src_ip));
1438 offset += sizeof (nat_src_ip);
1440 clib_memcpy (b0->data + offset, &proto, sizeof (proto));
1441 offset += sizeof (proto);
1443 clib_memcpy (b0->data + offset, &src_port, sizeof (src_port));
1444 offset += sizeof (src_port);
1446 clib_memcpy (b0->data + offset, &nat_src_port, sizeof (nat_src_port));
1447 offset += sizeof (nat_src_port);
1449 clib_memcpy (b0->data + offset, dst_ip, sizeof (ip6_address_t));
1450 offset += sizeof (ip6_address_t);
1452 clib_memcpy (b0->data + offset, &nat_dst_ip, sizeof (nat_dst_ip));
1453 offset += sizeof (nat_dst_ip);
1455 clib_memcpy (b0->data + offset, &dst_port, sizeof (dst_port));
1456 offset += sizeof (dst_port);
1458 clib_memcpy (b0->data + offset, &nat_dst_port, sizeof (nat_dst_port));
1459 offset += sizeof (nat_dst_port);
1461 clib_memcpy (b0->data + offset, &vrf_id, sizeof (vrf_id));
1462 offset += sizeof (vrf_id);
1464 b0->current_length += NAT64_SES_LEN;
1468 (do_flush || (offset + NAT64_SES_LEN) > frm->path_mtu))
1470 snat_ipfix_send (frm, f, b0, silm->nat64_ses_template_id);
1471 silm->nat64_ses_frame = 0;
1472 silm->nat64_ses_buffer = 0;
1475 silm->nat64_ses_next_record_offset = offset;
1479 snat_ipfix_logging_nat44_ses_rpc_cb (snat_ipfix_logging_nat44_ses_args_t * a)
1481 snat_ipfix_logging_nat44_ses (a->nat_event, a->src_ip, a->nat_src_ip,
1482 a->snat_proto, a->src_port, a->nat_src_port,
1487 * @brief Generate NAT44 session create event
1489 * @param src_ip source IPv4 address
1490 * @param nat_src_ip transaltes source IPv4 address
1491 * @param snat_proto NAT transport protocol
1492 * @param src_port source port
1493 * @param nat_src_port translated source port
1494 * @param vrf_id VRF ID
1497 snat_ipfix_logging_nat44_ses_create (u32 src_ip,
1499 snat_protocol_t snat_proto,
1501 u16 nat_src_port, u32 vrf_id)
1503 snat_ipfix_logging_nat44_ses_args_t a;
1505 skip_if_disabled ();
1507 a.nat_event = NAT44_SESSION_CREATE;
1509 a.nat_src_ip = nat_src_ip;
1510 a.snat_proto = snat_proto;
1511 a.src_port = src_port;
1512 a.nat_src_port = nat_src_port;
1515 vl_api_rpc_call_main_thread (snat_ipfix_logging_nat44_ses_rpc_cb,
1516 (u8 *) & a, sizeof (a));
1520 * @brief Generate NAT44 session delete event
1522 * @param src_ip source IPv4 address
1523 * @param nat_src_ip transaltes source IPv4 address
1524 * @param snat_proto NAT transport protocol
1525 * @param src_port source port
1526 * @param nat_src_port translated source port
1527 * @param vrf_id VRF ID
1530 snat_ipfix_logging_nat44_ses_delete (u32 src_ip,
1532 snat_protocol_t snat_proto,
1534 u16 nat_src_port, u32 vrf_id)
1536 snat_ipfix_logging_nat44_ses_args_t a;
1538 skip_if_disabled ();
1540 a.nat_event = NAT44_SESSION_DELETE;
1542 a.nat_src_ip = nat_src_ip;
1543 a.snat_proto = snat_proto;
1544 a.src_port = src_port;
1545 a.nat_src_port = nat_src_port;
1548 vl_api_rpc_call_main_thread (snat_ipfix_logging_nat44_ses_rpc_cb,
1549 (u8 *) & a, sizeof (a));
1553 snat_data_callback_nat44_session (flow_report_main_t * frm,
1556 u32 * to_next, u32 node_index)
1558 snat_ipfix_logging_nat44_ses (0, 0, 0, 0, 0, 0, 0, 1);
1563 snat_ipfix_logging_addr_exhausted_rpc_cb
1564 (snat_ipfix_logging_addr_exhausted_args_t * a)
1566 snat_ipfix_logging_addr_exhausted (a->pool_id, 0);
1570 * @brief Generate NAT addresses exhausted event
1572 * @param pool_id NAT pool ID
1575 snat_ipfix_logging_addresses_exhausted (u32 pool_id)
1577 //TODO: This event SHOULD be rate limited
1578 snat_ipfix_logging_addr_exhausted_args_t a;
1580 skip_if_disabled ();
1582 a.pool_id = pool_id;
1584 vl_api_rpc_call_main_thread (snat_ipfix_logging_addr_exhausted_rpc_cb,
1585 (u8 *) & a, sizeof (a));
1589 snat_data_callback_addr_exhausted (flow_report_main_t * frm,
1592 u32 * to_next, u32 node_index)
1594 snat_ipfix_logging_addr_exhausted (0, 1);
1599 snat_ipfix_logging_max_entries_per_usr_rpc_cb
1600 (snat_ipfix_logging_max_entries_per_user_args_t * a)
1602 snat_ipfix_logging_max_entries_per_usr (a->limit, a->src_ip, 0);
1606 * @brief Generate maximum entries per user exceeded event
1608 * @param limit maximum NAT entries that can be created per user
1609 * @param src_ip source IPv4 address
1612 snat_ipfix_logging_max_entries_per_user (u32 limit, u32 src_ip)
1614 //TODO: This event SHOULD be rate limited
1615 snat_ipfix_logging_max_entries_per_user_args_t a;
1617 skip_if_disabled ();
1622 vl_api_rpc_call_main_thread (snat_ipfix_logging_max_entries_per_usr_rpc_cb,
1623 (u8 *) & a, sizeof (a));
1627 snat_data_callback_max_entries_per_usr (flow_report_main_t * frm,
1630 u32 * to_next, u32 node_index)
1632 snat_ipfix_logging_max_entries_per_usr (0, 0, 1);
1637 nat_ipfix_logging_max_ses_rpc_cb (nat_ipfix_logging_max_sessions_args_t * a)
1639 nat_ipfix_logging_max_ses (a->limit, 0);
1643 * @brief Generate maximum session entries exceeded event
1645 * @param limit configured limit
1648 nat_ipfix_logging_max_sessions (u32 limit)
1650 //TODO: This event SHOULD be rate limited
1651 nat_ipfix_logging_max_sessions_args_t a;
1653 skip_if_disabled ();
1657 vl_api_rpc_call_main_thread (nat_ipfix_logging_max_ses_rpc_cb,
1658 (u8 *) & a, sizeof (a));
1662 nat_data_callback_max_sessions (flow_report_main_t * frm,
1665 u32 * to_next, u32 node_index)
1667 nat_ipfix_logging_max_ses (0, 1);
1672 nat_ipfix_logging_max_bib_rpc_cb (nat_ipfix_logging_max_bibs_args_t * a)
1674 nat_ipfix_logging_max_bib (a->limit, 0);
1678 * @brief Generate maximum BIB entries exceeded event
1680 * @param limit configured limit
1683 nat_ipfix_logging_max_bibs (u32 limit)
1685 //TODO: This event SHOULD be rate limited
1686 nat_ipfix_logging_max_bibs_args_t a;
1688 skip_if_disabled ();
1692 vl_api_rpc_call_main_thread (nat_ipfix_logging_max_bib_rpc_cb,
1693 (u8 *) & a, sizeof (a));
1697 nat_data_callback_max_bibs (flow_report_main_t * frm,
1700 u32 * to_next, u32 node_index)
1702 nat_ipfix_logging_max_bib (0, 1);
1707 nat_ipfix_logging_max_frag_ip4_rpc_cb (nat_ipfix_logging_max_frags_ip4_args_t * a)
1709 nat_ipfix_logging_max_frag_ip4 (a->limit, a->src, 0);
1713 * @brief Generate maximum IPv4 fragments pending reassembly exceeded event
1715 * @param limit configured limit
1716 * @param src source IPv4 address
1719 nat_ipfix_logging_max_fragments_ip4 (u32 limit, ip4_address_t * src)
1721 //TODO: This event SHOULD be rate limited
1722 nat_ipfix_logging_max_frags_ip4_args_t a;
1724 skip_if_disabled ();
1727 a.src = src->as_u32;
1729 vl_api_rpc_call_main_thread (nat_ipfix_logging_max_frag_ip4_rpc_cb,
1730 (u8 *) & a, sizeof (a));
1734 nat_data_callback_max_frags_ip4 (flow_report_main_t * frm,
1737 u32 * to_next, u32 node_index)
1739 nat_ipfix_logging_max_frag_ip4 (0, 0, 1);
1744 nat_ipfix_logging_max_frag_ip6_rpc_cb (nat_ipfix_logging_max_frags_ip6_args_t * a)
1747 src.as_u64[0] = a->src[0];
1748 src.as_u64[1] = a->src[1];
1749 nat_ipfix_logging_max_frag_ip6 (a->limit, &src, 0);
1753 * @brief Generate maximum IPv6 fragments pending reassembly exceeded event
1755 * @param limit configured limit
1756 * @param src source IPv6 address
1759 nat_ipfix_logging_max_fragments_ip6 (u32 limit, ip6_address_t * src)
1761 //TODO: This event SHOULD be rate limited
1762 nat_ipfix_logging_max_frags_ip6_args_t a;
1764 skip_if_disabled ();
1767 a.src[0] = src->as_u64[0];
1768 a.src[1] = src->as_u64[1];
1770 vl_api_rpc_call_main_thread (nat_ipfix_logging_max_frag_ip6_rpc_cb,
1771 (u8 *) & a, sizeof (a));
1775 nat_data_callback_max_frags_ip6 (flow_report_main_t * frm,
1778 u32 * to_next, u32 node_index)
1780 nat_ipfix_logging_max_frag_ip6 (0, 0, 1);
1785 nat_ipfix_logging_nat64_bib_rpc_cb (nat_ipfix_logging_nat64_bib_args_t * a)
1787 ip6_address_t src_ip;
1788 src_ip.as_u64[0] = a->src_ip[0];
1789 src_ip.as_u64[1] = a->src_ip[1];
1790 nat_ipfix_logging_nat64_bibe (a->nat_event, &src_ip, a->nat_src_ip,
1791 a->proto, a->src_port, a->nat_src_port,
1796 * @brief Generate NAT64 BIB create and delete events
1798 * @param src_ip source IPv6 address
1799 * @param nat_src_ip transaltes source IPv4 address
1800 * @param proto L4 protocol
1801 * @param src_port source port
1802 * @param nat_src_port translated source port
1803 * @param vrf_id VRF ID
1804 * @param is_create non-zero value if create event otherwise delete event
1807 nat_ipfix_logging_nat64_bib (ip6_address_t * src_ip,
1808 ip4_address_t * nat_src_ip, u8 proto,
1809 u16 src_port, u16 nat_src_port, u32 vrf_id,
1812 nat_ipfix_logging_nat64_bib_args_t a;
1814 skip_if_disabled ();
1816 a.src_ip[0] = src_ip->as_u64[0];
1817 a.src_ip[1] = src_ip->as_u64[1];
1818 a.nat_src_ip = nat_src_ip->as_u32;
1820 a.src_port = src_port;
1821 a.nat_src_port = nat_src_port;
1823 a.nat_event = is_create ? NAT64_BIB_CREATE : NAT64_BIB_DELETE;
1825 vl_api_rpc_call_main_thread (nat_ipfix_logging_nat64_bib_rpc_cb,
1826 (u8 *) & a, sizeof (a));
1830 nat_data_callback_nat64_bib (flow_report_main_t * frm,
1833 u32 * to_next, u32 node_index)
1835 nat_ipfix_logging_nat64_bibe (0, 0, 0, 0, 0, 0, 0, 1);
1840 nat_ipfix_logging_nat64_ses_rpc_cb (nat_ipfix_logging_nat64_ses_args_t * a)
1842 ip6_address_t src_ip, dst_ip;
1843 src_ip.as_u64[0] = a->src_ip[0];
1844 src_ip.as_u64[1] = a->src_ip[1];
1845 dst_ip.as_u64[0] = a->dst_ip[0];
1846 dst_ip.as_u64[1] = a->dst_ip[1];
1847 nat_ipfix_logging_nat64_ses (a->nat_event, &src_ip, a->nat_src_ip,
1848 a->proto, a->src_port, a->nat_src_port,
1849 &dst_ip, a->nat_dst_ip, a->dst_port,
1850 a->nat_dst_port, a->vrf_id, 0);
1854 * @brief Generate NAT64 session create and delete events
1856 * @param src_ip source IPv6 address
1857 * @param nat_src_ip transaltes source IPv4 address
1858 * @param proto L4 protocol
1859 * @param src_port source port
1860 * @param nat_src_port translated source port
1861 * @param dst_ip destination IPv6 address
1862 * @param nat_dst_ip destination IPv4 address
1863 * @param dst_port destination port
1864 * @param nat_dst_port translated destination port
1865 * @param vrf_id VRF ID
1866 * @param is_create non-zero value if create event otherwise delete event
1869 nat_ipfix_logging_nat64_session (ip6_address_t * src_ip,
1870 ip4_address_t * nat_src_ip, u8 proto,
1871 u16 src_port, u16 nat_src_port,
1872 ip6_address_t * dst_ip,
1873 ip4_address_t * nat_dst_ip, u16 dst_port,
1874 u16 nat_dst_port, u32 vrf_id, u8 is_create)
1876 nat_ipfix_logging_nat64_ses_args_t a;
1878 skip_if_disabled ();
1880 a.src_ip[0] = src_ip->as_u64[0];
1881 a.src_ip[1] = src_ip->as_u64[1];
1882 a.nat_src_ip = nat_src_ip->as_u32;
1884 a.src_port = src_port;
1885 a.nat_src_port = nat_src_port;
1886 a.dst_ip[0] = dst_ip->as_u64[0];
1887 a.dst_ip[1] = dst_ip->as_u64[1];
1888 a.nat_dst_ip = nat_dst_ip->as_u32;
1889 a.dst_port = dst_port;
1890 a.nat_dst_port = nat_dst_port;
1892 a.nat_event = is_create ? NAT64_SESSION_CREATE : NAT64_SESSION_DELETE;
1894 vl_api_rpc_call_main_thread (nat_ipfix_logging_nat64_ses_rpc_cb,
1895 (u8 *) & a, sizeof (a));
1899 nat_data_callback_nat64_session (flow_report_main_t * frm,
1902 u32 * to_next, u32 node_index)
1904 nat_ipfix_logging_nat64_ses (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
1909 * @brief Enable/disable NAT plugin IPFIX logging
1911 * @param enable 1 if enable, 0 if disable
1912 * @param domain_id observation domain ID
1913 * @param src_port source port number
1915 * @returns 0 if success
1918 snat_ipfix_logging_enable_disable (int enable, u32 domain_id, u16 src_port)
1920 snat_main_t *sm = &snat_main;
1921 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
1922 flow_report_main_t *frm = &flow_report_main;
1923 vnet_flow_report_add_del_args_t a;
1925 u8 e = enable ? 1 : 0;
1927 if (silm->enabled == e)
1932 memset (&a, 0, sizeof (a));
1934 a.domain_id = domain_id ? domain_id : 1;
1935 a.src_port = src_port ? src_port : UDP_DST_PORT_ipfix;
1937 if (sm->deterministic)
1939 a.rewrite_callback = snat_template_rewrite_max_entries_per_usr;
1940 a.flow_data_callback = snat_data_callback_max_entries_per_usr;
1942 rv = vnet_flow_report_add_del (frm, &a, NULL);
1945 clib_warning ("vnet_flow_report_add_del returned %d", rv);
1951 a.rewrite_callback = snat_template_rewrite_nat44_session;
1952 a.flow_data_callback = snat_data_callback_nat44_session;
1954 rv = vnet_flow_report_add_del (frm, &a, NULL);
1957 clib_warning ("vnet_flow_report_add_del returned %d", rv);
1961 a.rewrite_callback = snat_template_rewrite_addr_exhausted;
1962 a.flow_data_callback = snat_data_callback_addr_exhausted;
1964 rv = vnet_flow_report_add_del (frm, &a, NULL);
1967 clib_warning ("vnet_flow_report_add_del returned %d", rv);
1971 a.rewrite_callback = nat_template_rewrite_max_sessions;
1972 a.flow_data_callback = nat_data_callback_max_sessions;
1974 rv = vnet_flow_report_add_del (frm, &a, NULL);
1977 clib_warning ("vnet_flow_report_add_del returned %d", rv);
1981 a.rewrite_callback = nat_template_rewrite_max_bibs;
1982 a.flow_data_callback = nat_data_callback_max_bibs;
1984 rv = vnet_flow_report_add_del (frm, &a, NULL);
1987 clib_warning ("vnet_flow_report_add_del returned %d", rv);
1991 a.rewrite_callback = nat_template_rewrite_max_frags_ip4;
1992 a.flow_data_callback = nat_data_callback_max_frags_ip4;
1994 rv = vnet_flow_report_add_del (frm, &a, NULL);
1997 clib_warning ("vnet_flow_report_add_del returned %d", rv);
2001 a.rewrite_callback = nat_template_rewrite_max_frags_ip6;
2002 a.flow_data_callback = nat_data_callback_max_frags_ip6;
2004 rv = vnet_flow_report_add_del (frm, &a, NULL);
2007 clib_warning ("vnet_flow_report_add_del returned %d", rv);
2011 a.rewrite_callback = nat_template_rewrite_nat64_bib;
2012 a.flow_data_callback = nat_data_callback_nat64_bib;
2014 rv = vnet_flow_report_add_del (frm, &a, NULL);
2017 clib_warning ("vnet_flow_report_add_del returned %d", rv);
2021 a.rewrite_callback = nat_template_rewrite_nat64_session;
2022 a.flow_data_callback = nat_data_callback_nat64_session;
2024 rv = vnet_flow_report_add_del (frm, &a, NULL);
2027 clib_warning ("vnet_flow_report_add_del returned %d", rv);
2031 if (sm->endpoint_dependent)
2033 a.rewrite_callback = snat_template_rewrite_max_entries_per_usr;
2034 a.flow_data_callback = snat_data_callback_max_entries_per_usr;
2036 rv = vnet_flow_report_add_del (frm, &a, NULL);
2039 clib_warning ("vnet_flow_report_add_del returned %d", rv);
2049 * @brief Initialize NAT plugin IPFIX logging
2051 * @param vm vlib main
2054 snat_ipfix_logging_init (vlib_main_t * vm)
2056 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main;
2060 /* Set up time reference pair */
2061 silm->vlib_time_0 = vlib_time_now (vm);
2062 silm->milisecond_time_0 = unix_time_now_nsec () * 1e-6;