summaryrefslogtreecommitdiff
path: root/ipanat
diff options
context:
space:
mode:
authorSkylar Chang <chiaweic@codeaurora.org>2013-06-26 19:13:29 -0700
committerRavi Gummadidala <rgummadi@codeaurora.org>2013-07-05 12:23:22 -0700
commitda7c82dff7bea0b08dab1ab87eeb55189b7261f3 (patch)
tree8afee5b9a76dbd653487df37f47bdd238d4942d3 /ipanat
parenta1289c21aba594204716504b4f8e3e1da543465b (diff)
downloadipacfg-mgr-da7c82dff7bea0b08dab1ab87eeb55189b7261f3.tar.gz
IPACM/IPANAT: Fix using syslog causing crash
Before IPACM/IPANAT use the same syslog circular buffer to log messages, now they write the info to different files using circular memory instead. Change-Id: I8b637be2aa12d7e4999799b4b780133446422d2a Signed-off-by: Skylar Chang <chiaweic@codeaurora.org> Signed-off-by: Ravi Gummadidala <rgummadi@codeaurora.org>
Diffstat (limited to 'ipanat')
-rw-r--r--ipanat/inc/ipa_nat_drvi.h5
-rw-r--r--ipanat/inc/ipa_nat_logi.h40
-rw-r--r--ipanat/src/Makefile.am2
-rw-r--r--ipanat/src/ipa_nat_drv.c7
-rw-r--r--[-rwxr-xr-x]ipanat/src/ipa_nat_drvi.c12
-rw-r--r--ipanat/src/ipa_nat_logi.c68
6 files changed, 32 insertions, 102 deletions
diff --git a/ipanat/inc/ipa_nat_drvi.h b/ipanat/inc/ipa_nat_drvi.h
index 2a5a5ba..6fce315 100644
--- a/ipanat/inc/ipa_nat_drvi.h
+++ b/ipanat/inc/ipa_nat_drvi.h
@@ -407,8 +407,9 @@ int ipa_nati_query_timestamp(uint32_t tbl_hdl,
uint32_t rule_hdl,
uint32_t *time_stamp);
-uint32_t ipa_nati_add_ipv4_rule(uint32_t tbl_hdl,
- const ipa_nat_ipv4_rule *clnt_rule);
+int ipa_nati_add_ipv4_rule(uint32_t tbl_hdl,
+ const ipa_nat_ipv4_rule *clnt_rule,
+ uint32_t *rule_hdl);
int ipa_nati_generate_rule(uint32_t tbl_hdl,
const ipa_nat_ipv4_rule *clnt_rule,
diff --git a/ipanat/inc/ipa_nat_logi.h b/ipanat/inc/ipa_nat_logi.h
index b4eee0f..0e1a5d1 100644
--- a/ipanat/inc/ipa_nat_logi.h
+++ b/ipanat/inc/ipa_nat_logi.h
@@ -50,32 +50,24 @@ extern "C"
#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_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_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_INFO);\
- }
-
-extern void log_nat_message(char *msg, int log_level);
-extern char nat_log_buf[NAT_LOG_SIZE];
+
+#define IPAERR(fmt, ...) syslog(LOG_ERR, "ERROR: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);\
+ printf("ERR: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
+
+#ifdef DEBUG
+#define IPADBG(fmt, ...) syslog(LOG_DEBUG, "%s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);\
+ printf("%s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
+
+#define IPADUMP(fmt, ...) syslog(LOG_DEBUG, fmt, ##__VA_ARGS__);\
+ printf(fmt, ##__VA_ARGS__);
+
+#else
+#define IPADBG(fmt, ...)
+#define IPADUMP(fmt, ...)
+#endif
+
#ifdef __cplusplus
}
diff --git a/ipanat/src/Makefile.am b/ipanat/src/Makefile.am
index a688893..ef6969e 100644
--- a/ipanat/src/Makefile.am
+++ b/ipanat/src/Makefile.am
@@ -1,6 +1,6 @@
AM_CFLAGS = -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs
AM_CFLAGS += -I./../inc
-AM_CFLAGS += -DDEBUG
+#AM_CFLAGS += -DDEBUG
c_sources = ipa_nat_drv.c \
ipa_nat_drvi.c \
diff --git a/ipanat/src/ipa_nat_drv.c b/ipanat/src/ipa_nat_drv.c
index 68e2de8..2b62a3c 100644
--- a/ipanat/src/ipa_nat_drv.c
+++ b/ipanat/src/ipa_nat_drv.c
@@ -110,9 +110,12 @@ int ipa_nat_add_ipv4_rule(uint32_t tbl_hdl,
}
IPADBG("Passed Table handle: 0x%x\n", tbl_hdl);
- *rule_hdl = ipa_nati_add_ipv4_rule(tbl_hdl, clnt_rule);
- IPADBG("returning rule handle 0x%x\n", *rule_hdl);
+ if(ipa_nati_add_ipv4_rule(tbl_hdl, clnt_rule, rule_hdl) != 0)
+ {
+ return -1;
+ }
+ IPADBG("returning rule handle 0x%x\n", *rule_hdl);
return 0;
}
diff --git a/ipanat/src/ipa_nat_drvi.c b/ipanat/src/ipa_nat_drvi.c
index 692509f..5678306 100755..100644
--- a/ipanat/src/ipa_nat_drvi.c
+++ b/ipanat/src/ipa_nat_drvi.c
@@ -1072,14 +1072,14 @@ int ipa_nati_query_timestamp(uint32_t tbl_hdl,
return 0;
}
-uint32_t ipa_nati_add_ipv4_rule(uint32_t tbl_hdl,
- const ipa_nat_ipv4_rule *clnt_rule)
+int ipa_nati_add_ipv4_rule(uint32_t tbl_hdl,
+ const ipa_nat_ipv4_rule *clnt_rule,
+ uint32_t *rule_hdl)
{
struct ipa_nat_ip4_table_cache *tbl_ptr;
struct ipa_nat_sw_rule sw_rule;
struct ipa_nat_indx_tbl_sw_rule index_sw_rule;
uint16_t new_entry, new_index_tbl_entry;
- uint32_t rule_hdl = 0;
memset(&sw_rule, 0, sizeof(sw_rule));
memset(&index_sw_rule, 0, sizeof(index_sw_rule));
@@ -1108,8 +1108,8 @@ uint32_t ipa_nati_add_ipv4_rule(uint32_t tbl_hdl,
}
/* Generate rule handle */
- rule_hdl = ipa_nati_make_rule_hdl((uint16_t)tbl_hdl, new_entry);
- if (!rule_hdl)
+ *rule_hdl = ipa_nati_make_rule_hdl((uint16_t)tbl_hdl, new_entry);
+ if (!(*rule_hdl))
{
IPAERR("unable to generate rule handle\n");
return -1;
@@ -1119,7 +1119,7 @@ uint32_t ipa_nati_add_ipv4_rule(uint32_t tbl_hdl,
ipa_nat_dump_ipv4_table(tbl_hdl);
#endif
- return rule_hdl;
+ return 0;
}
int ipa_nati_generate_rule(uint32_t tbl_hdl,
const ipa_nat_ipv4_rule *clnt_rule,
diff --git a/ipanat/src/ipa_nat_logi.c b/ipanat/src/ipa_nat_logi.c
index ead8154..b829b78 100644
--- a/ipanat/src/ipa_nat_logi.c
+++ b/ipanat/src/ipa_nat_logi.c
@@ -41,74 +41,8 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#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"
-
-/* 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, int log_level)
+void log_nat_message(char *msg)
{
-#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(access(LOG_USE_SYS, F_OK) != -1 )
- {
- log_sys = 1;
- }
- else if(access(LOG_USE_FILE, F_OK) != -1)
- {
- log_file = 1;
- }
- else
- {
- 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);
- }
-#endif
return;
}