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.
|
|
|
|
*
|
1998-05-01 19:20:09 +00:00
|
|
|
* $Id: bundle.c,v 1.1.2.65 1998/04/30 23:53:21 brian Exp $
|
1998-02-02 19:32:16 +00:00
|
|
|
*/
|
|
|
|
|
1998-04-07 00:54:26 +00:00
|
|
|
#include <sys/types.h>
|
1998-02-02 19:32:16 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/if_dl.h>
|
1998-03-16 22:54:35 +00:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
1998-04-25 10:49:52 +00:00
|
|
|
#include <net/if_tun.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>
|
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>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "command.h"
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "id.h"
|
|
|
|
#include "defs.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"
|
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"
|
|
|
|
#include "bundle.h"
|
1998-02-07 20:50:08 +00:00
|
|
|
#include "async.h"
|
|
|
|
#include "physical.h"
|
1998-02-06 02:23:48 +00:00
|
|
|
#include "modem.h"
|
1998-02-07 20:50:08 +00:00
|
|
|
#include "auth.h"
|
|
|
|
#include "lcpproto.h"
|
|
|
|
#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"
|
|
|
|
#include "datalink.h"
|
|
|
|
#include "ip.h"
|
1998-02-07 20:50:08 +00:00
|
|
|
|
|
|
|
static const char *PhaseNames[] = {
|
|
|
|
"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)
|
|
|
|
LogPrintf(LogPHASE, "bundle: %s\n", PhaseNames[new]);
|
1998-02-07 20:50:08 +00:00
|
|
|
|
|
|
|
switch (new) {
|
|
|
|
case PHASE_DEAD:
|
|
|
|
bundle->phase = new;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHASE_ESTABLISH:
|
|
|
|
bundle->phase = new;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHASE_AUTHENTICATE:
|
1998-03-01 01:07:49 +00:00
|
|
|
bundle->phase = new;
|
1998-04-03 19:26:02 +00:00
|
|
|
bundle_DisplayPrompt(bundle);
|
1998-02-07 20:50:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PHASE_NETWORK:
|
1998-03-13 21:07:46 +00:00
|
|
|
ipcp_Setup(&bundle->ncp.ipcp);
|
|
|
|
FsmUp(&bundle->ncp.ipcp.fsm);
|
|
|
|
FsmOpen(&bundle->ncp.ipcp.fsm);
|
1998-04-23 21:50:13 +00:00
|
|
|
bundle->phase = new;
|
|
|
|
bundle_DisplayPrompt(bundle);
|
|
|
|
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-04-03 19:26:02 +00:00
|
|
|
bundle_DisplayPrompt(bundle);
|
1998-02-07 20:50:08 +00:00
|
|
|
break;
|
1998-02-02 19:32:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bundle_CleanInterface(const struct bundle *bundle)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct ifreq ifrq;
|
|
|
|
struct ifaliasreq ifra;
|
|
|
|
|
|
|
|
s = ID0socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (s < 0) {
|
|
|
|
LogPrintf(LogERROR, "bundle_CleanInterface: socket(): %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
strncpy(ifrq.ifr_name, bundle->ifname, sizeof ifrq.ifr_name - 1);
|
|
|
|
ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0';
|
|
|
|
while (ID0ioctl(s, SIOCGIFADDR, &ifrq) == 0) {
|
|
|
|
memset(&ifra.ifra_mask, '\0', sizeof ifra.ifra_mask);
|
|
|
|
strncpy(ifra.ifra_name, bundle->ifname, sizeof ifra.ifra_name - 1);
|
|
|
|
ifra.ifra_name[sizeof ifra.ifra_name - 1] = '\0';
|
|
|
|
ifra.ifra_addr = ifrq.ifr_addr;
|
|
|
|
if (ID0ioctl(s, SIOCGIFDSTADDR, &ifrq) < 0) {
|
|
|
|
if (ifra.ifra_addr.sa_family == AF_INET)
|
|
|
|
LogPrintf(LogERROR,
|
|
|
|
"bundle_CleanInterface: Can't get dst for %s on %s !\n",
|
|
|
|
inet_ntoa(((struct sockaddr_in *)&ifra.ifra_addr)->sin_addr),
|
|
|
|
bundle->ifname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ifra.ifra_broadaddr = ifrq.ifr_dstaddr;
|
|
|
|
if (ID0ioctl(s, SIOCDIFADDR, &ifra) < 0) {
|
|
|
|
if (ifra.ifra_addr.sa_family == AF_INET)
|
|
|
|
LogPrintf(LogERROR,
|
|
|
|
"bundle_CleanInterface: Can't delete %s address on %s !\n",
|
|
|
|
inet_ntoa(((struct sockaddr_in *)&ifra.ifra_addr)->sin_addr),
|
|
|
|
bundle->ifname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
static void
|
|
|
|
bundle_Notify(struct bundle *bundle, char c)
|
|
|
|
{
|
|
|
|
if (bundle->notify.fd != -1) {
|
|
|
|
if (write(bundle->notify.fd, &c, 1) == 1)
|
|
|
|
LogPrintf(LogPHASE, "Parent notified of success.\n");
|
|
|
|
else
|
|
|
|
LogPrintf(LogPHASE, "Failed to notify parent of success.\n");
|
|
|
|
close(bundle->notify.fd);
|
|
|
|
bundle->notify.fd = -1;
|
|
|
|
}
|
|
|
|
}
|
1998-04-03 19:21:56 +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
|
1998-04-23 03:23:03 +00:00
|
|
|
* If it's an LCP set our mtu (if we're multilink, add up the link
|
|
|
|
* speeds and set the MRRU).
|
1998-04-10 13:19:23 +00:00
|
|
|
* If it's an NCP, tell our -background parent to go away.
|
1998-04-03 19:21:56 +00:00
|
|
|
* If it's the first NCP, start the idle 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-04-03 19:21:56 +00:00
|
|
|
if (bundle->ncp.mp.active) {
|
|
|
|
int speed;
|
|
|
|
struct datalink *dl;
|
|
|
|
|
|
|
|
for (dl = bundle->links, speed = 0; dl; dl = dl->next)
|
|
|
|
speed += modem_Speed(dl->physical);
|
|
|
|
if (speed)
|
1998-04-23 03:23:03 +00:00
|
|
|
tun_configure(bundle, bundle->ncp.mp.peer_mrru, speed);
|
1998-04-03 19:21:56 +00:00
|
|
|
} else
|
|
|
|
tun_configure(bundle, fsm2lcp(fp)->his_mru,
|
|
|
|
modem_Speed(link2physical(fp->link)));
|
|
|
|
} else if (fp->proto == PROTO_IPCP) {
|
1998-03-09 19:26:41 +00:00
|
|
|
bundle_StartIdleTimer(bundle);
|
1998-03-25 18:38:59 +00:00
|
|
|
bundle_Notify(bundle, EX_NORMAL);
|
1998-03-09 19:26:41 +00:00
|
|
|
}
|
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.
|
1998-04-03 19:21:56 +00:00
|
|
|
* If it's our last NCP *OR* LCP, enter TERMINATE phase.
|
|
|
|
* If it's an LCP and we're in multilink mode, adjust our tun speed.
|
1998-02-27 01:22:39 +00:00
|
|
|
*/
|
1998-03-09 19:26:41 +00:00
|
|
|
|
|
|
|
struct bundle *bundle = (struct bundle *)v;
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
if (fp->proto == PROTO_IPCP) {
|
1998-03-09 19:26:41 +00:00
|
|
|
bundle_StopIdleTimer(bundle);
|
1998-04-03 19:21:56 +00:00
|
|
|
} else if (fp->proto == PROTO_LCP) {
|
|
|
|
int speed, others_active;
|
|
|
|
struct datalink *dl;
|
|
|
|
|
|
|
|
others_active = 0;
|
|
|
|
for (dl = bundle->links, speed = 0; dl; dl = dl->next)
|
|
|
|
if (fp != &dl->physical->link.lcp.fsm &&
|
|
|
|
dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP) {
|
|
|
|
speed += modem_Speed(dl->physical);
|
|
|
|
others_active++;
|
|
|
|
}
|
|
|
|
if (bundle->ncp.mp.active && speed)
|
|
|
|
tun_configure(bundle, bundle->ncp.mp.link.lcp.his_mru, speed);
|
|
|
|
|
|
|
|
if (!others_active)
|
|
|
|
bundle_NewPhase(bundle, PHASE_TERMINATE);
|
|
|
|
}
|
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)
|
|
|
|
*
|
|
|
|
* If it's the last LCP, FsmDown all NCPs
|
1998-04-03 19:21:56 +00:00
|
|
|
* If it's the last NCP, FsmClose all LCPs
|
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
|
|
|
|
1998-03-13 21:07:14 +00:00
|
|
|
if (fp->proto == PROTO_IPCP) {
|
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)
|
|
|
|
datalink_Close(dl, 0);
|
|
|
|
FsmDown(fp);
|
|
|
|
FsmClose(fp);
|
|
|
|
} else if (fp->proto == PROTO_LCP) {
|
|
|
|
int others_active;
|
1998-02-27 01:22:39 +00:00
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
others_active = 0;
|
1998-02-27 01:22:39 +00:00
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
1998-04-03 19:21:56 +00:00
|
|
|
if (fp != &dl->physical->link.lcp.fsm &&
|
|
|
|
dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP)
|
|
|
|
others_active++;
|
1998-03-13 21:07:14 +00:00
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
if (!others_active) {
|
|
|
|
FsmDown(&bundle->ncp.ipcp.fsm);
|
|
|
|
FsmClose(&bundle->ncp.ipcp.fsm); /* ST_INITIAL please */
|
|
|
|
}
|
|
|
|
}
|
1998-02-27 01:22:39 +00:00
|
|
|
}
|
|
|
|
|
1998-02-02 19:32:16 +00:00
|
|
|
int
|
|
|
|
bundle_LinkIsUp(const struct bundle *bundle)
|
|
|
|
{
|
1998-03-13 21:07:46 +00:00
|
|
|
return bundle->ncp.ipcp.fsm.state == ST_OPENED;
|
1998-02-02 19:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-02-16 00:01:12 +00:00
|
|
|
bundle_Close(struct bundle *bundle, const char *name, int staydown)
|
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-04-30 23:53:56 +00:00
|
|
|
* If name == NULL or name is the last datalink, FsmClose all NCPs
|
|
|
|
* (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
|
|
|
if (bundle->phase == PHASE_TERMINATE || bundle->phase == PHASE_DEAD)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (staydown)
|
1998-02-18 00:27:49 +00:00
|
|
|
datalink_StayDown(dl);
|
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) {
|
|
|
|
LogPrintf(LogWARN, "%s: Invalid datalink name\n", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!others_active) {
|
|
|
|
if (bundle->ncp.ipcp.fsm.state > ST_CLOSED ||
|
|
|
|
bundle->ncp.ipcp.fsm.state == ST_STARTING)
|
1998-03-13 21:07:46 +00:00
|
|
|
FsmClose(&bundle->ncp.ipcp.fsm);
|
1998-04-03 19:21:56 +00:00
|
|
|
else {
|
|
|
|
if (bundle->ncp.ipcp.fsm.state > ST_INITIAL) {
|
|
|
|
FsmClose(&bundle->ncp.ipcp.fsm);
|
|
|
|
FsmDown(&bundle->ncp.ipcp.fsm);
|
|
|
|
}
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
datalink_Close(dl, staydown);
|
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)
|
|
|
|
datalink_Close(this_dl, staydown);
|
1998-02-02 19:32:16 +00:00
|
|
|
}
|
|
|
|
|
1998-03-20 19:48:28 +00:00
|
|
|
static int
|
|
|
|
bundle_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
|
|
|
|
{
|
|
|
|
struct bundle *bundle = descriptor2bundle(d);
|
|
|
|
struct datalink *dl;
|
1998-04-03 19:26:02 +00:00
|
|
|
struct descriptor *desc;
|
1998-03-20 19:48:28 +00:00
|
|
|
int result;
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
result += descriptor_UpdateSet(&dl->desc, r, w, e, n);
|
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
for (desc = bundle->desc.next; desc; desc = desc->next)
|
|
|
|
result += descriptor_UpdateSet(desc, r, w, e, n);
|
|
|
|
|
1998-03-20 19:48:28 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bundle_IsSet(struct descriptor *d, const fd_set *fdset)
|
|
|
|
{
|
|
|
|
struct bundle *bundle = descriptor2bundle(d);
|
|
|
|
struct datalink *dl;
|
1998-04-03 19:26:02 +00:00
|
|
|
struct descriptor *desc;
|
1998-03-20 19:48:28 +00:00
|
|
|
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (descriptor_IsSet(&dl->desc, fdset))
|
|
|
|
return 1;
|
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
for (desc = bundle->desc.next; desc; desc = desc->next)
|
|
|
|
if (descriptor_IsSet(desc, fdset))
|
|
|
|
return 1;
|
|
|
|
|
1998-03-20 19:48:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bundle_DescriptorRead(struct descriptor *d, struct bundle *bundle,
|
|
|
|
const fd_set *fdset)
|
|
|
|
{
|
|
|
|
struct datalink *dl;
|
1998-04-03 19:26:02 +00:00
|
|
|
struct descriptor *desc;
|
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
|
|
|
|
|
|
|
for (desc = bundle->desc.next; desc; desc = desc->next)
|
|
|
|
if (descriptor_IsSet(desc, fdset))
|
|
|
|
descriptor_Read(desc, bundle, fdset);
|
1998-03-20 19:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bundle_DescriptorWrite(struct descriptor *d, struct bundle *bundle,
|
|
|
|
const fd_set *fdset)
|
|
|
|
{
|
|
|
|
struct datalink *dl;
|
1998-04-03 19:26:02 +00:00
|
|
|
struct descriptor *desc;
|
1998-03-20 19:48:28 +00:00
|
|
|
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (descriptor_IsSet(&dl->desc, fdset))
|
|
|
|
descriptor_Write(&dl->desc, bundle, fdset);
|
1998-04-03 19:26:02 +00:00
|
|
|
|
|
|
|
for (desc = bundle->desc.next; desc; desc = desc->next)
|
|
|
|
if (descriptor_IsSet(desc, fdset))
|
|
|
|
descriptor_Write(desc, bundle, fdset);
|
1998-03-20 19:48:28 +00:00
|
|
|
}
|
|
|
|
|
1998-02-02 19:32:16 +00:00
|
|
|
|
|
|
|
struct bundle *
|
1998-04-10 13:19:23 +00:00
|
|
|
bundle_Create(const char *prefix, struct prompt *prompt, int type)
|
1998-02-02 19:32:16 +00:00
|
|
|
{
|
|
|
|
int s, enoentcount, err;
|
|
|
|
struct ifreq ifrq;
|
|
|
|
static struct bundle bundle; /* there can be only one */
|
|
|
|
|
|
|
|
if (bundle.ifname != NULL) { /* Already allocated ! */
|
|
|
|
LogPrintf(LogERROR, "bundle_Create: There's only one BUNDLE !\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ENOENT;
|
|
|
|
enoentcount = 0;
|
1998-04-27 01:40:38 +00:00
|
|
|
for (bundle.unit = 0; ; bundle.unit++) {
|
1998-02-02 19:32:16 +00:00
|
|
|
snprintf(bundle.dev, sizeof bundle.dev, "%s%d", prefix, bundle.unit);
|
|
|
|
bundle.tun_fd = ID0open(bundle.dev, O_RDWR);
|
|
|
|
if (bundle.tun_fd >= 0)
|
|
|
|
break;
|
1998-04-27 01:40:38 +00:00
|
|
|
else if (errno == ENXIO) {
|
1998-02-02 19:32:16 +00:00
|
|
|
err = errno;
|
1998-04-27 01:40:38 +00:00
|
|
|
break;
|
1998-02-02 19:32:16 +00:00
|
|
|
} else if (errno == ENOENT) {
|
|
|
|
if (++enoentcount > 2)
|
1998-04-27 01:40:38 +00:00
|
|
|
break;
|
1998-02-02 19:32:16 +00:00
|
|
|
} else
|
|
|
|
err = errno;
|
|
|
|
}
|
|
|
|
|
1998-04-27 01:40:38 +00:00
|
|
|
if (bundle.tun_fd < 0) {
|
|
|
|
LogPrintf(LogWARN, "No available tunnel devices found (%s).\n",
|
|
|
|
strerror(err));
|
1998-02-02 19:32:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogSetTun(bundle.unit);
|
|
|
|
|
|
|
|
s = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (s < 0) {
|
|
|
|
LogPrintf(LogERROR, "bundle_Create: socket(): %s\n", strerror(errno));
|
|
|
|
close(bundle.tun_fd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bundle.ifname = strrchr(bundle.dev, '/');
|
|
|
|
if (bundle.ifname == NULL)
|
|
|
|
bundle.ifname = bundle.dev;
|
|
|
|
else
|
|
|
|
bundle.ifname++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now, bring up the interface.
|
|
|
|
*/
|
|
|
|
memset(&ifrq, '\0', sizeof ifrq);
|
|
|
|
strncpy(ifrq.ifr_name, bundle.ifname, sizeof ifrq.ifr_name - 1);
|
|
|
|
ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0';
|
|
|
|
if (ID0ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) {
|
|
|
|
LogPrintf(LogERROR, "OpenTunnel: ioctl(SIOCGIFFLAGS): %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
close(s);
|
|
|
|
close(bundle.tun_fd);
|
|
|
|
bundle.ifname = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ifrq.ifr_flags |= IFF_UP;
|
|
|
|
if (ID0ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) {
|
|
|
|
LogPrintf(LogERROR, "OpenTunnel: ioctl(SIOCSIFFLAGS): %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
close(s);
|
|
|
|
close(bundle.tun_fd);
|
|
|
|
bundle.ifname = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(s);
|
|
|
|
|
|
|
|
if ((bundle.ifIndex = GetIfIndex(bundle.ifname)) < 0) {
|
|
|
|
LogPrintf(LogERROR, "OpenTunnel: Can't find ifindex.\n");
|
|
|
|
close(bundle.tun_fd);
|
|
|
|
bundle.ifname = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(prompt, "Using interface: %s\n", bundle.ifname);
|
1998-02-02 19:32:16 +00:00
|
|
|
LogPrintf(LogPHASE, "Using interface: %s\n", bundle.ifname);
|
|
|
|
|
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;
|
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
|
|
|
|
1998-03-09 19:26:41 +00:00
|
|
|
bundle.cfg.idle_timeout = NCP_IDLE_TIMEOUT;
|
1998-04-16 00:26:21 +00:00
|
|
|
*bundle.cfg.auth.name = '\0';
|
|
|
|
*bundle.cfg.auth.key = '\0';
|
|
|
|
bundle.cfg.opt = OPT_IDCHECK | OPT_LOOPBACK | OPT_THROUGHPUT | OPT_UTMP;
|
1998-04-23 03:23:03 +00:00
|
|
|
*bundle.cfg.label = '\0';
|
|
|
|
bundle.cfg.mtu = DEF_MTU;
|
1998-04-10 13:19:23 +00:00
|
|
|
bundle.phys_type = type;
|
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) {
|
|
|
|
LogPrintf(LogERROR, "Cannot create data link: %s\n", strerror(errno));
|
1998-02-27 01:22:39 +00:00
|
|
|
close(bundle.tun_fd);
|
|
|
|
bundle.ifname = NULL;
|
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.next = NULL;
|
|
|
|
bundle.desc.UpdateSet = bundle_UpdateSet;
|
|
|
|
bundle.desc.IsSet = bundle_IsSet;
|
|
|
|
bundle.desc.Read = bundle_DescriptorRead;
|
|
|
|
bundle.desc.Write = bundle_DescriptorWrite;
|
|
|
|
|
1998-04-23 03:23:03 +00:00
|
|
|
mp_Init(&bundle.ncp.mp, &bundle);
|
|
|
|
|
|
|
|
/* Send over the first physical link by default */
|
1998-03-13 21:07:46 +00:00
|
|
|
ipcp_Init(&bundle.ncp.ipcp, &bundle, &bundle.links->physical->link,
|
|
|
|
&bundle.fsm);
|
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;
|
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-03-18 23:15:31 +00:00
|
|
|
|
1998-02-27 01:22:39 +00:00
|
|
|
/* Clean out any leftover crud */
|
|
|
|
bundle_CleanInterface(&bundle);
|
|
|
|
|
1998-04-07 23:46:09 +00:00
|
|
|
if (prompt) {
|
|
|
|
/* Retrospectively introduce ourselves to the prompt */
|
|
|
|
prompt->bundle = &bundle;
|
|
|
|
bundle_RegisterDescriptor(&bundle, &prompt->desc);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct ifreq ifrq;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
DeleteIfRoutes(bundle, 1);
|
|
|
|
|
|
|
|
s = ID0socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (s < 0) {
|
|
|
|
LogPrintf(LogERROR, "bundle_DownInterface: socket: %s\n", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&ifrq, '\0', sizeof ifrq);
|
|
|
|
strncpy(ifrq.ifr_name, bundle->ifname, sizeof ifrq.ifr_name - 1);
|
|
|
|
ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0';
|
|
|
|
if (ID0ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) {
|
|
|
|
LogPrintf(LogERROR, "bundle_DownInterface: ioctl(SIOCGIFFLAGS): %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
close(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ifrq.ifr_flags &= ~IFF_UP;
|
|
|
|
if (ID0ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) {
|
|
|
|
LogPrintf(LogERROR, "bundle_DownInterface: ioctl(SIOCSIFFLAGS): %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
close(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
close(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
struct descriptor *desc, *ndesc;
|
|
|
|
|
1998-04-10 13:19:23 +00:00
|
|
|
if (bundle->phys_type & PHYS_DEMAND) {
|
|
|
|
IpcpCleanInterface(&bundle->ncp.ipcp);
|
1998-02-08 19:29:45 +00:00
|
|
|
bundle_DownInterface(bundle);
|
|
|
|
}
|
1998-02-16 00:01:12 +00:00
|
|
|
|
|
|
|
dl = bundle->links;
|
|
|
|
while (dl)
|
|
|
|
dl = datalink_Destroy(dl);
|
|
|
|
|
1998-03-25 18:38:59 +00:00
|
|
|
bundle_Notify(bundle, EX_ERRDEAD);
|
1998-04-03 19:26:02 +00:00
|
|
|
|
|
|
|
desc = bundle->desc.next;
|
|
|
|
while (desc) {
|
|
|
|
ndesc = desc->next;
|
|
|
|
if (desc->type == PROMPT_DESCRIPTOR)
|
|
|
|
prompt_Destroy((struct prompt *)desc, 1);
|
|
|
|
else
|
|
|
|
LogPrintf(LogERROR, "bundle_Destroy: Don't know how to delete descriptor"
|
|
|
|
" type %d\n", desc->type);
|
|
|
|
desc = ndesc;
|
|
|
|
}
|
|
|
|
bundle->desc.next = NULL;
|
1998-02-08 19:29:45 +00:00
|
|
|
bundle->ifname = NULL;
|
|
|
|
}
|
|
|
|
|
1998-02-02 19:32:16 +00:00
|
|
|
struct rtmsg {
|
|
|
|
struct rt_msghdr m_rtm;
|
|
|
|
char m_space[64];
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
1998-02-02 19:33:02 +00:00
|
|
|
bundle_SetRoute(struct bundle *bundle, int cmd, struct in_addr dst,
|
1998-02-02 19:32:16 +00:00
|
|
|
struct in_addr gateway, struct in_addr mask, int bang)
|
|
|
|
{
|
|
|
|
struct rtmsg rtmes;
|
|
|
|
int s, nb, wb;
|
|
|
|
char *cp;
|
|
|
|
const char *cmdstr;
|
|
|
|
struct sockaddr_in rtdata;
|
|
|
|
|
|
|
|
if (bang)
|
|
|
|
cmdstr = (cmd == RTM_ADD ? "Add!" : "Delete!");
|
|
|
|
else
|
|
|
|
cmdstr = (cmd == RTM_ADD ? "Add" : "Delete");
|
|
|
|
s = ID0socket(PF_ROUTE, SOCK_RAW, 0);
|
|
|
|
if (s < 0) {
|
1998-02-08 19:29:45 +00:00
|
|
|
LogPrintf(LogERROR, "bundle_SetRoute: socket(): %s\n", strerror(errno));
|
1998-02-02 19:32:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
memset(&rtmes, '\0', sizeof rtmes);
|
|
|
|
rtmes.m_rtm.rtm_version = RTM_VERSION;
|
|
|
|
rtmes.m_rtm.rtm_type = cmd;
|
|
|
|
rtmes.m_rtm.rtm_addrs = RTA_DST;
|
1998-02-02 19:33:02 +00:00
|
|
|
rtmes.m_rtm.rtm_seq = ++bundle->routing_seq;
|
1998-02-02 19:32:16 +00:00
|
|
|
rtmes.m_rtm.rtm_pid = getpid();
|
|
|
|
rtmes.m_rtm.rtm_flags = RTF_UP | RTF_GATEWAY | RTF_STATIC;
|
|
|
|
|
|
|
|
memset(&rtdata, '\0', sizeof rtdata);
|
1998-04-16 23:06:53 +00:00
|
|
|
rtdata.sin_len = sizeof rtdata;
|
1998-02-02 19:32:16 +00:00
|
|
|
rtdata.sin_family = AF_INET;
|
|
|
|
rtdata.sin_port = 0;
|
|
|
|
rtdata.sin_addr = dst;
|
|
|
|
|
|
|
|
cp = rtmes.m_space;
|
1998-04-16 23:06:53 +00:00
|
|
|
memcpy(cp, &rtdata, rtdata.sin_len);
|
|
|
|
cp += rtdata.sin_len;
|
1998-04-25 10:49:52 +00:00
|
|
|
if (cmd == RTM_ADD) {
|
1998-02-02 19:32:16 +00:00
|
|
|
if (gateway.s_addr == INADDR_ANY) {
|
|
|
|
/* Add a route through the interface */
|
|
|
|
struct sockaddr_dl dl;
|
|
|
|
const char *iname;
|
|
|
|
int ilen;
|
|
|
|
|
|
|
|
iname = Index2Nam(bundle->ifIndex);
|
|
|
|
ilen = strlen(iname);
|
|
|
|
dl.sdl_len = sizeof dl - sizeof dl.sdl_data + ilen;
|
|
|
|
dl.sdl_family = AF_LINK;
|
|
|
|
dl.sdl_index = bundle->ifIndex;
|
|
|
|
dl.sdl_type = 0;
|
|
|
|
dl.sdl_nlen = ilen;
|
|
|
|
dl.sdl_alen = 0;
|
|
|
|
dl.sdl_slen = 0;
|
|
|
|
strncpy(dl.sdl_data, iname, sizeof dl.sdl_data);
|
|
|
|
memcpy(cp, &dl, dl.sdl_len);
|
|
|
|
cp += dl.sdl_len;
|
|
|
|
rtmes.m_rtm.rtm_addrs |= RTA_GATEWAY;
|
|
|
|
} else {
|
|
|
|
rtdata.sin_addr = gateway;
|
1998-04-16 23:06:53 +00:00
|
|
|
memcpy(cp, &rtdata, rtdata.sin_len);
|
|
|
|
cp += rtdata.sin_len;
|
1998-02-02 19:32:16 +00:00
|
|
|
rtmes.m_rtm.rtm_addrs |= RTA_GATEWAY;
|
|
|
|
}
|
1998-04-25 10:49:52 +00:00
|
|
|
}
|
1998-02-02 19:32:16 +00:00
|
|
|
|
|
|
|
if (dst.s_addr == INADDR_ANY)
|
|
|
|
mask.s_addr = INADDR_ANY;
|
|
|
|
|
|
|
|
if (cmd == RTM_ADD || dst.s_addr == INADDR_ANY) {
|
|
|
|
rtdata.sin_addr = mask;
|
1998-04-16 23:06:53 +00:00
|
|
|
memcpy(cp, &rtdata, rtdata.sin_len);
|
|
|
|
cp += rtdata.sin_len;
|
1998-02-02 19:32:16 +00:00
|
|
|
rtmes.m_rtm.rtm_addrs |= RTA_NETMASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nb = cp - (char *) &rtmes;
|
|
|
|
rtmes.m_rtm.rtm_msglen = nb;
|
|
|
|
wb = ID0write(s, &rtmes, nb);
|
|
|
|
if (wb < 0) {
|
1998-02-08 19:29:45 +00:00
|
|
|
LogPrintf(LogTCPIP, "bundle_SetRoute failure:\n");
|
1998-04-16 23:06:53 +00:00
|
|
|
LogPrintf(LogTCPIP, "bundle_SetRoute: Cmd = %s\n", cmdstr);
|
1998-02-08 19:29:45 +00:00
|
|
|
LogPrintf(LogTCPIP, "bundle_SetRoute: Dst = %s\n", inet_ntoa(dst));
|
|
|
|
LogPrintf(LogTCPIP, "bundle_SetRoute: Gateway = %s\n", inet_ntoa(gateway));
|
|
|
|
LogPrintf(LogTCPIP, "bundle_SetRoute: Mask = %s\n", inet_ntoa(mask));
|
1998-02-02 19:32:16 +00:00
|
|
|
failed:
|
|
|
|
if (cmd == RTM_ADD && (rtmes.m_rtm.rtm_errno == EEXIST ||
|
1998-04-25 10:49:52 +00:00
|
|
|
(rtmes.m_rtm.rtm_errno == 0 && errno == EEXIST))) {
|
1998-02-02 19:32:16 +00:00
|
|
|
if (!bang)
|
|
|
|
LogPrintf(LogWARN, "Add route failed: %s already exists\n",
|
|
|
|
inet_ntoa(dst));
|
|
|
|
else {
|
|
|
|
rtmes.m_rtm.rtm_type = cmd = RTM_CHANGE;
|
|
|
|
if ((wb = ID0write(s, &rtmes, nb)) < 0)
|
|
|
|
goto failed;
|
|
|
|
}
|
1998-04-25 10:49:52 +00:00
|
|
|
} else if (cmd == RTM_DELETE &&
|
1998-02-02 19:32:16 +00:00
|
|
|
(rtmes.m_rtm.rtm_errno == ESRCH ||
|
|
|
|
(rtmes.m_rtm.rtm_errno == 0 && errno == ESRCH))) {
|
|
|
|
if (!bang)
|
|
|
|
LogPrintf(LogWARN, "Del route failed: %s: Non-existent\n",
|
|
|
|
inet_ntoa(dst));
|
|
|
|
} else if (rtmes.m_rtm.rtm_errno == 0)
|
|
|
|
LogPrintf(LogWARN, "%s route failed: %s: errno: %s\n", cmdstr,
|
|
|
|
inet_ntoa(dst), strerror(errno));
|
|
|
|
else
|
|
|
|
LogPrintf(LogWARN, "%s route failed: %s: %s\n",
|
|
|
|
cmdstr, inet_ntoa(dst), strerror(rtmes.m_rtm.rtm_errno));
|
|
|
|
}
|
|
|
|
LogPrintf(LogDEBUG, "wrote %d: cmd = %s, dst = %x, gateway = %x\n",
|
1998-04-19 23:09:03 +00:00
|
|
|
wb, cmdstr, (unsigned)dst.s_addr, (unsigned)gateway.s_addr);
|
1998-02-02 19:32:16 +00:00
|
|
|
close(s);
|
|
|
|
}
|
1998-02-06 02:24:29 +00:00
|
|
|
|
1998-02-16 00:01:12 +00:00
|
|
|
void
|
|
|
|
bundle_LinkClosed(struct bundle *bundle, struct datalink *dl)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Our datalink has closed.
|
1998-04-10 13:19:23 +00:00
|
|
|
* UpdateSet() will remove 1OFF and STDIN links.
|
1998-04-03 19:21:56 +00:00
|
|
|
* If it's the last data link, enter phase DEAD.
|
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-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-04-10 13:19:23 +00:00
|
|
|
if (dl->physical->type != PHYS_DEMAND)
|
1998-04-03 19:21:56 +00:00
|
|
|
bundle_DownInterface(bundle);
|
1998-04-16 21:19:05 +00:00
|
|
|
if (bundle->ncp.ipcp.fsm.state > ST_CLOSED ||
|
|
|
|
bundle->ncp.ipcp.fsm.state == ST_STARTING) {
|
|
|
|
FsmDown(&bundle->ncp.ipcp.fsm);
|
|
|
|
FsmClose(&bundle->ncp.ipcp.fsm); /* ST_INITIAL please */
|
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
bundle_NewPhase(bundle, PHASE_DEAD);
|
1998-04-03 19:26:02 +00:00
|
|
|
bundle_DisplayPrompt(bundle);
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
1998-02-07 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
1998-02-16 00:01:12 +00:00
|
|
|
void
|
1998-04-10 13:19:23 +00:00
|
|
|
bundle_Open(struct bundle *bundle, const char *name, int mask)
|
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-04-10 13:19:23 +00:00
|
|
|
if (mask & dl->physical->type)
|
|
|
|
datalink_Up(dl, 1, 1);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
bundle_FillQueues(struct bundle *bundle)
|
|
|
|
{
|
1998-04-03 19:21:56 +00:00
|
|
|
int total;
|
1998-02-16 00:01:12 +00:00
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
if (bundle->ncp.mp.active) {
|
|
|
|
total = mp_FillQueues(bundle);
|
|
|
|
} else {
|
1998-04-03 19:26:29 +00:00
|
|
|
total = link_QueueLen(&bundle->links->physical->link);
|
|
|
|
if (total == 0 && bundle->links->physical->out == NULL)
|
|
|
|
total = IpFlushPacket(&bundle->links->physical->link, bundle);
|
1998-02-16 00:01:12 +00:00
|
|
|
}
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
return total + ip_QueueLen();
|
1998-02-16 00:01:12 +00:00
|
|
|
}
|
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;
|
1998-02-17 19:28:01 +00:00
|
|
|
|
1998-04-24 19:16:15 +00:00
|
|
|
for (dl = arg->bundle->links; dl; dl = dl->next)
|
|
|
|
prompt_Printf(arg->prompt, "Name: %s [%s]\n", dl->name, datalink_State(dl));
|
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-04-24 19:16:15 +00:00
|
|
|
prompt_Printf(arg->prompt, " Interface: %s\n", arg->bundle->dev);
|
1998-04-11 21:50:47 +00:00
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, "\nDefaults:\n");
|
1998-04-24 19:16:15 +00:00
|
|
|
prompt_Printf(arg->prompt, " Label: %s\n", arg->bundle->cfg.label);
|
1998-04-20 00:21:24 +00:00
|
|
|
prompt_Printf(arg->prompt, " Auth name: %s\n", arg->bundle->cfg.auth.name);
|
1998-04-11 21:50:47 +00:00
|
|
|
prompt_Printf(arg->prompt, " Idle Timer: ");
|
|
|
|
if (arg->bundle->cfg.idle_timeout) {
|
|
|
|
prompt_Printf(arg->prompt, "%ds", arg->bundle->cfg.idle_timeout);
|
|
|
|
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");
|
1998-04-23 18:56:21 +00:00
|
|
|
prompt_Printf(arg->prompt, " MTU: ");
|
|
|
|
if (arg->bundle->cfg.mtu)
|
|
|
|
prompt_Printf(arg->prompt, "%d\n", arg->bundle->cfg.mtu);
|
|
|
|
else
|
|
|
|
prompt_Printf(arg->prompt, "unspecified\n");
|
1998-04-11 21:50:47 +00:00
|
|
|
|
1998-04-16 00:26:21 +00:00
|
|
|
prompt_Printf(arg->prompt, " ID check: %s\n",
|
|
|
|
optval(arg->bundle, OPT_IDCHECK));
|
|
|
|
prompt_Printf(arg->prompt, " Loopback: %s\n",
|
|
|
|
optval(arg->bundle, OPT_LOOPBACK));
|
|
|
|
prompt_Printf(arg->prompt, " PasswdAuth: %s\n",
|
|
|
|
optval(arg->bundle, OPT_PASSWDAUTH));
|
|
|
|
prompt_Printf(arg->prompt, " Proxy: %s\n",
|
|
|
|
optval(arg->bundle, OPT_PROXY));
|
|
|
|
prompt_Printf(arg->prompt, " Throughput: %s\n",
|
|
|
|
optval(arg->bundle, OPT_THROUGHPUT));
|
|
|
|
prompt_Printf(arg->prompt, " Utmp: %s\n",
|
|
|
|
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;
|
|
|
|
|
1998-03-18 23:15:31 +00:00
|
|
|
bundle->idle.done = 0;
|
1998-04-18 23:17:26 +00:00
|
|
|
LogPrintf(LogPHASE, "Idle timer expired.\n");
|
1998-03-09 19:26:41 +00:00
|
|
|
bundle_Close(bundle, NULL, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start Idle timer. If timeout is reached, we call bundle_Close() to
|
|
|
|
* close LCP and link.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
bundle_StartIdleTimer(struct bundle *bundle)
|
|
|
|
{
|
1998-04-16 22:11:46 +00:00
|
|
|
if (!(bundle->phys_type & (PHYS_DEDICATED|PHYS_PERM))) {
|
1998-03-18 23:15:31 +00:00
|
|
|
StopTimer(&bundle->idle.timer);
|
1998-04-16 22:11:46 +00:00
|
|
|
if (bundle->cfg.idle_timeout) {
|
|
|
|
bundle->idle.timer.func = bundle_IdleTimeout;
|
|
|
|
bundle->idle.timer.name = "idle";
|
|
|
|
bundle->idle.timer.load = bundle->cfg.idle_timeout * SECTICKS;
|
|
|
|
bundle->idle.timer.arg = bundle;
|
|
|
|
StartTimer(&bundle->idle.timer);
|
|
|
|
bundle->idle.done = time(NULL) + bundle->cfg.idle_timeout;
|
|
|
|
}
|
1998-03-09 19:26:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_SetIdleTimer(struct bundle *bundle, int value)
|
|
|
|
{
|
|
|
|
bundle->cfg.idle_timeout = value;
|
|
|
|
if (bundle_LinkIsUp(bundle))
|
|
|
|
bundle_StartIdleTimer(bundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_StopIdleTimer(struct bundle *bundle)
|
|
|
|
{
|
1998-03-18 23:15:31 +00:00
|
|
|
StopTimer(&bundle->idle.timer);
|
1998-04-07 01:49:24 +00:00
|
|
|
bundle->idle.done = 0;
|
1998-03-09 19:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
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
|
|
|
|
|
|
|
int
|
|
|
|
bundle_IsDead(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
return !bundle->links || (bundle->phase == PHASE_DEAD && bundle->CleaningUp);
|
|
|
|
}
|
1998-04-03 19:26:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
bundle_RegisterDescriptor(struct bundle *bundle, struct descriptor *d)
|
|
|
|
{
|
|
|
|
d->next = bundle->desc.next;
|
|
|
|
bundle->desc.next = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_UnRegisterDescriptor(struct bundle *bundle, struct descriptor *d)
|
|
|
|
{
|
|
|
|
struct descriptor **desc;
|
|
|
|
|
|
|
|
for (desc = &bundle->desc.next; *desc; desc = &(*desc)->next)
|
|
|
|
if (*desc == d) {
|
|
|
|
*desc = d->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_DelPromptDescriptors(struct bundle *bundle, struct server *s)
|
|
|
|
{
|
|
|
|
struct descriptor **desc;
|
|
|
|
struct prompt *p;
|
|
|
|
|
|
|
|
desc = &bundle->desc.next;
|
|
|
|
while (*desc) {
|
|
|
|
if ((*desc)->type == PROMPT_DESCRIPTOR) {
|
|
|
|
p = (struct prompt *)*desc;
|
|
|
|
if (p->owner == s) {
|
|
|
|
prompt_Destroy(p, 1);
|
|
|
|
desc = &bundle->desc.next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
desc = &(*desc)->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_DisplayPrompt(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
struct descriptor **desc;
|
|
|
|
|
|
|
|
for (desc = &bundle->desc.next; *desc; desc = &(*desc)->next)
|
|
|
|
if ((*desc)->type == PROMPT_DESCRIPTOR)
|
|
|
|
prompt_Required((struct prompt *)*desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_WriteTermPrompt(struct bundle *bundle, struct datalink *dl,
|
|
|
|
const char *data, int len)
|
|
|
|
{
|
|
|
|
struct descriptor *desc;
|
|
|
|
struct prompt *p;
|
|
|
|
|
|
|
|
for (desc = bundle->desc.next; desc; desc = desc->next)
|
|
|
|
if (desc->type == PROMPT_DESCRIPTOR) {
|
|
|
|
p = (struct prompt *)desc;
|
|
|
|
if (prompt_IsTermMode(p, dl))
|
1998-04-04 13:01:19 +00:00
|
|
|
prompt_Printf(p, "%.*s", len, data);
|
1998-04-03 19:26:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_SetTtyCommandMode(struct bundle *bundle, struct datalink *dl)
|
|
|
|
{
|
|
|
|
struct descriptor *desc;
|
|
|
|
struct prompt *p;
|
|
|
|
|
|
|
|
for (desc = bundle->desc.next; desc; desc = desc->next)
|
|
|
|
if (desc->type == PROMPT_DESCRIPTOR) {
|
|
|
|
p = (struct prompt *)desc;
|
|
|
|
if (prompt_IsTermMode(p, dl))
|
|
|
|
prompt_TtyCommandMode(p);
|
|
|
|
}
|
|
|
|
}
|
1998-04-10 13:19:23 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
bundle_GenPhysType(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
struct datalink *dl;
|
|
|
|
|
|
|
|
bundle->phys_type = 0;
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
bundle->phys_type |= dl->physical->type;
|
|
|
|
}
|
|
|
|
|
1998-04-05 22:48:25 +00:00
|
|
|
void
|
|
|
|
bundle_DatalinkClone(struct bundle *bundle, struct datalink *dl,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct datalink *ndl = datalink_Clone(dl, name);
|
|
|
|
|
|
|
|
ndl->next = dl->next;
|
|
|
|
dl->next = ndl;
|
1998-04-10 13:19:23 +00:00
|
|
|
bundle_GenPhysType(bundle);
|
1998-04-05 22:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_DatalinkRemove(struct bundle *bundle, struct datalink *dl)
|
|
|
|
{
|
|
|
|
struct datalink **dlp;
|
|
|
|
|
|
|
|
if (dl->state == DATALINK_CLOSED)
|
|
|
|
for (dlp = &bundle->links; *dlp; dlp = &(*dlp)->next)
|
|
|
|
if (*dlp == dl) {
|
|
|
|
*dlp = datalink_Destroy(dl);
|
|
|
|
break;
|
|
|
|
}
|
1998-04-10 13:19:23 +00:00
|
|
|
bundle_GenPhysType(bundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bundle_CleanDatalinks(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
struct datalink **dlp = &bundle->links;
|
|
|
|
|
|
|
|
while (*dlp)
|
|
|
|
if ((*dlp)->state == DATALINK_CLOSED &&
|
1998-04-30 23:53:56 +00:00
|
|
|
(*dlp)->physical->type & (PHYS_DIRECT|PHYS_1OFF))
|
1998-04-10 13:19:23 +00:00
|
|
|
*dlp = datalink_Destroy(*dlp);
|
|
|
|
else
|
|
|
|
dlp = &(*dlp)->next;
|
|
|
|
bundle_GenPhysType(bundle);
|
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
|
|
|
|
|
|
|
void
|
1998-04-30 23:53:56 +00:00
|
|
|
bundle_ReceiveDatalink(struct bundle *bundle, int fd)
|
1998-04-28 01:25:46 +00:00
|
|
|
{
|
1998-04-30 23:53:56 +00:00
|
|
|
struct datalink *dl, *ndl;
|
|
|
|
u_char *buf;
|
|
|
|
int get, got, vlen;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We expect:
|
|
|
|
* .---------.---------.--------------.
|
|
|
|
* | ver len | Version | datalink len |
|
|
|
|
* `---------'---------'--------------'
|
|
|
|
* We then pass the rest of the stream to datalink.
|
|
|
|
*/
|
|
|
|
|
|
|
|
LogPrintf(LogPHASE, "Receiving datalink\n");
|
|
|
|
|
|
|
|
vlen = strlen(Version);
|
|
|
|
get = sizeof(int) * 2 + vlen;
|
|
|
|
buf = (u_char *)malloc(get);
|
|
|
|
got = fullread(fd, buf, get);
|
|
|
|
if (got != get) {
|
|
|
|
LogPrintf(LogWARN, "Cannot receive datalink header"
|
|
|
|
" (got %d bytes, not %d)\n", got, get);
|
|
|
|
close(fd);
|
|
|
|
free(buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*(int *)buf != vlen || *(int *)(buf + sizeof(int) + vlen) != sizeof *dl ||
|
|
|
|
memcmp(buf + sizeof(int), Version, vlen)) {
|
|
|
|
LogPrintf(LogWARN, "Cannot receive datalink, incorrect version\n");
|
|
|
|
close(fd);
|
|
|
|
free(buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
ndl = datalink_FromBinary(bundle, fd);
|
|
|
|
if (ndl) {
|
|
|
|
/* Make sure the name is unique ! */
|
|
|
|
do {
|
|
|
|
for (dl = bundle->links; dl; dl = dl->next)
|
|
|
|
if (!strcasecmp(ndl->name, dl->name)) {
|
|
|
|
datalink_Rename(ndl);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (dl);
|
|
|
|
|
|
|
|
ndl->next = bundle->links;
|
|
|
|
bundle->links = ndl;
|
|
|
|
bundle_GenPhysType(bundle);
|
|
|
|
LogPrintf(LogPHASE, "%s: Created in %s state\n",
|
|
|
|
ndl->name, datalink_State(ndl));
|
|
|
|
datalink_AuthOk(ndl);
|
|
|
|
}
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-01 19:20:09 +00:00
|
|
|
bundle_SendDatalink(struct datalink *dl, int ppp_fd)
|
1998-04-28 01:25:46 +00:00
|
|
|
{
|
1998-05-01 19:20:09 +00:00
|
|
|
int len, link_fd, err, nfd, flags;
|
1998-04-30 23:53:56 +00:00
|
|
|
struct datalink **pdl;
|
|
|
|
struct bundle *bundle = dl->bundle;
|
|
|
|
char procname[100];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We send:
|
|
|
|
* .---------.---------.--------------.
|
|
|
|
* | ver len | Version | datalink len |
|
|
|
|
* `---------'---------'--------------'
|
|
|
|
* We then pass the rest of the stream to datalink.
|
|
|
|
*/
|
|
|
|
|
|
|
|
LogPrintf(LogPHASE, "Transmitting datalink %s\n", dl->name);
|
|
|
|
|
|
|
|
/* First, un-hook the datalink */
|
|
|
|
for (pdl = &bundle->links; *pdl; pdl = &(*pdl)->next)
|
|
|
|
if (*pdl == dl) {
|
|
|
|
*pdl = dl->next;
|
|
|
|
dl->next = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write our bit of the data */
|
|
|
|
err = 0;
|
|
|
|
len = strlen(Version);
|
1998-05-01 19:20:09 +00:00
|
|
|
if (write(ppp_fd, &len, sizeof len) != sizeof len)
|
1998-04-30 23:53:56 +00:00
|
|
|
err++;
|
1998-05-01 19:20:09 +00:00
|
|
|
if (write(ppp_fd, Version, len) != len)
|
1998-04-30 23:53:56 +00:00
|
|
|
err++;
|
|
|
|
len = sizeof(struct datalink);
|
1998-05-01 19:20:09 +00:00
|
|
|
if (write(ppp_fd, &len, sizeof len) != sizeof len)
|
1998-04-30 23:53:56 +00:00
|
|
|
err++;
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
LogPrintf(LogERROR, "Failed sending version\n");
|
1998-05-01 19:20:09 +00:00
|
|
|
close(ppp_fd);
|
|
|
|
ppp_fd = -1;
|
1998-04-30 23:53:56 +00:00
|
|
|
}
|
|
|
|
|
1998-05-01 19:20:09 +00:00
|
|
|
link_fd = datalink_ToBinary(dl, ppp_fd);
|
1998-04-30 23:53:56 +00:00
|
|
|
|
|
|
|
if (link_fd != -1) {
|
|
|
|
switch (fork()) {
|
|
|
|
case 0:
|
1998-05-01 19:20:09 +00:00
|
|
|
TermTimerService();
|
|
|
|
|
|
|
|
ppp_fd = fcntl(ppp_fd, F_DUPFD, 3);
|
|
|
|
link_fd = fcntl(link_fd, F_DUPFD, 3);
|
|
|
|
nfd = dup2(open(_PATH_DEVNULL, O_WRONLY), STDERR_FILENO);
|
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
setsid();
|
|
|
|
setuid(geteuid());
|
1998-05-01 19:20:09 +00:00
|
|
|
|
|
|
|
flags = fcntl(ppp_fd, F_GETFL, 0);
|
|
|
|
fcntl(ppp_fd, F_SETFL, flags & ~O_NONBLOCK);
|
|
|
|
flags = fcntl(link_fd, F_GETFL, 0);
|
|
|
|
fcntl(link_fd, F_SETFL, flags & ~O_NONBLOCK);
|
|
|
|
|
|
|
|
switch (fork()) {
|
|
|
|
case 0:
|
|
|
|
dup2(ppp_fd, STDIN_FILENO);
|
|
|
|
dup2(link_fd, STDOUT_FILENO);
|
|
|
|
snprintf(procname, sizeof procname, "%s -> %s",
|
|
|
|
dl->name, *dl->physical->name.base ?
|
|
|
|
dl->physical->name.base : "network");
|
|
|
|
execl(CATPROG, procname, NULL);
|
|
|
|
LogPrintf(LogERROR, "exec: %s: %s\n", CATPROG, strerror(errno));
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dup2(link_fd, STDIN_FILENO);
|
|
|
|
dup2(ppp_fd, STDOUT_FILENO);
|
|
|
|
snprintf(procname, sizeof procname, "%s <- %s",
|
|
|
|
dl->name, *dl->physical->name.base ?
|
|
|
|
dl->physical->name.base : "network");
|
|
|
|
execl(CATPROG, procname, NULL);
|
|
|
|
LogPrintf(LogERROR, "exec: %s: %s\n", CATPROG, strerror(errno));
|
|
|
|
break;
|
|
|
|
}
|
1998-04-30 23:53:56 +00:00
|
|
|
exit(1);
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
LogPrintf(LogERROR, "fork: %s\n", strerror(errno));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-04-28 01:25:46 +00:00
|
|
|
}
|