libnl  3.2.24-rc1
Generic Netlink Library (libnl-genl)

Modules

 Controller (Resolver)
 Resolves Generic Netlink family names to numeric identifiers.
 
 Family and Command Registration
 Registering Generic Netlink Families and Commands.
 

Generic Netlink Socket

int genl_connect (struct nl_sock *sk)
 Connect a Generic Netlink socket. More...
 

Sending Data

int genl_send_simple (struct nl_sock *sk, int family, int cmd, int version, int flags)
 Send a Generic Netlink message consisting only of a header. More...
 

Message Parsing

int genlmsg_valid_hdr (struct nlmsghdr *nlh, int hdrlen)
 Validate Generic Netlink message headers. More...
 
int genlmsg_validate (struct nlmsghdr *nlh, int hdrlen, int maxtype, struct nla_policy *policy)
 Validate Generic Netlink message including attributes. More...
 
int genlmsg_parse (struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, struct nla_policy *policy)
 Parse Generic Netlink message including attributes. More...
 
struct genlmsghdr * genlmsg_hdr (struct nlmsghdr *nlh)
 Return pointer to Generic Netlink header. More...
 
int genlmsg_len (const struct genlmsghdr *gnlh)
 Return length of message payload including user header. More...
 
void * genlmsg_user_hdr (const struct genlmsghdr *gnlh)
 Return pointer to user header. More...
 
void * genlmsg_user_data (const struct genlmsghdr *gnlh, const int hdrlen)
 Return pointer to user data. More...
 
int genlmsg_user_datalen (const struct genlmsghdr *gnlh, const int hdrlen)
 Return length of user data. More...
 
struct nlattr * genlmsg_attrdata (const struct genlmsghdr *gnlh, int hdrlen)
 Return pointer to message attributes. More...
 
int genlmsg_attrlen (const struct genlmsghdr *gnlh, int hdrlen)
 Return length of message attributes. More...
 

Message Construction

void * genlmsg_put (struct nl_msg *msg, uint32_t port, uint32_t seq, int family, int hdrlen, int flags, uint8_t cmd, uint8_t version)
 Add Generic Netlink headers to Netlink message. More...
 

Deprecated

void * genlmsg_data (const struct genlmsghdr *gnlh)
 Return pointer to message payload. More...
 

Detailed Description

Function Documentation

int genl_connect ( struct nl_sock *  sk)

Connect a Generic Netlink socket.

Parameters
skUnconnected Netlink socket

This function expects a struct nl_socket object previously allocated via nl_socket_alloc(). It calls nl_connect() to create the local socket file descriptor and binds the socket to the NETLINK_GENERIC Netlink protocol.

Using this function is equivalent to:

nl_connect(sk, NETLINK_GENERIC);
See Also
nl_connect()
Returns
0 on success or a negative error code.

Definition at line 45 of file genl.c.

References nl_connect().

+ Here is the call graph for this function:

int genl_send_simple ( struct nl_sock *  sk,
int  family,
int  cmd,
int  version,
int  flags 
)

Send a Generic Netlink message consisting only of a header.

Parameters
skGeneric Netlink socket
familyNumeric family identifier
cmdNumeric command identifier
versionInterface version
flagsAdditional Netlink message flags (optional)

This function is a shortcut for sending a Generic Netlink message without any message payload. The message will only consist of the Netlink and Generic Netlink headers. The header is constructed based on the specified parameters and passed on to nl_send_simple() to send it on the specified socket.

Example:
#include <netlink/genl/genl.h>
#include <linux/genetlink.h>
err = genl_send_simple(sk, GENL_ID_CTRL, CTRL_CMD_GETFAMILY, CTRL_VERSION,
NLM_F_DUMP);
See Also
nl_send_simple()
Returns
0 on success or a negative error code.

Definition at line 84 of file genl.c.

References nl_send_simple().

+ Here is the call graph for this function:

int genlmsg_valid_hdr ( struct nlmsghdr *  nlh,
int  hdrlen 
)

Validate Generic Netlink message headers.

Parameters
nlhPointer to Netlink message header
hdrlenLength of user header

Verifies the integrity of the Netlink and Generic Netlink headers by enforcing the following requirements:

  • Valid Netlink message header (nlmsg_valid_hdr())
  • Presence of a complete Generic Netlink header
  • At least hdrlen bytes of payload included after the generic netlink header.
Returns
A positive integer (true) if the headers are valid or 0 (false) if not.

Definition at line 117 of file genl.c.

References genlmsg_len(), and nlmsg_data().

Referenced by genl_handle_msg(), genlmsg_parse(), and genlmsg_validate().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int genlmsg_validate ( struct nlmsghdr *  nlh,
int  hdrlen,
int  maxtype,
struct nla_policy policy 
)

Validate Generic Netlink message including attributes.

Parameters
nlhPointer to Netlink message header
hdrlenLength of user header
maxtypeMaximum attribtue id expected
policyAttribute validation policy

Verifies the validity of the Netlink and Generic Netlink headers using genlmsg_valid_hdr() and calls nla_validate() on the message payload to verify the integrity of eventual attributes.

Note
You may call genlmsg_parse() directly to perform validation and parsing in a single step.
See Also
genlmsg_valid_hdr()
nla_validate()
genlmsg_parse()
Returns
0 on success or a negative error code.

Definition at line 151 of file genl.c.

References genlmsg_attrdata(), genlmsg_attrlen(), genlmsg_valid_hdr(), nla_validate(), and nlmsg_data().

+ Here is the call graph for this function:

int genlmsg_parse ( struct nlmsghdr *  nlh,
int  hdrlen,
struct nlattr *  tb[],
int  maxtype,
struct nla_policy policy 
)

Parse Generic Netlink message including attributes.

Parameters
nlhPointer to Netlink message header
hdrlenLength of user header
tbArray to store parsed attributes
maxtypeMaximum attribute id expected
policyAttribute validation policy

Verifies the validity of the Netlink and Generic Netlink headers using genlmsg_valid_hdr() and calls nla_parse() on the message payload to parse eventual attributes.

Example:
struct nlattr *attrs[MY_TYPE_MAX+1];
if ((err = genlsmg_parse(nlmsg_nlh(msg), sizeof(struct my_hdr), attrs,
MY_TYPE_MAX, attr_policy)) < 0)
// ERROR
See Also
genlmsg_valid_hdr()
genlmsg_validate()
nla_parse()
Returns
0 on success or a negative error code.

Definition at line 191 of file genl.c.

References genlmsg_attrdata(), genlmsg_attrlen(), genlmsg_valid_hdr(), nla_parse(), and nlmsg_data().

+ Here is the call graph for this function:

struct genlmsghdr* genlmsg_hdr ( struct nlmsghdr *  nlh)
read

Return pointer to Generic Netlink header.

Parameters
nlhNetlink message header
Returns
Pointer to Generic Netlink message header

Definition at line 210 of file genl.c.

References nlmsg_data().

+ Here is the call graph for this function:

int genlmsg_len ( const struct genlmsghdr *  gnlh)

Return length of message payload including user header.

Parameters
gnlhGeneric Netlink message header
See Also
genlmsg_data()
Returns
Length of user payload including an eventual user header in number of bytes.

Definition at line 224 of file genl.c.

Referenced by genlmsg_attrlen(), genlmsg_user_datalen(), and genlmsg_valid_hdr().

+ Here is the caller graph for this function:

void* genlmsg_user_hdr ( const struct genlmsghdr *  gnlh)

Return pointer to user header.

Parameters
gnlhGeneric Netlink message header

Calculates the pointer to the user header based on the pointer to the Generic Netlink message header.

Returns
Pointer to the user header

Definition at line 242 of file genl.c.

References genlmsg_data().

Referenced by genlmsg_user_data().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* genlmsg_user_data ( const struct genlmsghdr *  gnlh,
const int  hdrlen 
)

Return pointer to user data.

Parameters
gnlhGeneric netlink message header
hdrlenLength of user header

Calculates the pointer to the user data based on the pointer to the Generic Netlink message header.

See Also
genlmsg_user_datalen()
Returns
Pointer to the user data

Definition at line 259 of file genl.c.

References genlmsg_user_hdr().

Referenced by genlmsg_attrdata().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int genlmsg_user_datalen ( const struct genlmsghdr *  gnlh,
const int  hdrlen 
)

Return length of user data.

Parameters
gnlhGeneric Netlink message header
hdrlenLength of user header
See Also
genlmsg_user_data()
Returns
Length of user data in bytes

Definition at line 273 of file genl.c.

References genlmsg_len().

+ Here is the call graph for this function:

struct nlattr* genlmsg_attrdata ( const struct genlmsghdr *  gnlh,
int  hdrlen 
)
read

Return pointer to message attributes.

Parameters
gnlhGeneric Netlink message header
hdrlenLength of user header
See Also
genlmsg_attrlen()
Returns
Pointer to the start of the message's attributes section.

Definition at line 287 of file genl.c.

References genlmsg_user_data().

Referenced by genlmsg_parse(), and genlmsg_validate().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int genlmsg_attrlen ( const struct genlmsghdr *  gnlh,
int  hdrlen 
)

Return length of message attributes.

Parameters
gnlhGeneric Netlink message header
hdrlenLength of user header
See Also
genlmsg_attrdata()
Returns
Length of the message section containing attributes in number of bytes.

Definition at line 302 of file genl.c.

References genlmsg_len().

Referenced by genlmsg_parse(), and genlmsg_validate().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* genlmsg_put ( struct nl_msg *  msg,
uint32_t  port,
uint32_t  seq,
int  family,
int  hdrlen,
int  flags,
uint8_t  cmd,
uint8_t  version 
)

Add Generic Netlink headers to Netlink message.

Parameters
msgNetlink message object
portNetlink port or NL_AUTO_PORT
seqSequence number of message or NL_AUTO_SEQ
familyNumeric family identifier
hdrlenLength of user header
flagsAdditional Netlink message flags (optional)
cmdNumeric command identifier
versionInterface version

Calls nlmsg_put() on the specified message object to reserve space for the Netlink header, the Generic Netlink header, and a user header of specified length. Fills out the header fields with the specified parameters.

Example:
struct nl_msg *msg;
struct my_hdr *user_hdr;
if (!(msg = nlmsg_alloc()))
// ERROR
user_hdr = genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, family_id,
sizeof(struct my_hdr), 0, MY_CMD_FOO, 0);
if (!user_hdr)
// ERROR
See Also
nlmsg_put()

Returns Pointer to user header or NULL if an error occurred.

Definition at line 348 of file genl.c.

References nlmsg_data(), and nlmsg_put().

+ Here is the call graph for this function:

void* genlmsg_data ( const struct genlmsghdr *  gnlh)

Return pointer to message payload.

Parameters
gnlhGeneric Netlink message header
Deprecated:
This function has been deprecated due to inability to specify the length of the user header. Use genlmsg_user_hdr() respectively genlmsg_user_data().
Returns
Pointer to payload section

Definition at line 385 of file genl.c.

Referenced by genlmsg_user_hdr().

+ Here is the caller graph for this function: