Module Name: src
Committed By: pooka
Date: Mon Dec 13 17:42:17 UTC 2010
Modified Files:
src/sbin/ping: Makefile ping.c
Added Files:
src/sbin/ping: ping_hostops.c ping_rumpops.c prog_ops.h
Log Message:
RUMP_ACTION -> RUMPPRG
To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sbin/ping/Makefile
cvs rdiff -u -r1.91 -r1.92 src/sbin/ping/ping.c
cvs rdiff -u -r0 -r1.1 src/sbin/ping/ping_hostops.c \
src/sbin/ping/ping_rumpops.c src/sbin/ping/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/sbin/ping/Makefile
diff -u src/sbin/ping/Makefile:1.15 src/sbin/ping/Makefile:1.16
--- src/sbin/ping/Makefile:1.15 Thu Nov 11 22:56:38 2010
+++ src/sbin/ping/Makefile Mon Dec 13 17:42:17 2010
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.15 2010/11/11 22:56:38 pooka Exp $
+# $NetBSD: Makefile,v 1.16 2010/12/13 17:42:17 pooka Exp $
# @(#)Makefile 8.1 (Berkeley) 6/5/93
USE_FORT?= yes # setuid
-PROG= ping
+RUMPPRG=ping
MAN= ping.8
BINOWN= root
BINMODE=4555
@@ -12,16 +12,4 @@
LDADD+= -lipsec
DPADD+= ${LIBIPSEC}
-#
-# Compile-time debug flag. If compiled with "make RUMP_ACTION=1",
-# make rump system calls. This allows to single-step ioctl commands
-# to figure out where ioctl's go in the kernel.
-#
-.ifdef RUMP_ACTION
-CPPFLAGS+= -DRUMP_SYS_NETWORKING -DRUMP_SYS_IOCTL -DRUMP_SYS_CLOSE
-CPPFLAGS+= -DRUMP_ACTION
-LDADD+= -lrumpclient
-DBG= -g
-.endif
-
.include <bsd.prog.mk>
Index: src/sbin/ping/ping.c
diff -u src/sbin/ping/ping.c:1.91 src/sbin/ping/ping.c:1.92
--- src/sbin/ping/ping.c:1.91 Thu Nov 11 22:56:38 2010
+++ src/sbin/ping/ping.c Mon Dec 13 17:42:17 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: ping.c,v 1.91 2010/11/11 22:56:38 pooka Exp $ */
+/* $NetBSD: ping.c,v 1.92 2010/12/13 17:42:17 pooka Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -58,7 +58,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ping.c,v 1.91 2010/11/11 22:56:38 pooka Exp $");
+__RCSID("$NetBSD: ping.c,v 1.92 2010/12/13 17:42:17 pooka Exp $");
#endif
#include <stdio.h>
@@ -92,12 +92,7 @@
#include <netinet6/ipsec.h>
#endif /*IPSEC*/
-#ifdef RUMP_ACTION
-#include <rump/rump.h>
-#include <rump/rump_syscalls.h>
-#include <rump/rumpclient.h>
-#define poll(a,b,c) rump_sys_poll(a,b,c)
-#endif
+#include "prog_ops.h"
#define FLOOD_INTVL 0.01 /* default flood output interval */
#define MAXPACKET (IP_MAXPACKET-60-8) /* max packet size */
@@ -251,21 +246,19 @@
struct sigaction sa;
#endif
-#ifdef RUMP_ACTION
- if (rumpclient_init() == -1)
- err(1, "rumpclient init failed");
-#endif
+ if (prog_init && prog_init() == -1)
+ err(1, "init failed");
- if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0)
+ if ((s = prog_socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0)
err(1, "Cannot create socket");
- if ((sloop = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0)
+ if ((sloop = prog_socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0)
err(1, "Cannot create socket");
/*
* sloop is never read on. This prevents packets from
* queueing in its recv buffer.
*/
- if (shutdown(sloop, SHUT_RD) == -1)
+ if (prog_shutdown(sloop, SHUT_RD) == -1)
warn("Cannot shutdown for read");
if (setuid(getuid()) == -1)
@@ -472,23 +465,23 @@
ident = arc4random() & 0xFFFF;
if (options & SO_DEBUG) {
- if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
+ if (prog_setsockopt(s, SOL_SOCKET, SO_DEBUG,
(char *)&on, sizeof(on)) == -1)
warn("Can't turn on socket debugging");
}
if (options & SO_DONTROUTE) {
- if (setsockopt(s, SOL_SOCKET, SO_DONTROUTE,
+ if (prog_setsockopt(s, SOL_SOCKET, SO_DONTROUTE,
(char *)&on, sizeof(on)) == -1)
warn("SO_DONTROUTE");
}
if (options & SO_DEBUG) {
- if (setsockopt(sloop, SOL_SOCKET, SO_DEBUG,
+ if (prog_setsockopt(sloop, SOL_SOCKET, SO_DEBUG,
(char *)&on, sizeof(on)) == -1)
warn("Can't turn on socket debugging");
}
if (options & SO_DONTROUTE) {
- if (setsockopt(sloop, SOL_SOCKET, SO_DONTROUTE,
+ if (prog_setsockopt(sloop, SOL_SOCKET, SO_DONTROUTE,
(char *)&on, sizeof(on)) == -1)
warn("SO_DONTROUTE");
}
@@ -513,7 +506,8 @@
- optlen);
(void) memcpy(opack_ip + 1, optspace, optlen);
- if (setsockopt(s,IPPROTO_IP,IP_HDRINCL, (char *) &on, sizeof(on)) < 0)
+ if (prog_setsockopt(s,IPPROTO_IP,IP_HDRINCL,
+ (char *) &on, sizeof(on)) < 0)
err(1, "Can't set special IP header");
opack_ip->ip_v = IPVERSION;
@@ -528,24 +522,25 @@
if (pingflags & F_MCAST) {
if (pingflags & F_MCAST_NOLOOP) {
u_char loop = 0;
- if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP,
+ if (prog_setsockopt(s, IPPROTO_IP,
+ IP_MULTICAST_LOOP,
(char *) &loop, 1) < 0)
err(1, "Can't disable multicast loopback");
}
if (ttl != 0
- && setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL,
+ && prog_setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL,
(char *) &ttl, 1) < 0)
err(1, "Can't set multicast time-to-live");
if ((pingflags & F_SOURCE_ADDR)
- && setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF,
+ && prog_setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF,
(char *) &src_addr.sin_addr,
sizeof(src_addr.sin_addr)) < 0)
err(1, "Can't set multicast source interface");
} else if (pingflags & F_SOURCE_ADDR) {
- if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF,
+ if (prog_setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF,
(char *) &src_addr.sin_addr,
sizeof(src_addr.sin_addr)) < 0)
err(1, "Can't set source interface/address");
@@ -559,7 +554,7 @@
buf = ipsec_set_policy(policy_in, strlen(policy_in));
if (buf == NULL)
errx(1, "%s", ipsec_strerror());
- if (setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY,
+ if (prog_setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY,
buf, ipsec_get_policylen(buf)) < 0) {
err(1, "ipsec policy cannot be configured");
}
@@ -569,7 +564,7 @@
buf = ipsec_set_policy(policy_out, strlen(policy_out));
if (buf == NULL)
errx(1, "%s", ipsec_strerror());
- if (setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY,
+ if (prog_setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY,
buf, ipsec_get_policylen(buf)) < 0) {
err(1, "ipsec policy cannot be configured");
}
@@ -579,7 +574,7 @@
buf = ipsec_set_policy("out bypass", strlen("out bypass"));
if (buf == NULL)
errx(1, "%s", ipsec_strerror());
- if (setsockopt(sloop, IPPROTO_IP, IP_IPSEC_POLICY,
+ if (prog_setsockopt(sloop, IPPROTO_IP, IP_IPSEC_POLICY,
buf, ipsec_get_policylen(buf)) < 0) {
#if 0
warnx("ipsec is not configured");
@@ -595,27 +590,27 @@
if (pingflags & F_AUTHHDR) {
optval = IPSEC_LEVEL_REQUIRE;
#ifdef IP_AUTH_TRANS_LEVEL
- (void)setsockopt(s, IPPROTO_IP, IP_AUTH_TRANS_LEVEL,
+ (void)prog_setsockopt(s, IPPROTO_IP, IP_AUTH_TRANS_LEVEL,
(char *)&optval, sizeof(optval));
#else
- (void)setsockopt(s, IPPROTO_IP, IP_AUTH_LEVEL,
+ (void)prog_setsockopt(s, IPPROTO_IP, IP_AUTH_LEVEL,
(char *)&optval, sizeof(optval));
#endif
}
if (pingflags & F_ENCRYPT) {
optval = IPSEC_LEVEL_REQUIRE;
- (void)setsockopt(s, IPPROTO_IP, IP_ESP_TRANS_LEVEL,
+ (void)prog_setsockopt(s, IPPROTO_IP, IP_ESP_TRANS_LEVEL,
(char *)&optval, sizeof(optval));
}
optval = IPSEC_LEVEL_BYPASS;
#ifdef IP_AUTH_TRANS_LEVEL
- (void)setsockopt(sloop, IPPROTO_IP, IP_AUTH_TRANS_LEVEL,
+ (void)prog_setsockopt(sloop, IPPROTO_IP, IP_AUTH_TRANS_LEVEL,
(char *)&optval, sizeof(optval));
#else
- (void)setsockopt(sloop, IPPROTO_IP, IP_AUTH_LEVEL,
+ (void)prog_setsockopt(sloop, IPPROTO_IP, IP_AUTH_LEVEL,
(char *)&optval, sizeof(optval));
#endif
- (void)setsockopt(sloop, IPPROTO_IP, IP_ESP_TRANS_LEVEL,
+ (void)prog_setsockopt(sloop, IPPROTO_IP, IP_ESP_TRANS_LEVEL,
(char *)&optval, sizeof(optval));
}
#endif /*IPSEC_POLICY_IPSEC*/
@@ -629,7 +624,7 @@
* are trying to stress the ethernet, or just want to
* fill the arp cache to get some stuff for /etc/ethers.
*/
- while (0 > setsockopt(s, SOL_SOCKET, SO_RCVBUF,
+ while (0 > prog_setsockopt(s, SOL_SOCKET, SO_RCVBUF,
(char*)&bufspace, sizeof(bufspace))) {
if ((bufspace -= 4096) <= 0)
err(1, "Cannot set the receive buffer size");
@@ -638,7 +633,7 @@
/* make it possible to send giant probes, but do not worry now
* if it fails, since we probably won't send giant probes.
*/
- (void)setsockopt(s, SOL_SOCKET, SO_SNDBUF,
+ (void)prog_setsockopt(s, SOL_SOCKET, SO_SNDBUF,
(char*)&bufspace, sizeof(bufspace));
(void)signal(SIGINT, prefinish);
@@ -717,7 +712,7 @@
fdmaskp[0].fd = s;
fdmaskp[0].events = POLLIN;
- cc = poll(fdmaskp, 1, (int)(sec * 1000));
+ cc = prog_poll(fdmaskp, 1, (int)(sec * 1000));
if (cc <= 0) {
if (cc < 0) {
if (errno == EINTR)
@@ -729,7 +724,7 @@
}
fromlen = sizeof(from);
- cc = recvfrom(s, (char *) packet, packlen,
+ cc = prog_recvfrom(s, (char *) packet, packlen,
0, (struct sockaddr *)&from,
&fromlen);
if (cc < 0) {
@@ -838,10 +833,11 @@
opack_icmp.icmp_cksum = in_cksum((u_int16_t *)&opack_icmp,
PHDR_LEN);
sw = 0;
- if (setsockopt(sloop,IPPROTO_IP,IP_HDRINCL,
+ if (prog_setsockopt(sloop,IPPROTO_IP,IP_HDRINCL,
(char *)&sw,sizeof(sw)) < 0)
err(1, "Can't turn off special IP header");
- if (sendto(sloop, (char *) &opack_icmp, PHDR_LEN, MSG_DONTROUTE,
+ if (prog_sendto(sloop, (char *) &opack_icmp,
+ PHDR_LEN, MSG_DONTROUTE,
(struct sockaddr *)&loc_addr,
sizeof(struct sockaddr_in)) < 0) {
/*
@@ -854,7 +850,7 @@
warn("failed to clear cached route");
}
sw = 1;
- if (setsockopt(sloop,IPPROTO_IP,IP_HDRINCL,
+ if (prog_setsockopt(sloop,IPPROTO_IP,IP_HDRINCL,
(char *)&sw, sizeof(sw)) < 0)
err(1, "Can't set special IP header");
@@ -873,7 +869,7 @@
cc += opack_ip->ip_hl<<2;
opack_ip->ip_len = cc;
- i = sendto(s, (char *) opack_ip, cc, 0,
+ i = prog_sendto(s, (char *) opack_ip, cc, 0,
(struct sockaddr *)&send_addr, sizeof(struct sockaddr_in));
if (i != cc) {
jiggle_flush(1);
Added files:
Index: src/sbin/ping/ping_hostops.c
diff -u /dev/null src/sbin/ping/ping_hostops.c:1.1
--- /dev/null Mon Dec 13 17:42:17 2010
+++ src/sbin/ping/ping_hostops.c Mon Dec 13 17:42:17 2010
@@ -0,0 +1,51 @@
+/* $NetBSD: ping_hostops.c,v 1.1 2010/12/13 17:42:17 pooka Exp $ */
+
+/*
+ * Copyright (c) 2010 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: ping_hostops.c,v 1.1 2010/12/13 17:42:17 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+#include <poll.h>
+#include <unistd.h>
+
+#include "prog_ops.h"
+
+const struct prog_ops prog_ops = {
+ .op_socket = socket,
+ .op_setsockopt = setsockopt,
+ .op_shutdown = shutdown,
+ .op_poll = poll,
+ .op_recvfrom = recvfrom,
+ .op_sendto = sendto,
+ .op_close = close,
+};
Index: src/sbin/ping/ping_rumpops.c
diff -u /dev/null src/sbin/ping/ping_rumpops.c:1.1
--- /dev/null Mon Dec 13 17:42:17 2010
+++ src/sbin/ping/ping_rumpops.c Mon Dec 13 17:42:17 2010
@@ -0,0 +1,56 @@
+/* $NetBSD: ping_rumpops.c,v 1.1 2010/12/13 17:42:17 pooka Exp $ */
+
+/*
+ * Copyright (c) 2010 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: ping_rumpops.c,v 1.1 2010/12/13 17:42:17 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <poll.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_setsockopt= rump_sys_setsockopt,
+ .op_shutdown = rump_sys_shutdown,
+ .op_poll = rump_sys_poll,
+ .op_sendto = rump_sys_sendto,
+ .op_recvfrom = rump_sys_recvfrom,
+ .op_close = rump_sys_close,
+};
Index: src/sbin/ping/prog_ops.h
diff -u /dev/null src/sbin/ping/prog_ops.h:1.1
--- /dev/null Mon Dec 13 17:42:17 2010
+++ src/sbin/ping/prog_ops.h Mon Dec 13 17:42:17 2010
@@ -0,0 +1,61 @@
+/* $NetBSD: prog_ops.h,v 1.1 2010/12/13 17:42:17 pooka Exp $ */
+
+/*
+ * Copyright (c) 2010 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>
+
+struct prog_ops {
+ int (*op_init)(void);
+
+ int (*op_socket)(int, int, int);
+ int (*op_setsockopt)(int, int, int, const void *, socklen_t);
+ int (*op_shutdown)(int, int);
+
+ int (*op_poll)(struct pollfd *, nfds_t, int);
+
+ ssize_t (*op_recvfrom)(int, void *, size_t, int,
+ struct sockaddr *, socklen_t *);
+ ssize_t (*op_sendto)(int, const void *, size_t, int,
+ const struct sockaddr *, socklen_t);
+
+ int (*op_close)(int);
+};
+extern const struct prog_ops prog_ops;
+
+#define prog_init prog_ops.op_init
+#define prog_socket prog_ops.op_socket
+#define prog_setsockopt prog_ops.op_setsockopt
+#define prog_shutdown prog_ops.op_shutdown
+#define prog_poll prog_ops.op_poll
+#define prog_recvfrom prog_ops.op_recvfrom
+#define prog_sendto prog_ops.op_sendto
+#define prog_close prog_ops.op_close
+
+#endif /* _PROG_OPS_H_ */