|
1 /* |
|
2 * Copyright (c) 2003-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: IKEv2 protocol plugin |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <random.h> |
|
19 #include <in_sock.h> |
|
20 |
|
21 #include "ikev2plugin.h" |
|
22 #include "ikedebug.h" |
|
23 #include "ikev2pluginsession.h" |
|
24 #include "ipsecpolicyutil.h" |
|
25 |
|
26 |
|
27 EXPORT_C MIkePluginIf* Ikev2PlugInL( MKmdEventLoggerIf& aEventLogger, |
|
28 MIkeDebug& aDebug ) |
|
29 { |
|
30 return CIkev2PlugIn::NewL(aEventLogger, aDebug); |
|
31 } |
|
32 |
|
33 CIkev2PlugIn* CIkev2PlugIn::NewL( MKmdEventLoggerIf& aEventLogger, |
|
34 MIkeDebug& aDebug ) |
|
35 { |
|
36 CIkev2PlugIn* self = new (ELeave) CIkev2PlugIn(aEventLogger, aDebug); |
|
37 CleanupStack::PushL(self); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop(self); |
|
40 return self; |
|
41 } |
|
42 |
|
43 |
|
44 CIkev2PlugIn::CIkev2PlugIn( MKmdEventLoggerIf& aEventLogger, |
|
45 MIkeDebug& aDebug ) |
|
46 : iEventLogger(aEventLogger), iDebug(aDebug) |
|
47 { |
|
48 } |
|
49 |
|
50 |
|
51 void CIkev2PlugIn::ConstructL() |
|
52 { |
|
53 iPfKeySocketIf = CPFKeySocketIf::NewL(this, iDebug); |
|
54 iIpsecPolicyUtil = CIpsecPolicyUtil::NewL(); |
|
55 } |
|
56 |
|
57 |
|
58 CIkev2PlugIn::~CIkev2PlugIn() |
|
59 { |
|
60 delete iIpsecPolicyUtil; |
|
61 delete iPfKeySocketIf; |
|
62 |
|
63 __ASSERT_DEBUG( iPluginSessions.Count() == 0, |
|
64 User::Invariant() ); |
|
65 iPluginSessions.Close(); |
|
66 } |
|
67 |
|
68 |
|
69 MIkePluginSessionIf* CIkev2PlugIn::CreateSessionL( TUint32 aVpnIapId, |
|
70 TUint32 aVpnNetId, |
|
71 TUint32 aVpnInterfaceIndex, |
|
72 MIkeDataInterface& aIkeDataInterface ) |
|
73 { |
|
74 CIkev2PluginSession* pluginSession = CIkev2PluginSession::NewL( aVpnIapId, |
|
75 aVpnNetId, |
|
76 aVpnInterfaceIndex, |
|
77 aIkeDataInterface, |
|
78 *this, |
|
79 *iPfKeySocketIf, |
|
80 *iIpsecPolicyUtil, |
|
81 iEventLogger, |
|
82 iDebug ); |
|
83 TInt err = iPluginSessions.Append( pluginSession ); |
|
84 |
|
85 if ( err != KErrNone ) |
|
86 { |
|
87 delete pluginSession; |
|
88 pluginSession = NULL; |
|
89 User::Leave( err ); |
|
90 } |
|
91 |
|
92 return pluginSession; |
|
93 } |
|
94 |
|
95 void CIkev2PlugIn::PluginSessionDeleted(const MIkePluginSessionIf* aDeletedSession) |
|
96 { |
|
97 for (TInt i = 0; i < iPluginSessions.Count(); ++i) |
|
98 { |
|
99 if (iPluginSessions[i] == aDeletedSession) |
|
100 { |
|
101 iPluginSessions.Remove(i); |
|
102 } |
|
103 } |
|
104 } |
|
105 |
|
106 void CIkev2PlugIn::PfkeyMessageReceived( const TPfkeyMessage& aPfkeyMessage ) |
|
107 { |
|
108 switch ( aPfkeyMessage.iBase.iMsg->sadb_msg_type ) |
|
109 { |
|
110 case SADB_ADD: // Fall through |
|
111 case SADB_ACQUIRE: |
|
112 { |
|
113 for ( TInt i=0; i< iPluginSessions.Count(); i++ ) |
|
114 { |
|
115 if ( iPluginSessions[i]->MatchDestinationAddress( aPfkeyMessage.iDstAddr.Address() ) ) |
|
116 { |
|
117 iPluginSessions[i]->PfkeyMessageReceived( aPfkeyMessage ); |
|
118 break; |
|
119 } |
|
120 } |
|
121 break; |
|
122 } |
|
123 |
|
124 case SADB_EXPIRE: |
|
125 { |
|
126 for ( TInt i=0; i< iPluginSessions.Count(); i++ ) |
|
127 { |
|
128 if ( iPluginSessions[i]->MatchDestinationAddress( aPfkeyMessage.iSrcAddr.Address() ) ) |
|
129 { |
|
130 iPluginSessions[i]->PfkeyMessageReceived( aPfkeyMessage ); |
|
131 break; |
|
132 } |
|
133 } |
|
134 break; |
|
135 } |
|
136 default: |
|
137 break; |
|
138 } |
|
139 } |