diff options
author | Ravi Gummadidala <rgummadi@codeaurora.org> | 2013-04-12 13:47:02 -0700 |
---|---|---|
committer | Ravi Gummadidala <rgummadi@codeaurora.org> | 2013-04-15 08:55:38 -0700 |
commit | 87b30d91f84558bca275282bd741f7c48cd1f1a4 (patch) | |
tree | cd7b146047cc5dd78aca7cabe8d7600bdd9cf2f9 /ipanat | |
parent | 4367ae1f6ee8e35f3406f13d198b460b2c56bd49 (diff) | |
download | ipacfg-mgr-87b30d91f84558bca275282bd741f7c48cd1f1a4.tar.gz |
1. adding sys log support
2. added dynamic enabled/disable file/sys log
3. added circular file log
Change-Id: I9f7de1779239d0617b6b171e3a4e40d439711185
Diffstat (limited to 'ipanat')
-rw-r--r-- | ipanat/inc/ipa_nat_drvi.h | 1 | ||||
-rw-r--r-- | ipanat/inc/ipa_nat_logi.h | 11 | ||||
-rw-r--r-- | ipanat/src/Makefile.am | 1 | ||||
-rw-r--r-- | ipanat/src/ipa_nat_drvi.c | 115 | ||||
-rw-r--r-- | ipanat/src/ipa_nat_logi.c | 69 |
5 files changed, 178 insertions, 19 deletions
diff --git a/ipanat/inc/ipa_nat_drvi.h b/ipanat/inc/ipa_nat_drvi.h index 25309e1..2a5a5ba 100644 --- a/ipanat/inc/ipa_nat_drvi.h +++ b/ipanat/inc/ipa_nat_drvi.h @@ -468,6 +468,7 @@ void ipa_nati_del_dead_ipv4_head_nodes(uint8_t tbl_indx); void ipa_nati_print_rule(struct ipa_nat_rule *rule, uint32_t rule_id); void ipa_nat_dump_ipv4_table(uint32_t tbl_hdl); void ipa_nati_print_index_rule(struct ipa_nat_indx_tbl_rule *param, uint32_t rule_id); +int ipa_nati_query_nat_rules(uint32_t tbl_hdl, nat_table_type tbl_type); #endif #endif /* #ifndef IPA_NAT_DRVI_H */ diff --git a/ipanat/inc/ipa_nat_logi.h b/ipanat/inc/ipa_nat_logi.h index e98445a..b4eee0f 100644 --- a/ipanat/inc/ipa_nat_logi.h +++ b/ipanat/inc/ipa_nat_logi.h @@ -48,34 +48,33 @@ extern "C" #include <stdio.h> #include <string.h> +#include <syslog.h> #define NAT_LOG_SIZE 200 #define PERROR(fmt) printf("%s:%d %s()", __FILE__, __LINE__, __FUNCTION__);\ perror(fmt); - #define IPADBG(fmt, ...) {\ int n =0; \ n = snprintf(nat_log_buf, sizeof(nat_log_buf), "%s:%d %s() ", __FILE__, __LINE__, __FUNCTION__);\ snprintf((nat_log_buf+n), (sizeof(nat_log_buf)-n-1), fmt, ##__VA_ARGS__);\ - log_nat_message(nat_log_buf);\ + log_nat_message(nat_log_buf, LOG_DEBUG);\ } - #define IPAERR(fmt, ...) {\ int n =0; \ n = snprintf(nat_log_buf, sizeof(nat_log_buf), "%s:%d %s() %s", __FILE__, __LINE__, __FUNCTION__, "Error:");\ snprintf((nat_log_buf+n), (sizeof(nat_log_buf)-n-1), fmt, ##__VA_ARGS__);\ - log_nat_message(nat_log_buf);\ + log_nat_message(nat_log_buf, LOG_ERR);\ } #define IPADUMP(fmt, ...) {\ int n =0; \ snprintf((nat_log_buf+n), (sizeof(nat_log_buf)-1), fmt, ##__VA_ARGS__);\ - log_nat_message(nat_log_buf);\ + log_nat_message(nat_log_buf, LOG_INFO);\ } -extern void log_nat_message(char *msg); +extern void log_nat_message(char *msg, int log_level); extern char nat_log_buf[NAT_LOG_SIZE]; #ifdef __cplusplus diff --git a/ipanat/src/Makefile.am b/ipanat/src/Makefile.am index f8b775c..a688893 100644 --- a/ipanat/src/Makefile.am +++ b/ipanat/src/Makefile.am @@ -1,5 +1,6 @@ AM_CFLAGS = -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs AM_CFLAGS += -I./../inc +AM_CFLAGS += -DDEBUG c_sources = ipa_nat_drv.c \ ipa_nat_drvi.c \ diff --git a/ipanat/src/ipa_nat_drvi.c b/ipanat/src/ipa_nat_drvi.c index 106abac..dbe9102 100644 --- a/ipanat/src/ipa_nat_drvi.c +++ b/ipanat/src/ipa_nat_drvi.c @@ -2262,7 +2262,6 @@ void ipa_nat_dump_ipv4_table(uint32_t tbl_hdl) INDX_TBL_TBL_ENTRY_FIELD)) { ipa_nati_print_index_rule(&indx_tbl_ptr[cnt], cnt); - //ipa_nati_dump_index_rule_buf(&indx_tbl_ptr[cnt], sizeof(struct ipa_nat_indx_tbl_rule), cnt); } } if(!atl_one) @@ -2284,7 +2283,6 @@ void ipa_nat_dump_ipv4_table(uint32_t tbl_hdl) INDX_TBL_TBL_ENTRY_FIELD)) { ipa_nati_print_index_rule(&indx_tbl_ptr[cnt], cnt); - //ipa_nati_dump_index_rule_buf(&indx_tbl_ptr[cnt], sizeof(struct ipa_nat_indx_tbl_rule), cnt); } } if(!atl_one) @@ -2320,4 +2318,117 @@ void ipa_nati_print_index_rule(struct ipa_nat_indx_tbl_rule *param, uint32_t rul IPADUMP("\n"); return; } + +int ipa_nati_query_nat_rules(uint32_t tbl_hdl, nat_table_type tbl_type) +{ + + struct ipa_nat_rule *tbl_ptr; + struct ipa_nat_indx_tbl_rule *indx_tbl_ptr; + int cnt =0, ret = 0; + + if (IPA_NAT_INVALID_NAT_ENTRY == tbl_hdl || + tbl_hdl > IPA_NAT_MAX_IP4_TBLS) + { + IPAERR("invalid table handle passed \n"); + return ret; + } + + /* Print ipv4 rules */ + if (tbl_type == IPA_NAT_BASE_TBL) + { + IPADBG("Counting ipv4 active rules:\n"); + tbl_ptr = (struct ipa_nat_rule *) + ipv4_nat_cache.ip4_tbl[tbl_hdl-1].ipv4_rules_addr; + for( cnt=0; + cnt<ipv4_nat_cache.ip4_tbl[tbl_hdl-1].table_entries; + cnt++) + { + if (Read16BitFieldValue( tbl_ptr[cnt].ip_cksm_enbl, + ENABLE_FIELD)) + { + ret++; + } + } + if(!ret) + { + IPADBG("No active base rules\n"); + } + + IPADBG("Number of active base rules: %d\n", ret); + } + + /* Print ipv4 expansion rules */ + if (tbl_type == IPA_NAT_EXPN_TBL) + { + IPADBG("Counting ipv4 active expansion rules:\n"); + tbl_ptr = (struct ipa_nat_rule *) + ipv4_nat_cache.ip4_tbl[tbl_hdl-1].ipv4_expn_rules_addr; + for( cnt=0; + cnt<ipv4_nat_cache.ip4_tbl[tbl_hdl-1].expn_table_entries; + cnt++) + { + if (Read16BitFieldValue(tbl_ptr[cnt].ip_cksm_enbl, + ENABLE_FIELD)) + { + ret++; + } + } + if(!ret) + { + IPADBG("No active base expansion rules\n"); + } + + IPADBG("Number of active base expansion rules: %d\n", ret); + } + + /* Print ipv4 index rules */ + if (tbl_type == IPA_NAT_INDX_TBL) + { + IPADBG("Counting ipv4 index active rules: \n"); + indx_tbl_ptr = (struct ipa_nat_indx_tbl_rule *) + ipv4_nat_cache.ip4_tbl[tbl_hdl-1].index_table_addr; + for( cnt=0; + cnt<ipv4_nat_cache.ip4_tbl[tbl_hdl-1].table_entries; + cnt++) + { + if (Read16BitFieldValue(indx_tbl_ptr[cnt].tbl_entry_nxt_indx, + INDX_TBL_TBL_ENTRY_FIELD)) + { + ret++; + } + } + if(!ret) + { + IPADBG("No active index table rules\n"); + } + + IPADBG("Number of active index table rules: %d\n", ret); + } + + /* Print ipv4 index expansion rules */ + if (tbl_type == IPA_NAT_INDEX_EXPN_TBL) + { + IPADBG("Counting ipv4 index expansion active rules: \n"); + indx_tbl_ptr = (struct ipa_nat_indx_tbl_rule *) + ipv4_nat_cache.ip4_tbl[tbl_hdl-1].index_table_expn_addr; + for ( cnt=0; + cnt<ipv4_nat_cache.ip4_tbl[tbl_hdl-1].expn_table_entries; + cnt++) + { + if (Read16BitFieldValue(indx_tbl_ptr[cnt].tbl_entry_nxt_indx, + INDX_TBL_TBL_ENTRY_FIELD)) + { + ret++; + } + } + if(!ret) + { + IPADBG("No active index expansion rules\n"); + } + + IPADBG("Number of active index expansion rules: %d\n", ret); + } + + return ret; +} #endif diff --git a/ipanat/src/ipa_nat_logi.c b/ipanat/src/ipa_nat_logi.c index 11991c9..ead8154 100644 --- a/ipanat/src/ipa_nat_logi.c +++ b/ipanat/src/ipa_nat_logi.c @@ -39,28 +39,75 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "ipa_nat_logi.h" #include <stdlib.h> +#include <unistd.h> +/* write logging to a local file */ +#define LOG_USE_FILE "/etc/IPACM_LOG_F" #define NAT_FILE_NAME "/usr/ipanat_log.txt" -static FILE *nat_fp = NULL; +/* To use syslog for logging and + use logread cmd to read */ +#define LOG_USE_SYS "/etc/IPACM_LOG_S" + +/* Maximum log file size. 1MB(1048576) */ +#define MAX_LOG_FILE_SIZE (1048576ul/4) + char nat_log_buf[NAT_LOG_SIZE]; -void log_nat_message(char *msg) +void log_nat_message(char *msg, int log_level) { +#ifdef DEBUG + static FILE *nat_fp = NULL; + static int is_natsys_log_open = 0; + int log_sys = 0, log_file = 0; + printf("%s", msg); -#if 0 - if(nat_fp == NULL) + if(access(LOG_USE_SYS, F_OK) != -1 ) + { + log_sys = 1; + } + else if(access(LOG_USE_FILE, F_OK) != -1) + { + log_file = 1; + } + else { - nat_fp = fopen(NAT_FILE_NAME, "wb+"); - if(nat_fp == NULL) - { + log_sys = 0; + log_file = 0; + } + + if(log_sys) + { + if(is_natsys_log_open == 0) + { + setlogmask(LOG_UPTO(LOG_DEBUG)); + openlog("IPANAT", LOG_PID, LOG_LOCAL0); + + is_natsys_log_open = 1; + } + syslog(log_level, msg); + } + else if(log_file) + { + if(nat_fp == NULL) + { + nat_fp = fopen(NAT_FILE_NAME, "wb+"); + if(nat_fp == NULL) + { printf("unable to open file\n"); return; - } - } + } + } + + if(ftell(nat_fp) > MAX_LOG_FILE_SIZE) + { + rewind(nat_fp); + fprintf(nat_fp, "====Rewinding=====\n"); + } - fprintf(nat_fp, msg); - fflush(nat_fp); + fprintf(nat_fp, msg); + fflush(nat_fp); + } #endif return; } |