netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Netfilter Netlink
Collaboration diagram for Netfilter Netlink:

Modules

 Conntrack object handling
 
 Log
 
 nf_tables
 
 Queue
 

Socket Creating

int nfnl_connect (struct nl_sock *sk)
 Create and connect netfilter netlink socket. More...
 

Sending

int nfnl_send_simple (struct nl_sock *sk, uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id)
 Send trivial netfilter netlink message. More...
 

Message Parsing

uint8_t nfnlmsg_subsys (struct nlmsghdr *nlh)
 Get netfilter subsystem id from message. More...
 
uint8_t nfnlmsg_subtype (struct nlmsghdr *nlh)
 Get netfilter message type from message. More...
 
uint8_t nfnlmsg_family (struct nlmsghdr *nlh)
 Get netfilter family from message. More...
 
uint16_t nfnlmsg_res_id (struct nlmsghdr *nlh)
 Get netfilter resource id from message. More...
 

Message Building

struct nl_msgnfnlmsg_alloc_simple (uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id)
 Allocate a new netfilter netlink message. More...
 
int nfnlmsg_put (struct nl_msg *msg, uint32_t pid, uint32_t seq, uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id)
 Add netlink and netfilter netlink headers to netlink message. More...
 

Detailed Description

Message Format
<------- NLMSG_ALIGN(hlen) ------> <---- NLMSG_ALIGN(len) --->
+----------------------------+- - -+- - - - - - - - - - -+- - -+
| Header | Pad | Payload | Pad |
| struct nlmsghdr | | | |
+----------------------------+- - -+- - - - - - - - - - -+- - -+
<-------- NFNL_HDRLEN --------->
+--------------------------+- - -+------------+
| Netfilter Netlink Header | Pad | Attributes |
| struct nfgenmsg | | |
+--------------------------+- - -+------------+
nfnlmsg_attrdata(nfg, hdrlen)-----^
1) Creating a new netfilter netlink message
struct nl_msg *msg;
// Create a new empty netlink message
msg = nlmsg_alloc();
// Append the netlink and netfilter netlink message header
hdr = nfnlmsg_put(msg, PID, SEQ, SUBSYS, TYPE, NLM_F_ECHO,
FAMILY, RES_ID);
// Append the attributes.
nla_put_u32(msg, 1, 0x10);
// Message is ready to be sent.
// All done? Free the message.
2) Sending of trivial messages
// For trivial messages not requiring any subsys specific header or
// attributes, nfnl_send_simple() may be used to send messages directly.
nfnl_send_simple(sk, SUBSYS, TYPE, 0, FAMILY, RES_ID);

Function Documentation

int nfnl_connect ( struct nl_sock sk)

Create and connect netfilter netlink socket.

  • sk Netlink socket.

Creates a NETLINK_NETFILTER netlink socket, binds the socket and issues a connection attempt.

See also
nl_connect()
Returns
0 on success or a negative error code.

References NETLINK_NETFILTER, and nl_connect().

Here is the call graph for this function:

int nfnl_send_simple ( struct nl_sock sk,
uint8_t  subsys_id,
uint8_t  type,
int  flags,
uint8_t  family,
uint16_t  res_id 
)

Send trivial netfilter netlink message.

  • sk Netlink socket.
  • subsys_id nfnetlink subsystem
  • type nfnetlink message type
  • flags message flags
  • family nfnetlink address family
  • res_id nfnetlink resource id
Returns
Newly allocated netlink message or NULL.

References nfgenmsg::nfgen_family, NFNETLINK_V0, NFNLMSG_TYPE, and nl_send_simple().

Referenced by nfnl_ct_dump_request(), nfnl_nft_chain_dump_request(), nfnl_nft_rule_dump_request(), and nfnl_nft_table_dump_request().

Here is the call graph for this function:

Here is the caller graph for this function:

struct nl_msg* nfnlmsg_alloc_simple ( uint8_t  subsys_id,
uint8_t  type,
int  flags,
uint8_t  family,
uint16_t  res_id 
)

Allocate a new netfilter netlink message.

  • subsys_id nfnetlink subsystem
  • type nfnetlink message type
  • flags message flags
  • family nfnetlink address family
  • res_id nfnetlink resource id
Returns
Newly allocated netlink message or NULL.

References NFNLMSG_TYPE, nlmsg_alloc_simple(), nlmsg_free(), and NULL.

Referenced by nfnl_queue_msg_build_verdict().

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t nfnlmsg_family ( struct nlmsghdr nlh)

Get netfilter family from message.

  • nlh netlink messsage header

References nfgenmsg::nfgen_family, and nlmsg_data().

Referenced by nfnlmsg_ct_parse(), nfnlmsg_log_msg_parse(), nfnlmsg_nft_chain_parse(), nfnlmsg_nft_rule_parse(), nfnlmsg_nft_set_parse(), nfnlmsg_nft_table_parse(), and nfnlmsg_queue_msg_parse().

Here is the call graph for this function:

Here is the caller graph for this function:

int nfnlmsg_put ( struct nl_msg msg,
uint32_t  pid,
uint32_t  seq,
uint8_t  subsys_id,
uint8_t  type,
int  flags,
uint8_t  family,
uint16_t  res_id 
)

Add netlink and netfilter netlink headers to netlink message.

  • msg netlink message
  • pid netlink process id
  • seq sequence number of message
  • subsys_id nfnetlink subsystem
  • type nfnetlink message type
  • flags message flags
  • family nfnetlink address family
  • res_id nfnetlink resource id

References NFNLMSG_TYPE, NLE_MSGSIZE, nlh, nlmsg_put(), and NULL.

Referenced by nfnl_nft_set_dump_request(), and nfnl_nft_setelem_dump_request().

Here is the call graph for this function:

Here is the caller graph for this function:

uint16_t nfnlmsg_res_id ( struct nlmsghdr nlh)

Get netfilter resource id from message.

  • nlh netlink messsage header

References nlmsg_data(), and nfgenmsg::res_id.

Referenced by nfnlmsg_queue_msg_parse().

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t nfnlmsg_subsys ( struct nlmsghdr nlh)

Get netfilter subsystem id from message.

  • nlh netlink messsage header

References NFNL_SUBSYS_ID, and nlmsghdr::nlmsg_type.

uint8_t nfnlmsg_subtype ( struct nlmsghdr nlh)

Get netfilter message type from message.

  • nlh netlink messsage header

References NFNL_MSG_TYPE, and nlmsghdr::nlmsg_type.

Referenced by nfnlmsg_ct_group().

Here is the caller graph for this function: