214 lines
6.5 KiB
C
214 lines
6.5 KiB
C
|
|
/*
|
|
******************************************************************************
|
|
* INTERPEAK SOURCE FILE
|
|
*
|
|
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmip6_icmp_pkt.c,v $ $Revision: 1.29 $
|
|
* $Source: /home/interpeak/CVSRoot/ipmip6/src/ipmip6_icmp_pkt.c,v $
|
|
* $Author: jhorteli $
|
|
* $State: Exp $ $Locker: $
|
|
*
|
|
* INTERPEAK_COPYRIGHT_STRING
|
|
* Design and implementation by Joel Hortelius <joel.hortelis@interpeak.se>
|
|
******************************************************************************
|
|
*/
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 1 DESCRIPTION
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 2 CONFIGURATION
|
|
****************************************************************************
|
|
*/
|
|
#include "ipmip6_config.h"
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 3 INCLUDE FILES
|
|
****************************************************************************
|
|
*/
|
|
#define IPCOM_USE_CLIB_PROTO
|
|
#include <ipcom_clib.h>
|
|
#include <ipcom_os.h>
|
|
#include <ipcom_sock.h>
|
|
#include <ipcom_sock6.h>
|
|
#include <ipcom_inet.h>
|
|
#include <ipcom_list.h>
|
|
#include <ipcom_syslog.h>
|
|
|
|
#include <ipmip.h>
|
|
|
|
#include "ipmip6_h.h"
|
|
#include <private/ipmip6_context.h>
|
|
#include <private/ipmip6_if.h>
|
|
#include <private/ipmip6_icmp_pkt.h>
|
|
#include <private/ipmip6_nd_nud.h>
|
|
#include <private/ipmip6_nd_proxy.h>
|
|
#include <private/ipmip6_util.h>
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 4 DEFINES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 5 TYPES
|
|
****************************************************************************
|
|
*/
|
|
typedef struct Ipmip6_icmp_pkt_opt_hdr
|
|
{
|
|
Ip_u8 type;
|
|
Ip_u8 len;
|
|
}
|
|
Ipmip6_icmp_pkt_opt_hdr_t;
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 6 EXTERN PROTOTYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 7 LOCAL PROTOTYPES
|
|
****************************************************************************
|
|
*/
|
|
typedef struct Ipmip6_icmp_pkt
|
|
{
|
|
Ipmip6_pktbuf_t pkt; /* Basic Packet */
|
|
|
|
/* Mobility Header specific extensions */
|
|
Ipcom_list opt_icmp; /* MH Options */
|
|
}
|
|
Ipmip6_icmp_pkt_t;
|
|
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 8 DATA
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 9 STATIC FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 10 GLOBAL FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipmip6_mh_pkt_opt_add
|
|
*===========================================================================
|
|
* Description: Adds an option to the tail of the packet option list, and
|
|
* calculates the necessary padding based on the alignment
|
|
* requirements.
|
|
* Parameters: pkt - The packet pointer.
|
|
* type - The option type value.
|
|
* len - The length of data
|
|
* data - The data, or IP_NULL if an empty option is to be
|
|
* added.
|
|
* Returns: IP_TRUE if added, IP_FALSE otherwise.
|
|
*
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipmip6_icmp_pkt_opt_add(Ipmip6_context_t *ctx,
|
|
Ipmip_proc_t *proc,
|
|
Ipmip6_pktbuf_t *pkt,
|
|
Ip_u8 type,
|
|
Ip_u8 len,
|
|
void* data)
|
|
{
|
|
Ipmip6_icmp_pkt_opt_hdr_t *iopt;
|
|
Ip_u32 size = len + 2;
|
|
|
|
IPMIP_UNUSED_PARAMETER(ctx);
|
|
IPMIP_UNUSED_PARAMETER(proc);
|
|
|
|
/* Sanity. Length + type + len field, must be multiple of 8 */
|
|
if ((size & 7) != 0)
|
|
return IP_FALSE;
|
|
|
|
iopt = ipmip_buffer_get(&pkt->ipmip.packet, sizeof(*iopt));
|
|
|
|
/* Set the basic values */
|
|
iopt->type = type;
|
|
iopt->len = (Ip_u8) (size >> 3);
|
|
|
|
ipmip_buffer_append(&pkt->ipmip.packet, data, len);
|
|
|
|
/* All done */
|
|
return IP_TRUE;
|
|
}
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipmip6_mh_pkt_alloc
|
|
*===========================================================================
|
|
* Description: Allocates a new ICMP header of size bytes.
|
|
* Parameters: context - The context
|
|
* size - The size of the ICMP payload.
|
|
* type - The MH type.
|
|
* code - The ICMP code.
|
|
* Returns: A packet pointer, or IP_NULL if failure.
|
|
*
|
|
*/
|
|
IP_GLOBAL Ipmip6_pktbuf_t *
|
|
ipmip6_icmp_pkt_alloc(Ipmip6_context_t *ctx,
|
|
Ipmip_proc_t *proc,
|
|
Ip_u16 size,
|
|
Ip_u8 type,
|
|
Ip_u8 code)
|
|
{
|
|
Ipmip6_pktbuf_t *pkt = (Ipmip6_pktbuf_t *)ipmip_pktbuf_alloc(&ctx->ipmip, proc, sizeof(Ipmip6_pkt_icmp6_t) + size);
|
|
|
|
if (pkt != IP_NULL)
|
|
{
|
|
/* Grab the payload */
|
|
Ipmip6_pkt_icmp6_t *icmp;
|
|
|
|
ipmip_buffer_append(&pkt->ipmip.packet, IP_NULL, sizeof(Ipmip6_pkt_icmp6_t) + size);
|
|
|
|
icmp = (Ipmip6_pkt_icmp6_t *) IPMIP_BUFFER_PTR(&pkt->ipmip.packet);
|
|
|
|
/**/
|
|
ipcom_memset(icmp, 0, sizeof(*icmp));
|
|
|
|
/**/
|
|
icmp->icmp6_type = type;
|
|
icmp->icmp6_code = code;
|
|
}
|
|
|
|
/* OK */
|
|
return pkt;
|
|
}
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 11 PUBLIC FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* END OF FILE
|
|
****************************************************************************
|
|
*/
|