Smart Home firewall
Profile-based Smart Home firewall
Classes | Macros | Typedefs | Functions
nfqueue.h File Reference

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"
Include dependency graph for nfqueue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  interaction_data_t
 Structure which stores the data relative to one policy interaction. More...
 
struct  counters_id_t
 Packet and duration counters ids. More...
 
struct  callback_struct
 
struct  thread_arg_t
 Contains the necessary arguments for an nfqueue thread. The arguments are: More...
 

Macros

#define DEFAULT_TIMEOUT   3600
 

Typedefs

typedef uint32_t basic_callback(int pkt_id, int pkt_len, uint8_t *payload, void *arg)
 Alias for a basic callback function. More...
 
typedef struct callback_struct callback_struct_t
 

Functions

int get_pkt_id (struct nfq_data *nfad)
 
void bind_queue (uint16_t queue_num, basic_callback *callback, void *arg)
 
void * nfqueue_thread (void *arg)
 pthread wrapper for bind_queue. More...
 
bool is_timedout (double threshold, time_t last_request)
 Check if the last request is too old to be accepted. More...
 

Detailed Description

Wrapper for the netfilter_queue library.

Date
2022-09-09

Typedef Documentation

◆ 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_idpacket ID for netfilter queue
hashpacket payload SHA256 hash (only present if LOG is defined)
timestamppacket timestamp (only present if LOG is defined)
pkt_lenpacket length, in bytes
payloadpointer to the packet payload
argpointer 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.

Function Documentation

◆ 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_numthe number of the queue to bind to
callbackthe 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)
argthe argument to pass to the callback function

Bind queue to callback function, and wait for packets.

Parameters
queue_numthe number of the queue to bind to
callbackthe 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)
argthe 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
nfathe 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
thresholdtime in sec before dropping the request
last_requesttime 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
argtypeless pointer to the thread argument, which is a thread_arg_t struct containing the necessary arguments for bind_queue.
Returns
NULL
Parameters
argtypeless pointer to the thread argument, which is a thread_arg_t struct containing the necessary arguments for bind_queue.
Returns
NULL (should loop forever)