some clean-ups
[senf.git] / Socket / Protocols / Raw / TunTapSocketHandle.hh
index 86c3668..fb5f95f 100644 (file)
@@ -1,9 +1,9 @@
 // $Id:PacketSocketHandle.hh 218 2007-03-20 14:39:32Z tho $
 //
-// Copyright (C) 2006
-// Fraunhofer Institute for Open Communication Systems (FOKUS) 
-// Competence Center NETwork research (NET), St. Augustin, GERMANY 
-//     Stefan Bund <g0dil@berlios.de>
+// Copyright (C) 2008
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Thorsten Horstmann <tho@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 /** \file
-    \brief PacketProtocol and PacketSocketHandle public header
-
-    \todo Implement global promisc() helper based on ioctl() interface.
+    \brief PacketSocketProtocol and PacketSocketHandle public header
  */
 
-#ifndef HH_TunTapSocketHandle_
-#define HH_TunTapSocketHandle_ 1
+#ifndef HH_SENF_Socket_Protocols_Raw_TunTapSocketHandle_
+#define HH_SENF_Socket_Protocols_Raw_TunTapSocketHandle_ 1
 
 // Custom includes
 #include "../../../Socket/SocketPolicy.hh"
@@ -36,7 +34,6 @@
 #include "../../../Socket/FramingPolicy.hh"
 #include "../../../Socket/CommunicationPolicy.hh"
 #include "../../../Socket/ReadWritePolicy.hh"
-#include "../../../Socket/BufferingPolicy.hh"
 #include "../../../Socket/Protocols/BSDSocketProtocol.hh"
 #include "LLAddressing.hh"
 
@@ -54,63 +51,83 @@ namespace senf {
         DatagramFramingPolicy,
         ConnectedCommunicationPolicy,
         ReadablePolicy,
-        WriteablePolicy,
-        SocketBufferingPolicy
-        >::policy Tap_Policy;        ///< Policy for TAP
-
-    /** \brief TAP
+        WriteablePolicy
+        >::policy Tap_Policy;        ///< Policy for TapSocketProtocol
 
-        \todo document me
+    /** \brief SocketProcol for the tap pseudo-device.
 
         \par Socket Handle typedefs:
-
+            \ref TapSocketHandle
 
         \par Policy Interface:
+            ClientSocketHandle::read() ...
 
+        The TapSocketProtocol provides access to the Linux tap device.
 
-        \par Address Type:
-
+        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 typedefs above.
+        Socket Handle typedef above.
+
+        \see <a href="http://www.kernel.org/pub/linux/kernel/people/marcelo/linux-2.4/Documentation/networking/tuntap.txt">Kernel documentation for the TUN/TAP device driver.</a>
      */
-    class TapProtocol
-        : public ConcreteSocketProtocol<Tap_Policy>,
-          public BSDSocketProtocol,
-          public senf::pool_alloc_mixin<TapProtocol>
+    class TapSocketProtocol
+        : public ConcreteSocketProtocol<Tap_Policy,TapSocketProtocol>,
+          public BSDSocketProtocol
     {
     public:
         ///\name Constructors
         ///@{
-        void init_client() const;
-                                        ///< Create TAP socket
-                                        /**< \todo document me */
+        void init_client() const;       ///< Open tap socket and create new tap interface
+                                        /**< Opens the tun/tap socket and create a new tap interface
+                                             Use \ref 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 */
-        void init_client(std::string const & interface_name, bool const NO_PI=true) const;
-                                        ///< Create TAP socket
-                                        /**< \todo document me
-                                             \param[in] address remote address to connect to */
+        void 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 \ref 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. 
+                                             \param[in] interface_name name of the new tap interface.
+                                             \param[in] NO_PI if set to \c false each packet has a 
+                                                 additional 4 bytes header (flags, proto) */
                                         /**< \note This member is implicitly called from the
                                              ProtocolClientSocketHandle::ProtocolClientSocketHandle()
                                              constructor */
-        
+
         ///@}
 
         ///\name Abstract Interface Implementation
         ///@{
 
-        std::auto_ptr<SocketProtocol> clone() const;
         unsigned available() const;
-        bool eof() const;
+        bool eof() const;               ///< returns always false.
+        unsigned int ifaceIndex() const;///< returns the index of the correspondent tap interface
+        std::string ifaceName() const;  ///< returns the actual name of the correspondent tap interface  
 
+    private:
+        mutable unsigned int ifaceIndex_;
         ///@}
     };
 
-    typedef ProtocolClientSocketHandle<TapProtocol> TapSocketHandle;
-                                        ///< SocketHandle of TapProtocol
-                                        /**< \related TapPrototol */
+    typedef ProtocolClientSocketHandle<TapSocketProtocol> TapSocketHandle;
+                                        ///< SocketHandle of TapSocketProtocol
+                                        /**< \related TapSocketProtocol */
 
     /// @}
 }
@@ -122,7 +139,7 @@ namespace senf {
 //#include "TunTapSocketHandle.mpp"
 #endif
 
-\f
+
 // Local Variables:
 // mode: c++
 // fill-column: 100