📄 pppmenu.c
字号:
if(!mppp)
{
ns_printf(pio, "Usage: pup linkindex\n");
return -1;
}
//ConPrintf("menu: link up on link %p\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);
ns_printf(pio, "IPCP open started on link %p\n", index);
return 0;
}
#ifdef USE_MODEM /* support old "direct_dial" menu routine */
int
direct_dial(void * pio)
{
return pm_linkup(pio);
}
#endif /* USE_MODEM */
/* FUNCTION: pm_linkdown()
*
* Menu routine to shut down a PPP link.
*
* PARAM1: void * pio
*
* RETURNS: 0 if OK or -1 if error.
*/
int
pm_linkdown(void * pio)
{
M_PPP mppp; /* link for parameter index */
int index;
char * cp = nextarg( ((GEN_IO)pio)->inbuf );
int open; /* TRUE if link was full open */
mppp = ppp_linkbycp(pio, cp, &index);
if(!mppp)
{
ns_printf(pio, "Usage: pdown linkindex\n");
return -1;
}
// ConPrintf("menu: link down on link %p\n");
if(mppp->states[IPCP_STATE] == ST_OPENED)
open = TRUE;
else
open = FALSE;
/* start the close process at IPCP layer */
ppp_close(mppp, IPCP_STATE);
/* If the IPCP was not fully up and the LCP is not now down, then also
* explicitly shut down LCP now:
*/
if(!open && (mppp->states[LCP_STATE] != ST_INITIAL))
ppp_close(mppp, LCP_STATE);
ns_printf(pio, "closing link %d\n", atoi(cp));
return 0;
}
/* FUNCTION: pm_dellink()
*
* Menu routine to kill a PPP link
*
* PARAM1: void * pio
*
* RETURNS: 0 if OK or -1 if error.
*/
int
pm_dellink(void * pio)
{
M_PPP mppp; /* pointer to link to delete */
char * cp = nextarg( ((GEN_IO)pio)->inbuf );
int index;
mppp = ppp_linkbycp(pio, cp, &index);
if(!mppp)
{
ns_printf(pio, "usage: pdel linkindex\n");
return -1;
}
if(mppp->states[LCP_STATE] > ST_STARTING)
{
ns_printf(pio, "Please shut down link first\n");
return -1;
}
del_ppp(mppp);
return 0;
}
#ifdef PPP_MULTILINK
extern NET if_getbyname(void * pio); /* in ..\ip\iface.c */
/* FUNCTION: pm_multilink()
*
* Menu routine to create a new multilink and add link to multilink bundle
*
* PARAM1: void * pio
*
* RETURNS: 0 if OK or -1 if error.
*/
int
pm_multilink(void * pio)
{
char * type; /* type of new PPP link (text) */
char * name; /* name/number of iface from cmd line */
int linetype; /* type of link line to create */
int index; /* index of bundle to join */
M_PPP mppp; /* new link object */
M_PPP bundle; /* bundle to join */
NET ifp; /* iface using this bundle */
name = nextarg(((GEN_IO)pio)->inbuf);
#ifdef DYNAMIC_IFACES
ifp = if_getbyname(pio);
if(!ifp)
goto usage;
#else /* "name" must be numeric index */
index = atoi(name); /* borrow index var for a while */
if((index == 0) && (*name != '0')) /* verify user gave a number */
{
ns_printf(pio, "iface must be numeric index\n");
goto usage;
}
ifp = nets[index];
#endif
if((ifp->n_local == NULL) || (ifp->mib.ifType != PPP))
{
ns_printf(pio, "iface %s is not a PPP net.\n", name);
goto usage;
}
bundle = (M_PPP)(ifp->n_local);
index = index_bymppp(bundle);
if((bundle == NULL) || (bundle->ml_ipcp == NULL) || (index < 0))
{
ns_printf(pio, "Link for index %d is not a PPP ML bundle.\n", index);
goto usage;
}
linetype = ppp_default_type; /* set line default (modem, uart, etc) */
type = nextarg(name); /* see if there is cmd line type arg */
if(*type == 0)
goto type_set; /* no arg, use default type */
linetype = get_linetype(type);
if(linetype < 0)
{
ns_printf(pio, "bad type '%s'\n", type);
goto usage;
}
type_set:
/* The parameters are now read from the command line and parsed. The
* code which follows may be used as an example of how to create
* a new link and join it to a multilink bundle.
*/
mppp = new_mlppp(ifp, linetype);
/* Set a pointer to the bundle's IPCP object. When we then do an LCP
* connect (as client or server) this setting will cause this mppp to
* be merged with the bundle rather than initiating a IPCP state for it.
*/
mppp->ml_ipcp = bundle;
/* start the actual connection of the new link */
ppp_open(mppp, LCP_STATE);
ns_printf(pio, "LCP open started on link %d\n", index);
return 0;
usage:
ns_printf(pio, "Usage: link bundle_iface [linktype(PPPOE|UART|MODEM|LOOPBACK)]\n");
return -1;
}
/* FUNCTION: pm_srvlink()
*
* Menu routine to create an unattached M_PPP structure which is listening for
* a device to come up.
*
* PARAM1: void * pio
*
* RETURNS: 0 if OK or -1 if error.
*/
int
pm_srvlink(void * pio)
{
int linetype;
M_PPP mppp;
char * cp;
cp = nextarg(((GEN_IO)pio)->inbuf);
if(*cp == 0)
goto usage;
linetype = get_linetype(cp);
if(linetype < 0)
goto usage;
/* create an unattached M_PPP structure which is listening for
* a device to come up
*/
mppp = new_mlppp(NULL, linetype);
if(mppp)
ns_printf(pio, "created link %p\n", mppp);
else
ns_printf(pio, "failed to create link.\n");
return 0;
usage:
ns_printf(pio, "Usage: 'mlserve linktype' (PPPOE|UART|MODEM|LOOPBACK)\n");
return -1;
}
#endif /* PPP_MULTILINK */
/* FUNCTION: pm_linkstat()
*
* Menu routine to do detailed stats dump for a PPP link
*
* PARAM1: void * pio
*
* RETURNS: 0 if OK or -1 if error.
*/
int
pm_linkstat(void * pio)
{
M_PPP mppp; /* pointer to link for stats dump */
char * cp = nextarg( ((GEN_IO)pio)->inbuf );
int index;
mppp = ppp_linkbycp(pio, cp, &index);
if(!mppp)
{
ns_printf(pio, "usage: pls linkindex\n");
return -1;
}
ppp_mstats(pio, mppp);
#ifdef PPP_MULTILINK
{
M_PPP link; /* pointer to link to ML links, if any */
/* loop through the Multilink links and dump any which are not
* the master link.
*/
for(link = mppp->ml_links; link; link = link->ml_next)
{
if(link == mppp)
ns_printf(pio, "*** Master link is also a sublink\n");
else
{
ns_printf(pio, "*** Sublink:\n");
ppp_mstats(pio, link);
}
}
}
#endif /* PPP_MULTILINK */
return 0;
}
/* FUNCTION: pm_options()
*
* Menu routine to toggle some boolean options in PPP links
*
* PARAM1: void * pio
*
* RETURNS: 0 if OK or -1 if error.
*/
int
pm_options(void * pio)
{
int index; /* index of PPP link to toggle */
int toggle; /* ON (1) or OFF (0) */
char * opcode; /* text for option string */
int bitflag; /* bit for option to be set/cleared */
M_PPP mppp;
char * cp = nextarg( ((GEN_IO)pio)->inbuf );
/* get PPP link index from cmd line */
mppp = ppp_linkbycp(pio, cp, &index);
if(!mppp)
{
ns_printf(pio, "bad index\n");
goto usage;
}
opcode = nextarg(cp);
if((*opcode != '-') && (*opcode != '+'))
{
ns_printf(pio, "option must start with '+' to enable, '-' to disable\n");
goto usage;
}
if(*opcode == '+')
toggle = 1;
else
toggle = 0;
opcode++;
switch (*opcode)
{
case 'm':
bitflag = ALLOW_ML;
break;
case 'd':
bitflag = IPCP_DHCP;
break;
case 'v':
bitflag = ALLOW_VJ;
break;
default:
goto usage;
}
if(toggle)
mppp->pppflags |= bitflag;
else
mppp->pppflags &= ~bitflag;
ns_printf(pio, "flag %s %sabled on link %p\n", opcode, toggle?"en":"dis", mppp);
return 0;
usage:
ns_printf(pio, "usage: poption link_index [+|-]opcode \n");
ns_printf(pio, " options are:\n ml - multilink\n vj - VJ compression\n");
ns_printf(pio, " dh - DHCP client\nexample: poption 0 -ml\n");
return -1;
}
/* FUNCTION: pm_xovers()
*
* Menu routine to display loopback-crossover linkages
*
* PARAM1: void * pio
*
* RETURNS: 0
*/
#ifdef LB_XOVER
int
pm_xovers(void * pio)
{
int i;
int index;
int links = 0;
for(i = 0; i < MAX_LBXOVERS; i++)
{
if(lb_mppps[i] == NULL)
continue;
links++;
if(links == 1)
ns_printf(pio, "index link status\n");
index = index_bymppp(lb_mppps[i]);
ns_printf(pio, " %d - %p, ", index, lb_mppps[i]);
if(lb_otherend[i] == NULL)
{
ns_printf(pio, "unlinked\n");
}
else
{
index = index_bymppp(lb_otherend[i]);
ns_printf(pio, "linked to %d - %p\n", index, lb_otherend[i]);
}
}
if(links == 0)
ns_printf(pio, "No LBXOVER links\n");
return 0;
}
#endif /* LB_XOVER */
/* FUNCTION: pm_maxhexdump()
*
* Menu routine to set the maximum number of bytes to hexdump via ConPrintf
* in a single packet.
*
* PARAM1: void * pio
*
* RETURNS: 0 if OK or -1 if error.
*/
int
pm_maxhexdump(void * pio)
{
char * cp = nextarg( ((GEN_IO)pio)->inbuf );
if(*cp == 0)
{
ns_printf(pio, "please specify max length; 0 disables hexdump\n");
return -1;
}
ppp_hexmax = atoi(cp);
ns_printf(pio, "ppp hexdump len now limited to %d bytes\n", ppp_hexmax);
return 0;
}
#endif /* PPP_MENU */
#endif /* USE_PPP - whole file can be ifdeffed out */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -