libnl  3.2.14
Send & Receive Data

Connection management, sending & receiving of data. More...


Detailed Description

Connection management, sending & receiving of data.

Related sections in the development guide:

Header

#include <netlink/netlink.h>

Connection Management

int nl_connect (struct nl_sock *sk, int protocol)
 Create and connect netlink socket.
void nl_close (struct nl_sock *sk)
 Close/Disconnect netlink socket.

Send

int nl_sendto (struct nl_sock *sk, void *buf, size_t size)
 Send raw data over netlink socket.
int nl_sendmsg (struct nl_sock *sk, struct nl_msg *msg, struct msghdr *hdr)
 Send netlink message with control over sendmsg() message header.
int nl_send_iovec (struct nl_sock *sk, struct nl_msg *msg, struct iovec *iov, unsigned iovlen)
 Send netlink message.
int nl_send (struct nl_sock *sk, struct nl_msg *msg)
 Send netlink message.
void nl_complete_msg (struct nl_sock *sk, struct nl_msg *msg)
void nl_auto_complete (struct nl_sock *sk, struct nl_msg *msg)
int nl_send_auto (struct nl_sock *sk, struct nl_msg *msg)
 Automatically complete and send a netlink message.
int nl_send_auto_complete (struct nl_sock *sk, struct nl_msg *msg)
int nl_send_sync (struct nl_sock *sk, struct nl_msg *msg)
 Send netlink message and wait for response (sync request-response)
int nl_send_simple (struct nl_sock *sk, int type, int flags, void *buf, size_t size)
 Send simple netlink message using nl_send_auto_complete()

Receive

int nl_recv (struct nl_sock *sk, struct sockaddr_nl *nla, unsigned char **buf, struct ucred **creds)
 Receive data from netlink socket.
int nl_recvmsgs_report (struct nl_sock *sk, struct nl_cb *cb)
 Receive a set of messages from a netlink socket and report parsed messages.
int nl_recvmsgs (struct nl_sock *sk, struct nl_cb *cb)
 Receive a set of messages from a netlink socket.
int nl_recvmsgs_default (struct nl_sock *sk)
 Receive a set of message from a netlink socket using handlers in nl_sock.
int nl_wait_for_ack (struct nl_sock *sk)
 Wait for ACK.
int nl_pickup (struct nl_sock *sk, int(*parser)(struct nl_cache_ops *, struct sockaddr_nl *, struct nlmsghdr *, struct nl_parser_param *), struct nl_object **result)
 Pickup netlink answer, parse is and return object.

Function Documentation

int nl_connect ( struct nl_sock *  sk,
int  protocol 
)

Create and connect netlink socket.

Parameters:
skNetlink socket.
protocolNetlink protocol to use.

Creates a netlink socket using the specified protocol, binds the socket and issues a connection attempt.

This function fail if socket is already connected.

Note:
SOCK_CLOEXEC is set on the socket if available.
Returns:
0 on success or a negative error code.

Definition at line 78 of file nl.c.

References nl_socket_set_buffer_size().

Referenced by genl_connect(), nfnl_connect(), and nl_cache_mngr_alloc().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void nl_close ( struct nl_sock *  sk)

Close/Disconnect netlink socket.

Parameters:
skNetlink socket.

Definition at line 143 of file nl.c.

Referenced by nl_cache_mngr_free().

+ Here is the caller graph for this function:

int nl_sendto ( struct nl_sock *  sk,
void *  buf,
size_t  size 
)

Send raw data over netlink socket.

Parameters:
skNetlink socket.
bufData buffer.
sizeSize of data buffer.
Returns:
Number of characters written on success or a negative error code.

Definition at line 167 of file nl.c.

int nl_sendmsg ( struct nl_sock *  sk,
struct nl_msg *  msg,
struct msghdr *  hdr 
)

Send netlink message with control over sendmsg() message header.

Parameters:
skNetlink socket.
msgNetlink message to be sent.
hdrSendmsg() message header.
Returns:
Number of characters sent on sucess or a negative error code.

Definition at line 186 of file nl.c.

References NL_CB_MSG_OUT, and NL_OK.

Referenced by nl_send_iovec().

+ Here is the caller graph for this function:

int nl_send_iovec ( struct nl_sock *  sk,
struct nl_msg *  msg,
struct iovec *  iov,
unsigned  iovlen 
)

Send netlink message.

Parameters:
skNetlink socket.
msgNetlink message to be sent.
ioviovec to be sent.
iovlennumber of struct iovec to be sent.
See also:
nl_sendmsg()
Returns:
Number of characters sent on success or a negative error code.

Definition at line 216 of file nl.c.

References nl_sendmsg().

Referenced by nl_send().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int nl_send ( struct nl_sock *  sk,
struct nl_msg *  msg 
)

Send netlink message.

Parameters:
skNetlink socket.
msgNetlink message to be sent.
See also:
nl_sendmsg()
Returns:
Number of characters sent on success or a negative error code.

Definition at line 262 of file nl.c.

References nl_send_iovec(), and nlmsg_hdr().

Referenced by nl_send_auto().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int nl_send_auto ( struct nl_sock *  sk,
struct nl_msg *  msg 
)

Automatically complete and send a netlink message.

Parameters:
skNetlink socket.
msgNetlink message to be sent.

This function takes a netlink message and passes it on to nl_auto_complete() for completion.

Checks the netlink message nlh for completness and extends it as required before sending it out. Checked fields include pid, sequence nr, and flags.

See also:
nl_send()
Returns:
Number of characters sent or a negative error code.

Definition at line 312 of file nl.c.

References nl_send().

Referenced by nl_send_sync(), and rtnl_link_get_kernel().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int nl_send_sync ( struct nl_sock *  sk,
struct nl_msg *  msg 
)

Send netlink message and wait for response (sync request-response)

Parameters:
skNetlink socket
msgNetlink message to be sent

This function takes a netlink message and sends it using nl_send_auto(). It will then wait for the response (ACK or error message) to be received. Threfore this function will block until the operation has been completed.

Note:
Disabling auto-ack (nl_socket_disable_auto_ack()) will cause this function to return immediately after sending. In this case, it is the responsibility of the caller to handle any eventual error messages returned.
See also:
nl_send_auto().
Returns:
0 on success or a negative error code.

Definition at line 348 of file nl.c.

References nl_send_auto(), and nlmsg_free().

Referenced by rtnl_class_add(), rtnl_class_delete(), rtnl_cls_add(), rtnl_cls_change(), rtnl_cls_delete(), rtnl_link_add(), rtnl_link_delete(), rtnl_qdisc_add(), rtnl_qdisc_delete(), and rtnl_qdisc_update().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int nl_send_simple ( struct nl_sock *  sk,
int  type,
int  flags,
void *  buf,
size_t  size 
)

Send simple netlink message using nl_send_auto_complete()

Parameters:
skNetlink socket.
typeNetlink message type.
flagsNetlink message flags.
bufData buffer.
sizeSize of data buffer.

Builds a netlink message with the specified type and flags and appends the specified data as payload to the message.

See also:
nl_send_auto_complete()
Returns:
Number of characters sent on success or a negative error code.

Definition at line 374 of file nl.c.

References nlmsg_alloc_simple(), nlmsg_append(), and nlmsg_free().

Referenced by genl_send_simple(), nfnl_send_simple(), and nl_rtgen_request().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int nl_recv ( struct nl_sock *  sk,
struct sockaddr_nl *  nla,
unsigned char **  buf,
struct ucred **  creds 
)

Receive data from netlink socket.

Parameters:
skNetlink socket.
nlaDestination pointer for peer's netlink address.
bufDestination pointer for message content.
credsDestination pointer for credentials.

Receives a netlink message, allocates a buffer in *buf and stores the message content. The peer's netlink address is stored in *nla. The caller is responsible for freeing the buffer allocated in *buf if a positive value is returned. Interrupted system calls are handled by repeating the read. The input buffer size is determined by peeking before the actual read is done.

A non-blocking sockets causes the function to return immediately with a return value of 0 if no data is available.

Returns:
Number of octets read, 0 on EOF or a negative error code.

Definition at line 424 of file nl.c.

int nl_recvmsgs_report ( struct nl_sock *  sk,
struct nl_cb *  cb 
)

Receive a set of messages from a netlink socket and report parsed messages.

Parameters:
skNetlink socket.
cbset of callbacks to control behaviour.

This function is identical to nl_recvmsgs() to the point that it will return the number of parsed messages instead of 0 on success.

See also:
nl_recvmsgs()
Returns:
Number of received messages or a negative error code from nl_recv().

Definition at line 755 of file nl.c.

Referenced by nl_cache_mngr_data_ready(), and nl_recvmsgs().

+ Here is the caller graph for this function:

int nl_recvmsgs ( struct nl_sock *  sk,
struct nl_cb *  cb 
)

Receive a set of messages from a netlink socket.

Parameters:
skNetlink socket.
cbset of callbacks to control behaviour.

Repeatedly calls nl_recv() or the respective replacement if provided by the application (see nl_cb_overwrite_recv()) and parses the received data as netlink messages. Stops reading if one of the callbacks returns NL_STOP or nl_recv returns either 0 or a negative error code.

A non-blocking sockets causes the function to return immediately if no data is available.

See also:
nl_recvmsgs_report()
Returns:
0 on success or a negative error code from nl_recv().

Definition at line 780 of file nl.c.

References nl_recvmsgs_report().

Referenced by nl_pickup(), nl_recvmsgs_default(), and nl_wait_for_ack().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int nl_recvmsgs_default ( struct nl_sock *  sk)

Receive a set of message from a netlink socket using handlers in nl_sock.

Parameters:
skNetlink socket.

Calls nl_recvmsgs() with the handlers configured in the netlink socket.

Definition at line 796 of file nl.c.

References nl_recvmsgs().

+ Here is the call graph for this function:

int nl_wait_for_ack ( struct nl_sock *  sk)

Wait for ACK.

Parameters:
skNetlink socket.
Precondition:
The netlink socket must be in blocking state.

Waits until an ACK is received for the latest not yet acknowledged netlink message.

Definition at line 815 of file nl.c.

References NL_CB_ACK, nl_cb_clone(), NL_CB_CUSTOM, nl_cb_set(), and nl_recvmsgs().

+ Here is the call graph for this function:

int nl_pickup ( struct nl_sock *  sk,
int(*)(struct nl_cache_ops *, struct sockaddr_nl *, struct nlmsghdr *, struct nl_parser_param *)  parser,
struct nl_object **  result 
)

Pickup netlink answer, parse is and return object.

Parameters:
skNetlink socket
parserParser function to parse answer
resultResult pointer to return parsed object
Returns:
0 on success or a negative error code.

Definition at line 873 of file nl.c.

References nl_cb_clone(), NL_CB_CUSTOM, nl_cb_set(), NL_CB_VALID, and nl_recvmsgs().

Referenced by rtnl_link_get_kernel().

+ Here is the call graph for this function:

+ Here is the caller graph for this function: