X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=VNFs%2FDPPD-PROX%2Flog.c;h=2fa63f34ffb3f8cfbf0854a8ba225cffc625a3fc;hb=e2ce11c54f2f64df472c64bcf03c9f858e79b835;hp=cd8ee002746f0dceeaa52ce21087c8d24614e9ac;hpb=7286b2518ec8e4398b512ce95def9166a7af2e4a;p=samplevnf.git diff --git a/VNFs/DPPD-PROX/log.c b/VNFs/DPPD-PROX/log.c index cd8ee002..2fa63f34 100644 --- a/VNFs/DPPD-PROX/log.c +++ b/VNFs/DPPD-PROX/log.c @@ -25,9 +25,12 @@ #include #include "log.h" +#include "quit.h" #include "display.h" +#include "defaults.h" #include "etypes.h" #include "prox_cfg.h" +#include "prox_compat.h" static pthread_mutex_t file_mtx = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; int log_lvl = PROX_MAX_LOG_LVL; @@ -55,7 +58,7 @@ const char *get_warning(int i) static void store_warning(const char *warning) { - strncpy(last_warn[n_warnings % 5], warning, sizeof(last_warn[0])); + prox_strncpy(last_warn[n_warnings % 5], warning, sizeof(last_warn[0])); n_warnings++; } @@ -68,10 +71,10 @@ void plog_init(const char *log_name, int log_name_pid) if (log_name_pid) snprintf(buf, sizeof(buf), "%s-%u.log", "prox", getpid()); else - strncpy(buf, "prox.log", sizeof(buf)); + prox_strncpy(buf, "prox.log", sizeof(buf)); } else { - strncpy(buf, log_name, sizeof(buf)); + prox_strncpy(buf, log_name, sizeof(buf)); } fp = fopen(buf, "w"); @@ -79,6 +82,13 @@ void plog_init(const char *log_name, int log_name_pid) tsc_off = rte_rdtsc() + 2500000000; } +void plog_end(void) +{ + if (fp) + fclose(fp); + fp = NULL; +} + int plog_set_lvl(int lvl) { if (lvl <= PROX_MAX_LOG_LVL) { @@ -140,11 +150,10 @@ static const char* lvl_to_str(int lvl, int always) } } -#define DUMP_PKT_LEN 128 static int dump_pkt(char *dst, size_t dst_size, const struct rte_mbuf *mbuf) { - const struct ether_hdr *peth = rte_pktmbuf_mtod(mbuf, const struct ether_hdr *); - const struct ipv4_hdr *dpip = (const struct ipv4_hdr *)(peth + 1); + const prox_rte_ether_hdr *peth = rte_pktmbuf_mtod(mbuf, const prox_rte_ether_hdr *); + const prox_rte_ipv4_hdr *dpip = (const prox_rte_ipv4_hdr *)(peth + 1); const uint8_t *pkt_bytes = (const uint8_t *)peth; const uint16_t len = rte_pktmbuf_pkt_len(mbuf); size_t str_len = 0; @@ -204,6 +213,10 @@ static int vplog(int lvl, const char *format, va_list ap, const struct rte_mbuf ret--; ret += dump_pkt(buf + ret, sizeof(buf) - ret, mbuf); } + + if (lvl == PROX_LOG_PANIC) + PROX_PANIC(1, "%s", buf); + plog_buf(buf); if (lvl == PROX_LOG_WARN) { @@ -270,6 +283,23 @@ int plog_err(const char *fmt, ...) return ret; } +int plog_err_or_panic(int do_panic, const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + if (do_panic) { + ret = vplog(PROX_LOG_PANIC, fmt, ap, NULL, 0); + va_end(ap); + return ret; + } else { + ret = vplog(PROX_LOG_ERR, fmt, ap, NULL, 0); + va_end(ap); + return ret; + } +} + int plogx_err(const char *fmt, ...) { va_list ap;