AzureMXChip/MXCHIPAZ3166/core/lib/netxduo/addons/dhcp/nxd_dhcpv6_server.c
UINT _nx_dhcpv6_retrieve_client_record(NX_DHCPV6_SERVER *dhcpv6_server_ptr, UINT table_index, ULONG *message_xid, NXD_ADDRESS *client_address, UINT *client_state, 
                                  ULONG *IP_lease_time_accrued, ULONG *valid_lifetime, UINT *duid_type,  UINT *duid_hardware, ULONG *physical_address_msw, 
                                  ULONG *physical_address_lsw, ULONG *duid_time, ULONG *duid_vendor_number, UCHAR *duid_vendor_private, UINT *duid_private_length)
{

NX_DHCPV6_CLIENT *client_ptr;
INT              length;


    /* Get a local pointer for convenience. */
    client_ptr = &(dhcpv6_server_ptr ->nx_dhcpv6_clients[table_index]);

    /* Load the generic client data. */
    *message_xid = client_ptr -> nx_dhcpv6_message_xid;

    /* Is this an empty record? */
    if (*message_xid == 0)
    {

        /* Yes so return null data. */
        memset(client_address, 0, sizeof(NXD_ADDRESS));
        *client_state = 0;
        *IP_lease_time_accrued = 0;
        *valid_lifetime = 0;
        *duid_type  = 0;
        if (duid_hardware)
            *duid_hardware = 0;
        if (physical_address_msw)
            *physical_address_msw = 0;
        if (physical_address_lsw)
            *physical_address_lsw = 0;
        if (duid_time)
            *duid_time = 0;
        if (duid_vendor_number)
            *duid_vendor_number = 0;
        if (duid_private_length)
            *duid_private_length = 0;

        return NX_SUCCESS;
    }

    /* Not an empty record. Extract the data! */
    COPY_NXD_ADDRESS(&(client_ptr -> nx_dhcpv6_ia.nx_global_address), client_address);
    *client_state = client_ptr -> nx_dhcpv6_state;
    *IP_lease_time_accrued = client_ptr -> nx_dhcpv6_IP_lease_time_accrued;
    *valid_lifetime = client_ptr -> nx_dhcpv6_ia.nx_valid_lifetime;
    *duid_type  = client_ptr -> nx_dhcpv6_client_duid.nx_duid_type;

    /* If this is a LINK LAYER Duid type, load the appropriate data. */
    if ((*duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_ONLY) || (*duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_TIME))
    {

        /* Check for invalid pointer input for DUID of the link layer type. */
        if ((duid_hardware == NX_NULL) || (physical_address_msw == NX_NULL) || (physical_address_lsw == NX_NULL))
        {
            return NX_PTR_ERROR;
        }

        *duid_hardware = client_ptr -> nx_dhcpv6_client_duid.nx_hardware_type;
        *physical_address_msw = client_ptr -> nx_dhcpv6_client_duid.nx_link_layer_address_msw;
        *physical_address_lsw = client_ptr -> nx_dhcpv6_client_duid.nx_link_layer_address_lsw;

        if (*duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_TIME)
        {

            if (duid_time == NX_NULL)
            {
                return NX_PTR_ERROR;
            }

            *duid_time = client_ptr -> nx_dhcpv6_client_duid.nx_duid_time;
        }
    }
    else
    {

        /* Client DUID type is vendor assigned. */

        /* Check for valid pointer input for enterprise ID data */
        if ((duid_vendor_number == NX_NULL) || (duid_vendor_private == NX_NULL) || (duid_private_length == NX_NULL))
        {
            return NX_PTR_ERROR;
        }

       *duid_vendor_number = client_ptr -> nx_dhcpv6_client_duid.nx_duid_enterprise_number;
       length = client_ptr -> nx_dhcpv6_client_duid.nx_option_length - 6;
       if (length < 0)
       {
           return NX_DHCPV6_INVALID_DUID;
       }

       /* NOTE: The duid_vendor_private buffer is provided by user, and the buffer size must be not less than NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_LENGTH.  */
       memcpy(duid_vendor_private, &(client_ptr -> nx_dhcpv6_client_duid.nx_duid_private_identifier[0]), (UINT)length); /* Use case of memcpy is verified. The buffer is provided by user.  */
       *duid_private_length = (UINT)length;
    }

   return NX_SUCCESS;
}
/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nx_dhcpv6_retrieve_client_record                   PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*   This function returns DHCPv6 Client record data at the specified     */
/*   index into the server table to the caller.  Note that if a slot in   */
/*   the server's client table is empty, evidenced by a zero transaction  */
/*   ID, the service returns null data in all parameters with a successful*/
/*   completion status.                                                   */
/*                                                                        */
/*   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 client data */
/*    message_xid                        Client transaction ID            */
/*    client_address                     IP address leased to client      */
/*    client_state                       Client DHCPv6 state e.g. bound   */
/*    IP_lease_time_accrued              Time expired on current IP lease */
/*    valid_lifetime                     When address becomes invalid     */
/*    duid_type                          Type of Client DUID              */
/*    duid_hardware                      DUID hardware (usually ethernet) */
/*    physical_address_msw               MSB of client mac address        */
/*    physical_address_lsw               LSB of client mac address        */
/*    duid_time                          Time for link layer time DUID    */
/*    duid_vendor_number                 Enterprise ID for Vendor DUID    */
/*    duid_vendor_private                Pointer to private ID for DUID   */
/*    duid_private_length                Vendor Duid private ID length    */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    NX_SUCCESS                         Successful IP address copy       */
/*    NX_PTR_ERROR                       Invalid pointer input            */
/*    NX_INVALID_PARAMETERS              Invalid non pointer input        */
/*    NX_DHCPV6_INVALID_DUID             Malformed DUID retrieved         */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    COPY_NXD_ADDRESS                   Copy IPv6 address to specified   */
/*                                         memory (holding an IPv6 address*/
/*                                                                        */
/*  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), corrected*/
/*                                            the length of identifier,   */
/*                                            resulting in version 6.1    */
/*                                                                        */
/**************************************************************************/
FUNCTION                                               RELEASE

_nx_dhcpv6_retrieve_client_record                   PORTABLE C
6.1
AUTHOR

Yuxin Zhou, Microsoft Corporation

DESCRIPTION

This function returns DHCPv6 Client record data at the specified
index into the server table to the caller.  Note that if a slot in
the server's client table is empty, evidenced by a zero transaction
ID, the service returns null data in all parameters with a successful
completion status.

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 client data
message_xid                        Client transaction ID
client_address                     IP address leased to client
client_state                       Client DHCPv6 state e.g. bound
IP_lease_time_accrued              Time expired on current IP lease
valid_lifetime                     When address becomes invalid
duid_type                          Type of Client DUID
duid_hardware                      DUID hardware (usually ethernet)
physical_address_msw               MSB of client mac address
physical_address_lsw               LSB of client mac address
duid_time                          Time for link layer time DUID
duid_vendor_number                 Enterprise ID for Vendor DUID
duid_vendor_private                Pointer to private ID for DUID
duid_private_length                Vendor Duid private ID length

OUTPUT

NX_SUCCESS                         Successful IP address copy
NX_PTR_ERROR                       Invalid pointer input
NX_INVALID_PARAMETERS              Invalid non pointer input
NX_DHCPV6_INVALID_DUID             Malformed DUID retrieved

CALLS

COPY_NXD_ADDRESS                   Copy IPv6 address to specified
memory (holding an IPv6 address

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), corrected
the length of identifier,
resulting in version 6.1
FUNCTION RELEASE _nx_dhcpv6_retrieve_client_record PORTABLE C 6 . 1 AUTHOR Yuxin Zhou Microsoft Corporation DESCRIPTION This function returns DHCPv6 Client record data at the specified index into the server table to the caller . Note that if a slot in the server ' s client table is empty evidenced by a zero transaction ID the service returns null data in all parameters with a successful completion status . 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 client data message_xid Client transaction ID client_address IP address leased to client client_state Client DHCPv6 state e . g . bound IP_lease_time_accrued Time expired on current IP lease valid_lifetime When address becomes invalid duid_type Type of Client DUID duid_hardware DUID hardware ( usually ethernet ) physical_address_msw MSB of client mac address physical_address_lsw LSB of client mac address duid_time Time for link layer time DUID duid_vendor_number Enterprise ID for Vendor DUID duid_vendor_private Pointer to private ID for DUID duid_private_length Vendor Duid private ID length OUTPUT NX_SUCCESS Successful IP address copy NX_PTR_ERROR Invalid pointer input NX_INVALID_PARAMETERS Invalid non pointer input NX_DHCPV6_INVALID_DUID Malformed DUID retrieved CALLS COPY_NXD_ADDRESS Copy IPv6 address to specified memory ( holding an IPv6 address 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 ) corrected the length of identifier resulting in version 6 . 1
UINT _nx_dhcpv6_retrieve_client_record(NX_DHCPV6_SERVER *dhcpv6_server_ptr, UINT table_index, ULONG *message_xid, NXD_ADDRESS *client_address, UINT *client_state, 
                                  ULONG *IP_lease_time_accrued, ULONG *valid_lifetime, UINT *duid_type,  UINT *duid_hardware, ULONG *physical_address_msw, 
                                  ULONG *physical_address_lsw, ULONG *duid_time, ULONG *duid_vendor_number, UCHAR *duid_vendor_private, UINT *duid_private_length)
{
NX_DHCPV6_CLIENT *client_ptr;
INT              length;
    client_ptr = &(dhcpv6_server_ptr ->nx_dhcpv6_clients[table_index]);
    *message_xid = client_ptr -> nx_dhcpv6_message_xid;
    if (*message_xid == 0)
    {
        memset(client_address, 0, sizeof(NXD_ADDRESS));
        *client_state = 0;
        *IP_lease_time_accrued = 0;
        *valid_lifetime = 0;
        *duid_type  = 0;
        if (duid_hardware)
            *duid_hardware = 0;
        if (physical_address_msw)
            *physical_address_msw = 0;
        if (physical_address_lsw)
            *physical_address_lsw = 0;
        if (duid_time)
            *duid_time = 0;
        if (duid_vendor_number)
            *duid_vendor_number = 0;
        if (duid_private_length)
            *duid_private_length = 0;
        return NX_SUCCESS;
    }
    COPY_NXD_ADDRESS(&(client_ptr -> nx_dhcpv6_ia.nx_global_address), client_address);
    *client_state = client_ptr -> nx_dhcpv6_state;
    *IP_lease_time_accrued = client_ptr -> nx_dhcpv6_IP_lease_time_accrued;
    *valid_lifetime = client_ptr -> nx_dhcpv6_ia.nx_valid_lifetime;
    *duid_type  = client_ptr -> nx_dhcpv6_client_duid.nx_duid_type;
    if ((*duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_ONLY) || (*duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_TIME))
    {
        if ((duid_hardware == NX_NULL) || (physical_address_msw == NX_NULL) || (physical_address_lsw == NX_NULL))
        {
            return NX_PTR_ERROR;
        }
        *duid_hardware = client_ptr -> nx_dhcpv6_client_duid.nx_hardware_type;
        *physical_address_msw = client_ptr -> nx_dhcpv6_client_duid.nx_link_layer_address_msw;
        *physical_address_lsw = client_ptr -> nx_dhcpv6_client_duid.nx_link_layer_address_lsw;
        if (*duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_TIME)
        {
            if (duid_time == NX_NULL)
            {
                return NX_PTR_ERROR;
            }
            *duid_time = client_ptr -> nx_dhcpv6_client_duid.nx_duid_time;
        }
    }
    else
    {
        if ((duid_vendor_number == NX_NULL) || (duid_vendor_private == NX_NULL) || (duid_private_length == NX_NULL))
        {
            return NX_PTR_ERROR;
        }
       *duid_vendor_number = client_ptr -> nx_dhcpv6_client_duid.nx_duid_enterprise_number;
       length = client_ptr -> nx_dhcpv6_client_duid.nx_option_length - 6;
       if (length < 0)
       {
           return NX_DHCPV6_INVALID_DUID;
       }
       memcpy(duid_vendor_private, &(client_ptr -> nx_dhcpv6_client_duid.nx_duid_private_identifier[0]), (UINT)length); 
       *duid_private_length = (UINT)length;
    }
   return NX_SUCCESS;
}
UINT _nx_dhcpv6_retrieve_client_record ( NX_DHCPV6_SERVER * dhcpv6_server_ptr , UINT table_index , ULONG * message_xid , NXD_ADDRESS * client_address , UINT * client_state , ULONG * IP_lease_time_accrued , ULONG * valid_lifetime , UINT * duid_type , UINT * duid_hardware , ULONG * physical_address_msw , ULONG * physical_address_lsw , ULONG * duid_time , ULONG * duid_vendor_number , UCHAR * duid_vendor_private , UINT * duid_private_length ) { NX_DHCPV6_CLIENT * client_ptr ; INT length ; client_ptr = & ( dhcpv6_server_ptr -> nx_dhcpv6_clients [ table_index ] ) ; * message_xid = client_ptr -> nx_dhcpv6_message_xid ; if ( * message_xid == 0 ) { memset ( client_address , 0 , sizeof ( NXD_ADDRESS ) ) ; * client_state = 0 ; * IP_lease_time_accrued = 0 ; * valid_lifetime = 0 ; * duid_type = 0 ; if ( duid_hardware ) * duid_hardware = 0 ; if ( physical_address_msw ) * physical_address_msw = 0 ; if ( physical_address_lsw ) * physical_address_lsw = 0 ; if ( duid_time ) * duid_time = 0 ; if ( duid_vendor_number ) * duid_vendor_number = 0 ; if ( duid_private_length ) * duid_private_length = 0 ; return NX_SUCCESS ; } COPY_NXD_ADDRESS ( & ( client_ptr -> nx_dhcpv6_ia . nx_global_address ) , client_address ) ; * client_state = client_ptr -> nx_dhcpv6_state ; * IP_lease_time_accrued = client_ptr -> nx_dhcpv6_IP_lease_time_accrued ; * valid_lifetime = client_ptr -> nx_dhcpv6_ia . nx_valid_lifetime ; * duid_type = client_ptr -> nx_dhcpv6_client_duid . nx_duid_type ; if ( ( * duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_ONLY ) || ( * duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_TIME ) ) { if ( ( duid_hardware == NX_NULL ) || ( physical_address_msw == NX_NULL ) || ( physical_address_lsw == NX_NULL ) ) { return NX_PTR_ERROR ; } * duid_hardware = client_ptr -> nx_dhcpv6_client_duid . nx_hardware_type ; * physical_address_msw = client_ptr -> nx_dhcpv6_client_duid . nx_link_layer_address_msw ; * physical_address_lsw = client_ptr -> nx_dhcpv6_client_duid . nx_link_layer_address_lsw ; if ( * duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_TIME ) { if ( duid_time == NX_NULL ) { return NX_PTR_ERROR ; } * duid_time = client_ptr -> nx_dhcpv6_client_duid . nx_duid_time ; } } else { if ( ( duid_vendor_number == NX_NULL ) || ( duid_vendor_private == NX_NULL ) || ( duid_private_length == NX_NULL ) ) { return NX_PTR_ERROR ; } * duid_vendor_number = client_ptr -> nx_dhcpv6_client_duid . nx_duid_enterprise_number ; length = client_ptr -> nx_dhcpv6_client_duid . nx_option_length - 6 ; if ( length < 0 ) { return NX_DHCPV6_INVALID_DUID ; } memcpy ( duid_vendor_private , & ( client_ptr -> nx_dhcpv6_client_duid . nx_duid_private_identifier [ 0 ] ) , ( UINT ) length ) ; * duid_private_length = ( UINT ) length ; } return NX_SUCCESS ; }
FUNCTION                                               RELEASE
FUNCTION RELEASE
/* Get a local pointer for convenience. */ /* Load the generic client data. */ /* Is this an empty record? */ /* Yes so return null data. */ /* Not an empty record. Extract the data! */ /* If this is a LINK LAYER Duid type, load the appropriate data. */ /* Check for invalid pointer input for DUID of the link layer type. */ /* Client DUID type is vendor assigned. */ /* Check for valid pointer input for enterprise ID data */ /* NOTE: The duid_vendor_private buffer is provided by user, and the buffer size must be not less than NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_LENGTH.  */ /* Use case of memcpy is verified. The buffer is provided by user.  */