summaryrefslogtreecommitdiff
path: root/usr.sbin/ppp
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/ppp')
-rw-r--r--usr.sbin/ppp/ppp/command.c6
-rw-r--r--usr.sbin/ppp/ppp/exec.c4
-rw-r--r--usr.sbin/ppp/ppp/exec.h3
-rw-r--r--usr.sbin/ppp/ppp/physical.c81
-rw-r--r--usr.sbin/ppp/ppp/physical.h5
-rw-r--r--usr.sbin/ppp/ppp/tcp.c4
-rw-r--r--usr.sbin/ppp/ppp/tcp.h3
-rw-r--r--usr.sbin/ppp/ppp/tty.c31
-rw-r--r--usr.sbin/ppp/ppp/tty.h3
-rw-r--r--usr.sbin/ppp/ppp/udp.c29
-rw-r--r--usr.sbin/ppp/ppp/udp.h3
11 files changed, 137 insertions, 35 deletions
diff --git a/usr.sbin/ppp/ppp/command.c b/usr.sbin/ppp/ppp/command.c
index 93b258a1642..06abdae701d 100644
--- a/usr.sbin/ppp/ppp/command.c
+++ b/usr.sbin/ppp/ppp/command.c
@@ -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.24 1999/06/02 21:27:54 brian Exp $
+ * $Id: command.c,v 1.25 1999/06/05 21:35:58 brian Exp $
*
*/
#include <sys/param.h>
@@ -142,8 +142,8 @@
#define NEG_VJCOMP 51
#define NEG_DNS 52
-const char Version[] = "2.21";
-const char VersionDate[] = "$Date: 1999/06/02 21:27:54 $";
+const char Version[] = "2.22";
+const char VersionDate[] = "$Date: 1999/06/05 21:35:58 $";
static int ShowCommand(struct cmdargs const *);
static int TerminalCommand(struct cmdargs const *);
diff --git a/usr.sbin/ppp/ppp/exec.c b/usr.sbin/ppp/ppp/exec.c
index 1e979d3febd..a2e4387bd99 100644
--- a/usr.sbin/ppp/ppp/exec.c
+++ b/usr.sbin/ppp/ppp/exec.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: exec.c,v 1.4 1999/06/01 19:08:52 brian Exp $
+ * $Id: exec.c,v 1.5 1999/06/05 21:35:59 brian Exp $
*/
#include <sys/param.h>
@@ -41,6 +41,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
+#include <sys/uio.h>
#include <termios.h>
#include <unistd.h>
@@ -98,6 +99,7 @@ exec_iov2device(int type, struct physical *p, struct iovec *iov,
int *niov, int maxiov)
{
if (type == EXEC_DEVICE) {
+ free(iov[(*niov)++].iov_base);
physical_SetupStack(p, execdevice.name, PHYSICAL_FORCE_ASYNC);
return &execdevice;
}
diff --git a/usr.sbin/ppp/ppp/exec.h b/usr.sbin/ppp/ppp/exec.h
index 5c989a2b86c..eb9a786eb8a 100644
--- a/usr.sbin/ppp/ppp/exec.h
+++ b/usr.sbin/ppp/ppp/exec.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: exec.h,v 1.2 1999/05/12 10:03:51 brian Exp $
+ * $Id: exec.h,v 1.3 1999/06/05 21:36:00 brian Exp $
*/
struct physical;
@@ -32,3 +32,4 @@ struct device;
extern struct device *exec_Create(struct physical *);
extern struct device *exec_iov2device(int, struct physical *,
struct iovec *, int *, int);
+#define exec_DeviceSize physical_DeviceSize
diff --git a/usr.sbin/ppp/ppp/physical.c b/usr.sbin/ppp/ppp/physical.c
index 24fd08eafc8..873a156eeda 100644
--- a/usr.sbin/ppp/ppp/physical.c
+++ b/usr.sbin/ppp/ppp/physical.c
@@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: physical.c,v 1.12 1999/06/02 00:46:55 brian Exp $
+ * $Id: physical.c,v 1.13 1999/06/05 21:36:00 brian Exp $
*
*/
@@ -98,15 +98,22 @@ static int physical_DescriptorWrite(struct descriptor *, struct bundle *,
static void physical_DescriptorRead(struct descriptor *, struct bundle *,
const fd_set *);
+static int
+physical_DeviceSize(void)
+{
+ return sizeof(struct device);
+}
+
struct {
struct device *(*create)(struct physical *);
struct device *(*iov2device)(int, struct physical *, struct iovec *iov,
int *niov, int maxiov);
+ int (*DeviceSize)(void);
} devices[] = {
- { tty_Create, tty_iov2device },
- { tcp_Create, tcp_iov2device },
- { udp_Create, udp_iov2device },
- { exec_Create, exec_iov2device }
+ { tty_Create, tty_iov2device, tty_DeviceSize },
+ { tcp_Create, tcp_iov2device, tcp_DeviceSize },
+ { udp_Create, udp_iov2device, udp_DeviceSize },
+ { exec_Create, exec_iov2device, exec_DeviceSize }
};
#define NDEVICES (sizeof devices / sizeof devices[0])
@@ -559,6 +566,20 @@ iov2physical(struct datalink *dl, struct iovec *iov, int *niov, int maxiov,
p->fd = fd;
+ type = (long)p->handler;
+ p->handler = NULL;
+ for (h = 0; h < NDEVICES && p->handler == NULL; h++)
+ p->handler = (*devices[h].iov2device)(type, p, iov, niov, maxiov);
+
+ if (p->handler == NULL) {
+ log_Printf(LogPHASE, "%s: Device %s, unknown link type\n",
+ p->link.name, p->name.full);
+ free(iov[(*niov)++].iov_base);
+ physical_SetupStack(p, "unknown", PHYSICAL_NOFORCE);
+ } else
+ log_Printf(LogPHASE, "%s: Device %s, link type is %s\n",
+ p->link.name, p->name.full, p->handler->name);
+
if (p->hdlc.lqm.method && p->hdlc.lqm.timer.load)
lqr_reStart(&p->link.lcp);
hdlc_StartTimer(&p->hdlc);
@@ -566,20 +587,33 @@ iov2physical(struct datalink *dl, struct iovec *iov, int *niov, int maxiov,
throughput_start(&p->link.throughput, "physical throughput",
Enabled(dl->bundle, OPT_THROUGHPUT));
- type = (long)p->handler;
- for (h = 0; h < NDEVICES && p->handler == NULL; h++)
- p->handler = (*devices[h].iov2device)(type, p, iov, niov, maxiov);
+ return p;
+}
- if (p->handler == NULL)
- physical_SetupStack(p, "unknown", PHYSICAL_NOFORCE);
+int
+physical_MaxDeviceSize()
+{
+ int biggest, sz, n;
- return p;
+ biggest = sizeof(struct device);
+ for (sz = n = 0; n < NDEVICES; n++)
+ if (devices[n].DeviceSize) {
+ sz = (*devices[n].DeviceSize)();
+ if (biggest < sz)
+ biggest = sz;
+ }
+
+ return biggest;
}
int
physical2iov(struct physical *p, struct iovec *iov, int *niov, int maxiov,
pid_t newpid)
{
+ struct device *h;
+ int sz;
+
+ h = NULL;
if (p) {
hdlc_StopTimer(&p->hdlc);
lqr_StopTimer(p);
@@ -591,7 +625,7 @@ physical2iov(struct physical *p, struct iovec *iov, int *niov, int maxiov,
timer_Stop(&p->link.ccp.fsm.StoppedTimer);
if (p->handler) {
if (p->handler->device2iov)
- (*p->handler->device2iov)(p, iov, niov, maxiov, newpid);
+ h = p->handler;
p->handler = (struct device *)(long)p->handler->type;
}
@@ -604,17 +638,34 @@ physical2iov(struct physical *p, struct iovec *iov, int *niov, int maxiov,
physical_ChangedPid(p, newpid);
}
- if (*niov >= maxiov) {
- log_Printf(LogERROR, "physical2iov: No room for physical !\n");
+ if (*niov + 1 >= maxiov) {
+ log_Printf(LogERROR, "physical2iov: No room for physical + device !\n");
if (p)
free(p);
return -1;
}
- iov[*niov].iov_base = p ? p : malloc(sizeof *p);
+ iov[*niov].iov_base = p ? (void *)p : malloc(sizeof *p);
iov[*niov].iov_len = sizeof *p;
(*niov)++;
+ sz = physical_MaxDeviceSize();
+ if (p) {
+ if (h)
+ (*h->device2iov)(h, iov, niov, maxiov, newpid);
+ else {
+ iov[*niov].iov_base = malloc(sz);
+ if (p->handler)
+ memcpy(iov[*niov].iov_base, p->handler, sizeof *p->handler);
+ iov[*niov].iov_len = sz;
+ (*niov)++;
+ }
+ } else {
+ iov[*niov].iov_base = malloc(sz);
+ iov[*niov].iov_len = sz;
+ (*niov)++;
+ }
+
return p ? p->fd : 0;
}
diff --git a/usr.sbin/ppp/ppp/physical.h b/usr.sbin/ppp/ppp/physical.h
index 93635dd93e1..d008164198e 100644
--- a/usr.sbin/ppp/ppp/physical.h
+++ b/usr.sbin/ppp/ppp/physical.h
@@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: physical.h,v 1.10 1999/06/01 19:08:52 brian Exp $
+ * $Id: physical.h,v 1.11 1999/06/05 21:36:01 brian Exp $
*
*/
@@ -44,7 +44,7 @@ struct device {
void (*destroy)(struct physical *);
ssize_t (*read)(struct physical *, void *, size_t);
ssize_t (*write)(struct physical *, const void *, size_t);
- void (*device2iov)(struct physical *, struct iovec *, int *, int, pid_t);
+ void (*device2iov)(struct device *, struct iovec *, int *, int, pid_t);
int (*speed)(struct physical *);
const char *(*openinfo)(struct physical *);
};
@@ -136,3 +136,4 @@ extern int physical_SetMode(struct physical *, int);
extern void physical_DeleteQueue(struct physical *);
extern void physical_SetupStack(struct physical *, const char *, int);
extern void physical_StopDeviceTimer(struct physical *);
+extern int physical_MaxDeviceSize(void);
diff --git a/usr.sbin/ppp/ppp/tcp.c b/usr.sbin/ppp/ppp/tcp.c
index 6ed9a13dc86..631c5a1135a 100644
--- a/usr.sbin/ppp/ppp/tcp.c
+++ b/usr.sbin/ppp/ppp/tcp.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: tcp.c,v 1.3 1999/05/24 16:39:19 brian Exp $
+ * $Id: tcp.c,v 1.4 1999/06/05 21:36:01 brian Exp $
*/
#include <sys/types.h>
@@ -36,6 +36,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/uio.h>
#include <termios.h>
#include <unistd.h>
@@ -116,6 +117,7 @@ tcp_iov2device(int type, struct physical *p, struct iovec *iov,
int *niov, int maxiov)
{
if (type == TCP_DEVICE) {
+ free(iov[(*niov)++].iov_base);
physical_SetupStack(p, tcpdevice.name, PHYSICAL_FORCE_ASYNC);
return &tcpdevice;
}
diff --git a/usr.sbin/ppp/ppp/tcp.h b/usr.sbin/ppp/ppp/tcp.h
index b614dbaa7ff..140e4e0e097 100644
--- a/usr.sbin/ppp/ppp/tcp.h
+++ b/usr.sbin/ppp/ppp/tcp.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: tcp.h,v 1.2 1999/05/12 10:03:54 brian Exp $
+ * $Id: tcp.h,v 1.3 1999/06/05 21:36:02 brian Exp $
*/
struct physical;
@@ -31,3 +31,4 @@ struct physical;
extern struct device *tcp_Create(struct physical *);
extern struct device *tcp_iov2device(int, struct physical *,
struct iovec *, int *, int);
+#define tcp_DeviceSize physical_DeviceSize
diff --git a/usr.sbin/ppp/ppp/tty.c b/usr.sbin/ppp/ppp/tty.c
index c9fd1476d48..c9b83d789f4 100644
--- a/usr.sbin/ppp/ppp/tty.c
+++ b/usr.sbin/ppp/ppp/tty.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: tty.c,v 1.8 1999/05/27 08:44:59 brian Exp $
+ * $Id: tty.c,v 1.9 1999/06/05 21:36:03 brian Exp $
*/
#include <sys/param.h>
@@ -47,6 +47,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include <sys/wait.h>
#include <sys/uio.h>
#include <termios.h>
@@ -85,6 +86,7 @@
#include "chap.h"
#include "cbcp.h"
#include "datalink.h"
+#include "main.h"
#include "tty.h"
#define Online(dev) ((dev)->mbits & TIOCM_CD)
@@ -98,6 +100,12 @@ struct ttydevice {
#define device2tty(d) ((d)->type == TTY_DEVICE ? (struct ttydevice *)d : NULL)
+int
+tty_DeviceSize(void)
+{
+ return sizeof(struct ttydevice);
+}
+
/*
* tty_Timeout() watches the DCD signal and mentions it if it's status
* changes.
@@ -292,13 +300,18 @@ tty_OpenInfo(struct physical *p)
}
static void
-tty_device2iov(struct physical *p, struct iovec *iov, int *niov,
+tty_device2iov(struct device *d, struct iovec *iov, int *niov,
int maxiov, pid_t newpid)
{
- struct ttydevice *dev = p ? device2tty(p->handler) : NULL;
+ struct ttydevice *dev = device2tty(d);
+ int sz = physical_MaxDeviceSize();
- iov[*niov].iov_base = p ? p->handler : malloc(sizeof(struct ttydevice));
- iov[*niov].iov_len = sizeof(struct ttydevice);
+ iov[*niov].iov_base = realloc(d, sz);
+ if (iov[*niov].iov_base == NULL) {
+ log_Printf(LogALERT, "Failed to allocate memory: %d\n", sz);
+ AbortProgram(EX_OSERR);
+ }
+ iov[*niov].iov_len = sz;
(*niov)++;
if (dev->Timer.state != TIMER_STOPPED) {
@@ -329,12 +342,20 @@ tty_iov2device(int type, struct physical *p, struct iovec *iov, int *niov,
if (type == TTY_DEVICE) {
struct ttydevice *dev = (struct ttydevice *)iov[(*niov)++].iov_base;
+ dev = realloc(dev, sizeof *dev); /* Reduce to the correct size */
+ if (dev == NULL) {
+ log_Printf(LogALERT, "Failed to allocate memory: %d\n",
+ (int)(sizeof *dev));
+ AbortProgram(EX_OSERR);
+ }
+
/* Refresh function pointers etc */
memcpy(&dev->dev, &basettydevice, sizeof dev->dev);
physical_SetupStack(p, dev->dev.name, PHYSICAL_NOFORCE);
if (dev->Timer.state != TIMER_STOPPED) {
dev->Timer.state = TIMER_STOPPED;
+ p->handler = &dev->dev; /* For the benefit of StartTimer */
tty_StartTimer(p);
}
return &dev->dev;
diff --git a/usr.sbin/ppp/ppp/tty.h b/usr.sbin/ppp/ppp/tty.h
index 747a0e57080..6f2573aa7b1 100644
--- a/usr.sbin/ppp/ppp/tty.h
+++ b/usr.sbin/ppp/ppp/tty.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: tty.h,v 1.2 1999/05/12 10:03:55 brian Exp $
+ * $Id: tty.h,v 1.3 1999/06/05 21:36:03 brian Exp $
*/
struct physical;
@@ -32,3 +32,4 @@ struct device;
extern struct device *tty_Create(struct physical *);
extern struct device *tty_iov2device(int, struct physical *,
struct iovec *, int *, int);
+extern int tty_DeviceSize(void);
diff --git a/usr.sbin/ppp/ppp/udp.c b/usr.sbin/ppp/ppp/udp.c
index 9694cb64989..f7d5541b9d6 100644
--- a/usr.sbin/ppp/ppp/udp.c
+++ b/usr.sbin/ppp/ppp/udp.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: udp.c,v 1.2 1999/05/24 16:39:19 brian Exp $
+ * $Id: udp.c,v 1.3 1999/06/05 21:36:04 brian Exp $
*/
#include <sys/types.h>
@@ -36,6 +36,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include <sys/uio.h>
#include <termios.h>
#include <unistd.h>
@@ -56,6 +57,7 @@
#include "async.h"
#include "descriptor.h"
#include "physical.h"
+#include "main.h"
#include "udp.h"
struct udpdevice {
@@ -66,6 +68,12 @@ struct udpdevice {
#define device2udp(d) ((d)->type == UDP_DEVICE ? (struct udpdevice *)d : NULL)
+int
+udp_DeviceSize(void)
+{
+ return sizeof(struct udpdevice);
+}
+
static ssize_t
udp_Sendto(struct physical *p, const void *v, size_t n)
{
@@ -108,11 +116,17 @@ udp_Free(struct physical *p)
}
static void
-udp_device2iov(struct physical *p, struct iovec *iov, int *niov,
+udp_device2iov(struct device *d, struct iovec *iov, int *niov,
int maxiov, pid_t newpid)
{
- iov[*niov].iov_base = p ? p->handler : malloc(sizeof(struct udpdevice));
- iov[*niov].iov_len = sizeof(struct udpdevice);
+ int sz = physical_MaxDeviceSize();
+
+ iov[*niov].iov_base = realloc(d, sz);
+ if (iov[*niov].iov_base == NULL) {
+ log_Printf(LogALERT, "Failed to allocate memory: %d\n", sz);
+ AbortProgram(EX_OSERR);
+ }
+ iov[*niov].iov_len = sz;
(*niov)++;
}
@@ -138,6 +152,13 @@ udp_iov2device(int type, struct physical *p, struct iovec *iov, int *niov,
if (type == UDP_DEVICE) {
struct udpdevice *dev = (struct udpdevice *)iov[(*niov)++].iov_base;
+ dev = realloc(dev, sizeof *dev); /* Reduce to the correct size */
+ if (dev == NULL) {
+ log_Printf(LogALERT, "Failed to allocate memory: %d\n",
+ (int)(sizeof *dev));
+ AbortProgram(EX_OSERR);
+ }
+
/* Refresh function pointers etc */
memcpy(&dev->dev, &baseudpdevice, sizeof dev->dev);
diff --git a/usr.sbin/ppp/ppp/udp.h b/usr.sbin/ppp/ppp/udp.h
index 3674e281f41..3562169075f 100644
--- a/usr.sbin/ppp/ppp/udp.h
+++ b/usr.sbin/ppp/ppp/udp.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: udp.h,v 1.1 1999/05/12 10:03:55 brian Exp $
+ * $Id: udp.h,v 1.2 1999/06/05 21:36:04 brian Exp $
*/
struct physical;
@@ -32,3 +32,4 @@ struct device;
extern struct device *udp_Create(struct physical *);
extern struct device *udp_iov2device(int, struct physical *,
struct iovec *, int *, int);
+extern int udp_DeviceSize(void);