📄 pppmenu.c
字号:
/*
* FILENAME: pppmenu.c
*
* Copyright 2001 By InterNiche Technologies Inc. All rights reserved
*
*
* MODULE: PPP
*
* ROUTINES: pm_defmtu(), ppp_byindex(), index_bymppp(),
* ROUTINES: ppp_linkbycp(), get_linetype(), pm_linklist(), pm_linkup(),
* ROUTINES: pm_linkdown(), pm_dellink(), pm_multilink(), pm_srvlink(),
* ROUTINES: pm_linkstat(), pm_options(), pm_xovers(), pm_maxhexdump(), direct_dial(),
*
* PORTABLE: yes
*/
#include "ipport.h"
#ifdef USE_PPP /* whole file can be ifdeffed out */
#include "ppp_port.h"
#include "mppp.h"
/* FUNCTION: ppp_byindex()
*
* Select a ppp link based on a zero-based index
*
* PARAM1: int index - 0 based index of link to get
*
* RETURNS: Pointer to indexed PPP link, NULL if index too high.
*/
M_PPP
ppp_byindex(int index)
{
M_PPP mppp;
int count = 0;
for(mppp = ppp_list; mppp; mppp = mppp->next)
{
if(count++ == index)
return mppp;
}
/* fall to here is we counted through whole loop */
return NULL;
}
/* (yaxon add) */
void ppp_up(void)
{
M_PPP mppp; /* link for parameter index */
mppp = ppp_byindex(0);
if(mppp == NULL) {
dtrap("pppmenu 1\n");
return;
}
//ConPrintf("link up on link 0\n");
/* If the PPP has an iface, make sure admin status is UP */
if(mppp->ifp)
mppp->ifp->mib.ifAdminStatus = 1;
/* start the open process */
ppp_open(mppp, IPCP_STATE);
}
/* (yaxon add) */
#ifdef PPP_MENU
#ifndef IN_MENUS
#error PPP_MENU requires IN_MENUS to be set
#endif /* IN_MENUS */
char * linetypes[] =
{
"Foo",
"PPP",
"SLIP",
"UART",
"ATMODEM",
"PPPOE",
"LBXOVER",
"(PORT)",
};
extern char * fsmstate[10];
#include "menu.h"
int pm_linklist(void * pio);
int pm_linkup(void * pio);
int pm_linkdown(void * pio);
int pm_dellink(void * pio);
int pm_multilink(void * pio);
int pm_srvlink(void * pio);
int pm_linkstat(void * pio);
int pm_options(void * pio);
int pm_xovers(void * pio);
int pm_maxhexdump(void * pio);
int pm_defmtu(void * pio);
int pm_setuser(void * pio);
int pm_setpass(void * pio);
extern void ppp_mstats(void * pio, M_PPP mppp);
/* array of menu options, see menu.h */
struct menu_op ppp_menu[] =
{
#ifdef USE_PPPOE /* needs a name which won't match "pppoe" */
"mppp", stooges, "PPP managemnt menu",
#else
"ppp", stooges, "PPP managemnt menu",
#endif
"plist", pm_linklist, "list current PPP links",
"pup", pm_linkup, "bring up a PPP link",
"pdown", pm_linkdown, "take down a PPP link",
"pdel", pm_dellink, "delete an unused PPP link object",
"plstat", pm_linkstat, "detailed stats for a single link",
"poptions", pm_options, "set/clear link options",
"phexlen", pm_maxhexdump, "set length of pkt log hexdumps",
"pmtu", pm_defmtu, "set default MTU for new links",
"puser", pm_setuser, "set PPP user name",
"ppass", pm_setpass, "set PPP password/secret",
#ifdef PPP_MULTILINK
"mlink", pm_multilink, "add new client link to multilink bundle",
"mlserve", pm_srvlink, "create new multilink server link",
#endif /* PPP_MULTILINK */
#ifdef LB_XOVER
"pxover", pm_xovers, "list crosover loopback devices",
#endif /* LB_XOVER */
NULL, NULL, NULL, /* end of list marker */
};
/* FUNCTION: pm_defmtu()
*
* set default MTU for new links
*
* PARAM1: void * pio
*
* RETURNS: 0 if OK, else ENP_ error code
*/
int
pm_defmtu(void * pio)
{
char * cp = nextarg( ((GEN_IO)pio)->inbuf );
int newmtu;
if(*cp == 0) /* no parameter */
{
ns_printf(pio, "current mtu: %d\n", ppp_mtu);
return 0;
}
newmtu = atoi(cp);
ns_printf(pio, "changing PPP MTU from %d to %d\n", ppp_mru, newmtu);
ppp_mru = newmtu;
ppp_mtu = newmtu;
return 0;
}
/* FUNCTION: index_bymppp()
*
* return the current list index for an mppp object
*
* PARAM1: M_PPP bundle - the PPP session to index
*
* RETURNS: 0 based index of passed session, -1 if not found
*/
int
index_bymppp(M_PPP bundle)
{
int index; /* index of bundle to join */
M_PPP mppp; /* new link object */
for(index = 0, mppp = ppp_list; mppp; mppp = mppp->next, index++)
{
if(mppp == bundle)
return index;
}
dtrap("pppmenu 0\n");
return -1;
}
/* FUNCTION: ppp_linkbycp()
*
* Get M_PPP based on index. Index is decimal digit
* characters pointed to by passed parameter.
*
* PARAM1: void * pio
* PARAM2: char * cp
* PARAM3: int * indexptr
*
* RETURNS: link for passed index, NULL if error.
*/
M_PPP
ppp_linkbycp(void * pio, char * cp, int * indexptr)
{
M_PPP mppp; /* link to return */
int index; /* scratch - index of link */
if(*cp == 0 || cp == NULL)
{
ns_printf(pio, "Missing link number parameter\n");
return NULL;
}
if(*cp < '0' || *cp > '9')
{
ns_printf(pio, "Bad index '%s'. Must be a decimal number.\n", cp);
return NULL;
}
index = atoi(cp);
mppp = ppp_byindex(index);
if(mppp == NULL)
{
ns_printf(pio, "Bad index: %d\n", index);
return NULL;
}
*indexptr = index; /* return index */
return mppp;
}
#ifdef PPP_MULTILINK
/* FUNCTION: get_linetype()
*
* convert command line "type" character into a PPP LN_ type
*
* PARAM1: char * type
*
* RETURNS: typecode if OK, else -1
*/
static int
get_linetype(char * type)
{
/* convert command line "type" parameter into a code */
switch(*type)
{
case 'P': /* PPPoE */
case 'p':
return LN_PPPOE;
case 'u': /* raw uart */
case 'U':
return LN_UART;
case 'm': /* modem */
case 'M':
return LN_ATMODEM;
case 'l': /* loopback */
case 'L':
return LN_LBXOVER;
default:
return -1;
}
}
#endif /* PPP_MULTILINK */
/* FUNCTION: pm_setuser()
*
* Menu routine to set a link's PPP password
*
* PARAM1: void * pio
*
* RETURNS: 0 if OK or -1 if error
*/
int
pm_setuser(void * pio)
{
M_PPP mppp;
int index;
char * username;
char * cp = nextarg( ((GEN_IO)pio)->inbuf );
mppp = ppp_linkbycp(pio, cp, &index);
if(!mppp)
{
ns_printf(pio, "please enter a numeric PPP link index\n");
goto usage;
}
username = nextarg( cp );
if(*username == 0) /* no parameter, just print current one */
{
ns_printf(pio, "current name for link %d is: %s\n", index, mppp->username);
return 0;
}
strcpy( mppp->username, username);
mppp->userlen = strlen(username);
ns_printf(pio, "set link %d usename to %s.\n", index, mppp->username);
return 0;
usage:
ns_printf(pio, "usage: puser index [username]\n");
return -1;
}
/* FUNCTION: pm_setpass()
*
* Menu routine to set a link's PPP password
*
* PARAM1: void * pio
*
* RETURNS: 0 if OK or -1 if error
*/
int
pm_setpass(void * pio)
{
M_PPP mppp;
int index;
char * password;
char * cp = nextarg( ((GEN_IO)pio)->inbuf );
mppp = ppp_linkbycp(pio, cp, &index);
if(!mppp)
{
ns_printf(pio, "please enter a numeric PPP link index\n");
goto usage;
}
password = nextarg( cp );
if(*password == 0) /* no parameter, just print current one */
{
ns_printf(pio, "current password for link %d is: %s\n", index, mppp->password);
return 0;
}
strcpy( mppp->password, password);
mppp->pwlen = strlen(password);
ns_printf(pio, "set link %d password to %s.\n", index, mppp->password);
return 0;
usage:
ns_printf(pio, "usage: ppass index [password]\n");
return -1;
}
/* FUNCTION: pm_linklist()
*
* Menu routine to list current PPP links
*
* PARAM1: void * pio
*
* RETURNS: 0
*/
int
pm_linklist(void * pio)
{
M_PPP mppp;
int index;
if(ppp_list == NULL)
{
ns_printf(pio, "no ppp links\n");
return 0;
}
#ifdef PPP_MULTILINK
ns_printf(pio, "index link_addr iface flags type LCP IPCP MultiLink \n");
#else /* PPP_MULTILINK */
ns_printf(pio, "index link_addr iface flags type LCP IPCP\n");
#endif /* PPP_MULTILINK */
for(mppp = ppp_list, index = 0; mppp; mppp = mppp->next)
{
char * ifname;
if(mppp->ifp)
ifname = mppp->ifp->name;
else
ifname = "---";
ns_printf(pio, " %d - 0x%p %s %04x ",
index++, mppp, ifname, mppp->pppflags);
ns_printf(pio, "%s %s %s ",
linetypes[mppp->line.lower_type], fsmstate[mppp->states[LCP_STATE]],
fsmstate[mppp->states[IPCP_STATE]] );
#ifdef PPP_MULTILINK
if((mppp->pppflags & ALLOW_ML) == 0)
ns_printf(pio, "disabled");
else
{
int linkflags = mppp->pppflags & (ML_IPCP|ML_LCP);
switch (linkflags)
{
case 0:
ns_printf(pio, "enabled, idle");
break;
case ML_IPCP:
ns_printf(pio, "Bundle master - IPCP only");
break;
case (ML_IPCP|ML_LCP):
ns_printf(pio, "Bundle master & link");
break;
case ML_LCP:
ns_printf(pio, "link for bundle %p", mppp->ml_ipcp);
break;
}
}
#endif /* PPP_MULTILINK */
ns_printf(pio, "\n");
}
return 0;
}
/* FUNCTION: pm_linkup()
*
* Menu routine to start up a PPP link.
*
* PARAM1: void * pio
*
* RETURNS: 0 if OK or -1 if error.
*/
int
pm_linkup(void * pio)
{
M_PPP mppp; /* link for parameter index */
int index;
char * cp = nextarg( ((GEN_IO)pio)->inbuf );
mppp = ppp_linkbycp(pio, cp, &index);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -