/* ******************************************************************************* * INTERPEAK SOURCE FILE * * Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmippm_cmd_pm.c,v $ $Revision: 1.9.16.1 $ * $Source: /home/interpeak/CVSRoot/ipmippm/src/ipmippm_cmd_pm.c,v $ * $Author: jsheng $ * $State: Exp $ $Locker: $ * * INTERPEAK_COPYRIGHT_STRING * Design and implementation by Niklas Lundberg ****************************************************************************** */ /* ******************************************************************************* * 1 DESCRIPTION ******************************************************************************* * */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #define IPCOM_USE_CLIB_PROTO #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ipmippm.h" #include "ipmippm_attr.h" #include "ipmippm_cli.h" /* **************************************************************************** * 4 DEFINES **************************************************************************** */ /* **************************************************************************** * 5 TYPES **************************************************************************** */ /* **************************************************************************** * 6 EXTERN PROTOTYPES **************************************************************************** */ /* **************************************************************************** * 7 LOCAL PROTOTYPES **************************************************************************** */ IP_PUBLIC int ipmippm_cmd_pm(int argc, char **argv); /* **************************************************************************** * 8 DATA **************************************************************************** */ #define IPMIPPM_CMD_OP_LIST (1) #define IPMIPPM_CMD_OP_SHOW (2) #define IPMIPPM_CMD_OP_DELETE (3) IP_STATIC Ipcom_cmd_int_str_map ipmippm_cmd_ops[] = { { IPMIPPM_CMD_OP_LIST, "list" }, { IPMIPPM_CMD_OP_SHOW, "show" }, { IPMIPPM_CMD_OP_DELETE, "delete" }, { 0, 0 } }; /* **************************************************************************** * 9 STATIC FUNCTIONS **************************************************************************** */ /* *=========================================================================== * ipmipha_cmd_print_binding_fmt *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC void ipmippm_cmd_print_binding_fmt(const char *hoa, const char *coa, const char *home_agent, const char *lifetime, const char *nai) { /* */ ipcom_printf("%-20s %-20s %-16s %-15s %s"IP_LF, hoa, coa, home_agent, lifetime, nai); } IP_STATIC void ipmippm_cmd_print_node(Ipmip_proc_t *proc, struct Ipmip_attr *node, struct Ipmip_attr *coa, Ip_bool verbose) { IPMIP_UNUSED_PARAMETER(verbose); ipcom_snprintf(proc->ntop.ntop_lla, sizeof(proc->ntop.ntop_lla), "%d/%d", ipmipmn_api_cli_node_get_time_remaining(node), ipmipmn_api_cli_node_get_time_requested(node)); ipmippm_cmd_print_binding_fmt(ipmip_ntop_inet(proc, ipmipmn_api_cli_node_get_home_address(node)), ipmip_ntop_inet(proc, ipmipmn_api_cli_node_coa_get_address(coa)), ipmip_ntop_inet(proc, ipmipmn_api_cli_node_get_home_agent(node)), proc->ntop.ntop_lla, ipmipmn_api_cli_node_get_nai(node)); } IP_STATIC void ipmippm_cmd_show_node(Ipmip_proc_t *proc, struct Ipmip_attr *node, struct Ipmip_attr *coa, Ip_bool verbose) { Ip_u32 tmp; Ip_u32 status; const char *str; IPMIP_UNUSED_PARAMETER(verbose); ipcom_printf("Proxy Mobile Node : %08x"IP_LF, ipmippm_cli_node_get_handle(node)); status = ipmipmn_api_cli_node_get_status(node); ipcom_printf(" Status : %s"IP_LF, ipmipmn_api_attr_statename[status]); tmp = ipmipmn_api_cli_node_get_home_address(node); if (tmp != 0) ipcom_printf(" Home Address : %s"IP_LF, ipmip_ntop_inet(proc, tmp)); ipcom_printf(" Dynamic Home Address: %s"IP_LF, ipmipmn_api_cli_node_get_home_address_dynamic(node)? "yes" : "no"); tmp = ipmipmn_api_cli_node_get_home_agent(node); if (tmp != 0) ipcom_printf(" Assigned Home Agent : %s"IP_LF, ipmip_ntop_inet(proc, tmp)); tmp = ipmipmn_api_cli_node_get_home_agent_pending(node); if (tmp != 0) ipcom_printf(" Pending Home Agent : %s"IP_LF, ipmip_ntop_inet(proc, tmp)); ipcom_printf(" Reverse Tunnel : %s"IP_LF, ipmipmn_api_cli_node_get_tunnel_reverse(node)? "yes" : "no"); ipcom_printf(" Broadcast : %s"IP_LF, ipmipmn_api_cli_node_get_receive_broadcast(node)? "yes" : "no"); ipcom_printf(" Home Agent Discovery: %s"IP_LF, ipmipmn_api_attr_dhaa[ipmipmn_api_cli_node_get_home_agent_dhaa(node)]); ipcom_printf(" Tunnel type : %s"IP_LF, ipmip_util_tunnel_to_desc(ipmipmn_api_cli_node_get_tunnel_type(node))); str = ipmipmn_api_cli_node_get_nai(node); if (str != IP_NULL) ipcom_printf(" Mobile Node NAI : %s"IP_LF, str); if (status >= IPMIPMN_ATTR_STATE_REGISTERED) { ipcom_printf(" Established : %s"IP_LF, ipmip_ntop_tm(proc, ipmipmn_api_cli_node_get_created(node)));; ipcom_printf(" Updated : %s"IP_LF, ipmip_ntop_tm(proc, ipmipmn_api_cli_node_get_last_updated(node))); ipcom_printf(" Lifetime : %u/%u"IP_LF, ipmipmn_api_cli_node_get_time_remaining(node), ipmipmn_api_cli_node_get_time_requested(node)); str = ipmipmn_api_cli_node_get_nai_ha(node); if (str != IP_NULL) ipcom_printf(" Home Agent NAI : %s"IP_LF, str); str = ipmipmn_api_cli_node_get_nai_aaah(node); if (str != IP_NULL) ipcom_printf(" AAAH Agent NAI : %s"IP_LF, str); } /* Current care of? */ if (coa != IP_NULL) { ipcom_printf(" Care Of Address :"IP_LF); ipcom_printf(" CoA Type : %s"IP_LF, ipmipmn_api_attr_coaname[ipmipmn_api_cli_node_coa_get_type(coa)]); ipcom_printf(" CoA Peer : %s"IP_LF, ipmipmn_api_attr_peername[ipmipmn_api_cli_node_coa_get_peer(coa)]); ipcom_printf(" CoA Address : %s"IP_LF, ipmip_ntop_inet(proc, ipmipmn_api_cli_node_coa_get_address(coa))); ipcom_printf(" Challenge : %s"IP_LF, ipmipmn_api_cli_node_coa_get_challenge(coa)? "yes" : "no"); tmp = ipmipmn_api_cli_node_coa_get_tunnel_flags(coa); ipcom_printf(" NAT Traversal : %s"IP_LF, IP_BIT_ARESET(tmp, IPMIP4_TUNNELMODE_NAT_T_CONFIRMED)? "yes" : "no"); ipcom_printf(" Reg. Revocation : %s"IP_LF, IP_BIT_ARESET(tmp, IPMIP4_TUNNELMODE_REVOCATION_CONFIRMED)? "yes" : "no"); ipcom_printf(" Retransmits : %u"IP_LF, ipmipmn_api_cli_node_coa_get_retransmits(coa)); tmp = ipmipmn_api_cli_node_coa_get_spi_mf(coa); if (tmp) ipcom_printf(" SPI MF : %u"IP_LF, tmp); tmp = ipmipmn_api_cli_node_coa_get_spi_mh(coa); if (tmp) ipcom_printf(" SPI MH : %u"IP_LF, tmp); } } /* *=========================================================================== * ipmippm_cmd_print_event *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC void ipmippm_cmd_handle_exec(Ipmip_proc_t *proc, Ipmip_cli_daemon_t *daemon, Ip_u32 handle, Ip_u32 cmd, Ip_bool verbose) { struct Ipmip_attr *node; Ipmip_cli_daemon_req_t nreq; ipmip_cli_daemon_request_init(&nreq); if (cmd == IPMIPPM_CMD_OP_DELETE) ipmippm_cli_node_delete(daemon, handle); else if ((node = ipmippm_cli_node_get(daemon, &nreq, handle)) != IP_NULL) { struct Ipmip_attr *coa = ipmipmn_api_cli_node_coa_get(node); if(IP_NULL == coa) return; switch (cmd) { case IPMIPPM_CMD_OP_LIST: ipmippm_cmd_print_node(proc, node, coa, verbose); break; case IPMIPPM_CMD_OP_SHOW: ipmippm_cmd_show_node(proc, node, coa, verbose); break; } } ipmip_cli_daemon_request_release(&nreq); } /* **************************************************************************** * 10 GLOBAL FUNCTIONS **************************************************************************** */ /* **************************************************************************** * 11 PUBLIC FUNCTIONS **************************************************************************** */ /* *=========================================================================== * ipmippm_cmd_mn *=========================================================================== * Description: * Parameters: . * Returns: . * */ IP_PUBLIC int ipmippm_cmd_pm(int argc, char **argv) { Ipcom_getopt opt; int op_val; char *op; Ipmip_cli_daemon_t daemon; Ipmip_cli_daemon_req_t req; Ipmip_proc_t *proc = IP_NULL; int i; daemon.fd = IP_INVALID_SOCKET; ipmip_cli_daemon_request_init(&req); proc = ipmip_proc_alloc(); if (proc == IP_NULL) { ipcom_printf("mn: failed to create process context"IP_LF); return -1; } if (argc < 2) goto usage; /* Get a connection to the home agent. */ for (i = 0; i < 10; i++) { if (ipmippm_cli_connect(&daemon)) break; ipcom_sleep(1); } if (daemon.fd == IP_INVALID_SOCKET) { ipcom_printf("pm: failed to connect to proxy client"IP_LF); ipmip_proc_destroy(proc); return -1; } ipcom_getopt_clear_r(&opt); op = argv[1]; op_val = ipcom_cmd_str_to_key(ipmippm_cmd_ops, op); if (op_val == -1) { if (ipmip4_cli_shell_cmd(argc, argv, proc, &daemon) == -1) { ipcom_printf("'%s' is an invalid operation"IP_LF, op); goto usage; } goto exit_out; } if (op_val == IPMIPPM_CMD_OP_LIST || op_val == IPMIPPM_CMD_OP_SHOW || op_val == IPMIPPM_CMD_OP_DELETE) { /* Show node information */ Ip_bool all = IP_FALSE; Ip_bool verbose = IP_FALSE; const char *nai = IP_NULL; Ip_u32 hoa = 0; int args = 0; int ret = IPCOM_SUCCESS; static struct Ip_option long_options[] = { {"hoa", 1, 0, 0}, {"nai", 1, 0, 0}, {"all", 0, 0, 0}, {"verbose", 0, 0, 0}, {0, 0, 0, 0} }; opt.long_only = 1; opt.long_options = long_options; while ((i = ipcom_getopt_r(argc - 1, argv + 1, "av", &opt)) != -1) { switch (i) { case 0: switch(opt.long_index) { case 0: /* hoa -- Home Address */ args++; if (ipcom_inet_pton(IP_AF_INET, opt.optarg, &hoa) != 1) { ipcom_printf("bad '--hoa' IPv4 address."IP_LF); goto usage; } break; case 1: /* nai */ args++; nai = opt.optarg; break; case 2: args++; all = IP_TRUE; break; case 3: verbose = IP_TRUE; break; default: ipcom_printf("unknown option %s", long_options[opt.long_index].name); if (opt.optarg) ipcom_printf(" with arg %s", opt.optarg); ipcom_printf(IP_LF); goto usage; } break; case 'a': args++; all = IP_TRUE; break; case 'v': verbose = IP_TRUE; break; default: ipcom_printf("fa: invalid option '%c'"IP_LF, i); goto usage; } } if (op_val == IPMIPPM_CMD_OP_LIST) ipmippm_cmd_print_binding_fmt("Home Address", "Care of Address", "Home Agent", "Lifetime", "NAI"); if (args > 0) { if (all) ret = ipmippm_cli_node_list(&daemon, &req, IP_NULL, 0); else if (args) ret = ipmippm_cli_node_list(&daemon, &req, nai, hoa); if (ret == IPCOM_SUCCESS) { Ipmip_attr_iter_t riter; Ip_u32 handle; /**/ ipmip_cli_daemon_iter_request_init(&req, &riter); while ((handle = ipmippm_cli_handle_next(&riter)) != 0) ipmippm_cmd_handle_exec(proc, &daemon, handle, op_val, verbose); } } else { for (i = opt.optind + 1; i < argc; i++) ipmippm_cmd_handle_exec(proc, &daemon, ipcom_strtoul(argv[i], IP_NULL, 0), op_val, verbose); } } exit_out: ipmip_cli_daemon_disconnect(&daemon); ipmip_cli_daemon_request_release(&req); ipmip_proc_destroy(proc); return 0; /****** Usage ******/ usage: ipmip_util_identprintf(proc, 0, "NAME"IP_LF); ipmip_util_identprintf(proc, 1, "pm - Displays Proxy Mobile Node bindings, statistics and status" IP_LF); ipmip_util_identprintf(proc, 0, "SYNOPSIS"IP_LF); ipmip_util_identprintf(proc, 1, "pm [arguments]"IP_LF); ipmip_util_identprintf(proc, 0, "DESCRIPTION"IP_LF); ipmip_util_identprintf(proc, 1, "The pm command version %u.%u.%u is used to display current Proxy Mobile Node MIPv4"IP_LF "bindings, statistics and status."IP_LF, (IPMIPPM_RELEASE / 10000) % 100, (IPMIPPM_RELEASE / 100) % 100, IPMIPPM_RELEASE % 100); ipmip_util_identprintf(proc, 0, "COMMANDS"IP_LF); ipmip_util_cmdprintf(proc, 1, "show [--all] [--verbose] [--hoa=] [--nai=] []", "Show the proxy mobile node status"); ipmip_util_identprintf(proc, 2, "--verbose Verbose mode"IP_LF); ipmip_util_identprintf(proc, 2, "--all Affect all nodes"IP_LF); ipmip_util_identprintf(proc, 2, "--hoa= Specify the hoa we're looking for"IP_LF); ipmip_util_identprintf(proc, 2, "--nai= Specify the nai we're looking for"IP_LF); ipmip_util_identprintf(proc, 2, " The unique handle for the proxy mobile node"IP_LF); ipmip_util_cmdprintf(proc, 1, "delete [--all] [--hoa=] [--nai=] []", "Delete the proxy mobile node status"); ipmip_util_identprintf(proc, 2, "--all Affect all nodes"IP_LF); ipmip_util_identprintf(proc, 2, "--hoa= Specify the hoa we're looking for"IP_LF); ipmip_util_identprintf(proc, 2, "--nai= Specify the nai we're looking for"IP_LF); ipmip_util_identprintf(proc, 2, " The unique handle for the proxy mobile node"IP_LF); ipmip_util_cmdprintf(proc, 1, "list [--all] [--hoa=] [--nai=] []", "List the proxy mobile nodes"); ipmip_util_identprintf(proc, 2, "--all Affect all nodes"IP_LF); ipmip_util_identprintf(proc, 2, "--hoa= Specify the hoa we're looking for"IP_LF); ipmip_util_identprintf(proc, 2, "--nai= Specify the nai we're looking for"IP_LF); ipmip_util_identprintf(proc, 2, " The unique handle for the proxy mobile node"IP_LF); ipmip4_cli_shell_usage(proc); ipmip_cli_daemon_disconnect(&daemon); ipmip_cli_daemon_request_release(&req); ipmip_proc_destroy(proc); return 0; } /* **************************************************************************** * END OF FILE **************************************************************************** */