xorp

IoIpSocket Class Reference

A base class for I/O IP raw socket communication. More...

#include <io_ip_socket.hh>

Inheritance diagram for IoIpSocket:
IoIp IfTreeListener

List of all members.

Public Member Functions

 IoIpSocket (FeaDataPlaneManager &fea_data_plane_manager, const IfTree &iftree, int family, uint8_t ip_protocol)
 Constructor for a given address family and protocol.
virtual ~IoIpSocket ()
 Virtual destructor.
int start (string &error_msg)
 Start operation.
int stop (string &error_msg)
 Stop operation.
int set_multicast_ttl (int ttl, string &error_msg)
 Set the default TTL (or hop-limit in IPv6) for the outgoing multicast packets.
int enable_multicast_loopback (bool is_enabled, string &error_msg)
 Enable/disable multicast loopback when transmitting multicast packets.
int set_default_multicast_interface (const string &if_name, const string &vif_name, string &error_msg)
 Set default interface for transmitting multicast packets.
int join_multicast_group (const string &if_name, const string &vif_name, const IPvX &group, string &error_msg)
 Join a multicast group on an interface.
int leave_multicast_group (const string &if_name, const string &vif_name, const IPvX &group, string &error_msg)
 Leave a multicast group on an interface.
int send_packet (const string &if_name, const string &vif_name, const IPvX &src_address, const IPvX &dst_address, int32_t ip_ttl, int32_t ip_tos, bool ip_router_alert, bool ip_internet_control, const vector< uint8_t > &ext_headers_type, const vector< vector< uint8_t > > &ext_headers_payload, const vector< uint8_t > &payload, string &error_msg)
 Send a raw IP packet.
XorpFdfindExistingInputSocket (const string &if_name, const string &vif_name)
 Get the file descriptor for receiving protocol messages on the specified vif.
XorpFdmcast_protocol_fd_in ()
 Get the input file descriptor to be used for multicast routing.
void notifyDeletingIface (const string &ifname)
 Interface is going away..clean up the sockets for the associated vif(s)
void notifyErasingIface (const string &ifname)
void notifyDeletingVif (const string &ifname, const string &vifname)
 VIF is going away..clean up the socket.
void notifyErasingVif (const string &ifname, const string &vifname)

Private Member Functions

int open_proto_sockets (string &error_msg)
 Open the protocol sockets.
int initializeInputSocket (XorpFd *rv, string &error_msg)
 Returns XORP_ERROR on error.
XorpFdfindOrCreateInputSocket (const string &if_name, const string &vif_name, string &error_msg)
 Find or create an input socket for the specified VIF.
int close_proto_sockets (string &error_msg)
 Close the protocol sockets.
int cleanupXorpFd (XorpFd *fd)
 Helper method to close a single socket.
int enable_ip_hdr_include (bool is_enabled, string &error_msg)
 Enable/disable the "Header Included" option (for IPv4) on the outgoing protocol socket.
int enable_recv_pktinfo (XorpFd *input_fd, bool is_enabled, string &error_msg)
 Enable/disable receiving information about a packet received on the incoming protocol socket.
void proto_socket_read (XorpFd fd, IoEventType type)
 Read data from a protocol socket, and then call the appropriate protocol module to process it.
int proto_socket_transmit (const IfTreeInterface *ifp, const IfTreeVif *vifp, const IPvX &src_address, const IPvX &dst_address, string &error_msg)
 Transmit a packet on a protocol socket.

Private Attributes

map< string, XorpFd * > _proto_sockets_in
XorpFd _proto_socket_out
bool _is_ip_hdr_included
uint16_t _ip_id
uint8_t * _rcvbuf
uint8_t * _sndbuf
uint8_t * _rcvcmsgbuf
uint8_t * _sndcmsgbuf
struct iovec _rcviov [1]
struct iovec _sndiov [1]
struct msghdr _rcvmh
struct msghdr _sndmh
struct sockaddr_in _from4
struct sockaddr_in _to4

Detailed Description

A base class for I/O IP raw socket communication.

Each protocol 'registers' for I/O and gets assigned one object of this class.


Constructor & Destructor Documentation

IoIpSocket::IoIpSocket ( FeaDataPlaneManager fea_data_plane_manager,
const IfTree iftree,
int  family,
uint8_t  ip_protocol 
)

Constructor for a given address family and protocol.

Parameters:
fea_data_plane_managerthe corresponding data plane manager (FeaDataPlaneManager).
iftreethe interface tree to use.
familythe address family (AF_INET or AF_INET6 for IPv4 and IPv6 respectively).
ip_protocolthe IP protocol number (IPPROTO_*).

Member Function Documentation

int IoIpSocket::cleanupXorpFd ( XorpFd fd) [private]

Helper method to close a single socket.

Does not remove from socket map structure. Deletes memory associated with 'fd'.

int IoIpSocket::close_proto_sockets ( string &  error_msg) [private]

Close the protocol sockets.

Parameters:
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoIpSocket::enable_ip_hdr_include ( bool  is_enabled,
string &  error_msg 
) [private]

Enable/disable the "Header Included" option (for IPv4) on the outgoing protocol socket.

If enabled, the IP header of a raw packet should be created by the application itself, otherwise the kernel will build it. Note: used only for IPv4. In RFC-3542, IPV6_PKTINFO has similar functions, but because it requires the interface index and outgoing address, it is of little use for our purpose. Also, in RFC-2292 this option was a flag, so for compatibility reasons we better not set it here; instead, we will use sendmsg() to specify the header's field values.

Parameters:
is_enabledif true, enable the option, otherwise disable it.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoIpSocket::enable_multicast_loopback ( bool  is_enabled,
string &  error_msg 
) [virtual]

Enable/disable multicast loopback when transmitting multicast packets.

If the multicast loopback is enabled, a transmitted multicast packet will be delivered back to this host (assuming the host is a member of the same multicast group).

Parameters:
is_enabledif true, enable the loopback, otherwise disable it.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implements IoIp.

int IoIpSocket::enable_recv_pktinfo ( XorpFd input_fd,
bool  is_enabled,
string &  error_msg 
) [private]

Enable/disable receiving information about a packet received on the incoming protocol socket.

If enabled, values such as interface index, destination address and IP TTL (a.k.a. hop-limit in IPv6), and hop-by-hop options will be received as well.

Parameters:
is_enabledif true, set the option, otherwise reset it.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
XorpFd* IoIpSocket::findExistingInputSocket ( const string &  if_name,
const string &  vif_name 
)

Get the file descriptor for receiving protocol messages on the specified vif.

Returns:
a reference to the file descriptor for receiving protocol messages.
XorpFd* IoIpSocket::findOrCreateInputSocket ( const string &  if_name,
const string &  vif_name,
string &  error_msg 
) [private]

Find or create an input socket for the specified VIF.

Returns NULL if the socket cannot be found or created.

int IoIpSocket::initializeInputSocket ( XorpFd rv,
string &  error_msg 
) [private]

Returns XORP_ERROR on error.

int IoIpSocket::join_multicast_group ( const string &  if_name,
const string &  vif_name,
const IPvX group,
string &  error_msg 
) [virtual]

Join a multicast group on an interface.

Parameters:
if_namethe name of the interface to join the multicast group.
vif_namethe name of the vif to join the multicast group.
groupthe multicast group to join.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implements IoIp.

int IoIpSocket::leave_multicast_group ( const string &  if_name,
const string &  vif_name,
const IPvX group,
string &  error_msg 
) [virtual]

Leave a multicast group on an interface.

Parameters:
if_namethe name of the interface to leave the multicast group.
vif_namethe name of the vif to leave the multicast group.
groupthe multicast group to leave.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implements IoIp.

XorpFd* IoIpSocket::mcast_protocol_fd_in ( ) [virtual]

Get the input file descriptor to be used for multicast routing.

This should not be bound to any specific interface. Returns NULL if cannot find or create one.

Implements IoIp.

int IoIpSocket::open_proto_sockets ( string &  error_msg) [private]

Open the protocol sockets.

The protocol sockets are specific to the particular protocol of this entry.

Parameters:
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
void IoIpSocket::proto_socket_read ( XorpFd  fd,
IoEventType  type 
) [private]

Read data from a protocol socket, and then call the appropriate protocol module to process it.

This is called as a IoEventCb callback.

Parameters:
fdfile descriptor that with event caused this method to be called.
typethe event type.
int IoIpSocket::proto_socket_transmit ( const IfTreeInterface ifp,
const IfTreeVif vifp,
const IPvX src_address,
const IPvX dst_address,
string &  error_msg 
) [private]

Transmit a packet on a protocol socket.

Parameters:
ifpthe interface to send the packet on.
vifpthe vif to send the packet on.
src_addressthe IP source address.
dst_addressthe IP destination address.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.
int IoIpSocket::send_packet ( const string &  if_name,
const string &  vif_name,
const IPvX src_address,
const IPvX dst_address,
int32_t  ip_ttl,
int32_t  ip_tos,
bool  ip_router_alert,
bool  ip_internet_control,
const vector< uint8_t > &  ext_headers_type,
const vector< vector< uint8_t > > &  ext_headers_payload,
const vector< uint8_t > &  payload,
string &  error_msg 
) [virtual]

Send a raw IP packet.

Parameters:
if_namethe interface to send the packet on. It is essential for multicast. In the unicast case this field may be empty.
vif_namethe vif to send the packet on. It is essential for multicast. In the unicast case this field may be empty.
src_addressthe IP source address.
dst_addressthe IP destination address.
ip_ttlthe IP TTL (hop-limit). If it has a negative value, the TTL will be set internally before transmission.
ip_tosthe Type Of Service (Diffserv/ECN bits for IPv4 or IP traffic class for IPv6). If it has a negative value, the TOS will be set internally before transmission.
ip_router_alertif true, then add the IP Router Alert option to the IP packet.
ip_internet_controlif true, then this is IP control traffic.
ext_headers_typea vector of integers with the types of the optional IPv6 extention headers.
ext_headers_payloada vector of payload data, one for each optional IPv6 extention header. The number of entries must match ext_headers_type.
payloadthe payload, everything after the IP header and options.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implements IoIp.

int IoIpSocket::set_default_multicast_interface ( const string &  if_name,
const string &  vif_name,
string &  error_msg 
) [virtual]

Set default interface for transmitting multicast packets.

Parameters:
if_namethe name of the interface that would become the default multicast interface.
vif_namethe name of the vif that would become the default multicast interface.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implements IoIp.

int IoIpSocket::set_multicast_ttl ( int  ttl,
string &  error_msg 
) [virtual]

Set the default TTL (or hop-limit in IPv6) for the outgoing multicast packets.

Parameters:
ttlthe desired IP TTL (a.k.a. hop-limit in IPv6) value.
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implements IoIp.

int IoIpSocket::start ( string &  error_msg) [virtual]

Start operation.

Parameters:
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implements IoIp.

int IoIpSocket::stop ( string &  error_msg) [virtual]

Stop operation.

Parameters:
error_msgthe error message (if error).
Returns:
XORP_OK on success, otherwise XORP_ERROR.

Implements IoIp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Typedefs Enumerations