Smart Home firewall
Profile-based Smart Home firewall
Functions
nfqueue.c File Reference

Wrapper for the netfilter_queue library. More...

#include "nfqueue.h"
Include dependency graph for nfqueue.c:

Functions

int get_pkt_id (struct nfq_data *nfad)
 
int nfqueue_callback (struct nfq_q_handle *qh, struct nfgenmsg *nfmsg, struct nfq_data *nfad, void *data)
 Full callback function, compliant to the nfq_callback type. More...
 
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

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 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_callback()

int nfqueue_callback ( struct nfq_q_handle *  qh,
struct nfgenmsg *  nfmsg,
struct nfq_data *  nfad,
void *  data 
)

Full callback function, compliant to the nfq_callback type.

Parameters
qhqueue handle
nfmsgmessage object that contains the packet
nfadNetlink packet data handle
datadata to be used by the function. In this case, a pointer to a callback_struct_t, which contains a basic_callback function and its arguments.
Returns
-1 on error, >= 0 otherwise

◆ 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 (should loop forever)