tcpiputils/dhcp/include/DHCPIP6IA.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 // DHCPv6 Identity Association - holds config info associated with IAID
       
    15 // IAID (Identity Association Id) is generated by client at least one per interface 
       
    16 // (DUID DHCP Unique IDentifier)
       
    17 // 
       
    18 //
       
    19 
       
    20 /**
       
    21  @file DHCPIP6IA.h
       
    22 */
       
    23 
       
    24 #ifndef DHCPIP6IA_H
       
    25 #define DHCPIP6IA_H
       
    26 
       
    27 #include <e32base.h>
       
    28 #include "DhcpIP6Msg.h"
       
    29 #include <comms-infras/metadata.h>
       
    30 
       
    31 class CDHCPIP6Control;
       
    32 class CDHCPIP6StateMachine;
       
    33 
       
    34 namespace DHCPv6
       
    35 {
       
    36 
       
    37 const TInt KDHCPOptionIA_IAIDLength = 4; //(4 bytes)
       
    38 
       
    39 /*
       
    40       Identity Association for Non-temporary Addresses Option
       
    41        0                   1                   2                   3
       
    42        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
       
    43       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    44       |          OPTION_IA_NA         |          option-len           |
       
    45       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    46       |                        IAID (4 octets)                        |
       
    47       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    48       |                              T1                               |
       
    49       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    50       |                              T2                               |
       
    51       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    52       |                                                               |
       
    53       .                         IA_NA-options                         .
       
    54       .                                                               .
       
    55       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    56 
       
    57       option-code          OPTION_IA_NA (3).
       
    58 
       
    59       option-len           12 + length of IA_NA-options field.
       
    60 
       
    61       IAID                 The unique identifier for this IA_NA; the
       
    62                            IAID must be unique among the identifiers for
       
    63                            all of this client's IA_NAs.  The number
       
    64                            space for IA_NA IAIDs is separate from the
       
    65                            number space for IA_TA IAIDs.
       
    66 
       
    67       T1                   The time at which the client contacts the
       
    68                            server from which the addresses in the IA_NA
       
    69                            were obtained to extend the lifetimes of the
       
    70                            addresses assigned to the IA_NA; T1 is a
       
    71                            time duration relative to the current time
       
    72                            expressed in units of seconds.
       
    73 
       
    74       T2                   The time at which the client contacts any
       
    75                            available server to extend the lifetimes of
       
    76                            the addresses assigned to the IA_NA; T2 is a
       
    77                            time duration relative to the current time
       
    78                            expressed in units of seconds.
       
    79 
       
    80       IA_NA-options        Options associated with this IA_NA.
       
    81 
       
    82 Identity Association for Temporary Addresses Option doesn't have T1 and T2 fields
       
    83 */
       
    84 class CDHCPOptionIA : public COptionNode
       
    85 /**
       
    86   * Option associated with DUID identifying one set of config parameters
       
    87   * associated with a DHCP interface Id (DUID).
       
    88   * Part common for NA_IA & TA_IA
       
    89   *
       
    90   * @internalTechnology
       
    91   */
       
    92 	{
       
    93 
       
    94 public:
       
    95 	CDHCPOptionIA() :
       
    96 		COptionNode(NULL)
       
    97 		{
       
    98 		}
       
    99 
       
   100     virtual TPtr8 GetOptionsDes() const = 0;
       
   101     
       
   102 	TUint32 GetIAID() const; 
       
   103 	void SetIAID(const TUint32 aIAID);
       
   104 	};
       
   105 
       
   106 inline TUint32 CDHCPOptionIA::GetIAID() const
       
   107     {
       
   108     __ASSERT_DEBUG(GetLength() >= KDHCPOptionIA_IAIDLength, User::Panic(KDhcpv6, KErrBadDescriptor));
       
   109     return TBigEndian::GetValue(iPtr8 + KOptionHeaderLength, KDHCPOptionIA_IAIDLength);
       
   110     }
       
   111 
       
   112 inline void CDHCPOptionIA::SetIAID(const TUint32 aIAID)
       
   113     {
       
   114    __ASSERT_DEBUG( GetLength() >= KDHCPOptionIA_IAIDLength, User::Panic( KDhcpv6, KErrBadDescriptor ) );
       
   115 	TBigEndian::SetValue(iPtr8 + KOptionHeaderLength, KDHCPOptionIA_IAIDLength, aIAID);
       
   116     }
       
   117 
       
   118 //no options involved in the init length of IA_TA option
       
   119 const TInt KDHCPOptionIA_TATInitLength = KDHCPOptionIA_IAIDLength;
       
   120 
       
   121 class CDHCPOptionIA_TA : public CDHCPOptionIA
       
   122 /**
       
   123   * Option associated with DUID identifying one set of config parameters
       
   124   * associated with a DHCP interface Id (DUID).
       
   125   * Part specific to TA_IA
       
   126   *
       
   127   * @internalTechnology
       
   128   */
       
   129 	{
       
   130 
       
   131 public:
       
   132 	CDHCPOptionIA_TA() :
       
   133 		CDHCPOptionIA()
       
   134 		{
       
   135 		}
       
   136 
       
   137     static COptionNode* NewL();
       
   138 
       
   139     virtual TPtr8 GetOptionsDes() const;
       
   140 	};
       
   141 
       
   142 const TInt KDHCPOptionIA_NAT1Length = 4; //(4 bytes)
       
   143 const TInt KDHCPOptionIA_NAT2Length = 4; //(4 bytes)
       
   144 //no options involved in the init length
       
   145 const TInt KDHCPOptionIA_NATInitLength = KDHCPOptionIA_NAT1Length + KDHCPOptionIA_NAT2Length + KDHCPOptionIA_IAIDLength;
       
   146 
       
   147 const TInt KIA_NoTimePreference = 0x00;
       
   148 
       
   149 class CDHCPOptionIA_NA : public CDHCPOptionIA
       
   150 /**
       
   151   * Option associated with DUID identifying one set of config parameters
       
   152   * associated with a DHCP interface Id (DUID)
       
   153   * Part specific to IA_NA
       
   154   *
       
   155   * @internalTechnology
       
   156   */
       
   157 	{
       
   158 
       
   159 public:
       
   160 	CDHCPOptionIA_NA() :
       
   161 		CDHCPOptionIA()
       
   162 		{
       
   163 		}
       
   164 
       
   165 	static COptionNode* NewL();
       
   166 
       
   167 
       
   168     virtual TPtr8 GetOptionsDes() const;
       
   169 
       
   170 	TUint32 GetT1() const; 
       
   171 	void SetT1(TUint32 aT1);
       
   172 	TUint32 GetT2() const; 
       
   173 	void SetT2(TUint32 aT1);
       
   174 	};
       
   175 
       
   176 
       
   177 inline TUint32 CDHCPOptionIA_NA::GetT1() const
       
   178     {
       
   179 //    __ASSERT_DEBUG(GetLength() >= KDHCPOptionStatusCodeLength, User::Panic(KDhcpv6, KErrBadDescriptor));
       
   180     return TBigEndian::GetValue(iPtr8 + KOptionHeaderLength + KDHCPOptionIA_IAIDLength, KDHCPOptionIA_NAT1Length);
       
   181     }
       
   182 
       
   183 inline void CDHCPOptionIA_NA::SetT1(TUint32 aT1)
       
   184     {
       
   185 //    __ASSERT_DEBUG(GetLength() >= KDHCPOptionStatusCodeLength, User::Panic(KDhcpv6, KErrBadDescriptor));
       
   186     TBigEndian::SetValue(iPtr8 + KOptionHeaderLength + KDHCPOptionIA_IAIDLength, KDHCPOptionIA_NAT1Length, aT1);
       
   187     }    
       
   188 
       
   189 
       
   190 inline TUint32 CDHCPOptionIA_NA::GetT2() const
       
   191     {
       
   192 //    __ASSERT_DEBUG(GetLength() >= KDHCPOptionStatusCodeLength, User::Panic(KDhcpv6, KErrBadDescriptor));
       
   193     return TBigEndian::GetValue(iPtr8 + KOptionHeaderLength + KDHCPOptionIA_IAIDLength + KDHCPOptionIA_NAT1Length, 
       
   194         KDHCPOptionIA_NAT2Length);
       
   195     }
       
   196 
       
   197 inline void CDHCPOptionIA_NA::SetT2(TUint32 aT2)
       
   198     {
       
   199 //    __ASSERT_DEBUG(GetLength() >= KDHCPOptionStatusCodeLength, User::Panic(KDhcpv6, KErrBadDescriptor));
       
   200     TBigEndian::SetValue(iPtr8 + KOptionHeaderLength + KDHCPOptionIA_IAIDLength + KDHCPOptionIA_NAT1Length, 
       
   201         KDHCPOptionIA_NAT2Length, aT2);
       
   202     }    
       
   203 
       
   204 
       
   205 const TInt KDHCPOptionAddressPrefLifeTimeLength = 4; //(4 bytes)
       
   206 const TInt KDHCPOptionAddressValidLifeTimeLength = 4; //(4 bytes)
       
   207 /*
       
   208       IA Address Option
       
   209        0                   1                   2                   3
       
   210        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
       
   211       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   212       |          OPTION_IAADDR        |          option-len           |
       
   213       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   214       |                                                               |
       
   215       |                         IPv6 address                          |
       
   216       |                                                               |
       
   217       |                                                               |
       
   218       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   219       |                      preferred-lifetime                       |
       
   220       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   221       |                        valid-lifetime                         |
       
   222       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   223       .                                                               .
       
   224       .                        IAaddr-options                         .
       
   225       .                                                               .
       
   226       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   227 
       
   228       option-code   OPTION_IAADDR (5).
       
   229 
       
   230       option-len    24 + length of IAaddr-options field.
       
   231 
       
   232       IPv6 address  An IPv6 address.
       
   233 
       
   234       preferred-lifetime The preferred lifetime for the IPv6 address in
       
   235                     the option, expressed in units of seconds.
       
   236 
       
   237       valid-lifetime The valid lifetime for the IPv6 address in the
       
   238                     option, expressed in units of seconds.
       
   239 
       
   240       IAaddr-options Options associated with this address.
       
   241 */
       
   242 
       
   243 const TInt KDHCPOptionIAAddressLength = KOptionHeaderLength + KIp6AddressLength + KDHCPOptionAddressPrefLifeTimeLength + KDHCPOptionAddressValidLifeTimeLength;
       
   244 const TInt KDHCPOptionIAAddressWithStatusCodeLength = KDHCPOptionIAAddressLength + KOptionHeaderLength + KDHCPOptionStatusCodeLength;
       
   245 
       
   246 struct SIPAddressInfo;
       
   247 
       
   248 class CDHCPOptionIAAddress : public COptionNode
       
   249 /**
       
   250   * Option associated with IAID (IA option) carrying address config info
       
   251   *
       
   252   * @internalTechnology
       
   253   */
       
   254 	{
       
   255 
       
   256 public:
       
   257    CDHCPOptionIAAddress() :
       
   258 		COptionNode( &iAddress ),
       
   259 		iAddress( &iPreferredLifeTime, KIp6AddressLength ),
       
   260 		iPreferredLifeTime( &iValidLifeTime, KDHCPOptionAddressPrefLifeTimeLength ),
       
   261 		iValidLifeTime(&iOptions, KDHCPOptionAddressValidLifeTimeLength ),
       
   262 		iOptions(NULL)
       
   263       {
       
   264 		iRecord.iFirst = &iAddress;
       
   265       }
       
   266         
       
   267     virtual ~CDHCPOptionIAAddress();    
       
   268 
       
   269 	static CDHCPOptionIAAddress* NewL() 
       
   270 		 { 
       
   271 		 return new(ELeave)CDHCPOptionIAAddress(); 
       
   272 		 }
       
   273 
       
   274 	TInt GetAddressOptionL(TPtr8& aPtr, SIPAddressInfo& aAddressInfo);
       
   275 	TInt AddAddressOptionL(TPtr8& aPtr, SIPAddressInfo& aAddressInfo, TStatusCodes aStatusCodeToSend);
       
   276 
       
   277 	inline COptionList& GetOptions() { return iOptions; }
       
   278 	
       
   279 
       
   280 public:
       
   281 	CConstItem iAddress;
       
   282 	CConstItem iPreferredLifeTime;
       
   283 	CConstItem iValidLifeTime;
       
   284 	
       
   285 protected:
       
   286 	COptionList iOptions;
       
   287     };
       
   288     
       
   289     
       
   290     
       
   291 const TInt KAddrIndexAll = -1;
       
   292 
       
   293 //persistent data
       
   294 struct SIPAddressInfo
       
   295 /**
       
   296   * Contains IPv6 address info associated with the particular IAID
       
   297   *
       
   298   * @internalTechnology
       
   299   */
       
   300 	{
       
   301 	  SIPAddressInfo() :
       
   302 		iPreferredLifeTime( KIA_NoTimePreference ),
       
   303 		iValidLifeTime( KIA_NoTimePreference ),
       
   304 		iStatusCode( ESuccess )
       
   305 		{
       
   306 		}
       
   307 	TInetAddr iAddress;
       
   308 	TUint32 iPreferredLifeTime; //renew of the address via unicast (renew)
       
   309 	TUint32 iValidLifeTime; //renew address via multicast (rebind)
       
   310 	TInt	iStatusCode;
       
   311 	};
       
   312 
       
   313 struct SIdentityAssociationConfigInfo : public Meta::SMetaData
       
   314 /**
       
   315   * Contains config info associated with one IAID. The first address of the first IA option
       
   316   * in the server's reply message is stored in CDHCPStateMachine::iCurrentAddress variable
       
   317   * so as KConnGetCurrentAddr Ioctl command works for IP4 & IP6
       
   318   *
       
   319   * @see SIdentityAssociationConfigInfoTA, SIdentityAssociationConfigInfoNA
       
   320   * @internalTechnology
       
   321   */
       
   322 	{
       
   323 	SIdentityAssociationConfigInfo() : iIAID(0)
       
   324 		{
       
   325 		}
       
   326 		
       
   327 	~SIdentityAssociationConfigInfo() //non-virtual since never accessed via base class
       
   328 		{
       
   329 		iAddressInfo.Close();
       
   330 		}
       
   331 
       
   332 	void Reset();
       
   333 	void ResetAddressInfos();
       
   334 	TUint32 IaId() const;
       
   335 	TInt AddressInfo( TInt aIndex, TStatusCodes aStatusCode ) const;
       
   336 	TInt AddAddressesL( CDHCPOptionIA& aDHCPOptionIA, TMessageType aMessageType );
       
   337 	void ExtractAddressesL( CDHCPOptionIA& aDHCPOptionIA, TUint32 aRebindTimeSpan );
       
   338 
       
   339 	const SIPAddressInfo* GetValidAddressInfo( TInt& aPos ) const;
       
   340 
       
   341 	void SetAddressStatus( TInt aIndex, TStatusCodes aStatusCode );
       
   342 
       
   343 protected:
       
   344 	TUint32 iIAID;    //Identity Association ID
       
   345 	RArray<SIPAddressInfo> iAddressInfo;
       
   346 
       
   347 public:
       
   348 	DATA_VTABLE
       
   349 	};
       
   350 
       
   351 inline void SIdentityAssociationConfigInfo::ResetAddressInfos()
       
   352 	{
       
   353 	iAddressInfo.Reset();
       
   354 	}
       
   355 
       
   356 inline TUint32 SIdentityAssociationConfigInfo::IaId() const
       
   357 	{
       
   358 	return iIAID;
       
   359 	}
       
   360 
       
   361 inline const SIPAddressInfo* SIdentityAssociationConfigInfo::GetValidAddressInfo( TInt& aPos ) const
       
   362 	{
       
   363 	return ( aPos = AddressInfo( aPos, ESuccess )) != KErrNotFound ? &iAddressInfo[aPos - 1] : NULL;
       
   364 	}
       
   365 
       
   366 struct SIdentityAssociationConfigInfoTA : public SIdentityAssociationConfigInfo
       
   367 /**
       
   368   * Contains config info associated with one IAID for Temporary Addresses
       
   369   *
       
   370   * @see SIPAddressInfo
       
   371   * @internalTechnology
       
   372   */
       
   373    {
       
   374 	TUint32 iLifeTime; //the longest life time from associated addresses
       
   375    };
       
   376 
       
   377 struct SIdentityAssociationConfigInfoNA : public SIdentityAssociationConfigInfo
       
   378 /**
       
   379   * Contains config info associated with one IAID for Non-temporary Addresses
       
   380   *
       
   381   * @see SIPAddressInfo
       
   382   * @internalTechnology
       
   383   */
       
   384    {
       
   385    TUint32 iT1;    //renew of the IA via unicast
       
   386    TUint32 iT2;    //rebind of the IA via multicast to all servers and rely agents
       
   387 
       
   388    void ExtractIAOptionInfoL( CDHCPOptionIA_NA& aDHCPOptionIA );
       
   389 
       
   390 public:
       
   391 	DATA_VTABLE
       
   392    };
       
   393 
       
   394 class TInterfaceConfigInfo
       
   395 /**
       
   396   * Contains all IAIDs associated with the interface identified by DUID
       
   397   * By having iSIdentityAssociationConfigInfoTA and iSIdentityAssociationConfigInfoNA members
       
   398   * we confined ourselves to one NAID and one TAID for the moment. There could be an array of these.
       
   399   *
       
   400   * @see SIdentityAssociationConfigInfo
       
   401   * @see SIdentityAssociationConfigInfoTA
       
   402   * @see SIdentityAssociationConfigInfoNA
       
   403   * @internalTechnology
       
   404   */
       
   405    {
       
   406 friend class CDHCPIP6Control;
       
   407 friend class CDHCPIP6StateMachine;
       
   408 
       
   409 public:
       
   410 	void Reset();
       
   411 	void AppendIAOptionsL( CDHCPMessageHeaderIP6& aMessage, TMessageType aMessageType );
       
   412 	void ParseIAOptionsL( CDHCPMessageHeaderIP6& aMessage );
       
   413 
       
   414 	void ResetUseUnicast();	
       
   415 	void CheckForUnicast( CDHCPMessageHeaderIP6& aMessage );
       
   416 	void GetServerAddress( TInetAddr& aAddress );	// to send/receive data
       
   417 	
       
   418 	TBool AnyAddressToDecline() const;
       
   419 	void SetAddressStatus( TInt aIndex, TStatusCodes aStatusCode );
       
   420 
       
   421 	const SIPAddressInfo* GetValidAddressInfo( TInt& aPos ) const;
       
   422 
       
   423 	TUint32 RenewTime() const;
       
   424 	TUint32 RebindTime() const;
       
   425 
       
   426 protected:
       
   427    TBool iUseUnicast; //ETrue if the server's sent a unicast option
       
   428 	TInetAddr iServerAddress;	// to store the address of the DHCP Server we are dealing with
       
   429 
       
   430 public:
       
   431 //not used yet   SIdentityAssociationConfigInfoTA iSIdentityAssociationConfigInfoTA;
       
   432    SIdentityAssociationConfigInfoNA iSIdentityAssociationConfigInfoNA;   
       
   433    };
       
   434    
       
   435 //if we ever what to work with more than one IA we need to add mechanism how to make one an active one
       
   436 inline TUint32 TInterfaceConfigInfo::RenewTime() const
       
   437 	{
       
   438 	return iSIdentityAssociationConfigInfoNA.iT1;
       
   439 	}
       
   440 
       
   441 inline TUint32 TInterfaceConfigInfo::RebindTime() const
       
   442 	{
       
   443 	return iSIdentityAssociationConfigInfoNA.iT2;
       
   444 	}
       
   445 
       
   446 inline void TInterfaceConfigInfo::SetAddressStatus( TInt aIndex, TStatusCodes aStatusCode )
       
   447 	{
       
   448 	iSIdentityAssociationConfigInfoNA.SetAddressStatus(aIndex, aStatusCode);
       
   449 	}
       
   450 
       
   451 inline void TInterfaceConfigInfo::ResetUseUnicast()
       
   452 	{
       
   453 	iUseUnicast = EFalse;
       
   454 	}
       
   455 
       
   456 inline TBool TInterfaceConfigInfo::AnyAddressToDecline() const
       
   457 	{
       
   458 	TInt dummy = 0;
       
   459 	return iSIdentityAssociationConfigInfoNA.AddressInfo( dummy, EMarkForDecline ) != KErrNotFound;
       
   460 	}
       
   461 
       
   462 inline const SIPAddressInfo* TInterfaceConfigInfo::GetValidAddressInfo( TInt& aPos ) const
       
   463 	{
       
   464 	return iSIdentityAssociationConfigInfoNA.GetValidAddressInfo(aPos);
       
   465 	}
       
   466 
       
   467 }//DHCPv6 namespace
       
   468 
       
   469 #endif
       
   470