From 882d98733fb7f267d7d022c671b9c9a6c9a55c7a Mon Sep 17 00:00:00 2001 From: Ken Steele Date: Mon, 11 Nov 2013 13:11:39 -0500 Subject: [PATCH] Fix pfring so that zero-copy mode can work. Detect when default_packet_size is zero, which enables zero-copy mode for pfring and in that case, do what AF Packet does and set pkt_ext pointer to the data and set PKT_ZERO_COPY flag. --- src/detect.c | 12 ++++-------- src/source-pfring.c | 11 +++++++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/detect.c b/src/detect.c index f1ce18c973..7c8f55a922 100644 --- a/src/detect.c +++ b/src/detect.c @@ -6536,8 +6536,8 @@ int SigTest24IPV4Keyword(void) memset(&th_v, 0, sizeof(ThreadVars)); memset(p1, 0, SIZE_OF_PACKET); memset(p2, 0, SIZE_OF_PACKET); - p1->ip4vars.comp_csum = -1; - p2->ip4vars.comp_csum = -1; + PACKET_RESET_CHECKSUMS(p1); + PACKET_RESET_CHECKSUMS(p2); p1->ip4h = (IPV4Hdr *)valid_raw_ipv4; @@ -6640,8 +6640,8 @@ int SigTest25NegativeIPV4Keyword(void) memset(&th_v, 0, sizeof(ThreadVars)); memset(p1, 0, SIZE_OF_PACKET); memset(p2, 0, SIZE_OF_PACKET); - p1->ip4vars.comp_csum = -1; - p2->ip4vars.comp_csum = -1; + PACKET_RESET_CHECKSUMS(p1); + PACKET_RESET_CHECKSUMS(p2); p1->ip4h = (IPV4Hdr *)valid_raw_ipv4; @@ -6861,9 +6861,7 @@ static int SigTest26TCPV4AndNegativeIPV4Keyword(void) memset(&th_v, 0, sizeof(ThreadVars)); memset(p1, 0, SIZE_OF_PACKET); - p1->pkt = (uint8_t *)(p1 + 1); memset(p2, 0, SIZE_OF_PACKET); - p2->pkt = (uint8_t *)(p2 + 1); PacketCopyData(p1, raw_ipv4, sizeof(raw_ipv4)); PacketCopyDataOffset(p1, GET_PKT_LEN(p1), valid_raw_tcp, sizeof(valid_raw_tcp)); @@ -6989,9 +6987,7 @@ static int SigTest26TCPV4AndIPV4Keyword(void) memset(&th_v, 0, sizeof(ThreadVars)); memset(p1, 0, SIZE_OF_PACKET); - p1->pkt = (uint8_t *)(p1 + 1); memset(p2, 0, SIZE_OF_PACKET); - p2->pkt = (uint8_t *)(p2 + 1); PacketCopyData(p1, raw_ipv4, sizeof(raw_ipv4)); PacketCopyDataOffset(p1, GET_PKT_LEN(p1), valid_raw_tcp, sizeof(valid_raw_tcp)); diff --git a/src/source-pfring.c b/src/source-pfring.c index 90e8ef8af2..92992f99bc 100644 --- a/src/source-pfring.c +++ b/src/source-pfring.c @@ -303,10 +303,17 @@ TmEcode ReceivePfringLoop(ThreadVars *tv, void *data, void *slot) /* Depending on what compile time options are used for pfring we either return 0 or -1 on error and always 1 for success */ #ifdef HAVE_PFRING_RECV_UCHAR - int r = pfring_recv(ptv->pd, (u_char**)&GET_PKT_DIRECT_DATA(p), - (u_int)GET_PKT_DIRECT_MAX_SIZE(p), + u_char *pkt_buffer = GET_PKT_DIRECT_DATA(p); + u_int buffer_size = GET_PKT_DIRECT_MAX_SIZE(p); + int r = pfring_recv(ptv->pd, &pkt_buffer, + buffer_size, &hdr, LIBPFRING_WAIT_FOR_INCOMING); + + /* Check for Zero-copy if buffer size is zero */ + if (buffer_size == 0) { + PacketSetData(p, pkt_buffer, hdr.caplen); + } #else int r = pfring_recv(ptv->pd, (char *)GET_PKT_DIRECT_DATA(p), (u_int)GET_PKT_DIRECT_MAX_SIZE(p), -- 2.47.2