vpnengine/ikeutils/src/pfkeymsg.cpp
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     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: Key management daemon PFKEY message module.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <es_sock.h>
       
    19 #include <in_sock.h>
       
    20 #include <eikenv.h>
       
    21 
       
    22 #include "pfkeymsg.h"
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 #ifdef _DEBUG
       
    27 //
       
    28 //  Convert to String methods
       
    29 //
       
    30 //  TPfkeyBase::String
       
    31 //      Convert Base Message Header to printable string
       
    32 //
       
    33 
       
    34 void TPfkeyBase::String(TDes &aStr, const TDesC &aLabel) const
       
    35     {
       
    36 
       
    37     if (!iMsg)
       
    38         return;
       
    39 
       
    40     aStr.Append(aLabel);
       
    41     aStr.AppendFormat(_L("#%d.%d "),
       
    42             (int)iMsg->sadb_msg_seq,
       
    43             (int)iMsg->sadb_msg_pid);
       
    44     switch (iMsg->sadb_msg_type)
       
    45         {
       
    46     case SADB_GETSPI:
       
    47         aStr.Append(_L("GETSPI"));
       
    48         break;
       
    49     case SADB_UPDATE:
       
    50         aStr.Append(_L("UPDATE"));
       
    51         break;
       
    52     case SADB_ADD:
       
    53         aStr.Append(_L("ADD"));
       
    54         break;
       
    55     case SADB_DELETE:
       
    56         aStr.Append(_L("DELETE"));
       
    57         break;
       
    58     case SADB_GET:
       
    59         aStr.Append(_L("GET"));
       
    60         break;
       
    61     case SADB_ACQUIRE:
       
    62         aStr.Append(_L("ACQUIRE"));
       
    63         break;
       
    64     case SADB_REGISTER:
       
    65         aStr.Append(_L("REGISTER"));
       
    66         break;
       
    67     case SADB_EXPIRE:
       
    68         aStr.Append(_L("EXPIRE"));
       
    69         break;
       
    70     case SADB_FLUSH:
       
    71         aStr.Append(_L("FLUSH"));
       
    72         break;
       
    73     case SADB_DUMP:
       
    74         aStr.Append(_L("DUMP"));
       
    75         break;
       
    76     default:
       
    77         aStr.AppendFormat(_L("UNKNOWN(%d)"),
       
    78             iMsg->sadb_msg_type);
       
    79         break;
       
    80         }
       
    81     if (iMsg->sadb_msg_version != PF_KEY_V2)
       
    82         aStr.AppendFormat(_L("(V%d)"), (int)iMsg->sadb_msg_version);
       
    83 
       
    84     if (iMsg->sadb_msg_errno) 
       
    85         {
       
    86         aStr.AppendFormat(_L("(Errno%d)"), (int)iMsg->sadb_msg_errno);      
       
    87         }
       
    88     else
       
    89         aStr.Append(_L("[ok] "));
       
    90     switch (iMsg->sadb_msg_satype)
       
    91         {
       
    92     case SADB_SATYPE_AH:
       
    93         aStr.Append(_L("AH"));
       
    94         break;
       
    95     case SADB_SATYPE_ESP:
       
    96         aStr.Append(_L("ESP"));
       
    97         break;
       
    98     case SADB_SATYPE_UNSPEC:
       
    99         aStr.Append('*');
       
   100         break;
       
   101     default:
       
   102         aStr.AppendFormat(_L("UNKNOWN=%d"), (int)iMsg->sadb_msg_satype);
       
   103         break;
       
   104         }
       
   105     }
       
   106 
       
   107 void TPfkeyAssociation::String(TDes &aStr, const TDesC &aLabel) const
       
   108     {
       
   109     if (!iExt)
       
   110         return;
       
   111     aStr.Append(aLabel);
       
   112     if (iExt->sadb_sa_encrypt || iExt->sadb_sa_auth)
       
   113         {
       
   114         aStr.Append('(');
       
   115         if (iExt->sadb_sa_encrypt)
       
   116             TPfkeySupportedEncrypt::Alg2String(aStr, iExt->sadb_sa_encrypt);
       
   117         aStr.Append(',');
       
   118         if (iExt->sadb_sa_auth)
       
   119             TPfkeySupportedAuth::Alg2String(aStr, iExt->sadb_sa_auth);
       
   120         aStr.Append(')');
       
   121         }
       
   122 
       
   123     switch (iExt->sadb_sa_state)
       
   124         {
       
   125     case SADB_SASTATE_LARVAL:
       
   126         aStr.Append(_L(" LARVAL"));
       
   127         break;
       
   128     case SADB_SASTATE_MATURE:
       
   129         aStr.Append(_L(" MATURE"));
       
   130         break;
       
   131     case SADB_SASTATE_DYING:
       
   132         aStr.Append(_L(" DYING"));
       
   133         break;
       
   134     case SADB_SASTATE_DEAD:
       
   135         aStr.Append(_L(" DEAD"));
       
   136         break;
       
   137     default:
       
   138         aStr.AppendFormat(_L(" UNKNOWN=%d"), (int)iExt->sadb_sa_state);
       
   139         break;
       
   140         }
       
   141     aStr.AppendFormat(_L(" SPI=%x"), (int)ByteOrder::Swap32(iExt->sadb_sa_spi));
       
   142     if (iExt->sadb_sa_replay)
       
   143         aStr.AppendFormat(_L(" Replay=%d"), (int)iExt->sadb_sa_replay);
       
   144     }
       
   145 
       
   146 void TPfkeyAddress::String(TDes &aStr, const TDesC &aLabel) const
       
   147     {
       
   148     if (!iExt)
       
   149         return;
       
   150     aStr.Append(aLabel);
       
   151     if (iAddr)
       
   152         {
       
   153         TBuf<39> addr;
       
   154         iAddr->OutputWithScope(addr);
       
   155         aStr.Append(addr);
       
   156         if (iExt->sadb_address_proto)
       
   157             aStr.AppendFormat(_L(" proto=%d"), iExt->sadb_address_proto);
       
   158         if (iAddr->Port())
       
   159             aStr.AppendFormat(_L(" port=%d"), iAddr->Port());
       
   160         }
       
   161     }
       
   162 
       
   163 void TPfkeyKey::String(TDes &aStr, const TDesC &aLabel) const
       
   164     {
       
   165     if (iExt)
       
   166         aStr.Append(aLabel);
       
   167     }
       
   168 
       
   169 void TPfkeyLifetime::String(TDes &aStr, const TDesC &aLabel) const
       
   170     {
       
   171     if (!iExt)
       
   172         return;
       
   173     aStr.Append(aLabel);
       
   174     aStr.Append((TChar)'(');
       
   175     aStr.AppendNum(iExt->sadb_lifetime_allocations);
       
   176     aStr.Append((TChar)',');
       
   177     aStr.AppendNum(iExt->sadb_lifetime_bytes);
       
   178     aStr.Append((TChar)',');
       
   179     aStr.AppendNum(iExt->sadb_lifetime_addtime);
       
   180     aStr.Append((TChar)',');
       
   181     aStr.AppendNum(iExt->sadb_lifetime_usetime);
       
   182     aStr.Append((TChar)')');
       
   183     }
       
   184 
       
   185 void TPfkeySupported::String(TDes &aStr, const TDesC &aLabel) const
       
   186     {
       
   187     if (!iExt)
       
   188         return;
       
   189     aStr.Append(aLabel);
       
   190     for (int i = 0; i < iNumAlg; ++i)
       
   191         {
       
   192         AlgString(aStr, iAlg[i].sadb_alg_id);
       
   193         if (iAlg[i].sadb_alg_minbits == iAlg[i].sadb_alg_maxbits)
       
   194             aStr.AppendFormat
       
   195                 (_L("(IV=%d,key=%d)"),
       
   196                 (int)iAlg[i].sadb_alg_ivlen,
       
   197                 (int)iAlg[i].sadb_alg_maxbits);
       
   198         else
       
   199             aStr.AppendFormat
       
   200                 (_L("(IV=%d,%d<=key<=%d)"),
       
   201                 (int)iAlg[i].sadb_alg_ivlen,
       
   202                 (int)iAlg[i].sadb_alg_minbits,
       
   203                 (int)iAlg[i].sadb_alg_maxbits);
       
   204         }
       
   205     }
       
   206 
       
   207 void TPfkeyIdentity::String(TDes &aStr, const TDesC &aLabel) const
       
   208 {
       
   209 
       
   210 #ifdef _UNICODE
       
   211     if (iExt)
       
   212     {
       
   213         aStr.Append(aLabel);
       
   214         if (iData.Length() == 0)
       
   215             return;
       
   216         HBufC *unibuf = HBufC::New(iData.Length());
       
   217         if (!unibuf)
       
   218             return;
       
   219         unibuf->Des().Copy(iData);
       
   220         aStr.Append(unibuf->Des());
       
   221         delete unibuf;
       
   222     }
       
   223 #else
       
   224     if (iExt)
       
   225     {
       
   226         aStr.Append(aLabel);
       
   227         aStr.Append(iData);
       
   228     }
       
   229 #endif
       
   230 }
       
   231 
       
   232 void TPfkeySensitivity::String(TDes &aStr, const TDesC &aLabel) const
       
   233     {
       
   234     if (iExt)
       
   235         {
       
   236         aStr.Append(aLabel);
       
   237         }
       
   238     }
       
   239 
       
   240 void TPfkeyProposal::String(TDes &aStr, const TDesC &aLabel) const
       
   241     {
       
   242     if (!iExt)
       
   243         return;
       
   244     aStr.Append(aLabel);
       
   245     if (iExt->sadb_prop_replay)
       
   246         aStr.AppendFormat(_L("replay=%d"), (int)iExt->sadb_prop_replay);
       
   247     for (int i = 0; i < iNumComb; i++)
       
   248         {
       
   249         aStr.AppendFormat(_L(" %d:("), i+1);
       
   250         if (iComb[i].sadb_comb_flags & SADB_SAFLAGS_PFS)
       
   251             aStr.Append(_L("PFS "));
       
   252         if (iComb[i].sadb_comb_encrypt)
       
   253             {
       
   254             TPfkeySupportedEncrypt::Alg2String(aStr, iComb[i].sadb_comb_encrypt);
       
   255             aStr.AppendFormat(_L("[%d..%d]"),
       
   256                 iComb[i].sadb_comb_encrypt_minbits,
       
   257                 iComb[i].sadb_comb_encrypt_maxbits);
       
   258             }
       
   259         if (iComb[i].sadb_comb_auth)
       
   260             {
       
   261             aStr.Append(',');
       
   262             TPfkeySupportedAuth::Alg2String(aStr, iComb[i].sadb_comb_auth);
       
   263             aStr.AppendFormat(_L("[%d..%d]"),
       
   264                 iComb[i].sadb_comb_auth_minbits,
       
   265                 iComb[i].sadb_comb_auth_maxbits);
       
   266             }
       
   267         if (iComb[i].sadb_comb_soft_allocations ||
       
   268             iComb[i].sadb_comb_soft_bytes != 0 ||
       
   269             iComb[i].sadb_comb_soft_addtime != 0||
       
   270             iComb[i].sadb_comb_soft_usetime != 0)
       
   271             {
       
   272             aStr.AppendFormat(_L(" soft=(%d,"), (int)iComb[i].sadb_comb_soft_allocations);
       
   273             aStr.AppendNum(iComb[i].sadb_comb_soft_bytes);
       
   274             aStr.Append(',');
       
   275             aStr.AppendNum(iComb[i].sadb_comb_soft_addtime);
       
   276             aStr.Append(',');
       
   277             aStr.AppendNum(iComb[i].sadb_comb_soft_usetime);
       
   278             aStr.Append(')');
       
   279             }
       
   280         if (iComb[i].sadb_comb_hard_allocations ||
       
   281             iComb[i].sadb_comb_hard_bytes != 0 ||
       
   282             iComb[i].sadb_comb_hard_addtime != 0 ||
       
   283             iComb[i].sadb_comb_hard_usetime != 0)
       
   284             {
       
   285             aStr.AppendFormat(_L(" hard=(%d,"), (int)iComb[i].sadb_comb_hard_allocations);
       
   286             aStr.AppendNum(iComb[i].sadb_comb_hard_bytes);
       
   287             aStr.Append(',');
       
   288             aStr.AppendNum(iComb[i].sadb_comb_hard_addtime);
       
   289             aStr.Append(',');
       
   290             aStr.AppendNum(iComb[i].sadb_comb_hard_usetime);
       
   291             aStr.Append(')');
       
   292             }
       
   293         aStr.Append(')');
       
   294         }
       
   295     }
       
   296 
       
   297 void TPfkeySpirange::String(TDes &aStr,const TDesC &aLabel) const
       
   298     {
       
   299     if (iExt)
       
   300         {
       
   301         aStr.Append(aLabel);
       
   302         }
       
   303     }
       
   304 
       
   305 void TPfkeyTs::String(TDes &aStr,const TDesC &aLabel) const
       
   306     {       
       
   307     if (iExt)
       
   308         {            
       
   309         for (TInt i = 0; i < SelectorCount(); ++i)
       
   310             {                              
       
   311             const TPfKeySelector& selector = Selector(i);
       
   312             
       
   313             TBuf<50> src;
       
   314             TBuf<50> dst;
       
   315             
       
   316             selector.iSrc.OutputWithScope(src);
       
   317             selector.iDst.OutputWithScope(dst);
       
   318                     
       
   319             aStr.AppendFormat(_L("%S[%d] proto=%d src=%S:%d, dst=%S:%d" ), 
       
   320                               &aLabel, i, selector.sadb_x_selector_proto,
       
   321                               &src, selector.iSrc.Port(),
       
   322                               &dst, selector.iDst.Port());
       
   323                             
       
   324                                                                                                           
       
   325             }
       
   326         }
       
   327     }
       
   328 
       
   329 void TPFkeyPrivExt::String(TDes &aStr, const TDesC &aLabel) const
       
   330     {
       
   331     if (iExt)
       
   332         aStr.Append(aLabel);
       
   333     }
       
   334 
       
   335 #endif   //#ifdef _DEBUG 
       
   336 
       
   337 
       
   338 TPfkeyBase::TPfkeyBase()
       
   339  : iMsg( 0 )
       
   340     {    
       
   341     }
       
   342 
       
   343 TPfkeyAssociation::TPfkeyAssociation() 
       
   344  : iExt( 0 )
       
   345      {     
       
   346      }
       
   347 
       
   348 TPfkeyLifetime::TPfkeyLifetime()
       
   349  : iExt( 0 )
       
   350      {     
       
   351      }
       
   352 
       
   353 TPfkeyAddress::TPfkeyAddress()
       
   354  : iExt(0), iAddr(0)
       
   355      {     
       
   356      }
       
   357 
       
   358 EXPORT_C const TInetAddr& TPfkeyAddress::Address() const
       
   359     {
       
   360     return *iAddr;
       
   361     }
       
   362 
       
   363 TPfkeyKey::TPfkeyKey()
       
   364  : iExt( 0 )
       
   365      {     
       
   366      }
       
   367 
       
   368 TPfkeyIdentity::TPfkeyIdentity()
       
   369  : iExt( 0 )
       
   370      {     
       
   371      }
       
   372 
       
   373 TPfkeySensitivity::TPfkeySensitivity()
       
   374  : iExt(0)
       
   375      {     
       
   376      }
       
   377 
       
   378 TPfkeyProposal::TPfkeyProposal()
       
   379  : iExt( 0 ),
       
   380    iComb( 0 ),
       
   381    iNumComb( 0 )
       
   382     {    
       
   383     }
       
   384 
       
   385 TPfkeySupported::TPfkeySupported()
       
   386  : iExt( 0 ),
       
   387    iAlg( 0 ),
       
   388    iNumAlg( 0 )
       
   389        {       
       
   390        }
       
   391 
       
   392 void TPfkeySupportedAuth::AlgString( TDes &aStr,
       
   393                                      TUint8 aAlg ) const
       
   394        {
       
   395        Alg2String( aStr, aAlg ); 
       
   396        }
       
   397 
       
   398 void TPfkeySupportedAuth::Alg2String(TDes &aStr, TUint8 aAlg)
       
   399     {
       
   400     switch (aAlg)
       
   401         {
       
   402     case SADB_AALG_MD5HMAC:
       
   403         aStr.Append(_L("md5hmac"));
       
   404         break;
       
   405     case SADB_AALG_SHA1HMAC:
       
   406         aStr.Append(_L("sha1hmac"));
       
   407         break;
       
   408     default:
       
   409         aStr.AppendFormat(_L("%d"), (int)aAlg);
       
   410         }
       
   411     }
       
   412 
       
   413 void TPfkeySupportedEncrypt::AlgString( TDes &aStr,
       
   414                                         TUint8 aAlg ) const
       
   415        {
       
   416        Alg2String( aStr, aAlg );
       
   417        }
       
   418 
       
   419 void TPfkeySupportedEncrypt::Alg2String(TDes &aStr, TUint8 aAlg)
       
   420     {
       
   421     switch (aAlg)
       
   422         {
       
   423     case SADB_EALG_DESCBC:
       
   424         aStr.Append(_L("descbc"));
       
   425         break;
       
   426     case SADB_EALG_3DESCBC:
       
   427         aStr.Append(_L("3descbc"));
       
   428         break;
       
   429     case SADB_EALG_NULL:
       
   430         aStr.Append(_L("null"));
       
   431         break;
       
   432     case 4:
       
   433         aStr.Append(_L("rc5"));
       
   434         break;
       
   435     case 5:
       
   436         aStr.Append(_L("idea"));
       
   437         break;
       
   438     case 6:
       
   439         aStr.Append(_L("cast"));
       
   440         break;
       
   441     case 7:
       
   442         aStr.Append(_L("blowfish"));
       
   443         break;
       
   444     case 8:
       
   445         aStr.Append(_L("3idea"));
       
   446         break;
       
   447     case 9:
       
   448         aStr.Append(_L("desiv32"));
       
   449         break;
       
   450     case 10:
       
   451         aStr.Append(_L("rc4"));
       
   452         break;
       
   453     case 12:
       
   454         aStr.Append(_L("aes"));
       
   455         break;
       
   456         
       
   457     default:
       
   458         aStr.AppendFormat(_L("%d"), (int)aAlg);
       
   459         }
       
   460     }
       
   461 
       
   462 TPfkeySpirange::TPfkeySpirange()
       
   463  : iExt( 0 )
       
   464      {     
       
   465      }
       
   466 
       
   467 TPfkeyTs::TPfkeyTs()
       
   468  : iExt(0)
       
   469      {     
       
   470      }
       
   471 
       
   472 EXPORT_C TInt TPfkeyTs::SelectorCount() const
       
   473     {
       
   474     return (iExt != NULL) ? iExt->sadb_x_ts_numsel : 0;
       
   475     }
       
   476 
       
   477 EXPORT_C const TPfKeySelector& TPfkeyTs::Selector(TInt aIndex) const
       
   478     {        
       
   479     __ASSERT_DEBUG(iExt != NULL, User::Invariant());
       
   480     __ASSERT_DEBUG(iExt->sadb_x_ts_numsel > aIndex, User::Invariant());
       
   481     
       
   482     TPfKeySelector *selector = (TPfKeySelector*)((TUint8*)iExt + sizeof(struct sadb_x_ts));
       
   483     return selector[aIndex];
       
   484     }
       
   485 
       
   486 TPFkeyPrivExt::TPFkeyPrivExt()
       
   487  : iExt( 0 )
       
   488      {     
       
   489      }
       
   490 
       
   491 //
       
   492 //  TPfkeyMessage
       
   493 //
       
   494 TPfkeyMessage::TPfkeyMessage()
       
   495  : iError( KErrNone )
       
   496      {     
       
   497      }
       
   498 
       
   499 //
       
   500 //  Construct TPfkeyMesage from a PF_KEY v2 byte stream (aMsg)
       
   501 //
       
   502 TPfkeyMessage::TPfkeyMessage(TPfkeyRecvMsg& aMsg)
       
   503     {
       
   504 	const TUint8 *p = aMsg.Ptr();
       
   505 	TInt length = aMsg.Length();
       
   506 
       
   507 	iError = KErrArgument;
       
   508 	if (length < (TInt)sizeof(sadb_msg))
       
   509 		return;		// EMSGSIZE (impossible message size)
       
   510 
       
   511 	// Base Message Header
       
   512 	iBase.iMsg = (struct sadb_msg *)p;
       
   513 	if (iBase.iMsg->sadb_msg_version != PF_KEY_V2)
       
   514 		return;		// EINVAL
       
   515 	// SADB_ACQUIRE response can have sadb_msg_errno set to non-zero value  
       
   516 	 if (iBase.iMsg->sadb_msg_errno && (iBase.iMsg->sadb_msg_type != SADB_ACQUIRE))
       
   517 	 	return;                   // EINVAL (should be set zero by sender) 		
       
   518 	if (iBase.iMsg->sadb_msg_len * 8 != length)
       
   519 		return;		// EMSGSIZE (incorrect message length)
       
   520 	// SADB_ACQUIRE response can have sadb_msg_reserved set to non-zero value            
       
   521 	if (iBase.iMsg->sadb_msg_reserved && (iBase.iMsg->sadb_msg_type != SADB_ACQUIRE))		
       
   522 		return;		// EINVAL (unused parts must be zeroed)
       
   523 	p += sizeof(struct sadb_msg);
       
   524 	length -= sizeof(struct sadb_msg);
       
   525 
       
   526 	// Extension headers
       
   527 	// Some general rules:
       
   528 	// - only one instance of an extension type is valid
       
   529 	while (length > 0)
       
   530 		{
       
   531 		struct sadb_ext *ext = (struct sadb_ext *)p;
       
   532 		int ext_len = ext->sadb_ext_len;
       
   533 		int data_len, data_len2;
       
   534 
       
   535 		if (ext_len < 1)
       
   536 			return;		// EINVAL (bad message format)
       
   537 		ext_len *= 8;
       
   538 		if (ext_len > length)
       
   539 			return;		// EINVAL
       
   540 		switch (ext->sadb_ext_type)
       
   541         {
       
   542             case SADB_EXT_RESERVED:
       
   543                 return;     // EINVAL (bad mesage format)
       
   544 
       
   545             case SADB_EXT_SA:
       
   546                 if (iSa.iExt)
       
   547                     return; // EINVAL
       
   548                 iSa.iExt = (struct sadb_sa *)p;
       
   549                 break;
       
   550 
       
   551             case SADB_EXT_LIFETIME_CURRENT:
       
   552                 if (iCurrent.iExt)
       
   553                     return; // EINVAL;
       
   554                 iCurrent.iExt = (struct sadb_lifetime *)p;
       
   555                 break;
       
   556 
       
   557             case SADB_EXT_LIFETIME_HARD:
       
   558                 if (iHard.iExt)
       
   559                     return;
       
   560                 iHard.iExt = (struct sadb_lifetime *)p;
       
   561                 break;
       
   562 
       
   563             case SADB_EXT_LIFETIME_SOFT:
       
   564                 if (iSoft.iExt)
       
   565                     return;
       
   566                 iSoft.iExt = (struct sadb_lifetime *)p;
       
   567                 break;
       
   568 
       
   569             case SADB_EXT_ADDRESS_SRC:
       
   570                 if (iSrcAddr.iExt)
       
   571                     return;
       
   572                 if (ext_len != sizeof(struct sadb_address) + sizeof(TInetAddr))
       
   573                     return;
       
   574                 iSrcAddr.iExt = (struct sadb_address *)p;
       
   575                 iSrcAddr.iAddr = (TInetAddr *)(p + sizeof(struct sadb_address));
       
   576                 break;
       
   577 
       
   578             case SADB_EXT_ADDRESS_DST:
       
   579                 if (iDstAddr.iExt)
       
   580                     return;
       
   581                 if (ext_len != sizeof(struct sadb_address) + sizeof(TInetAddr))
       
   582                     return;
       
   583                 iDstAddr.iExt = (struct sadb_address *)p;
       
   584                 iDstAddr.iAddr = (TInetAddr *)(p + sizeof(struct sadb_address));
       
   585                 break;
       
   586 
       
   587             case SADB_EXT_ADDRESS_PROXY:
       
   588                 if (iProxyAddr.iExt)
       
   589                     return;
       
   590                 if (ext_len != sizeof(struct sadb_address) + sizeof(TInetAddr))
       
   591                     return;
       
   592                 iProxyAddr.iExt = (struct sadb_address *)p;
       
   593                 iProxyAddr.iAddr = (TInetAddr *)(p + sizeof(struct sadb_address));
       
   594                 break;
       
   595 
       
   596             case SADB_EXT_KEY_AUTH:
       
   597                 if (iAuthKey.iExt)
       
   598                     return;
       
   599                 iAuthKey.iExt = (struct sadb_key *)p;
       
   600                 data_len = (iAuthKey.iExt->sadb_key_bits + 7) / 8;
       
   601                 if (data_len == 0 || data_len + (int)sizeof(struct sadb_key) > ext_len)
       
   602                     return;
       
   603                 iAuthKey.iData.Set(p + sizeof(struct sadb_key), data_len);
       
   604                     break;
       
   605 
       
   606             case SADB_EXT_KEY_ENCRYPT:
       
   607                 if (iEncryptKey.iExt)
       
   608                     return;
       
   609                 iEncryptKey.iExt = (struct sadb_key *)p;
       
   610                 data_len = (iEncryptKey.iExt->sadb_key_bits + 7) / 8;
       
   611                 if (data_len == 0 || data_len + (int)sizeof(struct sadb_key) > ext_len)
       
   612                     return;
       
   613                 iEncryptKey.iData.Set(p + sizeof(struct sadb_key), data_len);
       
   614                 break;
       
   615 
       
   616             case SADB_EXT_IDENTITY_SRC:
       
   617                 {
       
   618                 if (iSrcIdent.iExt)
       
   619                     return;
       
   620                 iSrcIdent.iExt = (struct sadb_ident *)p;
       
   621                 data_len = ext_len - sizeof(struct sadb_ident);
       
   622                 if (data_len < 0)
       
   623                     return;
       
   624                 iSrcIdent.iData.Set(p + sizeof(struct sadb_ident), data_len);
       
   625                 TInt i = iSrcIdent.iData.Locate((TChar)0);
       
   626                 if (i >= 0)
       
   627                     iSrcIdent.iData.Set(iSrcIdent.iData.Ptr(), i);
       
   628                 break;
       
   629                 }
       
   630 
       
   631             case SADB_EXT_IDENTITY_DST:
       
   632                 {
       
   633                 if (iDstIdent.iExt)
       
   634                     return;
       
   635                 iDstIdent.iExt = (struct sadb_ident *)p;
       
   636                 data_len = ext_len - sizeof(struct sadb_ident);
       
   637                 if (data_len < 0)
       
   638                     return;
       
   639                 iDstIdent.iData.Set(p + sizeof(struct sadb_ident), data_len);
       
   640                 TInt i = iDstIdent.iData.Locate((TChar)0);
       
   641                 if (i >= 0)
       
   642                     iDstIdent.iData.Set(iDstIdent.iData.Ptr(), i);
       
   643                 break;
       
   644                 }
       
   645 
       
   646             case SADB_EXT_SENSITIVITY:
       
   647                 if (iSensitivity.iExt)
       
   648                     return;
       
   649                 iSensitivity.iExt = (struct sadb_sens *)p;
       
   650                 data_len = iSensitivity.iExt->sadb_sens_sens_len * 8;
       
   651                 iSensitivity.iSensBitmap.Set(p + sizeof(struct sadb_sens), data_len);
       
   652                 data_len2 = iSensitivity.iExt->sadb_sens_integ_len * 8;
       
   653                 iSensitivity.iSensBitmap.Set(p + (sizeof(struct sadb_sens) + data_len),
       
   654                          data_len2);
       
   655                 if (data_len + data_len2 + (int)sizeof(struct sadb_sens) > ext_len)
       
   656                     return;
       
   657                 break;
       
   658 
       
   659             case SADB_EXT_PROPOSAL:
       
   660                 if (iProposal.iExt)
       
   661                     return;
       
   662                 iProposal.iExt = (struct sadb_prop *)p;
       
   663                 iProposal.iNumComb = (ext_len - sizeof(struct sadb_prop)) / sizeof(struct sadb_comb);
       
   664                 iProposal.iComb = (struct sadb_comb *)(p + sizeof(struct sadb_prop));
       
   665                 break;
       
   666 
       
   667             case SADB_EXT_SUPPORTED_AUTH:
       
   668                 if (iAuthAlgs.iExt)
       
   669                     return;
       
   670                 iAuthAlgs.iExt = (struct sadb_supported *)p;
       
   671                 iAuthAlgs.iNumAlg = (ext_len - sizeof(struct sadb_supported)) / sizeof(struct sadb_alg);
       
   672                 iAuthAlgs.iAlg = (struct sadb_alg *)(p + sizeof(struct sadb_supported));
       
   673                 break;
       
   674 
       
   675             case SADB_EXT_SUPPORTED_ENCRYPT:
       
   676                 if (iEncryptAlgs.iExt)
       
   677                     return;
       
   678                 iEncryptAlgs.iExt = (struct sadb_supported *)p;
       
   679                 iEncryptAlgs.iNumAlg = (ext_len - sizeof(struct sadb_supported)) / sizeof(struct sadb_alg);
       
   680                 iEncryptAlgs.iAlg = (struct sadb_alg *)(p + sizeof(struct sadb_supported));
       
   681                 break;
       
   682 
       
   683             case SADB_EXT_SPIRANGE:
       
   684                 if (iSpirange.iExt)
       
   685                     return;
       
   686                 iSpirange.iExt = (struct sadb_spirange *)p;
       
   687                 break;
       
   688                 
       
   689 			/**---------------------------------------------------------------
       
   690 			 *
       
   691 			 *  PFKEY API general private extension.
       
   692 			 *
       
   693 			 *----------------------------------------------------------------*/                
       
   694             case SADB_PRIV_GENERIC_EXT:
       
   695                 if (iPrivateExtension.iExt)
       
   696                     return;
       
   697                 iPrivateExtension.iExt = (struct sadb_gen_ext *)p;
       
   698                 data_len = (ext_len - sizeof(struct sadb_gen_ext));
       
   699                 if (data_len > ext_len)
       
   700                     return;
       
   701                 iPrivateExtension.iData.Set(p + sizeof(struct sadb_gen_ext), data_len);
       
   702                 break;
       
   703                 
       
   704 
       
   705             case SADB_X_EXT_TS:
       
   706                 if (iTs.iExt)
       
   707                     return;
       
   708                 iTs.iExt = (struct sadb_x_ts *)p;                                
       
   709                 break;
       
   710 
       
   711             default:
       
   712                 // Unknown extensions must be ignored, not an error!
       
   713                 break;
       
   714             }
       
   715             p += ext_len;
       
   716 			length -= ext_len;
       
   717         }
       
   718 	if (length != 0)
       
   719 		return;
       
   720 
       
   721     iError = KErrNone;  // Message unpacked successfully
       
   722     }