Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/isibootd Add isibootd(8) command, which is a dumb n...



details:   https://anonhg.NetBSD.org/src/rev/072614278c8f
branches:  trunk
changeset: 772079:072614278c8f
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sat Dec 17 13:24:18 2011 +0000

description:
Add isibootd(8) command, which is a dumb network boot server program
for the OMRON LUNA clients, like ndbootd(8) for Sun2 machines.

No particular comment on tech-userlevel@:
http://mail-index.NetBSD.org/tech-userlevel/2011/12/15/msg005872.html

diffstat:

 usr.sbin/isibootd/Makefile   |   13 +
 usr.sbin/isibootd/isibootd.8 |  101 +++++++++
 usr.sbin/isibootd/isibootd.c |  467 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 581 insertions(+), 0 deletions(-)

diffs (truncated from 593 to 300 lines):

diff -r 04f8eaa26f3d -r 072614278c8f usr.sbin/isibootd/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/isibootd/Makefile        Sat Dec 17 13:24:18 2011 +0000
@@ -0,0 +1,13 @@
+#      $NetBSD: Makefile,v 1.1 2011/12/17 13:24:18 tsutsui Exp $
+
+USE_FORT?= yes # network server
+
+PROG=  isibootd
+SRCS=  isibootd.c
+MAN=   isibootd.8
+
+LDADD+=        -lutil
+DPADD+=        ${LIBUTIL}
+
+.include <bsd.own.mk>
+.include <bsd.prog.mk>
diff -r 04f8eaa26f3d -r 072614278c8f usr.sbin/isibootd/isibootd.8
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/isibootd/isibootd.8      Sat Dec 17 13:24:18 2011 +0000
@@ -0,0 +1,101 @@
+.\"    $NetBSD: isibootd.8,v 1.1 2011/12/17 13:24:18 tsutsui Exp $
+.\"
+.\" Copyright (c) 2011 The NetBSD Foundation, Inc.
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+.\"
+.Dd December 15, 2011
+.Dt ISIBOOTD 8
+.Os
+.Sh NAME
+.Nm isibootd
+.Nd TRFS based network boot server
+.Sh SYNOPSIS
+.Nm
+.Op Fl d Ar tracelevel
+.Op Fl i Ar interface
+.Op Fl s Ar directory
+.Sh DESCRIPTION
+The
+.Nm
+command is a server which supports OMRON LUNA's network boot protocol
+based on the Transparent Remote File System (TRFS) protocol.
+The TRFS protocol uses special Ethernet type packets and
+works within a local network.
+.Pp
+.Nm
+is a simple TRFS server that only supports client reads for booting
+and exports files in a specified directory.
+.Nm
+accepts requests only from clients listed in the
+.Pa /etc/ethers
+and have valid hostnames.
+.Pp
+The options are as follows:
+.Bl -tag -width Fl
+.It Fl d Ar tracelevel
+Run
+.Nm
+in debug mode with specified tracelevel.
+The tracelevel can be value 1, 2, or 3, and
+greater tracelevel provides more detailed trace output.
+The server will not fork in the debug mode.
+.It Fl i Ar interface
+Specify a network interface to service network boot.
+If not specified
+.Nm
+searches available network interfaces (excluding loopback)
+and use the first configured 
+.Dq up
+one.
+.It Fl s Ar directory
+Specify a directory containing boot files to be served by
+.Nm .
+If not specified
+.Nm
+uses
+.Pa /tftpboot
+by default.
+.Sh FILES
+.Bl -tag -width Pa -compact
+.It Pa /etc/ethers
+.It Pa /etc/hosts
+.It Pa /tftpboot
+.It Pa /var/run/isibootd.pid
+.El
+.Sh SEE ALSO
+.Xr ethers 5 ,
+.Xr hosts 5 ,
+.Xr tftpd 8
+.Pp
+.Pa http://www.NetBSD.org/ports/luna68k/install.html
+.Sh HISTORY
+.Nm
+is based on
+.Pa isiboot
+utility which was originally written by
+.An Tohru Nishimura
+for
+.Nx Ns /luna68k
+development, and first appeared in
+.Nx 6.0 .
diff -r 04f8eaa26f3d -r 072614278c8f usr.sbin/isibootd/isibootd.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/isibootd/isibootd.c      Sat Dec 17 13:24:18 2011 +0000
@@ -0,0 +1,467 @@
+/*     $NetBSD: isibootd.c,v 1.1 2011/12/17 13:24:18 tsutsui Exp $     */
+/*     Id: isiboot.c,v 1.2 1999/12/26 14:33:33 nisimura Exp    */
+
+/*-
+ * Copyright (c) 2000, 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Tohru Nishimura.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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/param.h>
+#include <sys/types.h>
+#include <sys/endian.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+#include <net/bpf.h>
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_ether.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <ifaddrs.h>
+#include <netdb.h>
+#include <paths.h>
+#include <poll.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <util.h>
+
+#define        TRACE(l, x) if ((l) <= dbg) printf x
+
+/*
+ * TRFS (Integrated Solutions Inc. Transparent Remote File System) frame
+ *
+ * Following data format depends on m68k order, and aligned harmful
+ * to RISC processors.
+ */
+#define        FRAMETYPE       0x80df
+#define        FRAMELEN        1468
+struct frame {
+       uint8_t dst[ETHER_ADDR_LEN];
+       uint8_t src[ETHER_ADDR_LEN];
+       uint16_t type;
+       uint16_t pad_0;
+       uint16_t seqno;
+       uint8_t opcode;
+       uint8_t pad_1;
+       uint8_t pos[4];
+       uint8_t siz[4];
+       uint8_t data[FRAMELEN - 28];
+} __packed;
+
+struct station {
+       int     fd;
+       char    name[MAXHOSTNAMELEN];
+       char    ifname[IFNAMSIZ];
+       uint8_t addr[ETHER_ADDR_LEN];
+} station;
+
+struct session {
+       struct session *next;
+       int state;
+       FILE *file;
+       uint8_t addr[ETHER_ADDR_LEN];
+} *activelist, *freelist;
+#define        NEWPOOL 10
+
+#define        WAITING 0       /* implicit state after receiving the first frame */
+#define        OPENING 1       /* waiting for OPEN after CONNECT is received */
+#define        TRANSFER 2      /* data transferring state after OPEN is well done */
+static __unused const char *state[] = { "WAITING", "OPENING", "TRANSFER" };
+
+#define        CONNECT 0
+#define        OPEN    1
+#define        READ    2
+#define        CLOSE   4
+static __unused const char *op[] =
+    { "CONNECT", "OPEN", "READ", "WRITE", "CLOSE", "FIND" };
+
+static void createbpfport(char *, uint8_t **, size_t *, struct station *);
+static struct session *search(uint8_t *);
+static void closedown(struct session *);
+static void makepool(void);
+static char *etheraddr(uint8_t *);
+static int pickif(char *, uint8_t *);
+static __dead void usage(void);
+
+#define        FRAME(buf)      ((buf) + ((struct bpf_hdr *)(buf))->bh_hdrlen)
+
+#define        PATH_DEFBOOTDIR "/tftpboot"
+
+int
+main(int argc, char *argv[])
+{
+       int cc, dbg, dflag;
+       size_t iolen;
+       uint32_t pos, siz;
+       size_t nread;
+       char *ifname, *p;
+       const char *bootwd, *servername, *filename;
+       uint8_t *iobuf;
+       struct session *cp;
+       struct frame *fp;
+       struct pollfd pollfd;
+       char clientname[MAXHOSTNAMELEN + 1];
+       struct hostent *clientent;
+
+       ifname = NULL;
+       bootwd = PATH_DEFBOOTDIR;
+       dbg = 0;
+       dflag = 0;
+       while ((cc = getopt(argc, argv, "i:s:d:")) != -1) {
+               switch (cc) {
+               case 'i':
+                       ifname = optarg;
+                       break;
+               case 's':
+                       bootwd = optarg;
+                       break;
+               case 'd':
+                       dflag = 1;
+                       dbg = atoi(optarg);
+                       break;
+               default:
+                       usage();
+                       /* NOTREACHED */
+               }
+       }
+       argv += optind;
+       argc -= optind;
+
+       if (geteuid() != 0)
+               warnx("WARNING: run by non root priviledge");
+
+       memset(station.name, 0, sizeof(station.name));
+       gethostname(station.name, sizeof(station.name) - 1);
+       if ((p = strchr(station.name, '.')) != NULL)
+               *p = '\0';
+
+       createbpfport(ifname, &iobuf, &iolen, &station);
+
+       TRACE(1, ("Using interface: %s (%s)\n",
+           station.ifname, etheraddr(station.addr)));
+
+       if (!dflag) {
+               if (daemon(0, 0))
+                       err(EXIT_FAILURE, "can not start daemon");



Home | Main Index | Thread Index | Old Index