From 52936818604e0e3b322fadb1dc4620f5f202c3fd Mon Sep 17 00:00:00 2001 From: Gurvinder Singh Date: Tue, 9 Feb 2010 17:43:29 +0100 Subject: [PATCH] b86 --- Makefile.am | 1 + src/source-nfq.c | 10 ++++++---- src/source-pcap-file.c | 10 +++++++--- src/source-pcap.c | 21 ++++++++++++++------- src/util-error.c | 3 +++ src/util-error.h | 1 + 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/Makefile.am b/Makefile.am index eb11e825d9..d86e2bbc30 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,7 @@ # not a GNU package. You can remove this line, if # have all needed files, that a GNU package needs AUTOMAKE_OPTIONS = foreign 1.4 +ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = ChangeLog COPYING LICENSE suricata.yaml \ doc/AUTHORS doc/GITGUIDE doc/INSTALL doc/NEWS \ doc/README doc/TODO diff --git a/src/source-nfq.c b/src/source-nfq.c index 911f406cf2..93224b4c0b 100644 --- a/src/source-nfq.c +++ b/src/source-nfq.c @@ -212,10 +212,12 @@ TmEcode NFQInitThread(NFQThreadVars *nfq_t, uint16_t queue_num, uint32_t queue_m * run. Ignoring the error seems to have no bad effects. */ SCLogDebug("unbinding existing nf_queue handler for AF_INET (if any)"); if (nfq_unbind_pf(nfq_t->h, AF_INET) < 0) { - SCLogWarning(SC_ERR_NFQ_UNBIND, "nfq_unbind_pf() for AF_INET failed"); + SCLogError(SC_ERR_NFQ_UNBIND, "nfq_unbind_pf() for AF_INET failed"); + exit(EXIT_FAILURE); } if (nfq_unbind_pf(nfq_t->h, AF_INET6) < 0) { - SCLogWarning(SC_ERR_NFQ_UNBIND, "nfq_unbind_pf() for AF_INET6 failed"); + SCLogError(SC_ERR_NFQ_UNBIND, "nfq_unbind_pf() for AF_INET6 failed"); + exit(EXIT_FAILURE); } nfq_g.unbind = 1; @@ -223,11 +225,11 @@ TmEcode NFQInitThread(NFQThreadVars *nfq_t, uint16_t queue_num, uint32_t queue_m if (nfq_bind_pf(nfq_t->h, AF_INET) < 0) { SCLogError(SC_ERR_NFQ_BIND, "nfq_bind_pf() for AF_INET failed"); - return TM_ECODE_FAILED; + exit(EXIT_FAILURE); } if (nfq_bind_pf(nfq_t->h, AF_INET6) < 0) { SCLogError(SC_ERR_NFQ_BIND, "nfq_bind_pf() for AF_INET6 failed"); - return TM_ECODE_FAILED; + exit(EXIT_FAILURE); } } diff --git a/src/source-pcap-file.c b/src/source-pcap-file.c index c28f1c547f..4240381c22 100644 --- a/src/source-pcap-file.c +++ b/src/source-pcap-file.c @@ -143,8 +143,9 @@ TmEcode ReceivePcapFileThreadInit(ThreadVars *tv, void *initdata, void **data) { char errbuf[PCAP_ERRBUF_SIZE] = ""; pcap_g.pcap_handle = pcap_open_offline((char *)initdata, errbuf); if (pcap_g.pcap_handle == NULL) { - printf("error %s\n", errbuf); - return TM_ECODE_FAILED; + SCLogError(SC_ERR_FOPEN, "%s\n", errbuf); + free(ptv); + exit(EXIT_FAILURE); } if (ConfGet("bpf-filter", &tmpbpfstring) != 1) { @@ -154,11 +155,13 @@ TmEcode ReceivePcapFileThreadInit(ThreadVars *tv, void *initdata, void **data) { if(pcap_compile(pcap_g.pcap_handle,&pcap_g.filter,tmpbpfstring,1,0) < 0) { SCLogError(SC_ERR_BPF,"bpf compilation error %s",pcap_geterr(pcap_g.pcap_handle)); + free(ptv); return TM_ECODE_FAILED; } if(pcap_setfilter(pcap_g.pcap_handle,&pcap_g.filter) < 0) { SCLogError(SC_ERR_BPF,"could not set bpf filter %s",pcap_geterr(pcap_g.pcap_handle)); + free(ptv); return TM_ECODE_FAILED; } } @@ -181,7 +184,8 @@ TmEcode ReceivePcapFileThreadInit(ThreadVars *tv, void *initdata, void **data) { break; default: - printf("Error: datalink type %" PRId32 " not (yet) supported in module PcapFile.\n", pcap_g.datalink); + SCLogError(SC_ERR_UNIMPLEMENTED, "datalink type %" PRId32 " not " + "(yet) supported in module PcapFile.\n", pcap_g.datalink); free(ptv); return TM_ECODE_FAILED; } diff --git a/src/source-pcap.c b/src/source-pcap.c index 7b72642e7e..76721299e1 100644 --- a/src/source-pcap.c +++ b/src/source-pcap.c @@ -168,7 +168,7 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { char *tmpbpfstring; if (initdata == NULL) { - printf("ReceivePcapThreadInit error: initdata == NULL\n"); + SCLogError(SC_ERR_PCAP_RECV_INIT, "initdata == NULL"); return TM_ECODE_FAILED; } @@ -186,7 +186,8 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { char errbuf[PCAP_ERRBUF_SIZE]; ptv->pcap_handle = pcap_create((char *)initdata, errbuf); if (ptv->pcap_handle == NULL) { - printf("error %s\n", pcap_geterr(ptv->pcap_handle)); + SCLogError(SC_ERR_PCAP_RECV_INIT, " %s", pcap_geterr(ptv->pcap_handle)); + free(ptv); return TM_ECODE_FAILED; } @@ -194,21 +195,24 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { int pcap_set_snaplen_r = pcap_set_snaplen(ptv->pcap_handle,LIBPCAP_SNAPLEN); //printf("ReceivePcapThreadInit: pcap_set_snaplen(%p) returned %" PRId32 "\n", ptv->pcap_handle, pcap_set_snaplen_r); if (pcap_set_snaplen_r != 0) { - printf("ReceivePcapThreadInit: error is %s\n", pcap_geterr(ptv->pcap_handle)); + SCLogError(SC_ERR_PCAP_RECV_INIT, " %s", pcap_geterr(ptv->pcap_handle)); + free(ptv); return TM_ECODE_FAILED; } int pcap_set_promisc_r = pcap_set_promisc(ptv->pcap_handle,LIBPCAP_PROMISC); //printf("ReceivePcapThreadInit: pcap_set_promisc(%p) returned %" PRId32 "\n", ptv->pcap_handle, pcap_set_promisc_r); if (pcap_set_promisc_r != 0) { - printf("ReceivePcapThreadInit: error is %s\n", pcap_geterr(ptv->pcap_handle)); + SCLogError(SC_ERR_PCAP_RECV_INIT, "%s", pcap_geterr(ptv->pcap_handle)); + free(ptv); return TM_ECODE_FAILED; } int pcap_set_timeout_r = pcap_set_timeout(ptv->pcap_handle,LIBPCAP_COPYWAIT); //printf("ReceivePcapThreadInit: pcap_set_timeout(%p) returned %" PRId32 "\n", ptv->pcap_handle, pcap_set_timeout_r); if (pcap_set_timeout_r != 0) { - printf("ReceivePcapThreadInit: error is %s\n", pcap_geterr(ptv->pcap_handle)); + SCLogError(SC_ERR_PCAP_RECV_INIT, " %s", pcap_geterr(ptv->pcap_handle)); + free(ptv); return TM_ECODE_FAILED; } @@ -216,8 +220,9 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { int pcap_activate_r = pcap_activate(ptv->pcap_handle); //printf("ReceivePcapThreadInit: pcap_activate(%p) returned %" PRId32 "\n", ptv->pcap_handle, pcap_activate_r); if (pcap_activate_r != 0) { - printf("ReceivePcapThreadInit: error is %s\n", pcap_geterr(ptv->pcap_handle)); - return TM_ECODE_FAILED; + SCLogError(SC_ERR_PCAP_RECV_INIT, " %s", pcap_geterr(ptv->pcap_handle)); + free(ptv); + exit(EXIT_FAILURE); } /* set bpf filter if we have one */ @@ -228,11 +233,13 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { if(pcap_compile(ptv->pcap_handle,&ptv->filter,tmpbpfstring,1,0) < 0) { SCLogError(SC_ERR_BPF,"bpf compilation error %s",pcap_geterr(ptv->pcap_handle)); + free(ptv); return TM_ECODE_FAILED; } if(pcap_setfilter(ptv->pcap_handle,&ptv->filter) < 0) { SCLogError(SC_ERR_BPF,"could not set bpf filter %s",pcap_geterr(ptv->pcap_handle)); + free(ptv); return TM_ECODE_FAILED; } } diff --git a/src/util-error.c b/src/util-error.c index 72ee54e1ce..3d2fb1cc84 100644 --- a/src/util-error.c +++ b/src/util-error.c @@ -95,6 +95,9 @@ const char * SCErrorToString(SCError err) CASE_CODE (SC_ERR_INVALID_VALUE); CASE_CODE (SC_ERR_UNKNOWN_REGEX_MOD); CASE_CODE (SC_ERR_INVALID_OPERATOR); + CASE_CODE (SC_ERR_PCAP_RECV_INIT); + CASE_CODE (SC_ERR_NFQ_UNBIND); + CASE_CODE (SC_ERR_NFQ_BIND); default: return "UNKNOWN_ERROR"; } diff --git a/src/util-error.h b/src/util-error.h index dc032bc59a..13c7c43a06 100644 --- a/src/util-error.h +++ b/src/util-error.h @@ -114,6 +114,7 @@ typedef enum { SC_ERR_INVALID_VALUE, SC_ERR_UNKNOWN_REGEX_MOD, SC_ERR_INVALID_OPERATOR, + SC_ERR_PCAP_RECV_INIT, } SCError; const char *SCErrorToString(SCError);