af-packet: clean APFPacketVar before release.

This patch resets the AFPPacketVar linked to a Packet in the release
function to avoid any side effect when the packet is reused. To do
so a new AFPV_CLEANUP macro has been introduced.
pull/82/merge
Eric Leblond 13 years ago committed by Victor Julien
parent 775f379e2b
commit 680e941a8f

@ -648,15 +648,17 @@ TmEcode AFPReleaseDataFromRing(ThreadVars *t, Packet *p)
} }
if (AFPDerefSocket(p->afp_v.mpeer) == 0) if (AFPDerefSocket(p->afp_v.mpeer) == 0)
return ret; goto cleanup;
if (p->afp_v.relptr) { if (p->afp_v.relptr) {
union thdr h; union thdr h;
h.raw = p->afp_v.relptr; h.raw = p->afp_v.relptr;
h.h2->tp_status = TP_STATUS_KERNEL; h.h2->tp_status = TP_STATUS_KERNEL;
return ret;
} }
return TM_ECODE_FAILED;
cleanup:
AFPV_CLEANUP(&p->afp_v);
return ret;
} }
/** /**

@ -93,7 +93,12 @@ typedef struct AFPPeer_ {
TAILQ_ENTRY(AFPPeer_) next; TAILQ_ENTRY(AFPPeer_) next;
} AFPPeer; } AFPPeer;
/* per packet AF_PACKET vars */ /**
* \brief per packet AF_PACKET vars
*
* This structure is used y the release data system and is cleaned
* up by the AFPV_CLEANUP macro below.
*/
typedef struct AFPPacketVars_ typedef struct AFPPacketVars_
{ {
void *relptr; void *relptr;
@ -105,6 +110,13 @@ typedef struct AFPPacketVars_
AFPPeer *mpeer; AFPPeer *mpeer;
} AFPPacketVars; } AFPPacketVars;
#define AFPV_CLEANUP(afpv) do { \
(afpv)->relptr = NULL; \
(afpv)->copy_mode = 0; \
(afpv)->peer = NULL; \
(afpv)->mpeer = NULL; \
} while(0)
/** /**
* @} * @}
*/ */

Loading…
Cancel
Save