1998-04-03 19:21:56 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1998-04-03 19:21:56 +00:00
|
|
|
*/
|
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
#include <sys/param.h>
|
1998-04-03 19:21:56 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
1998-04-23 03:23:03 +00:00
|
|
|
#include <arpa/inet.h>
|
1998-04-23 23:50:40 +00:00
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <sys/socket.h>
|
1998-04-28 01:25:46 +00:00
|
|
|
#include <sys/un.h>
|
1998-04-03 19:21:56 +00:00
|
|
|
|
1998-04-23 23:50:40 +00:00
|
|
|
#include <errno.h>
|
1998-04-28 01:25:46 +00:00
|
|
|
#include <paths.h>
|
2002-08-27 20:11:58 +00:00
|
|
|
#include <stdarg.h>
|
1998-04-23 03:23:03 +00:00
|
|
|
#include <stdio.h>
|
2002-08-27 20:11:58 +00:00
|
|
|
#include <stdlib.h>
|
1998-04-03 19:21:56 +00:00
|
|
|
#include <string.h>
|
1998-04-28 01:25:46 +00:00
|
|
|
#include <sys/stat.h>
|
1998-04-03 19:21:56 +00:00
|
|
|
#include <termios.h>
|
1998-04-23 23:50:40 +00:00
|
|
|
#include <unistd.h>
|
1998-04-03 19:21:56 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "layer.h"
|
1999-08-19 18:15:52 +00:00
|
|
|
#ifndef NONAT
|
1999-09-08 07:34:52 +00:00
|
|
|
#include "nat_cmd.h"
|
1999-05-08 11:07:56 +00:00
|
|
|
#endif
|
|
|
|
#include "vjcomp.h"
|
1998-09-04 18:26:00 +00:00
|
|
|
#include "ua.h"
|
1998-06-15 19:06:25 +00:00
|
|
|
#include "defs.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "command.h"
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "fsm.h"
|
|
|
|
#include "iplist.h"
|
|
|
|
#include "throughput.h"
|
|
|
|
#include "slcompress.h"
|
1998-08-26 17:39:37 +00:00
|
|
|
#include "lqr.h"
|
|
|
|
#include "hdlc.h"
|
2001-08-14 16:05:52 +00:00
|
|
|
#include "ncpaddr.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "ipcp.h"
|
|
|
|
#include "auth.h"
|
|
|
|
#include "lcp.h"
|
|
|
|
#include "async.h"
|
|
|
|
#include "ccp.h"
|
|
|
|
#include "link.h"
|
|
|
|
#include "descriptor.h"
|
|
|
|
#include "physical.h"
|
|
|
|
#include "chat.h"
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "proto.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "filter.h"
|
|
|
|
#include "mp.h"
|
|
|
|
#include "chap.h"
|
1998-08-07 18:42:51 +00:00
|
|
|
#include "cbcp.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "datalink.h"
|
1999-01-28 01:56:34 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
#include "radius.h"
|
|
|
|
#endif
|
2001-08-14 16:05:52 +00:00
|
|
|
#include "ipv6cp.h"
|
|
|
|
#include "ncp.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "bundle.h"
|
1998-04-23 03:23:03 +00:00
|
|
|
#include "prompt.h"
|
1998-04-23 23:50:40 +00:00
|
|
|
#include "id.h"
|
|
|
|
#include "arp.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
|
1998-04-24 19:16:15 +00:00
|
|
|
void
|
|
|
|
peerid_Init(struct peerid *peer)
|
|
|
|
{
|
|
|
|
peer->enddisc.class = 0;
|
|
|
|
*peer->enddisc.address = '\0';
|
|
|
|
peer->enddisc.len = 0;
|
|
|
|
*peer->authname = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
peerid_Equal(const struct peerid *p1, const struct peerid *p2)
|
|
|
|
{
|
|
|
|
return !strcmp(p1->authname, p2->authname) &&
|
|
|
|
p1->enddisc.class == p2->enddisc.class &&
|
|
|
|
p1->enddisc.len == p2->enddisc.len &&
|
|
|
|
!memcmp(p1->enddisc.address, p2->enddisc.address, p1->enddisc.len);
|
|
|
|
}
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
static u_int32_t
|
1998-05-04 03:00:09 +00:00
|
|
|
inc_seq(unsigned is12bit, u_int32_t seq)
|
1998-04-03 19:21:56 +00:00
|
|
|
{
|
|
|
|
seq++;
|
1998-05-04 03:00:09 +00:00
|
|
|
if (is12bit) {
|
1998-04-03 19:21:56 +00:00
|
|
|
if (seq & 0xfffff000)
|
|
|
|
seq = 0;
|
|
|
|
} else if (seq & 0xff000000)
|
|
|
|
seq = 0;
|
|
|
|
return seq;
|
|
|
|
}
|
|
|
|
|
1998-05-04 21:42:41 +00:00
|
|
|
static int
|
|
|
|
isbefore(unsigned is12bit, u_int32_t seq1, u_int32_t seq2)
|
|
|
|
{
|
1998-05-06 23:49:48 +00:00
|
|
|
u_int32_t max = (is12bit ? 0xfff : 0xffffff) - 0x200;
|
|
|
|
|
|
|
|
if (seq1 > max) {
|
|
|
|
if (seq2 < 0x200 || seq2 > seq1)
|
|
|
|
return 1;
|
|
|
|
} else if ((seq1 > 0x200 || seq2 <= max) && seq1 < seq2)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
1998-05-04 21:42:41 +00:00
|
|
|
}
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
static int
|
|
|
|
mp_ReadHeader(struct mp *mp, struct mbuf *m, struct mp_header *header)
|
|
|
|
{
|
1998-04-23 03:23:03 +00:00
|
|
|
if (mp->local_is12bit) {
|
1998-09-04 18:26:00 +00:00
|
|
|
u_int16_t val;
|
|
|
|
|
|
|
|
ua_ntohs(MBUF_CTOP(m), &val);
|
|
|
|
if (val & 0x3000) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "Oops - MP header without required zero bits\n");
|
1998-04-03 19:21:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1998-09-04 18:26:00 +00:00
|
|
|
header->begin = val & 0x8000 ? 1 : 0;
|
|
|
|
header->end = val & 0x4000 ? 1 : 0;
|
|
|
|
header->seq = val & 0x0fff;
|
1998-04-03 19:21:56 +00:00
|
|
|
return 2;
|
|
|
|
} else {
|
1998-09-04 18:26:00 +00:00
|
|
|
ua_ntohl(MBUF_CTOP(m), &header->seq);
|
1998-04-03 19:21:56 +00:00
|
|
|
if (header->seq & 0x3f000000) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "Oops - MP header without required zero bits\n");
|
1998-04-03 19:21:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1998-04-23 18:56:21 +00:00
|
|
|
header->begin = header->seq & 0x80000000 ? 1 : 0;
|
|
|
|
header->end = header->seq & 0x40000000 ? 1 : 0;
|
1998-04-03 19:21:56 +00:00
|
|
|
header->seq &= 0x00ffffff;
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-09-05 01:46:52 +00:00
|
|
|
mp_LayerStart(void *v __unused, struct fsm *fp __unused)
|
1998-04-03 19:21:56 +00:00
|
|
|
{
|
1998-04-23 03:23:03 +00:00
|
|
|
/* The given FSM (ccp) is about to start up ! */
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-09-05 01:46:52 +00:00
|
|
|
mp_LayerUp(void *v __unused, struct fsm *fp)
|
1998-04-03 19:21:56 +00:00
|
|
|
{
|
1998-04-23 03:23:03 +00:00
|
|
|
/* The given fsm (ccp) is now up */
|
2001-07-03 22:20:19 +00:00
|
|
|
|
|
|
|
bundle_CalculateBandwidth(fp->bundle); /* Against ccp_MTUOverhead */
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-09-05 01:46:52 +00:00
|
|
|
mp_LayerDown(void *v __unused, struct fsm *fp __unused)
|
1998-04-03 19:21:56 +00:00
|
|
|
{
|
1998-04-23 03:23:03 +00:00
|
|
|
/* The given FSM (ccp) has been told to come down */
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-09-05 01:46:52 +00:00
|
|
|
mp_LayerFinish(void *v __unused, struct fsm *fp)
|
1998-04-03 19:21:56 +00:00
|
|
|
{
|
1998-04-23 03:23:03 +00:00
|
|
|
/* The given fsm (ccp) is now down */
|
1998-05-15 18:21:12 +00:00
|
|
|
if (fp->state == ST_CLOSED && fp->open_mode == OPEN_PASSIVE)
|
|
|
|
fsm_Open(fp); /* CCP goes to ST_STOPPED */
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
|
1999-08-05 10:32:16 +00:00
|
|
|
static void
|
|
|
|
mp_UpDown(void *v)
|
|
|
|
{
|
|
|
|
struct mp *mp = (struct mp *)v;
|
|
|
|
int percent;
|
|
|
|
|
2000-08-15 10:25:42 +00:00
|
|
|
percent = MAX(mp->link.stats.total.in.OctetsPerSecond,
|
|
|
|
mp->link.stats.total.out.OctetsPerSecond) * 800 /
|
|
|
|
mp->bundle->bandwidth;
|
1999-08-05 10:32:16 +00:00
|
|
|
if (percent >= mp->cfg.autoload.max) {
|
|
|
|
log_Printf(LogDEBUG, "%d%% saturation - bring a link up ?\n", percent);
|
|
|
|
bundle_AutoAdjust(mp->bundle, percent, AUTO_UP);
|
|
|
|
} else if (percent <= mp->cfg.autoload.min) {
|
|
|
|
log_Printf(LogDEBUG, "%d%% saturation - bring a link down ?\n", percent);
|
|
|
|
bundle_AutoAdjust(mp->bundle, percent, AUTO_DOWN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mp_StopAutoloadTimer(struct mp *mp)
|
|
|
|
{
|
2000-08-15 00:59:21 +00:00
|
|
|
throughput_stop(&mp->link.stats.total);
|
1999-08-05 10:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mp_CheckAutoloadTimer(struct mp *mp)
|
|
|
|
{
|
2000-08-15 00:59:21 +00:00
|
|
|
if (mp->link.stats.total.SamplePeriod != mp->cfg.autoload.period) {
|
|
|
|
throughput_destroy(&mp->link.stats.total);
|
|
|
|
throughput_init(&mp->link.stats.total, mp->cfg.autoload.period);
|
|
|
|
throughput_callback(&mp->link.stats.total, mp_UpDown, mp);
|
1999-08-05 10:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bundle_WantAutoloadTimer(mp->bundle))
|
2000-08-15 00:59:21 +00:00
|
|
|
throughput_start(&mp->link.stats.total, "MP throughput", 1);
|
1999-08-05 10:32:16 +00:00
|
|
|
else
|
|
|
|
mp_StopAutoloadTimer(mp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mp_RestartAutoloadTimer(struct mp *mp)
|
|
|
|
{
|
2000-08-15 00:59:21 +00:00
|
|
|
if (mp->link.stats.total.SamplePeriod != mp->cfg.autoload.period)
|
1999-08-05 10:32:16 +00:00
|
|
|
mp_CheckAutoloadTimer(mp);
|
|
|
|
else
|
2000-08-15 00:59:21 +00:00
|
|
|
throughput_clear(&mp->link.stats.total, THROUGHPUT_OVERALL, NULL);
|
1999-08-05 10:32:16 +00:00
|
|
|
}
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
void
|
|
|
|
mp_Init(struct mp *mp, struct bundle *bundle)
|
|
|
|
{
|
1998-04-23 03:23:03 +00:00
|
|
|
mp->peer_is12bit = mp->local_is12bit = 0;
|
|
|
|
mp->peer_mrru = mp->local_mrru = 0;
|
1998-04-24 19:16:15 +00:00
|
|
|
|
|
|
|
peerid_Init(&mp->peer);
|
|
|
|
|
1998-05-03 22:13:14 +00:00
|
|
|
mp->out.seq = 0;
|
|
|
|
mp->out.link = 0;
|
2001-08-14 16:05:52 +00:00
|
|
|
mp->out.af = AF_INET;
|
1998-04-03 19:21:56 +00:00
|
|
|
mp->seq.min_in = 0;
|
|
|
|
mp->seq.next_in = 0;
|
|
|
|
mp->inbufs = NULL;
|
|
|
|
mp->bundle = bundle;
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
mp->link.type = LOGICAL_LINK;
|
1998-04-03 19:21:56 +00:00
|
|
|
mp->link.name = "mp";
|
|
|
|
mp->link.len = sizeof *mp;
|
1998-04-24 19:16:15 +00:00
|
|
|
|
1999-08-05 10:32:16 +00:00
|
|
|
mp->cfg.autoload.period = SAMPLE_PERIOD;
|
|
|
|
mp->cfg.autoload.min = mp->cfg.autoload.max = 0;
|
2000-08-15 00:59:21 +00:00
|
|
|
throughput_init(&mp->link.stats.total, mp->cfg.autoload.period);
|
|
|
|
throughput_callback(&mp->link.stats.total, mp_UpDown, mp);
|
|
|
|
mp->link.stats.parent = NULL;
|
|
|
|
mp->link.stats.gather = 0; /* Let the physical links gather stats */
|
1998-04-03 19:21:56 +00:00
|
|
|
memset(mp->link.Queue, '\0', sizeof mp->link.Queue);
|
|
|
|
memset(mp->link.proto_in, '\0', sizeof mp->link.proto_in);
|
|
|
|
memset(mp->link.proto_out, '\0', sizeof mp->link.proto_out);
|
|
|
|
|
|
|
|
mp->fsmp.LayerStart = mp_LayerStart;
|
|
|
|
mp->fsmp.LayerUp = mp_LayerUp;
|
|
|
|
mp->fsmp.LayerDown = mp_LayerDown;
|
|
|
|
mp->fsmp.LayerFinish = mp_LayerFinish;
|
|
|
|
mp->fsmp.object = mp;
|
|
|
|
|
1998-04-28 01:25:46 +00:00
|
|
|
mpserver_Init(&mp->server);
|
|
|
|
|
1998-04-23 03:23:03 +00:00
|
|
|
mp->cfg.mrru = 0;
|
|
|
|
mp->cfg.shortseq = NEG_ENABLED|NEG_ACCEPTED;
|
1999-06-09 16:54:04 +00:00
|
|
|
mp->cfg.negenddisc = NEG_ENABLED|NEG_ACCEPTED;
|
1998-04-23 03:23:03 +00:00
|
|
|
mp->cfg.enddisc.class = 0;
|
|
|
|
*mp->cfg.enddisc.address = '\0';
|
|
|
|
mp->cfg.enddisc.len = 0;
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
lcp_Init(&mp->link.lcp, mp->bundle, &mp->link, NULL);
|
|
|
|
ccp_Init(&mp->link.ccp, mp->bundle, &mp->link, &mp->fsmp);
|
1999-05-08 11:07:56 +00:00
|
|
|
|
|
|
|
link_EmptyStack(&mp->link);
|
|
|
|
link_Stack(&mp->link, &protolayer);
|
|
|
|
link_Stack(&mp->link, &ccplayer);
|
|
|
|
link_Stack(&mp->link, &vjlayer);
|
1999-08-19 18:15:52 +00:00
|
|
|
#ifndef NONAT
|
|
|
|
link_Stack(&mp->link, &natlayer);
|
1999-05-08 11:07:56 +00:00
|
|
|
#endif
|
1998-04-23 03:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-04-28 01:25:46 +00:00
|
|
|
mp_Up(struct mp *mp, struct datalink *dl)
|
1998-04-23 03:23:03 +00:00
|
|
|
{
|
1998-04-28 01:25:46 +00:00
|
|
|
struct lcp *lcp = &dl->physical->link.lcp;
|
|
|
|
|
1998-04-23 03:23:03 +00:00
|
|
|
if (mp->active) {
|
|
|
|
/* We're adding a link - do a last validation on our parameters */
|
1998-04-28 01:25:46 +00:00
|
|
|
if (!peerid_Equal(&dl->peer, &mp->peer)) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "%s: Inappropriate peer !\n", dl->name);
|
2000-05-22 08:23:13 +00:00
|
|
|
log_Printf(LogPHASE, " Attached to peer %s/%s\n", mp->peer.authname,
|
|
|
|
mp_Enddisc(mp->peer.enddisc.class, mp->peer.enddisc.address,
|
|
|
|
mp->peer.enddisc.len));
|
|
|
|
log_Printf(LogPHASE, " New link is peer %s/%s\n", dl->peer.authname,
|
|
|
|
mp_Enddisc(dl->peer.enddisc.class, dl->peer.enddisc.address,
|
|
|
|
dl->peer.enddisc.len));
|
1998-04-28 01:25:46 +00:00
|
|
|
return MP_FAILED;
|
1998-04-24 19:16:15 +00:00
|
|
|
}
|
1998-04-28 01:25:46 +00:00
|
|
|
if (mp->local_mrru != lcp->want_mrru ||
|
|
|
|
mp->peer_mrru != lcp->his_mrru ||
|
|
|
|
mp->local_is12bit != lcp->want_shortseq ||
|
|
|
|
mp->peer_is12bit != lcp->his_shortseq) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "%s: Invalid MRRU/SHORTSEQ MP parameters !\n",
|
1998-04-28 01:25:46 +00:00
|
|
|
dl->name);
|
|
|
|
return MP_FAILED;
|
1998-04-23 03:23:03 +00:00
|
|
|
}
|
1998-04-28 01:25:46 +00:00
|
|
|
return MP_ADDED;
|
1998-04-23 03:23:03 +00:00
|
|
|
} else {
|
|
|
|
/* First link in multilink mode */
|
1998-04-03 19:21:56 +00:00
|
|
|
|
1998-04-28 01:25:46 +00:00
|
|
|
mp->local_mrru = lcp->want_mrru;
|
|
|
|
mp->peer_mrru = lcp->his_mrru;
|
|
|
|
mp->local_is12bit = lcp->want_shortseq;
|
|
|
|
mp->peer_is12bit = lcp->his_shortseq;
|
|
|
|
mp->peer = dl->peer;
|
1998-04-03 19:21:56 +00:00
|
|
|
|
2000-08-15 00:59:21 +00:00
|
|
|
throughput_destroy(&mp->link.stats.total);
|
|
|
|
throughput_init(&mp->link.stats.total, mp->cfg.autoload.period);
|
|
|
|
throughput_callback(&mp->link.stats.total, mp_UpDown, mp);
|
1998-04-23 21:50:13 +00:00
|
|
|
memset(mp->link.Queue, '\0', sizeof mp->link.Queue);
|
|
|
|
memset(mp->link.proto_in, '\0', sizeof mp->link.proto_in);
|
|
|
|
memset(mp->link.proto_out, '\0', sizeof mp->link.proto_out);
|
|
|
|
|
2000-08-15 00:59:21 +00:00
|
|
|
/* Tell the link who it belongs to */
|
|
|
|
dl->physical->link.stats.parent = &mp->link.stats.total;
|
|
|
|
|
1998-05-03 22:13:14 +00:00
|
|
|
mp->out.seq = 0;
|
|
|
|
mp->out.link = 0;
|
2001-08-14 16:05:52 +00:00
|
|
|
mp->out.af = AF_INET;
|
1998-04-23 21:50:13 +00:00
|
|
|
mp->seq.min_in = 0;
|
|
|
|
mp->seq.next_in = 0;
|
|
|
|
|
1998-04-28 01:25:46 +00:00
|
|
|
/*
|
|
|
|
* Now we create our server socket.
|
|
|
|
* If it already exists, join it. Otherwise, create and own it
|
|
|
|
*/
|
1998-05-02 21:57:50 +00:00
|
|
|
switch (mpserver_Open(&mp->server, &mp->peer)) {
|
|
|
|
case MPSERVER_CONNECTED:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "mp: Transfer link on %s\n",
|
1998-04-30 23:53:56 +00:00
|
|
|
mp->server.socket.sun_path);
|
1998-05-02 21:57:50 +00:00
|
|
|
mp->server.send.dl = dl; /* Defer 'till it's safe to send */
|
1998-04-28 01:25:46 +00:00
|
|
|
return MP_LINKSENT;
|
1998-05-02 21:57:50 +00:00
|
|
|
case MPSERVER_FAILED:
|
1998-04-28 01:25:46 +00:00
|
|
|
return MP_FAILED;
|
1998-05-02 21:57:50 +00:00
|
|
|
case MPSERVER_LISTENING:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "mp: Listening on %s\n", mp->server.socket.sun_path);
|
|
|
|
log_Printf(LogPHASE, " First link: %s\n", dl->name);
|
1998-04-28 01:25:46 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
/* Re-point our NCP layers at our MP link */
|
|
|
|
ncp_SetLink(&mp->bundle->ncp, &mp->link);
|
1998-04-28 01:25:46 +00:00
|
|
|
|
|
|
|
/* Our lcp's already up 'cos of the NULL parent */
|
1998-06-30 23:04:17 +00:00
|
|
|
if (ccp_SetOpenMode(&mp->link.ccp)) {
|
|
|
|
fsm_Up(&mp->link.ccp.fsm);
|
|
|
|
fsm_Open(&mp->link.ccp.fsm);
|
|
|
|
}
|
1998-04-28 01:25:46 +00:00
|
|
|
|
|
|
|
mp->active = 1;
|
1998-05-02 21:57:50 +00:00
|
|
|
break;
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
1998-04-23 03:23:03 +00:00
|
|
|
}
|
|
|
|
|
1998-04-28 01:25:46 +00:00
|
|
|
return MP_UP;
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
|
1998-04-23 21:50:13 +00:00
|
|
|
void
|
|
|
|
mp_Down(struct mp *mp)
|
|
|
|
{
|
|
|
|
if (mp->active) {
|
|
|
|
struct mbuf *next;
|
|
|
|
|
1999-08-05 10:32:16 +00:00
|
|
|
/* Stop that ! */
|
|
|
|
mp_StopAutoloadTimer(mp);
|
|
|
|
|
1998-04-28 01:25:46 +00:00
|
|
|
/* Don't want any more of these */
|
|
|
|
mpserver_Close(&mp->server);
|
|
|
|
|
|
|
|
/* CCP goes down with a bang */
|
1998-06-20 00:19:42 +00:00
|
|
|
fsm2initial(&mp->link.ccp.fsm);
|
1998-04-23 21:50:13 +00:00
|
|
|
|
|
|
|
/* Received fragments go in the bit-bucket */
|
|
|
|
while (mp->inbufs) {
|
1999-12-20 20:29:47 +00:00
|
|
|
next = mp->inbufs->m_nextpkt;
|
|
|
|
m_freem(mp->inbufs);
|
1998-04-23 21:50:13 +00:00
|
|
|
mp->inbufs = next;
|
|
|
|
}
|
|
|
|
|
1998-04-24 19:16:15 +00:00
|
|
|
peerid_Init(&mp->peer);
|
1998-04-23 21:50:13 +00:00
|
|
|
mp->active = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
void
|
|
|
|
mp_linkInit(struct mp_link *mplink)
|
|
|
|
{
|
|
|
|
mplink->seq = 0;
|
1999-08-05 10:32:16 +00:00
|
|
|
mplink->bandwidth = 0;
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
static void
|
|
|
|
mp_Assemble(struct mp *mp, struct mbuf *m, struct physical *p)
|
1998-04-03 19:21:56 +00:00
|
|
|
{
|
|
|
|
struct mp_header mh, h;
|
|
|
|
struct mbuf *q, *last;
|
2004-09-05 01:46:52 +00:00
|
|
|
u_int32_t seq;
|
1998-04-03 19:21:56 +00:00
|
|
|
|
1998-05-23 17:05:28 +00:00
|
|
|
/*
|
|
|
|
* When `m' and `p' are NULL, it means our oldest link has gone down.
|
|
|
|
* We want to determine a new min, and process any intermediate stuff
|
|
|
|
* as normal
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (m && mp_ReadHeader(mp, m, &mh) == 0) {
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(m);
|
1998-04-03 19:21:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-05-23 17:05:28 +00:00
|
|
|
if (p) {
|
|
|
|
seq = p->dl->mp.seq;
|
|
|
|
p->dl->mp.seq = mh.seq;
|
|
|
|
} else
|
|
|
|
seq = mp->seq.min_in;
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
if (mp->seq.min_in == seq) {
|
|
|
|
/*
|
|
|
|
* We've received new data on the link that has our min (oldest) seq.
|
|
|
|
* Figure out which link now has the smallest (oldest) seq.
|
|
|
|
*/
|
|
|
|
struct datalink *dl;
|
|
|
|
|
1998-05-23 17:05:28 +00:00
|
|
|
mp->seq.min_in = (u_int32_t)-1;
|
1998-04-03 19:21:56 +00:00
|
|
|
for (dl = mp->bundle->links; dl; dl = dl->next)
|
1998-05-23 17:05:28 +00:00
|
|
|
if (dl->state == DATALINK_OPEN &&
|
2004-09-05 01:46:52 +00:00
|
|
|
(mp->seq.min_in == (u_int32_t)-1 ||
|
1998-05-23 17:05:28 +00:00
|
|
|
isbefore(mp->local_is12bit, dl->mp.seq, mp->seq.min_in)))
|
1998-04-03 19:21:56 +00:00
|
|
|
mp->seq.min_in = dl->mp.seq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now process as many of our fragments as we can, adding our new
|
|
|
|
* fragment in as we go, and ordering with the oldest at the top of
|
|
|
|
* the queue.
|
|
|
|
*/
|
|
|
|
|
|
|
|
last = NULL;
|
|
|
|
seq = mp->seq.next_in;
|
|
|
|
q = mp->inbufs;
|
2000-07-12 15:08:03 +00:00
|
|
|
while (q || m) {
|
|
|
|
if (!q) {
|
1998-04-03 19:21:56 +00:00
|
|
|
if (last)
|
1999-12-20 20:29:47 +00:00
|
|
|
last->m_nextpkt = m;
|
1998-04-03 19:21:56 +00:00
|
|
|
else
|
|
|
|
mp->inbufs = m;
|
|
|
|
q = m;
|
|
|
|
m = NULL;
|
2000-07-12 15:08:03 +00:00
|
|
|
h = mh;
|
|
|
|
} else {
|
|
|
|
mp_ReadHeader(mp, q, &h);
|
|
|
|
|
|
|
|
if (m && isbefore(mp->local_is12bit, mh.seq, h.seq)) {
|
|
|
|
/* Our received fragment fits in before this one, so link it in */
|
|
|
|
if (last)
|
|
|
|
last->m_nextpkt = m;
|
|
|
|
else
|
|
|
|
mp->inbufs = m;
|
|
|
|
m->m_nextpkt = q;
|
|
|
|
q = m;
|
|
|
|
h = mh;
|
|
|
|
m = NULL;
|
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (h.seq != seq) {
|
|
|
|
/* we're missing something :-( */
|
1999-06-03 13:29:32 +00:00
|
|
|
if (isbefore(mp->local_is12bit, seq, mp->seq.min_in)) {
|
1998-04-03 19:21:56 +00:00
|
|
|
/* we're never gonna get it */
|
|
|
|
struct mbuf *next;
|
|
|
|
|
|
|
|
/* Zap all older fragments */
|
|
|
|
while (mp->inbufs != q) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogDEBUG, "Drop frag\n");
|
1999-12-20 20:29:47 +00:00
|
|
|
next = mp->inbufs->m_nextpkt;
|
|
|
|
m_freem(mp->inbufs);
|
1998-04-03 19:21:56 +00:00
|
|
|
mp->inbufs = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Zap everything until the next `end' fragment OR just before
|
|
|
|
* the next `begin' fragment OR 'till seq.min_in - whichever
|
|
|
|
* comes first.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
mp_ReadHeader(mp, mp->inbufs, &h);
|
|
|
|
if (h.begin) {
|
1998-04-23 18:56:21 +00:00
|
|
|
/* We might be able to process this ! */
|
1998-04-03 19:21:56 +00:00
|
|
|
h.seq--; /* We're gonna look for fragment with h.seq+1 */
|
|
|
|
break;
|
|
|
|
}
|
1999-12-20 20:29:47 +00:00
|
|
|
next = mp->inbufs->m_nextpkt;
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogDEBUG, "Drop frag %u\n", h.seq);
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(mp->inbufs);
|
1998-04-03 19:21:56 +00:00
|
|
|
mp->inbufs = next;
|
1999-06-03 13:29:32 +00:00
|
|
|
} while (mp->inbufs && (isbefore(mp->local_is12bit, mp->seq.min_in,
|
|
|
|
h.seq) || h.end));
|
1998-04-03 19:21:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Continue processing things from here.
|
|
|
|
* This deals with the possibility that we received a fragment
|
|
|
|
* on the slowest link that invalidates some of our data (because
|
|
|
|
* of the hole at `q'), but where there are subsequent `whole'
|
|
|
|
* packets that have already been received.
|
|
|
|
*/
|
|
|
|
|
1998-05-04 03:00:09 +00:00
|
|
|
mp->seq.next_in = seq = inc_seq(mp->local_is12bit, h.seq);
|
1998-04-03 19:21:56 +00:00
|
|
|
last = NULL;
|
|
|
|
q = mp->inbufs;
|
|
|
|
} else
|
|
|
|
/* we may still receive the missing fragment */
|
|
|
|
break;
|
|
|
|
} else if (h.end) {
|
|
|
|
/* We've got something, reassemble */
|
|
|
|
struct mbuf **frag = &q;
|
|
|
|
int len;
|
2004-09-05 01:46:52 +00:00
|
|
|
long long first = -1;
|
1998-04-03 19:21:56 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
*frag = mp->inbufs;
|
1999-12-20 20:29:47 +00:00
|
|
|
mp->inbufs = mp->inbufs->m_nextpkt;
|
1998-04-03 19:21:56 +00:00
|
|
|
len = mp_ReadHeader(mp, *frag, &h);
|
1998-04-23 18:56:21 +00:00
|
|
|
if (first == -1)
|
|
|
|
first = h.seq;
|
1998-04-03 19:21:56 +00:00
|
|
|
if (frag == &q && !h.begin) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "Oops - MP frag %lu should have a begin flag\n",
|
1998-04-03 19:21:56 +00:00
|
|
|
(u_long)h.seq);
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(q);
|
1998-04-03 19:21:56 +00:00
|
|
|
q = NULL;
|
|
|
|
} else if (frag != &q && h.begin) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "Oops - MP frag %lu should have an end flag\n",
|
1998-04-03 19:21:56 +00:00
|
|
|
(u_long)h.seq - 1);
|
|
|
|
/*
|
|
|
|
* Stuff our fragment back at the front of the queue and zap
|
2002-05-07 12:48:45 +00:00
|
|
|
* our half-assembled packet.
|
1998-04-03 19:21:56 +00:00
|
|
|
*/
|
1999-12-20 20:29:47 +00:00
|
|
|
(*frag)->m_nextpkt = mp->inbufs;
|
1998-04-03 19:21:56 +00:00
|
|
|
mp->inbufs = *frag;
|
|
|
|
*frag = NULL;
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(q);
|
1998-04-03 19:21:56 +00:00
|
|
|
q = NULL;
|
|
|
|
frag = &q;
|
|
|
|
h.end = 0; /* just in case it's a whole packet */
|
2002-05-07 12:48:45 +00:00
|
|
|
} else {
|
|
|
|
(*frag)->m_offset += len;
|
|
|
|
(*frag)->m_len -= len;
|
|
|
|
(*frag)->m_nextpkt = NULL;
|
1998-04-03 19:21:56 +00:00
|
|
|
do
|
1999-12-20 20:29:47 +00:00
|
|
|
frag = &(*frag)->m_next;
|
1998-04-23 18:56:21 +00:00
|
|
|
while (*frag != NULL);
|
2002-05-07 12:48:45 +00:00
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
} while (!h.end);
|
|
|
|
|
|
|
|
if (q) {
|
1999-12-20 20:29:47 +00:00
|
|
|
q = m_pullup(q);
|
2004-09-06 00:07:58 +00:00
|
|
|
log_Printf(LogDEBUG, "MP: Reassembled frags %lu-%lu, length %zd\n",
|
2004-09-05 01:46:52 +00:00
|
|
|
(u_long)first, (u_long)h.seq, m_length(q));
|
1999-12-20 20:29:47 +00:00
|
|
|
link_PullPacket(&mp->link, MBUF_CTOP(q), q->m_len, mp->bundle);
|
|
|
|
m_freem(q);
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
|
1998-05-04 03:00:09 +00:00
|
|
|
mp->seq.next_in = seq = inc_seq(mp->local_is12bit, h.seq);
|
1998-04-03 19:21:56 +00:00
|
|
|
last = NULL;
|
|
|
|
q = mp->inbufs;
|
|
|
|
} else {
|
|
|
|
/* Look for the next fragment */
|
1998-05-04 03:00:09 +00:00
|
|
|
seq = inc_seq(mp->local_is12bit, seq);
|
1998-04-03 19:21:56 +00:00
|
|
|
last = q;
|
1999-12-20 20:29:47 +00:00
|
|
|
q = q->m_nextpkt;
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m) {
|
|
|
|
/* We still have to find a home for our new fragment */
|
|
|
|
last = NULL;
|
1999-12-20 20:29:47 +00:00
|
|
|
for (q = mp->inbufs; q; last = q, q = q->m_nextpkt) {
|
1998-04-03 19:21:56 +00:00
|
|
|
mp_ReadHeader(mp, q, &h);
|
1998-05-04 21:42:41 +00:00
|
|
|
if (isbefore(mp->local_is12bit, mh.seq, h.seq))
|
1998-04-03 19:21:56 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-05-04 03:00:09 +00:00
|
|
|
/* Our received fragment fits in here */
|
|
|
|
if (last)
|
1999-12-20 20:29:47 +00:00
|
|
|
last->m_nextpkt = m;
|
1998-05-04 03:00:09 +00:00
|
|
|
else
|
|
|
|
mp->inbufs = m;
|
1999-12-20 20:29:47 +00:00
|
|
|
m->m_nextpkt = q;
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
struct mbuf *
|
|
|
|
mp_Input(struct bundle *bundle, struct link *l, struct mbuf *bp)
|
|
|
|
{
|
|
|
|
struct physical *p = link2physical(l);
|
|
|
|
|
|
|
|
if (!bundle->ncp.mp.active)
|
|
|
|
/* Let someone else deal with it ! */
|
|
|
|
return bp;
|
|
|
|
|
|
|
|
if (p == NULL) {
|
|
|
|
log_Printf(LogWARN, "DecodePacket: Can't do MP inside MP !\n");
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-06-02 15:59:09 +00:00
|
|
|
} else {
|
1999-12-20 20:29:47 +00:00
|
|
|
m_settype(bp, MB_MPIN);
|
1999-05-08 11:07:56 +00:00
|
|
|
mp_Assemble(&bundle->ncp.mp, bp, p);
|
1999-06-02 15:59:09 +00:00
|
|
|
}
|
1999-05-08 11:07:56 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
static void
|
1999-05-08 11:07:56 +00:00
|
|
|
mp_Output(struct mp *mp, struct bundle *bundle, struct link *l,
|
|
|
|
struct mbuf *m, u_int32_t begin, u_int32_t end)
|
1998-04-03 19:21:56 +00:00
|
|
|
{
|
1999-12-20 20:29:47 +00:00
|
|
|
char prepend[4];
|
1998-04-03 19:21:56 +00:00
|
|
|
|
1998-04-23 18:56:21 +00:00
|
|
|
/* Stuff an MP header on the front of our packet and send it */
|
1999-12-20 20:29:47 +00:00
|
|
|
|
1998-04-23 03:23:03 +00:00
|
|
|
if (mp->peer_is12bit) {
|
1998-09-04 18:26:00 +00:00
|
|
|
u_int16_t val;
|
1998-04-23 18:56:21 +00:00
|
|
|
|
1998-09-04 18:26:00 +00:00
|
|
|
val = (begin << 15) | (end << 14) | (u_int16_t)mp->out.seq;
|
1999-12-20 20:29:47 +00:00
|
|
|
ua_htons(&val, prepend);
|
|
|
|
m = m_prepend(m, prepend, 2, 0);
|
1998-04-03 19:21:56 +00:00
|
|
|
} else {
|
1998-09-04 18:26:00 +00:00
|
|
|
u_int32_t val;
|
1998-04-23 18:56:21 +00:00
|
|
|
|
1998-09-04 18:26:00 +00:00
|
|
|
val = (begin << 31) | (end << 30) | (u_int32_t)mp->out.seq;
|
1999-12-20 20:29:47 +00:00
|
|
|
ua_htonl(&val, prepend);
|
|
|
|
m = m_prepend(m, prepend, 4, 0);
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
1998-05-01 19:26:12 +00:00
|
|
|
if (log_IsKept(LogDEBUG))
|
2004-09-06 00:07:58 +00:00
|
|
|
log_Printf(LogDEBUG, "MP[frag %d]: Send %zd bytes on link `%s'\n",
|
1999-12-20 20:29:47 +00:00
|
|
|
mp->out.seq, m_length(m), l->name);
|
1998-05-04 03:00:09 +00:00
|
|
|
mp->out.seq = inc_seq(mp->peer_is12bit, mp->out.seq);
|
1998-04-03 19:21:56 +00:00
|
|
|
|
2001-07-03 22:20:19 +00:00
|
|
|
if (l->ccp.fsm.state != ST_OPENED && ccp_Required(&l->ccp)) {
|
|
|
|
log_Printf(LogPHASE, "%s: Not transmitting... waiting for CCP\n", l->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
link_PushPacket(l, m, bundle, LINK_QUEUES(l) - 1, PROTO_MP);
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-08-14 16:05:52 +00:00
|
|
|
mp_FillPhysicalQueues(struct bundle *bundle)
|
1998-04-03 19:21:56 +00:00
|
|
|
{
|
|
|
|
struct mp *mp = &bundle->ncp.mp;
|
1998-05-03 22:13:14 +00:00
|
|
|
struct datalink *dl, *fdl;
|
1999-12-20 20:29:47 +00:00
|
|
|
size_t total, add, len;
|
2002-05-14 00:59:28 +00:00
|
|
|
int thislink, nlinks, nopenlinks, sendasip;
|
1998-05-06 23:49:48 +00:00
|
|
|
u_int32_t begin, end;
|
1998-04-03 19:21:56 +00:00
|
|
|
struct mbuf *m, *mo;
|
2001-08-14 16:05:52 +00:00
|
|
|
struct link *bestlink;
|
1998-04-03 19:21:56 +00:00
|
|
|
|
2002-05-14 00:59:28 +00:00
|
|
|
thislink = nlinks = nopenlinks = 0;
|
1998-05-03 22:13:14 +00:00
|
|
|
for (fdl = NULL, dl = bundle->links; dl; dl = dl->next) {
|
1998-05-23 17:05:28 +00:00
|
|
|
/* Include non-open links here as mp->out.link will stay more correct */
|
1998-05-03 22:13:14 +00:00
|
|
|
if (!fdl) {
|
|
|
|
if (thislink == mp->out.link)
|
|
|
|
fdl = dl;
|
|
|
|
else
|
|
|
|
thislink++;
|
|
|
|
}
|
|
|
|
nlinks++;
|
2002-05-14 00:59:28 +00:00
|
|
|
if (dl->state == DATALINK_OPEN)
|
|
|
|
nopenlinks++;
|
1998-05-03 22:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!fdl) {
|
|
|
|
fdl = bundle->links;
|
1998-05-06 18:50:12 +00:00
|
|
|
if (!fdl)
|
|
|
|
return 0;
|
1998-05-03 22:13:14 +00:00
|
|
|
thislink = 0;
|
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
|
|
|
|
total = 0;
|
1998-05-03 22:13:14 +00:00
|
|
|
for (dl = fdl; nlinks > 0; dl = dl->next, nlinks--, thislink++) {
|
|
|
|
if (!dl) {
|
|
|
|
dl = bundle->links;
|
|
|
|
thislink = 0;
|
|
|
|
}
|
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
if (dl->state != DATALINK_OPEN)
|
|
|
|
continue;
|
1998-05-03 22:13:14 +00:00
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
if (dl->physical->out)
|
|
|
|
/* this link has suffered a short write. Let it continue */
|
|
|
|
continue;
|
1998-05-03 22:13:14 +00:00
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
add = link_QueueLen(&dl->physical->link);
|
2000-08-17 14:14:54 +00:00
|
|
|
if (add) {
|
1998-04-03 19:21:56 +00:00
|
|
|
/* this link has got stuff already queued. Let it continue */
|
2000-08-17 14:14:54 +00:00
|
|
|
total += add;
|
1998-04-03 19:21:56 +00:00
|
|
|
continue;
|
2000-08-17 14:14:54 +00:00
|
|
|
}
|
1998-05-03 22:13:14 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (!mp_QueueLen(mp)) {
|
2000-08-17 14:14:54 +00:00
|
|
|
int mrutoosmall;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there's only a single open link in our bundle and we haven't got
|
|
|
|
* MP level link compression, queue outbound traffic directly via that
|
|
|
|
* link's protocol stack rather than using the MP link. This results
|
2001-08-14 16:05:52 +00:00
|
|
|
* in the outbound traffic going out as PROTO_IP or PROTO_IPV6 rather
|
|
|
|
* than PROTO_MP.
|
2000-08-17 14:14:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
mrutoosmall = 0;
|
2002-05-14 00:59:28 +00:00
|
|
|
sendasip = nopenlinks < 2;
|
|
|
|
if (sendasip) {
|
2000-08-17 14:14:54 +00:00
|
|
|
if (dl->physical->link.lcp.his_mru < mp->peer_mrru) {
|
|
|
|
/*
|
|
|
|
* Actually, forget it. This test is done against the MRRU rather
|
|
|
|
* than the packet size so that we don't end up sending some data
|
|
|
|
* in MP fragments and some data in PROTO_IP packets. That's just
|
|
|
|
* too likely to upset some ppp implementations.
|
|
|
|
*/
|
|
|
|
mrutoosmall = 1;
|
2002-05-14 00:59:28 +00:00
|
|
|
sendasip = 0;
|
2000-08-17 14:14:54 +00:00
|
|
|
}
|
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
|
2002-05-14 00:59:28 +00:00
|
|
|
bestlink = sendasip ? &dl->physical->link : &mp->link;
|
2001-08-14 16:05:52 +00:00
|
|
|
if (!ncp_PushPacket(&bundle->ncp, &mp->out.af, bestlink))
|
|
|
|
break; /* Nothing else to send */
|
2000-08-17 14:14:54 +00:00
|
|
|
|
|
|
|
if (mrutoosmall)
|
|
|
|
log_Printf(LogDEBUG, "Don't send data as PROTO_IP, MRU < MRRU\n");
|
2002-05-14 00:59:28 +00:00
|
|
|
else if (sendasip)
|
2000-08-17 14:14:54 +00:00
|
|
|
log_Printf(LogDEBUG, "Sending data as PROTO_IP, not PROTO_MP\n");
|
|
|
|
|
2002-05-14 00:59:28 +00:00
|
|
|
if (sendasip) {
|
2000-08-17 14:14:54 +00:00
|
|
|
add = link_QueueLen(&dl->physical->link);
|
|
|
|
if (add) {
|
|
|
|
/* this link has got stuff already queued. Let it continue */
|
|
|
|
total += add;
|
|
|
|
continue;
|
1998-05-03 22:13:14 +00:00
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
2000-08-17 14:14:54 +00:00
|
|
|
}
|
1998-05-03 22:13:14 +00:00
|
|
|
|
2000-08-17 14:14:54 +00:00
|
|
|
m = link_Dequeue(&mp->link);
|
|
|
|
if (m) {
|
|
|
|
len = m_length(m);
|
|
|
|
begin = 1;
|
|
|
|
end = 0;
|
|
|
|
|
|
|
|
while (!end) {
|
|
|
|
if (dl->state == DATALINK_OPEN) {
|
|
|
|
/* Write at most his_mru bytes to the physical link */
|
|
|
|
if (len <= dl->physical->link.lcp.his_mru) {
|
|
|
|
mo = m;
|
|
|
|
end = 1;
|
|
|
|
m_settype(mo, MB_MPOUT);
|
|
|
|
} else {
|
|
|
|
/* It's > his_mru, chop the packet (`m') into bits */
|
|
|
|
mo = m_get(dl->physical->link.lcp.his_mru, MB_MPOUT);
|
|
|
|
len -= mo->m_len;
|
|
|
|
m = mbuf_Read(m, MBUF_CTOP(mo), mo->m_len);
|
|
|
|
}
|
|
|
|
mp_Output(mp, bundle, &dl->physical->link, mo, begin, end);
|
|
|
|
begin = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!end) {
|
|
|
|
nlinks--;
|
|
|
|
dl = dl->next;
|
|
|
|
if (!dl) {
|
|
|
|
dl = bundle->links;
|
|
|
|
thislink = 0;
|
|
|
|
} else
|
|
|
|
thislink++;
|
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-05-03 22:13:14 +00:00
|
|
|
mp->out.link = thislink; /* Start here next time */
|
1998-04-03 19:21:56 +00:00
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-08-05 10:32:16 +00:00
|
|
|
mp_SetDatalinkBandwidth(struct cmdargs const *arg)
|
1998-04-03 19:21:56 +00:00
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc != arg->argn+1)
|
1998-04-03 19:21:56 +00:00
|
|
|
return -1;
|
2000-08-17 14:14:54 +00:00
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
val = atoi(arg->argv[arg->argn]);
|
1999-08-05 10:32:16 +00:00
|
|
|
if (val <= 0) {
|
|
|
|
log_Printf(LogWARN, "The link bandwidth must be greater than zero\n");
|
1998-04-03 19:21:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
1999-08-05 10:32:16 +00:00
|
|
|
arg->cx->mp.bandwidth = val;
|
|
|
|
|
|
|
|
if (arg->cx->state == DATALINK_OPEN)
|
|
|
|
bundle_CalculateBandwidth(arg->bundle);
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1998-04-23 03:23:03 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
mp_ShowStatus(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
struct mp *mp = &arg->bundle->ncp.mp;
|
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, "Multilink is %sactive\n", mp->active ? "" : "in");
|
1998-05-03 22:13:14 +00:00
|
|
|
if (mp->active) {
|
1999-06-02 15:59:09 +00:00
|
|
|
struct mbuf *m, *lm;
|
1998-05-03 22:13:14 +00:00
|
|
|
int bufs = 0;
|
|
|
|
|
1999-06-02 23:06:21 +00:00
|
|
|
lm = NULL;
|
1998-04-28 01:25:46 +00:00
|
|
|
prompt_Printf(arg->prompt, "Socket: %s\n",
|
1998-04-30 23:53:56 +00:00
|
|
|
mp->server.socket.sun_path);
|
1999-12-20 20:29:47 +00:00
|
|
|
for (m = mp->inbufs; m; m = m->m_nextpkt) {
|
1998-05-03 22:13:14 +00:00
|
|
|
bufs++;
|
1999-06-02 15:59:09 +00:00
|
|
|
lm = m;
|
|
|
|
}
|
|
|
|
prompt_Printf(arg->prompt, "Pending frags: %d", bufs);
|
|
|
|
if (bufs) {
|
|
|
|
struct mp_header mh;
|
|
|
|
unsigned long first, last;
|
|
|
|
|
|
|
|
first = mp_ReadHeader(mp, mp->inbufs, &mh) ? mh.seq : 0;
|
|
|
|
last = mp_ReadHeader(mp, lm, &mh) ? mh.seq : 0;
|
1999-06-03 13:29:32 +00:00
|
|
|
prompt_Printf(arg->prompt, " (Have %lu - %lu, want %lu, lowest %lu)\n",
|
1999-06-02 15:59:09 +00:00
|
|
|
first, last, (unsigned long)mp->seq.next_in,
|
|
|
|
(unsigned long)mp->seq.min_in);
|
1999-06-03 13:29:32 +00:00
|
|
|
prompt_Printf(arg->prompt, " First has %sbegin bit and "
|
|
|
|
"%send bit", mh.begin ? "" : "no ", mh.end ? "" : "no ");
|
1999-06-02 15:59:09 +00:00
|
|
|
}
|
|
|
|
prompt_Printf(arg->prompt, "\n");
|
1998-05-03 22:13:14 +00:00
|
|
|
}
|
1998-04-23 03:23:03 +00:00
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, "\nMy Side:\n");
|
|
|
|
if (mp->active) {
|
1999-08-05 10:32:16 +00:00
|
|
|
prompt_Printf(arg->prompt, " Output SEQ: %u\n", mp->out.seq);
|
1998-04-24 19:16:15 +00:00
|
|
|
prompt_Printf(arg->prompt, " MRRU: %u\n", mp->local_mrru);
|
|
|
|
prompt_Printf(arg->prompt, " Short Seq: %s\n",
|
1998-04-23 03:23:03 +00:00
|
|
|
mp->local_is12bit ? "on" : "off");
|
|
|
|
}
|
1998-04-24 19:16:15 +00:00
|
|
|
prompt_Printf(arg->prompt, " Discriminator: %s\n",
|
1998-04-23 03:23:03 +00:00
|
|
|
mp_Enddisc(mp->cfg.enddisc.class, mp->cfg.enddisc.address,
|
|
|
|
mp->cfg.enddisc.len));
|
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, "\nHis Side:\n");
|
|
|
|
if (mp->active) {
|
1998-04-24 19:16:15 +00:00
|
|
|
prompt_Printf(arg->prompt, " Auth Name: %s\n", mp->peer.authname);
|
1999-08-05 10:32:16 +00:00
|
|
|
prompt_Printf(arg->prompt, " Input SEQ: %u\n", mp->seq.next_in);
|
1998-04-24 19:16:15 +00:00
|
|
|
prompt_Printf(arg->prompt, " MRRU: %u\n", mp->peer_mrru);
|
|
|
|
prompt_Printf(arg->prompt, " Short Seq: %s\n",
|
1998-04-23 03:23:03 +00:00
|
|
|
mp->peer_is12bit ? "on" : "off");
|
|
|
|
}
|
1998-04-24 19:16:15 +00:00
|
|
|
prompt_Printf(arg->prompt, " Discriminator: %s\n",
|
|
|
|
mp_Enddisc(mp->peer.enddisc.class, mp->peer.enddisc.address,
|
|
|
|
mp->peer.enddisc.len));
|
1998-04-23 03:23:03 +00:00
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, "\nDefaults:\n");
|
2000-08-17 14:14:54 +00:00
|
|
|
|
1998-04-24 19:16:15 +00:00
|
|
|
prompt_Printf(arg->prompt, " MRRU: ");
|
1998-04-23 03:23:03 +00:00
|
|
|
if (mp->cfg.mrru)
|
|
|
|
prompt_Printf(arg->prompt, "%d (multilink enabled)\n", mp->cfg.mrru);
|
|
|
|
else
|
|
|
|
prompt_Printf(arg->prompt, "disabled\n");
|
1998-04-24 19:16:15 +00:00
|
|
|
prompt_Printf(arg->prompt, " Short Seq: %s\n",
|
1998-04-23 03:23:03 +00:00
|
|
|
command_ShowNegval(mp->cfg.shortseq));
|
1999-06-09 16:54:04 +00:00
|
|
|
prompt_Printf(arg->prompt, " Discriminator: %s\n",
|
|
|
|
command_ShowNegval(mp->cfg.negenddisc));
|
1999-08-05 10:32:16 +00:00
|
|
|
prompt_Printf(arg->prompt, " AutoLoad: min %d%%, max %d%%,"
|
|
|
|
" period %d secs\n", mp->cfg.autoload.min,
|
|
|
|
mp->cfg.autoload.max, mp->cfg.autoload.period);
|
1998-04-23 03:23:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2004-09-05 01:46:52 +00:00
|
|
|
mp_Enddisc(u_char c, const char *address, size_t len)
|
1998-04-23 03:23:03 +00:00
|
|
|
{
|
1998-06-15 19:06:58 +00:00
|
|
|
static char result[100]; /* Used immediately after it's returned */
|
2004-09-05 01:46:52 +00:00
|
|
|
unsigned f, header;
|
1998-04-23 03:23:03 +00:00
|
|
|
|
|
|
|
switch (c) {
|
1998-04-23 23:50:40 +00:00
|
|
|
case ENDDISC_NULL:
|
1998-04-23 03:23:03 +00:00
|
|
|
sprintf(result, "Null Class");
|
|
|
|
break;
|
|
|
|
|
1998-04-23 23:50:40 +00:00
|
|
|
case ENDDISC_LOCAL:
|
2004-09-06 00:07:58 +00:00
|
|
|
snprintf(result, sizeof result, "Local Addr: %.*s", (int)len,
|
|
|
|
address);
|
1998-04-23 03:23:03 +00:00
|
|
|
break;
|
|
|
|
|
1998-04-23 23:50:40 +00:00
|
|
|
case ENDDISC_IP:
|
1998-04-23 03:23:03 +00:00
|
|
|
if (len == 4)
|
|
|
|
snprintf(result, sizeof result, "IP %s",
|
|
|
|
inet_ntoa(*(const struct in_addr *)address));
|
|
|
|
else
|
2004-09-06 00:07:58 +00:00
|
|
|
sprintf(result, "IP[%zd] ???", len);
|
1998-04-23 03:23:03 +00:00
|
|
|
break;
|
|
|
|
|
1998-04-23 23:50:40 +00:00
|
|
|
case ENDDISC_MAC:
|
1998-04-23 03:23:03 +00:00
|
|
|
if (len == 6) {
|
|
|
|
const u_char *m = (const u_char *)address;
|
|
|
|
snprintf(result, sizeof result, "MAC %02x:%02x:%02x:%02x:%02x:%02x",
|
|
|
|
m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
|
|
} else
|
2004-09-06 00:07:58 +00:00
|
|
|
sprintf(result, "MAC[%zd] ???", len);
|
1998-04-23 03:23:03 +00:00
|
|
|
break;
|
|
|
|
|
1998-04-23 23:50:40 +00:00
|
|
|
case ENDDISC_MAGIC:
|
1998-04-23 03:23:03 +00:00
|
|
|
sprintf(result, "Magic: 0x");
|
|
|
|
header = strlen(result);
|
2004-09-05 01:46:52 +00:00
|
|
|
if (len + header + 1 > sizeof result)
|
1998-04-23 03:23:03 +00:00
|
|
|
len = sizeof result - header - 1;
|
|
|
|
for (f = 0; f < len; f++)
|
|
|
|
sprintf(result + header + 2 * f, "%02x", address[f]);
|
|
|
|
break;
|
|
|
|
|
1998-04-23 23:50:40 +00:00
|
|
|
case ENDDISC_PSN:
|
2004-09-06 00:07:58 +00:00
|
|
|
snprintf(result, sizeof result, "PSN: %.*s", (int)len, address);
|
1998-04-23 03:23:03 +00:00
|
|
|
break;
|
|
|
|
|
2004-09-05 01:46:52 +00:00
|
|
|
default:
|
1998-04-23 03:23:03 +00:00
|
|
|
sprintf(result, "%d: ", (int)c);
|
|
|
|
header = strlen(result);
|
2004-09-05 01:46:52 +00:00
|
|
|
if (len + header + 1 > sizeof result)
|
1998-04-23 03:23:03 +00:00
|
|
|
len = sizeof result - header - 1;
|
|
|
|
for (f = 0; f < len; f++)
|
|
|
|
sprintf(result + header + 2 * f, "%02x", address[f]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mp_SetEnddisc(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
struct mp *mp = &arg->bundle->ncp.mp;
|
1998-04-24 19:15:48 +00:00
|
|
|
struct in_addr addr;
|
1998-04-23 03:23:03 +00:00
|
|
|
|
1998-10-24 01:08:45 +00:00
|
|
|
switch (bundle_Phase(arg->bundle)) {
|
|
|
|
case PHASE_DEAD:
|
|
|
|
break;
|
|
|
|
case PHASE_ESTABLISH:
|
|
|
|
/* Make sure none of our links are DATALINK_LCP or greater */
|
|
|
|
if (bundle_HighestState(arg->bundle) >= DATALINK_LCP) {
|
2011-12-30 10:58:14 +00:00
|
|
|
log_Printf(LogWARN, "enddisc: Only changeable before"
|
1998-10-24 01:08:45 +00:00
|
|
|
" LCP negotiations\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2011-12-30 10:58:14 +00:00
|
|
|
log_Printf(LogWARN, "enddisc: Only changeable at phase DEAD/ESTABLISH\n");
|
1998-10-24 01:08:45 +00:00
|
|
|
return 1;
|
1998-04-23 03:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->argc == arg->argn) {
|
|
|
|
mp->cfg.enddisc.class = 0;
|
|
|
|
*mp->cfg.enddisc.address = '\0';
|
|
|
|
mp->cfg.enddisc.len = 0;
|
1998-04-25 10:49:52 +00:00
|
|
|
} else if (arg->argc > arg->argn) {
|
1998-04-23 23:50:40 +00:00
|
|
|
if (!strcasecmp(arg->argv[arg->argn], "label")) {
|
|
|
|
mp->cfg.enddisc.class = ENDDISC_LOCAL;
|
|
|
|
strcpy(mp->cfg.enddisc.address, arg->bundle->cfg.label);
|
|
|
|
mp->cfg.enddisc.len = strlen(mp->cfg.enddisc.address);
|
|
|
|
} else if (!strcasecmp(arg->argv[arg->argn], "ip")) {
|
1998-04-24 19:16:20 +00:00
|
|
|
if (arg->bundle->ncp.ipcp.my_ip.s_addr == INADDR_ANY)
|
2001-08-14 16:05:52 +00:00
|
|
|
ncprange_getip4addr(&arg->bundle->ncp.ipcp.cfg.my_range, &addr);
|
1998-04-24 19:15:48 +00:00
|
|
|
else
|
1998-04-24 19:16:20 +00:00
|
|
|
addr = arg->bundle->ncp.ipcp.my_ip;
|
1998-04-24 19:15:48 +00:00
|
|
|
memcpy(mp->cfg.enddisc.address, &addr.s_addr, sizeof addr.s_addr);
|
1998-04-23 23:50:40 +00:00
|
|
|
mp->cfg.enddisc.class = ENDDISC_IP;
|
1998-04-23 03:23:03 +00:00
|
|
|
mp->cfg.enddisc.len = sizeof arg->bundle->ncp.ipcp.my_ip.s_addr;
|
1998-04-23 23:50:40 +00:00
|
|
|
} else if (!strcasecmp(arg->argv[arg->argn], "mac")) {
|
|
|
|
struct sockaddr_dl hwaddr;
|
|
|
|
|
1998-04-24 19:16:20 +00:00
|
|
|
if (arg->bundle->ncp.ipcp.my_ip.s_addr == INADDR_ANY)
|
2001-08-14 16:05:52 +00:00
|
|
|
ncprange_getip4addr(&arg->bundle->ncp.ipcp.cfg.my_range, &addr);
|
1998-04-24 19:15:48 +00:00
|
|
|
else
|
1998-04-24 19:16:20 +00:00
|
|
|
addr = arg->bundle->ncp.ipcp.my_ip;
|
1998-04-24 19:15:48 +00:00
|
|
|
|
2004-09-05 01:46:52 +00:00
|
|
|
if (arp_EtherAddr(addr, &hwaddr, 1)) {
|
1998-04-23 23:50:40 +00:00
|
|
|
mp->cfg.enddisc.class = ENDDISC_MAC;
|
|
|
|
memcpy(mp->cfg.enddisc.address, hwaddr.sdl_data + hwaddr.sdl_nlen,
|
|
|
|
hwaddr.sdl_alen);
|
|
|
|
mp->cfg.enddisc.len = hwaddr.sdl_alen;
|
|
|
|
} else {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "set enddisc: Can't locate MAC address for %s\n",
|
1998-04-24 19:16:20 +00:00
|
|
|
inet_ntoa(addr));
|
1998-04-23 23:50:40 +00:00
|
|
|
return 4;
|
|
|
|
}
|
1998-04-23 03:23:03 +00:00
|
|
|
} else if (!strcasecmp(arg->argv[arg->argn], "magic")) {
|
|
|
|
int f;
|
|
|
|
|
|
|
|
randinit();
|
|
|
|
for (f = 0; f < 20; f += sizeof(long))
|
|
|
|
*(long *)(mp->cfg.enddisc.address + f) = random();
|
1998-04-23 23:50:40 +00:00
|
|
|
mp->cfg.enddisc.class = ENDDISC_MAGIC;
|
1998-04-23 03:23:03 +00:00
|
|
|
mp->cfg.enddisc.len = 20;
|
|
|
|
} else if (!strcasecmp(arg->argv[arg->argn], "psn")) {
|
|
|
|
if (arg->argc > arg->argn+1) {
|
1998-04-23 23:50:40 +00:00
|
|
|
mp->cfg.enddisc.class = ENDDISC_PSN;
|
1998-04-23 03:23:03 +00:00
|
|
|
strcpy(mp->cfg.enddisc.address, arg->argv[arg->argn+1]);
|
|
|
|
mp->cfg.enddisc.len = strlen(mp->cfg.enddisc.address);
|
|
|
|
} else {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "PSN endpoint requires additional data\n");
|
1998-04-23 23:50:40 +00:00
|
|
|
return 5;
|
1998-04-23 03:23:03 +00:00
|
|
|
}
|
|
|
|
} else {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: Unrecognised endpoint type\n",
|
1998-04-23 03:23:03 +00:00
|
|
|
arg->argv[arg->argn]);
|
1998-04-23 23:50:40 +00:00
|
|
|
return 6;
|
1998-04-23 03:23:03 +00:00
|
|
|
}
|
1998-04-25 10:49:52 +00:00
|
|
|
}
|
1998-04-23 03:23:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
1998-04-28 01:25:46 +00:00
|
|
|
|
|
|
|
static int
|
2000-03-14 01:46:09 +00:00
|
|
|
mpserver_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w, fd_set *e,
|
1998-04-28 01:25:46 +00:00
|
|
|
int *n)
|
|
|
|
{
|
|
|
|
struct mpserver *s = descriptor2mpserver(d);
|
1998-05-23 22:24:50 +00:00
|
|
|
int result;
|
1998-04-28 01:25:46 +00:00
|
|
|
|
1998-05-23 22:24:50 +00:00
|
|
|
result = 0;
|
1998-04-30 23:53:56 +00:00
|
|
|
if (s->send.dl != NULL) {
|
1998-05-02 21:57:50 +00:00
|
|
|
/* We've connect()ed */
|
1998-05-08 01:15:19 +00:00
|
|
|
if (!link_QueueLen(&s->send.dl->physical->link) &&
|
|
|
|
!s->send.dl->physical->out) {
|
|
|
|
/* Only send if we've transmitted all our data (i.e. the ConfigAck) */
|
1998-05-23 22:24:50 +00:00
|
|
|
result -= datalink_RemoveFromSet(s->send.dl, r, w, e);
|
1998-05-08 01:15:19 +00:00
|
|
|
bundle_SendDatalink(s->send.dl, s->fd, &s->socket);
|
|
|
|
s->send.dl = NULL;
|
|
|
|
s->fd = -1;
|
1998-05-15 18:21:45 +00:00
|
|
|
} else
|
|
|
|
/* Never read from a datalink that's on death row ! */
|
1998-05-23 22:24:50 +00:00
|
|
|
result -= datalink_RemoveFromSet(s->send.dl, r, NULL, NULL);
|
1998-05-02 21:57:50 +00:00
|
|
|
} else if (r && s->fd >= 0) {
|
1998-04-28 01:25:46 +00:00
|
|
|
if (*n < s->fd + 1)
|
|
|
|
*n = s->fd + 1;
|
|
|
|
FD_SET(s->fd, r);
|
1998-05-10 22:20:20 +00:00
|
|
|
log_Printf(LogTIMER, "mp: fdset(r) %d\n", s->fd);
|
1998-05-23 22:24:50 +00:00
|
|
|
result++;
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
1998-05-23 22:24:50 +00:00
|
|
|
return result;
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-03-14 01:46:09 +00:00
|
|
|
mpserver_IsSet(struct fdescriptor *d, const fd_set *fdset)
|
1998-04-28 01:25:46 +00:00
|
|
|
{
|
|
|
|
struct mpserver *s = descriptor2mpserver(d);
|
|
|
|
return s->fd >= 0 && FD_ISSET(s->fd, fdset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-09-05 01:46:52 +00:00
|
|
|
mpserver_Read(struct fdescriptor *d, struct bundle *bundle,
|
|
|
|
const fd_set *fdset __unused)
|
1998-04-28 01:25:46 +00:00
|
|
|
{
|
|
|
|
struct mpserver *s = descriptor2mpserver(d);
|
|
|
|
|
Rewrite the link descriptor transfer code in MP mode.
Previously, ppp attempted to bind() to a local domain tcp socket
based on the peer authname & enddisc. If it succeeded, it listen()ed
and became MP server. If it failed, it connect()ed and became MP
client. The server then select()ed on the descriptor, accept()ed
it and wrote its pid to it then read the link data & link file descriptor,
and finally sent an ack (``!''). The client would read() the server
pid, transfer the link lock to that pid, send the link data & descriptor
and read the ack. It would then close the descriptor and clean up.
There was a race between the bind() and listen() where someone could
attempt to connect() and fail.
This change removes the race. Now ppp makes the RCVBUF big enough on a
socket descriptor and attempts to bind() to a local domain *udp* socket
(same name as before). If it succeeds, it becomes MP server. If it
fails, it sets the SNDBUF and connect()s, becoming MP client. The server
select()s on the descriptor and recvmsg()s the message, insisting on at
least two descriptors (plus the link data). It uses the second descriptor
to write() its pid then read()s an ack (``!''). The client creates a
socketpair() and sendmsg()s the link data, link descriptor and one of
the socketpair descriptors. It then read()s the server pid from the
other socketpair descriptor, transfers any locks and write()s an ack.
Now, there can be no race, and a connect() failure indicates a stale
socket file.
This also fixes MP ppp over ethernet, where the struct msghdr was being
misconstructed when transferring the control socket descriptor.
Also, if we fail to send the link, don't hang around in a ``session
owner'' state, just do the setsid() and fork() if it's required to
disown a tty.
UDP idea suggested by: Chris Bennet from Mindspring at FreeBSDCon
1999-11-25 02:47:04 +00:00
|
|
|
bundle_ReceiveDatalink(bundle, s->fd);
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
|
|
|
|
1998-06-24 19:33:36 +00:00
|
|
|
static int
|
2004-09-05 01:46:52 +00:00
|
|
|
mpserver_Write(struct fdescriptor *d __unused, struct bundle *bundle __unused,
|
|
|
|
const fd_set *fdset __unused)
|
1998-04-28 01:25:46 +00:00
|
|
|
{
|
|
|
|
/* We never want to write here ! */
|
1998-06-16 19:40:42 +00:00
|
|
|
log_Printf(LogALERT, "mpserver_Write: Internal error: Bad call !\n");
|
1998-06-24 19:33:36 +00:00
|
|
|
return 0;
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mpserver_Init(struct mpserver *s)
|
|
|
|
{
|
|
|
|
s->desc.type = MPSERVER_DESCRIPTOR;
|
|
|
|
s->desc.UpdateSet = mpserver_UpdateSet;
|
|
|
|
s->desc.IsSet = mpserver_IsSet;
|
|
|
|
s->desc.Read = mpserver_Read;
|
|
|
|
s->desc.Write = mpserver_Write;
|
1998-04-30 23:53:56 +00:00
|
|
|
s->send.dl = NULL;
|
1998-04-28 01:25:46 +00:00
|
|
|
s->fd = -1;
|
1998-04-30 23:53:56 +00:00
|
|
|
memset(&s->socket, '\0', sizeof s->socket);
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mpserver_Open(struct mpserver *s, struct peerid *peer)
|
|
|
|
{
|
1999-11-30 23:52:37 +00:00
|
|
|
int f, l;
|
1998-04-28 01:25:46 +00:00
|
|
|
mode_t mask;
|
|
|
|
|
|
|
|
if (s->fd != -1) {
|
1998-06-16 19:40:42 +00:00
|
|
|
log_Printf(LogALERT, "Internal error ! mpserver already open\n");
|
1998-04-30 23:53:56 +00:00
|
|
|
mpserver_Close(s);
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
l = snprintf(s->socket.sun_path, sizeof s->socket.sun_path, "%sppp-%s-%02x-",
|
|
|
|
_PATH_VARRUN, peer->authname, peer->enddisc.class);
|
2001-08-18 22:43:11 +00:00
|
|
|
if (l < 0) {
|
|
|
|
log_Printf(LogERROR, "mpserver: snprintf(): %s\n", strerror(errno));
|
|
|
|
return MPSERVER_FAILED;
|
|
|
|
}
|
1998-04-28 01:25:46 +00:00
|
|
|
|
2004-09-05 01:46:52 +00:00
|
|
|
for (f = 0;
|
|
|
|
f < peer->enddisc.len && (size_t)l < sizeof s->socket.sun_path - 2;
|
|
|
|
f++) {
|
1998-04-30 23:53:56 +00:00
|
|
|
snprintf(s->socket.sun_path + l, sizeof s->socket.sun_path - l,
|
1998-04-28 01:25:46 +00:00
|
|
|
"%02x", *(u_char *)(peer->enddisc.address+f));
|
1998-04-30 23:53:56 +00:00
|
|
|
l += 2;
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
s->socket.sun_family = AF_LOCAL;
|
|
|
|
s->socket.sun_len = sizeof s->socket;
|
2002-01-16 14:03:52 +00:00
|
|
|
s->fd = ID0socket(PF_LOCAL, SOCK_DGRAM, 0);
|
1998-04-28 01:25:46 +00:00
|
|
|
if (s->fd < 0) {
|
Rewrite the link descriptor transfer code in MP mode.
Previously, ppp attempted to bind() to a local domain tcp socket
based on the peer authname & enddisc. If it succeeded, it listen()ed
and became MP server. If it failed, it connect()ed and became MP
client. The server then select()ed on the descriptor, accept()ed
it and wrote its pid to it then read the link data & link file descriptor,
and finally sent an ack (``!''). The client would read() the server
pid, transfer the link lock to that pid, send the link data & descriptor
and read the ack. It would then close the descriptor and clean up.
There was a race between the bind() and listen() where someone could
attempt to connect() and fail.
This change removes the race. Now ppp makes the RCVBUF big enough on a
socket descriptor and attempts to bind() to a local domain *udp* socket
(same name as before). If it succeeds, it becomes MP server. If it
fails, it sets the SNDBUF and connect()s, becoming MP client. The server
select()s on the descriptor and recvmsg()s the message, insisting on at
least two descriptors (plus the link data). It uses the second descriptor
to write() its pid then read()s an ack (``!''). The client creates a
socketpair() and sendmsg()s the link data, link descriptor and one of
the socketpair descriptors. It then read()s the server pid from the
other socketpair descriptor, transfers any locks and write()s an ack.
Now, there can be no race, and a connect() failure indicates a stale
socket file.
This also fixes MP ppp over ethernet, where the struct msghdr was being
misconstructed when transferring the control socket descriptor.
Also, if we fail to send the link, don't hang around in a ``session
owner'' state, just do the setsid() and fork() if it's required to
disown a tty.
UDP idea suggested by: Chris Bennet from Mindspring at FreeBSDCon
1999-11-25 02:47:04 +00:00
|
|
|
log_Printf(LogERROR, "mpserver: socket(): %s\n", strerror(errno));
|
1998-05-02 21:57:50 +00:00
|
|
|
return MPSERVER_FAILED;
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
setsockopt(s->fd, SOL_SOCKET, SO_REUSEADDR, (struct sockaddr *)&s->socket,
|
|
|
|
sizeof s->socket);
|
1998-04-28 01:25:46 +00:00
|
|
|
mask = umask(0177);
|
Rewrite the link descriptor transfer code in MP mode.
Previously, ppp attempted to bind() to a local domain tcp socket
based on the peer authname & enddisc. If it succeeded, it listen()ed
and became MP server. If it failed, it connect()ed and became MP
client. The server then select()ed on the descriptor, accept()ed
it and wrote its pid to it then read the link data & link file descriptor,
and finally sent an ack (``!''). The client would read() the server
pid, transfer the link lock to that pid, send the link data & descriptor
and read the ack. It would then close the descriptor and clean up.
There was a race between the bind() and listen() where someone could
attempt to connect() and fail.
This change removes the race. Now ppp makes the RCVBUF big enough on a
socket descriptor and attempts to bind() to a local domain *udp* socket
(same name as before). If it succeeds, it becomes MP server. If it
fails, it sets the SNDBUF and connect()s, becoming MP client. The server
select()s on the descriptor and recvmsg()s the message, insisting on at
least two descriptors (plus the link data). It uses the second descriptor
to write() its pid then read()s an ack (``!''). The client creates a
socketpair() and sendmsg()s the link data, link descriptor and one of
the socketpair descriptors. It then read()s the server pid from the
other socketpair descriptor, transfers any locks and write()s an ack.
Now, there can be no race, and a connect() failure indicates a stale
socket file.
This also fixes MP ppp over ethernet, where the struct msghdr was being
misconstructed when transferring the control socket descriptor.
Also, if we fail to send the link, don't hang around in a ``session
owner'' state, just do the setsid() and fork() if it's required to
disown a tty.
UDP idea suggested by: Chris Bennet from Mindspring at FreeBSDCon
1999-11-25 02:47:04 +00:00
|
|
|
|
|
|
|
/*
|
1999-11-30 23:52:37 +00:00
|
|
|
* Try to bind the socket. If we succeed we play server, if we fail
|
|
|
|
* we connect() and hand the link off.
|
Rewrite the link descriptor transfer code in MP mode.
Previously, ppp attempted to bind() to a local domain tcp socket
based on the peer authname & enddisc. If it succeeded, it listen()ed
and became MP server. If it failed, it connect()ed and became MP
client. The server then select()ed on the descriptor, accept()ed
it and wrote its pid to it then read the link data & link file descriptor,
and finally sent an ack (``!''). The client would read() the server
pid, transfer the link lock to that pid, send the link data & descriptor
and read the ack. It would then close the descriptor and clean up.
There was a race between the bind() and listen() where someone could
attempt to connect() and fail.
This change removes the race. Now ppp makes the RCVBUF big enough on a
socket descriptor and attempts to bind() to a local domain *udp* socket
(same name as before). If it succeeds, it becomes MP server. If it
fails, it sets the SNDBUF and connect()s, becoming MP client. The server
select()s on the descriptor and recvmsg()s the message, insisting on at
least two descriptors (plus the link data). It uses the second descriptor
to write() its pid then read()s an ack (``!''). The client creates a
socketpair() and sendmsg()s the link data, link descriptor and one of
the socketpair descriptors. It then read()s the server pid from the
other socketpair descriptor, transfers any locks and write()s an ack.
Now, there can be no race, and a connect() failure indicates a stale
socket file.
This also fixes MP ppp over ethernet, where the struct msghdr was being
misconstructed when transferring the control socket descriptor.
Also, if we fail to send the link, don't hang around in a ``session
owner'' state, just do the setsid() and fork() if it's required to
disown a tty.
UDP idea suggested by: Chris Bennet from Mindspring at FreeBSDCon
1999-11-25 02:47:04 +00:00
|
|
|
*/
|
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
if (ID0bind_un(s->fd, &s->socket) < 0) {
|
|
|
|
if (errno != EADDRINUSE) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "mpserver: can't create bundle socket %s (%s)\n",
|
1998-04-30 23:53:56 +00:00
|
|
|
s->socket.sun_path, strerror(errno));
|
|
|
|
umask(mask);
|
1998-04-28 01:25:46 +00:00
|
|
|
close(s->fd);
|
|
|
|
s->fd = -1;
|
1998-05-02 21:57:50 +00:00
|
|
|
return MPSERVER_FAILED;
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
Rewrite the link descriptor transfer code in MP mode.
Previously, ppp attempted to bind() to a local domain tcp socket
based on the peer authname & enddisc. If it succeeded, it listen()ed
and became MP server. If it failed, it connect()ed and became MP
client. The server then select()ed on the descriptor, accept()ed
it and wrote its pid to it then read the link data & link file descriptor,
and finally sent an ack (``!''). The client would read() the server
pid, transfer the link lock to that pid, send the link data & descriptor
and read the ack. It would then close the descriptor and clean up.
There was a race between the bind() and listen() where someone could
attempt to connect() and fail.
This change removes the race. Now ppp makes the RCVBUF big enough on a
socket descriptor and attempts to bind() to a local domain *udp* socket
(same name as before). If it succeeds, it becomes MP server. If it
fails, it sets the SNDBUF and connect()s, becoming MP client. The server
select()s on the descriptor and recvmsg()s the message, insisting on at
least two descriptors (plus the link data). It uses the second descriptor
to write() its pid then read()s an ack (``!''). The client creates a
socketpair() and sendmsg()s the link data, link descriptor and one of
the socketpair descriptors. It then read()s the server pid from the
other socketpair descriptor, transfers any locks and write()s an ack.
Now, there can be no race, and a connect() failure indicates a stale
socket file.
This also fixes MP ppp over ethernet, where the struct msghdr was being
misconstructed when transferring the control socket descriptor.
Also, if we fail to send the link, don't hang around in a ``session
owner'' state, just do the setsid() and fork() if it's required to
disown a tty.
UDP idea suggested by: Chris Bennet from Mindspring at FreeBSDCon
1999-11-25 02:47:04 +00:00
|
|
|
|
1999-11-30 23:52:37 +00:00
|
|
|
/* So we're the sender */
|
1998-04-28 01:25:46 +00:00
|
|
|
umask(mask);
|
1998-04-30 23:53:56 +00:00
|
|
|
if (ID0connect_un(s->fd, &s->socket) < 0) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "mpserver: can't connect to bundle socket %s (%s)\n",
|
1998-04-30 23:53:56 +00:00
|
|
|
s->socket.sun_path, strerror(errno));
|
|
|
|
if (errno == ECONNREFUSED)
|
Rewrite the link descriptor transfer code in MP mode.
Previously, ppp attempted to bind() to a local domain tcp socket
based on the peer authname & enddisc. If it succeeded, it listen()ed
and became MP server. If it failed, it connect()ed and became MP
client. The server then select()ed on the descriptor, accept()ed
it and wrote its pid to it then read the link data & link file descriptor,
and finally sent an ack (``!''). The client would read() the server
pid, transfer the link lock to that pid, send the link data & descriptor
and read the ack. It would then close the descriptor and clean up.
There was a race between the bind() and listen() where someone could
attempt to connect() and fail.
This change removes the race. Now ppp makes the RCVBUF big enough on a
socket descriptor and attempts to bind() to a local domain *udp* socket
(same name as before). If it succeeds, it becomes MP server. If it
fails, it sets the SNDBUF and connect()s, becoming MP client. The server
select()s on the descriptor and recvmsg()s the message, insisting on at
least two descriptors (plus the link data). It uses the second descriptor
to write() its pid then read()s an ack (``!''). The client creates a
socketpair() and sendmsg()s the link data, link descriptor and one of
the socketpair descriptors. It then read()s the server pid from the
other socketpair descriptor, transfers any locks and write()s an ack.
Now, there can be no race, and a connect() failure indicates a stale
socket file.
This also fixes MP ppp over ethernet, where the struct msghdr was being
misconstructed when transferring the control socket descriptor.
Also, if we fail to send the link, don't hang around in a ``session
owner'' state, just do the setsid() and fork() if it's required to
disown a tty.
UDP idea suggested by: Chris Bennet from Mindspring at FreeBSDCon
1999-11-25 02:47:04 +00:00
|
|
|
log_Printf(LogPHASE, " The previous server died badly !\n");
|
1998-04-30 23:53:56 +00:00
|
|
|
close(s->fd);
|
|
|
|
s->fd = -1;
|
1998-05-02 21:57:50 +00:00
|
|
|
return MPSERVER_FAILED;
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
1998-04-30 23:53:56 +00:00
|
|
|
|
|
|
|
/* Donate our link to the other guy */
|
1998-05-02 21:57:50 +00:00
|
|
|
return MPSERVER_CONNECTED;
|
1998-04-30 23:53:56 +00:00
|
|
|
}
|
|
|
|
|
1998-05-02 21:57:50 +00:00
|
|
|
return MPSERVER_LISTENING;
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mpserver_Close(struct mpserver *s)
|
|
|
|
{
|
1998-04-30 23:53:56 +00:00
|
|
|
if (s->send.dl != NULL) {
|
1998-05-02 21:57:50 +00:00
|
|
|
bundle_SendDatalink(s->send.dl, s->fd, &s->socket);
|
1998-04-30 23:53:56 +00:00
|
|
|
s->send.dl = NULL;
|
1998-05-02 21:57:50 +00:00
|
|
|
s->fd = -1;
|
|
|
|
} else if (s->fd >= 0) {
|
1998-04-28 01:25:46 +00:00
|
|
|
close(s->fd);
|
1998-04-30 23:53:56 +00:00
|
|
|
if (ID0unlink(s->socket.sun_path) == -1)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogERROR, "%s: Failed to remove: %s\n", s->socket.sun_path,
|
1998-04-30 23:53:56 +00:00
|
|
|
strerror(errno));
|
|
|
|
memset(&s->socket, '\0', sizeof s->socket);
|
1998-04-28 01:25:46 +00:00
|
|
|
s->fd = -1;
|
|
|
|
}
|
|
|
|
}
|
1998-05-23 17:05:28 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
mp_LinkLost(struct mp *mp, struct datalink *dl)
|
|
|
|
{
|
|
|
|
if (mp->seq.min_in == dl->mp.seq)
|
|
|
|
/* We've lost the link that's holding everything up ! */
|
1999-05-08 11:07:56 +00:00
|
|
|
mp_Assemble(mp, NULL, NULL);
|
1998-05-23 17:05:28 +00:00
|
|
|
}
|
1998-08-25 17:48:43 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
size_t
|
|
|
|
mp_QueueLen(struct mp *mp)
|
1998-08-25 17:48:43 +00:00
|
|
|
{
|
2001-08-14 16:05:52 +00:00
|
|
|
return link_QueueLen(&mp->link);
|
1998-08-25 17:48:43 +00:00
|
|
|
}
|