/* ******************************************************************************* * INTERPEAK SOURCE FILE * * Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmipmn_cmd_mn.c,v $ $Revision: 1.29 $ * $Source: /home/interpeak/CVSRoot/ipmipmn/src/ipmipmn_cmd_mn.c,v $ * $Author: jhorteli $ * $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 "ipmipmn.h" #include "ipmipmn_attr.h" #include "ipmipmn_cli.h" /* **************************************************************************** * 4 DEFINES **************************************************************************** */ /* **************************************************************************** * 5 TYPES **************************************************************************** */ /* **************************************************************************** * 6 EXTERN PROTOTYPES **************************************************************************** */ /* **************************************************************************** * 7 LOCAL PROTOTYPES **************************************************************************** */ IP_PUBLIC int ipmipmn_cmd_mn(int argc, char **argv); /* **************************************************************************** * 8 DATA **************************************************************************** */ #define IPMIPMN_CMD_LLH_MT (1) #define IPMIPMN_CMD_OP_SHOW (2) #define IPMIPMN_CMD_OP_SETIF (3) #define IPMIPMN_CMD_OP_LU (4) #define IPMIPMN_CMD_OP_LD (5) IP_STATIC Ipcom_cmd_int_str_map ipmipmn_cmd_ops[] = { { IPMIPMN_CMD_LLH_MT, "mt" }, { IPMIPMN_CMD_OP_LU, "lu" }, { IPMIPMN_CMD_OP_LD, "ld" }, { IPMIPMN_CMD_OP_SHOW, "show" }, { IPMIPMN_CMD_OP_SETIF, "setif" }, { 0, 0 } }; /* **************************************************************************** * 9 STATIC FUNCTIONS **************************************************************************** */ /* **************************************************************************** * 10 GLOBAL FUNCTIONS **************************************************************************** */ /* *=========================================================================== * ipmipmn_cmd_show_status *=========================================================================== * Description: * Parameters: * Returns: * */ IP_STATIC void ipmipmn_cmd_show_status(Ipmip_proc_t *proc, struct Ipmip_attr *node, Ip_bool verbose) { Ip_u32 tmp; Ip_u32 status; struct Ipmip_attr *coa; const char *str; IPMIP_UNUSED_PARAMETER(verbose); /* parse it */ coa = ipmipmn_api_cli_node_coa_get(node); ipcom_printf("Mobile Node :"IP_LF); status = ipmipmn_api_cli_node_get_status(node); ipcom_printf(" Status : %s%s"IP_LF, ipmipmn_api_attr_statename[status], (coa != IP_NULL && ipmipmn_api_cli_node_coa_get_down(coa))? "*" : ""); str = ipmipmn_api_cli_node_get_mipifname(node); if (str != IP_NULL) ipcom_printf(" Mobile Interface : %s"IP_LF, str); str = ipmipmn_api_cli_node_get_ifname(node); if (str != IP_NULL) ipcom_printf(" Interface : %s"IP_LF, str); tmp = ipmipmn_api_cli_node_get_home_address(node); if (tmp != 0) ipcom_printf(" Home Address : %s"IP_LF, ipmip_ntop_inet(proc, tmp)); 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(" Dynamic Home Address: %s"IP_LF, ipmipmn_api_cli_node_get_home_address_dynamic(node)? "yes" : "no"); 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_HOME && 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(" CoA Mobike : %s"IP_LF, ipmipmn_api_cli_node_coa_get_mobike(coa)? "yes" : "no"); 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)); ipcom_printf(" Low Latency : %s"IP_LF, ipmipmn_api_cli_node_coa_get_llh(coa)? "yes" : "no"); 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); } } /* **************************************************************************** * 11 PUBLIC FUNCTIONS **************************************************************************** */ /* *=========================================================================== * ipmipmn_cmd_mn *=========================================================================== * Description: * Parameters: . * Returns: . * */ IP_PUBLIC int ipmipmn_cmd_mn(int argc, char **argv) { Ipcom_getopt opt; int c; 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 (ipmipmn_cli_connect(&daemon)) break; ipcom_sleep(1); } if (daemon.fd == IP_INVALID_SOCKET) { ipcom_printf("mn: failed to connect to mobile node"IP_LF); ipmip_proc_destroy(proc); return -1; } ipcom_getopt_clear_r(&opt); op = argv[1]; op_val = ipcom_cmd_str_to_key(ipmipmn_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 == IPMIPMN_CMD_LLH_MT) { Ip_u32 faip = 0; Ip_u32 faap = 0; const char *ifname = IP_NULL; static struct Ip_option long_options[] = { {"fa", 1, 0, 0}, {"ap", 1, 0, 0}, {"ifname", 1, 0, 0}, {0, 0, 0, 0} }; ipcom_getopt_clear_r(&opt); opt.long_only = 1; opt.long_options = long_options; while((c = ipcom_getopt_r(argc - 1, argv + 1, "", &opt)) != -1) { switch (c) { case 0: switch(opt.long_index) { case 0: /* faip */ if (ipcom_inet_pton(IP_AF_INET, opt.optarg, &faip) != 1) { ipcom_printf("bad '--fa' IPv4 address."IP_LF); goto usage; } break; case 1: /* faap */ faap = ipcom_atoi(opt.optarg); break; case 2: /* mnifname */ ifname = opt.optarg; 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; default: ipcom_printf("Unknown option '%c'"IP_LF, i); goto usage; } } if (ifname == IP_NULL) goto usage; /****** Run the command ******/ ipmipmn_cli_node_llh_mt(&daemon, ifname, faip, faap); } else { ipcom_getopt_clear_r(&opt); if (op_val == IPMIPMN_CMD_OP_SHOW) { struct Ipmip_attr *node; /* joel@interpeak.se * 10.2.3.1:101.1.1.20 */ /* Show node information */ Ip_bool verbose = IP_FALSE; while ((i = ipcom_getopt_r(argc - 1, argv + 1, "v", &opt)) != -1) { switch (i) { case 'v': verbose = IP_TRUE; break; default: ipcom_printf("mn: invalid option '%c'"IP_LF, i); goto usage; } } if ((node = ipmipmn_cli_node_get(&daemon, &req)) != IP_NULL) ipmipmn_cmd_show_status(proc, node, verbose); } else if (op_val == IPMIPMN_CMD_OP_SETIF) { if (argc < 3) goto usage; /**/ ipmipmn_cli_node_setif(&daemon, argv[2]); } else if (op_val == IPMIPMN_CMD_OP_LD) { if (argc < 3) goto usage; /**/ ipmipmn_cli_daemon_if_link_down(&daemon, argv[2]); } else if (op_val == IPMIPMN_CMD_OP_LU) { if (argc < 3) goto usage; /**/ ipmipmn_cli_daemon_if_link_up(&daemon, argv[2]); } 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, "mn - Displays Mobile Node bindings, statistics and status" IP_LF); ipmip_util_identprintf(proc, 0, "SYNOPSIS"IP_LF); ipmip_util_identprintf(proc, 1, "mn [arguments]"IP_LF); ipmip_util_identprintf(proc, 0, "DESCRIPTION"IP_LF); ipmip_util_identprintf(proc, 1, "The mn command version %u.%u.%u is used to display current Mobile Node MIPv4"IP_LF "bindings, statistics and status."IP_LF, (IPMIPMN_RELEASE / 10000) % 100, (IPMIPMN_RELEASE / 100) % 100, IPMIPMN_RELEASE % 100); ipmip_util_identprintf(proc, 0, "COMMANDS"IP_LF); ipmip_util_cmdprintf(proc, 1, "show [-v]", "Show the mobile node status"); ipmip_util_identprintf(proc, 2, "-v Verbose mode"IP_LF); ipmip_util_cmdprintf(proc, 1, "setif ", "Set the interface to be used by the mobile node"); ipmip_util_identprintf(proc, 2, " Interface name"IP_LF); ipmip_util_cmdprintf(proc, 1, "lu ", "Bring a particular interface administratively up"); ipmip_util_identprintf(proc, 2, " Interface name"IP_LF); ipmip_util_cmdprintf(proc, 1, "ld ", "Bring a particular interface administratively down"); ipmip_util_identprintf(proc, 2, " Interface name"IP_LF); ipmip_util_cmdprintf(proc, 1, "mt --ifname= [--fa=] [--ap=]", "Send a mobile trigger"); ipmip_util_identprintf(proc, 2, " Interface name"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 **************************************************************************** */