summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1997-11-16 22:15:11 +0000
committerbrian <brian@FreeBSD.org>1997-11-16 22:15:11 +0000
commit5696a07f36cde36ef7955344c7b33fc5c7c57248 (patch)
tree766aa7f660926161982f1e79a01aa4827f8022d9 /usr.sbin/ppp
parent0f428e70f1f534b0936e0af7a36d1ad2f7e76775 (diff)
downloadFreeBSD-src-5696a07f36cde36ef7955344c7b33fc5c7c57248.zip
FreeBSD-src-5696a07f36cde36ef7955344c7b33fc5c7c57248.tar.gz
Abstract data read from and written to the tun device,
allowing for a possible header on the front of all packets. In OpenBSD, there's a structure containing the address family here. If we're building under OpenBSD, set up the ``flags'' part of struct tuninfo (not there under FreeBSD) so that we config the interface as POINTOPOINT. Prefix prototypes with ``extern'' in os.c for consistency. These changes are cosmetic under FreeBSD, but allow ppp to build & work under OpenBSD (bar the srandomdev() stuff, the inclusing of <net/if_var.h> and some Makefile symantecs).
Diffstat (limited to 'usr.sbin/ppp')
-rw-r--r--usr.sbin/ppp/Makefile11
-rw-r--r--usr.sbin/ppp/ip.c52
-rw-r--r--usr.sbin/ppp/lcp.c11
-rw-r--r--usr.sbin/ppp/main.c20
-rw-r--r--usr.sbin/ppp/os.c17
-rw-r--r--usr.sbin/ppp/os.h19
-rw-r--r--usr.sbin/ppp/tun.c39
-rw-r--r--usr.sbin/ppp/tun.h16
8 files changed, 130 insertions, 55 deletions
diff --git a/usr.sbin/ppp/Makefile b/usr.sbin/ppp/Makefile
index 35a35b0..7562f21 100644
--- a/usr.sbin/ppp/Makefile
+++ b/usr.sbin/ppp/Makefile
@@ -1,10 +1,11 @@
-# $Id: Makefile,v 1.28 1997/10/26 01:01:58 brian Exp $
+# $Id: Makefile,v 1.29 1997/11/09 06:22:37 brian Exp $
PROG= ppp
-SRCS= alias_cmd.c arp.c async.c auth.c ccp.c chap.c chat.c command.c \
- defs.c filter.c fsm.c hdlc.c id.c ip.c ipcp.c lcp.c loadalias.c log.c \
- lqr.c main.c mbuf.c modem.c os.c pap.c phase.c pred.c route.c \
- server.c sig.c slcompress.c systems.c timer.c vars.c vjcomp.c
+SRCS= alias_cmd.c arp.c async.c auth.c ccp.c chap.c chat.c \
+ command.c defs.c filter.c fsm.c hdlc.c id.c ip.c ipcp.c lcp.c \
+ loadalias.c log.c lqr.c main.c mbuf.c modem.c os.c pap.c phase.c \
+ pred.c route.c server.c sig.c slcompress.c systems.c timer.c tun.c \
+ vars.c vjcomp.c
CFLAGS+=-Wall -Wmissing-prototypes
LDADD+= -lmd -lcrypt -lutil
DPADD+= ${LIBMD} ${LIBCRYPT} ${LIBUTIL}
diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c
index 0fcddf9..26cee11 100644
--- a/usr.sbin/ppp/ip.c
+++ b/usr.sbin/ppp/ip.c
@@ -17,13 +17,16 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: ip.c,v 1.28 1997/11/12 19:48:45 brian Exp $
+ * $Id: ip.c,v 1.29 1997/11/12 21:04:21 brian Exp $
*
* TODO:
* o Return ICMP message for filterd packet
* and optionaly record it into log.
*/
#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/select.h>
+#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
@@ -31,6 +34,9 @@
#include <netinet/udp.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/if_tun.h>
#include <alias.h>
#include <errno.h>
@@ -57,6 +63,7 @@
#include "vjcomp.h"
#include "lcp.h"
#include "modem.h"
+#include "tun.h"
#include "ip.h"
static struct pppTimer IdleTimer;
@@ -369,9 +376,10 @@ IpInput(struct mbuf * bp)
u_char *cp;
struct mbuf *wp;
int nb, nw;
- u_char tunbuff[MAX_MRU];
+ struct tun_data tun, *frag;
- cp = tunbuff;
+ tun_fill_header(tun, AF_INET);
+ cp = tun.data;
nb = 0;
for (wp = bp; wp; wp = wp->next) { /* Copy to contiguous region */
memcpy(cp, MBUF_CTOP(wp), wp->cnt);
@@ -383,8 +391,8 @@ IpInput(struct mbuf * bp)
int iresult;
char *fptr;
- iresult = VarPacketAliasIn(tunbuff, sizeof tunbuff);
- nb = ntohs(((struct ip *) tunbuff)->ip_len);
+ iresult = VarPacketAliasIn(tun.data, sizeof tun.data);
+ nb = ntohs(((struct ip *) tun.data)->ip_len);
if (nb > MAX_MRU) {
LogPrintf(LogERROR, "IpInput: Problem with IP header length\n");
@@ -393,14 +401,15 @@ IpInput(struct mbuf * bp)
}
if (iresult == PKT_ALIAS_OK
|| iresult == PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
- if (PacketCheck(tunbuff, nb, FL_IN) < 0) {
+ if (PacketCheck(tun.data, nb, FL_IN) < 0) {
pfree(bp);
return;
}
ipInOctets += nb;
- nb = ntohs(((struct ip *) tunbuff)->ip_len);
- nw = write(tun_out, tunbuff, nb);
+ nb = ntohs(((struct ip *) tun.data)->ip_len);
+ nb += sizeof(tun)-sizeof(tun.data);
+ nw = write(tun_out, &tun, nb);
if (nw != nb)
if (nw == -1)
LogPrintf(LogERROR, "IpInput: wrote %d, got %s\n", nb,
@@ -409,36 +418,41 @@ IpInput(struct mbuf * bp)
LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
if (iresult == PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
- while ((fptr = VarPacketAliasGetFragment(tunbuff)) != NULL) {
- VarPacketAliasFragmentIn(tunbuff, fptr);
+ while ((fptr = VarPacketAliasGetFragment(tun.data)) != NULL) {
+ VarPacketAliasFragmentIn(tun.data, fptr);
nb = ntohs(((struct ip *) fptr)->ip_len);
- nw = write(tun_out, fptr, nb);
+ frag = (struct tun_data *)((char *)fptr-sizeof(tun)+sizeof(tun.data));
+ nb += sizeof(tun)-sizeof(tun.data);
+ nw = write(tun_out, frag, nb);
if (nw != nb)
if (nw == -1)
LogPrintf(LogERROR, "IpInput: wrote %d, got %s\n", nb,
strerror(errno));
else
LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
- free(fptr);
+ free(frag);
}
}
} else if (iresult == PKT_ALIAS_UNRESOLVED_FRAGMENT) {
- nb = ntohs(((struct ip *) tunbuff)->ip_len);
- fptr = malloc(nb);
- if (fptr == NULL)
+ nb = ntohs(((struct ip *) tun.data)->ip_len);
+ nb += sizeof(tun)-sizeof(tun.data);
+ frag = (struct tun_data *)malloc(nb);
+ if (frag == NULL)
LogPrintf(LogALERT, "IpInput: Cannot allocate memory for fragment\n");
else {
- memcpy(fptr, tunbuff, nb);
- VarPacketAliasSaveFragment(fptr);
+ tun_fill_header(*frag, AF_INET);
+ memcpy(frag->data, tun.data, nb-sizeof(tun)+sizeof(tun.data));
+ VarPacketAliasSaveFragment(frag->data);
}
}
} else { /* no aliasing */
- if (PacketCheck(tunbuff, nb, FL_IN) < 0) {
+ if (PacketCheck(tun.data, nb, FL_IN) < 0) {
pfree(bp);
return;
}
ipInOctets += nb;
- nw = write(tun_out, tunbuff, nb);
+ nb += sizeof(tun)-sizeof(tun.data);
+ nw = write(tun_out, &tun, nb);
if (nw != nb)
if (nw == -1)
LogPrintf(LogERROR, "IpInput: wrote %d, got %s\n", nb, strerror(errno));
diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c
index 33646c7..c23c8dd 100644
--- a/usr.sbin/ppp/lcp.c
+++ b/usr.sbin/ppp/lcp.c
@@ -17,15 +17,21 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: lcp.c,v 1.44 1997/11/11 13:08:12 brian Exp $
+ * $Id: lcp.c,v 1.45 1997/11/14 15:39:15 brian Exp $
*
* TODO:
* o Validate magic number received from peer.
* o Limit data field length by MRU
*/
#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/select.h>
+#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/if_tun.h>
#include <signal.h>
#include <stdio.h>
@@ -58,6 +64,7 @@
#include "main.h"
#include "ip.h"
#include "modem.h"
+#include "tun.h"
struct lcpstate LcpInfo;
@@ -350,7 +357,7 @@ static void
LcpLayerUp(struct fsm * fp)
{
LogPrintf(LogLCP, "LcpLayerUp\n");
- OsSetInterfaceParams(23, LcpInfo.his_mru, ModemSpeed());
+ tun_configure(LcpInfo.his_mru, ModemSpeed());
SetLinkParams(&LcpInfo);
NewPhase(PHASE_AUTHENTICATE);
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index 1e6bec1..54a5ede 100644
--- a/usr.sbin/ppp/main.c
+++ b/usr.sbin/ppp/main.c
@@ -17,19 +17,24 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: main.c,v 1.97 1997/11/13 14:44:06 brian Exp $
+ * $Id: main.c,v 1.98 1997/11/13 15:35:06 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
* o Add signal handler for misc controls.
*/
#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/select.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <netdb.h>
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/if_tun.h>
#include <errno.h>
#include <fcntl.h>
@@ -70,6 +75,7 @@
#include "vjcomp.h"
#include "async.h"
#include "pathnames.h"
+#include "tun.h"
#ifndef O_NONBLOCK
#ifdef O_NDELAY
@@ -728,11 +734,12 @@ DoLoop()
struct timeval timeout, *tp;
int ssize = sizeof(hisaddr);
u_char *cp;
- u_char rbuff[MAX_MRU];
int tries;
int qlen;
int res;
pid_t pgroup;
+ struct tun_data tun;
+#define rbuff tun.data
pgroup = getpgrp();
@@ -1004,11 +1011,18 @@ DoLoop()
}
if (tun_in >= 0 && FD_ISSET(tun_in, &rfds)) { /* something to read
* from tun */
- n = read(tun_in, rbuff, sizeof(rbuff));
+ n = read(tun_in, &tun, sizeof(tun));
if (n < 0) {
LogPrintf(LogERROR, "read from tun: %s\n", strerror(errno));
continue;
}
+ n -= sizeof(tun)-sizeof(tun.data);
+ if (n <= 0) {
+ LogPrintf(LogERROR, "read from tun: Only %d bytes read\n", n);
+ continue;
+ }
+ if (!tun_check_header(tun, AF_INET))
+ continue;
if (((struct ip *) rbuff)->ip_dst.s_addr == IpcpInfo.want_ipaddr.s_addr) {
/* we've been asked to send something addressed *to* us :( */
if (VarLoopback) {
diff --git a/usr.sbin/ppp/os.c b/usr.sbin/ppp/os.c
index ce8bb29..95c66f0 100644
--- a/usr.sbin/ppp/os.c
+++ b/usr.sbin/ppp/os.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: os.c,v 1.32 1997/11/11 22:58:12 brian Exp $
+ * $Id: os.c,v 1.33 1997/11/13 12:09:57 brian Exp $
*
*/
#include <sys/param.h>
@@ -287,21 +287,6 @@ OsInterfaceDown(int final)
return (0);
}
-void
-OsSetInterfaceParams(int type, int mtu, int speed)
-{
- struct tuninfo info;
-
- info.type = type;
- info.mtu = mtu;
- if (VarPrefMTU != 0 && VarPrefMTU < mtu)
- info.mtu = VarPrefMTU;
- info.baudrate = speed;
- if (ioctl(tun_out, TUNSIFINFO, &info) < 0)
- LogPrintf(LogERROR, "OsSetInterfaceParams: ioctl(TUNSIFINFO): %s\n",
- strerror(errno));
-}
-
/*
* Open tunnel device and returns its descriptor
*/
diff --git a/usr.sbin/ppp/os.h b/usr.sbin/ppp/os.h
index d95ce0d..a4041be 100644
--- a/usr.sbin/ppp/os.h
+++ b/usr.sbin/ppp/os.h
@@ -15,19 +15,18 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: os.h,v 1.9 1997/10/26 01:03:27 brian Exp $
+ * $Id: os.h,v 1.10 1997/10/29 01:19:48 brian Exp $
*
* TODO:
*/
extern char *IfDevName;
-int OsSetIpaddress(struct in_addr, struct in_addr, struct in_addr);
-int OsInterfaceDown(int);
-void OsSetInterfaceParams(int, int, int);
-int OpenTunnel(int *);
-void OsLinkup(void);
-int OsLinkIsUp(void);
-void OsLinkdown(void);
-void OsSetRoute(int, struct in_addr, struct in_addr, struct in_addr);
-void DeleteIfRoutes(int);
+extern int OsSetIpaddress(struct in_addr, struct in_addr, struct in_addr);
+extern int OsInterfaceDown(int);
+extern int OpenTunnel(int *);
+extern void OsLinkup(void);
+extern int OsLinkIsUp(void);
+extern void OsLinkdown(void);
+extern void OsSetRoute(int, struct in_addr, struct in_addr, struct in_addr);
+extern void DeleteIfRoutes(int);
diff --git a/usr.sbin/ppp/tun.c b/usr.sbin/ppp/tun.c
new file mode 100644
index 0000000..c848c7e
--- /dev/null
+++ b/usr.sbin/ppp/tun.c
@@ -0,0 +1,39 @@
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/select.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/if_tun.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/errno.h>
+
+#include "hdlc.h"
+#include "defs.h"
+#include "loadalias.h"
+#include "command.h"
+#include "vars.h"
+#include "log.h"
+#include "tun.h"
+
+void
+tun_configure(int mtu, int speed)
+{
+ struct tuninfo info;
+
+ info.type = 23;
+ info.mtu = mtu;
+ if (VarPrefMTU != 0 && VarPrefMTU < mtu)
+ info.mtu = VarPrefMTU;
+ info.baudrate = speed;
+#ifdef __OpenBSD__
+ info.flags = IFF_UP|IFF_POINTOPOINT;
+#endif
+ if (ioctl(tun_out, TUNSIFINFO, &info) < 0)
+ LogPrintf(LogERROR, "tun_configure: ioctl(TUNSIFINFO): %s\n",
+ strerror(errno));
+}
diff --git a/usr.sbin/ppp/tun.h b/usr.sbin/ppp/tun.h
new file mode 100644
index 0000000..bc495e1
--- /dev/null
+++ b/usr.sbin/ppp/tun.h
@@ -0,0 +1,16 @@
+struct tun_data {
+#ifdef __OpenBSD__
+ struct tunnel_header head;
+#endif
+ u_char data[MAX_MRU];
+};
+
+#ifdef __OpenBSD__
+#define tun_fill_header(f,proto) do { (f).head.tun_af = (proto); } while (0)
+#define tun_check_header(f,proto) ((f).head.tun_af == (proto))
+#else
+#define tun_fill_header(f,proto) do { } while (0)
+#define tun_check_header(f,proto) (1)
+#endif
+
+extern void tun_configure(int, int);
OpenPOWER on IntegriCloud