freebsd-dev/usr.sbin/ppp/physical.c
Brian Somers 565e35e50e o Remove the `mode' global - it's now per physical device.
o Shuffle things that live at the datalink level into
  ``show link'' rather than ``show modem''.
o Make both ``show'' commands prettier and more consistent,
  and display carrier status, link type and our name in
  ``show modem''.
o Show redial and reconnect information in ``show link''
  and remove ``show redial'' and ``show reconnect''.
o Down the correct link in bundle_LinkLost().
o Remove stale -direct and -background links at the end
  of our main loop, not when we know they're going.  This
  prevents unexpected pointer-invalidations...
o If we ``set server'' with the same values twice, notice
  and don't moan about failure.
o Record dial script despite our link mode.  The mode may
  be changed later (next mod) :-)  We never run scripts
  in -direct and -dedicated modes.
o Make ``set server none'' functional again.
o Correct datalink state array so that we don't report an
  ``unknown'' state.
o Pass struct ipcp to IpcpCleanInterface, not struct fsm.
o Create TUN_PREFIX define rather than hard-coding in main.c
o prompt_TtyInit now handles a NULL prompt for -direct mode
  rather than having to create one then destroy it uncleanly.
o Mention our mode in the "PPP Started" LogPHASE message.
o Bring all auto links up when we have something to send.
o Remove some redundant Physical_*() functions.
o Show which connection is running a command when logging
  commands.
o Initialise throughput uptime correctly.
1998-04-10 13:19:23 +00:00

198 lines
4.3 KiB
C

/*
* Written by Eivind Eklund <eivind@yes.no>
* for Yes Interactive
*
* Copyright (C) 1998, Yes Interactive. All rights reserved.
*
* Redistribution and use in any form is permitted. Redistribution in
* source form should include the above copyright and this set of
* conditions, because large sections american law seems to have been
* created by a bunch of jerks on drugs that are now illegal, forcing
* me to include this copyright-stuff instead of placing this in the
* public domain. The name of of 'Yes Interactive' or 'Eivind Eklund'
* may not be used to endorse or promote products derived from this
* software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: physical.c,v 1.1.2.22 1998/04/07 00:54:13 brian Exp $
*
*/
#include <sys/types.h>
#include <sys/tty.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <utmp.h>
/* XXX Name space pollution from vars.h */
#include "defs.h"
/* XXX Name space pollution from hdlc.h */
#include "mbuf.h"
/* Name space pollution for physical.h */
#include "timer.h"
#include "lqr.h"
#include "hdlc.h"
#include "throughput.h"
#include "fsm.h"
#include "lcp.h"
#include "async.h"
#include "ccp.h"
#include "link.h"
#include "descriptor.h"
#include "physical.h"
#include "vars.h"
#include "log.h"
#include "id.h"
/* External calls - should possibly be moved inline */
extern int IntToSpeed(int);
int
Physical_GetFD(struct physical *phys) {
return phys->fd;
}
int
Physical_IsATTY(struct physical *phys) {
return isatty(phys->fd);
}
int
Physical_IsSync(struct physical *phys) {
return phys->cfg.speed == 0;
}
const char *Physical_GetDevice(struct physical *phys)
{
return phys->name.full;
}
/* XXX-ML - must be moved into the physical struct */
void
Physical_SetDeviceList(struct physical *phys, const char *new_device_list) {
strncpy(phys->cfg.devlist, new_device_list, sizeof phys->cfg.devlist - 1);
phys->cfg.devlist[sizeof phys->cfg.devlist - 1] = '\0';
}
int
Physical_SetSpeed(struct physical *phys, int speed) {
if (IntToSpeed(speed) != B0) {
phys->cfg.speed = speed;
return 1;
} else {
return 0;
}
}
void
Physical_SetSync(struct physical *phys) {
phys->cfg.speed = 0;
}
int
Physical_SetRtsCts(struct physical *phys, int enable) {
assert(enable == 0 || enable == 1);
phys->cfg.rts_cts = enable;
return 1;
}
void
Physical_DupAndClose(struct physical *phys) {
int nmodem;
nmodem = dup(phys->fd);
close(phys->fd);
phys->fd = nmodem;
}
/* Encapsulation for a read on the FD. Avoids some exposure, and
concentrates control. */
ssize_t
Physical_Read(struct physical *phys, void *buf, size_t nbytes) {
return read(phys->fd, buf, nbytes);
}
ssize_t
Physical_Write(struct physical *phys, const void *buf, size_t nbytes) {
return write(phys->fd, buf, nbytes);
}
int
Physical_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
int *n, int force)
{
struct physical *p = descriptor2physical(d);
int sets;
sets = 0;
if (p->fd >= 0) {
if (r) {
FD_SET(p->fd, r);
sets++;
}
if (e) {
FD_SET(p->fd, e);
sets++;
}
if (w && (force || link_QueueLen(&p->link))) {
FD_SET(p->fd, w);
sets++;
}
if (sets && *n < p->fd + 1)
*n = p->fd + 1;
}
return sets;
}
int
Physical_IsSet(struct descriptor *d, const fd_set *fdset)
{
struct physical *p = descriptor2physical(d);
return p->fd >= 0 && FD_ISSET(p->fd, fdset);
}
void
Physical_Login(struct physical *phys, const char *name)
{
if (phys->type == PHYS_STDIN && Physical_IsATTY(phys) && Enabled(ConfUtmp))
if (phys->Utmp)
LogPrintf(LogERROR, "Oops, already logged in on %s\n", phys->name.base);
else {
struct utmp ut;
memset(&ut, 0, sizeof ut);
time(&ut.ut_time);
strncpy(ut.ut_name, name, sizeof ut.ut_name);
strncpy(ut.ut_line, phys->name.base, sizeof ut.ut_line - 1);
ID0login(&ut);
phys->Utmp = 1;
}
}
void
Physical_Logout(struct physical *phys)
{
if (phys->Utmp) {
ID0logout(phys->name.base);
phys->Utmp = 0;
}
}