Smart Home firewall
Profile-based Smart Home firewall
nfqueue.h
Go to the documentation of this file.
1 
10 #ifndef _IOTFIREWALL_NFQUEUE_
11 #define _IOTFIREWALL_NFQUEUE_
12 
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <time.h>
16 #include <unistd.h>
17 #include <sys/time.h>
18 #include <netinet/in.h>
19 #include <linux/types.h>
20 #include <linux/netfilter.h>
21 #include <errno.h>
22 #include <pthread.h>
23 #include <libnetfilter_queue/libnetfilter_queue.h>
24 #include "rule_utils.h"
25 #include "packet_utils.h"
26 
27 #define DEFAULT_TIMEOUT 3600 // Default timeout is one sec
28 
32 typedef struct {
33  uint16_t nfq_id_base; // Base nfqueue ID
34  uint8_t num_policies; // Total number of policies
35  uint8_t num_states; // Number of different states
36  pthread_mutex_t mutex; // State mutex
37  uint8_t current_state; // Current state
38  counters_t *counters; // Array of counters
39  ip_addr_t cached_ip; // Cached IP address
40  double timeout; // Timeout of the request (in sec). 0 = DEFAULT_TIMEOUT ; -1 = no timeout
41  time_t time_request; // Time since last request ; set to 0 if no request has been made before
43 
50 typedef struct {
51  uint8_t packet_counter_id;
52  uint8_t duration_counter_id;
54 
66 #ifdef LOG
67 typedef uint32_t basic_callback(int pkt_id, uint8_t *hash, struct timeval timestamp, int pkt_len, uint8_t *payload, void *arg);
68 #else
69 typedef uint32_t basic_callback(int pkt_id, int pkt_len, uint8_t *payload, void *arg);
70 #endif /* LOG */
71 
75 typedef struct callback_struct {
76  basic_callback *func; // Basic callback function
77  void *arg; // Arguments to pass to the callback function
79 
88 typedef struct {
89  uint16_t queue_id; // Queue number to bind to
90  basic_callback *func; // Basic callback function
91  void *arg; // Arguments to pass to the callback function
92 } thread_arg_t;
93 
101 int get_pkt_id(struct nfq_data *nfad);
102 
113 void bind_queue(uint16_t queue_num, basic_callback *callback, void *arg);
114 
121 void* nfqueue_thread(void *arg);
122 
131 bool is_timedout(double threshold, time_t last_request);
132 
133 
134 #endif /* _IOTFIREWALL_NFQUEUE_ */
void * nfqueue_thread(void *arg)
pthread wrapper for bind_queue.
Definition: nfqueue.c:209
bool is_timedout(double threshold, time_t last_request)
Check if the last request is too old to be accepted.
Definition: nfqueue.c:223
void bind_queue(uint16_t queue_num, basic_callback *callback, void *arg)
Definition: nfqueue.c:86
uint32_t basic_callback(int pkt_id, int pkt_len, uint8_t *payload, void *arg)
Alias for a basic callback function.
Definition: nfqueue.h:69
int get_pkt_id(struct nfq_data *nfad)
Definition: nfqueue.c:20
struct callback_struct callback_struct_t
Utilitaries for payload manipulation and display.
Interface to nftables counters.
Definition: nfqueue.h:75
Packet and duration counters ids.
Definition: nfqueue.h:50
Definition: rule_utils.h:44
Structure which stores the data relative to one policy interaction.
Definition: nfqueue.h:32
IP (v4 or v6) address.
Definition: packet_utils.h:37
Contains the necessary arguments for an nfqueue thread. The arguments are:
Definition: nfqueue.h:88