|
1 // Copyright (c) 2004-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 // iface.h - IPv6/IPv4 interface and route manager |
|
15 // |
|
16 |
|
17 |
|
18 |
|
19 /** |
|
20 @internalComponent |
|
21 */ |
|
22 #ifndef __IFACE_H__ |
|
23 #define __IFACE_H__ |
|
24 |
|
25 // The preprocessor symbol: ARP |
|
26 // ---------------------------- |
|
27 // Add code for doing IPv4 Address Resolution Protocol (ARP) on |
|
28 // IPv4 interfaces that specify "NeedNd". (also needed in ip6.cpp) |
|
29 // |
|
30 #undef ARP |
|
31 #define ARP 1 // include IPv4 ARP code always for now. |
|
32 |
|
33 #ifdef SYMBIAN_TCPIPDHCP_UPDATE |
|
34 //RFC 5006 definitions |
|
35 #define RDNSS_REFRESH_TIMEOUT 30 |
|
36 #define RDNSS_NAMESERVER1 1 |
|
37 #define RDNSS_NAMESERVER2 2 |
|
38 #define RDNSSMINLEN 24 // Minimum Length is 3 for a single Address i.e (8 * 3 = 24 Octets) |
|
39 #endif //SYMBIAN_TCPIPDHCP_UPDATE |
|
40 |
|
41 #include <e32base.h> |
|
42 #include <ip6_hook.h> |
|
43 #include <in_bind.h> |
|
44 #ifdef SYMBIAN_TCPIPDHCP_UPDATE |
|
45 #include <icmp6_hdr.h> |
|
46 #endif //SYMBIAN_TCPIPDHCP_UPDATE |
|
47 // |
|
48 // The special returns from StartSending and Error calls are |
|
49 // |
|
50 // The generic rules are as follows: |
|
51 // |
|
52 // returns > 0, ready to send data out (was not possible previously) |
|
53 // returns = 0, no further action required |
|
54 // returns < 0, interface is down |
|
55 // |
|
56 const TInt KIfaceTransition_UP = 2; // Interface changed from PENDING/DOWN to READY |
|
57 const TInt KIfaceTransition_READY = 1; // Interface changed from HOLD to READY |
|
58 const TInt KIfaceTransition_NONE = 0; // No change in the interface state (only PENDING, READY or HOLD) |
|
59 const TInt KIfaceTransition_DOWN = KErrNotReady; // (never compare return value against this directly!), only for < 0. |
|
60 |
|
61 class TIcmpTypeCode |
|
62 /** |
|
63 * A help class to package both IPv4 and IPv6 ICMP type and code. |
|
64 * |
|
65 * This is just a parameter to MNetworkServiceExtension::IcmpWrap method. |
|
66 */ |
|
67 { |
|
68 public: |
|
69 TIcmpTypeCode(TUint8 a4type, TUint8 a4code, TUint8 a6type, TUint8 a6code) |
|
70 : i4type(a4type), i4code(a4code), i6type(a6type), i6code(a6code) {} |
|
71 const TUint8 i4type; |
|
72 const TUint8 i4code; |
|
73 const TUint8 i6type; |
|
74 const TUint8 i6code; |
|
75 }; |
|
76 |
|
77 |
|
78 // MNetworkServiceExtension |
|
79 // ************************ |
|
80 // Extends the MNetworkService with additional private methods |
|
81 // which are only used betwen the interface manager and IP |
|
82 // protocol instance. |
|
83 class CNifIfBase; |
|
84 class MNetworkServiceExtension : public MNetworkService |
|
85 { |
|
86 public: |
|
87 // InterfaceAtteched is called just after the CNifIfBase pointer has |
|
88 // been stored into the internal interface manager instance (CIp6Interface), |
|
89 // aIf->Open() has been called. |
|
90 virtual void InterfaceAttached(const TDesC &aName, CNifIfBase *aIf) = 0; |
|
91 // InterfaceDetached is called just before the CNifIfBase pointer is going |
|
92 // going to be removed from the internal interface managere instance |
|
93 // (CIp6Interface) and before the aIf->Close() is being called. |
|
94 virtual void InterfaceDetached(const TDesC &aName, CNifIfBase *aIf) = 0; |
|
95 // Wrap a packet into ICMP error reply |
|
96 virtual void IcmpWrap(RMBufChain &aPacket, const TIcmpTypeCode aIcmp, const TUint32 aParameter = 0, const TInt aMC = 0) = 0; |
|
97 // Fragment packet to specificied MTU |
|
98 virtual TBool Fragment(RMBufSendPacket &aPacket, RMBufSendInfo &aInfo, TInt aMtu, RMBufPktQ &aFragments) = 0; |
|
99 }; |
|
100 |
|
101 // |
|
102 // CIfManager |
|
103 // ********** |
|
104 // |
|
105 class MNifIfUser; |
|
106 class MFlowManager; |
|
107 class CFlowContext; |
|
108 class RTimeout; |
|
109 class CIfManager : public CBase, public MInterfaceManager |
|
110 { |
|
111 friend class CProtocolFamilyInet6; |
|
112 // |
|
113 // Construct and destruct (only used by the INET6 Family object) |
|
114 // |
|
115 static CIfManager *NewL(); |
|
116 protected: |
|
117 virtual ~CIfManager() {} |
|
118 |
|
119 public: |
|
120 virtual CFlowContext *NewFlowL(const void *aOwner, MFlowManager *aManager, TUint aProtocol) = 0; |
|
121 virtual CFlowContext *NewFlowL(const void *aOwner, MFlowManager *aManager, CFlowContext &aFlow) = 0; |
|
122 virtual TInt SetChanged() const = 0; |
|
123 // |
|
124 // |
|
125 virtual TInt StartSending(CNifIfBase *aIface) = 0; |
|
126 virtual TInt Error(TInt aError, CNifIfBase *aIface) = 0; |
|
127 // |
|
128 // Protocol registering (iNifUsers list) |
|
129 // |
|
130 virtual MNifIfUser *Register(MNetworkServiceExtension *aService) = 0; // Makes protocol visible to interfaces |
|
131 virtual void Unregister(MNetworkServiceExtension *aService) = 0; // Removes protocol (called from protocol destructor) |
|
132 // |
|
133 // IcmpError() is only intended to be used from the |
|
134 // IcmpError() method of the IP protocol instance. The |
|
135 // packet in the aHead is in "unpacked" state, and it |
|
136 // begins with the returned IP header. |
|
137 // Returns |
|
138 // > 0,if packet has been released (not a normal |
|
139 // situation, as this would prevent it reaching |
|
140 // the upper layers) |
|
141 // = 0,if ICMP noted and can be passed to the |
|
142 // appropriate upper layer protocol |
|
143 // > 0,NOT USED CURRENTLY! (treat as = 0) |
|
144 // The first reason for this method is to get the |
|
145 // path MTU mechanism implemented. |
|
146 // |
|
147 virtual TInt IcmpError(RMBufRecvPacket &aPacket, RMBufRecvInfo &aInfo) = 0; |
|
148 virtual TInt IcmpHandler(RMBufRecvPacket &aPacket, RMBufRecvInfo &aInfo) = 0; |
|
149 #ifdef ARP |
|
150 virtual TInt ArpHandler(RMBufRecvPacket &aPacket, RMBufRecvInfo &aInfo) = 0; |
|
151 #endif |
|
152 virtual TInt IsForMePacket(RMBufRecvInfo &aInfo) const = 0; |
|
153 virtual void SetTimer(RTimeout &aHandle, TUint32 aDelay) = 0; |
|
154 virtual TInt GetIniValue(const TDesC &aSection, const TDesC &aName, TInt aDefault = 0, TInt aMin = 0, TInt aMax = 1) = 0; |
|
155 }; |
|
156 |
|
157 |
|
158 static const TInt KLoopbackMcastMetric = 0xffff; |
|
159 //< Metric set for multicast routes on loopback interface |
|
160 |
|
161 #ifdef _LOG |
|
162 // Internal help function for logging only |
|
163 //extern void PktLog(const TDesC &aFormat, const RMBufPktInfo &aInfo, const TDesC &aName); |
|
164 extern void PktLog(const TDesC &aFormat, const RMBufPktInfo &aInfo, TUint aIndex, const TDesC &aName); |
|
165 #endif |
|
166 |
|
167 #ifdef SYMBIAN_TCPIPDHCP_UPDATE |
|
168 //RFC-5006 Changes |
|
169 typedef TUint32 TRdnssLifetime; |
|
170 |
|
171 class TRdnssOptionData |
|
172 //Class to read RDNSS option data from TInet6OptionICMP_DnsInformationV1 |
|
173 /* |
|
174 @internalTechnology |
|
175 */ |
|
176 { |
|
177 public: |
|
178 |
|
179 TRdnssLifetime iStoredRdnssLifeTime; // (life time + system time) at which iRDNSS address becomes invalid |
|
180 TInetAddr iRDNSSaddress; //128 bit DNS address |
|
181 }; |
|
182 |
|
183 |
|
184 class TRdnssSortData |
|
185 //Class to Sort RDNSS Server List data |
|
186 /* |
|
187 @internalTechnology |
|
188 */ |
|
189 { |
|
190 public: |
|
191 TRdnssLifetime iStoredRdnssLifeTime; // (life time + system time) at which iRDNSS address becomes invalid |
|
192 TInt iRdnssServerListIndex; //index corresponds to iRdnssArrayList entries |
|
193 }; |
|
194 |
|
195 //Class to Manage RDNSS option data from TInet6OptionICMP_DnsInformationV1 |
|
196 class CManageRdnssServerList: public CBase |
|
197 /* |
|
198 @ internalTechnology |
|
199 */ |
|
200 { |
|
201 public: |
|
202 static CManageRdnssServerList *NewL(); |
|
203 ~CManageRdnssServerList(); |
|
204 |
|
205 public: |
|
206 // Functions to Process RDNSS Option and Manage RDNSS server List |
|
207 void RdnssProcessOptionData(TInet6OptionICMP_DnsInformationV1 aRdnssOption, TUint8 aNumRdnssAddr); |
|
208 TBool RdnssParseOptionHdr(TInet6OptionICMP_DnsInformationV1 aRdnssOption, TUint8& aNumRdnssAddr ); |
|
209 void RdnssServerListUpdate(TInet6OptionICMP_DnsInformationV1 aRdnssIcmpOption, TUint8 aNumRdnssAddr); |
|
210 TBool RdnssServerListSync(TInetAddr& aNameSer1, TInetAddr& aNameSer2); |
|
211 |
|
212 // Functions to syncrhonise NameServer Entries |
|
213 void RdnssNameServerUpdate(TInetAddr& aNameSer, TUint8 aNameSerIndex); |
|
214 void RdnssNameServerSync(TInt aRdnssIndex, TInetAddr& aNameSer1, TInetAddr& aNameSer2 ); |
|
215 void RdnssNameServerReset(TInetAddr& aNameSer, TInt& aDdnsflag); |
|
216 |
|
217 //RArray Wrapper Functions |
|
218 inline TInt CountRdnssEntry() { return iRdnssArrayList.Count(); } |
|
219 inline TInt CountRdnssLifetimeEntry() { return iRdnssLifetimeArrayList.Count(); } |
|
220 TBool InsertRdnssEntryL(TRdnssOptionData& aRdnssEntry, TInt aIndex); |
|
221 void DeleteRdnssEntry(TInt aRdnssArrayIndex); |
|
222 void DeleteRdnssLifetimeEntry(TInt aRdnssArrayIndex); |
|
223 |
|
224 //Miscallaneous Utitility Functions |
|
225 TRdnssOptionData& GetRdnssEntryRef(TInt aIndex); |
|
226 TRdnssSortData& GetRdnssLifetimeEntryRef(TInt aIndex); |
|
227 TBool RdnssEntryExists(const TIp6Addr& aRdnssAddr, TInt& aIndex); |
|
228 TInt& GetRdnssFlag(); |
|
229 void SetStoredLifeTime(TInt aIndex, TRdnssOptionData aRdnssData); |
|
230 void RdnssExpireLeastEntry(TRdnssOptionData aRdnssRcvData); |
|
231 void RdnssServerListDelete(); |
|
232 void RdnssServerListSort(); |
|
233 void RdnssServerListCopyL(); |
|
234 void PrintRdnssServerList(TUint8 aIndex); |
|
235 void PrintRdnssLifetimeList(TUint8 aIndex); |
|
236 void RdnssLifetimeListDelete(); |
|
237 |
|
238 // Return the number of seconds between the given time (aStamp) and |
|
239 // the time when interface was activated (iTimeStamp). aStamp must |
|
240 // always be same of after iTimeStamp. |
|
241 TRdnssLifetime Elapsed(const TTime &aStamp) const; |
|
242 TRdnssLifetime GetRemainingLifeTime(TInt aRdnssEntryindex); |
|
243 TRdnssLifetime ElapsedLifeTime(TRdnssOptionData aRdnssEntry); |
|
244 |
|
245 private: |
|
246 CManageRdnssServerList(); |
|
247 void ConstructL(); // Two Phase construction |
|
248 |
|
249 private: |
|
250 TTime iCurrentTimeStamp; // TimeStamp at which RDNSS data is stored |
|
251 TInt iRouterLifeTime; // Router lifetime |
|
252 TInt iRdnssFlag; // RDNSS Flag associated with Resolver repository1 and Repository2 |
|
253 RArray<TRdnssOptionData> iRdnssArrayList; // RDNSS Server List [index 0 set to iNameserver1, index 1 set to iNameServer2] |
|
254 RArray<TRdnssSortData> iRdnssLifetimeArrayList;// RDNSS Dummy Server List for sorting Lifetime |
|
255 }; |
|
256 #endif // SYMBIAN_TCPIPDHCP_UPDATE |
|
257 |
|
258 #endif |