X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnat%2Fnat_inlines.h;h=ae8ed7fb165ed91936bb5a05b52f182225e29160;hb=e6e09a4acef2c38bc31e89c05bd1f40f1829debb;hp=c0f1672117397c747ff990a630b50685ecf1cb09;hpb=178cf493d009995b28fdf220f04c98860ff79a9b;p=vpp.git diff --git a/src/plugins/nat/nat_inlines.h b/src/plugins/nat/nat_inlines.h index c0f16721173..ae8ed7fb165 100644 --- a/src/plugins/nat/nat_inlines.h +++ b/src/plugins/nat/nat_inlines.h @@ -21,6 +21,7 @@ #include #include +#include always_inline u32 ip_proto_to_snat_proto (u8 ip_proto) @@ -159,6 +160,8 @@ nat44_delete_user_with_no_session (snat_main_t * sm, snat_user_t * u, pool_put_index (tsm->list_pool, u->sessions_per_user_list_head_index); pool_put (tsm->users, u); clib_bihash_add_del_8_8 (&tsm->user_hash, &kv, 0); + vlib_set_simple_counter (&sm->total_users, thread_index, 0, + pool_elts (tsm->users)); } } @@ -172,11 +175,11 @@ nat44_delete_session (snat_main_t * sm, snat_session_t * ses, snat_user_key_t u_key; snat_user_t *u; - nat_log_debug ("session deleted %U", format_snat_session, tsm, ses); - clib_dlist_remove (tsm->list_pool, ses->per_user_index); pool_put_index (tsm->list_pool, ses->per_user_index); pool_put (tsm->sessions, ses); + vlib_set_simple_counter (&sm->total_sessions, thread_index, 0, + pool_elts (tsm->sessions)); u_key.addr = ses->in2out.addr; u_key.fib_index = ses->in2out.fib_index; @@ -200,6 +203,10 @@ always_inline int nat44_set_tcp_session_state_i2o (snat_main_t * sm, snat_session_t * ses, tcp_header_t * tcp, u32 thread_index) { + if ((ses->state == 0) && (tcp->flags & TCP_FLAG_RST)) + ses->state = NAT44_SES_RST; + if ((ses->state == NAT44_SES_RST) && !(tcp->flags & TCP_FLAG_RST)) + ses->state = 0; if ((tcp->flags & TCP_FLAG_ACK) && (ses->state & NAT44_SES_I2O_SYN) && (ses->state & NAT44_SES_O2I_SYN)) ses->state = 0; @@ -215,11 +222,10 @@ nat44_set_tcp_session_state_i2o (snat_main_t * sm, snat_session_t * ses, if (clib_net_to_host_u32 (tcp->ack_number) > ses->o2i_fin_seq) ses->state |= NAT44_SES_O2I_FIN_ACK; } - if (nat44_is_ses_closed (ses)) + if (nat44_is_ses_closed (ses) + && !(ses->flags & SNAT_SESSION_FLAG_OUTPUT_FEATURE)) { - nat_log_debug ("TCP close connection %U", format_snat_session, - &sm->per_thread_data[thread_index], ses); - nat_free_session_data (sm, ses, thread_index); + nat_free_session_data (sm, ses, thread_index, 0); nat44_delete_session (sm, ses, thread_index); return 1; } @@ -230,6 +236,10 @@ always_inline int nat44_set_tcp_session_state_o2i (snat_main_t * sm, snat_session_t * ses, tcp_header_t * tcp, u32 thread_index) { + if ((ses->state == 0) && (tcp->flags & TCP_FLAG_RST)) + ses->state = NAT44_SES_RST; + if ((ses->state == NAT44_SES_RST) && !(tcp->flags & TCP_FLAG_RST)) + ses->state = 0; if ((tcp->flags & TCP_FLAG_ACK) && (ses->state & NAT44_SES_I2O_SYN) && (ses->state & NAT44_SES_O2I_SYN)) ses->state = 0; @@ -247,9 +257,7 @@ nat44_set_tcp_session_state_o2i (snat_main_t * sm, snat_session_t * ses, } if (nat44_is_ses_closed (ses)) { - nat_log_debug ("TCP close connection %U", format_snat_session, - &sm->per_thread_data[thread_index], ses); - nat_free_session_data (sm, ses, thread_index); + nat_free_session_data (sm, ses, thread_index, 0); nat44_delete_session (sm, ses, thread_index); return 1; } @@ -280,11 +288,16 @@ nat44_session_get_timeout (snat_main_t * sm, snat_session_t * s) } always_inline void -nat44_session_update_counters (snat_session_t * s, f64 now, uword bytes) +nat44_session_update_counters (snat_session_t * s, f64 now, uword bytes, + u32 thread_index) { s->last_heard = now; s->total_pkts++; s->total_bytes += bytes; + nat_ha_sref (&s->out2in.addr, s->out2in.port, &s->ext_host_addr, + s->ext_host_port, s->out2in.protocol, s->out2in.fib_index, + s->total_pkts, s->total_bytes, thread_index, + &s->ha_last_refreshed, now); } /** \brief Per-user LRU list maintenance */