2 *------------------------------------------------------------------
3 * cnat_debug_msg_handler.c - debug command
5 * Copyright (c) 2007-2013 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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
20 #include <vlib/vlib.h>
21 #include <vnet/vnet.h>
25 u32 global_debug_flag = CNAT_DEBUG_NONE;
26 u16 debug_i_vrf = CNAT_DEBUG_NONE;
27 u32 debug_i_flag = CNAT_DEBUG_NONE;
28 u32 debug_i_addr_start = CNAT_DEBUG_NONE;
29 u32 debug_i_addr_end = CNAT_DEBUG_NONE;
31 u16 debug_o_vrf = CNAT_DEBUG_NONE;
32 u32 debug_o_flag = CNAT_DEBUG_NONE;
33 u32 debug_o_addr_start = CNAT_DEBUG_NONE;
34 u32 debug_o_addr_end = CNAT_DEBUG_NONE;
36 u32 udp_inside_checksum_disable = 0;
37 u32 udp_outside_checksum_disable = 0;
38 u32 udp_inside_packet_dump_enable = 0;
39 u32 udp_outside_packet_dump_enable = 0;
41 u32 tcp_logging_enable_flag = 0;
43 u32 icmp_debug_flag = 0;
44 u32 frag_debug_flag = 0;
46 u32 nfv9_logging_debug_flag = 0;
47 u32 syslog_debug_flag = 0;
49 u32 summary_stats_debug_flag = 0;
52 * By defaut we set the config debug level to 1
54 u32 config_debug_level = 1;
57 extern void show_bulk_port_stats();
58 extern void clear_bulk_port_stats();
59 extern void show_bulk_port_allocation(u16 in_vrfid, u32 inside_ip);
60 extern void set_bulk_size_to_all_vrfs(int bulk_size);
62 u32 *cnat_debug_addr_list;
64 extern int global_pd_dbg_lvl;
65 extern int global_pi_dbg_lvl;
66 extern int global_l2_dbg_lvl;
67 extern u32 cnat_pptp_debug_flag;
68 extern u32 cnat_pcp_debug_flag;
70 void spp_api_cnat_get_cgn_db_summary
71 (spp_api_cnat_generic_command_request_t *);
73 void spp_api_cnat_v4_debug_dummy_t_handler
74 (spp_api_cnat_v4_debug_dummy_t *mp)
76 u32 arr[] = { DEBUG_DUMMY };
77 spp_printf(CNAT_DUMMY_HANDLER_HIT, 1, arr);
78 if(global_pd_dbg_lvl) {
79 PLATFORM_DEBUG_PRINT("\n invalid debug command received: message id is 0\n");
81 mp->rc = CNAT_ERR_INVALID_MSG_ID;
85 void spp_api_cnat_v4_debug_dummy_max_t_handler
86 (spp_api_cnat_v4_debug_dummy_max_t *mp)
88 u32 arr[] = { DEBUG_DUMMY_MAX };
89 spp_printf(CNAT_DUMMY_HANDLER_HIT, 1, arr);
90 if(global_pd_dbg_lvl) {
91 PLATFORM_DEBUG_PRINT("\n invalid debug command received: message id is out of range\n");
93 mp->rc = CNAT_ERR_INVALID_MSG_ID;
98 void spp_api_cnat_v4_debug_global_t_handler
99 (spp_api_cnat_v4_debug_global_t *mp)
101 if ((mp->debug_flag == CNAT_DEBUG_GLOBAL_ERR) ||
102 (mp->debug_flag == CNAT_DEBUG_GLOBAL_ALL) ||
103 (mp->debug_flag == CNAT_DEBUG_NONE)) {
104 mp->rc = CNAT_SUCCESS;
105 global_debug_flag = mp->debug_flag;
109 mp->rc = CNAT_ERR_PARSER;
110 if(global_pd_dbg_lvl) {
111 PLATFORM_DEBUG_PRINT("invalid global debug flag %x\n",
117 void spp_node_print_cnat_counters()
119 if (cnat_global_counters.nfv9_downstream_constipation_count) {
120 PLATFORM_DEBUG_PRINT("\nNF downstream constipation count: %llu\n",
121 cnat_global_counters.nfv9_downstream_constipation_count);
124 if (xlat_global_counters.v4_to_v6_frag_invalid_uidb_drop_count ||
125 xlat_global_counters.v6_to_v4_frag_invalid_uidb_drop_count ||
126 xlat_global_counters.v4_to_v6_icmp_invalid_uidb_drop_count ||
127 xlat_global_counters.v6_to_v4_icmp_invalid_uidb_drop_count ||
128 xlat_global_counters.v4_to_v6_tcp_invalid_uidb_drop_count ||
129 xlat_global_counters.v6_to_v4_tcp_invalid_uidb_drop_count ||
130 xlat_global_counters.v4_to_v6_udp_invalid_uidb_drop_count ||
131 xlat_global_counters.v6_to_v4_udp_invalid_uidb_drop_count ||
132 xlat_global_counters.v4_to_v6_udp_crc_zero_invalid_uidb_drop_count) {
134 PLATFORM_DEBUG_PRINT("\nMy_instance %d: v4_to_v6 frag invalid uidb drop count %lld",
136 xlat_global_counters.v4_to_v6_frag_invalid_uidb_drop_count);
138 PLATFORM_DEBUG_PRINT("\nMy_instance %d: v6_to_v4 frag invalid uidb drop count %lld",
140 xlat_global_counters.v6_to_v4_frag_invalid_uidb_drop_count);
142 PLATFORM_DEBUG_PRINT("\nMy_instance %d: v4_to_v6 icmp invalid uidb drop count %lld",
144 xlat_global_counters.v4_to_v6_icmp_invalid_uidb_drop_count);
146 PLATFORM_DEBUG_PRINT("\nMy_instance %d: v6_to_v4 icmp invalid uidb drop count %lld",
148 xlat_global_counters.v6_to_v4_icmp_invalid_uidb_drop_count);
150 PLATFORM_DEBUG_PRINT("\nMy_instance %d: v4_to_v6 tcp invalid uidb drop count %lld",
152 xlat_global_counters.v4_to_v6_tcp_invalid_uidb_drop_count);
154 PLATFORM_DEBUG_PRINT("\nMy_instance %d: v6_to_v4 tcp invalid uidb drop count %lld",
156 xlat_global_counters.v6_to_v4_tcp_invalid_uidb_drop_count);
158 PLATFORM_DEBUG_PRINT("\nMy_instance %d: v4_to_v6 udp invalid uidb drop count %lld",
160 xlat_global_counters.v4_to_v6_udp_invalid_uidb_drop_count);
162 PLATFORM_DEBUG_PRINT("\nMy_instance %d: v6_to_v4 udp invalid uidb drop count %lld",
164 xlat_global_counters.v6_to_v4_udp_invalid_uidb_drop_count);
166 PLATFORM_DEBUG_PRINT("\nMy_instance %d: v4_to_v6 udp crc0 invld uidb drop count %lld",
168 xlat_global_counters.v4_to_v6_udp_crc_zero_invalid_uidb_drop_count);
170 PLATFORM_DEBUG_PRINT("\n");
176 void spp_log_p2mp_req(spp_api_cnat_p2mp_debug_request_t *mp)
179 u32 num_rec = spp_net_to_host_byte_order_32(&mp->param[i++]);
188 err_c_num_args = spp_net_to_host_byte_order_32(&mp->param[i++]);
189 err_c = (err_c_num_args >> 16) & 0xFFFF;
190 num_args = err_c_num_args & 0xFFFF;
192 num_args = (num_args <= 32) ? num_args : 32;
193 while (j < num_args) {
194 argv[j++] = spp_net_to_host_byte_order_32(&mp->param[i++]);
197 i += ((num_args - 32) > 0) ? (num_args - 32) : 0;
198 spp_printf(err_c, num_args, argv);
202 void nat64_debug_addr_pool_add_del()
204 cnat_portmap_v2_t *my_pm = NULL;
205 cnat_portmap_v2_t *pm = NULL;
208 PLATFORM_DEBUG_PRINT("\n sizeof port_map =%d\n", sizeof( cnat_portmap_v2_t));
210 PLATFORM_DEBUG_PRINT("\n adding 10 entries in vector 1-10\n ");
211 vec_add2(pm, my_pm, len);
214 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
216 my_pm->ipv4_address = i+1;
219 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
221 pm_len = vec_len(pm);
222 PLATFORM_DEBUG_PRINT("\n printing vector contents : vec_len = %d \n", pm_len);
224 for(i=0;i<pm_len ; i++)
226 PLATFORM_DEBUG_PRINT(" %d ,",my_pm->ipv4_address);
229 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
231 PLATFORM_DEBUG_PRINT("\n adding 5 entries in vector 11-15\n ");
233 vec_add2(pm, my_pm, len);
235 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
237 my_pm->ipv4_address = 11+i;
241 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
242 pm_len = vec_len(pm);
243 PLATFORM_DEBUG_PRINT("\n printing vector contents : vec_len = %d \n", pm_len);
245 for(i=0;i<pm_len ; i++)
247 PLATFORM_DEBUG_PRINT(" %d ,",my_pm->ipv4_address);
250 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
252 PLATFORM_DEBUG_PRINT("\n adding 6 entries in vector 16-21\n ");
254 vec_add2(pm, my_pm, len);
255 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
257 my_pm->ipv4_address = 16+i;
261 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
262 pm_len = vec_len(pm);
263 PLATFORM_DEBUG_PRINT("\n printing vector contents : vec_len = %d \n", pm_len);
265 for(i=0;i<pm_len ; i++)
267 PLATFORM_DEBUG_PRINT(" %d ,",my_pm->ipv4_address);
271 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
272 PLATFORM_DEBUG_PRINT("\nDeleting 7 entries starting from entry value=8\n");
273 pm_len = vec_len(pm);
275 PLATFORM_DEBUG_PRINT(" pm_len =%d\n", pm_len);
276 for(i=0;i<pm_len;i++)
278 if(my_pm->ipv4_address == 8){
279 PLATFORM_DEBUG_PRINT("\n match found brraeaking..\n");
285 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p i= %d\n", pm, my_pm, i);
286 // vec_delete(pm, 7, my_pm);
287 vec_delete(pm, 7, i);
288 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
290 PLATFORM_DEBUG_PRINT(" printing entries aftr deletion from 8-14\n");
291 pm_len = vec_len(pm);
292 PLATFORM_DEBUG_PRINT("\n printing vector contents : vec_len = %d \n", pm_len);
294 for(i=0;i<pm_len ; i++)
296 PLATFORM_DEBUG_PRINT(" %d ,",my_pm->ipv4_address);
301 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
303 PLATFORM_DEBUG_PRINT("\nadding deleted items again 8-14\n");
305 vec_add2(pm, my_pm, len);
307 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
309 my_pm->ipv4_address = 8+i;
313 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
314 pm_len = vec_len(pm);
315 PLATFORM_DEBUG_PRINT("\n printing vector contents : vec_len = %d \n", pm_len);
317 for(i=0;i<pm_len ; i++)
319 PLATFORM_DEBUG_PRINT(" %d ,",my_pm->ipv4_address);
322 PLATFORM_DEBUG_PRINT(" pm =%p , my_pm = %p\n", pm, my_pm);
323 PLATFORM_DEBUG_PRINT("\n");
327 void uidb_mapping_dump_timeout() {
331 PLATFORM_DEBUG_PRINT("\nCGSE uidb mapping table \n");
332 for(i = 0;i < 30;i++) {
333 PLATFORM_DEBUG_PRINT("%d ",*(cgse_uidb_index_cgse_id_mapping_ptr + i));
338 void nat64_debug_dump_info(u32 debug_value)
341 switch(debug_value) {
352 bib_add_v6_entry1_new();
356 bib_add_v6_entry1_new_static();
364 bib_add_v6_entry_new2();
368 nat64_fill_table_entry();
372 nat64_db_dump_main();
376 nat64_db_dump_user();
380 nat64_db_dump_session();
388 bib_del_v6_entry1_static();
392 nat64_debug_addr_pool_add_del();
396 nat64_db_dump_timeout(0);
400 uidb_mapping_dump_timeout();
408 void cnat_debug_flags_set (spp_api_cnat_p2mp_debug_request_t *mp)
410 u32 debug_variable = spp_net_to_host_byte_order_32(&mp->param[0]);
411 u32 debug_value = spp_net_to_host_byte_order_32(&mp->param[1]);
415 switch (debug_variable) {
417 case CNAT_DEBUG_FLAG_UDP_INSIDE_CHECKSUM_DISABLE:
418 udp_inside_checksum_disable = debug_value;
419 PLATFORM_DEBUG_PRINT("\nudp_inside_checksum_disable set to %d\n", debug_value);
422 case CNAT_DEBUG_FLAG_UDP_OUTSIDE_CHECKSUM_DISABLE:
423 udp_outside_checksum_disable = debug_value;
424 PLATFORM_DEBUG_PRINT("\nudp_outside_checksum_disable set to %d\n", debug_value);
427 case CNAT_DEBUG_FLAG_UDP_OUTSIDE_PKT_DUMP_ENABLE:
428 udp_outside_packet_dump_enable = debug_value;
429 PLATFORM_DEBUG_PRINT("\nudp_outside_packet_dump_enable set to %d\n", debug_value);
432 case CNAT_DEBUG_FLAG_UDP_INSIDE_PKT_DUMP_ENABLE:
433 udp_inside_packet_dump_enable = debug_value;
434 PLATFORM_DEBUG_PRINT("\nudp_inside_packet_dump_enable set to %d\n", debug_value);
437 case CNAT_DEBUG_FLAG_ICMP_PKT_DUMP_ENABLE:
438 icmp_debug_flag = debug_value;
439 PLATFORM_DEBUG_PRINT("\nicmp_debug_flag set to %d\n", debug_value);
442 case CNAT_DEBUG_FLAG_FRAG_PKT_DUMP_ENABLE:
443 frag_debug_flag = debug_value;
444 PLATFORM_DEBUG_PRINT("\nfrag_debug_flag set to %d\n", debug_value);
447 case CNAT_DEBUG_FLAG_XLAT_CONFIG_DEBUG_ENABLE:
448 xlat_config_debug_level = debug_value;
449 PLATFORM_DEBUG_PRINT("\nxlat_config_debug_level set to %d\n", debug_value);
452 case CNAT_DEBUG_FLAG_NAT64_CONFIG_DEBUG_ENABLE:
453 nat64_config_debug_level = debug_value;
454 PLATFORM_DEBUG_PRINT("\nnat64_config_debug_level set to %d\n", debug_value);
455 nat64_debug_dump_info(debug_value);
458 case CNAT_DEBUG_FLAG_NAT64_DATA_PATH_DEBUG_ENABLE:
459 nat64_data_path_debug_level = debug_value;
460 PLATFORM_DEBUG_PRINT("\nnat64_data_path_debug_level set to %d\n", debug_value);
463 case CNAT_DEBUG_FLAG_DSLITE_CONFIG_DEBUG_ENABLE:
464 ds_lite_config_debug_level = debug_value;
465 PLATFORM_DEBUG_PRINT("\nds_lite_config_debug_level set to %d\n", debug_value);
468 case CNAT_DEBUG_FLAG_XLAT_DATA_PATH_DEBUG_ENABLE:
469 xlat_data_path_debug_level = debug_value;
470 PLATFORM_DEBUG_PRINT("\nxlat_data_path_debug_level set to %d\n", debug_value);
473 case CNAT_DEBUG_FLAG_CONFIG_DEBUG_ENABLE:
474 config_debug_level = debug_value;
476 PLATFORM_DEBUG_PRINT("\nconfig_debug_level set to %d\n", debug_value);
479 case CNAT_DEBUG_FLAG_CONFIG_PPTP_ENABLE:
480 cnat_pptp_debug_flag = debug_value;
482 if(debug_value == 0) {
483 pptp_dump_counters();
486 PLATFORM_DEBUG_PRINT("\ncnat_pptp_debug_level set to %d\n", debug_value);
489 case CNAT_DEBUG_FLAG_CONFIG_PCP_ENABLE:
490 cnat_pcp_debug_flag = debug_value;
492 if(debug_value == 0) {
495 PLATFORM_DEBUG_PRINT("\ncnat_pcp_debug_level set to %d\n", debug_value);
498 case CNAT_DEBUG_FLAG_GLOBAL_DEBUG_ALL_ENABLE:
499 global_debug_flag = debug_value;
500 PLATFORM_DEBUG_PRINT("\nglobal_debug_flag set to %d\n", debug_value);
503 case CNAT_DEBUG_FLAG_SUMMARY_STATS_DEBUG_ENABLE:
504 summary_stats_debug_flag = debug_value;
505 PLATFORM_DEBUG_PRINT("\nsummary_stats_debug_flag set to %d\n", debug_value);
508 case CNAT_DEBUG_FLAG_SHOW_DEBUG_ENABLE:
509 show_debug_level = debug_value;
510 PLATFORM_DEBUG_PRINT("\nshow_debug_level set to %d\n", debug_value);
513 case CNAT_DEBUG_FLAG_TCP_LOGGING_ENABLE:
514 tcp_debug_logging_enable_disable(debug_value);
516 case CNAT_DEBUG_FLAG_V6RD_DATA_PATH_DEBUG_ENABLE:
517 v6rd_data_path_debug_level = debug_value;
518 PLATFORM_DEBUG_PRINT("\nv6rd_data_path_debug_level set to %d\n", debug_value);
520 case CNAT_DEBUG_FLAG_V6RD_CONFIG_DEBUG_ENABLE:
521 v6rd_config_debug_level = debug_value;
522 PLATFORM_DEBUG_PRINT("\nv6rd_config_debug_level set to %d\n", debug_value);
524 case CNAT_DEBUG_FLAG_V6RD_DEFRAG_DEBUG_ENABLE:
525 /* set debug atleast to 1, so that critical errors are always
528 v6rd_defrag_debug_level = debug_value ? debug_value : 1;
529 PLATFORM_DEBUG_PRINT("\nv6rd_config_debug_level set to %d\n", debug_value);
533 case CNAT_DEBUG_SET_STATIC_PORT_RANGE:
534 PLATFORM_DEBUG_PRINT("\nChange Static Port Range from %d --> %d\n",
535 cnat_static_port_range, debug_value);
536 cnat_static_port_range = debug_value;
539 case CNAT_DEBUG_FLAG_DSLITE_DP_ENABLE:
540 PLATFORM_DEBUG_PRINT("\n Changing dslite debug flag from %d --> %d\n",
541 dslite_debug_level, debug_value);
542 dslite_debug_level = debug_value;
545 case CNAT_DEBUG_FLAG_NFV9_LOGGING_DUMP_ENABLE:
546 nfv9_logging_debug_flag = debug_value;
547 PLATFORM_DEBUG_PRINT("\nnfv9_logging_debug_flag set to %d\n", debug_value);
550 case CNAT_DEBUG_FLAG_SYSLOG_LOGGING_DUMP_ENABLE:
551 syslog_debug_flag = debug_value;
552 PLATFORM_DEBUG_PRINT("\nsyslog_debug_flag set to %d\n", debug_value);
555 case CNAT_DEBUG_FLAG_MAPE_CONFIG_DEBUG_ENABLE:
556 mape_config_debug_level = debug_value;
557 PLATFORM_DEBUG_PRINT("\nmape_config_debug_level set to %d\n", debug_value);
560 case CNAT_DEBUG_FLAG_MAPE_DATA_PATH_DEBUG_ENABLE:
561 mape_data_path_debug_level = debug_value;
562 PLATFORM_DEBUG_PRINT("\nmape_data_path_debug_level set to %d\n", debug_value);
565 case CNAT_DEBUG_FLAGS_DUMP:
568 PLATFORM_DEBUG_PRINT("\nCurrent values of Debug Variables\n");
569 PLATFORM_DEBUG_PRINT("\nTo modify an item chose its index and provide the value\n");
570 PLATFORM_DEBUG_PRINT("\n%d: udp_inside_checksum_disable %d\n",
571 CNAT_DEBUG_FLAG_UDP_INSIDE_CHECKSUM_DISABLE,
572 udp_inside_checksum_disable);
573 PLATFORM_DEBUG_PRINT("%d: udp_outside_checksum_disable %d\n",
574 CNAT_DEBUG_FLAG_UDP_OUTSIDE_CHECKSUM_DISABLE,
575 udp_outside_checksum_disable);
576 PLATFORM_DEBUG_PRINT("%d: udp_inside_packet_dump_enable %d\n",
577 CNAT_DEBUG_FLAG_UDP_OUTSIDE_PKT_DUMP_ENABLE,
578 udp_inside_packet_dump_enable);
579 PLATFORM_DEBUG_PRINT("%d: udp_outside_packet_dump_enable %d\n",
580 CNAT_DEBUG_FLAG_UDP_INSIDE_PKT_DUMP_ENABLE,
581 udp_outside_packet_dump_enable);
582 PLATFORM_DEBUG_PRINT("%d: icmp_debug_flag %d\n",
583 CNAT_DEBUG_FLAG_ICMP_PKT_DUMP_ENABLE,
585 PLATFORM_DEBUG_PRINT("%d: frag_debug_flag %d\n",
586 CNAT_DEBUG_FLAG_FRAG_PKT_DUMP_ENABLE,
588 PLATFORM_DEBUG_PRINT("%d: config_debug_level %d\n",
589 CNAT_DEBUG_FLAG_CONFIG_DEBUG_ENABLE,
591 PLATFORM_DEBUG_PRINT("%d: global_debug_flag %d\n",
592 CNAT_DEBUG_FLAG_GLOBAL_DEBUG_ALL_ENABLE,
594 PLATFORM_DEBUG_PRINT("%d: summary_stats_debug_flag %d\n",
595 CNAT_DEBUG_FLAG_SUMMARY_STATS_DEBUG_ENABLE,
596 summary_stats_debug_flag);
597 PLATFORM_DEBUG_PRINT("%d: show_debug_level %d\n",
598 CNAT_DEBUG_FLAG_SHOW_DEBUG_ENABLE,
600 PLATFORM_DEBUG_PRINT("%d: xlat_config_debug_level %d\n",
601 CNAT_DEBUG_FLAG_XLAT_CONFIG_DEBUG_ENABLE,
602 xlat_config_debug_level);
603 PLATFORM_DEBUG_PRINT("%d: xlat_data_path_debug_level %d\n",
604 CNAT_DEBUG_FLAG_XLAT_DATA_PATH_DEBUG_ENABLE,
605 xlat_data_path_debug_level);
606 PLATFORM_DEBUG_PRINT("%d: tcp_logging_enable_flag %d\n",
607 CNAT_DEBUG_FLAG_TCP_LOGGING_ENABLE,
608 tcp_logging_enable_flag);
609 PLATFORM_DEBUG_PRINT(" tcp_logging_enable_options DISABLE %d, ENABLE %d, PKT_DUMP %d, SUMMARY_DUMP %d\n",
610 TCP_LOGGING_DISABLE, TCP_LOGGING_ENABLE,
611 TCP_LOGGING_PACKET_DUMP, TCP_LOGGING_SUMMARY_DUMP);
612 PLATFORM_DEBUG_PRINT("%d: nfv9_logging_debug_flag %d\n",
613 CNAT_DEBUG_FLAG_NFV9_LOGGING_DUMP_ENABLE,
614 nfv9_logging_debug_flag);
615 PLATFORM_DEBUG_PRINT("%d: syslog_debug_flag %d\n",
616 CNAT_DEBUG_FLAG_SYSLOG_LOGGING_DUMP_ENABLE,
618 PLATFORM_DEBUG_PRINT("%d: cnat_static_port_range %d\n",
619 CNAT_DEBUG_SET_STATIC_PORT_RANGE,
620 cnat_static_port_range);
621 PLATFORM_DEBUG_PRINT("%d: v6rd_data_path_debug_level %d\n",
622 CNAT_DEBUG_FLAG_V6RD_DATA_PATH_DEBUG_ENABLE,
623 v6rd_data_path_debug_level);
624 PLATFORM_DEBUG_PRINT("%d: v6rd_config_debug_level %d\n",
625 CNAT_DEBUG_FLAG_V6RD_CONFIG_DEBUG_ENABLE,
626 v6rd_config_debug_level);
627 PLATFORM_DEBUG_PRINT("%d: v6rd_defrag_debug_level %d\n",
628 CNAT_DEBUG_FLAG_V6RD_DEFRAG_DEBUG_ENABLE,
629 v6rd_defrag_debug_level);
630 PLATFORM_DEBUG_PRINT("%d: nat64_stful_debug %d\n",
631 CNAT_DEBUG_FLAG_NAT64_CONFIG_DEBUG_ENABLE,
632 nat64_config_debug_level);
633 PLATFORM_DEBUG_PRINT("%d: nat64_data_path_debug_level %d\n",
634 CNAT_DEBUG_FLAG_NAT64_DATA_PATH_DEBUG_ENABLE,
635 nat64_data_path_debug_level);
636 PLATFORM_DEBUG_PRINT("%d: dslite_debug_level %d\n",
637 CNAT_DEBUG_FLAG_DSLITE_DP_ENABLE,
639 PLATFORM_DEBUG_PRINT("%d: ds_lite_config_debug_level %d\n",
640 CNAT_DEBUG_FLAG_DSLITE_CONFIG_DEBUG_ENABLE,
641 ds_lite_config_debug_level);
642 PLATFORM_DEBUG_PRINT("%d: mape_config_debug_level %d\n",
643 CNAT_DEBUG_FLAG_MAPE_CONFIG_DEBUG_ENABLE,
644 mape_config_debug_level);
645 PLATFORM_DEBUG_PRINT("%d: mape_data_path_debug_level %d\n",
646 CNAT_DEBUG_FLAG_MAPE_DATA_PATH_DEBUG_ENABLE,
647 mape_data_path_debug_level);
653 extern void dump_cnat_frag_stats(void);
655 void spp_api_cnat_p2mp_debug_request_t_handler
656 (spp_api_cnat_p2mp_debug_request_t *mp)
661 if (mp->core_num != my_instance_number) {
662 mp->rc = CNAT_NOT_THIS_CORE;
667 command_type = spp_net_to_host_byte_order_16(&mp->dump_type);
668 PLATFORM_DEBUG_PRINT("-->> Core%d: Received debug msg ... cmd type: %d\n",
669 my_instance_number, command_type);
671 switch (command_type) {
673 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_POLICY:
674 PLATFORM_DEBUG_PRINT("Core%d: policy\n", my_instance_number);
675 cnat_db_dump_policy();
678 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_MAIN_DB:
679 PLATFORM_DEBUG_PRINT("Core%d: Main db\n", my_instance_number);
683 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_MAIN_DB_SUMMARY:
684 PLATFORM_DEBUG_PRINT("Core%d: Main db Summary\n", my_instance_number);
685 cnat_db_dump_main_summary();
688 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_USER_DB:
689 PLATFORM_DEBUG_PRINT("Core%d: User db\n", my_instance_number);
693 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_USER_DB_SUMMARY:
694 PLATFORM_DEBUG_PRINT("Core%d: User db Summary\n", my_instance_number);
695 cnat_db_dump_user_summary();
698 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_HASHES_DB:
699 PLATFORM_DEBUG_PRINT("Core%d: Hashes db\n", my_instance_number);
700 cnat_db_dump_hashes();
703 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_VRF_MAP:
704 PLATFORM_DEBUG_PRINT("Core%d: Vrf map \n", my_instance_number);
705 cnat_db_dump_portmaps();
708 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_SUMMARY_DB:
709 PLATFORM_DEBUG_PRINT("Core%d: dump summary DB \n", my_instance_number);
713 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_STATS:
714 PLATFORM_DEBUG_PRINT("Core%d: dump stats \n", my_instance_number);
715 spp_node_print_stats(1, NULL);
718 /* Currently does same as clear node ctr, may change */
719 case CNAT_DEBUG_GENERIC_COMMAND_CLEAR_STATS:
720 PLATFORM_DEBUG_PRINT("Core%d: clear stats \n", my_instance_number);
721 spp_node_clear_stats();
724 case CNAT_DEBUG_SPP_LOG:
725 PLATFORM_DEBUG_PRINT("Core%d: SPP LOG \n", my_instance_number);
726 spp_log_p2mp_req(mp);
729 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_NODE_COUNTER:
730 PLATFORM_DEBUG_PRINT("Core%d: NODE Counter dump \n", my_instance_number);
731 spp_node_print_counters();
734 case CNAT_DEBUG_GENERIC_COMMAND_CLEAR_NODE_COUNTER:
735 PLATFORM_DEBUG_PRINT("Core%d: clear node counter \n", my_instance_number);
736 spp_node_clear_stats();
739 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_CNAT_COUNTER:
740 PLATFORM_DEBUG_PRINT("Core%d: CNAT Counter dump \n", my_instance_number);
741 spp_node_print_cnat_counters();
744 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_VA:
745 PLATFORM_DEBUG_PRINT("Core%d: VA dump \n", my_instance_number);
748 u32 arg[2] = {spp_net_to_host_byte_order_32(&mp->param[0]), 0};
750 cnat_va_dump(argc, arg);
754 case CNAT_DEBUG_GENERIC_COMMAND_SHOW_CONFIG:
755 PLATFORM_DEBUG_PRINT("Core%d: Show config dump \n", my_instance_number);
758 unsigned long arg[3];
760 if (arg[argc++] = spp_net_to_host_byte_order_32(&mp->param[0])) {
761 if (arg[argc++] = spp_net_to_host_byte_order_32(&mp->param[1])) {
768 cnat_show_cdb_command_v2(argc, arg);
774 dslite_show_config();
780 case CNAT_DEBUG_GENERIC_COMMAND_SHOW_NFV9:
781 PLATFORM_DEBUG_PRINT("Core%d: NFv9 dump \n", my_instance_number);
782 #if 0 /* Currently not calling this */
783 cnat_nfv9_show_cmd();
787 case CNAT_DEBUG_GENERIC_COMMAND_SHOW_IVRF:
788 PLATFORM_DEBUG_PRINT("Core%d: IVRF dump \n", my_instance_number);
791 unsigned long arg[3];
793 if (arg[argc++] = spp_net_to_host_byte_order_32(&mp->param[0])) {
794 if (arg[argc++] = spp_net_to_host_byte_order_32(&mp->param[1])) {
795 if (arg[argc++] = spp_net_to_host_byte_order_32(&mp->param[2])) {
806 PLATFORM_DEBUG_PRINT("VRF: %d \n", spp_net_to_host_byte_order_32(&mp->param[0]));
807 PLATFORM_DEBUG_PRINT("2nd arg: %d \n",
808 spp_net_to_host_byte_order_32(&mp->param[1]));
810 cnat_show_ivrf_command_v2(argc, arg);
814 case CNAT_DEBUG_GENERIC_COMMAND_SHOW_OVRF:
815 PLATFORM_DEBUG_PRINT("Core%d: OVRF dump \n", my_instance_number);
818 unsigned long arg[3];
819 if (arg[argc++] = spp_net_to_host_byte_order_32(&mp->param[0])) {
820 if (arg[argc++] = spp_net_to_host_byte_order_32(&mp->param[1])) {
821 if (arg[argc++] = spp_net_to_host_byte_order_32(&mp->param[2])) {
831 PLATFORM_DEBUG_PRINT("VRF: %d \n", spp_net_to_host_byte_order_32(&mp->param[0]));
832 PLATFORM_DEBUG_PRINT("2nd arg: %d \n",
833 spp_net_to_host_byte_order_32(&mp->param[1]));
835 cnat_show_ovrf_command_v2(argc, arg);
839 case CNAT_DEBUG_GENERIC_COMMAND_DEBUG_OPTIONS:
840 PLATFORM_DEBUG_PRINT("Core%d: Debug option dump \n", my_instance_number);
842 global_pd_dbg_lvl = 0;
843 global_pi_dbg_lvl = 0;
844 global_l2_dbg_lvl = 0;
847 spp_net_to_host_byte_order_32(&mp->param[0]);
849 spp_net_to_host_byte_order_32(&mp->param[1]);
851 spp_net_to_host_byte_order_32(&mp->param[2]);
853 PLATFORM_DEBUG_PRINT("global_pd_dbg_lvl: %d, global_pi_dbg_lvl: %d, global_l2_dbg_lvl: %d\n",
854 global_pd_dbg_lvl, global_pi_dbg_lvl, global_l2_dbg_lvl);
858 case CNAT_DEBUG_GENERIC_COMMAND_DUMP_DEBUG_LEVELS:
859 PLATFORM_DEBUG_PRINT("Core%d: PD Debug level: %d \n", my_instance_number, global_pd_dbg_lvl);
860 PLATFORM_DEBUG_PRINT("Core%d: PI Debug level: %d \n", my_instance_number, global_pi_dbg_lvl);
861 PLATFORM_DEBUG_PRINT("Core%d: L2 Debug level: %d \n", my_instance_number, global_l2_dbg_lvl);
864 case CNAT_DEBUG_GENERIC_COMMAND_DEBUG_FLAGS:
865 PLATFORM_DEBUG_PRINT("Core%d: Debug flags \n", my_instance_number);
866 cnat_debug_flags_set(mp);
869 case CNAT_READ_TEMP_SENSORS:
870 PLATFORM_INIT_TEMP_SENSORS();
871 PLATFORM_READ_CPU_SENSORS(TEMPERATURE_SENSOR_TEST_MODE);
874 case CNAT_BLOCK_OCTEON_SENSOR_READ:
876 PLATFORM_SET_TEMP_READ_BLOCK(temperature_read_blocked , mp);
877 #ifdef TARGET_RODDICK
878 temperature_read_blocked =
879 spp_net_to_host_byte_order_32(&mp->param[0]);
883 case CNAT_DEBUG_TIMEOUT_DB_SUMMARY:
884 cnat_db_dump_timeout();
887 /* This option has to be removed later */
888 case CNAT_DEBUG_SET_BULK_SIZE:
889 PLATFORM_DEBUG_PRINT("\nSetting bulk size to %d\n",
890 spp_net_to_host_byte_order_32(&mp->param[0]));
891 set_bulk_size_to_all_vrfs(
892 spp_net_to_host_byte_order_32(&mp->param[0]));
895 case CNAT_DEBUG_SHOW_BULK_STAT:
896 show_bulk_port_stats();
899 case CNAT_DEBUG_CLEAR_BULK_STAT:
900 clear_bulk_port_stats();
903 case CNAT_DEBUG_SHOW_BULK_ALLOC:
905 u16 in_vrfid = spp_net_to_host_byte_order_32(&mp->param[0]);
906 u32 inside_ip = spp_net_to_host_byte_order_32(&mp->param[1]);
907 show_bulk_port_allocation(in_vrfid, inside_ip);
911 case CNAT_DEBUG_NAT44_IN2OUT_FRAG_STATS:
912 dump_cnat_frag_stats();
916 mp->rc = CNAT_ERR_INVALID_MSG_ID;
920 mp->rc = CNAT_SUCCESS;
925 void spp_api_cnat_v4_debug_in2out_private_addr_t_handler
926 (spp_api_cnat_v4_debug_in2out_private_addr_t *mp)
930 u32 start_addr, end_addr;
934 spp_net_to_host_byte_order_32(&mp->start_addr);
936 spp_net_to_host_byte_order_32(&mp->end_addr);
938 spp_net_to_host_byte_order_16(&mp->i_vrf);
940 spp_net_to_host_byte_order_32(&mp->debug_flag);
942 if ((i_vrf > MAX_UIDX) || (start_addr > end_addr) ||
943 ((debug_flag != CNAT_DEBUG_NONE) &&
944 ((debug_flag & CNAT_DEBUG_ALL) == CNAT_DEBUG_NONE))) {
945 mp->rc = CNAT_ERR_PARSER;
946 PLATFORM_DEBUG_PRINT("invalid debug ivrf 0x%x flag 0x%x "
947 "start addr 0x%x end addr 0x%x\n",
949 start_addr, end_addr);
953 PLATFORM_DEBUG_PRINT("debug ivrf 0x%x flag 0x%x "
954 "start addr 0x%x end addr 0x%x\n",
956 start_addr, end_addr);
958 mp->rc = CNAT_SUCCESS;
960 debug_i_flag = debug_flag;
961 debug_i_addr_start = start_addr;
962 debug_i_addr_end = end_addr;
966 void spp_api_cnat_v4_debug_out2in_public_addr_t_handler
967 (spp_api_cnat_v4_debug_out2in_public_addr_t *mp)
971 u32 start_addr, end_addr;
974 spp_net_to_host_byte_order_32(&mp->start_addr);
976 spp_net_to_host_byte_order_32(&mp->end_addr);
978 spp_net_to_host_byte_order_16(&mp->o_vrf);
980 spp_net_to_host_byte_order_32(&mp->debug_flag);
982 if ((o_vrf > MAX_UIDX) || (start_addr > end_addr) ||
983 ((debug_flag != CNAT_DEBUG_NONE) &&
984 ((debug_flag & CNAT_DEBUG_ALL) == CNAT_DEBUG_NONE))) {
985 mp->rc = CNAT_ERR_PARSER;
986 PLATFORM_DEBUG_PRINT("invalid debug ovrf 0x%x flag 0x%x "
987 "start addr 0x%x end addr 0x%x\n",
989 start_addr, end_addr);
993 mp->rc = CNAT_SUCCESS;
995 debug_o_flag = debug_flag;
996 debug_o_addr_start = start_addr;
997 debug_o_addr_end = end_addr;
999 PLATFORM_DEBUG_PRINT(" o2i debug currently is not supported\n");
1002 void nat64_reset_session_expiry(nat64_bib_entry_t *db)
1004 NAT64_STFUL_DEBUG_PRINT(3, " invoking nat64_clean_bib_db_entry\n " );
1005 nat64_clean_bib_db_entry(db);
1006 NAT64_STFUL_DEBUG_PRINT(3, "done with clean_bib_db_entry\n " );
1009 void spp_api_nat64_clear_db_request_t_handler
1010 (spp_api_nat64_clear_db_request_t *mp)
1012 u16 port, proto, flag;
1015 nat64_bib_entry_t* db;
1017 nat64_table_entry_t *my_nat64_table_db_ptr;
1020 NAT64_STFUL_FUNC_ENTER;
1021 NAT64_STFUL_DEBUG_DUMP_MSG(mp);
1023 nat64_id = spp_net_to_host_byte_order_16(&mp->nat64_id);
1024 my_nat64_table_db_ptr = nat64_table_ptr + nat64_id;
1026 port = spp_net_to_host_byte_order_16(&mp->port_num);
1027 proto = mp->protocol;
1030 ki.vrf |= ((u16)proto << CNAT_PRO_SHIFT);
1032 for(i =0 ; i< 4 ; i++)
1033 ki.ipv6[i] = spp_net_to_host_byte_order_32(&mp->ip_addr[i]);
1039 mp->rc = CNAT_SUCCESS;
1041 NAT64_STFUL_DEBUG_PRINT(3, "\n Nat64_id = %d, port =%d, \
1042 proto =%d, flags=0x%08X",\
1043 nat64_id, port, proto, flag);
1045 NAT64_STFUL_DEBUG_PRINT(3, "\n IPv6 Addr = %08X : %08X: %08X: %08X",\
1046 ki.ipv6[0], ki.ipv6[1], ki.ipv6[2], ki.ipv6[3]);
1048 if (flag == CNAT_DB_CLEAR_SPECIFIC) {
1049 NAT64_STFUL_DEBUG_PRINT(3, "\n clear specific \n");
1051 db = nat64_bib_db_lookup_entry(&ki);
1053 NAT64_STFUL_DEBUG_PRINT(3, "\n clear specific - not present\n");
1054 mp->rc = CNAT_NOT_FOUND_ANY;
1058 if( !(db->flags & CNAT_DB_NAT64_FLAG) ||
1059 (db->nat64_inst_id != nat64_id))
1063 nat64_reset_session_expiry(db);
1067 pool_header_t *p = pool_header(nat64_bib_db);
1069 for(index = 0; index < vec_len(nat64_bib_db); index++) {
1071 /* check is it nat44, if yes skip , do it n nat44 as well */
1073 if (PREDICT_FALSE(!clib_bitmap_get(p->free_bitmap, index))) {
1074 db = nat64_bib_db + index;
1076 if( !(db->flags & CNAT_DB_NAT64_FLAG) ||
1077 (db->nat64_inst_id != nat64_id))
1080 if (flag == CNAT_DB_CLEAR_ALL) {
1081 nat64_reset_session_expiry(db);
1085 if (flag & CNAT_DB_CLEAR_ADDR) {
1086 if ((db->v6_in_key.ipv6[0] != ki.ipv6[0]) ||
1087 (db->v6_in_key.ipv6[1] != ki.ipv6[1]) ||
1088 (db->v6_in_key.ipv6[2] != ki.ipv6[2]) ||
1089 (db->v6_in_key.ipv6[3] != ki.ipv6[3])){
1090 NAT64_STFUL_DEBUG_PRINT(3, "\n%s:%d\n", __FUNCTION__, \
1096 if (flag & CNAT_DB_CLEAR_PROTO) {
1097 if (((db->v6_in_key.vrf & CNAT_PRO_MASK) >> CNAT_PRO_SHIFT)
1099 NAT64_STFUL_DEBUG_PRINT(3, "\n%s:%d\n", __FUNCTION__, \
1105 if (flag & CNAT_DB_CLEAR_PORT) {
1106 if (db->v6_in_key.port != port) {
1107 NAT64_STFUL_DEBUG_PRINT(3, "\n%s:%d\n", __FUNCTION__, \
1113 NAT64_STFUL_DEBUG_PRINT(3, "\n%s:%d\n", __FUNCTION__, \
1116 * Delete if the db entry matches and it is not a
1118 nat64_reset_session_expiry(db);
1123 void inline cnat_clear_session_db(cnat_main_db_entry_t *db)
1125 if(PREDICT_FALSE(db->nsessions > 1)) {
1126 u32 session_index = db->session_head_index;
1127 cnat_session_entry_t *sdb;
1129 sdb = cnat_session_db + session_index;
1130 if(PREDICT_FALSE(!sdb)) {
1134 sdb->entry_expires = 0;
1135 session_index = sdb->main_list.next;
1136 } while(session_index != db->session_head_index
1137 && db->session_head_index != EMPTY);
1143 extern dslite_table_entry_t dslite_table_array[];
1145 void spp_api_ds_lite_clear_db_request_t_handler
1146 (spp_api_ds_lite_clear_db_request_t *mp)
1148 u16 port, proto, flag;
1151 cnat_main_db_entry_t *db;
1152 cnat_user_db_entry_t *udb;
1154 dslite_table_entry_t *my_table_db_ptr;
1159 id = spp_net_to_host_byte_order_16(&mp->ds_lite_id);
1160 id = DS_LITE_CONFIG_TO_ARRAY_ID(id);
1162 my_table_db_ptr = &dslite_table_array[id];
1163 i_vrf = my_table_db_ptr->i_vrf;
1165 port = spp_net_to_host_byte_order_16(&mp->port_num);
1166 proto = mp->protocol;
1168 ki.ipv4_key.k.vrf = i_vrf;
1169 ki.ipv4_key.k.vrf |= ((u16)proto << CNAT_PRO_SHIFT);
1171 for(i =0 ; i< 4 ; i++)
1172 ki.ipv6[i] = spp_net_to_host_byte_order_32(&mp->ip_addr[i]);
1174 ki.ipv4_key.k.port = port;
1178 mp->rc = CNAT_SUCCESS;
1180 DSLITE_PRINTF(3, "\n dslite id = %d, port =%d"
1181 "proto =%d, flags=0x%08X",\
1182 id, port, proto, flag);
1184 DSLITE_PRINTF(3, "\n IPv6 Addr = %08X : %08X: %08X: %08X",\
1185 ki.ipv6[0], ki.ipv6[1], ki.ipv6[2], ki.ipv6[3]);
1187 if (flag == CNAT_DB_CLEAR_SPECIFIC) {
1188 DSLITE_PRINTF(3, "\n Clear specific NOT supported for DS Lite \n");
1192 pool_header_t *p = pool_header(cnat_main_db);
1194 for(index = 0; index < vec_len(cnat_main_db); index++) {
1196 /* check is it dslite entry, if not skip */
1198 if (PREDICT_FALSE(!clib_bitmap_get(p->free_bitmap, index))) {
1199 db = cnat_main_db + index;
1201 if( !(db->flags & CNAT_DB_DSLITE_FLAG) ||
1202 ((db->in2out_key.k.vrf & CNAT_VRF_MASK) != i_vrf) ||
1203 (db->flags & CNAT_DB_FLAG_STATIC_PORT)) {
1207 if (flag == CNAT_DB_CLEAR_ALL) {
1210 * Make the entry time as very old (0), and wait
1211 * for a timeout to auto-expire the entry.
1213 db->entry_expires = 0;
1214 /* Handle sessions as well.. */
1215 cnat_clear_session_db(db);
1219 if (flag & CNAT_DB_CLEAR_ADDR) {
1220 udb = cnat_user_db + db->user_index;
1221 if(PREDICT_FALSE(!udb)) {
1224 if ((udb->ipv6[0] != ki.ipv6[0]) ||
1225 (udb->ipv6[1] != ki.ipv6[1]) ||
1226 (udb->ipv6[2] != ki.ipv6[2]) ||
1227 (udb->ipv6[3] != ki.ipv6[3])) {
1232 if (flag & CNAT_DB_CLEAR_PROTO) {
1233 if (((db->in2out_key.k.vrf & CNAT_PRO_MASK) >> CNAT_PRO_SHIFT)
1239 if (flag & CNAT_DB_CLEAR_PORT) {
1240 if (db->in2out_key.k.port != port) {
1246 * Mark for expiry in the next round of DB scan
1248 db->entry_expires = 0;
1249 /* Handle sessions as well.. */
1250 cnat_clear_session_db(db);
1254 #endif /* #ifdef CGSE_DS_LITE */
1256 void spp_api_cnat_clear_db_request_t_handler
1257 (spp_api_cnat_clear_db_request_t *mp)
1259 u16 i_vrf, port, proto, flag;
1262 cnat_main_db_entry_t * db;
1263 cnat_db_key_bucket_t ki;
1265 #if defined(TARGET_LINUX_UDVR) || defined(CNAT_PG)
1266 i_vrf = mp->inside_vrf;
1267 ip_addr = mp->ip_addr;
1268 port = mp->port_num;
1269 proto = mp->protocol;
1271 i_vrf = spp_net_to_host_byte_order_16(&mp->inside_vrf);
1272 ip_addr = spp_net_to_host_byte_order_32(&mp->ip_addr);
1273 port = spp_net_to_host_byte_order_16(&mp->port_num);
1274 proto = spp_net_to_host_byte_order_16(&mp->protocol);
1280 ki.k.k.vrf |= ((u16)proto << CNAT_PRO_SHIFT);
1281 ki.k.k.ipv4 = ip_addr;
1284 flag = mp->wildcard;
1286 mp->rc = CNAT_SUCCESS;
1288 if (flag == CNAT_DB_CLEAR_SPECIFIC) {
1289 CNAT_V4_GET_HASH(ki.k.key64,
1291 CNAT_MAIN_HASH_MASK);
1292 index = cnat_in2out_hash[ki.bucket].next;
1293 if (PREDICT_TRUE(index == EMPTY)) {
1294 mp->rc = CNAT_NOT_FOUND_ANY;
1299 db = cnat_main_db + index;
1302 * Delete if the db entry matches and it is not a
1305 if ((db->in2out_key.key64 == ki.k.key64) &&
1306 !(db->flags & CNAT_DB_FLAG_STATIC_PORT) &&
1307 !(db->flags & CNAT_DB_NAT64_FLAG) &&
1308 !(db->flags & CNAT_DB_DSLITE_FLAG)) {
1311 * Make the entry time as very old (0), and wait
1312 * for a timeout to auto-expire the entry.
1314 db->entry_expires = 0;
1315 /* Handle sessions as well.. */
1316 cnat_clear_session_db(db);
1319 index = db->in2out_hash.next;
1320 } while (index != EMPTY);
1322 mp->rc = CNAT_NOT_FOUND_ANY;
1326 pool_header_t *p = vec_header(cnat_main_db, sizeof(pool_header_t));
1328 for(index = 0; index < vec_len(cnat_main_db); index++) {
1330 if (PREDICT_TRUE(!clib_bitmap_get(p->free_bitmap, index))) {
1331 db = cnat_main_db + index;
1333 if(PREDICT_FALSE(db->flags & CNAT_DB_NAT64_FLAG)) {
1337 if(PREDICT_FALSE(db->flags & CNAT_DB_DSLITE_FLAG)) {
1341 if (flag == CNAT_DB_CLEAR_ALL) {
1342 if (!(db->flags & CNAT_DB_FLAG_STATIC_PORT)) {
1343 db->entry_expires = 0;
1344 /* Handle sessions as well.. */
1345 cnat_clear_session_db(db);
1350 if (flag & CNAT_DB_CLEAR_VRF) {
1351 if (((db->in2out_key.k.vrf & CNAT_VRF_MASK) != i_vrf)) {
1356 if (flag & CNAT_DB_CLEAR_ADDR) {
1357 if ((db->in2out_key.k.ipv4 != ip_addr)) {
1362 if (flag & CNAT_DB_CLEAR_PROTO) {
1363 if (((db->in2out_key.k.vrf & CNAT_PRO_MASK) >> CNAT_PRO_SHIFT)
1369 if (flag & CNAT_DB_CLEAR_PORT) {
1370 if (db->in2out_key.k.port != port) {
1376 * Delete if the db entry matches and it is not a
1379 if (!(db->flags & CNAT_DB_FLAG_STATIC_PORT)) {
1380 db->entry_expires = 0;
1381 /* Handle sessions as well.. */
1382 cnat_clear_session_db(db);
1389 spp_api_cnat_generic_command_debug (cnat_generic_command_resp *mp_resp)
1394 i = spp_net_to_host_byte_order_32(&(mp_resp->num_bytes));
1396 PLATFORM_DEBUG_PRINT("\nNum_Bytes %d\n", i);
1398 for (j = 0; j < i; j++) {
1399 PLATFORM_DEBUG_PRINT("0x%02X ", mp_resp->raw_data[j]);
1400 if ((j % 16) == 15) {
1401 PLATFORM_DEBUG_PRINT("\n");
1408 * The following commands implements command to dump the
1409 * user-db information
1410 * port-map information
1411 * for a give user source IP address
1413 * The format of the output is:
1414 * Word 0: Address of udb
1415 * Word 1: udb->translation_list_head_index
1417 * Bytes 0..1: udb->ntranslations
1418 * Bytes 2..2: udb->icmp_msg_coung
1419 * Bytes 3..3: udb->unused
1420 * Word 3: udb->portmap_index
1421 * Word 4: udb->key.k.ipv4
1423 * Bytes 0..1: udb->key.k.port = 0
1424 * Bytes 2..3: udb->key.k.vrf
1425 * Word 6: udb->user_hash
1426 * Word 7: Address of my_pm
1427 * Word 8: my_pm->status
1428 * Word 9: my_pm->inuse
1429 * Word A: my_pm->delete_time
1430 * Word B: my_pm->ipv4_address
1432 void spp_api_cnat_generic_command_user_db_pm
1433 (spp_api_cnat_generic_command_request_t *mp)
1436 cnat_db_key_bucket_t u_ki;
1437 u16 my_vrfmap_index;
1439 cnat_generic_command_resp *mp_resp;
1440 cnat_user_db_entry_t *udb;
1441 cnat_user_db_entry_t *mp_udb;
1442 cnat_vrfmap_t *my_vrfmap;
1443 cnat_portmap_v2_t *pm;
1444 cnat_portmap_v2_t *my_pm;
1447 * Request structure is used to send the response
1449 mp_resp = (cnat_generic_command_resp *) mp;
1451 u_ki.k.k.vrf = spp_net_to_host_byte_order_32(&mp->params[1]);
1452 u_ki.k.k.ipv4 = spp_net_to_host_byte_order_32(&mp->params[2]);
1455 udb = cnat_user_db_lookup_entry(&u_ki);
1458 mp_resp->num_bytes = spp_host_to_net_byte_order_32(0);
1462 result_array = (u32 *) (&(mp_resp->raw_data[0]));
1465 result_array[i++] = spp_host_to_net_byte_order_32((u32) udb);
1467 mp_udb = (cnat_user_db_entry_t *) &(result_array[i]);
1470 * Align the entry to the next 4 byte boundary
1472 i = i + ((sizeof(cnat_user_db_entry_t)+3)/4);
1475 * Fill in the UDB information
1477 mp_udb->translation_list_head_index =
1478 spp_host_to_net_byte_order_32(udb->translation_list_head_index);
1479 mp_udb->ntranslations =
1480 spp_host_to_net_byte_order_16(udb->ntranslations);
1481 mp_udb->icmp_msg_count = udb->icmp_msg_count;
1482 mp_udb->flags = udb->flags;
1483 mp_udb->portmap_index =
1484 spp_host_to_net_byte_order_32(udb->portmap_index);
1485 mp_udb->key.k.ipv4 =
1486 spp_host_to_net_byte_order_32(udb->key.k.ipv4);
1487 mp_udb->key.k.port =
1488 spp_host_to_net_byte_order_16(udb->key.k.port);
1490 spp_host_to_net_byte_order_16(udb->key.k.vrf);
1491 mp_udb->user_hash.next =
1492 spp_host_to_net_byte_order_32(udb->user_hash.next);
1494 my_vrfmap_index = vrf_map_array[u_ki.k.k.vrf];
1495 my_vrfmap = cnat_map_by_vrf + my_vrfmap_index;
1496 pm = my_vrfmap->portmap_list;
1497 my_pm = pm + udb->portmap_index;
1500 * Fill in the port_map information
1502 result_array[i++] = spp_host_to_net_byte_order_32((u32) my_pm);
1503 result_array[i++] = spp_host_to_net_byte_order_32(my_pm->inuse);
1504 result_array[i++] = spp_host_to_net_byte_order_32(my_pm->delete_time);
1505 result_array[i++] = spp_host_to_net_byte_order_32(my_pm->ipv4_address);
1507 mp_resp->num_bytes = spp_host_to_net_byte_order_32(i*4);
1510 spp_api_cnat_generic_command_debug(mp_resp);
1514 * The following commands implements command to dump the
1515 * DB usage stats for
1521 * The format of the output is:
1522 * Word 0: Main-DB - Total
1523 * Word 1: Main-DB - Active
1524 * Word 2: Main-DB - Free
1525 * Word 3: User-DB - Total
1526 * Word 4: User-DB - Active
1527 * Word 5: User-DB - Free
1528 * Word 6: Hash In2Out - Size
1529 * Word 7: Hash In2Out - Used
1530 * Word 8: Hash In2Out - Used Percentage
1531 * Word 9: Hash Out2In - Size
1532 * Word A: Hash Out2In - Used
1533 * Word B: Hash Out2In - Used Percentage
1535 void spp_api_cnat_generic_command_db_summary
1536 (spp_api_cnat_generic_command_request_t *mp)
1538 u32 count1, count2, count3;
1541 cnat_generic_command_resp *mp_resp;
1545 * Request structure is used to send the response
1547 mp_resp = (cnat_generic_command_resp *) mp;
1548 result_array = (u32 *) (&(mp_resp->raw_data[0]));
1551 * Find entries free and used in main-db
1553 count1 = vec_len(cnat_main_db);
1554 count2 = db_free_entry(cnat_main_db);
1555 count3 = count1 - count2;
1557 *(result_array + i++) = spp_host_to_net_byte_order_32(count1);
1558 *(result_array + i++) = spp_host_to_net_byte_order_32(count3);
1559 *(result_array + i++) = spp_host_to_net_byte_order_32(count2);
1562 * Find entries free and used in user-db
1564 count1 = vec_len(cnat_user_db);
1565 count2 = db_free_entry(cnat_user_db);
1566 count3 = count1 - count2;
1568 *(result_array + i++) = spp_host_to_net_byte_order_32(count1);
1569 *(result_array + i++) = spp_host_to_net_byte_order_32(count3);
1570 *(result_array + i++) = spp_host_to_net_byte_order_32(count2);
1573 * Find entries used in in2out and out2in hash tables
1574 * and percentage utilization.
1576 count1 = count2 = 0;
1577 for (k = 0; k < CNAT_MAIN_HASH_SIZE; k++) {
1578 if(cnat_in2out_hash[k].next != ~0) count1++;
1579 if(cnat_out2in_hash[k].next != ~0) count2++;
1583 count3 = count1*100/CNAT_MAIN_HASH_SIZE;
1585 *(result_array + i++) = spp_host_to_net_byte_order_32(CNAT_MAIN_HASH_SIZE);
1586 *(result_array + i++) = spp_host_to_net_byte_order_32(count1);
1587 *(result_array + i++) = spp_host_to_net_byte_order_32(count3);
1589 count3 = count2*100/CNAT_MAIN_HASH_SIZE;
1591 *(result_array + i++) = spp_host_to_net_byte_order_32(CNAT_MAIN_HASH_SIZE);
1592 *(result_array + i++) = spp_host_to_net_byte_order_32(count2);
1593 *(result_array + i++) = spp_host_to_net_byte_order_32(count3);
1595 mp_resp->num_bytes = spp_host_to_net_byte_order_32(i*4);
1597 spp_api_cnat_generic_command_debug(mp_resp);
1601 * The following commands implements generic commands such as:
1604 * Reads num_bytes octets from a start_locn
1605 * generic command <core_num> <cmd_type=1> <start_locn> <num_bytes> 0 0 0 0 0
1608 * Writes upto 8 octets from a start_locn
1609 * generic command <core_num> <cmd_type=2> <start_locn> <num_bytes> 0 0 0 0 0
1612 * Dump the db summary stats
1613 * generic command <core_num> <cmd_type=3>
1616 * Dump the user db entry
1617 * generic command <core_num> <cmd_type=4> <vrf_id> <src_ip_addr>
1619 * The following structures are referenced by this command:
1620 * typedef struct _spp_api_cnat_generic_command_request {
1625 * } spp_api_cnat_generic_command_request_t;
1633 * } cnat_generic_command_resp;
1636 void spp_api_cnat_generic_command_request_t_handler
1637 (spp_api_cnat_generic_command_request_t *mp)
1639 cnat_generic_command_resp *resp_ptr;
1640 u32 command_type, start_locn, num_bytes;
1642 command_type = spp_net_to_host_byte_order_32(&mp->params[0]);
1643 resp_ptr = (cnat_generic_command_resp *) mp;
1645 switch (command_type) {
1646 case CNAT_DEBUG_GENERIC_COMMAND_READ_MEM:
1647 start_locn = spp_net_to_host_byte_order_32(&mp->params[1]);
1648 num_bytes = spp_net_to_host_byte_order_32(&mp->params[2]);
1649 memcpy(&(resp_ptr->raw_data[0]), (u8 *) start_locn, num_bytes);
1650 resp_ptr->num_bytes = spp_host_to_net_byte_order_32(num_bytes);
1656 for (i = 0; i < num_bytes; i++) {
1657 PLATFORM_DEBUG_PRINT("0x%02X ", resp_ptr->raw_data[i]);
1658 if ((i % 16) == 15) {
1659 PLATFORM_DEBUG_PRINT("\n");
1666 case CNAT_DEBUG_GENERIC_COMMAND_WRITE_MEM:
1667 start_locn = spp_net_to_host_byte_order_32(&mp->params[1]);
1668 num_bytes = spp_net_to_host_byte_order_32(&mp->params[2]);
1670 if (num_bytes > sizeof(u64)) {
1671 mp->rc = CNAT_ERR_INVALID_MSG_SIZE;
1675 memcpy((u8 *) start_locn, &(mp->params[3]), num_bytes);
1676 resp_ptr->num_bytes = 0;
1679 case CNAT_DEBUG_GENERIC_COMMAND_DB_SUMMARY:
1680 spp_api_cnat_generic_command_db_summary(mp);
1683 case CNAT_DEBUG_GENERIC_COMMAND_USER_DB_PM:
1684 spp_api_cnat_generic_command_user_db_pm(mp);
1687 case CNAT_DEBUG_GET_CGN_DB_SUMMARY:
1688 spp_api_cnat_get_cgn_db_summary(mp);
1692 mp->rc = CNAT_ERR_INVALID_MSG_ID;
1698 static int cnat_debug_init (void *notused)
1700 spp_msg_api_set_handler(SPP_API_CNAT_V4_DEBUG_DUMMY,
1701 spp_api_cnat_v4_debug_dummy_t_handler);
1703 spp_msg_api_set_handler(SPP_API_CNAT_V4_DEBUG_DUMMY_MAX,
1704 spp_api_cnat_v4_debug_dummy_max_t_handler);
1706 spp_msg_api_set_handler(SPP_API_CNAT_V4_DEBUG_GLOBAL,
1707 spp_api_cnat_v4_debug_global_t_handler);
1709 spp_msg_api_set_handler(SPP_API_CNAT_V4_DEBUG_IN2OUT_PRIVATE_ADDR,
1710 spp_api_cnat_v4_debug_in2out_private_addr_t_handler);
1712 spp_msg_api_set_handler(SPP_API_CNAT_V4_DEBUG_OUT2IN_PUBLIC_ADDR,
1713 spp_api_cnat_v4_debug_out2in_public_addr_t_handler);
1715 spp_msg_api_set_handler(SPP_API_CNAT_CLEAR_DB_REQUEST,
1716 spp_api_cnat_clear_db_request_t_handler);
1718 spp_msg_api_set_handler(SPP_API_CNAT_GENERIC_COMMAND_REQUEST,
1719 spp_api_cnat_generic_command_request_t_handler);
1721 spp_msg_api_set_handler(SPP_API_CNAT_P2MP_DEBUG_REQUEST,
1722 spp_api_cnat_p2mp_debug_request_t_handler);
1724 spp_msg_api_set_handler(SPP_API_NAT64_CLEAR_DB_REQUEST,
1725 spp_api_nat64_clear_db_request_t_handler);
1727 spp_msg_api_set_handler(SPP_API_DS_LITE_CLEAR_DB_REQUEST,
1728 spp_api_ds_lite_clear_db_request_t_handler);
1734 ************************
1735 * spp_api_cnat_get_cgn_db_summary
1736 * This is for finding out the per core CPU users and utilization
1737 ************************
1740 void spp_api_cnat_get_cgn_db_summary
1741 (spp_api_cnat_generic_command_request_t *mp)
1743 u32 total_db_entries, total_free_entries, used_entries;
1745 cnat_generic_command_resp *mp_resp;
1749 * Request structure is used to send the response
1751 mp_resp = (cnat_generic_command_resp *) mp;
1752 result_array = (u32 *) (&(mp_resp->raw_data[0]));
1755 * Find entries free and used in main-db
1757 total_db_entries = vec_len(cnat_main_db);
1758 total_free_entries = db_free_entry(cnat_main_db);
1759 used_entries = total_db_entries - total_free_entries;
1761 *(result_array + i++) = spp_host_to_net_byte_order_32(total_db_entries);
1762 *(result_array + i++) = spp_host_to_net_byte_order_32(used_entries);
1763 *(result_array + i++) = spp_host_to_net_byte_order_32(total_free_entries);
1766 * Find entries free and used in user-db
1768 total_db_entries = vec_len(cnat_user_db);
1769 total_free_entries = db_free_entry(cnat_user_db);
1770 used_entries = total_db_entries - total_free_entries;
1772 *(result_array + i++) = spp_host_to_net_byte_order_32(total_db_entries);
1773 *(result_array + i++) = spp_host_to_net_byte_order_32(used_entries);
1774 *(result_array + i++) = spp_host_to_net_byte_order_32(total_free_entries);
1776 mp_resp->num_bytes = spp_host_to_net_byte_order_32(i*sizeof(u32));
1779 SPP_INIT_FUNCTION(cnat_debug_init);
1780 #endif /* TOBE_PORTED */