diff options
Diffstat (limited to 'src/plugins/nat/lib')
-rw-r--r-- | src/plugins/nat/lib/alloc.h | 2 | ||||
-rw-r--r-- | src/plugins/nat/lib/inlines.h | 22 | ||||
-rw-r--r-- | src/plugins/nat/lib/ipfix_logging.c | 241 | ||||
-rw-r--r-- | src/plugins/nat/lib/ipfix_logging.h | 4 | ||||
-rw-r--r-- | src/plugins/nat/lib/lib.h | 11 | ||||
-rw-r--r-- | src/plugins/nat/lib/log.h | 15 | ||||
-rw-r--r-- | src/plugins/nat/lib/nat_proto.h | 1 |
7 files changed, 158 insertions, 138 deletions
diff --git a/src/plugins/nat/lib/alloc.h b/src/plugins/nat/lib/alloc.h index 0c302bf4cfb..882809e829c 100644 --- a/src/plugins/nat/lib/alloc.h +++ b/src/plugins/nat/lib/alloc.h @@ -42,14 +42,12 @@ struct nat_ip4_pool_addr_s { ip4_address_t addr; u32 fib_index; -/* *INDENT-OFF* */ #define _(N, i, n, s) \ u16 busy_##n##_ports; \ u16 * busy_##n##_ports_per_thread; \ uword * busy_##n##_port_bitmap; foreach_nat_protocol #undef _ -/* *INDENT-ON* */ }; struct nat_ip4_addr_port_s diff --git a/src/plugins/nat/lib/inlines.h b/src/plugins/nat/lib/inlines.h index 46be64d36cf..24e3ba83a5b 100644 --- a/src/plugins/nat/lib/inlines.h +++ b/src/plugins/nat/lib/inlines.h @@ -20,20 +20,18 @@ #include <vnet/ip/icmp46_packet.h> -static_always_inline u8 +static_always_inline u64 icmp_type_is_error_message (u8 icmp_type) { - switch (icmp_type) - { - case ICMP4_destination_unreachable: - case ICMP4_time_exceeded: - case ICMP4_parameter_problem: - case ICMP4_source_quench: - case ICMP4_redirect: - case ICMP4_alternate_host_address: - return 1; - } - return 0; + int bmp = 0; + bmp |= 1 << ICMP4_destination_unreachable; + bmp |= 1 << ICMP4_time_exceeded; + bmp |= 1 << ICMP4_parameter_problem; + bmp |= 1 << ICMP4_source_quench; + bmp |= 1 << ICMP4_redirect; + bmp |= 1 << ICMP4_alternate_host_address; + + return (1ULL << icmp_type) & bmp; } #endif /* included_nat_inlines_h__ */ diff --git a/src/plugins/nat/lib/ipfix_logging.c b/src/plugins/nat/lib/ipfix_logging.c index 27a0b92ae71..593fa09f7e2 100644 --- a/src/plugins/nat/lib/ipfix_logging.c +++ b/src/plugins/nat/lib/ipfix_logging.c @@ -143,12 +143,9 @@ do { \ * @returns template packet */ static inline u8 * -nat_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) +nat_template_rewrite (ipfix_exporter_t *exp, flow_report_t *fr, + u16 collector_port, nat_event_t event, + quota_exceed_event_t quota_event) { nat_ipfix_logging_main_t *silm = &nat_ipfix_logging_main; ip4_header_t *ip; @@ -164,7 +161,7 @@ nat_template_rewrite (flow_report_main_t * frm, flow_report_stream_t *stream; u32 stream_index; - stream = &frm->streams[fr->stream_index]; + stream = &exp->streams[fr->stream_index]; stream_index = clib_atomic_fetch_or(&silm->stream_index, 0); clib_atomic_cmp_and_swap (&silm->stream_index, @@ -241,8 +238,8 @@ nat_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)); @@ -390,97 +387,72 @@ nat_template_rewrite (flow_report_main_t * frm, } u8 * -nat_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) +nat_template_rewrite_addr_exhausted (ipfix_exporter_t *exp, flow_report_t *fr, + u16 collector_port, + ipfix_report_element_t *elts, u32 n_elts, + u32 *stream_index) { - return nat_template_rewrite (frm, fr, collector_address, src_address, - collector_port, NAT_ADDRESSES_EXHAUTED, 0); + return nat_template_rewrite (exp, fr, collector_port, NAT_ADDRESSES_EXHAUTED, + 0); } u8 * -nat_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) +nat_template_rewrite_nat44_session (ipfix_exporter_t *exp, flow_report_t *fr, + u16 collector_port, + ipfix_report_element_t *elts, u32 n_elts, + u32 *stream_index) { - return nat_template_rewrite (frm, fr, collector_address, src_address, - collector_port, NAT44_SESSION_CREATE, 0); + return nat_template_rewrite (exp, fr, collector_port, NAT44_SESSION_CREATE, + 0); } u8 * -nat_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) +nat_template_rewrite_max_entries_per_usr ( + ipfix_exporter_t *exp, 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) { - return nat_template_rewrite (frm, fr, collector_address, src_address, - collector_port, QUOTA_EXCEEDED, - MAX_ENTRIES_PER_USER); + return nat_template_rewrite (exp, fr, collector_port, QUOTA_EXCEEDED, + MAX_ENTRIES_PER_USER); } 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, +nat_template_rewrite_max_sessions (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) { - return nat_template_rewrite (frm, fr, collector_address, src_address, - collector_port, QUOTA_EXCEEDED, - MAX_SESSION_ENTRIES); + return nat_template_rewrite (exp, fr, collector_port, QUOTA_EXCEEDED, + MAX_SESSION_ENTRIES); } 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, +nat_template_rewrite_max_bibs (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) { - return nat_template_rewrite (frm, fr, collector_address, src_address, - collector_port, QUOTA_EXCEEDED, - MAX_BIB_ENTRIES); + return nat_template_rewrite (exp, fr, collector_port, QUOTA_EXCEEDED, + MAX_BIB_ENTRIES); } 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) +nat_template_rewrite_nat64_bib (ipfix_exporter_t *exp, flow_report_t *fr, + u16 collector_port, + ipfix_report_element_t *elts, u32 n_elts, + u32 *stream_index) { - return nat_template_rewrite (frm, fr, collector_address, src_address, - collector_port, NAT64_BIB_CREATE, 0); + return nat_template_rewrite (exp, fr, collector_port, NAT64_BIB_CREATE, 0); } 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) +nat_template_rewrite_nat64_session (ipfix_exporter_t *exp, flow_report_t *fr, + u16 collector_port, + ipfix_report_element_t *elts, u32 n_elts, + u32 *stream_index) { - return nat_template_rewrite (frm, fr, collector_address, src_address, - collector_port, NAT64_SESSION_CREATE, 0); + return nat_template_rewrite (exp, fr, collector_port, NAT64_SESSION_CREATE, + 0); } static inline void @@ -497,16 +469,17 @@ nat_ipfix_header_create (flow_report_main_t * frm, ip4_header_t *ip; udp_header_t *udp; vlib_main_t *vm = vlib_get_main (); - + ipfix_exporter_t *exp = pool_elt_at_index (frm->exporters, 0); + stream_index = clib_atomic_fetch_or(&silm->stream_index, 0); - stream = &frm->streams[stream_index]; + stream = &exp->streams[stream_index]; b0->current_data = 0; b0->current_length = sizeof (*ip) + sizeof (*udp) + sizeof (*h) + sizeof (*s); b0->flags |= (VLIB_BUFFER_TOTAL_LENGTH_VALID | VNET_BUFFER_F_FLOW_REPORT); 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; udp = (udp_header_t *) (ip + 1); @@ -517,10 +490,10 @@ nat_ipfix_header_create (flow_report_main_t * frm, ip->ttl = 254; ip->protocol = IP_PROTOCOL_UDP; ip->flags_and_fragment_offset = 0; - ip->src_address.as_u32 = frm->src_address.as_u32; - ip->dst_address.as_u32 = frm->ipfix_collector.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 (frm->collector_port); + udp->dst_port = clib_host_to_net_u16 (exp->collector_port); udp->checksum = 0; h->export_time = clib_host_to_net_u32 ((u32) @@ -545,6 +518,7 @@ nat_ipfix_send (flow_report_main_t *frm, vlib_frame_t *f, vlib_buffer_t *b0, ip4_header_t *ip; udp_header_t *udp; vlib_main_t *vm = vlib_get_main (); + ipfix_exporter_t *exp = pool_elt_at_index (frm->exporters, 0); tp = vlib_buffer_get_current (b0); ip = (ip4_header_t *) & tp->ip4; @@ -563,7 +537,7 @@ nat_ipfix_send (flow_report_main_t *frm, vlib_frame_t *f, vlib_buffer_t *b0, ip->checksum = ip4_header_checksum (ip); udp->length = clib_host_to_net_u16 (b0->current_length - sizeof (*ip)); - if (frm->udp_checksum) + if (exp->udp_checksum) { udp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip); if (udp->checksum == 0) @@ -591,6 +565,7 @@ nat_ipfix_logging_nat44_ses (u32 thread_index, u8 nat_event, u32 src_ip, u64 now; u16 template_id; u32 vrf_id; + ipfix_exporter_t *exp = pool_elt_at_index (frm->exporters, 0); now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3); now += silm->milisecond_time_0; @@ -663,8 +638,8 @@ nat_ipfix_logging_nat44_ses (u32 thread_index, u8 nat_event, u32 src_ip, b0->current_length += NAT44_SESSION_CREATE_LEN; } - if (PREDICT_FALSE - (do_flush || (offset + NAT44_SESSION_CREATE_LEN) > frm->path_mtu)) + if (PREDICT_FALSE (do_flush || + (offset + NAT44_SESSION_CREATE_LEN) > exp->path_mtu)) { template_id = clib_atomic_fetch_or ( &silm->nat44_session_template_id, @@ -691,6 +666,7 @@ nat_ipfix_logging_addr_exhausted (u32 thread_index, u32 pool_id, int do_flush) u64 now; u8 nat_event = NAT_ADDRESSES_EXHAUTED; u16 template_id; + ipfix_exporter_t *exp = pool_elt_at_index (frm->exporters, 0); now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3); now += silm->milisecond_time_0; @@ -746,8 +722,8 @@ nat_ipfix_logging_addr_exhausted (u32 thread_index, u32 pool_id, int do_flush) b0->current_length += NAT_ADDRESSES_EXHAUTED_LEN; } - if (PREDICT_FALSE - (do_flush || (offset + NAT_ADDRESSES_EXHAUTED_LEN) > frm->path_mtu)) + if (PREDICT_FALSE (do_flush || + (offset + NAT_ADDRESSES_EXHAUTED_LEN) > exp->path_mtu)) { template_id = clib_atomic_fetch_or ( &silm->addr_exhausted_template_id, @@ -776,6 +752,7 @@ nat_ipfix_logging_max_entries_per_usr (u32 thread_index, u8 nat_event = QUOTA_EXCEEDED; u32 quota_event = clib_host_to_net_u32 (MAX_ENTRIES_PER_USER); u16 template_id; + ipfix_exporter_t *exp = pool_elt_at_index (frm->exporters, 0); now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3); now += silm->milisecond_time_0; @@ -838,8 +815,8 @@ nat_ipfix_logging_max_entries_per_usr (u32 thread_index, b0->current_length += MAX_ENTRIES_PER_USER_LEN; } - if (PREDICT_FALSE - (do_flush || (offset + MAX_ENTRIES_PER_USER_LEN) > frm->path_mtu)) + if (PREDICT_FALSE (do_flush || + (offset + MAX_ENTRIES_PER_USER_LEN) > exp->path_mtu)) { template_id = clib_atomic_fetch_or ( &silm->max_entries_per_user_template_id, @@ -867,6 +844,7 @@ nat_ipfix_logging_max_ses (u32 thread_index, u32 limit, int do_flush) u8 nat_event = QUOTA_EXCEEDED; u32 quota_event = clib_host_to_net_u32 (MAX_SESSION_ENTRIES); u16 template_id; + ipfix_exporter_t *exp = pool_elt_at_index (frm->exporters, 0); now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3); now += silm->milisecond_time_0; @@ -926,8 +904,7 @@ nat_ipfix_logging_max_ses (u32 thread_index, u32 limit, int do_flush) b0->current_length += MAX_SESSIONS_LEN; } - if (PREDICT_FALSE - (do_flush || (offset + MAX_SESSIONS_LEN) > frm->path_mtu)) + if (PREDICT_FALSE (do_flush || (offset + MAX_SESSIONS_LEN) > exp->path_mtu)) { template_id = clib_atomic_fetch_or ( &silm->max_sessions_template_id, @@ -955,6 +932,7 @@ nat_ipfix_logging_max_bib (u32 thread_index, u32 limit, int do_flush) u8 nat_event = QUOTA_EXCEEDED; u32 quota_event = clib_host_to_net_u32 (MAX_BIB_ENTRIES); u16 template_id; + ipfix_exporter_t *exp = pool_elt_at_index (frm->exporters, 0); now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3); now += silm->milisecond_time_0; @@ -1014,8 +992,7 @@ nat_ipfix_logging_max_bib (u32 thread_index, u32 limit, int do_flush) b0->current_length += MAX_BIBS_LEN; } - if (PREDICT_FALSE - (do_flush || (offset + MAX_BIBS_LEN) > frm->path_mtu)) + if (PREDICT_FALSE (do_flush || (offset + MAX_BIBS_LEN) > exp->path_mtu)) { template_id = clib_atomic_fetch_or ( &silm->max_bibs_template_id, @@ -1044,6 +1021,7 @@ nat_ipfix_logging_nat64_bibe (u32 thread_index, u8 nat_event, vlib_main_t *vm = vlib_get_main (); u64 now; u16 template_id; + ipfix_exporter_t *exp = pool_elt_at_index (frm->exporters, 0); now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3); now += silm->milisecond_time_0; @@ -1115,8 +1093,7 @@ nat_ipfix_logging_nat64_bibe (u32 thread_index, u8 nat_event, b0->current_length += NAT64_BIB_LEN; } - if (PREDICT_FALSE - (do_flush || (offset + NAT64_BIB_LEN) > frm->path_mtu)) + if (PREDICT_FALSE (do_flush || (offset + NAT64_BIB_LEN) > exp->path_mtu)) { template_id = clib_atomic_fetch_or ( &silm->nat64_bib_template_id, @@ -1147,6 +1124,7 @@ nat_ipfix_logging_nat64_ses (u32 thread_index, u8 nat_event, vlib_main_t *vm = vlib_get_main (); u64 now; u16 template_id; + ipfix_exporter_t *exp = pool_elt_at_index (frm->exporters, 0); now = (u64) ((vlib_time_now (vm) - silm->vlib_time_0) * 1e3); now += silm->milisecond_time_0; @@ -1230,8 +1208,7 @@ nat_ipfix_logging_nat64_ses (u32 thread_index, u8 nat_event, b0->current_length += NAT64_SES_LEN; } - if (PREDICT_FALSE - (do_flush || (offset + NAT64_SES_LEN) > frm->path_mtu)) + if (PREDICT_FALSE (do_flush || (offset + NAT64_SES_LEN) > exp->path_mtu)) { template_id = clib_atomic_fetch_or ( &silm->nat64_ses_template_id, @@ -1342,9 +1319,23 @@ nat_ipfix_logging_nat44_ses_delete (u32 thread_index, u32 src_ip, void nat_ipfix_logging_addresses_exhausted (u32 thread_index, u32 pool_id) { - //TODO: This event SHOULD be rate limited + nat_ipfix_logging_main_t *silm = &nat_ipfix_logging_main; + static f64 *last_sent = 0; + skip_if_disabled (); + /* TODO: make rate configurable, use 1pps so far */ + clib_spinlock_lock_if_init (&silm->addr_exhausted_lock); + f64 now = vlib_time_now (vlib_get_main ()); + vec_validate (last_sent, pool_id); + if (now < last_sent[pool_id] + 1.0) + { + clib_spinlock_unlock_if_init (&silm->addr_exhausted_lock); + return; + } + last_sent[pool_id] = now; + clib_spinlock_unlock_if_init (&silm->addr_exhausted_lock); + nat_ipfix_logging_addr_exhausted (thread_index, pool_id, 0); } @@ -1385,9 +1376,22 @@ deterministic_nat_data_callback void nat_ipfix_logging_max_sessions (u32 thread_index, u32 limit) { - //TODO: This event SHOULD be rate limited + nat_ipfix_logging_main_t *silm = &nat_ipfix_logging_main; + static f64 last_sent = 0; + skip_if_disabled (); + /* TODO: make rate configurable, use 1pps so far */ + clib_spinlock_lock_if_init (&silm->max_sessions_lock); + f64 now = vlib_time_now (vlib_get_main ()); + if (now < last_sent + 1.0) + { + clib_spinlock_unlock_if_init (&silm->max_sessions_lock); + return; + } + last_sent = now; + clib_spinlock_unlock_if_init (&silm->max_sessions_lock); + nat_ipfix_logging_max_ses (thread_index, limit, 0); } @@ -1400,9 +1404,22 @@ nat_ipfix_logging_max_sessions (u32 thread_index, u32 limit) void nat_ipfix_logging_max_bibs (u32 thread_index, u32 limit) { - //TODO: This event SHOULD be rate limited + nat_ipfix_logging_main_t *silm = &nat_ipfix_logging_main; + static f64 last_sent = 0; + skip_if_disabled (); + /* TODO: make rate configurable, use 1pps so far */ + clib_spinlock_lock_if_init (&silm->max_bibs_lock); + f64 now = vlib_time_now (vlib_get_main ()); + if (now < last_sent + 1.0) + { + clib_spinlock_unlock_if_init (&silm->max_bibs_lock); + return; + } + last_sent = now; + clib_spinlock_unlock_if_init (&silm->max_bibs_lock); + nat_ipfix_logging_max_bib (thread_index, limit, 0); } @@ -1473,12 +1490,13 @@ nat_ipfix_logging_nat64_session (u32 thread_index, } vlib_frame_t * -data_callback (flow_report_main_t * frm, flow_report_t * fr, - vlib_frame_t * f, u32 * to_next, u32 node_index) +data_callback (flow_report_main_t *frm, ipfix_exporter_t *exp, + flow_report_t *fr, vlib_frame_t *f, u32 *to_next, + u32 node_index) { nat_ipfix_logging_main_t *silm = &nat_ipfix_logging_main; - if (PREDICT_FALSE (++silm->call_counter >= vec_len (frm->reports))) + if (PREDICT_FALSE (++silm->call_counter >= vec_len (exp->reports))) { nat_ipfix_flush_from_main(); silm->call_counter = 0; @@ -1500,7 +1518,7 @@ int nat_ipfix_logging_enable_disable (int enable, u32 domain_id, u16 src_port) { nat_ipfix_logging_main_t *silm = &nat_ipfix_logging_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 a; int rv; u8 e = enable ? 1 : 0; @@ -1515,7 +1533,7 @@ nat_ipfix_logging_enable_disable (int enable, u32 domain_id, u16 src_port) a.flow_data_callback = data_callback; a.rewrite_callback = nat_template_rewrite_nat44_session; - rv = vnet_flow_report_add_del (frm, &a, NULL); + rv = vnet_flow_report_add_del (exp, &a, NULL); if (rv) { //nat_elog_warn_X1 ("vnet_flow_report_add_del returned %d", "i4", rv); @@ -1523,7 +1541,7 @@ nat_ipfix_logging_enable_disable (int enable, u32 domain_id, u16 src_port) } a.rewrite_callback = nat_template_rewrite_addr_exhausted; - rv = vnet_flow_report_add_del (frm, &a, NULL); + rv = vnet_flow_report_add_del (exp, &a, NULL); if (rv) { //nat_elog_warn_X1 ("vnet_flow_report_add_del returned %d", "i4", rv); @@ -1531,7 +1549,7 @@ nat_ipfix_logging_enable_disable (int enable, u32 domain_id, u16 src_port) } a.rewrite_callback = nat_template_rewrite_max_sessions; - rv = vnet_flow_report_add_del (frm, &a, NULL); + rv = vnet_flow_report_add_del (exp, &a, NULL); if (rv) { //nat_elog_warn_X1 ("vnet_flow_report_add_del returned %d", "i4", rv); @@ -1539,7 +1557,7 @@ nat_ipfix_logging_enable_disable (int enable, u32 domain_id, u16 src_port) } a.rewrite_callback = nat_template_rewrite_max_bibs; - rv = vnet_flow_report_add_del (frm, &a, NULL); + rv = vnet_flow_report_add_del (exp, &a, NULL); if (rv) { //nat_elog_warn_X1 ("vnet_flow_report_add_del returned %d", "i4", rv); @@ -1547,7 +1565,7 @@ nat_ipfix_logging_enable_disable (int enable, u32 domain_id, u16 src_port) } a.rewrite_callback = nat_template_rewrite_nat64_bib; - rv = vnet_flow_report_add_del (frm, &a, NULL); + rv = vnet_flow_report_add_del (exp, &a, NULL); if (rv) { //nat_elog_warn_X1 ("vnet_flow_report_add_del returned %d", "i4", rv); @@ -1555,7 +1573,7 @@ nat_ipfix_logging_enable_disable (int enable, u32 domain_id, u16 src_port) } a.rewrite_callback = nat_template_rewrite_nat64_session; - rv = vnet_flow_report_add_del (frm, &a, NULL); + rv = vnet_flow_report_add_del (exp, &a, NULL); if (rv) { //nat_elog_warn_X1 ("vnet_flow_report_add_del returned %d", "i4", rv); @@ -1565,7 +1583,7 @@ nat_ipfix_logging_enable_disable (int enable, u32 domain_id, u16 src_port) // if endpoint dependent per user max entries is also required /* a.rewrite_callback = nat_template_rewrite_max_entries_per_usr; - rv = vnet_flow_report_add_del (frm, &a, NULL); + rv = vnet_flow_report_add_del (exp, &a, NULL); if (rv) { //nat_elog_warn_X1 ("vnet_flow_report_add_del returned %d", "i4", rv); @@ -1596,6 +1614,11 @@ nat_ipfix_logging_init (vlib_main_t * vm) silm->milisecond_time_0 = unix_time_now_nsec () * 1e-6; vec_validate (silm->per_thread_data, tm->n_vlib_mains - 1); + + /* Set up rate-limit */ + clib_spinlock_init (&silm->addr_exhausted_lock); + clib_spinlock_init (&silm->max_sessions_lock); + clib_spinlock_init (&silm->max_bibs_lock); } static uword @@ -1607,11 +1630,9 @@ ipfix_flush_process (vlib_main_t *vm, return 0; } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (nat_ipfix_flush_node) = { .function = ipfix_flush_process, .name = "nat-ipfix-flush", .type = VLIB_NODE_TYPE_INPUT, .state = VLIB_NODE_STATE_INTERRUPT, }; -/* *INDENT-ON* */ diff --git a/src/plugins/nat/lib/ipfix_logging.h b/src/plugins/nat/lib/ipfix_logging.h index 0b8f568e1b1..dc7927a160c 100644 --- a/src/plugins/nat/lib/ipfix_logging.h +++ b/src/plugins/nat/lib/ipfix_logging.h @@ -108,6 +108,10 @@ typedef struct { /** nat data callbacks call counter */ u16 call_counter; + /** rate-limit locks */ + clib_spinlock_t addr_exhausted_lock; + clib_spinlock_t max_sessions_lock; + clib_spinlock_t max_bibs_lock; } nat_ipfix_logging_main_t; extern nat_ipfix_logging_main_t nat_ipfix_logging_main; diff --git a/src/plugins/nat/lib/lib.h b/src/plugins/nat/lib/lib.h index cea9ed71c8c..dc2c43beaaf 100644 --- a/src/plugins/nat/lib/lib.h +++ b/src/plugins/nat/lib/lib.h @@ -21,6 +21,17 @@ #include <vlibapi/api.h> +typedef struct +{ + u16 identifier; + u16 sequence; +} nat_icmp_echo_header_t; + +typedef struct +{ + u16 src_port, dst_port; +} nat_tcp_udp_header_t; + /* NAT API Configuration flags */ #define foreach_nat_config_flag \ _(0x01, IS_TWICE_NAT) \ diff --git a/src/plugins/nat/lib/log.h b/src/plugins/nat/lib/log.h index 26bd93f2589..a82028ed8bf 100644 --- a/src/plugins/nat/lib/log.h +++ b/src/plugins/nat/lib/log.h @@ -21,20 +21,7 @@ #include <vppinfra/elog.h> -#define foreach_nat_log_level \ - _ (0x00, LOG_NONE) \ - _ (0x01, LOG_ERROR) \ - _ (0x02, LOG_WARNING) \ - _ (0x03, LOG_NOTICE) \ - _ (0x04, LOG_INFO) \ - _ (0x05, LOG_DEBUG) - -typedef enum nat_log_level_t_ -{ -#define _(n, f) NAT_##f = n, - foreach_nat_log_level -#undef _ -} nat_log_level_t; +#include <nat/lib/nat_types.api_types.h> #define nat_elog(_pm, _level, _str) \ do \ diff --git a/src/plugins/nat/lib/nat_proto.h b/src/plugins/nat/lib/nat_proto.h index 9b20d9a71d1..4b57b994e22 100644 --- a/src/plugins/nat/lib/nat_proto.h +++ b/src/plugins/nat/lib/nat_proto.h @@ -28,6 +28,7 @@ typedef enum #define _(N, i, n, s) NAT_PROTOCOL_##N = i, foreach_nat_protocol #undef _ + NAT_N_PROTOCOLS } nat_protocol_t; always_inline nat_protocol_t |