AzureMXChip/MXCHIPAZ3166/core/lib/netxduo/addons/dhcp/nxd_dhcpv6_server.c
UINT _nx_dhcpv6_add_ip_address_lease(NX_DHCPV6_SERVER *dhcpv6_server_ptr, UINT table_index, NXD_ADDRESS *lease_IP_address, 
                                       ULONG T1, ULONG T2, ULONG valid_lifetime, ULONG preferred_lifetime)
{

UINT i;
NX_DHCPV6_ADDRESS_LEASE *lease_ptr;
UINT                    ga_address_index;
UINT                    prefix_length;


    /* Get the DHCPv6 server address interface index. */
    ga_address_index = dhcpv6_server_ptr -> nx_dhcpv6_server_ga_address_index; 

    prefix_length = dhcpv6_server_ptr -> nx_dhcpv6_ip_ptr -> nx_ipv6_address[ga_address_index].nxd_ipv6_address_prefix_length;

    /* Verify the input addresses match the server interface address prefix (in IPv4 terms, the
       network masked addresses should be equal). */

    if (!CHECK_IP_ADDRESSES_BY_PREFIX(&(dhcpv6_server_ptr -> nx_dhcpv6_ip_ptr -> nx_ipv6_address[ga_address_index].nxd_ipv6_address[0]),
                                       &lease_IP_address -> nxd_ip_address.v6[0], prefix_length))
    {

        return NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS;
    }

    /* Is there a table index specified? */
    if (table_index == 0xFFFFFFFF)
    {

        /* No, so lets search the server table and find an available slot. */
        for (i = 0; i < NX_DHCPV6_MAX_LEASES; i++)
        {

            /* Get a local pointer for convenience. */
            lease_ptr = &(dhcpv6_server_ptr -> nx_dhcpv6_lease_list[i]);

            /* Does this slot have an address already? */
            if (CHECK_UNSPECIFIED_ADDRESS(&(lease_ptr -> nx_dhcpv6_lease_IP_address.nxd_ip_address.v6[0])))
            {
    
                /* This one looks empty. */
                table_index = i;
                break;
            }
        }

        if (table_index == 0xFFFFFFFF)
        {
            return NX_DHCPV6_TABLE_FULL;
        }
    }
    else
    {
        /* Check for valid table index. */
        if (table_index >= NX_DHCPV6_MAX_LEASES)
        {

            /* No good. Exceeds the size of the table. */
            return NX_DHCPV6_PARAM_ERROR;
        }
    }

    /* Copy the supplied IP data into the lease entry. */
    lease_ptr = &(dhcpv6_server_ptr -> nx_dhcpv6_lease_list[table_index]);

    COPY_NXD_ADDRESS(lease_IP_address, &(lease_ptr -> nx_dhcpv6_lease_IP_address));
    lease_ptr -> nx_dhcpv6_lease_T1_lifetime = T1;                     
    lease_ptr -> nx_dhcpv6_lease_T2_lifetime = T2;                     
    lease_ptr -> nx_dhcpv6_lease_valid_lifetime = valid_lifetime;              
    lease_ptr -> nx_dhcpv6_lease_preferred_lifetime =preferred_lifetime;   

    dhcpv6_server_ptr -> nx_dhcpv6_assignable_addresses++;

    return NX_SUCCESS;
}
/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nx_dhcpv6_add_ip_address_lease                     PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*   This function copies lease data into the Server IP lease table.      */
/*   The caller can specify which slot with a index value up to the size  */
/*   of the lease table, (NX_DHCPV6_MAX_LEASES - 1), or the DHCPv6 server */
/*   will find an empty slot to store the lease data if the table index is*/
/*   set to 'infinity' e.g. 0xFFFFFFFF.                                   */
/*                                                                        */
/*   This is intended to satisfy the DHCPv6 protocol requirement that a   */
/*   DHPCv6 Server be able to store and retrieve IP lease data from       */
/*   nonvolatile memory e..g between reboots.                             */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    dhcpv6_server_ptr                  Pointer to DHCPv6 server         */
/*    table_index                        Table index to store data        */
/*    lease_IP_address                   Lease IP address                 */
/*    T1                                 T1 lifetime (when to renew)      */
/*    T2                                 T2 lifetime (when to rebind)     */
/*    preferred_lifetime                 When address becomes deprecated  */
/*    valid_lifetime                     When address becomes invalid     */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    NX_SUCCESS                         Successful IP address copy       */
/*    NX_DHCPV6_PARAM_ERROR              Invalid table index              */
/*    NX_DHCPV6_TABLE_FULL               No empty entries for lease data  */
/*    NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS                              */
/*                                       Address not onlink with Server   */
/*                                         DHCPv6 network interface       */
/*  CALLS                                                                 */
/*                                                                        */
/*    None                                                                */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    Application code                                                    */
/*                                                                        */
/*  RELEASE HISTORY                                                       */
/*                                                                        */
/*    DATE              NAME                      DESCRIPTION             */
/*                                                                        */
/*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
/*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
/*                                            resulting in version 6.1    */
/*                                                                        */
/**************************************************************************/
FUNCTION                                               RELEASE

_nx_dhcpv6_add_ip_address_lease                     PORTABLE C
6.1
AUTHOR

Yuxin Zhou, Microsoft Corporation

DESCRIPTION

This function copies lease data into the Server IP lease table.
The caller can specify which slot with a index value up to the size
of the lease table, (NX_DHCPV6_MAX_LEASES - 1), or the DHCPv6 server
will find an empty slot to store the lease data if the table index is
set to 'infinity' e.g. 0xFFFFFFFF.

This is intended to satisfy the DHCPv6 protocol requirement that a
DHPCv6 Server be able to store and retrieve IP lease data from
nonvolatile memory e..g between reboots.

INPUT

dhcpv6_server_ptr                  Pointer to DHCPv6 server
table_index                        Table index to store data
lease_IP_address                   Lease IP address
T1                                 T1 lifetime (when to renew)
T2                                 T2 lifetime (when to rebind)
preferred_lifetime                 When address becomes deprecated
valid_lifetime                     When address becomes invalid

OUTPUT

NX_SUCCESS                         Successful IP address copy
NX_DHCPV6_PARAM_ERROR              Invalid table index
NX_DHCPV6_TABLE_FULL               No empty entries for lease data
NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS
Address not onlink with Server
DHCPv6 network interface
CALLS

None

CALLED BY

Application code

RELEASE HISTORY

DATE              NAME                      DESCRIPTION

05-19-2020     Yuxin Zhou               Initial Version 6.0
09-30-2020     Yuxin Zhou               Modified comment(s),
resulting in version 6.1
FUNCTION RELEASE _nx_dhcpv6_add_ip_address_lease PORTABLE C 6 . 1 AUTHOR Yuxin Zhou Microsoft Corporation DESCRIPTION This function copies lease data into the Server IP lease table . The caller can specify which slot with a index value up to the size of the lease table ( NX_DHCPV6_MAX_LEASES - 1 ) or the DHCPv6 server will find an empty slot to store the lease data if the table index is set to ' infinity ' e . g . 0xFFFFFFFF . This is intended to satisfy the DHCPv6 protocol requirement that a DHPCv6 Server be able to store and retrieve IP lease data from nonvolatile memory e .. g between reboots . INPUT dhcpv6_server_ptr Pointer to DHCPv6 server table_index Table index to store data lease_IP_address Lease IP address T1 T1 lifetime ( when to renew ) T2 T2 lifetime ( when to rebind ) preferred_lifetime When address becomes deprecated valid_lifetime When address becomes invalid OUTPUT NX_SUCCESS Successful IP address copy NX_DHCPV6_PARAM_ERROR Invalid table index NX_DHCPV6_TABLE_FULL No empty entries for lease data NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS Address not onlink with Server DHCPv6 network interface CALLS None CALLED BY Application code RELEASE HISTORY DATE NAME DESCRIPTION 05 - 19 - 2020 Yuxin Zhou Initial Version 6 . 0 09 - 30 - 2020 Yuxin Zhou Modified comment ( s ) resulting in version 6 . 1
UINT _nx_dhcpv6_add_ip_address_lease(NX_DHCPV6_SERVER *dhcpv6_server_ptr, UINT table_index, NXD_ADDRESS *lease_IP_address, 
                                       ULONG T1, ULONG T2, ULONG valid_lifetime, ULONG preferred_lifetime)
{
UINT i;
NX_DHCPV6_ADDRESS_LEASE *lease_ptr;
UINT                    ga_address_index;
UINT                    prefix_length;
    ga_address_index = dhcpv6_server_ptr -> nx_dhcpv6_server_ga_address_index; 
    prefix_length = dhcpv6_server_ptr -> nx_dhcpv6_ip_ptr -> nx_ipv6_address[ga_address_index].nxd_ipv6_address_prefix_length;
    if (!CHECK_IP_ADDRESSES_BY_PREFIX(&(dhcpv6_server_ptr -> nx_dhcpv6_ip_ptr -> nx_ipv6_address[ga_address_index].nxd_ipv6_address[0]),
                                       &lease_IP_address -> nxd_ip_address.v6[0], prefix_length))
    {
        return NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS;
    }
    if (table_index == 0xFFFFFFFF)
    {
        for (i = 0; i < NX_DHCPV6_MAX_LEASES; i++)
        {
            lease_ptr = &(dhcpv6_server_ptr -> nx_dhcpv6_lease_list[i]);
            if (CHECK_UNSPECIFIED_ADDRESS(&(lease_ptr -> nx_dhcpv6_lease_IP_address.nxd_ip_address.v6[0])))
            {
                table_index = i;
                break;
            }
        }
        if (table_index == 0xFFFFFFFF)
        {
            return NX_DHCPV6_TABLE_FULL;
        }
    }
    else
    {
        if (table_index >= NX_DHCPV6_MAX_LEASES)
        {
            return NX_DHCPV6_PARAM_ERROR;
        }
    }
    lease_ptr = &(dhcpv6_server_ptr -> nx_dhcpv6_lease_list[table_index]);
    COPY_NXD_ADDRESS(lease_IP_address, &(lease_ptr -> nx_dhcpv6_lease_IP_address));
    lease_ptr -> nx_dhcpv6_lease_T1_lifetime = T1;                     
    lease_ptr -> nx_dhcpv6_lease_T2_lifetime = T2;                     
    lease_ptr -> nx_dhcpv6_lease_valid_lifetime = valid_lifetime;              
    lease_ptr -> nx_dhcpv6_lease_preferred_lifetime =preferred_lifetime;   
    dhcpv6_server_ptr -> nx_dhcpv6_assignable_addresses++;
    return NX_SUCCESS;
}
UINT _nx_dhcpv6_add_ip_address_lease ( NX_DHCPV6_SERVER * dhcpv6_server_ptr , UINT table_index , NXD_ADDRESS * lease_IP_address , ULONG T1 , ULONG T2 , ULONG valid_lifetime , ULONG preferred_lifetime ) { UINT i ; NX_DHCPV6_ADDRESS_LEASE * lease_ptr ; UINT ga_address_index ; UINT prefix_length ; ga_address_index = dhcpv6_server_ptr -> nx_dhcpv6_server_ga_address_index ; prefix_length = dhcpv6_server_ptr -> nx_dhcpv6_ip_ptr -> nx_ipv6_address [ ga_address_index ] . nxd_ipv6_address_prefix_length ; if ( ! CHECK_IP_ADDRESSES_BY_PREFIX ( & ( dhcpv6_server_ptr -> nx_dhcpv6_ip_ptr -> nx_ipv6_address [ ga_address_index ] . nxd_ipv6_address [ 0 ] ) , & lease_IP_address -> nxd_ip_address . v6 [ 0 ] , prefix_length ) ) { return NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS ; } if ( table_index == 0xFFFFFFFF ) { for ( i = 0 ; i < NX_DHCPV6_MAX_LEASES ; i ++ ) { lease_ptr = & ( dhcpv6_server_ptr -> nx_dhcpv6_lease_list [ i ] ) ; if ( CHECK_UNSPECIFIED_ADDRESS ( & ( lease_ptr -> nx_dhcpv6_lease_IP_address . nxd_ip_address . v6 [ 0 ] ) ) ) { table_index = i ; break ; } } if ( table_index == 0xFFFFFFFF ) { return NX_DHCPV6_TABLE_FULL ; } } else { if ( table_index >= NX_DHCPV6_MAX_LEASES ) { return NX_DHCPV6_PARAM_ERROR ; } } lease_ptr = & ( dhcpv6_server_ptr -> nx_dhcpv6_lease_list [ table_index ] ) ; COPY_NXD_ADDRESS ( lease_IP_address , & ( lease_ptr -> nx_dhcpv6_lease_IP_address ) ) ; lease_ptr -> nx_dhcpv6_lease_T1_lifetime = T1 ; lease_ptr -> nx_dhcpv6_lease_T2_lifetime = T2 ; lease_ptr -> nx_dhcpv6_lease_valid_lifetime = valid_lifetime ; lease_ptr -> nx_dhcpv6_lease_preferred_lifetime = preferred_lifetime ; dhcpv6_server_ptr -> nx_dhcpv6_assignable_addresses ++ ; return NX_SUCCESS ; }
FUNCTION                                               RELEASE
FUNCTION RELEASE
/* Get the DHCPv6 server address interface index. */ /* Verify the input addresses match the server interface address prefix (in IPv4 terms, the
       network masked addresses should be equal). */ /* Is there a table index specified? */ /* No, so lets search the server table and find an available slot. */ /* Get a local pointer for convenience. */ /* Does this slot have an address already? */ /* This one looks empty. */ /* Check for valid table index. */ /* No good. Exceeds the size of the table. */ /* Copy the supplied IP data into the lease entry. */