f7089ea0c2180cc9ff19b4d46956fe1550ec9621
[vpp.git] / src / plugins / nat / nat44-ei / nat44_ei_inlines.h
1 /*
2  * Copyright (c) 2020 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef __included_nat44_ei_inlines_h__
17 #define __included_nat44_ei_inlines_h__
18
19 #include <nat/nat44-ei/nat44_ei_ha.h>
20
21 static_always_inline u8
22 nat44_ei_maximum_sessions_exceeded (snat_main_t *sm, u32 thread_index)
23 {
24   if (pool_elts (sm->per_thread_data[thread_index].sessions) >=
25       sm->max_translations_per_thread)
26     return 1;
27   return 0;
28 }
29
30 always_inline void
31 nat44_ei_session_update_counters (snat_session_t *s, f64 now, uword bytes,
32                                   u32 thread_index)
33 {
34   s->last_heard = now;
35   s->total_pkts++;
36   s->total_bytes += bytes;
37   nat_ha_sref (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
38                s->ext_host_port, s->nat_proto, s->out2in.fib_index,
39                s->total_pkts, s->total_bytes, thread_index,
40                &s->ha_last_refreshed, now);
41 }
42
43 #endif /* __included_nat44_ei_inlines_h__ */
44
45 /*
46  * fd.io coding-style-patch-verification: ON
47  *
48  * Local Variables:
49  * eval: (c-set-style "gnu")
50  * End:
51  */