FD.io VPP  v19.08.1-401-g8e4ed521a
Vector Packet Processing
nat_inlines.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 NAT inline functions
17  */
18 
19 #ifndef __included_nat_inlines_h__
20 #define __included_nat_inlines_h__
21 
22 #include <vnet/fib/ip4_fib.h>
23 #include <nat/nat.h>
24 #include <nat/nat_ha.h>
25 
28 {
29  u32 snat_proto = ~0;
30 
31  snat_proto = (ip_proto == IP_PROTOCOL_UDP) ? SNAT_PROTOCOL_UDP : snat_proto;
32  snat_proto = (ip_proto == IP_PROTOCOL_TCP) ? SNAT_PROTOCOL_TCP : snat_proto;
33  snat_proto =
34  (ip_proto == IP_PROTOCOL_ICMP) ? SNAT_PROTOCOL_ICMP : snat_proto;
35  snat_proto =
36  (ip_proto == IP_PROTOCOL_ICMP6) ? SNAT_PROTOCOL_ICMP : snat_proto;
37 
38  return snat_proto;
39 }
40 
43 {
44  u8 ip_proto = ~0;
45 
46  ip_proto = (snat_proto == SNAT_PROTOCOL_UDP) ? IP_PROTOCOL_UDP : ip_proto;
47  ip_proto = (snat_proto == SNAT_PROTOCOL_TCP) ? IP_PROTOCOL_TCP : ip_proto;
48  ip_proto = (snat_proto == SNAT_PROTOCOL_ICMP) ? IP_PROTOCOL_ICMP : ip_proto;
49 
50  return ip_proto;
51 }
52 
54 icmp_is_error_message (icmp46_header_t * icmp)
55 {
56  switch (icmp->type)
57  {
58  case ICMP4_destination_unreachable:
59  case ICMP4_time_exceeded:
60  case ICMP4_parameter_problem:
61  case ICMP4_source_quench:
62  case ICMP4_redirect:
63  case ICMP4_alternate_host_address:
64  return 1;
65  }
66  return 0;
67 }
68 
71  u32 sw_if_index0, u32 ip4_addr)
72 {
74  ip4_address_t *first_int_addr;
75 
76  if (PREDICT_FALSE (rt->cached_sw_if_index != sw_if_index0))
77  {
78  first_int_addr =
79  ip4_interface_first_address (sm->ip4_main, sw_if_index0,
80  0 /* just want the address */ );
81  rt->cached_sw_if_index = sw_if_index0;
82  if (first_int_addr)
83  rt->cached_ip4_address = first_int_addr->as_u32;
84  else
85  rt->cached_ip4_address = 0;
86  }
87 
88  if (PREDICT_FALSE (ip4_addr == rt->cached_ip4_address))
89  return 1;
90  else
91  return 0;
92 }
93 
96 {
97  if (pool_elts (sm->per_thread_data[thread_index].sessions) >=
98  sm->max_translations)
99  return 1;
100 
101  return 0;
102 }
103 
104 always_inline void
106  vlib_node_runtime_t * node, vlib_error_t * error,
107  u32 next)
108 {
109  u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
110 
111  from = bi_vector;
112  n_left_from = vec_len (bi_vector);
113  next_index = node->cached_next_index;
114  while (n_left_from > 0)
115  {
116  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
117  while (n_left_from > 0 && n_left_to_next > 0)
118  {
119  u32 bi0 = to_next[0] = from[0];
120  from += 1;
121  n_left_from -= 1;
122  to_next += 1;
123  n_left_to_next -= 1;
124  vlib_buffer_t *p0 = vlib_get_buffer (vm, bi0);
125  if (error)
126  p0->error = *error;
127  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
128  n_left_to_next, bi0, next);
129  }
130  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
131  }
132 }
133 
134 always_inline void
136 {
138  {
139  if (is_static)
140  u->nstaticsessions++;
141  else
142  u->nsessions++;
143  }
144 }
145 
146 always_inline void
148  u32 thread_index)
149 {
151  snat_user_key_t u_key;
153  thread_index);
154 
155  if (u->nstaticsessions == 0 && u->nsessions == 0)
156  {
157  u_key.addr.as_u32 = u->addr.as_u32;
158  u_key.fib_index = u->fib_index;
159  kv.key = u_key.as_u64;
161  pool_put (tsm->users, u);
162  clib_bihash_add_del_8_8 (&tsm->user_hash, &kv, 0);
163  vlib_set_simple_counter (&sm->total_users, thread_index, 0,
164  pool_elts (tsm->users));
165  }
166 }
167 
168 always_inline void
169 nat44_delete_session (snat_main_t * sm, snat_session_t * ses,
170  u32 thread_index)
171 {
173  thread_index);
175  snat_user_t *u;
176  const snat_user_key_t u_key = {
177  .addr = ses->in2out.addr,
178  .fib_index = ses->in2out.fib_index
179  };
180  const u8 u_static = snat_is_session_static (ses);
181 
182  clib_dlist_remove (tsm->list_pool, ses->per_user_index);
183  pool_put_index (tsm->list_pool, ses->per_user_index);
184  pool_put (tsm->sessions, ses);
185  vlib_set_simple_counter (&sm->total_sessions, thread_index, 0,
186  pool_elts (tsm->sessions));
187 
188  kv.key = u_key.as_u64;
189  if (!clib_bihash_search_8_8 (&tsm->user_hash, &kv, &value))
190  {
191  u = pool_elt_at_index (tsm->users, value.value);
192  if (u_static)
193  u->nstaticsessions--;
194  else
195  u->nsessions--;
196 
197  nat44_delete_user_with_no_session (sm, u, thread_index);
198  }
199 }
200 
201 /** \brief Set TCP session state.
202  @return 1 if session was closed, otherwise 0
203 */
204 always_inline int
205 nat44_set_tcp_session_state_i2o (snat_main_t * sm, snat_session_t * ses,
206  tcp_header_t * tcp, u32 thread_index)
207 {
208  if ((ses->state == 0) && (tcp->flags & TCP_FLAG_RST))
209  ses->state = NAT44_SES_RST;
210  if ((ses->state == NAT44_SES_RST) && !(tcp->flags & TCP_FLAG_RST))
211  ses->state = 0;
212  if ((tcp->flags & TCP_FLAG_ACK) && (ses->state & NAT44_SES_I2O_SYN) &&
213  (ses->state & NAT44_SES_O2I_SYN))
214  ses->state = 0;
215  if (tcp->flags & TCP_FLAG_SYN)
216  ses->state |= NAT44_SES_I2O_SYN;
217  if (tcp->flags & TCP_FLAG_FIN)
218  {
219  ses->i2o_fin_seq = clib_net_to_host_u32 (tcp->seq_number);
220  ses->state |= NAT44_SES_I2O_FIN;
221  }
222  if ((tcp->flags & TCP_FLAG_ACK) && (ses->state & NAT44_SES_O2I_FIN))
223  {
224  if (clib_net_to_host_u32 (tcp->ack_number) > ses->o2i_fin_seq)
225  ses->state |= NAT44_SES_O2I_FIN_ACK;
226  }
227  if (nat44_is_ses_closed (ses)
228  && !(ses->flags & SNAT_SESSION_FLAG_OUTPUT_FEATURE))
229  {
230  nat_free_session_data (sm, ses, thread_index, 0);
231  nat44_delete_session (sm, ses, thread_index);
232  return 1;
233  }
234  return 0;
235 }
236 
237 always_inline int
238 nat44_set_tcp_session_state_o2i (snat_main_t * sm, snat_session_t * ses,
239  tcp_header_t * tcp, u32 thread_index)
240 {
241  if ((ses->state == 0) && (tcp->flags & TCP_FLAG_RST))
242  ses->state = NAT44_SES_RST;
243  if ((ses->state == NAT44_SES_RST) && !(tcp->flags & TCP_FLAG_RST))
244  ses->state = 0;
245  if ((tcp->flags & TCP_FLAG_ACK) && (ses->state & NAT44_SES_I2O_SYN) &&
246  (ses->state & NAT44_SES_O2I_SYN))
247  ses->state = 0;
248  if (tcp->flags & TCP_FLAG_SYN)
249  ses->state |= NAT44_SES_O2I_SYN;
250  if (tcp->flags & TCP_FLAG_FIN)
251  {
252  ses->o2i_fin_seq = clib_net_to_host_u32 (tcp->seq_number);
253  ses->state |= NAT44_SES_O2I_FIN;
254  }
255  if ((tcp->flags & TCP_FLAG_ACK) && (ses->state & NAT44_SES_I2O_FIN))
256  {
257  if (clib_net_to_host_u32 (tcp->ack_number) > ses->i2o_fin_seq)
258  ses->state |= NAT44_SES_I2O_FIN_ACK;
259  }
260  if (nat44_is_ses_closed (ses))
261  {
262  nat_free_session_data (sm, ses, thread_index, 0);
263  nat44_delete_session (sm, ses, thread_index);
264  return 1;
265  }
266  return 0;
267 }
268 
270 nat44_session_get_timeout (snat_main_t * sm, snat_session_t * s)
271 {
272  switch (s->in2out.protocol)
273  {
274  case SNAT_PROTOCOL_ICMP:
275  return sm->icmp_timeout;
276  case SNAT_PROTOCOL_UDP:
277  return sm->udp_timeout;
278  case SNAT_PROTOCOL_TCP:
279  {
280  if (s->state)
281  return sm->tcp_transitory_timeout;
282  else
283  return sm->tcp_established_timeout;
284  }
285  default:
286  return sm->udp_timeout;
287  }
288 
289  return 0;
290 }
291 
292 always_inline void
293 nat44_session_update_counters (snat_session_t * s, f64 now, uword bytes,
294  u32 thread_index)
295 {
296  s->last_heard = now;
297  s->total_pkts++;
298  s->total_bytes += bytes;
299  nat_ha_sref (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
300  s->ext_host_port, s->out2in.protocol, s->out2in.fib_index,
301  s->total_pkts, s->total_bytes, thread_index,
302  &s->ha_last_refreshed, now);
303 }
304 
305 /** \brief Per-user LRU list maintenance */
306 always_inline void
307 nat44_session_update_lru (snat_main_t * sm, snat_session_t * s,
308  u32 thread_index)
309 {
310  clib_dlist_remove (sm->per_thread_data[thread_index].list_pool,
311  s->per_user_index);
312  clib_dlist_addtail (sm->per_thread_data[thread_index].list_pool,
313  s->per_user_list_head_index, s->per_user_index);
314 }
315 
316 always_inline void
318  ip4_address_t * r_addr, u8 proto, u32 fib_index, u16 l_port,
319  u16 r_port)
320 {
322 
323  key->l_addr.as_u32 = l_addr->as_u32;
324  key->r_addr.as_u32 = r_addr->as_u32;
325  key->fib_index = fib_index;
326  key->proto = proto;
327  key->l_port = l_port;
328  key->r_port = r_port;
329 
330  kv->value = ~0ULL;
331 }
332 
333 always_inline void
335  u32 fib_index, u16 port)
336 {
338 
339  key.addr.as_u32 = addr->as_u32;
340  key.port = port;
341  key.protocol = proto;
342  key.fib_index = fib_index;
343 
344  kv->key = key.as_u64;
345  kv->value = ~0ULL;
346 }
347 
350 {
351  icmp46_header_t *icmp0;
352  nat_ed_ses_key_t key0;
353  icmp_echo_header_t *echo0, *inner_echo0 = 0;
354  ip4_header_t *inner_ip0 = 0;
355  void *l4_header = 0;
356  icmp46_header_t *inner_icmp0;
357 
358  icmp0 = (icmp46_header_t *) ip4_next_header (ip0);
359  echo0 = (icmp_echo_header_t *) (icmp0 + 1);
360 
361  if (!icmp_is_error_message (icmp0))
362  {
363  key0.proto = IP_PROTOCOL_ICMP;
364  key0.l_addr = ip0->src_address;
365  key0.r_addr = ip0->dst_address;
366  key0.l_port = echo0->identifier;
367  key0.r_port = 0;
368  }
369  else
370  {
371  inner_ip0 = (ip4_header_t *) (echo0 + 1);
372  l4_header = ip4_next_header (inner_ip0);
373  key0.proto = inner_ip0->protocol;
374  key0.r_addr = inner_ip0->src_address;
375  key0.l_addr = inner_ip0->dst_address;
376  switch (ip_proto_to_snat_proto (inner_ip0->protocol))
377  {
378  case SNAT_PROTOCOL_ICMP:
379  inner_icmp0 = (icmp46_header_t *) l4_header;
380  inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1);
381  key0.r_port = 0;
382  key0.l_port = inner_echo0->identifier;
383  break;
384  case SNAT_PROTOCOL_UDP:
385  case SNAT_PROTOCOL_TCP:
386  key0.l_port = ((tcp_udp_header_t *) l4_header)->dst_port;
387  key0.r_port = ((tcp_udp_header_t *) l4_header)->src_port;
388  break;
389  default:
390  return NAT_IN2OUT_ED_ERROR_UNSUPPORTED_PROTOCOL;
391  }
392  }
393  *p_key0 = key0;
394  return 0;
395 }
396 
397 
400 {
401  icmp46_header_t *icmp0;
402  nat_ed_ses_key_t key0;
403  icmp_echo_header_t *echo0, *inner_echo0 = 0;
404  ip4_header_t *inner_ip0;
405  void *l4_header = 0;
406  icmp46_header_t *inner_icmp0;
407 
408  icmp0 = (icmp46_header_t *) ip4_next_header (ip0);
409  echo0 = (icmp_echo_header_t *) (icmp0 + 1);
410 
411  if (!icmp_is_error_message (icmp0))
412  {
413  key0.proto = IP_PROTOCOL_ICMP;
414  key0.l_addr = ip0->dst_address;
415  key0.r_addr = ip0->src_address;
416  key0.l_port = echo0->identifier;
417  key0.r_port = 0;
418  }
419  else
420  {
421  inner_ip0 = (ip4_header_t *) (echo0 + 1);
422  l4_header = ip4_next_header (inner_ip0);
423  key0.proto = inner_ip0->protocol;
424  key0.l_addr = inner_ip0->src_address;
425  key0.r_addr = inner_ip0->dst_address;
426  switch (ip_proto_to_snat_proto (inner_ip0->protocol))
427  {
428  case SNAT_PROTOCOL_ICMP:
429  inner_icmp0 = (icmp46_header_t *) l4_header;
430  inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1);
431  key0.l_port = inner_echo0->identifier;
432  key0.r_port = 0;
433  break;
434  case SNAT_PROTOCOL_UDP:
435  case SNAT_PROTOCOL_TCP:
436  key0.l_port = ((tcp_udp_header_t *) l4_header)->src_port;
437  key0.r_port = ((tcp_udp_header_t *) l4_header)->dst_port;
438  break;
439  default:
440  return -1;
441  }
442  }
443  *p_key0 = key0;
444  return 0;
445 }
446 
447 always_inline void
449 {
450  u8 *data;
451  u8 opt_len, opts_len, kind;
452  u16 mss;
453 
454  if (!(sm->mss_clamping && tcp_syn (tcp)))
455  return;
456 
457  opts_len = (tcp_doff (tcp) << 2) - sizeof (tcp_header_t);
458  data = (u8 *) (tcp + 1);
459  for (; opts_len > 0; opts_len -= opt_len, data += opt_len)
460  {
461  kind = data[0];
462 
463  if (kind == TCP_OPTION_EOL)
464  break;
465  else if (kind == TCP_OPTION_NOOP)
466  {
467  opt_len = 1;
468  continue;
469  }
470  else
471  {
472  if (opts_len < 2)
473  return;
474  opt_len = data[1];
475 
476  if (opt_len < 2 || opt_len > opts_len)
477  return;
478  }
479 
480  if (kind == TCP_OPTION_MSS)
481  {
482  mss = *(u16 *) (data + 2);
483  if (clib_net_to_host_u16 (mss) > sm->mss_clamping)
484  {
485  *sum =
486  ip_csum_update (*sum, mss, sm->mss_value_net, ip4_header_t,
487  length);
488  clib_memcpy_fast (data + 2, &sm->mss_value_net, 2);
489  }
490  return;
491  }
492  }
493 }
494 
495 /**
496  * @brief Check if packet should be translated
497  *
498  * Packets aimed at outside interface and external address with active session
499  * should be translated.
500  *
501  * @param sm NAT main
502  * @param rt NAT runtime data
503  * @param sw_if_index0 index of the inside interface
504  * @param ip0 IPv4 header
505  * @param proto0 NAT protocol
506  * @param rx_fib_index0 RX FIB index
507  *
508  * @returns 0 if packet should be translated otherwise 1
509  */
510 static inline int
512  u32 sw_if_index0, ip4_header_t * ip0, u32 proto0,
513  u32 rx_fib_index0)
514 {
515  if (sm->out2in_dpo)
516  return 0;
517 
519  nat_outside_fib_t *outside_fib;
520  fib_prefix_t pfx = {
522  .fp_len = 32,
523  .fp_addr = {
524  .ip4.as_u32 = ip0->dst_address.as_u32,
525  }
526  ,
527  };
528 
529  /* Don't NAT packet aimed at the intfc address */
530  if (PREDICT_FALSE (is_interface_addr (sm, node, sw_if_index0,
531  ip0->dst_address.as_u32)))
532  return 1;
533 
534  fei = fib_table_lookup (rx_fib_index0, &pfx);
535  if (FIB_NODE_INDEX_INVALID != fei)
536  {
538  if (sw_if_index == ~0)
539  {
540  vec_foreach (outside_fib, sm->outside_fibs)
541  {
542  fei = fib_table_lookup (outside_fib->fib_index, &pfx);
543  if (FIB_NODE_INDEX_INVALID != fei)
544  {
545  sw_if_index = fib_entry_get_resolving_interface (fei);
546  if (sw_if_index != ~0)
547  break;
548  }
549  }
550  }
551  if (sw_if_index == ~0)
552  return 1;
553 
555  pool_foreach (i, sm->interfaces, (
556  {
557  /* NAT packet aimed at outside interface */
558  if ((nat_interface_is_outside (i))
559  && (sw_if_index ==
560  i->sw_if_index)) return 0;}
561  ));
562  }
563 
564  return 1;
565 }
566 
567 #endif /* __included_nat_inlines_h__ */
568 
569 /*
570  * fd.io coding-style-patch-verification: ON
571  *
572  * Local Variables:
573  * eval: (c-set-style "gnu")
574  * End:
575  */
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
nat_outside_fib_t * outside_fibs
Definition: nat.h:555
#define snat_is_session_static(s)
Check if SNAT session is created from static mapping.
Definition: nat.h:709
u32 sessions_per_user_list_head_index
Definition: nat.h:312
End of options.
Definition: tcp_packet.h:104
#define NAT44_SES_I2O_FIN
Definition: nat.h:235
u32 icmp_timeout
Definition: nat.h:631
u8 runtime_data[0]
Function dependent node-runtime data.
Definition: node.h:523
ip4_address_t src_address
Definition: ip4_packet.h:170
static u32 nat44_session_get_timeout(snat_main_t *sm, snat_session_t *s)
Definition: nat_inlines.h:270
#define TCP_FLAG_SYN
Definition: fa_node.h:13
static_always_inline int get_icmp_i2o_ed_key(ip4_header_t *ip0, nat_ed_ses_key_t *p_key0)
Definition: nat_inlines.h:349
u32 nsessions
Definition: nat.h:313
static_always_inline u8 icmp_is_error_message(icmp46_header_t *icmp)
Definition: nat_inlines.h:54
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
Definition: ip4_forward.c:278
static void make_sm_kv(clib_bihash_kv_8_8_t *kv, ip4_address_t *addr, u8 proto, u32 fib_index, u16 port)
Definition: nat_inlines.h:334
#define tcp_doff(_th)
Definition: tcp_packet.h:78
void nat_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index, u8 is_ha)
Free NAT44 session data (lookup keys, external addrres port)
Definition: nat.c:179
u32 nstaticsessions
Definition: nat.h:314
u16 vlib_error_t
Definition: error.h:43
int i
uword ip_csum_t
Definition: ip_packet.h:219
u8 data[128]
Definition: ipsec.api:251
u32 fib_index
Definition: nat.h:311
#define nat44_is_ses_closed(s)
Check if NAT44 endpoint-dependent TCP session is closed.
Definition: nat.h:763
#define NAT44_SES_O2I_FIN
Definition: nat.h:236
No operation.
Definition: tcp_packet.h:105
dlist_elt_t * list_pool
Definition: nat.h:475
struct _tcp_header tcp_header_t
vhost_vring_addr_t addr
Definition: vhost_user.h:147
u32 proto
Definition: nat.h:70
unsigned char u8
Definition: types.h:56
static int nat44_set_tcp_session_state_o2i(snat_main_t *sm, snat_session_t *ses, tcp_header_t *tcp, u32 thread_index)
Definition: nat_inlines.h:238
u16 l_port
Definition: nat.h:71
double f64
Definition: types.h:142
clib_bihash_8_8_t user_hash
Definition: nat.h:466
u32 cached_sw_if_index
Definition: nat.h:665
void nat_ha_sref(ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index, u32 total_pkts, u64 total_bytes, u32 thread_index, f64 *last_refreshed, f64 now)
Create session refresh HA event.
Definition: nat_ha.c:734
static int snat_not_translate_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, ip4_header_t *ip0, u32 proto0, u32 rx_fib_index0)
Check if packet should be translated.
Definition: nat_inlines.h:511
u32 max_translations_per_user
Definition: nat.h:621
Limit MSS.
Definition: tcp_packet.h:106
#define static_always_inline
Definition: clib.h:99
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
static_always_inline int get_icmp_o2i_ed_key(ip4_header_t *ip0, nat_ed_ses_key_t *p_key0)
Definition: nat_inlines.h:399
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
u16 r_port
Definition: nat.h:72
#define always_inline
Definition: clib.h:98
ip4_address_t dst_address
Definition: ip4_packet.h:170
#define TCP_FLAG_ACK
Definition: fa_node.h:16
ip4_address_t addr
Definition: nat.h:310
#define SNAT_SESSION_FLAG_OUTPUT_FEATURE
Definition: nat.h:251
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Aggregate type for a prefix.
Definition: fib_types.h:203
ip4_main_t * ip4_main
Definition: nat.h:652
static void * ip4_next_header(ip4_header_t *i)
Definition: ip4_packet.h:241
unsigned int u32
Definition: types.h:88
fib_node_index_t fib_table_lookup(u32 fib_index, const fib_prefix_t *prefix)
Perfom a longest prefix match in the non-forwarding table.
Definition: fib_table.c:66
#define NAT44_SES_RST
Definition: nat.h:241
static u8 maximum_sessions_exceeded(snat_main_t *sm, u32 thread_index)
Definition: nat_inlines.h:95
static void nat44_delete_session(snat_main_t *sm, snat_session_t *ses, u32 thread_index)
Definition: nat_inlines.h:169
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:136
u32 max_translations
Definition: nat.h:618
static void mss_clamping(snat_main_t *sm, tcp_header_t *tcp, ip_csum_t *sum)
Definition: nat_inlines.h:448
u32 fib_index
Definition: nat.h:70
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
u32 fib_index
Definition: nat.h:333
u16 mss_value_net
Definition: nat.h:635
u64 key
the key
Definition: bihash_8_8.h:35
u16 mss_clamping
Definition: nat.h:634
static void clib_dlist_addtail(dlist_elt_t *pool, u32 head_index, u32 new_index)
Definition: dlist.h:43
unsigned short u16
Definition: types.h:57
u16 protocol
Definition: nat.h:55
u8 out2in_dpo
Definition: nat.h:614
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
u32 udp_timeout
Definition: nat.h:628
#define PREDICT_FALSE(x)
Definition: clib.h:111
#define TCP_FLAG_FIN
Definition: fa_node.h:12
u16 port
Definition: punt.api:40
#define NAT44_SES_O2I_SYN
Definition: nat.h:240
static void vlib_set_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 value)
Set a simple counter.
Definition: counter.h:94
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:218
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:338
#define TCP_FLAG_RST
Definition: fa_node.h:14
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
Definition: fib_entry.c:1458
u64 value
the value
Definition: bihash_8_8.h:36
snat_user_t * users
Definition: nat.h:469
static void nat44_delete_user_with_no_session(snat_main_t *sm, snat_user_t *u, u32 thread_index)
Definition: nat_inlines.h:147
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
Definition: nat_inlines.h:42
vlib_main_t * vm
Definition: buffer.c:323
ip4_address_t l_addr
Definition: nat.h:68
static void nat44_session_update_counters(snat_session_t *s, f64 now, uword bytes, u32 thread_index)
Definition: nat_inlines.h:293
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:33
ip4_address_t addr
Definition: nat.h:53
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:456
static void make_ed_kv(clib_bihash_kv_16_8_t *kv, ip4_address_t *l_addr, ip4_address_t *r_addr, u8 proto, u32 fib_index, u16 l_port, u16 r_port)
Definition: nat_inlines.h:317
u32 tcp_transitory_timeout
Definition: nat.h:630
ip4_address_t r_addr
Definition: nat.h:69
static int nat44_set_tcp_session_state_i2o(snat_main_t *sm, snat_session_t *ses, tcp_header_t *tcp, u32 thread_index)
Set TCP session state.
Definition: nat_inlines.h:205
ip_proto
Definition: ip_types.api:63
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:515
u8 value
Definition: qos.api:53
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:311
#define tcp_syn(_th)
Definition: tcp_packet.h:80
static void nat44_session_update_lru(snat_main_t *sm, snat_session_t *s, u32 thread_index)
Per-user LRU list maintenance.
Definition: nat_inlines.h:307
u64 as_u64
Definition: nat.h:103
ip4_address_t addr
Definition: nat.h:100
static void clib_dlist_remove(dlist_elt_t *pool, u32 index)
Definition: dlist.h:99
#define NAT44_SES_I2O_SYN
Definition: nat.h:239
vlib_simple_counter_main_t total_users
Definition: nat.h:638
static u32 ip_proto_to_snat_proto(u8 ip_proto)
The NAT inline functions.
Definition: nat_inlines.h:27
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
static void user_session_increment(snat_main_t *sm, snat_user_t *u, u8 is_static)
Definition: nat_inlines.h:135
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
snat_main_per_thread_data_t * per_thread_data
Definition: nat.h:525
snat_protocol_t
Definition: nat.h:152
typedef key
Definition: ipsec.api:247
#define ip_csum_update(sum, old, new, type, field)
Definition: ip_packet.h:269
static u8 is_interface_addr(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, u32 ip4_addr)
Definition: nat_inlines.h:70
u32 fib_index
Definition: nat.h:101
#define NAT44_SES_I2O_FIN_ACK
Definition: nat.h:237
#define vec_foreach(var, vec)
Vector iterator.
static void nat_send_all_to_node(vlib_main_t *vm, u32 *bi_vector, vlib_node_runtime_t *node, vlib_error_t *error, u32 next)
Definition: nat_inlines.h:105
#define NAT44_SES_O2I_FIN_ACK
Definition: nat.h:238
vlib_simple_counter_main_t total_sessions
Definition: nat.h:639
snat_session_t * sessions
Definition: nat.h:472
u32 cached_ip4_address
Definition: nat.h:666
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
snat_interface_t * interfaces
Definition: nat.h:537
NAT active-passive HA.
u16 fib_index
Definition: nat.h:55
vl_api_fib_path_nh_proto_t proto
Definition: fib_types.api:125
u32 tcp_established_timeout
Definition: nat.h:629
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128