FD.io VPP  v16.12-rc0-308-g931be3a
Vector Packet Processing
cnat_show.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * cnat_show.c - translation database definitions
4  *
5  * Copyright (c) 2007-2014 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <vlib/vlib.h>
21 #include <vnet/vnet.h>
22 #include <vppinfra/vec.h>
23 #include <vppinfra/bitmap.h>
24 #include <vppinfra/hash.h>
25 #include <vppinfra/pool.h>
26 #include <vppinfra/clib.h>
27 
28 #include "cnat_db.h"
29 #include "cnat_config.h"
30 #include "cnat_global.h"
31 #include "cnat_logging.h"
32 #include "spp_ctx.h"
33 #include "spp_timers.h"
34 #include "platform_common.h"
35 #include "cnat_syslog.h"
36 #include "cnat_v4_pptp_alg.h"
37 #include "platform_common.h"
38 
39 #ifndef TOBE_PORTED
40 /* The following variable is in cnat_config_msg_handler.c which
41  * is to be ported later.. if required
42  */
44 #endif
45 
46 #ifndef NO_BULK_LOGGING
47 #define CNAT_MY_VRFMAP_PRINT \
48 PLATFORM_DEBUG_PRINT("i-uidx 0x%x o-uidx 0x%x i-vrfid 0x%x o-vrfid 0x%x\n" \
49  "status %d del time 0x%x tcp mss 0x%x pm list 0x%x\n" \
50  "bulk size %d\n" \
51  "ip n:1 %d\n" \
52  "NFV9 template index 0x%x\n" \
53  "SYSLOG template index 0x%x\n" \
54  "Netflow Session Logging %d \n" \
55  "Syslog Session Logging %d \n" \
56  "PCP Server 0x%x, Port %u \n", \
57  my_vrfmap->i_vrf, my_vrfmap->o_vrf, my_vrfmap->i_vrf_id, \
58  my_vrfmap->o_vrf_id, my_vrfmap->status, my_vrfmap->delete_time, \
59  my_vrfmap->tcp_mss, my_vrfmap->portmap_list, \
60  BULKSIZE_FROM_VRFMAP(my_vrfmap), \
61  my_vrfmap->ip_n_to_1, \
62  my_vrfmap->nfv9_logging_index, \
63  my_vrfmap->syslog_logging_index,\
64  my_vrfmap->nf_logging_policy, \
65  my_vrfmap->syslog_logging_policy, \
66  my_vrfmap->pcp_server_addr, \
67  my_vrfmap->pcp_server_port);
68 #else
69 #define CNAT_MY_VRFMAP_PRINT \
70 PLATFORM_DEBUG_PRINT("i-uidx 0x%x o-uidx 0x%x i-vrfid 0x%x o-vrfid 0x%x\n" \
71  "status %d del time 0x%x tcp mss 0x%x pm list 0x%x\n" \
72  "NFV9 template index 0x%x\n ip n:1 %d\n", \
73  my_vrfmap->i_vrf, my_vrfmap->o_vrf, my_vrfmap->i_vrf_id, \
74  my_vrfmap->o_vrf_id, my_vrfmap->status, my_vrfmap->delete_time, \
75  my_vrfmap->tcp_mss, my_vrfmap->portmap_list, \
76  my_vrfmap->nfv9_logging_index, my_vrfmap->ip_n_to_1);
77 #endif /* NO_BULK_LOGGING */
78 
79 #define CNAT_MY_LOGGING_INFO_PRINT \
80 do { \
81  cnat_syslog_logging_info_t *my_syslog_info = 0; \
82  PLATFORM_DEBUG_PRINT("SYSLOG config: \n"); \
83  pool_foreach (my_syslog_info, cnat_syslog_logging_info_pool, ({ \
84  if (my_syslog_info->i_vrf == my_vrfmap->i_vrf) { \
85  PLATFORM_DEBUG_PRINT(" \
86  ipv4[0x%x], port[%u], hostname[%s]\n", \
87  my_syslog_info->ipv4_address, my_syslog_info->port, \
88  my_syslog_info->header_hostname); \
89  break; \
90  } \
91  })); \
92 }while (0) \
93 ;
94 
95 
96 void printf_ipv4(u32 ad)
97 {
98  u8 a __attribute__((unused)), b __attribute__((unused)),
99  c __attribute__((unused)), d __attribute__((unused));
100 
101  a = ad>>24;
102  b = (ad>>16) & 0xFF;
103  c = (ad>>8) & 0xFF;
104  d = (ad>>0) & 0xFF;
105 
106  PLATFORM_DEBUG_PRINT("%d.%d.%d.%d", a, b, c, d);
107 }
109 {
110  PLATFORM_DEBUG_PRINT("Main DB entry at %p, index %ld dst_ip %x\n",
111  db, db - cnat_main_db, db->dst_ipv4);
112  /* only dump hash next index if it's non EMPTY */
113  if (db->out2in_hash.next != EMPTY || db->in2out_hash.next != EMPTY)
114  PLATFORM_DEBUG_PRINT("out2in hash %u, in2out hash %u\n",
115  db->out2in_hash.next,
116  db->in2out_hash.next);
117  PLATFORM_DEBUG_PRINT("out2in key ipv4 0x%08X, port 0x%04X (%5d), vrf %d, protocol %s\n",
118  db->out2in_key.k.ipv4,
119  db->out2in_key.k.port,
120  db->out2in_key.k.port,
122  (db->out2in_key.k.vrf & CNAT_PRO_MASK) == CNAT_UDP ? "UDP" :
123  ((db->in2out_key.k.vrf & CNAT_PRO_MASK) == CNAT_TCP ? "TCP" :
124  ((db->in2out_key.k.vrf & CNAT_PRO_MASK) == CNAT_ICMP ? "ICMP" : "PPTP ALG")));
125 
126  PLATFORM_DEBUG_PRINT("in2out key ipv4 0x%08X, port 0x%04X (%5d), vrf %d, protocol %s\n",
127  db->in2out_key.k.ipv4,
128  db->in2out_key.k.port,
129  db->in2out_key.k.port,
131  (db->in2out_key.k.vrf & CNAT_PRO_MASK) == CNAT_UDP ? "UDP" :
132  ((db->in2out_key.k.vrf & CNAT_PRO_MASK) == CNAT_TCP ? "TCP" :
133  ((db->in2out_key.k.vrf & CNAT_PRO_MASK) == CNAT_ICMP ? "ICMP" : "UNKNOWN")));
134 
135  PLATFORM_DEBUG_PRINT("user %d, user ports (nxt) %d (prev) %d, vrfmap_index 0x%x\n",
136  db->user_index, db->user_ports.next, db->user_ports.prev,
137  db->vrfmap_index);
138  PLATFORM_DEBUG_PRINT("timeout %d \n", db->timeout);
139  PLATFORM_DEBUG_PRINT("flags 0x%x ", db->flags);
140 
141  if (db->flags & CNAT_DB_FLAG_TCP_ACTIVE) {
142  PLATFORM_DEBUG_PRINT(" TCP_ACTIVE ");
143  } else if (db->flags & CNAT_DB_FLAG_UDP_ACTIVE) {
144  PLATFORM_DEBUG_PRINT(" UDP_ACTIVE ");
145  } else if (db->flags & CNAT_DB_FLAG_STATIC_PORT) {
146  PLATFORM_DEBUG_PRINT(" STATIC_PORT ");
147  }
148 
149  PLATFORM_DEBUG_PRINT(" ALG dlt0 0x%02X dlt1 0x%02X\n", db->alg.alg_dlt[0], db->alg.alg_dlt[1]);
150  PLATFORM_DEBUG_PRINT("\n");
151 
152  PLATFORM_DEBUG_PRINT("out2in_pkts: %u\n", db->out2in_pkts);
153  PLATFORM_DEBUG_PRINT("in2out_pkts: %u\n", db->in2out_pkts);
154  PLATFORM_DEBUG_PRINT("entry_expires: %u current time: %u\n", db->entry_expires, cnat_current_time);
155  PLATFORM_DEBUG_PRINT("-------------------------\n");
156 }
157 
159 {
160  u32 db_entry_index, first_db_entry_index;
162 
163  PLATFORM_DEBUG_PRINT("User DB entry at %p, index %ld\n",
164  up, up - cnat_user_db);
165  PLATFORM_DEBUG_PRINT("translation list head index %u, %u translations portmapindex 0x%x\n",
167  up->ntranslations, up->portmap_index);
168  PLATFORM_DEBUG_PRINT("source ipv4 0x%x, source port 0x%x, vrf %d\n",
169  up->key.k.ipv4,
170  up->key.k.port,
171  up->key.k.vrf);
172  first_db_entry_index = db_entry_index = up->translation_list_head_index;
173  if (first_db_entry_index != EMPTY) {
174  PLATFORM_DEBUG_PRINT("Port translation list:\n");
175  do {
176  PLATFORM_DEBUG_PRINT(" [%d]\n", db_entry_index);
177  ep = cnat_main_db + db_entry_index;
178  db_entry_index = ep->user_ports.next;
179  } while (first_db_entry_index != db_entry_index);
180  } else {
181  PLATFORM_DEBUG_PRINT("WARNING: empty translation list!\n");
182  }
183  PLATFORM_DEBUG_PRINT("-------------------------\n");
184 }
185 
187 {
188  u32 db_entry_index, first_db_entry_index;
189  u32 total_entries = 0;
190 
191  PLATFORM_DEBUG_PRINT("User DB entry at %p, index %ld\n",
192  up, up - cnat_user_db);
193  PLATFORM_DEBUG_PRINT("translation list head index %u, %u translations portmapindex 0x%x\n",
195  up->ntranslations, up->portmap_index);
196  PLATFORM_DEBUG_PRINT("source ipv4 0x%x, source port 0x%x, vrf %d\n",
197  up->key.k.ipv4,
198  up->key.k.port,
199  up->key.k.vrf);
200  first_db_entry_index = db_entry_index = up->translation_list_head_index;
201  if (first_db_entry_index != EMPTY) {
202  PLATFORM_DEBUG_PRINT("Port translation list:\n");
203  do {
204  total_entries++;
205  } while (first_db_entry_index != db_entry_index);
206  PLATFORM_DEBUG_PRINT("TOTAL_ENTRIES: %d\n", total_entries);
207  } else {
208  PLATFORM_DEBUG_PRINT("WARNING: empty translation list!\n");
209  }
210  PLATFORM_DEBUG_PRINT("-------------------------\n");
211 }
212 
213 /* for internal development and UT only */
214 void cnat_db_dump_main_by_index (int argc, unsigned long *argv)
215 {
216  u32 index, i, len;
217  u32 active_count, scan_count;
218 
219  if (argc != 1) {
220  PLATFORM_DEBUG_PRINT("invalid input %d\n", argc);
221  return;
222  }
223 
224  index = argv[0];
225 
226  len = vec_len(cnat_main_db);
227 
228  active_count = pool_elts(cnat_main_db);
229 
230  if (index >= active_count) {
231  PLATFORM_DEBUG_PRINT("Index %u >= total active entries %u\n", index, active_count);
232  return;
233  }
234 
235  scan_count = 0;
236  for (i=0; i< len; i++) {
237  if(pool_is_free_index(cnat_main_db, i)) continue;
238 
239  if (index == scan_count) {
241  break;
242  }
243  scan_count++;
244  }
245 }
246 
247 void cnat_db_dump_main (int argc, unsigned long *argv)
248 {
250 
251  pool_foreach(db, cnat_main_db, ({
253  }));
254 }
255 
256 void cnat_db_dump_main_summary (int argc, unsigned long *argv)
257 {
259  u32 num_entries = 0;
260 
261  pool_foreach(db, cnat_main_db, ({
262  num_entries++;
263  }));
264 
265  PLATFORM_DEBUG_PRINT("\nNum main entries %d\n", num_entries);
266 }
267 
268 void cnat_db_dump_user (int argc, unsigned long *argv)
269 {
271 
272  pool_foreach(up, cnat_user_db, ({
274  }));
275 }
276 
277 void cnat_db_dump_user_summary (int argc, unsigned long *argv)
278 {
280 
281  pool_foreach(up, cnat_user_db, ({
283  }));
284 }
285 
286 void cnat_db_dump_hashes (int argc, unsigned long *argv)
287 {
288  int i;
289 
290  PLATFORM_DEBUG_PRINT("Main DB out2in hash:\n");
291  for (i = 0; i < vec_len(cnat_out2in_hash); i++) {
292  if (cnat_out2in_hash[i].next != EMPTY) {
293  PLATFORM_DEBUG_PRINT("[%d]: %u\n", i, cnat_out2in_hash[i].next);
294  }
295  }
296  PLATFORM_DEBUG_PRINT("Main DB in2out hash:\n");
297  for (i = 0; i < vec_len(cnat_in2out_hash); i++) {
298  if (cnat_in2out_hash[i].next != EMPTY) {
299  PLATFORM_DEBUG_PRINT("[%d]: %u\n", i, cnat_in2out_hash[i].next);
300  }
301  }
302 
303  PLATFORM_DEBUG_PRINT("User hash:\n");
304  for (i = 0; i < vec_len(cnat_user_hash); i++) {
305  if (cnat_user_hash[i].next != EMPTY) {
306  PLATFORM_DEBUG_PRINT("[%d]: %u\n", i, cnat_user_hash[i].next);
307  }
308  }
309  PLATFORM_DEBUG_PRINT("-------------------------\n");
310 }
311 
312 
313 #ifdef OLD_VRFMAP
314 
315 void cnat_db_dump_cdb (int argc, unsigned long *argv)
316 {
317  int k;
318  int verbose=0;
319  int all = 0;
320 
321  if (argc > 0) {
322  verbose = 1;
323  }
324 
325  if (argc > 1) {
326  all = 1;
327  }
328 
329  PLATFORM_DEBUG_PRINT ("%d vrfmap vectors \n", vec_len(cnat_portmap_by_vrf));
330 
331  for (k = 0; k < vec_len(cnat_portmap_by_vrf); k++) {
332  PLATFORM_DEBUG_PRINT("index%d: status %d i_vrf 0x%x o_vrf 0x%x\n", k,
333  cnat_portmap_by_vrf[k].status,
334  cnat_portmap_by_vrf[k].i_vrf,
335  cnat_portmap_by_vrf[k].o_vrf);
336  cnat_db_dump_address_portmap(verbose, all,
337  cnat_portmaps[k],
339  }
340 }
341 
342 void cnat_db_dump_i_vrf (int argc, unsigned long *argv)
343 {
344  u32 k;
345  u32 vrf =0;
346  int verbose=0;
347  int all = 0;
348 
349  if (!argc) {
350  PLATFORM_DEBUG_PRINT("need vrf input ,return\n");
351  return;
352  }
353 
354  if (argc > 0) {
355  vrf = argv[0];
356  }
357 
358  if (argc > 1) {
359  verbose = 1;
360  }
361 
362  if (argc > 2) {
363  all = 1;
364  }
365 
366  PLATFORM_DEBUG_PRINT ("%d vrfmap vectors \n", vec_len(cnat_portmap_by_vrf));
367 
368  for (k = 0; k < vec_len(cnat_portmap_by_vrf); k++) {
369  if (cnat_portmap_by_vrf[k].i_vrf == vrf) {
370  PLATFORM_DEBUG_PRINT("%d: i_vrf 0x%x o_vrf 0x%x\n", k,
371  cnat_portmap_by_vrf[k].i_vrf,
372  cnat_portmap_by_vrf[k].o_vrf);
373  cnat_db_dump_address_portmap(verbose, all,
374  cnat_portmaps[k],
376  return;
377  }
378  }
379  PLATFORM_DEBUG_PRINT("not found\n");
380 }
381 
382 void cnat_db_dump_o_vrf (int argc, unsigned long *argv)
383 {
384  u32 k;
385  int verbose=0;
386  int all = 0;
387  u32 vrf =0;
388 
389  if (!argc) {
390  PLATFORM_DEBUG_PRINT("need vrf input ,return\n");
391  return;
392  }
393 
394  if (argc > 0) {
395  vrf = argv[0];
396  }
397 
398  if (argc > 1) {
399  verbose = 1;
400  }
401 
402  if (argc > 2) {
403  all = 1;
404  }
405 
406  PLATFORM_DEBUG_PRINT ("%d vrfmap vectors \n", vec_len(cnat_portmap_by_vrf));
407 
408  for (k = 0; k < vec_len(cnat_portmap_by_vrf); k++) {
409  if (cnat_portmap_by_vrf[k].o_vrf == vrf) {
410  PLATFORM_DEBUG_PRINT("index%d: status %d i_vrf 0x%x o_vrf 0x%x\n", k,
411  cnat_portmap_by_vrf[k].status,
412  cnat_portmap_by_vrf[k].i_vrf,
413  cnat_portmap_by_vrf[k].o_vrf);
414  cnat_db_dump_address_portmap(verbose, all,
415  cnat_portmaps[k],
417  return;
418  }
419  }
420  PLATFORM_DEBUG_PRINT("not found\n");
421 }
422 #endif
423 
424 #ifdef TOBE_PORTED
425 /* This does not seem to be used */
426 void cnat_db_mem_usage_cmd (int argc, unsigned long *argv)
427 {
428  pool_header_t * p;
429  _VEC *_v;
430  u32 bitmap_bytes=0, free_indices_bytes=0, vec_bytes=0, total_bytes=0;
431 
432  if (cnat_main_db) {
434  if (p->free_bitmap) {
435  _v = _vec_find(p->free_bitmap);
436  bitmap_bytes = _v->alen;
437  } else {
438  bitmap_bytes = 0;
439  }
440  if (p->free_indices) {
441  _v = _vec_find(p->free_indices);
442  free_indices_bytes = _v->alen;
443  } else {
444  free_indices_bytes = 0;
445  }
446  _v = _vec_find(cnat_main_db);
447  vec_bytes = _v->alen;
448  } else {
449  vec_bytes = 0;
450  }
451 
452  total_bytes = bitmap_bytes + free_indices_bytes + vec_bytes;
453 
454  PLATFORM_DEBUG_PRINT ("Main DB: %d total bytes, %d bitmap, %d indices, %d vec\n",
455  total_bytes, bitmap_bytes, free_indices_bytes, vec_bytes);
456  PLATFORM_DEBUG_PRINT (" vector length %d\n", vec_len(cnat_main_db));
457 
458  if (cnat_user_db) {
460  if (p->free_bitmap) {
461  _v = _vec_find(p->free_bitmap);
462  bitmap_bytes = _v->alen;
463  } else {
464  bitmap_bytes = 0;
465  }
466  if (p->free_indices) {
467  _v = _vec_find(p->free_indices);
468  free_indices_bytes = _v->alen;
469  } else {
470  free_indices_bytes = 0;
471  }
472  _v = _vec_find(cnat_user_db);
473  vec_bytes = _v->alen;
474  } else {
475  vec_bytes = 0;
476  }
477 
478  total_bytes = bitmap_bytes + free_indices_bytes + vec_bytes;
479 
480  PLATFORM_DEBUG_PRINT ("User DB: %d total bytes, %d bitmap, %d indices, %d vec\n",
481  total_bytes, bitmap_bytes, free_indices_bytes, vec_bytes);
482  PLATFORM_DEBUG_PRINT (" vector length %d\n", vec_len(cnat_user_db));
483 
484  _v = _vec_find(cnat_out2in_hash);
485  PLATFORM_DEBUG_PRINT("out2in hash: %d total bytes\n", _v->alen);
486 
487  _v = _vec_find(cnat_in2out_hash);
488  PLATFORM_DEBUG_PRINT("in2out hash: %d total bytes\n", _v->alen);
489 }
490 #endif
491 
493 {
494  unsigned char bytes[4];
495  bytes[0] = ip & 0xFF;
496  bytes[1] = (ip >> 8) & 0xFF;
497  bytes[2] = (ip >> 16) & 0xFF;
498  bytes[3] = (ip >> 24) & 0xFF;
499  vlib_cli_output(vm, "\tIP Address : %d.%d.%d.%d\n", bytes[0], bytes[1], bytes[2], bytes[3]);
500 }
501 
503 {
505  my_nfv9_logging_info->server_index;
506 #if 0
507  vlib_cli_output(vm,"\tVRF - 0x%x - %s\n", my_nfv9_logging_info->i_vrf,
508  my_nfv9_logging_info->deleted?"DELETED":"ACTIVE");
509 #endif
510  print_server_ip_address(vm, clib_net_to_host_u32(server->ipv4_address));
511  vlib_cli_output(vm,"\tPort : %d\n", server->port);
512  vlib_cli_output(vm,"\tTimeout : %d\n", server->timeout_rate);
513  vlib_cli_output(vm,"\tRefresh Rate : %d\n", server->refresh_rate);
514  vlib_cli_output(vm,"\tMax Pkt Size : %d\n", my_nfv9_logging_info->max_length_minus_max_record_size);
515 
516  return;
517 }
518 
519 void cnat_db_dump_policy (int argc, unsigned long *argv)
520 {
521 
523 
526  cnat_nfv9_logging_info_t *my_nfv9_logging_info;
527  nfv9_server_info_t *server __attribute__((unused));
528 
529  my_nfv9_logging_info = cnat_nfv9_logging_info_pool +
531  server = nfv9_server_info_pool +
532  my_nfv9_logging_info->server_index;
533 
534  PLATFORM_DEBUG_PRINT("NFv9 logging ip 0x%x port 0x%x refresh-rate %d timeout %d\n",
535  server->ipv4_address,
536  server->port,
537  server->refresh_rate,
538  server->timeout_rate);
539  PLATFORM_DEBUG_PRINT("NFv9 path_mtu = %d\n",
540  my_nfv9_logging_info->max_length_minus_max_record_size);
541  } else {
542  PLATFORM_DEBUG_PRINT("NFv9 global logging is not configured\n");
543  }
544  } else {
545  PLATFORM_DEBUG_PRINT("NFv9 LOGGING is not configured\n");
546  }
547 
548 }
549 
550 #ifdef OLD_VRFMAP
551 void cnat_show_cdb (int verbose)
552 {
553  int k, l, i;
554  for (i = 0; i < vec_len(cnat_portmap_by_vrf); i++) {
555  PLATFORM_DEBUG_PRINT("i_vrf %d : o_vrf %d\n",
556  cnat_portmap_by_vrf[i].i_vrf,
557  cnat_portmap_by_vrf[i].o_vrf);
558  }
559 
561 
562  PLATFORM_DEBUG_PRINT ("%d portmap vectors\n", vec_len(cnat_portmaps));
563 
564  for (k = 0; k < vec_len(cnat_portmaps); k++) {
565  cnat_portmap_t *pm;
566  u16 *inuse;
567  pm = cnat_portmaps[k];
568  inuse = cnat_portmaps_inuse[k];
569  for (l = 0; l < vec_len(pm); l++) {
570  if (inuse[l] || verbose ) {
571  u32 net_address;
572  net_address =
573  spp_host_to_net_byte_order_32((pm+l)->ipv4_address);
574  printf_ipv4(net_address);
575  PLATFORM_DEBUG_PRINT (": %d inuse\n", inuse[l]);
576  if (verbose && inuse[l]) {
577  cnat_portmap_dump (pm+l, inuse+l);
578  }
579  }
580  }
581  }
582 }
583 #endif
584 
585 
586 
587 /* v2 show command */
589 {
590  cnat_portmap_v2_t *my_pm =0;
591  u32 first_address = 0;
592  u32 second_address = 0;
593  u32 last_address = 0;
594  u32 i, pm_len;
595 
596  if ((pm_len = vec_len(pm))) {
597  PLATFORM_DEBUG_PRINT("%d portmap in this list 0x%lx\n",
598  pm_len, (u32)pm);
599  for (i = 0; i < pm_len; i++) {
600  my_pm = pm + i;
601  if (!first_address) {
602  first_address = my_pm->ipv4_address;
603  } else if (!second_address) {
604  second_address = my_pm->ipv4_address;
605  }
606  last_address = my_pm->ipv4_address;
607  }
608 
609  if (first_address) {
610  PLATFORM_DEBUG_PRINT("1. 0x%08x", first_address);
611  }
612  if (second_address) {
613  PLATFORM_DEBUG_PRINT(", 2. 0x%08x", second_address);
614  }
615 
616  if ((last_address != first_address) &&
617  (last_address != second_address)) {
618  PLATFORM_DEBUG_PRINT(", ....., %d. 0x%08x", pm_len, last_address);
619  }
620  PLATFORM_DEBUG_PRINT("\n");
621  } else {
622  PLATFORM_DEBUG_PRINT("ZERO POOL ADDRESSES in this list 0x%x \n", (u32)pm);
623  }
624 }
625 
626 
627 void cnat_show_address_portmap (int verbose, int all,
628  cnat_portmap_v2_t *pm, u16 port_limit)
629 {
630  cnat_portmap_v2_t *my_pm =0;
631  u32 i, pm_len;
632 
633  pm_len = vec_len(pm);
634  if (!all) {
636  } else {
637  PLATFORM_DEBUG_PRINT("%d portmap in this list 0x%x \n", pm_len, (u32)pm);
638  }
639 
640  for (i = 0; i < pm_len; i++) {
641 
642  my_pm = pm + i;
643  if (all) {
644  PLATFORM_DEBUG_PRINT("pm:0x%x ip address:0x%x del_time 0x%x inuse:%d\n",
645  (u32)my_pm, my_pm->ipv4_address, my_pm->delete_time, my_pm->inuse);
646  } else if (my_pm->inuse) {
647  PLATFORM_DEBUG_PRINT("pm:0x%x ip address:0x%x inuse:%d\n",
648  (u32)my_pm, my_pm->ipv4_address, my_pm->inuse);
649  }
650 
651  if (verbose && (my_pm->inuse)) {
652  if(PREDICT_FALSE(!port_limit)) {
654  }
655  else {
656  cnat_portmap_dump_v2 (my_pm, port_limit);
657  }
658  }
659  }
660 
661  PLATFORM_DEBUG_PRINT("\n");
662 }
663 
664 
665 void cnat_show_cdb_v2 (int verbose, int all)
666 {
667  cnat_vrfmap_t *my_vrfmap = 0;
668  cnat_portmap_v2_t *pm =0;
670  PLATFORM_DEBUG_PRINT("total address pool allocated %d\n", total_address_pool_allocated);
671  PLATFORM_DEBUG_PRINT("icmp rate limit %d (per core %d)\n",
673  PLATFORM_DEBUG_PRINT("dynamic port range start %d\n", cnat_static_port_range);
674  if (pptp_cfg.enable == PPTP_DISABLED) {
675  PLATFORM_DEBUG_PRINT("PPTP alg disabled \n");
676  } else {
677  PLATFORM_DEBUG_PRINT("PPTP alg enabled \n");
678  }
679 
680  if (ftp_alg_enabled) {
681  PLATFORM_DEBUG_PRINT("FTP alg enabled\n");
682  } else {
683  PLATFORM_DEBUG_PRINT("FTP alg disabled\n");
684  }
685 
686  pool_foreach (my_vrfmap, cnat_map_by_vrf, ({
689  PLATFORM_DEBUG_PRINT("per vrf port limit %d\n", my_vrfmap->port_limit);
690  pm = my_vrfmap->portmap_list;
691  cnat_show_address_portmap(verbose, all, pm, my_vrfmap->port_limit);
692 
693  }));
694 }
695 
696 
697 void cnat_show_cdb_command_v2(int argc, unsigned long *argv)
698 {
699  int verbose=0;
700  int all = 0;
701 
702  if (argc > 0) {
703  verbose = 1;
704  }
705 
706  if (argc > 1) {
707  all = 1;
708  }
709 
710  cnat_show_cdb_v2(verbose, all);
711 }
712 
713 void cnat_show_ivrf_command_v2 (int argc, unsigned long *argv)
714 {
715  u32 vrf =0;
716  int verbose=0;
717  int all = 0;
718  cnat_vrfmap_t *my_vrfmap = 0;
719  cnat_portmap_v2_t *pm =0;
720 
721  if (!argc) {
722  PLATFORM_DEBUG_PRINT("need vrf input ,return\n");
723  return;
724  }
725  if (argc > 0) {
726  vrf = argv[0];
727  }
728  if (argc > 1) {
729  verbose = 1;
730  }
731  if (argc > 2) {
732  all = 1;
733  }
734  PLATFORM_DEBUG_PRINT ("%lld vrfmap vectors \n", pool_elts(cnat_map_by_vrf));
735  pool_foreach (my_vrfmap, cnat_map_by_vrf, ({
736  if (my_vrfmap->i_vrf == vrf) {
737  CNAT_MY_VRFMAP_PRINT
738  pm = my_vrfmap->portmap_list;
739  cnat_show_address_portmap(verbose, all, pm,my_vrfmap->port_limit);
740  return;
741  }
742  }));
743  PLATFORM_DEBUG_PRINT("not found\n");
744 }
745 
746 void cnat_show_ovrf_command_v2 (int argc, unsigned long *argv)
747 {
748  u32 not_found =1;
749  u32 vrf =0;
750  int verbose=0;
751  int all = 0;
752  cnat_vrfmap_t *my_vrfmap = 0;
753  cnat_portmap_v2_t *pm =0;
754 
755  if (!argc) {
756  PLATFORM_DEBUG_PRINT("need vrf input ,return\n");
757  return;
758  }
759  if (argc > 0) {
760  vrf = argv[0];
761  }
762  if (argc > 1) {
763  verbose = 1;
764  }
765  if (argc > 2) {
766  all = 1;
767  }
768  PLATFORM_DEBUG_PRINT("%d vrfmap vectors \n", pool_elts(cnat_map_by_vrf));
769  pool_foreach (my_vrfmap, cnat_map_by_vrf, ({
770  if (my_vrfmap->o_vrf == vrf) {
771  CNAT_MY_VRFMAP_PRINT
772  pm = my_vrfmap->portmap_list;
773  cnat_show_address_portmap(verbose, all, pm,my_vrfmap->port_limit);
774  not_found = 0;
775  }
776  }));
777  if (not_found) {
778  PLATFORM_DEBUG_PRINT("not found\n");
779  }
780 }
781 
783 {
784  u32 db_entry_index __attribute__((unused)),
785  first_db_entry_index __attribute__((unused));
786 
787  PLATFORM_DEBUG_PRINT("Timeout DB entry at index %ld\n", up - cnat_timeout_db);
788  PLATFORM_DEBUG_PRINT("Desnt key 0x%16llx\n", up->t_key.timeout_key.key64);
789  PLATFORM_DEBUG_PRINT("Timeout value %d\n", up->t_key.timeout_value);
790  PLATFORM_DEBUG_PRINT("Hash Next 0x%x\n", up->t_hash.next);
791 
792 }
793 
795 {
797  pool_header_t *h;
798  u32 used __attribute__((unused)), free __attribute__((unused));
799 
801  free = vec_len(h->free_indices);
802  used = (vec_len(cnat_timeout_db) - free);
803 
804  PLATFORM_DEBUG_PRINT("Timeout DB Free %d, Used %d\n",free, used);
805 
808  }));
809 }
810 
cnat_nfv9_global_info_t cnat_nfv9_global_info
Definition: cnat_logging.c:63
void cnat_db_dump_user(int argc, unsigned long *argv)
Definition: cnat_show.c:268
i8 alg_dlt[2]
Definition: cnat_db.h:218
u16 flags
Definition: cnat_db.h:159
cnat_main_db_entry_t * cnat_main_db
Definition: cnat_db_v2.c:201
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
void cnat_db_dump_user_summary(int argc, unsigned long *argv)
Definition: cnat_show.c:277
#define CNAT_MY_LOGGING_INFO_PRINT
Definition: cnat_show.c:79
a
Definition: bitmap.h:516
void cnat_user_db_entry_dump_summary(cnat_user_db_entry_t *up)
Definition: cnat_show.c:186
void cnat_user_db_entry_dump(cnat_user_db_entry_t *up)
Definition: cnat_show.c:158
u32 user_index
Definition: cnat_db.h:195
void cnat_db_dump_main(int argc, unsigned long *argv)
Definition: cnat_show.c:247
u32 cnat_main_db_icmp_rate_limit_core
Definition: cnat_config.c:51
Fixed length block allocator.
void cnat_db_dump_policy(int argc, unsigned long *argv)
Definition: cnat_show.c:519
u32 * free_indices
Vector of free indices.
Definition: pool.h:58
u32 cnat_current_time
Definition: cnat_global.c:29
cnat_vrfmap_t * cnat_portmap_by_vrf
u64 key64
Definition: cnat_db.h:109
u16 cnat_static_port_range
Definition: cnat_config.c:53
Definition: cnat_db.h:153
index_slist_t in2out_hash
Definition: cnat_db.h:156
#define CNAT_DB_FLAG_STATIC_PORT
Definition: cnat_db.h:164
#define vec_bytes(v)
Number of data bytes in vector.
#define CNAT_VRF_MASK
Definition: cnat_db.h:96
cnat_portmap_v2_t * portmap_list
Definition: cnat_db.h:430
cnat_key_t timeout_key
Definition: cnat_db.h:136
u8 ftp_alg_enabled
Definition: cnat_config.c:59
void cnat_show_ivrf_command_v2(int argc, unsigned long *argv)
Definition: cnat_show.c:713
u16 cnat_main_db_max_ports_per_user
Definition: cnat_config.c:48
index_slist_t out2in_hash
Definition: cnat_db.h:155
void cnat_portmap_dump_v2(cnat_portmap_v2_t *pm, u16 print_limit)
Definition: cnat_ports.c:1072
index_slist_t * cnat_in2out_hash
Definition: cnat_db_v2.c:196
#define PLATFORM_DEBUG_PRINT(...)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:348
void cnat_show_address_portmap(int verbose, int all, cnat_portmap_v2_t *pm, u16 port_limit)
Definition: cnat_show.c:627
union cnat_main_db_entry_t::@252 alg
#define CNAT_PRO_MASK
Definition: cnat_db.h:97
void cnat_timeout_db_entry_dump(cnat_timeout_db_entry_t *up)
Definition: cnat_show.c:782
void cnat_show_cdb_command_v2(int argc, unsigned long *argv)
Definition: cnat_show.c:697
u16 port_limit
Definition: cnat_db.h:444
u16 timeout
Definition: cnat_db.h:224
u16 ntranslations
Definition: cnat_db.h:290
index_slist_t * cnat_user_hash
Definition: cnat_db_v2.c:197
static pool_header_t * pool_header(void *v)
Get pool header from user pool pointer.
Definition: pool.h:67
#define PPTP_DISABLED
cnat_key_t key
Definition: cnat_db.h:309
void cnat_show_address_portmap_sumary(cnat_portmap_v2_t *pm)
Definition: cnat_show.c:588
void cnat_db_dump_timeout()
Definition: cnat_show.c:794
u16 ** cnat_portmaps_inuse
nfv9_server_info_t * nfv9_server_info_pool
Definition: cnat_logging.c:95
index_slist_t t_hash
Definition: cnat_db.h:142
u32 cnat_main_db_icmp_rate_limit
Definition: cnat_config.c:50
#define PREDICT_FALSE(x)
Definition: clib.h:97
#define CNAT_UDP
Definition: cnat_db.h:93
void cnat_nfv9_show_collector(vlib_main_t *vm, cnat_nfv9_logging_info_t *my_nfv9_logging_info)
Definition: cnat_show.c:502
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:575
cnat_user_db_entry_t * cnat_user_db
Definition: cnat_db_v2.c:202
u32 portmap_index
Definition: cnat_db.h:306
cnat_timeout_db_entry_t * cnat_timeout_db
Definition: cnat_db_v2.c:204
u32 translation_list_head_index
Definition: cnat_db.h:303
#define CNAT_ICMP
Definition: cnat_db.h:95
svmdb_client_t * c
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:211
u32 total_address_pool_allocated
Definition: cnat_show.c:43
cnat_db_key_t k
Definition: cnat_db.h:108
u16 timeout_value
Definition: cnat_db.h:137
#define CNAT_DB_FLAG_TCP_ACTIVE
Definition: cnat_db.h:161
void cnat_db_dump_main_by_index(int argc, unsigned long *argv)
Definition: cnat_show.c:214
void cnat_db_dump_main_summary(int argc, unsigned long *argv)
Definition: cnat_show.c:256
void cnat_show_ovrf_command_v2(int argc, unsigned long *argv)
Definition: cnat_show.c:746
Definition: cnat_db.h:285
unsigned int u32
Definition: types.h:88
u32 entry_expires
Definition: cnat_db.h:213
Definition: cnat_db.h:140
index_dlist_t user_ports
Definition: cnat_db.h:204
static void print_server_ip_address(vlib_main_t *vm, u32 ip)
Definition: cnat_show.c:492
cnat_key_t out2in_key
Definition: cnat_db.h:198
index_slist_t * cnat_out2in_hash
Definition: cnat_db_v2.c:195
Bitmaps built as vectors of machine words.
#define CNAT_TCP
Definition: cnat_db.h:94
cnat_nfv9_logging_info_t * cnat_nfv9_logging_info_pool
Definition: cnat_logging.c:93
void cnat_db_dump_hashes(int argc, unsigned long *argv)
Definition: cnat_show.c:286
cnat_pptp_config_t pptp_cfg
Definition: cnat_config.c:32
cnat_portmap_t ** cnat_portmaps
uword * free_bitmap
Bitmap of indices of free objects.
Definition: pool.h:55
unsigned short u16
Definition: types.h:57
cnat_vrfmap_t * cnat_map_by_vrf
Definition: cnat_db_v2.c:218
void cnat_main_db_entry_dump(cnat_main_db_entry_t *db)
Definition: cnat_show.c:108
void printf_ipv4(u32 ad)
Definition: cnat_show.c:96
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
#define CNAT_MY_VRFMAP_PRINT
Definition: cnat_show.c:47
u32 dst_ipv4
Definition: cnat_db.h:254
u16 vrfmap_index
Definition: cnat_db.h:192
#define PLATFORM_CNAT_DB_DUMP_POLICY_PRINT()
u32 out2in_pkts
Definition: cnat_db.h:207
u32 num_entries
#define EMPTY
Definition: index_list.h:24
#define CNAT_DB_FLAG_UDP_ACTIVE
Definition: cnat_db.h:163
cnat_timeout_t t_key
Definition: cnat_db.h:141
void cnat_show_cdb_v2(int verbose, int all)
Definition: cnat_show.c:665
cnat_key_t in2out_key
Definition: cnat_db.h:201
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
u32 in2out_pkts
Definition: cnat_db.h:210
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:109