diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-04-25 06:29:54 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-04-25 06:29:54 +0000 |
commit | 2d8114c122b4e562e43d9badff92df0a5bc34789 (patch) | |
tree | fc619a5bcc5bc3ddaf3eaebf6b7b237744a6b548 | |
parent | 4de721ed54cbe92d6c77a4da135edd3b031efa7f (diff) |
logging to syslogd on -l flag; netbsd
create /var/run/rarpd.pid if running
-rw-r--r-- | usr.sbin/rarpd/pathnames.h | 31 | ||||
-rw-r--r-- | usr.sbin/rarpd/rarpd.8 | 8 | ||||
-rw-r--r-- | usr.sbin/rarpd/rarpd.c | 51 |
3 files changed, 76 insertions, 14 deletions
diff --git a/usr.sbin/rarpd/pathnames.h b/usr.sbin/rarpd/pathnames.h new file mode 100644 index 00000000000..1f3e93a3c3c --- /dev/null +++ b/usr.sbin/rarpd/pathnames.h @@ -0,0 +1,31 @@ +/* $NetBSD: pathnames.h,v 1.1 1998/04/23 02:48:33 mrg Exp $ */ + +/* + * Copyright (c) 1998 Matthew R. Green + * 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. 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. + */ + + #define _PATH_RARPDPID "/var/run/rarpd.pid" diff --git a/usr.sbin/rarpd/rarpd.8 b/usr.sbin/rarpd/rarpd.8 index 37f2e39a437..e79b76bcb7e 100644 --- a/usr.sbin/rarpd/rarpd.8 +++ b/usr.sbin/rarpd/rarpd.8 @@ -1,4 +1,4 @@ -.\" +.\" $NetBSD: rarpd.8,v 1.7 1998/04/15 15:06:06 mrg Exp $ .\" Copyright (c) 1988-1990 The Regents of the University of California. .\" All rights reserved. .\" @@ -17,7 +17,7 @@ .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -.\" @(#) $Id: rarpd.8,v 1.2 1996/12/10 18:24:54 deraadt Exp $ +.\" @(#) $Id: rarpd.8,v 1.3 1998/04/25 06:29:52 deraadt Exp $ .\" .Dd October 26, 1990 .Dt RARPD 8 @@ -26,7 +26,7 @@ .Nd Reverse ARP Daemon .Sh SYNOPSIS .Nm rarpd -.Op Fl adf +.Op Fl adfl .Op Ar interface .Sh DESCRIPTION .Nm Rarpd @@ -70,6 +70,8 @@ This option implies the option. .It Fl f Run in the foreground. +.It Fl l +Log all requests to syslog. .El .Sh FILES .Bl -tag -width Pa -compact diff --git a/usr.sbin/rarpd/rarpd.c b/usr.sbin/rarpd/rarpd.c index 7d0c71762c7..10762b31a08 100644 --- a/usr.sbin/rarpd/rarpd.c +++ b/usr.sbin/rarpd/rarpd.c @@ -1,5 +1,5 @@ -/* $OpenBSD: rarpd.c,v 1.17 1998/03/23 04:18:41 deraadt Exp $ */ -/* $NetBSD: rarpd.c,v 1.12 1996/03/21 18:28:23 jtc Exp $ */ +/* $OpenBSD: rarpd.c,v 1.18 1998/04/25 06:29:53 deraadt Exp $ */ +/* $NetBSD: rarpd.c,v 1.25 1998/04/23 02:48:33 mrg Exp $ */ /* * Copyright (c) 1990 The Regents of the University of California. @@ -28,15 +28,15 @@ char copyright[] = #endif /* not lint */ #ifndef lint -static char rcsid[] = "$OpenBSD: rarpd.c,v 1.17 1998/03/23 04:18:41 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: rarpd.c,v 1.18 1998/04/25 06:29:53 deraadt Exp $"; #endif /* * rarpd - Reverse ARP Daemon * - * Usage: rarpd -a [ -d -f ] - * rarpd [ -d -f ] interface + * Usage: rarpd -a [ -d ] [ -f ] [ -l ] + * rarpd [ -d ] [ -f ] [ -l ] interface */ #include <stdio.h> @@ -60,6 +60,8 @@ static char rcsid[] = "$OpenBSD: rarpd.c,v 1.17 1998/03/23 04:18:41 deraadt Exp #include <arpa/inet.h> #include <dirent.h> +#include "pathnames.h" + #define FATAL 1 /* fatal error occurred */ #define NONFATAL 0 /* non fatal error occurred */ @@ -88,7 +90,8 @@ void lookup_eaddr __P((char *, u_char *)); void lookup_ipaddr __P((char *, u_int32_t *, u_int32_t *)); void usage __P((void)); void rarp_process __P((struct if_info *, u_char *)); -void rarp_reply __P((struct if_info *, struct ether_header *, u_int32_t)); +void rarp_reply __P((struct if_info *, struct ether_header *, u_int32_t, + struct hostent *)); void update_arptab __P((u_char *, u_int32_t)); void err __P((int, const char *,...)); void debug __P((const char *,...)); @@ -101,6 +104,7 @@ int rarp_bootable __P((u_int32_t)); int aflag = 0; /* listen on "all" interfaces */ int dflag = 0; /* print debugging messages */ int fflag = 0; /* don't fork */ +int lflag = 0; /* log all replies */ int main(argc, argv) @@ -117,7 +121,7 @@ main(argc, argv) openlog(__progname, LOG_PID | LOG_CONS, LOG_DAEMON); opterr = 0; - while ((op = getopt(argc, argv, "adf")) != -1) { + while ((op = getopt(argc, argv, "adfl")) != -1) { switch (op) { case 'a': ++aflag; @@ -131,6 +135,10 @@ main(argc, argv) ++fflag; break; + case 'l': + ++lflag; + break; + default: usage(); /* NOTREACHED */ @@ -147,6 +155,8 @@ main(argc, argv) init_one(ifname); if ((!fflag) && (!dflag)) { + FILE *fp; + pid = fork(); if (pid > 0) /* Parent exits, leaving child in background. */ @@ -156,6 +166,13 @@ main(argc, argv) err(FATAL, "cannot fork"); /* NOTREACHED */ } + + /* write pid file */ + if ((fp = fopen(_PATH_RARPDPID, "w")) != NULL) { + fprintf(fp, "%u\n", getpid()); + (void)fclose(fp); + } + /* Fade into the background */ f = open("/dev/tty", O_RDWR); if (f >= 0) { @@ -459,7 +476,7 @@ rarp_loop() fd = ii->ii_fd; if (!FD_ISSET(fd, lfdsp)) continue; - again: + again: cc = read(fd, (char *) buf, bufsize); /* Don't choke when we get ptraced */ if (cc < 0 && errno == EINTR) @@ -593,7 +610,7 @@ rarp_process(ii, pkt) #ifdef REQUIRE_TFTPBOOT if (rarp_bootable(htonl(target_ipaddr))) #endif - rarp_reply(ii, ep, target_ipaddr); + rarp_reply(ii, ep, target_ipaddr, hp); } /* * Lookup the ethernet address of the interface attached to the BPF @@ -686,6 +703,7 @@ lookup_ipaddr(ifname, addrp, netmaskp) *addrp = ((struct sockaddr_in *) & ifr.ifr_addr)->sin_addr.s_addr; if (ioctl(fd, SIOCGIFNETMASK, (char *) &ifr) < 0) { perror("SIOCGIFNETMASK"); + unlink(_PATH_RARPDPID); exit(1); } *netmaskp = ((struct sockaddr_in *) & ifr.ifr_addr)->sin_addr.s_addr; @@ -773,10 +791,11 @@ update_arptab(ep, ipaddr) * ARP request. */ void -rarp_reply(ii, ep, ipaddr) +rarp_reply(ii, ep, ipaddr, hp) struct if_info *ii; struct ether_header *ep; u_int32_t ipaddr; + struct hostent *hp; { int n; struct ether_arp *ap = (struct ether_arp *) (ep + 1); @@ -798,6 +817,14 @@ rarp_reply(ii, ep, ipaddr) /* Target hardware is unchanged. */ memcpy((char *) ap->arp_spa, (char *) &ii->ii_ipaddr, 4); + if (lflag) { + struct ether_addr ea; + + memcpy(&ea.ether_addr_octet, &ap->arp_sha, 6); + syslog(LOG_INFO, "%s asked; %s replied", hp->h_name, + ether_ntoa(&ea)); + } + len = sizeof(*ep) + sizeof(*ap); n = write(ii->ii_fd, (char *) ep, len); if (n != len) { @@ -854,8 +881,10 @@ va_dcl } vsyslog(LOG_ERR, fmt, ap); va_end(ap); - if (fatal) + if (fatal) { + unlink(_PATH_RARPDPID); exit(1); + } /* NOTREACHED */ } |