Wrapper for the netfilter_queue library.
More...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <linux/types.h>
#include <linux/netfilter.h>
#include <errno.h>
#include <pthread.h>
#include <libnetfilter_queue/libnetfilter_queue.h>
#include "rule_utils.h"
#include "packet_utils.h"
Go to the source code of this file.
|
#define | DEFAULT_TIMEOUT 3600 |
|
Wrapper for the netfilter_queue library.
- Date
- 2022-09-09
- Copyright
- Copyright (c) 2022
◆ basic_callback
typedef uint32_t basic_callback(int pkt_id, int pkt_len, uint8_t *payload, void *arg) |
Alias for a basic callback function.
- Parameters
-
pkt_id | packet ID for netfilter queue |
hash | packet payload SHA256 hash (only present if LOG is defined) |
timestamp | packet timestamp (only present if LOG is defined) |
pkt_len | packet length, in bytes |
payload | pointer to the packet payload |
arg | pointer to the argument passed to the callback function |
- Returns
- the verdict for the packet
◆ callback_struct_t
Structure that stores a basic callback function and its arguments.
◆ bind_queue()
void bind_queue |
( |
uint16_t |
queue_num, |
|
|
basic_callback * |
callback, |
|
|
void * |
arg |
|
) |
| |
Bind queue to callback function, and wait for packets.
- Parameters
-
queue_num | the number of the queue to bind to |
callback | the callback funtion, called upon packet reception The callback function must have the following signature: int callback(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg, struct nfq_data *nfa, void *data) |
arg | the argument to pass to the callback function |
Bind queue to callback function, and wait for packets.
- Parameters
-
queue_num | the number of the queue to bind to |
callback | the basic callback function, called upon packet reception The callback function must have the following signature: uint32_t callback(int pkt_id, uint8_t *payload, void *arg) |
arg | the argument to pass to the basic callback function |
◆ get_pkt_id()
int get_pkt_id |
( |
struct nfq_data * |
nfad | ) |
|
Retrieve the packet id from a nfq_data struct, or -1 in case of error.
- Parameters
-
nfa | the given nfq_data struct |
- Returns
- the packet id, or -1 in case of error
◆ is_timedout()
bool is_timedout |
( |
double |
threshold, |
|
|
time_t |
last_request |
|
) |
| |
Check if the last request is too old to be accepted.
- Parameters
-
threshold | time in sec before dropping the request |
last_request | time of the last request |
- Returns
- true the request is too old and must be refused
-
false the request is recent enought and might be accepted
◆ nfqueue_thread()
void* nfqueue_thread |
( |
void * |
arg | ) |
|
pthread wrapper for bind_queue.
- Parameters
-
arg | typeless pointer to the thread argument, which is a thread_arg_t struct containing the necessary arguments for bind_queue. |
- Returns
- NULL
- Parameters
-
arg | typeless pointer to the thread argument, which is a thread_arg_t struct containing the necessary arguments for bind_queue. |
- Returns
- NULL (should loop forever)