Commit 9ee312b1 authored by 's avatar
Browse files

Fixed debug logging in bpfcompiler module.

Added the error check in log.c.


git-svn-id: file:///home/svn/mapi/trunk@1302 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent f6bb8a78
......@@ -44,7 +44,6 @@
#include <limits.h>
#include <stdarg.h>
#include "debug.h"
#include "utils.h"
#include "bpfcompiler.h"
......@@ -112,7 +111,7 @@ int main(int argc, char **argv)
if ((filter = dagdsm_bpf_compile(filter, inbuf, lineno, errbuf)) == NULL)
fatal("%s: Compilation error on input line %d: %s\n", argv[0], lineno, errbuf);
DEBUG_CMD3(fprintf(stderr, "line %d filtermask 0x%08x\n", lineno, dagdsm_bpf_get_last_usage_mask(filter)));
BPF_DEBUG_CMD(fprintf(stderr, "line %d filtermask 0x%08x\n", lineno, dagdsm_bpf_get_last_usage_mask(filter)));
}
filter_count = dagdsm_bpf_get_filter_count(filter);
......
......@@ -144,7 +144,6 @@ LUP configuration tool
#include <setjmp.h>
#include <string.h>
#include "debug.h"
#include "utils.h"
#include "bpfcompiler.h"
......@@ -330,7 +329,7 @@ static char **transform_and_compile(node_t *b, int *count)
rules = xmalloc(sizeof(char *) * *count);
DEBUG_CMD3(
BPF_DEBUG_CMD(
fprintf(stderr, "resulting rules:\n");
for (i=0; i < *count; i++) {
fprintf(stderr, "%u: ", i+1);
......@@ -339,13 +338,13 @@ static char **transform_and_compile(node_t *b, int *count)
}
)
DEBUG_CMD3(fprintf(stderr, "compiled filter rules:\n"));
BPF_DEBUG_CMD(fprintf(stderr, "compiled filter rules:\n"));
for (i=0; i < *count; i++) {
DEBUG_CMD3(fprintf(stderr, "%u: ", i+1));
BPF_DEBUG_CMD(fprintf(stderr, "%u: ", i+1));
dsclear(&s);
combo6_compile_node(&s, list[i]);
rules[i] = dsstrdup(&s);
DEBUG_CMD3(fprintf(stderr, "%s\n", rules[i]));
BPF_DEBUG_CMD(fprintf(stderr, "%s\n", rules[i]));
}
dsfree(&s);
......@@ -372,7 +371,7 @@ combo6_bpf_filter_t *combo6_bpf_compile(combo6_bpf_filter_t *bpf_filter, char *b
//TODO: Test for the same filter_default values
DEBUG_CMD3(fprintf(stderr, "combo6_bpf_compile: %s\n", buf));
BPF_DEBUG_CMD(fprintf(stderr, "combo6_bpf_compile: %s\n", buf));
/* Compile BPF filter */
if (bpf_compile(&root, errbuf, buf, 1) < 0) {
......@@ -390,9 +389,9 @@ combo6_bpf_filter_t *combo6_bpf_compile(combo6_bpf_filter_t *bpf_filter, char *b
}
DEBUG_CMD3(fprintf(stderr, "compiled node: "));
DEBUG_CMD3(print_node(stderr, root));
DEBUG_CMD3(fprintf(stderr, "\n"));
BPF_DEBUG_CMD(fprintf(stderr, "compiled node: "));
BPF_DEBUG_CMD(print_node(stderr, root));
BPF_DEBUG_CMD(fprintf(stderr, "\n"));
/* Transform and compile filter in */
rules = transform_and_compile(root, &nrules);
......@@ -425,7 +424,7 @@ combo6_bpf_filter_t *combo6_bpf_compile(combo6_bpf_filter_t *bpf_filter, char *b
bpf_filter->filters[filter_cnt-1] = filter;
bpf_filter->filter_default = filter_default;
DEBUG_CMD3(fprintf(stderr, "compiling finished\n"));
BPF_DEBUG_CMD(fprintf(stderr, "compiling finished\n"));
return bpf_filter;
}
......
......@@ -107,7 +107,6 @@ Structure of Unified_Header
#include <setjmp.h>
#include <string.h>
#include "debug.h"
#include "utils.h"
#include "bpfcompiler.h"
#include "bpf_dagdsm.h"
......@@ -272,7 +271,7 @@ static char **transform_and_compile(node_t *b, int *count)
rules = xmalloc(sizeof(char *) * *count);
DEBUG_CMD3(
BPF_DEBUG_CMD(
fprintf(stderr, "resulting rules:\n");
for (i=0; i < *count; i++) {
fprintf(stderr, "%u: ", i+1);
......@@ -310,11 +309,11 @@ dagdsm_bpf_filter_t *dagdsm_bpf_compile(dagdsm_bpf_filter_t *bpf_filter, char *b
int filter_cnt;
if (buf == NULL) {
ERROR_CMD(fprintf(stderr, "dagdsm_bpf_compile: BPF expression is NULL.\n"));
BPF_DEBUG_CMD(fprintf(stderr, "dagdsm_bpf_compile: BPF expression is NULL.\n"));
return NULL;
}
DEBUG_CMD3(fprintf(stderr, "*** dagdsm_bpf_compile expression #%d: %s\n", index, buf));
BPF_DEBUG_CMD(fprintf(stderr, "*** dagdsm_bpf_compile expression #%d: %s\n", index, buf));
/* Compile BPF filter */
if (bpf_compile(&root, errbuf, buf, 0) < 0) {
......@@ -331,9 +330,9 @@ dagdsm_bpf_filter_t *dagdsm_bpf_compile(dagdsm_bpf_filter_t *bpf_filter, char *b
return NULL;
}
DEBUG_CMD3(fprintf(stderr, "compiled node: "));
DEBUG_CMD3(print_node(stderr, root));
DEBUG_CMD3(fprintf(stderr, "\n"));
BPF_DEBUG_CMD(fprintf(stderr, "compiled node: "));
BPF_DEBUG_CMD(print_node(stderr, root));
BPF_DEBUG_CMD(fprintf(stderr, "\n"));
/* Transform and compile filter in */
rules = transform_and_compile(root, &nrules);
......@@ -364,7 +363,7 @@ dagdsm_bpf_filter_t *dagdsm_bpf_compile(dagdsm_bpf_filter_t *bpf_filter, char *b
bpf_filter->filters = filters;
bpf_filter->filters[filter_cnt-1] = filter;
DEBUG_CMD3(fprintf(stderr, "compiling finished\n"));
BPF_DEBUG_CMD(fprintf(stderr, "compiling finished\n"));
return bpf_filter;
}
......@@ -379,7 +378,7 @@ char *dagdsm_bpf_xprintf(dagdsm_bpf_filter_t *bpf_filter, int always_match, bal_
int f, ff, r, first_cnt, cnt = 0;
if (bpf_filter == NULL) {
ERROR_CMD(fprintf(stderr, "dagdsm_bpf_xprintf: NULL argument.\n"));
BPF_DEBUG_CMD(fprintf(stderr, "dagdsm_bpf_xprintf: NULL argument.\n"));
return NULL;
}
......@@ -423,7 +422,7 @@ char *dagdsm_bpf_xprintf(dagdsm_bpf_filter_t *bpf_filter, int always_match, bal_
if (always_match) {
if (cnt == 0) {
ERROR_CMD(fprintf(stderr, "bpfcompiler: Specified always-match feature, but there are no filters to bypass!\n"));
printf("bpfcompiler: Specified always-match feature, but there are no filters to bypass!\n");
} else {
dsprintf(&s, " <partial-component invert=\"true\">filter0</partial-component>"
" <!-- This component ensures all packets are accepted to the stream (classification only mode). -->\n");
......@@ -519,11 +518,11 @@ unsigned int dagdsm_bpf_get_last_usage_mask(dagdsm_bpf_filter_t *bpf_filter)
for (; nr ; nr--)
mask |= (1 << (i+nr-1));
} else {
ERROR_CMD(fprintf(stderr, "dagdsm_bpf_get_last_usage_mask: Too many filters for the width of int type!\n"));
BPF_DEBUG_CMD(fprintf(stderr, "dagdsm_bpf_get_last_usage_mask: Too many filters for the width of int type!\n"));
}
}
} else {
ERROR_CMD(fprintf(stderr, "dagdsm_bpf_get_last_usage_mask: NULL argument.\n"));
BPF_DEBUG_CMD(fprintf(stderr, "dagdsm_bpf_get_last_usage_mask: NULL argument.\n"));
}
return mask;
......
......@@ -41,7 +41,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "debug.h"
#include "utils.h"
#include "bpf_node.h"
#include "bpf_compile.h"
......@@ -144,24 +143,24 @@ node_t **transform_tree(node_t *b, int *count)
int dnf = 1;
node_t **list;
DEBUG_CMD3(fprintf(stderr, "transform_tree\n"));
BPF_DEBUG_CMD(fprintf(stderr, "transform_tree\n"));
while (transform(b, &dnf)) {
i++;
dnf = 1;
}
DEBUG_CMD3(fprintf(stderr, "transformation cycles: %u, dnf deep: %u\n", i, dnf));
BPF_DEBUG_CMD(fprintf(stderr, "transformation cycles: %u, dnf deep: %u\n", i, dnf));
list = xmalloc(sizeof(node_t) * dnf);
*count = 0;
dnf_list(b, list, count);
if (*count != dnf) {
DEBUG_CMD3(fprintf(stderr, "transform_tree error, bad dnf.\n"));
BPF_DEBUG_CMD(fprintf(stderr, "transform_tree error, bad dnf.\n"));
return NULL;
}
DEBUG_CMD3(fprintf(stderr, "transformation completed\n"));
BPF_DEBUG_CMD(fprintf(stderr, "transformation completed\n"));
return list;
}
......@@ -42,6 +42,12 @@
#define CERROR() ERROR("compilation error [%s:%d]", __FILE__, __LINE__)
#if 0
# define BPF_DEBUG_CMD(code) code
#else
# define BPF_DEBUG_CMD(code)
#endif
typedef struct dstring {
int size;
int nchars;
......
......@@ -275,13 +275,17 @@ int get_log_level(char *mapi_conf){
int log_level = LOGGING_DISABLED;
if(pc_load(mapi_conf)){
log_level = atoi(pc_get_param(pc_get_category(""), "log_level")); // TODO check for error values
if(log_level == 0) log_level = LOG_INFORMATION;
else if(log_level == 1) log_level = LOG_INFO_DEBUG_ALL;
else if(log_level == 2) log_level = LOG_INFO_DEBUG_NOT_STDOUT;
else log_level = LOG_INFO_DEBUG_NOT_STDOUT; // default level
char *log_level_str = pc_get_param(pc_get_category(""), "log_level");
if (log_level_str != NULL) {
log_level = atoi(log_level_str);
if(log_level == 0) log_level = LOG_INFORMATION;
else if(log_level == 1) log_level = LOG_INFO_DEBUG_ALL;
else if(log_level == 2) log_level = LOG_INFO_DEBUG_NOT_STDOUT;
else log_level = LOG_INFO_DEBUG_NOT_STDOUT; // default level
} else {
log_level = LOG_INFO_DEBUG_NOT_STDOUT; // default level
}
pc_close ();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment