1.1 --- a/epoc32/include/in_pkt.h Wed Mar 31 12:27:01 2010 +0100
1.2 +++ b/epoc32/include/in_pkt.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -1,9 +1,9 @@
1.4 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 // All rights reserved.
1.6 // This component and the accompanying materials are made available
1.7 -// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
1.8 +// under the terms of "Eclipse Public License v1.0"
1.9 // which accompanies this distribution, and is available
1.10 -// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.11 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.12 //
1.13 // Initial Contributors:
1.14 // Nokia Corporation - initial contribution.
1.15 @@ -26,11 +26,12 @@
1.16 #ifndef __IN_PKT_H__
1.17 #define __IN_PKT_H__
1.18
1.19 -#include <nifmbuf.h>
1.20 #include "ip6_hdr.h" // ..should eventually be <inet/ip6_hdr.h>? -- msa
1.21 #include "ip4_hdr.h"
1.22 +class RMBufChain;
1.23
1.24 -#define TPACKETHEAD_FRAGMENT 1 ///< Enable iFragment in TPacketHead
1.25 +
1.26 +#define TPACKETHEAD_FRAGMENT 1 //< Enable iFragment in TPacketHead
1.27
1.28 /**
1.29 TScopeType is only provided so that "magic" constants can be
1.30 @@ -50,13 +51,13 @@
1.31 */
1.32 enum TScopeType
1.33 {
1.34 - EScopeType_IF = 0x0, ///< (= #KIp6AddrScopeNodeLocal - 1), id is interface index
1.35 - EScopeType_IAP = 0x1, ///< (= #KIp6AddrScopeLinkLocal - 1). id is IAP number
1.36 - EScopeType_GLOBAL = 0xD,///< (= #KIp6AddrScopeGlobal - 1). id is global scope id
1.37 + EScopeType_IF = 0x0, //< (= #KIp6AddrScopeNodeLocal - 1), id is interface index
1.38 + EScopeType_IAP = 0x1, //< (= #KIp6AddrScopeLinkLocal - 1). id is IAP number
1.39 + EScopeType_GLOBAL = 0xD,//< (= #KIp6AddrScopeGlobal - 1). id is global scope id
1.40 //
1.41 // no symbols defined for types 2..14 (they are also valid)
1.42 //
1.43 - EScopeType_NET = 0xF ///< (= #KIp6AddrScopeNetwork - 1), id is network number (must be the last entry)
1.44 + EScopeType_NET = 0xF //< (= #KIp6AddrScopeNetwork - 1), id is network number (must be the last entry)
1.45 };
1.46
1.47 //
1.48 @@ -102,345 +103,6 @@
1.49 };
1.50
1.51
1.52 -// RMBufPacketPeek
1.53 -// ***************
1.54 -class RMBufPacketPeek : public RMBufChain
1.55 - /**
1.56 - Extends RMBufChain to add functions to read packet data as a descriptor
1.57 - and as an IP header.
1.58 -
1.59 - The RMBufChain is assumed to contain the raw packet, without
1.60 - the info block prepended (e.g. if this class is used for RMBufPacketBase
1.61 - derived handle, it must be in "unpacked" state).
1.62 -
1.63 - @since v7.0
1.64 - @publishedAll
1.65 - @released
1.66 - */
1.67 - {
1.68 -public:
1.69 - IMPORT_C TPtr8 Access(TInt aSize, TUint aOffset = 0);
1.70 - IMPORT_C TIpHeader *GetIpHeader();
1.71 - };
1.72 -
1.73 -// TPacketHead
1.74 -// ***********
1.75 -class TPacketHead
1.76 - /**
1.77 - Storage for some precomputed information for an outbound packet flow.
1.78 -
1.79 - The outbound TPacketHead is part of the flow context (CFlowContext).
1.80 -
1.81 - The CFlowContext::Connect initializes the content from the parameters
1.82 - of the flow (TFlowInfo) and runs the connection process.. The connection
1.83 - process (MIp6Hook::OpenL and MFlowHook::ReadyL phases) completes the
1.84 - information. After this, as long as the flow is connected, the content
1.85 - is mostly frozen and <b>must not be modified by anyone</b>.
1.86 -
1.87 - When there is a need to change any flow information, the changes must
1.88 - be done to the flow parameters (and not to TPacketHead). The change of
1.89 - flow parameters also sets the CFlowContext::iChanged flag, and this
1.90 - eventually causes a new CFlowContext::Connect, which re-initializes
1.91 - the TPacketHead with the new information.
1.92 -
1.93 - For each field in the TPacketHead, the hook writer must follow the
1.94 - basic rule (only for fields that it intends to change):
1.95 -
1.96 - - if some field is changed in MIp6Hook::OpenL, then the previous
1.97 - value should be restored in the MFlowHook::ReadyL.
1.98 - - an exeception: the hook must omit the restore, if the
1.99 - previous value was unspecified value (for example, the source
1.100 - address).
1.101 - - the content of #iPacket (and #iOffset) are special: they cannot
1.102 - be modified in the MIp6Hook::OpenL phase. A hook can
1.103 - modify them only in the MFlowHook::ReadyL phase. And, if the hook
1.104 - is adding an IP header for tunneling, it must save the current content
1.105 - of these fields in the ReadyL function, and then clear out the fields
1.106 - (it must make the iPacket empty and zero iOffset). The hook must add
1.107 - the saved iPacket content below the added tunnel header in
1.108 - MFlowHook::ApplyL .
1.109 -
1.110 - @since v7.0
1.111 - @publishedAll
1.112 - @released
1.113 - */
1.114 - {
1.115 -public:
1.116 - IMPORT_C TBool ExtHdrGet(TInt aType, TInt& aOfs, TInt& aLen);
1.117 - IMPORT_C TBool ExtHdrGetOrPrependL(TInt aType, TInt& aOfs, TInt& aLen);
1.118 - IMPORT_C TBool ExtHdrGetOrAppendL(TInt aType, TInt& aOfs, TInt& aLen);
1.119 - IMPORT_C void AddDestinationOptionL(const TPtrC8& aOption, TUint8 aAlign=0, TUint8 aModulo=4);
1.120 - IMPORT_C void AddDestinationOptionL(const TUint8* aOption, TUint8 aLen, TUint8 aAlign=0, TUint8 aModulo=4);
1.121 -
1.122 -public:
1.123 - /**
1.124 - "Virtual" IP header. The IPv6 header stucture is used, but the same
1.125 - format is <b>also</b> used for the IPv4 destinations (Version() == 4,
1.126 - even though the header format is still IPv6!)
1.127 -
1.128 - This header is initialized in the beginning of the OpenL phase
1.129 - as follows:
1.130 - @li Version = 0
1.131 - @li Traffic Class, copied from the flow iOptions.iTrafficClass
1.132 - @li Flow Label = 0
1.133 - @li Payload Length = 0 (dummy field, not used)
1.134 - @li Next Header, copied from the flow iProtocol
1.135 - @li Hop Limit, copied from the flow iOptions.iHopLimit
1.136 - @li Src Address, copied from the flow Local Address (usually unspecified)
1.137 - @li Dst Address, copied from the flow Remote Address
1.138 -
1.139 - At beginning of the ReadyL phase (= at end of OpenL), the destination
1.140 - address (and iDstId) are used to find a route on the interface. Depending
1.141 - on whether this address is IPv4 (mapped) or IPv6, the Version field is set
1.142 - accordingly to either 4 or 6.
1.143 -
1.144 - After succesfull completion of the ReadyL, this used for *each* packet
1.145 - which needs an IP header to be generated on send. The Version() determines
1.146 - whether IPv4 or IPv6 frame is to be generated (this is the initial
1.147 - header in the packet, *before* running outbound ApplyL hooks):
1.148 -
1.149 - @verbatim
1.150 - IPv6 IPv4
1.151 - Version == 6 ==4
1.152 - Traffic Class used as is used as TOS
1.153 - Flow Label used as is ignored
1.154 - Payload Length ignored ignored
1.155 - Next Header used as is used as Protocol
1.156 - Hop Limit used as is used as TTL
1.157 - Src Address used as is used as IPv4 mapped
1.158 - Dst Address used as is used as IPv4 mapped
1.159 - @endverbatim
1.160 - */
1.161 - TInet6HeaderIP ip6;
1.162 - /**
1.163 - Contains the scope id associated with the destination address
1.164 - which is stored in #ip6 Dst Address. This id and address must
1.165 - always be considered as a unit. Logically, any change changes
1.166 - both values.
1.167 -
1.168 - iDstId is initialized from the flow context TFlowInfo::iRemote.Scope() at
1.169 - beginning of the flow connect phase. If application does not define
1.170 - this scope id, then the system will attempt to choose a default value
1.171 - at beginning of the connect phase. If the default cannot be determined,
1.172 - the flow is put into pending state (and no connect happens).
1.173 -
1.174 - @par MIp6Hook::OpenL
1.175 - On entry to the OpenL, the iDstId is always non-zero and destination
1.176 - address is specified. If a hook changes the destination address in
1.177 - OpenL method, it must provide the correct id value
1.178 - which goes with the new destination. If it cannot do this, it
1.179 - must either abort the connect by leaving with an error state, or it
1.180 - can leave with PENDING (> 0) status to signal there is no route
1.181 - for the new destination.
1.182 - If the stack cannot find suitable interface for the destination, then
1.183 - it aborts the connect phase, and the flow is placed into holding state.
1.184 -
1.185 - @note
1.186 - Only a tunneling hook can safely change the destination
1.187 - address (a use of routing header can also be a kind of
1.188 - tunneling).
1.189 -
1.190 - @par MFlowHook::ReadyL
1.191 - If the hook changed the destination address (or id) in the OpenL,
1.192 - the ReadyL must restore the original values back.
1.193 -
1.194 - */
1.195 - TUint32 iDstId;
1.196 - /**
1.197 - Contains the scope id associated with the source address
1.198 - which is stored in #ip6 Src address. This is defined when the source
1.199 - address is defined, and otherwise undefined.
1.200 -
1.201 - iSrcId is initialized from TFlowInfo::iLocal.Scope() at beginning of the
1.202 - flow connect phase. If application defines the source address,
1.203 - but does not specify this scope id, then the system chooses
1.204 - the id based on the interface defined by the source address.
1.205 - If scope and address are both specified, they must match the
1.206 - selected interface.
1.207 -
1.208 - @par MIp6Hook::OpenL
1.209 - On entry to the OpenL, the iSrcId (and source address) may be
1.210 - undefined (#iSourceSet = 0). If defined (iSourceSet = 1), then
1.211 - both address and iSrcId are defined (iSrcId != 0). A hook may
1.212 - force a reselection of the source just by zeroing the
1.213 - iSourceSet.
1.214 -
1.215 - @par MFlowHook::ReadyL
1.216 - If the hook changed the source address (or id) in the OpenL,
1.217 - the ReadyL must restore the original values back, but only
1.218 - if the original value was defined (#iSourceSet = 1 in OpenL).
1.219 - */
1.220 - TUint32 iSrcId;
1.221 - /**
1.222 - The source address has been set.
1.223 -
1.224 - This bit indicates whether the value stored in #ip6 src field
1.225 - and #iSrcId is to be used as a source address as is.
1.226 -
1.227 - Initialized from TFlowInfo::iLocalSet, which tells whether user
1.228 - specified tbe source address or not (e.g used RSocket Bind method).
1.229 - The stack checks the value after each MIp6Hook::OpenL call, and
1.230 - if the flag is set, the source in ip6 is used as is. If the flag
1.231 - is zero, then the stack performs the normal source address selection
1.232 - based on the current destination address (#iSrcId and destination
1.233 - address).
1.234 -
1.235 - @par MIp6Hook::OpenL
1.236 - On entry, this flag is always set and source address is defined.
1.237 - A hook may clear this flag, if it wants the
1.238 - stack choose the source address based on current destination.
1.239 - The clearing operation is normally needed only by a tunneling
1.240 - hook.
1.241 -
1.242 - @note
1.243 - If the hook specifies the source address, it must be either
1.244 - a valid source address for the interface or unspecified
1.245 - address.
1.246 -
1.247 - @par MFlowHook::ReadyL
1.248 - Upon entry to the ReadyL, the source address is always fully
1.249 - known (the hook can assume that #iSrcId and the #ip6 source
1.250 - addresses are valid).
1.251 - If the source address was set before the OpenL, then this
1.252 - must restore the original value (along with the #iSrcId
1.253 - and source address).
1.254 - */
1.255 - TUint iSourceSet:1;
1.256 -#ifdef TPACKETHEAD_FRAGMENT
1.257 - /**
1.258 - The fragment processing alredy done.
1.259 -
1.260 - This bit is meaningful only in OpenL phase. If already set,
1.261 - then some ealier hook has requested that the packet must
1.262 - be fragmented to fit the mtu.
1.263 -
1.264 - A tunneling hook can set this bit in OpenL, if it needs
1.265 - the fragmenting to happen before the ApplyL is called (e.g.
1.266 - the fragments are tunneled instead of fragmenting the
1.267 - tunneling).
1.268 -
1.269 - This bit can only be set or left as is. It cannot be cleared
1.270 - once set.
1.271 - */
1.272 - TUint iFragment:1;
1.273 -#endif
1.274 - /**
1.275 - Selector info, the upper layer protocol.
1.276 -
1.277 - iProtocol has the same value as ip6.NextHeader() when iPacket is empty,
1.278 - and otherwise it is the same as NextHeader() of the last extension
1.279 - header in the iPacket.
1.280 -
1.281 - The values of the other selector fields: #iIcmpType, #iIcmpCode
1.282 - #iSrcPort and #iDstPort depend on iProtocol. Whenever iProtocol
1.283 - is changed, the other fields must be updated accordingly.
1.284 -
1.285 - @par MIp6Hook::OpenL
1.286 - Because iPacket cannot be modified during the OpenL phase, the
1.287 - content of this field and the Next Header (protocol) field in
1.288 - the #ip6 pseudoheader must always be the same. This field should
1.289 - be considered as <b>read-only</b>, unless the hook intends to
1.290 - apply IP-in-IP tunneling, in which case the hook <b>must</b>
1.291 - change the value to the appropriate tunneling protocol
1.292 - (#KProtocolInet6Ipip or #KProtocolInetIpip).
1.293 -
1.294 - @par MFlowHook::ReadyL
1.295 - Only a tunneling hook needs to restore the value here to match
1.296 - the original upper layer protocol. See #iPacket for
1.297 - more detailed information.
1.298 - */
1.299 - TUint8 iProtocol;
1.300 - /**
1.301 - Selector field whose value depends on #iProtocol.
1.302 -
1.303 - If this field does not have meaning with the protocol,
1.304 - the field content should be set to ZERO.
1.305 - */
1.306 - TUint8 iIcmpType;
1.307 - /**
1.308 - Selector field whose value depends on #iProtocol.
1.309 -
1.310 - If this field does not have meaning with the protocol,
1.311 - the field content should be set to ZERO.
1.312 - */
1.313 - TUint8 iIcmpCode;
1.314 - /**
1.315 - Selector field whose value depends on #iProtocol.
1.316 -
1.317 - If this field does not have meaning with the protocol,
1.318 - the field content should be set to ZERO.
1.319 - */
1.320 - TUint16 iSrcPort;
1.321 - /**
1.322 - Selector field whose value depends on #iProtocol.
1.323 -
1.324 - If this field does not have meaning with the protocol,
1.325 - the field content should be set to ZERO.
1.326 - */
1.327 - TUint16 iDstPort;
1.328 - /**
1.329 - The amount of pre-computed IPv6 extension headers in iPacket which
1.330 - are copied to the beginning of each outgoing packet
1.331 -
1.332 - If iOffset > 0, then #iPacket includes that much of extension
1.333 - headers that are copied in front of each packet.
1.334 - */
1.335 - TInt iOffset;
1.336 - /**
1.337 - Pre-computed extension headers for all packets in this flow.
1.338 -
1.339 - These can only be added in the ReadyL phase. If any of the
1.340 - ReadyL's adds extension headers into this, it must take care
1.341 - of maintaining the correct Next Header in the virtual IP header
1.342 - (and the original upper layer protocol must be placed in the
1.343 - next header of the last extension header added.
1.344 -
1.345 - Stack copies the content of this to each outgoing packet, just below
1.346 - the IP header, before running the ApplyL functions of the outbound
1.347 - flow hooks.
1.348 -
1.349 - @par MIp6Hook::OpenL
1.350 - The iPacket <b>must not</b> be modified during the OpenL phase.
1.351 -
1.352 - @par MFlowHook::ReadyL
1.353 - A non-tunneling hook may add extension headers into the current
1.354 - iPacket. A tunneling hook has more complex requirements:
1.355 - it must save the current iPacket and #iOffset and initialize
1.356 - iOffset = 0, and iPacket as empty.
1.357 -
1.358 - @par MFlowHook::ApplyL
1.359 - When a tunneling hook adds the tunneling IP header, it
1.360 - must also copy the saved iPacket below the added IP header.
1.361 - */
1.362 - RMBufPacketPeek iPacket;
1.363 - /**
1.364 - The received packet which caused an ICMP error reply to be sent.
1.365 -
1.366 - This is only used for ICMP error repply flows, and should be
1.367 - ignored by others -- mainly for IPSEC hook. The packet, if
1.368 - present, is in unpacked state.
1.369 - */
1.370 - RMBufPacketBase iIcmp;
1.371 - /**
1.372 - The current destination interface.
1.373 -
1.374 - This is ONLY used during connect/OpenL phase.
1.375 -
1.376 - The value is maintained by the stack, and is intended as
1.377 - read-only information for the hooks that have a use for
1.378 - it (for example, IPSEC implementing VPN specific policies).
1.379 -
1.380 - A hook must not modify this value (the stack will recompute
1.381 - the value after each OpenL, based on the possibly changed
1.382 - address parameters in the TPacketHead)
1.383 -
1.384 - @par MIp6Hook::OpenL
1.385 - <b>read-only</b>
1.386 - @par MFlowHook::ReadyL
1.387 - <b>read-only</b>
1.388 - */
1.389 - TUint32 iInterfaceIndex;
1.390 - };
1.391
1.392 class TInet6PacketBase
1.393 /**
1.394 @@ -450,10 +112,10 @@
1.395 public:
1.396 enum TAlign
1.397 {
1.398 - EAlign1 = 0, ///< Align to byte (no align requirement)
1.399 - EAlign2 = 1, ///< Align to 2 byte unit (even address)
1.400 - EAlign4 = 3, ///< Align to 4 byte unit
1.401 - EAlign8 = 7 ///< Align to 8 byte unit
1.402 + EAlign1 = 0, //< Align to byte (no align requirement)
1.403 + EAlign2 = 1, //< Align to 2 byte unit (even address)
1.404 + EAlign4 = 3, //< Align to 4 byte unit
1.405 + EAlign8 = 7 //< Align to 8 byte unit
1.406 };
1.407
1.408 /**
1.409 @@ -593,121 +255,4 @@
1.410 };
1.411
1.412
1.413 -// TPacketPoker
1.414 -// ************
1.415 -class TPacketPoker
1.416 - /**
1.417 - Provides a utility for linear scanning of a chain of RMBuf objects (an RMBufChain).
1.418 -
1.419 - An object of this type maintains a current point in the RMBufChain. This point
1.420 - can only move forward, and a leave occurs if the point advances beyond the
1.421 - end of the chain.
1.422 -
1.423 - Any pointers and aligns arranged before the current point, remain valid: for
1.424 - example, you can save a reference and advance the pointer, and the reference
1.425 - remains usable.
1.426 -
1.427 - If instead you need to go to a single specified offset, then use
1.428 - RMBufChain::Goto() or RMBufPacketPeek::Access().
1.429 -
1.430 - @post
1.431 - A Generic implementation assert:
1.432 - after construct, iTail == 0 iff iCurrent == 0 (all scanned), or
1.433 - in other words: as long as there are bytes after current point,
1.434 - iTail will be non-zero (and More() returns ETrue).
1.435 - All methods maintain this invariant or leave, if impossible.
1.436 -
1.437 - Some other utility methods, not directly related to scanning, are also included.
1.438 - @since v7.0
1.439 - @publishedAll
1.440 - @released
1.441 - */
1.442 - {
1.443 -public:
1.444 - IMPORT_C TPacketPoker(RMBufChain &aChain);
1.445 -
1.446 - inline void SkipL(TInt aSize)
1.447 - /**
1.448 - Moves the current point forward a specified number of bytes.
1.449 -
1.450 - @param aSize Number of bytes to move forward
1.451 - @leave KErrEof
1.452 - if the request cannot be satisfied.
1.453 - */
1.454 - { if (aSize < iTail) { iTail -= aSize; iOffset += aSize; } else OverL(aSize); }
1.455 -
1.456 - inline TUint8 *Ptr() const
1.457 - /**
1.458 - Raw pointer to the current point (can be invalid, if iTail = 0).
1.459 -
1.460 - @note Internal "unsafe" method
1.461 - */
1.462 - {return iCurrent->Ptr() + iOffset; }
1.463 -
1.464 - inline TUint8 *ReferenceL(TInt aSize = 1)
1.465 - /**
1.466 - Gets a pointer to the current point, such that
1.467 - at least the specified minimum number of bytes can be read.
1.468 -
1.469 - @param aSize
1.470 - Specified minimum number of bytes to be read through
1.471 - the returned pointer.
1.472 - @return Raw data pointer
1.473 - @leave KErrEof
1.474 - if the request cannot be satisfied.
1.475 - */
1.476 - { if (iTail >= aSize) return Ptr(); else return AdjustL(aSize); }
1.477 -
1.478 - inline TUint8 *ReferenceAndSkipL(TInt aSize)
1.479 - /**
1.480 - Gets a pointer to the current point, such that at least the
1.481 - specified minimum number of bytes can be read,
1.482 - and moves the point the specified number of bytes forward.
1.483 -
1.484 - @param aSize
1.485 - Specified minimum number of bytes to be read through the returned
1.486 - pointer, and the number of bytes to move forward
1.487 - @return
1.488 - Raw data pointer
1.489 - @leave KErrEof
1.490 - if the request cannot be satisfied.
1.491 - */
1.492 - { TUint8 *x = ReferenceL(aSize); SkipL(aSize); return x; }
1.493 -
1.494 - inline TInt Remainder() const
1.495 - /**
1.496 - Gets the length of the contiguous space after the current point.
1.497 -
1.498 - @return Length after the current point
1.499 - */
1.500 - { return iTail; }
1.501 -
1.502 - inline TBool AtBegin() const
1.503 - /**
1.504 - Tests whether the current point is at the beginning of an RMBuf.
1.505 -
1.506 - @return ETrue if current point is at the beginning
1.507 - */
1.508 - { return iOffset == 0; }
1.509 -
1.510 - inline TBool More() const
1.511 - /**
1.512 - Tests whether there is more data to scan.
1.513 -
1.514 - @return ETrue if there is more data to scan
1.515 - */
1.516 - { return iTail > 0; }
1.517 -
1.518 - IMPORT_C static TBool IsExtensionHeader(TInt aProtocolId);
1.519 -private:
1.520 - IMPORT_C void OverL(TInt aSize);
1.521 - IMPORT_C TUint8 *AdjustL(TInt aSize);
1.522 - /** The RMBuf of the current point. */
1.523 - RMBuf *iCurrent;
1.524 - /** The offset of the current point in the RMBuf. */
1.525 - TInt iOffset;
1.526 - /** Remaining bytes starting from the current point in the RMBuf. */
1.527 - TInt iTail;
1.528 - };
1.529 -
1.530 #endif