283 lines
9.0 KiB
C
283 lines
9.0 KiB
C
|
|
/*
|
|
******************************************************************************
|
|
* INTERPEAK SOURCE FILE
|
|
*
|
|
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipl2tp_message.c,v $ $Revision: 1.2 $
|
|
* $Source: /home/interpeak/CVSRoot/ipl2tp/src/ipl2tp_message.c,v $
|
|
* $Author: joel $
|
|
* $State: Exp $ $Locker: $
|
|
*
|
|
* INTERPEAK_COPYRIGHT_STRING
|
|
* Design and implementation by Joel Hortelius <joel.hortelis@interpeak.se>
|
|
******************************************************************************
|
|
*/
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 1 DESCRIPTION
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 2 CONFIGURATION
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 3 INCLUDE FILES
|
|
****************************************************************************
|
|
*/
|
|
#include "ipl2tp_h.h"
|
|
#include "ipl2tp_avp.h"
|
|
#include "ipl2tp_data.h"
|
|
#include "ipl2tp_message.h"
|
|
#include "ipl2tp_state.h"
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 4 DEFINES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 5 TYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
struct Ipl2tp_message_type
|
|
{
|
|
const char *name;
|
|
Ip_bool recognized;
|
|
};
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 6 EXTERN PROTOTYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 7 LOCAL PROTOTYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 8 DATA
|
|
****************************************************************************
|
|
*/
|
|
|
|
|
|
static struct Ipl2tp_message_type ipl2tp_message_types[] =
|
|
{
|
|
{ "ZLB", IP_FALSE }, /* 0 */
|
|
{ "SCCRQ", IP_TRUE }, /* 1 */
|
|
{ "SCCRP", IP_TRUE }, /* 2 */
|
|
{ "SCCCN", IP_TRUE }, /* 3 */
|
|
{ "StopCCN", IP_TRUE }, /* 4 */
|
|
{ "<reserved 5>", IP_FALSE }, /* 5 */
|
|
{ "HELLO", IP_TRUE }, /* 6 */
|
|
{ "OCRQ", IP_TRUE }, /* 7 */
|
|
{ "OCRP", IP_TRUE }, /* 8 */
|
|
{ "OCCN", IP_TRUE }, /* 9 */
|
|
{ "ICRQ", IP_TRUE }, /* 10 */
|
|
{ "ICRP", IP_TRUE }, /* 11 */
|
|
{ "ICCN", IP_TRUE }, /* 12 */
|
|
{ "<reserved 13>", IP_FALSE }, /* 13 */
|
|
{ "CDN", IP_TRUE }, /* 14 */
|
|
{ "WEN", IP_TRUE }, /* 15 */
|
|
{ "SLI", IP_TRUE }, /* 16 */
|
|
{ "<unimplemented 17>", IP_FALSE }, /* 17 */
|
|
{ "<unimplemented 18>", IP_FALSE }, /* 18 */
|
|
{ "<unimplemented 19>", IP_FALSE }, /* 19 */
|
|
{ "ACK", IP_TRUE }, /* 20 */
|
|
};
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 9 STATIC FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 10 GLOBAL FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipl2tp_message_name
|
|
*===========================================================================
|
|
* Description: Get name of message.
|
|
* Parameters: type - Message type.
|
|
* Returns: Human readable message name.
|
|
*
|
|
*/
|
|
IP_GLOBAL CONST char *
|
|
ipl2tp_message_name(Ip_u16 message_type)
|
|
{
|
|
if (message_type < (sizeof(ipl2tp_message_types) / sizeof(ipl2tp_message_types[0])))
|
|
return ipl2tp_message_types[message_type].name;
|
|
|
|
return "<invalid>";
|
|
}
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipl2tp_message_recognized
|
|
*===========================================================================
|
|
* Description: Check if message is recognized.
|
|
* Parameters: type - Message type.
|
|
* Returns: IP_TRUE if message type is recognized, IP_FALSE otherwise.
|
|
*
|
|
*/
|
|
IP_GLOBAL Ip_bool
|
|
ipl2tp_message_recognized(Ip_u16 message_type)
|
|
{
|
|
if (message_type < (sizeof(ipl2tp_message_types) / sizeof(ipl2tp_message_types[0])))
|
|
return ipl2tp_message_types[message_type].recognized;
|
|
|
|
return IP_FALSE;
|
|
}
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipl2tp_message_new
|
|
*===========================================================================
|
|
* Description: Allocate a new L2TP control container.
|
|
* Parameters: tunnel - The tunnel the container belongs to.
|
|
* session - The session the container belongs to.
|
|
* Returns: The container if successful; IP_NULL otherwise.
|
|
*
|
|
*/
|
|
IP_GLOBAL Ipl2tp_message *
|
|
ipl2tp_message_new(Ipl2tp_tunnel *tunnel,
|
|
Ipl2tp_session *session)
|
|
{
|
|
Ipl2tp_message *container =
|
|
ipcom_malloc(IPL2TP_MAX_MESSAGE_SIZE + sizeof(*container));
|
|
|
|
if (container == IP_NULL)
|
|
{
|
|
IPCOM_LOG3(ERR,
|
|
"%s(%d,%s): Out of memory for L2TP message",
|
|
ipl2tp_versions[tunnel->local.key.version],
|
|
(int)tunnel->local.key.ident,
|
|
ipl2tp_util_ntoa(&tunnel->remote.addr));
|
|
return IP_NULL;
|
|
}
|
|
|
|
if (tunnel->attr.hide_avp != IPL2TP_MIB_NO && tunnel->attr.secret.size == 0)
|
|
{
|
|
IPCOM_LOG3(WARNING,
|
|
"%s(%d,%s): Missing secret for tunnel, hiding disabled",
|
|
ipl2tp_versions[tunnel->local.key.version],
|
|
(int)tunnel->local.key.ident,
|
|
ipl2tp_util_ntoa(&tunnel->remote.addr));
|
|
}
|
|
|
|
/* Enter header fields */
|
|
ipcom_list_init(&container->admin.head);
|
|
IPCOM_TMO_INIT(&container->admin.timer);
|
|
container->admin.tunnel = tunnel;
|
|
container->admin.session = session;
|
|
container->admin.retransmit = 0;
|
|
container->admin.flags = 0;
|
|
container->admin.is_zlb = IP_FALSE;
|
|
|
|
/* Version dependent container initialization */
|
|
IPL2TP_TUNNEL_MESSAGE_INIT(container);
|
|
|
|
/* Ns and Nr values are entered by transport module */
|
|
|
|
return container;
|
|
}
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipl2tp_message_delete
|
|
*===========================================================================
|
|
* Description: Delete a L2TP control container
|
|
* Parameters: container - The container
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL void
|
|
ipl2tp_message_delete(Ipl2tp_message *container)
|
|
{
|
|
/* Cancel possible pending timeout */
|
|
ipcom_tmo_cancel(&container->admin.timer);
|
|
ipcom_free(container);
|
|
}
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipl2tp_message_is_zlb
|
|
*===========================================================================
|
|
* Description: Mark container as ZLB
|
|
* Parameters: container - The container
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL void
|
|
ipl2tp_message_is_zlb(Ipl2tp_message *container)
|
|
{
|
|
/**/
|
|
container->admin.is_zlb = IP_TRUE;
|
|
}
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipl2tp_message_rq
|
|
*===========================================================================
|
|
* Description: Send appropriate request based on type of session.
|
|
* Parameters: session - The session the container belongs to.
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL Ipl2tp_status
|
|
ipl2tp_message_rq(Ipl2tp_session *session)
|
|
{
|
|
Ipl2tp_status ret;
|
|
|
|
session->state = IPL2TP_SSTATE_WAIT_REPLY;
|
|
if (session->outgoing)
|
|
{
|
|
/* Outgoing */
|
|
ret = ipl2tp_message_ocrq(session);
|
|
}
|
|
else
|
|
{
|
|
/* Incoming */
|
|
ret = ipl2tp_message_icrq(session);
|
|
}
|
|
|
|
ipl2tp_state_establish_session_timeout_init(session, 1);
|
|
return ret;
|
|
}
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 11 PUBLIC FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* END OF FILE
|
|
****************************************************************************
|
|
*/
|