Source-Changes-HG archive

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

[src/trunk]: src Introduce rump.arp



details:   https://anonhg.NetBSD.org/src/rev/a47945748675
branches:  trunk
changeset: 809716:a47945748675
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Jul 29 06:07:35 2015 +0000

description:
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@.

diffstat:

 distrib/sets/lists/base/mi  |   3 +-
 distrib/sets/lists/debug/mi |   3 +-
 usr.sbin/arp/Makefile       |  14 +++++++-
 usr.sbin/arp/arp.c          |  27 ++++++++++-------
 usr.sbin/arp/arp_hostops.c  |  52 ++++++++++++++++++++++++++++++++++
 usr.sbin/arp/arp_rumpops.c  |  56 +++++++++++++++++++++++++++++++++++++
 usr.sbin/arp/prog_ops.h     |  68 +++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 207 insertions(+), 16 deletions(-)

diffs (truncated from 350 to 300 lines):

diff -r fc81420d8cec -r a47945748675 distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Wed Jul 29 04:59:48 2015 +0000
+++ b/distrib/sets/lists/base/mi        Wed Jul 29 06:07:35 2015 +0000
@@ -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
diff -r fc81420d8cec -r a47945748675 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Wed Jul 29 04:59:48 2015 +0000
+++ b/distrib/sets/lists/debug/mi       Wed Jul 29 06:07:35 2015 +0000
@@ -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
diff -r fc81420d8cec -r a47945748675 usr.sbin/arp/Makefile
--- a/usr.sbin/arp/Makefile     Wed Jul 29 04:59:48 2015 +0000
+++ b/usr.sbin/arp/Makefile     Wed Jul 29 06:07:35 2015 +0000
@@ -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>
diff -r fc81420d8cec -r a47945748675 usr.sbin/arp/arp.c
--- a/usr.sbin/arp/arp.c        Wed Jul 29 04:59:48 2015 +0000
+++ b/usr.sbin/arp/arp.c        Wed Jul 29 06:07:35 2015 +0000
@@ -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 @@
 #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 @@
 #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 @@
 
        setprogname(argv[0]);
 
-       pid = getpid();
-
        while ((ch = getopt(argc, argv, "andsfv")) != -1)
                switch((char)ch) {
                case 'a':
@@ -155,6 +155,11 @@
        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 @@
 {
        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 @@
        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 @@
        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 @@
        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");
diff -r fc81420d8cec -r a47945748675 usr.sbin/arp/arp_hostops.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/arp/arp_hostops.c        Wed Jul 29 06:07:35 2015 +0000
@@ -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,
+};
diff -r fc81420d8cec -r a47945748675 usr.sbin/arp/arp_rumpops.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/arp/arp_rumpops.c        Wed Jul 29 06:07:35 2015 +0000
@@ -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,
+};
diff -r fc81420d8cec -r a47945748675 usr.sbin/arp/prog_ops.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/arp/prog_ops.h   Wed Jul 29 06:07:35 2015 +0000
@@ -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



Home | Main Index | Thread Index | Old Index