misc: remove GNU Indent directives
[vpp.git] / src / plugins / nat / dslite / dslite.h
1 /*
2  * Copyright (c) 2017 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 #ifndef __included_dslite_h__
16 #define __included_dslite_h__
17
18 #include <vppinfra/dlist.h>
19 #include <vppinfra/bihash_8_8.h>
20 #include <vppinfra/bihash_16_8.h>
21 #include <vppinfra/bihash_24_8.h>
22
23 #include <nat/lib/lib.h>
24 #include <nat/lib/alloc.h>
25 #include <nat/lib/inlines.h>
26
27 typedef struct
28 {
29   u16 identifier;
30   u16 sequence;
31 } echo_header_t;
32
33 /* session key (4-tuple) */
34 typedef struct
35 {
36   union
37   {
38     struct
39     {
40       ip4_address_t addr;
41       u16 port;
42       u16 protocol:3, fib_index:13;
43     };
44     u64 as_u64;
45   };
46 } nat_session_key_t;
47
48 typedef struct
49 {
50   union
51   {
52     struct
53     {
54       ip6_address_t softwire_id;
55       ip4_address_t addr;
56       u16 port;
57       u8 proto;
58       u8 pad;
59     };
60     u64 as_u64[3];
61   };
62 } dslite_session_key_t;
63
64 typedef CLIB_PACKED (struct
65 {
66   nat_session_key_t out2in;
67   dslite_session_key_t in2out;
68   u32 per_b4_index;
69   u32 per_b4_list_head_index;
70   f64 last_heard;
71   u64 total_bytes;
72   u32 total_pkts;
73 }) dslite_session_t;
74
75 typedef struct
76 {
77   ip6_address_t addr;
78   u32 sessions_per_b4_list_head_index;
79   u32 nsessions;
80 } dslite_b4_t;
81
82 typedef struct
83 {
84   /* Main lookup tables */
85   clib_bihash_8_8_t out2in;
86   clib_bihash_24_8_t in2out;
87
88   /* Find a B4 */
89   clib_bihash_16_8_t b4_hash;
90
91   /* B4 pool */
92   dslite_b4_t *b4s;
93
94   /* Session pool */
95   dslite_session_t *sessions;
96
97   /* Pool of doubly-linked list elements */
98   dlist_elt_t *list_pool;
99 } dslite_per_thread_data_t;
100
101 typedef struct
102 {
103   ip6_address_t aftr_ip6_addr;
104   ip4_address_t aftr_ip4_addr;
105   ip6_address_t b4_ip6_addr;
106   ip4_address_t b4_ip4_addr;
107   dslite_per_thread_data_t *per_thread_data;
108   u32 num_workers;
109   u32 first_worker_index;
110   u16 port_per_thread;
111
112   /* nat address pool */
113   nat_ip4_pool_t pool;
114
115   /* counters/gauges */
116   vlib_simple_counter_main_t total_b4s;
117   vlib_simple_counter_main_t total_sessions;
118
119   /* node index */
120   u32 dslite_in2out_node_index;
121   u32 dslite_in2out_slowpath_node_index;
122   u32 dslite_out2in_node_index;
123
124   /* If set then the DSLite component behaves as CPE/B4
125    * otherwise it behaves as AFTR */
126   u8 is_ce;
127
128   u8 is_enabled;
129   u16 msg_id_base;
130 } dslite_main_t;
131
132 typedef struct
133 {
134   u32 next_index;
135   u32 session_index;
136 } dslite_trace_t;
137
138 typedef struct
139 {
140   u32 next_index;
141 } dslite_ce_trace_t;
142
143 #define foreach_dslite_error                    \
144 _(IN2OUT, "valid in2out DS-Lite packets")       \
145 _(OUT2IN, "valid out2in DS-Lite packets")       \
146 _(CE_ENCAP, "valid CE encap DS-Lite packets")   \
147 _(CE_DECAP, "valid CE decap DS-Lite packets")   \
148 _(NO_TRANSLATION, "no translation")             \
149 _(BAD_IP6_PROTOCOL, "bad ip6 protocol")         \
150 _(OUT_OF_PORTS, "out of ports")                 \
151 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \
152 _(BAD_ICMP_TYPE, "unsupported icmp type")       \
153 _(UNKNOWN, "unknown")
154
155 typedef enum
156 {
157 #define _(sym,str) DSLITE_ERROR_##sym,
158   foreach_dslite_error
159 #undef _
160     DSLITE_N_ERROR,
161 } dslite_error_t;
162
163 extern dslite_main_t dslite_main;
164 extern vlib_node_registration_t dslite_in2out_node;
165 extern vlib_node_registration_t dslite_in2out_slowpath_node;
166 extern vlib_node_registration_t dslite_out2in_node;
167 extern vlib_node_registration_t dslite_ce_encap_node;
168 extern vlib_node_registration_t dslite_ce_decap_node;
169
170 void dslite_set_ce (dslite_main_t * dm, u8 set);
171 int dslite_set_aftr_ip6_addr (dslite_main_t * dm, ip6_address_t * addr);
172 int dslite_set_b4_ip6_addr (dslite_main_t * dm, ip6_address_t * addr);
173 int dslite_set_aftr_ip4_addr (dslite_main_t * dm, ip4_address_t * addr);
174 int dslite_set_b4_ip4_addr (dslite_main_t * dm, ip4_address_t * addr);
175 int dslite_add_del_pool_addr (dslite_main_t * dm, ip4_address_t * addr,
176                               u8 is_add);
177 u8 *format_dslite_trace (u8 * s, va_list * args);
178 u8 *format_dslite_ce_trace (u8 * s, va_list * args);
179
180 #endif /* __included_dslite_h__ */
181
182 /*
183  * fd.io coding-style-patch-verification: ON
184  *
185  * Local Variables:
186  * eval: (c-set-style "gnu")
187  * End:
188  */