Module Name: src
Committed By: ozaki-r
Date: Wed Jul 29 06:07:36 UTC 2015
Modified Files:
src/distrib/sets/lists/base: mi
src/distrib/sets/lists/debug: mi
src/usr.sbin/arp: Makefile arp.c
Added Files:
src/usr.sbin/arp: arp_hostops.c arp_rumpops.c prog_ops.h
Log Message:
Introduce rump.arp
arp(8) uses RTM that requires that getpid(2) works correctly. Unfortunately
supporting getpid(2) in librumphijack will be tricky so that we rump-ify
arp(8) as well as ifconfig and route commands.
Suggested by pooka@.
To generate a diff of this commit:
cvs rdiff -u -r1.1104 -r1.1105 src/distrib/sets/lists/base/mi
cvs rdiff -u -r1.121 -r1.122 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/arp/Makefile
cvs rdiff -u -r1.51 -r1.52 src/usr.sbin/arp/arp.c
cvs rdiff -u -r0 -r1.1 src/usr.sbin/arp/arp_hostops.c \
src/usr.sbin/arp/arp_rumpops.c src/usr.sbin/arp/prog_ops.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/base/mi
diff -u src/distrib/sets/lists/base/mi:1.1104 src/distrib/sets/lists/base/mi:1.1105
--- src/distrib/sets/lists/base/mi:1.1104 Mon Jun 22 06:02:01 2015
+++ src/distrib/sets/lists/base/mi Wed Jul 29 06:07:35 2015
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1104 2015/06/22 06:02:01 matt Exp $
+# $NetBSD: mi,v 1.1105 2015/07/29 06:07:35 ozaki-r Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@@ -1819,6 +1819,7 @@
./usr/sbin/rtadvd base-router-bin use_inet6
./usr/sbin/rtquery base-netutil-bin
./usr/sbin/rtsold base-obsolete obsolete
+./usr/sbin/rump.arp base-netutil-bin rump
./usr/sbin/rump.envstat base-sysutil-bin rump
./usr/sbin/rump.powerd base-sysutil-bin rump
./usr/sbin/rump.traceroute base-netutil-bin rump
Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.121 src/distrib/sets/lists/debug/mi:1.122
--- src/distrib/sets/lists/debug/mi:1.121 Sat Jun 27 15:46:09 2015
+++ src/distrib/sets/lists/debug/mi Wed Jul 29 06:07:35 2015
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.121 2015/06/27 15:46:09 matt Exp $
+# $NetBSD: mi,v 1.122 2015/07/29 06:07:35 ozaki-r Exp $
./etc/mtree/set.debug comp-sys-root
./usr/lib comp-sys-usr compatdir
@@ -1202,6 +1202,7 @@
./usr/libdata/debug/usr/sbin/rtadvd.debug comp-router-debug use_inet6,debug
./usr/libdata/debug/usr/sbin/rtquery.debug comp-netutil-debug debug
./usr/libdata/debug/usr/sbin/rtsold.debug comp-obsolete obsolete
+./usr/libdata/debug/usr/sbin/rump.arp.debug comp-netutil-debug debug,rump
./usr/libdata/debug/usr/sbin/rump.envstat.debug comp-sysutil-debug debug,rump
./usr/libdata/debug/usr/sbin/rump.powerd.debug comp-sysutil-debug debug,rump
./usr/libdata/debug/usr/sbin/rump.traceroute.debug comp-netutil-debug debug,rump
Index: src/usr.sbin/arp/Makefile
diff -u src/usr.sbin/arp/Makefile:1.11 src/usr.sbin/arp/Makefile:1.12
--- src/usr.sbin/arp/Makefile:1.11 Wed Apr 22 15:23:02 2009
+++ src/usr.sbin/arp/Makefile Wed Jul 29 06:07:35 2015
@@ -1,7 +1,15 @@
-# $NetBSD: Makefile,v 1.11 2009/04/22 15:23:02 lukem Exp $
+# $NetBSD: Makefile,v 1.12 2015/07/29 06:07:35 ozaki-r Exp $
# from: @(#)Makefile 8.2 (Berkeley) 4/18/94
-PROG= arp
-MAN= arp.4 arp.8
+.include <bsd.own.mk>
+
+RUMPPRG= arp
+MAN= arp.4 arp.8
+
+.PATH: ${.CURDIR}/../../lib/libc/net
+RUMPSRCS= getifaddrs.c getnameinfo.c
+.if (${MKRUMP} != "no")
+CPPFLAGS+= -DRUMP_ACTION
+.endif
.include <bsd.prog.mk>
Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.51 src/usr.sbin/arp/arp.c:1.52
--- src/usr.sbin/arp/arp.c:1.51 Fri Jun 7 17:18:33 2013
+++ src/usr.sbin/arp/arp.c Wed Jul 29 06:07:35 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: arp.c,v 1.51 2013/06/07 17:18:33 christos Exp $ */
+/* $NetBSD: arp.c,v 1.52 2015/07/29 06:07:35 ozaki-r Exp $ */
/*
* Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
#if 0
static char sccsid[] = "@(#)arp.c 8.3 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: arp.c,v 1.51 2013/06/07 17:18:33 christos Exp $");
+__RCSID("$NetBSD: arp.c,v 1.52 2015/07/29 06:07:35 ozaki-r Exp $");
#endif
#endif /* not lint */
@@ -76,6 +76,8 @@ __RCSID("$NetBSD: arp.c,v 1.51 2013/06/0
#include <unistd.h>
#include <ifaddrs.h>
+#include "prog_ops.h"
+
static int is_llinfo(const struct sockaddr_dl *, int);
static int delete(const char *, const char *);
static void dump(uint32_t);
@@ -126,8 +128,6 @@ main(int argc, char **argv)
setprogname(argv[0]);
- pid = getpid();
-
while ((ch = getopt(argc, argv, "andsfv")) != -1)
switch((char)ch) {
case 'a':
@@ -155,6 +155,11 @@ main(int argc, char **argv)
if (!op && aflag)
op = 'a';
+ if (prog_init && prog_init() == -1)
+ err(1, "init failed");
+
+ pid = prog_getpid();
+
switch((char)op) {
case 'a':
dump(0);
@@ -232,7 +237,7 @@ getsocket(void)
{
if (s >= 0)
return;
- s = socket(PF_ROUTE, SOCK_RAW, 0);
+ s = prog_socket(PF_ROUTE, SOCK_RAW, 0);
if (s < 0)
err(1, "socket");
}
@@ -464,13 +469,13 @@ dump(uint32_t addr)
mib[3] = AF_INET;
mib[4] = NET_RT_FLAGS;
mib[5] = RTF_LLINFO;
- if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
+ if (prog_sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
err(1, "route-sysctl-estimate");
if (needed == 0)
return;
if ((buf = malloc(needed)) == NULL)
err(1, "malloc");
- if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+ if (prog_sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
err(1, "actual retrieval of routing table");
lim = buf + needed;
for (next = buf; next < lim; next += rtm->rtm_msglen) {
@@ -539,13 +544,13 @@ delete_all(void)
mib[3] = AF_INET;
mib[4] = NET_RT_FLAGS;
mib[5] = RTF_LLINFO;
- if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
+ if (prog_sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
err(1, "route-sysctl-estimate");
if (needed == 0)
return;
if ((buf = malloc(needed)) == NULL)
err(1, "malloc");
- if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+ if (prog_sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
err(1, "actual retrieval of routing table");
lim = buf + needed;
for (next = buf; next < lim; next += rtm->rtm_msglen) {
@@ -676,14 +681,14 @@ doit:
l = rtm->rtm_msglen;
rtm->rtm_seq = ++seq;
rtm->rtm_type = cmd;
- if (write(s, &m_rtmsg, (size_t)l) < 0) {
+ if (prog_write(s, &m_rtmsg, (size_t)l) < 0) {
if (errno != ESRCH || cmd != RTM_DELETE) {
warn("writing to routing socket");
return (-1);
}
}
do {
- l = read(s, &m_rtmsg, sizeof(m_rtmsg));
+ l = prog_read(s, &m_rtmsg, sizeof(m_rtmsg));
} while (l > 0 && (rtm->rtm_seq != seq || rtm->rtm_pid != pid));
if (l < 0)
warn("read from routing socket");
Added files:
Index: src/usr.sbin/arp/arp_hostops.c
diff -u /dev/null src/usr.sbin/arp/arp_hostops.c:1.1
--- /dev/null Wed Jul 29 06:07:36 2015
+++ src/usr.sbin/arp/arp_hostops.c Wed Jul 29 06:07:35 2015
@@ -0,0 +1,52 @@
+/* $NetBSD: arp_hostops.c,v 1.1 2015/07/29 06:07:35 ozaki-r Exp $ */
+
+/*
+ * Copyright (c) 2015 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: arp_hostops.c,v 1.1 2015/07/29 06:07:35 ozaki-r Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/sysctl.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "prog_ops.h"
+
+const struct prog_ops prog_ops = {
+ .op_socket = socket,
+ .op_open = open,
+ .op_getpid = getpid,
+
+ .op_read = read,
+ .op_write = write,
+
+ .op_sysctl = sysctl,
+};
Index: src/usr.sbin/arp/arp_rumpops.c
diff -u /dev/null src/usr.sbin/arp/arp_rumpops.c:1.1
--- /dev/null Wed Jul 29 06:07:36 2015
+++ src/usr.sbin/arp/arp_rumpops.c Wed Jul 29 06:07:35 2015
@@ -0,0 +1,56 @@
+/* $NetBSD: arp_rumpops.c,v 1.1 2015/07/29 06:07:35 ozaki-r Exp $ */
+
+/*
+ * Copyright (c) 2015 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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: arp_rumpops.c,v 1.1 2015/07/29 06:07:35 ozaki-r Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <unistd.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+#include <rump/rumpclient.h>
+
+#include "prog_ops.h"
+
+const struct prog_ops prog_ops = {
+ .op_init = rumpclient_init,
+
+ .op_socket = rump_sys_socket,
+ .op_open = rump_sys_open,
+ .op_getpid = rump_sys_getpid,
+
+ .op_read = rump_sys_read,
+ .op_write = rump_sys_write,
+
+ .op_sysctl = rump_sys___sysctl,
+};
Index: src/usr.sbin/arp/prog_ops.h
diff -u /dev/null src/usr.sbin/arp/prog_ops.h:1.1
--- /dev/null Wed Jul 29 06:07:36 2015
+++ src/usr.sbin/arp/prog_ops.h Wed Jul 29 06:07:35 2015
@@ -0,0 +1,68 @@
+/* $NetBSD: prog_ops.h,v 1.1 2015/07/29 06:07:35 ozaki-r Exp $ */
+
+/*
+ * Copyright (c) 2015 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.
+ */
+
+#ifndef _PROG_OPS_H_
+#define _PROG_OPS_H_
+
+#include <sys/types.h>
+
+#ifndef CRUNCHOPS
+/* XXX: Keep same order with netstat! */
+struct prog_ops {
+ int (*op_init)(void);
+
+ int (*op_sysctl)(const int *, u_int, void *, size_t *,
+ const void *, size_t);
+
+ int (*op_socket)(int, int, int);
+ int (*op_open)(const char *, int, ...);
+ pid_t (*op_getpid)(void);
+
+ ssize_t (*op_read)(int, void *, size_t);
+ ssize_t (*op_write)(int, const void *, size_t);
+};
+extern const struct prog_ops prog_ops;
+
+#define prog_init prog_ops.op_init
+#define prog_socket prog_ops.op_socket
+#define prog_open prog_ops.op_open
+#define prog_getpid prog_ops.op_getpid
+#define prog_read prog_ops.op_read
+#define prog_write prog_ops.op_write
+#define prog_sysctl prog_ops.op_sysctl
+#else
+#define prog_init ((int (*)(void))NULL)
+#define prog_socket socket
+#define prog_open open
+#define prog_getpid getpid
+#define prog_read read
+#define prog_write write
+#define prog_sysctl sysctl
+#endif
+
+#endif /* _PROG_OPS_H_ */