networksecurity/ipsec/ipsec6/inc/pfkeymsg.h
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     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 // pfkeymsg.h - IPv6/IPv4 IPSEC PFKEY message handling utilities
       
    15 // PF_KEY v2 message transformation between the socket stream and
       
    16 // internal representation.
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  @internalComponent
       
    23 */
       
    24 #ifndef __PFKEYMSG_H__
       
    25 #define __PFKEYMSG_H__
       
    26 
       
    27 #include <es_mbuf.h>
       
    28 #include "ipaddress.h"
       
    29 #include <networking/pfkeyv2.h>
       
    30 #include "pfkeyext.h"
       
    31 #include "sa_spec.h"
       
    32 
       
    33 // Descriptor representing a single ZERO byte (octet)
       
    34 const TLitC8<1> KZeroByte = {1, {0}};
       
    35 
       
    36 //
       
    37 // Map the basic PFKEY V2 structures into Classes with
       
    38 // constructors for initialized content.
       
    39 class T_sadb_msg : public sadb_msg
       
    40 	{
       
    41 public:
       
    42 	T_sadb_msg(TUint8 aMsgType, TUint8 aSaType = 0, TUint32 aSeq = 0);
       
    43 	};
       
    44 
       
    45 class T_sadb_sa : public sadb_sa
       
    46 	{
       
    47 public:
       
    48 	T_sadb_sa(TUint32 aSPI = 0, TUint8 aWindow = 0, TUint8 aState = SADB_SASTATE_LARVAL,
       
    49 		TUint8 aAalg = 0, TUint8 aEalg = 0, TUint32 aFlags = 0);
       
    50 	};
       
    51 
       
    52 
       
    53 //	T_sadb_lifetime
       
    54 class T_sadb_lifetime : public sadb_lifetime
       
    55 	{
       
    56 public:
       
    57 	T_sadb_lifetime(const TLifetime &aLt);
       
    58 	T_sadb_lifetime(TUint8 aType, const TLifetime &aLt, const TLifetime &aRef);
       
    59 	};
       
    60 
       
    61 
       
    62 class T_sadb_address : public sadb_address
       
    63 	{
       
    64 public:
       
    65 	T_sadb_address(TUint8 aType, TUint8 aProto = 0, TUint8 aPrefix = 0);
       
    66 	};
       
    67 
       
    68 class T_sadb_key : public sadb_key
       
    69 	{
       
    70 public:
       
    71 	T_sadb_key(TUint8 aType, TInt aKeyBytes = 0, TInt aKeyBits = -1);
       
    72 	};
       
    73 
       
    74 class T_sadb_supported : public sadb_supported
       
    75 	{
       
    76 public:
       
    77 	T_sadb_supported(TUint8 aType, TInt aNum = 0);
       
    78 	};
       
    79 
       
    80 class T_sadb_ident : public sadb_ident
       
    81 	{
       
    82 public:
       
    83 	T_sadb_ident(TUint8 aType, TInt aLength = 0);
       
    84 	};
       
    85 
       
    86 class T_sadb_sens : public sadb_sens
       
    87 	{
       
    88 public:
       
    89 	// A dummy
       
    90 	T_sadb_sens();
       
    91 	};
       
    92 
       
    93 class T_sadb_prop : public sadb_prop
       
    94 	{
       
    95 public:
       
    96 	T_sadb_prop(TUint8 aReplay, TInt aNum);
       
    97 	};
       
    98 
       
    99 class T_sadb_selector : public sadb_x_selector
       
   100 	{
       
   101 public:
       
   102 	TInetAddr iSrc;
       
   103 	TInetAddr iDst;
       
   104 	};
       
   105 
       
   106 class T_sadb_ts : public sadb_x_ts
       
   107 	{
       
   108 public:
       
   109 	T_sadb_ts(TInt aNum);
       
   110 	};
       
   111 
       
   112 //
       
   113 // Remapping of the bytestream PF_KEY into structures
       
   114 //
       
   115 
       
   116 class TPfkeyBase
       
   117 	{
       
   118 public:
       
   119 	const struct sadb_msg *iMsg;
       
   120 	TPfkeyBase() {iMsg = 0;}
       
   121 	TUint Length() const {return iMsg ? sizeof(*iMsg) : 0;}
       
   122 	TInt ByteStream(RMBufChain &aPacket, TInt aTotal) const;
       
   123 	void LogPrint(const TDesC &aLabel) const;		// Only available in DEBUG mode
       
   124 	};
       
   125 
       
   126 class TPfkeyAssociation
       
   127 	{
       
   128 public:
       
   129 	const struct sadb_sa *iExt;
       
   130 	TPfkeyAssociation() {iExt = 0;}
       
   131 	TUint Length() const {return iExt ? sizeof(*iExt) : 0;}
       
   132 	TInt ByteStream(RMBufChain &aPacket, TInt aOffset) const;
       
   133 	void LogPrint(const TDesC &aLabel, const CAlgorithmList *aAlgorithms) const;		// Only available in DEBUG mode
       
   134 	};
       
   135 
       
   136 class TPfkeyLifetime
       
   137 	{
       
   138 public:
       
   139 	const struct sadb_lifetime *iExt;
       
   140 	TPfkeyLifetime() {iExt = 0;}
       
   141 	TUint Length() const {return iExt ? sizeof(*iExt) : 0;}
       
   142 	TInt ByteStream(RMBufChain &aPacket, TInt aOffset) const;
       
   143 	void LogPrint(const TDesC &aLabel) const;		// Only available in DEBUG mode
       
   144 	};
       
   145 
       
   146 class TPfkeyIdentity
       
   147 	{
       
   148 public:
       
   149 	const struct sadb_ident *iExt;
       
   150 	TPtrC8 iData;
       
   151 	TPfkeyIdentity() {iExt = 0;}
       
   152 	TUint Length() const
       
   153 		{return iExt ? ((sizeof(*iExt) + iData.Length() + 1 + 7) / 8) * 8 : 0; }
       
   154 	TInt LoadFromStream(const TInt aLength, const TUint8 *aPtr);
       
   155 	TInt ByteStream(RMBufChain &aPacket, TInt aOffset) const;
       
   156 	void LogPrint(const TDesC8 &aLabel) const;		// Only available in DEBUG mode
       
   157 	};
       
   158 
       
   159 class TPfkeyAddress
       
   160 	{
       
   161 public:
       
   162 	const struct sadb_address *iExt;
       
   163 	RIpAddress iAddr;
       
   164 	TUint16 iPort;
       
   165 	TPfkeyAddress() {iExt = 0; }
       
   166 	TUint Length() const
       
   167 		{return iExt ? ((sizeof(*iExt) + sizeof(TInetAddr) + 7) / 8) * 8 : 0; }
       
   168 	TInt ByteStream(RMBufChain &aPacket, TInt aOffset) const;
       
   169 	TInt LoadFromStream(const TInt aLength, const TUint8 *aPtr, REndPoints &aEp);
       
   170 	TInt BindToEndPoint(TPfkeyIdentity &aIdentity, REndPoints &aEp);
       
   171 	void LogPrint(const TDesC &aLabel) const;		// Only available in DEBUG mode
       
   172 	};
       
   173 
       
   174 class TPfkeyKey
       
   175 	{
       
   176 public:
       
   177 	const struct sadb_key *iExt;
       
   178 	TPtrC8 iData;
       
   179 	TPfkeyKey() {iExt = 0;}
       
   180 	TUint Length() const
       
   181 		{return iExt ? ((sizeof(*iExt) + iData.Length() + 7) / 8) * 8 : 0; }
       
   182 	TInt ByteStream(RMBufChain &aPacket, TInt aOffset) const;
       
   183 	void LogPrint(const TDesC &aLabel) const;		// Only available in DEBUG mode
       
   184 	};
       
   185 
       
   186 
       
   187 class TPfkeySensitivity
       
   188 	{
       
   189 public:
       
   190 	const struct sadb_sens *iExt;
       
   191 	TPtrC8 iSensBitmap;
       
   192 	TPtrC8 iIntegBitmap;
       
   193 	TPfkeySensitivity() {iExt = 0;}
       
   194 	TUint Length() const
       
   195 		{return iExt ? ((sizeof(*iExt) + iSensBitmap.Length() + iIntegBitmap.Length() + 7) / 8) * 8 : 0; }
       
   196 	TInt ByteStream(RMBufChain &aPacket, TInt aOffset) const;
       
   197 	void LogPrint(const TDesC &aLabel) const;		// Only available in DEBUG mode
       
   198 	};
       
   199 
       
   200 class TPfkeyProposal
       
   201 	{
       
   202 public:
       
   203 	const struct sadb_prop *iExt;
       
   204 	const struct sadb_comb *iComb;
       
   205 	TInt iNumComb;
       
   206 	TPfkeyProposal() {iExt = 0; iComb = 0; iNumComb = 0;}
       
   207 	TUint Length() const
       
   208 		{return iExt ? ((sizeof(*iExt) + iNumComb * sizeof(*iComb) + 7) / 8) * 8 : 0;}
       
   209 	TInt ByteStream(RMBufChain &aPacket, TInt aOffset) const;
       
   210 	void LogPrint(const TDesC &aLabel, const CAlgorithmList *aAlgorithms) const;		// Only available in DEBUG mode
       
   211 	};
       
   212 
       
   213 class TPfkeySupported
       
   214 	{
       
   215 public:
       
   216 	const struct sadb_supported *iExt;
       
   217 	const struct sadb_alg *iAlg;
       
   218 	TInt iNumAlg;
       
   219 	TPfkeySupported() {iExt = 0; iAlg = 0; iNumAlg = 0;}
       
   220 	TUint Length() const
       
   221 		{return iExt ? ((sizeof(*iExt) + iNumAlg * sizeof(*iAlg) + 7) / 8) * 8 : 0;}
       
   222 	TInt ByteStream(RMBufChain &aPacket, TInt aOffset) const;
       
   223 	void Init(struct sadb_supported *aExt, TInt aNumAlg, struct sadb_alg *aAlg);
       
   224 	void LogPrint(const TDesC &aLabel, const CAlgorithmList *aAlgorithms) const;		// Only available in DEBUG mode
       
   225 	};
       
   226 
       
   227 class TPfkeySpirange
       
   228 	{
       
   229 public:
       
   230 	const struct sadb_spirange *iExt;
       
   231 	TPfkeySpirange() {iExt = 0;}
       
   232 	TUint Length() const
       
   233 		{return iExt  ? sizeof(*iExt) : 0;}
       
   234 	TInt ByteStream(RMBufChain &aPacket, TInt aOffset) const;
       
   235 	void LogPrint(const TDesC &aLabel) const;		// Only available in DEBUG mode
       
   236 	};
       
   237 
       
   238 class RTrafficSelectorSet;
       
   239 class TPfkeyTs
       
   240 	{
       
   241 public:
       
   242 	const struct sadb_x_ts *iExt;
       
   243 	TPfkeyTs() {iExt = 0; iTS = NULL;}
       
   244 	const RTrafficSelectorSet *iTS;
       
   245 	TUint Length() const
       
   246 		{
       
   247 		return (iExt && iTS) ? ((sizeof(*iExt) + iExt->sadb_x_ts_numsel * sizeof(T_sadb_selector) + 7) / 8) * 8 : 0;
       
   248 		}
       
   249 	const T_sadb_selector &Selector(TInt aIndex) const
       
   250 		{
       
   251 		return ((T_sadb_selector *)((TUint8 *)iExt + sizeof(*iExt)))[aIndex];
       
   252 		}
       
   253 	TInt ByteStream(RMBufChain &aPacket, TInt aOffset) const;
       
   254 	void LogPrint(const TDesC &aLabel) const;		// Only available in DEBUG mode
       
   255 	};
       
   256 
       
   257 class TPFkeyPrivExt
       
   258 	{
       
   259 public:
       
   260 	const struct sadb_gen_ext *iExt;
       
   261 	TPtrC8 iData;
       
   262 	TPFkeyPrivExt() {iExt = 0;}
       
   263 	};
       
   264 
       
   265 //
       
   266 // Internal presentation of the PF_KEY message
       
   267 //
       
   268 class TPfkeyMessage
       
   269 	{
       
   270 public:
       
   271 	// Length64()
       
   272 	//	Returns the length of the stream representation
       
   273 	//	of this message in 8 byte blocks (e.g. multiply
       
   274 	//  this by 8 to get the length in octets.
       
   275 	TUint16 Length64() const;
       
   276 
       
   277 	// ByteStream(aPacket)
       
   278 	//	Append a byte stream presentation of this message into
       
   279 	//	a RMBufChain (aPacket)
       
   280 	void ByteStreamL(RMBufChain &aPacket) const;
       
   281 	//
       
   282 	//
       
   283 	// Construct internal presentation from the PFKEY bytestream message
       
   284 	TPfkeyMessage(const TDesC8& aMsg, REndPoints &aEp);
       
   285 	TPfkeyMessage() {}
       
   286 	void LogPrint(const TDesC &aLabel, const CAlgorithmList *aAlgorithms) const;		// Only available in DEBUG mode
       
   287 
       
   288 	TInt iError;	// == KErrNone, if message format valid.
       
   289 	TPfkeyBase iBase;
       
   290 	TPfkeyAssociation iSa;
       
   291 	TPfkeyLifetime iCurrent;
       
   292 	TPfkeyLifetime iHard;
       
   293 	TPfkeyLifetime iSoft;
       
   294 	TPfkeyAddress iSrcAddr;
       
   295 	TPfkeyAddress iDstAddr;
       
   296 	TPfkeyAddress iProxyAddr;
       
   297 	TPfkeyKey iAuthKey;
       
   298 	TPfkeyKey iEncryptKey;
       
   299 	TPfkeyIdentity iSrcIdent;
       
   300 	TPfkeyIdentity iDstIdent;
       
   301 	TPfkeyIdentity iSrcEndpoint;
       
   302 	TPfkeyIdentity iDstEndpoint;
       
   303 	TPfkeySensitivity iSensitivity;
       
   304 	TPfkeyProposal iProposal;
       
   305 	TPfkeySupported iAuthAlgs;
       
   306 	TPfkeySupported iEncryptAlgs;
       
   307 	TPfkeySpirange iSpirange;
       
   308 	TPfkeyTs iTs;
       
   309 
       
   310 	TPFkeyPrivExt  iPrivateExtension;  // For ESP UDP encapsulation     
       
   311 	};
       
   312 #endif