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;
83  } verdict_cache;
84 
85 } NFQQueueVars;
86 
87 typedef struct NFQGlobalVars_
88 {
89  char unbind;
91 
92 void NFQInitConfig(char quiet);
93 int NFQRegisterQueue(const uint16_t number);
94 int NFQParseAndRegisterQueues(const char *queues);
95 int NFQGetQueueCount(void);
96 void *NFQGetQueue(int number);
97 int NFQGetQueueNum(int number);
98 void *NFQGetThread(int number);
99 #endif /* NFQ */
100 #endif /* __SOURCE_NFQ_H__ */
101 
uint32_t mark
Definition: source-nfq.h:79
struct NFQGlobalVars_ NFQGlobalVars
uint32_t verdict
Definition: source-nfq.h:78
uint32_t packet_id
Definition: source-nfq.h:77
void NFQInitConfig(char quiet)
To initialize the NFQ global configuration data.
Definition: source-nfq.c:226
uint8_t maxlen
Definition: source-nfq.h:82
int NFQParseAndRegisterQueues(const char *queues)
Parses and adds Netfilter queue(s).
Definition: source-nfq.c:901
uint32_t accepted
Definition: source-nfq.h:73
SCMutex mutex_qh
Definition: source-nfq.h:59
struct NFQQueueVars_ NFQQueueVars
uint16_t nfq_index
Definition: source-nfq.h:42
int NFQRegisterQueue(const uint16_t number)
Add a single Netfilter queue.
Definition: source-nfq.c:843
uint64_t bytes
Definition: source-nfq.h:71
uint32_t dropped
Definition: source-nfq.h:74
uint32_t replaced
Definition: source-nfq.h:75
struct NFQPacketVars_ NFQPacketVars
void * NFQGetThread(int number)
Get a pointer to the NFQ thread at index.
Definition: source-nfq.c:978
uint32_t errs
Definition: source-nfq.h:72
uint16_t queue_num
Definition: source-nfq.h:61
uint16_t nfq_index
Definition: source-nfq.h:63
struct nfq_q_handle * qh
Definition: source-nfq.h:58
uint16_t hw_protocol
Definition: source-nfq.h:48
uint8_t len
Definition: source-nfq.h:81
void * NFQGetQueue(int number)
Get a pointer to the NFQ queue at index.
Definition: source-nfq.c:960
uint32_t ifi
Definition: source-nfq.h:46
struct nfnl_handle * nh
Definition: source-nfq.h:54
int NFQGetQueueCount(void)
uint8_t use_mutex
Definition: source-nfq.h:56
#define SCMutex
int NFQGetQueueNum(int number)
uint8_t verdicted
Definition: source-nfq.h:43
struct nfq_handle * h
Definition: source-nfq.h:53
uint32_t ifo
Definition: source-nfq.h:47
uint32_t mark
Definition: source-nfq.h:45
uint32_t pkts
Definition: source-nfq.h:70