Parsing(3)
π Parsing(3) π
okay so bestie, welcome to Parsing(3) from the Library Functions Manual β these are the message parsing functions, and heads up: the whole thing is [DEPRECATED]. π Like, it still works and the tea is all here, but just know the elders have moved on, iykyk. π
π NAME π
Parsing β message parsing functions [DEPRECATED] π
π¦ SYNOPSIS π¦
Functions
here's the whole friend group of functions, bestie β literally every single one, no skips: π
struct nfqnl_msg_packet_hdr * nfq_get_msg_packet_hdr (struct nfq_data *nfad)
uint32_t nfq_get_nfmark (struct nfq_data *nfad)
int nfq_get_timestamp (struct nfq_data *nfad, struct timeval *tv)
uint32_t nfq_get_indev (struct nfq_data *nfad)
uint32_t nfq_get_physindev (struct nfq_data *nfad)
uint32_t nfq_get_outdev (struct nfq_data *nfad)
uint32_t nfq_get_physoutdev (struct nfq_data *nfad)
int nfq_get_indev_name (struct nlif_handle *nlif_handle, struct nfq_data *nfad, char *name)
int nfq_get_physindev_name (struct nlif_handle *nlif_handle, struct nfq_data *nfad, char *name)
int nfq_get_outdev_name (struct nlif_handle *nlif_handle, struct nfq_data *nfad, char *name)
int nfq_get_physoutdev_name (struct nlif_handle *nlif_handle, struct nfq_data *nfad, char *name)
struct nfqnl_msg_packet_hw * nfq_get_packet_hw (struct nfq_data *nfad)
uint32_t nfq_get_skbinfo (struct nfq_data *nfad)
int nfq_get_uid (struct nfq_data *nfad, uint32_t *uid)
int nfq_get_gid (struct nfq_data *nfad, uint32_t *gid)
int nfq_get_secctx (struct nfq_data *nfad, unsigned char **secdata)
int nfq_get_payload (struct nfq_data *nfad, unsigned char **data)
β¨ DETAILED DESCRIPTION β¨
ngl there's no extra prose here in the original, bestie β the whole vibe lives in the function docs down below. keep scrolling, it's giving main character energy the whole way down. ππ
π FUNCTION DOCUMENTATION π
int nfq_get_gid (struct nfq_data * nfad, uint32_t * gid)
nfq_get_gid β get the GID of the user the packet belongs to π«Ά
Parameters
nfadβ Netlink packet data handle passed to callback functiongidβ Set to GID on return
Warning
β οΈ If theNFQA_CFG_F_GSOflag is not set, then fragmented packets may be pushed into the queue. In this case, only one fragment will have the GID field set. To deal with this issue always setNFQA_CFG_F_GSO. (fr fr, don't skip this one bestie π)
Returns
1if there is a GID available,0otherwise.
Definition at line 1277 of file libnetfilter_queue.c.
uint32_t nfq_get_indev (struct nfq_data * nfad)
nfq_get_indev β get the interface that the packet was received through π«
Parameters
nfadβ Netlink packet data handle passed to callback function
Returns
- The index of the device the queued packet was received via. If the returned index is
0, the packet was locally generated or the input interface is not known (ie.POSTROUTING?).
Warning
β οΈ allnfq_get_dev()functions return0if not set, since linux only allowsifindex >= 1, seenet/core/dev.c:2600(in2.6.13.1)
Definition at line 1028 of file libnetfilter_queue.c.
int nfq_get_indev_name (struct nlif_handle * nlif_handle, struct nfq_data * nfad, char * name)
nfq_get_indev_name β get the name of the interface the packet was received through πΈ
Parameters
nlif_handleβ pointer to a nlif interface resolving handlenfadβ Netlink packet data handle passed to callback functionnameβ pointer to the buffer to receive the interface name; not more thanIFNAMSIZbytes will be copied to it.
Returns
-1in case of error,>0if it succeed.
To use a nlif_handle, You need first to call nlif_open() and to open an handler. Don't forget to store the result as it will be used during all your program life: π
h = nlif_open();
if (h == NULL) {
perror('nlif_open');
exit(EXIT_FAILURE);
}
Once the handler is open, you need to fetch the interface table at a whole via a call to nlif_query. β¨
nlif_query(h);
libnfnetlink is able to update the interface mapping when a new interface appears. To do so, you need to call nlif_catch() on the handler after each interface related event. The simplest way to get and treat event is to run a select() or poll() against the nlif file descriptor. To get this file descriptor, you need to use nlif_fd:
if_fd = nlif_fd(h);
Don't forget to close the handler when you don't need the feature anymore: π
nlif_close(h);
Definition at line 1116 of file libnetfilter_queue.c.
struct nfqnl_msg_packet_hdr * nfq_get_msg_packet_hdr (struct nfq_data * nfad)
nfqnl_msg_packet_hdr β return the metaheader that wraps the packet π¦
Parameters
nfadβ Netlink packet data handle passed to callback function
Returns
- the netfilter queue netlink packet header for the given
nfq_dataargument. Typically, thenfq_datavalue is passed as the 3rd parameter to the callback function set by a call tonfq_create_queue().
The nfqnl_msg_packet_hdr structure is defined in libnetfilter_queue.h as: π
struct nfqnl_msg_packet_hdr {
uint32_t packet_id; // unique ID of packet in queue
uint16_t hw_protocol; // hw protocol (network order)
uint8_t hook; // netfilter hook
} __attribute__ ((packed));
Definition at line 974 of file libnetfilter_queue.c.
uint32_t nfq_get_nfmark (struct nfq_data * nfad)
nfq_get_nfmark β get the packet mark π·οΈ
Parameters
nfadβ Netlink packet data handle passed to callback function
Returns
- the netfilter mark currently assigned to the given queued packet.
Definition at line 987 of file libnetfilter_queue.c.
uint32_t nfq_get_outdev (struct nfq_data * nfad)
nfq_get_outdev β gets the interface that the packet will be routed out π
Parameters
nfadβ Netlink packet data handle passed to callback function
Returns
- The index of the device the queued packet will be sent out. If the returned index is
0, the packet is destined for localhost or the output interface is not yet known (ie.PREROUTING?).
Definition at line 1056 of file libnetfilter_queue.c.
int nfq_get_outdev_name (struct nlif_handle * nlif_handle, struct nfq_data * nfad, char * name)
nfq_get_outdev_name β get the name of the physical interface the packet will be sent to π
Parameters
nlif_handleβ pointer to a nlif interface resolving handlenfadβ Netlink packet data handle passed to callback functionnameβ pointer to the buffer to receive the interface name; not more thanIFNAMSIZbytes will be copied to it.
See nfq_get_indev_name() documentation for nlif_handle usage.
Returns
-1in case of error,> 0if it succeed.
Definition at line 1156 of file libnetfilter_queue.c.
struct nfqnl_msg_packet_hw * nfq_get_packet_hw (struct nfq_data * nfad)
nfq_get_packet_hw
get hardware address π
Parameters
nfadβ Netlink packet data handle passed to callback function
Retrieves the hardware address associated with the given queued packet. For ethernet packets, the hardware address returned (if any) will be the MAC address of the packet source host. The destination MAC address is not known until after POSTROUTING and a successful ARP request, so cannot currently be retrieved. π
The nfqnl_msg_packet_hw structure is defined in libnetfilter_queue.h as: π¦
struct nfqnl_msg_packet_hw {
uint16_t hw_addrlen;
uint16_t _pad;
uint8_t hw_addr[8];
} __attribute__ ((packed));
Definition at line 1207 of file libnetfilter_queue.c.
int nfq_get_payload (struct nfq_data * nfad, unsigned char ** data)
nfq_get_payload β get payload π
Parameters
nfadβ Netlink packet data handle passed to callback functiondataβ Pointer of pointer that will be pointed to the payload
Retrieve the payload for a queued packet. The actual amount and type of data retrieved by this function will depend on the mode set with the nfq_set_mode() function. β¨
Returns
-1on error, otherwise> 0.
Definition at line 1324 of file libnetfilter_queue.c.
uint32_t nfq_get_physindev (struct nfq_data * nfad)
nfq_get_physindev β get the physical interface that the packet was received π§
Parameters
nfadβ Netlink packet data handle passed to callback function
Returns
- The index of the physical device the queued packet was received via. If the returned index is
0, the packet was locally generated or the physical input interface is no longer known (ie.POSTROUTING?).
Definition at line 1042 of file libnetfilter_queue.c.
int nfq_get_physindev_name (struct nlif_handle * nlif_handle, struct nfq_data * nfad, char * name)
nfq_get_physindev_name β get the name of the physical interface the packet was received through π
Parameters
nlif_handleβ pointer to a nlif interface resolving handlenfadβ Netlink packet data handle passed to callback functionnameβ pointer to the buffer to receive the interface name; not more thanIFNAMSIZbytes will be copied to it.
See nfq_get_indev_name() documentation for nlif_handle usage.
Returns
-1in case of error,> 0if it succeed.
Definition at line 1136 of file libnetfilter_queue.c.
uint32_t nfq_get_physoutdev (struct nfq_data * nfad)
nfq_get_physoutdev β get the physical interface that the packet output π
Parameters
nfadβ Netlink packet data handle passed to callback function
The index of the physical device the queued packet will be sent out. If the returned index is 0, the packet is destined for localhost or the physical output interface is not yet known (ie. PREROUTING?).
Returns
- The index of physical interface that the packet output will be routed out.
Definition at line 1072 of file libnetfilter_queue.c.
int nfq_get_physoutdev_name (struct nlif_handle * nlif_handle, struct nfq_data * nfad, char * name)
nfq_get_physoutdev_name β get the name of the interface the packet will be sent to π
Parameters
nlif_handleβ pointer to a nlif interface resolving handlenfadβ Netlink packet data handle passed to callback functionnameβ pointer to the buffer to receive the interface name; not more thanIFNAMSIZbytes will be copied to it.
See nfq_get_indev_name() documentation for nlif_handle usage.
Returns
-1in case of error,> 0if it succeed.
Definition at line 1177 of file libnetfilter_queue.c.
int nfq_get_secctx (struct nfq_data * nfad, unsigned char ** secdata)
nfq_get_secctx β get the security context for this packet π
Parameters
nfadβ Netlink packet data handle passed to callback functionsecdataβ data to write the security context to
Warning
β οΈ If theNFQA_CFG_F_GSOflag is not set, then fragmented packets may be pushed into the queue. In this case, only one fragment will have theSECCTXfield set. To deal with this issue always setNFQA_CFG_F_GSO. (yes bestie, same warning as before β set the flag, periodt π )
Returns
-1on error, otherwise> 0
Definition at line 1298 of file libnetfilter_queue.c.
uint32_t nfq_get_skbinfo (struct nfq_data * nfad)
nfq_get_skbinfo β return the NFQA_SKB_INFO meta information π«§
Parameters
nfadβ Netlink packet data handle passed to callback function
so like bestie, you can use this to get extra info about a packet by testing the returned integer for any of these bit flags β¨:
NFQA_SKB_CSUMNOTREADYβ packet header checksums will be computed by hardware later on, i.e. tcp/ip checksums in the packet must not be validated, application should pretend they are correct. πNFQA_SKB_GSOβ packet is an aggregated super-packet. It exceeds device mtu and will be (re-)split on transmit by hardware. π¦NFQA_SKB_CSUM_NOTVERIFIEDβ packet checksum was not yet verified by the kernel/hardware, for example because this is an incoming packet and the NIC does not perform checksum validation at hardware level. β
Returns
the skbinfo value π
See also
Definition at line 1236 of file libnetfilter_queue.c.
nfq_get_timestamp β°
int nfq_get_timestamp (struct nfq_data * nfad, struct timeval * tv)
nfq_get_timestamp - get the packet timestamp πΈ
Parameters
nfadβ Netlink packet data handle passed to callback functiontvβ structure to fill with timestamp info
Retrieves the received timestamp when the given queued packet. fr fr
Returns
0 on success, non-zero on failure.
Definition at line 1002 of file libnetfilter_queue.c.
nfq_get_uid π
int nfq_get_uid (struct nfq_data * nfad, uint32_t * uid)
nfq_get_uid - get the UID of the user the packet belongs to π
Parameters
nfadβ Netlink packet data handle passed to callback functionuidβ Set to UID on return
Warning π¨ If theNFQA_CFG_F_GSOflag is not set, then fragmented packets may be pushed into the queue. In this case, only one fragment will have the UID field set. To deal with this issue always setNFQA_CFG_F_GSO. like, always, okay? don't skip it.
Returns
1 if there is a UID available, 0 otherwise.
Definition at line 1256 of file libnetfilter_queue.c.
Author
Generated automatically by Doxygen for libnetfilter_queue from the source code.
and that's the tea, bestie! π This page is from libnetfilter_queue, version 1.0.5, and it's the Parsing(3) manual. No cap, you're now a parsing pro. β¨π π¦ The footer didn't come with a date, but it's giving timeless anyway. periodt.
π¦ where this page comes from
- ubuntu noble: libnetfilter-queue-doc 1.0.5-4build1 Β· GPL-2.0-or-later
- ubuntu questing: libnetfilter-queue-doc 1.0.5-4build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms