diff --git a/src/source-af-packet.c b/src/source-af-packet.c index ac8a45e3ce..a128243262 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -832,6 +832,7 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot) ptv->afp_state = AFP_STATE_DOWN; continue; case AFP_FAILURE: + ptv->afp_state = AFP_STATE_DOWN; SCReturnInt(TM_ECODE_FAILED); break; case AFP_READ_OK: @@ -1045,23 +1046,6 @@ static int AFPCreateSocket(AFPThreadVars *ptv, char *devname, int verbose) ptv->frame_offset = 0; } - r = bind(ptv->socket, (struct sockaddr *)&bind_address, sizeof(bind_address)); - if (r < 0) { - if (verbose) { - if (errno == ENETDOWN) { - SCLogError(SC_ERR_AFP_CREATE, - "Couldn't bind AF_PACKET socket, iface %s is down", - devname); - } else { - SCLogError(SC_ERR_AFP_CREATE, - "Couldn't bind AF_PACKET socket to iface %s, error %s", - devname, - strerror(errno)); - } - } - close(ptv->socket); - return -1; - } if (ptv->promisc != 0) { /* Force promiscuous mode */ memset(&sock_params, 0, sizeof(sock_params)); @@ -1071,8 +1055,7 @@ static int AFPCreateSocket(AFPThreadVars *ptv, char *devname, int verbose) if (r < 0) { SCLogError(SC_ERR_AFP_CREATE, "Couldn't switch iface %s to promiscuous, error %s", - devname, - strerror(errno)); + devname, strerror(errno)); close(ptv->socket); return -1; } @@ -1099,14 +1082,29 @@ static int AFPCreateSocket(AFPThreadVars *ptv, char *devname, int verbose) sizeof(ptv->buffer_size)) == -1) { SCLogError(SC_ERR_AFP_CREATE, "Couldn't set buffer size to %d on iface %s, error %s", - ptv->buffer_size, - devname, - strerror(errno)); + ptv->buffer_size, devname, strerror(errno)); close(ptv->socket); return -1; } } + r = bind(ptv->socket, (struct sockaddr *)&bind_address, sizeof(bind_address)); + if (r < 0) { + if (verbose) { + if (errno == ENETDOWN) { + SCLogError(SC_ERR_AFP_CREATE, + "Couldn't bind AF_PACKET socket, iface %s is down", + devname); + } else { + SCLogError(SC_ERR_AFP_CREATE, + "Couldn't bind AF_PACKET socket to iface %s, error %s", + devname, strerror(errno)); + } + } + close(ptv->socket); + return -1; + } + #ifdef HAVE_PACKET_FANOUT /* add binded socket to fanout group */ if (ptv->threads > 1) { @@ -1292,6 +1290,7 @@ TmEcode ReceiveAFPThreadInit(ThreadVars *tv, void *initdata, void **data) { SCReturnInt(TM_ECODE_FAILED); } + ptv->copy_mode = afpconfig->copy_mode; if (ptv->copy_mode != AFP_COPY_MODE_NONE) { strlcpy(ptv->out_iface, afpconfig->out_iface, AFP_IFACE_NAME_LENGTH); @@ -1303,7 +1302,6 @@ TmEcode ReceiveAFPThreadInit(ThreadVars *tv, void *initdata, void **data) { } } - #define T_DATA_SIZE 70000 ptv->data = SCMalloc(T_DATA_SIZE); if (ptv->data == NULL) {