libnl
3.2.14
|
Connection management, sending & receiving of data. More...
Connection management, sending & receiving of data.
Related sections in the development guide:
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. |
int nl_connect | ( | struct nl_sock * | sk, |
int | protocol | ||
) |
Create and connect netlink socket.
sk | Netlink socket. |
protocol | Netlink 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.
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().
void nl_close | ( | struct nl_sock * | sk | ) |
Close/Disconnect netlink socket.
sk | Netlink socket. |
Definition at line 143 of file nl.c.
Referenced by nl_cache_mngr_free().
int nl_sendto | ( | struct nl_sock * | sk, |
void * | buf, | ||
size_t | size | ||
) |
int nl_sendmsg | ( | struct nl_sock * | sk, |
struct nl_msg * | msg, | ||
struct msghdr * | hdr | ||
) |
Send netlink message with control over sendmsg() message header.
sk | Netlink socket. |
msg | Netlink message to be sent. |
hdr | Sendmsg() message header. |
Definition at line 186 of file nl.c.
References NL_CB_MSG_OUT, and NL_OK.
Referenced by nl_send_iovec().
int nl_send_iovec | ( | struct nl_sock * | sk, |
struct nl_msg * | msg, | ||
struct iovec * | iov, | ||
unsigned | iovlen | ||
) |
Send netlink message.
sk | Netlink socket. |
msg | Netlink message to be sent. |
iov | iovec to be sent. |
iovlen | number of struct iovec to be sent. |
Definition at line 216 of file nl.c.
References nl_sendmsg().
Referenced by nl_send().
int nl_send | ( | struct nl_sock * | sk, |
struct nl_msg * | msg | ||
) |
Send netlink message.
sk | Netlink socket. |
msg | Netlink message to be sent. |
Definition at line 262 of file nl.c.
References nl_send_iovec(), and nlmsg_hdr().
Referenced by nl_send_auto().
int nl_send_auto | ( | struct nl_sock * | sk, |
struct nl_msg * | msg | ||
) |
Automatically complete and send a netlink message.
sk | Netlink socket. |
msg | Netlink 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.
Definition at line 312 of file nl.c.
References nl_send().
Referenced by nl_send_sync(), and rtnl_link_get_kernel().
int nl_send_sync | ( | struct nl_sock * | sk, |
struct nl_msg * | msg | ||
) |
Send netlink message and wait for response (sync request-response)
sk | Netlink socket |
msg | Netlink 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.
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().
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()
sk | Netlink socket. |
type | Netlink message type. |
flags | Netlink message flags. |
buf | Data buffer. |
size | Size of data buffer. |
Builds a netlink message with the specified type and flags and appends the specified data as payload to the message.
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().
int nl_recv | ( | struct nl_sock * | sk, |
struct sockaddr_nl * | nla, | ||
unsigned char ** | buf, | ||
struct ucred ** | creds | ||
) |
Receive data from netlink socket.
sk | Netlink socket. |
nla | Destination pointer for peer's netlink address. |
buf | Destination pointer for message content. |
creds | Destination 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.
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.
sk | Netlink socket. |
cb | set 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.
Definition at line 755 of file nl.c.
Referenced by nl_cache_mngr_data_ready(), and nl_recvmsgs().
int nl_recvmsgs | ( | struct nl_sock * | sk, |
struct nl_cb * | cb | ||
) |
Receive a set of messages from a netlink socket.
sk | Netlink socket. |
cb | set 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.
Definition at line 780 of file nl.c.
References nl_recvmsgs_report().
Referenced by nl_pickup(), nl_recvmsgs_default(), and nl_wait_for_ack().
int nl_recvmsgs_default | ( | struct nl_sock * | sk | ) |
Receive a set of message from a netlink socket using handlers in nl_sock.
sk | Netlink socket. |
Calls nl_recvmsgs() with the handlers configured in the netlink socket.
Definition at line 796 of file nl.c.
References nl_recvmsgs().
int nl_wait_for_ack | ( | struct nl_sock * | sk | ) |
Wait for ACK.
sk | Netlink socket. |
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().
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.
sk | Netlink socket |
parser | Parser function to parse answer |
result | Result pointer to return parsed object |
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().