X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=modules%2Fppp.c;h=0000cb147ac319d7500dd48da87543742ceafd7e;hp=b3d78a336c1694cafecedd0007dbe9283e9b61c0;hb=92c20f261b9618715d6b1579e997e8757a88174e;hpb=a44a616baa968a263dc273bc06ed79c475b7deec diff --git a/modules/ppp.c b/modules/ppp.c index b3d78a3..0000cb1 100644 --- a/modules/ppp.c +++ b/modules/ppp.c @@ -14,7 +14,7 @@ * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF - * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY + * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, @@ -24,11 +24,11 @@ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, * OR MODIFICATIONS. * - * $Id: ppp.c,v 1.1 1995/12/11 05:06:40 paulus Exp $ + * $Id: ppp.c,v 1.3 1996/01/01 22:48:39 paulus Exp $ */ /* - * This file is used under Solaris 2 and SunOS 4. + * This file is used under Solaris 2, SVR4, and SunOS 4. */ #include @@ -38,6 +38,7 @@ #include #include #include +#include #ifdef SVR4 #include #include @@ -66,7 +67,7 @@ #endif /* - * The IP module uses this SAP value for IP packets. + * The IP module may use this SAP value for IP packets. */ #ifndef ETHERTYPE_IP #define ETHERTYPE_IP 0x800 @@ -76,6 +77,8 @@ #define PPP_MAXMTU 65535 #endif +extern time_t time; + /* * Private information; one per upper stream. */ @@ -90,6 +93,7 @@ typedef struct upperstr { struct upperstr *ppa; /* control stream for our ppa */ struct upperstr *next; /* next stream for this ppa */ uint ioc_id; /* last ioctl ID for this stream */ + enum NPmode npmode; /* what to do with packets on this SAP */ /* * There is exactly one control stream for each PPA. * The following fields are only used for control streams. @@ -100,6 +104,8 @@ typedef struct upperstr { int mru; int mtu; struct pppstat stats; /* statistics */ + time_t last_sent; /* time last NP packet sent */ + time_t last_recv; /* time last NP packet rcvd */ #ifdef SOL2 kstat_t *kstats; /* stats for netstat */ #endif /* SOL2 */ @@ -282,6 +288,8 @@ pppopen(q, dev, oflag, sflag) up->ifflags = IFF_UP | IFF_POINTOPOINT; #endif up->sap = -1; + up->last_sent = up->last_recv = time; + up->npmode = NPMODE_DROP; q->q_ptr = (caddr_t) up; WR(q)->q_ptr = (caddr_t) up; noenable(WR(q)); @@ -396,7 +404,7 @@ pppuwput(q, mp) queue_t *q; mblk_t *mp; { - upperstr_t *us, *usnext, *ppa, *os; + upperstr_t *us, *usnext, *ppa, *os, *nps; struct iocblk *iop; struct linkblk *lb; #ifdef LACHTCP @@ -404,8 +412,9 @@ pppuwput(q, mp) int i; #endif queue_t *lq; - int error, n; + int error, n, sap; mblk_t *mq; + struct ppp_idle *pip; us = (upperstr_t *) q->q_ptr; switch (mp->b_datap->db_type) { @@ -429,6 +438,10 @@ pppuwput(q, mp) freemsg(mp); break; } +#ifdef NO_DLPI + if ((us->flags & US_CONTROL) == 0) + us->ppa->last_sent = time; +#endif if (!send_data(mp, us)) putq(q, mp); break; @@ -598,6 +611,47 @@ pppuwput(q, mp) } break; + case PPPIO_NPMODE: + if (iop->ioc_count != 2 * sizeof(int)) + break; + if ((us->flags & US_CONTROL) == 0) + break; + sap = ((int *)mp->b_cont->b_rptr)[0]; + for (nps = us->next; nps != 0; nps = nps->next) + if (nps->sap == sap) + break; + if (nps == 0) + break; + nps->npmode = (enum NPmode) ((int *)mp->b_cont->b_rptr)[1]; + if (nps->npmode == NPMODE_DROP || nps->npmode == NPMODE_ERROR) + flushq(WR(nps->q), FLUSHDATA); + else if (nps->npmode == NPMODE_PASS && qsize(WR(nps->q)) > 0 + && (nps->flags & US_BLOCKED) == 0) + qenable(WR(nps->q)); + iop->ioc_count = 0; + error = 0; + break; + + case PPPIO_GIDLE: + if ((ppa = us->ppa) == 0) + break; + mq = allocb(sizeof(struct ppp_idle), BPRI_HI); + if (mq == 0) { + error = ENOSR; + break; + } + if (mp->b_cont != 0) + freemsg(mp->b_cont); + mp->b_cont = mq; + mq->b_cont = 0; + pip = (struct ppp_idle *) mq->b_wptr; + pip->xmit_idle = time - ppa->last_sent; + pip->recv_idle = time - ppa->last_recv; + mq->b_wptr += sizeof(struct ppp_idle); + iop->ioc_count = sizeof(struct ppp_idle); + error = 0; + break; + #ifdef LACHTCP case SIOCSIFNAME: printf("SIOCSIFNAME\n"); @@ -840,9 +894,7 @@ dlpi_request(q, mp, us) except that we accept ETHERTYPE_IP in place of PPP_IP. */ sap = d->bind_req.dl_sap; us->req_sap = sap; -#if DEBUG - cmn_err(CE_CONT, "ppp bind %x\n", sap); -#endif + DPRINT1("ppp bind %x\n", sap); if (sap == ETHERTYPE_IP) sap = PPP_IP; if (sap < 0x21 || sap > 0x3fff || (sap & 0x101) != 1) { @@ -886,7 +938,7 @@ dlpi_request(q, mp, us) } us->sap = -1; us->state = DL_UNBOUND; -#ifndef sun +#ifdef LACHTCP us->ppa->ifstats.ifs_active = 0; #endif dlpi_ok(q, DL_UNBIND_REQ); @@ -899,17 +951,16 @@ dlpi_request(q, mp, us) dlpi_error(q, DL_UNITDATA_REQ, DL_OUTSTATE, 0); break; } - if (us->ppa == 0) { + if ((ppa = us->ppa) == 0) { cmn_err(CE_CONT, "ppp: in state dl_idle but ppa == 0?\n"); break; } len = mp->b_cont == 0? 0: msgdsize(mp->b_cont); - if (len > us->ppa->mtu) { -#if DEBUG - cmn_err(CE_CONT, "dlpi data too large (%d > %d)\n", len, us->mtu); -#endif + if (len > ppa->mtu) { + DPRINT2("dlpi data too large (%d > %d)\n", len, ppa->mtu); break; } + ppa->last_sent = time; /* this assumes PPP_HDRLEN <= sizeof(dl_unitdata_req_t) */ if (mp->b_datap->db_ref > 1) { np = allocb(PPP_HDRLEN, BPRI_HI); @@ -1028,10 +1079,10 @@ send_data(mp, us) queue_t *q; upperstr_t *ppa; - if (us->flags & US_BLOCKED) + if (us->flags & US_BLOCKED || us->npmode == NPMODE_QUEUE) return 0; ppa = us->ppa; - if (ppa == 0) { + if (ppa == 0 || us->npmode == NPMODE_DROP || us->npmode == NPMODE_ERROR) { freemsg(mp); return 1; } @@ -1083,6 +1134,7 @@ new_ppa(q, mp) us->nextppa = *usp; *usp = us; us->flags |= US_CONTROL; + us->npmode = NPMODE_PASS; us->mtu = PPP_MRU; us->mru = PPP_MRU; @@ -1402,6 +1454,7 @@ ppplrput(q, mp) putq(us->q, mp); else putq(q, mp); + ppa->last_recv = time; break; } }