diff options
author | Mats O Jansson <maja@cvs.openbsd.org> | 1999-03-27 14:31:24 +0000 |
---|---|---|
committer | Mats O Jansson <maja@cvs.openbsd.org> | 1999-03-27 14:31:24 +0000 |
commit | bdf0fa84baff8b71398e2760eb959d794df83839 (patch) | |
tree | 78765789cde5335291ef0143474ed35b3342c8ec /usr.sbin/mopd/otherOS | |
parent | 2afff778427a17b38b9ebedd4bb658d36eee20c3 (diff) |
Upgrade to 2.5.4. Mopprobe is working again, and some linux support. -moj
Diffstat (limited to 'usr.sbin/mopd/otherOS')
-rw-r--r-- | usr.sbin/mopd/otherOS/Makefile | 80 | ||||
-rw-r--r-- | usr.sbin/mopd/otherOS/linux2/Makefile | 12 | ||||
-rw-r--r-- | usr.sbin/mopd/otherOS/linux2/mopd-x.x.x.spec | 74 | ||||
-rw-r--r-- | usr.sbin/mopd/otherOS/linux2/mopd.init | 50 | ||||
-rw-r--r-- | usr.sbin/mopd/otherOS/loop-linux2.c | 168 | ||||
-rw-r--r-- | usr.sbin/mopd/otherOS/mdtype | 26 | ||||
-rw-r--r-- | usr.sbin/mopd/otherOS/os-linux2.h | 53 | ||||
-rw-r--r-- | usr.sbin/mopd/otherOS/ostype | 12 | ||||
-rw-r--r-- | usr.sbin/mopd/otherOS/pf-linux2.c | 318 |
9 files changed, 784 insertions, 9 deletions
diff --git a/usr.sbin/mopd/otherOS/Makefile b/usr.sbin/mopd/otherOS/Makefile index 5d6294d0783..b47bcce59ce 100644 --- a/usr.sbin/mopd/otherOS/Makefile +++ b/usr.sbin/mopd/otherOS/Makefile @@ -1,12 +1,13 @@ # Copyright (c) 1993-1994 Mats O Jansson, Stockholm, Sweden # All rights reserved. # -# @(#) $OpenBSD: Makefile,v 1.2 1996/09/21 19:12:42 maja Exp $ +# @(#) $OpenBSD: Makefile,v 1.3 1999/03/27 14:31:22 maja Exp $ # Script (or program) that returns the machine and os types, # or jsut edit in the name yourself. MD=`./mdtype` OS=`./ostype` +REL=`cat ../common/VERSION` CCOPT = -O INCLUDES = -I.. @@ -25,9 +26,21 @@ STANDARD_CFLAGS = $(CCOPT) $(SPEC_FLAGS) $(DEFINES) $(INCLUDES) #sun4-sunos4#CFLAGS = $(STANDARD_CFLAGS) -DNO__P #sun4-sunos5#CFLAGS = $(STANDARD_CFLAGS) -DNO__P -DDLPIPF #rs6000-aix3#CFLAGS = $(STANDARD_CFLAGS) +#alpha-linux2#CFLAGS = $(STANDARD_CFLAGS) +#i386-linux2#CFLAGS = $(STANDARD_CFLAGS) +#sparc-linux2#CFLAGS = $(STANDARD_CFLAGS) #sun4-sunos5#LIB = -lsocket +INSTBIN="#" +INSTMAN="#" +#alpha-linux2#INSTBIN= install -c -s -o root -g root -m 755 +#alpha-linux2#INSTMAN= install -c -o root -g root -m 644 +#i386-linux2#INSTBIN= install -c -s -o root -g root -m 755 +#i386-linux2#INSTMAN= install -c -o root -g root -m 644 +#sparc-linux2#INSTBIN= install -c -s -o root -g root -m 755 +#sparc-linux2#INSTMAN= install -c -o root -g root -m 644 + # Change these to cc/lex/yacc if you don't have gcc, flex and/or bison. CC = cc LEX = lex @@ -42,15 +55,19 @@ MAKE = make DIRS= mopchk mopd mopprobe moptrace +CHDOC= mopchk.1 CHFIL= mopchk.c CHOBJ= mopchk.o CHHDR= +LDDOC= mopd.8 LDFIL= mopd.c process.c LDOBJ= mopd.o process.o LDHDR= process.h +PBDOC= mopprobe.1 PBFIL= mopprobe.c PBOBJ= mopprobe.o PBHDR= +TRDOC= moptrace.1 TRFIL= moptrace.c TROBJ= moptrace.o TRHDR= @@ -67,21 +84,37 @@ TRHDR= #rs6000-aix3#PFFIL= pf-aix3.c #rs6000-aix3#LOOP= loop.c +#alpha-linux2#OSHDR= os-linux2.h +#alpha-linux2#PFFIL= pf-linux2.c +#alpha-linux2#LOOP= loop-linux2.c + +#i386-linux2#OSHDR= os-linux2.h +#i386-linux2#PFFIL= pf-linux2.c +#i386-linux2#LOOP= loop-linux2.c + +#sparc-linux2#OSHDR= os-linux2.h +#sparc-linux2#PFFIL= pf-linux2.c +#sparc-linux2#LOOP= loop-linux2.c + #mopchk#COFIL= device.c file.c mopdef.c #mopchk#COOBJ= device.o file.o mopdef.o #mopchk#OTOBJ= pf.o loop.o +#mopchk#MANDIR=man1 #mopd#COFIL= cmp.c device.c dl.c file.c get.c mopdef.c nma.c print.c put.c rc.c #mopd#COOBJ= cmp.o device.o dl.o file.o get.o mopdef.o nma.o print.o put.o rc.o #mopd#OTOBJ= pf.o loop.o +#mopd#MANDIR=man8 -#mopprobe#COFIL= cmp.c device.c get.c mopdef.c -#mopprobe#COOBJ= cmp.o device.o get.o mopdef.o +#mopprobe#COFIL= cmp.c device.c get.c mopdef.c nma.c print.c +#mopprobe#COOBJ= cmp.o device.o get.o mopdef.o nma.o print.o #mopprobe#OTOBJ= pf.o loop.o +#mopprobe#MANDIR=man1 #moptrace#COFIL= cmp.c device.c dl.c get.c mopdef.c nma.c print.c rc.c #moptrace#COOBJ= cmp.o device.o dl.o get.o mopdef.o nma.o print.o rc.o #moptrace#OTOBJ= pf.o loop.o +#moptrace#MANDIR=man1 toplvl: osmake @@ -109,44 +142,77 @@ submake: force ${MAKE} ${MFLAGS} files; cd ..; fi; done; \ for i in $(DIRS); do cd $$i; ${MAKE} ${MFLAGS}; cd ..; done +osinstall: force + @os=$(OS); \ + if [ -d $$os ]; then (cd $$os; ${MAKE} ${MFLAGS} INSTALL="$(INSTALL)" install); fi; + +install: osinstall + @dir=$(MD)-$(OS); cd $$dir; \ + for i in $(DIRS); do cd $$i; ${MAKE} ${MFLAGS} INSTALL="$(INSTALL)" inst; cd ..; done; + config: @md=$(MD); os=$(OS); dir=$$md-$$os; \ mkdir $$dir; chmod ug+w $$dir; \ sed -e "/^toplvl:/d" -e "s/^#$$dir#//" Makefile >$$dir/Makefile; \ chmod ug+w $$dir/Makefile +tar: + @rel=$(REL); cd ..; \ + tar -cf ../mopd-$$rel.tar [M]* c*/[Va-z]* m*/[MTa-np-z]* otherOS/*.[ch] otherOS/[M]* otherOS/*type otherOS/linux2/[Mm]*; \ + gzip -9 ../mopd-$$rel.tar + #mopchk#files: force #mopchk# echo "Adding files in mopchk"; \ #mopchk# ln -s ../../../common common; \ -#mopchk# for i in $(CHFIL) $(CHHDR); do ln -s ../../../mopchk/$$i $$i; done; \ +#mopchk# for i in $(CHFIL) $(CHHDR) $(CHDOC); do ln -s ../../../mopchk/$$i $$i; done; \ #mopchk# for i in $(COFIL); do ln -s ../../../common/$$i $$i; done; \ #mopchk# ln -s ../../$(OSHDR) os.h; ln -s ../../$(PFFIL) pf.c; \ #mopchk# ln -s ../../$(LOOP) loop.c +#mopchk#inst: mopchk +#mopchk# echo "Installing files in mopchk"; +#mopchk# $(INSTBIN) $< $(INSTALL)/usr/sbin +#mopchk# $(INSTMAN) $(CHDOC) $(INSTALL)/usr/man/$(MANDIR) + #mopd#files: force #mopd# echo "Adding files in mopd"; \ #mopd# ln -s ../../../common common; \ -#mopd# for i in $(LDFIL) $(LDHDR); do ln -s ../../../mopd/$$i $$i; done; \ +#mopd# for i in $(LDFIL) $(LDHDR) $(LDDOC); do ln -s ../../../mopd/$$i $$i; done; \ #mopd# for i in $(COFIL); do ln -s ../../../common/$$i $$i; done; \ #mopd# ln -s ../../$(OSHDR) os.h; ln -s ../../$(PFFIL) pf.c; \ #mopd# ln -s ../../$(LOOP) loop.c +#mopd#inst: mopd +#mopd# echo "Installing files in mopd"; +#mopd# $(INSTBIN) $< $(INSTALL)/usr/sbin +#mopd# $(INSTMAN) $(LDDOC) $(INSTALL)/usr/man/$(MANDIR) + #mopprobe#files: force #mopprobe# echo "Adding files in mopprobe"; \ #mopprobe# ln -s ../../../common common; \ -#mopprobe# for i in $(PBFIL) $(PBHDR); do ln -s ../../../mopprobe/$$i $$i; done; \ +#mopprobe# for i in $(PBFIL) $(PBHDR) $(PBDOC); do ln -s ../../../mopprobe/$$i $$i; done; \ #mopprobe# for i in $(COFIL); do ln -s ../../../common/$$i $$i; done; \ #mopprobe# ln -s ../../$(OSHDR) os.h; ln -s ../../$(PFFIL) pf.c; \ #mopprobe# ln -s ../../$(LOOP) loop.c +#mopprobe#inst: mopprobe +#mopprobe# echo "Installing files in mopprobe"; +#mopprobe# $(INSTBIN) $< $(INSTALL)/usr/sbin +#mopprobe# $(INSTMAN) $(PBDOC) $(INSTALL)/usr/man/$(MANDIR) + #moptrace#files: force #moptrace# echo "Adding files in moptrace"; \ #moptrace# ln -s ../../../common common; \ -#moptrace# for i in $(TRFIL) $(TRHDR); do ln -s ../../../moptrace/$$i $$i; done; \ +#moptrace# for i in $(TRFIL) $(TRHDR) $(TRDOC); do ln -s ../../../moptrace/$$i $$i; done; \ #moptrace# for i in $(COFIL); do ln -s ../../../common/$$i $$i; done; \ #moptrace# ln -s ../../$(OSHDR) os.h; ln -s ../../$(PFFIL) pf.c; \ #moptrace# ln -s ../../$(LOOP) loop.c +#moptrace#inst: moptrace +#moptrace# echo "Installing files in moptrace"; +#moptrace# $(INSTBIN) $< $(INSTALL)/usr/sbin +#moptrace# $(INSTMAN) $(TRDOC) $(INSTALL)/usr/man/$(MANDIR) + mopchk: $(CHOBJ) $(COOBJ) $(OTOBJ) version.o $(CC) $(CFLAGS) -o $@ $(CHOBJ) $(COOBJ) $(OTOBJ) version.o $(LIB) diff --git a/usr.sbin/mopd/otherOS/linux2/Makefile b/usr.sbin/mopd/otherOS/linux2/Makefile new file mode 100644 index 00000000000..1d4596fcf9f --- /dev/null +++ b/usr.sbin/mopd/otherOS/linux2/Makefile @@ -0,0 +1,12 @@ +# Copyright (c) 1999 Mats O Jansson, Stockholm, Sweden +# All rights reserved. +# +# @(#) $OpenBSD: Makefile,v 1.1 1999/03/27 14:31:23 maja Exp $ + +INSTBIN= install -c -s -o root -g root -m 755 +INSTINIT= install -c -o root -g root -m 755 + +install: mopd.init + echo "Installing files in linux2"; + $(INSTINIT) $< $(INSTALL)/etc/rc.d/init.d/mopd + diff --git a/usr.sbin/mopd/otherOS/linux2/mopd-x.x.x.spec b/usr.sbin/mopd/otherOS/linux2/mopd-x.x.x.spec new file mode 100644 index 00000000000..c5fdc87d6ab --- /dev/null +++ b/usr.sbin/mopd/otherOS/linux2/mopd-x.x.x.spec @@ -0,0 +1,74 @@ +# $OpenBSD: mopd-x.x.x.spec,v 1.1 1999/03/27 14:31:23 maja Exp $ +Summary: MOP (Maintenance Operations Protocol) loader daemon +Name: mopd +Version: 2.5.4 +Release: 2 +Copyright: BSD +Group: Networking +Source: ftp://ftp.stacken.kth.se/pub/NetBSD/mopd/mopd-2.5.4.tar.gz +BuildRoot: /var/tmp/mopd-2.5.4 +Packager: Mats O Jansson <moj@stacken.kth.se> + +%description +Mopd services MOP Load requests on the Ethernet connected to interface or +all interfaces if a `-a' is given. In a load request received by mopd a +filename can be given. This is the normal case for e.g. terminal servers. +If a filename isn't given mopd must know what image to load. + +Upon receiving a request, mopd checks if the requested file exists in +/tftpboot/mop, the filename is normaly uppercase and with an extension of +.SYS. If the filename isn't given, the ethernet address of the target is +used as filename, e.g. 08002b09f4de.SYS and it might be a soft link to +another file. + +Mopd supports two kinds of files. The first type that is check is if the +file is in a.out(5) format. If not, a couple of Digital's formats are +checked. + +%prep +%setup -q -c mopd-2.5.4 + +%build +(cd otherOS && make) + +%install +rm -rf $RPM_BUILD_ROOT +mkdir -p -m 755 $RPM_BUILD_ROOT/etc/rc.d/init.d +mkdir -p -m 755 $RPM_BUILD_ROOT/usr/man/man1 +mkdir -p -m 755 $RPM_BUILD_ROOT/usr/man/man8 +mkdir -p -m 755 $RPM_BUILD_ROOT/usr/sbin +mkdir -p -m 755 $RPM_BUILD_ROOT/tftpboot/mop +(cd otherOS && make INSTALL="$RPM_BUILD_ROOT" install) + +%clean +cd .. +rm -rf mopd-2.5.4 +rm -rf $RPM_BUILD_ROOT + +%post +/sbin/chkconfig --add mopd + +%postun +if [ $1 = 0 ]; then + /sbin/chkconfig --del mopd +fi + +%files +%attr(755, root, root) /tftpboot/mop +%attr(755, root, root) /usr/sbin/mopchk +%attr(644, root, root) /usr/man/man1/mopchk.1 +%attr(755, root, root) /usr/sbin/mopd +%attr(644, root, root) /usr/man/man8/mopd.8 +%attr(755, root, root) /usr/sbin/mopprobe +%attr(644, root, root) /usr/man/man1/mopprobe.1 +%attr(755, root, root) /usr/sbin/moptrace +%attr(644, root, root) /usr/man/man1/moptrace.1 +%config %attr(755, root, root) /etc/rc.d/init.d/mopd + +%changelog +* Fri Mar 26 1998 Mats O Jansson <moj@stacken.kth.se> +- incorparated lots of ideas from <xenophon@irtnog.org> who had written + the mopd-linux-2.5.3 package. + +* Wed Mar 24 1998 Mats O Jansson <moj@stacken.kth.se> +- initial build diff --git a/usr.sbin/mopd/otherOS/linux2/mopd.init b/usr.sbin/mopd/otherOS/linux2/mopd.init new file mode 100644 index 00000000000..e037db17e4f --- /dev/null +++ b/usr.sbin/mopd/otherOS/linux2/mopd.init @@ -0,0 +1,50 @@ +#! /bin/sh +# $OpenBSD: mopd.init,v 1.1 1999/03/27 14:31:23 maja Exp $ +# +# chkconfig: - 60 20 +# description: The mopd server allows older DEC workstations to net boot \ +# from Linux boxes. It (along with rarp) is rarely used anymore; \ +# bootp and dhcp have mostly replaced both of them. +# processname: mopd + +# Source function library. +. /etc/rc.d/init.d/functions + +# Get config. +. /etc/sysconfig/network + +# Check that networking is up. +if [ ${NETWORKING} = "no" ] +then + exit 0 +fi + +# See how we were called. +case "$1" in + start) + echo -n "Starting mopd services: " + daemon mopd -a + + echo + touch /var/lock/subsys/mopd + ;; + stop) + echo -n "Stopping mopd services: " + killproc mopd + + echo + rm -f /var/lock/subsys/mopd + ;; + status) + status mopd + ;; + restart|reload) + $0 stop + $0 start + ;; + *) + echo "Usage: mopd {start|stop|status|restart|reload}" + exit 1 +esac + +exit 0 diff --git a/usr.sbin/mopd/otherOS/loop-linux2.c b/usr.sbin/mopd/otherOS/loop-linux2.c new file mode 100644 index 00000000000..d726211726b --- /dev/null +++ b/usr.sbin/mopd/otherOS/loop-linux2.c @@ -0,0 +1,168 @@ +/* + * Copyright (c) 1993-95 Mats O Jansson. 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#ifndef LINT +static char rcsid[] = "$Id: loop-linux2.c,v 1.1 1999/03/27 14:31:22 maja Exp $"; +#endif + +#include <stdlib.h> +#include <strings.h> +#include <unistd.h> +#if defined(__bsdi__) || defined(__FreeBSD__) +#include <sys/time.h> +#endif +#include <sys/ioctl.h> +#include <sys/errno.h> + +#include "os.h" +#include "common/common.h" +#include "common/mopdef.h" + +int +mopOpenRC(p, trans) + struct if_info *p; + int trans; +{ +#ifndef NORC + return (*(p->iopen))(p->if_name, + O_RDWR, + MOP_K_PROTO_RC, + trans); +#else + return -1; +#endif +} + +int +mopOpenDL(p, trans) + struct if_info *p; + int trans; +{ +#ifndef NODL + return (*(p->iopen))(p->if_name, + O_RDWR, + MOP_K_PROTO_DL, + trans); +#else + return -1; +#endif +} + +void +mopReadRC() +{ +} + +void +mopReadDL() +{ +} + +/* + * The list of all interfaces that are being listened to. loop() + * "selects" on the descriptors in this list. + */ +struct if_info *iflist; + +void mopProcess __P((struct if_info *, u_char *)); + +/* + * Loop indefinitely listening for MOP requests on the + * interfaces in 'iflist'. + */ +void +Loop() +{ + u_char *buf, *bp, *ep; + int cc; + fd_set fds, listeners; + int bufsize = 1100, maxfd =0; + struct if_info *ii; + +/* FIXME : this is a hack, for some reason specifying an interface would + * cause it to fail because bufsize is an impossible number, so I added a + * sanity check because I'm too lazy to figure out why. -- Karl + */ + if (bufsize > 1100) + bufsize = 64; + + if (iflist == 0) { + syslog(LOG_ERR, "no interfaces"); + exit(0); + } + + buf = (u_char *) malloc((unsigned) bufsize); + + if (buf == 0) { + syslog(LOG_ERR, "malloc: %m"); + exit(0); + } + /* + * Find the highest numbered file descriptor for select(). + * Initialize the set of descriptors to listen to. + */ + FD_ZERO(&fds); + for (ii = iflist; ii; ii = ii->next) { + if (ii->fd != -1) { + FD_SET(ii->fd, &fds); + if (ii->fd > maxfd) + maxfd = ii->fd; + } + } + while (1) { + listeners = fds; + if (select(maxfd + 1, &listeners, (fd_set *) 0, + (fd_set *) 0, (struct timeval *) 0) < 0) { + syslog(LOG_ERR, "select: %m"); + exit(0); + } + for (ii = iflist; ii; ii = ii->next) { + if (ii->fd != -1) { + if (!FD_ISSET(ii->fd, &listeners)) + continue; + } + again: + cc = read(ii->fd, (char *) buf, bufsize); + /* Don't choke when we get ptraced */ + if (cc < 0 && errno == EINTR) + goto again; + + bp = buf; + ep = bp + cc; + +if(bp < ep) + { + mopProcess(ii,buf); + } + +} + +} +} + diff --git a/usr.sbin/mopd/otherOS/mdtype b/usr.sbin/mopd/otherOS/mdtype index ea274963ed6..a74b48dee4b 100644 --- a/usr.sbin/mopd/otherOS/mdtype +++ b/usr.sbin/mopd/otherOS/mdtype @@ -1,6 +1,6 @@ #!/bin/sh # -# @(#) $OpenBSD: mdtype,v 1.2 1996/09/21 19:12:45 maja Exp $ +# @(#) $OpenBSD: mdtype,v 1.3 1999/03/27 14:31:22 maja Exp $ # # Determine machine type. # @@ -42,6 +42,30 @@ if [ -f /usr/bin/uname ]; then fi +if [ -f /bin/uname ]; then + + os=`/bin/uname` + + if [ $os = "Linux" ]; then + + machine="`/bin/uname -m`" + + if [ $machine = "i686" ]; then + machine="i386" + fi + + if [ $machine = "i586" ]; then + machine="i386" + fi + + if [ $machine = "i486" ]; then + machine="i386" + fi + + fi + +fi + echo $machine if [ $machine = "UNKNOWN" ]; then diff --git a/usr.sbin/mopd/otherOS/os-linux2.h b/usr.sbin/mopd/otherOS/os-linux2.h new file mode 100644 index 00000000000..d2658be2d5c --- /dev/null +++ b/usr.sbin/mopd/otherOS/os-linux2.h @@ -0,0 +1,53 @@ +/* $OpenBSD: os-linux2.h,v 1.1 1999/03/27 14:31:22 maja Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * @(#) $OpenBSD: os-linux2.h,v 1.1 1999/03/27 14:31:22 maja Exp $ + */ + +#include <stdio.h> + +#include <syslog.h> +#include <signal.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> +#include <sys/socket.h> +#include <net/if.h> +#include <sys/ioctl.h> +#include <stdlib.h> +#include <sys/time.h> +#include <time.h> +#include <fcntl.h> +#include <unistd.h> +#include <string.h> + +#define LINUX2_PF +#define SETPGRP_NOPARAM + diff --git a/usr.sbin/mopd/otherOS/ostype b/usr.sbin/mopd/otherOS/ostype index c1359bed291..ebe2b365a37 100644 --- a/usr.sbin/mopd/otherOS/ostype +++ b/usr.sbin/mopd/otherOS/ostype @@ -1,6 +1,6 @@ #!/bin/sh # -# @(#) $OpenBSD: ostype,v 1.2 1996/09/21 19:12:48 maja Exp $ +# @(#) $OpenBSD: ostype,v 1.3 1999/03/27 14:31:23 maja Exp $ # # Determine os type. # @@ -24,6 +24,16 @@ if [ -f /usr/bin/uname ]; then fi +if [ -f /bin/uname ]; then + + osname=`/bin/uname` + + if [ $osname = "Linux" ]; then + os="linux`/bin/uname -r | /usr/bin/cut -d. -f1`" + fi + +fi + echo $os if [ $os = "UNKNOWN" ]; then diff --git a/usr.sbin/mopd/otherOS/pf-linux2.c b/usr.sbin/mopd/otherOS/pf-linux2.c new file mode 100644 index 00000000000..de05c43e410 --- /dev/null +++ b/usr.sbin/mopd/otherOS/pf-linux2.c @@ -0,0 +1,318 @@ +/* + * General Purpose AppleTalk Packet Filter Interface + * + * Copyright (c) 1992-1995, The University of Melbourne. + * All Rights Reserved. Permission to redistribute or + * use any part of this software for any purpose must + * be obtained in writing from the copyright owner. + * + * This software is supplied "as is" without express + * or implied warranty. + * + * djh@munnari.OZ.AU + * + * Supports: + * Linux SOCK_PACKET + * + * $Author: maja $ + * $Revision: 1.1 $ + * + * + * Modified for use with the linux-mopd port by Karl Maftoum + * u963870@student.canberra.edu.au + * + */ + +/* + * include header files + * + */ + +#include <stdio.h> +#include <sys/types.h> +#include <sys/time.h> +#include <sys/ioctl.h> +#include <sys/file.h> +#include <sys/socket.h> +#include <net/if.h> +#include <sys/errno.h> +#include <linux/if_ether.h> +#include <netdb.h> +#include <ctype.h> +#include <string.h> + +#define MOPDEF_SUPRESS_EXTERN +#include "common/mopdef.h" + +/* + * definitions + * + */ + +#define READBUFSIZ 4096 +#define NUMRDS 32 + +struct RDS { + u_short dataLen; + u_char *dataPtr; +}; + +/* + * variables + * + */ + +struct socklist { + int iflen; + struct sockaddr sa; +} socklist[32]; + +struct ifreq ifr; +extern int errno; +extern int promisc; + +struct RDS RDS[NUMRDS]; + +/* + * Open and initialize packet filter + * for a particular protocol type. + * + */ + + +int +pfInit(interface, mode, protocol, typ) +char *interface; +u_short protocol; +int typ, mode; +{ + int s; + int ioarg; + char device[64]; + unsigned long if_flags; + + + { u_short prot; + + prot = ((typ == TRANS_8023) ? htons(ETH_P_802_2) : htons(protocol)); + if ((s = socket(AF_INET, SOCK_PACKET, prot)) < 0) { + perror(interface); + return(-1); + } + if (s >= 32) { + close(s); + return(-1); + } + } + + /* + * set filter for protocol and type (IPTalk, Phase 1/2) + * + */ + + if (setup_pf(s, protocol, typ) < 0) + return(-1); + + /* + * set options, bind to underlying interface + * + */ + + strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); + + /* record socket interface name and length */ + strncpy(socklist[s].sa.sa_data, interface, sizeof(socklist[s].sa.sa_data)); + socklist[s].iflen = strlen(interface); + + return(s); +} + +/* + * establish protocol filter + * + */ + +int +setup_pf(s, prot, typ) +int s, typ; +u_short prot; +{ + int ioarg; + u_short offset; + return(0); +} + +/* + * get the interface ethernet address + * + */ + +int +pfEthAddr(s, interface, addr) +int s; +char *interface; +u_char *addr; +{ + strcpy(ifr.ifr_name, interface); + ifr.ifr_addr.sa_family = AF_INET; + if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { + perror("SIOCGIFHWADDR"); + return(-1); + } + memcpy((char *)addr, ifr.ifr_hwaddr.sa_data, 6); + return(0); +} + +/* + * add a multicast address to the interface + * + */ + +int +pfAddMulti(s, interface, addr) +int s; +char *interface; +u_char *addr; +{ + int sock; + + strcpy(ifr.ifr_name, interface); + + ifr.ifr_addr.sa_family = AF_UNSPEC; + bcopy((char *)addr, ifr.ifr_addr.sa_data, 6); + + /* + * open a socket, temporarily, to use for SIOC* ioctls + * + */ + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + perror("socket()"); + return(-1); + } + if (ioctl(sock, SIOCADDMULTI, (caddr_t)&ifr) < 0) { + perror("SIOCADDMULTI"); + close(sock); + return(-1); + } + close(sock); + + return(0); +} + +/* + * delete a multicast address from the interface + * + */ + +int +pfDelMulti(s, interface, addr) +int s; +char *interface; +u_char *addr; +{ + int sock; + + strcpy(ifr.ifr_name, interface); + + ifr.ifr_addr.sa_family = AF_UNSPEC; + bcopy((char *)addr, ifr.ifr_addr.sa_data, 6); + + /* + * open a socket, temporarily, to use for SIOC* ioctls + * + */ + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + perror("socket()"); + return(-1); + } + if (ioctl(sock, SIOCDELMULTI, (caddr_t)&ifr) < 0) { + perror("SIOCDELMULTI"); + close(sock); + return(-1); + } + close(sock); + + return(0); +} + +/* + * return 1 if ethernet interface capable of multiple opens + * + */ + +int +eth_mopen(phase) +int phase; +{ + if (phase == 2) + return(0); + return(1); +} + +/* + * read a packet + * Read Data Structure describes packet(s) received + * + */ + + + + +int +pfRead(fd, buf, len) +int fd, len; +u_char *buf; +{ + int i, cc; + + int fromlen; + struct sockaddr sa; + + RDS[0].dataLen = 0; + fromlen = sizeof(struct sockaddr); + + if ((cc = recvfrom(fd, (char *)buf, len, 0, &sa, &fromlen)) <= 0) + return(cc); + + /* check if from right interface */ + for (i = socklist[fd].iflen-1; i >= 0; i--) + if (sa.sa_data[i] != socklist[fd].sa.sa_data[i]) + return(0); + + RDS[0].dataLen = cc; + RDS[0].dataPtr = buf; + RDS[1].dataLen = 0; + + return(cc); +} + +/* + * write a packet + * + */ + +int +pfWrite(fd, buf, len) +int fd, len; +u_char *buf; +{ + + if (sendto(fd, buf, len, 0, &socklist[fd].sa, sizeof(struct sockaddr)) == len) + return(len); + + return(-1); +} + +/* + * Return information to device.c how to open device. + * In this case the driver can handle both Ethernet type II and + * IEEE 802.3 frames (SNAP) in a single pfOpen. + */ + +int +pfTrans(interface) + char *interface; +{ + return TRANS_ETHER+TRANS_8023; +} + |