summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorbrian <brian@cvs.openbsd.org>2000-02-27 01:34:06 +0000
committerbrian <brian@cvs.openbsd.org>2000-02-27 01:34:06 +0000
commit171e89af0db4aa2aac4609f56cb701b2bbf180d2 (patch)
tree074dd015c581da848c59cc36251c0ef0175131c4 /usr.sbin
parent0b9c6c302f5adf323ce40459851cd2f5127e0750 (diff)
Fix a bug in end-of-line comment parsing.
Fix callback (don't ``forget'' to call back). Restructure how we add/remove the address family when writing/reading the tun device. Notify the tun device that we've changed PID under FreeBSD.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ppp/ppp/bundle.c76
-rw-r--r--usr.sbin/ppp/ppp/bundle.h4
-rw-r--r--usr.sbin/ppp/ppp/chap_ms.c6
-rw-r--r--usr.sbin/ppp/ppp/datalink.c4
-rw-r--r--usr.sbin/ppp/ppp/defs.c4
-rw-r--r--usr.sbin/ppp/ppp/id.c4
-rw-r--r--usr.sbin/ppp/ppp/ip.c16
-rw-r--r--usr.sbin/ppp/ppp/main.c3
-rw-r--r--usr.sbin/ppp/ppp/tun.h14
9 files changed, 91 insertions, 40 deletions
diff --git a/usr.sbin/ppp/ppp/bundle.c b/usr.sbin/ppp/ppp/bundle.c
index 1e2620c80ec..973af47e441 100644
--- a/usr.sbin/ppp/ppp/bundle.c
+++ b/usr.sbin/ppp/ppp/bundle.c
@@ -23,14 +23,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: bundle.c,v 1.28 2000/02/27 00:21:05 brian Exp $
+ * $Id: bundle.c,v 1.29 2000/02/27 01:34:04 brian Exp $
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
-#include <net/if_tun.h> /* For TUNSIFMODE & TUNSLMODE */
+#include <net/if_tun.h> /* For TUNS* ioctls */
#include <arpa/inet.h>
#include <net/route.h>
#include <netinet/in_systm.h>
@@ -524,20 +524,36 @@ bundle_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
if (FD_ISSET(bundle->dev.fd, fdset)) {
struct tun_data tun;
int n, pri;
+ char *data;
+ size_t sz;
+
+ if (bundle->dev.header) {
+ data = (char *)&tun;
+ sz = sizeof tun;
+ } else {
+ data = tun.data;
+ sz = sizeof tun.data;
+ }
/* something to read from tun */
- n = read(bundle->dev.fd, &tun, sizeof tun);
+
+ n = read(bundle->dev.fd, data, sz);
if (n < 0) {
- log_Printf(LogWARN, "read from %s: %s\n", TUN_NAME, strerror(errno));
+ log_Printf(LogWARN, "%s: read: %s\n", bundle->dev.Name, strerror(errno));
return;
}
- n -= sizeof tun - sizeof tun.data;
- if (n <= 0) {
- log_Printf(LogERROR, "read from %s: Only %d bytes read ?\n", TUN_NAME, n);
- return;
+
+ if (bundle->dev.header) {
+ n -= sz - sizeof tun.data;
+ if (n <= 0) {
+ log_Printf(LogERROR, "%s: read: Got only %d bytes of data !\n",
+ bundle->dev.Name, n);
+ return;
+ }
+ if (ntohl(tun.family) != AF_INET)
+ /* XXX: Should be maintaining drop/family counts ! */
+ return;
}
- if (!tun_check_header(tun, AF_INET))
- return;
if (((struct ip *)tun.data)->ip_dst.s_addr ==
bundle->ncp.ipcp.my_ip.s_addr) {
@@ -545,8 +561,8 @@ bundle_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
if (Enabled(bundle, OPT_LOOPBACK)) {
pri = PacketCheck(bundle, tun.data, n, &bundle->filter.in);
if (pri >= 0) {
- n += sizeof tun - sizeof tun.data;
- write(bundle->dev.fd, &tun, n);
+ n += sz - sizeof tun.data;
+ write(bundle->dev.fd, data, n);
log_Printf(LogDEBUG, "Looped back packet addressed to myself\n");
}
return;
@@ -638,7 +654,7 @@ bundle_Create(const char *prefix, int type, int unit)
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
int kldtried;
#endif
-#if defined(TUNSIFMODE) || defined(TUNSLMODE)
+#if defined(TUNSIFMODE) || defined(TUNSLMODE) || defined(TUNSIFHEAD)
int iff;
#endif
@@ -722,13 +738,36 @@ bundle_Create(const char *prefix, int type, int unit)
#endif
#ifdef TUNSLMODE
- /* Make sure we're POINTOPOINT */
+ /* Make sure we're not prepending sockaddrs */
iff = 0;
if (ID0ioctl(bundle.dev.fd, TUNSLMODE, &iff) < 0)
log_Printf(LogERROR, "bundle_Create: ioctl(TUNSLMODE): %s\n",
strerror(errno));
#endif
+#ifdef TUNSIFHEAD
+ /* We want the address family please ! */
+ iff = 1;
+ if (ID0ioctl(bundle.dev.fd, TUNSIFHEAD, &iff) < 0) {
+ log_Printf(LogERROR, "bundle_Create: ioctl(TUNSIFHEAD): %s\n",
+ strerror(errno));
+ bundle.dev.header = 0;
+ } else
+ bundle.dev.header = 1;
+#else
+#ifdef __OpenBSD__
+ /* Always present for OpenBSD */
+ bundle.dev.header = 1;
+#else
+ /*
+ * If TUNSIFHEAD isn't available and we're not OpenBSD, assume
+ * everything's AF_INET (hopefully the tun device won't pass us
+ * anything else !).
+ */
+ bundle.dev.header = 0;
+#endif
+#endif
+
if (!iface_SetFlags(bundle.iface, IFF_UP)) {
iface_Destroy(bundle.iface);
bundle.iface = NULL;
@@ -1738,6 +1777,7 @@ bundle_setsid(struct bundle *bundle, int holdsession)
read(fds[0], &done, 1); /* uu_locks are mine ! */
close(fds[0]);
setsid();
+ bundle_ChangedPID(bundle);
log_Printf(LogPHASE, "%d -> %d: %s session control\n",
(int)orig, (int)getpid(),
holdsession ? "Passed" : "Dropped");
@@ -1940,3 +1980,11 @@ bundle_WantAutoloadTimer(struct bundle *bundle)
return 0;
}
+
+void
+bundle_ChangedPID(struct bundle *bundle)
+{
+#ifdef TUNSIFPID
+ ioctl(bundle->dev.fd, TUNSIFPID, 0);
+#endif
+}
diff --git a/usr.sbin/ppp/ppp/bundle.h b/usr.sbin/ppp/ppp/bundle.h
index cbd618ebcd5..671a9543f8e 100644
--- a/usr.sbin/ppp/ppp/bundle.h
+++ b/usr.sbin/ppp/ppp/bundle.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: bundle.h,v 1.10 2000/02/27 00:21:06 brian Exp $
+ * $Id: bundle.h,v 1.11 2000/02/27 01:34:04 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@@ -67,6 +67,7 @@ struct bundle {
struct {
char Name[20]; /* The /dev/XXXX name */
int fd; /* The /dev/XXXX descriptor */
+ unsigned header : 1; /* Family header sent & received ? */
} dev;
u_long bandwidth; /* struct tuninfo speed */
@@ -187,3 +188,4 @@ extern void bundle_AdjustFilters(struct bundle *, struct in_addr *,
extern void bundle_CalculateBandwidth(struct bundle *);
extern void bundle_AutoAdjust(struct bundle *, int, int);
extern int bundle_WantAutoloadTimer(struct bundle *);
+extern void bundle_ChangedPID(struct bundle *);
diff --git a/usr.sbin/ppp/ppp/chap_ms.c b/usr.sbin/ppp/ppp/chap_ms.c
index 6a89f16338d..564ca296e34 100644
--- a/usr.sbin/ppp/ppp/chap_ms.c
+++ b/usr.sbin/ppp/ppp/chap_ms.c
@@ -19,14 +19,18 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: chap_ms.c,v 1.3 1999/02/18 00:50:45 brian Exp $
+ * $Id: chap_ms.c,v 1.4 2000/02/27 01:34:04 brian Exp $
*
*/
#include <sys/types.h>
#include <ctype.h>
+#ifdef __FreeBSD__
+#include <openssl/des.h>
+#else
#include <des.h>
+#endif
#include <string.h>
#include "chap_ms.h"
diff --git a/usr.sbin/ppp/ppp/datalink.c b/usr.sbin/ppp/ppp/datalink.c
index 43a74c5b17c..e70a189b6b5 100644
--- a/usr.sbin/ppp/ppp/datalink.c
+++ b/usr.sbin/ppp/ppp/datalink.c
@@ -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.26 2000/02/27 00:21:07 brian Exp $
+ * $Id: datalink.c,v 1.27 2000/02/27 01:34:04 brian Exp $
*/
#include <sys/param.h>
@@ -1011,6 +1011,8 @@ datalink_Down(struct datalink *dl, int how)
case DATALINK_AUTH:
case DATALINK_LCP:
fsm2initial(&dl->physical->link.lcp.fsm);
+ if (dl->state == DATALINK_OPENING)
+ return; /* we're doing a callback... */
/* fall through */
default:
diff --git a/usr.sbin/ppp/ppp/defs.c b/usr.sbin/ppp/ppp/defs.c
index ae4a7420e6c..07028da2228 100644
--- a/usr.sbin/ppp/ppp/defs.c
+++ b/usr.sbin/ppp/ppp/defs.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: defs.c,v 1.8 2000/02/27 00:21:07 brian Exp $
+ * $Id: defs.c,v 1.9 2000/02/27 01:34:04 brian Exp $
*/
@@ -297,7 +297,7 @@ MakeArgs(char *script, char **pvect, int maxargs, int flags)
int nargs;
nargs = 0;
- while (*script) {
+ while (*script && *script != '#') {
script += strspn(script, " \t");
if (*script) {
if (nargs >= maxargs - 1)
diff --git a/usr.sbin/ppp/ppp/id.c b/usr.sbin/ppp/ppp/id.c
index 460b0cefa0e..02643602137 100644
--- a/usr.sbin/ppp/ppp/id.c
+++ b/usr.sbin/ppp/ppp/id.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: id.c,v 1.3 2000/01/07 03:26:54 brian Exp $
+ * $Id: id.c,v 1.4 2000/02/27 01:34:04 brian Exp $
*/
#include <sys/param.h>
@@ -38,7 +38,7 @@
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
-#include <stdlib.h> /* setproctitle() under OpenBSD (+NetBSD ?)*/
+#include <stdlib.h> /* setproctitle() under OpenBSD (+NetBSD ?)*/
#include <string.h>
#include <sysexits.h>
#if defined(__FreeBSD__) && !defined(NOKLDLOAD)
diff --git a/usr.sbin/ppp/ppp/ip.c b/usr.sbin/ppp/ppp/ip.c
index 9032723bd9f..9dbb4205eac 100644
--- a/usr.sbin/ppp/ppp/ip.c
+++ b/usr.sbin/ppp/ppp/ip.c
@@ -17,16 +17,14 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: ip.c,v 1.19 2000/02/27 00:21:08 brian Exp $
+ * $Id: ip.c,v 1.20 2000/02/27 01:34:04 brian Exp $
*
* TODO:
* o Return ICMP message for filterd packet
* and optionaly record it into log.
*/
#include <sys/param.h>
-#if defined(__OpenBSD__) || defined(__NetBSD__)
#include <sys/socket.h>
-#endif
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
@@ -617,6 +615,7 @@ ip_Input(struct bundle *bundle, struct link *l, struct mbuf *bp)
int nb, nw;
struct tun_data tun;
struct ip *pip;
+ char *data;
if (bundle->ncp.ipcp.fsm.state != ST_OPENED) {
log_Printf(LogWARN, "ip_Input: IPCP not open - packet dropped\n");
@@ -625,7 +624,6 @@ ip_Input(struct bundle *bundle, struct link *l, struct mbuf *bp)
}
m_settype(bp, MB_IPIN);
- tun_fill_header(tun, AF_INET);
nb = m_length(bp);
if (nb > sizeof tun.data) {
log_Printf(LogWARN, "ip_Input: %s: Packet too large (got %d, max %d)\n",
@@ -644,8 +642,14 @@ ip_Input(struct bundle *bundle, struct link *l, struct mbuf *bp)
ipcp_AddInOctets(&bundle->ncp.ipcp, nb);
- nb += sizeof tun - sizeof tun.data;
- nw = write(bundle->dev.fd, &tun, nb);
+ if (bundle->dev.header) {
+ tun.family = htonl(AF_INET);
+ nb += sizeof tun - sizeof tun.data;
+ data = (char *)&tun;
+ } else
+ data = tun.data;
+
+ nw = write(bundle->dev.fd, data, nb);
if (nw != nb) {
if (nw == -1)
log_Printf(LogERROR, "ip_Input: %s: wrote %d, got %s\n",
diff --git a/usr.sbin/ppp/ppp/main.c b/usr.sbin/ppp/ppp/main.c
index 65dc7707387..152a1e01adf 100644
--- a/usr.sbin/ppp/ppp/main.c
+++ b/usr.sbin/ppp/ppp/main.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: main.c,v 1.16 2000/02/27 00:21:08 brian Exp $
+ * $Id: main.c,v 1.17 2000/02/27 01:34:05 brian Exp $
*
* TODO:
*/
@@ -466,6 +466,7 @@ main(int argc, char **argv)
bundle->notify.fd = bgpipe[1];
}
+ bundle_ChangedPID(bundle);
bundle_LockTun(bundle); /* we have a new pid */
}
diff --git a/usr.sbin/ppp/ppp/tun.h b/usr.sbin/ppp/ppp/tun.h
index fbf78b4072c..1e5535575ab 100644
--- a/usr.sbin/ppp/ppp/tun.h
+++ b/usr.sbin/ppp/ppp/tun.h
@@ -23,24 +23,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: tun.h,v 1.2 1999/02/06 03:22:49 brian Exp $
+ * $Id: tun.h,v 1.3 2000/02/27 01:34:05 brian Exp $
*/
struct tun_data {
-#ifdef __OpenBSD__
- u_int32_t head;
-#endif
+ u_int32_t family;
u_char data[MAX_MRU];
};
-#ifdef __OpenBSD__
-#define tun_fill_header(f,proto) do { (f).head = htonl(proto); } while (0)
-#define tun_check_header(f,proto) ((f).head == htonl(proto))
-#else
-#define tun_fill_header(f,proto) do { } while (0)
-#define tun_check_header(f,proto) (1)
-#endif
-
struct bundle;
extern void tun_configure(struct bundle *, int);