nat: remove unused code
[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 static_always_inline void
46 nat44_user_del_sessions (snat_user_t * u, u32 thread_index)
47 {
48   dlist_elt_t *elt;
49   snat_session_t *s;
50
51   snat_main_t *sm = &snat_main;
52   snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
53
54   // get head
55   elt = pool_elt_at_index (tsm->list_pool,
56                            u->sessions_per_user_list_head_index);
57   // get first element
58   elt = pool_elt_at_index (tsm->list_pool, elt->next);
59
60   while (elt->value != ~0)
61     {
62       s = pool_elt_at_index (tsm->sessions, elt->value);
63       elt = pool_elt_at_index (tsm->list_pool, elt->next);
64
65       nat44_free_session_data (sm, s, thread_index, 0);
66       nat44_delete_session (sm, s, thread_index);
67     }
68 }
69
70 static_always_inline int
71 nat44_user_del (ip4_address_t * addr, u32 fib_index)
72 {
73   int rv = 1;
74
75   snat_main_t *sm = &snat_main;
76   snat_main_per_thread_data_t *tsm;
77
78   snat_user_key_t user_key;
79   clib_bihash_kv_8_8_t kv, value;
80
81   if (sm->endpoint_dependent)
82     return rv;
83
84   user_key.addr.as_u32 = addr->as_u32;
85   user_key.fib_index = fib_index;
86   kv.key = user_key.as_u64;
87
88   if (sm->num_workers > 1)
89     {
90       /* *INDENT-OFF* */
91       vec_foreach (tsm, sm->per_thread_data)
92         {
93           if (!clib_bihash_search_8_8 (&tsm->user_hash, &kv, &value))
94             {
95               nat44_user_del_sessions (
96                   pool_elt_at_index (tsm->users, value.value),
97                   tsm->thread_index);
98               rv = 0;
99               break;
100             }
101         }
102       /* *INDENT-ON* */
103     }
104   else
105     {
106       tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
107       if (!clib_bihash_search_8_8 (&tsm->user_hash, &kv, &value))
108         {
109           nat44_user_del_sessions (pool_elt_at_index
110                                    (tsm->users, value.value),
111                                    tsm->thread_index);
112           rv = 0;
113         }
114     }
115   return rv;
116 }
117
118 #endif /* included_nat44_inlines_h__ */
119
120 /*
121  * fd.io coding-style-patch-verification: ON
122  *
123  * Local Variables:
124  * eval: (c-set-style "gnu")
125  * End:
126  */