vpnengine/ikev1lib/src/ikev1plugin.cpp
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   IKEv1 protocol plugin 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "ikedebug.h"
       
    19 #include "ikeplugindefs.h"
       
    20 #include "ikev1pluginsession.h"
       
    21 #include "ikev1SAdata.h"
       
    22 #include "ipsecpolicyutil.h"
       
    23 #include "pfkeysocketif.h"
       
    24 
       
    25 // CLASS HEADER
       
    26 #include "ikev1plugin.h"
       
    27 
       
    28 // ======== GLOBAL FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // Creates IKEv1 plugin instance.
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 EXPORT_C MIkePluginIf* Ikev1PlugInL( MKmdEventLoggerIf& aEventLogger,
       
    35                                      MIkeDebug& aDebug )
       
    36     {
       
    37     CIkev1Plugin* plugin = CIkev1Plugin::NewL( aEventLogger, aDebug );
       
    38     return plugin;
       
    39     }
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // Two-phased constructor.
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CIkev1Plugin* CIkev1Plugin::NewL( MKmdEventLoggerIf& aEventLogger,
       
    48                                   MIkeDebug& aDebug )
       
    49     {
       
    50     CIkev1Plugin* self = new ( ELeave ) CIkev1Plugin( aEventLogger, aDebug );
       
    51     CleanupStack::PushL( self );                      
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop( self );
       
    54     return self;    
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // Destructor.
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CIkev1Plugin::~CIkev1Plugin()
       
    62     {    
       
    63     __ASSERT_DEBUG( iPluginSessions.Count() == 0,
       
    64                     User::Invariant() );
       
    65     iPluginSessions.Close();    
       
    66     delete iPFKeySocket;
       
    67     delete iIpsecPolicyUtil;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // Constructor.
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CIkev1Plugin::CIkev1Plugin( MKmdEventLoggerIf& aEventLogger,
       
    75                             MIkeDebug& aDebug )
       
    76  : iEventLogger( aEventLogger ),
       
    77    iDebug( aDebug )
       
    78     {    
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // Second phase construction.
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void CIkev1Plugin::ConstructL()
       
    86     {
       
    87     iPFKeySocket = CPFKeySocketIf::NewL( this,
       
    88                                          iDebug );
       
    89     
       
    90     iIpsecPolicyUtil = CIpsecPolicyUtil::NewL();
       
    91     }
       
    92     
       
    93 // ---------------------------------------------------------------------------
       
    94 // Removes IKE plugin session from array.
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void CIkev1Plugin::IkePluginSessionDeleted( CIkev1PluginSession* aPluginSession )
       
    98     {
       
    99     for ( TInt i=0; i<iPluginSessions.Count(); i++ )
       
   100         {
       
   101         if ( iPluginSessions[i] == aPluginSession )
       
   102             {
       
   103             iPluginSessions.Remove( i );
       
   104             break;
       
   105             }
       
   106         }
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Gets acceptable IPsec policies for specified selectors.
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 CIpsecSaSpecList* CIkev1Plugin::GetIpseSaSpecListLC( const TInetAddr& aLocalAddr, const TInetAddr& aLocalMask, 
       
   114                                                      const TInetAddr& aRemoteAddr, const TInetAddr& aRemoteMask,
       
   115                                                      TInt aProtocol, TUint32 aVpnNetId )
       
   116     {
       
   117     return iIpsecPolicyUtil->GetIpseSaSpecListLC( aLocalAddr, aLocalMask, 
       
   118                                                   aRemoteAddr, aRemoteMask,
       
   119                                                   aProtocol, aVpnNetId );
       
   120     }
       
   121 
       
   122 // Methods to build and send PFKEY API primitives to IPsec
       
   123 
       
   124 void CIkev1Plugin::AcquireSAError( TIpsecSAData& aSAData,
       
   125                                    TInt aError )
       
   126     {
       
   127     iPFKeySocket->AcquireSAError( aSAData, aError );
       
   128     }
       
   129 
       
   130 void CIkev1Plugin::UpdateSAL( TIpsecSAData& aSaData )
       
   131     {
       
   132     iPFKeySocket->UpdateSAL( aSaData );
       
   133     }
       
   134 
       
   135 void CIkev1Plugin::AddSAL( TIpsecSAData& aSaData )
       
   136     {
       
   137     iPFKeySocket->AddSAL( aSaData );
       
   138     }
       
   139 
       
   140 void CIkev1Plugin::DeleteIpsecSA( TIpsecSPI& aIpsecSpi )
       
   141     {
       
   142     iPFKeySocket->DeleteSA( aIpsecSpi.iSPI,
       
   143                             aIpsecSpi.iSrcAddr,
       
   144                             aIpsecSpi.iDstAddr, 
       
   145                             aIpsecSpi.iProtocol );  
       
   146     }
       
   147 
       
   148 void CIkev1Plugin::DeleteIpsecSA( TUint32 aSPI,
       
   149                                   TInetAddr& aSrc, 
       
   150                                   TInetAddr& aDst,
       
   151                                   TUint8 aProtocol )
       
   152     {
       
   153     iPFKeySocket->DeleteSA( aSPI, aSrc, aDst, aProtocol );
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // Creates IKEv1 plugin session.
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 MIkePluginSessionIf* CIkev1Plugin::CreateSessionL( TUint32 aVpnIapId,
       
   161                                                    TUint32 aVpnNetId,
       
   162                                                    TUint32 aVpnInterfaceIndex,
       
   163                                                    MIkeDataInterface& aDataInterface )
       
   164     {
       
   165     CIkev1PluginSession* pluginSession = CIkev1PluginSession::NewL( aVpnIapId,
       
   166                                                                     aVpnNetId,
       
   167                                                                     aVpnInterfaceIndex,
       
   168                                                                     aDataInterface,
       
   169                                                                     *this,
       
   170                                                                     *iPFKeySocket,
       
   171                                                                     iDebug ); 
       
   172     TInt err = iPluginSessions.Append( pluginSession );
       
   173     
       
   174     if ( err != KErrNone )
       
   175         {
       
   176         delete pluginSession;
       
   177         pluginSession = NULL;
       
   178         User::Leave( err );
       
   179         }
       
   180     
       
   181     return pluginSession;
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // Handles PFKEY message.
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 void CIkev1Plugin::PfkeyMessageReceived( const TPfkeyMessage& aPfkeyMessage  )
       
   189     {
       
   190     switch ( aPfkeyMessage.iBase.iMsg->sadb_msg_type )
       
   191         {
       
   192         case SADB_ACQUIRE:
       
   193             {
       
   194             for ( TInt i=0; i< iPluginSessions.Count(); i++ )
       
   195                 {
       
   196                 if ( iPluginSessions[i]->MatchDestinationAddress( aPfkeyMessage.iDstAddr.Address() ) )                
       
   197                     {
       
   198                     iPluginSessions[i]->PfkeyMessageReceived( aPfkeyMessage );
       
   199                     break;
       
   200                     }
       
   201                 }
       
   202             break;
       
   203             }
       
   204             
       
   205         case SADB_EXPIRE:
       
   206             {
       
   207             for ( TInt i=0; i< iPluginSessions.Count(); i++ )
       
   208                 {
       
   209                 if ( iPluginSessions[i]->MatchDestinationAddress( aPfkeyMessage.iSrcAddr.Address() ) )                
       
   210                     {
       
   211                     iPluginSessions[i]->PfkeyMessageReceived( aPfkeyMessage );
       
   212                     break;
       
   213                     }
       
   214                 }
       
   215             break;                        
       
   216             }
       
   217         default:
       
   218             break;
       
   219         }
       
   220     }
       
   221 
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // Returns UID.
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 TUint32 CIkev1Plugin::Uid()
       
   228     {
       
   229     return KIkeV1PluginUid3.iUid;
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // Returns event logger interface.
       
   234 // ---------------------------------------------------------------------------
       
   235 //
       
   236 MKmdEventLoggerIf& CIkev1Plugin::EventLogger()
       
   237     {
       
   238     return iEventLogger;
       
   239     }
       
   240