nat: api,cli and test update & cleanup
[vpp.git] / src / plugins / nat / nat44 / 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  * @brief The NAT44 inline functions
17  */
18
19 #ifndef included_nat44_inlines_h__
20 #define included_nat44_inlines_h__
21
22 #include <vnet/fib/ip4_fib.h>
23 #include <nat/nat.h>
24
25 static_always_inline u8
26 nat44_maximum_sessions_exceeded (snat_main_t * sm, u32 thread_index)
27 {
28   if (pool_elts (sm->per_thread_data[thread_index].sessions) >=
29       sm->max_translations_per_thread)
30     return 1;
31   return 0;
32 }
33
34 static_always_inline u8
35 nat44_ed_maximum_sessions_exceeded (snat_main_t * sm,
36                                     u32 fib_index, u32 thread_index)
37 {
38   u32 translations;
39   translations = pool_elts (sm->per_thread_data[thread_index].sessions);
40   if (vec_len (sm->max_translations_per_fib) <= fib_index)
41     fib_index = 0;
42   return translations >= sm->max_translations_per_fib[fib_index];
43 }
44
45 #endif /* included_nat44_inlines_h__ */
46
47 /*
48  * fd.io coding-style-patch-verification: ON
49  *
50  * Local Variables:
51  * eval: (c-set-style "gnu")
52  * End:
53  */