20 #include <arpa/inet.h> 27 #define SYSLOG_DELIMITER ' ' 28 #define SYSLOG_FIELD_ABSENT '-' 35 #define PLATFORM_SYSLOG_DISP_NODE_IDX PLATFORM_NFV9_DISP_NODE_IDX 42 #define CNAT_SYSLOG_DEBUG_CODE 2 44 #if CNAT_SYSLOG_DEBUG_CODE > 3 45 #define SYSLOG_COND if(my_instance_number == 0) 47 #define SYSLOG_DEBUG_PRINTF1(a) SYSLOG_COND printf(a); 48 #define SYSLOG_DEBUG_PRINTF2(a, b) SYSLOG_COND printf(a, b); 49 #define SYSLOG_DEBUG_PRINTF3(a, b, c) SYSLOG_COND printf(a, b, c); 50 #define SYSLOG_DEBUG_PRINTF4(a, b, c, d) SYSLOG_COND printf(a, b, c, d); 54 #define SYSLOG_DEBUG_PRINTF1(a) 55 #define SYSLOG_DEBUG_PRINTF2(a, b) 56 #define SYSLOG_DEBUG_PRINTF3(a, b, c) 57 #define SYSLOG_DEBUG_PRINTF4(a, b, c, d) 65 if(logging_index ==
EMPTY) {
70 log_info = cnat_syslog_logging_info_pool + logging_index;
346 unsigned char *ptr,
unsigned char num)
364 inline static int __attribute__((unused))
367 unsigned char *temp = ptr;
438 #ifndef NO_BULK_LOGGING
455 #ifndef NO_BULK_LOGGING
470 cnat_syslog_dump_logging_context (
u32 value1,
486 printf(
"\nDumping %s packet at locn %d: time 0x%x",
487 (value2 == 1) ?
"CURRENT" :
"QUEUED",
491 printf(
"\ni_vrf 0x%x, ip_address 0x%x, port %d, pkt len %d",
513 printf(
"\nL2_HEADER + SHIM_HEADER: \n");
515 printf(
"\nIP_HEADER: \n");
517 printf(
"\nUDP_HEADER: \n");
519 printf(
"\nSyslog content..\n");
522 printf(
"%c", (
u8)(*(pkt_ptr + i)));
524 if((
u8)(*(pkt_ptr + i)) ==
'[')
532 c1 = (c3 >> 4) & 0xf;
535 ((c1 <= 9) ? (c1 +
'0') : (c1 - 10 +
'a')),
536 ((c2 <= 9) ? (c2 +
'0') : (c2 - 10 +
'a')));
557 spp_node_t *output_node;
561 output_node = spp_get_nodes() +
564 cnat_syslog_dump_logging_context (2, logging_info, 1);
566 if (
PREDICT_TRUE(output_node->sf.nused < SPP_MAXDISPATCH)) {
574 spp_dispatch_make_node_runnable(output_node);
575 output_node->sf.ctxs[output_node->sf.nused++] =
579 printf(
"\nSyslog: 2. Sending Current packet\n");
588 printf(
"\nSyslog: 2. Downstream congestion \n");
619 spp_node_t *output_node;
621 output_node = spp_get_nodes() +
624 cnat_syslog_dump_logging_context(1, logging_info, 2);
626 if(
PREDICT_TRUE(output_node->sf.nused < SPP_MAXDISPATCH)) {
635 spp_dispatch_make_node_runnable(output_node);
636 output_node->sf.ctxs[output_node->sf.nused++] =
659 void handle_pending_syslog_pkts()
661 spp_node_t *output_node;
666 output_node = spp_get_nodes() +
669 sf_nused = output_node->sf.nused;
671 pool_foreach (my_logging_info, cnat_syslog_logging_info_pool, ({
679 cnat_syslog_send_queued_pkt (my_logging_info);
682 ((current_timestamp -
690 SYSLOG_DEBUG_PRINTF4(
"\nLOG_TIMER: queued %p, curr %p, sf_nused %d",
691 my_logging_info->queued_logging_context,
692 my_logging_info->current_logging_context,
694 cnat_syslog_send_pkt(my_logging_info);
699 const unsigned char hex_numbers_single_digit[] =
700 {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
701 '9',
'a',
'b',
'c',
'd',
'e',
'f' };
703 inline static int u16_to_ascii_decimal_aligned(
704 unsigned char *ptr,
u16 num,
u16 min_digits)
713 unsigned char *temp = ptr;
714 int no_leading_zeros = 0;
716 if(num > 9999 || min_digits == 5) {
717 *temp++ = hex_numbers_single_digit[num/10000];
719 no_leading_zeros = 1;
722 if(no_leading_zeros || num > 999 || min_digits == 4) {
723 *temp++ = hex_numbers_single_digit[num/1000];
725 no_leading_zeros = 1;
728 if(no_leading_zeros || num > 99 || min_digits == 3) {
729 *temp++ = hex_numbers_single_digit[num/100];
731 no_leading_zeros = 1;
734 if(no_leading_zeros || num > 9 || min_digits == 2) {
735 *temp++ = hex_numbers_single_digit[num/10];
739 *temp++ = hex_numbers_single_digit[num];
744 inline static int u16_to_ascii_decimal_unaligned(
745 unsigned char *ptr,
u16 num)
755 unsigned char *temp = ptr;
756 int no_leading_zeros = 0;
759 *temp++ = hex_numbers_single_digit[num/10000];
761 no_leading_zeros = 1;
764 if(no_leading_zeros || num > 999) {
765 *temp++ = hex_numbers_single_digit[num/1000];
767 no_leading_zeros = 1;
770 if(no_leading_zeros || num > 99) {
771 *temp++ = hex_numbers_single_digit[num/100];
773 no_leading_zeros = 1;
776 if(no_leading_zeros || num > 9) {
777 *temp++ = hex_numbers_single_digit[num/10];
781 *temp++ = hex_numbers_single_digit[num];
786 static int syslog_get_timestamp(
unsigned char *ts)
788 static const char *months[] = {
"Jan ",
"Feb ",
"Mar ",
"Apr ",
"May ",
789 "Jun ",
"Jul ",
"Aug ",
"Sep ",
"Oct ",
"Nov ",
"Dec " };
791 unsigned char *temp = ts;
801 gmtime_r(&time, &tm1);
804 ts += u16_to_ascii_decimal_unaligned(ts, (tm1.tm_year + 1900));
810 ts += u16_to_ascii_decimal_unaligned(ts, tm1.tm_mday);
813 ts += u16_to_ascii_decimal_aligned(ts, tm1.tm_hour, 2);
816 ts += u16_to_ascii_decimal_aligned(ts, tm1.tm_min, 2);
819 ts += u16_to_ascii_decimal_aligned(ts, tm1.tm_sec, 2);
826 static char *syslog_service_string[] = {
"NAT44",
"DSLITE" };
834 } syslog_event_description_type;
836 const static syslog_event_description_type sys_log_event[] = {
837 {
"UserbasedA", 10 },
838 {
"UserbasedW", 10 },
839 {
"SessionbasedA", 13 },
840 {
"SessionbasedW", 13 },
841 {
"SessionbasedAD", 14 },
842 {
"SessionbasedWD", 14 },
843 {
"Portblockrunout", 15 },
844 {
"TCPseqmismatch", 14},
859 unsigned char *temp, *header;
861 temp = header = (
unsigned char *)
870 temp += syslog_get_timestamp(temp);
881 count = strlen(syslog_service_string[s_type]);
882 clib_memcpy(temp, syslog_service_string[s_type], count);
887 #ifdef SHOW_SYSLOG_TIMESTAMP 888 printf(
"\nSysLog TS: %s : Length %d", header, temp - header);
893 extern void cnat_logging_init();
920 void cnat_syslog_create_logging_context (
934 cnat_syslog_send_queued_pkt(logging_info);
949 if (spp_ctx_alloc(&ctx, 1) < 1) {
962 ctx->flags = SPP_CTX_END_OF_PACKET;
963 ctx->next_ctx_this_packet = (
spp_ctx_t*) SPP_CTX_NO_NEXT_CTX;
966 logging_info->
pkt_length = syslog_fill_header(logging_info, s_type);
974 inline static int u16_to_ascii_hex_unaligned(
975 unsigned char *ptr,
u16 num)
977 unsigned char nibble, *temp;
978 int no_leading_zeros = 0;
980 nibble = (num >> 12);
982 *temp++ = hex_numbers_single_digit[nibble];
983 no_leading_zeros = 1;
986 nibble = (num >> 8) & 0xF;
987 if(nibble || no_leading_zeros) {
988 *temp++ = hex_numbers_single_digit[nibble];
989 no_leading_zeros = 1;
992 nibble = (num >> 4) & 0xF;
993 if(nibble || no_leading_zeros) {
994 *temp++ = hex_numbers_single_digit[nibble];
997 *temp++ = hex_numbers_single_digit[num & 0xF];
1002 inline static int ipv6_int_2_str(
u32 ipv6[],
unsigned char *ipv6_str)
1009 #define DC_NOT_USED_YET 0 1011 #define DC_ALREADY_USED 2 1013 u16 *ipv6_temp = (
u16 *)ipv6;
1014 unsigned char *temp = ipv6_str;
1015 int double_colon = DC_NOT_USED_YET;
1016 for(i = 0; i < 7; i++) {
1018 ipv6_str += u16_to_ascii_hex_unaligned(ipv6_str, ipv6_temp[i]);
1020 if(double_colon == DC_IN_USE) {
1021 double_colon = DC_ALREADY_USED;
1024 if(double_colon == DC_IN_USE) {
1027 }
else if((ipv6_temp[i+1])
1029 || (double_colon != DC_NOT_USED_YET)) {
1030 ipv6_str += u16_to_ascii_hex_unaligned(ipv6_str,
1035 double_colon = DC_IN_USE;
1040 ipv6_str += u16_to_ascii_hex_unaligned(ipv6_str, ipv6_temp[7]);
1041 }
else if(double_colon != DC_IN_USE) {
1046 return ipv6_str - temp;
1051 void cnat_syslog_insert_nat44_record(
1065 unsigned char *temp, *record;
1066 u32 network_order_ipv6[4];
1081 clib_memcpy(record, sys_log_event[e_type].event_name,
1082 sys_log_event[e_type].name_length);
1083 record += sys_log_event[e_type].name_length;
1128 record += u16_to_ascii_decimal_unaligned(
1136 record += u16_to_ascii_decimal_unaligned(record, bulk_alloc);
1141 record += u16_to_ascii_decimal_unaligned(record,
1153 record += u16_to_ascii_decimal_unaligned(record, db->
dst_port);
1171 void cnat_syslog_insert_record(
1185 unsigned char *temp, *record;
1186 u32 network_order_ipv6[4];
1200 clib_memcpy(record, sys_log_event[e_type].event_name,
1201 sys_log_event[e_type].name_length);
1202 record += sys_log_event[e_type].name_length;
1226 #ifdef DSLITE_USER_IPV4 1243 network_order_ipv6[0] = htonl(udb->
ipv6[0]);
1244 network_order_ipv6[1] = htonl(udb->
ipv6[1]);
1245 network_order_ipv6[2] = htonl(udb->
ipv6[2]);
1246 network_order_ipv6[3] = htonl(udb->
ipv6[3]);
1248 inet_ntop(AF_INET6,network_order_ipv6,record,INET6_ADDRSTRLEN);
1249 record += strlen(record);
1259 record += u16_to_ascii_decimal_unaligned(
1267 record += u16_to_ascii_decimal_unaligned(record, bulk_alloc);
1272 record += u16_to_ascii_decimal_unaligned(record,
1283 record += u16_to_ascii_decimal_unaligned(record, db->
dst_port);
1301 #define SYSLOG_PRECHECK(entry, s_type) \ 1302 if(PREDICT_FALSE((entry)->syslog_logging_index == EMPTY)) { \ 1303 SYSLOG_DEBUG_PRINTF1("\n1. Log Mapping failed") \ 1307 cnat_syslog_logging_info_pool + (entry)->syslog_logging_index; \ 1308 if(PREDICT_FALSE(logging_info->current_logging_context == NULL)) { \ 1309 cnat_syslog_create_logging_context(logging_info, s_type); \ 1310 if(PREDICT_FALSE(logging_info->current_logging_context == NULL)) { \ 1311 SYSLOG_DEBUG_PRINTF1("\n2. Log Mapping failed") \ 1318 #ifndef NO_BULK_LOGGING
1328 SYSLOG_PRECHECK(vrfmap,
NAT44)
1330 #ifndef NO_BULK_LOGGING 1331 if(bulk_alloc > 0) {
1333 start_port = bulk_alloc;
1345 #ifndef NO_BULK_LOGGING 1349 cnat_syslog_insert_nat44_record(logging_info, db, vrfmap, sdb,
1350 start_port, e_type);
1361 cnat_syslog_send_pkt(logging_info);
1367 #ifndef NO_BULK_LOGGING
1376 SYSLOG_PRECHECK(dslite_entry,
DSLite)
1378 #ifndef NO_BULK_LOGGING 1379 if(bulk_alloc > 0) {
1381 start_port = bulk_alloc;
1393 #ifndef NO_BULK_LOGGING 1397 cnat_syslog_insert_record(logging_info, db, dslite_entry, sdb,
1398 start_port, e_type);
1409 cnat_syslog_send_pkt(logging_info);
1415 #ifndef NO_BULK_LOGGING
1425 SYSLOG_PRECHECK(vrfmap,
NAT44)
1427 #ifndef NO_BULK_LOGGING 1428 if(bulk_alloc > 0) {
1430 start_port = bulk_alloc;
1442 #ifndef NO_BULK_LOGGING 1445 cnat_syslog_insert_nat44_record(logging_info, db, vrfmap, sdb,
1446 start_port, e_type);
1455 cnat_syslog_send_pkt(logging_info);
1461 #ifndef NO_BULK_LOGGING
1470 SYSLOG_PRECHECK(dslite_entry,
DSLite)
1472 #ifndef NO_BULK_LOGGING 1473 if(bulk_alloc > 0) {
1475 start_port = bulk_alloc;
1487 #ifndef NO_BULK_LOGGING 1490 cnat_syslog_insert_record(logging_info, db, dslite_entry, sdb,
1491 start_port, e_type);
1502 cnat_syslog_send_pkt(logging_info);
1506 void cnat_syslog_dslite_insert_port_exceeded(
1514 u32 network_order_ipv6[4];
1515 unsigned char *temp, *record;
1551 network_order_ipv6[0] = htonl(key->
ipv6[0]);
1552 network_order_ipv6[1] = htonl(key->
ipv6[1]);
1553 network_order_ipv6[2] = htonl(key->
ipv6[2]);
1554 network_order_ipv6[3] = htonl(key->
ipv6[3]);
1556 inet_ntop(AF_INET6,network_order_ipv6,record,INET6_ADDRSTRLEN);
1557 record += strlen(record);
1563 record += u16_to_ascii_decimal_unaligned(
1590 SYSLOG_PRECHECK(dslite_entry,
DSLite)
1592 cnat_syslog_dslite_insert_port_exceeded(logging_info, key);
1603 cnat_syslog_send_pkt(logging_info);
1607 void cnat_syslog_nat44_insert_port_exceeded(
1615 unsigned char *temp, *record;
1657 record += u16_to_ascii_decimal_unaligned(
1658 record, key->
k.
port);
1678 void cnat_syslog_nat44_port_limit_exceeded(
1684 SYSLOG_PRECHECK(vrfmap,
NAT44)
1686 cnat_syslog_nat44_insert_port_exceeded(logging_info, key);
1697 cnat_syslog_send_pkt(logging_info);
1701 void cnat_syslog_nat44_insert_tcp_seq_mismatch(
1709 unsigned char *temp, *record;
1743 record += u16_to_ascii_decimal_unaligned(
1747 record += u16_to_ascii_decimal_unaligned(
1765 void cnat_syslog_nat44_tcp_seq_mismatch(
1771 SYSLOG_PRECHECK(vrfmap,
NAT44)
1773 cnat_syslog_nat44_insert_tcp_seq_mismatch(logging_info, db);
1784 cnat_syslog_send_pkt(logging_info);
u32 cnat_get_sys_up_time_in_ms(void)
sll srl srl sll sra u16x4 i
cnat_syslog_global_counters_t cnat_syslog_global_counter
static int copy_ipv4_addr(unsigned char *ptr, u32 ipv4)
Fixed length block allocator.
cnat_syslog_global_info_t cnat_syslog_global_info
#define CNAT_NFV9_HDR_OFFSET
u16 cnat_syslog_disp_node_index
void cnat_syslog_ds_lite_mapping_create(cnat_main_db_entry_t *db, dslite_table_entry_t *dslite_entry, cnat_session_entry_t *sdb, int bulk_alloc)
#define SYSLOG_DEBUG_PRINTF1(a)
void syslog_params_show(u32 logging_index)
spp_ctx_t * current_logging_context
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
void cnat_syslog_logging_init()
u32 cnat_get_unix_time_in_seconds(void)
void cnat_syslog_nat44_mapping_delete(cnat_main_db_entry_t *db, cnat_vrfmap_t *vrfmap, cnat_session_entry_t *sdb, int bulk_alloc)
spp_ctx_t * queued_logging_context
void cnat_syslog_fill_ip_header(cnat_syslog_logging_info_t *logging_info)
#define CACHE_ALLOC_NO_LOG_REQUIRED
#define SYSLOG_FIELD_ABSENT
void cnat_syslog_nat44_mapping_create(cnat_main_db_entry_t *db, cnat_vrfmap_t *vrfmap, cnat_session_entry_t *sdb, int bulk_alloc)
cnat_user_db_entry_t * cnat_user_db
u32 current_logging_context_timestamp
#define PLATFORM_SYSLOG_DISP_NODE_IDX
#define SESSION_LOG_ENABLE
void cnat_syslog_ds_lite_port_limit_exceeded(dslite_key_t *key, dslite_table_entry_t *dslite_entry)
#define clib_memcpy(a, b, c)
void cnat_syslog_log_mapping_create(cnat_main_db_entry_t *db, cnat_vrfmap_t *vrfmap)
#define BULKSIZE_FROM_VRFMAP(vrfmap)
u64 logging_context_creation_fail_count
#define SYSLOG_CONFIG_DEBUG_PRINTF(level,...)
void fill_ip_n_udp_hdr(u32 ipv4_addr, u16 port, cnat_nfv9_logging_info_t *nfv9_logging_info)
static int byte_to_ascii_decimal_unaligned(unsigned char *ptr, unsigned char num)
char vrf_name[VRF_NAME_LEN_STORED]
u16 max_length_minus_max_record_size
cnat_syslog_logging_info_t * cnat_syslog_logging_info_pool
cnat_icmp_msg_t icmp_msg_gen_allowed()
struct _spp_ctx spp_ctx_t
u64 logging_context_creation_deferred_count
void cnat_syslog_log_mapping_delete(cnat_main_db_entry_t *db, cnat_vrfmap_t *vrfmap)
char header_hostname[MAX_SYSLOG_HOSTNAME_LEN]
#define CNAT_NFV9_IP_HDR_OFFSET
#define CNAT_NFV9_UDP_HDR_OFFSET
u64 downstream_constipation_count
const unsigned char ascii_numbers[][3]