original files of m241
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_cmd.c,v $ $Revision: 1.15 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_cmd.c,v $
|
||||
* $Author: hxie $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_KERNEL
|
||||
#undef IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_sock.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_cmd.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_netstat_key_to_str
|
||||
*===========================================================================
|
||||
* Description: Converts the key to the string representation in map.
|
||||
* Parameters: map - The int to string map to use.
|
||||
* key - The protocol number.
|
||||
* Returns: The string represenstion.
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL IP_CONST char *
|
||||
iplite_cmd_key_to_str(Iplite_cmd_int_str_map *map, int key)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; map[i].key != -1; i++)
|
||||
if (map[i].key == key)
|
||||
return map[i].str;
|
||||
IP_PANIC();
|
||||
return IP_NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_netstat_key_to_str
|
||||
*===========================================================================
|
||||
* Description: Converts the string representation in map to the numeric value.
|
||||
* Parameters: map - The int to string map to use.
|
||||
* key - The protocol number.
|
||||
* Returns: The string represenstion.
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_cmd_str_to_key(Iplite_cmd_int_str_map *map, IP_CONST char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; map[i].str != IP_NULL; i++)
|
||||
if (ipcom_strcmp(str, map[i].str) == 0)
|
||||
return map[i].key;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_cmd_hwaddr_to_str
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL char *
|
||||
iplite_cmd_hwaddr_to_str(Ip_u8 *hwaddr, Ip_size_t hwaddr_len, char *str, Ip_size_t str_len)
|
||||
{
|
||||
char tmp[4];
|
||||
Ip_size_t n = 0;
|
||||
Ip_size_t i = 0;
|
||||
|
||||
ipcom_sprintf (str, "%02X", hwaddr[n]);
|
||||
n++;
|
||||
i += 2;
|
||||
while (n < hwaddr_len && i < str_len - 1)
|
||||
{
|
||||
ipcom_sprintf (tmp, ":%02X", hwaddr[n]);
|
||||
ipcom_strcat (str, tmp);
|
||||
n++;
|
||||
i += 3;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
IP_GLOBAL void
|
||||
iplite_cmd_init_addrs(void *msg, Ip_u32 addrs, struct Ip_sockaddr **sas)
|
||||
{
|
||||
int i;
|
||||
Ip_size_t offset = 0;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
if (IP_BIT_ISSET(addrs, 1 << i))
|
||||
{
|
||||
sas[i] = (struct Ip_sockaddr *) &((Ip_u8 *) msg)[offset];
|
||||
offset += IPCOM_SA_LEN_GET(sas[i]) ?
|
||||
IP_ROUNDUP(IPCOM_SA_LEN_GET(sas[i]), sizeof(Ip_u32)) : sizeof(Ip_u32);
|
||||
}
|
||||
else
|
||||
sas[i] = IP_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_cmd.h,v $ $Revision: 1.5 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_cmd.h,v $
|
||||
* $Author: lob $ $Date: 2005-11-11 11:45:54 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPLITE_CMD_H
|
||||
#define IPLITE_CMD_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* Functions used by IPLITE shellcommands.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_sock.h>
|
||||
#include <ipcom_inet.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 PROTOS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
typedef struct Iplite_cmd_int_str_map_struct
|
||||
{
|
||||
int key;
|
||||
IP_CONST char *str;
|
||||
}
|
||||
Iplite_cmd_int_str_map;
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_GLOBAL IP_CONST char *
|
||||
iplite_cmd_key_to_str(Iplite_cmd_int_str_map *map, int key);
|
||||
|
||||
IP_GLOBAL int
|
||||
iplite_cmd_str_to_key(Iplite_cmd_int_str_map *map, IP_CONST char *key);
|
||||
|
||||
IP_GLOBAL char *
|
||||
iplite_cmd_hwaddr_to_str (Ip_u8 *hwaddr, Ip_size_t hwaddr_len, char *str, Ip_size_t str_len);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,486 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_cmd_arp.c,v $ $Revision: 1.23 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_cmd_arp.c,v $
|
||||
* $Author: lob $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_getopt.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_eth.h"
|
||||
#include "iplite_cmd.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC int iplite_cmd_arp(int argc, char **argv);
|
||||
|
||||
IP_STATIC int iplite_arp_add_entry(IP_CONST char *str_ip4_addr, IP_CONST char *str_link_addr, Ip_u32 ifindex);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_arp_print_entry
|
||||
*===========================================================================
|
||||
* Description: Prints an ARP entry.
|
||||
* Parameters: rt - An ARP entry.
|
||||
* addrs - Addresses in the ARP entry.
|
||||
* Returns: 0 == success, <0 == error
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_arp_print_entry(Iplite_netif *netif, Iplite_arp_entry *entry)
|
||||
{
|
||||
char str_addr[IPLITE_ETH_ADDR_SIZE * 3];
|
||||
struct Ip_in_addr ina;
|
||||
char buf[128];
|
||||
|
||||
ina.s_addr = entry->ipaddr_n;
|
||||
|
||||
if (ipcom_inet_ntop(IP_AF_INET, &ina, str_addr, sizeof(str_addr)) == IP_NULL)
|
||||
{
|
||||
return -ipcom_errno;
|
||||
}
|
||||
|
||||
ipcom_sprintf(buf, "%16s", str_addr);
|
||||
ipcom_sprintf(buf + 16, " at %s [%s]"IP_LF,
|
||||
iplite_cmd_hwaddr_to_str((Ip_u8 *) entry->state.valid.ethaddr,
|
||||
sizeof (entry->state.valid.ethaddr),
|
||||
str_addr,
|
||||
sizeof (str_addr)),
|
||||
netif->ipcom.name);
|
||||
IPLITE_CODE_UNLOCK();
|
||||
ipcom_printf(buf);
|
||||
IPLITE_CODE_LOCK();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_arp_for_each
|
||||
*===========================================================================
|
||||
* Description: Lists all ARP entries and call the callback function for each.
|
||||
* Parameters: ifindex - The interface specified at the command prompt.
|
||||
* cb - The callback function to call.
|
||||
* Returns: 0 == success, <0 == error
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_arp_for_each(Ip_u32 ifindex,
|
||||
int (*cb)(Iplite_netif *netif, Iplite_arp_entry *entry))
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
Iplite_arp_entry *entry;
|
||||
Iplite_netif *netif;
|
||||
|
||||
IPLITE_CODE_LOCK();
|
||||
|
||||
for(i = 1; i < IPLITE_CONF_MAX_NETIF; i++)
|
||||
{
|
||||
netif = iplite.netifs[i];
|
||||
if(netif == IP_NULL)
|
||||
continue;
|
||||
if(netif->eth == IP_NULL)
|
||||
continue;
|
||||
if(ifindex && ifindex != (Ip_u32)i)
|
||||
continue;
|
||||
|
||||
/* List the ARP cache. */
|
||||
for (j = 0; j < IPLITE_ARP_MAX_CACHE; j++)
|
||||
{
|
||||
entry = netif->eth->arp_cache[j];
|
||||
if (entry != IP_NULL)
|
||||
(void)cb(netif, entry);
|
||||
}
|
||||
}
|
||||
|
||||
IPLITE_CODE_UNLOCK();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_arp_delete_entry
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_arp_delete_entry(Iplite_netif *netif, Iplite_arp_entry *entry)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < IPLITE_ARP_MAX_CACHE; i++)
|
||||
{
|
||||
if (netif->eth->arp_cache[i] == entry)
|
||||
{
|
||||
iplite_kfree(entry);
|
||||
netif->eth->arp_cache[i] = IP_NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_arp_add_entry
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_arp_add_entry(IP_CONST char *str_ip4_addr, IP_CONST char *str_link_addr, Ip_u32 ifindex)
|
||||
{
|
||||
struct Ip_in_addr ina;
|
||||
Ip_u8 ethaddr[IPLITE_ETH_ADDR_SIZE];
|
||||
Iplite_netif *netif;
|
||||
int i = 0;
|
||||
Iplite_arp_entry **arp_entry;
|
||||
int ret = 0;
|
||||
char macstr[30]; /* 6*4+5+1 */
|
||||
char *str;
|
||||
char *endptr;
|
||||
char *tmp;
|
||||
Ip_u32 n;
|
||||
|
||||
ipcom_strncpy(macstr, str_link_addr, sizeof(macstr) - 1);
|
||||
macstr[sizeof(macstr) - 1] = '\0';
|
||||
|
||||
ret = ipcom_inet_pton(IP_AF_INET, str_ip4_addr, &ina);
|
||||
if (ret < 0)
|
||||
return -ipcom_errno;
|
||||
if (ret == 0)
|
||||
return -IP_ERRNO_EINVAL; /* Invalid IPv4 address */
|
||||
|
||||
str = ipcom_strtok_r(macstr, ":", &tmp);
|
||||
while (str != IP_NULL)
|
||||
{
|
||||
n = ipcom_strtol(str, &endptr, 16);
|
||||
if (*endptr != '\0')
|
||||
return -IP_ERRNO_EINVAL; /* Trailing garbage in hex-number */
|
||||
ethaddr[i] = (Ip_u8) n;
|
||||
i++;
|
||||
str = ipcom_strtok_r(IP_NULL, ":", &tmp);
|
||||
}
|
||||
if (i != IPLITE_ETH_ADDR_SIZE)
|
||||
return -IP_ERRNO_EINVAL;
|
||||
|
||||
IPLITE_CODE_LOCK();
|
||||
|
||||
if (ifindex == 0)
|
||||
netif = iplite_ip4_get_netif(ina.s_addr, IP_NULL);
|
||||
else
|
||||
netif = iplite.netifs[ifindex];
|
||||
if (netif == IP_NULL)
|
||||
{
|
||||
ret = -IP_ERRNO_EINVAL;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
arp_entry = &netif->eth->arp_cache[i];
|
||||
i++;
|
||||
}
|
||||
while (*arp_entry != IP_NULL && i < IPLITE_ARP_MAX_CACHE);
|
||||
|
||||
if (i >= IPLITE_ARP_MAX_CACHE)
|
||||
{
|
||||
ret = -IP_ERRNO_ENOBUFS;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
*arp_entry = iplite_kmalloc(sizeof(Iplite_arp_entry));
|
||||
if (*arp_entry == IP_NULL)
|
||||
{
|
||||
ret = -IP_ERRNO_ENOMEM;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
(*arp_entry)->ipaddr_n = ina.s_addr;
|
||||
(*arp_entry)->state.valid.enddate = IPLITE_ARP_TIMEOUT_PERMANENT;
|
||||
ipcom_memcpy((*arp_entry)->state.valid.ethaddr, ethaddr, IPLITE_ETH_ADDR_SIZE);
|
||||
ret = 0;
|
||||
|
||||
errout:
|
||||
IPLITE_CODE_UNLOCK();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_cmd_arp_get_entry_from_addr
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_cmd_arp_get_entry_from_addr(char *str_addr, Iplite_netif **matching_if, Iplite_arp_entry **matching_entry)
|
||||
{
|
||||
struct Ip_in_addr ina;
|
||||
Iplite_arp_entry *entry = IP_NULL;
|
||||
Iplite_netif *netif = IP_NULL;
|
||||
int i = 1;
|
||||
int j;
|
||||
|
||||
if (ipcom_inet_pton (IP_AF_INET, str_addr, &ina) < 0)
|
||||
{
|
||||
return -ipcom_errno;
|
||||
}
|
||||
|
||||
while (i < IPLITE_CONF_MAX_NETIF && entry == IP_NULL)
|
||||
{
|
||||
netif = iplite.netifs[i];
|
||||
i++;
|
||||
|
||||
if (netif == IP_NULL)
|
||||
continue;
|
||||
if (netif->eth == IP_NULL)
|
||||
continue;
|
||||
|
||||
for (j = 0; j < IPLITE_ARP_MAX_CACHE; j++)
|
||||
{
|
||||
entry = netif->eth->arp_cache[j];
|
||||
if (entry != IP_NULL && entry->ipaddr_n == ina.s_addr)
|
||||
break;
|
||||
else
|
||||
entry = IP_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry != IP_NULL)
|
||||
{
|
||||
*matching_if = netif;
|
||||
*matching_entry = entry;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -IP_ERRNO_ENXIO;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_arp_print_usage
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
iplite_arp_print_usage(void)
|
||||
{
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf("NAME"IP_LF);
|
||||
ipcom_printf(" arp - address resolution display and control"IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf("SYNOPSIS"IP_LF);
|
||||
ipcom_printf(" arp [-i <ifname>] -a"IP_LF);
|
||||
ipcom_printf(" arp [-i <ifname>] -A"IP_LF);
|
||||
ipcom_printf(" arp -d hostaddress"IP_LF);
|
||||
ipcom_printf(" arp [-i <ifname>] -s nodeaddress ether_addr"IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf("DESCRIPTION"IP_LF);
|
||||
ipcom_printf(" The arp program displays and modifies the Internet-to-Ethernet address"IP_LF);
|
||||
ipcom_printf(" translation tables used by the address resolution protocol."IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf(" Options:"IP_LF);
|
||||
ipcom_printf(" -i <ifname> Specify interface. First one if not specified."IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf(" Commands:"IP_LF);
|
||||
ipcom_printf(" -a Display the currently existing ARP entries."IP_LF);
|
||||
ipcom_printf(" -A Erase all the ARP entries."IP_LF);
|
||||
ipcom_printf(" -d Delete specified ARP entry."IP_LF);
|
||||
ipcom_printf(" -s Register a ARP entry for a node."IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_cmd_arp
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
iplite_cmd_arp(int argc, char **argv)
|
||||
{
|
||||
int c, ret = 17;
|
||||
Ip_u32 ifindex = 0;
|
||||
Ipcom_getopt opt;
|
||||
|
||||
/* Parse options */
|
||||
ipcom_getopt_clear_r(&opt);
|
||||
while ((c = ipcom_getopt_r(argc, argv, "aAd:si:", &opt)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'i' :
|
||||
ifindex = ipcom_if_nametoindex(opt.optarg);
|
||||
if (ifindex == 0)
|
||||
{
|
||||
ipcom_printf("arp: %s is not a valid interface."IP_LF, opt.optarg);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse commands */
|
||||
ipcom_getopt_clear_r(&opt);
|
||||
while ((c = ipcom_getopt_r(argc, argv, "aAd:si:", &opt)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'a':
|
||||
ret = iplite_arp_for_each(ifindex, iplite_arp_print_entry);
|
||||
goto done;
|
||||
case 'A':
|
||||
ret = iplite_arp_for_each(ifindex, iplite_arp_delete_entry);
|
||||
goto done;
|
||||
case 'd':
|
||||
{
|
||||
Iplite_arp_entry *entry;
|
||||
Iplite_netif *netif;
|
||||
|
||||
ret = iplite_cmd_arp_get_entry_from_addr(opt.optarg,
|
||||
&netif, &entry);
|
||||
if (ret == 0)
|
||||
{
|
||||
IPLITE_CODE_LOCK();
|
||||
ret = iplite_arp_delete_entry(netif, entry);
|
||||
IPLITE_CODE_UNLOCK();
|
||||
}
|
||||
}
|
||||
goto done;
|
||||
case 's':
|
||||
if (argc < opt.optind + 2)
|
||||
goto done;
|
||||
ret = iplite_arp_add_entry(argv[opt.optind], argv[opt.optind+1], ifindex);
|
||||
goto done;
|
||||
case 'i' :
|
||||
case 'V' :
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (ret == 17)
|
||||
iplite_arp_print_usage();
|
||||
|
||||
if (ret < 0)
|
||||
ipcom_printf("arp: operation failed, errno: %s" IP_LF, ipcom_strerror(-ret));
|
||||
ipcom_printf(IP_LF);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* IPCOM_USE_INET */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,465 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_cmd_ctrl.c,v $ $Revision: 1.20 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_cmd_ctrl.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_file.h>
|
||||
#include <ipcom_getopt.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_cmd.h"
|
||||
#ifdef IPCOM_USE_TCP
|
||||
#include "iplite_tcp.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPLITE_CTRL_PRINT_BUF_SIZE 32768
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC int iplite_cmd_ctrl(int argc, char **argv);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_PKT_ID_UNINITIALIZED 0xffff
|
||||
|
||||
#ifdef IPLITE_DEBUG
|
||||
IP_STATIC Iplite_cmd_int_str_map iplite_ctrl_id_map[] =
|
||||
{
|
||||
{ IPCOM_PKT_ID_INIT, "Init" },
|
||||
{ IPCOM_PKT_ID_UNINITIALIZED, "Uninitialized" },
|
||||
{ IPCOM_PKT_ID_MALLOC, "Just allocated" },
|
||||
{ IPCOM_PKT_ID_RX, "Driver input irq" },
|
||||
{ IPCOM_PKT_ID_TX, "Driver output" },
|
||||
{ IPCOM_PKT_ID_FREEQ, "Free queue" },
|
||||
{ IPCOM_PKT_ID_DELREF, "Delete ref" },
|
||||
{ IPCOM_PKT_ID_ADDREF, "Add ref" },
|
||||
{ IPCOM_PKT_ID_INPUT, "Pkt input" },
|
||||
{ IPCOM_PKT_ID_INQ, "Input queue" },
|
||||
{ IPCOM_PKT_ID_OUTQ, "Output queue" },
|
||||
{ IPCOM_PKT_ID_NETIF_OUTQ, "Netif output queue" },
|
||||
{ IPCOM_PKT_ID_SOCKRECVQ, "Recv. queue" },
|
||||
{ IPCOM_PKT_ID_TCP, "TCP" },
|
||||
{ IPCOM_PKT_ID_TCP_INPUT, "TCP input" },
|
||||
{ IPCOM_PKT_ID_TCP_OUTPUT, "TCP output" },
|
||||
{ IPCOM_PKT_ID_TCP_SOCKOOORECVQ, "TCP out-of-order" },
|
||||
{ IPCOM_PKT_ID_TCP_RETRANSQ, "TCP retrans. queue" },
|
||||
{ IPCOM_PKT_ID_IP4_INPUT, "IPv4 input" },
|
||||
{ IPCOM_PKT_ID_IP4_OUTPUT, "IPv4 output" },
|
||||
{ IPCOM_PKT_ID_IP4_REASSEMBLY, "IPv4 reassembly" },
|
||||
{ IPCOM_PKT_ID_IP6_INPUT, "IPv6 input" },
|
||||
{ IPCOM_PKT_ID_IP6_OUTPUT, "IPv6 output" },
|
||||
{ IPCOM_PKT_ID_IP6_REASSEMBLY, "IPv6 reassembly" },
|
||||
{ IPCOM_PKT_ID_REMOVE, "Removed from queue" },
|
||||
{ IPCOM_PKT_ID_IPSEC_INPUT, "input ipsec" },
|
||||
{ IPCOM_PKT_ID_IPSEC_OUTPUT, "output ipsec(new)" },
|
||||
{ IPCOM_PKT_ID_IPSEC_OUTPUT_ORG, "output ipsec(org)" },
|
||||
{ IPCOM_PKT_ID_IPSEC_PF_KEY_IN, "PF_KEY input" },
|
||||
{ IPCOM_PKT_ID_PPP, "PPP" },
|
||||
{ IPCOM_PKT_ID_PPP_ORGOUT, "PPP orgout" },
|
||||
{ IPCOM_PKT_ID_PPP_INPUT, "PPP input" },
|
||||
{ IPCOM_PKT_ID_PPP_OUTPUT, "PPP output" },
|
||||
{ IPCOM_PKT_ID_RTSOCK, "Route sock" },
|
||||
{ IPCOM_PKT_ID_UDP_INPUT, "UDP input" },
|
||||
{ IPCOM_PKT_ID_NETIF_DEQUEUE, "Dequeued from netif" },
|
||||
{ IPCOM_PKT_ID_SOCKSENDQ, "Send queue" },
|
||||
{ IPCOM_PKT_ID_SENT_PIPE, "Send to pipe" },
|
||||
{ IPCOM_PKT_ID_RECV_PIPE, "Received from pipe" },
|
||||
{ IPCOM_PKT_ID_FRAG, "New fragment" },
|
||||
{ -1, IP_NULL }
|
||||
};
|
||||
#endif /* IPLITE_DEBUG */
|
||||
|
||||
#define IPLITE_CTRL_INQ (-2) /* Must no be a valid socket or IP_SOCKERR */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPLITE_DEBUG
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ctrl_verify_inq
|
||||
*===========================================================================
|
||||
* Description: Verifies that a packet can be found in the input queue.
|
||||
* Parameters: pkt - Packet to find.
|
||||
* Returns: IPLITE_CTRL_INQ if the packet was found in the input queue,
|
||||
* IP_SOCKERR if it was not found.
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ctrl_verify_inq(Ipcom_pkt *pkt)
|
||||
{
|
||||
Ipcom_pkt *ipkt;
|
||||
|
||||
for (ipkt = iplite.inq_head; ipkt != IP_NULL; ipkt = ipkt->next)
|
||||
if (ipkt == pkt)
|
||||
return IPLITE_CTRL_INQ;
|
||||
return IP_SOCKERR;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ctrl_verify_reassembly
|
||||
*===========================================================================
|
||||
* Description: Verifies that a packet can be found in the reassembly queue.
|
||||
* Parameters: pkt_list_head - Head of list
|
||||
* pkt - Packet to find.
|
||||
* Returns: IPLITE_CTRL_INQ if the packet was found in the reassembly queue,
|
||||
* IP_SOCKERR if it was not found.
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ctrl_verify_reassembly(Ipcom_pkt *pkt_list_head, Ipcom_pkt *pkt)
|
||||
{
|
||||
Ipcom_pkt *fragment_list;
|
||||
Ipcom_pkt *fragment;
|
||||
|
||||
for (fragment_list = pkt_list_head; fragment_list != IP_NULL; fragment_list = fragment_list->next)
|
||||
{
|
||||
for (fragment = fragment_list; fragment != IP_NULL; fragment = fragment->next_fragment)
|
||||
if (fragment == pkt)
|
||||
return IPLITE_CTRL_INQ;
|
||||
}
|
||||
return IP_SOCKERR;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ctrl_verify_location
|
||||
*===========================================================================
|
||||
* Description: Verifies that the packet can be found in the location specified
|
||||
* by the 'id' field.
|
||||
* Parameters: pkt - Packet to find.
|
||||
* str - Buffer to print the status.
|
||||
* Returns: A description of the location status.
|
||||
*
|
||||
*/
|
||||
IP_STATIC IP_CONST char *
|
||||
iplite_ctrl_verify_location(Ipcom_pkt *pkt, char *str)
|
||||
{
|
||||
Ip_fd fd;
|
||||
enum Ipcom_pkt_id id;
|
||||
|
||||
id = IPCOM_GET_PKT_ID(pkt);
|
||||
switch (id)
|
||||
{
|
||||
#ifdef IPCOM_USE_TCP
|
||||
case IPCOM_PKT_ID_TCP_RETRANSQ:
|
||||
fd = iplite_tcp_ctrl_verify_retransq(pkt);
|
||||
break;
|
||||
case IPCOM_PKT_ID_SOCKRECVQ:
|
||||
fd = iplite_tcp_ctrl_verify_sockrecvq(pkt);
|
||||
break;
|
||||
case IPCOM_PKT_ID_TCP_SOCKOOORECVQ:
|
||||
fd = iplite_tcp_ctrl_verify_sockooorecvq(pkt);
|
||||
break;
|
||||
#endif /* IPCOM_USE_TCP */
|
||||
#ifdef IPCOM_USE_INET
|
||||
case IPCOM_PKT_ID_IP4_REASSEMBLY:
|
||||
fd = iplite_ctrl_verify_reassembly(iplite.ip4.reassembly_list, pkt);
|
||||
break;
|
||||
#endif /* IPCOM_USE_INET */
|
||||
#ifdef IPCOM_USE_INET6
|
||||
case IPCOM_PKT_ID_IP6_REASSEMBLY:
|
||||
fd = iplite_ctrl_verify_reassembly(iplite.ip6.reassembly_list, pkt);
|
||||
break;
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
|
||||
case IPCOM_PKT_ID_INIT:
|
||||
case IPCOM_PKT_ID_ADDREF:
|
||||
case IPCOM_PKT_ID_DELREF:
|
||||
case IPCOM_PKT_ID_UNINITIALIZED:
|
||||
case IPCOM_PKT_ID_RX:
|
||||
case IPCOM_PKT_ID_TX:
|
||||
case IPCOM_PKT_ID_INPUT:
|
||||
case IPCOM_PKT_ID_OUTQ:
|
||||
case IPCOM_PKT_ID_NETIF_OUTQ:
|
||||
case IPCOM_PKT_ID_TCP:
|
||||
case IPCOM_PKT_ID_TCP_INPUT:
|
||||
case IPCOM_PKT_ID_TCP_OUTPUT:
|
||||
case IPCOM_PKT_ID_IP4_INPUT:
|
||||
case IPCOM_PKT_ID_IP4_OUTPUT:
|
||||
case IPCOM_PKT_ID_IP6_INPUT:
|
||||
case IPCOM_PKT_ID_IP6_OUTPUT:
|
||||
case IPCOM_PKT_ID_REMOVE:
|
||||
case IPCOM_PKT_ID_IPSEC_INPUT:
|
||||
case IPCOM_PKT_ID_IPSEC_OUTPUT:
|
||||
case IPCOM_PKT_ID_IPSEC_OUTPUT_ORG:
|
||||
case IPCOM_PKT_ID_IPSEC_PF_KEY_IN:
|
||||
case IPCOM_PKT_ID_PPP:
|
||||
case IPCOM_PKT_ID_PPP_ORGOUT:
|
||||
case IPCOM_PKT_ID_PPP_INPUT:
|
||||
case IPCOM_PKT_ID_PPP_OUTPUT:
|
||||
case IPCOM_PKT_ID_RTSOCK:
|
||||
case IPCOM_PKT_ID_UDP_INPUT:
|
||||
case IPCOM_PKT_ID_NETIF_DEQUEUE:
|
||||
case IPCOM_PKT_ID_PRE_SEND_SIG:
|
||||
case IPCOM_PKT_ID_POST_SEND_SIG:
|
||||
case IPCOM_PKT_ID_SENT_PIPE:
|
||||
case IPCOM_PKT_ID_RECV_PIPE:
|
||||
/* Packet is not located in any list in this state */
|
||||
return ipcom_strcpy(str, "Can't check");
|
||||
case IPCOM_PKT_ID_INQ:
|
||||
fd = iplite_ctrl_verify_inq(pkt);
|
||||
break;
|
||||
case IPCOM_PKT_ID_FREEQ:
|
||||
/* This can only be caused by a bug! */
|
||||
return ipcom_strcpy(str, "BUG!");
|
||||
default:
|
||||
ipcom_sprintf(str, "Invalid id:%d", id);
|
||||
return str;
|
||||
}
|
||||
if (fd > 0)
|
||||
ipcom_sprintf(str, "Yes: sock=%d", fd);
|
||||
else if (fd == IP_SOCKERR)
|
||||
ipcom_strcpy(str, "No");
|
||||
else if (fd == IPLITE_CTRL_INQ)
|
||||
ipcom_strcpy(str, "Yes");
|
||||
else
|
||||
ipcom_strcpy(str, "BUG!");
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ctrl_count_buf
|
||||
*===========================================================================
|
||||
* Description: Counts the number of packets in a list.
|
||||
* Parameters: head - First element in the list.
|
||||
* Returns: The packet count in the list.
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ctrl_count_buf(Ipcom_pkt *head)
|
||||
{
|
||||
Ipcom_pkt *pkt;
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
for (pkt = head; pkt != IP_NULL; pkt = pkt->next)
|
||||
count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ctrl_print_memory_blocks
|
||||
*===========================================================================
|
||||
* Description: Prints information about allocated memory blocks.
|
||||
* Parameters: list_all - IP_TRUE = ignore last mark and print all entries.
|
||||
* IP_FALSE = print only entries allocates since the mark was set.
|
||||
* sort_order - The order the output should be printed.
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ctrl_print_packets(void)
|
||||
{
|
||||
char *output;
|
||||
char str[20];
|
||||
int pos;
|
||||
Ip_u32 isr;
|
||||
Ipcom_pkt *pkt;
|
||||
int i;
|
||||
IP_CONST char *if_name;
|
||||
Iplite_netif *netif;
|
||||
|
||||
output = ipcom_malloc(IPLITE_CTRL_PRINT_BUF_SIZE);
|
||||
if (output == IP_NULL)
|
||||
{
|
||||
ipcom_printf("Out of memory for display buffer\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
isr = ipcom_interrupt_disable();
|
||||
|
||||
pos = ipcom_snprintf(output, IPLITE_CTRL_PRINT_BUF_SIZE,
|
||||
"%-6s%-6s%-6s%-6s%-6s\n", "Pool", "MTU", "Total", "Free", "Used");
|
||||
|
||||
for (i = 0; i < iplite.pkt_pool_elem; i++)
|
||||
{
|
||||
pos += ipcom_snprintf(output + pos, IPLITE_CTRL_PRINT_BUF_SIZE - pos,
|
||||
"%-6d%-6d%-6d%-6d%-6d\n",
|
||||
i, iplite.pkt_pool[i].mtu,
|
||||
iplite.pkt_pool[i].total,
|
||||
iplite_ctrl_count_buf(iplite.pkt_pool[i].free_list),
|
||||
iplite.pkt_pool[i].used);
|
||||
}
|
||||
pos += ipcom_snprintf(output + pos, IPLITE_CTRL_PRINT_BUF_SIZE - pos,
|
||||
"\n%-4s%-4s%-6s%-6s%-6s%-20s%-16s%-6s%-9s%-10s\n",
|
||||
"Num", "Fd", "Start", "End", "Max", "Location", "Loc-verified", "If", "Flags", "Ptr");
|
||||
|
||||
for (i = 1, pkt = iplite.allocated_pkt_list; pkt != IP_NULL; pkt = pkt->next_alloc, i++)
|
||||
{
|
||||
if(pkt->ifindex < IPLITE_CONF_MAX_NETIF)
|
||||
netif = iplite.netifs[pkt->ifindex];
|
||||
else
|
||||
netif = IP_NULL;
|
||||
if (netif == IP_NULL)
|
||||
if_name = "N/A";
|
||||
else
|
||||
if_name = netif->ipcom.name;
|
||||
pos += ipcom_snprintf(output + pos, IPLITE_CTRL_PRINT_BUF_SIZE - pos,
|
||||
"%-4d%-4d%-6d%-6d%-6d%-20s%-16s%-6s%#08x %#08x\n",
|
||||
i,
|
||||
pkt->fd ,
|
||||
pkt->start, pkt->end, pkt->maxlen,
|
||||
iplite_cmd_key_to_str(iplite_ctrl_id_map, IPCOM_GET_PKT_ID(pkt)),
|
||||
iplite_ctrl_verify_location(pkt, str),
|
||||
if_name, (unsigned int) pkt->flags, (unsigned int) pkt);
|
||||
}
|
||||
|
||||
ipcom_interrupt_enable(isr);
|
||||
|
||||
(void)ipcom_fputs(output, ip_stdout);
|
||||
ipcom_free(output);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* IPLITE_DEBUG */
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ctrl_print_usage
|
||||
*===========================================================================
|
||||
* Description: Prints usage for the shell command.
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
iplite_ctrl_print_usage(void)
|
||||
{
|
||||
ipcom_printf("\n");
|
||||
ipcom_printf("NAME\n");
|
||||
ipcom_printf(" iplite_ctrl - control functions for IPLITE\n");
|
||||
ipcom_printf("\n");
|
||||
ipcom_printf("SYNOPSIS\n");
|
||||
#ifdef IPLITE_DEBUG
|
||||
ipcom_printf(" iplite_ctrl -p\n");
|
||||
#endif /* IPLITE_DEBUG */
|
||||
ipcom_printf("\n");
|
||||
ipcom_printf("DESCRIPTION\n");
|
||||
ipcom_printf(" iplite_ctrl is used to check the packets of the IPLITE stack.\n");
|
||||
ipcom_printf("\n");
|
||||
#ifdef IPLITE_DEBUG
|
||||
ipcom_printf(" -p\n");
|
||||
ipcom_printf(" List all allocated packets in the system.\n");
|
||||
#endif /* IPLITE_DEBUG */
|
||||
ipcom_printf("\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC int
|
||||
iplite_cmd_ctrl(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
Ipcom_getopt opt;
|
||||
|
||||
ipcom_getopt_clear_r(&opt);
|
||||
#ifdef IPLITE_DEBUG
|
||||
while ((c = ipcom_getopt_r(argc, argv, "p", &opt)) != -1)
|
||||
#else
|
||||
while ((c = ipcom_getopt_r(argc, argv, "", &opt)) != -1)
|
||||
#endif /* IPLITE_DEBUG */
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
#ifdef IPLITE_DEBUG
|
||||
case 'p':
|
||||
return iplite_ctrl_print_packets();
|
||||
#endif /* IPLITE_DEBUG */
|
||||
default:
|
||||
goto print_usage;
|
||||
}
|
||||
}
|
||||
print_usage:
|
||||
iplite_ctrl_print_usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_cmd_ifconfig.c,v $ $Revision: 1.43.22.1 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_cmd_ifconfig.c,v $
|
||||
* $Author: ulf $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
|
||||
#include "iplite.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_cmd_ifconfig
|
||||
*===========================================================================
|
||||
* Description: ifconfig shell command entry point.
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
iplite_cmd_ifconfig(int argc, char **argv)
|
||||
{
|
||||
return iplite_cmd_ifconfig_common(argc, argv);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,595 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_cmd_ndp.c,v $ $Revision: 1.22 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_cmd_ndp.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_cmd.h>
|
||||
#include <ipcom_getopt.h>
|
||||
#include <ipcom_inet.h>
|
||||
|
||||
#include "iplite.h"
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_ip6.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC int iplite_cmd_ndp(int argc, char **argv);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ndp_expire_time_str
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC IP_CONST char*
|
||||
iplite_ndp_expire_time_str(Ip_time_t expires, char *str_expire)
|
||||
{
|
||||
if (expires == (Ip_time_t)IPCOM_ADDR_INFINITE)
|
||||
ipcom_sprintf(str_expire, "permanent");
|
||||
else if (expires == IPLITE_EXPIRED)
|
||||
ipcom_sprintf(str_expire, "expired");
|
||||
else
|
||||
ipcom_sprintf(str_expire, "%ld s", (long)(expires - iplite.seconds));
|
||||
return str_expire;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ndp_status_str
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC char
|
||||
iplite_ndp_status_str(Ip_u16 status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case IPLITE_IP6_ND_INCOMPLETE:
|
||||
return 'I';
|
||||
case IPLITE_IP6_ND_REACHABLE:
|
||||
return 'R';
|
||||
case IPLITE_IP6_ND_STALE:
|
||||
return 'S';
|
||||
case IPLITE_IP6_ND_DELAY:
|
||||
return 'D';
|
||||
case IPLITE_IP6_ND_PROBE:
|
||||
return 'P';
|
||||
default:
|
||||
return ' ';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ndp_print_neighbor_cache_entries
|
||||
*===========================================================================
|
||||
* Description: Prints all neighbor cache entries.
|
||||
* Parameters:
|
||||
* Returns: 0 = success, -1 = fail.
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ndp_print_neighbor_cache_entries(void)
|
||||
{
|
||||
Iplite_ip6_nc_entry *nc;
|
||||
char str[256];
|
||||
struct Ip_sockaddr_in6 addr;
|
||||
Iplite_netif *netif;
|
||||
int i;
|
||||
|
||||
ipcom_printf("%-36s%-20s%-6s%-10s%-4s\n", "Neighbor", "Linklayer Address", "Netif", "Expire", "St");
|
||||
|
||||
addr.sin6_len = sizeof (struct Ip_sockaddr_in6);
|
||||
addr.sin6_family = IP_AF_INET6;
|
||||
|
||||
for (i = 2; i < IPLITE_CONF_MAX_NETIF; i++)
|
||||
{
|
||||
IPLITE_CODE_LOCK();
|
||||
netif = iplite.netifs[i];
|
||||
if (netif == IP_NULL)
|
||||
goto skip;
|
||||
|
||||
/* Lock this interface. */
|
||||
iplite_if_lock(netif);
|
||||
IPLITE_CODE_UNLOCK();
|
||||
|
||||
nc = netif->nc_list;
|
||||
while (nc != IP_NULL)
|
||||
{
|
||||
addr.sin6_addr = nc->addr;
|
||||
if (IP_IN6_IS_ADDR_LINK_LOCAL(&nc->addr))
|
||||
addr.sin6_scope_id = nc->netif->ipcom.ifindex;
|
||||
else
|
||||
addr.sin6_scope_id = 0;
|
||||
ipcom_printf("%-36s",
|
||||
ipcom_cmd_sockaddr_to_str((struct Ip_sockaddr *) &addr, IP_FALSE, IP_TRUE, str, sizeof(str)));
|
||||
ipcom_printf("%02x:%02x:%02x:%02x:%02x:%02x ",
|
||||
nc->link_addr[0], nc->link_addr[1], nc->link_addr[2],
|
||||
nc->link_addr[3], nc->link_addr[4], nc->link_addr[5]);
|
||||
ipcom_printf("%-6s", nc->netif->ipcom.name);
|
||||
ipcom_printf("%-10s", iplite_ndp_expire_time_str(nc->next_timeout, str));
|
||||
ipcom_printf("%c", iplite_ndp_status_str((Ip_u16) nc->status));
|
||||
ipcom_printf("\n");
|
||||
|
||||
nc = nc->next;
|
||||
}
|
||||
|
||||
/* Unlock this interface, must be code locked to do that. */
|
||||
IPLITE_CODE_LOCK();
|
||||
(void)iplite_if_unlock(netif);
|
||||
|
||||
/* Skip this interface. */
|
||||
skip:
|
||||
IPLITE_CODE_UNLOCK();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ndp_erase_all_neighbor_cache_entries
|
||||
*===========================================================================
|
||||
* Description: Deletes all neighbor cache entries.
|
||||
* Parameters:
|
||||
* Returns: 0 = success, -1 = fail.
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ndp_erase_all_neighbor_cache_entries(void)
|
||||
{
|
||||
Iplite_ip6_nc_entry *nc;
|
||||
Iplite_ip6_nc_entry *next_nc;
|
||||
Iplite_netif *netif;
|
||||
int i;
|
||||
|
||||
IPLITE_CODE_LOCK();
|
||||
for (i = 2; i < IPLITE_CONF_MAX_NETIF; i++)
|
||||
{
|
||||
netif = iplite.netifs[i];
|
||||
if (netif == IP_NULL)
|
||||
continue;
|
||||
|
||||
nc = netif->nc_list;
|
||||
while (nc != IP_NULL)
|
||||
{
|
||||
next_nc = nc->next;
|
||||
iplite_kfree(nc);
|
||||
nc = next_nc;
|
||||
}
|
||||
netif->nc_list = IP_NULL;
|
||||
}
|
||||
IPLITE_CODE_UNLOCK();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ndp_remove_neighbor_cache_entry
|
||||
*===========================================================================
|
||||
* Description: Removes the specified ND entry from the ND cache.
|
||||
* Parameters:
|
||||
* str_ip6_addr - A string representation of the IPv6 address
|
||||
* of the entry to remove.
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ndp_remove_neighbor_cache_entry(IP_CONST char *str_ip6_addr)
|
||||
{
|
||||
Iplite_ip6_nc_entry **nc;
|
||||
struct Ip_sockaddr_in6 in6_addr;
|
||||
int i;
|
||||
Iplite_netif *netif;
|
||||
|
||||
if (ipcom_getsockaddrbyaddrname(IP_AF_INET6, IP_TRUE, str_ip6_addr,
|
||||
(struct Ip_sockaddr *) &in6_addr) < 0)
|
||||
{
|
||||
ipcom_printf("%s is not a valid IPv6 address\n", str_ip6_addr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
IPLITE_CODE_LOCK();
|
||||
for (i = 2; i < IPLITE_CONF_MAX_NETIF; i++)
|
||||
{
|
||||
netif = iplite.netifs[i];
|
||||
if (netif == IP_NULL)
|
||||
continue;
|
||||
|
||||
nc = &netif->nc_list;
|
||||
while (*nc != IP_NULL)
|
||||
{
|
||||
if (IP_IN6_ARE_ADDR_EQUAL(&(*nc)->addr, &in6_addr.sin6_addr))
|
||||
{
|
||||
*nc = (*nc)->next;
|
||||
IPLITE_CODE_UNLOCK();
|
||||
return 0;
|
||||
}
|
||||
nc = &(*nc)->next;
|
||||
}
|
||||
}
|
||||
IPLITE_CODE_UNLOCK();
|
||||
|
||||
ipcom_printf("%s was not found in the neighbor cache\n", str_ip6_addr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ndp_print_default_router_entries
|
||||
*===========================================================================
|
||||
* Description: Prints all routers that has announced themself.
|
||||
* Parameters:
|
||||
* Returns: 0 = success, -1 = fail.
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ndp_print_default_router_entries(void)
|
||||
{
|
||||
Iplite_ip6_dr_entry *dr;
|
||||
char str[40];
|
||||
Iplite_netif *netif;
|
||||
int i;
|
||||
|
||||
ipcom_printf("%-36s%-10s%-8s\n", "Router address", "Expire", "Netif");
|
||||
|
||||
for (i = 2; i < IPLITE_CONF_MAX_NETIF; i++)
|
||||
{
|
||||
IPLITE_CODE_LOCK();
|
||||
netif = iplite.netifs[i];
|
||||
if (netif == IP_NULL)
|
||||
goto skip;
|
||||
|
||||
/* Lock this interface. */
|
||||
iplite_if_lock(netif);
|
||||
IPLITE_CODE_UNLOCK();
|
||||
|
||||
dr = &netif->dr;
|
||||
if (dr->is_set)
|
||||
{
|
||||
ipcom_printf("%-36s",
|
||||
ipcom_inet_ntop(IP_AF_INET6, &dr->addr, str, sizeof(str)));
|
||||
ipcom_printf("%-10s",
|
||||
iplite_ndp_expire_time_str(dr->expires_sec, str));
|
||||
ipcom_printf("%-8s", netif->ipcom.name);
|
||||
ipcom_printf("\n");
|
||||
}
|
||||
|
||||
/* Unlock this interface, must be code locked to do that. */
|
||||
IPLITE_CODE_LOCK();
|
||||
(void)iplite_if_unlock(netif);
|
||||
|
||||
/* Skip this interface. */
|
||||
skip:
|
||||
IPLITE_CODE_UNLOCK();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ndp_remove_all_default_router_entries
|
||||
*===========================================================================
|
||||
* Description: Remove all default router entries.
|
||||
* Parameters:
|
||||
* Returns: 0 = success, -1 = fail.
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ndp_remove_all_default_router_entries(void)
|
||||
{
|
||||
Iplite_ip6_dr_entry *dr;
|
||||
Iplite_netif *netif;
|
||||
int i;
|
||||
|
||||
IPLITE_CODE_LOCK();
|
||||
for (i = 2; i < IPLITE_CONF_MAX_NETIF; i++)
|
||||
{
|
||||
netif = iplite.netifs[i];
|
||||
if (netif == IP_NULL)
|
||||
continue;
|
||||
|
||||
dr = &netif->dr;
|
||||
if (dr->is_set)
|
||||
dr->is_set = IP_FALSE;
|
||||
}
|
||||
IPLITE_CODE_UNLOCK();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ndp_add_entry
|
||||
*===========================================================================
|
||||
* Description: Adds a neighbor cache entry.
|
||||
* Parameters: ifname - The name of the interface to a NC entry.
|
||||
* str_ip6_addr - The address of the entry.
|
||||
* str_link_addr - The link layer address.
|
||||
* Returns: 0 = success, -1 = fail.
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ndp_add_entry(Ip_u32 ifindex,
|
||||
IP_CONST char *str_ip6_addr, IP_CONST char *str_link_addr)
|
||||
{
|
||||
Iplite_netif *netif;
|
||||
struct Ip_sockaddr_in6 ip6_addr;
|
||||
struct Ip_sockaddr_dl link_addr;
|
||||
Iplite_ip6_nc_entry *nc;
|
||||
|
||||
if (ifindex < 2 || ifindex >= IPLITE_CONF_MAX_NETIF)
|
||||
{
|
||||
ipcom_printf("invalid interface index: %ld" IP_LF, ifindex);
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
|
||||
IPLITE_CODE_LOCK();
|
||||
netif = iplite.netifs[ifindex];
|
||||
if (netif == IP_NULL)
|
||||
{
|
||||
IPLITE_CODE_UNLOCK();
|
||||
ipcom_printf("no interface defined at index: %ld" IP_LF, ifindex);
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
iplite_if_lock(netif);
|
||||
IPLITE_CODE_UNLOCK();
|
||||
|
||||
if (ipcom_getsockaddrbyaddrname(IP_AF_INET6, IP_TRUE, str_ip6_addr,
|
||||
(struct Ip_sockaddr *) &ip6_addr) < 0)
|
||||
{
|
||||
ipcom_printf("%s is not a valid IPv6 address\n", str_ip6_addr);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (ipcom_getsockaddrbyaddr(IP_AF_LINK, str_link_addr, (struct Ip_sockaddr *) &link_addr) < 0)
|
||||
{
|
||||
ipcom_printf("%s is not a valid link address for %s\n", str_link_addr, netif->ipcom.name);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
IPLITE_CODE_LOCK();
|
||||
nc = iplite_ip6_neighbor_cache_find(netif, &ip6_addr.sin6_addr);
|
||||
IPLITE_CODE_UNLOCK();
|
||||
if (nc->status != IPLITE_IP6_ND_INCOMPLETE)
|
||||
{
|
||||
ipcom_printf("entry for: %s already exists" IP_LF, str_ip6_addr);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
IPLITE_CODE_LOCK();
|
||||
iplite_ip6_neighbor_cache_update(nc, IPLITE_IP6_ND_REACHABLE, link_addr.sdl_data);
|
||||
nc->next_timeout = IPCOM_ADDR_INFINITE;
|
||||
(void)iplite_if_unlock(netif);
|
||||
IPLITE_CODE_UNLOCK();
|
||||
|
||||
return 0;
|
||||
|
||||
errout:
|
||||
ip_assert(netif);
|
||||
IPLITE_CODE_LOCK();
|
||||
(void)iplite_if_unlock(netif);
|
||||
IPLITE_CODE_UNLOCK();
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ndp_print_usage
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
iplite_ndp_print_usage(void)
|
||||
{
|
||||
ipcom_printf(IP_LF "NAME" IP_LF
|
||||
" ndp - control/diagnose IPv6 neighbor discovery protocol" IP_LF
|
||||
IP_LF);
|
||||
ipcom_printf("SYNOPSIS" IP_LF
|
||||
" ndp -a" IP_LF
|
||||
" ndp -A" IP_LF
|
||||
" ndp -c" IP_LF
|
||||
" ndp -d hostaddress" IP_LF
|
||||
" ndp -r" IP_LF
|
||||
" ndp -R" IP_LF
|
||||
" ndp [-i <ifname>] -s nodeaddress ether_addr" IP_LF
|
||||
IP_LF);
|
||||
ipcom_printf("DESCRIPTION" IP_LF
|
||||
" The ndp command manipulates the address mapping table used by Neighbor" IP_LF
|
||||
" Discovery Protocol (NDP). It can take up to 1 minute before deleted" IP_LF
|
||||
" entries is removed, but they should be shown as 'expired' immediately." IP_LF
|
||||
IP_LF);
|
||||
ipcom_printf(" Options:"IP_LF
|
||||
" -i <ifname> Specify interface. Selected by the stack otherwise."IP_LF
|
||||
IP_LF
|
||||
" Commands:" IP_LF
|
||||
" -a Dump the currently existing NDP entries." IP_LF
|
||||
" -A Erase all the NDP entries." IP_LF
|
||||
" -d Delete specified NDP entry." IP_LF
|
||||
" -r Show default router list." IP_LF
|
||||
" -R Flush all the entries in the default router list." IP_LF
|
||||
" -s Register a NDP entry for a node. The entry will be permanent." IP_LF
|
||||
"" IP_LF);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_cmd_ndp
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
iplite_cmd_ndp(int argc, char **argv)
|
||||
{
|
||||
Ip_u32 ifindex = 0;
|
||||
int c;
|
||||
int ret = 17;
|
||||
Ipcom_getopt opt;
|
||||
|
||||
/* Parse options */
|
||||
ipcom_getopt_clear_r(&opt);
|
||||
while ((c = ipcom_getopt_r(argc, argv, "AHPRad:hprsi:", &opt)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'i' :
|
||||
ifindex = ipcom_if_nametoindex(opt.optarg);
|
||||
if(ifindex == 0)
|
||||
{
|
||||
ipcom_printf("%s is not a valid interface."IP_LF, opt.optarg);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ipcom_getopt_clear_r(&opt);
|
||||
while ((c = ipcom_getopt_r(argc, argv, "AHPRad:hprsV:i:", &opt)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'a':
|
||||
ret = iplite_ndp_print_neighbor_cache_entries();
|
||||
break;
|
||||
case 'A':
|
||||
ret = iplite_ndp_erase_all_neighbor_cache_entries();
|
||||
break;
|
||||
case 'd':
|
||||
ret = iplite_ndp_remove_neighbor_cache_entry(opt.optarg);
|
||||
break;
|
||||
case 'r':
|
||||
ret = iplite_ndp_print_default_router_entries();
|
||||
break;
|
||||
case 'R':
|
||||
ret = iplite_ndp_remove_all_default_router_entries();
|
||||
break;
|
||||
case 's':
|
||||
if (argc < opt.optind + 2)
|
||||
goto done;
|
||||
ret = iplite_ndp_add_entry(ifindex, argv[opt.optind], argv[opt.optind+1]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (ret == 17)
|
||||
iplite_ndp_print_usage();
|
||||
ipcom_printf(IP_LF);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_cmd_netstat.c,v $ $Revision: 1.21 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_cmd_netstat.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_cmd.h>
|
||||
#include <ipcom_getopt.h>
|
||||
#include <ipcom_sock.h>
|
||||
|
||||
#include "iplite_cmd.h"
|
||||
#include "iplite.h"
|
||||
#include "iplite_h.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
#define IPLITE_NETSTAT_STRLEN 256
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC int iplite_cmd_netstat(int argc, char **argv);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC Iplite_cmd_int_str_map af_map[] =
|
||||
{
|
||||
{ IP_AF_INET, "INET" },
|
||||
{ IP_AF_INET6, "INET6" },
|
||||
{ -1, IP_NULL }
|
||||
};
|
||||
|
||||
IP_STATIC Iplite_cmd_int_str_map proto_map[] =
|
||||
{
|
||||
{ IP_IPPROTO_TCP, "TCP" },
|
||||
{ IP_IPPROTO_UDP, "UDP" },
|
||||
{ IP_IPPROTO_ICMP, "ICMP" },
|
||||
{ IP_IPPROTO_ICMPV6, "ICMP6" },
|
||||
{ IP_IPPROTO_IP, "IP" },
|
||||
{ IP_IPPROTO_IPV4, "IPv4" },
|
||||
{ IP_IPPROTO_IPV6, "IPv6" },
|
||||
{ -1, IP_NULL }
|
||||
};
|
||||
|
||||
#ifdef IPCOM_USE_TCP
|
||||
IP_STATIC IP_CONST char *tcp_state_list[] =
|
||||
{
|
||||
"",
|
||||
"CLOSED",
|
||||
"LISTEN",
|
||||
"SYN_SENT",
|
||||
"SYN_RCVD",
|
||||
"ESTABLISHED",
|
||||
"CLOSE_WAIT",
|
||||
"FIN_WAIT_1",
|
||||
"CLOSING",
|
||||
"LAST_ACK",
|
||||
"FIN_WAIT_2",
|
||||
"TIME_WAIT"
|
||||
};
|
||||
#endif /* IPCOM_USE_TCP */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_netstat_print_entries
|
||||
*===========================================================================
|
||||
* Description: Prints the status of IPLITE sockets.
|
||||
* Parameters: af - The address family to print status for or -1 for all
|
||||
* address family types.
|
||||
* proto - The protocol to print status for or -1 for all
|
||||
* protocols.
|
||||
* show_unconnected - IP_TRUE if both connected and unconnected
|
||||
* sockets status should be printed.
|
||||
* no_dns - IP_TRUE if the addresses should not be resolved to
|
||||
* there DNS names.
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
iplite_netstat_print_entries(int af, int proto, Ip_bool show_unconnected, Ip_bool no_dns)
|
||||
{
|
||||
int p, x, a, y;
|
||||
char str[IPLITE_NETSTAT_STRLEN];
|
||||
struct Iplite_tag_sock_data tag;
|
||||
int ret;
|
||||
Ip_u16 dport;
|
||||
|
||||
for (y = 0; af_map[y].key != -1; y++)
|
||||
{
|
||||
if (af != 0)
|
||||
a = af;
|
||||
else
|
||||
a = af_map[y].key;
|
||||
ipcom_printf("%s sockets\n", iplite_cmd_key_to_str(af_map, a));
|
||||
ipcom_printf("%-6s%-4s%-30s%-30s%-5s\n",
|
||||
"Prot", "Fd", "Local Address", "Foreign Address", "State");
|
||||
|
||||
for (x = 0; proto_map[x].key != -1; x++)
|
||||
{
|
||||
if (proto != -1)
|
||||
p = proto;
|
||||
else
|
||||
p = proto_map[x].key;
|
||||
|
||||
tag.hdr.type = IPLITE_CTRL_NEW_ENUM_SOCK_DATA;
|
||||
tag.hdr.size = sizeof(tag);
|
||||
for (;;)
|
||||
{
|
||||
ret = iplite_ctrl(&tag.hdr);
|
||||
if (ret == IPLITE_CTRL_ENUM_DONE)
|
||||
break;
|
||||
if (ret < 0)
|
||||
{
|
||||
ipcom_printf("iplite_ctrl() failed (%d)\n", -ret);
|
||||
return;
|
||||
}
|
||||
tag.hdr.type = IPLITE_CTRL_CONT_ENUM_SOCK_DATA;
|
||||
|
||||
if (tag.protocol != p || tag.domain != a)
|
||||
continue;
|
||||
|
||||
dport = ip_ntohs(((struct Ip_sockaddr_in *) &tag.daddr)->sin_port);
|
||||
if (!show_unconnected && dport == 0)
|
||||
/* Show only connected sockets */
|
||||
continue;
|
||||
|
||||
ipcom_printf("%-6s", iplite_cmd_key_to_str(proto_map, tag.protocol));
|
||||
ipcom_printf("%-4d", tag.fd);
|
||||
ipcom_printf("%-30s",
|
||||
ipcom_cmd_sockaddr_to_str(&tag.saddr.addr, IP_TRUE, no_dns, str, sizeof(str)));
|
||||
ipcom_printf("%-30s",
|
||||
ipcom_cmd_sockaddr_to_str(&tag.daddr.addr, IP_TRUE, no_dns, str, sizeof(str)));
|
||||
|
||||
#ifdef IPCOM_USE_TCP
|
||||
if (tag.protocol == IP_IPPROTO_TCP)
|
||||
ipcom_printf("%-11s", tcp_state_list[tag.tcp_state]);
|
||||
|
||||
#endif /* IPCOM_USE_TCP */
|
||||
ipcom_printf("\n");
|
||||
}
|
||||
|
||||
if (proto != -1)
|
||||
break;
|
||||
}
|
||||
ipcom_printf("\n");
|
||||
if (af != -1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_cmd_netstat
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
iplite_cmd_netstat(int argc, char **argv)
|
||||
{
|
||||
int i, c;
|
||||
int proto = -1;
|
||||
int af = 0;
|
||||
Ip_bool show_unconnected = IP_FALSE;
|
||||
Ip_bool no_dns = IP_FALSE;
|
||||
Ipcom_getopt opt;
|
||||
|
||||
ipcom_getopt_clear_r(&opt);
|
||||
while ((c = ipcom_getopt_r(argc, argv, "?hHaf:p:nV:", &opt)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '?':
|
||||
case 'h':
|
||||
case 'H':
|
||||
goto usage;
|
||||
case 'a':
|
||||
show_unconnected = IP_TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
for (i = 0; af_map[i].key != -1; i++)
|
||||
if (ipcom_strcasecmp(opt.optarg, af_map[i].str) == 0)
|
||||
{
|
||||
af = af_map[i].key;
|
||||
break;
|
||||
}
|
||||
if (af_map[i].key == -1)
|
||||
goto usage;
|
||||
break;
|
||||
case 'p':
|
||||
for (i = 0; proto_map[i].key != -1; i++)
|
||||
if (ipcom_strcasecmp(opt.optarg, proto_map[i].str) == 0)
|
||||
{
|
||||
proto = proto_map[i].key;
|
||||
break;
|
||||
}
|
||||
if (proto_map[i].key == -1)
|
||||
goto usage;
|
||||
break;
|
||||
case 'n':
|
||||
no_dns = IP_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
iplite_netstat_print_entries(af, proto, show_unconnected, no_dns);
|
||||
|
||||
return 0;
|
||||
|
||||
usage:
|
||||
ipcom_printf("\n"
|
||||
"NAME\n"
|
||||
" netstat - show network status\n"
|
||||
"\n"
|
||||
"SYNOPSIS\n");
|
||||
ipcom_printf(" netstat [-anh] [-f address_family] [-p protocol]\n"
|
||||
"\n"
|
||||
"DESCRIPTION\n"
|
||||
" The netstat program displays and modifies the Internet-to-Ethernet address\n"
|
||||
" translation tables used by the address resolution protocol.\n"
|
||||
"\n");
|
||||
ipcom_printf(" -a Show the state of all sockets; normally sockets used by server\n"
|
||||
" processes are not shown.\n"
|
||||
" -f address_family\n"
|
||||
" Limit statistics or address control block reports to those of the\n"
|
||||
" specified address family. The following address families are\n"
|
||||
" recognized: inet for IPv4 (default) and inet6 for IPv6\n");
|
||||
ipcom_printf(" -h Help, this usage menu\n"
|
||||
" -n Show network addresses as numbers. Default is to lookup symbolic\n"
|
||||
" names for the addresses.\n"
|
||||
" -p protocol\n"
|
||||
" Show statistics about protocol, which is either a well-known name\n"
|
||||
" for a protocol or an alias for it.\n"
|
||||
"\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,444 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_cmd_ping.c,v $ $Revision: 1.25 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_cmd_ping.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_KERNEL
|
||||
#undef IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_cmd.h>
|
||||
#include <ipcom_getopt.h>
|
||||
#include <ipcom_inet.h>
|
||||
#include <ipcom_sock.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_cmd.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPLITE_ICMP4_TYPE_ECHO_REPLY 0
|
||||
#define IPLITE_ICMP4_TYPE_ECHO_REQUEST 8
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC int iplite_cmd_ping(int argc, char **argv);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ping_send_echo_request
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ping_send_echo_request(Ip_fd sock, struct Ip_sockaddr_in *to,
|
||||
Ip_u16 id, Ip_u16 seq, int icmp_len)
|
||||
{
|
||||
Iplite_pkt_icmp *echo_req;
|
||||
int i, ret;
|
||||
int data_len = icmp_len - 8;
|
||||
Ip_u16 *ping_data;
|
||||
|
||||
echo_req = ipcom_malloc(icmp_len);
|
||||
if (echo_req == IP_NULL)
|
||||
return -IP_ERRNO_ENOMEM;
|
||||
|
||||
ping_data = echo_req->data.echo.data;
|
||||
echo_req->type = IPLITE_ICMP4_TYPE_ECHO_REQUEST;
|
||||
echo_req->code = 0;
|
||||
echo_req->data.echo.id = ip_htons(id);
|
||||
echo_req->data.echo.seq = ip_htons(seq);
|
||||
for (i = 0; i < (data_len >> 1); i++)
|
||||
{
|
||||
int b1, b2;
|
||||
|
||||
b1 = i * 2 % (127 - ' ') + ' ';
|
||||
b2 = (i * 2 + 1) % (127 - ' ') + ' ';
|
||||
ping_data[i] = (Ip_u16)ip_htons((b1 << 8) | b2);
|
||||
}
|
||||
echo_req->cksum = 0;
|
||||
echo_req->cksum = ipcom_in_checksum(echo_req, (Ip_size_t)icmp_len);
|
||||
ret = ipcom_sendto(sock, echo_req, icmp_len, 0, (struct Ip_sockaddr*) to, to->sin_len);
|
||||
ipcom_free(echo_req);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ping_recv_echo_reply
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ping_recv_echo_reply(Ip_fd sock, struct Ip_sockaddr_in *from,
|
||||
Ip_u16 id, int icmp_len, int *res_size, int *hlim)
|
||||
{
|
||||
Ip_bool done = IP_FALSE;
|
||||
int totlen;
|
||||
Ip_socklen_t fromlen = from->sin_len;
|
||||
Iplite_pkt_ip *ip;
|
||||
Iplite_pkt_icmp *icmp;
|
||||
Ip_u16 *data;
|
||||
|
||||
data = ipcom_malloc(icmp_len + sizeof(Iplite_pkt_ip));
|
||||
if (data == IP_NULL)
|
||||
{
|
||||
ipcom_printf("Out of memory" IP_LF);
|
||||
return -IP_ERRNO_ENOMEM;
|
||||
}
|
||||
do
|
||||
{
|
||||
totlen = ipcom_recvfrom(sock, data, icmp_len + sizeof(Iplite_pkt_ip), 0, (struct Ip_sockaddr*) from, &fromlen);
|
||||
if (totlen < 0)
|
||||
goto cleanup;
|
||||
ip = (Iplite_pkt_ip*) data;
|
||||
icmp = (Iplite_pkt_icmp*) (data + (IPLITE_IP4_GET_VHL(ip) & 0x0F) * 4 / sizeof(*data));
|
||||
|
||||
if (icmp->type == IPLITE_ICMP4_TYPE_ECHO_REPLY
|
||||
&& ip_ntohs(icmp->data.echo.id) == id)
|
||||
{
|
||||
*hlim = IPLITE_IP4_GET_TTL(ip);
|
||||
*res_size = totlen - sizeof(Iplite_pkt_ip);
|
||||
done = IP_TRUE;
|
||||
}
|
||||
} while (!done);
|
||||
|
||||
cleanup:
|
||||
ipcom_free(data);
|
||||
return totlen;
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ping_print_usage
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
iplite_ping_print_usage(void)
|
||||
{
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf("NAME" IP_LF);
|
||||
ipcom_printf(" ping - send ICMPv4 ECHO_REQUEST packets to network hosts" IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf("SYNOPSIS" IP_LF);
|
||||
ipcom_printf(" ping [-nb] [-c count] [-T ttl] [-s packetsize] [-V routetab] host" IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf("DESCRIPTION" IP_LF);
|
||||
ipcom_printf(" ping uses the ICMPv4 protocol's mandatory ECHO_REQUEST datagram to" IP_LF);
|
||||
ipcom_printf(" elicit an ECHO_REPLY from a host or gateway." IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf(" -b Allow pinging a broadcast address." IP_LF);
|
||||
ipcom_printf(" -c count" IP_LF);
|
||||
ipcom_printf(" Stop after sending count ECHO_RESPONSE packets." IP_LF);
|
||||
ipcom_printf(" -T ttl Use the specified time-to-live." IP_LF);
|
||||
ipcom_printf(" -s packetsize" IP_LF);
|
||||
ipcom_printf(" Specifies the number of data bytes to be sent. The default is" IP_LF);
|
||||
ipcom_printf(" 56, which translates into 64 ICMP data bytes when combined with" IP_LF);
|
||||
ipcom_printf(" -S src_addr Specifies the address to use a source address when sending." IP_LF);
|
||||
ipcom_printf(" the 8 bytes of ICMP header data." IP_LF);
|
||||
ipcom_printf(" -t Ping the specified host until stopped." IP_LF);
|
||||
ipcom_printf(" -n Numeric output only. No attempts will be made to look up" IP_LF);
|
||||
ipcom_printf(" names for host addresses." IP_LF);
|
||||
ipcom_printf(" -V routetab Specify route table. 0 if not specified."IP_LF);
|
||||
ipcom_printf(" -w timeout in milliseconds, default is 1000 ms."IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_cmd_ping
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
iplite_cmd_ping(int argc, char **argv)
|
||||
{
|
||||
Ip_fd sock = IP_SOCKERR;
|
||||
int var;
|
||||
int req_size = 64;
|
||||
int ttl = 255;
|
||||
int count = 4;
|
||||
int i;
|
||||
int res_size;
|
||||
int timeout_msec = 1000;
|
||||
struct Ip_sockaddr_in to;
|
||||
struct Ip_sockaddr_in from;
|
||||
struct Ip_timeval tv;
|
||||
char str_addr[40];
|
||||
char targetaddr[16];
|
||||
char targetname[256];
|
||||
int err = 0;
|
||||
int no_dns = IP_FALSE;
|
||||
Ipcom_getopt opt;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
iplite_ping_print_usage();
|
||||
goto errout;
|
||||
}
|
||||
|
||||
sock = ipcom_socket(IP_AF_INET, IP_SOCK_RAW, IP_IPPROTO_ICMP);
|
||||
if (sock == IP_SOCKERR)
|
||||
{
|
||||
ipcom_printf("ipcom_socket() failed (%d)" IP_LF, ipcom_errno);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ipcom_getopt_clear_r(&opt);
|
||||
while ((i = ipcom_getopt_r(argc, argv, "bc:s:S:tT:n:w:", &opt)) != -1)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 'b':
|
||||
err = 1;
|
||||
err = ipcom_setsockopt(sock, IP_SOL_SOCKET, IP_SO_BROADCAST, &err, sizeof(err));
|
||||
if (err < 0)
|
||||
{
|
||||
ipcom_printf("ipcom_setsockopt() IP_SO_BROADCAST ");
|
||||
goto errout;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
count = ipcom_atoi(opt.optarg);
|
||||
break;
|
||||
case 's':
|
||||
req_size = ipcom_atoi(opt.optarg);
|
||||
if (req_size < 8)
|
||||
{
|
||||
ipcom_printf("Data length must be 8 or greater." IP_LF);
|
||||
goto errout;
|
||||
}
|
||||
break;
|
||||
case 'S':
|
||||
from.sin_family = IP_AF_INET;
|
||||
from.sin_len = sizeof(from);
|
||||
from.sin_port = 0;
|
||||
(void)ipcom_inet_pton(IP_AF_INET, opt.optarg, &from.sin_addr);
|
||||
err = ipcom_bind(sock, (struct Ip_sockaddr *) &from, sizeof(from));
|
||||
if (err < 0)
|
||||
{
|
||||
ipcom_printf("ipcom_bind(%s) ", opt.optarg);
|
||||
goto errout;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
count = -1;
|
||||
break;
|
||||
case 'T':
|
||||
ttl = ipcom_atoi(opt.optarg);
|
||||
break;
|
||||
case 'n':
|
||||
no_dns = IP_TRUE;
|
||||
break;
|
||||
case 'w':
|
||||
timeout_msec = ipcom_atoi(opt.optarg);
|
||||
break;
|
||||
default:
|
||||
ipcom_printf("'%c' is a unknown switch", i);
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the size of the send buffer so that the ping message fit
|
||||
(ICMP header + ICMP payload) */
|
||||
err = ipcom_setsockopt(sock, IP_SOL_SOCKET, IP_SO_SNDBUF, &req_size, sizeof(req_size));
|
||||
if (err < 0)
|
||||
{
|
||||
ipcom_printf("ipcom_setsockopt() IP_SO_SNDBUF ");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Set the size of the receive buffer so that the ping message fit
|
||||
(IPv4 header + ICMP header + ICMP payload) */
|
||||
var = req_size + 20;
|
||||
err = ipcom_setsockopt(sock, IP_SOL_SOCKET, IP_SO_RCVBUF, &var, sizeof(var));
|
||||
if (err < 0)
|
||||
{
|
||||
ipcom_printf("ipcom_setsockopt() IP_SO_RCVBUF ");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
err = ipcom_setsockopt(sock, IP_IPPROTO_IP, IP_IP_TTL, &ttl, sizeof(ttl));
|
||||
if (err < 0)
|
||||
{
|
||||
ipcom_printf("ipcom_setsockopt() IP_IP_TTL ");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
err = ipcom_getsockaddrbyaddrname(IP_AF_INET,
|
||||
no_dns, argv[argc-1], (struct Ip_sockaddr *) &to);
|
||||
if (err)
|
||||
goto errout;
|
||||
|
||||
(void)ipcom_cmd_sockaddr_to_str((struct Ip_sockaddr *) &to,
|
||||
IP_FALSE, IP_TRUE, targetaddr, sizeof(targetaddr));
|
||||
(void)ipcom_cmd_sockaddr_to_str((struct Ip_sockaddr *) &to,
|
||||
IP_FALSE, no_dns, targetname, sizeof(targetname));
|
||||
|
||||
ipcom_printf("\nPinging %s (%s) with %d bytes of data:" IP_LF,targetname, targetaddr, req_size);
|
||||
|
||||
for (i = 0; count == -1 || i < count; i++)
|
||||
{
|
||||
struct Ip_timeval tstart;
|
||||
struct Ip_timeval tstop;
|
||||
int msec;
|
||||
Ip_u16 id;
|
||||
Ip_bool dup;
|
||||
|
||||
ipcom_microtime(&tstart);
|
||||
id = (Ip_u16) (ipcom_getpid() + tstart.tv_sec + tstart.tv_usec);
|
||||
err = iplite_ping_send_echo_request(sock, &to, id, (Ip_u16) i, req_size);
|
||||
if (err < 0)
|
||||
{
|
||||
ipcom_printf("Echo request ");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
msec = 0;
|
||||
dup = IP_FALSE;
|
||||
for (;;)
|
||||
{
|
||||
tv.tv_sec = (long)((timeout_msec - msec) / 1000);
|
||||
tv.tv_usec = ((timeout_msec - msec) % 1000) * 1000;
|
||||
err = ipcom_setsockopt(sock, IP_SOL_SOCKET, IP_SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
if (err < 0)
|
||||
{
|
||||
ipcom_printf("ipcom_setsockopt() IP_SO_RCVTIMEO ");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
from.sin_len = sizeof(struct Ip_sockaddr_in);
|
||||
err = iplite_ping_recv_echo_reply(sock, &from, id, req_size, &res_size, &ttl);
|
||||
if (err < 0)
|
||||
break;
|
||||
ipcom_microtime(&tstop);
|
||||
msec = (tstop.tv_usec - tstart.tv_usec) / 1000 + (tstop.tv_sec - tstart.tv_sec) * 1000;
|
||||
if (msec > timeout_msec)
|
||||
break;
|
||||
|
||||
ipcom_printf("Reply from %s bytes=%d time=%dms ttl=%d %s" IP_LF,
|
||||
ipcom_inet_ntop(IP_AF_INET, &from.sin_addr, str_addr, sizeof(str_addr)),
|
||||
res_size, msec, ttl, dup ? "(DUP!)" : "");
|
||||
dup = IP_TRUE;
|
||||
}
|
||||
if (dup == IP_FALSE)
|
||||
ipcom_printf("Request timed out: %s (%d)." IP_LF, ipcom_strerror(ipcom_errno), ipcom_errno);
|
||||
|
||||
ipcom_microtime(&tstop);
|
||||
msec = (tstop.tv_usec - tstart.tv_usec) / 1000 + (tstop.tv_sec - tstart.tv_sec) * 1000;
|
||||
if (msec < timeout_msec)
|
||||
ipcom_millisleep(timeout_msec - msec);
|
||||
err = 0;
|
||||
}
|
||||
ipcom_printf(IP_LF);
|
||||
|
||||
errout:
|
||||
if (err < 0)
|
||||
{
|
||||
err = ipcom_errno;
|
||||
ipcom_printf("operation failed: %s (%d)" IP_LF, ipcom_strerror(err), err);
|
||||
}
|
||||
if (sock != IP_SOCKERR)
|
||||
ipcom_socketclose(sock);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif /* IPCOM_USE_INET */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,426 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_cmd_ping6.c,v $ $Revision: 1.25 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_cmd_ping6.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_KERNEL
|
||||
#undef IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_cmd.h>
|
||||
#include <ipcom_getopt.h>
|
||||
#include <ipcom_sock.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_cmd.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC int iplite_cmd_ping6(int argc, char **argv);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ping6_send_echo_request
|
||||
*===========================================================================
|
||||
* Description: Creates a ICMPv6 echo request message and sends it to the
|
||||
* specified address.
|
||||
* Parameters: sock - The socket to use when sending the message.
|
||||
* to - The recipient of the message.
|
||||
* id - The id to use in the echo request.
|
||||
* seq - The sequence number to use in the echo request.
|
||||
* icmp_len - The total length of the ICMPv6 message,
|
||||
* including header.
|
||||
* Returns: >0 = number of bytes sent (success), <0 = error code.
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ping6_send_echo_request(Ip_fd sock, struct Ip_sockaddr_in6 *to,
|
||||
Ip_u16 id, Ip_u16 seq, int icmp_len)
|
||||
{
|
||||
Iplite_pkt_icmp6 *echo_req;
|
||||
int i, ret;
|
||||
int data_len = icmp_len - 8;
|
||||
Ip_u16 *ping_data;
|
||||
|
||||
echo_req = ipcom_malloc(icmp_len);
|
||||
if (echo_req == IP_NULL)
|
||||
return IP_SOCKERR;
|
||||
IPLITE_ICMP6_SET_TYPE(echo_req, IPLITE_ICMP6_TYPE_ECHO_REQUEST);
|
||||
IPLITE_ICMP6_SET_CODE(echo_req, 0);
|
||||
echo_req->cksum = 0; /* Is calculate by the IP stack */
|
||||
echo_req->data.d16[0] = ip_htons(id);
|
||||
echo_req->data.d16[1] = ip_htons(seq);
|
||||
ping_data = (Ip_u16 *)(echo_req + 1);
|
||||
for (i = 0; i < (data_len >> 1); i++)
|
||||
{
|
||||
int b1, b2;
|
||||
|
||||
b1 = i * 2 % (127 - ' ') + ' ';
|
||||
b2 = (i * 2 + 1) % (127 - ' ') + ' ';
|
||||
ping_data[i] = (Ip_u16)(ip_htons((b1 << 8) | b2));
|
||||
}
|
||||
ret = ipcom_sendto(sock, echo_req, icmp_len, 0, (struct Ip_sockaddr*) to, to->sin6_len);
|
||||
ipcom_free(echo_req);
|
||||
if (ret && ipcom_errno == IP_ERRNO_ENOBUFS)
|
||||
/* Packet dropped due to missing NDP response */
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ping6_recv_echo_reply
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ping6_recv_echo_reply(Ip_fd sock, struct Ip_sockaddr_in6 *from,
|
||||
Ip_u16 id, int icmp_len, int *response_size)
|
||||
{
|
||||
int tries = 4;
|
||||
int bytes_recv;
|
||||
Ip_socklen_t fromlen;
|
||||
Iplite_pkt_icmp6 *icmp6;
|
||||
Ip_u8 *data;
|
||||
|
||||
data = ipcom_malloc(icmp_len + IPLITE_IP6_HDR_SIZE);
|
||||
if (data == IP_NULL)
|
||||
return -IP_ERRNO_ENOMEM;
|
||||
do
|
||||
{
|
||||
fromlen = sizeof(struct Ip_sockaddr_in6);
|
||||
bytes_recv = ipcom_recvfrom(sock, data, icmp_len + IPLITE_IP6_HDR_SIZE, 0,
|
||||
(struct Ip_sockaddr *) from, &fromlen);
|
||||
if (bytes_recv < 0)
|
||||
{
|
||||
ipcom_free(data);
|
||||
return -1;
|
||||
}
|
||||
|
||||
icmp6 = (Iplite_pkt_icmp6*) data;
|
||||
|
||||
if (IPLITE_ICMP6_GET_TYPE(icmp6) == IPLITE_ICMP6_TYPE_ECHO_REPLY
|
||||
&& ip_ntohs(icmp6->data.d16[0]) == id)
|
||||
{
|
||||
*response_size = bytes_recv;
|
||||
tries = 0;
|
||||
}
|
||||
} while (tries--);
|
||||
|
||||
ipcom_free(data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ping6_print_usage
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
iplite_ping6_print_usage(void)
|
||||
{
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf("NAME" IP_LF);
|
||||
ipcom_printf(" ping6 - send ICMPv6 ECHO_REQUEST packets to network hosts" IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf("SYNOPSIS" IP_LF);
|
||||
ipcom_printf(" ping6 [-n] [-c count] [-h hoplimit] [-s packetsize] [-V routetab] host" IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf("DESCRIPTION" IP_LF);
|
||||
ipcom_printf(" ping6 uses the ICMPv6 protocol's mandatory ICMP6_ECHO_REQUEST datagram to" IP_LF);
|
||||
ipcom_printf(" elicit an ICMP6_ECHO_REPLY from a host or gateway. ICMP6_ECHO_REQUEST" IP_LF);
|
||||
ipcom_printf(" datagrams (``pings'') have an IPv6 header, and ICMPv6 header formatted as" IP_LF);
|
||||
ipcom_printf(" documented in RFC2463." IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
ipcom_printf(" -c count" IP_LF);
|
||||
ipcom_printf(" Stop after sending count ECHO_RESPONSE packets." IP_LF);
|
||||
ipcom_printf(" -h hoplimit" IP_LF);
|
||||
ipcom_printf(" Set the IPv6 hoplimit." IP_LF);
|
||||
ipcom_printf(" -s packetsize" IP_LF);
|
||||
ipcom_printf(" Specifies the number of data bytes to be sent. The default is" IP_LF);
|
||||
ipcom_printf(" 56, which translates into 64 ICMP data bytes when combined with" IP_LF);
|
||||
ipcom_printf(" the 8 bytes of ICMP header data." IP_LF);
|
||||
ipcom_printf(" -t Ping the specified host until stopped." IP_LF);
|
||||
ipcom_printf(" -n Numeric output only. No attempts will be made to look up" IP_LF);
|
||||
ipcom_printf(" names for host addresses." IP_LF);
|
||||
ipcom_printf(" -V routetab Specify route table. <routetab> = 0 if not specified."IP_LF);
|
||||
ipcom_printf(" -w timeout in milliseconds, default is 1000 ms."IP_LF);
|
||||
ipcom_printf(IP_LF);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_cmd_ping6
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
iplite_cmd_ping6(int argc, char **argv)
|
||||
{
|
||||
Ip_fd sock = IP_SOCKERR;
|
||||
int req_size = 64;
|
||||
int var;
|
||||
int hlim;
|
||||
int count = 4;
|
||||
int i;
|
||||
int timeout_msec = 1000;
|
||||
struct Ip_sockaddr_in6 to;
|
||||
struct Ip_sockaddr_in6 from;
|
||||
char str_addr[IP_INET6_ADDRSTRLEN];
|
||||
char targetaddr[IP_INET6_ADDRSTRLEN];
|
||||
char targetname[256];
|
||||
struct Ip_timeval tv;
|
||||
int err = 0;
|
||||
int no_dns = IP_FALSE;
|
||||
Ipcom_getopt opt;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
iplite_ping6_print_usage();
|
||||
goto errout;
|
||||
}
|
||||
|
||||
sock = ipcom_socket(IP_AF_INET6, IP_SOCK_RAW, IP_IPPROTO_ICMPV6);
|
||||
if (sock == IP_SOCKERR)
|
||||
{
|
||||
ipcom_printf("ipcom_socket, errno %d ", ipcom_errno);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ipcom_getopt_clear_r(&opt);
|
||||
while ((i = ipcom_getopt_r(argc, argv, "c:h:s:tnw:", &opt)) != -1)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 'c':
|
||||
count = ipcom_atoi(opt.optarg);
|
||||
break;
|
||||
case 'h':
|
||||
hlim = ipcom_atoi(opt.optarg);
|
||||
if (ipcom_setsockopt(sock, IP_IPPROTO_IPV6, IP_IPV6_UNICAST_HOPS, &hlim, sizeof(hlim)))
|
||||
{
|
||||
ipcom_printf("ipcom_setsockopt IP_IPV6_UNICAST_HOPS ");
|
||||
goto errout;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
req_size = ipcom_atoi(opt.optarg);
|
||||
if (req_size < 8)
|
||||
{
|
||||
ipcom_printf("Data length must be 8 or greater." IP_LF);
|
||||
goto errout;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
count = -1;
|
||||
break;
|
||||
case 'n':
|
||||
no_dns = IP_TRUE;
|
||||
break;
|
||||
case 'w':
|
||||
timeout_msec = ipcom_atoi(opt.optarg);
|
||||
break;
|
||||
default:
|
||||
ipcom_printf("'%c' is a unknown switch", i);
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
|
||||
err = ipcom_getsockaddrbyaddrname(IP_AF_INET6,
|
||||
no_dns, argv[argc-1], (struct Ip_sockaddr *) &to);
|
||||
if (err)
|
||||
goto errout;
|
||||
|
||||
/* Set the size of the send buffer so that the ping message fit
|
||||
(ICMPv6 header + ICMPv6 payload) */
|
||||
err = ipcom_setsockopt(sock, IP_SOL_SOCKET, IP_SO_SNDBUF, &req_size, sizeof(req_size));
|
||||
if (err < 0)
|
||||
{
|
||||
ipcom_printf("ipcom_setsockopt() IP_SO_SNDBUF ");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Set the size of the receive buffer so that the ping message fit
|
||||
(IPv6 header + ICMPv6 header + ICMPv6 payload) */
|
||||
var = (req_size + 40) * 4;
|
||||
err = ipcom_setsockopt(sock, IP_SOL_SOCKET, IP_SO_RCVBUF, &var, sizeof(var));
|
||||
if (err < 0)
|
||||
{
|
||||
ipcom_printf("ipcom_setsockopt() IP_SO_RCVBUF ");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
(void)ipcom_cmd_sockaddr_to_str((struct Ip_sockaddr *) &to,
|
||||
IP_FALSE, IP_TRUE, targetaddr, sizeof(targetaddr));
|
||||
(void)ipcom_cmd_sockaddr_to_str((struct Ip_sockaddr *) &to,
|
||||
IP_FALSE, no_dns, targetname, sizeof(targetname));
|
||||
|
||||
ipcom_printf("\nPinging %s (%s) with %d bytes of data:" IP_LF, targetname, targetaddr, req_size);
|
||||
|
||||
for (i = 0; count == -1 || i < count; i++)
|
||||
{
|
||||
struct Ip_timeval tstart;
|
||||
struct Ip_timeval tstop;
|
||||
int msec;
|
||||
Ip_bool at_least_one_pkt_recv;
|
||||
int response_size;
|
||||
Ip_u16 id;
|
||||
|
||||
ipcom_microtime(&tstart);
|
||||
id = (Ip_u16) (ipcom_getpid() + tstart.tv_sec + tstart.tv_usec);
|
||||
err = iplite_ping6_send_echo_request(sock, &to, id, (Ip_u16) i, req_size);
|
||||
if (err < 0)
|
||||
{
|
||||
ipcom_printf("Echo request ");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
msec = 0;
|
||||
at_least_one_pkt_recv = IP_FALSE;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Receive all answers to the ping request (might be duplicates) */
|
||||
tv.tv_sec = (timeout_msec - msec) / 1000;
|
||||
tv.tv_usec = ((timeout_msec - msec) % 1000) * 1000;
|
||||
err = ipcom_setsockopt(sock, IP_SOL_SOCKET, IP_SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
if (err < 0)
|
||||
{
|
||||
ipcom_printf("ipcom_setsockopt IP_SO_RCVTIMEO ");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
err = iplite_ping6_recv_echo_reply(sock, &from, id, req_size, &response_size);
|
||||
if (err < 0)
|
||||
break;
|
||||
ipcom_microtime(&tstop);
|
||||
msec = (tstop.tv_usec - tstart.tv_usec) / 1000 + (tstop.tv_sec - tstart.tv_sec) * 1000;
|
||||
if (msec > timeout_msec)
|
||||
break;
|
||||
|
||||
ipcom_printf("Reply from %s bytes=%d time=%dms %s" IP_LF,
|
||||
ipcom_inet_ntop(IP_AF_INET6, &from.sin6_addr, str_addr, sizeof(str_addr)),
|
||||
response_size, msec, at_least_one_pkt_recv ? "(DUP!)" : "");
|
||||
at_least_one_pkt_recv = IP_TRUE;
|
||||
}
|
||||
if (at_least_one_pkt_recv == IP_FALSE)
|
||||
ipcom_printf("Request timed out: %s (%d)." IP_LF, ipcom_strerror(ipcom_errno), ipcom_errno);
|
||||
else
|
||||
err = 0;
|
||||
|
||||
ipcom_microtime(&tstop);
|
||||
msec = (tstop.tv_usec - tstart.tv_usec) / 1000 + (tstop.tv_sec - tstart.tv_sec) * 1000;
|
||||
if (msec < timeout_msec)
|
||||
ipcom_millisleep(timeout_msec - msec);
|
||||
}
|
||||
ipcom_printf(IP_LF);
|
||||
|
||||
errout:
|
||||
if (err < 0)
|
||||
{
|
||||
err = ipcom_errno;
|
||||
ipcom_printf("operation failed: %s (%d)" IP_LF, ipcom_strerror(err), err);
|
||||
}
|
||||
if (sock != IP_SOCKERR)
|
||||
ipcom_socketclose(sock);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_cmd_route.c,v $ $Revision: 1.17.24.1 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_cmd_route.c,v $
|
||||
* $Author: hxie $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Lennart Bang <lob@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_KERNEL
|
||||
#undef IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_sock.h>
|
||||
#include <ipcom_sock6.h>
|
||||
#include <ipcom_inet.h>
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC int iplite_cmd_route(int argc, char **argv);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_cmd_route
|
||||
*===========================================================================
|
||||
* Description: The entry point for the 'route' shell command.
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
iplite_cmd_route(int argc, char **argv)
|
||||
{
|
||||
char addrstr[46];
|
||||
#ifdef IPCOM_USE_INET6
|
||||
union Ip_sockaddr_union sau;
|
||||
#endif
|
||||
Ip_fd sock = IP_INVALID_SOCKET;
|
||||
int ret = 0;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
/* Usage */
|
||||
usage:
|
||||
ipcom_printf("NAME" IP_LF
|
||||
" route - manually manipulate the default gateway(s)" IP_LF
|
||||
"" IP_LF
|
||||
"SYNOPSIS" IP_LF
|
||||
" route <command> [new gateway]" IP_LF
|
||||
"" IP_LF);
|
||||
ipcom_printf("DESCRIPTION" IP_LF
|
||||
" Although IPLITE does not have a routing table it supports the notion" IP_LF
|
||||
" of default gateways (one for IPv4 and one for IPv6). Consequently, the" IP_LF
|
||||
" IPLITE route shell command can only be used to display or modify the" IP_LF
|
||||
" default gateway(s)."IP_LF
|
||||
"" IP_LF);
|
||||
ipcom_printf("COMMANDS" IP_LF
|
||||
" The route utility provides the following commands:" IP_LF
|
||||
" get Get IPv4 gateway." IP_LF
|
||||
" set Set IPv4 gateway." IP_LF
|
||||
" get6 Get IPv6 gateway." IP_LF
|
||||
" set6 Set IPv6 gateway." IP_LF
|
||||
"" IP_LF);
|
||||
ipcom_printf("EXAMPLES" IP_LF
|
||||
" (1) Set default IPv4 gateway to 10.1.1.1: " IP_LF
|
||||
" > route set 10.1.1.1" IP_LF
|
||||
" (2) Get default IPv6 gateway: " IP_LF
|
||||
" > route get6" IP_LF
|
||||
"" IP_LF);
|
||||
goto out;
|
||||
}
|
||||
|
||||
#ifdef IP_PORT_VXWORKS
|
||||
#ifdef IPCOM_USE_INET
|
||||
sock = ipcom_socket(IP_AF_INET, IP_SOCK_DGRAM, 0);
|
||||
#else
|
||||
sock = ipcom_socket(IP_AF_INET6, IP_SOCK_DGRAM, 0);
|
||||
#endif
|
||||
if (sock == IP_INVALID_SOCKET)
|
||||
{
|
||||
ipcom_printf("route: ipcom_socket() failed: %s"IP_LF, ipcom_strerror(ipcom_errno));
|
||||
return 0;
|
||||
}
|
||||
#endif /* IP_PORT_VXWORKS */
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
if (ipcom_strcmp(argv[1], "get") == 0)
|
||||
{
|
||||
struct Ip_ortentry ort;
|
||||
if (ipcom_socketioctl(sock, IP_SIOCXGETRT, &ort) == 0)
|
||||
{
|
||||
(void)ipcom_inet_ntop(IP_AF_INET,
|
||||
&((struct Ip_sockaddr_in *)&ort.rt_gateway)->sin_addr,
|
||||
addrstr, sizeof(addrstr));
|
||||
ipcom_printf("IPv4 default gateway: %s"IP_LF, addrstr);
|
||||
}
|
||||
else
|
||||
ipcom_printf("route: ioctl(IP_SIOCXGETRT) failed: %s"IP_LF, ipcom_strerror(ipcom_errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (ipcom_strcmp(argv[1], "set") == 0 && argc > 2)
|
||||
{
|
||||
struct Ip_ortentry ort;
|
||||
if(ipcom_getsockaddrbyaddr(IP_AF_INET, argv[2], &ort.rt_gateway) != 0)
|
||||
{
|
||||
ipcom_printf("route: invalid IPv4 gateway: '%s'"IP_LF, argv[2]);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
(void)ipcom_socketioctl(sock, IP_SIOCADDRT, &ort);
|
||||
ipcom_printf("route: ok"IP_LF);
|
||||
goto out;
|
||||
}
|
||||
#endif /* IPCOM_USE_INET */
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
if (ipcom_strcmp(argv[1], "get6") == 0)
|
||||
{
|
||||
(void)ipcom_socketioctl(sock, IP_SIOCXGETGW_IN6, &sau.sin6);
|
||||
(void)ipcom_inet_ntop(IP_AF_INET6, &sau.sin6.sin6_addr, addrstr, sizeof(addrstr));
|
||||
ipcom_printf("IPv6 default gateway: %s", addrstr);
|
||||
if (IP_IN6_IS_ADDR_LINK_LOCAL(&sau.sin6.sin6_addr))
|
||||
ipcom_printf("%%%s"IP_LF, ipcom_if_indextoname(sau.sin6.sin6_scope_id, addrstr));
|
||||
else
|
||||
ipcom_printf(IP_LF);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (ipcom_strcmp(argv[1], "set6") == 0 && argc > 2)
|
||||
{
|
||||
if(ipcom_getsockaddrbyaddr(IP_AF_INET6, argv[2], &sau.sa) != 0)
|
||||
{
|
||||
ipcom_printf("route: invalid IPv6 gateway: '%s'"IP_LF, argv[2]);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
(void)ipcom_socketioctl(sock, IP_SIOCXSETGW_IN6, &sau.sin6);
|
||||
ipcom_printf("route: ok"IP_LF);
|
||||
goto out;
|
||||
}
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
|
||||
goto usage;
|
||||
|
||||
out:
|
||||
#ifdef IP_PORT_VXWORKS
|
||||
if (sock != IP_INVALID_SOCKET)
|
||||
{
|
||||
ipcom_socketclose(sock);
|
||||
sock = IP_INVALID_SOCKET;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,335 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_ctrl.c,v $ $Revision: 1.31 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_ctrl.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $o
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* Functions for IP_PUBLIC int iplite_ctrl(struct Iplite_tag *tag) function.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_clib.h>
|
||||
|
||||
#include "iplite.h"
|
||||
#include "iplite_cmd.h"
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_sock.h"
|
||||
|
||||
#ifdef IPCOM_USE_TCP
|
||||
#include "iplite_tcp.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC int iplite_ctrl_sock(struct Iplite_tag *tag);
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
IP_STATIC int iplite_ctrl_ip6_nc(struct Iplite_tag *tag);
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ctrl_sock
|
||||
*===========================================================================
|
||||
* Description: Get state of sockets.
|
||||
* Parameters: tag - The tag structure fill in.
|
||||
* Returns: 0 >= success, <0 error code.
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ctrl_sock(struct Iplite_tag *tag)
|
||||
{
|
||||
struct Iplite_tag_sock_data *sock_tag;
|
||||
|
||||
sock_tag = (struct Iplite_tag_sock_data*) tag;
|
||||
|
||||
if (tag->size < sizeof(*sock_tag))
|
||||
{
|
||||
tag->size = sizeof(*sock_tag);
|
||||
return -IP_ERRNO_ENOSPC;
|
||||
}
|
||||
|
||||
if (tag->type == IPLITE_CTRL_NEW_ENUM_SOCK_DATA)
|
||||
sock_tag->fd = 0;
|
||||
else if (tag->type == IPLITE_CTRL_CONT_ENUM_SOCK_DATA)
|
||||
{
|
||||
if (sock_tag->fd < 0 || sock_tag->fd >= IPLITE_CONF_MAX_SOCKETS)
|
||||
return -IP_ERRNO_EINVAL;
|
||||
sock_tag->fd++;
|
||||
}
|
||||
else
|
||||
return -IP_ERRNO_EINVAL;
|
||||
|
||||
for (; sock_tag->fd < IPLITE_CONF_MAX_SOCKETS; sock_tag->fd++)
|
||||
{
|
||||
Iplite_socket *sock = iplite.sockets[sock_tag->fd];
|
||||
if (sock != IP_NULL)
|
||||
{
|
||||
sock_tag->domain = sock->ipcom.domain;
|
||||
sock_tag->type = sock->ipcom.type;
|
||||
sock_tag->protocol = sock->proto;
|
||||
#ifdef IPCOM_USE_TCP
|
||||
if (sock->proto == IP_IPPROTO_TCP)
|
||||
sock_tag->tcp_state = iplite_tcp_get_state(sock);
|
||||
#endif
|
||||
sock_tag->saddr.in_addr.sin_port = ip_htons(sock->sport);
|
||||
sock_tag->daddr.in_addr.sin_port = ip_htons(sock->dport);
|
||||
sock_tag->saddr.in_addr.sin_family = (Ip_u8) sock->ipcom.domain;
|
||||
sock_tag->daddr.in_addr.sin_family = (Ip_u8) sock->ipcom.domain;
|
||||
#ifdef IPCOM_USE_INET
|
||||
if (sock->ipcom.domain == IP_AF_INET)
|
||||
{
|
||||
sock_tag->saddr.in_addr.sin_len = sizeof(sock_tag->saddr.in_addr);
|
||||
sock_tag->saddr.in_addr.sin_addr.s_addr = sock->d->ip4.saddr_n;
|
||||
sock_tag->daddr.in_addr.sin_len = sizeof(sock_tag->daddr.in_addr);
|
||||
sock_tag->daddr.in_addr.sin_addr.s_addr = sock->d->ip4.daddr_n;
|
||||
}
|
||||
#endif /* IPCOM_USE_INET */
|
||||
#ifdef IPCOM_USE_INET6
|
||||
if (sock->ipcom.domain == IP_AF_INET6)
|
||||
{
|
||||
sock_tag->saddr.in6_addr.sin6_len = sizeof(sock_tag->saddr.in6_addr);
|
||||
sock_tag->saddr.in6_addr.sin6_addr = sock->d->ip6.saddr;
|
||||
sock_tag->daddr.in6_addr.sin6_len = sizeof(sock_tag->daddr.in6_addr);
|
||||
sock_tag->daddr.in6_addr.sin6_addr = sock->d->ip6.daddr;
|
||||
}
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
return IPLITE_CTRL_SUCCESS;
|
||||
}
|
||||
}
|
||||
return IPLITE_CTRL_ENUM_DONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ctrl_ip6_nc
|
||||
*===========================================================================
|
||||
* Description: Sets and gets IPv6 neighbor cache entries.
|
||||
* Parameters: tag - Contains the information to set/add/delete.
|
||||
* Returns: 0 = success, <0 = error.
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET6
|
||||
IP_STATIC int
|
||||
iplite_ctrl_ip6_nc(struct Iplite_tag *tag)
|
||||
{
|
||||
struct Iplite_tag_nc_entry *nc_tag = (struct Iplite_tag_nc_entry*) tag;
|
||||
Iplite_ip6_nc_entry *nc;
|
||||
Iplite_netif *netif;
|
||||
/*Ip_bool prev_entry;*/
|
||||
|
||||
if (tag->size < sizeof(*nc_tag))
|
||||
{
|
||||
tag->size = sizeof(*nc_tag);
|
||||
return -IP_ERRNO_ENOSPC;
|
||||
}
|
||||
|
||||
switch (tag->type)
|
||||
{
|
||||
case IPLITE_CTRL_NEW_ENUM_NC_ENTRY :
|
||||
/*prev_entry = IP_FALSE;*/
|
||||
/* Fall through */
|
||||
case IPLITE_CTRL_CONT_ENUM_NC_ENTRY :
|
||||
return IPLITE_CTRL_SUCCESS;
|
||||
|
||||
case IPLITE_CTRL_ADD_NC_ENTRY :
|
||||
case IPLITE_CTRL_DEL_NC_ENTRY :
|
||||
if (nc_tag->ifindex != 0)
|
||||
{
|
||||
netif = iplite_if_indextonetif(nc_tag->ifindex);
|
||||
if (netif == IP_NULL)
|
||||
/* The specified interface does not exist */
|
||||
return -IP_ERRNO_ENXIO;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use the interface specified by the route table */
|
||||
netif = IP_NULL;
|
||||
}
|
||||
nc = iplite_ip6_neighbor_cache_find(netif, &nc_tag->addr.sin6_addr);
|
||||
if (nc == IP_NULL)
|
||||
return -IP_ERRNO_ENOBUFS;
|
||||
|
||||
|
||||
if(tag->type == IPLITE_CTRL_ADD_NC_ENTRY)
|
||||
{
|
||||
iplite_ip6_neighbor_cache_update(nc, IPLITE_IP6_ND_REACHABLE,
|
||||
IP_SOCKADDR_DL_LLADDR(&nc_tag->link_addr));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Schedule for deletion */
|
||||
nc->status = IPLITE_IP6_ND_STALE;
|
||||
nc->next_timeout = 0;
|
||||
}
|
||||
|
||||
return IPLITE_CTRL_SUCCESS;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ctrl_islocked
|
||||
*===========================================================================
|
||||
* Description: SNMP helper function to access ndp tables
|
||||
* Code semaphore must be locked.
|
||||
* Parameters: tag - The data to set or get.
|
||||
* Returns: 0 = succcess, -1 = error
|
||||
* (get error code from ipcom_errno)
|
||||
*
|
||||
*/
|
||||
#if defined(IPCOM_USE_MIB2) && defined(IPCOM_USE_INET6)
|
||||
IP_GLOBAL int
|
||||
iplite_ctrl_islocked(struct Iplite_tag *tag)
|
||||
{
|
||||
int retval = -IP_ERRNO_EINVAL;
|
||||
ip_assert(tag != IP_NULL);
|
||||
|
||||
if (IP_BIT_ISSET(tag->type, IPLITE_CTRL_NC_ENTRY_BASE))
|
||||
retval = iplite_ctrl_ip6_nc(tag);
|
||||
|
||||
if (retval < 0)
|
||||
goto errout;
|
||||
return retval;
|
||||
|
||||
errout:
|
||||
return ipcom_errno_set(-retval);
|
||||
}
|
||||
#endif /* defined(IPCOM_USE_MIB2) && defined(IPCOM_USE_INET6) */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ctrl
|
||||
*===========================================================================
|
||||
* Description: Sets/gets runtime configuration for IPLITE.
|
||||
* Parameters: tag - The data to set or get.
|
||||
* Returns: 0 = succcess, -1 = error
|
||||
* (get error code from ipcom_errno)
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
iplite_ctrl(struct Iplite_tag *tag)
|
||||
{
|
||||
int retval;
|
||||
|
||||
ip_assert(tag != IP_NULL);
|
||||
|
||||
/* Block all ipcom_socket() calls until the stack is configured */
|
||||
while (IP_BIT_ISFALSE(iplite_flags, IPLITE_FLAG_CONFIGURED))
|
||||
ipcom_millisleep(100);
|
||||
|
||||
IPLITE_CODE_LOCK();
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
if (IP_BIT_ISSET(tag->type, IPLITE_CTRL_NC_ENTRY_BASE))
|
||||
retval = iplite_ctrl_ip6_nc(tag);
|
||||
else
|
||||
#endif
|
||||
if (IP_BIT_ISSET(tag->type, IPLITE_CTRL_SOCK_BASE))
|
||||
retval = iplite_ctrl_sock(tag);
|
||||
else
|
||||
retval = -IP_ERRNO_EINVAL;
|
||||
|
||||
IPLITE_CODE_UNLOCK();
|
||||
|
||||
if (retval < 0)
|
||||
return ipcom_errno_set(-retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_eth.h,v $ $Revision: 1.6.10.1 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_eth.h,v $
|
||||
* $Author: svc-cmnet $ $Date: 2013-03-13 07:45:29 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Lennart Bang <lob@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPLITE_ETH_H
|
||||
#define IPLITE_ETH_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_config.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_netif.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Frame Values
|
||||
*===========================================================================
|
||||
* Note: Also used for 3:rd argument to when creating packet sockets.
|
||||
*/
|
||||
#define IPLITE_ETH_P_ALL 0
|
||||
#define IPLITE_ETH_P_IP 0x0800
|
||||
#define IPLITE_ETH_P_ARP 0x0806
|
||||
#define IPLITE_ETH_P_IPV6 0x86DD
|
||||
#define IPLITE_ETH_P_PPPOE_DIS 0x8863
|
||||
#define IPLITE_ETH_P_PPPOE_SES 0x8864
|
||||
|
||||
#ifndef IPNET_ETH_P_IP
|
||||
#define IPNET_ETH_P_IP IPLITE_ETH_P_IP
|
||||
#endif
|
||||
#ifndef IPNET_ETH_P_ARP
|
||||
#define IPNET_ETH_P_ARP IPLITE_ETH_P_ARP
|
||||
#endif
|
||||
#ifndef IPNET_ETH_P_IPV6
|
||||
#define IPNET_ETH_P_IPV6 IPLITE_ETH_P_IPV6
|
||||
#endif
|
||||
#ifndef IPNET_ETH_P_PPPOE_DIS
|
||||
#define IPNET_ETH_P_PPPOE_DIS IPLITE_ETH_P_PPPOE_DIS
|
||||
#endif
|
||||
#ifndef IPNET_ETH_P_PPPOE_SES
|
||||
#define IPNET_ETH_P_PPPOE_SES IPLITE_ETH_P_PPPOE_SES
|
||||
#endif
|
||||
|
||||
|
||||
/* Ethernet MTU/MRU. */
|
||||
#define IPLITE_ETH_MTU 1500
|
||||
|
||||
/* Size of Ethernet address */
|
||||
#define IPLITE_ETH_ADDR_SIZE 6
|
||||
#ifndef IPNET_ETH_ADDR_SIZE
|
||||
#define IPNET_ETH_ADDR_SIZE IPLITE_ETH_ADDR_SIZE
|
||||
#endif
|
||||
|
||||
/* Size of Ethernet link header. */
|
||||
#define IPLITE_ETH_HDR_SIZE 14
|
||||
|
||||
/* Size of Ethernet link trailer (not used by IP layers) */
|
||||
#define IPLITE_ETH_TRL_SIZE 6
|
||||
|
||||
/* Number of bits in the host part (EUI-64) when using the
|
||||
ethernet MAC to create a IPv6 address (RFC 2464) */
|
||||
#define IPLITE_ETH_IP6_ID_BITS 64
|
||||
|
||||
|
||||
#ifdef IPCOM_32ON16_OK
|
||||
#define IPLITE_SET_ETH_ADDR(eth1,eth2) do { *(Ip_u32 *)eth1 = *(Ip_u32 *)eth2; \
|
||||
((Ip_u16*)eth1)[2] = ((Ip_u16*)eth2)[2]; } while(0)
|
||||
#else
|
||||
#define IPLITE_SET_ETH_ADDR(eth1,eth2) do { ((Ip_u16*)eth1)[0] = ((Ip_u16*)eth2)[0]; \
|
||||
((Ip_u16*)eth1)[1] = ((Ip_u16*)eth2)[1]; \
|
||||
((Ip_u16*)eth1)[2] = ((Ip_u16*)eth2)[2]; } while(0)
|
||||
#endif
|
||||
|
||||
#ifdef IPCOM_32ON16_OK
|
||||
#define IPLITE_CMP_ETH_ADDR(eth1,eth2) (*(Ip_u32 *)eth1 == *(Ip_u32 *)eth2 && \
|
||||
((Ip_u16*)eth1)[2] == ((Ip_u16*)eth2)[2])
|
||||
#else
|
||||
#define IPLITE_CMP_ETH_ADDR(eth1,eth2) (((Ip_u16*)eth1)[0] == ((Ip_u16*)eth2)[0] && \
|
||||
((Ip_u16*)eth1)[1] == ((Ip_u16*)eth2)[1] && \
|
||||
((Ip_u16*)eth1)[2] == ((Ip_u16*)eth2)[2])
|
||||
#endif
|
||||
|
||||
#define IPLITE_ARE_ETHADDR_EQUAL(addr1, addr2) (ipcom_memcmp(addr1, addr2, IPLITE_ETH_ADDR_SIZE) == 0)
|
||||
|
||||
/* Per packet information */
|
||||
#define IPLITE_ETH_PKT_MAGIC 0xD5A7
|
||||
|
||||
#define IPLITE_ETH_PKT_SET_VLAN_TAG(pkt, tag) \
|
||||
(pkt)->link_cookie = IPLITE_ETH_PKT_MAGIC + ((tag) << 16)
|
||||
|
||||
#define IPLITE_ETH_PKT_GET_VLAN_TAG(pkt) \
|
||||
(Ip_u16) (((pkt)->link_cookie & 0xffff) != IPLITE_ETH_PKT_MAGIC ? 0 : ((pkt)->link_cookie >> 16))
|
||||
|
||||
|
||||
#define IPNET_ETH_PKT_SET_VLAN_TAG IPLITE_ETH_PKT_SET_VLAN_TAG
|
||||
#define IPNET_ETH_PKT_GET_VLAN_TAG IPLITE_ETH_PKT_GET_VLAN_TAG
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_arp_entry
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef IP_PACKED struct Iplite_arp_entry_struct
|
||||
{
|
||||
Ip_u32 ipaddr_n;
|
||||
|
||||
union Iplite_arp_entry_union
|
||||
{
|
||||
struct Iplite_arp_pending_struct
|
||||
{
|
||||
Ipcom_pkt *pkt;
|
||||
struct Iplite_arp_entry_struct *next;
|
||||
Ip_s16 retries;
|
||||
Ip_u16 invalid; /* 1 = invalid IP addr, 0 = ARP requesting. */
|
||||
Iplite_netif *netif;
|
||||
} pending;
|
||||
|
||||
struct Iplite_arp_valid_struct
|
||||
{
|
||||
Ip_u16 ethaddr[3];
|
||||
Ip_u16 pad;
|
||||
Ip_u32 enddate;
|
||||
} valid;
|
||||
} state;
|
||||
}
|
||||
Iplite_arp_entry;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_netif_eth
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
/* maximum size of ARP cache. */
|
||||
#define IPLITE_ARP_MAX_CACHE 16
|
||||
|
||||
#define IPLITE_ARP_TIMEOUT_PERMANENT ((Ip_u16) -1)
|
||||
|
||||
typedef struct Iplite_netif_eth_struct
|
||||
{
|
||||
int ethflags;
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
int arp_slot;
|
||||
Iplite_arp_entry *arp_cache[IPLITE_ARP_MAX_CACHE];
|
||||
Iplite_arp_entry *arp_pending;
|
||||
#endif
|
||||
|
||||
#ifdef IPPPP_USE_PPPOE
|
||||
int pppoe_num_sessions; /* Used by ethX */
|
||||
void *pppoe_tmo_handle; /* Used by ethX (tmo_handle or pppif) */
|
||||
Ip_u32 pppoe_ppp_ifindex; /* Interface index. */
|
||||
#endif
|
||||
}
|
||||
Iplite_netif_eth;
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC int iplite_eth_if_init(Iplite_netif *netif);
|
||||
|
||||
#if defined(IPCOM_USE_ETHERNET) && defined(IPCOM_USE_INET)
|
||||
IP_GLOBAL void iplite_arp_request(Iplite_netif *netif, Ip_u32 dstaddr_n, int gratuitous);
|
||||
#ifdef IPLITE_USE_IOCTL_ARP
|
||||
IP_GLOBAL int iplite_arp_ioctl(unsigned long reqest, struct Ip_arpreq *req);
|
||||
#endif /* IPLITE_USE_IOCTL_ARP */
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,428 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_frag.c,v $ $Revision: 1.26 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_frag.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* Fragmentation and reassembly functions.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#if !defined(IPLITE_ONE_FILE) || defined(IPLITE_C)
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_os.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_fragment_packet
|
||||
*===========================================================================
|
||||
* Description: Splits a packet that is to big to fit into the MTU of the
|
||||
* network interface.
|
||||
* Parameters: pkt - The packet to split. pkt->start is the offset to the
|
||||
* extension header (or transport layer protocol) with the
|
||||
* id of 'next_hdr'. This packet is released by this function.
|
||||
* ip_hdr_size - The size of the IP header.
|
||||
* other_hdr_size - The size of other headers that will be
|
||||
* added due to fragmentation.
|
||||
* mtu - The MTU of the network interface.
|
||||
* Returns: A list of fragments or IP_NULL if not enough memory could
|
||||
* be allocated to create all fragments.
|
||||
*/
|
||||
IP_GLOBAL Ipcom_pkt *
|
||||
iplite_fragment_packet(Ipcom_pkt *pkt, int ip_hdr_size, int other_hdr_size, int mtu)
|
||||
{
|
||||
Ipcom_pkt *frag_pkt_head;
|
||||
Ipcom_pkt *frag_pkt_tail;
|
||||
Ipcom_pkt *frag_pkt;
|
||||
int frag_size;
|
||||
int total_size;
|
||||
int size_of_this_fragment;
|
||||
int frag_offset;
|
||||
|
||||
total_size = pkt->end - pkt->start;
|
||||
frag_size = (mtu - ip_hdr_size - other_hdr_size) & 0xfff8;
|
||||
frag_pkt_head = IP_NULL;
|
||||
frag_pkt_tail = IP_NULL;
|
||||
frag_offset = 0;
|
||||
|
||||
while (frag_offset < total_size)
|
||||
{
|
||||
if (total_size - frag_offset > frag_size)
|
||||
size_of_this_fragment = frag_size;
|
||||
else
|
||||
size_of_this_fragment = total_size - frag_offset;
|
||||
|
||||
frag_pkt = ipcom_pkt_malloc(mtu,
|
||||
IP_FLAG_FC_STACKCONTEXT
|
||||
| (IP_BIT_ISSET(pkt->flags, IPCOM_PKT_FLAG_NONBLOCKING) ? 0 : IP_FLAG_FC_BLOCKOK));
|
||||
if (frag_pkt == IP_NULL)
|
||||
{
|
||||
IPLITE_STATS(pkt_frag_nomem++);
|
||||
ipcom_pkt_free(pkt);
|
||||
if (frag_pkt_head != IP_NULL)
|
||||
ipcom_pkt_free(frag_pkt_head);
|
||||
return IP_NULL;
|
||||
}
|
||||
|
||||
#ifdef IPCOM_USE_MIB2
|
||||
if(other_hdr_size == 0)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
IPCOM_MIB2(ipFragCreates++);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef IPCOM_USE_INET6
|
||||
Iplite_netif *netif = iplite_if_indextonetif(pkt->ifindex);
|
||||
|
||||
IPCOM_MIB2_NETIF(ipv6IfStatsOutFragCreates++);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (frag_pkt_head == IP_NULL)
|
||||
frag_pkt_head = frag_pkt;
|
||||
else
|
||||
frag_pkt_tail->next_fragment = frag_pkt;
|
||||
frag_pkt_tail = frag_pkt;
|
||||
|
||||
IPCOM_PKT_TRACE(frag_pkt, IPCOM_GET_PKT_ID(pkt));
|
||||
frag_pkt->fd = pkt->fd;
|
||||
frag_pkt->ifindex = pkt->ifindex;
|
||||
frag_pkt->flags = pkt->flags;
|
||||
/* Copy IP packet payload */
|
||||
frag_pkt->start = pkt->start + other_hdr_size;
|
||||
frag_pkt->end = frag_pkt->start + size_of_this_fragment;
|
||||
ip_assert(frag_pkt->start < frag_pkt->maxlen);
|
||||
ipcom_memcpy(&frag_pkt->data[frag_pkt->start],
|
||||
&pkt->data[pkt->start + frag_offset],
|
||||
(Ip_size_t)size_of_this_fragment);
|
||||
|
||||
frag_pkt->offset = (Ip_u16) (frag_offset + pkt->offset);
|
||||
frag_offset += size_of_this_fragment;
|
||||
IP_BIT_SET(frag_pkt->flags, IPCOM_PKT_FLAG_MORE_FRAG);
|
||||
}
|
||||
if (IP_BIT_ISSET(pkt->flags, IPCOM_PKT_FLAG_FRAGMENT) == IP_FALSE)
|
||||
IP_BIT_CLR(frag_pkt_tail->flags, IPCOM_PKT_FLAG_MORE_FRAG);
|
||||
ip_assert(pkt->start + frag_offset == pkt->end);
|
||||
ip_assert(frag_pkt_head != IP_NULL);
|
||||
ip_assert(frag_pkt_head->next_fragment != IP_NULL);
|
||||
ipcom_pkt_free(pkt);
|
||||
return frag_pkt_head;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_reassembly
|
||||
*===========================================================================
|
||||
* Description: Reassembles fragmented IP packets.
|
||||
*
|
||||
* ... ...
|
||||
* | |
|
||||
* pkt #A pkt #B
|
||||
* frag #b frag #y
|
||||
* ^ ^
|
||||
* | |
|
||||
* | |
|
||||
* next_fragment next_fragment
|
||||
* | |
|
||||
* | |
|
||||
* ---> pkt #A -- next --> pkt #B -- next --> ...
|
||||
* | frag #a frag #x
|
||||
* |
|
||||
* reassembly_list
|
||||
*
|
||||
* pkt #A chain will time out before pkt #B if not all fragments
|
||||
* are recieved.
|
||||
* frag #a and frag #x has lower offset than frag #b and frag #y.
|
||||
* Parameters: pkt - A newly received fragment.
|
||||
* Returns: Pointer to the reassembled packet or IP_NULL if more fragments
|
||||
* is needed.
|
||||
*/
|
||||
IP_GLOBAL Ipcom_pkt *
|
||||
iplite_reassembly(Ipcom_pkt **reassembly_list,
|
||||
Ipcom_pkt *pkt,
|
||||
Iplite_is_part_of_same_pkt_func is_part_of_same_pkt,
|
||||
Iplite_get_offset_func get_offset,
|
||||
Iplite_more_fragments_func more_fragments,
|
||||
Iplite_timeout_handler tmo_cb,
|
||||
int frag_hdr_len)
|
||||
{
|
||||
Ipcom_pkt **pkt_it; /* The packet this fragment belongs to */
|
||||
Ipcom_pkt **frag_it; /* The fragment within the selected packet this fragment
|
||||
should inserted in-font of */
|
||||
Ipcom_pkt *frag_head = IP_NULL;
|
||||
Ipcom_pkt *tmo_pkt;
|
||||
Ipcom_pkt *new_tmo_pkt;
|
||||
int offset;
|
||||
int previous_end;
|
||||
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
tmo_pkt = *reassembly_list;
|
||||
|
||||
IPLITE_PKT_SET_TMO(pkt, IP_NULL);
|
||||
offset = get_offset(pkt);
|
||||
for (pkt_it = reassembly_list; *pkt_it != IP_NULL; pkt_it = &(*pkt_it)->next)
|
||||
{
|
||||
if (is_part_of_same_pkt(pkt, *pkt_it))
|
||||
break;
|
||||
}
|
||||
|
||||
if (*pkt_it == IP_NULL)
|
||||
{
|
||||
/* First fragment received of this packet, add it last to the list */
|
||||
*pkt_it = pkt;
|
||||
pkt->next = IP_NULL;
|
||||
ip_assert(pkt->next_fragment == IP_NULL);
|
||||
IPLITE_PKT_SET_TIMEOUT_ABS(pkt, iplite.seconds + IPLITE_CONF_REASSEMBLY_TIMEOUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
previous_end = 0;
|
||||
for (frag_it = pkt_it; (*frag_it) != IP_NULL; frag_it = &(*frag_it)->next_fragment)
|
||||
{
|
||||
if (offset <= get_offset(*frag_it))
|
||||
{
|
||||
/* The new fragment should be in front of this fragment */
|
||||
break;
|
||||
}
|
||||
previous_end = (*frag_it)->end - (*frag_it)->start
|
||||
+ get_offset(*frag_it) - frag_hdr_len;
|
||||
}
|
||||
|
||||
if (previous_end > offset
|
||||
|| (*frag_it
|
||||
&& (offset == get_offset(*frag_it)
|
||||
|| offset + pkt->end - pkt->start - frag_hdr_len > get_offset(*frag_it))))
|
||||
{
|
||||
/* Overlapping segment or this fragment has already been received */
|
||||
ipcom_pkt_free(pkt);
|
||||
return IP_NULL;
|
||||
}
|
||||
|
||||
/* The timeout is calculated from the point when the first fragment
|
||||
in this packet was received */
|
||||
IPLITE_PKT_SET_TIMEOUT_ABS(pkt, IPLITE_PKT_GET_TIMEOUT_ABS(*pkt_it));
|
||||
|
||||
/* Insert the fragment into the fragment list */
|
||||
pkt->next_fragment = *frag_it;
|
||||
*frag_it = pkt;
|
||||
|
||||
if (pkt->next_fragment && pkt->next_fragment->next)
|
||||
{
|
||||
/* New head in this list, move the 'next' pointer to the new head */
|
||||
pkt->next = pkt->next_fragment->next;
|
||||
pkt->next_fragment->next = IP_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if all fragments has been received */
|
||||
for (frag_it = pkt_it, offset = 0; (*frag_it) != IP_NULL; frag_it = &(*frag_it)->next_fragment)
|
||||
{
|
||||
ip_assert((offset & 0x7) == 0);
|
||||
if (offset != get_offset(*frag_it))
|
||||
break;
|
||||
|
||||
if (!more_fragments(*frag_it))
|
||||
{
|
||||
/* All fragments was received */
|
||||
frag_head = *pkt_it;
|
||||
|
||||
/* Remove the fragment list from reassembly list */
|
||||
*pkt_it = frag_head->next;
|
||||
frag_head->next = IP_NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
offset += (*frag_it)->end - (*frag_it)->start - frag_hdr_len;
|
||||
}
|
||||
|
||||
/* The TMO packet will change if
|
||||
* - the oldest fragment list is returned
|
||||
* - if the new fragment is a new head in the oldest fragment list
|
||||
*/
|
||||
new_tmo_pkt = *reassembly_list;
|
||||
if (new_tmo_pkt != tmo_pkt)
|
||||
{
|
||||
if (tmo_pkt)
|
||||
iplite_timeout_cancel(IPLITE_PKT_GET_TMO(tmo_pkt));
|
||||
if (new_tmo_pkt)
|
||||
(void)iplite_timeout_schedule(IPLITE_PKT_GET_TIMEOUT(new_tmo_pkt) * 1000,
|
||||
tmo_cb,
|
||||
new_tmo_pkt,
|
||||
IPLITE_PKT_GET_TMO_PTR(new_tmo_pkt));
|
||||
|
||||
}
|
||||
/* All fragments has not been received if frag_head == IP_NULL */
|
||||
return frag_head;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_create_reassembled_packet
|
||||
*===========================================================================
|
||||
* Description: Reassembles a list of fragments to the orginal packet and
|
||||
* creates a new packet of it.
|
||||
* Parameters: fragment_list - The first fragment in the list.
|
||||
* ip_hdr_size - The size of the IP header.
|
||||
* frag_hdr_size - The size of the header containing the fragmentation id.
|
||||
* update_ip_header - A function that can finish the IP header
|
||||
* of the reassembled packet.
|
||||
* Returns: The reassembled packet or IP_NULL if a packet big enough
|
||||
* to hold the whole packet.
|
||||
*/
|
||||
IP_GLOBAL Ipcom_pkt *
|
||||
iplite_create_reassembled_packet(Ipcom_pkt *fragment_list,
|
||||
int ip_hdr_size,
|
||||
int frag_hdr_size,
|
||||
Iplite_update_ip_header_func update_ip_header,
|
||||
Iplite_reassemble_err_hnd reassemble_err_hnd)
|
||||
{
|
||||
Ipcom_pkt *pkt = IP_NULL;
|
||||
Ipcom_pkt *pkt_it;
|
||||
int total_size = 0;
|
||||
|
||||
for (pkt_it = fragment_list; pkt_it != IP_NULL; pkt_it = pkt_it->next_fragment)
|
||||
{
|
||||
pkt_it->start += frag_hdr_size;
|
||||
total_size += pkt_it->end - pkt_it->start;
|
||||
ip_assert(pkt_it->ipstart < pkt_it->start);
|
||||
ip_assert(pkt_it->start < pkt_it->end);
|
||||
}
|
||||
|
||||
if (total_size > 65535)
|
||||
{
|
||||
if (reassemble_err_hnd)
|
||||
reassemble_err_hnd(fragment_list);
|
||||
goto done;
|
||||
}
|
||||
|
||||
total_size += ip_hdr_size;
|
||||
|
||||
pkt = ipcom_pkt_malloc(IP_MIN(total_size, iplite.pkt_pool_max_mtu),
|
||||
IP_FLAG_FC_STACKCONTEXT);
|
||||
if (pkt == IP_NULL || pkt->maxlen < total_size)
|
||||
{
|
||||
IPLITE_STATS(pkt_reasm_nomem++);
|
||||
goto done;
|
||||
}
|
||||
|
||||
pkt->start = fragment_list->ipstart;
|
||||
if (pkt->start + total_size > pkt->maxlen)
|
||||
pkt->start = (pkt->maxlen - total_size) & ~0x3;
|
||||
pkt->ipstart = pkt->start;
|
||||
pkt->end = pkt->start + ip_hdr_size;
|
||||
pkt->ifindex = fragment_list->ifindex;
|
||||
|
||||
/* Copy the IP header */
|
||||
ipcom_memcpy(&pkt->data[pkt->start],
|
||||
&fragment_list->data[fragment_list->ipstart],
|
||||
(Ip_size_t)ip_hdr_size);
|
||||
|
||||
/* Copy the rest of the packet */
|
||||
for (pkt_it = fragment_list; pkt_it != IP_NULL; pkt_it = pkt_it->next_fragment)
|
||||
{
|
||||
ipcom_memcpy(&pkt->data[pkt->end],
|
||||
&pkt_it->data[pkt_it->start],
|
||||
(Ip_size_t)(pkt_it->end - pkt_it->start));
|
||||
pkt->end += pkt_it->end - pkt_it->start;
|
||||
ip_assert(pkt->end <= pkt->maxlen);
|
||||
}
|
||||
|
||||
update_ip_header(pkt, fragment_list);
|
||||
|
||||
done:
|
||||
ipcom_pkt_free(fragment_list);
|
||||
return pkt;
|
||||
}
|
||||
|
||||
|
||||
#endif /* !defined(IPLITE_ONE_FILE) || defined(IPLITE_C) */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,788 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_h.h,v $ $Revision: 1.61 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_h.h,v $
|
||||
* $Author: hxie $ $Date: 2010-11-19 00:43:36 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPLITE_H_H
|
||||
#define IPLITE_H_H
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_config.h"
|
||||
|
||||
#define IPLITE_MAX_IF_EVENTCB 8
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_netif.h"
|
||||
#include "iplite_timeout.h"
|
||||
#ifdef IPCOM_USE_INET
|
||||
#include "iplite_ip4.h"
|
||||
#endif
|
||||
#ifdef IPCOM_USE_INET6
|
||||
#include "iplite_ip6.h"
|
||||
#endif
|
||||
#ifdef IPIPSEC2
|
||||
#include <ipipsec.h>
|
||||
#endif
|
||||
#ifdef IPPPP
|
||||
#include <ipppp_ipstack.h>
|
||||
#endif
|
||||
|
||||
#include <ipcom_mib2.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_pkt.h>
|
||||
#include <ipcom_pqueue.h>
|
||||
#include <ipcom_route.h>
|
||||
#include <ipcom_slab.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_time.h>
|
||||
/* #include <ipcom_wait_queue.h> */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPLITE event semaphore
|
||||
*===========================================================================
|
||||
*/
|
||||
/* Select stack daemon configuration */
|
||||
#ifdef IPCOM_STACKD_POST_IMPL
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPCOM_STACKD_POST_IMPL
|
||||
*===========================================================================
|
||||
* Description: Notifies the external stack daemon that a stack event has occured.
|
||||
* Parameters: new_timeout - IP_TRUE if called because a new timeout has occured.
|
||||
* is_posted - IP_TRUE if this function returned IP_TRUE the
|
||||
* last call and ipcom_stackd_event() has not
|
||||
* since the last call.
|
||||
* Returns: IP_TRUE if 'is_posted' should be IP_TRUE in the next call
|
||||
* if this function is called more times from the same
|
||||
* ipcom_stackd_event() run.
|
||||
*
|
||||
*/
|
||||
IP_EXTERN Ip_bool IPCOM_STACKD_POST_IMPL(Ip_bool new_timeout, Ip_bool is_posted);
|
||||
#define IPCOM_STACKD_POST(new_timeout) \
|
||||
iplite.daemon_posted = IPCOM_STACKD_POST_IMPL(new_timeout, iplite.daemon_posted)
|
||||
|
||||
#else /* !IPCOM_STACKD_POST_IMPL */
|
||||
|
||||
/* The built-in daemon process is used */
|
||||
#define IPLITE_STACKD_INTERNAL
|
||||
#define IPCOM_STACKD_POST(new_timeout) \
|
||||
if (!iplite.daemon_posted) \
|
||||
{ \
|
||||
iplite.daemon_posted = IP_TRUE; \
|
||||
(void)ipcom_block_post(iplite.daemon_block); \
|
||||
}
|
||||
|
||||
#endif /* IPCOM_STACKD_POST_IMPL */
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Misc
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define IPLITE_DATA_SETU16(pkt,off,val16) *(Ip_u16 *)(&(pkt)->data[off]) = (Ip_u16)(val16)
|
||||
|
||||
/* iplite lifetime macro, also see ipcom_sock6.h IPCOM_ADDR_INFINITE. */
|
||||
#define IPLITE_EXPIRED 0 /* Lifetime has expired */
|
||||
|
||||
#define IPLITE_IS_GT(s1, s2) ((Ip_s32) ((s1) - (s2)) > 0)
|
||||
#define IPLITE_IS_GEQ(s1, s2) ((Ip_s32) ((s1) - (s2)) >= 0)
|
||||
#define IPLITE_IS_LT(s1, s2) ((Ip_s32) ((s1) - (s2)) < 0)
|
||||
#define IPLITE_IS_LEQ(s1, s2) ((Ip_s32) ((s1) - (s2)) <= 0)
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* DEBUG/ASSERT
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#ifdef IPLITE_DEBUG
|
||||
/* #define IPLITE_DEBUG_PRINTF -- Now handled per-file */
|
||||
#define IPLITE_DEBUG_LINE(x) x
|
||||
#else
|
||||
#define IPLITE_DEBUG_LINE(x) IP_NOOP
|
||||
#endif /* IPLITE_DEBUG */
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* syslog
|
||||
*===========================================================================
|
||||
*/
|
||||
#define IPCOM_SYSLOG_PRIORITY IPLITE_SYSLOG_PRIORITY
|
||||
#define IPCOM_SYSLOG_FACILITY IPCOM_LOG_IPLITE
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* address types
|
||||
*===========================================================================
|
||||
*/
|
||||
#define IPLITE_ADDR_TYPE_NOT_LOCAL -1 /* Not any of the host local addresses */
|
||||
#define IPLITE_ADDR_TYPE_ANY 0 /* The ANY address */
|
||||
#define IPLITE_ADDR_TYPE_BROADCAST 1 /* Broadcast address */
|
||||
#define IPLITE_ADDR_TYPE_UNICAST 2 /* One of the localhost unicast addresses */
|
||||
#define IPLITE_ADDR_TYPE_MULTICAST 3 /* One of the localhost multicast addresses */
|
||||
#define IPLITE_ADDR_TYPE_SUBNETBROADCAST 11 /* IPv4 only, subnetwork broadcast */
|
||||
#define IPLITE_ADDR_TYPE_SOLICITED 20 /* IPv6 only, solicited multicast address of
|
||||
one of the unicast addresses */
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPLITE code lock
|
||||
*===========================================================================
|
||||
*/
|
||||
#if defined(IP_ASSERT) && !defined(IP_PORT_VXWORKS)
|
||||
#define IPLITE_CODE_ISLOCKED_ASSERT() ip_assert(iplite.code_mutex_count == 1)
|
||||
#define IPLITE_CODE_LOCK() do { ip_assert(iplite.code_lock_owner != ipcom_getpid()); \
|
||||
ipcom_mutex_lock(iplite.code_mutex); \
|
||||
iplite.code_lock_owner = ipcom_getpid(); \
|
||||
ip_assert(iplite.code_mutex_count == 0); \
|
||||
iplite.code_mutex_count++; \
|
||||
} while(0)
|
||||
#define IPLITE_CODE_UNLOCK() do { ip_assert(iplite.code_mutex_count == 1); \
|
||||
iplite.code_mutex_count--; \
|
||||
iplite.code_lock_owner = 0; \
|
||||
ipcom_mutex_unlock(iplite.code_mutex); \
|
||||
} while(0)
|
||||
#else
|
||||
#define IPLITE_CODE_ISLOCKED_ASSERT() IP_NOOP
|
||||
#define IPLITE_CODE_LOCK() ipcom_mutex_lock(iplite.code_mutex)
|
||||
#define IPLITE_CODE_UNLOCK() ipcom_mutex_unlock(iplite.code_mutex)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* WindView
|
||||
*===========================================================================
|
||||
* These are required for non-VxWorks ports or if WindView instrumentation
|
||||
* is disabled.
|
||||
*/
|
||||
#ifdef IPCOM_WV_INSTRUMENTATION
|
||||
#define IPCOM_WV_MARKER_1(classId, eventLevel, eventOffset, eventTag, eventId, arg1, module, entity) \
|
||||
ipcom_wv_marker_1(classId, eventLevel, eventOffset, eventTag, eventId, arg1, module, entity)
|
||||
|
||||
#define IPCOM_WV_MARKER_2(classId, eventLevel, eventOffset, eventTag, eventId, arg1, arg2, module, entity) \
|
||||
ipcom_wv_marker_2(classId, eventLevel, eventOffset, eventTag, eventId, arg1, arg2, module, entity)
|
||||
|
||||
#define IPCOM_WV_EVENT_2(classId, eventLevel, eventOffset, eventTag, eventId, status, arg1, arg2, module, entity) \
|
||||
ipcom_wv_event_2(classId, eventLevel, eventOffset, eventTag, eventId, status, arg1, arg2, module, entity)
|
||||
#else
|
||||
#define IPCOM_WV_MARKER_1(classId, eventLevel, eventOffset, eventTag, eventId, arg1, module, entity) \
|
||||
do {} while (0)
|
||||
|
||||
#define IPCOM_WV_MARKER_2(classId, eventLevel, eventOffset, eventTag, eventId, arg1, arg2, module, entity) \
|
||||
do {} while (0)
|
||||
|
||||
#define IPCOM_WV_EVENT_2(classId, eventLevel, eventOffset, eventTag, eventId, status, arg1, arg2, module, entity) \
|
||||
do {} while (0)
|
||||
#endif /* #ifdef IPCOM_WV_INSTRUMENTATION */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* Forward declaration */
|
||||
struct Iplite_netif_struct;
|
||||
|
||||
/* Socket lookup handler, must be declared here since this file
|
||||
cannot include iplite_sock.h to avoid cyclic includes */
|
||||
typedef struct Iplite_socket_struct * (*Iplite_socklookup)
|
||||
(int proto,
|
||||
IP_CONST void *local_addr,
|
||||
Ip_u16 local_port,
|
||||
IP_CONST void *peer_addr,
|
||||
Ip_u16 peer_port,
|
||||
int* last);
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_pkt_udp
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef IP_PACKED struct Iplite_pkt_udp_struct
|
||||
{
|
||||
Ip_u16 sport; /* Source port. */
|
||||
Ip_u16 dport; /* Destination port. */
|
||||
Ip_u16 ulen; /* UDP length. */
|
||||
Ip_u16 sum; /* UDP checksum. */
|
||||
}
|
||||
Iplite_pkt_udp;
|
||||
|
||||
#define IPLITE_UDP_HDR_SIZE 8 /* UDP header is 8 octest long */
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_frame
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef IP_PACKED union Iplite_frame_union
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
IP_PACKED struct Iplite_frame_ip_struct
|
||||
{
|
||||
Iplite_pkt_ip ip;
|
||||
Iplite_pkt_udp udp;
|
||||
Ip_u8 data[1];
|
||||
} ip4;
|
||||
|
||||
IP_PACKED struct Iplite_frame_icmp_struct
|
||||
{
|
||||
Iplite_pkt_ip ip;
|
||||
Iplite_pkt_icmp icmp;
|
||||
} icmp4;
|
||||
#endif /* IPCOM_USE_INET */
|
||||
#ifdef IPCOM_USE_INET6
|
||||
IP_PACKED struct Iplite_frame_ip6_struct
|
||||
{
|
||||
Iplite_pkt_ip6 ip6;
|
||||
Iplite_pkt_udp udp;
|
||||
Ip_u8 data[1];
|
||||
} ip6;
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
}
|
||||
Iplite_frame;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_transport_output
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef int (*Iplite_transport_output)(struct Iplite_socket_struct *sock,
|
||||
IP_CONST struct Ip_sockaddr *to,
|
||||
Ipcom_pkt *pkt);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_pkt_pool
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
typedef struct Iplite_pkt_pool_struct
|
||||
{
|
||||
Ip_u16 len; /* The length of the buffers in this pool */
|
||||
Ip_u16 mtu; /* The largets MTU supported by this buffer */
|
||||
Ipcom_pkt *free_list; /* The free packet list (NOTE: pkt + data) */
|
||||
int total; /* The total number of buffers of this length (free + allocated) */
|
||||
int used; /* Number of buffers allocated of this size. */
|
||||
}
|
||||
Iplite_pkt_pool;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_stats
|
||||
*===========================================================================
|
||||
* IPLITE debug statistics useful for debugging the stack if things go wrong.
|
||||
*/
|
||||
#if defined(IPLITE_DEBUG) || defined(IPLITE_STATISTICS)
|
||||
#ifndef IPLITE_STATISTICS
|
||||
#define IPLITE_STATISTICS
|
||||
#endif
|
||||
typedef struct Iplite_stats_struct
|
||||
{
|
||||
int pkt_input;
|
||||
int pkt_input_err;
|
||||
int pkt_input_opened_err;
|
||||
int pkt_input_queue_full;
|
||||
int pkt_drain_ip4_reasm;
|
||||
int pkt_drain_ip6_reasm;
|
||||
int pkt_clone_nomem;
|
||||
int pkt_frag_nomem;
|
||||
int pkt_reasm_nomem;
|
||||
int pkt_queue_enobufs;
|
||||
int pkt_queue_emsgsize;
|
||||
|
||||
int pkt_output;
|
||||
int pkt_output_drv;
|
||||
int pkt_output_ewouldblock; /* errors other than non-blocking. */
|
||||
int pkt_output_err; /* errors other than non-blocking. */
|
||||
int pkt_output_queue;
|
||||
int pkt_output_discard;
|
||||
int pkt_output_delayed;
|
||||
int pkt_output_sleep;
|
||||
int pkt_output_requeue;
|
||||
int pkt_output_fast_drv_ready;
|
||||
|
||||
int pkt_netif_output_done;
|
||||
int pkt_netif_output_done_pkt;
|
||||
int pkt_netif_output_user_wake;
|
||||
int pkt_inputd_output;
|
||||
int pkt_inputd_output_err;
|
||||
int pkt_inputd_output_ewouldblock;
|
||||
int pkt_inputd_output_err_nonetif;
|
||||
|
||||
int eth_input;
|
||||
int eth_input_down;
|
||||
int eth_input_arp;
|
||||
int eth_input_arp_unknown;
|
||||
int eth_input_arp_bad;
|
||||
int eth_input_arp_reperr;
|
||||
int eth_input_arp_reqother;
|
||||
int eth_input_ip4;
|
||||
int eth_input_ip6;
|
||||
int eth_input_other;
|
||||
int eth_output_ip4;
|
||||
int eth_output_ip4_err;
|
||||
int eth_output_ip4_drverr;
|
||||
int eth_output_ip4_multierr;
|
||||
int eth_output_ip6;
|
||||
int eth_output_ip6_err;
|
||||
int eth_output_ip6_drverr;
|
||||
int eth_output_arp_req;
|
||||
int eth_output_arp_req_nomem;
|
||||
int eth_output_arp_rep;
|
||||
int eth_output_ip4_arppending;
|
||||
int eth_output_ip4_arpdrop;
|
||||
|
||||
int ip4_input;
|
||||
int ip4_input_err;
|
||||
int ip4_input_hdr_trunc;
|
||||
int ip4_input_hdr_toolong;
|
||||
int ip4_input_inval_len;
|
||||
int ip4_input_inval_version;
|
||||
int ip4_input_not_to_me;
|
||||
int ip4_input_iph_badchksum;
|
||||
int ip4_input_no_route_to_host;
|
||||
int ip4_input_reasm_enobufs;
|
||||
int ip4_input_time_exceeded;
|
||||
int ip4_input_need_frag;
|
||||
|
||||
int ip4_output;
|
||||
int ip4_output_blackhole;
|
||||
int ip4_output_hdr_space;
|
||||
int ip4_output_noroute;
|
||||
int ip4_output_enobufs;
|
||||
int ip4_output_link_err;
|
||||
|
||||
int icmp4_input;
|
||||
int icmp4_input_echo_request;
|
||||
int icmp4_input_dst_unreach;
|
||||
int icmp4_input_dst_unreach_match;
|
||||
int icmp4_input_dst_unreach_nomatch;
|
||||
int icmp4_input_dst_unreach_badcode;
|
||||
int icmp4_input_hdrsize;
|
||||
int icmp4_input_badchksum;
|
||||
int icmp4_input_hdrsize2;
|
||||
int icmp4_send;
|
||||
int icmp4_send_nomem;
|
||||
|
||||
int ip6_input;
|
||||
int ip6_input_err;
|
||||
int ip6_input_hdr_trunc;
|
||||
int ip6_input_inval_len;
|
||||
int ip6_input_inval_exthdr;
|
||||
int ip6_input_not_to_me;
|
||||
int ip6_input_no_route_to_host;
|
||||
int ip6_input_too_big;
|
||||
int ip6_input_time_exceeded;
|
||||
int ip6_input_too_short;
|
||||
int ip6_input_tcp_multicast;
|
||||
int ip6_input_prot_err;
|
||||
int ip6_input_hdr_no_next;
|
||||
int ip6_input_raw;
|
||||
|
||||
int ip6_output;
|
||||
int ip6_output_err;
|
||||
int ip6_output_blackhole;
|
||||
int ip6_output_hdr_space;
|
||||
int ip6_output_noroute;
|
||||
int ip6_output_nomem;
|
||||
int ip6_output_enobufs;
|
||||
int ip6_output_err_probe;
|
||||
int ip6_output_link_err;
|
||||
|
||||
int icmp6_input;
|
||||
int icmp6_input_err;
|
||||
int icmp6_input_badchksum;
|
||||
int icmp6_input_nomem;
|
||||
|
||||
int icmp6_send_nomem;
|
||||
|
||||
int udp4_input;
|
||||
int udp4_input_ok;
|
||||
int udp4_input_err;
|
||||
|
||||
int tcp4_input;
|
||||
int tcp4_input_ok;
|
||||
int tcp4_input_err;
|
||||
|
||||
int raw4_input;
|
||||
int raw6_input;
|
||||
int raw_input_badchksum;
|
||||
|
||||
int udp_input;
|
||||
int udp_input_hdr_trunc;
|
||||
int udp_input_badchksum;
|
||||
int udp_input_sock_multicast;
|
||||
int udp_input_sock_match;
|
||||
int udp_input_sock_nomatch;
|
||||
int udp_input_queue_pkt_ok;
|
||||
int udp_input_queue_pkt_err;
|
||||
int udp_input_multicast;
|
||||
int udp_input_econnrefused;
|
||||
int udp_output;
|
||||
int udp_output_hdr_trunc;
|
||||
int udp_output_eaddrinuse;
|
||||
int udp_output_eafnosupport;
|
||||
|
||||
int sock_sendto;
|
||||
int sock_sendto_nomem;
|
||||
int sock_sendto_ebadf;
|
||||
int sock_sendto_emsgsize;
|
||||
int sock_sendto_tcp_err;
|
||||
|
||||
int sock_recvfrom;
|
||||
int sock_recvfrom_ebadf;
|
||||
int sock_recvfrom_tcp_err;
|
||||
int sock_recvfrom_err;
|
||||
int sock_krecvfrom;
|
||||
int sock_krecvfrom_errno;
|
||||
int sock_krecvfrom_block_nomem;
|
||||
int sock_krecvfrom_sem_nomem;
|
||||
int sock_krecvfrom_ewouldblock;
|
||||
}
|
||||
Iplite_stats;
|
||||
|
||||
#define IPLITE_STATS(xvar) iplite.stats.xvar
|
||||
#define IPLITE_STAT_LINE(xline) xline
|
||||
|
||||
#else
|
||||
#define IPLITE_STATS(xvar) IP_NOOP
|
||||
#define IPLITE_STAT_LINE(xline) IP_NOOP
|
||||
#endif
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_tcp_data
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
typedef struct Iplite_tcp_data_struct
|
||||
{
|
||||
/* Elements checked for timeout each time the timer ticks,
|
||||
* the first element is always the element that will expire first
|
||||
*/
|
||||
/* TCP initial send sequence number */
|
||||
Ip_u32 iss;
|
||||
/* The time a socket was last created */
|
||||
Ip_u32 msec_last_sock_create;
|
||||
/* TCP segment header cache */
|
||||
void *segment_cache;
|
||||
/* List of TCB in states that is short lived under normal
|
||||
operations. SYN_RCV, FIN_WAIT_1 & LAST_ACK. The session that
|
||||
has been in this state for the longest time is sitting at the
|
||||
front of the list. */
|
||||
Ipcom_list transient_head;
|
||||
/* List of sockets that an application has called close() on */
|
||||
Ipcom_list user_closed_sock_head;
|
||||
#if defined(IPTCP_DEBUG) || defined(IPTCP_STATISTICS)
|
||||
Iplite_tcp_stats stats; /* Statistics */
|
||||
#endif
|
||||
}
|
||||
Iplite_tcp_data;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_data
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
typedef struct Iplite_data_struct
|
||||
{
|
||||
/* Tick. */
|
||||
Ip_u32 ticks; /* ticks since system started */
|
||||
Ip_u32 seconds; /* seconds since system started */
|
||||
Ip_u32 msec_last; /* millisecond counter last time the 'seconds' field was updated */
|
||||
|
||||
/* Timeout */
|
||||
Ip_u32 msec_now; /* The current time */
|
||||
Ipcom_pqueue *timeouts; /* Priority queue of timeouts */
|
||||
Iplite_timeout *tmo_list; /* List of free timeout structures */
|
||||
|
||||
/* Soft interrupts, soft_irq_xxx can only be modified with interrupts disabled */
|
||||
Ip_bool soft_irq_pending; /* Set to IP_TRUE if at least 1 soft interrupt is pending */
|
||||
Iplite_soft_irq *soft_irq_head; /* Points to the first soft interrupt to run */
|
||||
Iplite_soft_irq *soft_irq_tail; /* Points to the last soft interrupt to run */
|
||||
|
||||
Iplite_soft_irq drain_soft_irq; /* Static buffer to signal drain soft interrupts */
|
||||
Iplite_soft_irq pktavail_soft_irq;/* Static buffer to signal packet available soft interrupts */
|
||||
Iplite_soft_irq pktnew_soft_irq; /* Static buffer to that more packets must be added to the pool */
|
||||
|
||||
/* Memory. */
|
||||
Ip_size_t mem_used; /* Number of bytes currently allocated with iplite_malloc() */
|
||||
int pkt_pool_elem; /* Number of elements in the pool array */
|
||||
int pkt_pool_max_mtu; /* The maxmimum MTU any pool can hold */
|
||||
Iplite_pkt_pool pkt_pool[IPLITE_CONF_MAX_PKTPOOL]; /* The pkt pool array */
|
||||
Ipcom_pkt *pkt_hdr_list; /* Pool with allocated Ipcom_pkt structures (WITHOUT data) */
|
||||
int pkt_pool_blocked; /* Number of processes waiting for a packet */
|
||||
Ipcom_sem pkt_pool_sem; /* The semaphore on which waiting processes are sleeping */
|
||||
#ifdef IPLITE_USE_EXTERNAL_PKT_BUF
|
||||
Ipcom_pkt *external_pkt_hdr_list; /* Packet headers without data that is used together with
|
||||
OS specific buffers as ->data */
|
||||
#endif
|
||||
#ifdef IPLITE_DEBUG
|
||||
Ipcom_pkt *allocated_pkt_list; /* List of currently allocated packets */
|
||||
#endif
|
||||
|
||||
/* Mutex to protect IPLITE global data. */
|
||||
Ipcom_mutex code_mutex;
|
||||
#ifdef IP_ASSERT
|
||||
int code_mutex_count;
|
||||
Ip_pid_t code_lock_owner;
|
||||
#endif
|
||||
|
||||
/* Socket stuff. */
|
||||
struct Iplite_socket_struct *sockets[IPLITE_CONF_MAX_SOCKETS]; /* Array of socket pointers, iplite_conf_max_sockets entries */
|
||||
struct Iplite_socket_struct *bound_sockets[IPLITE_CONF_MAX_SOCKETS]; /* sorted local port array. */
|
||||
#ifdef IPCOM_USE_PACKET
|
||||
int num_packet_sock; /* Number of packet sockets currently active */
|
||||
#endif
|
||||
#ifndef IPLITE_MEM_OPT
|
||||
struct Iplite_socket_struct *socket_last; /* pointer to last used incoming socket. */
|
||||
#endif
|
||||
#ifdef IP_PORT_OSE5
|
||||
int raw_input_id;
|
||||
#endif
|
||||
Ip_fd last_fd; /* Last returned fd */
|
||||
|
||||
/* IPLITE daemon */
|
||||
Ip_pid_t daemon_pid;
|
||||
Ip_bool daemon_posted;
|
||||
Ipcom_block daemon_block; /* The IPLITE daemon sleeps on this when no events is pending */
|
||||
|
||||
/* Interface input queue. */
|
||||
Ip_pid_t input_ext_pid; /* Pid of extern input process calling ipcom_pkt_input() */
|
||||
Ip_u16 inq_num;
|
||||
Ipcom_pkt *inq_head;
|
||||
Ipcom_pkt *inq_tail;
|
||||
|
||||
/* Link/interface layer. */
|
||||
Iplite_netif *netifs[IPLITE_CONF_MAX_NETIF]; /* Array of netif pointers */
|
||||
Ipcom_if_eventcb if_eventcb[IPLITE_MAX_IF_EVENTCB];
|
||||
|
||||
Ip_u16 eth_name_index;
|
||||
Ip_u16 ppp_name_index;
|
||||
|
||||
#if defined(IPLITE_DEBUG) || defined(IPLITE_STATISTICS)
|
||||
Iplite_stats stats;
|
||||
#endif
|
||||
|
||||
/* IP version 4 */
|
||||
#ifdef IPCOM_USE_INET
|
||||
Iplite_ip4_data ip4;
|
||||
#endif
|
||||
|
||||
/* IP version 6 */
|
||||
#ifdef IPCOM_USE_INET6
|
||||
Iplite_ip6_data ip6;
|
||||
#endif
|
||||
|
||||
#ifdef IPCOM_USE_TCP
|
||||
Iplite_tcp_data tcp;
|
||||
#endif
|
||||
|
||||
/* PPP and PPPoE support */
|
||||
#ifdef IPPPP
|
||||
Ipppp_ipstack_data ppp;
|
||||
#endif
|
||||
|
||||
/* MIB-2 */
|
||||
#ifdef IPCOM_USE_MIB2
|
||||
Ipcom_mib2_stats mib2;
|
||||
#endif
|
||||
|
||||
#if IPCOM_SYSLOG_PRIORITY >= IPCOM_LOG_WARNING
|
||||
char str[40];
|
||||
#endif
|
||||
}
|
||||
Iplite_data;
|
||||
|
||||
|
||||
/* Iplite_data flags: */
|
||||
#define IPLITE_FLAG_CREATED 0x01 /* IPLITE is opened. */
|
||||
#define IPLITE_FLAG_PKTAVAIL_CB_PENDING 0x10 /* A non-blocking socket with a callback handler failed
|
||||
due to no packets in the packet pool */
|
||||
#define IPLITE_FLAG_CONFIGURED 0x40 /* interface configuration complete. */
|
||||
|
||||
|
||||
/* iplite pkt info */
|
||||
#define IPLITE_PKT_INFO_PKTINFO 64
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPLITE_C
|
||||
IP_EXTERN Iplite_data iplite;
|
||||
IP_EXTERN Ip_u32 iplite_flags;
|
||||
#endif
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
IP_EXTERN IP_CONST struct Ip_in6_addr iplite_in6addr_any; /* :: (undefined address) */
|
||||
#endif
|
||||
|
||||
#ifdef IPCOM_USE_DMALLOC
|
||||
IP_GLOBAL void *iplite_kmalloc_impl(Ip_size_t size, const char *file, const char *function, Ip_u32 line);
|
||||
#define iplite_kmalloc(size) iplite_kmalloc_impl(size, __FILE__, __FUNCTION__, __LINE__)
|
||||
#else
|
||||
IP_GLOBAL void *iplite_kmalloc_impl(Ip_size_t size);
|
||||
#define iplite_kmalloc(size) iplite_kmalloc_impl(size)
|
||||
#endif
|
||||
|
||||
IP_GLOBAL void iplite_kfree(void *ptr);
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* OS port upcalls
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Driver/link upcalls
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
/* Note: The caller must be IPLITE code locked to call iplite_kioevent() */
|
||||
IP_PUBLIC void iplite_kioevent(Iplite_netif *netif, int command, void *data);
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPLITE Internal
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
IP_GLOBAL Ip_bool iplite_is_stack_task(void);
|
||||
|
||||
IP_GLOBAL Ipcom_pkt *iplite_pkt_clone(Ipcom_pkt *orginal);
|
||||
|
||||
IP_GLOBAL int iplite_udp_input(Ipcom_pkt *pkt, Ip_bool is_multicast,
|
||||
IP_CONST void *src_addr, IP_CONST void *dst_addr,
|
||||
Iplite_socklookup socklookup);
|
||||
IP_GLOBAL int iplite_udp_output(struct Iplite_socket_struct *sock, IP_CONST struct Ip_sockaddr *to, Ipcom_pkt *pkt);
|
||||
|
||||
IP_PUBLIC Ip_s32 iplite_timeval_to_msec(struct Ip_timeval *tv);
|
||||
|
||||
#ifndef IPLITE_DEBUG
|
||||
IP_GLOBAL void iplite_tcp_cache_free(void);
|
||||
#endif
|
||||
|
||||
IP_GLOBAL int iplite_raw_output(struct Iplite_socket_struct *sock, IP_CONST struct Ip_sockaddr *to, Ipcom_pkt *pkt);
|
||||
IP_GLOBAL void iplite_create_mask(void *mask, int netbits);
|
||||
|
||||
#if defined(IPCOM_USE_MIB2) && defined(IPCOM_USE_INET6)
|
||||
IP_GLOBAL Iplite_netif *iplite_ip6_addr_to_netif(struct Ip_in6_addr *in6_addr);
|
||||
#endif
|
||||
|
||||
IP_GLOBAL Ipcom_pkt * iplite_pkt_hdr_malloc(int fcflags);
|
||||
|
||||
IP_GLOBAL void iplite_sockpkt_pkt_free(void *data, void *cookie);
|
||||
|
||||
IP_PUBLIC void ipcom_stack_lock(void);
|
||||
IP_PUBLIC void ipcom_stack_unlock(void);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Fragmentation & reassembly
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef Ip_bool (*Iplite_is_part_of_same_pkt_func)(Ipcom_pkt *frag1, Ipcom_pkt *frag2);
|
||||
typedef int (*Iplite_get_offset_func)(Ipcom_pkt *frag);
|
||||
typedef Ip_bool (*Iplite_more_fragments_func)(Ipcom_pkt *frag);
|
||||
typedef void (*Iplite_update_ip_header_func)(Ipcom_pkt *pkt, Ipcom_pkt *frag_list);
|
||||
typedef void (*Iplite_reassemble_err_hnd)(Ipcom_pkt *frag_list);
|
||||
|
||||
IP_GLOBAL Ipcom_pkt *
|
||||
iplite_reassembly(Ipcom_pkt **reassembly_list,
|
||||
Ipcom_pkt *pkt,
|
||||
Iplite_is_part_of_same_pkt_func is_part_of_same_pkt,
|
||||
Iplite_get_offset_func get_offset,
|
||||
Iplite_more_fragments_func more_fragments,
|
||||
Iplite_timeout_handler tmo_cb,
|
||||
int frag_hdr_len);
|
||||
IP_GLOBAL Ipcom_pkt *
|
||||
iplite_create_reassembled_packet(Ipcom_pkt *fragment_list,
|
||||
int ip_hdr_size,
|
||||
int frag_hdr_size,
|
||||
Iplite_update_ip_header_func update_ip_header,
|
||||
Iplite_reassemble_err_hnd reassemble_err_hnd);
|
||||
IP_GLOBAL Ipcom_pkt *
|
||||
iplite_fragment_packet(Ipcom_pkt *pkt, int ip_hdr_size, int other_hdr_size, int mtu);
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* DEBUG FUNCTIONS
|
||||
*===========================================================================
|
||||
*
|
||||
*/
|
||||
#ifdef IPLITE_DEBUG
|
||||
IP_GLOBAL void iplite_pkt_check(Ipcom_pkt *pkt);
|
||||
IP_GLOBAL void iplite_pkt_add_to_alloc_list(Ipcom_pkt *pkt);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,781 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_ioctl.c,v $ $Revision: 1.54 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_ioctl.c,v $
|
||||
* $Author: lob $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* ipcom_socketioctl() function.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_SKIP_NATIVE_SOCK_API
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#if !defined(IPLITE_ONE_FILE) || defined(IPLITE_C) || defined(IPLITE_MEM_OPT)
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_inet.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_loopback.h"
|
||||
#include "iplite_sock.h"
|
||||
#ifdef IPCOM_USE_ETHERNET
|
||||
#include "iplite_eth.h"
|
||||
#endif
|
||||
|
||||
#ifdef IPIPSEC2
|
||||
#include <ipipsec.h>
|
||||
#include <ipipsec_pfkeyv2.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPLITE_USE_IOCTL_IFCONF
|
||||
struct Iplite_ifconf_entry
|
||||
{
|
||||
char if_name[IP_IFNAMSIZ];
|
||||
|
||||
union ifconf_addr
|
||||
{
|
||||
struct Ip_sockaddr sa;
|
||||
struct Ip_sockaddr_dl sdl;
|
||||
struct Ip_sockaddr_in sin;
|
||||
#ifdef IPCOM_USE_INET6
|
||||
struct Ip_sockaddr_in6 sin6;
|
||||
#endif
|
||||
} s;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPIPSEC2
|
||||
IP_GLOBAL Ip_err ipipsec_conf_internal(Ip_tag *ctrl_tags);
|
||||
IP_GLOBAL Ip_err ipipsec_ctrl_internal(Ip_tag *ctrl_tags);
|
||||
IP_GLOBAL Ip_err ipipsec_sactrl_internal(Ipipsec_sa_handle *sah, Ip_tag *ctrl_tags);
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ioctl_if_siocgifconf
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
#ifdef IPLITE_USE_IOCTL_IFCONF
|
||||
IP_STATIC int
|
||||
iplite_ioctl_if_siocgifconf(struct Ip_ifconf *ifconf)
|
||||
{
|
||||
Iplite_netif *netif;
|
||||
int len, ifc_len;
|
||||
Ip_u32 i;
|
||||
struct Iplite_ifconf_entry *entry;
|
||||
|
||||
entry = (struct Iplite_ifconf_entry *)ifconf->ip_ifc_buf;
|
||||
ifc_len = 0;
|
||||
|
||||
for (i = 1; i < IPLITE_CONF_MAX_NETIF; i++)
|
||||
{
|
||||
netif = iplite.netifs[i];
|
||||
if (netif == IP_NULL)
|
||||
continue;
|
||||
|
||||
/* sockaddr_dl */
|
||||
len = sizeof(entry->if_name) + sizeof(struct Ip_sockaddr_dl);
|
||||
if ((ifconf->ifc_len - ifc_len) < len)
|
||||
break;
|
||||
ifc_len += len;
|
||||
ipcom_memset(entry, 0, len);
|
||||
ipcom_strcpy(entry->if_name, netif->ipcom.name);
|
||||
entry->s.sdl.sdl_len = sizeof(struct Ip_sockaddr_dl);
|
||||
entry->s.sdl.sdl_family = IP_AF_LINK;
|
||||
entry->s.sdl.sdl_index = (Ip_u16) netif->ipcom.ifindex;
|
||||
entry->s.sdl.sdl_type = (Ip_u8) netif->ipcom.type;
|
||||
switch (netif->ipcom.type)
|
||||
{
|
||||
#ifdef IPCOM_USE_ETHERNET
|
||||
case IP_IFT_ETHER:
|
||||
entry->s.sdl.sdl_type = IP_IFT_ETHER;
|
||||
entry->s.sdl.sdl_alen = 6;
|
||||
ipcom_memcpy(entry->s.sdl.sdl_data, netif->ipcom.link_addr, 6);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
entry = (struct Iplite_ifconf_entry *)((char*)entry + len);
|
||||
|
||||
/* sockaddr_in */
|
||||
#ifdef IPCOM_USE_INET
|
||||
{
|
||||
Iplite_ip4_addr_entry *inet4_addr; /* List of IPv4 addresses */
|
||||
for (inet4_addr = netif->inet4_addr_list; inet4_addr; inet4_addr = inet4_addr->next)
|
||||
{
|
||||
if (IP_IN_CLASSD(inet4_addr->ipaddr_n))
|
||||
continue;
|
||||
len = sizeof(entry->if_name) + sizeof(struct Ip_sockaddr_in);
|
||||
if ((ifconf->ifc_len - ifc_len) < len)
|
||||
break;
|
||||
/* Add the unicast address */
|
||||
ifc_len += len;
|
||||
ipcom_memset(entry, 0, len);
|
||||
ipcom_strcpy(entry->if_name, netif->ipcom.name);
|
||||
entry->s.sin.sin_family = IP_AF_INET;
|
||||
entry->s.sin.sin_len = sizeof(struct Ip_sockaddr_in);
|
||||
entry->s.sin.sin_addr.s_addr = inet4_addr->ipaddr_n;
|
||||
entry = (struct Iplite_ifconf_entry *)((char*)entry + len);
|
||||
}
|
||||
}
|
||||
#endif /* IPCOM_USE_INET */
|
||||
|
||||
/* sockaddr_in6 */
|
||||
#ifdef IPCOM_USE_INET6
|
||||
{
|
||||
Iplite_ip6_addr_entry *inet6_addr; /* List of IPv6 addresses */
|
||||
for (inet6_addr = netif->inet6_addr_list; inet6_addr; inet6_addr = inet6_addr->next)
|
||||
{
|
||||
if (IP_IN6_IS_ADDR_MULTICAST(&inet6_addr->addr))
|
||||
continue;
|
||||
len = sizeof(entry->if_name) + sizeof(struct Ip_sockaddr_in6);
|
||||
if ((ifconf->ifc_len - ifc_len) < len)
|
||||
break;
|
||||
ifc_len += len;
|
||||
ipcom_memset(entry, 0, len);
|
||||
ipcom_strcpy(entry->if_name, netif->ipcom.name);
|
||||
entry->s.sin.sin_family = IP_AF_INET6;
|
||||
entry->s.sin.sin_len = sizeof(struct Ip_sockaddr_in6);
|
||||
ipcom_memcpy(&entry->s.sin6.sin6_addr, &inet6_addr->addr, sizeof(struct Ip_in6_addr));
|
||||
entry = (struct Iplite_ifconf_entry *)((char*)entry + len);
|
||||
}
|
||||
}
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
|
||||
}
|
||||
|
||||
ifconf->ifc_len = ifc_len;
|
||||
return 0;
|
||||
}
|
||||
#endif /* IPLITE_USE_IOCTL_IFCONF */
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ioctl_if
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ioctl_if(unsigned long request, struct Ip_ifreq *ifreq)
|
||||
{
|
||||
Iplite_netif *netif;
|
||||
int ret = 0;
|
||||
Ip_u32 old_flags;
|
||||
Ip_u32 param_flags;
|
||||
Ip_u32 ro_flags;
|
||||
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
#ifdef IPLITE_USE_IOCTL_IFCONF
|
||||
if (request == IP_SIOCGIFCONF)
|
||||
return iplite_ioctl_if_siocgifconf((struct Ip_ifconf *)ifreq);
|
||||
#endif
|
||||
|
||||
netif = iplite_if_nametonetif(ifreq->ifr_name);
|
||||
if (netif == IP_NULL)
|
||||
return -IP_ERRNO_ENXIO;
|
||||
|
||||
switch (request)
|
||||
{
|
||||
case IP_SIOCGIFMTU :
|
||||
ifreq->ifr_ifru.ifru_mtu = (int)netif->ipcom.mtu;
|
||||
break;
|
||||
case IP_SIOCSIFMTU :
|
||||
netif->ipcom.mtu = (Ip_u32) ifreq->ifr_ifru.ifru_mtu;
|
||||
break;
|
||||
case IP_SIOCGIFFLAGS :
|
||||
ifreq->ifr_ifru.ifru_flags = (Ip_u16) netif->ipcom.flags;
|
||||
break;
|
||||
case IP_SIOCSIFFLAGS :
|
||||
if (IP_BIT_ISSET(ifreq->ifr_ifru.ifru_flags, IP_IFF_UP))
|
||||
{
|
||||
/* Flag interface up and interface is not UP. */
|
||||
if(!IP_BIT_ISSET(netif->ipcom.flags, IP_IFF_UP))
|
||||
ret = netif->link_ioctl(netif, IP_SIOCXOPEN, IP_NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Flag interface down -> always issue close message */
|
||||
ret = netif->link_ioctl(netif, IP_SIOCXCLOSE, IP_NULL);
|
||||
}
|
||||
|
||||
/* Set new flags but leave all read-only flags unchanged. */
|
||||
param_flags = (Ip_u32) ifreq->ifr_ifru.ifru_flags;
|
||||
ro_flags = IP_IFF_UP | IP_IFF_RUNNING | IP_IFF_PROMISC | IP_IFF_BROADCAST
|
||||
| IP_IFF_POINTOPOINT | IP_IFF_SIMPLEX | IP_IFF_MULTICAST | IP_IFF_ALLMULTI;
|
||||
old_flags = netif->ipcom.flags & ~ro_flags;
|
||||
netif->ipcom.flags = (param_flags & ~ro_flags) | (netif->ipcom.flags & ro_flags);
|
||||
if ((old_flags ^ netif->ipcom.flags) & ~(IP_IFF_UP|IP_IFF_RUNNING))
|
||||
iplite_kioevent(netif, IP_EIOXCHANGE, IP_NULL);
|
||||
break;
|
||||
|
||||
case IP_SIOCXDETACH :
|
||||
IPLITE_CODE_UNLOCK();
|
||||
ret = ipcom_if_detach(&netif->ipcom);
|
||||
if(ret > 0)
|
||||
ret = ipcom_if_free(&netif->ipcom);
|
||||
IPLITE_CODE_LOCK();
|
||||
break;
|
||||
|
||||
case IP_SIOCXGDHCPRUNNING:
|
||||
ifreq->ifr_ifru.ifru_opt = IP_BIT_ISSET(netif->ipcom.flags, IP_IFF_X_DHCPRUNNING) ? 1 : 0;
|
||||
break;
|
||||
case IP_SIOCXSDHCPRUNNING:
|
||||
if (ifreq->ifr_ifru.ifru_opt == 1)
|
||||
IP_BIT_SET(netif->ipcom.flags, IP_IFF_X_DHCPRUNNING);
|
||||
else
|
||||
IP_BIT_CLR(netif->ipcom.flags, IP_IFF_X_DHCPRUNNING);
|
||||
iplite_kioevent(netif, IP_EIOXCHANGE, IP_NULL);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Remaining ioctl()'s to to link layer (including ETH, PPP etc). */
|
||||
ret = netif->link_ioctl(netif, request, ifreq);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ioctl_sock
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ioctl_sock(Ip_fd fd, unsigned long request, void *argp)
|
||||
{
|
||||
Iplite_socket *sock;
|
||||
int *iargp = (int*) argp;
|
||||
|
||||
/* The following options require a valid socket. */
|
||||
ip_assert2(fd >= IPLITE_SOCKET_STARTFD);
|
||||
ip_assert2(fd < IPLITE_CONF_MAX_SOCKETS);
|
||||
ip_assert2(iplite.sockets[fd] != IP_NULL);
|
||||
if (fd < IPLITE_SOCKET_STARTFD || fd >= IPLITE_CONF_MAX_SOCKETS || iplite.sockets[fd] == IP_NULL)
|
||||
return -IP_ERRNO_EBADF;
|
||||
sock = iplite.sockets[fd];
|
||||
|
||||
switch (request)
|
||||
{
|
||||
case IP_SIOCSPGRP:
|
||||
sock->ipcom.pid = *iargp;
|
||||
#if 0
|
||||
/*!!wakeup the blocking processes with error code? */
|
||||
if (sock->rcv_block != IPCOM_BLOCK_INVALID)
|
||||
(void)ipcom_block_delete(&sock->rcv_block);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case IP_SIOCGPGRP:
|
||||
*iargp = (int)sock->ipcom.pid;
|
||||
break;
|
||||
|
||||
case IP_FIONBIO:
|
||||
if (*iargp)
|
||||
IP_BIT_SET(sock->flags, IPLITE_SOCKET_FLAG_NONBLOCKING);
|
||||
else
|
||||
IP_BIT_CLR(sock->flags, IPLITE_SOCKET_FLAG_NONBLOCKING);
|
||||
break;
|
||||
|
||||
case IP_X_FIOGNBIO:
|
||||
*iargp = IP_BIT_ISSET(sock->flags, IPLITE_SOCKET_FLAG_NONBLOCKING) ? 1 : 0;
|
||||
break;
|
||||
|
||||
case IP_FIONREAD:
|
||||
*iargp = sock->ipcom.rcv_bytes;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ioctl_ip4
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET
|
||||
IP_STATIC int
|
||||
iplite_ioctl_ip4(unsigned long request, struct Ip_ifreq *ifreq)
|
||||
{
|
||||
Iplite_netif *netif;
|
||||
Iplite_ip4_addr_entry *addr;
|
||||
struct Ip_sockaddr_in *in_addr;
|
||||
struct Ip_in_aliasreq *ifalias;
|
||||
Ip_u32 ipaddr_n;
|
||||
Ip_u32 netmask_n;
|
||||
Ip_u32 subbrd_n;
|
||||
int ret;
|
||||
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
switch (request)
|
||||
{
|
||||
case IP_SIOCADDRT:
|
||||
iplite.ip4.default_gateway_n = ((struct Ip_sockaddr_in *)(&((struct Ip_ortentry *)ifreq)->rt_gateway))->sin_addr.s_addr;
|
||||
return 0;
|
||||
case IP_SIOCDELRT:
|
||||
iplite.ip4.default_gateway_n = 0; /* clear gateway */
|
||||
return 0;
|
||||
case IP_SIOCXGETRT:
|
||||
((struct Ip_sockaddr_in *)(&((struct Ip_ortentry *)ifreq)->rt_gateway))->sin_addr.s_addr = iplite.ip4.default_gateway_n;
|
||||
return 0;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
netif = iplite_if_nametonetif(ifreq->ifr_name);
|
||||
if (netif == IP_NULL)
|
||||
return -IP_ERRNO_ENXIO;
|
||||
|
||||
#ifdef IPPPP
|
||||
if (netif->ipcom.type == IP_IFT_PPP || netif->ipcom.type == IP_IFT_PPPOE)
|
||||
/* PPP special case. */
|
||||
return netif->link_ioctl(netif, request, ifreq);
|
||||
#endif
|
||||
|
||||
/* Get interface primary IPv4 address. */
|
||||
ifalias = (struct Ip_in_aliasreq *)ifreq;
|
||||
for (addr = netif->inet4_addr_list; addr != IP_NULL; addr = addr->next)
|
||||
{
|
||||
if(IP_IN_CLASSD(addr->ipaddr_n))
|
||||
continue;
|
||||
/* Alias add request, skip all addresses that do not match. */
|
||||
if(request == IP_SIOCAIFADDR &&
|
||||
((struct Ip_sockaddr_in *)&ifalias->ifra_addr)->sin_addr.s_addr != addr->ipaddr_n)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
in_addr = (struct Ip_sockaddr_in *) &ifreq->ifr_ifru.ifru_addr;
|
||||
|
||||
switch (request)
|
||||
{
|
||||
case IP_SIOCGIFADDR :
|
||||
case IP_SIOCGIFBRDADDR :
|
||||
case IP_SIOCGIFNETMASK :
|
||||
ipcom_memset(in_addr, 0, sizeof(struct Ip_sockaddr_in));
|
||||
in_addr->sin_family = IP_AF_INET;
|
||||
in_addr->sin_len = sizeof(struct Ip_sockaddr_in);
|
||||
break;
|
||||
default:
|
||||
if (in_addr->sin_family != IP_AF_INET
|
||||
|| in_addr->sin_len < sizeof(struct Ip_sockaddr_in))
|
||||
return -IP_ERRNO_EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (addr != IP_NULL)
|
||||
{
|
||||
ipaddr_n = addr->ipaddr_n;
|
||||
netmask_n = addr->netmask_n;
|
||||
subbrd_n = addr->subbrd_n;
|
||||
}
|
||||
else
|
||||
{
|
||||
ipaddr_n = 0;
|
||||
netmask_n = 0;
|
||||
subbrd_n = 0;
|
||||
}
|
||||
|
||||
switch (request)
|
||||
{
|
||||
case IP_SIOCGIFADDR :
|
||||
in_addr->sin_addr.s_addr = ipaddr_n;
|
||||
break;
|
||||
case IP_SIOCGIFBRDADDR :
|
||||
in_addr->sin_addr.s_addr = subbrd_n;
|
||||
break;
|
||||
case IP_SIOCGIFNETMASK :
|
||||
in_addr->sin_addr.s_addr = netmask_n;
|
||||
break;
|
||||
case IP_SIOCSIFNETMASK :
|
||||
if (addr == IP_NULL)
|
||||
return -IP_ERRNO_EINVAL;
|
||||
netmask_n = in_addr->sin_addr.s_addr;
|
||||
break;
|
||||
case IP_SIOCSIFADDR :
|
||||
if (addr != IP_NULL)
|
||||
{
|
||||
ipaddr_n = in_addr->sin_addr.s_addr;
|
||||
break;
|
||||
}
|
||||
ret = iplite_ip4_add_addr(netif, in_addr->sin_addr.s_addr, 0);
|
||||
break;
|
||||
case IP_SIOCAIFADDR :
|
||||
ret = iplite_ip4_add_addr(netif, in_addr->sin_addr.s_addr,
|
||||
((struct Ip_sockaddr_in *)&ifalias->ifra_mask)->sin_addr.s_addr);
|
||||
break;
|
||||
case IP_SIOCDIFADDR :
|
||||
ret = iplite_ip4_remove_addr(netif, in_addr->sin_addr.s_addr);
|
||||
break;
|
||||
default:
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
|
||||
if (addr != IP_NULL && request != IP_SIOCDIFADDR)
|
||||
{
|
||||
Ip_u32 ipaddr_netmask_n;
|
||||
|
||||
ipaddr_netmask_n = IP_NETMASK(ipaddr_n);
|
||||
addr->ipaddr_n = ipaddr_n;
|
||||
addr->netmask_n = netmask_n;
|
||||
addr->subbrd_n = (netmask_n & ipaddr_n) | ~netmask_n;
|
||||
addr->netbrd_n = (ipaddr_netmask_n & ipaddr_n) | ~ipaddr_netmask_n;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif /* IPCOM_USE_INET */
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ioctl_ip6
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET6
|
||||
IP_STATIC int
|
||||
iplite_ioctl_ip6(unsigned long request, void *data)
|
||||
{
|
||||
Iplite_netif *netif;
|
||||
struct Ip_in6_ifreq *ifreq = (struct Ip_in6_ifreq *) data;
|
||||
struct Ip_in6_aliasreq *ifareq = (struct Ip_in6_aliasreq *) data;
|
||||
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
netif = iplite_if_nametonetif(ifreq->ifr_name);
|
||||
if (netif == IP_NULL)
|
||||
return -IP_ERRNO_ENXIO;
|
||||
|
||||
#ifdef IPPPP
|
||||
if (netif->ipcom.type == IP_IFT_PPP || netif->ipcom.type == IP_IFT_PPPOE)
|
||||
/* PPP special case. */
|
||||
return netif->link_ioctl(netif, request, ifreq);
|
||||
#endif
|
||||
|
||||
/* Sanity check */
|
||||
switch (request)
|
||||
{
|
||||
case IP_SIOCAIFADDR_IN6 :
|
||||
case IP_SIOCDIFADDR_IN6 :
|
||||
if (ifreq->ifr_ifru.ifru_addr.sin6_family != IP_AF_INET6
|
||||
|| ifreq->ifr_ifru.ifru_addr.sin6_len < sizeof(struct Ip_sockaddr_in6))
|
||||
return -IP_ERRNO_EINVAL;
|
||||
break;
|
||||
default:
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
|
||||
switch (request)
|
||||
{
|
||||
case IP_SIOCAIFADDR_IN6 :
|
||||
{
|
||||
Ip_time_t now;
|
||||
Ip_u32 preferred_lifetime = IPCOM_ADDR_INFINITE;
|
||||
Ip_u32 valid_lifetime = IPCOM_ADDR_INFINITE;
|
||||
|
||||
now = ipcom_time(IP_NULL);
|
||||
if (ifareq->ifra_lifetime.ia6t_preferred != (Ip_time_t)IPCOM_ADDR_INFINITE)
|
||||
preferred_lifetime = ifareq->ifra_lifetime.ia6t_preferred - now;
|
||||
if (ifareq->ifra_lifetime.ia6t_expire != (Ip_time_t)IPCOM_ADDR_INFINITE)
|
||||
valid_lifetime = ifareq->ifra_lifetime.ia6t_expire - now;
|
||||
return iplite_ip6_add_addr(netif, &ifareq->ifra_addr.sin6_addr,
|
||||
ipcom_mask_to_prefixlen(&ifareq->ifra_prefixmask.sin6_addr, 128),
|
||||
IP_BIT_ISSET(ifareq->ifra_flags, IP_IN6_IFF_TENTATIVE) ? IPLITE_IP6_ADDR_FLAG_TENTATIVE : 0,
|
||||
preferred_lifetime, valid_lifetime);
|
||||
}
|
||||
case IP_SIOCDIFADDR_IN6 :
|
||||
return iplite_ip6_remove_addr(netif, &ifreq->ifr_ifru.ifru_addr.sin6_addr);
|
||||
default:
|
||||
IP_PANIC();
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
}
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_do_ioctl
|
||||
*===========================================================================
|
||||
* Description: Internal IO control.
|
||||
* Parameters: request - The IO control request.
|
||||
* argp - Request specific data.
|
||||
* Returns: 0 = success, -1 = error (error code from ipcom_errno).
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_do_ioctl(Ip_fd fd, unsigned long request, void *argp)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(IP_IOC_GROUP(request) == IP_IOCG_NETIF
|
||||
#ifdef IPPPP
|
||||
|| IP_IOC_GROUP(request) == IP_IOCG_PPP
|
||||
#endif
|
||||
#ifdef IPLITE_USE_WLAN
|
||||
|| IP_IOC_GROUP(request) == IP_IOCG_WLAN
|
||||
#endif
|
||||
|| IP_IOC_GROUP(request) == IP_IOCG_ETH)
|
||||
return iplite_ioctl_if(request, (struct Ip_ifreq *) argp);
|
||||
|
||||
if(IP_IOC_GROUP(request) == IP_IOCG_SOCK)
|
||||
return iplite_ioctl_sock(fd, request, argp);
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
if(IP_IOC_GROUP(request) == IP_IOCG_INET)
|
||||
return iplite_ioctl_ip4(request, (struct Ip_ifreq *) argp);
|
||||
#if defined(IPCOM_USE_ETHERNET) && defined(IPLITE_USE_IOCTL_ARP)
|
||||
if(IP_IOC_GROUP(request) == IP_IOCG_ARP)
|
||||
return iplite_arp_ioctl(request, (struct Ip_arpreq *) argp);
|
||||
#endif
|
||||
#endif /* IPCOM_USE_INET */
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
if(IP_IOC_GROUP(request) == IP_IOCG_INET6)
|
||||
return iplite_ioctl_ip6(request, argp);
|
||||
#endif
|
||||
|
||||
/* Base. */
|
||||
switch (request)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET6
|
||||
case IP_SIOCXGETGW_IN6:
|
||||
/* Get default IPv6 gateway. */
|
||||
ipcom_memcpy(&((struct Ip_sockaddr_in6 *)argp)->sin6_addr,
|
||||
&iplite.ip6.default_gateway,
|
||||
sizeof(struct Ip_in6_addr));
|
||||
((struct Ip_sockaddr_in6 *)argp)->sin6_scope_id = iplite.ip6.default_scope_id;
|
||||
break;
|
||||
case IP_SIOCXSETGW_IN6:
|
||||
/* Set default IPv6 gateway (including its optional scope id). */
|
||||
ipcom_memcpy(&iplite.ip6.default_gateway,
|
||||
&((struct Ip_sockaddr_in6 *)argp)->sin6_addr,
|
||||
sizeof(struct Ip_in6_addr));
|
||||
iplite.ip6.default_scope_id = ((struct Ip_sockaddr_in6 *)argp)->sin6_scope_id;
|
||||
break;
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
|
||||
case IP_SIOCXSIFFEVENTCB:
|
||||
/* Set interface event callback. */
|
||||
for (i = 0; i < IPLITE_MAX_IF_EVENTCB; i++)
|
||||
if (iplite.if_eventcb[i] == IP_NULL)
|
||||
{
|
||||
iplite.if_eventcb[i] = *(Ipcom_if_eventcb*)&argp;
|
||||
return 0;
|
||||
}
|
||||
return -IP_ERRNO_EINVAL;
|
||||
|
||||
case IP_SIOCXDIFFEVENTCB:
|
||||
/* Delete interface event callback. */
|
||||
for (i = 0; i < IPLITE_MAX_IF_EVENTCB; i++)
|
||||
if (iplite.if_eventcb[i] == *(Ipcom_if_eventcb*)&argp)
|
||||
{
|
||||
iplite.if_eventcb[i] = 0;
|
||||
return 0;
|
||||
}
|
||||
return -IP_ERRNO_ENOENT;
|
||||
|
||||
#ifdef IPIPSEC2
|
||||
case IP_SIOCXIPSEC_SELECTOR:
|
||||
case IP_SIOCXIPSEC_NEXT_SA:
|
||||
case IP_SIOCXIPSEC_Grouped:
|
||||
case IP_SIOCXIPSEC_InUserOctets:
|
||||
case IP_SIOCXIPSEC_OutUserOctets:
|
||||
case IP_SIOCXIPSEC_InUserPackets:
|
||||
case IP_SIOCXIPSEC_OutUserPackets:
|
||||
return ipipsec_sys_ioctl(fd, request, argp);
|
||||
#ifdef IPIPSEC_USE_CTRL_API
|
||||
case IP_SIOCXIPSEC_CTL:
|
||||
return ipipsec_ctrl_internal(((Ip_tag **)argp)[0]);
|
||||
case IP_SIOCXIPSEC_SA_CTL:
|
||||
return ipipsec_sactrl_internal(((void **)argp)[0], ((void **)argp)[1]);
|
||||
case IP_SIOCXIPSEC_CONF_CTL:
|
||||
return ipipsec_conf_internal(((void **)argp)[0]);
|
||||
#endif
|
||||
#endif /* IPIPSEC2 */
|
||||
|
||||
default:
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_socketioctl_islocked
|
||||
*===========================================================================
|
||||
* Description: IO control.
|
||||
* Parameters: fd - A socket descriptor.
|
||||
* request - The IO control request.
|
||||
* argp - Request specific data.
|
||||
* Returns: 0 = success, -1 = error (error code from ipcom_errno).
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_socketioctl_islocked(Ip_fd fd, unsigned long request, void *argp)
|
||||
{
|
||||
int ret;
|
||||
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
ret = iplite_do_ioctl(fd, request, argp);
|
||||
if (ret < 0)
|
||||
SOCK_ERROUT(-ret);
|
||||
|
||||
return ret;
|
||||
|
||||
errout:
|
||||
return (int)IP_SOCKERR;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipcom_socketioctl
|
||||
*===========================================================================
|
||||
* Description: IO control.
|
||||
* Parameters: fd - A socket descriptor.
|
||||
* request - The IO control request.
|
||||
* argp - Request specific data.
|
||||
* Returns: 0 = success, -1 = error (error code from ipcom_errno).
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
ipcom_socketioctl(Ip_fd fd, unsigned long request, void *argp)
|
||||
{
|
||||
int ret;
|
||||
|
||||
IPLITE_CODE_LOCK();
|
||||
|
||||
ret = iplite_do_ioctl(fd, request, argp);
|
||||
if (ret < 0)
|
||||
{
|
||||
(void)ipcom_errno_set(-ret);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
IPLITE_CODE_UNLOCK();
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* !defined(IPLITE_ONE_FILE) || defined(IPLITE_C) */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK API HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_ip4.h,v $ $Revision: 1.13.26.2 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_ip4.h,v $
|
||||
* $Author: svc-cmnet $ $Date: 2013-03-13 07:45:29 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPLITE_IP4_H
|
||||
#define IPLITE_IP4_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* Internal IPv4 header file.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_os.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPLITE_ICMP_HDR_SIZE 8
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* forward declarations
|
||||
*===========================================================================
|
||||
*/
|
||||
struct Iplite_socket_struct;
|
||||
union Iplite_frame_union;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_pkt_ip
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef IP_PACKED struct Iplite_pkt_ip_struct
|
||||
{
|
||||
Ip_u8 v_hl; /* 4bit version and 4bit header length. */
|
||||
Ip_u8 tos; /* 8bit type of service. */
|
||||
Ip_u16 len; /* Total length. */
|
||||
Ip_u16 id; /* Identification. */
|
||||
Ip_u16 off; /* Fragment offset field. */
|
||||
Ip_u8 ttl; /* 8bit time-to-live. */
|
||||
Ip_u8 p; /* 8bit IP protocol. */
|
||||
Ip_u16 sum; /* Internet Checksum. */
|
||||
Ip_u16 src[2]; /* Destination IP address. */
|
||||
Ip_u16 dst[2]; /* Source IP address. */
|
||||
}
|
||||
Iplite_pkt_ip;
|
||||
|
||||
#define IPLITE_IP_HDR_SIZE 20 /* The IPv4 header is 20 octets long */
|
||||
|
||||
#define IPLITE_IP4_GET_VHL(ip) (ip)->v_hl
|
||||
#define IPLITE_IP4_SET_VHL(ip,val) (ip)->v_hl = val
|
||||
#define IPLITE_IP4_GET_TOS(ip) (ip)->tos
|
||||
#define IPLITE_IP4_SET_TOS(ip,val) (ip)->tos = val
|
||||
#define IPLITE_IP4_GET_TTL(ip) (ip)->ttl
|
||||
#define IPLITE_IP4_SET_TTL(ip,val) (ip)->ttl = (Ip_u8) val
|
||||
#define IPLITE_IP4_GET_P(ip) (ip)->p
|
||||
#define IPLITE_IP4_SET_P(ip,val) (ip)->p = (Ip_u8) val
|
||||
|
||||
#define IPLITE_IP4_GET_IPADDR(ip) IP_GET_32ON16(ip)
|
||||
#define IPLITE_IP4_SET_IPADDR(ip1,ip2) IP_SET_32ON16(ip1,IP_GET_32ON16(ip2))
|
||||
|
||||
#ifdef IPLITE_USE_RFC3927
|
||||
#define IPLITE_IP4_IS_LINK_LOCAL(paddr) ((IP_GET_NTOHL(paddr) & 0xffff0000) == 0xa9fe0000)
|
||||
#endif
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_pkt_icmp
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef IP_PACKED struct Iplite_pkt_icmp_struct
|
||||
{
|
||||
Ip_u8 type;
|
||||
Ip_u8 code;
|
||||
Ip_u16 cksum; /* Internet Checksum. */
|
||||
|
||||
IP_PACKED union Iplite_pkt_icmp_data_union
|
||||
{
|
||||
IP_PACKED struct Iplite_pkt_icmp_data_echo_struct
|
||||
{
|
||||
Ip_u16 id;
|
||||
Ip_u16 seq;
|
||||
Ip_u16 data[2];
|
||||
} echo;
|
||||
|
||||
IP_PACKED struct Iplite_pkt_icmp_data_failing_pkt_struct
|
||||
{
|
||||
Ip_u16 unused[2];
|
||||
Ip_u16 ip[10];
|
||||
Ip_u16 transport_hdr[4];
|
||||
} failing_pkt;
|
||||
|
||||
IP_PACKED struct Iplite_pkt_igmp_group_struct
|
||||
{
|
||||
Ip_u16 multicast_addr[2];
|
||||
} group;
|
||||
}
|
||||
data;
|
||||
}
|
||||
Iplite_pkt_icmp;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_ip4_param
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
typedef struct Iplite_ip4_param_struct
|
||||
{
|
||||
struct Ip_in_addr from;
|
||||
struct Ip_in_addr to;
|
||||
Ip_u32 ppchk; /* partial pseudo checksum. */
|
||||
Ip_u32 ifindex;
|
||||
int to_addr_type;
|
||||
Ip_u8 proto;
|
||||
Ip_u8 ttl;
|
||||
Ip_u8 tos;
|
||||
Ip_u8 is_gw;
|
||||
Ip_u32 mtu;
|
||||
Ip_u32 unused;
|
||||
}
|
||||
Iplite_ip4_param;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_ip4_socket
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
/* Multicast address joined by this socket */
|
||||
struct Iplite_ip4_socket_multicast_data
|
||||
{
|
||||
struct Iplite_ip4_socket_multicast_data *next;
|
||||
Iplite_netif *netif;
|
||||
struct Ip_in_addr addr;
|
||||
};
|
||||
|
||||
typedef struct Iplite_ip4_socket_struct
|
||||
{
|
||||
Iplite_ip4_param param; /* output cache */
|
||||
|
||||
Ip_u32 saddr_n; /* source IP address. */
|
||||
Ip_u32 daddr_n; /* destination IP address. */
|
||||
|
||||
Ip_u8 type_of_service;
|
||||
Ip_u8 pad[3];
|
||||
Ip_u32 multicast_if; /* Interface to use for outgoing mcast packets */
|
||||
|
||||
/* Multicast addresses joined on this socket */
|
||||
struct Iplite_ip4_socket_multicast_data *multicast_addr_list;
|
||||
}
|
||||
Iplite_ip4_socket;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_ip4_addr_entry
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef struct Iplite_ip4_addr_entry_struct
|
||||
{
|
||||
/* Next address in list */
|
||||
struct Iplite_ip4_addr_entry_struct *next;
|
||||
|
||||
/* Number of references to this address */
|
||||
int ref_count;
|
||||
|
||||
Ip_u32 ipaddr_n;
|
||||
Ip_u32 netmask_n;
|
||||
Ip_u32 netbrd_n;
|
||||
Ip_u32 subbrd_n;
|
||||
}
|
||||
Iplite_ip4_addr_entry;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_ip4_data
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef struct Iplite_ip4_data_struct
|
||||
{
|
||||
/* next IP packet output id. */
|
||||
Ip_u16 id;
|
||||
Ip_u16 pad;
|
||||
|
||||
/* Fragmentation reassembly list, the list is sorted on timeout (oldest first) */
|
||||
Ipcom_pkt *reassembly_list;
|
||||
|
||||
Ip_u32 default_gateway_n;
|
||||
}
|
||||
Iplite_ip4_data;
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_GLOBAL int iplite_ip4_get_addr_type(Iplite_netif *netif, Ip_u32 ipaddr_n);
|
||||
|
||||
IP_GLOBAL void iplite_ip4_input(Iplite_netif *netif, Ipcom_pkt *pkt);
|
||||
IP_GLOBAL int iplite_ip4_output(Iplite_netif *netif, Iplite_ip4_param *param, Ipcom_pkt *pkt);
|
||||
|
||||
IP_GLOBAL int iplite_ip4_sendto(struct Iplite_socket_struct *sock, IP_CONST struct Ip_sockaddr *to, Ipcom_pkt *pkt);
|
||||
IP_GLOBAL int iplite_ip4_add_addr(Iplite_netif *netif, Ip_u32 ipaddr_n, Ip_u32 netmask_n);
|
||||
IP_GLOBAL int iplite_ip4_remove_addr(Iplite_netif *netif, Ip_u32 ipaddr_n);
|
||||
IP_GLOBAL Ip_u32 iplite_ip4_get_mss(struct Iplite_socket_struct *sock);
|
||||
IP_GLOBAL Ip_u32 iplite_ip4_get_src_addr(Iplite_netif *netif, Ip_u32 dst_addr_n);
|
||||
|
||||
IP_GLOBAL Ip_u32 iplite_ip4_pseudo_header_checksum_update(Ip_u16 *src, Ip_u16 *dst, Ip_u16 proto, Ip_u16 len);
|
||||
IP_GLOBAL struct Iplite_socket_struct *iplite_ip4_socklookup(int proto, Ip_u32 *src_addr, Ip_u16 src_port_n, Ip_u32 *dst_addr, Ip_u16 dst_port_n, int *last);
|
||||
|
||||
IP_GLOBAL Iplite_netif *iplite_ip4_get_netif (Ip_u32 ipaddr_n, Ip_u8 *is_gw);
|
||||
IP_GLOBAL void iplite_ip4_kioevent(struct Iplite_netif_struct *netif, int command);
|
||||
|
||||
#ifdef IPLITE_USE_RFC3927
|
||||
IP_GLOBAL void iplite_ip4_init_lladdr(struct Iplite_netif_struct *netif);
|
||||
IP_GLOBAL Ip_bool iplite_ip4_has_unicast_addr(struct Iplite_netif_struct *netif);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,551 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK API HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_ip6.h,v $ $Revision: 1.15 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_ip6.h,v $
|
||||
* $Author: kenneth $ $Date: 2009-10-21 07:53:35 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPLITE_IP6_H
|
||||
#define IPLITE_IP6_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* Internal IPv6 header file.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_os.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPv6 macros (non-standard, use internally only)
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
/* Set address where the source and/or the destination might be on
|
||||
a word boundary */
|
||||
#define IPLITE_IP6_SET_ADDR(dst, src) ipcom_memcpy(dst, src, sizeof(struct Ip_in6_addr))
|
||||
|
||||
#define IPLITE_IP6_SCOPE_INVALID 0xff /* Invalid scope */
|
||||
#define IPLITE_IP6_SCOPE_NODE_LOCAL 0x1 /* Node local scope */
|
||||
#define IPLITE_IP6_SCOPE_LINK_LOCAL 0x2 /* Link local scope */
|
||||
#define IPLITE_IP6_SCOPE_SITE_LOCAL 0x5 /* Site local scope */
|
||||
#define IPLITE_IP6_SCOPE_ORG_LOCAL 0x8 /* Orginazation local scope */
|
||||
#define IPLITE_IP6_SCOPE_GLOBAL 0xe /* Global scope */
|
||||
|
||||
#define IPLITE_IP6_MC_SCOPE(mc_addr) (ip_ntohs((mc_addr)->in6.addr16[0]) & 0x000f)
|
||||
|
||||
#define IPLITE_IP6_IS_SCOPE_LINK_LOCAL(addr) \
|
||||
(IP_IN6_IS_ADDR_LINK_LOCAL(addr) || \
|
||||
(IP_IN6_IS_ADDR_MULTICAST(addr) && IPLITE_IP6_MC_SCOPE(addr) == IPLITE_IP6_SCOPE_LINK_LOCAL))
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* forward declarations
|
||||
*===========================================================================
|
||||
*/
|
||||
struct Iplite_socket_struct;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_ip6_nc_entry
|
||||
*===========================================================================
|
||||
* Neighbor Cache entry
|
||||
*/
|
||||
typedef struct Iplite_ip6_nc_entry_struct
|
||||
{
|
||||
/* Status of this cache entry */
|
||||
Ip_u16 status;
|
||||
|
||||
/* Number of unanswered probe messages */
|
||||
Ip_u16 unanswered_probes;
|
||||
|
||||
/* Does this entry correspond to a router or host */
|
||||
Ip_bool is_router;
|
||||
|
||||
/* Packet that is waiting for the next hop to be reachable */
|
||||
Ipcom_pkt *pending_pkt;
|
||||
|
||||
/* Next event */
|
||||
Ip_u32 next_timeout;
|
||||
struct Iplite_netif_struct *netif;
|
||||
struct Ip_in6_addr addr;
|
||||
Ip_u8 link_addr[6];
|
||||
struct Iplite_ip6_nc_entry_struct *next;
|
||||
}
|
||||
Iplite_ip6_nc_entry;
|
||||
|
||||
/* The possible states a entry can have in the ND cache */
|
||||
#define IPLITE_IP6_ND_UNINITIALIZED 0
|
||||
#define IPLITE_IP6_ND_INCOMPLETE 1
|
||||
#define IPLITE_IP6_ND_REACHABLE 2
|
||||
#define IPLITE_IP6_ND_STALE 3
|
||||
#define IPLITE_IP6_ND_DELAY 4
|
||||
#define IPLITE_IP6_ND_PROBE 5
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_ip6_dr_entry
|
||||
*===========================================================================
|
||||
* Default Router List
|
||||
*/
|
||||
typedef struct Iplite_ip6_dr_entry_struct
|
||||
{
|
||||
/* IP_TRUE if this entry is valid */
|
||||
Ip_bool is_set;
|
||||
|
||||
/* Time when this entry should be removed */
|
||||
Ip_u32 expires_sec;
|
||||
|
||||
/* IPv6 address of the router */
|
||||
struct Ip_in6_addr addr;
|
||||
}
|
||||
Iplite_ip6_dr_entry;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_ip6_addr_entry
|
||||
*===========================================================================
|
||||
* IPv6 address entry
|
||||
*/
|
||||
typedef struct Iplite_ip6_addr_entry_struct
|
||||
{
|
||||
/* Next address list */
|
||||
struct Iplite_ip6_addr_entry_struct *next;
|
||||
|
||||
/* Number of references to this address */
|
||||
Ip_u16 ref_count;
|
||||
|
||||
/* Address flags */
|
||||
Ip_u16 flags;
|
||||
|
||||
/* The IPv6 address */
|
||||
struct Ip_in6_addr addr;
|
||||
Ip_u8 prefix[16];
|
||||
|
||||
/* The address is a preferred address until this time is reached */
|
||||
Ip_u32 preferred_sec;
|
||||
|
||||
/* Time when the address expires */
|
||||
Ip_u32 expires_sec;
|
||||
|
||||
/* The address is valid after this tick (used in duplicate address resolution) */
|
||||
Ip_u32 valid_from;
|
||||
}
|
||||
Iplite_ip6_addr_entry;
|
||||
|
||||
#define IPLITE_IP6_ADDR_FLAG_TENTATIVE 0x0001 /* This address is a tentative address */
|
||||
#define IPLITE_IP6_ADDR_FLAG_AUTO 0x0002 /* This addresses has been automatically
|
||||
created using stateless address conf. */
|
||||
#define IPLITE_IP6_ADDR_FLAG_DONE 0x8000 /* Used internally when doing updates
|
||||
on several addresses, this flag tells
|
||||
that this address has been processed already */
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_ip6_data
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef struct Iplite_ip6_data_struct
|
||||
{
|
||||
/* ID of next fragmented packet */
|
||||
Ip_u32 id;
|
||||
|
||||
/* Fragmentation reassembly list, the list is sorted on timeout (oldest first) */
|
||||
Ipcom_pkt *reassembly_list;
|
||||
Ip_u32 last_sec;
|
||||
|
||||
struct Ip_in6_addr default_gateway;
|
||||
Ip_u32 default_scope_id;
|
||||
}
|
||||
Iplite_ip6_data;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_ip6_param
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef struct Iplite_ip6_param_struct
|
||||
{
|
||||
IP_CONST struct Ip_in6_addr *from;
|
||||
IP_CONST struct Ip_in6_addr *to;
|
||||
Ip_u8 nxt_hdr; /* The type of header that was last written */
|
||||
Ip_u8 hlim; /* The hoplimit */
|
||||
Ip_u8 pad;
|
||||
Ip_u8 is_gw; /* 1 if the final destination is off-link */
|
||||
|
||||
Ip_u32 flowinfo_n; /* The flowinfo value */
|
||||
Ip_u32 ifindex;
|
||||
}
|
||||
Iplite_ip6_param;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_ip6_socket
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
struct Iplite_ip6_socket_multicast_data
|
||||
{
|
||||
struct Iplite_ip6_socket_multicast_data *next;
|
||||
struct Iplite_netif_struct *netif;
|
||||
struct Ip_in6_addr addr;
|
||||
};
|
||||
|
||||
typedef struct Iplite_ip6_socket_struct
|
||||
{
|
||||
struct Ip_in6_addr saddr; /* source IP address */
|
||||
struct Ip_in6_addr daddr; /* destination IP address */
|
||||
Ip_u32 scope_id; /* Scope id (in host byte order) */
|
||||
Ip_u32 flowinfo_n; /* Flow information (in network byte order) */
|
||||
Ip_u32 multicast_if; /* Interface to use for outgoing packets */
|
||||
|
||||
struct Ip_in6_addr cached_to;
|
||||
Ip_u32 cached_ifindex;
|
||||
Ip_u8 cached_is_gw;
|
||||
Ip_u8 pad[3];
|
||||
Ip_bool is_cache_valid;
|
||||
|
||||
/* Multicast addresses joined by this socket */
|
||||
struct Iplite_ip6_socket_multicast_data *multicast_addr_list;
|
||||
}
|
||||
Iplite_ip6_socket;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_pkt_icmp6
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef IP_PACKED struct Iplite_pkt_icmp6_struct
|
||||
{
|
||||
Ip_u8 type; /* type field */
|
||||
Ip_u8 code; /* code field */
|
||||
Ip_u16 cksum; /* checksum field */
|
||||
|
||||
IP_PACKED union Iplite_pkt_icmp6_data_union
|
||||
{
|
||||
Ip_u32 d32[1]; /* type-specific field */
|
||||
Ip_u16 d16[2]; /* type-specific field */
|
||||
Ip_u8 d8[4]; /* type-specific field */
|
||||
} data;
|
||||
}
|
||||
Iplite_pkt_icmp6;
|
||||
|
||||
#define IPLITE_ICMPV6_HDR_SIZE 8
|
||||
|
||||
#define IPLITE_ICMP6_GET_TYPE(icmp6) (icmp6)->type
|
||||
#define IPLITE_ICMP6_SET_TYPE(icmp6,val) ((icmp6)->type = (Ip_u8) val)
|
||||
#define IPLITE_ICMP6_GET_CODE(icmp6) (icmp6)->code
|
||||
#define IPLITE_ICMP6_SET_CODE(icmp6,val) ((icmp6)->code = (Ip_u8) val)
|
||||
|
||||
/* Destination unreachable codes */
|
||||
#define IPLITE_ICMP6_DST_UNREACH_NOROUTE 0
|
||||
#define IPLITE_ICMP6_DST_UNREACH_ADMIN 1
|
||||
#define IPLITE_ICMP6_DST_UNREACH_BEYONDSCOPE 2
|
||||
#define IPLITE_ICMP6_DST_UNREACH_ADDR 3
|
||||
#define IPLITE_ICMP6_DST_UNREACH_NOPORT 4
|
||||
|
||||
/* Time Exceeded codes */
|
||||
#define IPLITE_ICMP6_TIME_EXCEEDED_HLIM 0
|
||||
#define IPLITE_ICMP6_TIME_EXCEEDED_FRAG 1
|
||||
|
||||
/* Parameter Problem codes */
|
||||
#define IPLITE_ICMP6_PARAM_PROB_ERR_HDR 0
|
||||
#define IPLITE_ICMP6_PARAM_PROB_NXT_HDR 1
|
||||
#define IPLITE_ICMP6_PARAM_PROB_OPT 2
|
||||
|
||||
/* ICMPv6 type field */
|
||||
#define IPLITE_ICMP6_TYPE_DST_UNREACHABLE 1
|
||||
#define IPLITE_ICMP6_TYPE_PACKET_TOO_BIG 2
|
||||
#define IPLITE_ICMP6_TYPE_TIME_EXCEEDED 3
|
||||
#define IPLITE_ICMP6_TYPE_PARAMETER_PROBLEM 4
|
||||
#define IPLITE_ICMP6_TYPE_ECHO_REQUEST 128
|
||||
#define IPLITE_ICMP6_TYPE_ECHO_REPLY 129
|
||||
#define IPLITE_ICMP6_TYPE_MLD_QUERY 130
|
||||
#define IPLITE_ICMP6_TYPE_MLD_REPORT 131
|
||||
#define IPLITE_ICMP6_TYPE_MLD_DONE 132
|
||||
#define IPLITE_ICMP6_TYPE_ROUTER_SOL 133
|
||||
#define IPLITE_ICMP6_TYPE_ROUTER_ADV 134
|
||||
#define IPLITE_ICMP6_TYPE_NEIGHBOR_SOL 135
|
||||
#define IPLITE_ICMP6_TYPE_NEIGHBOR_ADV 136
|
||||
#define IPLITE_ICMP6_TYPE_REDIRECT 137
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_pkt_icmp6_xxx
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
/* ICMPv6 Options Types */
|
||||
#define IPLITE_ICMP6_OPT_SOURCE_LINK_ADDR 1
|
||||
#define IPLITE_ICMP6_OPT_TARGET_LINK_ADDR 2
|
||||
#define IPLITE_ICMP6_OPT_PREFIX_INFO 3
|
||||
#define IPLITE_ICMP6_OPT_REDIRECT_HDR 4
|
||||
#define IPLITE_ICMP6_OPT_MTU 5
|
||||
|
||||
/* Extension Header Options */
|
||||
typedef IP_PACKED struct Iplite_pkt_icmp6_opt_struct
|
||||
{
|
||||
Ip_u8 type;
|
||||
Ip_u8 len;
|
||||
Ip_u8 data[1];
|
||||
}
|
||||
Iplite_pkt_icmp6_opt;
|
||||
|
||||
#define IPLITE_ICMP6_GET_OPT_TYPE(opt) ((opt)->type)
|
||||
#define IPLITE_ICMP6_SET_OPT_TYPE(opt,val) ((opt)->type = (Ip_u8) val)
|
||||
#define IPLITE_ICMP6_GET_OPT_LEN(opt) ((opt)->len)
|
||||
#define IPLITE_ICMP6_SET_OPT_LEN(opt,val) ((opt)->len = (Ip_u8) val)
|
||||
|
||||
/* Prefix Extension Header Options */
|
||||
typedef IP_PACKED struct Iplite_pkt_icmp6_prefix_opt_struct
|
||||
{
|
||||
Ip_u8 type;
|
||||
Ip_u8 len;
|
||||
Ip_u8 prefix_len;
|
||||
Ip_u8 flags;
|
||||
Ip_u32 valid_lifetime;
|
||||
Ip_u32 preferred_lifetime;
|
||||
Ip_u32 reserved2;
|
||||
struct Ip_in6_addr prefix;
|
||||
}
|
||||
Iplite_pkt_icmp6_prefix_opt;
|
||||
|
||||
#define IPLITE_ICMP6_GET_OPT_PREFIX_LEN(opt) ((opt)->prefix_len)
|
||||
#define IPLITE_ICMP6_GET_OPT_ON_LINK(opt) ((opt)->flags & 0x80)
|
||||
#define IPLITE_ICMP6_GET_OPT_AUTO_ADDR_CONF(opt) ((opt)->flags & 0x40)
|
||||
|
||||
/* Multicast Listener Discovery. */
|
||||
typedef IP_PACKED struct Iplite_pkt_icmp6_mld_struct
|
||||
{
|
||||
Iplite_pkt_icmp6 hdr;
|
||||
struct Ip_in6_addr addr;
|
||||
}
|
||||
Iplite_pkt_icmp6_mld;
|
||||
|
||||
/* Router Advertisement Message */
|
||||
typedef IP_PACKED struct Iplite_pkt_icmp6_nd_router_advert_struct
|
||||
{
|
||||
Iplite_pkt_icmp6 hdr;
|
||||
Ip_u32 reach_time; /* Reachable time. */
|
||||
Ip_u32 retrans_time; /* Retransmission time. */
|
||||
/* could be followed by options. */
|
||||
}
|
||||
Iplite_pkt_icmp6_nd_router_advert;
|
||||
|
||||
#define IPLITE_ICMP6_RA_GET_HLIM(ra) IP_GET_16HI8(ra->d16[0])
|
||||
#define IPLITE_ICMP6_RA_GET_MANAGE_FLAG(ra) (IP_GET_16LO8(ra->d16[0]) & 0x80)
|
||||
#define IPLITE_ICMP6_RA_GET_OTHER_FLAG(ra) (IP_GET_16LO8(ra->d16[0]) & 0x40)
|
||||
#define IPLITE_ICMP6_RA_GET_RLIFE(ra) (ra->hdr.data.d16[1])
|
||||
|
||||
/* Neighbor Solicit. */
|
||||
typedef IP_PACKED struct Iplite_pkt_icmp6_nd_neighbor_solicit_struct
|
||||
{
|
||||
Iplite_pkt_icmp6 hdr;
|
||||
struct Ip_in6_addr addr; /* target address. */
|
||||
|
||||
/* could be followed by options. */
|
||||
}
|
||||
Iplite_pkt_icmp6_nd_neighbor_solicit;
|
||||
|
||||
/* Neighbor Advertisment */
|
||||
typedef IP_PACKED struct Iplite_pkt_icmp6_nd_neighbor_advert_struct
|
||||
{
|
||||
Iplite_pkt_icmp6 hdr;
|
||||
struct Ip_in6_addr addr; /* target address. */
|
||||
|
||||
/* could be followed by options. */
|
||||
}
|
||||
Iplite_pkt_icmp6_nd_neighbor_advert;
|
||||
|
||||
#define IPLITE_ICMP6_IS_ROUTER(adv) \
|
||||
((adv)->hdr.data.d16[0] & ip_htons(0x8000))
|
||||
#define IPLITE_ICMP6_SET_SOLICATED_FLAG(adv) \
|
||||
(adv)->hdr.data.d16[0] |= ip_htons(0x4000)
|
||||
#define IPLITE_ICMP6_IS_SOLICATED(adv) \
|
||||
((adv)->hdr.data.d16[0] & ip_htons(0x4000))
|
||||
#define IPLITE_ICMP6_SET_OVERRIDE_FLAG(adv) \
|
||||
(adv)->hdr.data.d16[0] |= ip_htons(0x2000)
|
||||
#define IPLITE_ICMP6_IS_OVERRIDE(adv) \
|
||||
((adv)->hdr.data.d16[0] & ip_htons(0x2000))
|
||||
|
||||
/* Redirect */
|
||||
typedef IP_PACKED struct Iplite_pkt_icmp6_nd_redirect_struct
|
||||
{
|
||||
Iplite_pkt_icmp6 hdr;
|
||||
struct Ip_in6_addr target_addr; /* Address of better first hop */
|
||||
struct Ip_in6_addr dst_addr; /* Address of the final host */
|
||||
|
||||
/* could be followed by options. */
|
||||
}
|
||||
Iplite_pkt_icmp6_nd_redirect;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_pkt_ip6_xxx
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
/* Generic Extension Header */
|
||||
typedef IP_PACKED struct Iplite_pkt_ip6_ext_hdr_struct
|
||||
{
|
||||
/* Next header field */
|
||||
Ip_u8 nxt;
|
||||
/* Length of of extension in 8-octets units,
|
||||
not counting the first 8-octets */
|
||||
Ip_u8 len;
|
||||
}
|
||||
Iplite_pkt_ip6_ext_hdr;
|
||||
|
||||
/* Generic Option Header */
|
||||
typedef IP_PACKED struct Iplite_pkt_ip6_ext_opt_struct
|
||||
{
|
||||
/* The option type */
|
||||
Ip_u8 type;
|
||||
/* Length of of extension in 8-octets units,
|
||||
not counting the first 8-octets */
|
||||
Ip_u8 len;
|
||||
}
|
||||
Iplite_pkt_ip6_ext_opt;
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_pkt_ip6
|
||||
*===========================================================================
|
||||
* 40 bytes large IPv6 packet header.
|
||||
*/
|
||||
typedef IP_PACKED struct Iplite_pkt_ip6_struct
|
||||
{
|
||||
Ip_u32 ver_class_flow; /* 4 bit version, 8 bit class, 20 bit flow. */
|
||||
Ip_u16 plen; /* Payload length. */
|
||||
Ip_u8 nxt; /* Next Header. */
|
||||
Ip_u8 hlim; /* Hop limit. */
|
||||
|
||||
struct Ip_in6_addr src; /* IPv6 source address. */
|
||||
struct Ip_in6_addr dst; /* IPv6 destination address. */
|
||||
}
|
||||
Iplite_pkt_ip6;
|
||||
|
||||
#define IPLITE_IP6_HDR_SIZE 40 /* IPv6 header is 40 octes long */
|
||||
|
||||
#define IPLITE_IP6_GET_NXT(ip6) (ip6)->nxt
|
||||
#define IPLITE_IP6_SET_NXT(ip6,val) ((ip6)->nxt = (Ip_u8) val)
|
||||
#define IPLITE_IP6_GET_HLIM(ip6) (ip6)->hlim
|
||||
#define IPLITE_IP6_SET_HLIM(ip6,val) ((ip6)->hlim = (Ip_u8) val)
|
||||
|
||||
#define IPLITE_IP6_GET_FLOW(ip6) (ip_ntohl(IP_GET_32ON16(&ip6->ver_class_flow)) & 0xfffff)
|
||||
|
||||
/* IPv6 payload types */
|
||||
#define IPLITE_IP6_HDR_HOP_BY_HOP_OPT 0
|
||||
#define IPLITE_IP6_HDR_ICMP4 1
|
||||
#define IPLITE_IP6_HDR_IPIP 4
|
||||
#define IPLITE_IP6_HDR_TCP 6
|
||||
#define IPLITE_IP6_HDR_UDP 17
|
||||
#define IPLITE_IP6_HDR_ROUTING 43
|
||||
#define IPLITE_IP6_HDR_FRAGMENT 44
|
||||
#define IPLITE_IP6_HDR_ESP 50
|
||||
#define IPLITE_IP6_HDR_AH 51
|
||||
#define IPLITE_IP6_HDR_ICMP6 58
|
||||
#define IPLITE_IP6_HDR_NO_NEXT 59
|
||||
#define IPLITE_IP6_HDR_DST_OPT 60
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_GLOBAL void iplite_ip6_tick(void);
|
||||
|
||||
IP_GLOBAL int iplite_ip6_get_addr_type(struct Iplite_netif_struct *netif, IP_CONST struct Ip_in6_addr *in6_addr);
|
||||
|
||||
IP_GLOBAL void iplite_ip6_input(struct Iplite_netif_struct *netif, Ipcom_pkt *pkt);
|
||||
IP_GLOBAL int iplite_ip6_output(struct Iplite_netif_struct *netif, Iplite_ip6_param *param, Ipcom_pkt *pkt);
|
||||
|
||||
IP_GLOBAL int iplite_ip6_sendto(struct Iplite_socket_struct *sock, IP_CONST struct Ip_sockaddr *to, Ipcom_pkt *pkt);
|
||||
IP_GLOBAL Ip_u32 iplite_ip6_get_mss(struct Iplite_socket_struct *sock);
|
||||
IP_GLOBAL IP_CONST struct Ip_in6_addr *
|
||||
iplite_ip6_get_src_addr(struct Iplite_netif_struct *netif, IP_CONST struct Ip_in6_addr *dst_addr, int scope);
|
||||
|
||||
IP_GLOBAL Ip_u32 iplite_ip6_pseudo_header_checksum_update(IP_CONST struct Ip_in6_addr *src,
|
||||
IP_CONST struct Ip_in6_addr *dst, Ip_u16 proto, Ip_u16 len);
|
||||
IP_GLOBAL struct Iplite_socket_struct* iplite_ip6_socklookup(int proto, struct Ip_in6_addr *src_addr, Ip_u16 src_port_n,
|
||||
struct Ip_in6_addr *dst_addr, Ip_u16 dst_port_n, int *last);
|
||||
IP_GLOBAL int iplite_ip6_add_addr(struct Iplite_netif_struct *netif, IP_CONST struct Ip_in6_addr *addr, IP_CONST int prefix, int flags, Ip_u32 preferred, Ip_u32 valid);
|
||||
IP_GLOBAL int iplite_ip6_remove_addr(struct Iplite_netif_struct *netif, struct Ip_in6_addr *in6_addr);
|
||||
IP_GLOBAL void iplite_ip6_create_mapped_addr(struct Ip_in_addr *ipv4_addr, struct Ip_in6_addr *ipv4_mapped_ipv6_addr);
|
||||
|
||||
IP_GLOBAL Iplite_ip6_nc_entry *iplite_ip6_neighbor_cache_find(struct Iplite_netif_struct *netif, IP_CONST struct Ip_in6_addr *in6_addr);
|
||||
IP_GLOBAL void iplite_ip6_neighbor_cache_update(Iplite_ip6_nc_entry *neighbor, int status, IP_CONST void *link_addr);
|
||||
IP_GLOBAL int iplite_ip6_prefix_add(struct Iplite_netif_struct *netif, struct Ip_in6_addr *prefix,
|
||||
int bits, Ip_u32 expires);
|
||||
IP_GLOBAL Ip_bool iplite_ip6_is_scoped_addr(IP_CONST struct Ip_in6_addr *in6_addr);
|
||||
IP_GLOBAL struct Iplite_netif_struct *
|
||||
iplite_ip6_get_netif(Ip_u32 scope_id, IP_CONST struct Ip_in6_addr *to, Ip_u8 *is_gw, Ip_bool top);
|
||||
IP_GLOBAL void iplite_ip6_kioevent(struct Iplite_netif_struct *netif, int command);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,975 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_ip_forward_mib.c,v $ $Revision: 1.12 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_ip_forward_mib.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Markus Carlstedt <markus@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IP-FORWARD-MIB
|
||||
*===========================================================================
|
||||
*
|
||||
* Autogenerated by 'ipmibc' with 'smidump 0.4.1' on 2003-11-25 at 14:50:41
|
||||
*
|
||||
* This file includes initialization code and stubs for all MIB variables in
|
||||
* IP-FORWARD-MIB. Without any changes it should compile and run with the
|
||||
* behaviour that GetRequests succeed with the returned value being
|
||||
* zero. SetRequests also succeed but without any actual variables
|
||||
* being updated.
|
||||
*
|
||||
* Modifications to this file are necessary in order to enable read and
|
||||
* write operations on actual variables presented in the MIB interface.
|
||||
* Each segment in the code where a change is proposed is marked with a
|
||||
* 'MIB_TODO' comment together with a pseudo code example describing the
|
||||
* modification.
|
||||
*
|
||||
* This file shall normally be compiled together with the product to which
|
||||
* SNMP support is to be added and then linked with the IPSNMP libraries.
|
||||
* The MIB is initialized by calling the public initialization function defined
|
||||
* at the end of this file. Since no header files are generated its function
|
||||
* prototype should be copied into the the product that initializes the MIB.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_err.h>
|
||||
|
||||
#ifdef IPSNMP
|
||||
#include <ipsnmp_config.h>
|
||||
#include <ipsnmp.h>
|
||||
#include <iplite_h.h>
|
||||
#include <iplite_loopback.h>
|
||||
|
||||
#if defined(IPCOM_USE_MIB2) && defined(IPCOM_USE_INET)
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_SYSLOG_FACILITY
|
||||
#undef IPCOM_SYSLOG_FACILITY
|
||||
#endif
|
||||
#define IPCOM_SYSLOG_FACILITY IPCOM_LOG_IPSNMP
|
||||
|
||||
#ifdef IPCOM_SYSLOG_PRIORITY
|
||||
#undef IPCOM_SYSLOG_PRIORITY
|
||||
#endif
|
||||
#define IPCOM_SYSLOG_PRIORITY IPCOM_LOG_DEBUG
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERNAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC Ip_err iplite_ip_forward_mib_init(void);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC struct Iplite_ip4_addr_entry_struct *bestaddr;
|
||||
IP_STATIC struct Iplite_ip4_addr_entry_struct default_gw;
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ip_forward_mib_lock
|
||||
*===========================================================================
|
||||
* Description: Protects MIB variables in SNMPv2-MIB from multiple access
|
||||
* Parameters: lock - boolean that controls lock or unlock
|
||||
* Returns: Nothing
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
iplite_ip_forward_mib_lock(Ip_bool lock)
|
||||
{
|
||||
if(lock == IP_TRUE)
|
||||
{
|
||||
IPLITE_CODE_LOCK();
|
||||
}
|
||||
else
|
||||
{
|
||||
IPLITE_CODE_UNLOCK();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ip_forward_mib_table_search_ipCidrRouteTable
|
||||
*===========================================================================
|
||||
* Description: Searches ipCidrRouteTable for a matching entry
|
||||
* Parameters: id, buf, best, cmd
|
||||
* Returns: Row index of the found entry OR -1 if not found OR -2 for error
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_s32
|
||||
iplite_ip_forward_mib_table_search_ipCidrRouteTable(char *id,
|
||||
char *buf,
|
||||
char *best,
|
||||
Ip_s32 cmd)
|
||||
{
|
||||
Ip_s32 i, len, lex, count = 0, bestindex = -1;
|
||||
Ip_u32 net_n;
|
||||
|
||||
bestaddr = IP_NULL;
|
||||
for (i = 1; i < IPLITE_CONF_MAX_NETIF; i++)
|
||||
{
|
||||
struct Iplite_ip4_addr_entry_struct *addr4;
|
||||
|
||||
buf[0] = '\0';
|
||||
|
||||
if(iplite.netifs[i] == IP_NULL ||
|
||||
iplite.netifs[i]->ipcom.ifindex == IPLITE_IF_LOOPBACK_INDEX)
|
||||
continue;
|
||||
|
||||
addr4 = iplite.netifs[i]->inet4_addr_list;
|
||||
if(addr4 != IP_NULL
|
||||
&& count == 0
|
||||
&& iplite.ip4.default_gateway_n != 0)
|
||||
{
|
||||
count = 1;
|
||||
default_gw.ipaddr_n = 0;
|
||||
default_gw.netmask_n = 0;
|
||||
default_gw.next = iplite.netifs[i]->inet4_addr_list;
|
||||
addr4 = &default_gw;
|
||||
}
|
||||
|
||||
while(addr4 != IP_NULL)
|
||||
{
|
||||
if(!IP_IN_CLASSD(addr4->ipaddr_n) && addr4->ipaddr_n != IP_INADDR_BROADCAST)
|
||||
{
|
||||
net_n = addr4->ipaddr_n & addr4->netmask_n;
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &net_n, buf, IPSNMP_CONFIG_MAX_OBJECT_ID);
|
||||
len = ipcom_strlen(buf);
|
||||
buf[len++] = '.';
|
||||
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &addr4->netmask_n, &buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID - len);
|
||||
len = ipcom_strlen(buf);
|
||||
|
||||
ipcom_sprintf(&buf[len], ".%d.", 0); /* TOS */
|
||||
len = ipcom_strlen(buf);
|
||||
|
||||
if(addr4->ipaddr_n == 0)
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &iplite.ip4.default_gateway_n, &buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID - len);
|
||||
else
|
||||
ipcom_strcpy(&buf[len], "0.0.0.0");
|
||||
|
||||
lex = ipsnmp_util_lexcmp_oid(buf, id);
|
||||
if(cmd == IPSNMP_MIB_COMMAND_NEXT)
|
||||
{
|
||||
if(lex > 0)
|
||||
{
|
||||
if(bestindex == -1 || ipsnmp_util_lexcmp_oid(buf, best) < 0)
|
||||
{
|
||||
ipcom_strcpy(best, buf);
|
||||
bestindex = i;
|
||||
bestaddr = addr4;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(lex == 0)
|
||||
{
|
||||
ipcom_strcpy(best, buf);
|
||||
bestindex = i;
|
||||
bestaddr = addr4;
|
||||
i = IPLITE_CONF_MAX_NETIF; /* Exit outer loop */
|
||||
break; /* Exit inner loop */
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addr4 = addr4->next;
|
||||
}
|
||||
}
|
||||
|
||||
return bestindex;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ip_forward_mib_handler_ipCidrRouteNumber
|
||||
*===========================================================================
|
||||
* Description: MIB handler for ipCidrRouteNumber
|
||||
* Parameters: See file 'ipsnmp.h'
|
||||
* Returns: IPSNMP_ERROR_XXX
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_s32
|
||||
iplite_ip_forward_mib_handler_ipCidrRouteNumber(Ip_s32 cmd,
|
||||
char *id,
|
||||
Ipsnmp_varbind *vb,
|
||||
Ip_s32 magic,
|
||||
struct Ipsnmp_node_object *nodeobj)
|
||||
{
|
||||
Ip_s32 i, ret = -1;
|
||||
Ip_u32 ipCidrRouteNumber = 0;
|
||||
char *iid;
|
||||
|
||||
(void)id;
|
||||
(void)vb;
|
||||
if(cmd == IPSNMP_MIB_COMMAND_GET || cmd == IPSNMP_MIB_COMMAND_NEXT)
|
||||
{
|
||||
iid = ipsnmp_create_iid_integer(nodeobj->id, 0);
|
||||
if(iid == IP_NULL)
|
||||
return IPSNMP_ERROR_GENERROR;
|
||||
|
||||
for (i = 0; i < IPLITE_CONF_MAX_NETIF; i++)
|
||||
{
|
||||
struct Iplite_ip4_addr_entry_struct *addr4;
|
||||
|
||||
if(iplite.netifs[i] == IP_NULL ||
|
||||
iplite.netifs[i]->ipcom.ifindex == IPLITE_IF_LOOPBACK_INDEX)
|
||||
continue;
|
||||
|
||||
addr4 = iplite.netifs[i]->inet4_addr_list;
|
||||
|
||||
if(addr4 != IP_NULL
|
||||
&& ipCidrRouteNumber == 0
|
||||
&& iplite.ip4.default_gateway_n != 0)
|
||||
{
|
||||
ipCidrRouteNumber = 1; /* Default gateway */
|
||||
}
|
||||
|
||||
while(addr4 != IP_NULL)
|
||||
{
|
||||
if(!IP_IN_CLASSD(addr4->ipaddr_n) && addr4->ipaddr_n != IP_INADDR_BROADCAST)
|
||||
ipCidrRouteNumber++; /* Network route */
|
||||
addr4 = addr4->next;
|
||||
}
|
||||
}
|
||||
|
||||
ret = ipsnmp_util_put_gauge32(magic, iid, ipCidrRouteNumber);
|
||||
ipcom_free(iid);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ip_forward_mib_handler_ipCidrRouteTable
|
||||
*===========================================================================
|
||||
* Description: MIB handler for ipCidrRouteDest
|
||||
* Parameters: See file 'ipsnmp.h'
|
||||
* Returns: IPSNMP_ERROR_XXX
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_s32
|
||||
iplite_ip_forward_mib_handler_ipCidrRouteTable(Ip_s32 cmd,
|
||||
char *id,
|
||||
Ipsnmp_varbind *vb,
|
||||
Ip_s32 magic,
|
||||
struct Ipsnmp_node_object *nodeobj)
|
||||
{
|
||||
Ip_s32 lid, bestindex, ret = -1;
|
||||
Ip_u32 net_n;
|
||||
char *iid;
|
||||
char *buf = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID);
|
||||
char *best = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID);
|
||||
|
||||
if(buf == IP_NULL || best == IP_NULL)
|
||||
{
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
lid = ipsnmp_util_last_subid(nodeobj->id);
|
||||
ip_assert(lid >= 1 && lid <= 16);
|
||||
bestindex = iplite_ip_forward_mib_table_search_ipCidrRouteTable(id, buf, best, cmd);
|
||||
if(bestindex == -2)
|
||||
{
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
goto exit;
|
||||
}
|
||||
else if(bestindex == -1)
|
||||
{
|
||||
ret = IPSNMP_ERROR_NOSUCHNAME;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(cmd == IPSNMP_MIB_COMMAND_GET || cmd == IPSNMP_MIB_COMMAND_NEXT)
|
||||
{
|
||||
iid = ipsnmp_create_iid_direct(nodeobj->id, best);
|
||||
if(iid == IP_NULL)
|
||||
{
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ip_assert(bestaddr != IP_NULL);
|
||||
switch(lid)
|
||||
{
|
||||
case 1: /* ipCidrRouteDest */
|
||||
net_n = bestaddr->ipaddr_n & bestaddr->netmask_n;
|
||||
ret = ipsnmp_util_put_ipaddress(magic, iid, ip_ntohl(net_n));
|
||||
break;
|
||||
case 2: /* ipCidrRouteMask */
|
||||
ret = ipsnmp_util_put_ipaddress(magic, iid, ip_ntohl(bestaddr->netmask_n));
|
||||
break;
|
||||
case 3: /* ipCidrRouteTos */
|
||||
ret = ipsnmp_util_put_integer(magic, iid, 0);
|
||||
break;
|
||||
case 4: /* ipCidrRouteNextHop */
|
||||
if(bestaddr->ipaddr_n == 0)
|
||||
ret = ipsnmp_util_put_ipaddress(magic, iid, ip_ntohl(iplite.ip4.default_gateway_n));
|
||||
else
|
||||
ret = ipsnmp_util_put_ipaddress(magic, iid, 0);
|
||||
break;
|
||||
case 5: /* ipCidrRouteIfIndex */
|
||||
ret = ipsnmp_util_put_integer(magic, iid, iplite.netifs[bestindex]->ipcom.ifindex);
|
||||
break;
|
||||
case 6: /* ipCidrRouteType */
|
||||
if(bestaddr->ipaddr_n == 0)
|
||||
ret = ipsnmp_util_put_integer(magic, iid, 4); /* indirect */
|
||||
else
|
||||
ret = ipsnmp_util_put_integer(magic, iid, 3); /* direct */
|
||||
break;
|
||||
case 7: /* ipCidrRouteProto */
|
||||
ret = ipsnmp_util_put_integer(magic, iid, 2); /* local */
|
||||
break;
|
||||
case 8: /* ipCidrRouteAge */
|
||||
ret = ipsnmp_util_put_integer(magic, iid, 0);
|
||||
break;
|
||||
case 9: /* ipCidrRouteInfo */
|
||||
ret = ipsnmp_util_put_oid(magic, iid, "0.0");
|
||||
break;
|
||||
case 10: /* ipCidrRouteNextHopAS */
|
||||
ret = ipsnmp_util_put_integer(magic, iid, 0);
|
||||
break;
|
||||
case 11: /* ipCidrRouteMetric1 */
|
||||
ret = ipsnmp_util_put_integer(magic, iid, -1);
|
||||
break;
|
||||
case 12: /* ipCidrRouteMetric2 */
|
||||
ret = ipsnmp_util_put_integer(magic, iid, -1);
|
||||
break;
|
||||
case 13: /* ipCidrRouteMetric3 */
|
||||
ret = ipsnmp_util_put_integer(magic, iid, -1);
|
||||
break;
|
||||
case 14: /* ipCidrRouteMetric4 */
|
||||
ret = ipsnmp_util_put_integer(magic, iid, -1);
|
||||
break;
|
||||
case 15: /* ipCidrRouteMetric5 */
|
||||
ret = ipsnmp_util_put_integer(magic, iid, -1);
|
||||
break;
|
||||
case 16: /* ipCidrRouteStatus */
|
||||
ret = ipsnmp_util_put_integer(magic, iid, 1); /* active */
|
||||
break;
|
||||
default:
|
||||
IP_PANIC();
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
ipcom_free(iid);
|
||||
}
|
||||
|
||||
if(cmd == IPSNMP_MIB_COMMAND_TEST || cmd == IPSNMP_MIB_COMMAND_SET)
|
||||
{
|
||||
(void)vb;
|
||||
switch(lid)
|
||||
{
|
||||
case 5: /* ipCidrRouteIfIndex */
|
||||
case 6: /* ipCidrRouteType */
|
||||
case 9: /* ipCidrRouteInfo */
|
||||
case 10: /* ipCidrRouteNextHopAS */
|
||||
case 11: /* ipCidrRouteMetric1 */
|
||||
case 12: /* ipCidrRouteMetric2 */
|
||||
case 13: /* ipCidrRouteMetric3 */
|
||||
case 14: /* ipCidrRouteMetric4 */
|
||||
case 15: /* ipCidrRouteMetric5 */
|
||||
case 16: /* ipCidrRouteStatus */
|
||||
ret = IPSNMP_ERROR_NOSUCHNAME;
|
||||
break;
|
||||
default:
|
||||
IP_PANIC();
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
if(buf != IP_NULL)
|
||||
ipcom_free(buf);
|
||||
if(best != IP_NULL)
|
||||
ipcom_free(best);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ip_forward_mib_init
|
||||
*===========================================================================
|
||||
* Description: Initializes IP-FORWARD-MIB
|
||||
* Parameters: None
|
||||
* Returns: IPCOM_SUCCESS or IPCOM_ERR_FAILED
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
iplite_ip_forward_mib_init(void)
|
||||
{
|
||||
struct Ipsnmp_node_object nodeobj;
|
||||
Ip_s32 ret;
|
||||
|
||||
/* Assign lock function */
|
||||
nodeobj.lock = iplite_ip_forward_mib_lock;
|
||||
|
||||
/* Add node "ipForward" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipForward";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_OTHER;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipForwardConformance" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.5";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipForwardConformance";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_OTHER;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipForwardGroups" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.5.1";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipForwardGroups";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_OTHER;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipForwardCompliances" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.5.2";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipForwardCompliances";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_OTHER;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteNumber" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_GAUGE32;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteNumber;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.3";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteNumber";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_SCALAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteTable" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteTable";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_AGGREGATE;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteEntry" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteEntry";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_AGGREGATE;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteDest" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_IPADDRESS;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.1";
|
||||
/* nodeobj.instance = IP_NULL; */
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteDest";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteMask" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_IPADDRESS;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.2";
|
||||
/* nodeobj.instance = IP_NULL; */
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteMask";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteTos" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.3";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteTos";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteNextHop" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_IPADDRESS;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.4";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteNextHop";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteIfIndex" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READCREATE;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.5";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteIfIndex";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteType" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READCREATE;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.6";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteType";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteProto" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.7";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteProto";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteAge" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.8";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteAge";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteInfo" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READCREATE;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_OID;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.9";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteInfo";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteNextHopAS" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READCREATE;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.10";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteNextHopAS";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteMetric1" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READCREATE;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.11";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteMetric1";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteMetric2" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READCREATE;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.12";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteMetric2";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteMetric3" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READCREATE;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.13";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteMetric3";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteMetric4" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READCREATE;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.14";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteMetric4";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteMetric5" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READCREATE;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.15";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteMetric5";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipCidrRouteStatus" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READCREATE;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ip_forward_mib_handler_ipCidrRouteTable;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.4.1.16";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipCidrRouteStatus";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipForwardMultiPathGroup" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.5.1.2";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipForwardMultiPathGroup";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_OTHER;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipForwardCidrRouteGroup" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.5.1.3";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipForwardCidrRouteGroup";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_OTHER;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipForwardCompliance" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.5.2.1";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipForwardCompliance";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_OTHER;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipForwardOldCompliance" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.4.24.5.2.2";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipForwardOldCompliance";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_OTHER;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
return IPCOM_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* #if defined(IPCOM_USE_MIB2) && defined(IPCOM_USE_INET) */
|
||||
#endif /* #ifdef IPSNMP */
|
||||
|
||||
#if !defined(IPSNMP) || !defined(IPCOM_USE_MIB2)
|
||||
void iplite_ip_forward_mib_empty_file(void);
|
||||
void iplite_ip_forward_mib_empty_file(void) { }
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,479 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_ipv6_udp_mib.c,v $ $Revision: 1.12 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_ipv6_udp_mib.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Markus Carlstedt <markus@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPV6-UDP-MIB
|
||||
*===========================================================================
|
||||
*
|
||||
* Autogenerated by 'ipmibc' with 'smidump 0.4.1' on 2003-11-21 at 13:57:50
|
||||
*
|
||||
* This file includes initialization code and stubs for MIB variables defined
|
||||
* in IPV6-UDP-MIB. Without any changes it should compile and run with the
|
||||
* behaviour that GetRequests succeed with the returned value being
|
||||
* zero. SetRequests also succeed but without any actual variables
|
||||
* being updated.
|
||||
*
|
||||
* Modifications to this file are necessary in order to enable read and
|
||||
* write operations on actual variables presented in the MIB interface.
|
||||
* Each segment in the code where a change is proposed is marked with a
|
||||
* 'MIB_TODO' comment together with a pseudo code example describing the
|
||||
* modification.
|
||||
*
|
||||
* This file shall normally be compiled together with the product to which
|
||||
* SNMP support is to be added and then linked with the IPSNMP libraries.
|
||||
* The MIB is initialized by calling the public initialization function defined
|
||||
* at the end of this file. Since no header files are generated its function
|
||||
* prototype should be copied into the the product that initializes the MIB.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_err.h>
|
||||
|
||||
#ifdef IPSNMP
|
||||
#include <ipsnmp_config.h>
|
||||
#include <ipsnmp.h>
|
||||
#include <iplite_h.h>
|
||||
|
||||
#if defined(IPCOM_USE_MIB2) && defined(IPCOM_USE_INET6)
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_SYSLOG_FACILITY
|
||||
#undef IPCOM_SYSLOG_FACILITY
|
||||
#endif
|
||||
#define IPCOM_SYSLOG_FACILITY IPCOM_LOG_IPSNMP
|
||||
|
||||
#ifdef IPCOM_SYSLOG_PRIORITY
|
||||
#undef IPCOM_SYSLOG_PRIORITY
|
||||
#endif
|
||||
#define IPCOM_SYSLOG_PRIORITY IPCOM_LOG_DEBUG
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERNAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC Ip_err iplite_ipv6_udp_mib_init(void);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ipv6_udp_mib_lock
|
||||
*===========================================================================
|
||||
* Description: Protects MIB variables in SNMPv2-MIB from multiple access
|
||||
* Parameters: lock - boolean that controls lock or unlock
|
||||
* Returns: Nothing
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
iplite_ipv6_udp_mib_lock(Ip_bool lock)
|
||||
{
|
||||
if(lock == IP_TRUE)
|
||||
{
|
||||
IPLITE_CODE_LOCK();
|
||||
}
|
||||
else
|
||||
{
|
||||
IPLITE_CODE_UNLOCK();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ipv6_udp_mib_table_search_ipv6UdpTable
|
||||
*===========================================================================
|
||||
* Description: Searches ipv6UdpTable for a matching entry
|
||||
* Parameters: id, buf, best, cmd
|
||||
* Returns: Row index of the found entry OR -1 if not found OR -2 for error
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_s32
|
||||
iplite_ipv6_udp_mib_table_search_ipv6UdpTable(char *id,
|
||||
char *buf,
|
||||
char *best,
|
||||
Ip_s32 cmd)
|
||||
{
|
||||
Ip_u8 *ipv6UdpLocalAddress;
|
||||
Ip_s32 ipv6UdpLocalAddress_len;
|
||||
Ip_s32 ipv6UdpLocalPort;
|
||||
Ip_s32 ipv6UdpIfIndex;
|
||||
Ip_s32 ipv6UdpTable_num_entries;
|
||||
Ip_s32 i, bestindex = -1;
|
||||
Iplite_netif *netif;
|
||||
|
||||
ipv6UdpTable_num_entries = IPLITE_CONF_MAX_SOCKETS;
|
||||
|
||||
for(i=0; i<ipv6UdpTable_num_entries; i++)
|
||||
{
|
||||
Ip_s32 j, lex, len = 0;
|
||||
|
||||
buf[0] = '\0';
|
||||
|
||||
if (iplite.sockets[i] == IP_NULL || iplite.sockets[i]->ipcom.domain != IP_AF_INET6
|
||||
|| iplite.sockets[i]->ipcom.type != IP_SOCK_DGRAM || iplite.sockets[i]->proto != IP_IPPROTO_UDP
|
||||
|| !IP_BIT_ISSET(iplite.sockets[i]->flags, IPLITE_SOCKET_FLAG_BOUND))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ipv6UdpLocalAddress = iplite.sockets[i]->d->ip6.saddr.in6.addr8;
|
||||
ipv6UdpLocalAddress_len = 16;
|
||||
|
||||
for(j=0; j<ipv6UdpLocalAddress_len; j++)
|
||||
{
|
||||
if(ipcom_snprintf(&buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, "%d.", ipv6UdpLocalAddress[j]) < 0)
|
||||
return -2;
|
||||
len = ipcom_strlen(buf);
|
||||
}
|
||||
len = ipcom_strlen(buf);
|
||||
|
||||
ipv6UdpLocalPort = iplite.sockets[i]->sport;
|
||||
|
||||
if(ipcom_snprintf(&buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, "%d.", (int)ipv6UdpLocalPort) < 0)
|
||||
return -2;
|
||||
len = ipcom_strlen(buf);
|
||||
|
||||
netif = iplite_ip6_addr_to_netif(&iplite.sockets[i]->d->ip6.saddr);
|
||||
ipv6UdpIfIndex = netif == IP_NULL ? 0 : netif->ipcom.ifindex;
|
||||
|
||||
if(ipcom_snprintf(&buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, "%d.", (int)ipv6UdpIfIndex) < 0)
|
||||
return -2;
|
||||
len = ipcom_strlen(buf);
|
||||
if(len)
|
||||
buf[len-1] = '\0';
|
||||
|
||||
lex = ipsnmp_util_lexcmp_oid(buf, id);
|
||||
if(cmd == IPSNMP_MIB_COMMAND_NEXT)
|
||||
{
|
||||
if(lex > 0)
|
||||
{
|
||||
if(bestindex == -1 || ipsnmp_util_lexcmp_oid(buf, best) < 0)
|
||||
{
|
||||
ipcom_strcpy(best, buf);
|
||||
bestindex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(lex == 0)
|
||||
{
|
||||
ipcom_strcpy(best, buf);
|
||||
bestindex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bestindex;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ipv6_udp_mib_handler_ipv6UdpIfIndex
|
||||
*===========================================================================
|
||||
* Description: MIB handler for ipv6UdpIfIndex
|
||||
* Parameters: See file 'ipsnmp.h'
|
||||
* Returns: IPSNMP_ERROR_XXX
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_s32
|
||||
iplite_ipv6_udp_mib_handler_ipv6UdpIfIndex(Ip_s32 cmd,
|
||||
char *id,
|
||||
Ipsnmp_varbind *vb,
|
||||
Ip_s32 magic,
|
||||
struct Ipsnmp_node_object *nodeobj)
|
||||
{
|
||||
Ip_s32 bestindex, ret = -1;
|
||||
Ip_s32 ipv6UdpIfIndex;
|
||||
char *iid;
|
||||
char *buf = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID);
|
||||
char *best = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID);
|
||||
Iplite_netif *netif;
|
||||
|
||||
(void)vb;
|
||||
if(buf == IP_NULL || best == IP_NULL)
|
||||
{
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
bestindex = iplite_ipv6_udp_mib_table_search_ipv6UdpTable(id, buf, best, cmd);
|
||||
if(bestindex == -2)
|
||||
{
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
goto exit;
|
||||
}
|
||||
else if(bestindex == -1)
|
||||
{
|
||||
ret = IPSNMP_ERROR_NOSUCHNAME;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(cmd == IPSNMP_MIB_COMMAND_GET || cmd == IPSNMP_MIB_COMMAND_NEXT)
|
||||
{
|
||||
iid = ipsnmp_create_iid_direct(nodeobj->id, best);
|
||||
if(iid == IP_NULL)
|
||||
{
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
netif = iplite_ip6_addr_to_netif(&iplite.sockets[bestindex]->d->ip6.saddr);
|
||||
ipv6UdpIfIndex = netif == IP_NULL ? 0 : netif->ipcom.ifindex;
|
||||
|
||||
ret = ipsnmp_util_put_integer(magic, iid, ipv6UdpIfIndex);
|
||||
ipcom_free(iid);
|
||||
}
|
||||
|
||||
exit:
|
||||
if(buf != IP_NULL)
|
||||
ipcom_free(buf);
|
||||
if(best != IP_NULL)
|
||||
ipcom_free(best);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ipv6_udp_mib_init
|
||||
*===========================================================================
|
||||
* Description: Initializes IPV6-UDP-MIB
|
||||
* Parameters: None
|
||||
* Returns: IPCOM_SUCCESS or IPCOM_ERR_FAILED
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
iplite_ipv6_udp_mib_init(void)
|
||||
{
|
||||
struct Ipsnmp_node_object nodeobj;
|
||||
Ip_s32 ret;
|
||||
|
||||
/* Assign lock function */
|
||||
nodeobj.lock = iplite_ipv6_udp_mib_lock;
|
||||
|
||||
/* Add node "ipv6UdpMIB" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.3.87";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipv6UdpMIB";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_OTHER;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
#ifndef IPCOM_USE_INET
|
||||
/* Add node "udp" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.7";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "udp";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_OTHER;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
#endif /* #ifndef IPCOM_USE_INET */
|
||||
|
||||
/* Add node "ipv6UdpTable" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.6";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipv6UdpTable";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_AGGREGATE;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipv6UdpEntry" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.6.1";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipv6UdpEntry";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_AGGREGATE;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipv6UdpLocalAddress" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_OCTETSTRING;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.6.1.1";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipv6UdpLocalAddress";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipv6UdpLocalPort" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.6.1.2";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipv6UdpLocalPort";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "ipv6UdpIfIndex" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_ipv6_udp_mib_handler_ipv6UdpIfIndex;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.6.1.3";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "ipv6UdpIfIndex";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if(ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
return IPCOM_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* #if defined(IPCOM_USE_MIB2) && defined(IPCOM_USE_INET6) */
|
||||
#endif /* #ifdef IPSNMP */
|
||||
|
||||
#if !defined(IPSNMP) || !defined(IPCOM_USE_MIB2)
|
||||
void iplite_ipv6_udp_mib_empty_file(void);
|
||||
void iplite_ipv6_udp_mib_empty_file(void) { }
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_loopback.c,v $ $Revision: 1.25 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_loopback.c,v $
|
||||
* $Author: lob $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* Loopback interface implementation.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#if !defined(IPLITE_ONE_FILE) || defined(IPLITE_C)
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
|
||||
#include "iplite_netif.h"
|
||||
#include "iplite_loopback.h"
|
||||
#include "iplite_h.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC int iplite_loopback_ioctl(Iplite_netif *netif, Ip_u32 command, void *data);
|
||||
IP_STATIC void iplite_loopback_input(Iplite_netif *netif, Ipcom_pkt *pkt);
|
||||
IP_STATIC int iplite_loopback_output(Iplite_netif *netif, struct Ip_in_addr *to, Ipcom_pkt *pkt);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_loopback_ioctl
|
||||
*===========================================================================
|
||||
* Description: IO control. Accept join/leave from multicast groups.
|
||||
* Parameters: netif - The network interface on which to perform the operation.
|
||||
* command - The command to perform.
|
||||
* data - Data associated with the command.
|
||||
* Returns: 0 = success, 0< = error code.
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_loopback_ioctl(Iplite_netif *netif, Ip_u32 command, void *data)
|
||||
{
|
||||
(void)netif;
|
||||
(void)data;
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case IP_SIOCXOPEN :
|
||||
case IP_SIOCXCLOSE :
|
||||
#ifdef IPCOM_USE_INET
|
||||
case IP_SIOCXADDMULTI_IN :
|
||||
case IP_SIOCXDELMULTI_IN :
|
||||
#endif
|
||||
#ifdef IPCOM_USE_INET6
|
||||
case IP_SIOCXADDMULTI_IN6 :
|
||||
case IP_SIOCXDELMULTI_IN6 :
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_loopback_input
|
||||
*===========================================================================
|
||||
* Description: Handles loopback packets from the input daemon.
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
iplite_loopback_input(Iplite_netif *netif, Ipcom_pkt *pkt)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
if ((pkt->data[pkt->start] & 0xf0) == 0x40)
|
||||
{
|
||||
iplite_ip4_input(netif, pkt);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
if ((pkt->data[pkt->start] & 0xf0) == 0x60)
|
||||
{
|
||||
iplite_ip6_input(netif, pkt);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
IP_PANIC2();
|
||||
ipcom_pkt_free(pkt);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_loopback_output
|
||||
*===========================================================================
|
||||
* Description: Loopbacks IP packets.
|
||||
* Parameters: netif - The interface the packet was sent to.
|
||||
* to - unused
|
||||
* pkt - The packet to loopback. pkt->start is the offset to the
|
||||
* IP header.
|
||||
* Returns: 0 = success, 0< = error code.
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_loopback_output(Iplite_netif *netif, struct Ip_in_addr *to, Ipcom_pkt *pkt)
|
||||
{
|
||||
(void)to; /* Note: can be Iplite_ip6_nc_entry or Ip_sockaddr_ll as well */
|
||||
|
||||
if (IP_BIT_ISFALSE(netif->ipcom.flags, IP_IFF_UP))
|
||||
{
|
||||
ipcom_pkt_free(pkt);
|
||||
return -IP_ERRNO_EHOSTDOWN;
|
||||
}
|
||||
|
||||
IPCOM_PKT_TRACE(pkt, IPCOM_PKT_ID_RX);
|
||||
IP_BIT_SET(pkt->flags, IPCOM_PKT_FLAG_LOOPED_BACK);
|
||||
|
||||
/* MUST queue packet or we will LOCK code twice! /lob 101007 */
|
||||
(void)ipcom_pkt_input_queue((Ipcom_netif *)netif, pkt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_loopback_get_frame_info
|
||||
*===========================================================================
|
||||
* Description: Extracts frame information from a packet sent on the loopback
|
||||
* device.
|
||||
* Parameters: netif - Loopback interface
|
||||
* pkt - The packet to extract information from
|
||||
* pkt_type - Will contain the packet type if != IP_NULL
|
||||
* frame_type - Will contain the frame type if != IP_NULL
|
||||
* src - Unused since the loopback does not have a link layer address.
|
||||
* dst - Unused since the loopback does not use link layer address.
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_PACKET
|
||||
IP_STATIC int
|
||||
iplite_loopback_get_frame_info(struct Iplite_netif_struct *netif,
|
||||
Ipcom_pkt *pkt, Ip_u8 *pkt_type, Ip_u16 *frame_type,
|
||||
Ip_u8 *src, Ip_u8 *dst)
|
||||
{
|
||||
(void)netif;
|
||||
(void)src;
|
||||
(void)dst;
|
||||
|
||||
if (frame_type != IP_NULL)
|
||||
{
|
||||
if ((pkt->data[pkt->start] & 0xf0) == 0x40)
|
||||
*frame_type = ip_htons(IP_IPPROTO_IPV4);
|
||||
else if ((pkt->data[pkt->start] & 0xf0) == 0x60)
|
||||
*frame_type = ip_htons(IP_IPPROTO_IPV6);
|
||||
else
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
|
||||
if (pkt_type != IP_NULL)
|
||||
*pkt_type = IP_PACKET_HOST;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* IPCOM_USE_PACKET */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_loopback_if_init
|
||||
*===========================================================================
|
||||
* Description: Initializes a new loopback interface.
|
||||
* Parameters: netif - The interface to initialize.
|
||||
* Returns: 0 = success, <0 = error code.
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
iplite_loopback_if_init(Iplite_netif *netif)
|
||||
{
|
||||
/* Init loopback interface */
|
||||
ipcom_strcpy(netif->ipcom.name, IPLITE_IF_LOOPBACK_NAME);
|
||||
netif->ipcom.mtu = IPLITE_CONF_LOOPBACK_MTU;
|
||||
netif->link_ioctl = iplite_loopback_ioctl;
|
||||
netif->ipcom.flags = IP_IFF_LOOPBACK | IP_IFF_BROADCAST | IP_IFF_MULTICAST | IP_IFF_RUNNING | IP_IFF_UP;
|
||||
netif->link_input = iplite_loopback_input;
|
||||
#ifdef IPCOM_USE_INET
|
||||
netif->link_ip4_output = iplite_loopback_output;
|
||||
#endif
|
||||
#ifdef IPCOM_USE_INET6
|
||||
netif->link_ip6_output = (Iplite_link_ip6_output)iplite_loopback_output;
|
||||
netif->inet6_if_id_bits = 64;
|
||||
#endif
|
||||
#ifdef IPCOM_USE_PACKET
|
||||
netif->link_raw_output = (Iplite_link_raw_output)iplite_loopback_output;
|
||||
netif->link_get_frame_info = iplite_loopback_get_frame_info;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* !defined(IPLITE_ONE_FILE) || defined(IPLITE_C) */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_loopback.h,v $ $Revision: 1.2 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_loopback.h,v $
|
||||
* $Author: lob $ $Date: 2005-11-11 11:45:55 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPLITE_LOOPBACK_H
|
||||
#define IPLITE_LOOPBACK_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* Loopback interface declarations.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPLITE_IF_LOOPBACK_INDEX 1 /* The index of the loopback interface */
|
||||
#define IPLITE_IF_LOOPBACK_NAME "lo0" /* The name IPLITE uses for the loopback netif */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC int iplite_loopback_if_init(Iplite_netif *netif);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,344 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_netif.h,v $ $Revision: 1.14.26.1 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_netif.h,v $
|
||||
* $Author: svc-cmnet $ $Date: 2013-03-13 07:45:29 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPLITE_NETIF_H
|
||||
#define IPLITE_NETIF_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* Types and function for network interface support in IPLITE */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_config.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_netif.h>
|
||||
#include <ipcom_os.h>
|
||||
#ifdef IPLITE_USE_RFC3927
|
||||
#include "iplite_timeout.h"
|
||||
#endif
|
||||
#ifdef IPCOM_USE_INET6
|
||||
#include "iplite_ip6.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPLITE_IF_UNSPECIFIED_INDEX 0
|
||||
#define IPLITE_IF_UNSPECIFIED_NAME IP_NULL
|
||||
#define IPLITE_IF_END ((IP_CONST char *) -1)
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* Forward declaration */
|
||||
struct Iplite_netif_struct;
|
||||
struct Iplite_netif_eth_struct;
|
||||
struct Iplite_ip6_nc_entry_struct;
|
||||
struct Iplite_ipsec_tdb_struct;
|
||||
struct Iplite_ip4_data_struct;
|
||||
struct Iplite_route_entry_struct;
|
||||
struct Iplite_ip6_dr_entry_struct;
|
||||
struct Iplite_netif_wlan_struct;
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_link_tick
|
||||
*===========================================================================
|
||||
* Description: Performes tasks that must be timer triggered.
|
||||
* Parameters: netif - A pointer to the network interface structure for this
|
||||
* driver.
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
typedef void (*Iplite_link_tick)(struct Iplite_netif_struct *netif);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_link_input
|
||||
*===========================================================================
|
||||
* Description: Process the link header and dispatch IPv4 packets to
|
||||
* iplite_ip4_input() and IPv6 packets to iplite_ip6_input().
|
||||
* The pkt->start must be changed to be the offset to the
|
||||
* IPv4 or IPv6 header for IPv4 and IPv6 packets.
|
||||
* Parameters: netif - A pointer to the network interface structure for this
|
||||
* driver.
|
||||
* pkt - The received packet. pkt->start is the offset to the
|
||||
* link header.
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
typedef void (*Iplite_link_input)(struct Iplite_netif_struct *netif, Ipcom_pkt *pkt);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_link_ip4_output
|
||||
*===========================================================================
|
||||
* Description: Adds the link header to a IPv4 packet and calls the
|
||||
* Iplite_drv_output function for the interface.
|
||||
* Parameters: netif - A pointer to the network interface structure for this
|
||||
* driver.
|
||||
* rt - The route to the next hop. Link specific data can be
|
||||
* stored at rt->data. The 'data' buffer is
|
||||
* IPLITE_ROUTE_ENTRY_DATA_LEN octets long.
|
||||
* pkt - The packet to send. pkt->start is the offset to the
|
||||
* IP header. pkt->start must be updated to be the offset to
|
||||
* the link layer before calling netif->drv_output().
|
||||
* Returns: 0 = success, <0 = error code (-IPLITE_ERRNO_xxx)
|
||||
*
|
||||
*/
|
||||
typedef int (*Iplite_link_ip4_output)(struct Iplite_netif_struct *netif, struct Ip_in_addr *next_hop, Ipcom_pkt *pkt);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_link_ip6_output
|
||||
*===========================================================================
|
||||
* Description: Adds the link header to a IPv6 packet and calls the
|
||||
* Iplite_drv_output function for the interface.
|
||||
* Parameters: netif - A pointer to the network interface structure for this
|
||||
* driver.
|
||||
* nc - The neighbor entry for the first hop (contains IPv6 to link
|
||||
* addr information).
|
||||
* pkt - The packet to send. pkt->start is the offset to the
|
||||
* IP header. pkt->start must be updated to be the offset to
|
||||
* the link layer before calling netif->drv_output().
|
||||
* Returns: 0 = success, <0 = error code (-IPLITE_ERRNO_xxx)
|
||||
*
|
||||
*/
|
||||
typedef int (*Iplite_link_ip6_output)(struct Iplite_netif_struct *netif,
|
||||
struct Iplite_ip6_nc_entry_struct *nc, Ipcom_pkt *pkt);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_link_ip6_create_addr
|
||||
*===========================================================================
|
||||
* Description: Creates a
|
||||
* Parameters: netif - A pointer to the network interface structure for this
|
||||
* driver.
|
||||
* prefix - The prefix to use (the topmost
|
||||
* 128 - netif->inet6_if_id_bits is used).
|
||||
* in6_addr - Will contain the auto address if the call is
|
||||
* successful.
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET6
|
||||
typedef void (*Iplite_link_ip6_create_addr)(struct Iplite_netif_struct *netif,
|
||||
IP_CONST struct Ip_in6_addr* prefix, struct Ip_in6_addr* in6_addr);
|
||||
#endif
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_link_ioctl
|
||||
*===========================================================================
|
||||
* Description: IO control function for the link layer.
|
||||
* Parameters: netif - A pointer to the network interface structure for this
|
||||
* driver.
|
||||
* command - IPLITE_IP4_SIOCxxx or IPLITE_IP6_SIOCxxx style command.
|
||||
* data - Depends on command.
|
||||
* Returns: 0 = success, <0 = error code (-IPLITE_ERRNO_xxx)
|
||||
*
|
||||
*/
|
||||
typedef int (*Iplite_link_ioctl)(struct Iplite_netif_struct *netif,
|
||||
Ip_u32 command, void *data);
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_link_raw_output
|
||||
*===========================================================================
|
||||
* Description: Adds a link layer header and outputs the frame to the driver
|
||||
* ARP (or similar) is bypassed.
|
||||
* Parameters: netif - A pointer to the network interface structure for this
|
||||
* driver.
|
||||
* to - The link layer address of the recipient of this frame.
|
||||
* pkt - The packet which should have a link layer header appended.
|
||||
* Returns: 0 = success, <0 = error code (-IPLITE_ERRNO_xxx)
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_PACKET
|
||||
typedef int (*Iplite_link_raw_output)(struct Iplite_netif_struct *netif,
|
||||
IP_CONST struct Ip_sockaddr_ll *to, Ipcom_pkt *pkt);
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_link_get_frame_info
|
||||
*===========================================================================
|
||||
* Description: Gets header information from the frame header.
|
||||
* Parameters: netif - A pointer to the network interface structure for this
|
||||
* driver.
|
||||
* frame - A complete link layer frame. pkt->start is the offset
|
||||
* to the link layer header.
|
||||
* pkt_type - Will be set to one of the IP_PACKET_xxx type,
|
||||
* can be IP_NULL if this value is not needed.
|
||||
* frame_type - Will be set to the frame type (i.e. one of the
|
||||
* IPLITE_ETH_P_xxx constants for Ethernet). can be IP_NULL if
|
||||
* this information is not needed.
|
||||
* src - Points to a buffer to where the source link address
|
||||
* will be copied. Can be IP_NULL if not needed.
|
||||
* dst - Points to a buffer to where the destination link address
|
||||
* will be copied. Can be IP_NULL if not needed.
|
||||
* Returns: 0 = success, <0 = error code (-IPLITE_ERRNO_xxx)
|
||||
*
|
||||
*/
|
||||
typedef int (*Iplite_link_get_frame_info)(struct Iplite_netif_struct *netif,
|
||||
Ipcom_pkt *frame, Ip_u8 *pkt_type, Ip_u16 *frame_type,
|
||||
Ip_u8 *src, Ip_u8 *dst);
|
||||
|
||||
#endif /* IPCOM_USE_PACKET */
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_netif
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef struct Iplite_netif_struct
|
||||
{
|
||||
Ipcom_netif ipcom; /* IPCOM Ipcom_netif structure.
|
||||
See IPCOM/include/ipcom_netif.h */
|
||||
|
||||
int ref_count; /* Reference count used with ipcom_if_detach() */
|
||||
|
||||
/* Additional interface data. */
|
||||
struct Iplite_netif_eth_struct *eth; /* Pointer to Ethernet info. IP_NULL if not Eth if */
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
struct Iplite_ip4_addr_entry_struct *inet4_addr_list; /* List of IPv4 addresses */
|
||||
#ifdef IPPPP
|
||||
Ip_u32 inet4_peeraddr_n;
|
||||
#endif
|
||||
|
||||
#ifdef IPLITE_USE_RFC3927
|
||||
Ip_u8 inet4_lladdr_state; /* IPLITE_IP4_LLADDR_STATE_xxx */
|
||||
Ip_u8 inet4_lladdr_num; /* Number of probes or announcement left */
|
||||
Ip_u8 inet4_lladdr_conflics; /* Number of address conflicts seen */
|
||||
struct Ip_in_addr inet4_lladdr; /* The current link local address */
|
||||
Iplite_timeout *inet4_lladdr_tmo; /* Timeout structure for link-local IPv4 address */
|
||||
#endif
|
||||
|
||||
#endif /* IPCOM_USE_INET */
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
Ip_u16 inet6_if_id_bits; /* Number of bits that should be used for host id
|
||||
when creating a IPv6 from the link address */
|
||||
Ip_u16 inet6_pad;
|
||||
struct Iplite_ip6_addr_entry_struct *inet6_addr_list; /* All addresses on this interface */
|
||||
struct Iplite_ip6_dr_entry_struct dr; /* Support only single Default router */
|
||||
struct Iplite_ip6_nc_entry_struct *nc_list;
|
||||
#ifdef IPPPP
|
||||
struct Ip_in6_addr inet6_peeraddr;
|
||||
#endif
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
|
||||
/***** IPLITE to link layer functions (downcall) *****/
|
||||
Iplite_link_tick link_tick; /* Can be IP_NULL if no tick is needed */
|
||||
Iplite_link_input link_input; /* Parse packet in link layer. */
|
||||
Iplite_link_ioctl link_ioctl;
|
||||
#ifdef IPCOM_USE_INET
|
||||
Iplite_link_ip4_output link_ip4_output;
|
||||
#endif
|
||||
#ifdef IPCOM_USE_INET6
|
||||
Iplite_link_ip6_output link_ip6_output;
|
||||
Iplite_link_ip6_create_addr link_ip6_create_addr;
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
|
||||
/* IPLITE to link layer packet functions. */
|
||||
#ifdef IPCOM_USE_PACKET
|
||||
Iplite_link_raw_output link_raw_output;
|
||||
Iplite_link_get_frame_info link_get_frame_info;
|
||||
#endif
|
||||
|
||||
/***** Interface output queue *****/
|
||||
Ipcom_sem snd_sem;
|
||||
Ipcom_pkt *snd_head;
|
||||
Ipcom_pkt *snd_tail;
|
||||
int snd_num;
|
||||
int snd_max;
|
||||
int snd_id;
|
||||
#ifdef IPLITE_USE_WLAN
|
||||
struct Iplite_netif_wlan_struct *wlan;
|
||||
#endif
|
||||
}
|
||||
Iplite_netif;
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* internal funcs
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
IP_GLOBAL void iplite_if_clean(Iplite_netif *netif, Ip_bool clean_ip4, Ip_bool clean_ip6);
|
||||
|
||||
IP_GLOBAL int iplite_if_output(Iplite_netif *netif, Ipcom_pkt *pkt);
|
||||
IP_GLOBAL int iplite_if_drv_output(Iplite_netif *netif, Ipcom_pkt *pkt);
|
||||
|
||||
IP_GLOBAL int iplite_if_configure(void);
|
||||
|
||||
IP_GLOBAL void iplite_if_lock(Iplite_netif *netif);
|
||||
IP_GLOBAL int iplite_if_unlock(Iplite_netif *netif);
|
||||
|
||||
IP_GLOBAL int iplite_if_drv_ioctl(Iplite_netif *netif, Ip_u32 command, void *data);
|
||||
|
||||
IP_GLOBAL Iplite_netif *iplite_if_indextonetif(Ip_u32 ifindex);
|
||||
IP_GLOBAL Iplite_netif *iplite_if_nametonetif(IP_CONST char *ifname);
|
||||
|
||||
#ifdef IPPPP
|
||||
IP_PUBLIC int iplite_ppp_if_init(Iplite_netif *netif);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,469 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_ppp.c,v $ $Revision: 1.24 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_ppp.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 IPPPP
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
|
||||
#include <ipppp.h>
|
||||
#include <ipppp_ipstack.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* Number of bits in the host part (EUI-64) when using the
|
||||
* PPP to create a IPv6 address (RFC 2464?)
|
||||
*/
|
||||
#define IPPPP_IP6_ID_BITS 64
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC void iplite_ppp_input(struct Iplite_netif_struct *netif, Ipcom_pkt *pkt);
|
||||
IP_STATIC int iplite_ppp_ioctl(struct Iplite_netif_struct *netif, Ip_u32 command, void *data);
|
||||
IP_STATIC int iplite_ppp_ioevent(Ipcom_netif *netif, int command, void *data, int fcflags);
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
IP_STATIC int iplite_ppp_ip4_output(struct Iplite_netif_struct *netif, struct Ip_in_addr *next_hop, Ipcom_pkt *pkt);
|
||||
#endif
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
IP_STATIC int iplite_ppp_ip6_output(struct Iplite_netif_struct *netif, struct Iplite_ip6_nc_entry_struct *nc, Ipcom_pkt *pkt);
|
||||
#endif
|
||||
|
||||
IP_PUBLIC int ipppp_if_init2(void *voidif);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ppp_input
|
||||
*===========================================================================
|
||||
* Description: Input handler for ethernet frames. pkt->start is the offset
|
||||
* to the ethernet header.
|
||||
* Parameters: pkt - The ethernet frame.
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
iplite_ppp_input(struct Iplite_netif_struct *netif, Ipcom_pkt *pkt)
|
||||
{
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
(void)ipppp_input(&netif->ipcom, pkt);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ppp_ioctl
|
||||
*===========================================================================
|
||||
* Description: PPP IO control.
|
||||
* Parameters: netif - The interface on which the multicast address will
|
||||
* be used.
|
||||
* command - ioctl command.
|
||||
* data - Depends on command.
|
||||
* Returns: 0 = success, < 0 = error code
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ppp_ioctl(struct Iplite_netif_struct *netif, Ip_u32 command, void *data)
|
||||
{
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
return ipppp_ioctl(&netif->ipcom, command, data);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ppp_ip4_output
|
||||
*===========================================================================
|
||||
* Description: Outputs a IPv4 packet.
|
||||
* Parameters:
|
||||
* Returns: 0 = success, <0 = error code.
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET
|
||||
IP_STATIC int
|
||||
iplite_ppp_ip4_output(struct Iplite_netif_struct *netif, struct Ip_in_addr *next_hop, Ipcom_pkt *pkt)
|
||||
{
|
||||
(void)next_hop;
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
return ipppp_ip4_output(&netif->ipcom, pkt);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ppp_ip6_output
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET6
|
||||
IP_STATIC int
|
||||
iplite_ppp_ip6_output(struct Iplite_netif_struct *netif, struct Iplite_ip6_nc_entry_struct *nc, Ipcom_pkt *pkt)
|
||||
{
|
||||
(void)nc;
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
return ipppp_ip6_output(&netif->ipcom, pkt);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ppp_ioevent
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_ppp_ioevent(Ipcom_netif *netif, int command, void *data, int fcflags)
|
||||
{
|
||||
int retval;
|
||||
|
||||
if(!IP_BIT_ISSET(fcflags, IP_FLAG_FC_ISRCONTEXT | IP_FLAG_FC_STACKCONTEXT))
|
||||
IPLITE_CODE_LOCK();
|
||||
|
||||
retval = ipppp_ioevent(netif, command, data);
|
||||
|
||||
if(!IP_BIT_ISSET(fcflags, IP_FLAG_FC_ISRCONTEXT | IP_FLAG_FC_STACKCONTEXT))
|
||||
IPLITE_CODE_UNLOCK();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_ppp_if_init
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
ipppp_if_init2(void *voidif)
|
||||
{
|
||||
Iplite_netif *netif = voidif;
|
||||
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
/* Setup link functions for PPP use. */
|
||||
netif->link_input = iplite_ppp_input;
|
||||
netif->link_ioctl = iplite_ppp_ioctl;
|
||||
netif->ipcom.link_ioevent = iplite_ppp_ioevent;
|
||||
#ifdef IPCOM_USE_INET
|
||||
netif->link_ip4_output = iplite_ppp_ip4_output;
|
||||
#endif
|
||||
#ifdef IPCOM_USE_INET6
|
||||
netif->inet6_if_id_bits = IPPPP_IP6_ID_BITS;
|
||||
netif->link_ip6_output = iplite_ppp_ip6_output;
|
||||
#endif
|
||||
|
||||
return ipppp_if_init(&netif->ipcom);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipcom_ppp_ioevent
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
ipcom_ppp_ioevent(Ipcom_netif *netif, int command, void *data)
|
||||
{
|
||||
#ifdef NOTYET
|
||||
struct Iplite_route_add_param param;
|
||||
struct Iplite_rt_metrics metrics;
|
||||
#endif
|
||||
Ip_u32 netmask_n;
|
||||
Iplite_netif *iplite_netif = (Iplite_netif *)netif;
|
||||
int ret = 0;
|
||||
#ifdef IPCOM_USE_INET6
|
||||
Iplite_ip6_nc_entry *nc;
|
||||
#endif
|
||||
|
||||
switch(command)
|
||||
{
|
||||
case IPPPP_EIOXBLOCKOK:
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
if (iplite_is_stack_task() == IP_FALSE)
|
||||
ret = 1; /* user process -> block is ok. */
|
||||
break;
|
||||
|
||||
case IPPPP_EIOXDRVIOCTL:
|
||||
{
|
||||
Ipppp_eio_ioctl *eio_ioctl = data;
|
||||
|
||||
ip_assert(netif);
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
IPLITE_CODE_UNLOCK();
|
||||
ret = netif->drv_ioctl(netif, eio_ioctl->command, eio_ioctl->data);
|
||||
IPLITE_CODE_LOCK();
|
||||
break;
|
||||
}
|
||||
|
||||
case IPPPP_EIOXOUTPUT_IF:
|
||||
ip_assert(iplite_netif);
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
ret = iplite_if_output(iplite_netif, data);
|
||||
break;
|
||||
|
||||
case IPPPP_EIOXINDEXTONETIF:
|
||||
{
|
||||
Iplite_netif *ptr;
|
||||
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
ptr = iplite_if_indextonetif((Ip_u32)data);
|
||||
return (int)ptr;
|
||||
}
|
||||
|
||||
case IPPPP_EIOXCODE_LOCK:
|
||||
IPLITE_CODE_LOCK();
|
||||
break;
|
||||
|
||||
case IPPPP_EIOXCODE_UNLOCK:
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
IPLITE_CODE_UNLOCK();
|
||||
break;
|
||||
|
||||
case IPPPP_EIOXIF_LOCK:
|
||||
ip_assert(netif);
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
iplite_if_lock(iplite_netif);
|
||||
break;
|
||||
|
||||
case IPPPP_EIOXIF_UNLOCK:
|
||||
ip_assert(netif);
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
(void)iplite_if_unlock(iplite_netif);
|
||||
break;
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
case IPPPP_EIOXINPUT_IN:
|
||||
ip_assert(iplite_netif);
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
iplite_ip4_input(iplite_netif, data);
|
||||
break;
|
||||
|
||||
case IPPPP_EIOXUP_IN:
|
||||
{
|
||||
Ipppp_eio_in *eio_in = data;
|
||||
|
||||
ip_assert(netif);
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
/* Add local IPv4 address to this interface. */
|
||||
netmask_n = IP_NETMASK(eio_in->local_addr_n);
|
||||
if(iplite_ip4_add_addr(iplite_netif, eio_in->local_addr_n, netmask_n) < 0)
|
||||
{
|
||||
IP_PANIC2();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Save peer address for "route" lookup. */
|
||||
iplite_netif->inet4_peeraddr_n = eio_in->peer_addr_n;
|
||||
|
||||
if (ipppp_sysvar_get_conf_string(netif, IP_NULL, "ipppp.flags", "defaultroute"))
|
||||
{
|
||||
/* Add default IPv4 gateway to peer. */
|
||||
iplite.ip4.default_gateway_n = eio_in->peer_addr_n;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case IPPPP_EIOXDOWN_IN:
|
||||
ip_assert(iplite_netif);
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
iplite_if_clean(iplite_netif, IP_TRUE, IP_FALSE);
|
||||
break;
|
||||
|
||||
case IPPPP_EIOXDSTADDR_IN:
|
||||
{
|
||||
struct Ip_ifreq ifreq;
|
||||
struct Ip_sockaddr_in *inaddr = (struct Ip_sockaddr_in *)&ifreq.ip_ifr_addr;
|
||||
Ip_u32 dstaddr = ((struct Ip_in_addr *)data)->s_addr;
|
||||
|
||||
Iplite_netif *tmpif;
|
||||
int i;
|
||||
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
dstaddr = ip_htonl(dstaddr);
|
||||
for (i = 1; i < IPLITE_CONF_MAX_NETIF; i++)
|
||||
{
|
||||
tmpif = iplite.netifs[i];
|
||||
if (tmpif == IP_NULL)
|
||||
continue;
|
||||
if (IP_BIT_ISFALSE(tmpif->ipcom.flags, IP_IFF_POINTOPOINT))
|
||||
continue;
|
||||
(void)tmpif->link_ioctl(tmpif, IP_SIOCGIFDSTADDR, &ifreq);
|
||||
if (inaddr->sin_addr.s_addr == dstaddr)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#endif /* ifdef IPCOM_USE_INET */
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
case IPPPP_EIOXINPUT_IN6:
|
||||
ip_assert(iplite_netif);
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
iplite_ip6_input(iplite_netif, data);
|
||||
break;
|
||||
|
||||
case IPPPP_EIOXUP_IN6:
|
||||
{
|
||||
Ipppp_eio_in6 *eio_in6 = data;
|
||||
|
||||
ip_assert(netif);
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
|
||||
/* Add IPv6 address. */
|
||||
if(iplite_ip6_add_addr(iplite_netif, &eio_in6->local_addr, 64,
|
||||
0, IPCOM_ADDR_INFINITE, IPCOM_ADDR_INFINITE) != 0)
|
||||
{
|
||||
IP_PANIC2();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Create neighbor cache entry for peer. */
|
||||
nc = iplite_ip6_neighbor_cache_find(iplite_netif, (IP_CONST struct Ip_in6_addr *)&eio_in6->peer_addr);
|
||||
nc->status = IPLITE_IP6_ND_REACHABLE;
|
||||
nc->next_timeout = IPCOM_ADDR_INFINITE;
|
||||
|
||||
/* Save peer address for "route" lookup. */
|
||||
ipcom_memcpy(&iplite_netif->inet6_peeraddr, &eio_in6->peer_addr, sizeof(struct Ip_in6_addr));
|
||||
}
|
||||
break;
|
||||
|
||||
case IPPPP_EIOXDOWN_IN6:
|
||||
ip_assert(iplite_netif);
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
iplite_if_clean(iplite_netif, IP_FALSE, IP_TRUE);
|
||||
|
||||
nc = iplite_ip6_neighbor_cache_find(iplite_netif, (IP_CONST struct Ip_in6_addr *)&iplite_netif->inet6_peeraddr);
|
||||
nc->status = IPLITE_IP6_ND_INCOMPLETE;
|
||||
nc->next_timeout = iplite.seconds + 1;
|
||||
break;
|
||||
#endif /* ifdef IPCOM_USE_INET6 */
|
||||
|
||||
default:
|
||||
ip_assert(iplite_netif);
|
||||
IPLITE_CODE_ISLOCKED_ASSERT();
|
||||
iplite_kioevent(iplite_netif, command, data);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* IPPPP */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,443 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_raw.c,v $ $Revision: 1.31 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_raw.c,v $
|
||||
* $Author: hxie $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* Raw socket address family functions */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#if !defined(IPLITE_ONE_FILE) || defined(IPLITE_C)
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_inet.h>
|
||||
#include <ipcom_syslog.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_sock.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_packet_socklookup
|
||||
*===========================================================================
|
||||
* Description: Returns IP_AF_PACKET sockets that match the frame type.
|
||||
* Parameters: frame_type - The frame type that the matching socket must have.
|
||||
* unused1 -
|
||||
* unused2 -
|
||||
* unused3 -
|
||||
* unused4 -
|
||||
* next - [in] The first socket to look at. [out] the next socket
|
||||
* to look at. Can be IP_NULL if only the first match should be
|
||||
* returned.
|
||||
* Returns: >0 = application bytes sent, <0 = error code.
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_PACKET
|
||||
IP_STATIC Iplite_socket *
|
||||
iplite_packet_socklookup(int frame_type, IP_CONST void *unused1, Ip_u16 unused2,
|
||||
IP_CONST void *unused3, Ip_u16 unused4, int *next)
|
||||
{
|
||||
int i;
|
||||
Iplite_socket *sock;
|
||||
|
||||
(void)unused1;
|
||||
(void)unused2;
|
||||
(void)unused3;
|
||||
(void)unused4;
|
||||
|
||||
for (i = (next == IP_NULL ? 0 : *next); i < IPLITE_CONF_MAX_SOCKETS; i++)
|
||||
{
|
||||
sock = iplite.sockets[i];
|
||||
if (sock == IP_NULL)
|
||||
continue;
|
||||
if (sock->ipcom.domain != IP_AF_PACKET)
|
||||
continue;
|
||||
if (sock->proto != 0 && sock->proto != frame_type)
|
||||
continue;
|
||||
if (next != IP_NULL)
|
||||
*next = i + 1;
|
||||
return sock;
|
||||
}
|
||||
return IP_NULL;
|
||||
}
|
||||
#endif /* IPCOM_USE_PACKET */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_USE_PACKET
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_packet_output
|
||||
*===========================================================================
|
||||
* Description: Sends a raw frame directly to the driver (IP_SOCK_RAW) or
|
||||
* directly to the link layer to get a link header
|
||||
* (IP_SOCK_DGRAM) (but no ARP or simlilar is performed).
|
||||
* Parameters: sock - The socket to use when sending.
|
||||
* to - The destination address address, ignored if the socket
|
||||
* is in connected state.
|
||||
* pkt - The packet data to send.
|
||||
* Returns: >0 = application bytes sent, <0 = error code.
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_packet_output(Iplite_socket *sock, IP_CONST struct Ip_sockaddr *to, Ipcom_pkt *pkt)
|
||||
{
|
||||
struct Ip_sockaddr_ll *ll_addr = (struct Ip_sockaddr_ll *) to;
|
||||
Iplite_netif *netif;
|
||||
int ret;
|
||||
int max_pkt_len;
|
||||
|
||||
if (ll_addr->sll_family != IP_AF_PACKET)
|
||||
{
|
||||
IPCOM_LOG2(DEBUG2, "RAW: sll_family must be IP_AF_PACKET (%d), got %d",
|
||||
IP_AF_PACKET, (int)ll_addr->sll_family);
|
||||
return -IP_ERRNO_EPROTOTYPE;
|
||||
}
|
||||
|
||||
netif = iplite_if_indextonetif(ll_addr->sll_ifindex);
|
||||
if (netif == IP_NULL)
|
||||
{
|
||||
IPCOM_LOG1(DEBUG2, "RAW: %d is not a valid interface index",
|
||||
(int)ll_addr->sll_ifindex);
|
||||
return -IP_ERRNO_ENXIO;
|
||||
}
|
||||
pkt->ifindex = netif->ipcom.ifindex;
|
||||
|
||||
if (sock->ipcom.type == IP_SOCK_RAW)
|
||||
/* Link layer header included */
|
||||
max_pkt_len = netif->ipcom.mtu + netif->ipcom.link_hdr_size;
|
||||
else if (sock->ipcom.type == IP_SOCK_DGRAM)
|
||||
/* Link layer must be added by the stack */
|
||||
max_pkt_len = netif->ipcom.mtu;
|
||||
else
|
||||
{
|
||||
max_pkt_len = 0;
|
||||
IP_PANIC();
|
||||
}
|
||||
|
||||
if (pkt->end - pkt->start > max_pkt_len)
|
||||
{
|
||||
IPCOM_LOG2(DEBUG2, "RAW: packet to big (%d bytes), allowed size is %d bytes",
|
||||
(int)(pkt->end - pkt->start), max_pkt_len);
|
||||
return -IP_ERRNO_ENOBUFS;
|
||||
}
|
||||
|
||||
if (sock->ipcom.type == IP_SOCK_DGRAM)
|
||||
{
|
||||
if (netif->link_raw_output == IP_NULL)
|
||||
{
|
||||
IPCOM_LOG1(DEBUG2, "RAW: interface %s does not support"
|
||||
"IP_SOCK_DGRAM type IP_AF_PACKET sockets", netif->ipcom.name);
|
||||
return -IP_ERRNO_ENOSYS;
|
||||
}
|
||||
if (ll_addr->sll_protocol == 0)
|
||||
{
|
||||
if (sock->proto == 0)
|
||||
{
|
||||
IPCOM_LOG1(DEBUG2, "RAW: protocol was neither specified when the socket %d was created"
|
||||
" nor in the 'to' address", (int)sock->ipcom.fd);
|
||||
return -IP_ERRNO_EFAULT;
|
||||
}
|
||||
ll_addr->sll_protocol = sock->proto;
|
||||
}
|
||||
iplite_if_lock(netif);
|
||||
ret = netif->link_raw_output(netif, ll_addr, pkt);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
ip_assert(netif->ipcom.drv_output != IP_NULL);
|
||||
|
||||
iplite_if_lock(netif);
|
||||
ret = iplite_if_output(netif, pkt);
|
||||
|
||||
leave:
|
||||
(void)iplite_if_unlock(netif);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_packet_input
|
||||
*===========================================================================
|
||||
* Context: Any non-interrupt context.
|
||||
* Description: Inputs a packet to the stack.
|
||||
* Parameters: netif - The interface the packet was received on.
|
||||
* pkt - The received packet. pkt->start is the offset to the
|
||||
* the link layer header.
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL Ip_bool
|
||||
iplite_packet_input(Iplite_netif *netif, Ipcom_pkt *pkt)
|
||||
{
|
||||
int i;
|
||||
Ip_u16 frame_type;
|
||||
Ip_bool continue_process = IP_TRUE;
|
||||
|
||||
ip_assert(iplite.num_packet_sock > 0);
|
||||
|
||||
if (netif->link_get_frame_info == IP_NULL)
|
||||
{
|
||||
IPCOM_LOG1(DEBUG2, "RAW: packet sockets is not supported by interface %d",
|
||||
(int)netif->ipcom.ifindex);
|
||||
return IP_TRUE;
|
||||
}
|
||||
|
||||
i = netif->link_get_frame_info(netif, pkt, IP_NULL, &frame_type, IP_NULL, IP_NULL);
|
||||
if (i < 0)
|
||||
{
|
||||
IPCOM_LOG1(DEBUG2, "RAW: failed to get information about the frame (%d)", -i);
|
||||
return IP_TRUE;
|
||||
}
|
||||
|
||||
pkt->ipstart = pkt->start; /* to avoid assert in clone() */
|
||||
|
||||
/* Give to all sockets that matches the protocol */
|
||||
if (iplite_raw_input(pkt, IP_FALSE, frame_type, IP_NULL, 0, IP_NULL, 0,
|
||||
(Iplite_socklookup)iplite_packet_socklookup) == -IP_ERRNO_ENODATA)
|
||||
continue_process = IP_FALSE;
|
||||
|
||||
/* Give to all sockets that should match any protocol -> all packets */
|
||||
if (iplite_raw_input(pkt, IP_FALSE, 0, IP_NULL, 0, IP_NULL, 0,
|
||||
(Iplite_socklookup)iplite_packet_socklookup) == -IP_ERRNO_ENODATA)
|
||||
continue_process = IP_FALSE;
|
||||
|
||||
if (!continue_process)
|
||||
ipcom_pkt_free(pkt);
|
||||
return continue_process;
|
||||
}
|
||||
|
||||
#endif /* IPCOM_USE_PACKET */
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_raw_input
|
||||
*===========================================================================
|
||||
* Description: Generic input handler for packet.
|
||||
* Parameters: pkt - The received packet.
|
||||
* take_ownership - Set to IP_TRUE if this function should control
|
||||
* the lifetime of the packet.
|
||||
* proto - The protocol number.
|
||||
* src_addr - The address (Ipv4 or IPv6) of the sender.
|
||||
* src_port - The source port.
|
||||
* dst_addr - The address (Ipv4 or IPv6) of the receiver (this system).
|
||||
* src_port - The destination port.
|
||||
* socklookup - A pointer to a function that can return the socket
|
||||
* that is associated with this packet.
|
||||
* Returns: 0 >= number of matching sockets, <0 = error code
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_raw_input(Ipcom_pkt *pkt, Ip_bool take_ownership, int proto,
|
||||
IP_CONST void *src_addr, Ip_u16 src_port, IP_CONST void *dst_addr, Ip_u16 dst_port,
|
||||
Iplite_socklookup socklookup)
|
||||
{
|
||||
int next = 0; /* start from 0 because bound sockets start from 0 */
|
||||
Ip_bool org_pkt_queued = IP_FALSE;
|
||||
int matching_sock = 0;
|
||||
Iplite_socket *sock;
|
||||
Ipcom_pkt *clone;
|
||||
Ip_u32 checksum;
|
||||
Ip_bool checksum_ok = IP_FALSE;
|
||||
|
||||
#ifdef IP_PORT_OSE5
|
||||
iplite.raw_input_id++;
|
||||
#endif
|
||||
|
||||
while (IP_NULL != (sock = socklookup(proto, dst_addr, dst_port, src_addr, src_port, &next)))
|
||||
{
|
||||
if (checksum_ok == IP_FALSE
|
||||
&& IP_BIT_ISSET(sock->flags, IPLITE_SOCKET_FLAG_ADDCHECKSUM)
|
||||
&& sock->proto != IP_IPPROTO_ICMPV6
|
||||
&& sock->proto != IP_IPPROTO_UDP)
|
||||
{
|
||||
/* The checksum must be checked for this packet
|
||||
UDP and ICMPv6 packets has already been checked */
|
||||
checksum = ipcom_in_checksum_update(&pkt->data[pkt->start],
|
||||
(Ip_size_t) (pkt->end - pkt->start));
|
||||
if (ipcom_in_checksum_finish(checksum + pkt->chk) != 0)
|
||||
{
|
||||
/* Wrong checksum */
|
||||
IPLITE_STATS(raw_input_badchksum++);
|
||||
matching_sock = -IP_ERRNO_EINVAL;
|
||||
goto leave;
|
||||
}
|
||||
checksum_ok = IP_TRUE;
|
||||
}
|
||||
|
||||
#ifdef IP_PORT_OSE5
|
||||
if (iplite.raw_input_id == sock->raw_input_id)
|
||||
continue;
|
||||
sock->raw_input_id = iplite.raw_input_id;
|
||||
#endif
|
||||
|
||||
if (org_pkt_queued || !take_ownership)
|
||||
{
|
||||
clone = iplite_pkt_clone(pkt);
|
||||
if (clone == IP_NULL)
|
||||
break;
|
||||
}
|
||||
else
|
||||
clone = pkt;
|
||||
|
||||
clone->fd = sock->ipcom.fd;
|
||||
if (sock->ipcom.event_cb)
|
||||
sock->ipcom.event_cb((Ipcom_socket *)sock, clone, IP_SOEVENT_CB_INPKT);
|
||||
|
||||
if (iplite_queue_received_packet(clone, sock) < 0)
|
||||
{
|
||||
if(clone != pkt)
|
||||
ipcom_pkt_free(clone);
|
||||
continue;
|
||||
}
|
||||
if (sock->ipcom.event_cb)
|
||||
sock->ipcom.event_cb((Ipcom_socket *)sock, pkt, IP_SOEVENT_CB_SELREAD);
|
||||
|
||||
if (pkt == clone)
|
||||
org_pkt_queued = IP_TRUE;
|
||||
|
||||
matching_sock++;
|
||||
}
|
||||
|
||||
leave:
|
||||
if (take_ownership && !org_pkt_queued)
|
||||
ipcom_pkt_free(pkt);
|
||||
return matching_sock;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_raw_output
|
||||
*===========================================================================
|
||||
* Description: Dispatches the call to the appropriate output handler.
|
||||
* Parameters: sock - The socket to use when sending.
|
||||
* to - The destination address address, ignored if the socket
|
||||
* is in connected state.
|
||||
* pkt - The packet data to send.
|
||||
* Returns: >0 = application bytes sent, <0 = error code.
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_raw_output(Iplite_socket *sock, IP_CONST struct Ip_sockaddr *to, Ipcom_pkt *pkt)
|
||||
{
|
||||
ip_assert(sock->ipcom.type == IP_SOCK_RAW);
|
||||
|
||||
switch (sock->ipcom.domain)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
case IP_AF_INET :
|
||||
return iplite_ip4_sendto(sock, to, pkt);
|
||||
#endif
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
case IP_AF_INET6 :
|
||||
return iplite_ip6_sendto(sock, to, pkt);
|
||||
#endif
|
||||
|
||||
#ifdef IPIPSEC2
|
||||
case IP_AF_KEY :
|
||||
return ipipsec_pfkeyv2_input((Ipcom_socket *)sock, IP_NULL, pkt);
|
||||
#endif
|
||||
|
||||
default :
|
||||
/* Invalid domain */
|
||||
return -IP_ERRNO_EAFNOSUPPORT;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* !defined(IPLITE_ONE_FILE) || defined(IPLITE_C) */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_sock.h,v $ $Revision: 1.5 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_sock.h,v $
|
||||
* $Author: hxie $ $Date: 2010-11-19 00:44:11 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPLITE_SOCK_H
|
||||
#define IPLITE_SOCK_H
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* IPLITE socket definition.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_h.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define SOCK_ERROUT(errval) do { (void)ipcom_errno_set(errval); goto errout; } while(0)
|
||||
|
||||
/* Socket lock and unlock macros */
|
||||
#define IPLITE_SOCK_ADD_REF(s) (++(s)->ref_count)
|
||||
#define IPLITE_SOCK_DEL_REF(s) do { if(--(s)->ref_count == 0) (void)iplite_sock_free(s); } while(0)
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_socket_domain
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
/* Domain specified socket data */
|
||||
typedef union Iplite_socket_domain_union
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
Iplite_ip4_socket ip4;
|
||||
#endif
|
||||
#ifdef IPCOM_USE_INET6
|
||||
Iplite_ip6_socket ip6;
|
||||
#endif
|
||||
}
|
||||
Iplite_socket_domain;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_poll_entries
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef struct Iplite_poll_entries_struct
|
||||
{
|
||||
Ipcom_list list; /* List of poll entries for a specific socket */
|
||||
Ipcom_block *sem; /* Semaphore to post if this socket becomes ready */
|
||||
}
|
||||
Iplite_poll_entry;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_socket
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
typedef struct Iplite_socket_struct
|
||||
{
|
||||
Ipcom_socket ipcom; /* Common (IPLITE/IPNET) socket info. */
|
||||
|
||||
int ref_count; /* Number of reference held on this socket */
|
||||
Ip_u16 proto; /* Protocol */
|
||||
Ip_u8 uni_hop_limit; /* The hop limit for unicast packtes */
|
||||
Ip_u8 multi_hop_limit; /* The hop limit for multicast packtes */
|
||||
Ip_u32 bind_to_ifindex; /* The interface this socket is bound to (with
|
||||
IP_SO_BINDTODEVICE). ==0 -> not bound */
|
||||
Ip_u32 flags; /* Socket flags. */
|
||||
Iplite_transport_output transport_output;
|
||||
|
||||
Ip_u16 max_hdrspace; /* Maximum needed header space for network (IP) and transport layer. */
|
||||
Ip_u16 chk_offset; /* Offset into the transport layer (TCP, UDP, e.t.c) where the
|
||||
16 bit internet checksum should be stored, used if the flag
|
||||
IPLITE_SOCKET_FLAGS_ADDCHECKSUM is set */
|
||||
|
||||
Ip_u16 sport; /* Source port. */
|
||||
Ip_u16 dport; /* Destination port. */
|
||||
|
||||
#ifdef IP_PORT_OSE5
|
||||
int raw_input_id;
|
||||
#endif
|
||||
|
||||
/* Synchronization object used when this socket is part of a
|
||||
ipcom_socketselect() call */
|
||||
Ipcom_list snd_poll_list; /* List of processes waiting to send
|
||||
on this socket. Contains
|
||||
Iplite_poll_entries */
|
||||
Ipcom_list rcv_poll_list; /* List of processes waiting to
|
||||
receive on this socket. Contains
|
||||
Iplite_poll_entries */
|
||||
|
||||
int snd_max_bytes; /* Max number of bytes that can be
|
||||
stored in the send buffer */
|
||||
int rcv_max_bytes; /* Max number of bytes that can be
|
||||
stored in the recieve buffer */
|
||||
|
||||
int snd_bytes; /* Number of bytes currently queued
|
||||
for transmission on this socket */
|
||||
|
||||
/* Variables used by protocols that is datagram based, the TCP
|
||||
receive queue is found in 'tcb' */
|
||||
Ipcom_pkt *rcv_head; /* Input packet queue head,
|
||||
pkt->start is the offset to the
|
||||
transport layer header. */
|
||||
Ipcom_pkt *rcv_tail; /* Input packet queue tail. */
|
||||
|
||||
/* Synchronization objects used when receiving data */
|
||||
struct Ip_timeval rcv_timeout; /* Time that a blocking
|
||||
ipcom_recv can block */
|
||||
|
||||
#ifdef IP_PORT_VXWORKS
|
||||
void *select_ctx;
|
||||
#endif
|
||||
#ifdef IPCOM_USE_TCP
|
||||
struct Iplite_tcp_tcb_struct *tcb; /* Transmission control block
|
||||
(used by TCP) */
|
||||
void (*notify_cb)(struct Iplite_socket_struct *sock, int event);
|
||||
#endif /* IPCOM_USE_TCP */
|
||||
|
||||
Iplite_socket_domain *d;
|
||||
|
||||
/* !NOTE! do not put any struct member below 'd',
|
||||
* since will end up in unallocated memory for IPv4 sockets
|
||||
*/
|
||||
}
|
||||
Iplite_socket;
|
||||
|
||||
/* socket flags. */
|
||||
#define IPLITE_SOCKET_FLAG_NONBLOCKING 0x00000001 /* Socket is in non-blocking mode */
|
||||
#define IPLITE_SOCKET_FLAG_BOUND 0x00000002 /* Socket is bound (explicit or implicit) */
|
||||
#define IPLITE_SOCKET_FLAG_CONNECTING 0x00000004 /* Asynchronous connect in progress */
|
||||
#define IPLITE_SOCKET_FLAG_CONNECTED 0x00000008 /* Socket is connected */
|
||||
#define IPLITE_SOCKET_FLAG_REUSEADDR 0x00000010 /* Resuse of address is ok */
|
||||
#define IPLITE_SOCKET_FLAG_REUSEPORT 0x00000020 /* Resuse of port and address is ok */
|
||||
#define IPLITE_SOCKET_FLAG_BLOCKED 0x00000080 /* A user process is blocked on this socket */
|
||||
#define IPLITE_SOCKET_FLAG_IP_HDRINCL 0x00000100 /* The user supplies the IP header */
|
||||
#define IPLITE_SOCKET_FLAG_LOOP_MULTICAST 0x00000200 /* Loopback multicast packets sent from this host */
|
||||
#define IPLITE_SOCKET_FLAG_ALLOW_BROADCAST 0x00000400 /* Packets can be sent to the IPv4 broadcast address */
|
||||
#define IPLITE_SOCKET_FLAG_TCP_NODELAY 0x00000800 /* Nagle algorithm is OFF when this flag is set */
|
||||
#define IPLITE_SOCKET_FLAG_RECV_IF 0x00001000 /* Returns the recv if for datagram proto */
|
||||
#define IPLITE_SOCKET_FLAG_ADDCHECKSUM 0x00004000 /* Pseudo header checksum should be added to outgoing packets */
|
||||
#define IPLITE_SOCKET_FLAG_RECVHOPLIMIT 0x00008000 /* Return the packet hoplimit of the received packet */
|
||||
|
||||
#define IPLITE_SOCKET_FLAG_PKTAVAIL_CB_PENDING 0x00010000 /* This socket want an IP_SOEVENT_CB_PKTAVAIL event when
|
||||
the next packet is freed */
|
||||
#define IPLITE_SOCKET_FLAG_READ_CLOSED 0x00100000 /* The read end of the socket is closed */
|
||||
#define IPLITE_SOCKET_FLAG_WRITE_CLOSED 0x00200000 /* The write end of the socket is closed */
|
||||
#define IPLITE_SOCKET_FLAG_PEER_WRITE_CLOSED 0x00400000 /* The peer has closed its write end */
|
||||
#define IPLITE_SOCKET_FLAG_CLOSED 0x00800000 /* The socket has been closed */
|
||||
#define IPLITE_SOCKET_FLAG_KEEPALIVE 0x08000000 /* Probe idle connection */
|
||||
#define IPLITE_SOCKET_FLAG_DONTROUTE 0x10000000 /* Bypass routing for outgoing messages */
|
||||
#define IPLITE_SOCKET_FLAG_OOBINLINE 0x20000000 /* Receive out-of-band data mixed with normal data */
|
||||
#ifdef IP_PORT_VXWORKS
|
||||
#define IPLITE_SOCKET_FLAG_RECVPKTINFO 0x40000000
|
||||
#endif
|
||||
|
||||
|
||||
/* socket start index (0,1,2 are resered and not used) */
|
||||
#define IPLITE_SOCKET_STARTFD 3
|
||||
|
||||
|
||||
#define IPLITE_SELECT_RD (1 << 0) /* This socket is part of the read set */
|
||||
#define IPLITE_SELECT_WR (1 << 1) /* This socket is part of the write set */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_GLOBAL Ip_bool iplite_is_sock_readable(Iplite_socket *sock, int lowat);
|
||||
IP_GLOBAL Ip_bool iplite_is_sock_writable(Iplite_socket *sock, int lowat);
|
||||
IP_GLOBAL Ip_bool iplite_is_sock_exceptional(Iplite_socket *sock, int lowat);
|
||||
IP_GLOBAL Iplite_socket * iplite_get_sock(int fd);
|
||||
IP_GLOBAL void iplite_release_sock(Iplite_socket *sock);
|
||||
IP_GLOBAL int iplite_sock_drop_all_multicast_memberships(Iplite_socket *sock, Iplite_netif *netif,
|
||||
Ip_bool drop_ip4, Ip_bool drop_ip6);
|
||||
IP_GLOBAL int iplite_raw_input(Ipcom_pkt *pkt, Ip_bool take_ownership, int proto,
|
||||
IP_CONST void *src_addr, Ip_u16 src_port,
|
||||
IP_CONST void *dst_addr, Ip_u16 dst_port,
|
||||
Iplite_socklookup socklookup);
|
||||
|
||||
IP_GLOBAL int iplite_socketioctl_islocked(Ip_fd fd, unsigned long request, void *argp);
|
||||
|
||||
IP_GLOBAL Ip_u16 iplite_next_ephemeral_port(void);
|
||||
IP_GLOBAL int iplite_queue_received_packet(Ipcom_pkt *pkt, Iplite_socket *sock);
|
||||
|
||||
IP_PUBLIC int iplite_do_socket(int domain, int type, int protocol, Ip_bool user_context);
|
||||
IP_GLOBAL int iplite_do_close(Iplite_socket *sock);
|
||||
IP_GLOBAL int iplite_do_bind(Iplite_socket *sock, IP_CONST struct Ip_sockaddr *name,
|
||||
Ip_socklen_t namelen, Ip_bool check_resuse);
|
||||
IP_PUBLIC int iplite_do_getname(int fd, struct Ip_sockaddr *name, Ip_socklen_t *namelenp, Ip_bool local);
|
||||
|
||||
IP_GLOBAL int
|
||||
iplite_do_socketselect(int nfds,
|
||||
Ip_fd_set *readfds,
|
||||
Ip_fd_set *writefds,
|
||||
Ip_fd_set *exceptfds,
|
||||
struct Ip_timeval *timeout);
|
||||
|
||||
IP_GLOBAL void iplite_sock_unbind(Iplite_socket *sock);
|
||||
IP_PUBLIC void iplite_sock_data_avail(Iplite_socket *sock, int so_errno, int how);
|
||||
IP_PUBLIC void iplite_sock_free(Iplite_socket *sock);
|
||||
IP_PUBLIC Ip_ssize_t ipcom_recvfrom_pktinfo(Ip_fd fd, void *buf, Ip_size_t len, int flags,
|
||||
struct Ip_sockaddr *from, Ip_socklen_t *fromlen, struct Ip_msghdr *msg);
|
||||
IP_PUBLIC Ip_ssize_t ipcom_sendto_pktinfo(Ip_fd fd, IP_CONST void *buf, Ip_size_t len, int flags,
|
||||
IP_CONST struct Ip_sockaddr *to, Ip_socklen_t tolen,
|
||||
IP_CONST struct Ip_msghdr *msg);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPLITE packet socket
|
||||
*===========================================================================
|
||||
*/
|
||||
#ifdef IPCOM_USE_PACKET
|
||||
IP_GLOBAL Ip_bool iplite_packet_input(Iplite_netif *netif, Ipcom_pkt *pkt);
|
||||
IP_GLOBAL int iplite_packet_output(Iplite_socket *sock, IP_CONST struct Ip_sockaddr *to, Ipcom_pkt *pkt);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_sockmsg.c,v $ $Revision: 1.9 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_sockmsg.c,v $
|
||||
* $Author: hxie $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* Functions for socket packet API.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_SKIP_NATIVE_SOCK_API
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_sock.h>
|
||||
#include "iplite_sock.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipcom_sendmsg
|
||||
*===========================================================================
|
||||
* Description: Simplistic wrapper sendmsg function (can't send control data).
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_ssize_t
|
||||
ipcom_sendmsg(Ip_fd fd, IP_CONST struct Ip_msghdr *msg, int flags)
|
||||
{
|
||||
Ip_u8 *buf;
|
||||
Ip_size_t i;
|
||||
Ip_size_t length;
|
||||
|
||||
/* Count the total length. */
|
||||
for (length = 0, i = 0; i < msg->msg_iovlen; i++)
|
||||
length += msg->msg_iov[i].iov_len;
|
||||
|
||||
buf = ipcom_malloc(length);
|
||||
if (buf == IP_NULL)
|
||||
return (Ip_ssize_t)ipcom_errno_set(IP_ERRNO_ENOMEM);
|
||||
|
||||
for (length = 0, i = 0; i < msg->msg_iovlen; i++)
|
||||
{
|
||||
ipcom_memcpy(buf + length, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len);
|
||||
length += msg->msg_iov[i].iov_len;
|
||||
}
|
||||
|
||||
i = ipcom_sendto_pktinfo(fd, buf, length, flags, msg->msg_name, msg->msg_namelen, msg);
|
||||
ipcom_free(buf);
|
||||
|
||||
return (Ip_ssize_t)i;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipcom_recvmsg
|
||||
*===========================================================================
|
||||
* Description: Receives data from a socket.
|
||||
* Parameters: fd - A socket descriptor.
|
||||
* msg - Receive parameters.
|
||||
* flags - Currently unused.
|
||||
* Returns: 0 = a packet was successfully received, -1 = error.
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_ssize_t
|
||||
ipcom_recvmsg(Ip_fd fd, struct Ip_msghdr *msg, int flags)
|
||||
{
|
||||
Ip_u8 *buf;
|
||||
Ip_size_t i;
|
||||
Ip_size_t bytes, length, copied;
|
||||
|
||||
/* No support for ancillary data */
|
||||
#ifndef IP_PORT_VXWORKS
|
||||
msg->msg_controllen = 0;
|
||||
#endif
|
||||
|
||||
/* Count the maximum total length. */
|
||||
for (length = 0, i = 0; i < msg->msg_iovlen; i++)
|
||||
length += msg->msg_iov[i].iov_len;
|
||||
|
||||
buf = ipcom_malloc(length);
|
||||
if (buf == IP_NULL)
|
||||
{
|
||||
#ifdef IP_PORT_VXWORKS
|
||||
msg->msg_controllen = 0;
|
||||
#endif
|
||||
return (Ip_ssize_t)ipcom_errno_set(IP_ERRNO_ENOMEM);
|
||||
}
|
||||
|
||||
length = ipcom_recvfrom_pktinfo(fd,
|
||||
buf,
|
||||
length,
|
||||
flags,
|
||||
msg->msg_name,
|
||||
(Ip_socklen_t *) &msg->msg_namelen,
|
||||
msg);
|
||||
if(length > 0)
|
||||
{
|
||||
for (copied = 0, i = 0; copied < length && i < msg->msg_iovlen; i++)
|
||||
{
|
||||
bytes = IP_MIN(length - copied, msg->msg_iov[i].iov_len);
|
||||
ipcom_memcpy(msg->msg_iov[i].iov_base, buf + copied, bytes);
|
||||
copied += bytes;
|
||||
}
|
||||
}
|
||||
#ifdef IP_PORT_VXWORKS
|
||||
else
|
||||
{
|
||||
msg->msg_controllen = 0;
|
||||
}
|
||||
#endif
|
||||
ipcom_free(buf);
|
||||
|
||||
return (Ip_ssize_t)length;
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipcom_socketwritev
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_ssize_t
|
||||
ipcom_socketwritev(Ip_fd fd, IP_CONST struct Ip_iovec *iov, int iovlen)
|
||||
{
|
||||
struct Ip_msghdr msghdr;
|
||||
|
||||
ipcom_memset(&msghdr, 0, sizeof(msghdr));
|
||||
msghdr.msg_iov = (struct Ip_iovec *) iov;
|
||||
msghdr.msg_iovlen = iovlen;
|
||||
|
||||
return ipcom_sendmsg(fd, &msghdr, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_sockpkt.c,v $ $Revision: 1.25.14.1 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_sockpkt.c,v $
|
||||
* $Author: xjiang1 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* Functions for socket packet API.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#if !defined(IPLITE_ONE_FILE) || defined(IPLITE_C)
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_inet.h>
|
||||
#include <ipcom_sock2.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_sock.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
IP_EXTERN Ipcom_slab_ctor ipnet_pkt_pool_hdr_ctor_func;
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_pkt_hdr_malloc
|
||||
*===========================================================================
|
||||
* Description: Receives a packet (zero-copy).
|
||||
* Parameters: fd - A socket descriptor.
|
||||
* pktp - Pointer to a packet pointer that will receive the packet.
|
||||
* flags - Currently unused.
|
||||
* from - The sender of the packet.
|
||||
* fromlen - The length of the from buffer.
|
||||
* Returns: 0 = a packet was successfully received, -1 = error.
|
||||
*
|
||||
*/
|
||||
#ifdef IPLITE_USE_EXTERNAL_PKT_BUF
|
||||
IP_GLOBAL Ipcom_pkt *
|
||||
iplite_pkt_hdr_malloc(int fcflags)
|
||||
{
|
||||
Ip_u32 isr;
|
||||
Ipcom_pkt *pkt;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
isr = ipcom_interrupt_disable();
|
||||
pkt = iplite.external_pkt_hdr_list;
|
||||
if (pkt != IP_NULL)
|
||||
{
|
||||
iplite.external_pkt_hdr_list = pkt->next;
|
||||
break;
|
||||
}
|
||||
else if (IP_BIT_ISFALSE(fcflags, IP_FLAG_FC_BLOCKOK))
|
||||
break;
|
||||
|
||||
iplite.pkt_pool_blocked++;
|
||||
ipcom_interrupt_enable(isr);
|
||||
if (IP_BIT_ISSET(fcflags, IP_FLAG_FC_STACKCONTEXT))
|
||||
IPLITE_CODE_UNLOCK();
|
||||
(void)ipcom_sem_wait(iplite.pkt_pool_sem);
|
||||
if (IP_BIT_ISSET(fcflags, IP_FLAG_FC_STACKCONTEXT))
|
||||
IPLITE_CODE_LOCK();
|
||||
}
|
||||
ipcom_interrupt_enable(isr);
|
||||
|
||||
if (pkt)
|
||||
{
|
||||
IPCOM_PKT_TRACE(pkt, IPCOM_PKT_ID_INIT);
|
||||
IPLITE_DEBUG_LINE(iplite_pkt_add_to_alloc_list(pkt));
|
||||
IPLITE_DEBUG_LINE(iplite_pkt_check(pkt));
|
||||
ipcom_pkt_create(pkt, IP_NULL, 0, IP_NULL, IP_NULL);
|
||||
}
|
||||
return pkt;
|
||||
}
|
||||
#endif /* IPLITE_USE_EXTERNAL_PKT_BUF */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipcom_pkt_add_hdr_to_pool
|
||||
*===========================================================================
|
||||
* Description: Allocates packet headers and put them in the pool.
|
||||
* Parameters: pkthdr_to_add - Number of packet headers to add.
|
||||
* Returns: 0 = success, < 0 = error code.
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
ipcom_pkt_add_hdr_to_pool(int pkthdr_to_add)
|
||||
{
|
||||
#ifdef IPLITE_USE_EXTERNAL_PKT_BUF
|
||||
Ipcom_pkt *pkt;
|
||||
Ipcom_pkt *first;
|
||||
Ip_u32 isr;
|
||||
Ip_size_t pkt_len;
|
||||
|
||||
pkt_len = sizeof(Ipcom_pkt) + ipcom_port_pkt_hdr_extra_size;
|
||||
|
||||
first = pkt = ipcom_calloc(pkthdr_to_add, pkt_len);
|
||||
if (pkt == IP_NULL)
|
||||
return -IP_ERRNO_ENOMEM;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
IPCOM_PKT_TRACE(pkt, IPCOM_PKT_ID_FREEQ);
|
||||
#ifdef IPCOM_VXWORKS_DRV_NULLPOOL
|
||||
ipnet_pkt_pool_hdr_ctor_func(IP_NULL, pkt);
|
||||
#endif
|
||||
if (--pkthdr_to_add == 0)
|
||||
break;
|
||||
|
||||
pkt->next = (Ipcom_pkt *) ((Ip_ptrdiff_t)pkt + pkt_len);
|
||||
pkt = pkt->next;
|
||||
}
|
||||
|
||||
isr = ipcom_interrupt_disable();
|
||||
pkt->next = iplite.external_pkt_hdr_list;
|
||||
iplite.external_pkt_hdr_list = first;
|
||||
ipcom_interrupt_enable(isr);
|
||||
|
||||
return 0;
|
||||
#else
|
||||
(void)pkthdr_to_add;
|
||||
return IP_ERRNO_ENOSUPPORT;
|
||||
#endif /* IPLITE_USE_EXTERNAL_PKT_BUF */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipcom_pkt_hdrspace
|
||||
*===========================================================================
|
||||
* Description: Get packet header space.
|
||||
* Parameters: fd - The socket descriptor to use when sending this packet.
|
||||
* Returns: >=0 = the number of octets that must be reserved for
|
||||
* transport, network and link header.
|
||||
* IP_SOCKERR = error, get the error from ipcom_errno.
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
ipcom_pkt_hdrspace(Ip_fd fd)
|
||||
{
|
||||
#ifdef IPLITE_USE_EXTERNAL_PKT_BUF
|
||||
int ret = IP_SOCKERR;
|
||||
Iplite_socket *sock;
|
||||
|
||||
IPLITE_CODE_LOCK();
|
||||
|
||||
sock = iplite.sockets[fd];
|
||||
if (sock == IP_NULL)
|
||||
SOCK_ERROUT(IP_ERRNO_EBADF);
|
||||
|
||||
if (sock->ipcom.type == IP_SOCK_STREAM)
|
||||
SOCK_ERROUT(IP_ERRNO_EPROTONOSUPPORT);
|
||||
|
||||
ret = ipcom_conf_max_link_hdr_size + sock->max_hdrspace;
|
||||
|
||||
errout:
|
||||
IPLITE_CODE_UNLOCK();
|
||||
return (int)ret;
|
||||
#else
|
||||
(void)fd;
|
||||
(void)ipcom_errno_set(IP_ERRNO_ENOSUPPORT);
|
||||
return (int)IP_SOCKERR;
|
||||
#endif /* IPLITE_USE_EXTERNAL_PKT_BUF */
|
||||
}
|
||||
|
||||
|
||||
#endif /* !defined(IPLITE_ONE_FILE) || defined(IPLITE_C) */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_sysctl.c,v $ $Revision: 1.5 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_sysctl.c,v $
|
||||
* $Author: hxie $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* Implementation of ipcom_sysctl().
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_sock.h>
|
||||
#include <ipcom_sock2.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_sysctl.h>
|
||||
#include <ipcom_errno.h>
|
||||
#include "iplite_h.h"
|
||||
#include "ipcom_sysctl.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipcom_sysctl
|
||||
*===========================================================================
|
||||
* Description: System control for IPLITE.
|
||||
* Parameters: name - the hierarchical sysctl name.
|
||||
* namelen - the size of the 'name' array.
|
||||
* oldp - buffer to where the route entries will be copied
|
||||
* oldlenp - [in] the length of 'oldp' buffer
|
||||
* [out] the number of bytes copied to 'oldp' buffer or
|
||||
* the number of bytes needed (if 'oldp' is IP_NULL).
|
||||
* newp - the new value for the variable
|
||||
* newlen - the length of the 'newp' buffer.
|
||||
* Returns: 0 == success, <0 == error code.
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
ipcom_sysctl(int *name, unsigned int namelen,
|
||||
void *oldp, Ip_size_t *oldlenp,
|
||||
void *newp, Ip_size_t newlen)
|
||||
{
|
||||
(void)name;
|
||||
(void)namelen;
|
||||
(void)oldp;
|
||||
(void)oldlenp;
|
||||
(void)newp;
|
||||
(void)newlen;
|
||||
(void)ipcom_errno_set(IP_ERRNO_ENOSUPPORT);
|
||||
return IP_SOCKERR;
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_getifaddrs
|
||||
*===========================================================================
|
||||
* Description: get all addresses.
|
||||
* Parameters: ifa - used to store addresses.
|
||||
* Returns: 0 == success, <0 == error code.
|
||||
*
|
||||
*/
|
||||
#ifdef IP_PORT_VXWORKS
|
||||
IP_PUBLIC int
|
||||
iplite_getifaddrs(struct Ip_ifaddrs **ifa)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET6
|
||||
int i;
|
||||
struct Ip_ifaddrs *faHead = IP_NULL;
|
||||
struct Ip_ifaddrs *faNew = IP_NULL;
|
||||
struct Ip_sockaddr_in6 * sin6Addr = IP_NULL;
|
||||
struct Iplite_ip6_addr_entry_struct *addrList = IP_NULL;
|
||||
IPLITE_CODE_LOCK();
|
||||
|
||||
for (i=0; i<IPLITE_CONF_MAX_NETIF; i++)
|
||||
{
|
||||
if ((iplite.netifs[i] == IP_NULL)
|
||||
|| (iplite.netifs[i]->inet6_addr_list == IP_NULL))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
addrList = iplite.netifs[i]->inet6_addr_list;
|
||||
while (addrList != IP_NULL)
|
||||
{
|
||||
faNew = (struct Ip_ifaddrs *)ipcom_malloc(sizeof(struct Ip_ifaddrs));
|
||||
ip_assert(faNew != IP_NULL);
|
||||
ipcom_memset(faNew, 0x00, sizeof(struct Ip_ifaddrs));
|
||||
faNew->ifa_next = faHead;
|
||||
faHead = faNew;
|
||||
faHead->ifa_addr = (struct Ip_sockaddr *)ipcom_malloc(sizeof(struct Ip_sockaddr_in6));
|
||||
memset(faHead->ifa_addr, 0x00, sizeof(struct Ip_sockaddr_in6));
|
||||
ip_assert(faNew != IP_NULL);
|
||||
faHead->ifa_addr->sa_family = IP_AF_INET6;
|
||||
faHead->ifa_name = ipcom_strdup(iplite.netifs[i]->ipcom.name);
|
||||
sin6Addr = (struct Ip_sockaddr_in6 *)faHead->ifa_addr;
|
||||
ipcom_memcpy(&sin6Addr->sin6_addr,
|
||||
&addrList->addr,
|
||||
sizeof(struct Ip_in6_addr));
|
||||
sin6Addr->sin6_family = IP_AF_INET6;
|
||||
|
||||
addrList = addrList->next;
|
||||
}
|
||||
|
||||
}
|
||||
IPLITE_CODE_UNLOCK();
|
||||
*ifa = faHead;
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
return IP_SOCKERR;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK API HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_sysctl.h,v $ $Revision: 1.2 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_sysctl.h,v $
|
||||
* $Author: hxie $ $Date: 2010-11-19 00:44:42 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPLITE_SYSCTL_H
|
||||
#define IPLITE_SYSCTL_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
/* IPNET sysctl */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipnet_cmd_sysctl
|
||||
*===========================================================================
|
||||
* Parameter struct used for registering IPNET base table.
|
||||
*/
|
||||
typedef struct Ipnet_cmd_sysctl_struct
|
||||
{
|
||||
const char *comp;
|
||||
|
||||
int type;
|
||||
int argument;
|
||||
|
||||
const struct Ipnet_cmd_sysctl_struct *ntable;
|
||||
int ctl[3];
|
||||
} Ipnet_cmd_sysctl;
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipnet_sysctl_get_base
|
||||
*===========================================================================
|
||||
* Description: This routine exposes the IPNET sysctl tree root node.
|
||||
* Parameters: None.
|
||||
* Returns: A pointer to Ipnet_cmd_sysctl
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ipnet_cmd_sysctl * ipnet_sysctl_get_base(void);
|
||||
#ifdef IP_PORT_VXWORKS
|
||||
IP_PUBLIC int iplite_getifaddrs(struct Ip_ifaddrs **ifa);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* IPNET_SYSCTL_H */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,382 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_tcp.h,v $ $Revision: 1.2 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_tcp.h,v $
|
||||
* $Author: kenneth $ $Date: 2009-10-21 07:53:36 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPLITE_TCP_H
|
||||
#define IPLITE_TCP_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_config.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite.h"
|
||||
#include "iplite_sock.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* TCP control flags */
|
||||
#define IPLITE_TCPC_FLAG_PASSIVE_OPEN (1 << 0) /* This is a listen socket */
|
||||
#define IPLITE_TCPC_FLAG_SOCK_CLOSED (1 << 1) /* The TCP module has closed the socket */
|
||||
#define IPLITE_TCPC_FLAG_CONNABORTED (1 << 2) /* User process has called close, but data was present */
|
||||
#define IPLITE_TCPC_FLAG_SMALL_PKT_OUT (1 << 3) /* 1 small (less that MSS) packet outstanding */
|
||||
|
||||
#define IPLITE_TCPC_FLAG_NO_SMDE (1 << 6) /* No Smooth mean deviation estimator calculated yet */
|
||||
#define IPLITE_TCPC_FLAG_RTT (1 << 7) /* Round Trip Time mesurement in progress */
|
||||
#define IPLITE_TCPC_FLAG_ACK_PENDING (1 << 8) /* An immediate ack pending */
|
||||
#define IPLITE_TCPC_FLAG_DACK_PENDING (1 << 9) /* A delayed acknowledge is pending */
|
||||
#define IPLITE_TCPC_FLAG_PERS_PENDING (1 << 10) /* A persist timer is running */
|
||||
#define IPLITE_TCPC_FLAG_KEEP_PENDING (1 << 11) /* A keep alive timer is running */
|
||||
#define IPLITE_TCPC_FLAG_FIN_PENDING (1 << 12) /* User process has called close, but data was present */
|
||||
#define IPLITE_TCPC_FLAG_TIMESTAMP_OPT (1 << 13) /* Include timestamp option */
|
||||
#define IPLITE_TCPC_FLAG_WND_SCALE_OPT (1 << 14) /* Include window scaling option */
|
||||
#define IPLITE_TCPC_FLAG_RESENDING (1 << 15) /* A resend timer has expired, send packets from the
|
||||
resend queue instead of the send queue */
|
||||
#define IPLITE_TCPC_FLAG_FAST_RETRANS (1 << 16) /* The oldest non-acked segment has been fast retransmitted */
|
||||
#define IPLITE_TCPC_FLAG_SENDER_URG (1 << 18) /* The this socket is in sender urgent mode */
|
||||
#define IPLITE_TCPC_FLAG_RECEIVER_URG (1 << 19) /* The this socket is in receiver urgent mode */
|
||||
#define IPLITE_TCPC_FLAG_CORK (1 << 21) /* Do not send any frames less than a MSS if this is set */
|
||||
#define IPLITE_TCPC_FLAG_RFC_1122_URG (1 << 24) /* Use the definition of urgen data described in RFC 1122, else use RFC 793*/
|
||||
#define IPLITE_TCPC_FLAG_KCLOSE_PENDING (1 << 25) /* iplite_sock_kclose() function must be called
|
||||
when user closes socket */
|
||||
#define IPLITE_TCPC_FLAG_USER_REF (1 << 26) /* This socket has been given to a user via
|
||||
socket() or accept() */
|
||||
#define IPLITE_TCPC_USER_CLOSED (1 << 27) /* A user task has called close() on this socket.
|
||||
The TCB will is on the user_closed_sock list. */
|
||||
|
||||
/* Size of a TCP header without options */
|
||||
#define IPLITE_TCP_HDR_SIZE 20 /* Default/minimum TCP header is 20 octets long */
|
||||
|
||||
#define IP_SHUT_EX (IP_SHUT_RDWR + 10)
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* TCP states (numeric values match those in RFC2452) */
|
||||
typedef enum Iplite_tcp_state_enum
|
||||
{
|
||||
IPLITE_TCPS_CLOSED = 1,
|
||||
IPLITE_TCPS_LISTEN = 2,
|
||||
IPLITE_TCPS_SYN_SENT = 3,
|
||||
IPLITE_TCPS_SYN_RCVD = 4,
|
||||
IPLITE_TCPS_ESTABLISHED = 5,
|
||||
IPLITE_TCPS_CLOSE_WAIT = 6,
|
||||
IPLITE_TCPS_FIN_WAIT_1 = 7,
|
||||
IPLITE_TCPS_CLOSING = 8,
|
||||
IPLITE_TCPS_LAST_ACK = 9,
|
||||
IPLITE_TCPS_FIN_WAIT_2 = 10,
|
||||
IPLITE_TCPS_TIME_WAIT = 11,
|
||||
IPLITE_TCPS_DELETE_TCB = 12
|
||||
}
|
||||
Iplite_tcp_state_t;
|
||||
|
||||
|
||||
/* Timeout type */
|
||||
typedef enum Iplite_tcp_timo_enum {
|
||||
IPLITE_TCP_TIMO_NONE = 0, /* Placeholder that means: do not add a timer */
|
||||
IPLITE_TCP_TIMO_CONN = 1, /* Connection Establishment */
|
||||
IPLITE_TCP_TIMO_RETR = 2, /* Retransmission */
|
||||
IPLITE_TCP_TIMO_DACK = 3, /* Delayed Acknowledge */
|
||||
IPLITE_TCP_TIMO_PERS = 4, /* Persist */
|
||||
IPLITE_TCP_TIMO_LOPE = 5, /* Lost peer (used during shutdown to avoid dead sockets) */
|
||||
IPLITE_TCP_TIMO_TIWA = 6, /* TIME_WAIT */
|
||||
IPLITE_TCP_TIMO_KEEP = 7, /* Keep-alive */
|
||||
IPLITE_TCP_TIMO_LNGR = 8, /* Linger timer */
|
||||
IPLITE_TCP_TIMO_RSRT = 9, /* Restart the 'send-FIN' call */
|
||||
IPLITE_TCP_TIMO_ACK = 10, /* Immediate ACK pending */
|
||||
IPLITE_TCP_TIMO_RCON = 11 /* Retry connect */
|
||||
} Iplite_tcp_timo_t;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Parameters for one TCP segment
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef struct Iplite_tcp_segment_struct
|
||||
{
|
||||
struct Iplite_tcp_segment_struct *next;
|
||||
/* Next packet in resend list for outgoing and next
|
||||
out-of-order package for incoming */
|
||||
Ipcom_pkt *pkt; /* Pointer to the packet that holds the TCP segment data */
|
||||
Ip_u32 seq_start; /* First sequence number for segment */
|
||||
Ip_u32 seq_end; /* Last sequence number for segment */
|
||||
int app_start; /* (Only send) Start of application data */
|
||||
int app_end; /* (Only send) End of application data */
|
||||
Ip_u16 flags_n; /* The TCP flags for this segment */
|
||||
Ip_u32 last_msec; /* Last timestamp this segment was processed */
|
||||
}
|
||||
Iplite_tcp_segment;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_tcp_notifycb
|
||||
*===========================================================================
|
||||
* Description: Is called when an event happens that can affect any of
|
||||
* socket parameters
|
||||
* Parameters: sock - The affected socket.
|
||||
* event - One of the IPNET_SOCKET_EVENT_xxx constants
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
typedef void (*Iplite_tcp_notifycb)(Iplite_socket *sock, int event);
|
||||
|
||||
/* Possible socket events */
|
||||
#define IPLITE_SOCKET_EVENT_PATH_MTU 1 /* The path MTU has changed */
|
||||
#define IPLITE_SOCKET_EVENT_KICKSTART 2 /* Try 'kickstart' this particular socket */
|
||||
|
||||
|
||||
typedef Iplite_socket * (*Iplite_tcp_socklookup)(int proto,
|
||||
IP_CONST void *local_addr,
|
||||
Ip_u16 local_port,
|
||||
IP_CONST void *peer_addr,
|
||||
Ip_u16 peer_port,
|
||||
int rtab_index,
|
||||
int *first);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* TCB sending parameters
|
||||
*===========================================================================
|
||||
*/
|
||||
struct Iplite_tcp_send
|
||||
{
|
||||
Ip_u32 seq_next; /* The sequence number of next byte to
|
||||
send */
|
||||
Ip_u32 seq_small; /* The last +1 sequence number in the last
|
||||
packet sent smaller than MSS */
|
||||
Ip_u32 uack_bytes; /* Number of unacknowledged data bytes
|
||||
outstanding */
|
||||
Ip_u32 peerwnd; /* Maximum number of bytes that the peer
|
||||
is ready to receive */
|
||||
Ip_u32 cwnd; /* Congestion windows in bytes */
|
||||
Ip_u32 ssthresh; /* Slow Start Threshold size (in bytes) */
|
||||
Ip_u32 lowat; /* The low water mark for sending */
|
||||
Ip_u32 urg_ptr; /* Urgent pointer, only valid if in send
|
||||
urgent mode () */
|
||||
Ip_u16 last_wnd; /* Value of the last sent recv window size */
|
||||
Ip_u8 wnd_scale; /* RFC1323 window scale shift, == 0 on
|
||||
<SYN,ACK> means to not use window
|
||||
scaling option */
|
||||
Ipcom_pkt *head; /* The send buffer, can contain multiple
|
||||
unsent packets, pkt->start is the
|
||||
offset to the application layer
|
||||
data. Head of send queue */
|
||||
Ipcom_pkt *tail; /* Tail of send queue */
|
||||
Ipcom_pkt *partial; /* Last sent packet that does not contain
|
||||
a full MSS of data */
|
||||
|
||||
struct Iplite_tcp_segment_struct *resend_head; /* List of sent segments
|
||||
for which an ack has
|
||||
not been received. */
|
||||
struct Iplite_tcp_segment_struct *resend_tail; /* The list is sorted on
|
||||
increasing sequence
|
||||
number */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* TCB receiving parameters
|
||||
*===========================================================================
|
||||
*/
|
||||
struct Iplite_tcp_recv
|
||||
{
|
||||
Ip_u32 seq_next; /* The start sequence number of the
|
||||
next expected TCP segment sent from
|
||||
the peer */
|
||||
Ip_u32 last_ack_sent; /* The last received sequence number
|
||||
that an ACK has been sent for */
|
||||
Ip_u32 lowat; /* The low water mark for receiving */
|
||||
Ip_u32 urg_ptr; /* Urgent pointer, only valid if in
|
||||
receive urgent mode () */
|
||||
Ip_u8 wnd_scale; /* RFC1323 window scale shift, == 0 on
|
||||
<SYN,ACK> means to not use window
|
||||
scaling option */
|
||||
struct Iplite_tcp_segment_struct *out_of_order_seg; /* Segments
|
||||
received, but was out of order. Will be
|
||||
moved to the received queue when the
|
||||
missing segment(s) are received */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* TCB (Transmission Control Block)
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef struct Iplite_tcp_tcb_struct
|
||||
{
|
||||
Iplite_socket *sock; /* The socket associated with this TCB */
|
||||
Ipcom_list transient; /* List of TCB:s in transient states */
|
||||
Ipcom_list closed; /* List of TCP sockets for which the
|
||||
user application has called close() */
|
||||
|
||||
Ip_u32 flags; /* IPLITE_TCPC_FLAG_xxx flags */
|
||||
Iplite_tcp_state_t state; /* The current state of the TCP connection */
|
||||
Ip_u8 duplicate_ack;/* Number of duplicate acks received */
|
||||
Ip_u8 retr_count; /* Number of retransmission timeouts */
|
||||
Ip_u8 peer_responded_to_pers; /* The peer has responded at least one time
|
||||
since the presist timer was last reset */
|
||||
Ip_u16 mss; /* Maximum Segment Size for the connection */
|
||||
Ip_u16 peer_mss; /* Maximum Segment Size presented by the peer */
|
||||
Ip_u16 max_mss; /* User set maximum mss or 0 to use the largest possible MSS */
|
||||
Ip_u32 sec_to_linger;/* Time this socket will linger after close */
|
||||
|
||||
int keepidle; /* Number of seconds an TCP connection must be
|
||||
idle before the first keep-alive probe is sent */
|
||||
Ip_u16 keepintvl; /* Interval between keep-alive probes */
|
||||
Ip_u16 keepcnt; /* Number of keep-alive probes before dropping connection */
|
||||
|
||||
Iplite_timeout *tmo_pers;
|
||||
Iplite_timeout *tmo_keep;
|
||||
Iplite_timeout *tmo_lngr;
|
||||
Iplite_timeout *tmo_rsrt;
|
||||
Iplite_timeout *tmo_dack;
|
||||
Iplite_timeout *tmo_retr;
|
||||
Iplite_timeout *tmo;
|
||||
|
||||
Ip_s32 srtt; /* Smoothed Round Trip Time in microseconds */
|
||||
Ip_s32 smde; /* Smooth mean deviation estimator in ticks (scaled as srtt) */
|
||||
Ip_s32 rto; /* Retransmission timeout (scaled as srtt) */
|
||||
Ip_u32 msec_sent; /* Absolute time when a timed data segment was sent */
|
||||
Ip_u32 seq_timed; /* A sequence number of the first data byte in the timed segment */
|
||||
struct Iplite_tcp_send send;
|
||||
struct Iplite_tcp_recv recv;
|
||||
int soft_error; /* Error code to use if this connections timeout */
|
||||
|
||||
Iplite_socket *parent; /* The listen socket that was used to create this socket */
|
||||
Ip_u16 backlog_len; /* Maximum number of entries in the backlog */
|
||||
Ip_u16 backlog_used; /* Number of used entries (pending + done) in the backlog */
|
||||
int *backlog_pending;/* Connections that are doing the three-way handshake */
|
||||
int *backlog_done; /* Connections that have finished the three-way handshake */
|
||||
|
||||
Ip_u32 (*get_mss)(Iplite_socket *sock);
|
||||
|
||||
#ifdef IPLITE_DEBUG
|
||||
/* The last tick when the calculated roundtrip time was printed */
|
||||
Ip_u32 rtt_last_printed;
|
||||
#endif /* IPLITE_DEBUG */
|
||||
|
||||
}
|
||||
Iplite_tcp_tcb;
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC int iplite_tcp_create(void);
|
||||
IP_PUBLIC int iplite_tcp_start(void);
|
||||
IP_PUBLIC const char *iplite_tcp_version(void);
|
||||
|
||||
IP_PUBLIC Iplite_tcp_state_t iplite_tcp_get_state(Iplite_socket *sock);
|
||||
IP_PUBLIC int iplite_tcp_input(Ipcom_pkt *pkt,
|
||||
IP_CONST void *src_addr,
|
||||
IP_CONST void *dst_addr,
|
||||
Iplite_socklookup socklookup);
|
||||
IP_PUBLIC void iplite_tcp_sock_init(Iplite_socket *sock);
|
||||
IP_PUBLIC int iplite_tcp_connect(Iplite_socket *sock);
|
||||
IP_PUBLIC void iplite_tcp_shutdown(Iplite_socket *sock, int how);
|
||||
IP_PUBLIC int iplite_tcp_close(Iplite_socket *sock);
|
||||
IP_PUBLIC void iplite_tcp_sock_free(Iplite_socket *sock);
|
||||
IP_PUBLIC int iplite_tcp_usr_send(Iplite_socket *sock,
|
||||
IP_CONST void *buf,
|
||||
Ip_size_t len,
|
||||
int flags);
|
||||
IP_PUBLIC int iplite_tcp_usr_recv(Iplite_socket *sock, void *buf, Ip_size_t len, int flags);
|
||||
IP_PUBLIC int iplite_tcp_listen(Iplite_socket *sock, int backlog);
|
||||
IP_PUBLIC int iplite_tcp_accept(Iplite_socket *sock, struct Ip_sockaddr *name, Ip_socklen_t *addrlen);
|
||||
IP_PUBLIC int iplite_tcp_getsockopt(Iplite_socket *sock, int level, int optname, void *optval, Ip_socklen_t *optlen);
|
||||
IP_PUBLIC int iplite_tcp_setsockopt(Iplite_socket *sock, int level, int optname, IP_CONST void *optval, Ip_socklen_t optlen);
|
||||
IP_PUBLIC int iplite_tcp_drop_connection(Iplite_socket *sock, int error_code);
|
||||
IP_PUBLIC void iplite_tcp_pkt_drain(void);
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
IP_PUBLIC void iplite_tcp_icmp4_report(Iplite_socket *sock, int type, int code, void *tcp_hdr);
|
||||
#endif
|
||||
#ifdef IPCOM_USE_INET6
|
||||
IP_PUBLIC void iplite_tcp_icmp6_report(Iplite_socket *sock, int type, int code, void *tcp_hdr);
|
||||
#endif
|
||||
|
||||
IP_PUBLIC int iplite_tcp_ioctl(Iplite_socket *sock, unsigned long request, void *argp);
|
||||
|
||||
#ifdef IPCOM_USE_MIB2
|
||||
IP_PUBLIC int iplite_tcp_get_rto(Ip_bool min);
|
||||
IP_PUBLIC int iplite_tcp_change_state_global(Iplite_socket *sock, int new_state);
|
||||
#endif /* IPCOM_USE_MIB2 */
|
||||
|
||||
#ifdef IPLITE_DEBUG
|
||||
IP_PUBLIC void iplite_tcp_pkt_freecheck(Ipcom_pkt *pkt);
|
||||
|
||||
IP_PUBLIC Ip_fd iplite_tcp_ctrl_verify_retransq(Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Ip_fd iplite_tcp_ctrl_verify_sockrecvq(Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Ip_fd iplite_tcp_ctrl_verify_sockooorecvq(Ipcom_pkt *pkt);
|
||||
#endif
|
||||
|
||||
IP_GLOBAL int iplite_tcp_send_reset(IP_CONST void *peer_addr,
|
||||
IP_CONST void *local_addr,
|
||||
Iplite_socket *sock,
|
||||
Iplite_tcp_segment *seg);
|
||||
|
||||
IP_GLOBAL IP_CONST char *iplite_tcp_state_to_str(Iplite_tcp_state_t state);
|
||||
IP_GLOBAL IP_CONST char *iplite_tcp_timer_to_str(Iplite_tcp_timo_t type);
|
||||
|
||||
IP_GLOBAL int iplite_tcp_pers_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len);
|
||||
IP_GLOBAL int iplite_tcp_keep_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len);
|
||||
IP_GLOBAL int iplite_tcp_conn_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len);
|
||||
IP_GLOBAL int iplite_tcp_dack_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len);
|
||||
IP_GLOBAL int iplite_tcp_retr_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len);
|
||||
IP_GLOBAL int iplite_tcp_tiwa_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len);
|
||||
IP_GLOBAL int iplite_tcp_lope_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len);
|
||||
IP_GLOBAL int iplite_tcp_lngr_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* IPLITE_TCP_H */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,536 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_tcp_debug.c,v $ $Revision: 1.2 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_tcp_debug.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
|
||||
#include "iplite_tcp.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_state_to_str
|
||||
*===========================================================================
|
||||
* Description: Returns a string representation of the state.
|
||||
* Parameters: state - One of the TCP states.
|
||||
* Returns: A string representation of the state.
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL IP_CONST char *
|
||||
iplite_tcp_state_to_str(Iplite_tcp_state_t state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case IPLITE_TCPS_CLOSED:
|
||||
return "CLOSED";
|
||||
case IPLITE_TCPS_LISTEN:
|
||||
return "LISTEN";
|
||||
case IPLITE_TCPS_SYN_SENT:
|
||||
return "SYN_SENT";
|
||||
case IPLITE_TCPS_SYN_RCVD:
|
||||
return "SYN_RECV";
|
||||
case IPLITE_TCPS_ESTABLISHED:
|
||||
return "ESTABLISHED";
|
||||
case IPLITE_TCPS_CLOSE_WAIT:
|
||||
return "CLOSE_WAIT";
|
||||
case IPLITE_TCPS_FIN_WAIT_1:
|
||||
return "FIN_WAIT_1";
|
||||
case IPLITE_TCPS_CLOSING:
|
||||
return "CLOSING";
|
||||
case IPLITE_TCPS_LAST_ACK:
|
||||
return "LAST_ACK";
|
||||
case IPLITE_TCPS_FIN_WAIT_2:
|
||||
return "FIN_WAIT_2";
|
||||
case IPLITE_TCPS_TIME_WAIT:
|
||||
return "TIME_WAIT";
|
||||
case IPLITE_TCPS_DELETE_TCB:
|
||||
return "DELETE_TCB";
|
||||
default:
|
||||
return "Unknown state";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_timer_to_str
|
||||
*===========================================================================
|
||||
* Description: Returns a string representation of the timer type.
|
||||
* Parameters: state - One of the TCP timer types.
|
||||
* Returns: A string representation.
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL IP_CONST char *
|
||||
iplite_tcp_timer_to_str(Iplite_tcp_timo_t type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case IPLITE_TCP_TIMO_CONN:
|
||||
return "CONN";
|
||||
case IPLITE_TCP_TIMO_RETR:
|
||||
return "RETR";
|
||||
case IPLITE_TCP_TIMO_DACK:
|
||||
return "DACK";
|
||||
case IPLITE_TCP_TIMO_ACK:
|
||||
return "ACK";
|
||||
case IPLITE_TCP_TIMO_PERS:
|
||||
return "PERS";
|
||||
case IPLITE_TCP_TIMO_LOPE:
|
||||
return "LOPE";
|
||||
case IPLITE_TCP_TIMO_TIWA:
|
||||
return "TIWA";
|
||||
case IPLITE_TCP_TIMO_KEEP:
|
||||
return "KEEP";
|
||||
case IPLITE_TCP_TIMO_LNGR:
|
||||
return "LNGR";
|
||||
case IPLITE_TCP_TIMO_RSRT:
|
||||
return "RSRT";
|
||||
default:
|
||||
return "Unkown timer type";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef IPLITE_DEBUG
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_to_string
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iplite_tcp_to_string(Iplite_socket *sock, const char *type, char *buf, Ip_size_t buf_len)
|
||||
{
|
||||
return ipcom_snprintf(buf, buf_len, "TCP %s timer on socket %d",
|
||||
type, sock->ipcom.fd);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_pers_to_string
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_tcp_pers_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len)
|
||||
{
|
||||
int offset = iplite_tcp_to_string(sock, "persist", buf, buf_len);
|
||||
offset += ipcom_snprintf(&buf[offset], buf_len - offset, " response %sseen retrans %u",
|
||||
sock->tcb->peer_responded_to_pers ? "" : "not ",
|
||||
sock->tcb->retr_count);
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_keep_to_string
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_tcp_keep_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len)
|
||||
{
|
||||
return iplite_tcp_to_string(sock, "keep-alive", buf, buf_len);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_conn_to_string
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_tcp_conn_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len)
|
||||
{
|
||||
return iplite_tcp_to_string(sock, "connection", buf, buf_len);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_dack_to_string
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_tcp_dack_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len)
|
||||
{
|
||||
return iplite_tcp_to_string(sock, "delayed ack", buf, buf_len);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_retr_to_string
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_tcp_retr_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len)
|
||||
{
|
||||
Iplite_tcp_tcb *tcb = sock->tcb;
|
||||
Iplite_tcp_segment *seg = tcb->send.resend_head;
|
||||
int offset;
|
||||
|
||||
if (seg == IP_NULL)
|
||||
return 0;
|
||||
offset = iplite_tcp_to_string(sock, "retransmission", buf, buf_len);
|
||||
offset += ipcom_snprintf(&buf[offset], buf_len - offset, " seg %u retrans %u",
|
||||
(unsigned) seg->seq_start,
|
||||
tcb->retr_count);
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_tiwa_to_string
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_tcp_tiwa_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len)
|
||||
{
|
||||
return iplite_tcp_to_string(sock, "time wait", buf, buf_len);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_lope_to_string
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_tcp_lope_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len)
|
||||
{
|
||||
return iplite_tcp_to_string(sock, "lost peer", buf, buf_len);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_lngr_to_string
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_tcp_lngr_to_string(Iplite_socket *sock, char *buf, Ip_size_t buf_len)
|
||||
{
|
||||
return iplite_tcp_to_string(sock, "linger", buf, buf_len);
|
||||
}
|
||||
#endif /* IPLITE_DEBUG */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPLITE_DEBUG
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_pkt_freecheck
|
||||
*===========================================================================
|
||||
* Description: Called from ipcom_pkt_free to verify pkt not in timerlist.
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC void
|
||||
iplite_tcp_pkt_freecheck(Ipcom_pkt *pkt)
|
||||
{
|
||||
Ip_u32 isr;
|
||||
int i;
|
||||
Iplite_tcp_segment *tcp_seg;
|
||||
Ipcom_pkt *spkt;
|
||||
|
||||
isr = ipcom_interrupt_disable();
|
||||
|
||||
if (IPCOM_PKT_HAS_MULTIPLE_OWNERS(pkt) == IP_FALSE)
|
||||
{
|
||||
for (i = 0; i < IPLITE_CONF_MAX_SOCKETS; i++)
|
||||
{
|
||||
if (iplite.sockets[i] == IP_NULL || iplite.sockets[i]->tcb == IP_NULL)
|
||||
continue;
|
||||
for (tcp_seg = iplite.sockets[i]->tcb->send.resend_head;
|
||||
tcp_seg != IP_NULL;
|
||||
tcp_seg = tcp_seg->next)
|
||||
{
|
||||
ip_assert(pkt != tcp_seg->pkt);
|
||||
}
|
||||
for (spkt = iplite.sockets[i]->tcb->send.head;
|
||||
spkt != IP_NULL;
|
||||
spkt = spkt->next)
|
||||
{
|
||||
ip_assert(spkt != pkt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ipcom_interrupt_enable(isr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_ctrl_verify_retransq
|
||||
*===========================================================================
|
||||
* Description: Verifies that a packet can be found in the retransmission
|
||||
* queue on one of the TCP sockets.
|
||||
* Parameters: pkt - Packet to find.
|
||||
* Returns: The socket descriptor where the packet is in retrasmission queue.
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_fd
|
||||
iplite_tcp_ctrl_verify_retransq(Ipcom_pkt *pkt)
|
||||
{
|
||||
int i;
|
||||
Iplite_socket *sock;
|
||||
Iplite_tcp_segment *seg;
|
||||
|
||||
for (i = 0; i < IPLITE_CONF_MAX_SOCKETS; i++)
|
||||
{
|
||||
sock = iplite.sockets[i];
|
||||
if (sock == IP_NULL || sock->tcb == IP_NULL)
|
||||
/* Not a TCP socket */
|
||||
continue;
|
||||
|
||||
for (seg = sock->tcb->send.resend_head; seg != IP_NULL; seg = seg->next)
|
||||
{
|
||||
if (seg->pkt == pkt)
|
||||
return sock->ipcom.fd;
|
||||
}
|
||||
}
|
||||
return IP_SOCKERR;
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_ctrl_verify_sockrecvq
|
||||
*===========================================================================
|
||||
* Description: Verifies that a packet can be found in the receive
|
||||
* queue on one of the sockets.
|
||||
* Parameters: pkt - Packet to find.
|
||||
* Returns: The socket descriptor where the packet is queued.
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_fd
|
||||
iplite_tcp_ctrl_verify_sockrecvq(Ipcom_pkt *pkt)
|
||||
{
|
||||
int i;
|
||||
Iplite_socket *sock;
|
||||
Ipcom_pkt *rpkt;
|
||||
|
||||
for (i = 0; i < IPLITE_CONF_MAX_SOCKETS; i++)
|
||||
{
|
||||
sock = iplite.sockets[i];
|
||||
if (sock == IP_NULL)
|
||||
continue;
|
||||
if (sock->tcb == IP_NULL)
|
||||
rpkt = sock->rcv_head;
|
||||
else
|
||||
rpkt = sock->rcv_head;
|
||||
|
||||
for (; rpkt != IP_NULL; rpkt = rpkt->next)
|
||||
{
|
||||
if (rpkt == pkt)
|
||||
return sock->ipcom.fd;
|
||||
}
|
||||
}
|
||||
return IP_SOCKERR;
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_ctrl_verify_sockooorecvq
|
||||
*===========================================================================
|
||||
* Description: Verifies that a packet can be found in the receive queue
|
||||
* for out-of-order packets on one of the TCP sockets.
|
||||
* Parameters: pkt - Packet to find.
|
||||
* str - Buffer to print the status.
|
||||
* Returns: The socket descriptor where the packet is queued in the
|
||||
* out-of-order queue.
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_fd
|
||||
iplite_tcp_ctrl_verify_sockooorecvq(Ipcom_pkt *pkt)
|
||||
{
|
||||
int i;
|
||||
Iplite_socket *sock;
|
||||
Iplite_tcp_segment *seg;
|
||||
|
||||
for (i = 0; i < IPLITE_CONF_MAX_SOCKETS; i++)
|
||||
{
|
||||
sock = iplite.sockets[i];
|
||||
if (sock == IP_NULL || sock->tcb == IP_NULL)
|
||||
/* Not a TCP socket */
|
||||
continue;
|
||||
|
||||
for (seg = sock->tcb->recv.out_of_order_seg; seg != IP_NULL; seg = seg->next)
|
||||
{
|
||||
if (seg->pkt == pkt)
|
||||
return sock->ipcom.fd;
|
||||
}
|
||||
}
|
||||
return IP_SOCKERR;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_tcp_print_tcb_flags
|
||||
*===========================================================================
|
||||
* Description: Converts the flags field from a TCB to a human readable form
|
||||
* Parameters: flags - flags from the TCB field of a TCP socket.
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
#ifdef NOT_CALLED_BY_ANY_OTHER_FUNCTION
|
||||
IP_PUBLIC void
|
||||
iplite_tcp_print_tcb_flags(Ip_u32 flags)
|
||||
{
|
||||
printf("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
|
||||
flags & IPLITE_TCPC_FLAG_PASSIVE_OPEN ? "PASSIVE_OPEN\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_SOCK_CLOSED ? "SOCK_CLOSED\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_CONNABORTED ? "CONNABORTED\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_SMALL_PKT_OUT ? "SMALL_PKT_OUT\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_NO_SMDE ? "NO_SMDE\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_RTT ? "RTT\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_ACK_PENDING ? "ACK_PENDING\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_DACK_PENDING ? "DACK_PENDING\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_PERS_PENDING ? "PERS_PENDING\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_KEEP_PENDING ? "KEEP_PENDING\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_FIN_PENDING ? "FIN_PENDING\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_TIMESTAMP_OPT ? "TIMESTAMP_OPT\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_WND_SCALE_OPT ? "WND_SCALE_OPT\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_RESENDING ? "RESENDING\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_FAST_RETRANS ? "FAST_RETRANS\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_SENDER_URG ? "SENDER_URG\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_RECEIVER_URG ? "RECVEIVER_URG\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_CORK ? "CORK\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_RFC_1122_URG ? "RFC_1122_URG\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_KCLOSE_PENDING ? "KCLOSE_PENDING\n" : "",
|
||||
flags & IPLITE_TCPC_FLAG_USER_REF ? "USER_REF\n" : "");
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* IPLITE_DEBUG */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK API HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_timeout.h,v $ $Revision: 1.2 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_timeout.h,v $
|
||||
* $Author: kenneth $ $Date: 2007-05-29 13:40:54 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth.jonsson@windriver.com>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPLITE_TIMEOUT_H
|
||||
#define IPLITE_TIMEOUT_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* set/get the timeout structure (if any) used for this fragment
|
||||
*/
|
||||
#define IPLITE_PKT_GET_TMO(pkt) ((Iplite_timeout *) (pkt)->link_cookie)
|
||||
#define IPLITE_PKT_GET_TMO_PTR(pkt) ((Iplite_timeout **) &(pkt)->link_cookie)
|
||||
#define IPLITE_PKT_SET_TMO(pkt, timeo) ((pkt)->link_cookie = (Ip_u32) (timeo))
|
||||
|
||||
/*
|
||||
* set/get the absolute time (in seconds) when this fragment times out.
|
||||
*/
|
||||
#define IPLITE_PKT_GET_TIMEOUT(pkt) ((pkt)->chk - iplite.seconds)
|
||||
#define IPLITE_PKT_GET_TIMEOUT_ABS(pkt) ((pkt)->chk)
|
||||
#define IPLITE_PKT_SET_TIMEOUT_ABS(pkt, timeo) ((pkt)->chk = (timeo))
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* Signature of timeout handler */
|
||||
typedef void (*Iplite_timeout_handler)(void *cookie);
|
||||
|
||||
typedef struct Iplite_timeout_struct
|
||||
{
|
||||
int pq_index; /* The index this timout has in the priority queue */
|
||||
Ip_u32 msec; /* The absolute time when this timeout is triggered */
|
||||
Iplite_timeout_handler handler; /* The function that will be called when
|
||||
the current time is equal to 'timeout_msec' */
|
||||
void *cookie; /* The (user specified) argument to the handler */
|
||||
struct Iplite_timeout_struct **ptmo; /* Pointer to the location the caller has stored the
|
||||
Ipnet_timeout handler, that location will be set to
|
||||
IP_NULL when the timer expires or is cancled. */
|
||||
}
|
||||
Iplite_timeout;
|
||||
|
||||
|
||||
/* Signature of soft IRQ handler */
|
||||
typedef void (*Iplite_soft_irq_handler)(void *cookie);
|
||||
|
||||
typedef struct Iplite_soft_irq_struct
|
||||
{
|
||||
struct Iplite_soft_irq_struct *next; /* Points to the next soft interrupt */
|
||||
Ip_bool pending; /* IP_TRUE if this is currently in the list
|
||||
of pending soft interrupts */
|
||||
Iplite_soft_irq_handler handler; /* The function that will handle this soft interrupt */
|
||||
void *cookie; /* The argument to the handler */
|
||||
}
|
||||
Iplite_soft_irq;
|
||||
|
||||
#define IPLITE_PKT_TO_SOFT_IRQ_STRUCT(pkt) ((Iplite_soft_irq *) (&(pkt)->data[4]))
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_GLOBAL void iplite_schedule_soft_interrupt(Iplite_soft_irq *soft_irq, Ip_bool irq_is_enabled);
|
||||
IP_GLOBAL int iplite_timeout_schedule(Ip_u32 msec_to_timeout,
|
||||
Iplite_timeout_handler handler,
|
||||
void *cookie,
|
||||
Iplite_timeout **ptmo);
|
||||
IP_GLOBAL void iplite_timeout_cancel(Iplite_timeout *tmo);
|
||||
IP_GLOBAL Ip_u32 iplite_timeout_msec_until(Iplite_timeout *tmo);
|
||||
IP_GLOBAL Ip_u32 iplite_msec_now(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,332 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_udp.c,v $ $Revision: 1.23 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_udp.c,v $
|
||||
* $Author: hxie $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* User datagram protocol transport layer */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#if !defined(IPLITE_ONE_FILE) || defined(IPLITE_C)
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_inet.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_sock.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_udp_input
|
||||
*===========================================================================
|
||||
* Description: Input handler for packet to UDP sockets. This function will
|
||||
* NOT free the packet if the operation fails.
|
||||
* Parameters: pkt - The received packet.
|
||||
* is_multicast - Set to IP_TRUE if the packet was sent to a
|
||||
* multicast address.
|
||||
* proto - The protocol number.
|
||||
* src_addr - The address (Ipv4 or IPv6) of the sender.
|
||||
* dst_addr - The address (Ipv4 or IPv6) of the receiver (this system).
|
||||
* socklookup - A pointer to a function that can return the socket
|
||||
* that is associated with this packet.
|
||||
* Returns: 0 >= number of matching sockets, <0 = error code
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_udp_input(Ipcom_pkt *pkt, Ip_bool is_multicast,
|
||||
IP_CONST void* src_addr, IP_CONST void* dst_addr,
|
||||
Iplite_socklookup socklookup)
|
||||
{
|
||||
Iplite_pkt_udp *udp_hdr;
|
||||
int retval;
|
||||
Ip_u16 ulen_h;
|
||||
Iplite_socket *sock;
|
||||
Ip_u16 src_port;
|
||||
Ip_u16 dst_port;
|
||||
int next;
|
||||
|
||||
IPLITE_STATS(udp_input++);
|
||||
IPCOM_PKT_TRACE(pkt, IPCOM_PKT_ID_UDP_INPUT);
|
||||
|
||||
if (pkt->end - pkt->start < IPLITE_UDP_HDR_SIZE)
|
||||
{
|
||||
IPLITE_STATS(udp_input_hdr_trunc++);
|
||||
IPCOM_MIB2(udpInErrors++);
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
|
||||
udp_hdr = (Iplite_pkt_udp*) &pkt->data[pkt->start];
|
||||
ulen_h = ip_ntohs(udp_hdr->ulen);
|
||||
src_port = ip_ntohs(udp_hdr->sport);
|
||||
dst_port = ip_ntohs(udp_hdr->dport);
|
||||
|
||||
if (pkt->end - pkt->start < ulen_h)
|
||||
{
|
||||
IPLITE_STATS(udp_input_hdr_trunc++);
|
||||
IPCOM_MIB2(udpInErrors++);
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
pkt->end = pkt->start + (int)ulen_h;
|
||||
|
||||
if (udp_hdr->sum != 0)
|
||||
{
|
||||
pkt->chk += ipcom_in_checksum_update(&pkt->data[pkt->start],
|
||||
(Ip_size_t) ulen_h);
|
||||
if (ipcom_in_checksum_finish(pkt->chk) != 0)
|
||||
{
|
||||
/* Wrong checksum */
|
||||
IPLITE_STATS(udp_input_badchksum++);
|
||||
IPCOM_MIB2(udpInErrors++);
|
||||
return -IP_ERRNO_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move the start to beginning of application data */
|
||||
pkt->start += IPLITE_UDP_HDR_SIZE;
|
||||
|
||||
if (is_multicast)
|
||||
{
|
||||
IPLITE_STATS(udp_input_multicast++);
|
||||
retval = iplite_raw_input(pkt, IP_FALSE, IP_IPPROTO_UDP,
|
||||
src_addr, src_port, dst_addr, dst_port, socklookup);
|
||||
|
||||
if (retval >= 0)
|
||||
{
|
||||
/* The packet must be freed unlesss an error occured */
|
||||
ipcom_pkt_free(pkt);
|
||||
IPCOM_MIB2(udpInDatagrams++);
|
||||
}
|
||||
else
|
||||
{
|
||||
IPCOM_MIB2(udpInErrors++);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Lookup UDP socket. Honor the SO_BINDTODEVICE option. */
|
||||
next = 0;
|
||||
do
|
||||
{
|
||||
sock = socklookup(IP_IPPROTO_UDP, dst_addr, dst_port, src_addr, src_port, &next);
|
||||
} while (sock != IP_NULL
|
||||
&& sock->bind_to_ifindex != 0
|
||||
&& sock->bind_to_ifindex != pkt->ifindex);
|
||||
|
||||
if (sock != IP_NULL)
|
||||
{
|
||||
IPLITE_STATS(udp_input_sock_match++);
|
||||
pkt->fd = sock->ipcom.fd;
|
||||
|
||||
|
||||
retval = iplite_queue_received_packet(pkt, sock);
|
||||
if (sock->ipcom.event_cb)
|
||||
sock->ipcom.event_cb((Ipcom_socket *)sock, pkt, IP_SOEVENT_CB_SELREAD);
|
||||
|
||||
|
||||
|
||||
if (retval < 0)
|
||||
{
|
||||
IPLITE_STATS(udp_input_queue_pkt_err++);
|
||||
IPCOM_MIB2(udpInErrors++);
|
||||
return retval;
|
||||
}
|
||||
else
|
||||
{
|
||||
IPLITE_STATS(udp_input_queue_pkt_ok++);
|
||||
}
|
||||
|
||||
IPCOM_MIB2(udpInDatagrams++);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
IPLITE_STATS(udp_input_sock_nomatch++);
|
||||
IPCOM_MIB2(udpNoPorts++);
|
||||
}
|
||||
|
||||
IPLITE_STATS(udp_input_econnrefused++);
|
||||
return -IP_ERRNO_ECONNREFUSED;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_udp_output
|
||||
*===========================================================================
|
||||
* Description: Adds a UDP header to the application data.
|
||||
* Parameters: sock - The socket to use when sending.
|
||||
* to - The destination address address, ignored if the socket
|
||||
* is in connected state.
|
||||
* pkt - The packet data to send.
|
||||
* Returns: >0 = application bytes sent, <0 = error code.
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
iplite_udp_output(Iplite_socket *sock, IP_CONST struct Ip_sockaddr *to, Ipcom_pkt *pkt)
|
||||
{
|
||||
Ip_u16 to_port_n;
|
||||
Iplite_pkt_udp *udp;
|
||||
int ret;
|
||||
|
||||
IPLITE_STATS(udp_output++);
|
||||
ip_assert(sock->ipcom.type == IP_SOCK_DGRAM);
|
||||
ip_assert(sock->proto == IP_IPPROTO_UDP);
|
||||
|
||||
if (IP_BIT_ISSET(sock->flags, IPLITE_SOCKET_FLAG_CONNECTED))
|
||||
to_port_n = ip_htons(sock->dport);
|
||||
else if (to == IP_NULL)
|
||||
{
|
||||
/* No destination address */
|
||||
ret = -IP_ERRNO_EDESTADDRREQ;
|
||||
goto errout;
|
||||
}
|
||||
else
|
||||
/* Ok for both IPv4 and IPv6 */
|
||||
to_port_n = ((struct Ip_sockaddr_in*) to)->sin_port;
|
||||
|
||||
if (pkt->start < IPLITE_UDP_HDR_SIZE)
|
||||
{
|
||||
/* Not enough space for UDP header */
|
||||
IPLITE_STATS(udp_output_hdr_trunc++);
|
||||
ret = -IP_ERRNO_EFAULT;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Fill in UDP header. */
|
||||
pkt->start -= IPLITE_UDP_HDR_SIZE;
|
||||
udp = (Iplite_pkt_udp *)&pkt->data[pkt->start];
|
||||
|
||||
udp->sport = ip_htons(sock->sport);
|
||||
ip_assert(udp->sport != 0);
|
||||
udp->dport = to_port_n;
|
||||
udp->sum = 0;
|
||||
udp->ulen = (Ip_u16) ip_htons(pkt->end - pkt->start);
|
||||
if (IP_BIT_ISSET(sock->flags, IPLITE_SOCKET_FLAG_ADDCHECKSUM))
|
||||
{
|
||||
/* Update the checksum with the UDP header */
|
||||
pkt->chk += (Ip_u32)udp->sport;
|
||||
pkt->chk += (Ip_u32)udp->dport;
|
||||
pkt->chk += (Ip_u32)udp->ulen;
|
||||
/* note: ignore sum entry since 0! */
|
||||
}
|
||||
|
||||
switch(sock->ipcom.domain)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
case IP_AF_INET:
|
||||
IPCOM_MIB2(udpOutDatagrams++);
|
||||
return iplite_ip4_sendto(sock, to, pkt);
|
||||
#endif
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
case IP_AF_INET6:
|
||||
IPCOM_MIB2(udpOutDatagrams++);
|
||||
return iplite_ip6_sendto(sock, to, pkt);
|
||||
#endif
|
||||
|
||||
default:
|
||||
/* Invalid domain */
|
||||
IP_PANIC();
|
||||
IPLITE_STATS(udp_output_eafnosupport++);
|
||||
ret = -IP_ERRNO_EAFNOSUPPORT;
|
||||
break;
|
||||
}
|
||||
|
||||
errout:
|
||||
ipcom_pkt_free(pkt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* !defined(IPLITE_ONE_FILE) || defined(IPLITE_C) */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,586 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_udp_mib.c,v $ $Revision: 1.14 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_udp_mib.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Markus Carlstedt <markus@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* UDP-MIB
|
||||
*===========================================================================
|
||||
*
|
||||
* Autogenerated by 'ipmibc' with 'smidump 0.4.1' on 2003-11-20 at 11:29:32
|
||||
*
|
||||
* This file includes initialization code and stubs for MIB variables defined
|
||||
* in UDP-MIB. Without any changes it should compile and run with the
|
||||
* behaviour that GetRequests succeed with the returned value being
|
||||
* zero. SetRequests also succeed but without any actual variables
|
||||
* being updated.
|
||||
*
|
||||
* Modifications to this file are necessary in order to enable read and
|
||||
* write operations on actual variables presented in the MIB interface.
|
||||
* Each segment in the code where a change is proposed is marked with a
|
||||
* 'MIB_TODO' comment together with a pseudo code example describing the
|
||||
* modification.
|
||||
*
|
||||
* This file shall normally be compiled together with the product to which
|
||||
* SNMP support is to be added and then linked with the IPSNMP libraries.
|
||||
* The MIB is initialized by calling the public initialization function defined
|
||||
* at the end of this file. Since no header files are generated its function
|
||||
* prototype should be copied into the the product that initializes the MIB.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPCOM_KERNEL
|
||||
#define IPCOM_KERNEL
|
||||
#endif
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_err.h>
|
||||
|
||||
#ifdef IPSNMP
|
||||
#include <ipsnmp_config.h>
|
||||
#include <ipsnmp.h>
|
||||
#include <ipcom_mib2.h>
|
||||
#include <iplite_h.h>
|
||||
|
||||
#ifdef IPCOM_USE_MIB2
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_SYSLOG_FACILITY
|
||||
#undef IPCOM_SYSLOG_FACILITY
|
||||
#endif
|
||||
#define IPCOM_SYSLOG_FACILITY IPCOM_LOG_IPSNMP
|
||||
|
||||
#ifdef IPCOM_SYSLOG_PRIORITY
|
||||
#undef IPCOM_SYSLOG_PRIORITY
|
||||
#endif
|
||||
#define IPCOM_SYSLOG_PRIORITY IPCOM_LOG_DEBUG
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERNAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC Ip_err iplite_udp_mib_init(void);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_udp_mib_lock
|
||||
*===========================================================================
|
||||
* Description: Protects MIB variables in SNMPv2-MIB from multiple access
|
||||
* Parameters: lock - boolean that controls lock or unlock
|
||||
* Returns: Nothing
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
iplite_udp_mib_lock(Ip_bool lock)
|
||||
{
|
||||
if (lock == IP_TRUE)
|
||||
{
|
||||
IPLITE_CODE_LOCK();
|
||||
}
|
||||
else
|
||||
{
|
||||
IPLITE_CODE_UNLOCK();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_udp_mib_table_search_udpTable
|
||||
*===========================================================================
|
||||
* Description: Searches udpTable for a matching entry
|
||||
* Parameters: id, buf, best, cmd
|
||||
* Returns: Row index of the found entry OR -1 if not found OR -2 for error
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_s32
|
||||
iplite_udp_mib_table_search_udpTable(char *id,
|
||||
char *buf,
|
||||
char *best,
|
||||
Ip_s32 cmd)
|
||||
{
|
||||
Ip_u32 udpLocalAddress = 0;
|
||||
Ip_s32 udpLocalPort;
|
||||
Ip_s32 udpTable_num_entries;
|
||||
Ip_s32 i, bestindex = -1;
|
||||
|
||||
udpTable_num_entries = IPLITE_CONF_MAX_SOCKETS;
|
||||
|
||||
for (i=0; i<udpTable_num_entries; i++)
|
||||
{
|
||||
Ip_s32 lex, len = 0;
|
||||
|
||||
buf[0] = '\0';
|
||||
|
||||
if (iplite.sockets[i] == IP_NULL || iplite.sockets[i]->ipcom.domain != IP_AF_INET
|
||||
|| iplite.sockets[i]->ipcom.type != IP_SOCK_DGRAM || iplite.sockets[i]->proto != IP_IPPROTO_UDP
|
||||
|| !IP_BIT_ISSET(iplite.sockets[i]->flags, IPLITE_SOCKET_FLAG_BOUND))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
udpLocalAddress = iplite.sockets[i]->d->ip4.saddr_n;
|
||||
|
||||
if (ipcom_inet_ntop(IP_AF_INET, &udpLocalAddress, &buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len) == IP_NULL)
|
||||
return -2;
|
||||
len = ipcom_strlen(buf);
|
||||
if (ipcom_snprintf(&buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, ".") < 0)
|
||||
return -2;
|
||||
len = ipcom_strlen(buf);
|
||||
|
||||
udpLocalPort = iplite.sockets[i]->sport;
|
||||
|
||||
if (ipcom_snprintf(&buf[len], IPSNMP_CONFIG_MAX_OBJECT_ID-len, "%d.", (int)udpLocalPort) < 0)
|
||||
return -2;
|
||||
len = ipcom_strlen(buf);
|
||||
if (len)
|
||||
buf[len-1] = '\0';
|
||||
|
||||
lex = ipsnmp_util_lexcmp_oid(buf, id);
|
||||
if (cmd == IPSNMP_MIB_COMMAND_NEXT)
|
||||
{
|
||||
if (lex > 0)
|
||||
{
|
||||
if (bestindex == -1 || ipsnmp_util_lexcmp_oid(buf, best) < 0)
|
||||
{
|
||||
ipcom_strcpy(best, buf);
|
||||
bestindex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lex == 0)
|
||||
{
|
||||
ipcom_strcpy(best, buf);
|
||||
bestindex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bestindex;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_udp_mib_handler_udpLocalAddress
|
||||
*===========================================================================
|
||||
* Description: MIB handler for udpLocalAddress
|
||||
* Parameters: See file 'ipsnmp.h'
|
||||
* Returns: IPSNMP_ERROR_XXX
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_s32
|
||||
iplite_udp_mib_handler_udpLocalAddress(Ip_s32 cmd,
|
||||
char *id,
|
||||
Ipsnmp_varbind *vb,
|
||||
Ip_s32 magic,
|
||||
struct Ipsnmp_node_object *nodeobj)
|
||||
{
|
||||
Ip_s32 bestindex, ret = -1;
|
||||
Ip_u32 udpLocalAddress;
|
||||
char *iid;
|
||||
char *buf = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID);
|
||||
char *best = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID);
|
||||
|
||||
(void)vb;
|
||||
if (buf == IP_NULL || best == IP_NULL)
|
||||
{
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
bestindex = iplite_udp_mib_table_search_udpTable(id, buf, best, cmd);
|
||||
if (bestindex == -2)
|
||||
{
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
goto exit;
|
||||
}
|
||||
else if (bestindex == -1)
|
||||
{
|
||||
ret = IPSNMP_ERROR_NOSUCHNAME;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (cmd == IPSNMP_MIB_COMMAND_GET || cmd == IPSNMP_MIB_COMMAND_NEXT)
|
||||
{
|
||||
iid = ipsnmp_create_iid_direct(nodeobj->id, best);
|
||||
if (iid == IP_NULL)
|
||||
{
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
udpLocalAddress = ip_ntohl(iplite.sockets[bestindex]->d->ip4.saddr_n);
|
||||
|
||||
ret = ipsnmp_util_put_ipaddress(magic, iid, udpLocalAddress);
|
||||
ipcom_free(iid);
|
||||
}
|
||||
|
||||
exit:
|
||||
if (buf != IP_NULL)
|
||||
ipcom_free(buf);
|
||||
if (best != IP_NULL)
|
||||
ipcom_free(best);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_udp_mib_handler_udpLocalPort
|
||||
*===========================================================================
|
||||
* Description: MIB handler for udpLocalPort
|
||||
* Parameters: See file 'ipsnmp.h'
|
||||
* Returns: IPSNMP_ERROR_XXX
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_s32
|
||||
iplite_udp_mib_handler_udpLocalPort(Ip_s32 cmd,
|
||||
char *id,
|
||||
Ipsnmp_varbind *vb,
|
||||
Ip_s32 magic,
|
||||
struct Ipsnmp_node_object *nodeobj)
|
||||
{
|
||||
Ip_s32 bestindex, ret = -1;
|
||||
Ip_s32 udpLocalPort;
|
||||
char *iid;
|
||||
char *buf = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID);
|
||||
char *best = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID);
|
||||
|
||||
(void)vb;
|
||||
if (buf == IP_NULL || best == IP_NULL)
|
||||
{
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
bestindex = iplite_udp_mib_table_search_udpTable(id, buf, best, cmd);
|
||||
if (bestindex == -2)
|
||||
{
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
goto exit;
|
||||
}
|
||||
else if (bestindex == -1)
|
||||
{
|
||||
ret = IPSNMP_ERROR_NOSUCHNAME;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (cmd == IPSNMP_MIB_COMMAND_GET || cmd == IPSNMP_MIB_COMMAND_NEXT)
|
||||
{
|
||||
iid = ipsnmp_create_iid_direct(nodeobj->id, best);
|
||||
if (iid == IP_NULL)
|
||||
{
|
||||
ret = IPSNMP_ERROR_GENERROR;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
udpLocalPort = iplite.sockets[bestindex]->sport;
|
||||
|
||||
ret = ipsnmp_util_put_integer(magic, iid, udpLocalPort);
|
||||
ipcom_free(iid);
|
||||
}
|
||||
|
||||
exit:
|
||||
if (buf != IP_NULL)
|
||||
ipcom_free(buf);
|
||||
if (best != IP_NULL)
|
||||
ipcom_free(best);
|
||||
return ret;
|
||||
}
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_udp_mib_init
|
||||
*===========================================================================
|
||||
* Description: Initializes UDP-MIB
|
||||
* Parameters: None
|
||||
* Returns: IPCOM_SUCCESS or IPCOM_ERR_FAILED
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
iplite_udp_mib_init(void)
|
||||
{
|
||||
struct Ipsnmp_node_object nodeobj;
|
||||
Ip_s32 ret;
|
||||
|
||||
/* Assign lock function */
|
||||
nodeobj.lock = iplite_udp_mib_lock;
|
||||
|
||||
/* Add node "udpMIB" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.50";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "udpMIB";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_OTHER;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if (ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "udp" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.7";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "udp";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_OTHER;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if (ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "udpInDatagrams" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_COUNTER32;
|
||||
nodeobj.handler = ipsnmp_mib_standard_handler;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.1";
|
||||
nodeobj.instance = &(&iplite)->mib2.udpInDatagrams;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "udpInDatagrams";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_SCALAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if (ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "udpNoPorts" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_COUNTER32;
|
||||
nodeobj.handler = ipsnmp_mib_standard_handler;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.2";
|
||||
nodeobj.instance = &(&iplite)->mib2.udpNoPorts;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "udpNoPorts";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_SCALAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if (ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "udpInErrors" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_COUNTER32;
|
||||
nodeobj.handler = ipsnmp_mib_standard_handler;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.3";
|
||||
nodeobj.instance = &(&iplite)->mib2.udpInErrors;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "udpInErrors";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_SCALAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if (ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "udpOutDatagrams" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_COUNTER32;
|
||||
nodeobj.handler = ipsnmp_mib_standard_handler;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.4";
|
||||
nodeobj.instance = &(&iplite)->mib2.udpOutDatagrams;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "udpOutDatagrams";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_SCALAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if (ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
/* Add node "udpTable" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.5";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "udpTable";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_AGGREGATE;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if (ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "udpEntry" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_NOACCESS;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_UNSPECIFIED;
|
||||
nodeobj.handler = IP_NULL;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.5.1";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "udpEntry";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_AGGREGATE;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if (ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "udpLocalAddress" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_IPADDRESS;
|
||||
nodeobj.handler = iplite_udp_mib_handler_udpLocalAddress;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.5.1.1";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "udpLocalAddress";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if (ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
/* Add node "udpLocalPort" to the MIB tree */
|
||||
nodeobj.access = IPSNMP_NODE_ACCESS_READONLY;
|
||||
nodeobj.datatype = IPSNMP_DATA_TYPE_INTEGER;
|
||||
nodeobj.handler = iplite_udp_mib_handler_udpLocalPort;
|
||||
nodeobj.id = "1.3.6.1.2.1.7.5.1.2";
|
||||
nodeobj.instance = IP_NULL;
|
||||
#ifdef IP_DEBUG
|
||||
nodeobj.name = "udpLocalPort";
|
||||
#endif
|
||||
nodeobj.nodetype = IPSNMP_NODE_TYPE_COLUMNAR;
|
||||
ret = ipsnmp_add_node(&nodeobj);
|
||||
if (ret != 0)
|
||||
{
|
||||
IPCOM_LOG2(ERR, "ipsnmp_add_node() :: failed to add %s (%d)", nodeobj.id, ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
|
||||
return IPCOM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
#endif /* #ifdef IPCOM_USE_MIB2 */
|
||||
#endif /* #ifdef IPSNMP */
|
||||
|
||||
#if !defined(IPSNMP) || !defined(IPCOM_USE_MIB2)
|
||||
void iplite_udp_mib_empty_file(void);
|
||||
void iplite_udp_mib_empty_file(void) { }
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_wlan.c,v $ $Revision: 1.6 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_wlan.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_KERNEL
|
||||
#include "iplite_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPLITE_USE_WLAN
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_netif.h>
|
||||
#include <ipcom_wlan.h>
|
||||
|
||||
#include "iplite_h.h"
|
||||
#include "iplite_eth.h"
|
||||
#include "iplite_netif.h"
|
||||
#include "iplite_wlan.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
IP_PUBLIC int iplite_eth_if_init(Iplite_netif *netif);
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC int iplite_wlan_ioctl(Iplite_netif *netif, Ip_u32 command, void *data);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_wlan_ioctl
|
||||
*===========================================================================
|
||||
* Description: WLAN IO control.
|
||||
* Parameters: netif - The network interface to operate on.
|
||||
* command -
|
||||
* data - Depends on command.
|
||||
* Returns: 0 = success, < 0 = error code
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef IPMARVELL
|
||||
IP_PUBLIC int ipmarvell_ioctl_if(void *netif, Ip_u32 cmd, Ipcom_iwreq *iw);
|
||||
#endif
|
||||
|
||||
IP_STATIC int
|
||||
iplite_wlan_ioctl(Iplite_netif *netif, Ip_u32 command, void *data)
|
||||
{
|
||||
int ret = 0;
|
||||
Ipcom_iwreq *iw = data;
|
||||
Ipcom_wlan_func wlan_if;
|
||||
|
||||
|
||||
switch(command)
|
||||
{
|
||||
case IP_SIOCSIWATTACHFUNC:
|
||||
case IP_SIOCSIWREMOVEFUNC:
|
||||
|
||||
if(command == IP_SIOCSIWATTACHFUNC)
|
||||
{
|
||||
netif->wlan->aux_link_ioctl = (int (*)(Iplite_netif *, Ip_u32, void *))iw->u.data.pointer;
|
||||
}
|
||||
|
||||
if(netif->wlan->aux_link_ioctl != IP_NULL)
|
||||
{
|
||||
wlan_if.link_input = (int (*)(Ipcom_netif *, Ipcom_pkt *))netif->link_input;
|
||||
ret = netif->wlan->aux_link_ioctl(netif, command, &wlan_if);
|
||||
netif->link_input = (Iplite_link_input)wlan_if.link_input;
|
||||
}
|
||||
|
||||
if(command == IP_SIOCSIWREMOVEFUNC)
|
||||
{
|
||||
netif->wlan->aux_link_ioctl = IP_NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
#ifdef IPMARVELL
|
||||
|
||||
ret = ipmarvell_ioctl_if(netif, command, data);
|
||||
if(ret < 1)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
if(netif->wlan->aux_link_ioctl)
|
||||
{
|
||||
ret = netif->wlan->aux_link_ioctl(netif, command, data);
|
||||
if(ret <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
ret = netif->wlan->eth_link_ioctl(netif, command, data);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iplite_wlan_if_init
|
||||
*===========================================================================
|
||||
* Description: WLAN uses the Ethernet interface with a few modifications
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
iplite_wlan_if_init(Iplite_netif *netif)
|
||||
{
|
||||
int i;
|
||||
|
||||
iplite_eth_if_init(netif);
|
||||
|
||||
netif->wlan = ipcom_malloc(sizeof(Iplite_netif_wlan));
|
||||
if (netif->wlan == IP_NULL)
|
||||
return -IP_ERRNO_ENOMEM;
|
||||
ipcom_memset(netif->wlan, 0, sizeof(Iplite_netif_wlan));
|
||||
|
||||
i = 0;
|
||||
do
|
||||
{
|
||||
ipcom_sprintf(netif->ipcom.name, "wlan%d", i++);
|
||||
} while (iplite_if_nametonetif(netif->ipcom.name) != IP_NULL);
|
||||
|
||||
|
||||
/* Setup link functions for WLAN use. */
|
||||
netif->wlan->eth_link_ioctl = (int (*)(Iplite_netif *, Ip_u32, void *))netif->link_ioctl;
|
||||
netif->link_ioctl = (Iplite_link_ioctl)iplite_wlan_ioctl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* IPLITE_USE_WLAN */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iplite_wlan.h,v $ $Revision: 1.4 $
|
||||
* $Source: /home/interpeak/CVSRoot/iplite2/src/iplite_wlan.h,v $
|
||||
* $Author: lob $ $Date: 2005-11-21 11:15:37 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPLITE_WLAN_H
|
||||
#define IPLITE_WLAN_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iplite_config.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Frame Values
|
||||
*===========================================================================
|
||||
* Note: Also used for 3:rd argument to when creating packet sockets.
|
||||
*/
|
||||
#define IPLITE_WLAN_P_ALL 0
|
||||
#define IPLITE_WLAN_P_IP 0x0800
|
||||
#define IPLITE_WLAN_P_ARP 0x0806
|
||||
#define IPLITE_WLAN_P_RARP 0x8035
|
||||
#define IPLITE_WLAN_P_IPV6 0x86DD
|
||||
#define IPLITE_WLAN_P_PPPOE_DIS 0x8863
|
||||
#define IPLITE_WLAN_P_PPPOE_SES 0x8864
|
||||
#define IPLITE_WLAN_P_8021Q_VLAN 0x8100
|
||||
|
||||
/* Ethernet MTU/MRU. */
|
||||
#define IPLITE_WLAN_MTU 1500
|
||||
|
||||
/* Size of MAC address */
|
||||
#define IPLITE_WLAN_ADDR_SIZE 6
|
||||
|
||||
/* Size of WLAN link header. (only applies to data frames) */
|
||||
#define IPLITE_WLAN_HDR_SIZE 30
|
||||
|
||||
/* Size of Ethernet link trailer (not used by IP layers) */
|
||||
#define IPLITE_WLAN_TRL_SIZE 6 /*!! FCS=4 */
|
||||
|
||||
/* Number of bits in the host part (EUI-64) when using the
|
||||
MAC addr to create a IPv6 address (RFC 2464) */
|
||||
#define IPLITE_WLAN_IP6_ID_BITS 64
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_netif_wlan_vlan
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef struct Iplite_netif_wlan_vlan_struct
|
||||
{
|
||||
Iplite_netif *parent; /* Parent WLAN interface */
|
||||
int id; /* Virtual LAN ID 1-4095 */
|
||||
}
|
||||
Iplite_netif_wlan_vlan;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iplite_netif_wlan
|
||||
*===========================================================================
|
||||
* WLAN specific data
|
||||
*/
|
||||
typedef struct Iplite_netif_wlan_struct
|
||||
{
|
||||
#ifdef IPLITE_USE_VLAN
|
||||
union
|
||||
{
|
||||
Ipcom_hash *ifs; /* All virtual interfaces that has this interface as parent */
|
||||
Iplite_netif_wlan_vlan param; /* Virtual LAN parameters */
|
||||
} vlan;
|
||||
#endif
|
||||
|
||||
int (*eth_link_ioctl)(Iplite_netif *, Ip_u32, void *);
|
||||
int (*aux_link_ioctl)(Iplite_netif *, Ip_u32, void *);
|
||||
|
||||
/* NIKLAS INTERFACE SPECIFIKA DATA HERE: */
|
||||
/* 4 nycklar, kanal, etc */
|
||||
}
|
||||
Iplite_netif_wlan;
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC int iplite_wlan_if_init(Iplite_netif *netif);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef IPLITE_IPNET_CMD_H
|
||||
#define IPLITE_IPNET_CMD_H
|
||||
|
||||
#include <iplite_cmd.h>
|
||||
|
||||
#define ipnet_cmd_init_addrs iplite_cmd_init_addrs
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
#include "iplite_eth.h"
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef _IPLITE_IPNET_H__
|
||||
#define _IPLITE_IPNET_H__
|
||||
|
||||
#include <iplite_h.h>
|
||||
|
||||
#define ipnet_pkt_clone(a, b) iplite_pkt_clone(a)
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1 @@
|
||||
#include "iplite_sysctl.h"
|
||||
Reference in New Issue
Block a user