original files of m241
This commit is contained in:
@@ -0,0 +1,431 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmip4_cli.c,v $ $Revision: 1.10 $
|
||||
* $Source: /home/interpeak/CVSRoot/ipmip4/src/ipmip4_cli.c,v $
|
||||
* $Author: jhorteli $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Joel Hortelius <joel.hortelis@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
#include "ipmip4_config.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_list.h>
|
||||
#include <ipcom_sock.h>
|
||||
#include <ipcom_sock6.h>
|
||||
#include <ipcom_inet.h>
|
||||
#include <ipcom_sysvar.h>
|
||||
#include <ipcom_getopt.h>
|
||||
|
||||
#include <ipmip.h>
|
||||
#include <private/ipmip_cli.h>
|
||||
#include <private/ipmip_util.h>
|
||||
#include <private/ipmip_sysvar.h>
|
||||
|
||||
#include "ipmip4_h.h"
|
||||
#include <private/ipmip4_context.h>
|
||||
#include <private/ipmip4_cli.h>
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_pmipv4_request_set_home_address(Ipmip_cli_daemon_req_t *req,
|
||||
Ip_u32 hoa)
|
||||
{
|
||||
if (hoa)
|
||||
ipmip_attr_put_inet(&req->reqbuf, IPMIP4_CLI_PMIPV4_ATTR_HOA, hoa);
|
||||
}
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_pmipv4_request_set_dhcp_relay_server(Ipmip_cli_daemon_req_t *req,
|
||||
Ip_u32 srv)
|
||||
{
|
||||
if (srv)
|
||||
ipmip_attr_put_inet(&req->reqbuf, IPMIP4_CLI_PMIPV4_ATTR_DHCP_RELAY_SERVER, srv);
|
||||
}
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_pmipv4_request_set_home_agent(Ipmip_cli_daemon_req_t *req,
|
||||
Ip_u32 ha)
|
||||
{
|
||||
if (ha)
|
||||
ipmip_attr_put_inet(&req->reqbuf, IPMIP4_CLI_PMIPV4_ATTR_HA, ha);
|
||||
}
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_pmipv4_request_set_nfa(Ipmip_cli_daemon_req_t *req,
|
||||
Ip_u32 fa)
|
||||
{
|
||||
if (fa)
|
||||
ipmip_attr_put_inet(&req->reqbuf, IPMIP4_CLI_PMIPV4_ATTR_NFA_COA, fa);
|
||||
}
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_pmipv4_request_set_ofa(Ipmip_cli_daemon_req_t *req,
|
||||
Ip_u32 fa)
|
||||
{
|
||||
if (fa)
|
||||
ipmip_attr_put_inet(&req->reqbuf, IPMIP4_CLI_PMIPV4_ATTR_OFA_COA, fa);
|
||||
}
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_pmipv4_request_set_mn_ha_spi(Ipmip_cli_daemon_req_t *req,
|
||||
Ip_u32 spi)
|
||||
{
|
||||
if (spi)
|
||||
ipmip_attr_put_inet(&req->reqbuf, IPMIP4_CLI_PMIPV4_ATTR_MN_HA_SPI, spi);
|
||||
}
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_pmipv4_request_set_nai(Ipmip_cli_daemon_req_t *req,
|
||||
const char *nai)
|
||||
{
|
||||
if (nai)
|
||||
ipmip_attr_put_str(&req->reqbuf, IPMIP4_CLI_PMIPV4_ATTR_MN_NAI, nai);
|
||||
}
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_request_set_ifname(Ipmip_cli_daemon_req_t *req,
|
||||
const char *ifname)
|
||||
{
|
||||
if (ifname)
|
||||
ipmip_attr_put_str(&req->reqbuf,IPMIP4_CLI_PMIPV4_ATTR_IFNAME, ifname);
|
||||
}
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_pmipv4_request_set_mn_ha_spi_secret(Ipmip_cli_daemon_req_t *req,
|
||||
const char *secret)
|
||||
{
|
||||
if (secret)
|
||||
ipmip_attr_put_str(&req->reqbuf,IPMIP4_CLI_PMIPV4_ATTR_MN_HA_SPI_SECRET, secret);
|
||||
}
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_pmipv4_request_set_handler(Ipmip_cli_daemon_req_t *req,
|
||||
const char *handler)
|
||||
{
|
||||
if (handler)
|
||||
ipmip_attr_put_str(&req->reqbuf, IPMIP4_CLI_PMIPV4_ATTR_HANDLER, handler);
|
||||
}
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_pmipv4_request_set_ifaddr(Ipmip_cli_daemon_req_t *req,
|
||||
const char *ifaddr)
|
||||
{
|
||||
if (ifaddr)
|
||||
ipmip_attr_put_str(&req->reqbuf, IPMIP4_CLI_PMIPV4_ATTR_IFADDR, ifaddr);
|
||||
}
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_pmipv4_request_set_tunnel_type(Ipmip_cli_daemon_req_t *req,
|
||||
Ip_u32 tunnel_type)
|
||||
{
|
||||
ipmip_attr_put_u32(&req->reqbuf, IPMIP4_CLI_PMIPV4_ATTR_TUNNEL_TYPE, tunnel_type);
|
||||
}
|
||||
|
||||
|
||||
IP_PUBLIC void
|
||||
ipmip4_cli_pmipv4_local_trigger_request_init(Ipmip_cli_daemon_req_t *req,
|
||||
const char *nai)
|
||||
{
|
||||
ipmip_cli_daemon_request_start(req, IPMIP4_CLI_PMIPV4_PLT);
|
||||
ipmip4_cli_pmipv4_request_set_nai(req, nai);
|
||||
}
|
||||
|
||||
IP_GLOBAL void
|
||||
ipmip4_cli_shell_pmipv4_usage(Ipmip_proc_t *proc)
|
||||
{
|
||||
ipmip_util_cmdprintf(proc, 1, "pmipv4 trigger <nai> <--ifaddr=<interface address> [options]", "Perform a PMIPv4 Trigger Option");
|
||||
ipmip_util_identprintf(proc, 2, "Where <nai> is the Network Access Identifier of this node."IP_LF);
|
||||
ipmip_util_identprintf(proc, 2, "Required options are:"IP_LF);
|
||||
ipmip_util_identprintf(proc, 2, "--ifaddr=<interface address> Interface address in the notation relevant"IP_LF);
|
||||
ipmip_util_identprintf(proc, 2, " to the type of interface specified. I.e. ethernet for example"IP_LF);
|
||||
ipmip_util_identprintf(proc, 2, " would be xx:xx:xx:xx:xx:xx in hexadecimal form."IP_LF);
|
||||
ipmip_util_identprintf(proc, 2, "Optional options are:"IP_LF);
|
||||
ipmip_util_identprintf(proc, 2, "--hoa=<home address> Home Address to be used in this trigger"IP_LF);
|
||||
ipmip_util_identprintf(proc, 2, "--ha=<home agent> Home Agent to be used in this trigger"IP_LF);
|
||||
ipmip_util_identprintf(proc, 2, "--ifname=<interface> Interface this PMIPv4 request is related to"IP_LF);
|
||||
ipmip_util_identprintf(proc, 2, "--dhcpr-server=<address> DHCP server to use for this node"IP_LF);
|
||||
|
||||
}
|
||||
|
||||
IP_GLOBAL int
|
||||
ipmip4_cli_shell_pmipv4_cmd(int argc,
|
||||
char **argv,
|
||||
Ipmip_proc_t *proc,
|
||||
Ipmip_cli_daemon_t *daemon)
|
||||
{
|
||||
static Ipcom_cmd_int_str_map ops[] = {
|
||||
{ 0, "pmipv4" },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
Ipcom_getopt opt;
|
||||
Ipmip_cli_daemon_req_t req;
|
||||
int op_val;
|
||||
int i;
|
||||
int ret = 0;
|
||||
|
||||
IPMIP_UNUSED_PARAMETER(proc);
|
||||
|
||||
/**/
|
||||
ipmip_cli_daemon_request_init(&req);
|
||||
ipcom_getopt_clear_r(&opt);
|
||||
|
||||
if (argc < 2)
|
||||
return -1;
|
||||
|
||||
op_val = ipcom_cmd_str_to_key(ops, argv[1]);
|
||||
|
||||
if (op_val == -1)
|
||||
return -1;
|
||||
|
||||
ipmip_cli_daemon_request_init(&req);
|
||||
if (op_val == 0)
|
||||
{
|
||||
/* PMIPv4 */
|
||||
static Ipcom_cmd_int_str_map pmipv4_ops[] = {
|
||||
{ 0, "trigger" },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
if (argc < 3)
|
||||
{
|
||||
ipcom_printf("Too few arguments to pmipv4 command"IP_LF);
|
||||
goto exit_out;
|
||||
}
|
||||
|
||||
op_val = ipcom_cmd_str_to_key(pmipv4_ops, argv[2]);
|
||||
if (op_val == -1)
|
||||
{
|
||||
ipcom_printf("Unknown subcommand pmipv4 '%s'"IP_LF, argv[1]);
|
||||
goto exit_out;
|
||||
}
|
||||
|
||||
if (op_val == 0)
|
||||
{
|
||||
static struct Ip_option long_options[] =
|
||||
{
|
||||
{"hoa", 1, 0, 0}, /* 0 */
|
||||
{"ha", 1, 0, 0}, /* 1 */
|
||||
{"ifname", 1, 0, 0}, /* 2 */
|
||||
{"nfa", 1, 0, 0}, /* 3 */
|
||||
{"ofa", 1, 0, 0}, /* 4 */
|
||||
{"mn-ha-spi", 1, 0, 0}, /* 5 */
|
||||
{"mn-ha-secret",1, 0, 0}, /* 6 */
|
||||
{"dhcpr-server",1, 0, 0}, /* 7 */
|
||||
{"handler", 1, 0, 0}, /* 8 */
|
||||
{"ifaddr", 1, 0, 0}, /* 9 */
|
||||
{"tunneltype", 1, 0, 0}, /* 10 */
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
Ip_u32 tmp32;
|
||||
|
||||
/* TRIGGER */
|
||||
if (argc < 4)
|
||||
{
|
||||
ipcom_printf("Too few arguments to pmipv4 trigger command"IP_LF);
|
||||
goto exit_out;
|
||||
}
|
||||
|
||||
/* Create the basic request */
|
||||
ipmip4_cli_pmipv4_local_trigger_request_init(&req, argv[3]);
|
||||
opt.long_only = 1;
|
||||
opt.long_options = long_options;
|
||||
while ((i = ipcom_getopt_r(argc - 3, argv + 3, "", &opt)) != -1)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
ipcom_printf("option %s"IP_LF, long_options[opt.long_index].name);
|
||||
|
||||
switch(opt.long_index)
|
||||
{
|
||||
case 0:
|
||||
/* hoa -- Home Address */
|
||||
if (ipcom_inet_pton(IP_AF_INET, opt.optarg, &tmp32) != 1)
|
||||
{
|
||||
ipcom_printf("bad '--hoa' IPv4 address."IP_LF);
|
||||
goto exit_out;
|
||||
}
|
||||
ipmip4_cli_pmipv4_request_set_home_address(&req, tmp32);
|
||||
break;
|
||||
case 1:
|
||||
/* ha */
|
||||
if (ipcom_inet_pton(IP_AF_INET, opt.optarg, &tmp32) != 1)
|
||||
{
|
||||
ipcom_printf("bad '--ha' IPv4 address."IP_LF);
|
||||
goto exit_out;
|
||||
}
|
||||
ipmip4_cli_pmipv4_request_set_home_agent(&req, tmp32);
|
||||
break;
|
||||
case 2:
|
||||
ipmip4_cli_request_set_ifname(&req, opt.optarg);
|
||||
break;
|
||||
case 3:
|
||||
if (ipcom_inet_pton(IP_AF_INET, opt.optarg, &tmp32) != 1)
|
||||
{
|
||||
ipcom_printf("bad '--nfa' IPv4 address."IP_LF);
|
||||
goto exit_out;
|
||||
}
|
||||
ipmip4_cli_pmipv4_request_set_nfa(&req, tmp32);
|
||||
break;
|
||||
case 4:
|
||||
if (ipcom_inet_pton(IP_AF_INET, opt.optarg, &tmp32) != 1)
|
||||
{
|
||||
ipcom_printf("bad '--ofa' IPv4 address."IP_LF);
|
||||
goto exit_out;
|
||||
}
|
||||
ipmip4_cli_pmipv4_request_set_ofa(&req, tmp32);
|
||||
break;
|
||||
case 5:
|
||||
tmp32 = ipcom_strtoul(opt.optarg, IP_NULL, 0);
|
||||
if (tmp32 == 0)
|
||||
{
|
||||
ipcom_printf("bad '--mn-ha-spi' SPI Value."IP_LF);
|
||||
goto exit_out;
|
||||
}
|
||||
ipmip4_cli_pmipv4_request_set_mn_ha_spi(&req, tmp32);
|
||||
break;
|
||||
case 6:
|
||||
ipmip4_cli_pmipv4_request_set_mn_ha_spi_secret(&req, opt.optarg);
|
||||
break;
|
||||
case 7:
|
||||
if (ipcom_inet_pton(IP_AF_INET, opt.optarg, &tmp32) != 1)
|
||||
{
|
||||
ipcom_printf("bad '--dhcpr-server' IPv4 address."IP_LF);
|
||||
goto exit_out;
|
||||
}
|
||||
ipmip4_cli_pmipv4_request_set_dhcp_relay_server(&req, tmp32);
|
||||
break;
|
||||
case 8:
|
||||
ipmip4_cli_pmipv4_request_set_handler(&req, opt.optarg);
|
||||
break;
|
||||
case 9:
|
||||
ipmip4_cli_pmipv4_request_set_ifaddr(&req, opt.optarg);
|
||||
break;
|
||||
case 10:
|
||||
{
|
||||
int type = ipmip_sysvar_cmd_str_to_key(ipmip_sysvar_tunnel_mask, opt.optarg);
|
||||
if (type == -1)
|
||||
{
|
||||
ipcom_printf("unknown tunneltype %s", opt.optarg);
|
||||
goto exit_out;
|
||||
}
|
||||
|
||||
/* */
|
||||
ipmip4_cli_pmipv4_request_set_tunnel_type(&req, ipmip_util_tunnelmask_to_type(type));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ipcom_printf("unhandled option %s", long_options[opt.long_index].name);
|
||||
if (opt.optarg)
|
||||
ipcom_printf(" with arg %s", opt.optarg);
|
||||
ipcom_printf(IP_LF);
|
||||
goto exit_out;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ipcom_printf("Unknown option '%c' in pmipv4 trigger command"IP_LF, i);
|
||||
goto exit_out;
|
||||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
if ((ret = ipmip_cli_daemon_request(daemon, &req)) < 0)
|
||||
ipcom_printf("PMIPv4 Trigger Failed with error: %s"IP_LF, ipcom_strerror(-ret));
|
||||
}
|
||||
}
|
||||
|
||||
exit_out:
|
||||
ipmip_cli_daemon_request_release(&req);
|
||||
return 0;
|
||||
}
|
||||
|
||||
IP_GLOBAL int
|
||||
ipmip4_cli_shell_cmd(int argc,
|
||||
char **argv,
|
||||
Ipmip_proc_t *proc,
|
||||
Ipmip_cli_daemon_t *daemon)
|
||||
{
|
||||
return ipmip_cli_shell_cmd(argc, argv, proc, daemon);
|
||||
}
|
||||
|
||||
IP_GLOBAL void
|
||||
ipmip4_cli_shell_usage(Ipmip_proc_t *proc)
|
||||
{
|
||||
ipmip_cli_shell_usage(proc);
|
||||
}
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user