tw_cli_ip.c.svn-base
资源名称:cli.rar [点击查看]
上传用户:hujq123
上传日期:2016-04-10
资源大小:153k
文件大小:18k
源码类别:
Telnet服务器
开发平台:
Unix_Linux
- /*
- * Copyright (C) 2002 Koninklijke Philips Electronics N.V.,
- * All Rights Reserved.
- *
- * This source code and any compilation or derivative thereof is the
- * proprietary information of Koninklijke Philips Electronics N.V.
- * and is confidential in nature.
- * Under no circumstances is this software to be exposed to or placed
- * under an Open Source License of any type without the expressed
- * written permission of Koninklijke Philips Electronics N.V.
- *
- *###########################################################
- */
- /*!
- * file tw_cli_ip.c
- *
- * brief -
- *
- */
- /*-----------------------------------------------------------*
- *
- * %version: 3 %
- * instance: DS_6
- * %date_created: Fri Feb 21 08:04:33 2003 %
- *
- *###########################################################
- */
- /****************************************************************************
- *
- * Filename : tw_cli_ip.c
- * Purpose : CLI command objects and functions to support IP commands.
- *
- *
- *****************************************************************************/
- #include <stdio.h>
- #include <stdarg.h>
- #include <string.h>
- #include <tmtypes.h>
- #include <tw_cli.h>
- /*****************************************************************************
- *
- * External Globals
- *
- *****************************************************************************/
- static int CliCoVoproc_Unavailable(Cli_cmdSession_t *pSess,
- char *CmdStr, int Ptr);
- /**************** *** Definition of CLI Command Objects *** ***************/
- /*** "ip" commands ***/
- /*** 3rd level CLI Command Option - ip arp "flush"
- ***/
- static int CliCoProc_IpArpFlush(Cli_cmdSession_t *pSess,
- char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_IpArpFlush =
- {
- "flush",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "flush the entire IP ARP cache",
- NULL_HELP_FUNC,
- #if defined(FUSION_TCPIP)
- CliCoProc_IpArpFlush,
- #else
- CliCoVoproc_Unavailable,
- #endif
- NULL_VAR_OPT_FUNC
- };
- /*** 3rd level CLI Command Option - ip route "add"
- ***/
- static int CliCoVoproc_IpRouteAdd(Cli_cmdSession_t *pSess,
- char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_IpRouteAdd =
- {
- "add",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "add a static IP route {DEV_NAME GW_IP DST_IP/MASK COST}",
- NULL_HELP_FUNC,
- NULL_PROC_FUNC,
- CliCoVoproc_IpRouteAdd
- };
- /*** 3rd level CLI Command Option - ip route "del"
- ***/
- static int CliCoVoproc_IpRouteDel(Cli_cmdSession_t *pSess,
- char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_IpRouteDel =
- {
- "del",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "delete a static IP route {DEV_NAME DST_IP/MASK}",
- NULL_HELP_FUNC,
- NULL_PROC_FUNC,
- CliCoVoproc_IpRouteDel
- };
- /*** 3rd level CLI Command Option - ip netdev "down"
- ***/
- static int CliCoVoproc_IpNetdevDown(Cli_cmdSession_t *pSess,
- char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_IpNetdevDown =
- {
- "down",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "bring down a network device {DEV_NAME IP/MASK}",
- NULL_HELP_FUNC,
- NULL_PROC_FUNC,
- #if defined(FUSION_TCPIP)
- CliCoVoproc_IpNetdevDown
- #else
- CliCoVoproc_Unavailable
- #endif
- };
- /*** 3rd level CLI Command Option - ip netdev "up"
- ***/
- static int CliCoVoproc_IpNetdevUp(Cli_cmdSession_t *pSess,
- char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_IpNetdevUp =
- {
- "up",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "bring up a network device {DEV_NAME IP/MASK}",
- NULL_HELP_FUNC,
- NULL_PROC_FUNC,
- #if defined(FUSION_TCPIP)
- CliCoVoproc_IpNetdevUp
- #else
- CliCoVoproc_Unavailable
- #endif
- };
- /*** 2nd level CLI Command Option - ip "arp"
- ***/
- Cli_CmdStruct_t *CliCoOptionList_IpArp[] =
- {
- &CliCo_IpArpFlush,
- NULL
- };
- Cli_CmdStruct_t CliCo_IpArp =
- {
- "arp",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- CliCoOptionList_IpArp,
- "manipulate IP ARP cache",
- NULL_HELP_FUNC,
- NULL_PROC_FUNC,
- NULL_VAR_OPT_FUNC
- };
- /*** 2nd level CLI Command Option - ip "route"
- ***/
- Cli_CmdStruct_t *CliCoOptionList_IpRoute[] =
- {
- &CliCo_IpRouteAdd,
- &CliCo_IpRouteDel,
- NULL
- };
- Cli_CmdStruct_t CliCo_IpRoute =
- {
- "route",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- CliCoOptionList_IpRoute,
- "configure static IP route",
- NULL_HELP_FUNC,
- NULL_PROC_FUNC,
- NULL_VAR_OPT_FUNC
- };
- /*** 1st level CLI Command Option - "ip"
- ***/
- Cli_CmdStruct_t *CliRcoOptionList_Ip[] =
- {
- &CliCo_IpArp,
- &CliCo_IpRoute,
- NULL
- };
- Cli_CmdStruct_t CliRco_Ip =
- {
- "ip",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- CliRcoOptionList_Ip,
- "IP configuration command",
- NULL_HELP_FUNC,
- NULL_PROC_FUNC,
- NULL_VAR_OPT_FUNC
- };
- /*** "show ip" commands ***/
- /*** 3rd level CLI Command Option - show ip "arp"
- ***/
- static int CliCoProc_ShowIpArp(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_ShowIpArp =
- {
- "arp",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "display IP ARP cache table",
- NULL_HELP_FUNC,
- #if defined(FUSION_TCPIP)
- CliCoProc_ShowIpArp,
- #else
- CliCoVoproc_Unavailable,
- #endif
- NULL_VAR_OPT_FUNC
- };
- /*** 3rd level CLI Command Option - show ip "netdev"
- ***/
- static int CliCoProc_ShowIpNetdev(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_ShowIpNetdev =
- {
- "netdev",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "display routing port info",
- NULL_HELP_FUNC,
- #if defined(FUSION_TCPIP)
- CliCoProc_ShowIpNetdev,
- #else
- CliCoVoproc_Unavailable,
- #endif
- NULL_VAR_OPT_FUNC
- };
- /*** 3rd level CLI Command Option - show ip "udp"
- ***/
- extern int CliCoProc_ShowUdp(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_ShowUdp =
- {
- "udp",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "displays the udp socket statitistics from fusion",
- NULL_HELP_FUNC,
- #if defined(FUSION_TCPIP)
- CliCoProc_ShowUdp,
- #else
- CliCoVoproc_Unavailable,
- #endif
- NULL_VAR_OPT_FUNC
- };
- /*** 3rd level CLI Command Option - show ip "tcp"
- ***/
- extern int CliCoProc_ShowTcp(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_ShowTcp =
- {
- "tcp",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "displays the tcp socket statitistics from fusion",
- NULL_HELP_FUNC,
- #if defined(FUSION_TCPIP)
- CliCoProc_ShowTcp,
- #else
- CliCoVoproc_Unavailable,
- #endif
- NULL_VAR_OPT_FUNC
- };
- /*** 3rd level CLI Command Option - show ip "heap"
- ***/
- extern int CliCoProc_ShowHeap(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_ShowHeap =
- {
- "heap",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "displays the heap status in fusion",
- NULL_HELP_FUNC,
- #if defined(FUSION_TCPIP)
- CliCoProc_ShowHeap,
- #else
- CliCoVoproc_Unavailable,
- #endif
- NULL_VAR_OPT_FUNC
- };
- #if 0
- /*** 3rd level CLI Command Option - show ip "route"
- ***/
- extern int CliCoProc_ShowRoute(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliCo_ShowIpRoute =
- {
- "route",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "displays all IP routes",
- NULL_HELP_FUNC,
- CliCoProc_ShowRoute,
- NULL_VAR_OPT_FUNC
- };
- #endif
- /*** 2nd level CLI Command Option - show "ip"
- ***/
- Cli_CmdStruct_t *CliCoOptionList_ShowIp[] =
- {
- &CliCo_ShowIpArp,
- &CliCo_ShowIpNetdev,
- &CliCo_ShowUdp,
- &CliCo_ShowTcp,
- &CliCo_ShowHeap,
- NULL
- };
- Cli_CmdStruct_t CliCo_ShowIp =
- {
- "ip",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- CliCoOptionList_ShowIp,
- "display IP related info",
- NULL_HELP_FUNC,
- NULL_PROC_FUNC,
- NULL_VAR_OPT_FUNC
- };
- /*****************************************************************************
- * int CliCoVoproc_IpRouteAdd(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- *
- * Description :
- * This is the command processing handler for
- * "ip route add DEVICE_NAME GW_IP DST_IP/MASK COST"
- *
- * Arguments :
- * Standard parameters.
- *
- * Returns :
- * 0 if OK, -1 if bad.
- *
- * History
- * who when why
- * KBL 10/9/99 created
- *
- *****************************************************************************/
- int CliCoVoproc_IpRouteAdd(Cli_cmdSession_t *pSess,
- char *CmdStr,
- int Ptr)
- {
- int Status;
- char DeviceName[20], GwIpStr[64], IpAndMaskStr[64];
- unsigned int DstIpAddress = 0, DstIpMask = 0, GwIpAddress = 0, Cost = 0;
- if (sscanf(CmdStr + Ptr, "%s %s %s %d",
- DeviceName, GwIpStr, IpAndMaskStr, &Cost) != 4)
- {
- goto BadParamError;
- }
- if (Cli_IpAndMask2int(GwIpStr, &GwIpAddress, NULL) == -1)
- {
- goto BadParamError;
- }
- if (Cli_IpAndMask2int(IpAndMaskStr, &DstIpAddress, &DstIpMask) == -1)
- {
- goto BadParamError;
- }
- #if defined(FUSION_TCPIP)
- Status = ll_route(DeviceName,
- GwIpAddress,
- DstIpAddress,
- DstIpMask,
- Cost);
- #endif /* defined(FUSION_TCPIP) */
- #if defined(BLUNK_TCPIP)
- Status = tcpAddRoute(GwIpAddress, DstIpAddress,DstIpMask);
- #endif /* defined(BLUNK_TCPIP) */
- if (!Status)
- {
- Cli_Printf(pSess, "Static route installed for "
- "%d.%d.%d.%d/%d.%d.%d.%d via %d.%d.%d.%d thru %sn",
- (DstIpAddress >> 24) & 0xFF,
- (DstIpAddress >> 16) & 0xFF,
- (DstIpAddress >> 8 ) & 0xFF,
- (DstIpAddress ) & 0xFF,
- (DstIpMask >> 24) & 0xFF,
- (DstIpMask >> 16) & 0xFF,
- (DstIpMask >> 8 ) & 0xFF,
- (DstIpMask ) & 0xFF,
- (GwIpAddress >> 24) & 0xFF,
- (GwIpAddress >> 16) & 0xFF,
- (GwIpAddress >> 8 ) & 0xFF,
- (GwIpAddress ) & 0xFF,
- DeviceName);
- }
- else
- {
- Cli_Printf(pSess, operationFailedStr);
- }
- goto Done;
- BadParamError:
- Cli_Printf(pSess, badParamStr);
- Done :
- return 0;
- }
- /*****************************************************************************
- * CliCoVoproc_IpRouteDel(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- *
- * Description :
- * This is the command processing handler for
- * "ip route del DEVICE_NAME DST_IP/MASK"
- *
- * Arguments :
- * Standard parameters.
- *
- * Returns :
- * 0 if OK, -1 if bad.
- *
- * History
- * who when why
- * KBL 10/9/99 created
- *
- *****************************************************************************/
- int CliCoVoproc_IpRouteDel(Cli_cmdSession_t *pSess,
- char *CmdStr,
- int Ptr)
- {
- int Status;
- char DeviceName[20], IpAndMaskStr[64];
- unsigned int DstIpAddress = 0, DstIpMask = 0;
- unsigned int GwIpAddress = 0;
- if (sscanf(CmdStr + Ptr, "%s %s",
- DeviceName, IpAndMaskStr) != 2)
- {
- goto BadParamError;
- }
- if (Cli_IpAndMask2int(IpAndMaskStr, &DstIpAddress, &DstIpMask) == -1)
- {
- goto BadParamError;
- }
- #if defined(FUSION_TCPIP)
- Status = ll_del_static_route(DeviceName,
- DstIpAddress,
- DstIpMask);
- #endif /* defined(FUSION_TCPIP) */
- #if defined(BLUNK_TCPIP)
- Status = tcpDelRoute(GwIpAddress, DstIpAddress,DstIpMask);
- #endif /* defined(BLUNK_TCPIP) */
- if (!Status)
- {
- Cli_Printf(pSess, "Static route deleted for "
- "%d.%d.%d.%d/%d.%d.%d.%d thru %sn",
- (DstIpAddress >> 24) & 0xFF,
- (DstIpAddress >> 16) & 0xFF,
- (DstIpAddress >> 8 ) & 0xFF,
- (DstIpAddress ) & 0xFF,
- (DstIpMask >> 24) & 0xFF,
- (DstIpMask >> 16) & 0xFF,
- (DstIpMask >> 8 ) & 0xFF,
- (DstIpMask ) & 0xFF,
- DeviceName);
- }
- else
- {
- Cli_Printf(pSess, operationFailedStr);
- }
- goto Done;
- BadParamError:
- Cli_Printf(pSess, badParamStr);
- Done :
- return 0;
- }
- /*****************************************************************************
- * int CliCoVoproc_IpNetdevUp(Cli_cmdSession_t *pSess, char *cmdStr, int ptr)
- *
- * Description :
- * This is the command processing handler for
- * "netdev up x.x.x.x y.y.y.y"
- *
- * Arguments :
- * Standard prarameters.
- *
- * Returns :
- * 0 if OK, -1 if bad.
- *
- * History
- * who when why
- * KBL 7/15/99 created
- *
- *****************************************************************************/
- int CliCoVoproc_IpNetdevUp(Cli_cmdSession_t *pSess,
- char *cmdStr,
- int ptr)
- {
- int errp;
- char *pb, devName[20];
- unsigned int ipaddress = 0;
- unsigned int ipmask = 0;
- if (sscanf(cmdStr + ptr, "%s", devName) != 1)
- goto ReturnError;
- pb = cmdStr + ptr + strlen(devName);
- if (Cli_IpAndMask2int(pb, &ipaddress, &ipmask) == -1)
- {
- goto ReturnError;
- }
- Cli_Printf(pSess,
- "Bringing up %s with %d.%d.%d.%d/%d.%d.%d.%d ...n",
- devName,
- ipaddress & 0xFF, (ipaddress >> 8) & 0xFF,
- (ipaddress >> 16) & 0xFF, (ipaddress >> 24) & 0xFF,
- ipmask & 0xFF, (ipmask >> 8) & 0xFF,
- (ipmask >> 16) & 0xFF, (ipmask >> 24) & 0xFF );
- if ((errp = ll_config(devName, ipaddress, ipmask, 0, 0)) == 0)
- {
- Cli_Printf(pSess, "Donen");
- }
- else
- {
- Cli_Printf(pSess, "Failed (%d)n", errp);
- }
- return 0;
- ReturnError:
- Cli_Printf(pSess, "Bad paramn");
- return 0;
- }
- /*****************************************************************************
- * int CliCoVoproc_IpNetdevDown(Cli_cmdSession_t *pSess, char *cmdStr, int ptr)
- *
- * Description :
- * This is the command processing handler for
- * "netdev down x.x.x.x y.y.y.y"
- *
- * Arguments :
- * Standard prarameters.
- *
- * Returns :
- * 0 if OK, -1 if bad.
- *
- * History
- * who when why
- * KBL 7/15/99 created
- *
- *****************************************************************************/
- int CliCoVoproc_IpNetdevDown(Cli_cmdSession_t *pSess,
- char *cmdStr,
- int ptr)
- {
- int errp;
- char *pb, devName[20];
- unsigned int ipaddress = 0;
- unsigned int ipmask = 0;
- if (sscanf(cmdStr + ptr, "%s", devName) != 1)
- goto ReturnError;
- pb = cmdStr + ptr + strlen(devName);
- if (Cli_IpAndMask2int(pb, &ipaddress, &ipmask) == -1)
- {
- goto ReturnError;
- }
- Cli_Printf(pSess,
- "Bringing down %s with %d.%d.%d.%d/%d.%d.%d.%d ...n",
- devName,
- ipaddress & 0xFF, (ipaddress >> 8) & 0xFF,
- (ipaddress >> 16) & 0xFF, (ipaddress >> 24) & 0xFF,
- ipmask & 0xFF, (ipmask >> 8) & 0xFF,
- (ipmask >> 16) & 0xFF, (ipmask >> 24) & 0xFF );
- if ((errp = ll_unconfig(devName)) == 0)
- {
- Cli_Printf(pSess, "Donen");
- }
- else
- {
- Cli_Printf(pSess, "Failed (%d)n", errp);
- }
- return 0;
- ReturnError:
- Cli_Printf(pSess, badParamStr);
- return 0;
- }
- /*****************************************************************************
- * int CliCoProc_ShowIpArp(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- *
- * Description :
- * This is the command processing handler for
- * "show ip arp"
- *
- * Arguments :
- * Standard prarameters.
- *
- * Returns :
- * 0 if OK, -1 if bad.
- *
- * History
- * who when why
- * KBL 12/27/99 created
- *
- *****************************************************************************/
- extern int Cli_PrintArp (Cli_cmdSession_t *pSess);
- static int CliCoProc_ShowIpArp(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- {
- return Cli_PrintArp (pSess);
- }
- /*****************************************************************************
- * int CliCoProc_IpArpFlush(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- *
- * Description :
- * This is the command processing handler for
- * "ip arp flush"
- *
- * Arguments :
- * Standard prarameters.
- *
- * Returns :
- * 0 if OK, -1 if bad.
- *
- * History
- * who when why
- * KBL 12/28/99 created
- *
- *****************************************************************************/
- extern int TwFns_ArpFlush (void);
- static int CliCoProc_IpArpFlush(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- {
- TwFns_ArpFlush();
- return 0;
- }
- /*****************************************************************************
- * int CliCoProc_ShowIpNetdev(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- *
- * Description :
- * This is the command processing handler for
- * "show ip netdev"
- *
- * Arguments :
- * Standard prarameters.
- *
- * Returns :
- * 0 if OK, -1 if bad.
- *
- * History
- * who when why
- * KBL 2/31/00 created
- *
- *****************************************************************************/
- extern int show_nd_status(void *pSess);
- extern UInt32 Fns_GetSysUpTimeInSecond( void );
- extern int Cli_PrintPrimaryStaticIpFsm(Cli_cmdSession_t *pSess);
- int CliCoProc_ShowIpNetdev(Cli_cmdSession_t *pSess, char *cmdStr, int ptr)
- {
- if (show_nd_status(pSess) < 0)
- {
- return -1;
- }
- return 0;
- }
- /*****************************************************************************
- * int CliCoVoproc_Unavailable(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr)
- *
- * Description :
- * Stub for unavailable feature.
- *
- * Arguments :
- * Standard prarameters.
- *
- * Returns :
- * 0 if OK, -1 if bad.
- *
- * History
- * who when why
- * KBL 2/31/00 created
- *
- *****************************************************************************/
- static int CliCoVoproc_Unavailable(Cli_cmdSession_t *pSess,
- char *CmdStr, int Ptr)
- {
- Cli_Printf(pSess, "FIXTHIS: Temporarily disabled because it's stack specific...n");
- return 0;
- }