af-packet: minor code cleanups

pull/6600/head
Victor Julien 3 years ago
parent e3d20acb98
commit e63db9d1d2

@ -1168,14 +1168,11 @@ static inline int AFPParsePacketV3(AFPThreadVars *ptv, struct tpacket_block_desc
static inline int AFPWalkBlock(AFPThreadVars *ptv, struct tpacket_block_desc *pbd)
{
int num_pkts = pbd->hdr.bh1.num_pkts, i;
uint8_t *ppd;
int ret = 0;
ppd = (uint8_t *)pbd + pbd->hdr.bh1.offset_to_first_pkt;
for (i = 0; i < num_pkts; ++i) {
ret = AFPParsePacketV3(ptv, pbd,
(struct tpacket3_hdr *)ppd);
const int num_pkts = pbd->hdr.bh1.num_pkts;
uint8_t *ppd = (uint8_t *)pbd + pbd->hdr.bh1.offset_to_first_pkt;
for (int i = 0; i < num_pkts; ++i) {
int ret = AFPParsePacketV3(ptv, pbd, (struct tpacket3_hdr *)ppd);
switch (ret) {
case AFP_READ_OK:
break;
@ -1207,9 +1204,6 @@ static inline int AFPWalkBlock(AFPThreadVars *ptv, struct tpacket_block_desc *pb
static int AFPReadFromRingV3(AFPThreadVars *ptv)
{
#ifdef HAVE_TPACKET_V3
struct tpacket_block_desc *pbd;
int ret = 0;
/* Loop till we have packets available */
while (1) {
if (unlikely(suricata_ctl_flags != 0)) {
@ -1217,14 +1211,15 @@ static int AFPReadFromRingV3(AFPThreadVars *ptv)
break;
}
pbd = (struct tpacket_block_desc *) ptv->ring.v3[ptv->frame_offset].iov_base;
struct tpacket_block_desc *pbd =
(struct tpacket_block_desc *)ptv->ring.v3[ptv->frame_offset].iov_base;
/* block is not ready to be read */
if ((pbd->hdr.bh1.block_status & TP_STATUS_USER) == 0) {
SCReturnInt(AFP_READ_OK);
}
ret = AFPWalkBlock(ptv, pbd);
int ret = AFPWalkBlock(ptv, pbd);
if (unlikely(ret != AFP_READ_OK)) {
AFPFlushBlock(pbd);
SCReturnInt(ret);
@ -1362,8 +1357,6 @@ static int AFPReadAndDiscard(AFPThreadVars *ptv, struct timeval *synctv,
static int AFPReadAndDiscardFromRing(AFPThreadVars *ptv, struct timeval *synctv,
uint64_t *discarded_pkts)
{
union thdr h;
if (unlikely(suricata_ctl_flags != 0)) {
return 1;
}
@ -1371,8 +1364,8 @@ static int AFPReadAndDiscardFromRing(AFPThreadVars *ptv, struct timeval *synctv,
#ifdef HAVE_TPACKET_V3
if (ptv->flags & AFP_TPACKET_V3) {
int ret = 0;
struct tpacket_block_desc *pbd;
pbd = (struct tpacket_block_desc *) ptv->ring.v3[ptv->frame_offset].iov_base;
struct tpacket_block_desc *pbd =
(struct tpacket_block_desc *)ptv->ring.v3[ptv->frame_offset].iov_base;
*discarded_pkts += pbd->hdr.bh1.num_pkts;
struct tpacket3_hdr *ppd =
(struct tpacket3_hdr *)((uint8_t *)pbd + pbd->hdr.bh1.offset_to_first_pkt);
@ -1389,6 +1382,7 @@ static int AFPReadAndDiscardFromRing(AFPThreadVars *ptv, struct timeval *synctv,
#endif
{
/* Read packet from ring */
union thdr h;
h.raw = (((union thdr **)ptv->ring.v2)[ptv->frame_offset]);
if (h.raw == NULL) {
return -1;
@ -1409,7 +1403,6 @@ static int AFPReadAndDiscardFromRing(AFPThreadVars *ptv, struct timeval *synctv,
}
}
return 0;
}
@ -2946,10 +2939,7 @@ TmEcode DecodeAFP(ThreadVars *tv, Packet *p, void *data)
TmEcode DecodeAFPThreadInit(ThreadVars *tv, const void *initdata, void **data)
{
SCEnter();
DecodeThreadVars *dtv = NULL;
dtv = DecodeThreadVarsAlloc(tv);
DecodeThreadVars *dtv = DecodeThreadVarsAlloc(tv);
if (dtv == NULL)
SCReturnInt(TM_ECODE_FAILED);

Loading…
Cancel
Save