o Don't enter phase TERMINATE in the LCP TLD, leave it exclusively
for the last NCP TLF. o Move tun reading from the main loop into the bundle descriptor handling routines. o Cosmetic: Add a few `const's and make some diagnostics clearer.
This commit is contained in:
parent
183df580c7
commit
078c562e54
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=35790
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: bundle.c,v 1.1.2.71 1998/05/05 03:01:24 brian Exp $
|
||||
* $Id: bundle.c,v 1.1.2.72 1998/05/05 23:29:55 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -73,6 +73,7 @@
|
||||
#include "async.h"
|
||||
#include "physical.h"
|
||||
#include "modem.h"
|
||||
#include "loadalias.h"
|
||||
#include "auth.h"
|
||||
#include "lcpproto.h"
|
||||
#include "chap.h"
|
||||
@ -235,30 +236,22 @@ bundle_LayerDown(void *v, struct fsm *fp)
|
||||
/*
|
||||
* The given FSM has been told to come down.
|
||||
* If it's our last NCP, stop the idle timer.
|
||||
* If it's our last NCP *OR* LCP, enter TERMINATE phase.
|
||||
* If it's an LCP and we're in multilink mode, adjust our tun speed.
|
||||
*/
|
||||
|
||||
struct bundle *bundle = (struct bundle *)v;
|
||||
|
||||
if (fp->proto == PROTO_IPCP) {
|
||||
if (fp->proto == PROTO_IPCP)
|
||||
bundle_StopIdleTimer(bundle);
|
||||
} else if (fp->proto == PROTO_LCP) {
|
||||
int speed, others_active;
|
||||
else if (fp->proto == PROTO_LCP && bundle->ncp.mp.active) {
|
||||
int speed;
|
||||
struct datalink *dl;
|
||||
|
||||
others_active = 0;
|
||||
for (dl = bundle->links, speed = 0; dl; dl = dl->next)
|
||||
if (fp != &dl->physical->link.lcp.fsm &&
|
||||
dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP) {
|
||||
if (fp != &dl->physical->link.lcp.fsm && dl->state == DATALINK_OPEN)
|
||||
speed += modem_Speed(dl->physical);
|
||||
others_active++;
|
||||
}
|
||||
if (bundle->ncp.mp.active && speed)
|
||||
if (speed)
|
||||
tun_configure(bundle, bundle->ncp.mp.link.lcp.his_mru, speed);
|
||||
|
||||
if (!others_active)
|
||||
bundle_NewPhase(bundle, PHASE_TERMINATE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -369,6 +362,14 @@ bundle_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
|
||||
for (desc = bundle->desc.next; desc; desc = desc->next)
|
||||
result += descriptor_UpdateSet(desc, r, w, e, n);
|
||||
|
||||
/* If there are aren't many packets queued, look for some more. */
|
||||
if (bundle_FillQueues(bundle) < 20) {
|
||||
if (*n < bundle->tun_fd + 1)
|
||||
*n = bundle->tun_fd + 1;
|
||||
FD_SET(bundle->tun_fd, r);
|
||||
result++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -387,7 +388,7 @@ bundle_IsSet(struct descriptor *d, const fd_set *fdset)
|
||||
if (descriptor_IsSet(desc, fdset))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return FD_ISSET(bundle->tun_fd, fdset);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -404,6 +405,83 @@ bundle_DescriptorRead(struct descriptor *d, struct bundle *bundle,
|
||||
for (desc = bundle->desc.next; desc; desc = desc->next)
|
||||
if (descriptor_IsSet(desc, fdset))
|
||||
descriptor_Read(desc, bundle, fdset);
|
||||
|
||||
if (FD_ISSET(bundle->tun_fd, fdset)) {
|
||||
struct tun_data tun;
|
||||
int n, pri;
|
||||
|
||||
/* something to read from tun */
|
||||
n = read(bundle->tun_fd, &tun, sizeof tun);
|
||||
if (n < 0) {
|
||||
log_Printf(LogERROR, "read from tun: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
n -= sizeof tun - sizeof tun.data;
|
||||
if (n <= 0) {
|
||||
log_Printf(LogERROR, "read from tun: Only %d bytes read\n", n);
|
||||
return;
|
||||
}
|
||||
if (!tun_check_header(tun, AF_INET))
|
||||
return;
|
||||
|
||||
if (((struct ip *)tun.data)->ip_dst.s_addr ==
|
||||
bundle->ncp.ipcp.my_ip.s_addr) {
|
||||
/* we've been asked to send something addressed *to* us :( */
|
||||
if (Enabled(bundle, OPT_LOOPBACK)) {
|
||||
pri = PacketCheck(bundle, tun.data, n, &bundle->filter.in);
|
||||
if (pri >= 0) {
|
||||
struct mbuf *bp;
|
||||
|
||||
#ifndef NOALIAS
|
||||
if (alias_IsEnabled()) {
|
||||
(*PacketAlias.In)(tun.data, sizeof tun.data);
|
||||
n = ntohs(((struct ip *)tun.data)->ip_len);
|
||||
}
|
||||
#endif
|
||||
bp = mbuf_Alloc(n, MB_IPIN);
|
||||
memcpy(MBUF_CTOP(bp), tun.data, n);
|
||||
ip_Input(bundle, bp);
|
||||
log_Printf(LogDEBUG, "Looped back packet addressed to myself\n");
|
||||
}
|
||||
return;
|
||||
} else
|
||||
log_Printf(LogDEBUG, "Oops - forwarding packet addressed to myself\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Process on-demand dialup. Output packets are queued within tunnel
|
||||
* device until IPCP is opened.
|
||||
*/
|
||||
|
||||
if (bundle_Phase(bundle) == PHASE_DEAD) {
|
||||
/*
|
||||
* Note, we must be in AUTO mode :-/ otherwise our interface should
|
||||
* *not* be UP and we can't receive data
|
||||
*/
|
||||
if ((pri = PacketCheck(bundle, tun.data, n, &bundle->filter.dial)) >= 0)
|
||||
bundle_Open(bundle, NULL, PHYS_DEMAND);
|
||||
else
|
||||
/*
|
||||
* Drop the packet. If we were to queue it, we'd just end up with
|
||||
* a pile of timed-out data in our output queue by the time we get
|
||||
* around to actually dialing. We'd also prematurely reach the
|
||||
* threshold at which we stop select()ing to read() the tun
|
||||
* device - breaking auto-dial.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
pri = PacketCheck(bundle, tun.data, n, &bundle->filter.out);
|
||||
if (pri >= 0) {
|
||||
#ifndef NOALIAS
|
||||
if (alias_IsEnabled()) {
|
||||
(*PacketAlias.Out)(tun.data, sizeof tun.data);
|
||||
n = ntohs(((struct ip *)tun.data)->ip_len);
|
||||
}
|
||||
#endif
|
||||
ip_Enqueue(pri, tun.data, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: datalink.c,v 1.1.2.53 1998/05/01 19:24:23 brian Exp $
|
||||
* $Id: datalink.c,v 1.1.2.54 1998/05/02 21:57:44 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -463,9 +463,9 @@ datalink_AuthOk(struct datalink *dl)
|
||||
return;
|
||||
case MP_UP:
|
||||
auth_Select(dl->bundle, dl->peer.authname, dl->physical);
|
||||
/* Fall through */
|
||||
break;
|
||||
case MP_ADDED:
|
||||
/* We're in multilink mode ! */
|
||||
/* We were already in multilink mode ! */
|
||||
break;
|
||||
case MP_FAILED:
|
||||
datalink_AuthNotOk(dl);
|
||||
@ -654,7 +654,7 @@ datalink_Clone(struct datalink *odl, const char *name)
|
||||
|
||||
chat_Init(&dl->chat, dl->physical, NULL, 1, NULL);
|
||||
|
||||
log_Printf(LogPHASE, "%s: Created in CLOSED state\n", dl->name);
|
||||
log_Printf(LogPHASE, "%s: Cloned in CLOSED state\n", dl->name);
|
||||
|
||||
return dl;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: main.c,v 1.121.2.53 1998/04/30 23:53:48 brian Exp $
|
||||
* $Id: main.c,v 1.121.2.54 1998/05/01 19:25:16 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -483,9 +483,7 @@ static void
|
||||
DoLoop(struct bundle *bundle, struct prompt *prompt)
|
||||
{
|
||||
fd_set rfds, wfds, efds;
|
||||
int pri, i, n, nfds;
|
||||
int qlen;
|
||||
struct tun_data tun;
|
||||
int i, nfds;
|
||||
|
||||
do {
|
||||
nfds = 0;
|
||||
@ -493,8 +491,6 @@ DoLoop(struct bundle *bundle, struct prompt *prompt)
|
||||
FD_ZERO(&wfds);
|
||||
FD_ZERO(&efds);
|
||||
|
||||
qlen = bundle_FillQueues(bundle);
|
||||
|
||||
sig_Handle();
|
||||
|
||||
/* This one comes first 'cos it may nuke a datalink */
|
||||
@ -503,13 +499,6 @@ DoLoop(struct bundle *bundle, struct prompt *prompt)
|
||||
descriptor_UpdateSet(&bundle->desc, &rfds, &wfds, &efds, &nfds);
|
||||
descriptor_UpdateSet(&server.desc, &rfds, &wfds, &efds, &nfds);
|
||||
|
||||
/* If there are aren't many packets queued, look for some more. */
|
||||
if (qlen < 20 && bundle->tun_fd >= 0) {
|
||||
if (bundle->tun_fd + 1 > nfds)
|
||||
nfds = bundle->tun_fd + 1;
|
||||
FD_SET(bundle->tun_fd, &rfds);
|
||||
}
|
||||
|
||||
if (bundle_IsDead(bundle))
|
||||
/* Don't select - we'll be here forever */
|
||||
break;
|
||||
@ -518,12 +507,9 @@ DoLoop(struct bundle *bundle, struct prompt *prompt)
|
||||
|
||||
if (i == 0)
|
||||
continue;
|
||||
|
||||
if (i < 0) {
|
||||
if (errno == EINTR) {
|
||||
sig_Handle();
|
||||
else if (i < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
}
|
||||
log_Printf(LogERROR, "DoLoop: select(): %s\n", strerror(errno));
|
||||
break;
|
||||
}
|
||||
@ -545,78 +531,6 @@ DoLoop(struct bundle *bundle, struct prompt *prompt)
|
||||
|
||||
if (descriptor_IsSet(&bundle->desc, &rfds))
|
||||
descriptor_Read(&bundle->desc, bundle, &rfds);
|
||||
|
||||
if (bundle->tun_fd >= 0 && FD_ISSET(bundle->tun_fd, &rfds)) {
|
||||
/* something to read from tun */
|
||||
n = read(bundle->tun_fd, &tun, sizeof tun);
|
||||
if (n < 0) {
|
||||
log_Printf(LogERROR, "read from tun: %s\n", strerror(errno));
|
||||
continue;
|
||||
}
|
||||
n -= sizeof tun - sizeof tun.data;
|
||||
if (n <= 0) {
|
||||
log_Printf(LogERROR, "read from tun: Only %d bytes read\n", n);
|
||||
continue;
|
||||
}
|
||||
if (!tun_check_header(tun, AF_INET))
|
||||
continue;
|
||||
if (((struct ip *)tun.data)->ip_dst.s_addr ==
|
||||
bundle->ncp.ipcp.my_ip.s_addr) {
|
||||
/* we've been asked to send something addressed *to* us :( */
|
||||
if (Enabled(bundle, OPT_LOOPBACK)) {
|
||||
pri = PacketCheck(bundle, tun.data, n, &bundle->filter.in);
|
||||
if (pri >= 0) {
|
||||
struct mbuf *bp;
|
||||
|
||||
#ifndef NOALIAS
|
||||
if (alias_IsEnabled()) {
|
||||
(*PacketAlias.In)(tun.data, sizeof tun.data);
|
||||
n = ntohs(((struct ip *)tun.data)->ip_len);
|
||||
}
|
||||
#endif
|
||||
bp = mbuf_Alloc(n, MB_IPIN);
|
||||
memcpy(MBUF_CTOP(bp), tun.data, n);
|
||||
ip_Input(bundle, bp);
|
||||
log_Printf(LogDEBUG, "Looped back packet addressed to myself\n");
|
||||
}
|
||||
continue;
|
||||
} else
|
||||
log_Printf(LogDEBUG, "Oops - forwarding packet addressed to myself\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Process on-demand dialup. Output packets are queued within tunnel
|
||||
* device until IPCP is opened.
|
||||
*/
|
||||
if (bundle_Phase(bundle) == PHASE_DEAD) {
|
||||
/*
|
||||
* Note, we must be in AUTO mode :-/ otherwise our interface should
|
||||
* *not* be UP and we can't receive data
|
||||
*/
|
||||
if ((pri = PacketCheck(bundle, tun.data, n, &bundle->filter.dial)) >= 0)
|
||||
bundle_Open(bundle, NULL, PHYS_DEMAND);
|
||||
else
|
||||
/*
|
||||
* Drop the packet. If we were to queue it, we'd just end up with
|
||||
* a pile of timed-out data in our output queue by the time we get
|
||||
* around to actually dialing. We'd also prematurely reach the
|
||||
* threshold at which we stop select()ing to read() the tun
|
||||
* device - breaking auto-dial.
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
|
||||
pri = PacketCheck(bundle, tun.data, n, &bundle->filter.out);
|
||||
if (pri >= 0) {
|
||||
#ifndef NOALIAS
|
||||
if (alias_IsEnabled()) {
|
||||
(*PacketAlias.Out)(tun.data, sizeof tun.data);
|
||||
n = ntohs(((struct ip *)tun.data)->ip_len);
|
||||
}
|
||||
#endif
|
||||
ip_Enqueue(pri, tun.data, n);
|
||||
}
|
||||
}
|
||||
} while (bundle_CleanDatalinks(bundle), !bundle_IsDead(bundle));
|
||||
|
||||
log_Printf(LogDEBUG, "DoLoop done.\n");
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: modem.c,v 1.77.2.65 1998/05/03 11:24:16 brian Exp $
|
||||
* $Id: modem.c,v 1.77.2.66 1998/05/05 03:01:28 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -142,7 +142,7 @@ modem_Create(struct datalink *dl, int type)
|
||||
|
||||
static void modem_LogicalClose(struct physical *);
|
||||
|
||||
static struct speeds {
|
||||
static const struct speeds {
|
||||
int nspeed;
|
||||
speed_t speed;
|
||||
} speeds[] = {
|
||||
@ -226,7 +226,7 @@ static struct speeds {
|
||||
static int
|
||||
SpeedToInt(speed_t speed)
|
||||
{
|
||||
struct speeds *sp;
|
||||
const struct speeds *sp;
|
||||
|
||||
for (sp = speeds; sp->nspeed; sp++) {
|
||||
if (sp->speed == speed) {
|
||||
@ -239,7 +239,7 @@ SpeedToInt(speed_t speed)
|
||||
speed_t
|
||||
IntToSpeed(int nspeed)
|
||||
{
|
||||
struct speeds *sp;
|
||||
const struct speeds *sp;
|
||||
|
||||
for (sp = speeds; sp->nspeed; sp++) {
|
||||
if (sp->nspeed == nspeed) {
|
||||
@ -319,7 +319,7 @@ modem_StartTimer(struct bundle *bundle, struct physical *modem)
|
||||
timer_Start(ModemTimer);
|
||||
}
|
||||
|
||||
static struct parity {
|
||||
static const struct parity {
|
||||
const char *name;
|
||||
const char *name1;
|
||||
int set;
|
||||
@ -333,7 +333,7 @@ static struct parity {
|
||||
static int
|
||||
GetParityValue(const char *str)
|
||||
{
|
||||
struct parity *pp;
|
||||
const struct parity *pp;
|
||||
|
||||
for (pp = validparity; pp->name; pp++) {
|
||||
if (strcasecmp(pp->name, str) == 0 ||
|
||||
|
Loading…
Reference in New Issue
Block a user