Module Name:    src
Committed By:   ozaki-r
Date:           Mon Aug  3 09:51:40 UTC 2015

Modified Files:
        src/distrib/sets/lists/base: mi
        src/distrib/sets/lists/debug: mi
        src/usr.sbin/ndp: Makefile ndp.c
Added Files:
        src/usr.sbin/ndp: ndp_hostops.c ndp_rumpops.c prog_ops.h

Log Message:
Introduce rump.ndp

ndp(8) uses RTM that requires that getpid(2) works correctly. Unfortunately
supporting getpid(2) in librumphijack will be tricky so that we rump-ify
ndp(8) as well as arp(8).


To generate a diff of this commit:
cvs rdiff -u -r1.1106 -r1.1107 src/distrib/sets/lists/base/mi
cvs rdiff -u -r1.122 -r1.123 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/ndp/Makefile
cvs rdiff -u -r1.44 -r1.45 src/usr.sbin/ndp/ndp.c
cvs rdiff -u -r0 -r1.1 src/usr.sbin/ndp/ndp_hostops.c \
    src/usr.sbin/ndp/ndp_rumpops.c src/usr.sbin/ndp/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.1106 src/distrib/sets/lists/base/mi:1.1107
--- src/distrib/sets/lists/base/mi:1.1106	Sun Aug  2 11:09:05 2015
+++ src/distrib/sets/lists/base/mi	Mon Aug  3 09:51:40 2015
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1106 2015/08/02 11:09:05 jmcneill Exp $
+# $NetBSD: mi,v 1.1107 2015/08/03 09:51:40 ozaki-r Exp $
 #
 # Note:	Don't delete entries from here - mark them as "obsolete" instead,
 #	unless otherwise stated below.
@@ -1821,6 +1821,7 @@
 ./usr/sbin/rtquery				base-netutil-bin
 ./usr/sbin/rtsold				base-obsolete		obsolete
 ./usr/sbin/rump.arp				base-netutil-bin	rump
+./usr/sbin/rump.ndp				base-netutil-bin	inet6,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.122 src/distrib/sets/lists/debug/mi:1.123
--- src/distrib/sets/lists/debug/mi:1.122	Wed Jul 29 06:07:35 2015
+++ src/distrib/sets/lists/debug/mi	Mon Aug  3 09:51:40 2015
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.122 2015/07/29 06:07:35 ozaki-r Exp $
+# $NetBSD: mi,v 1.123 2015/08/03 09:51:40 ozaki-r Exp $
 
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib					comp-sys-usr		compatdir
@@ -1203,6 +1203,7 @@
 ./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.ndp.debug	comp-netutil-debug	inet6,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/ndp/Makefile
diff -u src/usr.sbin/ndp/Makefile:1.9 src/usr.sbin/ndp/Makefile:1.10
--- src/usr.sbin/ndp/Makefile:1.9	Fri Jun 21 12:50:50 2013
+++ src/usr.sbin/ndp/Makefile	Mon Aug  3 09:51:40 2015
@@ -1,17 +1,23 @@
-# $NetBSD: Makefile,v 1.9 2013/06/21 12:50:50 uwe Exp $
+# $NetBSD: Makefile,v 1.10 2015/08/03 09:51:40 ozaki-r Exp $
 
 .include <bsd.own.mk>
 
-USE_FORT?= yes	# network client
+USE_FORT?=	yes	# network client
 
-TCPDUMP= ${NETBSDSRCDIR}/external/bsd/tcpdump/dist
-.PATH:	${TCPDUMP}
+TCPDUMP=	${NETBSDSRCDIR}/external/bsd/tcpdump/dist
+.PATH:		${TCPDUMP}
 
-PROG=	ndp
-SRCS=	ndp.c gmt2local.c
-MAN=	ndp.8
-
-CPPFLAGS+=-DINET6
-CPPFLAGS+=-I. -I${TCPDUMP}
+RUMPPRG=	ndp
+SRCS=		ndp.c gmt2local.c
+MAN=		ndp.8
+
+CPPFLAGS+=	-DINET6
+CPPFLAGS+=	-I. -I${TCPDUMP}
+
+.PATH:		${.CURDIR}/../../lib/libc/net
+RUMPSRCS=	getifaddrs.c getnameinfo.c if_indextoname.c
+.if (${MKRUMP} != "no")
+CPPFLAGS+= 	-DRUMP_ACTION
+.endif
 
 .include <bsd.prog.mk>

Index: src/usr.sbin/ndp/ndp.c
diff -u src/usr.sbin/ndp/ndp.c:1.44 src/usr.sbin/ndp/ndp.c:1.45
--- src/usr.sbin/ndp/ndp.c:1.44	Tue Jun 16 23:04:14 2015
+++ src/usr.sbin/ndp/ndp.c	Mon Aug  3 09:51:40 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ndp.c,v 1.44 2015/06/16 23:04:14 christos Exp $	*/
+/*	$NetBSD: ndp.c,v 1.45 2015/08/03 09:51:40 ozaki-r Exp $	*/
 /*	$KAME: ndp.c,v 1.121 2005/07/13 11:30:13 keiichi Exp $	*/
 
 /*
@@ -104,7 +104,9 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <unistd.h>
+
 #include "gmt2local.h"
+#include "prog_ops.h"
 
 static pid_t pid;
 static int nflag;
@@ -159,8 +161,6 @@ main(int argc, char **argv)
 {
 	int ch;
 
-	pid = getpid();
-	thiszone = gmt2local(0L);
 	while ((ch = getopt(argc, argv, "acd:f:Ii:nprstA:HPR")) != -1)
 		switch (ch) {
 		case 'a':
@@ -210,6 +210,12 @@ main(int argc, char **argv)
 	argc -= optind;
 	argv += optind;
 
+	if (prog_init && prog_init() == -1)
+		err(1, "init failed");
+
+	pid = prog_getpid();
+	thiszone = gmt2local(0L);
+
 	switch (mode) {
 	case 'a':
 	case 'c':
@@ -301,7 +307,7 @@ static void
 getsocket(void)
 {
 	if (my_s < 0) {
-		my_s = socket(PF_ROUTE, SOCK_RAW, 0);
+		my_s = prog_socket(PF_ROUTE, SOCK_RAW, 0);
 		if (my_s < 0)
 			err(1, "socket");
 	}
@@ -534,12 +540,12 @@ again:;
 	mib[3] = AF_INET6;
 	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, "sysctl(PF_ROUTE estimate)");
 	if (needed > 0) {
 		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, "sysctl(PF_ROUTE, NET_RT_FLAGS)");
 		lim = buf + needed;
 	} else
@@ -716,20 +722,20 @@ getnbrinfo(struct in6_addr *addr, unsign
 	static struct in6_nbrinfo nbi;
 	int s;
 
-	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
+	if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
 		err(1, "socket");
 
 	(void)memset(&nbi, 0, sizeof(nbi));
 	(void)if_indextoname(ifindex, nbi.ifname);
 	nbi.addr = *addr;
-	if (ioctl(s, SIOCGNBRINFO_IN6, &nbi) < 0) {
+	if (prog_ioctl(s, SIOCGNBRINFO_IN6, &nbi) < 0) {
 		if (warning)
 			warn("ioctl(SIOCGNBRINFO_IN6)");
-		(void)close(s);
+		(void)prog_close(s);
 		return(NULL);
 	}
 
-	(void)close(s);
+	(void)prog_close(s);
 	return(&nbi);
 }
 
@@ -839,12 +845,12 @@ doit:
 	l = rtm->rtm_msglen;
 	rtm->rtm_seq = ++seq;
 	rtm->rtm_type = cmd;
-	if (write(my_s, &m_rtmsg, (size_t)l) == -1) {
+	if (prog_write(my_s, &m_rtmsg, (size_t)l) == -1) {
 		if (errno != ESRCH || cmd != RTM_DELETE)
 			err(1, "writing to routing socket");
 	}
 	do {
-		l = read(my_s, &m_rtmsg, sizeof(m_rtmsg));
+		l = prog_read(my_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");
@@ -861,11 +867,11 @@ ifinfo(char *ifname, int argc, char **ar
 	u_int8_t nullbuf[8];
 #endif
 
-	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
+	if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
 		err(1, "socket");
 	(void)memset(&nd, 0, sizeof(nd));
 	(void)strlcpy(nd.ifname, ifname, sizeof(nd.ifname));
-	if (ioctl(s, SIOCGIFINFO_IN6, &nd) < 0)
+	if (prog_ioctl(s, SIOCGIFINFO_IN6, &nd) < 0)
 		err(1, "ioctl(SIOCGIFINFO_IN6)");
 #define ND nd.ndi
 	newflags = ND.flags;
@@ -933,10 +939,10 @@ ifinfo(char *ifname, int argc, char **ar
 
 		ND.flags = newflags;
 #ifdef SIOCSIFINFO_IN6
-		if (ioctl(s, SIOCSIFINFO_IN6, &nd) < 0)
+		if (prog_ioctl(s, SIOCSIFINFO_IN6, &nd) < 0)
 			err(1, "ioctl(SIOCSIFINFO_IN6)");
 #else
-		if (ioctl(s, SIOCSIFINFO_FLAGS, &nd) < 0)
+		if (prog_ioctl(s, SIOCSIFINFO_FLAGS, &nd) < 0)
 			err(1, "ioctl(SIOCSIFINFO_FLAGS)");
 #endif
 #undef SETFLAG
@@ -946,7 +952,7 @@ ifinfo(char *ifname, int argc, char **ar
 	if (!ND.initialized)
 		errx(1, "%s: not initialized yet", ifname);
 
-	if (ioctl(s, SIOCGIFINFO_IN6, &nd) < 0)
+	if (prog_ioctl(s, SIOCGIFINFO_IN6, &nd) < 0)
 		err(1, "ioctl(SIOCGIFINFO_IN6)");
 	(void)printf("linkmtu=%d", ND.linkmtu);
 	(void)printf(", maxmtu=%d", ND.maxmtu);
@@ -1011,7 +1017,7 @@ ifinfo(char *ifname, int argc, char **ar
 	(void)putc('\n', stdout);
 #undef ND
 
-	(void)close(s);
+	(void)prog_close(s);
 }
 
 #ifndef ND_RA_FLAG_RTPREF_MASK	/* XXX: just for compilation on *BSD release */
@@ -1028,7 +1034,7 @@ rtrlist(void)
 	size_t l;
 	struct timeval tim;
 
-	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
+	if (prog_sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
 		err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
 		/*NOTREACHED*/
 	}
@@ -1039,7 +1045,7 @@ rtrlist(void)
 		err(1, "malloc");
 		/*NOTREACHED*/
 	}
-	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
+	if (prog_sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
 		err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
 		/*NOTREACHED*/
 	}
@@ -1074,13 +1080,13 @@ rtrlist(void)
 	int s, i;
 	struct timeval time;
 
-	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+	if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
 		err(1, "socket");
 		/* NOTREACHED */
 	}
 	(void)memset(&dr, 0, sizeof(dr));
 	(void)strlcpy(dr.ifname, "lo0", sizeof(dr.ifname)); /* dummy */
-	if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {
+	if (prog_ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {
 		err(1, "ioctl(SIOCGDRLST_IN6)");
 		/* NOTREACHED */
 	}
@@ -1109,7 +1115,7 @@ rtrlist(void)
 			    sec2str(DR.expire - time.tv_sec));
 	}
 #undef DR
-	(void)close(s);
+	(void)prog_close(s);
 #endif
 }
 
@@ -1126,7 +1132,7 @@ plist(void)
 	int ninflags = nflag ? NI_NUMERICHOST : 0;
 	char namebuf[NI_MAXHOST];
 
-	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
+	if (prog_sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
 		err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
 		/*NOTREACHED*/
 	}
@@ -1135,7 +1141,7 @@ plist(void)
 		err(1, "malloc");
 		/*NOTREACHED*/
 	}
-	if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
+	if (prog_sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) {
 		err(1, "sysctl(ICMPV6CTL_ND6_PRLIST)");
 		/*NOTREACHED*/
 	}
@@ -1233,13 +1239,13 @@ plist(void)
 
 	(void)gettimeofday(&time, 0);
 
-	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+	if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
 		err(1, "socket");
 		/* NOTREACHED */
 	}
 	(void)memset(&pr, 0, sizeof(pr));
 	(void)strlcpy(pr.ifname, "lo0", sizeof(pr.ifname)); /* dummy */
-	if (ioctl(s, SIOCGPRLST_IN6, (caddr_t)&pr) < 0) {
+	if (prog_ioctl(s, SIOCGPRLST_IN6, (caddr_t)&pr) < 0) {
 		err(1, "ioctl(SIOCGPRLST_IN6)");
 		/* NOTREACHED */
 	}
@@ -1380,7 +1386,7 @@ plist(void)
 			(void)printf("  No advertising router\n");
 	}
 #undef PR
-	(void)close(s);
+	(void)prog_close(s);
 #endif
 }
 
@@ -1390,12 +1396,12 @@ pfx_flush(void)
 	char dummyif[IFNAMSIZ+8];
 	int s;
 
-	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
+	if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
 		err(1, "socket");
 	(void)strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */
-	if (ioctl(s, SIOCSPFXFLUSH_IN6, (caddr_t)&dummyif) < 0)
+	if (prog_ioctl(s, SIOCSPFXFLUSH_IN6, (caddr_t)&dummyif) < 0)
 		err(1, "ioctl(SIOCSPFXFLUSH_IN6)");
-	(void)close(s);
+	(void)prog_close(s);
 }
 
 static void
@@ -1404,13 +1410,13 @@ rtr_flush(void)
 	char dummyif[IFNAMSIZ+8];
 	int s;
 
-	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
+	if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
 		err(1, "socket");
 	(void)strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */
-	if (ioctl(s, SIOCSRTRFLUSH_IN6, (caddr_t)&dummyif) < 0)
+	if (prog_ioctl(s, SIOCSRTRFLUSH_IN6, (caddr_t)&dummyif) < 0)
 		err(1, "ioctl(SIOCSRTRFLUSH_IN6)");
 
-	(void)close(s);
+	(void)prog_close(s);
 }
 
 static void
@@ -1419,13 +1425,13 @@ harmonize_rtr(void)
 	char dummyif[IFNAMSIZ+8];
 	int s;
 
-	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
+	if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
 		err(1, "socket");
 	(void)strlcpy(dummyif, "lo0", sizeof(dummyif)); /* dummy */
-	if (ioctl(s, SIOCSNDFLUSH_IN6, (caddr_t)&dummyif) < 0)
+	if (prog_ioctl(s, SIOCSNDFLUSH_IN6, (caddr_t)&dummyif) < 0)
 		err(1, "ioctl(SIOCSNDFLUSH_IN6)");
 
-	(void)close(s);
+	(void)prog_close(s);
 }
 
 #ifdef SIOCSDEFIFACE_IN6	/* XXX: check SIOCGDEFIFACE_IN6 as well? */
@@ -1443,16 +1449,16 @@ setdefif(char *ifname)
 			err(1, "failed to resolve i/f index for %s", ifname);
 	}
 
-	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
+	if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
 		err(1, "socket");
 
 	(void)strlcpy(ndifreq.ifname, "lo0", sizeof(ndifreq.ifname)); /* dummy */
 	ndifreq.ifindex = ifindex;
 
-	if (ioctl(s, SIOCSDEFIFACE_IN6, &ndifreq) < 0)
+	if (prog_ioctl(s, SIOCSDEFIFACE_IN6, &ndifreq) < 0)
 		err(1, "ioctl(SIOCSDEFIFACE_IN6)");
 
-	(void)close(s);
+	(void)prog_close(s);
 }
 
 static void
@@ -1462,13 +1468,13 @@ getdefif(void)
 	char ifname[IFNAMSIZ+8];
 	int s;
 
-	if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
+	if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
 		err(1, "socket");
 
 	(void)memset(&ndifreq, 0, sizeof(ndifreq));
 	(void)strlcpy(ndifreq.ifname, "lo0", sizeof(ndifreq.ifname)); /* dummy */
 
-	if (ioctl(s, SIOCGDEFIFACE_IN6, &ndifreq) < 0)
+	if (prog_ioctl(s, SIOCGDEFIFACE_IN6, &ndifreq) < 0)
 		err(1, "ioctl(SIOCGDEFIFACE_IN6)");
 
 	if (ndifreq.ifindex == 0)
@@ -1480,7 +1486,7 @@ getdefif(void)
 		(void)printf("ND default interface = %s\n", ifname);
 	}
 
-	(void)close(s);
+	(void)prog_close(s);
 }
 #endif
 

Added files:

Index: src/usr.sbin/ndp/ndp_hostops.c
diff -u /dev/null src/usr.sbin/ndp/ndp_hostops.c:1.1
--- /dev/null	Mon Aug  3 09:51:41 2015
+++ src/usr.sbin/ndp/ndp_hostops.c	Mon Aug  3 09:51:40 2015
@@ -0,0 +1,55 @@
+/*	$NetBSD: ndp_hostops.c,v 1.1 2015/08/03 09:51:40 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: ndp_hostops.c,v 1.1 2015/08/03 09:51:40 ozaki-r Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/sysctl.h>
+#include <sys/ioctl.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "prog_ops.h"
+
+const struct prog_ops prog_ops = {
+	.op_socket = socket,
+	.op_open = open,
+	.op_close = close,
+	.op_getpid = getpid,
+
+	.op_read = read,
+	.op_write = write,
+
+	.op_sysctl = sysctl,
+	.op_ioctl = ioctl,
+};
Index: src/usr.sbin/ndp/ndp_rumpops.c
diff -u /dev/null src/usr.sbin/ndp/ndp_rumpops.c:1.1
--- /dev/null	Mon Aug  3 09:51:41 2015
+++ src/usr.sbin/ndp/ndp_rumpops.c	Mon Aug  3 09:51:40 2015
@@ -0,0 +1,59 @@
+/*	$NetBSD: ndp_rumpops.c,v 1.1 2015/08/03 09:51:40 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: ndp_rumpops.c,v 1.1 2015/08/03 09:51:40 ozaki-r Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.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_close =	rump_sys_close,
+	.op_getpid =	rump_sys_getpid,
+
+	.op_read =	rump_sys_read,
+	.op_write =	rump_sys_write,
+
+	.op_sysctl =	rump_sys___sysctl,
+	.op_ioctl =	rump_sys_ioctl,
+};
Index: src/usr.sbin/ndp/prog_ops.h
diff -u /dev/null src/usr.sbin/ndp/prog_ops.h:1.1
--- /dev/null	Mon Aug  3 09:51:41 2015
+++ src/usr.sbin/ndp/prog_ops.h	Mon Aug  3 09:51:40 2015
@@ -0,0 +1,74 @@
+/*      $NetBSD: prog_ops.h,v 1.1 2015/08/03 09:51:40 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_ioctl)(int, unsigned long, ...);
+
+	int (*op_socket)(int, int, int);
+	int (*op_open)(const char *, int, ...);
+	int (*op_close)(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_close prog_ops.op_close
+#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
+#define prog_ioctl prog_ops.op_ioctl
+#else
+#define prog_init ((int (*)(void))NULL)
+#define prog_socket socket
+#define prog_open open
+#define prog_close close
+#define prog_getpid getpid
+#define prog_read read
+#define prog_write write
+#define prog_sysctl sysctl
+#define prog_ioctl ioctl
+#endif
+
+#endif /* _PROG_OPS_H_ */

Reply via email to