netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
libmnl.h File Reference
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/socket.h>
#include <linux/netlink.h>
Include dependency graph for libmnl.h:

Macros

#define MNL_SOCKET_AUTOPID   0
 
#define MNL_SOCKET_BUFFER_SIZE   (getpagesize() < 8192L ? getpagesize() : 8192L)
 
#define MNL_ALIGNTO   4
 
#define MNL_ALIGN(len)   (((len)+MNL_ALIGNTO-1) & ~(MNL_ALIGNTO-1))
 
#define MNL_NLMSG_HDRLEN   MNL_ALIGN(sizeof(struct nlmsghdr))
 
#define MNL_ATTR_HDRLEN   MNL_ALIGN(sizeof(struct nlattr))
 
#define mnl_attr_for_each(attr, nlh, offset)
 
#define mnl_attr_for_each_nested(attr, nest)
 
#define mnl_attr_for_each_payload(payload, payload_size)
 
#define MNL_CB_ERROR   -1
 
#define MNL_CB_STOP   0
 
#define MNL_CB_OK   1
 
#define SOL_NETLINK   270
 
#define MNL_ARRAY_SIZE(a)   (sizeof(a)/sizeof((a)[0]))
 

Typedefs

typedef int(* mnl_attr_cb_t )(const struct nlattr *attr, void *data)
 
typedef int(* mnl_cb_t )(const struct nlmsghdr *nlh, void *data)
 

Enumerations

enum  mnl_attr_data_type {
  MNL_TYPE_UNSPEC,
  MNL_TYPE_U8,
  MNL_TYPE_U16,
  MNL_TYPE_U32,
  MNL_TYPE_U64,
  MNL_TYPE_STRING,
  MNL_TYPE_FLAG,
  MNL_TYPE_MSECS,
  MNL_TYPE_NESTED,
  MNL_TYPE_NESTED_COMPAT,
  MNL_TYPE_NUL_STRING,
  MNL_TYPE_BINARY,
  MNL_TYPE_MAX
}
 

Functions

struct mnl_socketmnl_socket_open (int type)
 mnl_socket_open - open a netlink socket More...
 
struct mnl_socketmnl_socket_fdopen (int fd)
 mnl_socket_fdopen - associates a mnl_socket object with pre-existing socket. More...
 
int mnl_socket_bind (struct mnl_socket *nl, unsigned int groups, pid_t pid)
 mnl_socket_bind - bind netlink socket More...
 
int mnl_socket_close (struct mnl_socket *nl)
 mnl_socket_close - close a given netlink socket More...
 
int mnl_socket_get_fd (const struct mnl_socket *nl)
 mnl_socket_get_fd - obtain file descriptor from netlink socket More...
 
unsigned int mnl_socket_get_portid (const struct mnl_socket *nl)
 mnl_socket_get_portid - obtain Netlink PortID from netlink socket More...
 
ssize_t mnl_socket_sendto (const struct mnl_socket *nl, const void *req, size_t siz)
 mnl_socket_sendto - send a netlink message of a certain size More...
 
ssize_t mnl_socket_recvfrom (const struct mnl_socket *nl, void *buf, size_t siz)
 mnl_socket_recvfrom - receive a netlink message More...
 
int mnl_socket_setsockopt (const struct mnl_socket *nl, int type, void *buf, socklen_t len)
 mnl_socket_setsockopt - set Netlink socket option More...
 
int mnl_socket_getsockopt (const struct mnl_socket *nl, int type, void *buf, socklen_t *len)
 mnl_socket_getsockopt - get a Netlink socket option More...
 
size_t mnl_nlmsg_size (size_t len)
 mnl_nlmsg_size - calculate the size of Netlink message (without alignment) More...
 
size_t mnl_nlmsg_get_payload_len (const struct nlmsghdr *nlh)
 mnl_nlmsg_get_payload_len - get the length of the Netlink payload More...
 
struct nlmsghdrmnl_nlmsg_put_header (void *buf)
 mnl_nlmsg_put_header - reserve and prepare room for Netlink header More...
 
void * mnl_nlmsg_put_extra_header (struct nlmsghdr *nlh, size_t size)
 mnl_nlmsg_put_extra_header - reserve and prepare room for an extra header More...
 
bool mnl_nlmsg_ok (const struct nlmsghdr *nlh, int len)
 mnl_nlmsg_ok - check a there is room for netlink message More...
 
struct nlmsghdrmnl_nlmsg_next (const struct nlmsghdr *nlh, int *len)
 mnl_nlmsg_next - get the next netlink message in a multipart message More...
 
bool mnl_nlmsg_seq_ok (const struct nlmsghdr *nlh, unsigned int seq)
 mnl_nlmsg_seq_ok - perform sequence tracking More...
 
bool mnl_nlmsg_portid_ok (const struct nlmsghdr *nlh, unsigned int portid)
 mnl_nlmsg_portid_ok - perform portID origin check More...
 
void * mnl_nlmsg_get_payload (const struct nlmsghdr *nlh)
 mnl_nlmsg_get_payload - get a pointer to the payload of the netlink message More...
 
void * mnl_nlmsg_get_payload_offset (const struct nlmsghdr *nlh, size_t offset)
 mnl_nlmsg_get_payload_offset - get a pointer to the payload of the message More...
 
void * mnl_nlmsg_get_payload_tail (const struct nlmsghdr *nlh)
 mnl_nlmsg_get_payload_tail - get the ending of the netlink message More...
 
void mnl_nlmsg_fprintf (FILE *fd, const void *data, size_t datalen, size_t extra_header_size)
 mnl_nlmsg_fprintf - print netlink message to file More...
 
struct mnl_nlmsg_batchmnl_nlmsg_batch_start (void *buf, size_t bufsiz)
 mnl_nlmsg_batch_start - initialize a batch More...
 
bool mnl_nlmsg_batch_next (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_next - get room for the next message in the batch More...
 
void mnl_nlmsg_batch_stop (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_stop - release a batch More...
 
size_t mnl_nlmsg_batch_size (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_size - get current size of the batch More...
 
void mnl_nlmsg_batch_reset (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_reset - reset the batch More...
 
void * mnl_nlmsg_batch_head (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_head - get head of this batch More...
 
void * mnl_nlmsg_batch_current (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_current - returns current position in the batch More...
 
bool mnl_nlmsg_batch_is_empty (struct mnl_nlmsg_batch *b)
 mnl_nlmsg_batch_is_empty - check if there is any message in the batch More...
 
uint16_t mnl_attr_get_type (const struct nlattr *attr)
 mnl_attr_get_type - get type of netlink attribute More...
 
uint16_t mnl_attr_get_len (const struct nlattr *attr)
 mnl_attr_get_len - get length of netlink attribute More...
 
uint16_t mnl_attr_get_payload_len (const struct nlattr *attr)
 mnl_attr_get_payload_len - get the attribute payload-value length More...
 
void * mnl_attr_get_payload (const struct nlattr *attr)
 mnl_attr_get_payload - get pointer to the attribute payload More...
 
uint8_t mnl_attr_get_u8 (const struct nlattr *attr)
 mnl_attr_get_u8 - returns 8-bit unsigned integer attribute payload More...
 
uint16_t mnl_attr_get_u16 (const struct nlattr *attr)
 mnl_attr_get_u16 - returns 16-bit unsigned integer attribute payload More...
 
uint32_t mnl_attr_get_u32 (const struct nlattr *attr)
 mnl_attr_get_u32 - returns 32-bit unsigned integer attribute payload More...
 
uint64_t mnl_attr_get_u64 (const struct nlattr *attr)
 mnl_attr_get_u64 - returns 64-bit unsigned integer attribute. More...
 
const char * mnl_attr_get_str (const struct nlattr *attr)
 mnl_attr_get_str - returns pointer to string attribute. More...
 
void mnl_attr_put (struct nlmsghdr *nlh, uint16_t type, size_t len, const void *data)
 mnl_attr_put - add an attribute to netlink message More...
 
void mnl_attr_put_u8 (struct nlmsghdr *nlh, uint16_t type, uint8_t data)
 mnl_attr_put_u8 - add 8-bit unsigned integer attribute to netlink message More...
 
void mnl_attr_put_u16 (struct nlmsghdr *nlh, uint16_t type, uint16_t data)
 mnl_attr_put_u16 - add 16-bit unsigned integer attribute to netlink message More...
 
void mnl_attr_put_u32 (struct nlmsghdr *nlh, uint16_t type, uint32_t data)
 mnl_attr_put_u32 - add 32-bit unsigned integer attribute to netlink message More...
 
void mnl_attr_put_u64 (struct nlmsghdr *nlh, uint16_t type, uint64_t data)
 mnl_attr_put_u64 - add 64-bit unsigned integer attribute to netlink message More...
 
void mnl_attr_put_str (struct nlmsghdr *nlh, uint16_t type, const char *data)
 mnl_attr_put_str - add string attribute to netlink message More...
 
void mnl_attr_put_strz (struct nlmsghdr *nlh, uint16_t type, const char *data)
 mnl_attr_put_strz - add string attribute to netlink message More...
 
bool mnl_attr_put_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, size_t len, const void *data)
 mnl_attr_put_check - add an attribute to netlink message More...
 
bool mnl_attr_put_u8_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint8_t data)
 mnl_attr_put_u8_check - add 8-bit unsigned int attribute to netlink message More...
 
bool mnl_attr_put_u16_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint16_t data)
 mnl_attr_put_u16_check - add 16-bit unsigned int attribute to netlink message More...
 
bool mnl_attr_put_u32_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint32_t data)
 mnl_attr_put_u32_check - add 32-bit unsigned int attribute to netlink message More...
 
bool mnl_attr_put_u64_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint64_t data)
 mnl_attr_put_u64_check - add 64-bit unsigned int attribute to netlink message More...
 
bool mnl_attr_put_str_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, const char *data)
 mnl_attr_put_str_check - add string attribute to netlink message More...
 
bool mnl_attr_put_strz_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type, const char *data)
 mnl_attr_put_strz_check - add string attribute to netlink message More...
 
struct nlattrmnl_attr_nest_start (struct nlmsghdr *nlh, uint16_t type)
 mnl_attr_nest_start - start an attribute nest More...
 
struct nlattrmnl_attr_nest_start_check (struct nlmsghdr *nlh, size_t buflen, uint16_t type)
 mnl_attr_nest_start_check - start an attribute nest More...
 
void mnl_attr_nest_end (struct nlmsghdr *nlh, struct nlattr *start)
 mnl_attr_nest_end - end an attribute nest More...
 
void mnl_attr_nest_cancel (struct nlmsghdr *nlh, struct nlattr *start)
 mnl_attr_nest_cancel - cancel an attribute nest More...
 
int mnl_attr_type_valid (const struct nlattr *attr, uint16_t maxtype)
 mnl_attr_type_valid - check if the attribute type is valid More...
 
int mnl_attr_validate (const struct nlattr *attr, enum mnl_attr_data_type type)
 mnl_attr_validate - validate netlink attribute (simplified version) More...
 
int mnl_attr_validate2 (const struct nlattr *attr, enum mnl_attr_data_type type, size_t len)
 mnl_attr_validate2 - validate netlink attribute (extended version) More...
 
bool mnl_attr_ok (const struct nlattr *attr, int len)
 mnl_attr_ok - check if there is room for an attribute in a buffer More...
 
struct nlattrmnl_attr_next (const struct nlattr *attr)
 mnl_attr_next - get the next attribute in the payload of a netlink message More...
 
int mnl_attr_parse (const struct nlmsghdr *nlh, unsigned int offset, mnl_attr_cb_t cb, void *data)
 mnl_attr_parse - parse attributes More...
 
int mnl_attr_parse_nested (const struct nlattr *attr, mnl_attr_cb_t cb, void *data)
 mnl_attr_parse_nested - parse attributes inside a nest More...
 
int mnl_attr_parse_payload (const void *payload, size_t payload_len, mnl_attr_cb_t cb, void *data)
 mnl_attr_parse_payload - parse attributes in payload of Netlink message More...
 
int mnl_cb_run (const void *buf, size_t numbytes, unsigned int seq, unsigned int portid, mnl_cb_t cb_data, void *data)
 mnl_cb_run - callback runqueue for netlink messages (simplified version) More...
 
int mnl_cb_run2 (const void *buf, size_t numbytes, unsigned int seq, unsigned int portid, mnl_cb_t cb_data, void *data, mnl_cb_t *cb_ctl_array, unsigned int cb_ctl_array_len)
 mnl_cb_run2 - callback runqueue for netlink messages More...
 

Macro Definition Documentation

#define MNL_ALIGNTO   4
#define MNL_ARRAY_SIZE (   a)    (sizeof(a)/sizeof((a)[0]))
#define mnl_attr_for_each (   attr,
  nlh,
  offset 
)
Value:
for ((attr) = mnl_nlmsg_get_payload_offset((nlh), (offset)); \
mnl_attr_ok((attr), (char *)mnl_nlmsg_get_payload_tail(nlh) - (char *)(attr)); \
(attr) = mnl_attr_next(attr))
bool mnl_attr_ok(const struct nlattr *attr, int len)
mnl_attr_ok - check if there is room for an attribute in a buffer
Definition: attr.c:97
struct nlattr * mnl_attr_next(const struct nlattr *attr)
mnl_attr_next - get the next attribute in the payload of a netlink message
Definition: attr.c:113
void * mnl_nlmsg_get_payload_tail(const struct nlmsghdr *nlh)
mnl_nlmsg_get_payload_tail - get the ending of the netlink message
Definition: nlmsg.c:195
void * mnl_nlmsg_get_payload_offset(const struct nlmsghdr *nlh, size_t offset)
mnl_nlmsg_get_payload_offset - get a pointer to the payload of the message
Definition: nlmsg.c:136
const struct nlmsghdr * nlh
Definition: libnetfilter_conntrack.h:565

Referenced by mnl_attr_parse().

#define mnl_attr_for_each_nested (   attr,
  nest 
)
Value:
for ((attr) = mnl_attr_get_payload(nest); \
mnl_attr_ok((attr), (char *)mnl_attr_get_payload(nest) + mnl_attr_get_payload_len(nest) - (char *)(attr)); \
(attr) = mnl_attr_next(attr))
bool mnl_attr_ok(const struct nlattr *attr, int len)
mnl_attr_ok - check if there is room for an attribute in a buffer
Definition: attr.c:97
struct nlattr * mnl_attr_next(const struct nlattr *attr)
mnl_attr_next - get the next attribute in the payload of a netlink message
Definition: attr.c:113
void * mnl_attr_get_payload(const struct nlattr *attr)
mnl_attr_get_payload - get pointer to the attribute payload
Definition: attr.c:75
uint16_t mnl_attr_get_payload_len(const struct nlattr *attr)
mnl_attr_get_payload_len - get the attribute payload-value length
Definition: attr.c:63

Referenced by mnl_attr_parse_nested().

#define mnl_attr_for_each_payload (   payload,
  payload_size 
)
Value:
for ((attr) = (payload); \
mnl_attr_ok((attr), (char *)(payload) + payload_size - (char *)(attr)); \
(attr) = mnl_attr_next(attr))
bool mnl_attr_ok(const struct nlattr *attr, int len)
mnl_attr_ok - check if there is room for an attribute in a buffer
Definition: attr.c:97
struct nlattr * mnl_attr_next(const struct nlattr *attr)
mnl_attr_next - get the next attribute in the payload of a netlink message
Definition: attr.c:113
struct iphdr payload
Definition: ulogd_inppkt_UNIXSOCK.c:37

Referenced by mnl_attr_parse_payload().

#define MNL_CB_ERROR   -1

Referenced by handle_qacb().

#define MNL_CB_STOP   0

Typedef Documentation

typedef int(* mnl_attr_cb_t)(const struct nlattr *attr, void *data)
typedef int(* mnl_cb_t)(const struct nlmsghdr *nlh, void *data)

Enumeration Type Documentation

Enumerator
MNL_TYPE_UNSPEC 
MNL_TYPE_U8 
MNL_TYPE_U16 
MNL_TYPE_U32 
MNL_TYPE_U64 
MNL_TYPE_STRING 
MNL_TYPE_FLAG 
MNL_TYPE_MSECS 
MNL_TYPE_NESTED 
MNL_TYPE_NESTED_COMPAT 
MNL_TYPE_NUL_STRING 
MNL_TYPE_BINARY 
MNL_TYPE_MAX