Go to the documentation of this file.
86 SCLogError(
"Error creating thread %s: you do not have support for ipfw "
87 "enabled please recompile with --enable-ipfw",
99 #define IPFW_SOCKET_POLL_MSEC 300
126 static uint16_t receive_port_num = 0;
130 static void *IPFWGetQueue(
int number);
133 static void ReceiveIPFWThreadExitStats(
ThreadVars *,
void *);
139 static void VerdictIPFWThreadExitStats(
ThreadVars *,
void *);
200 if (active_runmode && !strcmp(
"workers", active_runmode)) {
202 SCLogInfo(
"IPFW running in 'workers' runmode, will not use mutex.");
223 #define IP_MAXPACKET 65535
234 struct pollfd IPFWpoll;
235 struct timeval IPFWts;
244 SCLogInfo(
"Thread '%s' will run on port %d (item %d)",
256 IPFWpoll.fd = nq->
fd;
257 IPFWpoll.events = POLLRDNORM;
260 if (!(IPFWpoll.revents & (POLLRDNORM | POLLERR)))
264 if ((pktlen = recvfrom(nq->
fd, pkt,
sizeof(pkt), 0,
268 if (errno == EINTR || errno == EWOULDBLOCK) {
272 SCLogWarning(
"Read from IPFW divert socket failed: %s", strerror(errno));
277 memset (&IPFWts, 0,
sizeof(
struct timeval));
278 gettimeofday(&IPFWts, NULL);
290 SCLogDebug(
"Received Packet Len: %d", pktlen);
295 ptv->
bytes += pktlen;
302 SCLogDebug(
"Packet info: pkt_len: %" PRIu32
" (pkt %02x, pkt_data %02x)",
305 if (TmThreadsSlotProcessPkt(
tv, ((
TmSlot *) slot)->slot_next, p)
330 struct timeval timev;
336 pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
343 if ((nq->
fd = socket(PF_DIVERT, SOCK_RAW, 0)) == -1) {
345 if ((nq->
fd = socket(PF_INET, SOCK_RAW, IPPROTO_DIVERT)) == -1) {
347 SCLogError(
"Can't create divert socket: %s", strerror(errno));
356 if (setsockopt(nq->
fd, SOL_SOCKET, SO_RCVTIMEO, &timev,
sizeof(timev)) == -1) {
357 SCLogError(
"Can't set IPFW divert socket timeout: %s", strerror(errno));
364 nq->
ipfw_sin.sin_addr.s_addr = INADDR_ANY;
387 void ReceiveIPFWThreadExitStats(
ThreadVars *
tv,
void *data)
393 SCLogNotice(
"(%s) Treated: Pkts %" PRIu32
", Bytes %" PRIu64
", Errors %" PRIu32
"",
395 SCLogNotice(
"(%s) Verdict: Accepted %"PRIu32
", Dropped %"PRIu32
"",
415 if (close(nq->
fd) < 0) {
416 SCLogWarning(
"Unable to disable ipfw socket: %s", strerror(errno));
514 struct pollfd IPFWpoll;
532 IPFWpoll.fd = nq->fd;
533 IPFWpoll.events = POLLWRNORM;
555 SCLogInfo(
"Received ThreadShutdown: IPFW divert socket writing interrupted");
562 if (sendto(nq->fd,
GET_PKT_DATA(p),
GET_PKT_LEN(p), 0,(
struct sockaddr *)&nq->ipfw_sin, nq->ipfw_sinlen) == -1) {
566 SCLogWarning(
"Write to ipfw divert socket failed: %s", strerror(r));
618 if (PacketIsTunnel(p)) {
619 bool verdict = VerdictTunnelPacket(p);
622 if (verdict ==
true) {
624 retval = IPFWSetVerdict(
tv, ptv, p->
root ? p->
root : p);
629 retval = IPFWSetVerdict(
tv, ptv, p);
684 void VerdictIPFWThreadExitStats(
ThreadVars *
tv,
void *data)
703 uint16_t port_num = 0;
706 SCLogError(
"specified queue number %s is not "
714 SCLogError(
"too much IPFW divert port registered (%d)", receive_port_num);
718 if (receive_port_num == 0) {
719 memset(&ipfw_t, 0,
sizeof(ipfw_t));
720 memset(&ipfw_q, 0,
sizeof(ipfw_q));
723 ntv = &ipfw_t[receive_port_num];
726 nq = &ipfw_q[receive_port_num];
732 SCLogDebug(
"Queue \"%s\" registered.", queue);
744 void *IPFWGetQueue(
int number)
746 if (number >= receive_port_num)
749 return (
void *)&ipfw_q[number];
764 if (number >= receive_port_num)
767 return (
void *)&ipfw_t[number];
bool PacketCheckAction(const Packet *p, const uint8_t a)
void TmModuleReceiveIPFWRegister(void)
Registration Function for RecieveIPFW.
#define IPV6_GET_RAW_VER(ip6h)
int PacketCopyData(Packet *p, const uint8_t *pktdata, uint32_t pktlen)
Copy data to Packet payload and set packet length.
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
void TmThreadsSetFlag(ThreadVars *tv, uint32_t flag)
Set a thread flag.
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
#define SC_CAP_NET_BROADCAST
void PacketDecodeFinalize(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p)
Finalize decoding of a packet.
char * RunmodeGetActive(void)
TmEcode(* PktAcqLoop)(ThreadVars *, void *, void *)
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
#define PKT_SET_SRC(p, src_val)
#define SC_CAP_NET_BIND_SERVICE
void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
TmEcode(* PktAcqBreakLoop)(ThreadVars *, void *)
#define SCMutexUnlock(mut)
#define PKT_PSEUDO_STREAM_END
void TmModuleVerdictIPFWRegister(void)
Registration Function for VerdictIPFW.
Per thread variable structure.
#define SCTIME_FROM_TIMEVAL(tv)
TmEcode(* Func)(ThreadVars *, Packet *, void *)
#define SCLogWarning(...)
Macro used to log WARNING messages.
int IPFWRegisterQueue(char *queue)
Add an IPFW divert.
struct sockaddr_in ipfw_sin
void PacketPoolWait(void)
#define TM_FLAG_DECODE_TM
TmModule tmm_modules[TMM_SIZE]
int DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
#define IPV4_GET_RAW_VER(ip4h)
uint32_t max_pending_packets
struct IPFWThreadVars_ IPFWThreadVars
Structure to hold thread specific variables.
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define SCMutexInit(mut, mutattrs)
#define TM_FLAG_RECEIVE_TM
Structure to hold thread specific variables.
void DecodeThreadVarsFree(ThreadVars *tv, DecodeThreadVars *dtv)
#define IPFW_SOCKET_POLL_MSEC
void * IPFWGetThread(int number)
Get a pointer to the IPFW thread at index.
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
void(* ThreadExitPrintStats)(ThreadVars *, void *)
void TmModuleDecodeIPFWRegister(void)
Registration Function for DecodeIPFW.
#define SCLogError(...)
Macro used to log ERROR messages.
void DatalinkSetGlobalType(int datalink)
Structure to hold thread specific data for all decode modules.
DecodeThreadVars * DecodeThreadVarsAlloc(ThreadVars *tv)
Alloc and setup DecodeThreadVars.
void StatsSyncCountersIfSignalled(ThreadVars *tv)
int LiveRegisterDeviceName(const char *dev)
Add a device for monitoring.
int TmThreadsCheckFlag(ThreadVars *tv, uint32_t flag)
Check if a thread flag is set.
int DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
#define SCLogNotice(...)
Macro used to log NOTICE messages.
Packet * PacketGetFromQueueOrAlloc(void)
Get a packet. We try to get a packet from the packetpool first, but if that is empty we alloc a packe...
void DecodeUpdatePacketCounters(ThreadVars *tv, const DecodeThreadVars *dtv, const Packet *p)
volatile uint8_t suricata_ctl_flags