FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
nat44_ed_cli.c
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  * @file
17  * @brief NAT44 CLI
18  */
19 
20 #include <vnet/fib/fib_table.h>
21 
22 #include <nat/lib/log.h>
23 #include <nat/lib/nat_inlines.h>
24 #include <nat/lib/ipfix_logging.h>
25 
26 #include <nat/nat44-ed/nat44_ed.h>
29 
30 #define NAT44_ED_EXPECTED_ARGUMENT "expected required argument(s)"
31 
32 static clib_error_t *
34  vlib_cli_command_t *cmd)
35 {
36  snat_main_t *sm = &snat_main;
37  unformat_input_t _line_input, *line_input = &_line_input;
38  clib_error_t *error = 0;
39 
40  nat44_config_t c = { 0 };
41  u8 enable_set = 0, enable = 0, mode_set = 0;
42 
43  if (!unformat_user (input, unformat_line_input, line_input))
45 
46  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
47  {
48  if (!mode_set && unformat (line_input, "static-mapping-only"))
49  {
50  mode_set = 1;
51  c.static_mapping_only = 1;
52  if (unformat (line_input, "connection-tracking"))
53  {
54  c.connection_tracking = 1;
55  }
56  }
57  else if (unformat (line_input, "inside-vrf %u", &c.inside_vrf));
58  else if (unformat (line_input, "outside-vrf %u", &c.outside_vrf));
59  else if (unformat (line_input, "sessions %u", &c.sessions));
60  else if (!enable_set)
61  {
62  enable_set = 1;
63  if (unformat (line_input, "disable"))
64  ;
65  else if (unformat (line_input, "enable"))
66  enable = 1;
67  }
68  else
69  {
70  error = clib_error_return (0, "unknown input '%U'",
71  format_unformat_error, line_input);
72  goto done;
73  }
74  }
75 
76  if (!enable_set)
77  {
78  error = clib_error_return (0, "expected enable | disable");
79  goto done;
80  }
81 
82  if (enable)
83  {
84  if (sm->enabled)
85  {
86  error = clib_error_return (0, "already enabled");
87  goto done;
88  }
89 
90  if (nat44_plugin_enable (c) != 0)
91  error = clib_error_return (0, "enable failed");
92  }
93  else
94  {
95  if (!sm->enabled)
96  {
97  error = clib_error_return (0, "already disabled");
98  goto done;
99  }
100 
101  if (nat44_plugin_disable () != 0)
102  error = clib_error_return (0, "disable failed");
103  }
104 
105 done:
106  unformat_free (line_input);
107  return error;
108 }
109 
110 static clib_error_t *
112  unformat_input_t * input, vlib_cli_command_t * cmd)
113 {
114  unformat_input_t _line_input, *line_input = &_line_input;
115  uword *bitmap = 0;
116  int rv = 0;
117  clib_error_t *error = 0;
118 
119  /* Get a line of input. */
120  if (!unformat_user (input, unformat_line_input, line_input))
122 
123  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
124  {
125  if (unformat (line_input, "%U", unformat_bitmap_list, &bitmap))
126  ;
127  else
128  {
129  error = clib_error_return (0, "unknown input '%U'",
130  format_unformat_error, line_input);
131  goto done;
132  }
133  }
134 
135  if (bitmap == 0)
136  {
137  error = clib_error_return (0, "List of workers must be specified.");
138  goto done;
139  }
140 
141  rv = snat_set_workers (bitmap);
142 
143  clib_bitmap_free (bitmap);
144 
145  switch (rv)
146  {
147  case VNET_API_ERROR_INVALID_WORKER:
148  error = clib_error_return (0, "Invalid worker(s).");
149  goto done;
150  case VNET_API_ERROR_FEATURE_DISABLED:
152  "Supported only if 2 or more workes available.");
153  goto done;
154  default:
155  break;
156  }
157 
158 done:
159  unformat_free (line_input);
160 
161  return error;
162 }
163 
164 static clib_error_t *
166  vlib_cli_command_t * cmd)
167 {
168  snat_main_t *sm = &snat_main;
169  u32 *worker;
170 
171  if (sm->num_workers > 1)
172  {
173  vlib_cli_output (vm, "%d workers", vec_len (sm->workers));
174  vec_foreach (worker, sm->workers)
175  {
177  vlib_worker_threads + *worker + sm->first_worker_index;
178  vlib_cli_output (vm, " %s", w->name);
179  }
180  }
181 
182  return 0;
183 }
184 
185 static clib_error_t *
187  unformat_input_t * input,
188  vlib_cli_command_t * cmd)
189 {
190  unformat_input_t _line_input, *line_input = &_line_input;
191  snat_main_t *sm = &snat_main;
193  clib_error_t *error = 0;
194 
195  /* Get a line of input. */
196  if (!unformat_user (input, unformat_line_input, line_input))
198 
199  if (!unformat (line_input, "%d", &log_level))
200  {
201  error = clib_error_return (0, "unknown input '%U'",
202  format_unformat_error, line_input);
203  goto done;
204  }
205  if (log_level > NAT_LOG_DEBUG)
206  {
207  error = clib_error_return (0, "unknown logging level '%d'", log_level);
208  goto done;
209  }
210  sm->log_level = log_level;
211 
212 done:
213  unformat_free (line_input);
214 
215  return error;
216 }
217 
218 static clib_error_t *
220  unformat_input_t * input,
221  vlib_cli_command_t * cmd)
222 {
223  unformat_input_t _line_input, *line_input = &_line_input;
224  clib_error_t *error = 0;
225 
226  u32 domain_id = 0, src_port = 0;
227  u8 enable_set = 0, enable = 0;
228 
229  if (!unformat_user (input, unformat_line_input, line_input))
231 
232  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
233  {
234  if (unformat (line_input, "domain %d", &domain_id))
235  ;
236  else if (unformat (line_input, "src-port %d", &src_port))
237  ;
238  else if (!enable_set)
239  {
240  enable_set = 1;
241  if (unformat (line_input, "disable"))
242  ;
243  else if (unformat (line_input, "enable"))
244  enable = 1;
245  }
246  else
247  {
248  error = clib_error_return (0, "unknown input '%U'",
249  format_unformat_error, line_input);
250  goto done;
251  }
252  }
253 
254  if (!enable_set)
255  {
256  error = clib_error_return (0, "expected enable | disable");
257  goto done;
258  }
259 
260  if (nat_ipfix_logging_enable_disable (enable, domain_id, (u16) src_port))
261  {
262  error = clib_error_return (0, "ipfix logging enable failed");
263  goto done;
264  }
265 
266 done:
267  unformat_free (line_input);
268 
269  return error;
270 }
271 
272 static clib_error_t *
274  vlib_cli_command_t * cmd)
275 {
276  snat_main_t *sm = &snat_main;
278  int i;
279  int verbose = 0;
280 
281  if (unformat (input, "detail"))
282  verbose = 1;
283  else if (unformat (input, "verbose"))
284  verbose = 2;
285 
286  vlib_cli_output (vm, "%U", format_bihash_8_8, &sm->static_mapping_by_local,
287  verbose);
288  vlib_cli_output (vm, "%U",
289  format_bihash_8_8, &sm->static_mapping_by_external,
290  verbose);
291  vlib_cli_output (vm, "%U", format_bihash_16_8, &sm->flow_hash, verbose);
293  {
294  vlib_cli_output (vm, "-------- thread %d %s --------\n",
296  vlib_cli_output (vm, "%U", format_bihash_16_8, &sm->flow_hash, verbose);
297  }
298 
299  vlib_cli_output (vm, "%U", format_bihash_16_8, &nam->affinity_hash,
300  verbose);
301 
302  vlib_cli_output (vm, "-------- hash table parameters --------\n");
303  vlib_cli_output (vm, "translation buckets: %u", sm->translation_buckets);
304  return 0;
305 }
306 
307 static clib_error_t *
309  vlib_cli_command_t * cmd)
310 {
311  unformat_input_t _line_input, *line_input = &_line_input;
312  snat_main_t *sm = &snat_main;
313  clib_error_t *error = 0;
314  u32 mss;
315 
316  /* Get a line of input. */
317  if (!unformat_user (input, unformat_line_input, line_input))
319 
320  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
321  {
322  if (unformat (line_input, "disable"))
323  sm->mss_clamping = 0;
324  else if (unformat (line_input, "%d", &mss))
325  sm->mss_clamping = (u16) mss;
326  else
327  {
328  error = clib_error_return (0, "unknown input '%U'",
329  format_unformat_error, line_input);
330  goto done;
331  }
332  }
333 
334 done:
335  unformat_free (line_input);
336 
337  return error;
338 }
339 
340 static clib_error_t *
342  vlib_cli_command_t * cmd)
343 {
344  snat_main_t *sm = &snat_main;
345 
346  if (sm->mss_clamping)
347  vlib_cli_output (vm, "mss-clamping %d", sm->mss_clamping);
348  else
349  vlib_cli_output (vm, "mss-clamping disabled");
350 
351  return 0;
352 }
353 
354 static clib_error_t *
356  unformat_input_t * input, vlib_cli_command_t * cmd)
357 {
358  unformat_input_t _line_input, *line_input = &_line_input;
359  snat_main_t *sm = &snat_main;
360  ip4_address_t start_addr, end_addr, this_addr;
361  u32 start_host_order, end_host_order;
362  u32 vrf_id = ~0;
363  int i, count;
364  int is_add = 1;
365  int rv = 0;
366  clib_error_t *error = 0;
367  u8 twice_nat = 0;
368 
369  /* Get a line of input. */
370  if (!unformat_user (input, unformat_line_input, line_input))
372 
373  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
374  {
375  if (unformat (line_input, "%U - %U",
378  ;
379  else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
380  ;
381  else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
383  else if (unformat (line_input, "twice-nat"))
384  twice_nat = 1;
385  else if (unformat (line_input, "del"))
386  is_add = 0;
387  else
388  {
389  error = clib_error_return (0, "unknown input '%U'",
390  format_unformat_error, line_input);
391  goto done;
392  }
393  }
394 
395  if (sm->static_mapping_only)
396  {
397  error = clib_error_return (0, "static mapping only mode");
398  goto done;
399  }
400 
401  start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
402  end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
403 
404  if (end_host_order < start_host_order)
405  {
406  error = clib_error_return (0, "end address less than start address");
407  goto done;
408  }
409 
410  count = (end_host_order - start_host_order) + 1;
411 
412  if (count > 1024)
413  nat_log_info ("%U - %U, %d addresses...",
416 
417  this_addr = start_addr;
418 
419  for (i = 0; i < count; i++)
420  {
421  if (is_add)
422  {
423  rv = nat44_ed_add_address (&this_addr, vrf_id, twice_nat);
424  }
425  else
426  {
427  rv = nat44_ed_del_address (this_addr, 0, twice_nat);
428  }
429 
430  switch (rv)
431  {
432  case VNET_API_ERROR_VALUE_EXIST:
433  error = clib_error_return (0, "NAT address already in use.");
434  goto done;
435  case VNET_API_ERROR_NO_SUCH_ENTRY:
436  error = clib_error_return (0, "NAT address not exist.");
437  goto done;
438  case VNET_API_ERROR_UNSPECIFIED:
439  error =
440  clib_error_return (0, "NAT address used in static mapping.");
441  goto done;
442  default:
443  break;
444  }
445 
446  increment_v4_address (&this_addr);
447  }
448 
449 done:
450  unformat_free (line_input);
451 
452  return error;
453 }
454 
455 static void
457  u64 now, u64 sess_timeout_time)
458 {
459  snat_main_t *sm = &snat_main;
460  dlist_elt_t *oldest_elt;
461  snat_session_t *s;
462  u32 oldest_index;
463 
464  if (tsm->lru_pool)
465  {
466 #define _(n, d) \
467  oldest_index = \
468  clib_dlist_remove_head (tsm->lru_pool, tsm->n##_lru_head_index); \
469  if (~0 != oldest_index) \
470  { \
471  oldest_elt = pool_elt_at_index (tsm->lru_pool, oldest_index); \
472  s = pool_elt_at_index (tsm->sessions, oldest_elt->value); \
473  sess_timeout_time = \
474  s->last_heard + (f64) nat44_session_get_timeout (sm, s); \
475  vlib_cli_output (vm, d " LRU min session timeout %llu (now %llu)", \
476  sess_timeout_time, now); \
477  clib_dlist_addhead (tsm->lru_pool, tsm->n##_lru_head_index, \
478  oldest_index); \
479  }
480  _ (tcp_estab, "established tcp");
481  _ (tcp_trans, "transitory tcp");
482  _ (udp, "udp");
483  _ (unk_proto, "unknown protocol");
484  _ (icmp, "icmp");
485 #undef _
486  }
487 }
488 
489 static clib_error_t *
491  vlib_cli_command_t * cmd)
492 {
494  snat_main_t *sm = &snat_main;
495  snat_session_t *s;
496 
497  u32 count = 0;
498 
499  u64 now = vlib_time_now (vm);
500  u64 sess_timeout_time = 0;
501 
502  u32 udp_sessions = 0;
503  u32 tcp_sessions = 0;
504  u32 icmp_sessions = 0;
505 
506  u32 timed_out = 0;
507  u32 transitory = 0;
508  u32 transitory_wait_closed = 0;
509  u32 transitory_closed = 0;
510  u32 established = 0;
511 
512  u32 fib;
513 
514  for (fib = 0; fib < vec_len (sm->max_translations_per_fib); fib++)
515  vlib_cli_output (vm, "max translations per thread: %u fib %u",
516  sm->max_translations_per_fib[fib], fib);
517 
518  if (sm->num_workers > 1)
519  {
520  vec_foreach (tsm, sm->per_thread_data)
521  {
522  pool_foreach (s, tsm->sessions)
523  {
524  sess_timeout_time = s->last_heard +
525  (f64) nat44_session_get_timeout (sm, s);
526  if (now >= sess_timeout_time)
527  timed_out++;
528 
529  switch (s->nat_proto)
530  {
531  case NAT_PROTOCOL_ICMP:
532  icmp_sessions++;
533  break;
534  case NAT_PROTOCOL_TCP:
535  tcp_sessions++;
536  if (s->state)
537  {
538  if (s->tcp_closed_timestamp)
539  {
540  if (now >= s->tcp_closed_timestamp)
541  {
542  ++transitory_closed;
543  }
544  else
545  {
546  ++transitory_wait_closed;
547  }
548  }
549  transitory++;
550  }
551  else
552  established++;
553  break;
554  case NAT_PROTOCOL_UDP:
555  default:
556  udp_sessions++;
557  break;
558  }
559  }
560  nat44_show_lru_summary (vm, tsm, now, sess_timeout_time);
561  count += pool_elts (tsm->sessions);
562  }
563  }
564  else
565  {
567  pool_foreach (s, tsm->sessions)
568  {
569  sess_timeout_time = s->last_heard +
570  (f64) nat44_session_get_timeout (sm, s);
571  if (now >= sess_timeout_time)
572  timed_out++;
573 
574  switch (s->nat_proto)
575  {
576  case NAT_PROTOCOL_ICMP:
577  icmp_sessions++;
578  break;
579  case NAT_PROTOCOL_TCP:
580  tcp_sessions++;
581  if (s->state)
582  {
583  if (s->tcp_closed_timestamp)
584  {
585  if (now >= s->tcp_closed_timestamp)
586  {
587  ++transitory_closed;
588  }
589  else
590  {
591  ++transitory_wait_closed;
592  }
593  }
594  transitory++;
595  }
596  else
597  established++;
598  break;
599  case NAT_PROTOCOL_UDP:
600  default:
601  udp_sessions++;
602  break;
603  }
604  }
605  nat44_show_lru_summary (vm, tsm, now, sess_timeout_time);
606  count = pool_elts (tsm->sessions);
607  }
608 
609  vlib_cli_output (vm, "total timed out sessions: %u", timed_out);
610  vlib_cli_output (vm, "total sessions: %u", count);
611  vlib_cli_output (vm, "total tcp sessions: %u", tcp_sessions);
612  vlib_cli_output (vm, "total tcp established sessions: %u", established);
613  vlib_cli_output (vm, "total tcp transitory sessions: %u", transitory);
614  vlib_cli_output (vm, "total tcp transitory (WAIT-CLOSED) sessions: %u",
615  transitory_wait_closed);
616  vlib_cli_output (vm, "total tcp transitory (CLOSED) sessions: %u",
617  transitory_closed);
618  vlib_cli_output (vm, "total udp sessions: %u", udp_sessions);
619  vlib_cli_output (vm, "total icmp sessions: %u", icmp_sessions);
620  return 0;
621 }
622 
623 static clib_error_t *
625  vlib_cli_command_t * cmd)
626 {
627  snat_main_t *sm = &snat_main;
628  snat_address_t *ap;
629 
630  vlib_cli_output (vm, "NAT44 pool addresses:");
631  vec_foreach (ap, sm->addresses)
632  {
633  vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
634  if (ap->fib_index != ~0)
635  vlib_cli_output (vm, " tenant VRF: %u",
637  else
638  vlib_cli_output (vm, " tenant VRF independent");
639  #define _(N, i, n, s) \
640  vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
642  #undef _
643  }
644  vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
646  {
647  vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
648  if (ap->fib_index != ~0)
649  vlib_cli_output (vm, " tenant VRF: %u",
651  else
652  vlib_cli_output (vm, " tenant VRF independent");
653  #define _(N, i, n, s) \
654  vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
656  #undef _
657  }
658  return 0;
659 }
660 
661 static clib_error_t *
663  unformat_input_t * input, vlib_cli_command_t * cmd)
664 {
665  unformat_input_t _line_input, *line_input = &_line_input;
666  vnet_main_t *vnm = vnet_get_main ();
667  clib_error_t *error = 0;
669  u32 *inside_sw_if_indices = 0;
670  u32 *outside_sw_if_indices = 0;
671  u8 is_output_feature = 0;
672  int i, rv, is_del = 0;
673 
674  sw_if_index = ~0;
675 
676  /* Get a line of input. */
677  if (!unformat_user (input, unformat_line_input, line_input))
679 
680  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
681  {
682  if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
683  vnm, &sw_if_index))
684  vec_add1 (inside_sw_if_indices, sw_if_index);
685  else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
686  vnm, &sw_if_index))
687  vec_add1 (outside_sw_if_indices, sw_if_index);
688  else if (unformat (line_input, "output-feature"))
689  is_output_feature = 1;
690  else if (unformat (line_input, "del"))
691  is_del = 1;
692  else
693  {
694  error = clib_error_return (0, "unknown input '%U'",
695  format_unformat_error, line_input);
696  goto done;
697  }
698  }
699 
700  if (vec_len (inside_sw_if_indices))
701  {
702  for (i = 0; i < vec_len (inside_sw_if_indices); i++)
703  {
704  sw_if_index = inside_sw_if_indices[i];
705  if (is_output_feature)
706  {
707  if (is_del)
708  {
710  }
711  else
712  {
714  }
715  if (rv)
716  {
717  error = clib_error_return (0, "%s %U failed",
718  is_del ? "del" : "add",
720  vnm, sw_if_index);
721  goto done;
722  }
723  }
724  else
725  {
726  if (is_del)
727  {
729  }
730  else
731  {
733  }
734  if (rv)
735  {
736  error = clib_error_return (0, "%s %U failed",
737  is_del ? "del" : "add",
739  vnm, sw_if_index);
740  goto done;
741  }
742  }
743  }
744  }
745 
746  if (vec_len (outside_sw_if_indices))
747  {
748  for (i = 0; i < vec_len (outside_sw_if_indices); i++)
749  {
750  sw_if_index = outside_sw_if_indices[i];
751  if (is_output_feature)
752  {
753  if (is_del)
754  {
756  }
757  else
758  {
760  }
761  if (rv)
762  {
763  error = clib_error_return (0, "%s %U failed",
764  is_del ? "del" : "add",
766  vnm, sw_if_index);
767  goto done;
768  }
769  }
770  else
771  {
772  if (is_del)
773  {
775  }
776  else
777  {
779  }
780  if (rv)
781  {
782  error = clib_error_return (0, "%s %U failed",
783  is_del ? "del" : "add",
785  vnm, sw_if_index);
786  goto done;
787  }
788  }
789  }
790  }
791 
792 done:
793  unformat_free (line_input);
794  vec_free (inside_sw_if_indices);
795  vec_free (outside_sw_if_indices);
796 
797  return error;
798 }
799 
800 static clib_error_t *
802  vlib_cli_command_t * cmd)
803 {
804  snat_main_t *sm = &snat_main;
806  vnet_main_t *vnm = vnet_get_main ();
807 
808  vlib_cli_output (vm, "NAT44 interfaces:");
809  pool_foreach (i, sm->interfaces)
810  {
812  i->sw_if_index,
815  "in out" :
816  (nat44_ed_is_interface_inside (i) ? "in" : "out"));
817  }
818 
820  {
821  vlib_cli_output (vm, " %U output-feature %s",
822  format_vnet_sw_if_index_name, vnm, i->sw_if_index,
825  "in out" :
826  (nat44_ed_is_interface_inside (i) ? "in" : "out"));
827  }
828 
829  return 0;
830 }
831 
832 static clib_error_t *
834  unformat_input_t * input,
835  vlib_cli_command_t * cmd)
836 {
837  unformat_input_t _line_input, *line_input = &_line_input;
838  vnet_main_t *vnm = vnet_get_main ();
839  clib_error_t *error = 0;
840  int rv;
841 
842  nat_protocol_t proto = NAT_PROTOCOL_OTHER;
843  ip4_address_t l_addr, e_addr, pool_addr;
844  u32 l_port = 0, e_port = 0, vrf_id = ~0;
845  u8 l_port_set = 0, e_port_set = 0;
846  u32 sw_if_index, flags = 0;
847  int is_add = 1;
848 
849  if (!unformat_user (input, unformat_line_input, line_input))
851 
852  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
853  {
854  if (unformat (line_input, "local %U %u", unformat_ip4_address, &l_addr,
855  &l_port))
856  {
857  l_port_set = 1;
858  }
859  else
860  if (unformat (line_input, "local %U", unformat_ip4_address, &l_addr))
861  ;
862  else if (unformat (line_input, "external %U %u", unformat_ip4_address,
863  &e_addr, &e_port))
864  {
865  e_port_set = 1;
866  }
867  else if (unformat (line_input, "external %U", unformat_ip4_address,
868  &e_addr))
869  ;
870  else if (unformat (line_input, "external %U %u",
872  &e_port))
873  {
875  e_port_set = 1;
876  }
877  else if (unformat (line_input, "external %U",
879  {
881  }
882  else if (unformat (line_input, "exact %U", unformat_ip4_address,
883  &pool_addr))
884  {
886  }
887  else if (unformat (line_input, "vrf %u", &vrf_id))
888  ;
889  else if (unformat (line_input, "%U", unformat_nat_protocol, &proto))
890  ;
891  else if (unformat (line_input, "self-twice-nat"))
892  {
894  }
895  else if (unformat (line_input, "twice-nat"))
896  {
898  }
899  else if (unformat (line_input, "out2in-only"))
900  {
902  }
903  else if (unformat (line_input, "del"))
904  {
905  is_add = 0;
906  }
907  else
908  {
909  error = clib_error_return (0, "unknown input: '%U'",
910  format_unformat_error, line_input);
911  goto done;
912  }
913  }
914 
915  if (l_port_set != e_port_set)
916  {
917  error = clib_error_return (0, "Either both ports are set or none.");
918  goto done;
919  }
920 
921  if (!l_port_set)
922  {
924  }
925  else
926  {
927  l_port = clib_host_to_net_u16 (l_port);
928  e_port = clib_host_to_net_u16 (e_port);
929  }
930 
931  // TODO: specific pool_addr for both pool & twice nat pool ?
932 
933  if (is_add)
934  {
935  rv =
936  nat44_ed_add_static_mapping (l_addr, e_addr, l_port, e_port, proto,
937  vrf_id, sw_if_index, flags, pool_addr, 0);
938  }
939  else
940  {
941  rv = nat44_ed_del_static_mapping (l_addr, e_addr, l_port, e_port, proto,
943  }
944 
945  // TODO: fix returns
946 
947  switch (rv)
948  {
949  case VNET_API_ERROR_INVALID_VALUE:
950  error = clib_error_return (0, "External port already in use.");
951  goto done;
952  case VNET_API_ERROR_NO_SUCH_ENTRY:
953  if (is_add)
954  error = clib_error_return (0, "External address must be allocated.");
955  else
956  error = clib_error_return (0, "Mapping not exist.");
957  goto done;
958  case VNET_API_ERROR_NO_SUCH_FIB:
959  error = clib_error_return (0, "No such VRF id.");
960  goto done;
961  case VNET_API_ERROR_VALUE_EXIST:
962  error = clib_error_return (0, "Mapping already exist.");
963  goto done;
964  default:
965  break;
966  }
967 
968 done:
969  unformat_free (line_input);
970 
971  return error;
972 }
973 
974 // TODO: either delete this bullshit or update it
975 static clib_error_t *
977  unformat_input_t * input,
978  vlib_cli_command_t * cmd)
979 {
980  unformat_input_t _line_input, *line_input = &_line_input;
981  vnet_main_t *vnm = vnet_get_main ();
982  clib_error_t *error = 0;
983 
984  int rv, is_add = 1, port_set = 0;
985  u32 sw_if_index, port, flags, vrf_id = ~0;
988 
990 
991  /* Get a line of input. */
992  if (!unformat_user (input, unformat_line_input, line_input))
994 
995  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
996  {
997  if (unformat (line_input, "%U", unformat_ip4_address, &addr))
998  ;
999  else if (unformat (line_input, "external %U",
1001  {
1003  }
1004  else if (unformat (line_input, "vrf %u", &vrf_id))
1005  ;
1006  else if (unformat (line_input, "%U %u", unformat_nat_protocol, &proto,
1007  &port))
1008  {
1009  port_set = 1;
1010  }
1011  else if (unformat (line_input, "del"))
1012  {
1013  is_add = 0;
1014  }
1015  else
1016  {
1017  error = clib_error_return (0, "unknown input: '%U'",
1018  format_unformat_error, line_input);
1019  goto done;
1020  }
1021  }
1022 
1023  if (!port_set)
1024  {
1026  }
1027  else
1028  {
1029  port = clib_host_to_net_u16 (port);
1030  }
1031 
1032  if (is_add)
1033  {
1034 
1036  sw_if_index, flags, addr, 0);
1037  }
1038  else
1039  {
1041  sw_if_index, flags);
1042  }
1043 
1044  // TODO: fix returns
1045 
1046  switch (rv)
1047  {
1048  case VNET_API_ERROR_INVALID_VALUE:
1049  error = clib_error_return (0, "External port already in use.");
1050  goto done;
1051  case VNET_API_ERROR_NO_SUCH_ENTRY:
1052  if (is_add)
1053  error = clib_error_return (0, "External address must be allocated.");
1054  else
1055  error = clib_error_return (0, "Mapping not exist.");
1056  goto done;
1057  case VNET_API_ERROR_NO_SUCH_FIB:
1058  error = clib_error_return (0, "No such VRF id.");
1059  goto done;
1060  case VNET_API_ERROR_VALUE_EXIST:
1061  error = clib_error_return (0, "Mapping already exist.");
1062  goto done;
1063  default:
1064  break;
1065  }
1066 
1067 done:
1068  unformat_free (line_input);
1069 
1070  return error;
1071 }
1072 
1073 static clib_error_t *
1075  unformat_input_t * input,
1076  vlib_cli_command_t * cmd)
1077 {
1078  unformat_input_t _line_input, *line_input = &_line_input;
1079  clib_error_t *error = 0;
1080  ip4_address_t l_addr, e_addr;
1081  u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0, affinity = 0;
1082  u8 proto_set = 0;
1084  nat44_lb_addr_port_t *locals = 0, local;
1085  int rv, is_add = 1;
1086  u32 flags = 0;
1087 
1088  /* Get a line of input. */
1089  if (!unformat_user (input, unformat_line_input, line_input))
1091 
1092  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1093  {
1094  if (unformat (line_input, "local %U:%u probability %u",
1095  unformat_ip4_address, &l_addr, &l_port, &probability))
1096  {
1097  clib_memset (&local, 0, sizeof (local));
1098  local.addr = l_addr;
1099  local.port = (u16) l_port;
1100  local.probability = (u8) probability;
1101  vec_add1 (locals, local);
1102  }
1103  else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1104  unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1105  &probability))
1106  {
1107  clib_memset (&local, 0, sizeof (local));
1108  local.addr = l_addr;
1109  local.port = (u16) l_port;
1110  local.probability = (u8) probability;
1111  local.vrf_id = vrf_id;
1112  vec_add1 (locals, local);
1113  }
1114  else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1115  &e_addr, &e_port))
1116  ;
1117  else if (unformat (line_input, "protocol %U", unformat_nat_protocol,
1118  &proto))
1119  {
1120  proto_set = 1;
1121  }
1122  else if (unformat (line_input, "twice-nat"))
1123  {
1125  }
1126  else if (unformat (line_input, "self-twice-nat"))
1127  {
1129  }
1130  else if (unformat (line_input, "out2in-only"))
1131  {
1133  }
1134  else if (unformat (line_input, "del"))
1135  {
1136  is_add = 0;
1137  }
1138  else if (unformat (line_input, "affinity %u", &affinity))
1139  ;
1140  else
1141  {
1142  error = clib_error_return (0, "unknown input: '%U'",
1143  format_unformat_error, line_input);
1144  goto done;
1145  }
1146  }
1147 
1148  if (vec_len (locals) < 2)
1149  {
1150  error = clib_error_return (0, "at least two local must be set");
1151  goto done;
1152  }
1153 
1154  if (!proto_set)
1155  {
1156  error = clib_error_return (0, "missing protocol");
1157  goto done;
1158  }
1159 
1160  if (is_add)
1161  {
1162  rv = nat44_ed_add_lb_static_mapping (e_addr, (u16) e_port, proto, locals,
1163  flags, 0, affinity);
1164  }
1165  else
1166  {
1167  rv = nat44_ed_del_lb_static_mapping (e_addr, (u16) e_port, proto, flags);
1168  }
1169 
1170  switch (rv)
1171  {
1172  case VNET_API_ERROR_INVALID_VALUE:
1173  error = clib_error_return (0, "External port already in use.");
1174  goto done;
1175  case VNET_API_ERROR_NO_SUCH_ENTRY:
1176  if (is_add)
1177  error = clib_error_return (0, "External address must be allocated.");
1178  else
1179  error = clib_error_return (0, "Mapping not exist.");
1180  goto done;
1181  case VNET_API_ERROR_VALUE_EXIST:
1182  error = clib_error_return (0, "Mapping already exist.");
1183  goto done;
1184  default:
1185  break;
1186  }
1187 
1188 done:
1189  unformat_free (line_input);
1190  vec_free (locals);
1191 
1192  return error;
1193 }
1194 
1195 static clib_error_t *
1197  unformat_input_t * input, vlib_cli_command_t * cmd)
1198 {
1199  unformat_input_t _line_input, *line_input = &_line_input;
1200  clib_error_t *error = 0;
1201  ip4_address_t l_addr, e_addr;
1202  u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0;
1203  int is_add = 1;
1204  int rv;
1206  u8 proto_set = 0;
1207 
1208  /* Get a line of input. */
1209  if (!unformat_user (input, unformat_line_input, line_input))
1211 
1212  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1213  {
1214  if (unformat (line_input, "local %U:%u probability %u",
1215  unformat_ip4_address, &l_addr, &l_port, &probability))
1216  ;
1217  else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1218  unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1219  &probability))
1220  ;
1221  else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1222  &e_addr, &e_port))
1223  ;
1224  else if (unformat (line_input, "protocol %U", unformat_nat_protocol,
1225  &proto))
1226  proto_set = 1;
1227  else if (unformat (line_input, "del"))
1228  is_add = 0;
1229  else
1230  {
1231  error = clib_error_return (0, "unknown input: '%U'",
1232  format_unformat_error, line_input);
1233  goto done;
1234  }
1235  }
1236 
1237  if (!l_port || !e_port)
1238  {
1239  error = clib_error_return (0, "local or external must be set");
1240  goto done;
1241  }
1242 
1243  if (!proto_set)
1244  {
1245  error = clib_error_return (0, "missing protocol");
1246  goto done;
1247  }
1248 
1250  e_addr, (u16) e_port, l_addr, l_port, proto, vrf_id, probability, is_add);
1251 
1252  switch (rv)
1253  {
1254  case VNET_API_ERROR_INVALID_VALUE:
1255  error = clib_error_return (0, "External is not load-balancing static "
1256  "mapping.");
1257  goto done;
1258  case VNET_API_ERROR_NO_SUCH_ENTRY:
1259  error = clib_error_return (0, "Mapping or back-end not exist.");
1260  goto done;
1261  case VNET_API_ERROR_VALUE_EXIST:
1262  error = clib_error_return (0, "Back-end already exist.");
1263  goto done;
1264  case VNET_API_ERROR_UNSPECIFIED:
1265  error = clib_error_return (0, "At least two back-ends must remain");
1266  goto done;
1267  default:
1268  break;
1269  }
1270 
1271 done:
1272  unformat_free (line_input);
1273 
1274  return error;
1275 }
1276 
1277 static clib_error_t *
1279  unformat_input_t * input,
1280  vlib_cli_command_t * cmd)
1281 {
1282  snat_main_t *sm = &snat_main;
1285 
1286  vlib_cli_output (vm, "NAT44 static mappings:");
1287  pool_foreach (m, sm->static_mappings)
1288  {
1290  }
1291  vec_foreach (rp, sm->to_resolve)
1293 
1294  return 0;
1295 }
1296 
1297 static clib_error_t *
1299  unformat_input_t * input,
1300  vlib_cli_command_t * cmd)
1301 {
1302  unformat_input_t _line_input, *line_input = &_line_input;
1303  snat_main_t *sm = &snat_main;
1304  clib_error_t *error = 0;
1305  int rv, is_del = 0;
1306  u8 twice_nat = 0;
1307  u32 sw_if_index;
1308 
1309  if (!unformat_user (input, unformat_line_input, line_input))
1311 
1312  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1313  {
1314  if (unformat (line_input, "%U", unformat_vnet_sw_interface,
1315  sm->vnet_main, &sw_if_index))
1316  ;
1317  else if (unformat (line_input, "twice-nat"))
1318  {
1319  twice_nat = 1;
1320  }
1321  else if (unformat (line_input, "del"))
1322  {
1323  is_del = 1;
1324  }
1325  else
1326  {
1327  error = clib_error_return (0, "unknown input '%U'",
1328  format_unformat_error, line_input);
1329  goto done;
1330  }
1331  }
1332 
1333  if (!is_del)
1334  {
1336  if (rv)
1337  {
1338  error = clib_error_return (0, "add address returned %d", rv);
1339  }
1340  }
1341  else
1342  {
1344  if (rv)
1345  {
1346  error = clib_error_return (0, "del address returned %d", rv);
1347  }
1348  }
1349 
1350 done:
1351  unformat_free (line_input);
1352 
1353  return error;
1354 }
1355 
1356 static clib_error_t *
1358  unformat_input_t * input,
1359  vlib_cli_command_t * cmd)
1360 {
1361  snat_main_t *sm = &snat_main;
1362  vnet_main_t *vnm = vnet_get_main ();
1363  u32 *sw_if_index;
1364 
1365  vlib_cli_output (vm, "NAT44 pool address interfaces:");
1367  {
1369  *sw_if_index);
1370  }
1371  vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
1373  {
1375  *sw_if_index);
1376  }
1377 
1378  return 0;
1379 }
1380 
1381 static clib_error_t *
1383  vlib_cli_command_t * cmd)
1384 {
1385  unformat_input_t _line_input, *line_input = &_line_input;
1386  clib_error_t *error = 0;
1388  snat_main_t *sm = &snat_main;
1389 
1390  int i = 0;
1391 
1392  if (!unformat_user (input, unformat_line_input, line_input))
1393  goto print;
1394 
1395  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1396  {
1397  error = clib_error_return (0, "unknown input '%U'",
1398  format_unformat_error, line_input);
1399  break;
1400  }
1401  unformat_free (line_input);
1402 
1403 print:
1404  vlib_cli_output (vm, "NAT44 ED sessions:");
1405 
1407  {
1408  tsm = vec_elt_at_index (sm->per_thread_data, i);
1409 
1410  vlib_cli_output (vm, "-------- thread %d %s: %d sessions --------\n",
1412  pool_elts (tsm->sessions));
1413 
1414  snat_session_t *s;
1415  pool_foreach (s, tsm->sessions)
1416  {
1417  vlib_cli_output (vm, " %U\n", format_snat_session, tsm, s);
1418  }
1419  }
1420  return error;
1421 }
1422 
1423 static clib_error_t *
1425  unformat_input_t * input,
1426  vlib_cli_command_t * cmd)
1427 {
1428  unformat_input_t _line_input, *line_input = &_line_input;
1429  clib_error_t *error = 0;
1430 
1431  u32 session_limit = 0, vrf_id = 0;
1432 
1433  if (!unformat_user (input, unformat_line_input, line_input))
1435 
1436  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1437  {
1438  if (unformat (line_input, "%u", &session_limit))
1439  ;
1440  else if (unformat (line_input, "vrf %u", &vrf_id))
1441  ;
1442  else
1443  {
1444  error = clib_error_return (0, "unknown input '%U'",
1445  format_unformat_error, line_input);
1446  goto done;
1447  }
1448  }
1449 
1450  if (!session_limit)
1451  error = clib_error_return (0, "missing value of session limit");
1452  else if (nat44_update_session_limit (session_limit, vrf_id))
1453  error = clib_error_return (0, "nat44_set_session_limit failed");
1454 
1455 done:
1456  unformat_free (line_input);
1457 
1458  return error;
1459 }
1460 
1461 static clib_error_t *
1463  unformat_input_t * input,
1464  vlib_cli_command_t * cmd)
1465 {
1466  snat_main_t *sm = &snat_main;
1467  unformat_input_t _line_input, *line_input = &_line_input;
1468  u32 port = 0, eh_port = 0, vrf_id = sm->outside_vrf_id;
1469  clib_error_t *error = 0;
1470  ip4_address_t addr, eh_addr;
1472  int is_in = 0;
1473  int rv;
1474 
1475  if (!unformat_user (input, unformat_line_input, line_input))
1477 
1478  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1479  {
1480  if (unformat
1481  (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
1483  ;
1484  else if (unformat (line_input, "in"))
1485  {
1486  is_in = 1;
1487  vrf_id = sm->inside_vrf_id;
1488  }
1489  else if (unformat (line_input, "out"))
1490  {
1491  is_in = 0;
1492  vrf_id = sm->outside_vrf_id;
1493  }
1494  else if (unformat (line_input, "vrf %u", &vrf_id))
1495  ;
1496  else if (unformat (line_input, "external-host %U:%u",
1497  unformat_ip4_address, &eh_addr, &eh_port))
1498  ;
1499  else
1500  {
1501  error = clib_error_return (0, "unknown input '%U'",
1502  format_unformat_error, line_input);
1503  goto done;
1504  }
1505  }
1506 
1507  rv = nat44_ed_del_session (sm, &addr, clib_host_to_net_u16 (port), &eh_addr,
1508  clib_host_to_net_u16 (eh_port),
1509  nat_proto_to_ip_proto (proto), vrf_id, is_in);
1510 
1511  switch (rv)
1512  {
1513  case 0:
1514  break;
1515 
1516  default:
1517  error = clib_error_return (0, "nat44_del_session returned %d", rv);
1518  goto done;
1519  }
1520 
1521 done:
1522  unformat_free (line_input);
1523 
1524  return error;
1525 }
1526 
1527 static clib_error_t *
1529  unformat_input_t * input,
1530  vlib_cli_command_t * cmd)
1531 {
1532  snat_main_t *sm = &snat_main;
1533  unformat_input_t _line_input, *line_input = &_line_input;
1534  clib_error_t *error = 0;
1535 
1536  u8 enable_set = 0, enable = 0;
1537 
1538  if (!unformat_user (input, unformat_line_input, line_input))
1540 
1541  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1542  {
1543  if (!enable_set)
1544  {
1545  enable_set = 1;
1546  if (unformat (line_input, "disable"))
1547  ;
1548  else if (unformat (line_input, "enable"))
1549  enable = 1;
1550  }
1551  else
1552  {
1553  error = clib_error_return (0, "unknown input '%U'",
1554  format_unformat_error, line_input);
1555  goto done;
1556  }
1557  }
1558 
1559  if (!enable_set)
1560  error = clib_error_return (0, "expected enable | disable");
1561  else
1562  sm->forwarding_enabled = enable;
1563 
1564 done:
1565  unformat_free (line_input);
1566  return error;
1567 }
1568 
1569 static clib_error_t *
1571  unformat_input_t * input, vlib_cli_command_t * cmd)
1572 {
1573  snat_main_t *sm = &snat_main;
1574  unformat_input_t _line_input, *line_input = &_line_input;
1575  clib_error_t *error = 0;
1576 
1577  if (!unformat_user (input, unformat_line_input, line_input))
1579 
1580  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1581  {
1582  if (unformat (line_input, "udp %u", &sm->timeouts.udp));
1583  else if (unformat (line_input, "tcp-established %u",
1584  &sm->timeouts.tcp.established));
1585  else if (unformat (line_input, "tcp-transitory %u",
1586  &sm->timeouts.tcp.transitory));
1587  else if (unformat (line_input, "icmp %u", &sm->timeouts.icmp));
1588  else if (unformat (line_input, "reset"))
1590  else
1591  {
1592  error = clib_error_return (0, "unknown input '%U'",
1593  format_unformat_error, line_input);
1594  goto done;
1595  }
1596  }
1597 done:
1598  unformat_free (line_input);
1599  return error;
1600 }
1601 
1602 static clib_error_t *
1604  unformat_input_t * input,
1605  vlib_cli_command_t * cmd)
1606 {
1607  snat_main_t *sm = &snat_main;
1608 
1609  vlib_cli_output (vm, "udp timeout: %dsec", sm->timeouts.udp);
1610  vlib_cli_output (vm, "tcp-established timeout: %dsec",
1611  sm->timeouts.tcp.established);
1612  vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
1613  sm->timeouts.tcp.transitory);
1614  vlib_cli_output (vm, "icmp timeout: %dsec", sm->timeouts.icmp);
1615 
1616  return 0;
1617 }
1618 
1619 static clib_error_t *
1621  vlib_cli_command_t *cmd)
1622 {
1623  unformat_input_t _line_input, *line_input = &_line_input;
1624  clib_error_t *error = 0;
1625  u32 frame_queue_nelts = 0;
1626 
1627  if (!unformat_user (input, unformat_line_input, line_input))
1629 
1630  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1631  {
1632  if (unformat (line_input, "%u", &frame_queue_nelts))
1633  ;
1634  else
1635  {
1636  error = clib_error_return (0, "unknown input '%U'",
1637  format_unformat_error, line_input);
1638  goto done;
1639  }
1640  }
1641  if (!frame_queue_nelts)
1642  {
1643  error = clib_error_return (0, "frame_queue_nelts cannot be zero");
1644  goto done;
1645  }
1646  if (nat44_ed_set_frame_queue_nelts (frame_queue_nelts) != 0)
1647  {
1648  error = clib_error_return (0, "snat_set_frame_queue_nelts failed");
1649  goto done;
1650  }
1651 done:
1652  unformat_free (line_input);
1653  return error;
1654 }
1655 
1656 /*?
1657  * @cliexpar
1658  * @cliexstart{nat44}
1659  * Enable nat44 plugin
1660  * To enable nat44-ed, use:
1661  * vpp# nat44 enable
1662  * To disable nat44-ed, use:
1663  * vpp# nat44 disable
1664  * To enable nat44-ed static mapping with connection tracking, use:
1665  * vpp# nat44-ed enable static-mapping connection-tracking
1666  * To set inside-vrf outside-vrf, use:
1667  * vpp# nat44 enable inside-vrf <id> outside-vrf <id>
1668  * @cliexend
1669 ?*/
1671  .path = "nat44",
1672  .short_help = "nat44 <enable [sessions <max-number>] [static-mapping-only "
1673  "connection-tracking] [inside-vrf <vrf-id>] "
1674  "[outside-vrf <vrf-id>]>|disable",
1676 };
1677 
1678 /*?
1679  * @cliexpar
1680  * @cliexstart{set snat workers}
1681  * Set NAT workers if 2 or more workers available, use:
1682  * vpp# set snat workers 0-2,5
1683  * @cliexend
1684 ?*/
1686  .path = "set nat workers",
1687  .function = set_workers_command_fn,
1688  .short_help = "set nat workers <workers-list>",
1689 };
1690 
1691 /*?
1692  * @cliexpar
1693  * @cliexstart{show nat workers}
1694  * Show NAT workers.
1695  * vpp# show nat workers:
1696  * 2 workers
1697  * vpp_wk_0
1698  * vpp_wk_1
1699  * @cliexend
1700 ?*/
1702  .path = "show nat workers",
1703  .short_help = "show nat workers",
1704  .function = nat_show_workers_commnad_fn,
1705 };
1706 
1707 /*?
1708  * @cliexpar
1709  * @cliexstart{set nat timeout}
1710  * Set values of timeouts for NAT sessions (in seconds), use:
1711  * vpp# set nat timeout udp 120 tcp-established 7500 tcp-transitory 250 icmp 90
1712  * To reset default values use:
1713  * vpp# set nat timeout reset
1714  * @cliexend
1715 ?*/
1717  .path = "set nat timeout",
1718  .function = set_timeout_command_fn,
1719  .short_help =
1720  "set nat timeout [udp <sec> | tcp-established <sec> "
1721  "tcp-transitory <sec> | icmp <sec> | reset]",
1722 };
1723 
1724 /*?
1725  * @cliexpar
1726  * @cliexstart{show nat timeouts}
1727  * Show values of timeouts for NAT sessions.
1728  * vpp# show nat timeouts
1729  * udp timeout: 300sec
1730  * tcp-established timeout: 7440sec
1731  * tcp-transitory timeout: 240sec
1732  * icmp timeout: 60sec
1733  * @cliexend
1734 ?*/
1736  .path = "show nat timeouts",
1737  .short_help = "show nat timeouts",
1738  .function = nat_show_timeouts_command_fn,
1739 };
1740 
1741 /*?
1742  * @cliexpar
1743  * @cliexstart{set nat frame-queue-nelts}
1744  * Set number of worker handoff frame queue elements.
1745  * @cliexend
1746 ?*/
1748  .path = "set nat frame-queue-nelts",
1750  .short_help = "set nat frame-queue-nelts <number>",
1751 };
1752 
1753 /*?
1754  * @cliexpar
1755  * @cliexstart{nat set logging level}
1756  * To set NAT logging level use:
1757  * Set nat logging level
1758  * @cliexend
1759 ?*/
1761  .path = "nat set logging level",
1762  .function = snat_set_log_level_command_fn,
1763  .short_help = "nat set logging level <level>",
1764 };
1765 
1766 /*?
1767  * @cliexpar
1768  * @cliexstart{snat ipfix logging}
1769  * To enable NAT IPFIX logging use:
1770  * vpp# nat ipfix logging
1771  * To set IPFIX exporter use:
1772  * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
1773  * @cliexend
1774 ?*/
1776  .path = "nat ipfix logging",
1778  .short_help = "nat ipfix logging disable|<enable [domain <domain-id>] "
1779  "[src-port <port>]>",
1780 };
1781 
1782 /*?
1783  * @cliexpar
1784  * @cliexstart{nat mss-clamping}
1785  * Set TCP MSS rewriting configuration
1786  * To enable TCP MSS rewriting use:
1787  * vpp# nat mss-clamping 1452
1788  * To disbale TCP MSS rewriting use:
1789  * vpp# nat mss-clamping disable
1790  * @cliexend
1791 ?*/
1793  .path = "nat mss-clamping",
1794  .short_help = "nat mss-clamping <mss-value>|disable",
1795  .function = nat_set_mss_clamping_command_fn,
1796 };
1797 
1798 /*?
1799  * @cliexpar
1800  * @cliexstart{show nat mss-clamping}
1801  * Show TCP MSS rewriting configuration
1802  * @cliexend
1803 ?*/
1805  .path = "show nat mss-clamping",
1806  .short_help = "show nat mss-clamping",
1808 };
1809 
1810 /*?
1811  * @cliexpar
1812  * @cliexstart{show nat44 hash tables}
1813  * Show NAT44 hash tables
1814  * @cliexend
1815 ?*/
1817  .path = "show nat44 hash tables",
1818  .short_help = "show nat44 hash tables [detail|verbose]",
1819  .function = nat44_show_hash_command_fn,
1820 };
1821 
1822 /*?
1823  * @cliexpar
1824  * @cliexstart{nat44 add address}
1825  * Add/delete NAT44 pool address.
1826  * To add NAT44 pool address use:
1827  * vpp# nat44 add address 172.16.1.3
1828  * vpp# nat44 add address 172.16.2.2 - 172.16.2.24
1829  * To add NAT44 pool address for specific tenant (identified by VRF id) use:
1830  * vpp# nat44 add address 172.16.1.3 tenant-vrf 10
1831  * @cliexend
1832 ?*/
1834  .path = "nat44 add address",
1835  .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
1836  "[tenant-vrf <vrf-id>] [twice-nat] [del]",
1837  .function = add_address_command_fn,
1838 };
1839 
1840 /*?
1841  * @cliexpar
1842  * @cliexstart{show nat44 summary}
1843  * Show NAT44 summary
1844  * vpp# show nat44 summary
1845  * @cliexend
1846 ?*/
1848  .path = "show nat44 summary",
1849  .short_help = "show nat44 summary",
1850  .function = nat44_show_summary_command_fn,
1851 };
1852 
1853 /*?
1854  * @cliexpar
1855  * @cliexstart{show nat44 addresses}
1856  * Show NAT44 pool addresses.
1857  * vpp# show nat44 addresses
1858  * NAT44 pool addresses:
1859  * 172.16.2.2
1860  * tenant VRF independent
1861  * 10 busy udp ports
1862  * 0 busy tcp ports
1863  * 0 busy icmp ports
1864  * 172.16.1.3
1865  * tenant VRF: 10
1866  * 0 busy udp ports
1867  * 2 busy tcp ports
1868  * 0 busy icmp ports
1869  * NAT44 twice-nat pool addresses:
1870  * 10.20.30.72
1871  * tenant VRF independent
1872  * 0 busy udp ports
1873  * 0 busy tcp ports
1874  * 0 busy icmp ports
1875  * @cliexend
1876 ?*/
1878  .path = "show nat44 addresses",
1879  .short_help = "show nat44 addresses",
1880  .function = nat44_show_addresses_command_fn,
1881 };
1882 
1883 /*?
1884  * @cliexpar
1885  * @cliexstart{set interface nat44}
1886  * Enable/disable NAT44 feature on the interface.
1887  * To enable NAT44 feature with local network interface use:
1888  * vpp# set interface nat44 in GigabitEthernet0/8/0
1889  * To enable NAT44 feature with external network interface use:
1890  * vpp# set interface nat44 out GigabitEthernet0/a/0
1891  * @cliexend
1892 ?*/
1894  .path = "set interface nat44",
1895  .function = snat_feature_command_fn,
1896  .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
1897  "[del]",
1898 };
1899 
1900 /*?
1901  * @cliexpar
1902  * @cliexstart{show nat44 interfaces}
1903  * Show interfaces with NAT44 feature.
1904  * vpp# show nat44 interfaces
1905  * NAT44 interfaces:
1906  * GigabitEthernet0/8/0 in
1907  * GigabitEthernet0/a/0 out
1908  * @cliexend
1909 ?*/
1911  .path = "show nat44 interfaces",
1912  .short_help = "show nat44 interfaces",
1914 };
1915 
1916 /*?
1917  * @cliexpar
1918  * @cliexstart{nat44 add static mapping}
1919  * Static mapping allows hosts on the external network to initiate connection
1920  * to to the local network host.
1921  * To create static mapping between local host address 10.0.0.3 port 6303 and
1922  * external address 4.4.4.4 port 3606 for TCP protocol use:
1923  * vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
1924  * If not runnig "static mapping only" NAT plugin mode use before:
1925  * vpp# nat44 add address 4.4.4.4
1926  * To create address only static mapping between local and external address use:
1927  * vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
1928  * To create ICMP static mapping between local and external with ICMP echo
1929  * identifier 10 use:
1930  * vpp# nat44 add static mapping icmp local 10.0.0.3 10 external 4.4.4.4 10
1931  * To force use of specific pool address, vrf independent
1932  * vpp# nat44 add static mapping local 10.0.0.2 1234 external 10.0.2.2 1234 twice-nat exact 10.0.1.2
1933  * @cliexend
1934 ?*/
1936  .path = "nat44 add static mapping",
1937  .function = add_static_mapping_command_fn,
1938  .short_help =
1939  "nat44 add static mapping tcp|udp|icmp local <addr> [<port|icmp-echo-id>] "
1940  "external <addr> [<port|icmp-echo-id>] [vrf <table-id>] [twice-nat|self-twice-nat] "
1941  "[out2in-only] [exact <pool-addr>] [del]",
1942 };
1943 
1944 /*?
1945  * @cliexpar
1946  * @cliexstart{nat44 add identity mapping}
1947  * Identity mapping translate an IP address to itself.
1948  * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
1949  * use:
1950  * vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
1951  * To create identity mapping for address 10.0.0.3 use:
1952  * vpp# nat44 add identity mapping 10.0.0.3
1953  * To create identity mapping for DHCP addressed interface use:
1954  * vpp# nat44 add identity mapping external GigabitEthernet0/a/0 tcp 3606
1955  * @cliexend
1956 ?*/
1958  .path = "nat44 add identity mapping",
1959  .function = add_identity_mapping_command_fn,
1960  .short_help = "nat44 add identity mapping <ip4-addr>|external <interface> "
1961  "[<protocol> <port>] [vrf <table-id>] [del]",
1962 };
1963 
1964 /*?
1965  * @cliexpar
1966  * @cliexstart{nat44 add load-balancing static mapping}
1967  * Service load balancing using NAT44
1968  * To add static mapping with load balancing for service with external IP
1969  * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
1970  * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
1971  * vpp# nat44 add load-balancing static mapping protocol tcp external 1.2.3.4:80 local 10.100.10.10:8080 probability 80 local 10.100.10.20:8080 probability 20
1972  * @cliexend
1973 ?*/
1975  .path = "nat44 add load-balancing static mapping",
1977  .short_help =
1978  "nat44 add load-balancing static mapping protocol tcp|udp "
1979  "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
1980  "probability <n> [twice-nat|self-twice-nat] [out2in-only] "
1981  "[affinity <timeout-seconds>] [del]",
1982 };
1983 
1984 /*?
1985  * @cliexpar
1986  * @cliexstart{nat44 add load-balancing static mapping}
1987  * Modify service load balancing using NAT44
1988  * To add new back-end server 10.100.10.30:8080 for service load balancing
1989  * static mapping with external IP address 1.2.3.4 and TCP port 80 use:
1990  * vpp# nat44 add load-balancing back-end protocol tcp external 1.2.3.4:80 local 10.100.10.30:8080 probability 25
1991  * @cliexend
1992 ?*/
1994  .path = "nat44 add load-balancing back-end",
1995  .function = add_lb_backend_command_fn,
1996  .short_help =
1997  "nat44 add load-balancing back-end protocol tcp|udp "
1998  "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
1999  "probability <n> [del]",
2000 };
2001 
2002 /*?
2003  * @cliexpar
2004  * @cliexstart{show nat44 static mappings}
2005  * Show NAT44 static mappings.
2006  * vpp# show nat44 static mappings
2007  * NAT44 static mappings:
2008  * local 10.0.0.3 external 4.4.4.4 vrf 0
2009  * tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
2010  * tcp vrf 0 external 1.2.3.4:80 out2in-only
2011  * local 10.100.10.10:8080 probability 80
2012  * local 10.100.10.20:8080 probability 20
2013  * tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
2014  * tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
2015  * @cliexend
2016 ?*/
2018  .path = "show nat44 static mappings",
2019  .short_help = "show nat44 static mappings",
2021 };
2022 
2023 /*?
2024  * @cliexpar
2025  * @cliexstart{nat44 add interface address}
2026  * Use NAT44 pool address from specific interfce
2027  * To add NAT44 pool address from specific interface use:
2028  * vpp# nat44 add interface address GigabitEthernet0/8/0
2029  * @cliexend
2030 ?*/
2032  .path = "nat44 add interface address",
2033  .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
2035 };
2036 
2037 /*?
2038  * @cliexpar
2039  * @cliexstart{show nat44 interface address}
2040  * Show NAT44 pool address interfaces
2041  * vpp# show nat44 interface address
2042  * NAT44 pool address interfaces:
2043  * GigabitEthernet0/a/0
2044  * NAT44 twice-nat pool address interfaces:
2045  * GigabitEthernet0/8/0
2046  * @cliexend
2047 ?*/
2049  .path = "show nat44 interface address",
2050  .short_help = "show nat44 interface address",
2052 };
2053 
2054 /*?
2055  * @cliexpar
2056  * @cliexstart{show nat44 sessions}
2057  * Show NAT44 sessions.
2058  * @cliexend
2059 ?*/
2061  .path = "show nat44 sessions",
2062  .short_help = "show nat44 sessions",
2063  .function = nat44_show_sessions_command_fn,
2064 };
2065 
2066 /*?
2067  * @cliexpar
2068  * @cliexstart{set nat44 session limit}
2069  * Set NAT44 session limit.
2070  * @cliexend
2071 ?*/
2073  .path = "set nat44 session limit",
2074  .short_help = "set nat44 session limit <limit> [vrf <table-id>]",
2076 };
2077 
2078 /*?
2079  * @cliexpar
2080  * @cliexstart{nat44 del session}
2081  * To administratively delete NAT44 session by inside address and port use:
2082  * vpp# nat44 del session in 10.0.0.3:6303 tcp
2083  * To administratively delete NAT44 session by outside address and port use:
2084  * vpp# nat44 del session out 1.0.0.3:6033 udp
2085  * @cliexend
2086 ?*/
2088  .path = "nat44 del session",
2089  .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>] [external-host <addr>:<port>]",
2090  .function = nat44_del_session_command_fn,
2091 };
2092 
2093 /*?
2094  * @cliexpar
2095  * @cliexstart{nat44 forwarding}
2096  * Enable or disable forwarding
2097  * Forward packets which don't match existing translation
2098  * or static mapping instead of dropping them.
2099  * To enable forwarding, use:
2100  * vpp# nat44 forwarding enable
2101  * To disable forwarding, use:
2102  * vpp# nat44 forwarding disable
2103  * @cliexend
2104 ?*/
2106  .path = "nat44 forwarding",
2107  .short_help = "nat44 forwarding enable|disable",
2108  .function = snat_forwarding_set_command_fn,
2109 };
2110 
2111 /*
2112  * fd.io coding-style-patch-verification: ON
2113  *
2114  * Local Variables:
2115  * eval: (c-set-style "gnu")
2116  * End:
2117  */
nat44_ed_is_interface_outside
static bool nat44_ed_is_interface_outside(snat_interface_t *i)
Check if NAT interface is outside.
Definition: nat44_ed.h:808
snat_main_s::to_resolve
snat_static_map_resolve_t * to_resolve
Definition: nat44_ed.h:572
nat_timeouts_t::tcp
struct nat_timeouts_t::@742 tcp
snat_set_workers
int snat_set_workers(uword *bitmap)
Definition: nat44_ed.c:2032
nat44_update_session_limit
int nat44_update_session_limit(u32 session_limit, u32 vrf_id)
Update NAT44 session limit flushing all data (session limit, vrf id)
Definition: nat44_ed.c:3065
set_workers_command
static vlib_cli_command_t set_workers_command
(constructor) VLIB_CLI_COMMAND (set_workers_command)
Definition: nat44_ed_cli.c:1685
nat_timeouts_t::udp
u32 udp
Definition: lib.h:84
nat_show_timeouts_command_fn
static clib_error_t * nat_show_timeouts_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:1603
nat44_ed_del_static_mapping
int nat44_ed_del_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, u16 l_port, u16 e_port, nat_protocol_t proto, u32 vrf_id, u32 sw_if_index, u32 flags)
Definition: nat44_ed.c:983
snat_main_s::outside_vrf_id
u32 outside_vrf_id
Definition: nat44_ed.h:603
nat_timeouts_t::icmp
u32 icmp
Definition: lib.h:85
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
nat44_ed_add_output_interface
int nat44_ed_add_output_interface(u32 sw_if_index)
Definition: nat44_ed.c:1848
snat_forwarding_set_command
static vlib_cli_command_t snat_forwarding_set_command
(constructor) VLIB_CLI_COMMAND (snat_forwarding_set_command)
Definition: nat44_ed_cli.c:2105
snat_main_s::static_mappings
snat_static_mapping_t * static_mappings
Definition: nat44_ed.h:531
end_addr
vl_api_address_t end_addr
Definition: ikev2_types.api:38
snat_main_s::twice_nat_addresses
snat_address_t * twice_nat_addresses
Definition: nat44_ed.h:547
nat_log_info
#define nat_log_info(...)
Definition: nat44_ed.h:888
format_ip4_address
format_function_t format_ip4_address
Definition: format.h:73
nat44_show_hash
static vlib_cli_command_t nat44_show_hash
(constructor) VLIB_CLI_COMMAND (nat44_show_hash)
Definition: nat44_ed_cli.c:1816
nat_inlines.h
add_address_command_fn
static clib_error_t * add_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:355
snat_main_s::vnet_main
vnet_main_t * vnet_main
Definition: nat44_ed.h:676
nat44_set_session_limit_command
static vlib_cli_command_t nat44_set_session_limit_command
(constructor) VLIB_CLI_COMMAND (nat44_set_session_limit_command)
Definition: nat44_ed_cli.c:2072
snat_main_per_thread_data_t::lru_pool
dlist_elt_t * lru_pool
Definition: nat44_ed.h:477
nat44_ed_add_static_mapping
int nat44_ed_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, u16 l_port, u16 e_port, nat_protocol_t proto, u32 vrf_id, u32 sw_if_index, u32 flags, ip4_address_t pool_addr, u8 *tag)
Definition: nat44_ed.c:783
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
name
string name[64]
Definition: fib.api:25
unformat_nat_protocol
unformat_function_t unformat_nat_protocol
Definition: nat64.h:507
set_interface_snat_command
static vlib_cli_command_t set_interface_snat_command
(constructor) VLIB_CLI_COMMAND (set_interface_snat_command)
Definition: nat44_ed_cli.c:1893
nat44_session_get_timeout
static u32 nat44_session_get_timeout(snat_main_t *sm, snat_session_t *s)
Definition: nat44_ed_inlines.h:239
nat44_ed_del_session
int nat44_ed_del_session(snat_main_t *sm, ip4_address_t *addr, u16 port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 vrf_id, int is_in)
Delete NAT44 endpoint-dependent session.
Definition: nat44_ed.c:3465
nat44_ed_enable_disable_command_fn
static clib_error_t * nat44_ed_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:33
snat_main_s::translation_buckets
u32 translation_buckets
Definition: nat44_ed.h:599
nat_protocol_t
nat_protocol_t
Definition: lib.h:63
nat44_show_addresses_command
static vlib_cli_command_t nat44_show_addresses_command
(constructor) VLIB_CLI_COMMAND (nat44_show_addresses_command)
Definition: nat44_ed_cli.c:1877
snat_main_s::interfaces
snat_interface_t * interfaces
Definition: nat44_ed.h:541
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
u8
#define u8
Padding.
Definition: clib.h:121
vlib_cli_command_t::path
char * path
Definition: cli.h:96
nat_affinity_main_t::affinity_hash
clib_bihash_16_8_t affinity_hash
Definition: nat44_ed_affinity.h:57
probability
u8 probability
Definition: nat44_ed.api:1052
NAT_SM_FLAG_ADDR_ONLY
#define NAT_SM_FLAG_ADDR_ONLY
Definition: nat44_ed.h:192
fib_table.h
set_frame_queue_nelts_command
static vlib_cli_command_t set_frame_queue_nelts_command
(constructor) VLIB_CLI_COMMAND (set_frame_queue_nelts_command)
Definition: nat44_ed_cli.c:1747
u16
unsigned short u16
Definition: types.h:57
nat_set_mss_clamping_command_fn
static clib_error_t * nat_set_mss_clamping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:308
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
nat44_show_summary_command
static vlib_cli_command_t nat44_show_summary_command
(constructor) VLIB_CLI_COMMAND (nat44_show_summary_command)
Definition: nat44_ed_cli.c:1847
snat_main_s::workers
u32 * workers
Definition: nat44_ed.h:518
snat_ipfix_logging_enable_disable_command
static vlib_cli_command_t snat_ipfix_logging_enable_disable_command
(constructor) VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command)
Definition: nat44_ed_cli.c:1775
port
u16 port
Definition: lb_types.api:73
log.h
NAT port/address allocation lib.
snat_add_interface_address_command
static vlib_cli_command_t snat_add_interface_address_command
(constructor) VLIB_CLI_COMMAND (snat_add_interface_address_command)
Definition: nat44_ed_cli.c:2031
nat44_ed_add_lb_static_mapping
int nat44_ed_add_lb_static_mapping(ip4_address_t e_addr, u16 e_port, nat_protocol_t proto, nat44_lb_addr_port_t *locals, u32 flags, u8 *tag, u32 affinity)
Definition: nat44_ed.c:1136
nat44_show_lru_summary
static void nat44_show_lru_summary(vlib_main_t *vm, snat_main_per_thread_data_t *tsm, u64 now, u64 sess_timeout_time)
Definition: nat44_ed_cli.c:456
snat_main_s::timeouts
nat_timeouts_t timeouts
Definition: nat44_ed.h:608
snat_main_s::addresses
snat_address_t * addresses
Definition: nat44_ed.h:545
nat_timeouts_t::transitory
u32 transitory
Definition: lib.h:81
unformat_input_t
struct _unformat_input_t unformat_input_t
start_addr
vl_api_address_t start_addr
Definition: ikev2_types.api:37
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
snat_main_s::static_mapping_by_external
clib_bihash_8_8_t static_mapping_by_external
Definition: nat44_ed.h:528
vlib_worker_threads
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:35
format_snat_static_mapping
format_function_t format_snat_static_mapping
Definition: nat44_ed.h:713
nat44_ed_add_interface
int nat44_ed_add_interface(u32 sw_if_index, u8 is_inside)
Definition: nat44_ed.c:1635
NAT_SM_FLAG_OUT2IN_ONLY
#define NAT_SM_FLAG_OUT2IN_ONLY
Definition: nat44_ed.h:194
add_lb_static_mapping_command
static vlib_cli_command_t add_lb_static_mapping_command
(constructor) VLIB_CLI_COMMAND (add_lb_static_mapping_command)
Definition: nat44_ed_cli.c:1974
error
Definition: cJSON.c:88
NAT_SM_FLAG_IDENTITY_NAT
#define NAT_SM_FLAG_IDENTITY_NAT
Definition: nat44_ed.h:191
snat_main_s::log_level
u8 log_level
Definition: nat44_ed.h:657
snat_main_s::forwarding_enabled
u8 forwarding_enabled
Definition: nat44_ed.h:590
log_level
log_level
Definition: vpe_types.api:33
add_lb_static_mapping_command_fn
static clib_error_t * add_lb_static_mapping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:1074
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
snat_address_t
Definition: nat44_ed.h:355
foreach_nat_protocol
@ foreach_nat_protocol
Definition: lib.h:66
set_timeout_command
static vlib_cli_command_t set_timeout_command
(constructor) VLIB_CLI_COMMAND (set_timeout_command)
Definition: nat44_ed_cli.c:1716
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
count
u8 count
Definition: dhcp.api:208
set_timeout_command_fn
static clib_error_t * set_timeout_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:1570
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
snat_main_s::per_thread_data
snat_main_per_thread_data_t * per_thread_data
Definition: nat44_ed.h:522
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
nat_timeouts_t::established
u32 established
Definition: lib.h:80
nat44_ed_del_output_interface
int nat44_ed_del_output_interface(u32 sw_if_index)
Definition: nat44_ed.c:1946
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
snat_main_s::flow_hash
clib_bihash_16_8_t flow_hash
Definition: nat44_ed.h:538
nat44_ed_del_interface_address
int nat44_ed_del_interface_address(u32 sw_if_index, u8 twice_nat)
Definition: nat44_ed.c:3401
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
nat44_show_addresses_command_fn
static clib_error_t * nat44_show_addresses_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:624
snat_main_s::first_worker_index
u32 first_worker_index
Definition: nat44_ed.h:517
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
fib_table_t_::ft_table_id
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:92
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
nat_proto_to_ip_proto
static_always_inline u8 nat_proto_to_ip_proto(nat_protocol_t nat_proto)
Definition: inlines.h:37
nat44_del_session_command
static vlib_cli_command_t nat44_del_session_command
(constructor) VLIB_CLI_COMMAND (nat44_del_session_command)
Definition: nat44_ed_cli.c:2087
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
print
static unsigned char * print(const cJSON *const item, cJSON_bool format, const internal_hooks *const hooks)
Definition: cJSON.c:1183
vec_foreach_index
#define vec_foreach_index(var, v)
Iterate over vector indices.
Definition: vec_bootstrap.h:220
clib_bitmap_free
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
uword
u64 uword
Definition: types.h:112
nat44_show_hash_command_fn
static clib_error_t * nat44_show_hash_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:273
NAT_SM_FLAG_TWICE_NAT
#define NAT_SM_FLAG_TWICE_NAT
Definition: nat44_ed.h:190
add_lb_backend_command
static vlib_cli_command_t add_lb_backend_command
(constructor) VLIB_CLI_COMMAND (add_lb_backend_command)
Definition: nat44_ed_cli.c:1993
NAT_SM_FLAG_EXACT_ADDRESS
#define NAT_SM_FLAG_EXACT_ADDRESS
Definition: nat44_ed.h:193
snat_add_interface_address_command_fn
static clib_error_t * snat_add_interface_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:1298
ipfix_logging.h
nat_set_mss_clamping_command
static vlib_cli_command_t nat_set_mss_clamping_command
(constructor) VLIB_CLI_COMMAND (nat_set_mss_clamping_command)
Definition: nat44_ed_cli.c:1792
add_lb_backend_command_fn
static clib_error_t * add_lb_backend_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:1196
src_port
vl_api_ip_port_and_mask_t src_port
Definition: flow_types.api:91
set_frame_queue_nelts_command_fn
static clib_error_t * set_frame_queue_nelts_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:1620
NAT_LOG_NONE
@ NAT_LOG_NONE
Definition: nat_types.api:28
f64
double f64
Definition: types.h:142
nat44_show_static_mappings_command
static vlib_cli_command_t nat44_show_static_mappings_command
(constructor) VLIB_CLI_COMMAND (nat44_show_static_mappings_command)
Definition: nat44_ed_cli.c:2017
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
dlist_elt_t
Definition: dlist.h:28
nat44_lb_addr_port_t
Definition: nat44_ed.h:379
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
format_snat_static_map_to_resolve
format_function_t format_snat_static_map_to_resolve
Definition: nat44_ed.h:714
ip4_address_t
Definition: ip4_packet.h:50
NAT_LOG_DEBUG
@ NAT_LOG_DEBUG
Definition: nat_types.api:33
nat44_show_sessions_command
static vlib_cli_command_t nat44_show_sessions_command
(constructor) VLIB_CLI_COMMAND (nat44_show_sessions_command)
Definition: nat44_ed_cli.c:2060
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
nat_show_timeouts_command
static vlib_cli_command_t nat_show_timeouts_command
(constructor) VLIB_CLI_COMMAND (nat_show_timeouts_command)
Definition: nat44_ed_cli.c:1735
nat44_ed_add_del_lb_static_mapping_local
int nat44_ed_add_del_lb_static_mapping_local(ip4_address_t e_addr, u16 e_port, ip4_address_t l_addr, u16 l_port, nat_protocol_t proto, u32 vrf_id, u8 probability, u8 is_add)
Definition: nat44_ed.c:1399
snat_main_s
Definition: nat44_ed.h:513
snat_main_per_thread_data_t::sessions
snat_session_t * sessions
Definition: nat44_ed.h:471
add_identity_mapping_command_fn
static clib_error_t * add_identity_mapping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:976
nat44_plugin_enable
int nat44_plugin_enable(nat44_config_t c)
Definition: nat44_ed.c:2364
nat44_ed_add_address
int nat44_ed_add_address(ip4_address_t *addr, u32 vrf_id, u8 twice_nat)
Definition: nat44_ed.c:388
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
nat44_ed_set_frame_queue_nelts
int nat44_ed_set_frame_queue_nelts(u32 frame_queue_nelts)
Definition: nat44_ed.c:2058
nat44_ed_enable_disable_command
static vlib_cli_command_t nat44_ed_enable_disable_command
(constructor) VLIB_CLI_COMMAND (nat44_ed_enable_disable_command)
Definition: nat44_ed_cli.c:1670
add_address_command
static vlib_cli_command_t add_address_command
(constructor) VLIB_CLI_COMMAND (add_address_command)
Definition: nat44_ed_cli.c:1833
increment_v4_address
static void increment_v4_address(ip4_address_t *a)
Definition: nat_inlines.h:23
nat44_show_interfaces_command
static vlib_cli_command_t nat44_show_interfaces_command
(constructor) VLIB_CLI_COMMAND (nat44_show_interfaces_command)
Definition: nat44_ed_cli.c:1910
nat44_ed_del_lb_static_mapping
int nat44_ed_del_lb_static_mapping(ip4_address_t e_addr, u16 e_port, nat_protocol_t proto, u32 flags)
Definition: nat44_ed.c:1279
NAT44_ED_EXPECTED_ARGUMENT
#define NAT44_ED_EXPECTED_ARGUMENT
Definition: nat44_ed_cli.c:30
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
nat44_ed_affinity.h
NAT plugin client-IP based session affinity for load-balancing.
nat44_show_interfaces_command_fn
static clib_error_t * nat44_show_interfaces_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:801
nat_show_mss_clamping_command
static vlib_cli_command_t nat_show_mss_clamping_command
(constructor) VLIB_CLI_COMMAND (nat_show_mss_clamping_command)
Definition: nat44_ed_cli.c:1804
icmp
icmp
Definition: map.api:387
nat_ipfix_logging_enable_disable
int nat_ipfix_logging_enable_disable(int enable, u32 domain_id, u16 src_port)
Enable/disable NAT plugin IPFIX logging.
Definition: ipfix_logging.c:1524
nat44_ed_inlines.h
nat44_del_session_command_fn
static clib_error_t * nat44_del_session_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:1462
snat_main_s::max_translations_per_fib
u32 * max_translations_per_fib
Definition: nat44_ed.h:601
set_workers_command_fn
static clib_error_t * set_workers_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:111
nat44_config_t
Definition: nat44_ed.h:59
u64
unsigned long u64
Definition: types.h:89
format_vnet_sw_if_index_name
format_function_t format_vnet_sw_if_index_name
Definition: interface_funcs.h:458
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:462
nat_reset_timeouts
static_always_inline void nat_reset_timeouts(nat_timeouts_t *timeouts)
Definition: lib.h:90
fib_table_get
fib_table_t * fib_table_get(fib_node_index_t index, fib_protocol_t proto)
Get a pointer to a FIB table.
Definition: fib_table.c:29
nat44_ed_is_interface_inside
static bool nat44_ed_is_interface_inside(snat_interface_t *i)
Check if NAT interface is inside.
Definition: nat44_ed.h:798
nat44_show_static_mappings_command_fn
static clib_error_t * nat44_show_static_mappings_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:1278
u32
unsigned int u32
Definition: types.h:88
snat_main_s::auto_add_sw_if_indices
u32 * auto_add_sw_if_indices
Definition: nat44_ed.h:550
snat_main_s::mss_clamping
u16 mss_clamping
Definition: nat44_ed.h:611
snat_set_log_level_command_fn
static clib_error_t * snat_set_log_level_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:186
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
snat_main_s::static_mapping_by_local
clib_bihash_8_8_t static_mapping_by_local
Definition: nat44_ed.h:525
nat44_ed.h
vlib_worker_thread_t
Definition: threads.h:81
nat_show_workers_command
static vlib_cli_command_t nat_show_workers_command
(constructor) VLIB_CLI_COMMAND (nat_show_workers_command)
Definition: nat44_ed_cli.c:1701
nat44_show_summary_command_fn
static clib_error_t * nat44_show_summary_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:490
pool_elts
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127
snat_feature_command_fn
static clib_error_t * snat_feature_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:662
nat44_set_session_limit_command_fn
static clib_error_t * nat44_set_session_limit_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:1424
snat_ipfix_logging_enable_disable_command_fn
static clib_error_t * snat_ipfix_logging_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:219
snat_main_s::inside_vrf_id
u32 inside_vrf_id
Definition: nat44_ed.h:605
nat_show_mss_clamping_command_fn
static clib_error_t * nat_show_mss_clamping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:341
add_static_mapping_command
static vlib_cli_command_t add_static_mapping_command
(constructor) VLIB_CLI_COMMAND (add_static_mapping_command)
Definition: nat44_ed_cli.c:1935
snat_set_log_level_command
static vlib_cli_command_t snat_set_log_level_command
(constructor) VLIB_CLI_COMMAND (snat_set_log_level_command)
Definition: nat44_ed_cli.c:1760
now
f64 now
Definition: nat44_ei_out2in.c:710
NAT_SM_FLAG_SWITCH_ADDRESS
#define NAT_SM_FLAG_SWITCH_ADDRESS
Definition: nat44_ed.h:196
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
snat_main
snat_main_t snat_main
Definition: nat44_ed.c:41
NAT_SM_FLAG_SELF_TWICE_NAT
#define NAT_SM_FLAG_SELF_TWICE_NAT
Definition: nat44_ed.h:189
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
snat_main_s::num_workers
u32 num_workers
Definition: nat44_ed.h:516
snat_interface_t
Definition: nat44_ed.h:444
snat_address_t::fib_index
u32 fib_index
Definition: nat44_ed.h:358
i
int i
Definition: flowhash_template.h:376
vlib_worker_thread_t::name
u8 * name
Definition: threads.h:98
nat44_plugin_disable
int nat44_plugin_disable()
Definition: nat44_ed.c:2457
snat_static_mapping_t
Definition: nat44_ed.h:413
rv
int __clib_unused rv
Definition: application.c:491
unformat_ip4_address
unformat_function_t unformat_ip4_address
Definition: format.h:68
vrf_id
u32 vrf_id
Definition: nat44_ed.api:1053
add_identity_mapping_command
static vlib_cli_command_t add_identity_mapping_command
(constructor) VLIB_CLI_COMMAND (add_identity_mapping_command)
Definition: nat44_ed_cli.c:1957
vlib_time_now
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:327
snat_static_map_resolve_t
Definition: nat44_ed.h:450
snat_address_t::addr
ip4_address_t addr
Definition: nat44_ed.h:357
snat_main_per_thread_data_t
Definition: nat44_ed.h:468
nat_show_workers_commnad_fn
static clib_error_t * nat_show_workers_commnad_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:165
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
nat44_show_interface_address_command
static vlib_cli_command_t nat44_show_interface_address_command
(constructor) VLIB_CLI_COMMAND (nat44_show_interface_address_command)
Definition: nat44_ed_cli.c:2048
vlib_cli_command_t
Definition: cli.h:92
snat_main_s::static_mapping_only
u8 static_mapping_only
Definition: nat44_ed.h:593
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
nat44_ed_del_interface
int nat44_ed_del_interface(u32 sw_if_index, u8 is_inside)
Definition: nat44_ed.c:1743
snat_forwarding_set_command_fn
static clib_error_t * snat_forwarding_set_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:1528
add_static_mapping_command_fn
static clib_error_t * add_static_mapping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:833
nat44_show_sessions_command_fn
static clib_error_t * nat44_show_sessions_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:1382
nat44_ed_add_interface_address
int nat44_ed_add_interface_address(u32 sw_if_index, u8 twice_nat)
Definition: nat44_ed.c:3362
unformat_bitmap_list
__clib_export uword unformat_bitmap_list(unformat_input_t *input, va_list *va)
unformat a list of bit ranges into a bitmap (eg "0-3,5-7,11" )
Definition: bitmap.c:55
nat44_ed_del_address
int nat44_ed_del_address(ip4_address_t addr, u8 delete_sm, u8 twice_nat)
Definition: nat44_ed.c:449
snat_main_s::auto_add_sw_if_indices_twice_nat
u32 * auto_add_sw_if_indices_twice_nat
Definition: nat44_ed.h:551
format_snat_session
format_function_t format_snat_session
Definition: nat44_ed.h:715
nat_affinity_main
nat_affinity_main_t nat_affinity_main
Definition: nat44_ed_affinity.c:25
nat_affinity_main_t
Definition: nat44_ed_affinity.h:54
nat44_show_interface_address_command_fn
static clib_error_t * nat44_show_interface_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ed_cli.c:1357
snat_main_s::enabled
u8 enabled
Definition: nat44_ed.h:674
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
snat_main_s::output_feature_interfaces
snat_interface_t * output_feature_interfaces
Definition: nat44_ed.h:542
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105