236 lines
7.4 KiB
C
236 lines
7.4 KiB
C
/*
|
|
******************************************************************************
|
|
* 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
|
|
****************************************************************************
|
|
*/
|