From d24b3a0e50942a544629025f59071d2c4cc73873 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Thu, 5 Jan 2012 17:24:14 +0100 Subject: [PATCH] Clean up csum detection output, misc fixes. --- src/runmode-af-packet.c | 4 +--- src/runmode-pcap.c | 4 +--- src/runmode-pfring.c | 11 ++++------- src/source-pcap.c | 3 ++- src/util-checksum.c | 27 ++++++++++++++++----------- src/util-checksum.h | 5 ++--- src/util-device.c | 2 +- src/util-device.h | 6 +++--- 8 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/runmode-af-packet.c b/src/runmode-af-packet.c index cd3e94137a..cb48e604c4 100644 --- a/src/runmode-af-packet.c +++ b/src/runmode-af-packet.c @@ -205,9 +205,7 @@ void *ParseAFPConfig(const char *iface) aconf->promisc = 0; } - if (ConfGetChildValue(if_root, "checksum-checks", &tmpctype) != 1) { - SCLogError(SC_ERR_INVALID_ARGUMENT, "Could not get checksum-checks from config"); - } else { + if (ConfGetChildValue(if_root, "checksum-checks", &tmpctype) == 1) { if (strcmp(tmpctype, "auto") == 0) { aconf->checksum_mode = CHECKSUM_VALIDATION_AUTO; } else if (strcmp(tmpctype, "yes") == 0) { diff --git a/src/runmode-pcap.c b/src/runmode-pcap.c index ddbeb7f28a..26b59350f6 100644 --- a/src/runmode-pcap.c +++ b/src/runmode-pcap.c @@ -145,9 +145,7 @@ void *ParsePcapConfig(const char *iface) SCLogInfo("BPF filter set from command line or via old 'bpf-filter' option."); } - if (ConfGetChildValue(if_root, "checksum-checks", &tmpctype) != 1) { - SCLogError(SC_ERR_INVALID_ARGUMENT, "Could not get checksum-checks from config"); - } else { + if (ConfGetChildValue(if_root, "checksum-checks", &tmpctype) == 1) { if (strcmp(tmpctype, "auto") == 0) { aconf->checksum_mode = CHECKSUM_VALIDATION_AUTO; } else if (strcmp(tmpctype, "yes") == 0) { diff --git a/src/runmode-pfring.c b/src/runmode-pfring.c index bc938c5049..bbc7eaaeb6 100644 --- a/src/runmode-pfring.c +++ b/src/runmode-pfring.c @@ -194,8 +194,8 @@ void *ParsePfringConfig(const char *iface) ConfNode *pf_ring_node; PfringIfaceConfig *pfconf = SCMalloc(sizeof(*pfconf)); char *tmpclusterid; -#ifdef HAVE_PFRING_CLUSTER_TYPE char *tmpctype = NULL; +#ifdef HAVE_PFRING_CLUSTER_TYPE cluster_type default_ctype = CLUSTER_ROUND_ROBIN; int getctype = 0; #endif @@ -316,9 +316,9 @@ void *ParsePfringConfig(const char *iface) } } - if (ConfGetChildValue(if_root, "checksum-checks", &tmpctype) != 1) { - SCLogError(SC_ERR_INVALID_ARGUMENT, "Could not get checksum-checks from config"); - } else { +#endif /* HAVE_PFRING_CLUSTER_TYPE */ + + if (ConfGetChildValue(if_root, "checksum-checks", &tmpctype) == 1) { if (strcmp(tmpctype, "auto") == 0) { pfconf->checksum_mode = CHECKSUM_VALIDATION_AUTO; } else if (strcmp(tmpctype, "yes") == 0) { @@ -332,9 +332,6 @@ void *ParsePfringConfig(const char *iface) } } - -#endif - return pfconf; } diff --git a/src/source-pcap.c b/src/source-pcap.c index db9688ee44..8075b41585 100644 --- a/src/source-pcap.c +++ b/src/source-pcap.c @@ -393,7 +393,8 @@ TmEcode ReceivePcapThreadInit(ThreadVars *tv, void *initdata, void **data) { #ifdef HAVE_PCAP_SET_BUFF ptv->pcap_buffer_size = pcapconfig->buffer_size; if (ptv->pcap_buffer_size >= 0 && ptv->pcap_buffer_size <= INT_MAX) { - SCLogInfo("Going to use pcap buffer size of %" PRId32 "", ptv->pcap_buffer_size); + if (ptv->pcap_buffer_size > 0) + SCLogInfo("Going to use pcap buffer size of %" PRId32 "", ptv->pcap_buffer_size); int pcap_set_buffer_size_r = pcap_set_buffer_size(ptv->pcap_handle,ptv->pcap_buffer_size); //printf("ReceivePcapThreadInit: pcap_set_timeout(%p) returned %" PRId32 "\n", ptv->pcap_handle, pcap_set_buffer_size_r); diff --git a/src/util-checksum.c b/src/util-checksum.c index d08d2058d4..5184064e17 100644 --- a/src/util-checksum.c +++ b/src/util-checksum.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Open Information Security Foundation +/* Copyright (C) 2011-2012 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -60,25 +60,30 @@ int ReCalculateChecksum(Packet *p) return 0; } - +/** + * \brief Check if the number of invalid checksums indicate checksum + * offloading in place. + * + * \retval 1 yes, offloading in place + * \retval 0 no, no offloading used + */ int ChecksumAutoModeCheck(uint32_t thread_count, - uint32_t iface_count, - uint32_t iface_fail) + unsigned int iface_count, unsigned int iface_fail) { if (thread_count == CHECKSUM_SAMPLE_COUNT) { if (iface_fail != 0) { if ((iface_count / iface_fail) < CHECKSUM_INVALID_RATIO) { - SCLogInfo("More than 1/10 of invalid checksum, assuming checksum offloading is used (%d/%d)", - iface_fail, - iface_count); + SCLogInfo("More than 1/10th of packets have an invalid " + "checksum, assuming checksum offloading is used (%d/%d)", + iface_fail, iface_count); return 1; } else { - SCLogInfo("Less than 1/10 of invalid checksum, assuming checksum offloading is NOT used (%d/%d)", - iface_fail, - iface_count); + SCLogInfo("Less than 1/10th of packet have an invalid " + "checksum, assuming checksum offloading is NOT used (%d/%d)", + iface_fail, iface_count); } } else { - SCLogInfo("No packet with invalid checksum, assuming checksum offloading is NOT used"); + SCLogInfo("No packets with invalid checksum, assuming checksum offloading is NOT used"); } } return 0; diff --git a/src/util-checksum.h b/src/util-checksum.h index 949b482bda..fb0fc8b814 100644 --- a/src/util-checksum.h +++ b/src/util-checksum.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Open Information Security Foundation +/* Copyright (C) 2011-2012 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -26,8 +26,7 @@ int ReCalculateChecksum(Packet *p); int ChecksumAutoModeCheck(uint32_t thread_count, - uint32_t iface_count, - uint32_t iface_fail); + unsigned int iface_count, unsigned int iface_fail); /* constant linked with detection of interface with * invalid checksums */ diff --git a/src/util-device.c b/src/util-device.c index 0397c1d741..3718f0352a 100644 --- a/src/util-device.c +++ b/src/util-device.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Open Information Security Foundation +/* Copyright (C) 2011-2012 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free diff --git a/src/util-device.h b/src/util-device.h index f3f9019078..c740a5e6a4 100644 --- a/src/util-device.h +++ b/src/util-device.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Open Information Security Foundation +/* Copyright (C) 2011-2012 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -24,8 +24,8 @@ typedef struct LiveDevice_ { char *dev; /**< the device (e.g. "eth0") */ int ignore_checksum; - SC_ATOMIC_DECLARE(uint32_t, pkts); - SC_ATOMIC_DECLARE(uint32_t, invalid_checksums); + SC_ATOMIC_DECLARE(unsigned int, pkts); + SC_ATOMIC_DECLARE(unsigned int, invalid_checksums); TAILQ_ENTRY(LiveDevice_) next; } LiveDevice;