Modules | |
Abstract Address | |
Caching | |
Abstract Data | |
Callbacks/Customization | |
Messages | |
Netlink Message Construction/Parsing Interface. | |
Socket | |
Utilities | |
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_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 (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. | |
#define | NL_CB_CALL(cb, type, msg) |
// Bind and connect the socket to a protocol, NETLINK_ROUTE in this example. nl_connect(sk, NETLINK_ROUTE);
// The most rudimentary method is to use nl_sendto() simply pushing // a piece of data to the other netlink peer. This method is not // recommended. const char buf[] = { 0x01, 0x02, 0x03, 0x04 }; nl_sendto(sk, buf, sizeof(buf)); // A more comfortable interface is nl_send() taking a pointer to // a netlink message. struct nl_msg *msg = my_msg_builder(); nl_send(sk, nlmsg_hdr(msg)); // nl_sendmsg() provides additional control over the sendmsg() message // header in order to allow more specific addressing of multiple peers etc. struct msghdr hdr = { ... }; nl_sendmsg(sk, nlmsg_hdr(msg), &hdr); // You're probably too lazy to fill out the netlink pid, sequence number // and message flags all the time. nl_send_auto_complete() automatically // extends your message header as needed with an appropriate sequence // number, the netlink pid stored in the netlink socket and the message // flags NLM_F_REQUEST and NLM_F_ACK (if not disabled in the socket) nl_send_auto_complete(sk, nlmsg_hdr(msg)); // Simple protocols don't require the complex message construction interface // and may favour nl_send_simple() to easly send a bunch of payload // encapsulated in a netlink message header. nl_send_simple(sk, MY_MSG_TYPE, 0, buf, sizeof(buf));
// nl_recv() receives a single message allocating a buffer for the message // content and gives back the pointer to you. struct sockaddr_nl peer; unsigned char *msg; nl_recv(sk, &peer, &msg); // nl_recvmsgs() receives a bunch of messages until the callback system // orders it to state, usually after receving a compolete multi part // message series. nl_recvmsgs(sk, my_callback_configuration); // nl_recvmsgs_default() acts just like nl_recvmsg() but uses the callback // configuration stored in the socket. nl_recvmsgs_default(sk); // In case you want to wait for the ACK to be recieved that you requested // with your latest message, you can call nl_wait_for_ack() nl_wait_for_ack(sk);
// Close the socket first to release kernel memory nl_close(sk);
#define NL_CB_CALL | ( | cb, | ||
type, | ||||
msg | ||||
) |
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.
Definition at line 106 of file nl.c.
References nl_socket_set_buffer_size().
Referenced by nfnl_connect(), and nl_cache_mngr_alloc().
void nl_close | ( | struct nl_sock * | sk | ) |
Close/Disconnect netlink socket.
sk | Netlink socket. |
Definition at line 162 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 205 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 235 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 281 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 331 of file nl.c.
References nl_send().
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 362 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 | ( | 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 722 of file nl.c.
Referenced by 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 736 of file nl.c.
References nl_recvmsgs().
Referenced by nl_cache_mngr_data_ready().
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 755 of file nl.c.
References NL_CB_ACK, nl_cb_clone(), NL_CB_CUSTOM, nl_cb_set(), and nl_recvmsgs().
Referenced by rtnl_cls_add(), rtnl_cls_change(), and rtnl_cls_delete().