|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // NAPT (Network Address & Port translation Code ) |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 @prototype |
|
22 */ |
|
23 |
|
24 #ifndef __TRANSLATIONTABLE_H |
|
25 #define __TRANSLATIONTABLE_H |
|
26 |
|
27 |
|
28 #include <e32std.h> |
|
29 |
|
30 #include <e32base.h> |
|
31 #include <es_sock.h> // for BigEndian |
|
32 #include <icmp6_hdr.h> |
|
33 #include <ip4_hdr.h> |
|
34 #include <tcp_hdr.h> |
|
35 #include <in_pkt.h> |
|
36 #include <ext_hdr.h> |
|
37 #include <in_chk.h> |
|
38 #include "naptconfigtable.h" |
|
39 |
|
40 //Hash Table Array Size |
|
41 const TUint16 KTranslationHashTableSize= 111; |
|
42 |
|
43 //flags for TCP session close |
|
44 const TUint8 KTcpClosePacketOUT =0x40 ; |
|
45 const TUint8 KTcpClosePacketIN =0x80 ; |
|
46 const TUint8 KTcpCloseDeletePacket = KTcpClosePacketOUT | KTcpClosePacketIN | KTcpCtlACK ; |
|
47 |
|
48 //TImer Default Values.. All values in Seconds.. |
|
49 const TUint32 KTimerMaxSeconds =2147 ; //Maximum Timer Interval |
|
50 const TUint32 KTableScanIntervalDefault =3*60 ; //3 minutes |
|
51 //Inactive Protcol Timeout Default Values |
|
52 const TUint32 KTcpIdleTimeOutDefault =24*60*60; //One day |
|
53 const TUint32 KUdpIdleTimeoutDefault =3*60; //3 minutes |
|
54 const TUint32 KIcmpIdleTimeoutDefault =3*60; //3 minutes |
|
55 //Tcp Close Wait Time for Napt Table Node Deletion |
|
56 const TUint32 KTcpOpenTimeoutDefault =30 ; // 30 seconds |
|
57 const TUint32 KTcpCloseTimeoutDefault =4*60; // 4 minutes |
|
58 |
|
59 //Napt Port Range |
|
60 const TUint16 KNaptPort_HIGH =64000; |
|
61 const TUint16 KNaptPort_LOW =61000; |
|
62 |
|
63 //IcmpQueryIdRange |
|
64 const TUint16 KNaptIcmpQuery_HIGH =30000; |
|
65 const TUint16 KNaptIcmpQuery_LOW =28000; |
|
66 |
|
67 class CNaptTimer; |
|
68 class CNaptIPPortMap; |
|
69 |
|
70 NONSHARABLE_CLASS(CNaptIPPortMap): public CBase |
|
71 { |
|
72 |
|
73 friend class CProtocolNapt; |
|
74 public: |
|
75 |
|
76 static CNaptIPPortMap* NewL(); |
|
77 ~CNaptIPPortMap(); |
|
78 |
|
79 public: |
|
80 |
|
81 TUint16 iSrcPort; //original source Address port |
|
82 TUint16 iDstPort; //just needed to compare in EntryExists function |
|
83 TUint16 iTrPort; //final translated port |
|
84 TUint8 iProtocolFlag; //soft state for tcp session close |
|
85 TUint iProtocolType; //type of protocol TCP/UDP/ICMP |
|
86 TUint32 iSrcIpAddr; //original source address |
|
87 TUint32 iTrIpAddr; //final translated ip address |
|
88 TUint32 iDstIpAddr; //just needed to compare in EntryExists function |
|
89 TUint32 iCurTime; //used for deleting the entry based on the timout values |
|
90 TNaptConfigInfo* iConfigInfo; //used for fetching packet specific configuration in InBound hook |
|
91 TSglQueLink* iLink; |
|
92 }; |
|
93 |
|
94 class TNaptIPPortMap : public TSglQue<CNaptIPPortMap> |
|
95 { |
|
96 public: |
|
97 TNaptIPPortMap(): |
|
98 TSglQue<CNaptIPPortMap>(_FOFF(CNaptIPPortMap, iLink)) {}; |
|
99 }; |
|
100 |
|
101 |
|
102 typedef class TSglQueIter<CNaptIPPortMap> TNaptTableIter; |
|
103 |
|
104 class TNaptTableMapMgr |
|
105 { |
|
106 friend class CProtocolNapt; |
|
107 |
|
108 public: |
|
109 TNaptTableMapMgr(); |
|
110 ~TNaptTableMapMgr(); |
|
111 |
|
112 inline TInt FindBucket(TInt aPortNo){ return aPortNo % KTranslationHashTableSize; } |
|
113 inline TInt GetIndexedPortCount(){ return iBucketsInUse;} |
|
114 CNaptIPPortMap* FindOrCreateNaptEntryL( TUint aProtocolType,const TUint32& aSrcAddr,const TUint32& aDstAddr,const TUint16 aSrcPort,const TUint16 aDstPort, const TNaptConfigInfo *aConfigInfo); |
|
115 TBool VerifySender(const CNaptIPPortMap* aTableNode, const TUint32& aSrcIp,TUint16 aSrcPort); |
|
116 CNaptIPPortMap* GetIPTranslationNode(TUint16 aDstPortNo); |
|
117 void DeleteNodeInIndexedList(TInt aIndex, CNaptIPPortMap *aTableNode); |
|
118 void TimerComplete(); |
|
119 void HandleTcpConnectionPhases( TInet6Checksum<TInet6HeaderTCP> &aPacket, CNaptIPPortMap* aTableNode,const TInt direction); |
|
120 |
|
121 private : |
|
122 CNaptIPPortMap *AllocateTranslationNodeL(TUint aProtocolType,const TUint32& aSrcAddr,const TUint32& aDstAddr,const TUint16 aSrcPort ,const TUint16 aDstPort, const TNaptConfigInfo *aConfigInfo, TUint16 aQueryId=0); |
|
123 void DeleteNaptTableNode( CNaptIPPortMap* aTableNode); |
|
124 |
|
125 private : |
|
126 TNaptIPPortMap iIPPortMap[KTranslationHashTableSize]; |
|
127 TUint16 iLastPort; |
|
128 TInt16 iBucketsInUse; |
|
129 TUint16 iIcmpQueryId; |
|
130 TUint32 iPublicGatewayIP; |
|
131 CNaptTimer* iTimerPtr; |
|
132 |
|
133 }; |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 #endif //translation.h |