o Use two `cat' processes to connect the modem to an
already-running ppp. Suggested by: Garrett Wollman <wollman@khavrinen.lcs.mit.edu> o Use _PATH_DEVNULL rather than "/dev/null" o Be more paranoid about nuking running timers when transferring links.
This commit is contained in:
parent
b10a02ddff
commit
47723d29e5
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: bundle.c,v 1.1.2.64 1998/04/28 01:25:04 brian Exp $
|
||||
* $Id: bundle.c,v 1.1.2.65 1998/04/30 23:53:21 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -40,6 +40,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -1143,9 +1144,9 @@ bundle_ReceiveDatalink(struct bundle *bundle, int fd)
|
||||
}
|
||||
|
||||
void
|
||||
bundle_SendDatalink(struct datalink *dl, int fd)
|
||||
bundle_SendDatalink(struct datalink *dl, int ppp_fd)
|
||||
{
|
||||
int len, link_fd, err;
|
||||
int len, link_fd, err, nfd, flags;
|
||||
struct datalink **pdl;
|
||||
struct bundle *bundle = dl->bundle;
|
||||
char procname[100];
|
||||
@ -1171,42 +1172,65 @@ bundle_SendDatalink(struct datalink *dl, int fd)
|
||||
/* Write our bit of the data */
|
||||
err = 0;
|
||||
len = strlen(Version);
|
||||
if (write(fd, &len, sizeof len) != sizeof len)
|
||||
if (write(ppp_fd, &len, sizeof len) != sizeof len)
|
||||
err++;
|
||||
if (write(fd, Version, len) != len)
|
||||
if (write(ppp_fd, Version, len) != len)
|
||||
err++;
|
||||
len = sizeof(struct datalink);
|
||||
if (write(fd, &len, sizeof len) != sizeof len)
|
||||
if (write(ppp_fd, &len, sizeof len) != sizeof len)
|
||||
err++;
|
||||
|
||||
if (err) {
|
||||
LogPrintf(LogERROR, "Failed sending version\n");
|
||||
close(fd);
|
||||
fd = -1;
|
||||
close(ppp_fd);
|
||||
ppp_fd = -1;
|
||||
}
|
||||
|
||||
link_fd = datalink_ToBinary(dl, fd);
|
||||
link_fd = datalink_ToBinary(dl, ppp_fd);
|
||||
|
||||
if (link_fd != -1) {
|
||||
switch (fork()) {
|
||||
case 0:
|
||||
snprintf(procname, sizeof procname, "%s <-> %s",
|
||||
dl->name, *dl->physical->name.base ?
|
||||
dl->physical->name.base : "network");
|
||||
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);
|
||||
|
||||
setsid();
|
||||
dup2(link_fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
setuid(geteuid());
|
||||
/* signals are defaulted by the exec */
|
||||
execlp(PPPMPIPE, procname, NULL);
|
||||
LogPrintf(LogERROR, "exec: %s: %s\n", PPPMPIPE, strerror(errno));
|
||||
|
||||
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;
|
||||
}
|
||||
exit(1);
|
||||
break;
|
||||
case -1:
|
||||
LogPrintf(LogERROR, "fork: %s\n", strerror(errno));
|
||||
/* Fall through */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: command.c,v 1.131.2.73 1998/04/27 01:40:38 brian Exp $
|
||||
* $Id: command.c,v 1.131.2.74 1998/04/30 23:53:29 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
@ -123,7 +123,7 @@
|
||||
#define NEG_DNS 50
|
||||
|
||||
const char Version[] = "2.0-beta";
|
||||
const char VersionDate[] = "$Date: 1998/04/27 01:40:38 $";
|
||||
const char VersionDate[] = "$Date: 1998/04/30 23:53:29 $";
|
||||
|
||||
static int ShowCommand(struct cmdargs const *);
|
||||
static int TerminalCommand(struct cmdargs const *);
|
||||
@ -325,8 +325,9 @@ ShellCommand(struct cmdargs const *arg, int bg)
|
||||
|
||||
if (arg->prompt)
|
||||
fd = arg->prompt->fd_out;
|
||||
else if ((fd = open("/dev/null", O_RDWR)) == -1) {
|
||||
LogPrintf(LogALERT, "Failed to open /dev/null: %s\n", strerror(errno));
|
||||
else if ((fd = open(_PATH_DEVNULL, O_RDWR)) == -1) {
|
||||
LogPrintf(LogALERT, "Failed to open %s: %s\n",
|
||||
_PATH_DEVNULL, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
for (i = 0; i < 3; i++)
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: datalink.c,v 1.1.2.50 1998/04/30 23:52:53 brian Exp $
|
||||
* $Id: datalink.c,v 1.1.2.51 1998/04/30 23:53:32 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -1023,6 +1023,10 @@ datalink_ToBinary(struct datalink *dl, int fd)
|
||||
* `----------'----------'------'--------------'
|
||||
*/
|
||||
|
||||
StopTimer(&dl->dial_timer);
|
||||
StopTimer(&dl->pap.authtimer);
|
||||
StopTimer(&dl->chap.auth.authtimer);
|
||||
|
||||
if (fd != -1) {
|
||||
int err;
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: defs.h,v 1.29.2.14 1998/04/23 03:22:51 brian Exp $
|
||||
* $Id: defs.h,v 1.29.2.15 1998/04/30 23:53:36 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -32,7 +32,7 @@
|
||||
#endif
|
||||
|
||||
#define TUN_PREFIX "/dev/tun" /* tunnel device prefix */
|
||||
#define PPPMPIPE "pppmpipe" /* Multilink pipe program name */
|
||||
#define CATPROG "/bin/cat" /* Multilink pipe program name */
|
||||
|
||||
#define MODEM_SPEED B38400 /* tty speed */
|
||||
#define SERVER_PORT 3000 /* Base server port no. */
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: modem.c,v 1.77.2.59 1998/04/28 01:25:31 brian Exp $
|
||||
* $Id: modem.c,v 1.77.2.60 1998/04/30 23:53:49 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -76,12 +76,6 @@
|
||||
#include "systems.h"
|
||||
|
||||
|
||||
#ifndef O_NONBLOCK
|
||||
#ifdef O_NDELAY
|
||||
#define O_NONBLOCK O_NDELAY
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static void modem_DescriptorWrite(struct descriptor *, struct bundle *,
|
||||
const fd_set *);
|
||||
static void modem_DescriptorRead(struct descriptor *, struct bundle *,
|
||||
@ -997,6 +991,14 @@ modem_ToBinary(struct physical *p, int fd)
|
||||
|
||||
hdlc_StopTimer(&p->hdlc);
|
||||
StopLqrTimer(p);
|
||||
StopTimer(&p->link.lcp.fsm.FsmTimer);
|
||||
StopTimer(&p->link.ccp.fsm.FsmTimer);
|
||||
StopTimer(&p->link.lcp.fsm.OpenTimer);
|
||||
StopTimer(&p->link.ccp.fsm.OpenTimer);
|
||||
StopTimer(&p->link.lcp.fsm.StoppedTimer);
|
||||
StopTimer(&p->link.ccp.fsm.StoppedTimer);
|
||||
StopTimer(&p->Timer);
|
||||
StopTimer(&p->link.throughput.Timer);
|
||||
|
||||
if (fd != -1 && write(fd, p, sizeof *p) != sizeof *p) {
|
||||
LogPrintf(LogERROR, "Failed sending physical\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user