|
1 /* |
|
2 * Copyright (c) 1999-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: Security policy module payload structures |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ext_hdr.h> |
|
20 #include <tcp_hdr.h> |
|
21 #include <udp_hdr.h> |
|
22 #include <icmp6_hdr.h> |
|
23 |
|
24 // CLASS HEADER |
|
25 #include "secpolpayload.h" |
|
26 |
|
27 // ======== LOCAL FUNCTIONS ======== |
|
28 |
|
29 #ifdef _DEBUG |
|
30 static TInt IsShort( TDes &aStr, const TDesC &aName, TInt aMin, TInt aLength ) |
|
31 { |
|
32 aStr.Append( aName ); |
|
33 if ( aMin <= aLength ) |
|
34 { |
|
35 return 0; |
|
36 } |
|
37 aStr.Append(_L(".. truncated")); |
|
38 return 1; |
|
39 } |
|
40 #endif |
|
41 |
|
42 // ======== MEMBER FUNCTIONS ======== |
|
43 |
|
44 // |
|
45 // IPv4 HDR Dump routine |
|
46 // |
|
47 void THdrIP4::Dump( TDes &aStr, TInt /*aLength*/ ) |
|
48 { |
|
49 #ifndef _DEBUG |
|
50 (void)aStr; |
|
51 #endif |
|
52 |
|
53 #ifdef _DEBUG |
|
54 const TInt KMaxBufLength( 40 ); |
|
55 TBuf<KMaxBufLength> buf; |
|
56 TInetAddr addr; |
|
57 |
|
58 addr.SetAddress( SrcAddr() ); |
|
59 addr.OutputWithScope( buf ); |
|
60 aStr.Append( _L(" src=") ); |
|
61 aStr.Append( buf ); |
|
62 addr.SetAddress( DstAddr() ); |
|
63 addr.OutputWithScope( buf ); |
|
64 aStr.Append( _L(" dst=") ); |
|
65 aStr.Append( buf ); |
|
66 #endif |
|
67 } |
|
68 |
|
69 TBool THdrIP4::IsUnicast() |
|
70 { |
|
71 TInetAddr addr; |
|
72 TUint32 ip4Addr = DstAddr(); |
|
73 addr.SetAddress( ip4Addr ); |
|
74 TBool status = addr.IsUnicast(); |
|
75 if ( status != KErrNone ) |
|
76 { |
|
77 // |
|
78 // If at least 7 leftmost bits in address are set to 1 this |
|
79 // address is interpreted to be IPv4 subnet broadcast |
|
80 // |
|
81 status = ( ( ip4Addr & 0x7f ) != 0x7f ); |
|
82 } |
|
83 return status; |
|
84 } |
|
85 |
|
86 // |
|
87 // IPv6 HDR Dump routine |
|
88 // |
|
89 void THdrIP6::Dump( TDes &aStr, TInt /*aLength*/ ) |
|
90 { |
|
91 #ifndef _DEBUG |
|
92 (void)aStr; |
|
93 #endif |
|
94 |
|
95 #ifdef _DEBUG |
|
96 const TInt KMaxBufLength( 40 ); |
|
97 TBuf<KMaxBufLength> buf; |
|
98 TInetAddr addr; |
|
99 |
|
100 addr.SetAddress( SrcAddr() ); |
|
101 addr.OutputWithScope( buf ); |
|
102 aStr.Append( _L(" src=") ); |
|
103 aStr.Append( buf ); |
|
104 addr.SetAddress( DstAddr() ); |
|
105 addr.OutputWithScope( buf ); |
|
106 aStr.Append( _L(" dst=") ); |
|
107 aStr.Append( buf ); |
|
108 #endif |
|
109 } |
|
110 |
|
111 TBool THdrIP6::IsUnicast() |
|
112 { |
|
113 TInetAddr addr; |
|
114 addr.SetAddress( DstAddr() ); |
|
115 return addr.IsUnicast(); |
|
116 } |
|
117 |
|
118 TSecpolPayload::TSecpolPayload( const TUint8* aPtr ) |
|
119 : iRaw( aPtr ) |
|
120 { |
|
121 } |
|
122 |
|
123 void TSecpolPayload::Dump( TDes &aStr, TInt aLength, TInt aProtocol ) |
|
124 { |
|
125 #ifndef _DEBUG |
|
126 (void)aStr; |
|
127 (void)aLength; |
|
128 (void)aProtocol; |
|
129 #endif |
|
130 |
|
131 #ifdef _DEBUG |
|
132 for (;;) |
|
133 { |
|
134 TInt skip; |
|
135 switch ( aProtocol ) |
|
136 { |
|
137 case 50: // ESP |
|
138 if ( IsShort( aStr, |
|
139 _L(" ESP"), |
|
140 iESP->MinHeaderLength(), |
|
141 aLength ) ) |
|
142 { |
|
143 return; |
|
144 } |
|
145 aStr.AppendFormat( _L("(spi=%x,seq=%d)"), |
|
146 ByteOrder::Swap32( iESP->SPI() ), |
|
147 iESP->Sequence() ); |
|
148 return; // Cannot go past ESP |
|
149 case 51: |
|
150 if ( IsShort( aStr, |
|
151 _L(" AH"), |
|
152 iAH->MinHeaderLength(), |
|
153 aLength ) ) |
|
154 { |
|
155 return; |
|
156 } |
|
157 aStr.AppendFormat(_L("(spi=%x,seq=%d,protcol=%d)"), |
|
158 iAH->SPI(), iAH->Sequence(), iAH->NextHeader() ); |
|
159 skip = iAH->HeaderLength(); |
|
160 aProtocol = iAH->NextHeader(); |
|
161 break; // AH |
|
162 case 4: |
|
163 if ( IsShort( aStr, |
|
164 _L(" IP4-in-IP"), |
|
165 iIP4->MinHeaderLength(), |
|
166 aLength ) ) |
|
167 { |
|
168 return; |
|
169 } |
|
170 ((THdrIP4 *)iIP4)->Dump(aStr, aLength); |
|
171 skip = iIP4->HeaderLength(); |
|
172 aProtocol = iIP4->Protocol(); |
|
173 break; |
|
174 case 1: // Fall through |
|
175 case 58: |
|
176 if ( IsShort( aStr, |
|
177 _L(" ICMP"), |
|
178 iICMP->MinHeaderLength(), |
|
179 aLength ) ) |
|
180 { |
|
181 return; |
|
182 } |
|
183 aStr.AppendFormat(_L("(type=%d,code=%d)"), |
|
184 iICMP->Type(), iICMP->Code() ); |
|
185 return; |
|
186 case 6: |
|
187 if ( IsShort( aStr, |
|
188 _L(" TCP"), |
|
189 iTCP->MinHeaderLength(), |
|
190 aLength ) ) |
|
191 { |
|
192 return; |
|
193 } |
|
194 aStr.AppendFormat(_L("(src=%d,dst=%d)"), |
|
195 iTCP->SrcPort(), iTCP->DstPort()); |
|
196 return; |
|
197 case 17: |
|
198 if ( IsShort( aStr, |
|
199 _L(" UDP"), |
|
200 iUDP->MinHeaderLength(), |
|
201 aLength ) ) |
|
202 return; |
|
203 aStr.AppendFormat(_L("(src=%d,dst=%d)"), |
|
204 iUDP->SrcPort(), iUDP->DstPort()); |
|
205 return; |
|
206 case KProtocolInet6Ipip: |
|
207 if ( IsShort( aStr, |
|
208 _L(" IP6-in-IP"), |
|
209 iIP6->MinHeaderLength(), |
|
210 aLength ) ) |
|
211 { |
|
212 return; |
|
213 } |
|
214 ((THdrIP6 *)iIP6)->Dump( aStr, aLength ); |
|
215 skip = iIP6->HeaderLength(); |
|
216 aProtocol = iIP6->NextHeader(); |
|
217 break; |
|
218 case KProtocolInet6HopOptions: |
|
219 if ( IsShort( aStr, |
|
220 _L(" HBH"), |
|
221 iOPT->MinHeaderLength(), |
|
222 aLength ) ) |
|
223 { |
|
224 return; |
|
225 } |
|
226 skip = iOPT->HeaderLength(); |
|
227 aProtocol = iOPT->NextHeader(); |
|
228 break; |
|
229 case KProtocolInet6RoutingHeader: |
|
230 if ( IsShort( aStr, |
|
231 _L(" RTH"), |
|
232 iRTH->MinHeaderLength(), |
|
233 aLength ) ) |
|
234 { |
|
235 return; |
|
236 } |
|
237 aProtocol = iRTH->NextHeader(); |
|
238 skip = iRTH->HeaderLength(); |
|
239 break; |
|
240 case KProtocolInet6Fragment: |
|
241 if ( IsShort( aStr, |
|
242 _L(" FRAG"), |
|
243 iFRH->MinHeaderLength(), |
|
244 aLength ) ) |
|
245 { |
|
246 return; |
|
247 } |
|
248 aStr.AppendFormat(_L("(prot=%d,id=%d,offset=%d)"), |
|
249 iFRH->NextHeader(), iFRH->Id(), iFRH->FragmentOffset()); |
|
250 if ( iFRH->MFlag() ) |
|
251 { |
|
252 aStr.Append(_L(" More")); |
|
253 } |
|
254 return; |
|
255 case KProtocolInet6NoNextHeader: |
|
256 aStr.AppendFormat(_L(" NNH")); |
|
257 return; |
|
258 case KProtocolInet6DestinationOptions: |
|
259 if ( IsShort( aStr, |
|
260 _L(" DOP"), |
|
261 iOPT->MinHeaderLength(), |
|
262 aLength ) ) |
|
263 return; |
|
264 skip = iOPT->HeaderLength(); |
|
265 aProtocol = iOPT->NextHeader(); |
|
266 break; |
|
267 default: |
|
268 aStr.AppendFormat(_L(" protocol=%d"), aProtocol); |
|
269 return; |
|
270 } |
|
271 aLength -= skip; |
|
272 iRaw += skip; |
|
273 } |
|
274 #endif |
|
275 } |