|
1 /* |
|
2 * Copyright (c) 2008-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: VPN PFKEY extension data utility |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <in_sock.h> |
|
20 #include <networking/pfkeyv2.h> |
|
21 #include <networking/pfkeyext.h> |
|
22 |
|
23 #include "ikemsgheader.h" |
|
24 #include "pfkeyextdatautil.h" |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // This static method builds a generic PFKEY API extension data for IPSEC. |
|
30 // This data contains all parameters needed by the IPSEC to do UDP |
|
31 // encapsulation/decpsulation for ESP packet. Generic extension data format is |
|
32 // LID format begining with four bytes extension header. Extension header |
|
33 // consists two bytes extension length and two bytes extension ID. LID format |
|
34 // consists from one byte length, one byte ID and parameter data. |
|
35 // Buffer format: HL,HID,LID,LID,...LID |
|
36 // Generic extension data buffer handling macros are defined in pfkeyext.h |
|
37 // (common macros with IPSEC) |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 void PFKeyExtDataUtil::BuildUdpEncExtensionData( TDes8& aExtData, |
|
41 TUint32 aNAT_D_Flags, |
|
42 TBool aNATDetected, |
|
43 TBool aNokiaNATProbeUsed, |
|
44 TUint16 aUdpEncapsPort, |
|
45 TUint16 aKeepAliveTimeout, |
|
46 const TInetAddr& aDestinAddr, |
|
47 const TInetAddr& aOriginalAddr ) |
|
48 { |
|
49 if ( aNAT_D_Flags ) |
|
50 { |
|
51 aUdpEncapsPort = FLOATED_IKE_PORT; // for IETF specified ESP UDP encapsulation |
|
52 if ( ( aNAT_D_Flags & LOCAL_END_NAT ) == 0 ) |
|
53 { |
|
54 aKeepAliveTimeout = 0; // Local end is not behind NAT, no keepalive needed |
|
55 } |
|
56 } |
|
57 else |
|
58 { |
|
59 // |
|
60 // Nokia specific NAT traversal info (=ESP UDP tunneling) |
|
61 // If aNATDetected is true connection is over NAT:ted |
|
62 // network (=local end behind NAT). UDP encapsulation shall |
|
63 // then be done using configured port iEspUdpPort. If that |
|
64 // value is undefined default port 9872 shall be used then. |
|
65 // If aNATDetected is false and aNokiaNATProbeUsed is true |
|
66 // the NAT probe procedure has confirmed that there is no |
|
67 // NAT device between. ESP UDP encapsulation port is zeroed |
|
68 // then to avoid unnecessary ESP UDP encapsulation. |
|
69 // If aNokiaNATProbeUsed is false ESP UDP encapsulation is done |
|
70 // without probing, if any aUdpEncapsPort is defined |
|
71 // |
|
72 if ( !aNATDetected && aNokiaNATProbeUsed ) |
|
73 { |
|
74 aUdpEncapsPort = 0; |
|
75 } |
|
76 } |
|
77 |
|
78 if ( aUdpEncapsPort == 0 ) |
|
79 { |
|
80 aExtData.SetLength(0); // No extension data needed |
|
81 return; |
|
82 } |
|
83 |
|
84 TPfkeyGenExtension NatExtension( aExtData, ESP_UDP_ENCAPSULATION_EXT ); |
|
85 |
|
86 NatExtension.StoreParameter( UDP_ENCAPSULATION_PORT, |
|
87 2, |
|
88 (TUint8*)&aUdpEncapsPort ); |
|
89 |
|
90 if ( aKeepAliveTimeout ) |
|
91 { |
|
92 NatExtension.StoreParameter( NAT_KEEPALIVE_TIMEOUT, |
|
93 2, |
|
94 (TUint8*)&aKeepAliveTimeout ); |
|
95 } |
|
96 |
|
97 if ( aNAT_D_Flags & REMOTE_END_NAT ) |
|
98 { |
|
99 NatExtension.StoreParameter( DESTINATION_ADDRESS, |
|
100 sizeof(TInetAddr), |
|
101 (TUint8*)&aDestinAddr ); |
|
102 } |
|
103 |
|
104 if ( aOriginalAddr.Family() != KAFUnspec ) |
|
105 { |
|
106 NatExtension.StoreParameter( PEER_ORIGINAL_ADDRESS, |
|
107 sizeof(TInetAddr), |
|
108 (TUint8*)&aOriginalAddr ); |
|
109 } |
|
110 } |