summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoritojun <itojun>2001-07-18 06:47:36 +0000
committeritojun <itojun>2001-07-18 06:47:36 +0000
commitae74c4635dff2566d4187a13ebfbd3f87fac1d39 (patch)
tree8ff3fd99c00701811a7c2eab95cdc3b16bf505d6
parent2f011874a414173ec7b944aae09ec934819b8bf0 (diff)
downloadpkgsrc-ae74c4635dff2566d4187a13ebfbd3f87fac1d39.tar.gz
check if the hardware is really Wildlab LAMB (check MAC address),
so that we don't damage other i386 machines by mistake. bump pkgsrc version to 20010718.
-rw-r--r--sysutils/lambd/Makefile11
-rw-r--r--sysutils/lambd/files/Makefile3
-rw-r--r--sysutils/lambd/files/lambd.811
-rw-r--r--sysutils/lambd/files/lambd.c81
-rw-r--r--sysutils/lambd/files/lambio.c112
-rw-r--r--sysutils/lambd/files/lambio.h34
6 files changed, 209 insertions, 43 deletions
diff --git a/sysutils/lambd/Makefile b/sysutils/lambd/Makefile
index 34bd3c9fbbf..4b1b9651cc8 100644
--- a/sysutils/lambd/Makefile
+++ b/sysutils/lambd/Makefile
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.2 2001/07/13 23:12:18 itojun Exp $
+# $NetBSD: Makefile,v 1.3 2001/07/18 06:47:36 itojun Exp $
-DISTNAME= lambd-20010714
+DISTNAME= lambd-20010718
CATEGORIES= sysutils
MASTER_SITES= # none
DISTFILES= # none
@@ -15,12 +15,9 @@ ONLY_FOR_PLATFORM= NetBSD-*-i386
MAKE_ENV+= BINDIR=${PREFIX}/sbin MANDIR=${PREFIX}/man
-F= lambd.c lambd.8 Makefile
-
do-extract:
${MKDIR} ${WRKSRC}
- for i in ${F}; do \
- ${CP} ${FILESDIR}/$$i ${WRKSRC}; \
- done
+ ${CP} ${FILESDIR}/*.[ch8] ${WRKSRC}
+ ${CP} ${FILESDIR}/Makefile ${WRKSRC}
.include "../../mk/bsd.pkg.mk"
diff --git a/sysutils/lambd/files/Makefile b/sysutils/lambd/files/Makefile
index f0ddf082c92..30c1f2e3525 100644
--- a/sysutils/lambd/files/Makefile
+++ b/sysutils/lambd/files/Makefile
@@ -1,4 +1,7 @@
+# $NetBSD: Makefile,v 1.2 2001/07/18 06:47:37 itojun Exp $
+
PROG= lambd
+SRCS= lambd.c lambio.c
MAN= lambd.8
WARNS?= 2
diff --git a/sysutils/lambd/files/lambd.8 b/sysutils/lambd/files/lambd.8
index 23c2c78c139..2e52aa3c42e 100644
--- a/sysutils/lambd/files/lambd.8
+++ b/sysutils/lambd/files/lambd.8
@@ -1,4 +1,4 @@
-.\" $NetBSD: lambd.8,v 1.2 2001/07/13 22:56:24 itojun Exp $
+.\" $NetBSD: lambd.8,v 1.3 2001/07/18 06:47:37 itojun Exp $
.\"
.\" Copyright (C) 2001 WIDE Project. All rights reserved.
.\"
@@ -34,7 +34,7 @@
.Nd shutdown switch monitoring daemon for Wildlab LAMB
.Sh SYNOPSIS
.Nm ""
-.Op Fl df
+.Op Fl dfn
.Op Ar usec
.Sh DESCRIPTION
.Nm
@@ -47,8 +47,8 @@ Normally
.Nm
becomes a daemon on invocation.
.Pp
-Two command line options,
-.Fl df
+Three command line options,
+.Fl dfn
are supplied for debugging purposes.
.Fl d
lets it generate more messages, and forbids it from shutting down the machine.
@@ -56,6 +56,9 @@ lets it generate more messages, and forbids it from shutting down the machine.
runs
.Nm
in foreground mode.
+.Fl n
+avoids any hardware I/O accesses from
+.Nm Ns .
.Sh SEE ALSO
.Pa http://www.wildlab.com/
.Sh BUGS
diff --git a/sysutils/lambd/files/lambd.c b/sysutils/lambd/files/lambd.c
index bb11c07426c..ec411abf7db 100644
--- a/sysutils/lambd/files/lambd.c
+++ b/sysutils/lambd/files/lambd.c
@@ -1,4 +1,4 @@
-/* $NetBSD: lambd.c,v 1.1.1.1 2001/07/13 21:56:02 itojun Exp $ */
+/* $NetBSD: lambd.c,v 1.2 2001/07/18 06:47:37 itojun Exp $ */
/*
* Copyright (C) 2001 WIDE Project. All rights reserved.
@@ -36,16 +36,24 @@
#include <stdio.h>
#include <err.h>
+#include "lambio.h"
+
#define BASEPORT (0x378)
int main __P((int, char **));
void usage __P((void));
void mainloop __P((unsigned long));
+void lsleep __P((unsigned long));
int monitor __P((void));
void led __P((int));
int foreground = 0;
int debug = 0;
+#ifdef __i386__
+int nohw = 0;
+#else
+const int nohw = 1;
+#endif
int
main(argc, argv)
@@ -55,10 +63,8 @@ main(argc, argv)
int ch;
unsigned long delay;
char *p, *ep;
- unsigned long ioperm[1024 / sizeof(unsigned long) / 8];
- int i, off, bit;
- while ((ch = getopt(argc, argv, "df")) != -1) {
+ while ((ch = getopt(argc, argv, "dfn")) != -1) {
switch (ch) {
case 'd':
debug++;
@@ -66,12 +72,23 @@ main(argc, argv)
case 'f':
foreground++;
break;
+ case 'n':
+ nohw++;
+ break;
default:
usage();
exit(1);
}
}
+ if (!islamb()) {
+ if (debug)
+ fprintf(stderr, "it is not lamb\n");
+ nohw++;
+ } else
+ if (debug)
+ fprintf(stderr, "it is indeed lamb\n");
+
argc -= optind;
argv += optind;
@@ -91,19 +108,11 @@ main(argc, argv)
exit(1);
}
- if (i386_get_ioperm(ioperm) < 0) {
- err(1, "i386_get_ioperm");
- /* NOTREACHED */
- }
- for (i = 0; i < 3; i++) {
- off = (BASEPORT + i);
- bit = off % (sizeof(ioperm[0]) * 8);
- off /= (sizeof(ioperm[0]) * 8);
- ioperm[off] &= ~(1 << bit);
- }
- if (i386_set_ioperm(ioperm) < 0) {
- err(1, "i386_set_ioperm");
- /* NOTREACHED */
+ if (!nohw) {
+ if (lamb_open() < 0) {
+ err(1, "lamb_open");
+ /* NOTREACHED */
+ }
}
if (!foreground)
@@ -127,27 +136,19 @@ void
mainloop(delay)
unsigned long delay;
{
- unsigned int sec;
-
delay /= 2;
- sec = delay / 1000000;
- delay %= 1000000;
led(0);
while (1) {
if (monitor())
break;
led(1);
- if (sec)
- sleep(sec);
- usleep(delay);
+ lsleep(delay);
if (monitor())
break;
led(0);
- if (sec)
- sleep(sec);
- usleep(delay);
+ lsleep(delay);
}
led(0);
@@ -160,14 +161,27 @@ mainloop(delay)
}
}
-/* returns 1 if shutdown button is pressed */
+void
+lsleep(usec)
+ unsigned long usec;
+{
+
+ sleep(usec / 1000000);
+ usleep(usec % 1000000);
+}
+
int
monitor()
{
- if ((inb(BASEPORT + 1) & 0x20) == 0)
- return 1;
- else
+ int i;
+
+ if (nohw)
return 0;
+
+ for (i = 0; i < 10; i++)
+ if (!lamb_reboot())
+ return 0;
+ return 1;
}
void
@@ -177,5 +191,8 @@ led(on)
if (debug)
fprintf(stderr, "led=%d\n", on);
- outb(BASEPORT + 2, on ? 8 : 0);
+ if (nohw)
+ return;
+
+ lamb_led(on);
}
diff --git a/sysutils/lambd/files/lambio.c b/sysutils/lambd/files/lambio.c
new file mode 100644
index 00000000000..6edbb7d22ef
--- /dev/null
+++ b/sysutils/lambd/files/lambio.c
@@ -0,0 +1,112 @@
+/* $NetBSD: lambio.c,v 1.1 2001/07/18 06:47:37 itojun Exp $ */
+
+/*
+ * Copyright (C) 2001 WIDE Project. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_ether.h>
+#include <ifaddrs.h>
+
+#include <machine/sysarch.h>
+#include <machine/pio.h>
+
+#include "lambio.h"
+
+#define BASEPORT (0x378)
+
+int
+lamb_open()
+{
+ unsigned long ioperm[1024 / sizeof(unsigned long) / 8];
+ int off, bit;
+ int i;
+
+ if (i386_get_ioperm(ioperm) < 0)
+ return -1;
+ for (i = 0; i < 3; i++) {
+ off = (BASEPORT + i);
+ bit = off % (sizeof(ioperm[0]) * 8);
+ off /= (sizeof(ioperm[0]) * 8);
+ ioperm[off] &= ~(1 << bit);
+ }
+ if (i386_set_ioperm(ioperm) < 0)
+ return -1;
+
+ return 0;
+}
+
+/* returns 1 if shutdown button is pressed */
+int
+lamb_reboot()
+{
+
+ if ((inb(BASEPORT + 1) & 0x20) == 0)
+ return 1;
+ else
+ return 0;
+}
+
+void
+lamb_led(on)
+ int on;
+{
+
+ outb(BASEPORT + 2, on ? 8 : 0);
+}
+
+/*
+ * check MAC address against IEEE-registered Wildlab MAC address
+ */
+int
+islamb()
+{
+ struct ifaddrs *ifa, *ifap;
+ struct sockaddr_dl *sdl;
+ const u_int8_t wildlab[] = { 0x00, 0x30, 0xf5 };
+
+ if (getifaddrs(&ifap) < 0)
+ return 0;
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr->sa_family != AF_LINK)
+ continue;
+ sdl = (struct sockaddr_dl *)ifa->ifa_addr;
+ if (sdl->sdl_alen != sizeof(struct ether_addr))
+ continue;
+ if (memcmp(LLADDR(sdl), wildlab, sizeof(wildlab)) != 0)
+ continue;
+
+ freeifaddrs(ifap);
+ return 1;
+ }
+
+ freeifaddrs(ifap);
+ return 0;
+}
diff --git a/sysutils/lambd/files/lambio.h b/sysutils/lambd/files/lambio.h
new file mode 100644
index 00000000000..6d6645eea4d
--- /dev/null
+++ b/sysutils/lambd/files/lambio.h
@@ -0,0 +1,34 @@
+/* $NetBSD: lambio.h,v 1.1 2001/07/18 06:47:37 itojun Exp $ */
+
+/*
+ * Copyright (C) 2001 WIDE Project. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+int lamb_open __P((void));
+int lamb_reboot __P((void));
+void lamb_led __P((int));
+extern int islamb __P((void));