suricata
source-nfq.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  */
23 
24 #ifndef __SOURCE_NFQ_H__
25 #define __SOURCE_NFQ_H__
26 
27 #ifdef NFQ
28 
29 #include "threads.h"
30 #include <linux/netfilter.h> /* for NF_ACCEPT */
31 #include <libnetfilter_queue/libnetfilter_queue.h>
32 
33 // Netfilter's limit
34 #define NFQ_MAX_QUEUE 65535
35 
36 /* idea: set the recv-thread id in the packet to
37  * select an verdict-queue */
38 
39 typedef struct NFQPacketVars_
40 {
41  int id; /* this nfq packets id */
42  uint16_t nfq_index; /* index in NFQ array */
43  uint8_t verdicted;
44 
45  uint32_t mark;
46  uint32_t ifi;
47  uint32_t ifo;
48  uint16_t hw_protocol;
50 
51 typedef struct NFQQueueVars_
52 {
53  struct nfq_handle *h;
54  struct nfnl_handle *nh;
55  int fd;
56  uint8_t use_mutex;
57  /* 2 threads deal with the queue handle, so add a mutex */
58  struct nfq_q_handle *qh;
60  /* this one should be not changing after init */
61  uint16_t queue_num;
62  /* position into the NFQ queue var array */
63  uint16_t nfq_index;
64 
65 #ifdef DBG_PERF
66  int dbg_maxreadsize;
67 #endif /* DBG_PERF */
68 
69  /* counters */
70  uint32_t pkts;
71  uint64_t bytes;
72  uint32_t errs;
73  uint32_t accepted;
74  uint32_t dropped;
75  uint32_t replaced;
76  struct {
77  uint32_t packet_id; /* id of last processed packet */
78  uint32_t verdict;
79  uint32_t mark;
80  uint8_t mark_valid:1;
81  uint8_t len;
82  uint8_t maxlen;
84 
86 
87 typedef struct NFQGlobalVars_
88 {
89  char unbind;
91 
92 void NFQInitConfig(bool quiet);
93 int NFQRegisterQueue(const uint16_t number);
94 int NFQParseAndRegisterQueues(const char *queues);
95 void *NFQGetQueue(int number);
96 void *NFQGetThread(int number);
97 void NFQContextsClean(void);
98 #endif /* NFQ */
99 #endif /* __SOURCE_NFQ_H__ */
100 
NFQQueueVars
struct NFQQueueVars_ NFQQueueVars
NFQQueueVars_::errs
uint32_t errs
Definition: source-nfq.h:72
NFQGetThread
void * NFQGetThread(int number)
Get a pointer to the NFQ thread at index.
Definition: source-nfq.c:945
NFQQueueVars_::bytes
uint64_t bytes
Definition: source-nfq.h:71
NFQGetQueue
void * NFQGetQueue(int number)
Get a pointer to the NFQ queue at index.
Definition: source-nfq.c:927
NFQPacketVars_::ifi
uint32_t ifi
Definition: source-nfq.h:46
NFQQueueVars_::h
struct nfq_handle * h
Definition: source-nfq.h:53
NFQGlobalVars_
Definition: source-nfq.h:88
threads.h
NFQQueueVars_
Definition: source-nfq.h:52
NFQParseAndRegisterQueues
int NFQParseAndRegisterQueues(const char *queues)
Parses and adds Netfilter queue(s).
Definition: source-nfq.c:862
NFQPacketVars_::verdicted
uint8_t verdicted
Definition: source-nfq.h:43
NFQContextsClean
void NFQContextsClean(void)
Clean global contexts. Must be called on exit.
Definition: source-nfq.c:1280
NFQPacketVars_::mark
uint32_t mark
Definition: source-nfq.h:45
NFQGlobalVars
struct NFQGlobalVars_ NFQGlobalVars
NFQQueueVars_::packet_id
uint32_t packet_id
Definition: source-nfq.h:77
NFQQueueVars_::nh
struct nfnl_handle * nh
Definition: source-nfq.h:54
NFQPacketVars_::ifo
uint32_t ifo
Definition: source-nfq.h:47
NFQQueueVars_::maxlen
uint8_t maxlen
Definition: source-nfq.h:82
NFQQueueVars_::accepted
uint32_t accepted
Definition: source-nfq.h:73
NFQPacketVars_::id
int id
Definition: source-nfq.h:41
NFQQueueVars_::pkts
uint32_t pkts
Definition: source-nfq.h:70
NFQInitConfig
void NFQInitConfig(bool quiet)
To initialize the NFQ global configuration data.
Definition: source-nfq.c:208
NFQQueueVars_::replaced
uint32_t replaced
Definition: source-nfq.h:75
NFQQueueVars_::fd
int fd
Definition: source-nfq.h:55
NFQPacketVars
struct NFQPacketVars_ NFQPacketVars
NFQQueueVars_::verdict_cache
struct NFQQueueVars_::@134 verdict_cache
NFQPacketVars_
Definition: source-nfq.h:40
NFQQueueVars_::mark
uint32_t mark
Definition: source-nfq.h:79
NFQQueueVars_::nfq_index
uint16_t nfq_index
Definition: source-nfq.h:63
NFQQueueVars_::qh
struct nfq_q_handle * qh
Definition: source-nfq.h:58
NFQPacketVars_::nfq_index
uint16_t nfq_index
Definition: source-nfq.h:42
NFQQueueVars_::len
uint8_t len
Definition: source-nfq.h:81
NFQQueueVars_::queue_num
uint16_t queue_num
Definition: source-nfq.h:61
NFQQueueVars_::mark_valid
uint8_t mark_valid
Definition: source-nfq.h:80
NFQQueueVars_::verdict
uint32_t verdict
Definition: source-nfq.h:78
NFQRegisterQueue
int NFQRegisterQueue(const uint16_t number)
Add a single Netfilter queue.
Definition: source-nfq.c:806
NFQGlobalVars_::unbind
char unbind
Definition: source-nfq.h:89
NFQQueueVars_::mutex_qh
SCMutex mutex_qh
Definition: source-nfq.h:59
NFQPacketVars_::hw_protocol
uint16_t hw_protocol
Definition: source-nfq.h:48
SCMutex
#define SCMutex
Definition: threads-debug.h:114
NFQQueueVars_::use_mutex
uint8_t use_mutex
Definition: source-nfq.h:56
NFQQueueVars_::dropped
uint32_t dropped
Definition: source-nfq.h:74