27 #define NAT44_SESSION_CREATE_LEN 26 28 #define NAT_ADDRESSES_EXHAUTED_LEN 13 29 #define MAX_ENTRIES_PER_USER_LEN 21 30 #define MAX_SESSIONS_LEN 17 31 #define MAX_BIBS_LEN 17 32 #define MAX_FRAGMENTS_IP4_LEN 21 33 #define MAX_FRAGMENTS_IP6_LEN 33 34 #define NAT64_BIB_LEN 38 35 #define NAT64_SES_LEN 62 37 #define NAT44_SESSION_CREATE_FIELD_COUNT 8 38 #define NAT_ADDRESSES_EXHAUTED_FIELD_COUNT 3 39 #define MAX_ENTRIES_PER_USER_FIELD_COUNT 5 40 #define MAX_SESSIONS_FIELD_COUNT 4 41 #define MAX_BIBS_FIELD_COUNT 4 42 #define MAX_FRAGMENTS_FIELD_COUNT 5 43 #define NAT64_BIB_FIELD_COUNT 8 44 #define NAT64_SES_FIELD_COUNT 12 116 #define skip_if_disabled() \ 118 snat_ipfix_logging_main_t *silm = &snat_ipfix_logging_main; \ 119 if (PREDICT_TRUE (!clib_atomic_fetch_or(&silm->enabled, 0))) \ 123 #define update_template_id(old_id, new_id) \ 125 u16 template_id = clib_atomic_fetch_or(old_id, 0); \ 126 clib_atomic_cmp_and_swap(old_id, template_id, new_id); \ 258 udp->
dst_port = clib_host_to_net_u16 (collector_port);
259 udp->
length = clib_host_to_net_u16 (
vec_len (rewrite) -
sizeof (*ip));
427 ip->
length = clib_host_to_net_u16 ((
u8 *) f - (
u8 *) ip);
440 u32 n_elts,
u32 *stream_index)
453 u32 n_elts,
u32 *stream_index)
466 u32 n_elts,
u32 *stream_index)
480 u32 n_elts,
u32 *stream_index)
494 u32 n_elts,
u32 *stream_index)
508 u32 n_elts,
u32 *stream_index)
522 u32 n_elts,
u32 *stream_index)
536 u32 n_elts,
u32 *stream_index)
549 u32 n_elts,
u32 *stream_index)
570 stream = &frm->
streams[stream_index];
575 b0->
flags |= (VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_FLOW_REPORT);
603 *offset = (
u32) (((
u8 *) (s + 1)) - (
u8 *) tp);
625 (sizeof (*ip) +
sizeof (*udp) +
628 (sizeof (*ip) +
sizeof (*udp)));
678 nat_log_err (
"can't allocate buffer for NAT IPFIX event");
708 u64 time_stamp = clib_host_to_net_u64 (now);
710 offset +=
sizeof (time_stamp);
713 offset +=
sizeof (nat_event);
716 offset +=
sizeof (
src_ip);
719 offset +=
sizeof (nat_src_ip);
722 offset +=
sizeof (proto);
728 offset +=
sizeof (nat_src_port);
731 offset +=
sizeof (vrf_id);
777 nat_log_err (
"can't allocate buffer for NAT IPFIX event");
807 u64 time_stamp = clib_host_to_net_u64 (now);
809 offset +=
sizeof (time_stamp);
812 offset +=
sizeof (nat_event);
815 offset +=
sizeof (pool_id);
863 nat_log_err (
"can't allocate buffer for NAT IPFIX event");
893 u64 time_stamp = clib_host_to_net_u64 (now);
895 offset +=
sizeof (time_stamp);
898 offset +=
sizeof (nat_event);
901 offset +=
sizeof (quota_event);
904 offset +=
sizeof (limit);
907 offset +=
sizeof (
src_ip);
954 nat_log_err (
"can't allocate buffer for NAT IPFIX event");
984 u64 time_stamp = clib_host_to_net_u64 (now);
986 offset +=
sizeof (time_stamp);
989 offset +=
sizeof (nat_event);
992 offset +=
sizeof (quota_event);
995 offset +=
sizeof (limit);
1042 nat_log_err (
"can't allocate buffer for NAT IPFIX event");
1072 u64 time_stamp = clib_host_to_net_u64 (now);
1074 offset +=
sizeof (time_stamp);
1077 offset +=
sizeof (nat_event);
1080 offset +=
sizeof (quota_event);
1083 offset +=
sizeof (limit);
1131 nat_log_err (
"can't allocate buffer for NAT IPFIX event");
1161 u64 time_stamp = clib_host_to_net_u64 (now);
1163 offset +=
sizeof (time_stamp);
1166 offset +=
sizeof (nat_event);
1169 offset +=
sizeof (quota_event);
1172 offset +=
sizeof (limit);
1175 offset +=
sizeof (
src);
1223 nat_log_err (
"can't allocate buffer for NAT IPFIX event");
1253 u64 time_stamp = clib_host_to_net_u64 (now);
1255 offset +=
sizeof (time_stamp);
1258 offset +=
sizeof (nat_event);
1261 offset +=
sizeof (quota_event);
1264 offset +=
sizeof (limit);
1290 u32 vrf_id,
int do_flush)
1315 nat_log_err (
"can't allocate buffer for NAT IPFIX event");
1345 u64 time_stamp = clib_host_to_net_u64 (now);
1347 offset +=
sizeof (time_stamp);
1350 offset +=
sizeof (nat_event);
1356 offset +=
sizeof (nat_src_ip);
1359 offset +=
sizeof (proto);
1365 offset +=
sizeof (nat_src_port);
1368 offset +=
sizeof (vrf_id);
1393 u32 vrf_id,
int do_flush)
1418 nat_log_err (
"can't allocate buffer for NAT IPFIX event");
1448 u64 time_stamp = clib_host_to_net_u64 (now);
1450 offset +=
sizeof (time_stamp);
1453 offset +=
sizeof (nat_event);
1459 offset +=
sizeof (nat_src_ip);
1462 offset +=
sizeof (proto);
1468 offset +=
sizeof (nat_src_port);
1474 offset +=
sizeof (nat_dst_ip);
1480 offset +=
sizeof (nat_dst_port);
1483 offset +=
sizeof (vrf_id);
1508 0, 0, 0, 0, 0, 0, 0, do_flush);
1516 0, 0, 0, 0, 0, 0, 0, do_flush);
1518 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, do_flush);
1547 snat_ipfix_flush_node.index);
1571 u16 nat_src_port,
u32 vrf_id)
1576 nat_src_ip, snat_proto, src_port, nat_src_port,
1597 u16 nat_src_port,
u32 vrf_id)
1602 nat_src_ip, snat_proto, src_port, nat_src_port,
1642 u32 * to_next,
u32 node_index)
1738 nat_src_ip->
as_u32, proto, src_port,
1739 nat_src_port, vrf_id, 0);
1765 u16 nat_dst_port,
u32 vrf_id,
u8 is_create)
1774 nat_src_ip->
as_u32, proto, src_port,
1775 nat_src_port, dst_ip, nat_dst_ip->
as_u32,
1776 dst_port, nat_dst_port, vrf_id, 0);
1811 u8 e = enable ? 1 : 0;
1818 a.
domain_id = domain_id ? domain_id : 1;
1819 a.
src_port = src_port ? src_port : UDP_DST_PORT_ipfix;
1829 nat_log_warn (
"vnet_flow_report_add_del returned %d", rv);
1840 nat_log_warn (
"vnet_flow_report_add_del returned %d", rv);
1849 nat_log_warn (
"vnet_flow_report_add_del returned %d", rv);
1858 nat_log_warn (
"vnet_flow_report_add_del returned %d", rv);
1867 nat_log_warn (
"vnet_flow_report_add_del returned %d", rv);
1876 nat_log_warn (
"vnet_flow_report_add_del returned %d", rv);
1885 nat_log_warn (
"vnet_flow_report_add_del returned %d", rv);
1894 nat_log_warn (
"vnet_flow_report_add_del returned %d", rv);
1903 nat_log_warn (
"vnet_flow_report_add_del returned %d", rv);
1914 nat_log_warn (
"vnet_flow_report_add_del returned %d", rv);
1957 .name =
"snat-ipfix-flush",
1959 .state = VLIB_NODE_STATE_INTERRUPT,
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
u16 max_frags_ip4_template_id
void snat_ipfix_logging_max_entries_per_user(u32 thread_index, u32 limit, u32 src_ip)
Generate maximum entries per user exceeded event.
u8 * snat_template_rewrite_addr_exhausted(flow_report_main_t *frm, flow_report_t *fr, ip4_address_t *collector_address, ip4_address_t *src_address, u16 collector_port, ipfix_report_element_t *elts, u32 n_elts, u32 *stream_index)
vlib_frame_t * nat64_bib_frame
u16 max_frags_ip6_template_id
#define MAX_FRAGMENTS_IP6_LEN
u16 nat64_ses_template_id
u8 * nat_template_rewrite_max_sessions(flow_report_main_t *frm, flow_report_t *fr, ip4_address_t *collector_address, ip4_address_t *src_address, u16 collector_port, ipfix_report_element_t *elts, u32 n_elts, u32 *stream_index)
vlib_buffer_t * nat64_ses_buffer
void snat_ipfix_flush_from_main(void)
u32 nat64_bib_next_record_offset
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
vlib_buffer_t * max_frags_ip4_buffer
static void vlib_node_set_interrupt_pending(vlib_main_t *vm, u32 node_index)
#define clib_memcpy_fast(a, b, c)
static u32 ipfix_e_id_length(int e, u16 id, u16 length)
vlib_buffer_t * addr_exhausted_buffer
static f64 vlib_time_now(vlib_main_t *vm)
#define NAT44_SESSION_CREATE_FIELD_COUNT
int vnet_flow_report_add_del(flow_report_main_t *frm, vnet_flow_report_add_del_args_t *a, u16 *template_id)
u8 * nat_template_rewrite_max_bibs(flow_report_main_t *frm, flow_report_t *fr, ip4_address_t *collector_address, ip4_address_t *src_address, u16 collector_port, ipfix_report_element_t *elts, u32 n_elts, u32 *stream_index)
u16 current_length
Nbytes between current data and the end of this buffer.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define nat_log_warn(...)
u16 addr_exhausted_template_id
static uword ipfix_flush_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
ip4_address_t src_address
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
static void nat_ipfix_logging_nat64_bibe(u32 thread_index, u8 nat_event, ip6_address_t *src_ip, u32 nat_src_ip, u8 proto, u16 src_port, u16 nat_src_port, u32 vrf_id, int do_flush)
u8 enabled
NAT plugin IPFIX logging enabled.
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
u32 addr_exhausted_next_record_offset
#define MAX_SESSIONS_FIELD_COUNT
vlib_main_t ** vlib_mains
snat_ipfix_per_thread_data_t * per_thread_data
vlib_frame_t * max_frags_ip4_frame
ip4_address_t ipfix_collector
vlib_node_registration_t ip4_lookup_node
(constructor) VLIB_REGISTER_NODE (ip4_lookup_node)
u8 * snat_template_rewrite_nat44_session(flow_report_main_t *frm, flow_report_t *fr, ip4_address_t *collector_address, ip4_address_t *src_address, u16 collector_port, ipfix_report_element_t *elts, u32 n_elts, u32 *stream_index)
flow_report_stream_t * streams
static void nat_ipfix_logging_max_frag_ip4(u32 thread_index, u32 limit, u32 src, int do_flush)
#define update_template_id(old_id, new_id)
vlib_frame_t * deterministic_nat_data_callback(flow_report_main_t *frm, flow_report_t *fr, vlib_frame_t *f, u32 *to_next, u32 node_index)
void nat_ipfix_logging_max_bibs(u32 thread_index, u32 limit)
Generate maximum BIB entries exceeded event.
vnet_flow_rewrite_callback_t * rewrite_callback
snat_ipfix_logging_main_t snat_ipfix_logging_main
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
#define clib_atomic_fetch_or(a, b)
u32 max_sessions_next_record_offset
void snat_ipfix_logging_init(vlib_main_t *vm)
Initialize NAT plugin IPFIX logging.
int snat_ipfix_logging_enable_disable(int enable, u32 domain_id, u16 src_port)
Enable/disable NAT plugin IPFIX logging.
#define NAT44_SESSION_CREATE_LEN
void snat_ipfix_logging_addresses_exhausted(u32 thread_index, u32 pool_id)
Generate NAT addresses exhausted event.
void nat_ipfix_logging_max_fragments_ip4(u32 thread_index, u32 limit, ip4_address_t *src)
Generate maximum IPv4 fragments pending reassembly exceeded event.
u8 * snat_template_rewrite_max_entries_per_usr(flow_report_main_t *frm, flow_report_t *fr, ip4_address_t *collector_address, ip4_address_t *src_address, u16 collector_port, ipfix_report_element_t *elts, u32 n_elts, u32 *stream_index)
static u8 * snat_template_rewrite(flow_report_main_t *frm, flow_report_t *fr, ip4_address_t *collector_address, ip4_address_t *src_address, u16 collector_port, nat_event_t event, quota_exceed_event_t quota_event)
Create an IPFIX template packet rewrite string.
static void snat_ipfix_send(flow_report_main_t *frm, vlib_frame_t *f, vlib_buffer_t *b0, u16 template_id)
void nat_ipfix_logging_max_sessions(u32 thread_index, u32 limit)
Generate maximum session entries exceeded event.
#define MAX_FRAGMENTS_FIELD_COUNT
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
void snat_ipfix_flush(u32 thread_index)
u16 nat64_bib_template_id
static void nat_ipfix_logging_max_bib(u32 thread_index, u32 limit, int do_flush)
flow_report_main_t flow_report_main
vlib_main_t ** worker_vms
vector of worker vlib mains
vlib_frame_t * data_callback(flow_report_main_t *frm, flow_report_t *fr, vlib_frame_t *f, u32 *to_next, u32 node_index)
#define NAT_ADDRESSES_EXHAUTED_LEN
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static void snat_ipfix_logging_nat44_ses(u32 thread_index, u8 nat_event, u32 src_ip, u32 nat_src_ip, snat_protocol_t snat_proto, u16 src_port, u16 nat_src_port, u32 vrf_id, int do_flush)
vlib_frame_t * max_entries_per_user_frame
void nat_ipfix_logging_max_fragments_ip6(u32 thread_index, u32 limit, ip6_address_t *src)
Generate maximum IPv6 fragments pending reassembly exceeded event.
vl_api_address_union_t src_address
void nat_ipfix_logging_nat64_bib(u32 thread_index, ip6_address_t *src_ip, ip4_address_t *nat_src_ip, u8 proto, u16 src_port, u16 nat_src_port, u32 vrf_id, u8 is_create)
Generate NAT64 BIB create and delete events.
u32 stream_index
stream index
static u32 version_length(u16 length)
u16 call_counter
nat data callbacks call counter
vlib_frame_t * max_sessions_frame
u64 milisecond_time_0
Time reference pair.
vlib_node_registration_t snat_ipfix_flush_node
(constructor) VLIB_REGISTER_NODE (snat_ipfix_flush_node)
u16 max_entries_per_user_template_id
vlib_frame_t * nat64_ses_frame
static void nat_ipfix_logging_nat64_ses(u32 thread_index, u8 nat_event, ip6_address_t *src_ip, u32 nat_src_ip, u8 proto, u16 src_port, u16 nat_src_port, ip6_address_t *dst_ip, u32 nat_dst_ip, u16 dst_port, u16 nat_dst_port, u32 vrf_id, int do_flush)
void snat_ipfix_logging_nat44_ses_delete(u32 thread_index, u32 src_ip, u32 nat_src_ip, snat_protocol_t snat_proto, u16 src_port, u16 nat_src_port, u32 vrf_id)
Generate NAT44 session delete event.
vlib_frame_t * max_bibs_frame
static void snat_ipfix_logging_addr_exhausted(u32 thread_index, u32 pool_id, int do_flush)
#define VLIB_REGISTER_NODE(x,...)
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
vlib_buffer_t * max_entries_per_user_buffer
static u32 ipfix_id_count(u16 id, u16 count)
static void nat_ipfix_logging_max_ses(u32 thread_index, u32 limit, int do_flush)
static u64 unix_time_now_nsec(void)
void nat_ipfix_logging_nat64_session(u32 thread_index, ip6_address_t *src_ip, ip4_address_t *nat_src_ip, u8 proto, u16 src_port, u16 nat_src_port, ip6_address_t *dst_ip, ip4_address_t *nat_dst_ip, u16 dst_port, u16 nat_dst_port, u32 vrf_id, u8 is_create)
Generate NAT64 session create and delete events.
u16 nat44_session_template_id
template IDs
u8 * nat_template_rewrite_nat64_session(flow_report_main_t *frm, flow_report_t *fr, ip4_address_t *collector_address, ip4_address_t *src_address, u16 collector_port, ipfix_report_element_t *elts, u32 n_elts, u32 *stream_index)
#define clib_atomic_cmp_and_swap(addr, old, new)
vlib_frame_t * addr_exhausted_frame
u16 max_sessions_template_id
#define MAX_BIBS_FIELD_COUNT
u32 max_frags_ip4_next_record_offset
u16 ip4_tcp_udp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip4_header_t *ip0)
#define MAX_FRAGMENTS_IP4_LEN
vlib_frame_t * nat44_session_frame
frames containing ipfix buffers
u32 nat64_ses_next_record_offset
u32 max_frags_ip6_next_record_offset
u8 * nat_template_rewrite_nat64_bib(flow_report_main_t *frm, flow_report_t *fr, ip4_address_t *collector_address, ip4_address_t *src_address, u16 collector_port, ipfix_report_element_t *elts, u32 n_elts, u32 *stream_index)
vlib_frame_t * max_frags_ip6_frame
snat_protocol_t snat_proto
static void nat_ipfix_logging_max_frag_ip6(u32 thread_index, u32 limit, ip6_address_t *src, int do_flush)
#define clib_atomic_fetch_add(a, b)
vlib_buffer_t * nat44_session_buffer
ipfix buffers under construction
struct _vlib_node_registration vlib_node_registration_t
template key/value backing page structure
static u32 ipfix_set_id_length(u16 set_id, u16 length)
u8 * nat_template_rewrite_max_frags_ip4(flow_report_main_t *frm, flow_report_t *fr, ip4_address_t *collector_address, ip4_address_t *src_address, u16 collector_port, ipfix_report_element_t *elts, u32 n_elts, u32 *stream_index)
#define MAX_ENTRIES_PER_USER_LEN
#define MAX_ENTRIES_PER_USER_FIELD_COUNT
u32 nat44_session_next_record_offset
next record offset
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void snat_ipfix_logging_max_entries_per_usr(u32 thread_index, u32 limit, u32 src_ip, int do_flush)
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
VLIB buffer representation.
#define skip_if_disabled()
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
vlib_buffer_t * max_bibs_buffer
vnet_flow_data_callback_t * flow_data_callback
struct clib_bihash_value offset
template key/value backing page structure
#define NAT_ADDRESSES_EXHAUTED_FIELD_COUNT
u32 max_bibs_next_record_offset
#define NAT64_SES_FIELD_COUNT
static vlib_thread_main_t * vlib_get_thread_main()
static void snat_ipfix_header_create(flow_report_main_t *frm, vlib_buffer_t *b0, u32 *offset)
vlib_buffer_t * max_frags_ip6_buffer
vlib_buffer_t * max_sessions_buffer
#define CLIB_CACHE_LINE_BYTES
u8 * nat_template_rewrite_max_frags_ip6(flow_report_main_t *frm, flow_report_t *fr, ip4_address_t *collector_address, ip4_address_t *src_address, u16 collector_port, ipfix_report_element_t *elts, u32 n_elts, u32 *stream_index)
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u16 ip4_header_checksum(ip4_header_t *i)
u32 max_entries_per_user_next_record_offset
vlib_buffer_t * nat64_bib_buffer
#define NAT64_BIB_FIELD_COUNT
void snat_ipfix_logging_nat44_ses_create(u32 thread_index, u32 src_ip, u32 nat_src_ip, snat_protocol_t snat_proto, u16 src_port, u16 nat_src_port, u32 vrf_id)
Generate NAT44 session create event.