libnl 3.5.0

Modules
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, const struct nla_policy *policy)
| Validate Generic Netlink message including attributes. More...
int | genlmsg_parse (struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, const 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

## ◆ genl_connect()

int genl_connect | ( | struct nl_sock * | sk | ) |

Connect a Generic Netlink socket.

Parameters

  sk | Unconnected 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 46 of file genl.c.

References nl_connect().

Here is the call graph for this function:

## ◆ genl_send_simple()

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

  sk | Generic Netlink socket
  family | Numeric family identifier
  cmd | Numeric command identifier
  version | Interface version
  flags | Additional 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. Due to a bug, this function returns the number of bytes sent. Treat any non-negative number as success.

Definition at line 86 of file genl.c.

References nl_send_simple().

Here is the call graph for this function:

## ◆ genlmsg_valid_hdr()

int genlmsg_valid_hdr | ( | struct nlmsghdr * | nlh,
|  | int | hdrlen
| ) |  |

Validate Generic Netlink message headers.

Parameters

  nlh | Pointer to Netlink message header
  hdrlen | Length 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 119 of file genl.c.

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

Here is the caller graph for this function:

## ◆ genlmsg_validate()

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

Validate Generic Netlink message including attributes.

Parameters

  nlh | Pointer to Netlink message header
  hdrlen | Length of user header
  maxtype | Maximum attribtue id expected
  policy | Attribute 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 153 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:

## ◆ genlmsg_parse()

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

Parse Generic Netlink message including attributes.

Parameters

  nlh | Pointer to Netlink message header
  hdrlen | Length of user header
  tb | Array to store parsed attributes
  maxtype | Maximum attribute id expected
  policy | Attribute 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 = genlmsg_parse(nlmsg_hdr(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 193 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:

## ◆ genlmsg_hdr()

struct genlmsghdr* genlmsg_hdr | ( | struct nlmsghdr * | nlh | ) |

Return pointer to Generic Netlink header.

Parameters

  nlh | Netlink message header

Returns
  Pointer to Generic Netlink message header

Definition at line 212 of file genl.c.

References nlmsg_data().

Here is the call graph for this function:

## ◆ genlmsg_len()

int genlmsg_len | ( | const struct genlmsghdr * | gnlh | ) |

Return length of message payload including user header.

Parameters

  gnlh | Generic Netlink message header

See also
  genlmsg_data()

Returns
  Length of user payload including an eventual user header in number of bytes.

Definition at line 226 of file genl.c.

Referenced by genlmsg_attrlen(), and genlmsg_user_datalen().

Here is the caller graph for this function:

## ◆ genlmsg_user_hdr()

void* genlmsg_user_hdr | ( | const struct genlmsghdr * | gnlh | ) |

Return pointer to user header.

Parameters

  gnlh | Generic 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 244 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:

## ◆ genlmsg_user_data()

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

Return pointer to user data.

Parameters

  gnlh | Generic netlink message header
  hdrlen | Length 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 261 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:

## ◆ genlmsg_user_datalen()

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

Return length of user data.

Parameters

  gnlh | Generic Netlink message header
  hdrlen | Length of user header

See also
  genlmsg_user_data()

Returns
  Length of user data in bytes

Definition at line 275 of file genl.c.

References genlmsg_len().

Here is the call graph for this function:

## ◆ genlmsg_attrdata()

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

Return pointer to message attributes.

Parameters

  gnlh | Generic Netlink message header
  hdrlen | Length of user header

See also
  genlmsg_attrlen()

Returns
  Pointer to the start of the message's attributes section.

Definition at line 289 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:

## ◆ genlmsg_attrlen()

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

Return length of message attributes.

Parameters

  gnlh | Generic Netlink message header
  hdrlen | Length of user header

See also
  genlmsg_attrdata()

Returns
  Length of the message section containing attributes in number of bytes.

Definition at line 304 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:

## ◆ genlmsg_put()

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

  msg | Netlink message object
  port | Netlink port or NL_AUTO_PORT
  seq | Sequence number of message or NL_AUTO_SEQ
  family | Numeric family identifier
  hdrlen | Length of user header
  flags | Additional Netlink message flags (optional)
  cmd | Numeric command identifier
  version | Interface 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 350 of file genl.c.

References nlmsg_data(), and nlmsg_put().

Here is the call graph for this function:

## ◆ genlmsg_data()

void* genlmsg_data | ( | const struct genlmsghdr * | gnlh | ) |

Return pointer to message payload.

Parameters

  gnlh | Generic 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 387 of file genl.c.

Referenced by genlmsg_user_hdr().

Here is the caller graph for this function: