diff --git a/src/runmode-af-packet.c b/src/runmode-af-packet.c index 74ebbb3a76..a8f20faa3d 100644 --- a/src/runmode-af-packet.c +++ b/src/runmode-af-packet.c @@ -125,7 +125,7 @@ void *ParseAFPConfig(const char *iface) aconf->cluster_id = 1; aconf->cluster_type = PACKET_FANOUT_HASH; aconf->promisc = 1; - aconf->detect_offload = 1; + aconf->checksum_mode = CHECKSUM_VALIDATION_KERNEL; aconf->DerefFunc = AFPDerefConfig; /* Find initial node */ @@ -204,14 +204,25 @@ void *ParseAFPConfig(const char *iface) aconf->iface); aconf->promisc = 0; } - ConfGetChildValueBool(if_root, "detect-offload", (int *)&boolval); - if (! boolval) { - SCLogInfo("Disabling checksum offloading detection for %s", - aconf->iface); - aconf->detect_offload = 0; - } - + if (ConfGetChildValue(if_root, "checksum-checks", &tmpctype) != 1) { + SCLogError(SC_ERR_INVALID_ARGUMENT, "Could not get checksum-checks from config"); + } else { + if (strcmp(tmpctype, "auto") == 0) { + SCLogError(SC_ERR_INVALID_ARGUMENT,"'auto' mode is currently not supported"); + /* + aconf->checksum_mode = CHECKSUM_VALIDATION_AUTO; + */ + } else if (strcmp(tmpctype, "yes") == 0) { + aconf->checksum_mode = CHECKSUM_VALIDATION_ENABLE; + } else if (strcmp(tmpctype, "no") == 0) { + aconf->checksum_mode = CHECKSUM_VALIDATION_DISABLE; + } else if (strcmp(tmpctype, "kernel") == 0) { + aconf->checksum_mode = CHECKSUM_VALIDATION_KERNEL; + } else { + SCLogError(SC_ERR_INVALID_ARGUMENT, "Invalid value for checksum-checks for %s", aconf->iface); + } + } return aconf; } diff --git a/src/source-af-packet.c b/src/source-af-packet.c index da3f4ea26c..016f9d2a7e 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -160,14 +160,13 @@ typedef struct AFPThreadVars_ /* socket buffer size */ int buffer_size; int promisc; - int detect_offload; + ChecksumValidationMode checksum_mode; int cluster_id; int cluster_type; int threads; - } AFPThreadVars; TmEcode ReceiveAFP(ThreadVars *, Packet *, void *, PacketQueue *, PacketQueue *); @@ -290,21 +289,29 @@ int AFPRead(AFPThreadVars *ptv) SCLogDebug("pktlen: %" PRIu32 " (pkt %p, pkt data %p)", GET_PKT_LEN(p), p, GET_PKT_DATA(p)); - for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { - struct tpacket_auxdata *aux; - - if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct tpacket_auxdata)) || - cmsg->cmsg_level != SOL_PACKET || - cmsg->cmsg_type != PACKET_AUXDATA) - continue; + /* We only check for checksum disable */ + if (ptv->checksum_mode == CHECKSUM_VALIDATION_DISABLE) { + p->flags |= PKT_IGNORE_CHECKSUM; + } else { + /* List is NULL if we don't have activated auxiliary data */ + for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { + struct tpacket_auxdata *aux; + + if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct tpacket_auxdata)) || + cmsg->cmsg_level != SOL_PACKET || + cmsg->cmsg_type != PACKET_AUXDATA) + continue; - aux = (struct tpacket_auxdata *)CMSG_DATA(cmsg); + aux = (struct tpacket_auxdata *)CMSG_DATA(cmsg); - if (aux->tp_status & TP_STATUS_CSUMNOTREADY) { - p->flags |= PKT_IGNORE_CHECKSUM; + if (aux->tp_status & TP_STATUS_CSUMNOTREADY) { + p->flags |= PKT_IGNORE_CHECKSUM; + } + break; } } + if (TmThreadsSlotProcessPkt(ptv->tv, ptv->slot, p) != TM_ECODE_OK) { TmqhOutputPacketpool(ptv->tv, p); SCReturnInt(AFP_FAILURE); @@ -523,7 +530,7 @@ static int AFPCreateSocket(AFPThreadVars *ptv, char *devname, int verbose) } } - if (ptv->detect_offload) { + if (ptv->checksum_mode == CHECKSUM_VALIDATION_KERNEL) { int val = 1; if (setsockopt(ptv->socket, SOL_PACKET, PACKET_AUXDATA, &val, sizeof(val)) == -1 && errno != ENOPROTOOPT) { @@ -613,7 +620,7 @@ TmEcode ReceiveAFPThreadInit(ThreadVars *tv, void *initdata, void **data) { ptv->buffer_size = afpconfig->buffer_size; ptv->promisc = afpconfig->promisc; - ptv->detect_offload = afpconfig->detect_offload; + ptv->checksum_mode = afpconfig->checksum_mode; ptv->threads = 1; #ifdef HAVE_PACKET_FANOUT diff --git a/src/source-af-packet.h b/src/source-af-packet.h index a5fadd3a31..bd51b58951 100644 --- a/src/source-af-packet.h +++ b/src/source-af-packet.h @@ -53,8 +53,7 @@ typedef struct AFPIfaceConfig_ int cluster_type; /* promisc mode */ int promisc; - /* no local packet */ - int detect_offload; + ChecksumValidationMode checksum_mode; SC_ATOMIC_DECLARE(unsigned int, ref); void (*DerefFunc)(void *); } AFPIfaceConfig;