AzureMXChip/MXCHIPAZ3166/core/lib/netxduo/addons/dhcp/nxd_dhcpv6_server.c
UINT  _nx_dhcpv6_create_ip_address_range(NX_DHCPV6_SERVER *dhcpv6_server_ptr,  
                                         NXD_ADDRESS *start_ipv6_address, NXD_ADDRESS *end_ipv6_address,
                                         UINT *addresses_added)
{

UINT                         i;
NX_IP                        *ip_ptr;
UINT                         prefix_length;
NXD_ADDRESS                  next_ipv6_address;
UINT                         ga_address_index;


    *addresses_added = 0;

    COPY_NXD_ADDRESS(start_ipv6_address, &next_ipv6_address);

    /* Set up a local variable for convenience. */
    ip_ptr = dhcpv6_server_ptr -> nx_dhcpv6_ip_ptr;
    ga_address_index = dhcpv6_server_ptr -> nx_dhcpv6_server_ga_address_index;      
    prefix_length = 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(&(ip_ptr -> nx_ipv6_address[ga_address_index].nxd_ipv6_address[0]),
                                       &start_ipv6_address -> nxd_ip_address.v6[0], prefix_length))
    {

        return NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS;
    }

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

        return NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS;
    }

    /* Set the server ip address based on the specified interface. */

    /* Clear out existing entries and start adding IP addresses at the beginning of the list. */
    i = 0;

    /* Fit as many IP addresses in the specified range as will fit in the table. */
    while (i < NX_DHCPV6_MAX_LEASES)
    {

        NX_DHCPV6_ADDRESS_LEASE *ip_lease_ptr; 

        /* Set local pointer to the next entry for convenience. */
        ip_lease_ptr = &dhcpv6_server_ptr -> nx_dhcpv6_lease_list[i];

        /* Initialize each entry before adding data.  */
        memset(&dhcpv6_server_ptr -> nx_dhcpv6_lease_list[i], 0, sizeof(NX_DHCPV6_ADDRESS_LEASE));

        /* Add the IP address into this slot. */
        COPY_NXD_ADDRESS(&next_ipv6_address, &ip_lease_ptr -> nx_dhcpv6_lease_IP_address);

        /* Update the number of addresses added. */
        (*addresses_added)++;

        /* Increase the address low word by one. */
        next_ipv6_address.nxd_ip_address.v6[3]++;

        /* Check if we are overflowing the last word. */
        if (next_ipv6_address.nxd_ip_address.v6[3] == 0xFFFFFFFF)
        {

            /* We are. Let's stop here. */
            break;
        }

        if (CHECK_IPV6_ADDRESSES_SAME(&next_ipv6_address.nxd_ip_address.v6[0], &end_ipv6_address -> nxd_ip_address.v6[0]))
        {
            break;
        }

        i++;
    }

    /* Indicate how many addresses were actually added to the server list. */
    dhcpv6_server_ptr -> nx_dhcpv6_assignable_addresses = *addresses_added;

    return(NX_SUCCESS);
}
/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nx_dhcpv6_create_ip_address_range                  PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*   This function creates a list of IPv6 addresses the DHCPv6 server     */
/*   may assign to clients, using a start and end address.  It returns the*/
/*   number of addresses actually added, which may be limited by the size */
/*   of the server address table.                                         */
/*                                                                        */
/*   Note: The NetX Duo DHCPv6 server accomodates up to 256 assignable    */
/*   address ranges in the current release.                               */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    dhcpv6_server_ptr                  Pointer to DHCPv6 server         */
/*    start_ipv6_address                 Start of IP address in list.     */
/*    end_ipv6_address                   End of IP address in list.       */
/*    addresses_added                    Number of addresses added to list*/
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    NX_SUCCESS                         Successful IP list creation      */
/*    NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS                              */
/*                                       Supplied address not reachable   */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*                                                                        */
/*  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_create_ip_address_range                  PORTABLE C
6.1
AUTHOR

Yuxin Zhou, Microsoft Corporation

DESCRIPTION

This function creates a list of IPv6 addresses the DHCPv6 server
may assign to clients, using a start and end address.  It returns the
number of addresses actually added, which may be limited by the size
of the server address table.

The NetX Duo DHCPv6 server accomodates up to 256 assignable
address ranges in the current release.

INPUT

dhcpv6_server_ptr                  Pointer to DHCPv6 server
start_ipv6_address                 Start of IP address in list.
end_ipv6_address                   End of IP address in list.
addresses_added                    Number of addresses added to list

OUTPUT

NX_SUCCESS                         Successful IP list creation
NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS
Supplied address not reachable

CALLS

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_create_ip_address_range PORTABLE C 6 . 1 AUTHOR Yuxin Zhou Microsoft Corporation DESCRIPTION This function creates a list of IPv6 addresses the DHCPv6 server may assign to clients using a start and end address . It returns the number of addresses actually added which may be limited by the size of the server address table . The NetX Duo DHCPv6 server accomodates up to 256 assignable address ranges in the current release . INPUT dhcpv6_server_ptr Pointer to DHCPv6 server start_ipv6_address Start of IP address in list . end_ipv6_address End of IP address in list . addresses_added Number of addresses added to list OUTPUT NX_SUCCESS Successful IP list creation NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS Supplied address not reachable CALLS 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_create_ip_address_range(NX_DHCPV6_SERVER *dhcpv6_server_ptr,  
                                         NXD_ADDRESS *start_ipv6_address, NXD_ADDRESS *end_ipv6_address,
                                         UINT *addresses_added)
{
UINT                         i;
NX_IP                        *ip_ptr;
UINT                         prefix_length;
NXD_ADDRESS                  next_ipv6_address;
UINT                         ga_address_index;
    *addresses_added = 0;
    COPY_NXD_ADDRESS(start_ipv6_address, &next_ipv6_address);
    ip_ptr = dhcpv6_server_ptr -> nx_dhcpv6_ip_ptr;
    ga_address_index = dhcpv6_server_ptr -> nx_dhcpv6_server_ga_address_index;      
    prefix_length = ip_ptr -> nx_ipv6_address[ga_address_index].nxd_ipv6_address_prefix_length;
    if (!CHECK_IP_ADDRESSES_BY_PREFIX(&(ip_ptr -> nx_ipv6_address[ga_address_index].nxd_ipv6_address[0]),
                                       &start_ipv6_address -> nxd_ip_address.v6[0], prefix_length))
    {
        return NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS;
    }
    if (!CHECK_IP_ADDRESSES_BY_PREFIX(&(ip_ptr -> nx_ipv6_address[ga_address_index].nxd_ipv6_address[0]),
                                       &end_ipv6_address -> nxd_ip_address.v6[0], prefix_length))
    {
        return NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS;
    }
    i = 0;
    while (i < NX_DHCPV6_MAX_LEASES)
    {
        NX_DHCPV6_ADDRESS_LEASE *ip_lease_ptr; 
        ip_lease_ptr = &dhcpv6_server_ptr -> nx_dhcpv6_lease_list[i];
        memset(&dhcpv6_server_ptr -> nx_dhcpv6_lease_list[i], 0, sizeof(NX_DHCPV6_ADDRESS_LEASE));
        COPY_NXD_ADDRESS(&next_ipv6_address, &ip_lease_ptr -> nx_dhcpv6_lease_IP_address);
        (*addresses_added)++;
        next_ipv6_address.nxd_ip_address.v6[3]++;
        if (next_ipv6_address.nxd_ip_address.v6[3] == 0xFFFFFFFF)
        {
            break;
        }
        if (CHECK_IPV6_ADDRESSES_SAME(&next_ipv6_address.nxd_ip_address.v6[0], &end_ipv6_address -> nxd_ip_address.v6[0]))
        {
            break;
        }
        i++;
    }
    dhcpv6_server_ptr -> nx_dhcpv6_assignable_addresses = *addresses_added;
    return(NX_SUCCESS);
}
UINT _nx_dhcpv6_create_ip_address_range ( NX_DHCPV6_SERVER * dhcpv6_server_ptr , NXD_ADDRESS * start_ipv6_address , NXD_ADDRESS * end_ipv6_address , UINT * addresses_added ) { UINT i ; NX_IP * ip_ptr ; UINT prefix_length ; NXD_ADDRESS next_ipv6_address ; UINT ga_address_index ; * addresses_added = 0 ; COPY_NXD_ADDRESS ( start_ipv6_address , & next_ipv6_address ) ; ip_ptr = dhcpv6_server_ptr -> nx_dhcpv6_ip_ptr ; ga_address_index = dhcpv6_server_ptr -> nx_dhcpv6_server_ga_address_index ; prefix_length = ip_ptr -> nx_ipv6_address [ ga_address_index ] . nxd_ipv6_address_prefix_length ; if ( ! CHECK_IP_ADDRESSES_BY_PREFIX ( & ( ip_ptr -> nx_ipv6_address [ ga_address_index ] . nxd_ipv6_address [ 0 ] ) , & start_ipv6_address -> nxd_ip_address . v6 [ 0 ] , prefix_length ) ) { return NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS ; } if ( ! CHECK_IP_ADDRESSES_BY_PREFIX ( & ( ip_ptr -> nx_ipv6_address [ ga_address_index ] . nxd_ipv6_address [ 0 ] ) , & end_ipv6_address -> nxd_ip_address . v6 [ 0 ] , prefix_length ) ) { return NX_DHCPV6_INVALID_INTERFACE_IP_ADDRESS ; } i = 0 ; while ( i < NX_DHCPV6_MAX_LEASES ) { NX_DHCPV6_ADDRESS_LEASE * ip_lease_ptr ; ip_lease_ptr = & dhcpv6_server_ptr -> nx_dhcpv6_lease_list [ i ] ; memset ( & dhcpv6_server_ptr -> nx_dhcpv6_lease_list [ i ] , 0 , sizeof ( NX_DHCPV6_ADDRESS_LEASE ) ) ; COPY_NXD_ADDRESS ( & next_ipv6_address , & ip_lease_ptr -> nx_dhcpv6_lease_IP_address ) ; ( * addresses_added ) ++ ; next_ipv6_address . nxd_ip_address . v6 [ 3 ] ++ ; if ( next_ipv6_address . nxd_ip_address . v6 [ 3 ] == 0xFFFFFFFF ) { break ; } if ( CHECK_IPV6_ADDRESSES_SAME ( & next_ipv6_address . nxd_ip_address . v6 [ 0 ] , & end_ipv6_address -> nxd_ip_address . v6 [ 0 ] ) ) { break ; } i ++ ; } dhcpv6_server_ptr -> nx_dhcpv6_assignable_addresses = * addresses_added ; return ( NX_SUCCESS ) ; }
FUNCTION                                               RELEASE
FUNCTION RELEASE
/* Set up a local variable for convenience. */ /* Verify the input addresses match the server interface address prefix (in IPv4 terms, the
       network masked addresses should be equal). */ /* Set the server ip address based on the specified interface. */ /* Clear out existing entries and start adding IP addresses at the beginning of the list. */ /* Fit as many IP addresses in the specified range as will fit in the table. */ /* Set local pointer to the next entry for convenience. */ /* Initialize each entry before adding data.  */ /* Add the IP address into this slot. */ /* Update the number of addresses added. */ /* Increase the address low word by one. */ /* Check if we are overflowing the last word. */ /* We are. Let's stop here. */ /* Indicate how many addresses were actually added to the server list. */