original files of m241
This commit is contained in:
@@ -0,0 +1,372 @@
|
||||
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipl2tp_example_v2.c,v $ $Revision: 1.6 $
|
||||
* $Source: /home/interpeak/CVSRoot/ipl2tp/config/ipl2tp_example_v2.c,v $
|
||||
* $Author: tneale $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Joel Hortelius <joel.hortelis@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include "ipcom_clib.h"
|
||||
#include "ipcom_clib2.h"
|
||||
#include "ipcom_err.h"
|
||||
#include "ipcom_ipd.h"
|
||||
#include "ipcom_os.h"
|
||||
#include "ipcom_shell.h"
|
||||
#include "ipcom_sock2.h"
|
||||
#include "ipcom_syslog.h"
|
||||
#include "ipcom_type.h"
|
||||
#include "ipcom_hash.h"
|
||||
#include "ipcom_sysvar.h"
|
||||
#include "ipcom_netif.h"
|
||||
|
||||
#include "ipl2tp_h.h"
|
||||
#include "ipl2tp_api.h"
|
||||
#include "ipl2tp_api_tunnel.h"
|
||||
#include "ipl2tp_api_session.h"
|
||||
#include "ipl2tp_attr.h"
|
||||
#include "ipl2tp_cmd.h"
|
||||
#include "ipl2tp_example.h"
|
||||
#include "ipl2tp_example_v2.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipl2tp_example_tstatus_v2
|
||||
*===========================================================================
|
||||
* Description: Tunnel status callback.
|
||||
* Parameters: user_data - User callback data.
|
||||
* key - Tunnel ID.
|
||||
* status - Pointer to status info.
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
ipl2tp_example_tstatus_v2(void *user_data,
|
||||
Ipl2tp_key *key,
|
||||
Ipl2tp_result *result)
|
||||
{
|
||||
#define A_AUTH IPL2TP_MIB_AUTH_NONE
|
||||
#define A_SECRET "interop"
|
||||
#define A_NAME "hel"
|
||||
|
||||
(void)user_data;
|
||||
|
||||
switch (result->status)
|
||||
{
|
||||
case IPL2TP_STATUS_OK:
|
||||
switch (result->result_code)
|
||||
{
|
||||
case IPL2TP_OUTGOING_AUTHENTICATION:
|
||||
{
|
||||
/* Allocate an attribute object */
|
||||
Ipl2tp_attrobj attr = IP_NULL;
|
||||
Ipl2tp_attrobj replies = IP_NULL;
|
||||
|
||||
ipl2tp_attr_add_query(&attr,
|
||||
IPL2TP_TATTR_GET_l2tpTunnelStatsRemoteHostName);
|
||||
|
||||
/* Retrieve the attributes, the answers will end up in 'replies' */
|
||||
ipl2tp_api_tunnel_attribute_get(key, attr, &replies);
|
||||
|
||||
IPCOM_LOG3(DEBUG,
|
||||
"IPL2TPv2: TUNNEL (IPL2TP_OUTGOING_AUTHENTICATION) v%d %d requested by '%s'",
|
||||
key->version, key->ident,
|
||||
ipl2tp_attr_strdata(ipl2tp_attr_first(replies)));
|
||||
|
||||
ipl2tp_attr_delete(&replies);
|
||||
|
||||
/* Add integer attribute */
|
||||
ipl2tp_attr_clear(attr);
|
||||
|
||||
/* Set authentication */
|
||||
if (ipl2tp_attr_iappend(&attr,
|
||||
IPL2TP_TATTR_SET_l2tpTunnelConfigAuthentication, A_AUTH) != IPL2TP_STATUS_OK ||
|
||||
/* Add string peer host name */
|
||||
ipl2tp_attr_strappend(&attr, IPL2TP_TATTR_SET_PEER_HOST_NAME, A_NAME) != IPL2TP_STATUS_OK ||
|
||||
/* Add authentication vector */
|
||||
ipl2tp_attr_vappend(&attr,
|
||||
IPL2TP_TATTR_SET_l2tpTunnelConfigSecret,
|
||||
A_SECRET, (int)ipcom_strlen(A_SECRET)) != IPL2TP_STATUS_OK)
|
||||
{
|
||||
IPCOM_LOG3(WARNING,
|
||||
"IPL2TPv2: v%d %d requested by '%s': unable to set attributes",
|
||||
key->version, key->ident,
|
||||
ipl2tp_attr_strdata(ipl2tp_attr_first(replies)));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Do set the attributes */
|
||||
ipl2tp_api_tunnel_attribute_set(key, attr);
|
||||
}
|
||||
|
||||
/* Delete the attribute object */
|
||||
ipl2tp_attr_delete(&attr);
|
||||
|
||||
if (ipcom_strcmp(ipl2tp_poke_abort, "toa") == 0)
|
||||
return 1;
|
||||
|
||||
/* We've installed the authentication data required,
|
||||
* do continue the tunnel processing and attempt to establish */
|
||||
ipl2tp_api_tunnel_authentication_established(key);
|
||||
break;
|
||||
}
|
||||
|
||||
case IPL2TP_OUTGOING_REQUEST:
|
||||
{
|
||||
Ipl2tp_attrobj replies = IP_NULL;
|
||||
Ipl2tp_attrobj attr = IP_NULL;
|
||||
|
||||
ipl2tp_attr_add_query(&attr,
|
||||
IPL2TP_TATTR_GET_l2tpTunnelStatsRemoteHostName);
|
||||
|
||||
/* Retrieve the attributes, the answers will end up in 'replies' */
|
||||
ipl2tp_api_tunnel_attribute_get(key, attr, &replies);
|
||||
IPCOM_LOG3(DEBUG,
|
||||
"IPL2TPv2: TUNNEL (IPL2TP_OUTGOING_REQUEST) v%d %d requested by '%s'",
|
||||
key->version, key->ident,
|
||||
ipl2tp_attr_strdata(ipl2tp_attr_first(replies)));
|
||||
ipl2tp_attr_delete(&replies);
|
||||
ipl2tp_attr_delete(&attr);
|
||||
|
||||
if (ipcom_strcmp(ipl2tp_poke_abort, "tor") == 0)
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
|
||||
case IPL2TP_OUTGOING_ESTABLISHED:
|
||||
IPCOM_LOG2(DEBUG,
|
||||
"IPL2TPv2: TUNNEL (IPL2TP_OUTGOING_ESTABLISHED) v%d %d opened",
|
||||
key->version, key->ident);
|
||||
if (ipcom_strcmp(ipl2tp_poke_abort, "toe") == 0)
|
||||
return 1;
|
||||
break;
|
||||
|
||||
case IPL2TP_INCOMING_ESTABLISHED:
|
||||
IPCOM_LOG2(DEBUG,
|
||||
"IPL2TPv2: TUNNEL (IPL2TP_INCOMING_ESTABLISHED) v%d %d opened",
|
||||
key->version, key->ident);
|
||||
if (ipcom_strcmp(ipl2tp_poke_abort, "tie") == 0)
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IPL2TP_STATUS_NEGOTIATION:
|
||||
IPCOM_LOG2(DEBUG,
|
||||
"IPL2TPv2: TUNNEL (IPL2TP_STATUS_NEGOTIATION) v%d %d closed obsoleted by version negotiation",
|
||||
key->version, key->ident);
|
||||
break;
|
||||
|
||||
default:
|
||||
IPCOM_LOG5(DEBUG,
|
||||
"IPL2TPv2: TUNNEL (%u) v%d %d closed with status %d, %s",
|
||||
result->status,
|
||||
key->version, key->ident,
|
||||
(int)result->status,
|
||||
ipl2tp_api_errname(result->status));
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipl2tp_example_sstatus_v2
|
||||
*===========================================================================
|
||||
* Description: Session status callback.
|
||||
* Parameters: user_data - User callback data.
|
||||
* key - Session ID.
|
||||
* status - Pointer to status info.
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
ipl2tp_example_sstatus_v2(void *user_data,
|
||||
Ipl2tp_key *key,
|
||||
Ipl2tp_result *result)
|
||||
{
|
||||
unsigned long ifindexul = (unsigned long)user_data;
|
||||
int ifindex = (int)ifindexul;
|
||||
int ret = 1;
|
||||
|
||||
(void)ifindex;
|
||||
|
||||
switch (result->status)
|
||||
{
|
||||
case IPL2TP_STATUS_OK:
|
||||
switch (result->result_code)
|
||||
{
|
||||
case IPL2TP_OUTGOING_REQUEST:
|
||||
{
|
||||
Ipl2tp_attrobj replies = IP_NULL;
|
||||
|
||||
ipl2tp_api_session_attribute_query(key,
|
||||
IPL2TP_SATTR_GET_CALLED_NUMBER,
|
||||
&replies);
|
||||
IPCOM_LOG4(DEBUG,
|
||||
"IPL2TPv2: SESSION (IPL2TP_OUTGOING_REQUEST) v%d %d %s to '%s'",
|
||||
key->version, key->ident,
|
||||
ipl2tp_api_session_type(key),
|
||||
ipl2tp_attr_strdata(ipl2tp_attr_first(replies)));
|
||||
ipl2tp_attr_delete(&replies);
|
||||
if (ipcom_strcmp(ipl2tp_poke_abort, "sor") == 0)
|
||||
goto leave;
|
||||
break;
|
||||
}
|
||||
case IPL2TP_OUTGOING_REPLY:
|
||||
{
|
||||
Ipl2tp_attrobj attr = IP_NULL;
|
||||
|
||||
IPCOM_LOG3(DEBUG,
|
||||
"IPL2TPv2: SESSION (IPL2TP_OUTGOING_REPLY) v%d %d %s",
|
||||
key->version, key->ident,
|
||||
ipl2tp_api_session_type(key));
|
||||
|
||||
if (ipl2tp_attr_iappend(&attr,
|
||||
IPL2TP_SATTR_SET_TX_CONNECT_SPEED,
|
||||
38400) != IPL2TP_STATUS_OK ||
|
||||
ipl2tp_attr_iappend(&attr,
|
||||
IPL2TP_SATTR_SET_FRAMING_TYPE,
|
||||
IPL2TP_MIB_FRAMING_ASYNC) != IPL2TP_STATUS_OK)
|
||||
{
|
||||
IPCOM_LOG3(WARNING,
|
||||
"IPL2TPv2: SESSION (IPL2TP_OUTGOING_REPLY) v%d %d %s unable to set attributes",
|
||||
key->version, key->ident,
|
||||
ipl2tp_api_session_type(key));
|
||||
}
|
||||
else
|
||||
{
|
||||
ipl2tp_api_session_attribute_set(key, attr);
|
||||
}
|
||||
ipl2tp_attr_delete(&attr);
|
||||
|
||||
if (ipcom_strcmp(ipl2tp_poke_abort, "sop") == 0)
|
||||
goto leave;
|
||||
|
||||
ipl2tp_api_session_outgoing_established(key, 0, 0, "");
|
||||
break;
|
||||
}
|
||||
case IPL2TP_OUTGOING_ESTABLISHED:
|
||||
IPCOM_LOG3(DEBUG,
|
||||
"IPL2TPv2: SESSION (IPL2TP_OUTGOING_ESTABLISHED) v%d %d %s",
|
||||
key->version, key->ident,
|
||||
ipl2tp_api_session_type(key));
|
||||
if (ipcom_strcmp(ipl2tp_poke_abort, "soe") == 0)
|
||||
goto leave;
|
||||
break;
|
||||
|
||||
case IPL2TP_INCOMING_REQUEST:
|
||||
/* Setup */
|
||||
IPCOM_LOG3(DEBUG,
|
||||
"IPL2TPv2: SESSION (IPL2TP_INCOMING_REQUEST) v%d %d %s",
|
||||
key->version, key->ident,
|
||||
ipl2tp_api_session_type(key));
|
||||
ipl2tp_api_session_incoming_established(key, 0, 0, "");
|
||||
break;
|
||||
|
||||
case IPL2TP_INCOMING_ESTABLISHED:
|
||||
IPCOM_LOG3(DEBUG,
|
||||
"IPL2TPv2: SESSION (IPL2TP_INCOMING_ESTABLISHED) v%d %d %s",
|
||||
key->version, key->ident,
|
||||
ipl2tp_api_session_type(key));
|
||||
if (ipcom_strcmp(ipl2tp_poke_abort, "sie") == 0)
|
||||
goto leave;
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
IPCOM_LOG4(DEBUG,
|
||||
"IPL2TPv2: SESSION (%u) v%d %d closed with status %s",
|
||||
(int)result->status,
|
||||
key->version, key->ident,
|
||||
ipl2tp_api_errname(result->status));
|
||||
break;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
leave:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
Reference in New Issue
Block a user