|
1 // Copyright (c) 2007-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.cpp |
|
15 // implementation of ICMP tranlation |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalTechnology |
|
22 */ |
|
23 |
|
24 #include "hookdefs.h" |
|
25 #include <e32std.h> |
|
26 #include <in6_opt.h> |
|
27 #include <udp_hdr.h> |
|
28 #include <icmp6_hdr.h> |
|
29 #include <udp_hdr.h> |
|
30 #include <in_pkt.h> |
|
31 #include <ext_hdr.h> |
|
32 #include <in_chk.h> |
|
33 #include <tcp_hdr.h> |
|
34 #include <icmp6_hdr.h> |
|
35 #include "naptlog.h" |
|
36 #include "panic.h" |
|
37 #include "napt_ini.h" |
|
38 #include <posthook.h> |
|
39 |
|
40 |
|
41 /* |
|
42 *---------------------------------------------------------------------------------------- |
|
43 * ICMP FILE |
|
44 * Every ICMP message is supported except ICMP Redirect message. NAPT will not temper |
|
45 * Other messages are taken care. |
|
46 *------------------------------------------------------------------------------------------ |
|
47 */ |
|
48 |
|
49 |
|
50 TInt CProtocolNaptIn::IcmpHandler(RMBufHookPacket& aPacket, RMBufRecvInfo& aInfo) |
|
51 /* This Function will manipulate ICMP packets. It will handle two ICMP cases. |
|
52 * First ping request. |
|
53 * Second is Destination unreachable |
|
54 * @param aPacket |
|
55 * @param aInfo |
|
56 */ |
|
57 { |
|
58 TUint lSrcPort; |
|
59 // This flag states that packets have been translated and that KIp6Hook_DONE should be used as return value |
|
60 TBool translatedFlag = EFalse; |
|
61 |
|
62 TInet6Checksum<TInet6HeaderIP4> lIp(aPacket); |
|
63 TInt lengthIP = lIp.iHdr->HeaderLength(); |
|
64 |
|
65 //Obtain ICMP packet for checking error type |
|
66 TInet6Checksum<TInet6HeaderICMP_Echo> lIcmpIn(aPacket,lengthIP); |
|
67 TUint type = lIcmpIn.iHdr->Type(); |
|
68 |
|
69 //query identifier for particular ICMP echo reply |
|
70 TUint16 queryId = lIcmpIn.iHdr->Identifier(); |
|
71 |
|
72 const CNaptIPPortMap* table= NULL; |
|
73 TNaptConfigInfo* info = NULL; |
|
74 |
|
75 switch(type) |
|
76 { |
|
77 case KInet4ICMP_TimeStampReply: |
|
78 LOG(Log::Printf(_L("ICMP type is time stamp reply "))); |
|
79 case KInet4ICMP_EchoReply: |
|
80 |
|
81 LOG(Log::Printf(_L("ICMP type is PING response "))); |
|
82 |
|
83 //check whether translation is required or not.Result should be KErrNone |
|
84 table =iNapt->iNaptMapMgr.GetIPTranslationNode(queryId); |
|
85 |
|
86 if (table) |
|
87 { |
|
88 lIcmpIn.iHdr->SetIdentifier(table->iSrcPort); //Store Original Query Id from node |
|
89 info = table->iConfigInfo; //Store Config info in the local pointer |
|
90 |
|
91 //recompute checksum as we have changed query id |
|
92 lIcmpIn.ComputeChecksum(aPacket,NULL); |
|
93 |
|
94 //Take original IP which is translated by NAPT. |
|
95 TUint32 originalIP; |
|
96 originalIP=table->iSrcIpAddr; |
|
97 |
|
98 //Set destination IP to the Original IP which was translated |
|
99 lIp.iHdr->SetDstAddr(originalIP); |
|
100 TInetAddr::Cast(aInfo.iDstAddr).SetV4MappedAddress(originalIP); |
|
101 |
|
102 //This will set source scope i,e networkID as zero this will allow incoming hook to set scope |
|
103 //by itself. |
|
104 |
|
105 lIp.ComputeChecksum(); |
|
106 translatedFlag = ETrue; |
|
107 |
|
108 } |
|
109 break; |
|
110 |
|
111 case KInet4ICMP_SourceQuench: |
|
112 |
|
113 case KInet4ICMP_TimeExceeded: |
|
114 //IcmpHandlerTracert return type is TBool, which is same as TInt, hence it the return value is |
|
115 //directly assigned to translatedFlag. Any change in return value (other than 0 and 1), |
|
116 //this assginment have to be revisited. |
|
117 translatedFlag = IcmpHandlerTracert(aPacket, aInfo, &info); |
|
118 break; |
|
119 |
|
120 |
|
121 case KInet4ICMP_ParameterProblem: |
|
122 |
|
123 case KInet4ICMP_Unreachable: |
|
124 LOG(Log::Printf(_L("my type id is %d"),type)); |
|
125 |
|
126 /*------------------------------------------------------------------------------------ |
|
127 * ICMP destination Unreachable packet format. |
|
128 * |
|
129 * ------------------------------------------------- |
|
130 * | OUTER |ICMP |INNER |UDP |PAYLOAD| |
|
131 * | IP |HEADER |IP | | | |
|
132 * | HEADER | |header |HEADER | | |
|
133 * ------------------------------------------------- |
|
134 * |
|
135 * Rare case TYPE 3 CODE 4..NAPT not required |
|
136 * |
|
137 *From RFC 1191 for use when the code is set to 4: |
|
138 *when a router is unable to forward a datagram because it exceeds the MTU of the |
|
139 *next-hop network and its Don't Fragment bit is set, the router is required to |
|
140 *return an ICMP Destination Unreachable message to the source of the datagram, |
|
141 *with the Code indicating "fragmentation needed and DF set". |
|
142 *To support the Path MTU Discovery technique specified in this memo, |
|
143 *the router MUST include the MTU of that next-hop network in the low-order 16 bits of |
|
144 *the ICMP header field that is labelled "unused" in the ICMP specification. |
|
145 *The high-order 16 bits remain unused, and MUST be set to zero.... |
|
146 *The size in bytes of the largest datagram that could be forwarded, |
|
147 *along the path of the original datagram, without being fragmented at this |
|
148 *router. The size includes the IP header and IP data, and does not include |
|
149 *any lower-level headers. This field will never contain a value less than |
|
150 *68 since every router must be able to forward a 68 byte datagram without |
|
151 *fragmentation. |
|
152 --------------------------------------------------------------------------------------- |
|
153 */ |
|
154 |
|
155 //Split ICMP destnation Unreachable packet. |
|
156 RMBufChain payload; |
|
157 aPacket.SplitL(lengthIP, payload); |
|
158 |
|
159 TInet6Checksum<TInet6HeaderICMP> lIcmpIn(payload); |
|
160 |
|
161 TInt code = lIcmpIn.iHdr->Code(); |
|
162 TInt lenHeader=0; |
|
163 if(code==KInet4ICMP_CODE_DF) |
|
164 { |
|
165 //rare case TYPE 3, CODE 4 dont need NAPT.Since there is not Transport header |
|
166 LOG( |
|
167 TBuf<70> tmpSrc; |
|
168 TBuf<70> tmpDst; |
|
169 TInetAddr::Cast(aInfo.iSrcAddr).OutputWithScope(tmpSrc); |
|
170 TInetAddr::Cast(aInfo.iDstAddr).OutputWithScope(tmpDst); |
|
171 LOG(Log::Printf(_L("\t I am ICMP packet dont reqquire NAPT \n src=[%S] dst=[%S] ICMP code =%d"), &tmpSrc, &tmpDst,code,type)); |
|
172 ); |
|
173 |
|
174 aPacket.Append(payload); |
|
175 return KIp6Hook_PASS; |
|
176 } |
|
177 |
|
178 |
|
179 //Length of ICMP header + 4 is size of Empty + next Hop MTU |
|
180 lenHeader= lIcmpIn.iHdr->HeaderLength() + 4 ; |
|
181 |
|
182 //Inner IP header |
|
183 TInet6Checksum<TInet6HeaderIP4> lIpIn(payload, lenHeader); |
|
184 lenHeader += lIpIn.iHdr->HeaderLength(); |
|
185 |
|
186 //Find transport protocol it is using.According to this Translation will be made. |
|
187 TInt transport; |
|
188 transport=lIpIn.iHdr->Protocol(); |
|
189 |
|
190 LOG(Log::Printf(_L("I am using protocol=%d for communication and my destination is unreachable"),transport)); |
|
191 if(transport==KProtocolInetUdp) |
|
192 { |
|
193 |
|
194 //Inner UDP header. |
|
195 TInet6Packet<TInet6HeaderUDP> lUdpIn(payload,lenHeader); |
|
196 |
|
197 //check if header length is appropriate |
|
198 if(lUdpIn.iHdr==NULL) |
|
199 { |
|
200 LOG(Log::Printf(_L("Insuffient header length"))); |
|
201 aPacket.Append(payload); |
|
202 return KIp6Hook_PASS; |
|
203 } |
|
204 lenHeader += lUdpIn.iHdr->HeaderLength(); |
|
205 lSrcPort = lUdpIn.iHdr->SrcPort(); |
|
206 |
|
207 //Check if there is an entry in the translation table. |
|
208 table = iNapt->iNaptMapMgr.GetIPTranslationNode(lSrcPort); |
|
209 |
|
210 |
|
211 if(table) |
|
212 { |
|
213 TUint32 originalIP; |
|
214 originalIP = table->iSrcIpAddr; |
|
215 TUint originalPort = table->iSrcPort; |
|
216 info = table->iConfigInfo; |
|
217 |
|
218 lIp.iHdr->SetDstAddr(originalIP); |
|
219 |
|
220 //Translate inner IP information |
|
221 lIpIn.iHdr->SetSrcAddr(originalIP); |
|
222 lIpIn.ComputeChecksum(); |
|
223 |
|
224 //Translate inner Port |
|
225 lUdpIn.iHdr->SetSrcPort(originalPort); |
|
226 |
|
227 |
|
228 lUdpIn.iHdr->SetChecksum(0); |
|
229 |
|
230 |
|
231 TInetAddr::Cast(aInfo.iDstAddr).SetV4MappedAddress(originalIP); |
|
232 |
|
233 //This will set source scope i,e networkID of private Interface this will allow incoming hook to set scope |
|
234 //by itself. |
|
235 lIp.ComputeChecksum(); |
|
236 translatedFlag = ETrue; |
|
237 |
|
238 } |
|
239 |
|
240 aPacket.Append(payload); |
|
241 //NULL argument id for ICMP v4 packets |
|
242 lIcmpIn.ComputeChecksum(aPacket,NULL,NULL); |
|
243 |
|
244 }//Protocol UDP if |
|
245 |
|
246 else if(transport==KProtocolInetTcp) |
|
247 { |
|
248 //Tcp Header |
|
249 TInet6Checksum<TInet6HeaderTCP> lTcpIn(payload, lenHeader); |
|
250 //check if header length is appropriate |
|
251 if(lTcpIn.iHdr==NULL) |
|
252 { |
|
253 LOG(Log::Printf(_L("Insuffient header length rare case type 3 code 4"))); |
|
254 aPacket.Append(payload); |
|
255 return KIp6Hook_PASS; |
|
256 } |
|
257 |
|
258 lenHeader += lTcpIn.iHdr->HeaderLength(); |
|
259 lSrcPort = lTcpIn.iHdr->SrcPort(); |
|
260 |
|
261 //check whether packet need translation... |
|
262 table =iNapt->iNaptMapMgr.GetIPTranslationNode(lSrcPort); |
|
263 |
|
264 if(table) |
|
265 { |
|
266 TUint32 originalIP; |
|
267 originalIP =table->iSrcIpAddr; |
|
268 TUint originalPort = table->iSrcPort; |
|
269 info = table->iConfigInfo; |
|
270 |
|
271 //outer IP header... |
|
272 lIp.iHdr->SetDstAddr(originalIP); |
|
273 |
|
274 //Translate Inner IP header... |
|
275 lIpIn.iHdr->SetSrcAddr(originalIP); |
|
276 lIpIn.ComputeChecksum(); |
|
277 |
|
278 //Translate Port.... |
|
279 lTcpIn.iHdr->SetSrcPort(originalPort); |
|
280 |
|
281 |
|
282 //this one is to avoid armv5 errors and calculate checksum right |
|
283 RMBufChain& payload = static_cast<RMBufChain&>(aPacket); |
|
284 lTcpIn.ComputeChecksum(payload,&aInfo,aInfo.iOffset); |
|
285 |
|
286 TInetAddr::Cast(aInfo.iDstAddr).SetV4MappedAddress(originalIP); |
|
287 |
|
288 |
|
289 lIp.ComputeChecksum(); |
|
290 translatedFlag = ETrue; |
|
291 |
|
292 } |
|
293 aPacket.Append(payload); |
|
294 //NULL argument id for ICMP v4 packets |
|
295 lIcmpIn.ComputeChecksum(aPacket,NULL,NULL); |
|
296 }//Protocol TCP if |
|
297 break; |
|
298 }//Switch end |
|
299 if(translatedFlag) |
|
300 { |
|
301 aInfo.iFlags &= ~KIpAddressVerified; |
|
302 LOG( |
|
303 TBuf<70> tmpSrc; |
|
304 TBuf<70> tmpDst; |
|
305 TInetAddr::Cast(aInfo.iSrcAddr).OutputWithScope(tmpSrc); |
|
306 TInetAddr::Cast(aInfo.iDstAddr).OutputWithScope(tmpDst); |
|
307 LOG(Log::Printf(_L("\t I am translated ICMP packet \n src=[%S] dst=[%S] proto=%d"), &tmpSrc, &tmpDst, aInfo.iProtocol)); |
|
308 ); |
|
309 |
|
310 // Setting the scope to 0 will cause the stack to automatically fill in the correct scope itself |
|
311 TInetAddr::Cast(aInfo.iSrcAddr).SetScope(0); |
|
312 |
|
313 //Setting Network ID of private Interfae as a scope. Route will be searched according |
|
314 //to the Destination Id which is set as the scope of private interface. |
|
315 TInetAddr::Cast(aInfo.iDstAddr).SetScope(info->iScopeSrc); |
|
316 |
|
317 return KIp6Hook_DONE; |
|
318 } |
|
319 |
|
320 return KIp6Hook_PASS; |
|
321 |
|
322 } |
|
323 |
|
324 |
|
325 void CProtocolNapt::IcmpHandlerForward(RMBufHookPacket& aPacket, RMBufRecvInfo& aInfo) |
|
326 /* This Function will manipulate ICMP packets. It will handle two ICMP cases. |
|
327 * First ping request. |
|
328 * @param aPacket |
|
329 * @param aInfo |
|
330 */ |
|
331 { |
|
332 |
|
333 LOG(Log::Printf(_L(" CProtocolNapt::IcmpHandlerForwardL called for out going packets to global interface"))); |
|
334 |
|
335 //retrieve information from aInfo. This information will be maintained in the transation |
|
336 //table. |
|
337 TUint32 sourceIP = (TInetAddr::Cast(aInfo.iSrcAddr)).Address(); |
|
338 TUint32 destinationIP =(TInetAddr::Cast(aInfo.iDstAddr)).Address(); |
|
339 const TUint32 targetIP= iCurConfigInfo->iPublicGatewayIP.Address(); |
|
340 |
|
341 //IP packet.lengthIP is the length of IP header. |
|
342 TInet6Checksum<TInet6HeaderIP4> lIp(aPacket); |
|
343 TInt lengthIP = lIp.iHdr->HeaderLength(); |
|
344 |
|
345 //Obtain ICMP packet. |
|
346 TInet6Checksum<TInet6HeaderICMP_Echo> lIcmpIn(aPacket,lengthIP); |
|
347 TUint type = lIcmpIn.iHdr->Type(); |
|
348 |
|
349 //check if the type is ECHO i.e. 8. Then only translate else just pass packets. |
|
350 switch(type) |
|
351 { |
|
352 |
|
353 case KInet4ICMP_TimeStamp: |
|
354 |
|
355 case KInetICMP_Information_Request: |
|
356 |
|
357 case KInet4ICMP_AddressMask_Request: |
|
358 |
|
359 case KInet4ICMP_DNS_Request: |
|
360 |
|
361 case KInet4ICMP_Echo : |
|
362 LOG(Log::Printf(_L("my type id is %d"),type)); |
|
363 |
|
364 TUint16 orgQueryId = lIcmpIn.iHdr->Identifier(); |
|
365 |
|
366 const CNaptIPPortMap* table=NULL; |
|
367 |
|
368 //Finds Translation Node,if already existing or creates a new node filled with unique translated port number for |
|
369 //translated IP for TCP/UDP/ICMP connections. |
|
370 TRAPD(ret,table=iNaptMapMgr.FindOrCreateNaptEntryL(KProtocolInetIcmp ,sourceIP, destinationIP,orgQueryId ,0, iCurConfigInfo)); |
|
371 |
|
372 if(table==NULL || (ret== KErrNoMemory)) |
|
373 { |
|
374 LOG(Log::Printf(_L("No entry for table "))); |
|
375 return; |
|
376 } |
|
377 |
|
378 //set new Query Id -extract which is set in table node |
|
379 lIcmpIn.iHdr->SetIdentifier(table->iTrPort) ; |
|
380 //recompute checksum as we have changed QueryId in IcmpEchoRequest packet. |
|
381 lIcmpIn.ComputeChecksum(aPacket, NULL); |
|
382 |
|
383 lIp.iHdr->SetSrcAddr(targetIP); |
|
384 TInetAddr::Cast(aInfo.iSrcAddr).SetV4MappedAddress(targetIP); |
|
385 |
|
386 // Setting the scope to 0 will cause the stack to automatically fill in the correct scope itself |
|
387 TInetAddr::Cast(aInfo.iSrcAddr).SetScope(0); |
|
388 |
|
389 //Setting Network ID of desired interface as a scope. Route will be searched according |
|
390 //to the Destination Id which is set as the scope of desired interface. |
|
391 TInetAddr::Cast(aInfo.iDstAddr).SetScope(iCurConfigInfo->iScopedest); |
|
392 LOG( |
|
393 TBuf<70> tmpSrc; |
|
394 TBuf<70> tmpDst; |
|
395 TInetAddr::Cast(aInfo.iSrcAddr).OutputWithScope(tmpSrc); |
|
396 TInetAddr::Cast(aInfo.iDstAddr).OutputWithScope(tmpDst); |
|
397 LOG(Log::Printf(_L("\t I am translated ICMP packet OutBound \n src=[%S] dst=[%S] proto=%d"), &tmpSrc, &tmpDst, aInfo.iProtocol)); |
|
398 ); |
|
399 |
|
400 //Compute checksum |
|
401 lIp.ComputeChecksum(); |
|
402 aInfo.iFlags &= ~KIpAddressVerified; |
|
403 break; |
|
404 } |
|
405 } |
|
406 |
|
407 |
|
408 TInt CProtocolNaptIn::IcmpHandlerTracert(RMBufHookPacket& aPacket, RMBufRecvInfo& aInfo, TNaptConfigInfo** aConfigInfo) |
|
409 /* |
|
410 ------------------------------------------------------------------------------------------------ |
|
411 * Packet format for ICMP type 11(Time exceeded message) |
|
412 * |
|
413 * ------------------------------------------------------- |
|
414 * |IP |ICMP |IP | ICMP | |
|
415 * |Header |Header |Header | Header | |
|
416 * | |Type =11 | | Type = 8(ping request)| |
|
417 * ------------------------------------------------------- |
|
418 * The internet header plus the first 8 bytes of the original datagram's data is returned to the sender. |
|
419 * This data is used by the host to match the message to the appropriate process. |
|
420 * If a higher level protocol uses port numbers, they are assumed to be in the first 64 data bits of the original datagram's data. |
|
421 * |
|
422 * Tracert could be a application.Clients can send UDP packets for tracert.64 bits(8bytes)might contain transport header. |
|
423 * |
|
424 * |
|
425 * ------------------------------------------------------- |
|
426 * |IP |ICMP |IP | 64 bits of data | |
|
427 * |Header |Header |Header | which could contain | |
|
428 * | |Type =11 | | port) | |
|
429 * ------------------------------------------------------- |
|
430 * |
|
431 * |
|
432 ------------------------------------------------------------------------------------------------- |
|
433 */ |
|
434 { |
|
435 //source port of the packet |
|
436 TUint lSrcPort; |
|
437 |
|
438 const CNaptIPPortMap* table= NULL; |
|
439 |
|
440 //IP header,this header will be outer most header of the packet. Take header length |
|
441 //and split packet. |
|
442 TInet6Checksum<TInet6HeaderIP4> lIp(aPacket); |
|
443 TInt lengthIP = lIp.iHdr->HeaderLength(); |
|
444 |
|
445 // This flag states that packets have been translated and that KIp6Hook_DONE should be used as return value |
|
446 TBool translatedFlag= EFalse; |
|
447 |
|
448 //Split packet and seperate outer IP and ICMP |
|
449 RMBufChain payload; |
|
450 aPacket.SplitL(lengthIP, payload); |
|
451 |
|
452 |
|
453 TInet6Checksum<TInet6HeaderICMP> lIcmpTem(payload); |
|
454 |
|
455 //Length of ICMP header + 4 is size of Empty + next Hop MTU |
|
456 TInt headerLen = lIcmpTem.iHdr->HeaderLength() + 4 ; |
|
457 |
|
458 //Inner IP header |
|
459 TInet6Checksum<TInet6HeaderIP4> lIpInternal(payload, headerLen); |
|
460 headerLen += lIpInternal.iHdr->HeaderLength(); |
|
461 |
|
462 //Find whether after inner header there is transport header |
|
463 TInt transport= lIpInternal.iHdr->Protocol(); |
|
464 |
|
465 if(transport==KProtocolInetUdp) |
|
466 { |
|
467 //Inner UDP header. |
|
468 TInet6Packet<TInet6HeaderUDP> lUdpIn(payload,headerLen); |
|
469 |
|
470 //check if header length is appropriate |
|
471 if(lUdpIn.iHdr==NULL) |
|
472 { |
|
473 LOG(Log::Printf(_L("Insuffient header length"))); |
|
474 aPacket.Append(payload); |
|
475 return KIp6Hook_PASS; |
|
476 } |
|
477 headerLen += lUdpIn.iHdr->HeaderLength(); |
|
478 lSrcPort = lUdpIn.iHdr->SrcPort(); |
|
479 |
|
480 //Check if there is an entry in the translation table. |
|
481 table = iNapt->iNaptMapMgr.GetIPTranslationNode(lSrcPort); |
|
482 |
|
483 if(table) |
|
484 { |
|
485 TUint32 originalIP; |
|
486 originalIP = table->iSrcIpAddr; |
|
487 TUint originalPort = table->iSrcPort; |
|
488 *aConfigInfo = table->iConfigInfo; |
|
489 |
|
490 lIp.iHdr->SetDstAddr(originalIP); |
|
491 |
|
492 //Translate inner IP information |
|
493 lIpInternal.iHdr->SetSrcAddr(originalIP); |
|
494 lIpInternal.ComputeChecksum(); |
|
495 |
|
496 //Translate inner Port |
|
497 lUdpIn.iHdr->SetSrcPort(originalPort); |
|
498 |
|
499 |
|
500 lUdpIn.iHdr->SetChecksum(0); |
|
501 |
|
502 TInetAddr::Cast(aInfo.iDstAddr).SetV4MappedAddress(originalIP); |
|
503 |
|
504 //This will set source scope i,e networkID of private Interface this will allow incoming hook to set scope |
|
505 //by itself. |
|
506 lIp.ComputeChecksum(); |
|
507 translatedFlag = ETrue; |
|
508 } |
|
509 //Append splitted packet.Means join outer IP and ICMP. |
|
510 aPacket.Append(payload); |
|
511 |
|
512 //NULL argument id for ICMP v4 packets |
|
513 lIcmpTem.ComputeChecksum(aPacket,NULL,NULL); |
|
514 |
|
515 }//Protocol UDP if |
|
516 |
|
517 else if(transport==KProtocolInetTcp) |
|
518 { |
|
519 //Tcp Header |
|
520 TInet6Checksum<TInet6HeaderTCP> lTcpIn(payload, headerLen); |
|
521 //check if header length is appropriate |
|
522 if(lTcpIn.iHdr==NULL) |
|
523 { |
|
524 LOG(Log::Printf(_L("Insuffient header length"))); |
|
525 aPacket.Append(payload); |
|
526 return KIp6Hook_PASS; |
|
527 } |
|
528 |
|
529 headerLen += lTcpIn.iHdr->HeaderLength(); |
|
530 lSrcPort = lTcpIn.iHdr->SrcPort(); |
|
531 |
|
532 //check whether packet need translation... |
|
533 table =iNapt->iNaptMapMgr.GetIPTranslationNode(lSrcPort); |
|
534 |
|
535 if(table) |
|
536 { |
|
537 TUint32 originalIP; |
|
538 originalIP =table->iSrcIpAddr; |
|
539 TUint originalPort = table->iSrcPort; |
|
540 *aConfigInfo = table->iConfigInfo; |
|
541 //outer IP header... |
|
542 lIp.iHdr->SetDstAddr(originalIP); |
|
543 |
|
544 //Translate Inner IP header... |
|
545 lIpInternal.iHdr->SetSrcAddr(originalIP); |
|
546 lIpInternal.ComputeChecksum(); |
|
547 |
|
548 //Translate Port.... |
|
549 lTcpIn.iHdr->SetSrcPort(originalPort); |
|
550 |
|
551 |
|
552 //this one is to avoid armv5 errors and calculate checksum right |
|
553 RMBufChain& payload = static_cast<RMBufChain&>(aPacket); |
|
554 lTcpIn.ComputeChecksum(payload,&aInfo,aInfo.iOffset); |
|
555 |
|
556 TInetAddr::Cast(aInfo.iDstAddr).SetV4MappedAddress(originalIP); |
|
557 |
|
558 |
|
559 lIp.ComputeChecksum(); |
|
560 translatedFlag = ETrue; |
|
561 |
|
562 } |
|
563 aPacket.Append(payload);//Append splitted packet.Means join outer IP and ICMP. |
|
564 //NULL argument id for ICMP v4 packets |
|
565 lIcmpTem.ComputeChecksum(aPacket,NULL,NULL); |
|
566 }//Protocol TCP if |
|
567 else |
|
568 { |
|
569 TInet6Checksum<TInet6HeaderICMP_Echo> lIcmpPingHeader(payload, headerLen); |
|
570 |
|
571 TUint16 queryId = lIcmpPingHeader.iHdr->Identifier(); |
|
572 |
|
573 table =iNapt->iNaptMapMgr.GetIPTranslationNode(queryId); |
|
574 |
|
575 if(table) |
|
576 { |
|
577 TUint32 originalIP; |
|
578 originalIP =table->iSrcIpAddr; |
|
579 *aConfigInfo = table->iConfigInfo; |
|
580 //outer IP header... |
|
581 lIp.iHdr->SetDstAddr(originalIP); |
|
582 |
|
583 //Translate Inner IP header... |
|
584 lIpInternal.iHdr->SetSrcAddr(originalIP); |
|
585 lIpInternal.ComputeChecksum(); |
|
586 |
|
587 lIp.ComputeChecksum(); |
|
588 translatedFlag = ETrue; |
|
589 |
|
590 lIcmpPingHeader.ComputeChecksum(aPacket,NULL,NULL); |
|
591 } |
|
592 //Append splitted packet.Means join outer IP and ICMP. |
|
593 aPacket.Append(payload); |
|
594 lIcmpTem.ComputeChecksum(aPacket,NULL,NULL); |
|
595 |
|
596 }//ICMP else |
|
597 return translatedFlag; |
|
598 |
|
599 } |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |