1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* PPP IP Protocol Interface
|
|
|
|
*
|
|
|
|
* Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the Internet Initiative Japan. The name of the
|
|
|
|
* IIJ may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1997-06-09 03:27:43 +00:00
|
|
|
* $Id: ip.c,v 1.20 1997/05/26 00:44:01 brian Exp $
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-01-31 06:29:58 +00:00
|
|
|
* TODO:
|
|
|
|
* o Return ICMP message for filterd packet
|
|
|
|
* and optionaly record it into log.
|
|
|
|
*/
|
|
|
|
#include "fsm.h"
|
|
|
|
#include "lcpproto.h"
|
|
|
|
#include "hdlc.h"
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_icmp.h>
|
|
|
|
#include <netinet/udp.h>
|
|
|
|
#include <netinet/tcp.h>
|
1996-01-11 17:48:59 +00:00
|
|
|
#include <arpa/inet.h>
|
1997-05-23 04:54:03 +00:00
|
|
|
#include <alias.h>
|
1997-05-26 00:44:10 +00:00
|
|
|
#include "loadalias.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "vars.h"
|
|
|
|
#include "filter.h"
|
1997-06-09 03:27:43 +00:00
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1995-02-26 12:18:08 +00:00
|
|
|
extern void SendPppFrame();
|
1995-01-31 06:29:58 +00:00
|
|
|
extern void LcpClose();
|
|
|
|
|
|
|
|
static struct pppTimer IdleTimer;
|
|
|
|
|
|
|
|
static void IdleTimeout()
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogPHASE, "Idle timer expired.\n");
|
1997-05-24 17:32:42 +00:00
|
|
|
reconnect(RECON_FALSE);
|
1995-01-31 06:29:58 +00:00
|
|
|
LcpClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start Idle timer. If timeout is reached, we call LcpClose() to
|
|
|
|
* close LCP and link.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
StartIdleTimer()
|
|
|
|
{
|
1996-12-03 21:38:52 +00:00
|
|
|
if (!(mode & (MODE_DEDICATED|MODE_DDIAL))) {
|
1995-01-31 06:29:58 +00:00
|
|
|
StopTimer(&IdleTimer);
|
|
|
|
IdleTimer.func = IdleTimeout;
|
|
|
|
IdleTimer.load = VarIdleTimeout * SECTICKS;
|
|
|
|
IdleTimer.state = TIMER_STOPPED;
|
|
|
|
StartTimer(&IdleTimer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
void
|
|
|
|
UpdateIdleTimer()
|
|
|
|
{
|
|
|
|
if (IdleTimer.state == TIMER_RUNNING)
|
|
|
|
StartIdleTimer();
|
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
|
|
|
StopIdleTimer()
|
|
|
|
{
|
|
|
|
StopTimer(&IdleTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If any IP layer traffic is detected, refresh IdleTimer.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
RestartIdleTimer()
|
|
|
|
{
|
1996-12-03 21:38:52 +00:00
|
|
|
if (!(mode & (MODE_DEDICATED|MODE_DDIAL)) && ipKeepAlive ) {
|
1995-01-31 06:29:58 +00:00
|
|
|
StartTimer(&IdleTimer);
|
|
|
|
ipIdleSecs = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-01-30 11:08:50 +00:00
|
|
|
static u_short interactive_ports[32] = {
|
|
|
|
544, 513, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 21, 22, 23, 0, 0, 0, 0, 0, 0, 0, 543,
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
1996-01-30 11:08:50 +00:00
|
|
|
#define INTERACTIVE(p) (interactive_ports[(p) & 0x1F] == (p))
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
static char *TcpFlags[] = {
|
|
|
|
"FIN", "SYN", "RST", "PSH", "ACK", "URG",
|
|
|
|
};
|
|
|
|
|
1995-02-26 12:18:08 +00:00
|
|
|
static char *Direction[] = { "INP", "OUT", "OUT", "IN/OUT" };
|
|
|
|
static struct filterent *Filters[] = { ifilters, ofilters, dfilters, afilters };
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
PortMatch(op, pport, rport)
|
|
|
|
int op;
|
|
|
|
u_short pport, rport;
|
|
|
|
{
|
|
|
|
switch (op) {
|
|
|
|
case OP_EQ:
|
|
|
|
return(pport == rport);
|
|
|
|
case OP_GT:
|
|
|
|
return(pport > rport);
|
|
|
|
case OP_LT:
|
|
|
|
return(pport < rport);
|
|
|
|
default:
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check a packet against with defined filters
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
FilterCheck(pip, direction)
|
|
|
|
struct ip *pip;
|
|
|
|
int direction;
|
|
|
|
{
|
|
|
|
struct filterent *fp = Filters[direction];
|
|
|
|
int gotinfo, cproto, estab, n;
|
|
|
|
struct tcphdr *th;
|
|
|
|
struct udphdr *uh;
|
|
|
|
struct icmp *ih;
|
|
|
|
char *ptop;
|
|
|
|
u_short sport, dport;
|
|
|
|
|
|
|
|
if (fp->action) {
|
|
|
|
cproto = gotinfo = estab = 0;
|
|
|
|
sport = dport = 0;
|
|
|
|
for (n = 0; n < MAXFILTERS; n++) {
|
|
|
|
if (fp->action) {
|
1995-09-17 16:14:49 +00:00
|
|
|
/* permit fragments on in and out filter */
|
|
|
|
if ((direction == FL_IN || direction == FL_OUT) &&
|
1996-01-30 11:08:50 +00:00
|
|
|
(ntohs(pip->ip_off) & IP_OFFMASK) != 0) {
|
1995-09-17 16:14:49 +00:00
|
|
|
return(A_PERMIT);
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogDEBUG, "rule = %d\n", n);
|
1995-01-31 06:29:58 +00:00
|
|
|
if ((pip->ip_src.s_addr & fp->smask.s_addr) == fp->saddr.s_addr
|
|
|
|
&& (pip->ip_dst.s_addr & fp->dmask.s_addr) == fp->daddr.s_addr) {
|
|
|
|
if (fp->proto) {
|
|
|
|
if (!gotinfo) {
|
|
|
|
ptop = (char *)pip + (pip->ip_hl << 2);
|
|
|
|
|
|
|
|
switch (pip->ip_p) {
|
|
|
|
case IPPROTO_ICMP:
|
|
|
|
cproto = P_ICMP; ih = (struct icmp *)ptop;
|
|
|
|
sport = ih->icmp_type; estab = 1;
|
|
|
|
break;
|
|
|
|
case IPPROTO_UDP:
|
|
|
|
cproto = P_UDP; uh = (struct udphdr *)ptop;
|
|
|
|
sport = ntohs(uh->uh_sport); dport = ntohs(uh->uh_dport);
|
|
|
|
estab = 1;
|
|
|
|
break;
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
cproto = P_TCP; th = (struct tcphdr *)ptop;
|
|
|
|
sport = ntohs(th->th_sport); dport = ntohs(th->th_dport);
|
|
|
|
estab = (th->th_flags & TH_ACK);
|
1997-06-09 03:27:43 +00:00
|
|
|
if (estab == 0)
|
|
|
|
LogPrintf(LogDEBUG, "flag = %02x, sport = %d, dport = %d\n",
|
|
|
|
th->th_flags, sport, dport);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return(A_DENY); /* We'll block unknown type of packet */
|
|
|
|
}
|
|
|
|
gotinfo = 1;
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogDEBUG, "dir = %d, proto = %d, srcop = %d,"
|
|
|
|
" dstop = %d, estab = %d\n", direction, cproto,
|
|
|
|
fp->opt.srcop, fp->opt.dstop, estab);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
|
|
|
LogPrintf(LogDEBUG, "check0: rule = %d, proto = %d, sport = %d,"
|
|
|
|
" dport = %d\n", n, cproto, sport, dport);
|
|
|
|
LogPrintf(LogDEBUG, "check0: action = %d\n", fp->action);
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
if (cproto == fp->proto) {
|
|
|
|
if ((fp->opt.srcop == OP_NONE ||
|
|
|
|
PortMatch(fp->opt.srcop, sport, fp->opt.srcport))
|
|
|
|
&&
|
|
|
|
(fp->opt.dstop == OP_NONE ||
|
|
|
|
PortMatch(fp->opt.dstop, dport, fp->opt.dstport))
|
|
|
|
&&
|
|
|
|
(fp->opt.estab == 0 || estab)) {
|
|
|
|
return(fp->action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Address is mached. Make a decision. */
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogDEBUG, "check1: action = %d\n", fp->action);
|
1995-01-31 06:29:58 +00:00
|
|
|
return(fp->action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fp++;
|
|
|
|
}
|
|
|
|
return(A_DENY); /* No rule is mached. Deny this packet */
|
|
|
|
}
|
|
|
|
return(A_PERMIT); /* No rule is given. Permit this packet */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
IcmpError(pip, code)
|
|
|
|
struct ip *pip;
|
|
|
|
int code;
|
|
|
|
{
|
|
|
|
#ifdef notdef
|
|
|
|
struct mbuf *bp;
|
|
|
|
|
|
|
|
if (pip->ip_p != IPPROTO_ICMP) {
|
|
|
|
bp = mballoc(cnt, MB_IPIN);
|
|
|
|
bcopy(ptr, MBUF_CTOP(bp), cnt);
|
1996-01-30 11:08:50 +00:00
|
|
|
SendPppFrame(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
RestartIdleTimer();
|
|
|
|
ipOutOctets += cnt;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For debugging aid.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
PacketCheck(cp, nb, direction)
|
|
|
|
char *cp;
|
|
|
|
int nb;
|
|
|
|
int direction;
|
|
|
|
{
|
|
|
|
struct ip *pip;
|
|
|
|
struct tcphdr *th;
|
|
|
|
struct udphdr *uh;
|
|
|
|
struct icmp *icmph;
|
|
|
|
char *ptop;
|
|
|
|
int mask, len, n;
|
|
|
|
int logit;
|
|
|
|
int pri = PRI_NORMAL;
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
logit = LogIsKept(LogTCPIP);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
pip = (struct ip *)cp;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
if (logit) LogPrintf(LogTCPIP, "%s ", Direction[direction]);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
ptop = (cp + (pip->ip_hl << 2));
|
|
|
|
|
|
|
|
switch (pip->ip_p) {
|
|
|
|
case IPPROTO_ICMP:
|
|
|
|
if (logit) {
|
|
|
|
icmph = (struct icmp *)ptop;
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogTCPIP, "ICMP: %s:%d ---> ", inet_ntoa(pip->ip_src), icmph->icmp_type);
|
|
|
|
LogPrintf(LogTCPIP, "%s:%d\n", inet_ntoa(pip->ip_dst), icmph->icmp_type);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IPPROTO_UDP:
|
|
|
|
if (logit) {
|
|
|
|
uh = (struct udphdr *)ptop;
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogTCPIP, "UDP: %s:%d ---> ", inet_ntoa(pip->ip_src), ntohs(uh->uh_sport));
|
|
|
|
LogPrintf(LogTCPIP, "%s:%d\n", inet_ntoa(pip->ip_dst), ntohs(uh->uh_dport));
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
th = (struct tcphdr *)ptop;
|
|
|
|
if (pip->ip_tos == IPTOS_LOWDELAY)
|
|
|
|
pri = PRI_FAST;
|
1996-01-30 11:08:50 +00:00
|
|
|
else if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) {
|
1995-01-31 06:29:58 +00:00
|
|
|
if (INTERACTIVE(ntohs(th->th_sport)) || INTERACTIVE(ntohs(th->th_dport)))
|
|
|
|
pri = PRI_FAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logit) {
|
|
|
|
len = ntohs(pip->ip_len) - (pip->ip_hl << 2) - (th->th_off << 2);
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogTCPIP, "TCP: %s:%d ---> ", inet_ntoa(pip->ip_src), ntohs(th->th_sport));
|
|
|
|
LogPrintf(LogTCPIP, "%s:%d", inet_ntoa(pip->ip_dst), ntohs(th->th_dport));
|
1995-01-31 06:29:58 +00:00
|
|
|
n = 0;
|
|
|
|
for (mask = TH_FIN; mask != 0x40; mask <<= 1) {
|
|
|
|
if (th->th_flags & mask)
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogTCPIP, " %s", TcpFlags[n]);
|
1995-01-31 06:29:58 +00:00
|
|
|
n++;
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogTCPIP, " seq:%x ack:%x (%d/%d)\n",
|
1995-01-31 06:29:58 +00:00
|
|
|
ntohl(th->th_seq), ntohl(th->th_ack), len, nb);
|
|
|
|
if ((th->th_flags & TH_SYN) && nb > 40) {
|
|
|
|
u_short *sp;
|
|
|
|
|
|
|
|
ptop += 20;
|
|
|
|
sp = (u_short *)ptop;
|
|
|
|
if (ntohs(sp[0]) == 0x0204)
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogTCPIP, " MSS = %d\n", ntohs(sp[1]));
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1996-01-30 11:08:50 +00:00
|
|
|
|
|
|
|
if ((FilterCheck(pip, direction) & A_DENY)) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogDEBUG, "blocked.\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
if (direction == 0) IcmpError(pip, pri);
|
|
|
|
return(-1);
|
|
|
|
} else {
|
1995-03-11 15:18:55 +00:00
|
|
|
if ( FilterCheck(pip, FL_KEEP ) & A_DENY ) { /* Check Keep Alive filter */
|
1995-02-26 12:18:08 +00:00
|
|
|
ipKeepAlive = FALSE;
|
|
|
|
} else {
|
|
|
|
ipKeepAlive = TRUE;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
return(pri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IpInput(bp)
|
|
|
|
struct mbuf *bp; /* IN: Pointer to IP pakcet */
|
|
|
|
{
|
|
|
|
u_char *cp;
|
|
|
|
struct mbuf *wp;
|
|
|
|
int nb, nw;
|
|
|
|
u_char tunbuff[MAX_MRU];
|
|
|
|
|
|
|
|
cp = tunbuff;
|
|
|
|
nb = 0;
|
1997-06-09 03:27:43 +00:00
|
|
|
for (wp = bp; wp; wp = wp->next) { /* Copy to contiguous region */
|
1995-01-31 06:29:58 +00:00
|
|
|
bcopy(MBUF_CTOP(wp), cp, wp->cnt);
|
|
|
|
cp += wp->cnt;
|
|
|
|
nb += wp->cnt;
|
|
|
|
}
|
|
|
|
|
1996-12-12 14:39:47 +00:00
|
|
|
if (mode & MODE_ALIAS) {
|
1997-05-23 04:54:03 +00:00
|
|
|
int iresult;
|
|
|
|
char *fptr;
|
1996-12-12 14:39:47 +00:00
|
|
|
|
1997-05-26 00:44:10 +00:00
|
|
|
iresult = VarPacketAliasIn(tunbuff, sizeof tunbuff);
|
1997-05-23 04:54:03 +00:00
|
|
|
nb = ntohs(((struct ip *) tunbuff)->ip_len);
|
|
|
|
|
|
|
|
if (nb > MAX_MRU) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogERROR, "IpInput: Problem with IP header length\n");
|
1997-05-23 04:54:03 +00:00
|
|
|
pfree(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iresult == PKT_ALIAS_OK
|
|
|
|
|| iresult == PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
|
|
|
|
if ( PacketCheck(tunbuff, nb, FL_IN ) < 0) {
|
|
|
|
pfree(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipInOctets += nb;
|
|
|
|
|
|
|
|
nb = ntohs(((struct ip *) tunbuff)->ip_len);
|
|
|
|
nw = write(tun_out, tunbuff, nb);
|
|
|
|
if (nw != nb)
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
|
1997-05-23 04:54:03 +00:00
|
|
|
|
|
|
|
if (iresult == PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
|
1997-05-26 00:44:10 +00:00
|
|
|
while ((fptr = VarGetNextFragmentPtr(tunbuff)) != NULL) {
|
|
|
|
VarFragmentAliasIn(tunbuff, fptr);
|
1997-05-23 04:54:03 +00:00
|
|
|
nb = ntohs(((struct ip *) fptr)->ip_len);
|
|
|
|
nw = write(tun_out, fptr, nb);
|
|
|
|
if (nw != nb)
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
|
1997-05-23 04:54:03 +00:00
|
|
|
free(fptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (iresult == PKT_ALIAS_UNRESOLVED_FRAGMENT) {
|
|
|
|
nb = ntohs(((struct ip *) tunbuff)->ip_len);
|
|
|
|
fptr = malloc(nb);
|
1997-06-09 03:27:43 +00:00
|
|
|
if (fptr == NULL)
|
|
|
|
LogPrintf(LogALERT, "IpInput: Cannot allocate memory for fragment\n");
|
1997-05-23 04:54:03 +00:00
|
|
|
else {
|
|
|
|
memcpy(fptr, tunbuff, nb);
|
1997-05-26 00:44:10 +00:00
|
|
|
VarSaveFragmentPtr(fptr);
|
1997-05-23 04:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-05-23 04:54:03 +00:00
|
|
|
else
|
|
|
|
{ /* no aliasing */
|
|
|
|
if ( PacketCheck(tunbuff, nb, FL_IN ) < 0)
|
|
|
|
{
|
|
|
|
pfree(bp);
|
|
|
|
return;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-05-23 04:54:03 +00:00
|
|
|
ipInOctets += nb;
|
|
|
|
nw = write(tun_out, tunbuff, nb);
|
|
|
|
if (nw != nb)
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
|
1997-05-23 04:54:03 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
pfree(bp);
|
|
|
|
|
|
|
|
RestartIdleTimer();
|
|
|
|
}
|
|
|
|
|
1996-01-30 11:08:50 +00:00
|
|
|
static struct mqueue IpOutputQueues[PRI_FAST+1];
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
IpEnqueue(pri, ptr, count)
|
|
|
|
int pri;
|
|
|
|
char *ptr;
|
|
|
|
int count;
|
|
|
|
{
|
|
|
|
struct mbuf *bp;
|
|
|
|
|
|
|
|
bp = mballoc(count, MB_IPQ);
|
|
|
|
bcopy(ptr, MBUF_CTOP(bp), count);
|
|
|
|
Enqueue(&IpOutputQueues[pri], bp);
|
|
|
|
}
|
|
|
|
|
1995-05-30 03:57:47 +00:00
|
|
|
int
|
1995-03-11 15:18:55 +00:00
|
|
|
IsIpEnqueued()
|
|
|
|
{
|
|
|
|
struct mqueue *queue;
|
|
|
|
int exist = FALSE;
|
1996-01-30 11:08:50 +00:00
|
|
|
for (queue = &IpOutputQueues[PRI_FAST]; queue >= IpOutputQueues; queue--) {
|
1995-03-11 15:18:55 +00:00
|
|
|
if ( queue->qlen > 0 ) {
|
|
|
|
exist = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( exist );
|
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
|
|
|
IpStartOutput()
|
|
|
|
{
|
|
|
|
struct mqueue *queue;
|
|
|
|
struct mbuf *bp;
|
1997-05-10 01:22:19 +00:00
|
|
|
int cnt;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
if (IpcpFsm.state != ST_OPENED)
|
|
|
|
return;
|
1996-01-30 11:08:50 +00:00
|
|
|
for (queue = &IpOutputQueues[PRI_FAST]; queue >= IpOutputQueues; queue--) {
|
1995-01-31 06:29:58 +00:00
|
|
|
if (queue->top) {
|
|
|
|
bp = Dequeue(queue);
|
|
|
|
if (bp) {
|
|
|
|
cnt = plength(bp);
|
1996-01-30 11:08:50 +00:00
|
|
|
SendPppFrame(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
RestartIdleTimer();
|
|
|
|
ipOutOctets += cnt;
|
1996-01-30 11:08:50 +00:00
|
|
|
break;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|