rx TMs shouldn't return TM_ECODE_FAILED if engine is in shutdown mode + minor cleanup

pull/31/merge
Anoop Saldanha 14 years ago committed by Victor Julien
parent b057a20f10
commit 34581ce902

@ -510,14 +510,15 @@ static int AFPTryReopen(AFPThreadVars *ptv)
*/ */
TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot) TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot)
{ {
SCEnter();
uint16_t packet_q_len = 0; uint16_t packet_q_len = 0;
AFPThreadVars *ptv = (AFPThreadVars *)data; AFPThreadVars *ptv = (AFPThreadVars *)data;
TmSlot *s = (TmSlot *)slot;
ptv->slot = s->slot_next;
struct pollfd fds; struct pollfd fds;
int r; int r;
TmSlot *s = (TmSlot *)slot;
SCEnter(); ptv->slot = s->slot_next;
fds.fd = ptv->socket; fds.fd = ptv->socket;
fds.events = POLLIN; fds.events = POLLIN;

@ -302,21 +302,21 @@ ReceiveErfDagThreadInit(ThreadVars *tv, void *initdata, void **data)
*/ */
TmEcode ReceiveErfDagLoop(ThreadVars *tv, void *data, void *slot) TmEcode ReceiveErfDagLoop(ThreadVars *tv, void *data, void *slot)
{ {
SCEnter();
ErfDagThreadVars *dtv = (ErfDagThreadVars *)data; ErfDagThreadVars *dtv = (ErfDagThreadVars *)data;
TmSlot *s = (TmSlot *)slot;
dtv->slot = s->slot_next;
uint32_t diff = 0; uint32_t diff = 0;
int err; int err;
uint8_t *top = NULL; uint8_t *top = NULL;
uint32_t pkts_read = 0; uint32_t pkts_read = 0;
TmSlot *s = (TmSlot *)slot;
SCEnter(); dtv->slot = s->slot_next;
while (1) while (1)
{ {
if (suricata_ctl_flags & SURICATA_STOP || if (suricata_ctl_flags & (SURICATA_STOP || SURICATA_KILL)) {
suricata_ctl_flags & SURICATA_KILL) { SCReturnInt(TM_ECODE_OK);
SCReturnInt(TM_ECODE_FAILED);
} }
top = dag_advance_stream(dtv->dagfd, dtv->dagstream, &(dtv->btm)); top = dag_advance_stream(dtv->dagfd, dtv->dagstream, &(dtv->btm));
@ -327,10 +327,10 @@ TmEcode ReceiveErfDagLoop(ThreadVars *tv, void *data, void *slot)
dtv->btm = dtv->top; dtv->btm = dtv->top;
} }
continue; continue;
} } else {
else {
SCLogError(SC_ERR_ERF_DAG_STREAM_READ_FAILED, SCLogError(SC_ERR_ERF_DAG_STREAM_READ_FAILED,
"Failed to read from stream: %d, DAG: %s when using dag_advance_stream", "Failed to read from stream: %d, DAG: %s when "
"using dag_advance_stream",
dtv->dagstream, dtv->dagname); dtv->dagstream, dtv->dagname);
SCReturnInt(TM_ECODE_FAILED); SCReturnInt(TM_ECODE_FAILED);
} }
@ -350,17 +350,13 @@ TmEcode ReceiveErfDagLoop(ThreadVars *tv, void *data, void *slot)
"Failed to read from stream: %d, DAG: %s", "Failed to read from stream: %d, DAG: %s",
dtv->dagstream, dtv->dagname); dtv->dagstream, dtv->dagname);
ReceiveErfDagCloseStream(dtv->dagfd, dtv->dagstream); ReceiveErfDagCloseStream(dtv->dagfd, dtv->dagstream);
SCReturnInt(err); SCReturnInt(TM_ECODE_FAILED);
} }
SCLogDebug("Read %d records from stream: %d, DAG: %s", SCLogDebug("Read %d records from stream: %d, DAG: %s",
pkts_read, dtv->dagstream, dtv->dagname); pkts_read, dtv->dagstream, dtv->dagname);
} }
if (suricata_ctl_flags != 0) {
SCReturnInt(TM_ECODE_FAILED);
}
SCReturnInt(TM_ECODE_OK); SCReturnInt(TM_ECODE_OK);
} }

@ -109,14 +109,14 @@ TmModuleDecodeErfFileRegister(void)
*/ */
TmEcode ReceiveErfFileLoop(ThreadVars *tv, void *data, void *slot) TmEcode ReceiveErfFileLoop(ThreadVars *tv, void *data, void *slot)
{ {
Packet *p = NULL;
uint16_t packet_q_len = 0;
ErfFileThreadVars *etv = (ErfFileThreadVars *)data; ErfFileThreadVars *etv = (ErfFileThreadVars *)data;
etv->slot = ((TmSlot *)slot)->slot_next; etv->slot = ((TmSlot *)slot)->slot_next;
Packet *p;
uint16_t packet_q_len = 0;
while (1) { while (1) {
if (suricata_ctl_flags & SURICATA_STOP || if (suricata_ctl_flags & (SURICATA_STOP || SURICATA_KILL)) {
suricata_ctl_flags & SURICATA_KILL) {
SCReturnInt(TM_ECODE_OK); SCReturnInt(TM_ECODE_OK);
} }

@ -309,6 +309,8 @@ TmEcode ReceiveIPFW(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, Pack
TmEcode ReceiveIPFWLoop(ThreadVars *tv, void *data, void *slot) TmEcode ReceiveIPFWLoop(ThreadVars *tv, void *data, void *slot)
{ {
SCEnter();
IPFWThreadVars *ptv = (IPFWThreadVars *)data; IPFWThreadVars *ptv = (IPFWThreadVars *)data;
IPFWQueueVars *nq = NULL; IPFWQueueVars *nq = NULL;
uint8_t pkt[IP_MAXPACKET]; uint8_t pkt[IP_MAXPACKET];
@ -317,13 +319,7 @@ TmEcode ReceiveIPFWLoop(ThreadVars *tv, void *data, void *slot)
struct timeval IPFWts; struct timeval IPFWts;
Packet *p = NULL; Packet *p = NULL;
uint16_t packet_q_len = 0; uint16_t packet_q_len = 0;
SCEnter();
if (ptv == NULL) {
SCLogWarning(SC_ERR_INVALID_ARGUMENT, "Null data pointer");
SCReturnInt(TM_ECODE_FAILED);
}
nq = IPFWGetQueue(ptv->ipfw_index); nq = IPFWGetQueue(ptv->ipfw_index);
if (nq == NULL) { if (nq == NULL) {
SCLogWarning(SC_ERR_INVALID_ARGUMENT, "Can't get thread variable"); SCLogWarning(SC_ERR_INVALID_ARGUMENT, "Can't get thread variable");
@ -331,13 +327,9 @@ TmEcode ReceiveIPFWLoop(ThreadVars *tv, void *data, void *slot)
} }
SCLogInfo("Thread '%s' will run on port %d (item %d)", SCLogInfo("Thread '%s' will run on port %d (item %d)",
tv->name, tv->name, nq->port_num, ptv->ipfw_index);
nq->port_num,
ptv->ipfw_index);
while (1) { while (1) {
if (suricata_ctl_flags & SURICATA_STOP || if (suricata_ctl_flags & (SURICATA_STOP || SURICATA_KILL)) {
suricata_ctl_flags & SURICATA_KILL)
{
SCReturnInt(TM_ECODE_OK); SCReturnInt(TM_ECODE_OK);
} }
@ -362,7 +354,6 @@ TmEcode ReceiveIPFWLoop(ThreadVars *tv, void *data, void *slot)
strerror(errno)); strerror(errno));
SCReturnInt(TM_ECODE_FAILED); SCReturnInt(TM_ECODE_FAILED);
} }
SCReturnInt(TM_ECODE_FAILED);
} }
/* We have a packet to process */ /* We have a packet to process */
memset (&IPFWts, 0, sizeof(struct timeval)); memset (&IPFWts, 0, sizeof(struct timeval));

@ -196,24 +196,24 @@ TmEcode NapatechFeedThreadInit(ThreadVars *tv, void *initdata, void **data)
*/ */
TmEcode NapatechFeedLoop(ThreadVars *tv, void *data, void *slot) TmEcode NapatechFeedLoop(ThreadVars *tv, void *data, void *slot)
{ {
SCEnter();
int32_t status; int32_t status;
int32_t caplen; int32_t caplen;
PCAP_HEADER *header; PCAP_HEADER *header;
uint8_t *frame; uint8_t *frame;
uint16_t packet_q_len = 0; uint16_t packet_q_len = 0;
NapatechThreadVars *ntv = (NapatechThreadVars *)data; NapatechThreadVars *ntv = (NapatechThreadVars *)data;
TmSlot *s = (TmSlot *)slot;
ntv->slot = s->slot_next;
int r; int r;
TmSlot *s = (TmSlot *)slot;
SCEnter(); ntv->slot = s->slot_next;
while (1) { while (1) {
if (suricata_ctl_flags & SURICATA_STOP || if (suricata_ctl_flags & (SURICATA_STOP || SURICATA_KILL)) {
suricata_ctl_flags & SURICATA_KILL)
{
SCReturnInt(TM_ECODE_OK); SCReturnInt(TM_ECODE_OK);
} }
/* make sure we have at least one packet in the packet pool, to prevent /* make sure we have at least one packet in the packet pool, to prevent
* us from alloc'ing packets at line rate */ * us from alloc'ing packets at line rate */
do { do {
@ -233,8 +233,7 @@ TmEcode NapatechFeedLoop(ThreadVars *tv, void *data, void *slot)
* no frames currently available * no frames currently available
*/ */
continue; continue;
} } else if (status < 0) {
else if (status < 0) {
SCLogError(SC_ERR_NAPATECH_FEED_NEXT_FAILED, SCLogError(SC_ERR_NAPATECH_FEED_NEXT_FAILED,
"Failed to read from Napatech feed %d:%d", "Failed to read from Napatech feed %d:%d",
ntv->adapter_number, ntv->feed_number); ntv->adapter_number, ntv->feed_number);
@ -260,8 +259,10 @@ TmEcode NapatechFeedLoop(ThreadVars *tv, void *data, void *slot)
SCReturnInt(TM_ECODE_FAILED); SCReturnInt(TM_ECODE_FAILED);
} }
TmThreadsSlotProcessPkt(ntv->tv, ntv->slot, p); if (TmThreadsSlotProcessPkt(ntv->tv, ntv->slot, p) != TM_ECODE_OK) {
TmqhOutputPacketpool(ntv->tv, p);
SCReturnInt(TM_ECODE_FAILED);
}
} }
SCReturnInt(TM_ECODE_OK); SCReturnInt(TM_ECODE_OK);

@ -154,20 +154,20 @@ void PcapFileCallbackLoop(char *user, struct pcap_pkthdr *h, u_char *pkt) {
/** /**
* \brief Main PCAP file reading Loop function * \brief Main PCAP file reading Loop function
*/ */
TmEcode ReceivePcapFileLoop(ThreadVars *tv, void *data, void *slot) { TmEcode ReceivePcapFileLoop(ThreadVars *tv, void *data, void *slot)
{
SCEnter();
uint16_t packet_q_len = 0; uint16_t packet_q_len = 0;
PcapFileThreadVars *ptv = (PcapFileThreadVars *)data; PcapFileThreadVars *ptv = (PcapFileThreadVars *)data;
int r;
TmSlot *s = (TmSlot *)slot; TmSlot *s = (TmSlot *)slot;
ptv->slot = s->slot_next; ptv->slot = s->slot_next;
ptv->cb_result = TM_ECODE_OK; ptv->cb_result = TM_ECODE_OK;
int r;
SCEnter();
while (1) { while (1) {
if (suricata_ctl_flags & SURICATA_STOP || if (suricata_ctl_flags & (SURICATA_STOP || SURICATA_KILL)) {
suricata_ctl_flags & SURICATA_KILL)
{
SCReturnInt(TM_ECODE_OK); SCReturnInt(TM_ECODE_OK);
} }

@ -256,19 +256,18 @@ void PcapCallbackLoop(char *user, struct pcap_pkthdr *h, u_char *pkt) {
*/ */
TmEcode ReceivePcapLoop(ThreadVars *tv, void *data, void *slot) TmEcode ReceivePcapLoop(ThreadVars *tv, void *data, void *slot)
{ {
SCEnter();
uint16_t packet_q_len = 0; uint16_t packet_q_len = 0;
PcapThreadVars *ptv = (PcapThreadVars *)data; PcapThreadVars *ptv = (PcapThreadVars *)data;
int r;
TmSlot *s = (TmSlot *)slot; TmSlot *s = (TmSlot *)slot;
ptv->slot = s->slot_next; ptv->slot = s->slot_next;
ptv->cb_result = TM_ECODE_OK; ptv->cb_result = TM_ECODE_OK;
int r;
SCEnter();
while (1) { while (1) {
if (suricata_ctl_flags & SURICATA_STOP || if (suricata_ctl_flags & (SURICATA_STOP || SURICATA_KILL)) {
suricata_ctl_flags & SURICATA_KILL)
{
SCReturnInt(TM_ECODE_OK); SCReturnInt(TM_ECODE_OK);
} }

@ -241,20 +241,19 @@ static inline void PfringProcessPacket(void *user, struct pfring_pkthdr *h, Pack
*/ */
TmEcode ReceivePfringLoop(ThreadVars *tv, void *data, void *slot) TmEcode ReceivePfringLoop(ThreadVars *tv, void *data, void *slot)
{ {
SCEnter();
uint16_t packet_q_len = 0; uint16_t packet_q_len = 0;
PfringThreadVars *ptv = (PfringThreadVars *)data; PfringThreadVars *ptv = (PfringThreadVars *)data;
TmSlot *s = (TmSlot *)slot;
ptv->slot = s->slot_next;
Packet *p = NULL; Packet *p = NULL;
struct pfring_pkthdr hdr; struct pfring_pkthdr hdr;
TmSlot *s = (TmSlot *)slot;
SCEnter(); ptv->slot = s->slot_next;
while(1) { while(1) {
if (suricata_ctl_flags & SURICATA_STOP || if (suricata_ctl_flags & (SURICATA_STOP || SURICATA_KILL)) {
suricata_ctl_flags & SURICATA_KILL) { SCReturnInt(TM_ECODE_OK);
SCReturnInt(TM_ECODE_FAILED);
} }
/* make sure we have at least one packet in the packet pool, to prevent /* make sure we have at least one packet in the packet pool, to prevent
@ -300,7 +299,7 @@ TmEcode ReceivePfringLoop(ThreadVars *tv, void *data, void *slot)
} else { } else {
SCLogError(SC_ERR_PF_RING_RECV,"pfring_recv error %" PRId32 "", r); SCLogError(SC_ERR_PF_RING_RECV,"pfring_recv error %" PRId32 "", r);
TmqhOutputPacketpool(ptv->tv, p); TmqhOutputPacketpool(ptv->tv, p);
return TM_ECODE_FAILED; SCReturnInt(TM_ECODE_FAILED);
} }
SCPerfSyncCountersIfSignalled(tv, 0); SCPerfSyncCountersIfSignalled(tv, 0);
} }

Loading…
Cancel
Save