svn commit: r245076 - stable/9/usr.sbin/rarpd
Mark Johnston
markj at FreeBSD.org
Sat Jan 5 22:55:09 UTC 2013
Author: markj
Date: Sat Jan 5 22:55:08 2013
New Revision: 245076
URL: http://svnweb.freebsd.org/changeset/base/245076
Log:
- Add IFT_L2VLAN (vlan(4)) support.
- Add a -P option to support PID files. When -a is specified
/var/run/rarpd.pid is used by default, and when an interface is
specified /var/run/rarpd.<ifname>.pid is used by default.
Approved by: hrs, emaste (co-mentor)
Modified:
stable/9/usr.sbin/rarpd/Makefile
stable/9/usr.sbin/rarpd/rarpd.8
stable/9/usr.sbin/rarpd/rarpd.c
Directory Properties:
stable/9/usr.sbin/rarpd/ (props changed)
Modified: stable/9/usr.sbin/rarpd/Makefile
==============================================================================
--- stable/9/usr.sbin/rarpd/Makefile Sat Jan 5 22:04:40 2013 (r245075)
+++ stable/9/usr.sbin/rarpd/Makefile Sat Jan 5 22:55:08 2013 (r245076)
@@ -4,6 +4,9 @@
PROG= rarpd
MAN= rarpd.8
+DPADD= ${LIBUTIL}
+LDADD= -lutil
+
WARNS?= 3
# This breaks with format strings returned by expand_syslog_m().. argh!
#FORMAT_AUDIT?= 1
Modified: stable/9/usr.sbin/rarpd/rarpd.8
==============================================================================
--- stable/9/usr.sbin/rarpd/rarpd.8 Sat Jan 5 22:04:40 2013 (r245075)
+++ stable/9/usr.sbin/rarpd/rarpd.8 Sat Jan 5 22:55:08 2013 (r245076)
@@ -16,7 +16,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd November 16, 2001
+.Dd July 9, 2012
.Dt RARPD 8
.Os
.Sh NAME
@@ -27,9 +27,11 @@
.Fl a
.Op Fl dfsv
.Op Fl t Ar directory
+.Op Fl P Ar pidfile
.Nm
.Op Fl dfsv
.Op Fl t Ar directory
+.Op Fl P Ar pidfile
.Ar interface
.Sh DESCRIPTION
The
@@ -92,6 +94,15 @@ instead of via
.Xr syslog 3 .
.It Fl f
Run in the foreground.
+.It Fl P
+Specify the pathname of the PID file.
+If not specified,
+.Pa /var/run/rarpd.pid
+or
+.Pa /var/run/rarpd.ifname.pid
+will be used depending on the
+.Fl a
+flag or the specified interface name.
.It Fl s
Supply a response to any RARP request for which an ethernet to IP address
mapping exists; do not depend on the existence of
@@ -115,6 +126,7 @@ Enable verbose syslogging.
.It Pa /etc/ethers
.It Pa /etc/hosts
.It Pa /tftpboot
+.It Pa /var/run/rarpd.pid
.El
.Sh SEE ALSO
.Xr bpf 4
Modified: stable/9/usr.sbin/rarpd/rarpd.c
==============================================================================
--- stable/9/usr.sbin/rarpd/rarpd.c Sat Jan 5 22:04:40 2013 (r245075)
+++ stable/9/usr.sbin/rarpd/rarpd.c Sat Jan 5 22:55:08 2013 (r245076)
@@ -27,8 +27,8 @@ __FBSDID("$FreeBSD$");
/*
* rarpd - Reverse ARP Daemon
*
- * Usage: rarpd -a [-dfsv] [-t directory] [hostname]
- * rarpd [-dfsv] [-t directory] interface [hostname]
+ * Usage: rarpd -a [-dfsv] [-t directory] [-P pidfile] [hostname]
+ * rarpd [-dfsv] [-t directory] [-P pidfile] interface [hostname]
*
* 'hostname' is optional solely for backwards compatibility with Sun's rarpd.
* Currently, the argument is ignored.
@@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$");
#include <syslog.h>
#include <stdlib.h>
#include <unistd.h>
+#include <libutil.h>
/* Cast a struct sockaddr to a struct sockaddr_in */
#define SATOSIN(sa) ((struct sockaddr_in *)(sa))
@@ -99,6 +100,11 @@ int sflag; /* ignore /tftpboot */
static u_char zero[6];
+static char pidfile_buf[PATH_MAX];
+static char *pidfile;
+#define RARPD_PIDFILE "/var/run/rarpd.%s.pid"
+static struct pidfh *pidfile_fh;
+
static int bpf_open(void);
static in_addr_t choose_ipaddr(in_addr_t **, in_addr_t, in_addr_t);
static char *eatoa(u_char *);
@@ -140,7 +146,7 @@ main(int argc, char *argv[])
openlog(name, LOG_PID | LOG_CONS, LOG_DAEMON);
opterr = 0;
- while ((op = getopt(argc, argv, "adfst:v")) != -1)
+ while ((op = getopt(argc, argv, "adfsP:t:v")) != -1)
switch (op) {
case 'a':
++aflag;
@@ -158,6 +164,12 @@ main(int argc, char *argv[])
++sflag;
break;
+ case 'P':
+ strncpy(pidfile_buf, optarg, sizeof(pidfile_buf) - 1);
+ pidfile_buf[sizeof(pidfile_buf) - 1] = '\0';
+ pidfile = pidfile_buf;
+ break;
+
case 't':
tftp_dir = optarg;
break;
@@ -182,10 +194,23 @@ main(int argc, char *argv[])
init(ifname);
if (!fflag) {
+ if (pidfile == NULL && ifname != NULL && aflag == 0) {
+ snprintf(pidfile_buf, sizeof(pidfile_buf) - 1,
+ RARPD_PIDFILE, ifname);
+ pidfile_buf[sizeof(pidfile_buf) - 1] = '\0';
+ pidfile = pidfile_buf;
+ }
+ /* If pidfile == NULL, /var/run/<progname>.pid will be used. */
+ pidfile_fh = pidfile_open(pidfile, 0600, NULL);
+ if (pidfile_fh == NULL)
+ logmsg(LOG_ERR, "Cannot open or create pidfile: %s",
+ (pidfile == NULL) ? "/var/run/rarpd.pid" : pidfile);
if (daemon(0,0)) {
logmsg(LOG_ERR, "cannot fork");
+ pidfile_remove(pidfile_fh);
exit(1);
}
+ pidfile_write(pidfile_fh);
}
rarp_loop();
return(0);
@@ -235,6 +260,7 @@ init_one(struct ifaddrs *ifa, char *targ
ii = (struct if_info *)malloc(sizeof(*ii));
if (ii == NULL) {
logmsg(LOG_ERR, "malloc: %m");
+ pidfile_remove(pidfile_fh);
exit(1);
}
bzero(ii, sizeof(*ii));
@@ -252,6 +278,7 @@ init_one(struct ifaddrs *ifa, char *targ
ii2 = (struct if_info *)malloc(sizeof(*ii2));
if (ii2 == NULL) {
logmsg(LOG_ERR, "malloc: %m");
+ pidfile_remove(pidfile_fh);
exit(1);
}
memcpy(ii2, ii, sizeof(*ii2));
@@ -274,8 +301,11 @@ init_one(struct ifaddrs *ifa, char *targ
case AF_LINK:
ll = (struct sockaddr_dl *)ifa->ifa_addr;
- if (ll->sdl_type == IFT_ETHER)
+ switch (ll->sdl_type) {
+ case IFT_ETHER:
+ case IFT_L2VLAN:
bcopy(LLADDR(ll), ii->ii_eaddr, 6);
+ }
break;
}
}
@@ -294,6 +324,7 @@ init(char *target)
error = getifaddrs(&ifhead);
if (error) {
logmsg(LOG_ERR, "getifaddrs: %m");
+ pidfile_remove(pidfile_fh);
exit(1);
}
/*
@@ -340,8 +371,8 @@ static void
usage(void)
{
(void)fprintf(stderr, "%s\n%s\n",
- "usage: rarpd -a [-dfsv] [-t directory]",
- " rarpd [-dfsv] [-t directory] interface");
+ "usage: rarpd -a [-dfsv] [-t directory] [-P pidfile]",
+ " rarpd [-dfsv] [-t directory] [-P pidfile] interface");
exit(1);
}
@@ -362,6 +393,7 @@ bpf_open(void)
if (fd == -1) {
logmsg(LOG_ERR, "%s: %m", device);
+ pidfile_remove(pidfile_fh);
exit(1);
}
return fd;
@@ -400,12 +432,12 @@ rarp_open(char *device)
immediate = 1;
if (ioctl(fd, BIOCIMMEDIATE, &immediate) == -1) {
logmsg(LOG_ERR, "BIOCIMMEDIATE: %m");
- exit(1);
+ goto rarp_open_err;
}
strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) == -1) {
logmsg(LOG_ERR, "BIOCSETIF: %m");
- exit(1);
+ goto rarp_open_err;
}
/*
* Check that the data link layer is an Ethernet; this code won't
@@ -413,20 +445,24 @@ rarp_open(char *device)
*/
if (ioctl(fd, BIOCGDLT, (caddr_t)&dlt) == -1) {
logmsg(LOG_ERR, "BIOCGDLT: %m");
- exit(1);
+ goto rarp_open_err;
}
if (dlt != DLT_EN10MB) {
logmsg(LOG_ERR, "%s is not an ethernet", device);
- exit(1);
+ goto rarp_open_err;
}
/*
* Set filter program.
*/
if (ioctl(fd, BIOCSETF, (caddr_t)&filter) == -1) {
logmsg(LOG_ERR, "BIOCSETF: %m");
- exit(1);
+ goto rarp_open_err;
}
return fd;
+
+rarp_open_err:
+ pidfile_remove(pidfile_fh);
+ exit(1);
}
/*
@@ -481,16 +517,16 @@ rarp_loop(void)
if (iflist == NULL) {
logmsg(LOG_ERR, "no interfaces");
- exit(1);
+ goto rarpd_loop_err;
}
if (ioctl(iflist->ii_fd, BIOCGBLEN, (caddr_t)&bufsize) == -1) {
logmsg(LOG_ERR, "BIOCGBLEN: %m");
- exit(1);
+ goto rarpd_loop_err;
}
buf = malloc(bufsize);
if (buf == NULL) {
logmsg(LOG_ERR, "malloc: %m");
- exit(1);
+ goto rarpd_loop_err;
}
while (1) {
@@ -510,7 +546,7 @@ rarp_loop(void)
if (errno == EINTR)
continue;
logmsg(LOG_ERR, "select: %m");
- exit(1);
+ goto rarpd_loop_err;
}
for (ii = iflist; ii != NULL; ii = ii->ii_next) {
fd = ii->ii_fd;
@@ -538,6 +574,11 @@ rarp_loop(void)
}
}
#undef bhp
+ return;
+
+rarpd_loop_err:
+ pidfile_remove(pidfile_fh);
+ exit(1);
}
/*
@@ -563,12 +604,12 @@ rarp_bootable(in_addr_t addr)
else {
if (chdir(tftp_dir) == -1) {
logmsg(LOG_ERR, "chdir: %s: %m", tftp_dir);
- exit(1);
+ goto rarp_bootable_err;
}
d = opendir(".");
if (d == NULL) {
logmsg(LOG_ERR, "opendir: %m");
- exit(1);
+ goto rarp_bootable_err;
}
dd = d;
}
@@ -576,6 +617,10 @@ rarp_bootable(in_addr_t addr)
if (strncmp(dent->d_name, ipname, 8) == 0)
return 1;
return 0;
+
+rarp_bootable_err:
+ pidfile_remove(pidfile_fh);
+ exit(1);
}
/*
@@ -679,6 +724,7 @@ update_arptab(u_char *ep, in_addr_t ipad
r = socket(PF_ROUTE, SOCK_RAW, 0);
if (r == -1) {
logmsg(LOG_ERR, "raw route socket: %m");
+ pidfile_remove(pidfile_fh);
exit(1);
}
pid = getpid();
More information about the svn-src-stable-9
mailing list