class NetlinkSocket

NetlinkSocket class opens a netlink socket and forwards data arriving on the socket to NetlinkSocketObservers. More...

 
LOGO
 Annotated List  Files  Globals  Hierarchy  Index  Top

Public Methods


Detailed Description

NetlinkSocket class opens a netlink socket and forwards data arriving on the socket to NetlinkSocketObservers. The NetlinkSocket hooks itself into the EventLoop and activity usually happens asynchronously.

 NetlinkSocket (EventLoop& eventloop)

NetlinkSocket

 ~NetlinkSocket ()

~NetlinkSocket

int  start (string& error_msg)

start

Start the netlink socket operation.

Parameters:

error_msgthe error message (if error).

Returns: XORP_OK on success, otherwise XORP_ERROR.

int  stop (string& error_msg)

stop

Stop the netlink socket operation.

Parameters:

error_msgthe error message (if error).

Returns: XORP_OK on success, otherwise XORP_ERROR.

inline bool  is_open ()

is_open

[const]

Test if the netlink socket is open.

This method is needed because NetlinkSocket may fail to open netlink socket during startup.

Returns: true if the netlink socket is open, otherwise false.

ssize_t  write (const void* data, size_t nbytes)

write

Write data to netlink socket.

This method also updates the sequence number associated with this netlink socket.

Returns: the number of bytes which were written, or -1 if error.

ssize_t  sendto (const void* data, size_t nbytes, int flags, const struct sockaddr* to, socklen_t tolen)

sendto

Sendto data on netlink socket.

This method also updates the sequence number associated with this netlink socket.

Returns: the number of bytes which were written, or -1 if error.

inline uint32_t  seqno ()

seqno

[const]

Get the sequence number for next message written into the kernel.

The sequence number is derived from the instance number of this netlink socket and a 16-bit counter.

Returns: the sequence number for the next message written into the kernel.

inline uint32_t  nl_pid ()

nl_pid

[const]

Get cached netlink socket identifier value.

Returns: the cached netlink socket identifier value.

int  force_read (string& error_msg)

force_read

Force socket to read data.

This usually is performed after writing a request that the kernel will answer (e.g., after writing a route lookup). Use sparingly, with caution, and at your own risk.

Parameters:

error_msgthe error message (if error).

Returns: XORP_OK on success, otherwise XORP_ERROR.

int  force_recvfrom (int flags, struct sockaddr* from, socklen_t* fromlen, string& error_msg)

force_recvfrom

Force socket to recvfrom data.

This usually is performed after writing a sendto() request that the kernel will answer (e.g., after writing a route lookup). Use sparingly, with caution, and at your own risk.

Parameters:

flagsthe flags argument to the underlying recvfrom(2) system call.
fromif not NULL, on return it will be filled in with the source address of the received message.
fromlenit should be initialized to the size of the buffer associated with from. On return it will be modified to indicate the actual size of the address stored there.
error_msgthe error message (if error).

Returns: XORP_OK on success, otherwise XORP_ERROR.

int  force_recvmsg (int flags, bool only_kernel_messages, string& error_msg)

force_recvmsg

Force socket to recvmsg data.

This usually is performed after writing a sendmsg() request that the kernel will answer (e.g., after writing a route lookup). Use sparingly, with caution, and at your own risk.

Parameters:

flagsthe flags argument to the underlying recvmsg(2) system call.
only_kernel_messagesif true, accept only messages originated by the kernel.
error_msgthe error message (if error).

Returns: XORP_OK on success, otherwise XORP_ERROR.

void  set_nl_groups (uint32_t v)

set_nl_groups

Set the netlink multicast groups to listen for on the netlink socket.

Note that this method must be called before method start() is called. If this method is not called, then the netlink socket will listen to the default set of netlink multicast groups (the empty set).

Parameters:

vthe set of netlink multicast groups to listen for on the netlink socket.
void  set_multipart_message_read (bool v)

set_multipart_message_read

Set a flag to expect to read a multipart message that is terminated with NLMSG_DONE.

This flag is required to fix a bug with the Linux kernel: if we try to read the whole forwarding table, the kernel doesn't set the NLM_F_MULTI flag in each part of the multi-part message. The problem is similar when we read all addresses on an interface.

Parameters:

vif true, set the flag to expect to read a multi-part message that is terminated with NLMSG_DONE.

Generated by: pavlin on possum.icir.org on Wed Aug 2 15:36:19 2006, using kdoc $.