original files of m241
This commit is contained in:
@@ -0,0 +1,302 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_ipsec.c,v $ $Revision: 1.20 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_ipsec.c,v $
|
||||
* $Author: lob $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Lennart Bang <lob@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPIPSEC2
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_syslog.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_sock.h"
|
||||
|
||||
#include <ipipsec.h>
|
||||
#include <ipipsec_pfkeyv2.h>
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipipsec_pfkeyv2_lookup
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC Iplite_socket *
|
||||
ipipsec_pfkeyv2_socklookup(int proto,
|
||||
IP_CONST void *local_addr, Ip_u16 src_port_n,
|
||||
Ipipsec_eio_output *eio_output, Ip_u16 dst_port_n,
|
||||
int *next)
|
||||
{
|
||||
int i;
|
||||
Iplite_socket *sock;
|
||||
|
||||
(void)proto;
|
||||
(void)local_addr;
|
||||
(void)src_port_n;
|
||||
(void)dst_port_n;
|
||||
|
||||
if (*next <= -1)
|
||||
return IP_NULL;
|
||||
|
||||
for (sock = IP_NULL, i = *next; i < IPLITE_CONF_MAX_SOCKETS; i++)
|
||||
{
|
||||
sock = iplite.sockets[i];
|
||||
if (sock != IP_NULL && sock->proto == PF_KEY_V2)
|
||||
{
|
||||
if (eio_output != IP_NULL)
|
||||
{
|
||||
if (!IP_BIT_ISSET(sock->ipcom.ipsec_registered, 1 << eio_output->sadb_msg_satype))
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*next = i + 1;
|
||||
return sock;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipipsec_timeout_schedule
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC void
|
||||
ipipsec_timeout_schedule(Ip_u32 sec,
|
||||
Ipipsec_timeout_handler handler,
|
||||
void *cookie,
|
||||
void **ptmo)
|
||||
{
|
||||
(void) iplite_timeout_schedule(sec * 1000,
|
||||
(Iplite_timeout_handler) handler,
|
||||
cookie,
|
||||
(Iplite_timeout **) ptmo);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipipsec_timeout_cancel
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC void
|
||||
ipipsec_timeout_cancel(void *tmo)
|
||||
{
|
||||
iplite_timeout_cancel(tmo);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipipsec_seconds_now
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_u32
|
||||
ipipsec_seconds_now(void)
|
||||
{
|
||||
return iplite.seconds;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipcom_ipsec_ioevent
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC void *
|
||||
ipcom_ipsec_ioevent(int command, void *data)
|
||||
{
|
||||
int ret = 0;
|
||||
Ip_fd fd;
|
||||
Iplite_socket *sock;
|
||||
Ipipsec_eio_output *eio_output;
|
||||
|
||||
switch(command)
|
||||
{
|
||||
case IPIPSEC_EIOXFDTOSOCK :
|
||||
/* Return pointer to 'Ipcom_sock' from 'fd' */
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
fd = *((Ip_fd *)data);
|
||||
if (fd == IP_INVALID_SOCKET)
|
||||
return IP_NULL;
|
||||
ip_assert(fd > 2);
|
||||
ip_assert(fd < IPLITE_CONF_MAX_SOCKETS);
|
||||
sock = iplite.sockets[(int)fd];
|
||||
if (sock == IP_NULL)
|
||||
return IP_NULL;
|
||||
/* Only connected sockets can have a cache (since addresses may change). */
|
||||
if (!IP_BIT_ISSET(sock->flags, IPLITE_SOCKET_FLAG_CONNECTED))
|
||||
return IP_NULL;
|
||||
return sock;
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
case IPIPSEC_EIOXIP4ID:
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
ret = ++iplite.ip4.id;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case IPIPSEC_EIOXOUTPUT:
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
eio_output = data;
|
||||
switch(eio_output->sndmode)
|
||||
{
|
||||
case IPIPSEC_SNDMODE_UNICAST :
|
||||
ret = iplite_queue_received_packet(eio_output->pkt, eio_output->sock);
|
||||
if (ret < 0)
|
||||
ipcom_pkt_free(eio_output->pkt);
|
||||
break;
|
||||
|
||||
case IPIPSEC_SNDMODE_BROADCAST :
|
||||
(void)iplite_raw_input(eio_output->pkt, IP_TRUE, PF_KEY_V2,
|
||||
IP_NULL, 0, IP_NULL, 0,
|
||||
(Iplite_socklookup)ipipsec_pfkeyv2_socklookup);
|
||||
break;
|
||||
|
||||
case IPIPSEC_SNDMODE_REGISTERED :
|
||||
(void)iplite_raw_input(eio_output->pkt, IP_TRUE, PF_KEY_V2,
|
||||
eio_output, 0, IP_NULL, 0,
|
||||
(Iplite_socklookup)ipipsec_pfkeyv2_socklookup);
|
||||
break;
|
||||
|
||||
default:
|
||||
IP_PANIC();
|
||||
IPCOM_LOG1(ERR, "IPSEC: ipcom_ipsec_ioevent(IPIPSEC_EIOXOUTPUT) :: unknown sndmode (%ld)",
|
||||
eio_output->sndmode);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case IPIPSEC_EIOXCODE_LOCK :
|
||||
IPLITE_CODE_LOCK();
|
||||
break;
|
||||
|
||||
case IPIPSEC_EIOXCODE_UNLOCK :
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
IPLITE_CODE_UNLOCK();
|
||||
break;
|
||||
|
||||
default:
|
||||
IP_PANIC();
|
||||
break;
|
||||
}
|
||||
|
||||
return (void *)ret;
|
||||
}
|
||||
|
||||
|
||||
#endif /* IPIPSEC2 */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user