Socket
[Core]

Allocation



struct nl_sock * nl_socket_alloc (void)
 Allocate new netlink socket.
struct nl_sock * nl_socket_alloc_cb (struct nl_cb *cb)
 Allocate new socket with custom callbacks.
void nl_socket_free (struct nl_sock *sk)
 Free a netlink socket.

Sequence Numbers



void nl_socket_disable_seq_check (struct nl_sock *sk)
 Disable sequence number checking.
unsigned int nl_socket_use_seq (struct nl_sock *sk)
 Use next sequence number.
void nl_socket_disable_auto_ack (struct nl_sock *sk)
 Disable automatic request for ACK.
void nl_socket_enable_auto_ack (struct nl_sock *sk)
 Enable automatic request for ACK (default).

Source Idenficiation



uint32_t nl_socket_get_local_port (const struct nl_sock *sk)
void nl_socket_set_local_port (struct nl_sock *sk, uint32_t port)
 Set local port of socket.

Group Subscriptions



int nl_socket_add_memberships (struct nl_sock *sk, int group,...)
 Join groups.
int nl_socket_add_membership (struct nl_sock *sk, int group)
int nl_socket_drop_memberships (struct nl_sock *sk, int group,...)
 Leave groups.
int nl_socket_drop_membership (struct nl_sock *sk, int group)
void nl_join_groups (struct nl_sock *sk, int groups)
 Join multicast groups (deprecated).

Peer Identfication



uint32_t nl_socket_get_peer_port (const struct nl_sock *sk)
void nl_socket_set_peer_port (struct nl_sock *sk, uint32_t port)
uint32_t nl_socket_get_peer_groups (const struct nl_sock *sk)
void nl_socket_set_peer_groups (struct nl_sock *sk, uint32_t groups)

File Descriptor



int nl_socket_get_fd (const struct nl_sock *sk)
int nl_socket_set_nonblocking (const struct nl_sock *sk)
 Set file descriptor of socket to non-blocking state.
void nl_socket_enable_msg_peek (struct nl_sock *sk)
 Enable use of MSG_PEEK when reading from socket.
void nl_socket_disable_msg_peek (struct nl_sock *sk)
 Disable use of MSG_PEEK when reading from socket.

Callback Handler



struct nl_cb * nl_socket_get_cb (const struct nl_sock *sk)
void nl_socket_set_cb (struct nl_sock *sk, struct nl_cb *cb)
int nl_socket_modify_cb (struct nl_sock *sk, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t func, void *arg)
 Modify the callback handler associated to the socket.

Utilities



int nl_socket_set_buffer_size (struct nl_sock *sk, int rxbuf, int txbuf)
 Set socket buffer size of netlink socket.
int nl_socket_set_passcred (struct nl_sock *sk, int state)
 Enable/disable credential passing on netlink socket.
int nl_socket_recv_pktinfo (struct nl_sock *sk, int state)
 Enable/disable receival of additional packet information.

Function Documentation

struct nl_sock* nl_socket_alloc ( void   )  [read]

Allocate new netlink socket.

Returns:
Newly allocated netlink socket or NULL.

Definition at line 117 of file socket.c.

References nl_cb_alloc().

Here is the call graph for this function:

struct nl_sock* nl_socket_alloc_cb ( struct nl_cb *  cb  )  [read]

Allocate new socket with custom callbacks.

Parameters:
cb Callback handler

The reference to the callback handler is taken into account automatically, it is released again upon calling nl_socket_free().

Returns:
Newly allocted socket handle or NULL.

Definition at line 137 of file socket.c.

void nl_socket_free ( struct nl_sock *  sk  ) 

Free a netlink socket.

Parameters:
sk Netlink socket.

Definition at line 149 of file socket.c.

void nl_socket_disable_seq_check ( struct nl_sock *  sk  ) 

Disable sequence number checking.

Parameters:
sk Netlink socket.

Disables checking of sequence numbers on the netlink socket This is required to allow messages to be processed which were not requested by a preceding request message, e.g. netlink events.

Note:
This function modifies the NL_CB_SEQ_CHECK configuration in the callback handle associated with the socket.

Definition at line 188 of file socket.c.

References NL_CB_CUSTOM, NL_CB_SEQ_CHECK, and nl_cb_set().

Referenced by nl_cache_mngr_alloc().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int nl_socket_use_seq ( struct nl_sock *  sk  ) 

Use next sequence number.

Parameters:
sk Netlink socket.

Uses the next available sequence number and increases the counter by one for subsequent calls.

Returns:
Unique serial sequence number

Definition at line 203 of file socket.c.

void nl_socket_disable_auto_ack ( struct nl_sock *  sk  ) 

Disable automatic request for ACK.

Parameters:
sk Netlink socket.

The default behaviour of a socket is to request an ACK for each message sent to allow for the caller to synchronize to the completion of the netlink operation. This function disables this behaviour and will result in requests being sent which will not have the NLM_F_ACK flag set automatically. However, it is still possible for the caller to set the NLM_F_ACK flag explicitely.

Definition at line 220 of file socket.c.

void nl_socket_enable_auto_ack ( struct nl_sock *  sk  ) 

Enable automatic request for ACK (default).

Parameters:
sk Netlink socket.
See also:
nl_socket_disable_auto_ack

Definition at line 230 of file socket.c.

void nl_socket_set_local_port ( struct nl_sock *  sk,
uint32_t  port 
)

Set local port of socket.

Parameters:
sk Netlink socket.
port Local port identifier

Assigns a local port identifier to the socket. If port is 0 a unique port identifier will be generated automatically.

Definition at line 255 of file socket.c.

int nl_socket_add_memberships ( struct nl_sock *  sk,
int  group,
  ... 
)

Join groups.

Parameters:
sk Netlink socket
group Group identifier

Joins the specified groups using the modern socket option which is available since kernel version 2.6.14. It allows joining an almost arbitary number of groups without limitation. The list of groups has to be terminated by 0 (NFNLGRP_NONE).

Make sure to use the correct group definitions as the older bitmask definitions for nl_join_groups() are likely to still be present for backward compatibility reasons.

Returns:
0 on sucess or a negative error code.

Definition at line 292 of file socket.c.

int nl_socket_drop_memberships ( struct nl_sock *  sk,
int  group,
  ... 
)

Leave groups.

Parameters:
sk Netlink socket
group Group identifier

Leaves the specified groups using the modern socket option which is available since kernel version 2.6.14. The list of groups has to terminated by 0 (NFNLGRP_NONE).

See also:
nl_socket_add_membership
Returns:
0 on success or a negative error code.

Definition at line 336 of file socket.c.

void nl_join_groups ( struct nl_sock *  sk,
int  groups 
)

Join multicast groups (deprecated).

Parameters:
sk Netlink socket.
groups Bitmask of groups to join.

This function defines the old way of joining multicast group which has to be done prior to calling nl_connect(). It works on any kernel version but is very limited as only 32 groups can be joined.

Definition at line 378 of file socket.c.

int nl_socket_set_nonblocking ( const struct nl_sock *  sk  ) 

Set file descriptor of socket to non-blocking state.

Parameters:
sk Netlink socket.
Returns:
0 on success or a negative error code.

Definition at line 431 of file socket.c.

Referenced by nl_cache_mngr_alloc().

Here is the caller graph for this function:

void nl_socket_enable_msg_peek ( struct nl_sock *  sk  ) 

Enable use of MSG_PEEK when reading from socket.

Parameters:
sk Netlink socket.

Definition at line 446 of file socket.c.

void nl_socket_disable_msg_peek ( struct nl_sock *  sk  ) 

Disable use of MSG_PEEK when reading from socket.

Parameters:
sk Netlink socket.

Definition at line 455 of file socket.c.

int nl_socket_modify_cb ( struct nl_sock *  sk,
enum nl_cb_type  type,
enum nl_cb_kind  kind,
nl_recvmsg_msg_cb_t  func,
void *  arg 
)

Modify the callback handler associated to the socket.

Parameters:
sk Netlink socket.
type which type callback to set
kind kind of callback
func callback function
arg argument to be passwd to callback function
See also:
nl_cb_set

Definition at line 488 of file socket.c.

References nl_cb_set().

Referenced by nl_cache_mngr_alloc().

Here is the call graph for this function:

Here is the caller graph for this function:

int nl_socket_set_buffer_size ( struct nl_sock *  sk,
int  rxbuf,
int  txbuf 
)

Set socket buffer size of netlink socket.

Parameters:
sk Netlink socket.
rxbuf New receive socket buffer size in bytes.
txbuf New transmit socket buffer size in bytes.

Sets the socket buffer size of a netlink socket to the specified values rxbuf and txbuf. Providing a value of 0 assumes a good default value.

Note:
It is not required to call this function prior to nl_connect().
Returns:
0 on sucess or a negative error code.

Definition at line 515 of file socket.c.

Referenced by nl_connect().

Here is the caller graph for this function:

int nl_socket_set_passcred ( struct nl_sock *  sk,
int  state 
)

Enable/disable credential passing on netlink socket.

Parameters:
sk Netlink socket.
state New state (0 - disabled, 1 - enabled)
Returns:
0 on success or a negative error code

Definition at line 550 of file socket.c.

int nl_socket_recv_pktinfo ( struct nl_sock *  sk,
int  state 
)

Enable/disable receival of additional packet information.

Parameters:
sk Netlink socket.
state New state (0 - disabled, 1 - enabled)
Returns:
0 on success or a negative error code

Definition at line 577 of file socket.c.