📄 ni_pppoe.c
字号:
ccb->flags &= ~PPP_ANNOUNCE_FLAG;
}
else {
ccb->flags |= PPP_ANNOUNCE_FLAG;
ccb->mibstat.ifoperstatus = 1; /* mark up now */
}
break;
case SIOCGPPPSTATUS:
{
struct ppp_ioctl *pip;
pip = (struct ppp_ioctl *) arg;
pip->pi_status = ccb->pppstatus;
break;
}
case SIOCSPPPSTATUS:
{
struct ppp_ioctl *pip;
pip = (struct ppp_ioctl *) arg;
if (pip->pi_status == PSDOWN) {
if (ccb->pppstatus == PSUP)
{
CloseLink(unit);
/*lcp_wantoptions[unit].restart = 0; Dont Restart */
}
} else if (pip->pi_status == PSUP) {
if (ccb->pppstatus == PSDOWN) {
/*-----------------------------------------------------*/
/* Open the lcp link - this starts the LCP negotiation.*/
/* This will set PPPStatus and call ioctl(iff_up) */
/* upon finish. */
/*-----------------------------------------------------*/
interfaceinit(unit);
/* setup the link and noitify the lcp layer */
SetupLink(unit);
}
}
break;
}
case SIOCGPPPCFG:
{
struct ppp_cfg *pcp = ((struct ppp_ioctl *) arg)->pi_cfg;
*pcp = *ccp;
break;
}
case SIOCSPPPCFG:
{
struct ppp_cfg *pcp = ((struct ppp_ioctl *) arg)->pi_cfg;
if (ccb->pppstatus == PSUP)
return(-1);
*ccp = *pcp;
break;
}
case SIOCSPPPINIT:
{
if (ccb->pppstatus == PSUP)
return(-1);
/* send ppp init to the pppd task */
msgbuf[0] = MSG_INIT;
msgbuf[1] = unit;
if (q_send(Qid, msgbuf))
return -1;
/* send initialize event to the pppd task */
if (ev_send(Tid, PEV_QEVENT))
return(-1);
break;
}
case SIOCGPPPLINKSTATUS:
{
struct ppp_ioctl *pip;
pip = (struct ppp_ioctl *) arg;
pip->pi_status = ccb->linkstatus;
break;
}
/*----------------------------------------------------------*/
/* MIB ioctls */
/*----------------------------------------------------------*/
case SIOCGIFDESCR:
ifrp->ie_descr = ccb->mibstat.ifDescr;
break;
case SIOCGIFTYPE:
ifrp->ie_type = 23; /* PPP */
break;
case SIOCGIFMTUNIT:
ifrp->ie_mtu = ccb->mibstat.mtu;
break;
case SIOCGIFSPEED:
ifrp->ie_speed = ccb->mibstat.speed;
break;
case SIOCGIFPHYSADDRESS:
bzero((char *)&ifrp->ie_physaddress, sizeof(struct sockaddr));
break;
case SIOCGIFADMINSTATUS:
ifrp->ie_adminstatus = ccb->mibstat.ifadminstatus;
break;
case SIOCSIFADMINSTATUS:
ccb->mibstat.ifadminstatus = ifrp->ie_adminstatus;
if ((ccb->pppstatus != PSUP) && (ccb->mibstat.ifadminstatus == 1))
{
/*---------------------------------------------------------*/
/* Open the lcp link - this starts the LCP negotiation. */
/*---------------------------------------------------------*/
/* setup the link and noitify the lcp layer */
SetupLink(unit);
}
else if ((ccb->pppstatus == PSUP) && (ccb->mibstat.ifadminstatus == 2))
{
ccb->pppstatus = PSDOWN;
ccb->mibstat.ifoperstatus = 2;
lcp_close(unit);
}
break;
case SIOCGIFOPERSTATUS:
ifrp->ie_operstatus = ccb->mibstat.ifoperstatus;
break;
case SIOCGIFLASTCHANGE:
/*----------------------------------------------------------------*/
/* According to rfc1213, this is defined to be the value of */
/* sysUptime when this interface is operating in this mode. That */
/* is assuming that this driver has access to the system group of */
/* the snmp agent, which is not true in this case. Therefore, we */
/* set this value to 0. If this driver is to be used with an */
/* snmp agent, it has to get the sysUptime from the agent. */
/*----------------------------------------------------------------*/
ifrp->ie_lastchange = 0;
break;
case SIOCGIFINOCTETS:
ifrp->ie_inoctets = ccb->mibstat.inoctets;
break;
case SIOCGIFINUCASTPKTS:
ifrp->ie_inucastpkts = ccb->mibstat.inucastpkts;
break;
case SIOCGIFINNUCASTPKTS:
ifrp->ie_innucastpkts = ccb->mibstat.innucastpkts;
break;
case SIOCGIFINDISCARDS:
ifrp->ie_indiscards = ccb->mibstat.indiscards;
break;
case SIOCGIFINERRORS:
ifrp->ie_inerrors = ccb->mibstat.inerrors;
break;
case SIOCGIFINUNKNOWNPROTOS:
ifrp->ie_inunknownprotos = ccb->mibstat.inunknownprotos;
break;
case SIOCGIFOUTOCTETS:
ifrp->ie_outoctets = ccb->mibstat.outoctets;
break;
case SIOCGIFOUTUCASTPKTS:
ifrp->ie_outucastpkts = ccb->mibstat.outucastpkts;
break;
case SIOCGIFOUTNUCASTPKTS:
ifrp->ie_outnucastpkts = ccb->mibstat.outnucastpkts;
break;
case SIOCGIFOUTDISCARDS:
ifrp->ie_outdiscards = ccb->mibstat.outdiscards;
break;
case SIOCGIFOUTERRORS:
ifrp->ie_outerrors = ccb->mibstat.outerrors;
break;
case SIOCGIFOUTQLEN:
ifrp->ie_outqlen = ccb->mibstat.ifoutqlen;
break;
case SIOCGIFSPECIFIC:
break;
default:
break;
}
return 0;
}
/************************************************************************/
/* ni_init: Initialization routine for PPPoE driver. */
/* It uses pSOS device driver routines. */
/* */
/* INPUTS: var1: */
/* */
/* RETURNS: DORMANT or -1 if failed */
/* OUTPUTS: */
/* NOTE(S): */
/* */
/************************************************************************/
static unsigned long ni_init(unsigned long (*ap_addr)(), long num,
struct ni_funcs *funcs)
{
struct ppp_pccb *ccb;
pppoe_init();/* start pppoed_task,init variables */
/* Initialize the channel specific data structures */
nimap[num] = pppunit; /* Set the NI number-Channel map */
ccb = &PPPpccb[pppunit]; /* Get channel control block */
ccb->announce_packet = (int (*)())ap_addr; /* Set channel annouce packet */
ccb->nifuncs = *funcs; /* Set channel NI functions */
ccb->ppperrno = EOK; /* Set Channel errno */
ccb->ifno = num; /* Set Channel NI number */
ccb->flags |= PPP_CANON_MODE; /* Put channel in canonical mode */
/* send ppp unit to the pppd task */
msgbuf[0] = MSG_INIT;
msgbuf[1] = pppunit;
if (q_send(Qid, msgbuf))
return -1;
#if (!OPENTCPIP)
/* send initialize event to the pppd task */
if (ev_send(Tid, PEV_QEVENT))
return(-1);
#endif
pppunit++; /* set to next available unit */
ccb->pppstatus = PSNEGOTIATING;
ccb->linkstatus = PDS_SETUP;
#if (!OPENTCPIP)
return DORMANT; /* up-not-running ... */
#else
return (unsigned long) phyaddress; /* up-not-running ... */
#endif
}
/************************************************************************/
/* ip_input: Received a PPP_IP packet. */
/* INPUTS: */
/* RETURNS: */
/* OUTPUTS: */
/* NOTE(S): */
/************************************************************************/
void ip_input(u_char *p, u_long len, char *arg, u_long unit)
{
struct ppp_pccb *ccb = &PPPpccb[unit];
mblk_t *m;
frtn_t frtn;
frtn.free_func = (void (*)())ni_retpkb;
frtn.free_arg = (char *) arg;
if ((ccb->flags & PPP_ANNOUNCE_FLAG) &&
(m = ccb->nifuncs.esballoc(p, len, 0, &frtn)) != 0)
{
m->b_wptr += len;
#if (!OPENTCPIP)
psos_up_flag = ((u_long (*)(u_short, ... ))
*ccb->announce_packet) (0x800, (u_char *)m, len, ccb->ifno);
#else
psos_up_flag = ((u_long (*)(u_short, ... ))
*ccb->announce_packet) (0x800, (u_char *)m, len,
ccb->ifno, phyaddress, phyaddress);
#endif
}
else
{
ccb->mibstat.indiscards++;
pfree(arg);
}
}
int ppp_queue_output(unit, mp)
int unit;
mblk_t *mp;
{
struct ppp_pccb *ccb = &PPPpccb[unit];
mblk_t *outq;
/* MAINDEBUG((LOG_INFO, "ppp_queue_output: unit %d, mp 0x%x", unit, mp)); */
if (ccb->pppstatus == PSUP)
{
ni_send((char *)NULL, (long) ccb->ifno, (char *)mp, (unsigned long)(mp ->b_wptr - mp->b_rptr), 0);
return 0;
}
ccb->mibstat.ifoutqlen++;
if (ccb->outputQ == NULL ) {
ccb->outputQ = mp;
/* Initialize the serial channel. The channel is
* closed on a timeout.
*/
interfaceinit(unit);
/* setup the link, the first time */
SetupLink(unit);
} else {
outq = ccb->outputQ;
while (outq->b_next)
outq = outq->b_next;
outq->b_next = mp;
}
return 0;
}
int ppp_output(unit)
int unit;
{
struct ppp_pccb *ccb = &PPPpccb[unit];
mblk_t *outq = ccb->outputQ, *mp;
MAINDEBUG((LOG_INFO, "ppp_output: unit %d, outq 0x%x", unit, outq));
while (outq) {
mp = outq->b_next;
outq->b_next = NULL;
ni_send((char *)NULL, (long) ccb->ifno, (char *)outq, (unsigned long)(outq->b_wptr - outq->b_rptr), 0);
outq = mp;
}
ccb->outputQ = NULL;
ccb->mibstat.ifoutqlen = 0;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -