SocketProcol for the tap pseudo-device. More...

#include <senf/Socket/Protocols/Raw/TunTapSocketHandle.hh>

Inheritance diagram for senf::TapSocketProtocol:

Related Functions

(Note that these are not member functions.)

typedef ProtocolClientSocketHandle< TapSocketProtocolTapSocketHandle
 SocketHandle of TapSocketProtocol. More...
 

Constructors

void init_client () const
 Open tap socket and create new tap interface. More...
 
void init_client (std::string const &interface_name, bool NO_PI=true) const
 Open tap socket and create new tap interface. More...
 

Abstract Interface Implementation

unsigned available () const
 Return (maximum) number of bytes available for reading without < blocking. More...
 
bool eof () const
 returns always false. More...
 
unsigned int ifaceIndex () const
 returns the index of the correspondent tap interface More...
 
std::string ifaceName () const
 returns the actual name of the correspondent tap interface More...
 

Additional Inherited Members

- Public Types inherited from senf::ConcreteSocketProtocol< Tap_Policy, TapSocketProtocol >
typedef Tap_Policy Policy
 The protocols policy. More...
 
- Public Member Functions inherited from senf::ConcreteSocketProtocol< Tap_Policy, TapSocketProtocol >
Policy const & policy () const
 Access the policy instance. More...
 
 ~ConcreteSocketProtocol ()=0
 
- Public Member Functions inherited from senf::SocketProtocol
virtual void close ()
 Close socket. More...
 
virtual void terminate () const
 Forcibly close socket. More...
 
virtual void state (SocketStateMap &map, unsigned lod) const
 Return socket state information. More...
 
int fd () const
 Get file descriptor. More...
 
 SocketProtocol ()
 
virtual ~SocketProtocol ()=0
 
- Public Member Functions inherited from senf::BSDSocketProtocol
std::pair< bool, unsigned > linger () const
 Return current linger status. More...
 
void linger (bool enable, unsigned timeout=0) const
 Change linger status. More...
 
boost::uint8_t priority () const
 Get packet priority assigned to outgoing packets. More...
 
void priority (boost::uint8_t value) const
 Set packet priority (e.g. TOS) More...
 
int error () const
 Get and clear pending socket error. More...
 
unsigned rcvbuf () const
 Check receive buffer size. More...
 
void rcvbuf (unsigned size) const
 Change receive buffer size. More...
 
unsigned sndbuf () const
 Check send buffer size. More...
 
void sndbuf (unsigned size) const
 Change size of send buffer. More...
 
template<unsigned short N>
void attachSocketFilter (::sock_filter(&filter)[N])
 
void detachSocketFilter ()
 
void mtuDiscovery (int mode) const
 
void rcvLowat (unsigned lowWat) const
 
void sndLowat (unsigned lowWat) const
 
- Protected Member Functions inherited from senf::ConcreteSocketProtocol< Tap_Policy, TapSocketProtocol >
ClientSocketHandle< PolicyclientHandle () const
 Get client handle for associated socket. More...
 
ServerSocketHandle< PolicyserverHandle () const
 Get server handle for associated socket. More...
 
- Protected Member Functions inherited from senf::SocketProtocol
FileHandle fh () const
 Get a FileHandle for this instance. More...
 
void fd (int) const
 Initialize file descriptor. More...
 

Detailed Description

SocketProcol for the tap pseudo-device.

Socket Handle typedefs:
TapSocketHandle
Policy Interface:
ClientSocketHandle::read() ...

The TapSocketProtocol provides access to the Linux tap device.

The tap device is a virtual ethernet network device. The tap driver was designed as low level kernel support for ethernet tunneling. Userland application can write Ethernet frames to the socket and kernel will receive this frames from the tap interface. In the same time every frame that kernel writes to the tap interface can be read by userland application from the socket.

This class is utilized as the protocol class of the ProtocolClientSocketHandle via the Socket Handle typedef above.

See also
Kernel documentation for the TUN/TAP device driver.

Definition at line 68 of file TunTapSocketHandle.hh.

Member Function Documentation

◆ available()

unsigned senf::TapSocketProtocol::available ( ) const
virtual

Return (maximum) number of bytes available for reading without < blocking.

This member will check in a (very, sigh) protocol dependent way, how many bytes may be read from a socket in a single (non-blocking) read operation. If the socket does not support reading (viz. NotReadablePolicy is set), this member should always return 0.

Depending on the protocol, it may not be possible to return a good value. In this case, an upper bound may be returned (e.g.: When reading from a socket which returns ethernet frames, returning 1500 from available() is ok). However, this should only be done as a last resort. Also beware, that this number should not be too large since the socket layer will always need to allocate that number of bytes for the data to be read.

Implements senf::SocketProtocol.

Definition at line 62 of file TunTapSocketHandle.cc.

◆ eof()

bool senf::TapSocketProtocol::eof ( ) const
virtual

returns always false.

Implements senf::SocketProtocol.

Definition at line 89 of file TunTapSocketHandle.cc.

◆ ifaceIndex()

unsigned int senf::TapSocketProtocol::ifaceIndex ( ) const

returns the index of the correspondent tap interface

Definition at line 95 of file TunTapSocketHandle.cc.

◆ ifaceName()

std::string senf::TapSocketProtocol::ifaceName ( ) const

returns the actual name of the correspondent tap interface

Definition at line 101 of file TunTapSocketHandle.cc.

◆ init_client() [1/2]

void senf::TapSocketProtocol::init_client ( ) const

Open tap socket and create new tap interface.

Opens the tun/tap socket and create a new tap interface Use ifaceName() to get the actual name of the newly created interface.

The new interface is down and has to be set up separately. After closing the socket, the tap interface and all corresponding routes will be deleted automatically.

Note
This member is implicitly called from the ProtocolClientSocketHandle::ProtocolClientSocketHandle() constructor

Definition at line 33 of file TunTapSocketHandle.cc.

◆ init_client() [2/2]

void senf::TapSocketProtocol::init_client ( std::string const &  interface_name,
bool  NO_PI = true 
) const

Open tap socket and create new tap interface.

Opens the tun/tap socket and create a new tap interface with the given name. Note that the created interface can have a different name as specified. Use ifaceName() to get the actual name.

The new interface is down and has to be set up separately. After closing the socket, the tap interface and all corresponding routes will be deleted automatically.

Parameters
[in]interface_namename of the new tap interface.
[in]NO_PIif set to false each packet has a additional 4 bytes header (flags, proto)
Note
This member is implicitly called from the ProtocolClientSocketHandle::ProtocolClientSocketHandle() constructor

Definition at line 39 of file TunTapSocketHandle.cc.


The documentation for this class was generated from the following files: