af-packet: fix reconnection on netdown error.

AFPRead can fail following a NETDOWN error. This patch treat errors
of AFPRead by forcing a reconnection (instead of exiting thread
with error).
remotes/origin/master-1.1.x
Eric Leblond 14 years ago committed by Victor Julien
parent 361bf22121
commit 62e63e3fe9

@ -125,6 +125,12 @@ TmEcode NoAFPSupportExit(ThreadVars *tv, void *initdata, void **data)
#define POLL_TIMEOUT 100
enum {
AFP_READ_OK,
AFP_READ_FAILURE,
AFP_FAILURE,
};
/**
* \brief Structure to hold thread specific variables.
*/
@ -213,7 +219,7 @@ static int AFPCreateSocket(AFPThreadVars *ptv, char *devname, int verbose);
* \param user pointer to AFPThreadVars
* \retval TM_ECODE_FAILED on failure and TM_ECODE_OK on success
*/
TmEcode AFPRead(AFPThreadVars *ptv)
int AFPRead(AFPThreadVars *ptv)
{
Packet *p = NULL;
/* XXX should try to use read that get directly to packet */
@ -252,12 +258,12 @@ TmEcode AFPRead(AFPThreadVars *ptv)
if (caplen < 0) {
SCLogWarning(SC_ERR_AFP_READ, "recvmsg failed with error code %" PRId32,
errno);
SCReturnInt(TM_ECODE_FAILED);
SCReturnInt(AFP_READ_FAILURE);
}
p = PacketGetFromQueueOrAlloc();
if (p == NULL) {
SCReturnInt(TM_ECODE_FAILED);
SCReturnInt(AFP_FAILURE);
}
/* get timestamp of packet via ioctl */
@ -265,7 +271,7 @@ TmEcode AFPRead(AFPThreadVars *ptv)
SCLogWarning(SC_ERR_AFP_READ, "recvmsg failed with error code %" PRId32,
errno);
TmqhOutputPacketpool(ptv->tv, p);
SCReturnInt(TM_ECODE_FAILED);
SCReturnInt(AFP_READ_FAILURE);
}
ptv->pkts++;
@ -282,16 +288,16 @@ TmEcode AFPRead(AFPThreadVars *ptv)
SET_PKT_LEN(p, caplen + offset);
if (PacketCopyData(p, ptv->data, GET_PKT_LEN(p)) == -1) {
TmqhOutputPacketpool(ptv->tv, p);
SCReturnInt(TM_ECODE_FAILED);
SCReturnInt(AFP_FAILURE);
}
SCLogDebug("pktlen: %" PRIu32 " (pkt %p, pkt data %p)",
GET_PKT_LEN(p), p, GET_PKT_DATA(p));
if (TmThreadsSlotProcessPkt(ptv->tv, ptv->slot, p) != TM_ECODE_OK) {
TmqhOutputPacketpool(ptv->tv, p);
SCReturnInt(TM_ECODE_FAILED);
SCReturnInt(AFP_FAILURE);
}
SCReturnInt(TM_ECODE_OK);
SCReturnInt(AFP_READ_OK);
}
static int AFPTryReopen(AFPThreadVars *ptv)
@ -383,8 +389,19 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot)
} else if (r > 0) {
/* AFPRead will call TmThreadsSlotProcessPkt on read packets */
r = AFPRead(ptv);
if (r != TM_ECODE_OK) {
SCReturnInt(TM_ECODE_FAILED);
switch (r) {
case AFP_READ_FAILURE:
/* AFPRead in error: best to reset the socket */
SCLogError(SC_ERR_AFP_READ, "AFPRead error reading data from socket: (%d" PRIu32 ") %s",
errno, strerror(errno));
close(ptv->socket);
ptv->afp_state = AFP_STATE_DOWN;
continue;
case AFP_FAILURE:
SCReturnInt(TM_ECODE_FAILED);
break;
case AFP_READ_OK:
break;
}
} else if ((r < 0) && (errno != EINTR)) {
SCLogError(SC_ERR_AFP_READ, "Error reading data from socket: (%d" PRIu32 ") %s",

Loading…
Cancel
Save