1998-02-02 19:32:16 +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-02-02 19:32:16 +00:00
|
|
|
*/
|
|
|
|
|
1998-05-28 23:17:51 +00:00
|
|
|
#include <sys/param.h>
|
1998-02-02 19:32:16 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <net/if.h>
|
2000-01-23 01:48:19 +00:00
|
|
|
#include <net/if_tun.h> /* For TUNS* ioctls */
|
1998-02-02 19:32:16 +00:00
|
|
|
#include <net/route.h>
|
1998-03-16 22:54:35 +00:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
1998-04-28 01:25:46 +00:00
|
|
|
#include <sys/un.h>
|
1998-02-02 19:32:16 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
1999-11-17 21:12:35 +00:00
|
|
|
#ifdef __OpenBSD__
|
|
|
|
#include <util.h>
|
|
|
|
#else
|
|
|
|
#include <libutil.h>
|
|
|
|
#endif
|
1998-05-01 19:20:09 +00:00
|
|
|
#include <paths.h>
|
1998-02-02 19:32:16 +00:00
|
|
|
#include <stdio.h>
|
1998-04-30 23:53:56 +00:00
|
|
|
#include <stdlib.h>
|
1998-02-02 19:32:16 +00:00
|
|
|
#include <string.h>
|
1998-05-02 21:57:50 +00:00
|
|
|
#include <sys/uio.h>
|
1998-05-25 02:22:38 +00:00
|
|
|
#include <sys/wait.h>
|
1998-02-02 19:32:16 +00:00
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "layer.h"
|
1998-06-15 19:06:25 +00:00
|
|
|
#include "defs.h"
|
1998-02-02 19:32:16 +00:00
|
|
|
#include "command.h"
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "id.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "fsm.h"
|
|
|
|
#include "iplist.h"
|
1998-03-13 00:44:26 +00:00
|
|
|
#include "lqr.h"
|
1998-02-07 20:50:08 +00:00
|
|
|
#include "hdlc.h"
|
1998-02-02 19:32:16 +00:00
|
|
|
#include "throughput.h"
|
1998-03-16 22:54:35 +00:00
|
|
|
#include "slcompress.h"
|
2001-08-14 16:05:52 +00:00
|
|
|
#include "ncpaddr.h"
|
|
|
|
#include "ip.h"
|
1998-02-02 19:32:16 +00:00
|
|
|
#include "ipcp.h"
|
1998-03-16 22:52:54 +00:00
|
|
|
#include "filter.h"
|
1998-03-20 19:48:28 +00:00
|
|
|
#include "descriptor.h"
|
1998-02-02 19:32:16 +00:00
|
|
|
#include "route.h"
|
|
|
|
#include "lcp.h"
|
|
|
|
#include "ccp.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "link.h"
|
|
|
|
#include "mp.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-02-07 20:50:08 +00:00
|
|
|
#include "async.h"
|
|
|
|
#include "physical.h"
|
|
|
|
#include "auth.h"
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "proto.h"
|
1998-02-07 20:50:08 +00:00
|
|
|
#include "chap.h"
|
|
|
|
#include "tun.h"
|
1998-02-10 03:23:50 +00:00
|
|
|
#include "prompt.h"
|
1998-02-16 00:01:12 +00:00
|
|
|
#include "chat.h"
|
1998-08-07 18:42:51 +00:00
|
|
|
#include "cbcp.h"
|
1998-02-16 00:01:12 +00:00
|
|
|
#include "datalink.h"
|
1998-10-22 02:32:50 +00:00
|
|
|
#include "iface.h"
|
2001-01-26 01:41:34 +00:00
|
|
|
#include "server.h"
|
2001-08-15 13:53:38 +00:00
|
|
|
#include "probe.h"
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
2001-02-04 01:08:24 +00:00
|
|
|
#include "mppe.h"
|
2001-04-05 02:23:48 +00:00
|
|
|
#endif
|
1998-02-07 20:50:08 +00:00
|
|
|
|
2000-08-15 10:25:42 +00:00
|
|
|
#define SCATTER_SEGMENTS 7 /* version, datalink, name, physical,
|
|
|
|
throughput, throughput, device */
|
1999-11-06 22:50:59 +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
|
|
|
#define SEND_MAXFD 3 /* Max file descriptors passed through
|
|
|
|
the local domain socket */
|
1998-05-02 21:57:50 +00:00
|
|
|
|
1998-05-21 01:13:32 +00:00
|
|
|
static int bundle_RemainingIdleTime(struct bundle *);
|
|
|
|
|
1999-12-27 11:54:57 +00:00
|
|
|
static const char * const PhaseNames[] = {
|
1998-02-07 20:50:08 +00:00
|
|
|
"Dead", "Establish", "Authenticate", "Network", "Terminate"
|
|
|
|
};
|
1998-02-02 19:32:16 +00:00
|
|
|
|
1998-02-07 20:50:08 +00:00
|
|
|
const char *
|
|
|
|
bundle_PhaseName(struct bundle *bundle)
|
1998-02-02 19:32:16 +00:00
|
|
|
{
|
1998-02-07 20:50:08 +00:00
|
|
|
return bundle->phase <= PHASE_TERMINATE ?
|
|
|
|
PhaseNames[bundle->phase] : "unknown";
|
|
|
|
}
|
1998-02-02 19:32:16 +00:00
|
|
|
|
1998-02-07 20:50:08 +00:00
|
|
|
void
|
1998-03-13 00:44:33 +00:00
|
|
|
bundle_NewPhase(struct bundle *bundle, u_int new)
|
1998-02-07 20:50:08 +00:00
|
|
|
{
|
1998-02-17 19:28:01 +00:00
|
|
|
if (new == bundle->phase)
|
|
|
|
return;
|
|
|
|
|
1998-03-01 01:07:49 +00:00
|
|
|
if (new <= PHASE_TERMINATE)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "bundle: %s\n", PhaseNames[new]);
|
1998-02-07 20:50:08 +00:00
|
|
|
|
|
|
|
switch (new) {
|
|
|
|
case PHASE_DEAD:
|
|
|
|
bundle->phase = new;
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
2001-02-04 01:08:24 +00:00
|
|
|
MPPE_MasterKeyValid = 0;
|
2001-02-04 01:20:33 +00:00
|
|
|
#endif
|
2001-02-04 01:08:24 +00:00
|
|
|
log_DisplayPrompts();
|
1998-02-07 20:50:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PHASE_ESTABLISH:
|
|
|
|
bundle->phase = new;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHASE_AUTHENTICATE:
|
1998-03-01 01:07:49 +00:00
|
|
|
bundle->phase = new;
|
1998-05-23 22:24:50 +00:00
|
|
|
log_DisplayPrompts();
|
1998-02-07 20:50:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PHASE_NETWORK:
|
2001-08-14 16:05:52 +00:00
|
|
|
if (ncp_fsmStart(&bundle->ncp, bundle)) {
|
|
|
|
bundle->phase = new;
|
|
|
|
log_DisplayPrompts();
|
|
|
|
} else {
|
|
|
|
log_Printf(LogPHASE, "bundle: All NCPs are disabled\n");
|
|
|
|
bundle_Close(bundle, NULL, CLOSE_STAYDOWN);
|
|
|
|
}
|
1998-04-23 21:50:13 +00:00
|
|
|
break;
|
1998-02-07 20:50:08 +00:00
|
|
|
|
|
|
|
case PHASE_TERMINATE:
|
|
|
|
bundle->phase = new;
|
1998-04-23 21:50:13 +00:00
|
|
|
mp_Down(&bundle->ncp.mp);
|
1998-05-23 22:24:50 +00:00
|
|
|
log_DisplayPrompts();
|
1998-02-07 20:50:08 +00:00
|
|
|
break;
|
1998-02-02 19:32:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-02-27 01:22:39 +00:00
|
|
|
static void
|
|
|
|
bundle_LayerStart(void *v, struct fsm *fp)
|
1998-02-02 19:32:16 +00:00
|
|
|
{
|
1998-02-16 00:01:12 +00:00
|
|
|
/* The given FSM is about to start up ! */
|
1998-02-02 19:32:16 +00:00
|
|
|
}
|
|
|
|
|
1998-03-25 18:38:59 +00:00
|
|
|
|
2000-04-07 23:46:14 +00:00
|
|
|
void
|
1998-03-25 18:38:59 +00:00
|
|
|
bundle_Notify(struct bundle *bundle, char c)
|
|
|
|
{
|
|
|
|
if (bundle->notify.fd != -1) {
|
2000-04-07 23:46:14 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = write(bundle->notify.fd, &c, 1);
|
|
|
|
if (c != EX_REDIAL && c != EX_RECONNECT) {
|
|
|
|
if (ret == 1)
|
|
|
|
log_Printf(LogCHAT, "Parent notified of %s\n",
|
|
|
|
c == EX_NORMAL ? "success" : "failure");
|
|
|
|
else
|
|
|
|
log_Printf(LogERROR, "Failed to notify parent of success\n");
|
|
|
|
close(bundle->notify.fd);
|
|
|
|
bundle->notify.fd = -1;
|
|
|
|
} else if (ret == 1)
|
|
|
|
log_Printf(LogCHAT, "Parent notified of %s\n", ex_desc(c));
|
1998-03-25 18:38:59 +00:00
|
|
|
else
|
2000-04-07 23:46:14 +00:00
|
|
|
log_Printf(LogERROR, "Failed to notify parent of %s\n", ex_desc(c));
|
1998-03-25 18:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
|
1998-08-25 17:48:43 +00:00
|
|
|
static void
|
|
|
|
bundle_ClearQueues(void *v)
|
|
|
|
{
|
|
|
|
struct bundle *bundle = (struct bundle *)v;
|
|
|
|
struct datalink *dl;
|
|
|
|
|
|
|
|
log_Printf(LogPHASE, "Clearing choked output queue\n");
|
|
|
|
timer_Stop(&bundle->choked.timer);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Emergency time:
|
|
|
|
*
|
|
|
|
* We've had a full queue for PACKET_DEL_SECS seconds without being
|
|
|
|
* able to get rid of any of the packets. We've probably given up
|
|
|
|
* on the redials at this point, and the queued data has almost
|
|
|
|
* definitely been timed out by the layer above. As this is preventing
|
|
|
|
* us from reading the TUN_NAME device (we don't want to buffer stuff
|
|
|
|
* indefinitely), we may as well nuke this data and start with a clean
|
|
|
|
* slate !
|
|
|
|
*
|
|
|
|
* Unfortunately, this has the side effect of shafting any compression
|
|
|
|
* dictionaries in use (causing the relevant RESET_REQ/RESET_ACK).
|
|
|
|
*/
|
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
ncp_DeleteQueues(&bundle->ncp);
|
1998-08-25 17:48:43 +00:00
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
physical_DeleteQueue(dl->physical);
|
|
|
|
}
|
|
|
|
|
1998-06-12 17:45:10 +00:00
|
|
|
static void
|
|
|
|
bundle_LinkAdded(struct bundle *bundle, struct datalink *dl)
|
|
|
|
{
|
|
|
|
bundle->phys_type.all |= dl->physical->type;
|
|
|
|
if (dl->state == DATALINK_OPEN)
|
|
|
|
bundle->phys_type.open |= dl->physical->type;
|
|
|
|
|
2002-05-07 10:06:54 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL))
|
|
|
|
!= bundle->phys_type.open && bundle->session.timer.state == TIMER_STOPPED)
|
|
|
|
if (bundle->radius.sessiontime)
|
|
|
|
bundle_StartSessionTimer(bundle, 0);
|
|
|
|
#endif
|
|
|
|
|
1998-06-12 17:45:10 +00:00
|
|
|
if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL))
|
|
|
|
!= bundle->phys_type.open && bundle->idle.timer.state == TIMER_STOPPED)
|
|
|
|
/* We may need to start our idle timer */
|
2000-07-11 22:11:36 +00:00
|
|
|
bundle_StartIdleTimer(bundle, 0);
|
1998-06-12 17:45:10 +00:00
|
|
|
}
|
|
|
|
|
1998-08-07 18:42:51 +00:00
|
|
|
void
|
1998-06-12 17:45:10 +00:00
|
|
|
bundle_LinksRemoved(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
struct datalink *dl;
|
|
|
|
|
|
|
|
bundle->phys_type.all = bundle->phys_type.open = 0;
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
bundle_LinkAdded(bundle, dl);
|
|
|
|
|
1999-08-05 10:32:16 +00:00
|
|
|
bundle_CalculateBandwidth(bundle);
|
|
|
|
mp_CheckAutoloadTimer(&bundle->ncp.mp);
|
|
|
|
|
1998-06-12 17:45:10 +00:00
|
|
|
if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL))
|
2002-05-07 10:06:54 +00:00
|
|
|
== bundle->phys_type.open) {
|
|
|
|
#ifndef NORADIUS
|
|
|
|
if (bundle->radius.sessiontime)
|
|
|
|
bundle_StopSessionTimer(bundle);
|
|
|
|
#endif
|
1998-06-12 17:45:10 +00:00
|
|
|
bundle_StopIdleTimer(bundle);
|
2002-05-07 10:06:54 +00:00
|
|
|
}
|
1998-06-12 17:45:10 +00:00
|
|
|
}
|
1998-05-21 01:13:32 +00:00
|
|
|
|
1998-02-27 01:22:39 +00:00
|
|
|
static void
|
1998-04-30 23:53:56 +00:00
|
|
|
bundle_LayerUp(void *v, struct fsm *fp)
|
1998-02-02 19:32:16 +00:00
|
|
|
{
|
1998-02-16 00:01:12 +00:00
|
|
|
/*
|
|
|
|
* The given fsm is now up
|
1999-08-05 10:32:16 +00:00
|
|
|
* If it's an LCP, adjust our phys_mode.open value and check the
|
|
|
|
* autoload timer.
|
|
|
|
* If it's the first NCP, calculate our bandwidth
|
1999-08-17 17:22:46 +00:00
|
|
|
* If it's the first NCP, set our ``upat'' time
|
1998-04-03 19:21:56 +00:00
|
|
|
* If it's the first NCP, start the idle timer.
|
1999-08-05 10:32:16 +00:00
|
|
|
* If it's an NCP, tell our -background parent to go away.
|
|
|
|
* If it's the first NCP, start the autoload timer
|
1998-02-16 00:01:12 +00:00
|
|
|
*/
|
1998-04-30 23:53:56 +00:00
|
|
|
struct bundle *bundle = (struct bundle *)v;
|
1998-02-27 01:22:39 +00:00
|
|
|
|
1998-03-13 00:44:33 +00:00
|
|
|
if (fp->proto == PROTO_LCP) {
|
1998-06-12 17:45:10 +00:00
|
|
|
struct physical *p = link2physical(fp->link);
|
|
|
|
|
|
|
|
bundle_LinkAdded(bundle, p->dl);
|
1999-08-05 10:32:16 +00:00
|
|
|
mp_CheckAutoloadTimer(&bundle->ncp.mp);
|
2001-08-14 16:05:52 +00:00
|
|
|
} else if (isncp(fp->proto)) {
|
|
|
|
if (ncp_LayersOpen(&fp->bundle->ncp) == 1) {
|
|
|
|
bundle_CalculateBandwidth(fp->bundle);
|
|
|
|
time(&bundle->upat);
|
2002-05-07 10:06:54 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
if (bundle->radius.sessiontime)
|
|
|
|
bundle_StartSessionTimer(bundle, 0);
|
|
|
|
#endif
|
2001-08-14 16:05:52 +00:00
|
|
|
bundle_StartIdleTimer(bundle, 0);
|
|
|
|
mp_CheckAutoloadTimer(&fp->bundle->ncp.mp);
|
|
|
|
}
|
1998-03-25 18:38:59 +00:00
|
|
|
bundle_Notify(bundle, EX_NORMAL);
|
2001-07-03 22:20:19 +00:00
|
|
|
} else if (fp->proto == PROTO_CCP)
|
|
|
|
bundle_CalculateBandwidth(fp->bundle); /* Against ccp_MTUOverhead */
|
1998-02-02 19:32:16 +00:00
|
|
|
}
|
|
|
|
|
1998-02-27 01:22:39 +00:00
|
|
|
static void
|
|
|
|
bundle_LayerDown(void *v, struct fsm *fp)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The given FSM has been told to come down.
|
1998-03-09 19:26:41 +00:00
|
|
|
* If it's our last NCP, stop the idle timer.
|
1999-08-17 17:22:46 +00:00
|
|
|
* If it's our last NCP, clear our ``upat'' value.
|
1999-08-05 10:32:16 +00:00
|
|
|
* If it's our last NCP, stop the autoload timer
|
1998-06-12 17:45:10 +00:00
|
|
|
* If it's an LCP, adjust our phys_type.open value and any timers.
|
1998-05-23 17:05:28 +00:00
|
|
|
* If it's an LCP and we're in multilink mode, adjust our tun
|
2000-04-06 10:03:48 +00:00
|
|
|
* If it's the last LCP, down all NCPs
|
1998-05-23 17:05:28 +00:00
|
|
|
* speed and make sure our minimum sequence number is adjusted.
|
1998-02-27 01:22:39 +00:00
|
|
|
*/
|
1998-03-09 19:26:41 +00:00
|
|
|
|
|
|
|
struct bundle *bundle = (struct bundle *)v;
|
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (isncp(fp->proto)) {
|
|
|
|
if (ncp_LayersOpen(&fp->bundle->ncp) == 0) {
|
2002-05-07 10:06:54 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
if (bundle->radius.sessiontime)
|
|
|
|
bundle_StopSessionTimer(bundle);
|
|
|
|
#endif
|
2001-08-14 16:05:52 +00:00
|
|
|
bundle_StopIdleTimer(bundle);
|
|
|
|
bundle->upat = 0;
|
|
|
|
mp_StopAutoloadTimer(&bundle->ncp.mp);
|
|
|
|
}
|
1999-08-05 10:32:16 +00:00
|
|
|
} else if (fp->proto == PROTO_LCP) {
|
2000-04-06 10:03:48 +00:00
|
|
|
struct datalink *dl;
|
|
|
|
struct datalink *lost;
|
|
|
|
int others_active;
|
|
|
|
|
1998-06-12 17:45:10 +00:00
|
|
|
bundle_LinksRemoved(bundle); /* adjust timers & phys_type values */
|
1998-04-03 19:21:56 +00:00
|
|
|
|
2000-04-06 10:03:48 +00:00
|
|
|
lost = NULL;
|
|
|
|
others_active = 0;
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next) {
|
|
|
|
if (fp == &dl->physical->link.lcp.fsm)
|
|
|
|
lost = dl;
|
|
|
|
else if (dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP)
|
|
|
|
others_active++;
|
|
|
|
}
|
1998-05-23 17:05:28 +00:00
|
|
|
|
2000-04-06 10:03:48 +00:00
|
|
|
if (bundle->ncp.mp.active) {
|
1999-08-05 10:32:16 +00:00
|
|
|
bundle_CalculateBandwidth(bundle);
|
1998-05-23 17:05:28 +00:00
|
|
|
|
1998-06-12 17:45:10 +00:00
|
|
|
if (lost)
|
|
|
|
mp_LinkLost(&bundle->ncp.mp, lost);
|
|
|
|
else
|
1998-06-16 19:40:42 +00:00
|
|
|
log_Printf(LogALERT, "Oops, lost an unrecognised datalink (%s) !\n",
|
1998-06-12 17:45:10 +00:00
|
|
|
fp->link->name);
|
|
|
|
}
|
2000-04-06 10:03:48 +00:00
|
|
|
|
2002-03-30 12:52:55 +00:00
|
|
|
if (!others_active) {
|
2000-04-06 10:03:48 +00:00
|
|
|
/* Down the NCPs. We don't expect to get fsm_Close()d ourself ! */
|
2001-08-14 16:05:52 +00:00
|
|
|
ncp2initial(&bundle->ncp);
|
2002-03-30 12:52:55 +00:00
|
|
|
mp_Down(&bundle->ncp.mp);
|
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
1998-02-27 01:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bundle_LayerFinish(void *v, struct fsm *fp)
|
|
|
|
{
|
|
|
|
/* The given fsm is now down (fp cannot be NULL)
|
|
|
|
*
|
1998-05-01 19:26:12 +00:00
|
|
|
* If it's the last NCP, fsm_Close all LCPs
|
2002-03-30 12:52:55 +00:00
|
|
|
* If it's the last NCP, bring any MP layer down
|
1998-02-27 01:22:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct bundle *bundle = (struct bundle *)v;
|
1998-04-03 19:21:56 +00:00
|
|
|
struct datalink *dl;
|
1998-02-27 01:22:39 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (isncp(fp->proto) && !ncp_LayersUnfinished(&bundle->ncp)) {
|
1998-04-16 21:19:05 +00:00
|
|
|
if (bundle_Phase(bundle) != PHASE_DEAD)
|
|
|
|
bundle_NewPhase(bundle, PHASE_TERMINATE);
|
1998-04-03 19:21:56 +00:00
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
2000-04-06 10:03:48 +00:00
|
|
|
if (dl->state == DATALINK_OPEN)
|
|
|
|
datalink_Close(dl, CLOSE_STAYDOWN);
|
1998-06-20 00:19:42 +00:00
|
|
|
fsm2initial(fp);
|
2002-03-30 12:52:55 +00:00
|
|
|
mp_Down(&bundle->ncp.mp);
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
1998-02-27 01:22:39 +00:00
|
|
|
}
|
|
|
|
|
1998-02-02 19:32:16 +00:00
|
|
|
void
|
1998-06-15 19:05:27 +00:00
|
|
|
bundle_Close(struct bundle *bundle, const char *name, int how)
|
1998-02-02 19:32:16 +00:00
|
|
|
{
|
1998-02-07 20:50:08 +00:00
|
|
|
/*
|
1998-02-16 00:01:12 +00:00
|
|
|
* Please close the given datalink.
|
1998-05-01 19:26:12 +00:00
|
|
|
* If name == NULL or name is the last datalink, fsm_Close all NCPs
|
1998-04-30 23:53:56 +00:00
|
|
|
* (except our MP)
|
1998-04-03 19:21:56 +00:00
|
|
|
* If it isn't the last datalink, just Close that datalink.
|
1998-02-07 20:50:08 +00:00
|
|
|
*/
|
1998-02-02 19:32:16 +00:00
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
struct datalink *dl, *this_dl;
|
|
|
|
int others_active;
|
1998-02-16 00:01:12 +00:00
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
others_active = 0;
|
|
|
|
this_dl = NULL;
|
|
|
|
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next) {
|
|
|
|
if (name && !strcasecmp(name, dl->name))
|
|
|
|
this_dl = dl;
|
|
|
|
if (name == NULL || this_dl == dl) {
|
1998-06-15 19:05:27 +00:00
|
|
|
switch (how) {
|
|
|
|
case CLOSE_LCP:
|
|
|
|
datalink_DontHangup(dl);
|
2001-02-04 01:08:22 +00:00
|
|
|
break;
|
1998-06-15 19:05:27 +00:00
|
|
|
case CLOSE_STAYDOWN:
|
|
|
|
datalink_StayDown(dl);
|
|
|
|
break;
|
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
} else if (dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP)
|
|
|
|
others_active++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name && this_dl == NULL) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: Invalid datalink name\n", name);
|
1998-04-03 19:21:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!others_active) {
|
2002-05-07 10:06:54 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
if (bundle->radius.sessiontime)
|
|
|
|
bundle_StopSessionTimer(bundle);
|
|
|
|
#endif
|
1998-05-21 01:13:32 +00:00
|
|
|
bundle_StopIdleTimer(bundle);
|
2001-08-14 16:05:52 +00:00
|
|
|
if (ncp_LayersUnfinished(&bundle->ncp))
|
|
|
|
ncp_Close(&bundle->ncp);
|
1998-04-03 19:21:56 +00:00
|
|
|
else {
|
2001-08-14 16:05:52 +00:00
|
|
|
ncp2initial(&bundle->ncp);
|
2002-03-30 12:52:55 +00:00
|
|
|
mp_Down(&bundle->ncp.mp);
|
1998-04-03 19:21:56 +00:00
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
1998-06-15 19:05:27 +00:00
|
|
|
datalink_Close(dl, how);
|
1998-03-02 17:25:30 +00:00
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
} else if (this_dl && this_dl->state != DATALINK_CLOSED &&
|
|
|
|
this_dl->state != DATALINK_HANGUP)
|
1998-06-15 19:05:27 +00:00
|
|
|
datalink_Close(this_dl, how);
|
1998-02-02 19:32:16 +00:00
|
|
|
}
|
|
|
|
|
1998-05-06 18:50:12 +00:00
|
|
|
void
|
1998-06-16 19:40:28 +00:00
|
|
|
bundle_Down(struct bundle *bundle, int how)
|
1998-05-06 18:50:12 +00:00
|
|
|
{
|
|
|
|
struct datalink *dl;
|
|
|
|
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
1998-06-16 19:40:28 +00:00
|
|
|
datalink_Down(dl, how);
|
1998-05-06 18:50:12 +00:00
|
|
|
}
|
|
|
|
|
1998-03-20 19:48:28 +00:00
|
|
|
static int
|
2000-03-14 01:46:09 +00:00
|
|
|
bundle_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
|
1998-03-20 19:48:28 +00:00
|
|
|
{
|
|
|
|
struct bundle *bundle = descriptor2bundle(d);
|
|
|
|
struct datalink *dl;
|
1999-12-20 20:29:47 +00:00
|
|
|
int result, nlinks;
|
2000-06-11 02:30:51 +00:00
|
|
|
u_short ifqueue;
|
1999-12-20 20:29:47 +00:00
|
|
|
size_t queued;
|
1998-03-20 19:48:28 +00:00
|
|
|
|
|
|
|
result = 0;
|
|
|
|
|
1998-05-06 18:49:45 +00:00
|
|
|
/* If there are aren't many packets queued, look for some more. */
|
1998-05-21 01:13:32 +00:00
|
|
|
for (nlinks = 0, dl = bundle->links; dl; dl = dl->next)
|
|
|
|
nlinks++;
|
|
|
|
|
|
|
|
if (nlinks) {
|
2001-08-14 16:05:52 +00:00
|
|
|
queued = r ? ncp_FillPhysicalQueues(&bundle->ncp, bundle) :
|
|
|
|
ncp_QueueLen(&bundle->ncp);
|
1998-05-21 01:13:32 +00:00
|
|
|
|
1998-06-12 17:45:10 +00:00
|
|
|
if (r && (bundle->phase == PHASE_NETWORK ||
|
|
|
|
bundle->phys_type.all & PHYS_AUTO)) {
|
1998-05-21 01:13:32 +00:00
|
|
|
/* enough surplus so that we can tell if we're getting swamped */
|
2000-06-11 02:30:51 +00:00
|
|
|
ifqueue = nlinks > bundle->cfg.ifqueue ? nlinks : bundle->cfg.ifqueue;
|
|
|
|
if (queued < ifqueue) {
|
1998-05-21 01:13:32 +00:00
|
|
|
/* Not enough - select() for more */
|
1998-08-25 17:48:43 +00:00
|
|
|
if (bundle->choked.timer.state == TIMER_RUNNING)
|
|
|
|
timer_Stop(&bundle->choked.timer); /* Not needed any more */
|
1998-05-21 01:13:32 +00:00
|
|
|
FD_SET(bundle->dev.fd, r);
|
|
|
|
if (*n < bundle->dev.fd + 1)
|
|
|
|
*n = bundle->dev.fd + 1;
|
1998-05-28 23:17:51 +00:00
|
|
|
log_Printf(LogTIMER, "%s: fdset(r) %d\n", TUN_NAME, bundle->dev.fd);
|
1998-05-21 01:13:32 +00:00
|
|
|
result++;
|
1998-08-25 17:48:43 +00:00
|
|
|
} else if (bundle->choked.timer.state == TIMER_STOPPED) {
|
|
|
|
bundle->choked.timer.func = bundle_ClearQueues;
|
|
|
|
bundle->choked.timer.name = "output choke";
|
|
|
|
bundle->choked.timer.load = bundle->cfg.choked.timeout * SECTICKS;
|
|
|
|
bundle->choked.timer.arg = bundle;
|
|
|
|
timer_Start(&bundle->choked.timer);
|
1998-05-21 01:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
1998-05-06 18:49:45 +00:00
|
|
|
}
|
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
result += descriptor_UpdateSet(&bundle->radius.desc, r, w, e, n);
|
|
|
|
#endif
|
|
|
|
|
1998-06-07 00:16:37 +00:00
|
|
|
/* Which links need a select() ? */
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
result += descriptor_UpdateSet(&dl->desc, r, w, e, n);
|
|
|
|
|
1998-05-15 18:21:45 +00:00
|
|
|
/*
|
|
|
|
* This *MUST* be called after the datalink UpdateSet()s as it
|
1998-05-21 01:13:32 +00:00
|
|
|
* might be ``holding'' one of the datalinks (death-row) and
|
2000-03-14 01:47:07 +00:00
|
|
|
* wants to be able to de-select() it from the descriptor set.
|
1998-05-15 18:21:45 +00:00
|
|
|
*/
|
1998-05-23 22:24:50 +00:00
|
|
|
result += descriptor_UpdateSet(&bundle->ncp.mp.server.desc, r, w, e, n);
|
1998-05-15 18:21:45 +00:00
|
|
|
|
1998-03-20 19:48:28 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-03-14 01:46:09 +00:00
|
|
|
bundle_IsSet(struct fdescriptor *d, const fd_set *fdset)
|
1998-03-20 19:48:28 +00:00
|
|
|
{
|
|
|
|
struct bundle *bundle = descriptor2bundle(d);
|
|
|
|
struct datalink *dl;
|
|
|
|
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (descriptor_IsSet(&dl->desc, fdset))
|
|
|
|
return 1;
|
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
if (descriptor_IsSet(&bundle->radius.desc, fdset))
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
|
1998-05-17 10:16:14 +00:00
|
|
|
if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset))
|
|
|
|
return 1;
|
|
|
|
|
1998-05-06 23:50:25 +00:00
|
|
|
return FD_ISSET(bundle->dev.fd, fdset);
|
1998-03-20 19:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-03-14 01:46:09 +00:00
|
|
|
bundle_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
|
1998-03-20 19:48:28 +00:00
|
|
|
const fd_set *fdset)
|
|
|
|
{
|
|
|
|
struct datalink *dl;
|
2000-07-11 22:11:36 +00:00
|
|
|
unsigned secs;
|
2001-08-14 16:05:52 +00:00
|
|
|
u_int32_t af;
|
1998-03-20 19:48:28 +00:00
|
|
|
|
1998-05-15 18:21:45 +00:00
|
|
|
if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset))
|
|
|
|
descriptor_Read(&bundle->ncp.mp.server.desc, bundle, fdset);
|
|
|
|
|
1998-03-20 19:48:28 +00:00
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (descriptor_IsSet(&dl->desc, fdset))
|
|
|
|
descriptor_Read(&dl->desc, bundle, fdset);
|
1998-04-03 19:26:02 +00:00
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
if (descriptor_IsSet(&bundle->radius.desc, fdset))
|
|
|
|
descriptor_Read(&bundle->radius.desc, bundle, fdset);
|
|
|
|
#endif
|
|
|
|
|
1998-05-06 23:50:25 +00:00
|
|
|
if (FD_ISSET(bundle->dev.fd, fdset)) {
|
1998-05-06 18:49:45 +00:00
|
|
|
struct tun_data tun;
|
|
|
|
int n, pri;
|
2002-05-04 21:47:43 +00:00
|
|
|
u_char *data;
|
2000-01-23 01:48:19 +00:00
|
|
|
size_t sz;
|
|
|
|
|
|
|
|
if (bundle->dev.header) {
|
2002-05-04 21:47:43 +00:00
|
|
|
data = (u_char *)&tun;
|
2000-01-23 01:48:19 +00:00
|
|
|
sz = sizeof tun;
|
|
|
|
} else {
|
|
|
|
data = tun.data;
|
|
|
|
sz = sizeof tun.data;
|
|
|
|
}
|
1998-05-06 18:49:45 +00:00
|
|
|
|
|
|
|
/* something to read from tun */
|
2000-01-23 01:48:19 +00:00
|
|
|
|
|
|
|
n = read(bundle->dev.fd, data, sz);
|
1998-05-06 18:49:45 +00:00
|
|
|
if (n < 0) {
|
2000-01-23 01:48:19 +00:00
|
|
|
log_Printf(LogWARN, "%s: read: %s\n", bundle->dev.Name, strerror(errno));
|
1998-05-06 18:49:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-01-23 01:48:19 +00:00
|
|
|
|
|
|
|
if (bundle->dev.header) {
|
|
|
|
n -= sz - sizeof tun.data;
|
|
|
|
if (n <= 0) {
|
|
|
|
log_Printf(LogERROR, "%s: read: Got only %d bytes of data !\n",
|
|
|
|
bundle->dev.Name, n);
|
|
|
|
return;
|
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
af = ntohl(tun.header.family);
|
|
|
|
#ifndef NOINET6
|
2001-08-18 19:07:13 +00:00
|
|
|
if (af != AF_INET && af != AF_INET6)
|
2001-08-14 16:05:52 +00:00
|
|
|
#else
|
|
|
|
if (af != AF_INET)
|
|
|
|
#endif
|
2000-01-23 01:48:19 +00:00
|
|
|
/* XXX: Should be maintaining drop/family counts ! */
|
|
|
|
return;
|
2001-08-14 16:05:52 +00:00
|
|
|
} else
|
|
|
|
af = AF_INET;
|
1998-05-06 18:49:45 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (af == AF_INET && ((struct ip *)tun.data)->ip_dst.s_addr ==
|
1998-05-06 18:49:45 +00:00
|
|
|
bundle->ncp.ipcp.my_ip.s_addr) {
|
|
|
|
/* we've been asked to send something addressed *to* us :( */
|
|
|
|
if (Enabled(bundle, OPT_LOOPBACK)) {
|
2001-08-14 16:05:52 +00:00
|
|
|
pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.in,
|
|
|
|
NULL, NULL);
|
1998-05-06 18:49:45 +00:00
|
|
|
if (pri >= 0) {
|
2000-01-23 01:48:19 +00:00
|
|
|
n += sz - sizeof tun.data;
|
|
|
|
write(bundle->dev.fd, data, n);
|
1998-05-06 18:49:45 +00:00
|
|
|
log_Printf(LogDEBUG, "Looped back packet addressed to myself\n");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
log_Printf(LogDEBUG, "Oops - forwarding packet addressed to myself\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-08-14 16:05:52 +00:00
|
|
|
* Process on-demand dialup. Output packets are queued within the tunnel
|
|
|
|
* device until the appropriate NCP is opened.
|
1998-05-06 18:49:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2001-08-14 16:05:52 +00:00
|
|
|
pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.dial,
|
|
|
|
NULL, NULL);
|
2000-07-11 09:26:02 +00:00
|
|
|
if (pri >= 0)
|
1998-07-29 18:21:17 +00:00
|
|
|
bundle_Open(bundle, NULL, PHYS_AUTO, 0);
|
1998-05-06 18:49:45 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-07-11 22:11:36 +00:00
|
|
|
secs = 0;
|
2001-08-14 16:05:52 +00:00
|
|
|
pri = PacketCheck(bundle, af, tun.data, n, &bundle->filter.out,
|
|
|
|
NULL, &secs);
|
2000-07-11 22:11:36 +00:00
|
|
|
if (pri >= 0) {
|
|
|
|
/* Prepend the number of seconds timeout given in the filter */
|
|
|
|
tun.header.timeout = secs;
|
2001-08-14 16:05:52 +00:00
|
|
|
ncp_Enqueue(&bundle->ncp, af, pri, (char *)&tun, n + sizeof tun.header);
|
2000-07-11 22:11:36 +00:00
|
|
|
}
|
1998-05-06 18:49:45 +00:00
|
|
|
}
|
1998-03-20 19:48:28 +00:00
|
|
|
}
|
|
|
|
|
1998-06-24 19:33:36 +00:00
|
|
|
static int
|
2000-03-14 01:46:09 +00:00
|
|
|
bundle_DescriptorWrite(struct fdescriptor *d, struct bundle *bundle,
|
1998-03-20 19:48:28 +00:00
|
|
|
const fd_set *fdset)
|
|
|
|
{
|
|
|
|
struct datalink *dl;
|
1998-06-24 19:33:36 +00:00
|
|
|
int result = 0;
|
1998-03-20 19:48:28 +00:00
|
|
|
|
1998-05-15 18:21:45 +00:00
|
|
|
/* This is not actually necessary as struct mpserver doesn't Write() */
|
|
|
|
if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset))
|
2002-03-30 12:30:09 +00:00
|
|
|
if (descriptor_Write(&bundle->ncp.mp.server.desc, bundle, fdset) == 1)
|
|
|
|
result++;
|
1998-05-15 18:21:45 +00:00
|
|
|
|
1998-03-20 19:48:28 +00:00
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (descriptor_IsSet(&dl->desc, fdset))
|
2002-03-30 12:30:09 +00:00
|
|
|
switch (descriptor_Write(&dl->desc, bundle, fdset)) {
|
|
|
|
case -1:
|
|
|
|
datalink_ComeDown(dl, CLOSE_NORMAL);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
result++;
|
|
|
|
}
|
1998-06-24 19:33:36 +00:00
|
|
|
|
|
|
|
return result;
|
1998-03-20 19:48:28 +00:00
|
|
|
}
|
|
|
|
|
1998-06-06 20:50:57 +00:00
|
|
|
void
|
1998-05-28 23:17:51 +00:00
|
|
|
bundle_LockTun(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
FILE *lockfile;
|
2001-03-08 23:51:50 +00:00
|
|
|
char pidfile[PATH_MAX];
|
1998-05-28 23:17:51 +00:00
|
|
|
|
|
|
|
snprintf(pidfile, sizeof pidfile, "%stun%d.pid", _PATH_VARRUN, bundle->unit);
|
|
|
|
lockfile = ID0fopen(pidfile, "w");
|
|
|
|
if (lockfile != NULL) {
|
|
|
|
fprintf(lockfile, "%d\n", (int)getpid());
|
|
|
|
fclose(lockfile);
|
|
|
|
}
|
|
|
|
#ifndef RELEASE_CRUNCH
|
|
|
|
else
|
|
|
|
log_Printf(LogERROR, "Warning: Can't create %s: %s\n",
|
|
|
|
pidfile, strerror(errno));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bundle_UnlockTun(struct bundle *bundle)
|
|
|
|
{
|
2001-03-08 23:51:50 +00:00
|
|
|
char pidfile[PATH_MAX];
|
1998-05-28 23:17:51 +00:00
|
|
|
|
|
|
|
snprintf(pidfile, sizeof pidfile, "%stun%d.pid", _PATH_VARRUN, bundle->unit);
|
|
|
|
ID0unlink(pidfile);
|
|
|
|
}
|
1998-02-02 19:32:16 +00:00
|
|
|
|
|
|
|
struct bundle *
|
1999-11-17 21:12:35 +00:00
|
|
|
bundle_Create(const char *prefix, int type, int unit)
|
1998-02-02 19:32:16 +00:00
|
|
|
{
|
|
|
|
static struct bundle bundle; /* there can be only one */
|
1999-10-19 15:21:09 +00:00
|
|
|
int enoentcount, err, minunit, maxunit;
|
1999-05-27 08:42:17 +00:00
|
|
|
const char *ifname;
|
1999-11-16 21:57:34 +00:00
|
|
|
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
1999-09-22 00:40:47 +00:00
|
|
|
int kldtried;
|
|
|
|
#endif
|
2000-01-23 01:48:19 +00:00
|
|
|
#if defined(TUNSIFMODE) || defined(TUNSLMODE) || defined(TUNSIFHEAD)
|
1999-03-25 11:37:51 +00:00
|
|
|
int iff;
|
|
|
|
#endif
|
1998-02-02 19:32:16 +00:00
|
|
|
|
1998-10-22 02:32:50 +00:00
|
|
|
if (bundle.iface != NULL) { /* Already allocated ! */
|
1998-06-16 19:40:42 +00:00
|
|
|
log_Printf(LogALERT, "bundle_Create: There's only one BUNDLE !\n");
|
1998-02-02 19:32:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-10-19 15:21:09 +00:00
|
|
|
if (unit == -1) {
|
|
|
|
minunit = 0;
|
|
|
|
maxunit = -1;
|
|
|
|
} else {
|
|
|
|
minunit = unit;
|
|
|
|
maxunit = unit + 1;
|
|
|
|
}
|
1998-02-02 19:32:16 +00:00
|
|
|
err = ENOENT;
|
|
|
|
enoentcount = 0;
|
1999-11-16 21:57:34 +00:00
|
|
|
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
1999-09-22 00:40:47 +00:00
|
|
|
kldtried = 0;
|
|
|
|
#endif
|
1999-10-19 15:21:09 +00:00
|
|
|
for (bundle.unit = minunit; bundle.unit != maxunit; bundle.unit++) {
|
1998-05-06 23:50:25 +00:00
|
|
|
snprintf(bundle.dev.Name, sizeof bundle.dev.Name, "%s%d",
|
|
|
|
prefix, bundle.unit);
|
|
|
|
bundle.dev.fd = ID0open(bundle.dev.Name, O_RDWR);
|
|
|
|
if (bundle.dev.fd >= 0)
|
1998-02-02 19:32:16 +00:00
|
|
|
break;
|
2001-02-02 01:41:26 +00:00
|
|
|
else if (errno == ENXIO || errno == ENOENT) {
|
1999-11-16 21:57:34 +00:00
|
|
|
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
|
1999-10-19 15:21:09 +00:00
|
|
|
if (bundle.unit == minunit && !kldtried++) {
|
1999-09-22 00:40:47 +00:00
|
|
|
/*
|
2002-04-15 00:14:40 +00:00
|
|
|
* Attempt to load the tunnel interface KLD if it isn't loaded
|
|
|
|
* already.
|
1999-09-22 00:40:47 +00:00
|
|
|
*/
|
2002-04-15 00:14:40 +00:00
|
|
|
if (loadmodules(LOAD_VERBOSLY, "if_tun", NULL))
|
|
|
|
bundle.unit--;
|
2002-03-30 12:30:09 +00:00
|
|
|
continue;
|
1999-09-22 00:40:47 +00:00
|
|
|
}
|
|
|
|
#endif
|
2001-03-12 12:53:53 +00:00
|
|
|
if (errno != ENOENT || ++enoentcount > 2) {
|
|
|
|
err = errno;
|
1998-04-27 01:40:38 +00:00
|
|
|
break;
|
2001-03-12 12:53:53 +00:00
|
|
|
}
|
1998-02-02 19:32:16 +00:00
|
|
|
} else
|
|
|
|
err = errno;
|
|
|
|
}
|
|
|
|
|
1998-05-06 23:50:25 +00:00
|
|
|
if (bundle.dev.fd < 0) {
|
1999-10-19 15:21:09 +00:00
|
|
|
if (unit == -1)
|
|
|
|
log_Printf(LogWARN, "No available tunnel devices found (%s)\n",
|
|
|
|
strerror(err));
|
|
|
|
else
|
|
|
|
log_Printf(LogWARN, "%s%d: %s\n", prefix, unit, strerror(err));
|
1998-02-02 19:32:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
log_SetTun(bundle.unit);
|
1998-02-02 19:32:16 +00:00
|
|
|
|
1998-10-22 02:32:50 +00:00
|
|
|
ifname = strrchr(bundle.dev.Name, '/');
|
|
|
|
if (ifname == NULL)
|
|
|
|
ifname = bundle.dev.Name;
|
1998-02-02 19:32:16 +00:00
|
|
|
else
|
1998-10-22 02:32:50 +00:00
|
|
|
ifname++;
|
|
|
|
|
|
|
|
bundle.iface = iface_Create(ifname);
|
|
|
|
if (bundle.iface == NULL) {
|
|
|
|
close(bundle.dev.fd);
|
|
|
|
return NULL;
|
|
|
|
}
|
1998-02-02 19:32:16 +00:00
|
|
|
|
1999-03-25 11:37:51 +00:00
|
|
|
#ifdef TUNSIFMODE
|
2001-08-21 11:07:58 +00:00
|
|
|
/* Make sure we're POINTOPOINT & IFF_MULTICAST */
|
|
|
|
iff = IFF_POINTOPOINT | IFF_MULTICAST;
|
1999-03-25 11:37:51 +00:00
|
|
|
if (ID0ioctl(bundle.dev.fd, TUNSIFMODE, &iff) < 0)
|
|
|
|
log_Printf(LogERROR, "bundle_Create: ioctl(TUNSIFMODE): %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
#endif
|
|
|
|
|
1999-06-22 11:31:42 +00:00
|
|
|
#ifdef TUNSLMODE
|
2000-01-23 01:48:19 +00:00
|
|
|
/* Make sure we're not prepending sockaddrs */
|
1999-06-22 11:31:42 +00:00
|
|
|
iff = 0;
|
|
|
|
if (ID0ioctl(bundle.dev.fd, TUNSLMODE, &iff) < 0)
|
|
|
|
log_Printf(LogERROR, "bundle_Create: ioctl(TUNSLMODE): %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
#endif
|
|
|
|
|
2000-01-23 01:48:19 +00:00
|
|
|
#ifdef TUNSIFHEAD
|
|
|
|
/* We want the address family please ! */
|
|
|
|
iff = 1;
|
|
|
|
if (ID0ioctl(bundle.dev.fd, TUNSIFHEAD, &iff) < 0) {
|
|
|
|
log_Printf(LogERROR, "bundle_Create: ioctl(TUNSIFHEAD): %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
bundle.dev.header = 0;
|
|
|
|
} else
|
|
|
|
bundle.dev.header = 1;
|
|
|
|
#else
|
|
|
|
#ifdef __OpenBSD__
|
|
|
|
/* Always present for OpenBSD */
|
|
|
|
bundle.dev.header = 1;
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* If TUNSIFHEAD isn't available and we're not OpenBSD, assume
|
|
|
|
* everything's AF_INET (hopefully the tun device won't pass us
|
|
|
|
* anything else !).
|
|
|
|
*/
|
|
|
|
bundle.dev.header = 0;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
1998-10-22 02:32:50 +00:00
|
|
|
log_Printf(LogPHASE, "Using interface: %s\n", ifname);
|
1998-02-02 19:32:16 +00:00
|
|
|
|
1999-08-05 10:32:16 +00:00
|
|
|
bundle.bandwidth = 0;
|
1998-02-02 19:33:02 +00:00
|
|
|
bundle.routing_seq = 0;
|
1998-03-16 22:53:15 +00:00
|
|
|
bundle.phase = PHASE_DEAD;
|
|
|
|
bundle.CleaningUp = 0;
|
1999-08-19 18:15:52 +00:00
|
|
|
bundle.NatEnabled = 0;
|
1998-02-02 19:32:16 +00:00
|
|
|
|
1998-02-27 01:22:39 +00:00
|
|
|
bundle.fsm.LayerStart = bundle_LayerStart;
|
1998-04-30 23:53:56 +00:00
|
|
|
bundle.fsm.LayerUp = bundle_LayerUp;
|
1998-02-27 01:22:39 +00:00
|
|
|
bundle.fsm.LayerDown = bundle_LayerDown;
|
|
|
|
bundle.fsm.LayerFinish = bundle_LayerFinish;
|
|
|
|
bundle.fsm.object = &bundle;
|
1998-02-02 19:32:16 +00:00
|
|
|
|
1999-08-17 17:22:46 +00:00
|
|
|
bundle.cfg.idle.timeout = NCP_IDLE_TIMEOUT;
|
|
|
|
bundle.cfg.idle.min_timeout = 0;
|
1998-04-16 00:26:21 +00:00
|
|
|
*bundle.cfg.auth.name = '\0';
|
|
|
|
*bundle.cfg.auth.key = '\0';
|
2001-08-14 16:05:52 +00:00
|
|
|
bundle.cfg.opt = OPT_IDCHECK | OPT_LOOPBACK | OPT_SROUTES | OPT_TCPMSSFIXUP |
|
2001-08-15 13:53:38 +00:00
|
|
|
OPT_THROUGHPUT | OPT_UTMP;
|
2001-08-14 16:05:52 +00:00
|
|
|
#ifndef NOINET6
|
2001-08-15 13:53:38 +00:00
|
|
|
bundle.cfg.opt |= OPT_IPCP;
|
|
|
|
if (probe.ipv6_available)
|
|
|
|
bundle.cfg.opt |= OPT_IPV6CP;
|
2001-08-14 16:05:52 +00:00
|
|
|
#endif
|
1998-04-23 03:23:03 +00:00
|
|
|
*bundle.cfg.label = '\0';
|
2000-06-11 02:30:51 +00:00
|
|
|
bundle.cfg.ifqueue = DEF_IFQUEUE;
|
1998-08-25 17:48:43 +00:00
|
|
|
bundle.cfg.choked.timeout = CHOKED_TIMEOUT;
|
1998-06-12 17:45:10 +00:00
|
|
|
bundle.phys_type.all = type;
|
|
|
|
bundle.phys_type.open = 0;
|
1999-08-17 17:22:46 +00:00
|
|
|
bundle.upat = 0;
|
1998-03-09 19:26:41 +00:00
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
bundle.links = datalink_Create("deflink", &bundle, type);
|
1998-02-16 00:01:12 +00:00
|
|
|
if (bundle.links == NULL) {
|
1998-06-16 19:40:42 +00:00
|
|
|
log_Printf(LogALERT, "Cannot create data link: %s\n", strerror(errno));
|
1998-10-22 02:32:50 +00:00
|
|
|
iface_Destroy(bundle.iface);
|
|
|
|
bundle.iface = NULL;
|
1998-05-06 23:50:25 +00:00
|
|
|
close(bundle.dev.fd);
|
1998-02-06 02:23:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-03-20 19:48:28 +00:00
|
|
|
bundle.desc.type = BUNDLE_DESCRIPTOR;
|
|
|
|
bundle.desc.UpdateSet = bundle_UpdateSet;
|
|
|
|
bundle.desc.IsSet = bundle_IsSet;
|
|
|
|
bundle.desc.Read = bundle_DescriptorRead;
|
|
|
|
bundle.desc.Write = bundle_DescriptorWrite;
|
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
ncp_Init(&bundle.ncp, &bundle);
|
1998-02-27 01:22:39 +00:00
|
|
|
|
1998-03-16 22:52:54 +00:00
|
|
|
memset(&bundle.filter, '\0', sizeof bundle.filter);
|
|
|
|
bundle.filter.in.fragok = bundle.filter.in.logok = 1;
|
|
|
|
bundle.filter.in.name = "IN";
|
|
|
|
bundle.filter.out.fragok = bundle.filter.out.logok = 1;
|
|
|
|
bundle.filter.out.name = "OUT";
|
|
|
|
bundle.filter.dial.name = "DIAL";
|
1998-04-03 19:25:07 +00:00
|
|
|
bundle.filter.dial.logok = 1;
|
1998-03-16 22:52:54 +00:00
|
|
|
bundle.filter.alive.name = "ALIVE";
|
|
|
|
bundle.filter.alive.logok = 1;
|
1999-07-27 23:44:00 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAXFILTERS; i++) {
|
|
|
|
bundle.filter.in.rule[i].f_action = A_NONE;
|
|
|
|
bundle.filter.out.rule[i].f_action = A_NONE;
|
|
|
|
bundle.filter.dial.rule[i].f_action = A_NONE;
|
|
|
|
bundle.filter.alive.rule[i].f_action = A_NONE;
|
|
|
|
}
|
|
|
|
}
|
1998-03-18 23:15:31 +00:00
|
|
|
memset(&bundle.idle.timer, '\0', sizeof bundle.idle.timer);
|
|
|
|
bundle.idle.done = 0;
|
1998-03-25 18:38:59 +00:00
|
|
|
bundle.notify.fd = -1;
|
1998-08-25 17:48:43 +00:00
|
|
|
memset(&bundle.choked.timer, '\0', sizeof bundle.choked.timer);
|
1999-01-28 01:56:34 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
radius_Init(&bundle.radius);
|
|
|
|
#endif
|
1998-03-18 23:15:31 +00:00
|
|
|
|
1998-02-27 01:22:39 +00:00
|
|
|
/* Clean out any leftover crud */
|
2001-08-14 16:05:52 +00:00
|
|
|
iface_Clear(bundle.iface, &bundle.ncp, 0, IFACE_CLEAR_ALL);
|
1998-02-27 01:22:39 +00:00
|
|
|
|
1998-05-28 23:17:51 +00:00
|
|
|
bundle_LockTun(&bundle);
|
|
|
|
|
1998-02-02 19:32:16 +00:00
|
|
|
return &bundle;
|
|
|
|
}
|
|
|
|
|
1998-02-08 19:29:45 +00:00
|
|
|
static void
|
|
|
|
bundle_DownInterface(struct bundle *bundle)
|
|
|
|
{
|
1998-05-01 19:26:12 +00:00
|
|
|
route_IfDelete(bundle, 1);
|
2001-03-28 09:45:27 +00:00
|
|
|
iface_ClearFlags(bundle->iface->name, IFF_UP);
|
1998-02-08 19:29:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_Destroy(struct bundle *bundle)
|
|
|
|
{
|
1998-02-16 00:01:12 +00:00
|
|
|
struct datalink *dl;
|
1998-04-03 19:26:02 +00:00
|
|
|
|
1998-05-15 18:21:45 +00:00
|
|
|
/*
|
2001-08-14 16:05:52 +00:00
|
|
|
* Clean up the interface. We don't really need to do the timer_Stop()s,
|
|
|
|
* mp_Down(), iface_Clear() and bundle_DownInterface() unless we're getting
|
2000-03-14 01:47:07 +00:00
|
|
|
* out under exceptional conditions such as a descriptor exception.
|
1998-05-15 18:21:45 +00:00
|
|
|
*/
|
1998-05-21 01:13:32 +00:00
|
|
|
timer_Stop(&bundle->idle.timer);
|
1998-08-25 17:48:43 +00:00
|
|
|
timer_Stop(&bundle->choked.timer);
|
1998-05-11 23:39:30 +00:00
|
|
|
mp_Down(&bundle->ncp.mp);
|
2001-08-14 16:05:52 +00:00
|
|
|
iface_Clear(bundle->iface, &bundle->ncp, 0, IFACE_CLEAR_ALL);
|
1998-05-15 18:21:45 +00:00
|
|
|
bundle_DownInterface(bundle);
|
1998-05-28 23:17:51 +00:00
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
/* Tell the radius server the bad news */
|
|
|
|
radius_Destroy(&bundle->radius);
|
|
|
|
#endif
|
|
|
|
|
1998-05-15 18:21:45 +00:00
|
|
|
/* Again, these are all DATALINK_CLOSED unless we're abending */
|
1998-02-16 00:01:12 +00:00
|
|
|
dl = bundle->links;
|
|
|
|
while (dl)
|
|
|
|
dl = datalink_Destroy(dl);
|
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
ncp_Destroy(&bundle->ncp);
|
1999-09-04 00:00:21 +00:00
|
|
|
|
1998-05-28 23:17:51 +00:00
|
|
|
close(bundle->dev.fd);
|
|
|
|
bundle_UnlockTun(bundle);
|
|
|
|
|
1998-05-15 18:21:45 +00:00
|
|
|
/* In case we never made PHASE_NETWORK */
|
1998-03-25 18:38:59 +00:00
|
|
|
bundle_Notify(bundle, EX_ERRDEAD);
|
1998-04-03 19:26:02 +00:00
|
|
|
|
1998-10-22 02:32:50 +00:00
|
|
|
iface_Destroy(bundle->iface);
|
|
|
|
bundle->iface = NULL;
|
1998-02-08 19:29:45 +00:00
|
|
|
}
|
|
|
|
|
1998-02-16 00:01:12 +00:00
|
|
|
void
|
|
|
|
bundle_LinkClosed(struct bundle *bundle, struct datalink *dl)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Our datalink has closed.
|
1998-05-15 18:21:45 +00:00
|
|
|
* CleanDatalinks() (called from DoLoop()) will remove closed
|
1999-11-28 15:50:08 +00:00
|
|
|
* BACKGROUND, FOREGROUND and DIRECT links.
|
1998-04-03 19:21:56 +00:00
|
|
|
* If it's the last data link, enter phase DEAD.
|
1998-05-15 18:21:45 +00:00
|
|
|
*
|
|
|
|
* NOTE: dl may not be in our list (bundle_SendDatalink()) !
|
1998-02-16 00:01:12 +00:00
|
|
|
*/
|
1998-02-16 19:10:03 +00:00
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
struct datalink *odl;
|
|
|
|
int other_links;
|
1998-02-16 19:10:03 +00:00
|
|
|
|
1998-08-09 15:34:11 +00:00
|
|
|
log_SetTtyCommandMode(dl);
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
other_links = 0;
|
|
|
|
for (odl = bundle->links; odl; odl = odl->next)
|
|
|
|
if (odl != dl && odl->state != DATALINK_CLOSED)
|
|
|
|
other_links++;
|
1998-02-17 01:05:47 +00:00
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
if (!other_links) {
|
1998-05-29 18:32:11 +00:00
|
|
|
if (dl->physical->type != PHYS_AUTO) /* Not in -auto mode */
|
1998-05-19 23:05:10 +00:00
|
|
|
bundle_DownInterface(bundle);
|
2001-08-14 16:05:52 +00:00
|
|
|
ncp2initial(&bundle->ncp);
|
2002-03-30 12:52:55 +00:00
|
|
|
mp_Down(&bundle->ncp.mp);
|
1998-04-03 19:21:56 +00:00
|
|
|
bundle_NewPhase(bundle, PHASE_DEAD);
|
2002-05-07 10:06:54 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
if (bundle->radius.sessiontime)
|
|
|
|
bundle_StopSessionTimer(bundle);
|
|
|
|
#endif
|
1998-05-23 22:24:50 +00:00
|
|
|
bundle_StopIdleTimer(bundle);
|
1999-08-05 10:32:16 +00:00
|
|
|
}
|
1998-02-07 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
1998-02-16 00:01:12 +00:00
|
|
|
void
|
1998-07-29 18:21:17 +00:00
|
|
|
bundle_Open(struct bundle *bundle, const char *name, int mask, int force)
|
1998-02-16 00:01:12 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Please open the given datalink, or all if name == NULL
|
|
|
|
*/
|
|
|
|
struct datalink *dl;
|
|
|
|
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (name == NULL || !strcasecmp(dl->name, name)) {
|
1998-07-29 18:21:17 +00:00
|
|
|
if ((mask & dl->physical->type) &&
|
|
|
|
(dl->state == DATALINK_CLOSED ||
|
|
|
|
(force && dl->state == DATALINK_OPENING &&
|
2000-05-26 08:26:56 +00:00
|
|
|
dl->dial.timer.state == TIMER_RUNNING) ||
|
|
|
|
dl->state == DATALINK_READY)) {
|
|
|
|
timer_Stop(&dl->dial.timer); /* We're finished with this */
|
1998-04-10 13:19:23 +00:00
|
|
|
datalink_Up(dl, 1, 1);
|
1999-08-05 10:32:16 +00:00
|
|
|
if (mask & PHYS_AUTO)
|
2000-05-26 08:26:56 +00:00
|
|
|
break; /* Only one AUTO link at a time */
|
1998-05-21 01:13:32 +00:00
|
|
|
}
|
1998-02-16 00:01:12 +00:00
|
|
|
if (name != NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct datalink *
|
|
|
|
bundle2datalink(struct bundle *bundle, const char *name)
|
|
|
|
{
|
|
|
|
struct datalink *dl;
|
|
|
|
|
|
|
|
if (name != NULL) {
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (!strcasecmp(dl->name, name))
|
|
|
|
return dl;
|
|
|
|
} else if (bundle->links && !bundle->links->next)
|
|
|
|
return bundle->links;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-02-17 19:28:01 +00:00
|
|
|
int
|
|
|
|
bundle_ShowLinks(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-24 19:16:15 +00:00
|
|
|
struct datalink *dl;
|
1999-08-05 10:32:16 +00:00
|
|
|
struct pppThroughput *t;
|
2000-08-15 10:25:42 +00:00
|
|
|
unsigned long long octets;
|
1999-08-05 10:32:16 +00:00
|
|
|
int secs;
|
1998-02-17 19:28:01 +00:00
|
|
|
|
1998-05-03 22:13:14 +00:00
|
|
|
for (dl = arg->bundle->links; dl; dl = dl->next) {
|
2000-08-15 10:25:42 +00:00
|
|
|
octets = MAX(dl->physical->link.stats.total.in.OctetsPerSecond,
|
|
|
|
dl->physical->link.stats.total.out.OctetsPerSecond);
|
|
|
|
|
1998-05-23 22:28:19 +00:00
|
|
|
prompt_Printf(arg->prompt, "Name: %s [%s, %s]",
|
|
|
|
dl->name, mode2Nam(dl->physical->type), datalink_State(dl));
|
2000-08-15 00:59:21 +00:00
|
|
|
if (dl->physical->link.stats.total.rolling && dl->state == DATALINK_OPEN)
|
1999-08-09 22:56:18 +00:00
|
|
|
prompt_Printf(arg->prompt, " bandwidth %d, %llu bps (%llu bytes/sec)",
|
1999-08-05 10:32:16 +00:00
|
|
|
dl->mp.bandwidth ? dl->mp.bandwidth :
|
|
|
|
physical_GetSpeed(dl->physical),
|
2000-08-15 10:25:42 +00:00
|
|
|
octets * 8, octets);
|
1998-05-03 22:13:14 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n");
|
|
|
|
}
|
1998-02-17 19:28:01 +00:00
|
|
|
|
2000-08-15 00:59:21 +00:00
|
|
|
t = &arg->bundle->ncp.mp.link.stats.total;
|
2000-08-15 10:25:42 +00:00
|
|
|
octets = MAX(t->in.OctetsPerSecond, t->out.OctetsPerSecond);
|
1999-08-05 10:32:16 +00:00
|
|
|
secs = t->downtime ? 0 : throughput_uptime(t);
|
|
|
|
if (secs > t->SamplePeriod)
|
|
|
|
secs = t->SamplePeriod;
|
|
|
|
if (secs)
|
1999-08-09 22:56:18 +00:00
|
|
|
prompt_Printf(arg->prompt, "Currently averaging %llu bps (%llu bytes/sec)"
|
2000-08-15 10:25:42 +00:00
|
|
|
" over the last %d secs\n", octets * 8, octets, secs);
|
1999-08-05 10:32:16 +00:00
|
|
|
|
1998-02-17 19:28:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1998-03-09 19:26:41 +00:00
|
|
|
|
1998-04-16 00:26:21 +00:00
|
|
|
static const char *
|
|
|
|
optval(struct bundle *bundle, int bit)
|
|
|
|
{
|
|
|
|
return (bundle->cfg.opt & bit) ? "enabled" : "disabled";
|
|
|
|
}
|
|
|
|
|
1998-04-11 21:50:47 +00:00
|
|
|
int
|
|
|
|
bundle_ShowStatus(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int remaining;
|
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, "Phase %s\n", bundle_PhaseName(arg->bundle));
|
1998-05-06 23:50:25 +00:00
|
|
|
prompt_Printf(arg->prompt, " Device: %s\n", arg->bundle->dev.Name);
|
1999-08-17 17:22:46 +00:00
|
|
|
prompt_Printf(arg->prompt, " Interface: %s @ %lubps",
|
1999-08-05 10:32:16 +00:00
|
|
|
arg->bundle->iface->name, arg->bundle->bandwidth);
|
1998-04-11 21:50:47 +00:00
|
|
|
|
1999-08-17 17:22:46 +00:00
|
|
|
if (arg->bundle->upat) {
|
2001-11-03 21:45:32 +00:00
|
|
|
int secs = bundle_Uptime(arg->bundle);
|
1999-08-17 17:22:46 +00:00
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, ", up time %d:%02d:%02d", secs / 3600,
|
|
|
|
(secs / 60) % 60, secs % 60);
|
|
|
|
}
|
2000-06-18 10:07:53 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n Queued: %lu of %u\n",
|
2001-08-14 16:05:52 +00:00
|
|
|
(unsigned long)ncp_QueueLen(&arg->bundle->ncp),
|
2000-06-23 09:48:26 +00:00
|
|
|
arg->bundle->cfg.ifqueue);
|
1999-08-17 17:22:46 +00:00
|
|
|
|
2000-06-11 02:30:51 +00:00
|
|
|
prompt_Printf(arg->prompt, "\nDefaults:\n");
|
2001-01-26 01:41:34 +00:00
|
|
|
prompt_Printf(arg->prompt, " Label: %s\n",
|
|
|
|
arg->bundle->cfg.label);
|
|
|
|
prompt_Printf(arg->prompt, " Auth name: %s\n",
|
1998-05-05 23:30:13 +00:00
|
|
|
arg->bundle->cfg.auth.name);
|
2001-01-26 01:41:34 +00:00
|
|
|
prompt_Printf(arg->prompt, " Diagnostic socket: ");
|
2001-01-29 01:35:06 +00:00
|
|
|
if (*server.cfg.sockname != '\0') {
|
|
|
|
prompt_Printf(arg->prompt, "%s", server.cfg.sockname);
|
|
|
|
if (server.cfg.mask != (mode_t)-1)
|
|
|
|
prompt_Printf(arg->prompt, ", mask 0%03o", (int)server.cfg.mask);
|
|
|
|
prompt_Printf(arg->prompt, "%s\n", server.fd == -1 ? " (not open)" : "");
|
|
|
|
} else if (server.cfg.port != 0)
|
2001-01-26 01:41:34 +00:00
|
|
|
prompt_Printf(arg->prompt, "TCP port %d%s\n", server.cfg.port,
|
|
|
|
server.fd == -1 ? " (not open)" : "");
|
|
|
|
else
|
|
|
|
prompt_Printf(arg->prompt, "none\n");
|
1998-05-21 01:13:32 +00:00
|
|
|
|
2001-01-26 01:41:34 +00:00
|
|
|
prompt_Printf(arg->prompt, " Choked Timer: %ds\n",
|
1998-08-25 17:48:43 +00:00
|
|
|
arg->bundle->cfg.choked.timeout);
|
1999-01-28 01:56:34 +00:00
|
|
|
|
|
|
|
#ifndef NORADIUS
|
|
|
|
radius_Show(&arg->bundle->radius, arg->prompt);
|
|
|
|
#endif
|
|
|
|
|
2001-01-26 01:41:34 +00:00
|
|
|
prompt_Printf(arg->prompt, " Idle Timer: ");
|
1999-08-17 17:22:46 +00:00
|
|
|
if (arg->bundle->cfg.idle.timeout) {
|
|
|
|
prompt_Printf(arg->prompt, "%ds", arg->bundle->cfg.idle.timeout);
|
|
|
|
if (arg->bundle->cfg.idle.min_timeout)
|
|
|
|
prompt_Printf(arg->prompt, ", min %ds",
|
|
|
|
arg->bundle->cfg.idle.min_timeout);
|
1998-04-11 21:50:47 +00:00
|
|
|
remaining = bundle_RemainingIdleTime(arg->bundle);
|
|
|
|
if (remaining != -1)
|
|
|
|
prompt_Printf(arg->prompt, " (%ds remaining)", remaining);
|
|
|
|
prompt_Printf(arg->prompt, "\n");
|
|
|
|
} else
|
|
|
|
prompt_Printf(arg->prompt, "disabled\n");
|
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
prompt_Printf(arg->prompt, " Filter Decap: %-20.20s",
|
2000-07-07 14:22:08 +00:00
|
|
|
optval(arg->bundle, OPT_FILTERDECAP));
|
2001-08-14 16:05:52 +00:00
|
|
|
prompt_Printf(arg->prompt, " ID check: %s\n",
|
1998-04-16 00:26:21 +00:00
|
|
|
optval(arg->bundle, OPT_IDCHECK));
|
2001-08-14 16:05:52 +00:00
|
|
|
prompt_Printf(arg->prompt, " Iface-Alias: %-20.20s",
|
|
|
|
optval(arg->bundle, OPT_IFACEALIAS));
|
|
|
|
#ifndef NOINET6
|
|
|
|
prompt_Printf(arg->prompt, " IPCP: %s\n",
|
|
|
|
optval(arg->bundle, OPT_IPCP));
|
|
|
|
prompt_Printf(arg->prompt, " IPV6CP: %-20.20s",
|
|
|
|
optval(arg->bundle, OPT_IPV6CP));
|
|
|
|
#endif
|
2001-01-26 01:41:34 +00:00
|
|
|
prompt_Printf(arg->prompt, " Keep-Session: %s\n",
|
1999-06-02 00:46:55 +00:00
|
|
|
optval(arg->bundle, OPT_KEEPSESSION));
|
2001-01-26 01:41:34 +00:00
|
|
|
prompt_Printf(arg->prompt, " Loopback: %-20.20s",
|
1998-04-16 00:26:21 +00:00
|
|
|
optval(arg->bundle, OPT_LOOPBACK));
|
2001-01-26 01:41:34 +00:00
|
|
|
prompt_Printf(arg->prompt, " PasswdAuth: %s\n",
|
1998-04-16 00:26:21 +00:00
|
|
|
optval(arg->bundle, OPT_PASSWDAUTH));
|
2001-01-26 01:41:34 +00:00
|
|
|
prompt_Printf(arg->prompt, " Proxy: %-20.20s",
|
1998-04-16 00:26:21 +00:00
|
|
|
optval(arg->bundle, OPT_PROXY));
|
2001-01-26 01:41:34 +00:00
|
|
|
prompt_Printf(arg->prompt, " Proxyall: %s\n",
|
1998-10-26 19:07:39 +00:00
|
|
|
optval(arg->bundle, OPT_PROXYALL));
|
2001-08-14 16:05:52 +00:00
|
|
|
prompt_Printf(arg->prompt, " Sticky Routes: %-20.20s",
|
|
|
|
optval(arg->bundle, OPT_SROUTES));
|
|
|
|
prompt_Printf(arg->prompt, " TCPMSS Fixup: %s\n",
|
2000-11-28 13:18:35 +00:00
|
|
|
optval(arg->bundle, OPT_TCPMSSFIXUP));
|
2001-08-14 16:05:52 +00:00
|
|
|
prompt_Printf(arg->prompt, " Throughput: %-20.20s",
|
1998-04-16 00:26:21 +00:00
|
|
|
optval(arg->bundle, OPT_THROUGHPUT));
|
2001-08-14 16:05:52 +00:00
|
|
|
prompt_Printf(arg->prompt, " Utmp Logging: %s\n",
|
1998-04-16 00:26:21 +00:00
|
|
|
optval(arg->bundle, OPT_UTMP));
|
|
|
|
|
1998-04-11 21:50:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-03-09 19:26:41 +00:00
|
|
|
static void
|
|
|
|
bundle_IdleTimeout(void *v)
|
|
|
|
{
|
|
|
|
struct bundle *bundle = (struct bundle *)v;
|
|
|
|
|
2000-04-07 23:46:14 +00:00
|
|
|
log_Printf(LogPHASE, "Idle timer expired\n");
|
1998-05-21 01:13:32 +00:00
|
|
|
bundle_StopIdleTimer(bundle);
|
1998-06-15 19:05:27 +00:00
|
|
|
bundle_Close(bundle, NULL, CLOSE_STAYDOWN);
|
1998-03-09 19:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start Idle timer. If timeout is reached, we call bundle_Close() to
|
|
|
|
* close LCP and link.
|
|
|
|
*/
|
|
|
|
void
|
2000-07-11 22:11:36 +00:00
|
|
|
bundle_StartIdleTimer(struct bundle *bundle, unsigned secs)
|
1998-03-09 19:26:41 +00:00
|
|
|
{
|
1998-05-21 01:13:32 +00:00
|
|
|
timer_Stop(&bundle->idle.timer);
|
1998-06-12 17:45:10 +00:00
|
|
|
if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) !=
|
1999-08-17 17:22:46 +00:00
|
|
|
bundle->phys_type.open && bundle->cfg.idle.timeout) {
|
2000-07-11 22:11:36 +00:00
|
|
|
time_t now = time(NULL);
|
|
|
|
|
|
|
|
if (secs == 0)
|
|
|
|
secs = bundle->cfg.idle.timeout;
|
1999-08-17 17:22:46 +00:00
|
|
|
|
2000-07-11 22:11:36 +00:00
|
|
|
/* We want at least `secs' */
|
1999-08-17 17:22:46 +00:00
|
|
|
if (bundle->cfg.idle.min_timeout > secs && bundle->upat) {
|
2000-07-11 22:11:36 +00:00
|
|
|
int up = now - bundle->upat;
|
1999-08-17 17:22:46 +00:00
|
|
|
|
|
|
|
if ((long long)bundle->cfg.idle.min_timeout - up > (long long)secs)
|
2000-07-11 22:11:36 +00:00
|
|
|
/* Only increase from the current `remaining' value */
|
1999-08-17 17:22:46 +00:00
|
|
|
secs = bundle->cfg.idle.min_timeout - up;
|
|
|
|
}
|
1998-05-21 01:13:32 +00:00
|
|
|
bundle->idle.timer.func = bundle_IdleTimeout;
|
|
|
|
bundle->idle.timer.name = "idle";
|
1999-08-17 17:22:46 +00:00
|
|
|
bundle->idle.timer.load = secs * SECTICKS;
|
1998-05-21 01:13:32 +00:00
|
|
|
bundle->idle.timer.arg = bundle;
|
|
|
|
timer_Start(&bundle->idle.timer);
|
2000-07-11 22:11:36 +00:00
|
|
|
bundle->idle.done = now + secs;
|
1998-03-09 19:26:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-08-17 17:22:46 +00:00
|
|
|
bundle_SetIdleTimer(struct bundle *bundle, int timeout, int min_timeout)
|
1998-03-09 19:26:41 +00:00
|
|
|
{
|
1999-08-17 17:22:46 +00:00
|
|
|
bundle->cfg.idle.timeout = timeout;
|
|
|
|
if (min_timeout >= 0)
|
|
|
|
bundle->cfg.idle.min_timeout = min_timeout;
|
2001-08-14 16:05:52 +00:00
|
|
|
if (ncp_LayersOpen(&bundle->ncp))
|
2000-07-11 22:11:36 +00:00
|
|
|
bundle_StartIdleTimer(bundle, 0);
|
1998-03-09 19:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_StopIdleTimer(struct bundle *bundle)
|
|
|
|
{
|
1998-05-01 19:26:12 +00:00
|
|
|
timer_Stop(&bundle->idle.timer);
|
1998-04-07 01:49:24 +00:00
|
|
|
bundle->idle.done = 0;
|
1998-03-09 19:26:41 +00:00
|
|
|
}
|
|
|
|
|
1998-05-21 01:13:32 +00:00
|
|
|
static int
|
1998-03-09 19:26:41 +00:00
|
|
|
bundle_RemainingIdleTime(struct bundle *bundle)
|
|
|
|
{
|
1998-03-18 23:15:31 +00:00
|
|
|
if (bundle->idle.done)
|
|
|
|
return bundle->idle.done - time(NULL);
|
|
|
|
return -1;
|
1998-03-09 19:26:41 +00:00
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
|
2002-05-07 10:06:54 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
|
|
|
|
static void
|
|
|
|
bundle_SessionTimeout(void *v)
|
|
|
|
{
|
|
|
|
struct bundle *bundle = (struct bundle *)v;
|
|
|
|
|
|
|
|
log_Printf(LogPHASE, "Session-Timeout timer expired\n");
|
|
|
|
bundle_StopSessionTimer(bundle);
|
|
|
|
bundle_Close(bundle, NULL, CLOSE_STAYDOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_StartSessionTimer(struct bundle *bundle, unsigned secs)
|
|
|
|
{
|
|
|
|
timer_Stop(&bundle->session.timer);
|
|
|
|
if ((bundle->phys_type.open & (PHYS_DEDICATED|PHYS_DDIAL)) !=
|
|
|
|
bundle->phys_type.open && bundle->radius.sessiontime) {
|
|
|
|
time_t now = time(NULL);
|
|
|
|
|
|
|
|
if (secs == 0)
|
|
|
|
secs = bundle->radius.sessiontime;
|
|
|
|
|
|
|
|
bundle->session.timer.func = bundle_SessionTimeout;
|
|
|
|
bundle->session.timer.name = "session";
|
|
|
|
bundle->session.timer.load = secs * SECTICKS;
|
|
|
|
bundle->session.timer.arg = bundle;
|
|
|
|
timer_Start(&bundle->session.timer);
|
|
|
|
bundle->session.done = now + secs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_StopSessionTimer(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
timer_Stop(&bundle->session.timer);
|
|
|
|
bundle->session.done = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
int
|
|
|
|
bundle_IsDead(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
return !bundle->links || (bundle->phase == PHASE_DEAD && bundle->CleaningUp);
|
|
|
|
}
|
1998-04-03 19:26:02 +00:00
|
|
|
|
1998-05-21 01:13:32 +00:00
|
|
|
static struct datalink *
|
|
|
|
bundle_DatalinkLinkout(struct bundle *bundle, struct datalink *dl)
|
1998-04-05 22:48:25 +00:00
|
|
|
{
|
|
|
|
struct datalink **dlp;
|
|
|
|
|
1998-05-23 22:24:50 +00:00
|
|
|
for (dlp = &bundle->links; *dlp; dlp = &(*dlp)->next)
|
|
|
|
if (*dlp == dl) {
|
|
|
|
*dlp = dl->next;
|
|
|
|
dl->next = NULL;
|
|
|
|
bundle_LinksRemoved(bundle);
|
|
|
|
return dl;
|
|
|
|
}
|
1998-05-21 01:13:32 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bundle_DatalinkLinkin(struct bundle *bundle, struct datalink *dl)
|
|
|
|
{
|
|
|
|
struct datalink **dlp = &bundle->links;
|
|
|
|
|
|
|
|
while (*dlp)
|
|
|
|
dlp = &(*dlp)->next;
|
|
|
|
|
|
|
|
*dlp = dl;
|
|
|
|
dl->next = NULL;
|
|
|
|
|
|
|
|
bundle_LinkAdded(bundle, dl);
|
1999-08-05 10:32:16 +00:00
|
|
|
mp_CheckAutoloadTimer(&bundle->ncp.mp);
|
1998-04-10 13:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_CleanDatalinks(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
struct datalink **dlp = &bundle->links;
|
1998-05-21 01:13:32 +00:00
|
|
|
int found = 0;
|
1998-04-10 13:19:23 +00:00
|
|
|
|
|
|
|
while (*dlp)
|
|
|
|
if ((*dlp)->state == DATALINK_CLOSED &&
|
1999-11-28 15:50:08 +00:00
|
|
|
(*dlp)->physical->type &
|
|
|
|
(PHYS_DIRECT|PHYS_BACKGROUND|PHYS_FOREGROUND)) {
|
1998-04-10 13:19:23 +00:00
|
|
|
*dlp = datalink_Destroy(*dlp);
|
1998-05-21 01:13:32 +00:00
|
|
|
found++;
|
|
|
|
} else
|
1998-04-10 13:19:23 +00:00
|
|
|
dlp = &(*dlp)->next;
|
1998-05-21 01:13:32 +00:00
|
|
|
|
|
|
|
if (found)
|
|
|
|
bundle_LinksRemoved(bundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
bundle_DatalinkClone(struct bundle *bundle, struct datalink *dl,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
if (bundle2datalink(bundle, name)) {
|
|
|
|
log_Printf(LogWARN, "Clone: %s: name already exists\n", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bundle_DatalinkLinkin(bundle, datalink_Clone(dl, name));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_DatalinkRemove(struct bundle *bundle, struct datalink *dl)
|
|
|
|
{
|
|
|
|
dl = bundle_DatalinkLinkout(bundle, dl);
|
|
|
|
if (dl)
|
|
|
|
datalink_Destroy(dl);
|
1998-04-05 22:48:25 +00:00
|
|
|
}
|
1998-04-23 03:23:03 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
bundle_SetLabel(struct bundle *bundle, const char *label)
|
|
|
|
{
|
|
|
|
if (label)
|
|
|
|
strncpy(bundle->cfg.label, label, sizeof bundle->cfg.label - 1);
|
|
|
|
else
|
|
|
|
*bundle->cfg.label = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
bundle_GetLabel(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
return *bundle->cfg.label ? bundle->cfg.label : NULL;
|
|
|
|
}
|
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
|
|
|
int
|
|
|
|
bundle_LinkSize()
|
|
|
|
{
|
|
|
|
struct iovec iov[SCATTER_SEGMENTS];
|
|
|
|
int niov, expect, f;
|
|
|
|
|
|
|
|
iov[0].iov_len = strlen(Version) + 1;
|
|
|
|
iov[0].iov_base = NULL;
|
|
|
|
niov = 1;
|
|
|
|
if (datalink2iov(NULL, iov, &niov, SCATTER_SEGMENTS, NULL, NULL) == -1) {
|
|
|
|
log_Printf(LogERROR, "Cannot determine space required for link\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (f = expect = 0; f < niov; f++)
|
|
|
|
expect += iov[f].iov_len;
|
|
|
|
|
|
|
|
return expect;
|
|
|
|
}
|
|
|
|
|
1998-04-28 01:25:46 +00:00
|
|
|
void
|
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(struct bundle *bundle, int s)
|
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
|
|
|
char cmsgbuf[sizeof(struct cmsghdr) + sizeof(int) * SEND_MAXFD];
|
1999-11-30 23:52:37 +00:00
|
|
|
int niov, expect, f, *fd, nfd, onfd, got;
|
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
|
|
|
struct iovec iov[SCATTER_SEGMENTS];
|
1999-11-06 22:50:59 +00:00
|
|
|
struct cmsghdr *cmsg;
|
1998-05-02 21:57:50 +00:00
|
|
|
struct msghdr msg;
|
1998-05-08 01:15:19 +00:00
|
|
|
struct datalink *dl;
|
1998-05-28 23:15:40 +00:00
|
|
|
pid_t pid;
|
1998-04-30 23:53:56 +00:00
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "Receiving datalink\n");
|
1998-04-30 23:53:56 +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
|
|
|
/*
|
|
|
|
* Create our scatter/gather array - passing NULL gets the space
|
|
|
|
* allocation requirement rather than actually flattening the
|
|
|
|
* structures.
|
|
|
|
*/
|
1998-05-02 21:57:50 +00:00
|
|
|
iov[0].iov_len = strlen(Version) + 1;
|
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
|
|
|
iov[0].iov_base = NULL;
|
|
|
|
niov = 1;
|
|
|
|
if (datalink2iov(NULL, iov, &niov, SCATTER_SEGMENTS, NULL, NULL) == -1) {
|
|
|
|
log_Printf(LogERROR, "Cannot determine space required for link\n");
|
1998-05-02 21:57:50 +00:00
|
|
|
return;
|
1998-05-25 02:22:38 +00:00
|
|
|
}
|
1998-05-02 21:57:50 +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
|
|
|
/* Allocate the scatter/gather array for recvmsg() */
|
|
|
|
for (f = expect = 0; f < niov; f++) {
|
|
|
|
if ((iov[f].iov_base = malloc(iov[f].iov_len)) == NULL) {
|
|
|
|
log_Printf(LogERROR, "Cannot allocate space to receive link\n");
|
|
|
|
return;
|
|
|
|
}
|
1999-11-30 23:52:37 +00:00
|
|
|
if (f)
|
|
|
|
expect += iov[f].iov_len;
|
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-05-02 21:57:50 +00:00
|
|
|
|
|
|
|
/* Set up our message */
|
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
|
|
|
cmsg = (struct cmsghdr *)cmsgbuf;
|
|
|
|
cmsg->cmsg_len = sizeof cmsgbuf;
|
|
|
|
cmsg->cmsg_level = SOL_SOCKET;
|
|
|
|
cmsg->cmsg_type = 0;
|
1998-05-02 21:57:50 +00:00
|
|
|
|
|
|
|
memset(&msg, '\0', sizeof msg);
|
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
|
|
|
msg.msg_name = NULL;
|
|
|
|
msg.msg_namelen = 0;
|
1998-05-02 21:57:50 +00:00
|
|
|
msg.msg_iov = iov;
|
1999-11-30 23:52:37 +00:00
|
|
|
msg.msg_iovlen = 1; /* Only send the version at the first pass */
|
1998-05-02 21:57:50 +00:00
|
|
|
msg.msg_control = cmsgbuf;
|
|
|
|
msg.msg_controllen = sizeof cmsgbuf;
|
|
|
|
|
2000-03-14 01:47:19 +00:00
|
|
|
log_Printf(LogDEBUG, "Expecting %u scatter/gather bytes\n",
|
|
|
|
(unsigned)iov[0].iov_len);
|
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
|
|
|
if ((got = recvmsg(s, &msg, MSG_WAITALL)) != iov[0].iov_len) {
|
|
|
|
if (got == -1)
|
1998-05-02 21:57:50 +00:00
|
|
|
log_Printf(LogERROR, "Failed recvmsg: %s\n", strerror(errno));
|
|
|
|
else
|
2000-03-14 01:47:19 +00:00
|
|
|
log_Printf(LogERROR, "Failed recvmsg: Got %d, not %u\n",
|
|
|
|
got, (unsigned)iov[0].iov_len);
|
1998-05-02 21:57:50 +00:00
|
|
|
while (niov--)
|
|
|
|
free(iov[niov].iov_base);
|
1998-04-30 23:53:56 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-05-02 21:57:50 +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
|
|
|
if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
|
|
|
|
log_Printf(LogERROR, "Recvmsg: no descriptors received !\n");
|
|
|
|
while (niov--)
|
|
|
|
free(iov[niov].iov_base);
|
|
|
|
return;
|
1999-11-06 22:50:59 +00:00
|
|
|
}
|
|
|
|
|
2001-10-04 13:11:48 +00:00
|
|
|
fd = (int *)CMSG_DATA(cmsg);
|
|
|
|
nfd = ((caddr_t)cmsg + cmsg->cmsg_len - (caddr_t)fd) / sizeof(int);
|
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
|
|
|
|
|
|
|
if (nfd < 2) {
|
2000-03-14 01:47:07 +00:00
|
|
|
log_Printf(LogERROR, "Recvmsg: %d descriptor%s received (too few) !\n",
|
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
|
|
|
nfd, nfd == 1 ? "" : "s");
|
|
|
|
while (nfd--)
|
|
|
|
close(fd[nfd]);
|
1998-06-18 23:38:04 +00:00
|
|
|
while (niov--)
|
|
|
|
free(iov[niov].iov_base);
|
|
|
|
return;
|
1998-05-25 02:22:38 +00:00
|
|
|
}
|
1998-05-09 14:44:11 +00:00
|
|
|
|
1999-11-06 22:50:59 +00:00
|
|
|
/*
|
1999-11-30 23:52:37 +00:00
|
|
|
* We've successfully received two or more open file descriptors
|
|
|
|
* through our socket, plus a version string. Make sure it's the
|
|
|
|
* correct version, and drop the connection if it's not.
|
1999-11-06 22:50:59 +00:00
|
|
|
*/
|
1998-05-02 21:57:50 +00:00
|
|
|
if (strncmp(Version, iov[0].iov_base, iov[0].iov_len)) {
|
|
|
|
log_Printf(LogWARN, "Cannot receive datalink, incorrect version"
|
|
|
|
" (\"%.*s\", not \"%s\")\n", (int)iov[0].iov_len,
|
1998-06-27 12:03:46 +00:00
|
|
|
(char *)iov[0].iov_base, Version);
|
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
|
|
|
while (nfd--)
|
|
|
|
close(fd[nfd]);
|
1998-05-02 21:57:50 +00:00
|
|
|
while (niov--)
|
|
|
|
free(iov[niov].iov_base);
|
1998-04-30 23:53:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-11-30 23:52:37 +00:00
|
|
|
/*
|
|
|
|
* Everything looks good. Send the other side our process id so that
|
|
|
|
* they can transfer lock ownership, and wait for them to send the
|
|
|
|
* actual link data.
|
|
|
|
*/
|
|
|
|
pid = getpid();
|
|
|
|
if ((got = write(fd[1], &pid, sizeof pid)) != sizeof pid) {
|
|
|
|
if (got == -1)
|
|
|
|
log_Printf(LogERROR, "Failed write: %s\n", strerror(errno));
|
|
|
|
else
|
|
|
|
log_Printf(LogERROR, "Failed write: Got %d, not %d\n", got,
|
|
|
|
(int)(sizeof pid));
|
|
|
|
while (nfd--)
|
|
|
|
close(fd[nfd]);
|
|
|
|
while (niov--)
|
|
|
|
free(iov[niov].iov_base);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((got = readv(fd[1], iov + 1, niov - 1)) != expect) {
|
|
|
|
if (got == -1)
|
|
|
|
log_Printf(LogERROR, "Failed write: %s\n", strerror(errno));
|
|
|
|
else
|
|
|
|
log_Printf(LogERROR, "Failed write: Got %d, not %d\n", got, expect);
|
|
|
|
while (nfd--)
|
|
|
|
close(fd[nfd]);
|
|
|
|
while (niov--)
|
|
|
|
free(iov[niov].iov_base);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
close(fd[1]);
|
|
|
|
|
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
|
|
|
onfd = nfd; /* We've got this many in our array */
|
2000-03-14 01:47:07 +00:00
|
|
|
nfd -= 2; /* Don't include p->fd and our reply descriptor */
|
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
|
|
|
niov = 1; /* Skip the version id */
|
1999-11-06 22:50:59 +00:00
|
|
|
dl = iov2datalink(bundle, iov, &niov, sizeof iov / sizeof *iov, 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
|
|
|
fd + 2, &nfd);
|
1998-05-08 01:15:19 +00:00
|
|
|
if (dl) {
|
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-06 22:50:59 +00:00
|
|
|
if (nfd) {
|
|
|
|
log_Printf(LogERROR, "bundle_ReceiveDatalink: Failed to handle %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
|
|
|
"auxiliary file descriptors (%d remain)\n", onfd, nfd);
|
1999-11-06 22:50:59 +00:00
|
|
|
datalink_Destroy(dl);
|
|
|
|
while (nfd--)
|
|
|
|
close(fd[onfd--]);
|
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
|
|
|
close(fd[0]);
|
1999-11-06 22:50:59 +00:00
|
|
|
} else {
|
|
|
|
bundle_DatalinkLinkin(bundle, dl);
|
|
|
|
datalink_AuthOk(dl);
|
|
|
|
bundle_CalculateBandwidth(dl->bundle);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (nfd--)
|
|
|
|
close(fd[onfd--]);
|
|
|
|
close(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
|
|
|
close(fd[1]);
|
1999-11-06 22:50:59 +00:00
|
|
|
}
|
1998-05-02 21:57:50 +00:00
|
|
|
|
|
|
|
free(iov[0].iov_base);
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-02 21:57:50 +00:00
|
|
|
bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun)
|
1998-04-28 01:25:46 +00:00
|
|
|
{
|
2001-10-04 13:11:48 +00:00
|
|
|
char cmsgbuf[CMSG_SPACE(sizeof(int) * SEND_MAXFD)];
|
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
|
|
|
const char *constlock;
|
|
|
|
char *lock;
|
1999-11-06 22:50:59 +00:00
|
|
|
struct cmsghdr *cmsg;
|
1998-05-02 21:57:50 +00:00
|
|
|
struct msghdr msg;
|
|
|
|
struct iovec iov[SCATTER_SEGMENTS];
|
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
|
|
|
int niov, f, expect, newsid, fd[SEND_MAXFD], nfd, reply[2], got;
|
1998-05-28 23:15:40 +00:00
|
|
|
pid_t newpid;
|
1998-04-30 23:53:56 +00:00
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "Transmitting datalink %s\n", dl->name);
|
1998-04-30 23:53:56 +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
|
|
|
/* Record the base device name for a lock transfer later */
|
|
|
|
constlock = physical_LockedDevice(dl->physical);
|
|
|
|
if (constlock) {
|
|
|
|
lock = alloca(strlen(constlock) + 1);
|
|
|
|
strcpy(lock, constlock);
|
|
|
|
} else
|
|
|
|
lock = NULL;
|
|
|
|
|
1998-05-21 01:13:32 +00:00
|
|
|
bundle_LinkClosed(dl->bundle, dl);
|
1998-05-23 22:24:50 +00:00
|
|
|
bundle_DatalinkLinkout(dl->bundle, dl);
|
1998-05-15 18:21:45 +00:00
|
|
|
|
1998-05-02 21:57:50 +00:00
|
|
|
/* Build our scatter/gather array */
|
|
|
|
iov[0].iov_len = strlen(Version) + 1;
|
|
|
|
iov[0].iov_base = strdup(Version);
|
|
|
|
niov = 1;
|
1999-11-06 22:50:59 +00:00
|
|
|
nfd = 0;
|
1998-04-30 23:53:56 +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
|
|
|
fd[0] = datalink2iov(dl, iov, &niov, SCATTER_SEGMENTS, fd + 2, &nfd);
|
1999-11-06 22:50:59 +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
|
|
|
if (fd[0] != -1 && socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, reply) != -1) {
|
|
|
|
/*
|
|
|
|
* fd[1] is used to get the peer process id back, then to confirm that
|
|
|
|
* we've transferred any device locks to that process id.
|
|
|
|
*/
|
|
|
|
fd[1] = reply[1];
|
1998-04-30 23:53:56 +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
|
|
|
nfd += 2; /* Include fd[0] and fd[1] */
|
1998-05-02 21:57:50 +00:00
|
|
|
memset(&msg, '\0', sizeof msg);
|
1998-05-25 02:22:38 +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
|
|
|
msg.msg_name = NULL;
|
|
|
|
msg.msg_namelen = 0;
|
1999-11-30 23:52:37 +00:00
|
|
|
/*
|
|
|
|
* Only send the version to start... We used to send the whole lot, but
|
|
|
|
* this caused problems with our RECVBUF size as a single link is about
|
|
|
|
* 22k ! This way, we should bump into no limits.
|
|
|
|
*/
|
|
|
|
msg.msg_iovlen = 1;
|
1998-05-02 21:57:50 +00:00
|
|
|
msg.msg_iov = iov;
|
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
|
|
|
msg.msg_control = cmsgbuf;
|
2001-10-04 13:11:48 +00:00
|
|
|
msg.msg_controllen = CMSG_SPACE(sizeof(int) * nfd);
|
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
|
|
|
msg.msg_flags = 0;
|
1998-05-25 02:22:38 +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
|
|
|
cmsg = (struct cmsghdr *)cmsgbuf;
|
|
|
|
cmsg->cmsg_len = msg.msg_controllen;
|
|
|
|
cmsg->cmsg_level = SOL_SOCKET;
|
|
|
|
cmsg->cmsg_type = SCM_RIGHTS;
|
1999-11-06 22:50:59 +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
|
|
|
for (f = 0; f < nfd; f++)
|
2001-10-04 13:11:48 +00:00
|
|
|
*((int *)CMSG_DATA(cmsg) + f) = fd[f];
|
1998-05-02 21:57:50 +00:00
|
|
|
|
1999-11-30 23:52:37 +00:00
|
|
|
for (f = 1, expect = 0; f < niov; f++)
|
1998-05-02 21:57:50 +00:00
|
|
|
expect += iov[f].iov_len;
|
|
|
|
|
1999-11-30 23:52:37 +00:00
|
|
|
if (setsockopt(reply[0], SOL_SOCKET, SO_SNDBUF, &expect, sizeof(int)) == -1)
|
|
|
|
log_Printf(LogERROR, "setsockopt(SO_RCVBUF, %d): %s\n", expect,
|
|
|
|
strerror(errno));
|
|
|
|
if (setsockopt(reply[1], SOL_SOCKET, SO_RCVBUF, &expect, sizeof(int)) == -1)
|
|
|
|
log_Printf(LogERROR, "setsockopt(SO_RCVBUF, %d): %s\n", expect,
|
|
|
|
strerror(errno));
|
|
|
|
|
2000-03-14 01:47:19 +00:00
|
|
|
log_Printf(LogDEBUG, "Sending %d descriptor%s and %u bytes in scatter"
|
|
|
|
"/gather array\n", nfd, nfd == 1 ? "" : "s",
|
|
|
|
(unsigned)iov[0].iov_len);
|
1998-05-02 21:57:50 +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
|
|
|
if ((got = sendmsg(s, &msg, 0)) == -1)
|
|
|
|
log_Printf(LogERROR, "Failed sendmsg: %s: %s\n",
|
|
|
|
sun->sun_path, strerror(errno));
|
1999-11-30 23:52:37 +00:00
|
|
|
else if (got != iov[0].iov_len)
|
2000-03-14 01:47:19 +00:00
|
|
|
log_Printf(LogERROR, "%s: Failed initial sendmsg: Only sent %d of %u\n",
|
|
|
|
sun->sun_path, got, (unsigned)iov[0].iov_len);
|
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
|
|
|
else {
|
2000-03-14 01:47:07 +00:00
|
|
|
/* We must get the ACK before closing the descriptor ! */
|
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
|
|
|
int res;
|
|
|
|
|
1999-11-30 23:52:37 +00:00
|
|
|
if ((got = read(reply[0], &newpid, sizeof newpid)) == sizeof newpid) {
|
|
|
|
log_Printf(LogDEBUG, "Received confirmation from pid %d\n",
|
|
|
|
(int)newpid);
|
|
|
|
if (lock && (res = ID0uu_lock_txfr(lock, newpid)) != UU_LOCK_OK)
|
2000-04-07 23:46:14 +00:00
|
|
|
log_Printf(LogERROR, "uu_lock_txfr: %s\n", uu_lockerr(res));
|
1999-11-30 23:52:37 +00:00
|
|
|
|
|
|
|
log_Printf(LogDEBUG, "Transmitting link (%d bytes)\n", expect);
|
|
|
|
if ((got = writev(reply[0], iov + 1, niov - 1)) != expect) {
|
|
|
|
if (got == -1)
|
|
|
|
log_Printf(LogERROR, "%s: Failed writev: %s\n",
|
|
|
|
sun->sun_path, strerror(errno));
|
|
|
|
else
|
|
|
|
log_Printf(LogERROR, "%s: Failed writev: Wrote %d of %d\n",
|
|
|
|
sun->sun_path, got, expect);
|
|
|
|
}
|
|
|
|
} else if (got == -1)
|
|
|
|
log_Printf(LogERROR, "%s: Failed socketpair read: %s\n",
|
|
|
|
sun->sun_path, strerror(errno));
|
|
|
|
else
|
|
|
|
log_Printf(LogERROR, "%s: Failed socketpair read: Got %d of %d\n",
|
|
|
|
sun->sun_path, got, (int)(sizeof newpid));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
close(reply[0]);
|
|
|
|
close(reply[1]);
|
1998-05-25 02:22:38 +00:00
|
|
|
|
1999-06-02 00:46:55 +00:00
|
|
|
newsid = Enabled(dl->bundle, OPT_KEEPSESSION) ||
|
1999-11-06 22:50:59 +00:00
|
|
|
tcgetpgrp(fd[0]) == getpgrp();
|
|
|
|
while (nfd)
|
|
|
|
close(fd[--nfd]);
|
1998-05-28 23:17:51 +00:00
|
|
|
if (newsid)
|
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_setsid(dl->bundle, got != -1);
|
1998-04-30 23:53:56 +00:00
|
|
|
}
|
1998-05-28 23:15:40 +00:00
|
|
|
close(s);
|
1998-05-02 21:57:50 +00:00
|
|
|
|
|
|
|
while (niov--)
|
|
|
|
free(iov[niov].iov_base);
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
1998-05-15 23:58:30 +00:00
|
|
|
|
1998-05-16 23:47:28 +00:00
|
|
|
int
|
|
|
|
bundle_RenameDatalink(struct bundle *bundle, struct datalink *ndl,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct datalink *dl;
|
|
|
|
|
|
|
|
if (!strcasecmp(ndl->name, name))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (!strcasecmp(dl->name, name))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
datalink_Rename(ndl, name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-05-15 23:58:30 +00:00
|
|
|
int
|
|
|
|
bundle_SetMode(struct bundle *bundle, struct datalink *dl, int mode)
|
|
|
|
{
|
|
|
|
int omode;
|
|
|
|
|
|
|
|
omode = dl->physical->type;
|
|
|
|
if (omode == mode)
|
|
|
|
return 1;
|
|
|
|
|
1998-06-12 17:45:10 +00:00
|
|
|
if (mode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO))
|
|
|
|
/* First auto link */
|
1998-05-15 23:58:30 +00:00
|
|
|
if (bundle->ncp.ipcp.peer_ip.s_addr == INADDR_ANY) {
|
1998-06-12 17:45:10 +00:00
|
|
|
log_Printf(LogWARN, "You must `set ifaddr' or `open' before"
|
|
|
|
" changing mode to %s\n", mode2Nam(mode));
|
1998-05-15 23:58:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!datalink_SetMode(dl, mode))
|
|
|
|
return 0;
|
|
|
|
|
1998-06-12 17:45:10 +00:00
|
|
|
if (mode == PHYS_AUTO && !(bundle->phys_type.all & PHYS_AUTO) &&
|
|
|
|
bundle->phase != PHASE_NETWORK)
|
|
|
|
/* First auto link, we need an interface */
|
1998-05-15 23:58:30 +00:00
|
|
|
ipcp_InterfaceUp(&bundle->ncp.ipcp);
|
|
|
|
|
1999-08-05 10:32:16 +00:00
|
|
|
/* Regenerate phys_type and adjust idle timer */
|
1998-05-21 01:13:32 +00:00
|
|
|
bundle_LinksRemoved(bundle);
|
1998-05-15 23:58:30 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
1998-05-28 23:17:51 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
bundle_setsid(struct bundle *bundle, int holdsession)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Lose the current session. This means getting rid of our pid
|
|
|
|
* too so that the tty device will really go away, and any getty
|
|
|
|
* etc will be allowed to restart.
|
|
|
|
*/
|
|
|
|
pid_t pid, orig;
|
|
|
|
int fds[2];
|
|
|
|
char done;
|
|
|
|
struct datalink *dl;
|
|
|
|
|
1999-12-23 21:43:25 +00:00
|
|
|
if (!holdsession && bundle_IsDead(bundle)) {
|
|
|
|
/*
|
|
|
|
* No need to lose our session after all... we're going away anyway
|
|
|
|
*
|
|
|
|
* We should really stop the timer and pause if holdsession is set and
|
|
|
|
* the bundle's dead, but that leaves other resources lying about :-(
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-05-28 23:17:51 +00:00
|
|
|
orig = getpid();
|
|
|
|
if (pipe(fds) == -1) {
|
|
|
|
log_Printf(LogERROR, "pipe: %s\n", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch ((pid = fork())) {
|
|
|
|
case -1:
|
|
|
|
log_Printf(LogERROR, "fork: %s\n", strerror(errno));
|
|
|
|
close(fds[0]);
|
|
|
|
close(fds[1]);
|
|
|
|
return;
|
|
|
|
case 0:
|
|
|
|
close(fds[1]);
|
1999-03-07 01:41:40 +00:00
|
|
|
read(fds[0], &done, 1); /* uu_locks are mine ! */
|
|
|
|
close(fds[0]);
|
1998-05-28 23:17:51 +00:00
|
|
|
if (pipe(fds) == -1) {
|
|
|
|
log_Printf(LogERROR, "pipe(2): %s\n", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch ((pid = fork())) {
|
|
|
|
case -1:
|
1998-06-16 19:40:42 +00:00
|
|
|
log_Printf(LogERROR, "fork(2): %s\n", strerror(errno));
|
1998-05-28 23:17:51 +00:00
|
|
|
close(fds[0]);
|
|
|
|
close(fds[1]);
|
|
|
|
return;
|
|
|
|
case 0:
|
|
|
|
close(fds[1]);
|
1999-03-07 01:41:40 +00:00
|
|
|
bundle_LockTun(bundle); /* update pid */
|
|
|
|
read(fds[0], &done, 1); /* uu_locks are mine ! */
|
|
|
|
close(fds[0]);
|
1998-05-28 23:17:51 +00:00
|
|
|
setsid();
|
2000-01-21 00:33:27 +00:00
|
|
|
bundle_ChangedPID(bundle);
|
2000-04-07 23:46:14 +00:00
|
|
|
log_Printf(LogDEBUG, "%d -> %d: %s session control\n",
|
1998-05-28 23:17:51 +00:00
|
|
|
(int)orig, (int)getpid(),
|
|
|
|
holdsession ? "Passed" : "Dropped");
|
1998-12-14 19:24:30 +00:00
|
|
|
timer_InitService(0); /* Start the Timer Service */
|
1998-05-28 23:17:51 +00:00
|
|
|
break;
|
|
|
|
default:
|
1999-03-07 01:41:40 +00:00
|
|
|
close(fds[0]);
|
1999-05-08 11:07:56 +00:00
|
|
|
/* Give away all our physical locks (to the final process) */
|
1998-05-28 23:17:51 +00:00
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (dl->state != DATALINK_CLOSED)
|
1999-05-08 11:07:56 +00:00
|
|
|
physical_ChangedPid(dl->physical, pid);
|
1999-03-07 01:41:40 +00:00
|
|
|
write(fds[1], "!", 1); /* done */
|
|
|
|
close(fds[1]);
|
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
|
|
|
_exit(0);
|
1998-05-28 23:17:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
1999-03-07 01:41:40 +00:00
|
|
|
close(fds[0]);
|
1999-05-08 11:07:56 +00:00
|
|
|
/* Give away all our physical locks (to the intermediate process) */
|
1998-05-28 23:17:51 +00:00
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (dl->state != DATALINK_CLOSED)
|
1999-05-08 11:07:56 +00:00
|
|
|
physical_ChangedPid(dl->physical, pid);
|
1999-03-07 01:41:40 +00:00
|
|
|
write(fds[1], "!", 1); /* done */
|
|
|
|
close(fds[1]);
|
1998-05-28 23:17:51 +00:00
|
|
|
if (holdsession) {
|
|
|
|
int fd, status;
|
|
|
|
|
|
|
|
timer_TermService();
|
|
|
|
signal(SIGPIPE, SIG_DFL);
|
|
|
|
signal(SIGALRM, SIG_DFL);
|
|
|
|
signal(SIGHUP, SIG_DFL);
|
|
|
|
signal(SIGTERM, SIG_DFL);
|
|
|
|
signal(SIGINT, SIG_DFL);
|
|
|
|
signal(SIGQUIT, SIG_DFL);
|
|
|
|
for (fd = getdtablesize(); fd >= 0; fd--)
|
|
|
|
close(fd);
|
|
|
|
/*
|
|
|
|
* Reap the intermediate process. As we're not exiting but the
|
|
|
|
* intermediate is, we don't want it to become defunct.
|
|
|
|
*/
|
|
|
|
waitpid(pid, &status, 0);
|
1998-05-29 18:33:10 +00:00
|
|
|
/* Tweak our process arguments.... */
|
2000-08-16 09:07:23 +00:00
|
|
|
SetTitle("session owner");
|
2000-08-18 00:01:44 +00:00
|
|
|
#ifndef NOSUID
|
1999-12-30 03:36:11 +00:00
|
|
|
setuid(ID0realuid());
|
2000-08-18 00:01:44 +00:00
|
|
|
#endif
|
1998-05-28 23:17:51 +00:00
|
|
|
/*
|
|
|
|
* Hang around for a HUP. This should happen as soon as the
|
2000-03-14 01:47:07 +00:00
|
|
|
* ppp that we passed our ctty descriptor to closes it.
|
|
|
|
* NOTE: If this process dies, the passed descriptor becomes
|
1998-05-28 23:17:51 +00:00
|
|
|
* invalid and will give a select() error by setting one
|
|
|
|
* of the error fds, aborting the other ppp. We don't
|
|
|
|
* want that to happen !
|
|
|
|
*/
|
|
|
|
pause();
|
|
|
|
}
|
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
|
|
|
_exit(0);
|
1998-05-28 23:17:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-10-24 01:08:45 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
bundle_HighestState(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
struct datalink *dl;
|
|
|
|
int result = DATALINK_CLOSED;
|
|
|
|
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (result < dl->state)
|
|
|
|
result = dl->state;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
1998-12-10 18:36:30 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
bundle_Exception(struct bundle *bundle, int fd)
|
|
|
|
{
|
|
|
|
struct datalink *dl;
|
|
|
|
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (dl->physical->fd == fd) {
|
|
|
|
datalink_Down(dl, CLOSE_NORMAL);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
1999-05-31 23:57:40 +00:00
|
|
|
|
|
|
|
void
|
2001-08-14 16:05:52 +00:00
|
|
|
bundle_AdjustFilters(struct bundle *bundle, struct ncpaddr *local,
|
|
|
|
struct ncpaddr *remote)
|
1999-05-31 23:57:40 +00:00
|
|
|
{
|
2001-08-14 16:05:52 +00:00
|
|
|
filter_AdjustAddr(&bundle->filter.in, local, remote, NULL);
|
|
|
|
filter_AdjustAddr(&bundle->filter.out, local, remote, NULL);
|
|
|
|
filter_AdjustAddr(&bundle->filter.dial, local, remote, NULL);
|
|
|
|
filter_AdjustAddr(&bundle->filter.alive, local, remote, NULL);
|
2000-03-14 01:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-08-14 16:05:52 +00:00
|
|
|
bundle_AdjustDNS(struct bundle *bundle)
|
2000-03-14 01:47:27 +00:00
|
|
|
{
|
2001-08-14 16:05:52 +00:00
|
|
|
struct in_addr *dns = bundle->ncp.ipcp.ns.dns;
|
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
filter_AdjustAddr(&bundle->filter.in, NULL, NULL, dns);
|
|
|
|
filter_AdjustAddr(&bundle->filter.out, NULL, NULL, dns);
|
|
|
|
filter_AdjustAddr(&bundle->filter.dial, NULL, NULL, dns);
|
|
|
|
filter_AdjustAddr(&bundle->filter.alive, NULL, NULL, dns);
|
1999-05-31 23:57:40 +00:00
|
|
|
}
|
1999-08-05 10:32:16 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
bundle_CalculateBandwidth(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
struct datalink *dl;
|
2001-07-03 22:20:19 +00:00
|
|
|
int sp, overhead, maxoverhead;
|
1999-08-05 10:32:16 +00:00
|
|
|
|
|
|
|
bundle->bandwidth = 0;
|
2001-06-18 14:59:36 +00:00
|
|
|
bundle->iface->mtu = 0;
|
2001-07-03 22:20:19 +00:00
|
|
|
maxoverhead = 0;
|
|
|
|
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next) {
|
|
|
|
overhead = ccp_MTUOverhead(&dl->physical->link.ccp);
|
|
|
|
if (maxoverhead < overhead)
|
|
|
|
maxoverhead = overhead;
|
1999-08-05 10:32:16 +00:00
|
|
|
if (dl->state == DATALINK_OPEN) {
|
|
|
|
if ((sp = dl->mp.bandwidth) == 0 &&
|
|
|
|
(sp = physical_GetSpeed(dl->physical)) == 0)
|
|
|
|
log_Printf(LogDEBUG, "%s: %s: Cannot determine bandwidth\n",
|
|
|
|
dl->name, dl->physical->name.full);
|
|
|
|
else
|
|
|
|
bundle->bandwidth += sp;
|
|
|
|
if (!bundle->ncp.mp.active) {
|
2001-06-18 14:59:36 +00:00
|
|
|
bundle->iface->mtu = dl->physical->link.lcp.his_mru;
|
1999-08-05 10:32:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-07-03 22:20:19 +00:00
|
|
|
}
|
1999-08-05 10:32:16 +00:00
|
|
|
|
2002-05-07 10:06:54 +00:00
|
|
|
if (bundle->bandwidth == 0)
|
1999-08-05 10:32:16 +00:00
|
|
|
bundle->bandwidth = 115200; /* Shrug */
|
|
|
|
|
2001-07-03 22:20:19 +00:00
|
|
|
if (bundle->ncp.mp.active) {
|
2001-06-18 14:59:36 +00:00
|
|
|
bundle->iface->mtu = bundle->ncp.mp.peer_mrru;
|
2001-07-03 22:20:19 +00:00
|
|
|
overhead = ccp_MTUOverhead(&bundle->ncp.mp.link.ccp);
|
|
|
|
if (maxoverhead < overhead)
|
|
|
|
maxoverhead = overhead;
|
|
|
|
} else if (!bundle->iface->mtu)
|
2001-06-18 14:59:36 +00:00
|
|
|
bundle->iface->mtu = DEF_MRU;
|
1999-08-05 10:32:16 +00:00
|
|
|
|
|
|
|
#ifndef NORADIUS
|
2000-11-28 13:18:35 +00:00
|
|
|
if (bundle->radius.valid && bundle->radius.mtu &&
|
2001-06-18 14:59:36 +00:00
|
|
|
bundle->radius.mtu < bundle->iface->mtu) {
|
1999-08-05 10:32:16 +00:00
|
|
|
log_Printf(LogLCP, "Reducing MTU to radius value %lu\n",
|
|
|
|
bundle->radius.mtu);
|
2001-06-18 14:59:36 +00:00
|
|
|
bundle->iface->mtu = bundle->radius.mtu;
|
1999-08-05 10:32:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-07-03 22:20:19 +00:00
|
|
|
if (maxoverhead) {
|
|
|
|
log_Printf(LogLCP, "Reducing MTU from %d to %d (CCP requirement)\n",
|
|
|
|
bundle->iface->mtu, bundle->iface->mtu - maxoverhead);
|
|
|
|
bundle->iface->mtu -= maxoverhead;
|
|
|
|
}
|
|
|
|
|
2000-11-28 13:18:35 +00:00
|
|
|
tun_configure(bundle);
|
2001-04-05 02:23:48 +00:00
|
|
|
|
|
|
|
route_UpdateMTU(bundle);
|
1999-08-05 10:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_AutoAdjust(struct bundle *bundle, int percent, int what)
|
|
|
|
{
|
|
|
|
struct datalink *dl, *choice, *otherlinkup;
|
|
|
|
|
|
|
|
choice = otherlinkup = NULL;
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (dl->physical->type == PHYS_AUTO) {
|
|
|
|
if (dl->state == DATALINK_OPEN) {
|
|
|
|
if (what == AUTO_DOWN) {
|
|
|
|
if (choice)
|
|
|
|
otherlinkup = choice;
|
|
|
|
choice = dl;
|
|
|
|
}
|
|
|
|
} else if (dl->state == DATALINK_CLOSED) {
|
|
|
|
if (what == AUTO_UP) {
|
|
|
|
choice = dl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* An auto link in an intermediate state - forget it for the moment */
|
|
|
|
choice = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (dl->state == DATALINK_OPEN && what == AUTO_DOWN)
|
|
|
|
otherlinkup = dl;
|
|
|
|
|
|
|
|
if (choice) {
|
|
|
|
if (what == AUTO_UP) {
|
|
|
|
log_Printf(LogPHASE, "%d%% saturation -> Opening link ``%s''\n",
|
|
|
|
percent, choice->name);
|
|
|
|
datalink_Up(choice, 1, 1);
|
2000-05-31 15:35:29 +00:00
|
|
|
mp_CheckAutoloadTimer(&bundle->ncp.mp);
|
1999-08-05 10:32:16 +00:00
|
|
|
} else if (otherlinkup) { /* Only bring the second-last link down */
|
|
|
|
log_Printf(LogPHASE, "%d%% saturation -> Closing link ``%s''\n",
|
|
|
|
percent, choice->name);
|
1999-10-05 05:01:44 +00:00
|
|
|
datalink_Close(choice, CLOSE_STAYDOWN);
|
2000-05-31 15:35:29 +00:00
|
|
|
mp_CheckAutoloadTimer(&bundle->ncp.mp);
|
1999-08-05 10:32:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
bundle_WantAutoloadTimer(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
struct datalink *dl;
|
|
|
|
int autolink, opened;
|
|
|
|
|
|
|
|
if (bundle->phase == PHASE_NETWORK) {
|
|
|
|
for (autolink = opened = 0, dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (dl->physical->type == PHYS_AUTO) {
|
|
|
|
if (++autolink == 2 || (autolink == 1 && opened))
|
|
|
|
/* Two auto links or one auto and one open in NETWORK phase */
|
|
|
|
return 1;
|
|
|
|
} else if (dl->state == DATALINK_OPEN) {
|
|
|
|
opened++;
|
|
|
|
if (autolink)
|
|
|
|
/* One auto and one open link in NETWORK phase */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2000-01-21 00:33:27 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
bundle_ChangedPID(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
#ifdef TUNSIFPID
|
|
|
|
ioctl(bundle->dev.fd, TUNSIFPID, 0);
|
|
|
|
#endif
|
|
|
|
}
|
2001-11-03 21:45:32 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
bundle_Uptime(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
if (bundle->upat)
|
|
|
|
return time(NULL) - bundle->upat;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|