AzureMXChip/MXCHIPAZ3166/core/lib/netxduo/addons/dhcp/nxd_dhcpv6_server.c
UINT _nx_dhcpv6_add_ia(NX_DHCPV6_SERVER *dhcpv6_server_ptr, NX_DHCPV6_SERVER_IA_ADDRESS *dhcpv6_ia_ptr, UCHAR *buffer_ptr, UINT *index)
{

ULONG   message_word;
UINT    available_payload;


    /* Compute the available payload in the packet buffer. */
    available_payload = dhcpv6_server_ptr -> nx_dhcpv6_packet_pool_ptr -> nx_packet_pool_payload_size - 
                        NX_IPv6_UDP_PACKET - *index;

    /* Check if the client IA address option will fit in the packet buffer. */
    if (available_payload < (UINT)(dhcpv6_ia_ptr -> nx_option_length + 4)) 
    {

        /* Hmmm... not enough! Can't do it. */
        return NX_DHCPV6_INSUFFICIENT_PACKET_PAYLOAD;
    }

    /* If the client has created an address option, apply it to the message. */

    /* Clear memory to make the first word of the IA-Address header. */
    memset(&message_word, 0, sizeof(ULONG));

    /* Compile the header from the IA option on the client record. */
    message_word = (ULONG)(dhcpv6_ia_ptr -> nx_op_code << 16);
    message_word |= dhcpv6_ia_ptr -> nx_option_length;

    /* Adjust for endianness. */
    NX_CHANGE_ULONG_ENDIAN(message_word);

    /* Copy option header into the packet and update the index into the buffer. */
    memcpy(buffer_ptr + *index, &message_word, sizeof(ULONG)); /* Use case of memcpy is verified. */
    *index += (ULONG)sizeof(ULONG);

    /* Adjust for endianness. */
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[0]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[1]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[2]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[3]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_preferred_lifetime);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_valid_lifetime);

    /* Copy the IPv6 address to the packet. */
    memcpy(buffer_ptr + *index, &(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[0]), sizeof(ULONG)); /* Use case of memcpy is verified. */
    *index += (ULONG)sizeof(ULONG);

    memcpy(buffer_ptr + *index, &(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[1]), sizeof(ULONG)); /* Use case of memcpy is verified. */
    *index += (ULONG)sizeof(ULONG);

    memcpy(buffer_ptr + *index, &(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[2]), sizeof(ULONG)); /* Use case of memcpy is verified. */
    *index += (ULONG)sizeof(ULONG);

    memcpy(buffer_ptr + *index, &(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[3]), sizeof(ULONG)); /* Use case of memcpy is verified. */
    *index += (ULONG)sizeof(ULONG);

    /* Copy the Client's preference for lifetimes to packet. */
    memcpy(buffer_ptr + *index, &(dhcpv6_ia_ptr -> nx_preferred_lifetime), sizeof(ULONG)); /* Use case of memcpy is verified. */
    *index += (ULONG)sizeof(ULONG);

    memcpy(buffer_ptr + *index, &(dhcpv6_ia_ptr -> nx_valid_lifetime), sizeof(ULONG)); /* Use case of memcpy is verified. */
    *index += (ULONG)sizeof(ULONG);

    /* Swap bytes back. */
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[0]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[1]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[2]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[3]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_preferred_lifetime);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_valid_lifetime);

    return NX_SUCCESS;
}
/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nx_dhcpv6_add_ia                                   PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function adds the IA address option to the server response     */
/*    packet using the input IA option.                                   */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    dhcpv6_server_ptr                 Pointer to DHCPV6 server instance */
/*    dhcpv6_ia_ptr                     Pointer to IA to add              */
/*    buffer_ptr                        Pointer to response packet buffer */
/*    index                             Location into buffer to write data*/
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    NX_SUCCESS                        Successful completion status      */
/*    NX_DHCPV6_INSUFFICIENT_PACKET_PAYLOAD                               */
/*                                      Buffer to small for IA option     */
/*  CALLS                                                                 */
/*                                                                        */
/*    memset                            Clears specified area of memory   */
/*    memcpy                            Copies specified area of memory   */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    _nx_dhcpv6_server_add_iana         Adds the IANA to server response */
/*                                                                        */
/*  RELEASE HISTORY                                                       */
/*                                                                        */
/*    DATE              NAME                      DESCRIPTION             */
/*                                                                        */
/*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
/*  09-30-2020     Yuxin Zhou               Modified comment(s), and      */
/*                                            verified memcpy use cases,  */
/*                                            resulting in version 6.1    */
/*                                                                        */
/**************************************************************************/
FUNCTION                                               RELEASE

_nx_dhcpv6_add_ia                                   PORTABLE C
6.1
AUTHOR

Yuxin Zhou, Microsoft Corporation

DESCRIPTION

This function adds the IA address option to the server response
packet using the input IA option.

INPUT

dhcpv6_server_ptr                 Pointer to DHCPV6 server instance
dhcpv6_ia_ptr                     Pointer to IA to add
buffer_ptr                        Pointer to response packet buffer
index                             Location into buffer to write data

OUTPUT

NX_SUCCESS                        Successful completion status
NX_DHCPV6_INSUFFICIENT_PACKET_PAYLOAD
Buffer to small for IA option
CALLS

memset                            Clears specified area of memory
memcpy                            Copies specified area of memory

CALLED BY

_nx_dhcpv6_server_add_iana         Adds the IANA to server response

RELEASE HISTORY

DATE              NAME                      DESCRIPTION

05-19-2020     Yuxin Zhou               Initial Version 6.0
09-30-2020     Yuxin Zhou               Modified comment(s), and
verified memcpy use cases,
resulting in version 6.1
FUNCTION RELEASE _nx_dhcpv6_add_ia PORTABLE C 6 . 1 AUTHOR Yuxin Zhou Microsoft Corporation DESCRIPTION This function adds the IA address option to the server response packet using the input IA option . INPUT dhcpv6_server_ptr Pointer to DHCPV6 server instance dhcpv6_ia_ptr Pointer to IA to add buffer_ptr Pointer to response packet buffer index Location into buffer to write data OUTPUT NX_SUCCESS Successful completion status NX_DHCPV6_INSUFFICIENT_PACKET_PAYLOAD Buffer to small for IA option CALLS memset Clears specified area of memory memcpy Copies specified area of memory CALLED BY _nx_dhcpv6_server_add_iana Adds the IANA to server response RELEASE HISTORY DATE NAME DESCRIPTION 05 - 19 - 2020 Yuxin Zhou Initial Version 6 . 0 09 - 30 - 2020 Yuxin Zhou Modified comment ( s ) and verified memcpy use cases resulting in version 6 . 1
UINT _nx_dhcpv6_add_ia(NX_DHCPV6_SERVER *dhcpv6_server_ptr, NX_DHCPV6_SERVER_IA_ADDRESS *dhcpv6_ia_ptr, UCHAR *buffer_ptr, UINT *index)
{
ULONG   message_word;
UINT    available_payload;
    available_payload = dhcpv6_server_ptr -> nx_dhcpv6_packet_pool_ptr -> nx_packet_pool_payload_size - 
                        NX_IPv6_UDP_PACKET - *index;
    if (available_payload < (UINT)(dhcpv6_ia_ptr -> nx_option_length + 4)) 
    {
        return NX_DHCPV6_INSUFFICIENT_PACKET_PAYLOAD;
    }
    memset(&message_word, 0, sizeof(ULONG));
    message_word = (ULONG)(dhcpv6_ia_ptr -> nx_op_code << 16);
    message_word |= dhcpv6_ia_ptr -> nx_option_length;
    NX_CHANGE_ULONG_ENDIAN(message_word);
    memcpy(buffer_ptr + *index, &message_word, sizeof(ULONG)); 
    *index += (ULONG)sizeof(ULONG);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[0]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[1]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[2]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[3]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_preferred_lifetime);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_valid_lifetime);
    memcpy(buffer_ptr + *index, &(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[0]), sizeof(ULONG)); 
    *index += (ULONG)sizeof(ULONG);
    memcpy(buffer_ptr + *index, &(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[1]), sizeof(ULONG)); 
    *index += (ULONG)sizeof(ULONG);
    memcpy(buffer_ptr + *index, &(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[2]), sizeof(ULONG)); 
    *index += (ULONG)sizeof(ULONG);
    memcpy(buffer_ptr + *index, &(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[3]), sizeof(ULONG)); 
    *index += (ULONG)sizeof(ULONG);
    memcpy(buffer_ptr + *index, &(dhcpv6_ia_ptr -> nx_preferred_lifetime), sizeof(ULONG)); 
    *index += (ULONG)sizeof(ULONG);
    memcpy(buffer_ptr + *index, &(dhcpv6_ia_ptr -> nx_valid_lifetime), sizeof(ULONG)); 
    *index += (ULONG)sizeof(ULONG);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[0]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[1]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[2]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_global_address.nxd_ip_address.v6[3]);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_preferred_lifetime);
    NX_CHANGE_ULONG_ENDIAN(dhcpv6_ia_ptr -> nx_valid_lifetime);
    return NX_SUCCESS;
}
UINT _nx_dhcpv6_add_ia ( NX_DHCPV6_SERVER * dhcpv6_server_ptr , NX_DHCPV6_SERVER_IA_ADDRESS * dhcpv6_ia_ptr , UCHAR * buffer_ptr , UINT * index ) { ULONG message_word ; UINT available_payload ; available_payload = dhcpv6_server_ptr -> nx_dhcpv6_packet_pool_ptr -> nx_packet_pool_payload_size - NX_IPv6_UDP_PACKET - * index ; if ( available_payload < ( UINT ) ( dhcpv6_ia_ptr -> nx_option_length + 4 ) ) { return NX_DHCPV6_INSUFFICIENT_PACKET_PAYLOAD ; } memset ( & message_word , 0 , sizeof ( ULONG ) ) ; message_word = ( ULONG ) ( dhcpv6_ia_ptr -> nx_op_code << 16 ) ; message_word |= dhcpv6_ia_ptr -> nx_option_length ; NX_CHANGE_ULONG_ENDIAN ( message_word ) ; memcpy ( buffer_ptr + * index , & message_word , sizeof ( ULONG ) ) ; * index += ( ULONG ) sizeof ( ULONG ) ; NX_CHANGE_ULONG_ENDIAN ( dhcpv6_ia_ptr -> nx_global_address . nxd_ip_address . v6 [ 0 ] ) ; NX_CHANGE_ULONG_ENDIAN ( dhcpv6_ia_ptr -> nx_global_address . nxd_ip_address . v6 [ 1 ] ) ; NX_CHANGE_ULONG_ENDIAN ( dhcpv6_ia_ptr -> nx_global_address . nxd_ip_address . v6 [ 2 ] ) ; NX_CHANGE_ULONG_ENDIAN ( dhcpv6_ia_ptr -> nx_global_address . nxd_ip_address . v6 [ 3 ] ) ; NX_CHANGE_ULONG_ENDIAN ( dhcpv6_ia_ptr -> nx_preferred_lifetime ) ; NX_CHANGE_ULONG_ENDIAN ( dhcpv6_ia_ptr -> nx_valid_lifetime ) ; memcpy ( buffer_ptr + * index , & ( dhcpv6_ia_ptr -> nx_global_address . nxd_ip_address . v6 [ 0 ] ) , sizeof ( ULONG ) ) ; * index += ( ULONG ) sizeof ( ULONG ) ; memcpy ( buffer_ptr + * index , & ( dhcpv6_ia_ptr -> nx_global_address . nxd_ip_address . v6 [ 1 ] ) , sizeof ( ULONG ) ) ; * index += ( ULONG ) sizeof ( ULONG ) ; memcpy ( buffer_ptr + * index , & ( dhcpv6_ia_ptr -> nx_global_address . nxd_ip_address . v6 [ 2 ] ) , sizeof ( ULONG ) ) ; * index += ( ULONG ) sizeof ( ULONG ) ; memcpy ( buffer_ptr + * index , & ( dhcpv6_ia_ptr -> nx_global_address . nxd_ip_address . v6 [ 3 ] ) , sizeof ( ULONG ) ) ; * index += ( ULONG ) sizeof ( ULONG ) ; memcpy ( buffer_ptr + * index , & ( dhcpv6_ia_ptr -> nx_preferred_lifetime ) , sizeof ( ULONG ) ) ; * index += ( ULONG ) sizeof ( ULONG ) ; memcpy ( buffer_ptr + * index , & ( dhcpv6_ia_ptr -> nx_valid_lifetime ) , sizeof ( ULONG ) ) ; * index += ( ULONG ) sizeof ( ULONG ) ; NX_CHANGE_ULONG_ENDIAN ( dhcpv6_ia_ptr -> nx_global_address . nxd_ip_address . v6 [ 0 ] ) ; NX_CHANGE_ULONG_ENDIAN ( dhcpv6_ia_ptr -> nx_global_address . nxd_ip_address . v6 [ 1 ] ) ; NX_CHANGE_ULONG_ENDIAN ( dhcpv6_ia_ptr -> nx_global_address . nxd_ip_address . v6 [ 2 ] ) ; NX_CHANGE_ULONG_ENDIAN ( dhcpv6_ia_ptr -> nx_global_address . nxd_ip_address . v6 [ 3 ] ) ; NX_CHANGE_ULONG_ENDIAN ( dhcpv6_ia_ptr -> nx_preferred_lifetime ) ; NX_CHANGE_ULONG_ENDIAN ( dhcpv6_ia_ptr -> nx_valid_lifetime ) ; return NX_SUCCESS ; }
FUNCTION                                               RELEASE
FUNCTION RELEASE
/* Compute the available payload in the packet buffer. */ /* Check if the client IA address option will fit in the packet buffer. */ /* Hmmm... not enough! Can't do it. */ /* If the client has created an address option, apply it to the message. */ /* Clear memory to make the first word of the IA-Address header. */ /* Compile the header from the IA option on the client record. */ /* Adjust for endianness. */ /* Copy option header into the packet and update the index into the buffer. */ /* Use case of memcpy is verified. */ /* Adjust for endianness. */ /* Copy the IPv6 address to the packet. */ /* Use case of memcpy is verified. */ /* Use case of memcpy is verified. */ /* Use case of memcpy is verified. */ /* Use case of memcpy is verified. */ /* Copy the Client's preference for lifetimes to packet. */ /* Use case of memcpy is verified. */ /* Use case of memcpy is verified. */ /* Swap bytes back. */