Module Name:    src
Committed By:   pooka
Date:           Mon Dec 13 17:35:08 UTC 2010

Modified Files:
        src/sbin/ifconfig: Makefile Makefile.inc af_atalk.c af_inet.c
            af_inet6.c af_inetany.c af_iso.c env.c ieee80211.c ifconfig.c
            media.c util.c
Added Files:
        src/sbin/ifconfig: ifconfig_hostops.c ifconfig_rumpops.c prog_ops.h

Log Message:
Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sbin/ifconfig/Makefile
cvs rdiff -u -r1.7 -r1.8 src/sbin/ifconfig/Makefile.inc
cvs rdiff -u -r1.16 -r1.17 src/sbin/ifconfig/af_atalk.c
cvs rdiff -u -r1.14 -r1.15 src/sbin/ifconfig/af_inet.c
cvs rdiff -u -r1.26 -r1.27 src/sbin/ifconfig/af_inet6.c
cvs rdiff -u -r1.12 -r1.13 src/sbin/ifconfig/af_inetany.c
cvs rdiff -u -r1.13 -r1.14 src/sbin/ifconfig/af_iso.c
cvs rdiff -u -r1.6 -r1.7 src/sbin/ifconfig/env.c
cvs rdiff -u -r1.24 -r1.25 src/sbin/ifconfig/ieee80211.c
cvs rdiff -u -r1.223 -r1.224 src/sbin/ifconfig/ifconfig.c
cvs rdiff -u -r0 -r1.1 src/sbin/ifconfig/ifconfig_hostops.c \
    src/sbin/ifconfig/ifconfig_rumpops.c src/sbin/ifconfig/prog_ops.h
cvs rdiff -u -r1.4 -r1.5 src/sbin/ifconfig/media.c
cvs rdiff -u -r1.15 -r1.16 src/sbin/ifconfig/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/ifconfig/Makefile
diff -u src/sbin/ifconfig/Makefile:1.49 src/sbin/ifconfig/Makefile:1.50
--- src/sbin/ifconfig/Makefile:1.49	Fri Nov  5 16:23:56 2010
+++ src/sbin/ifconfig/Makefile	Mon Dec 13 17:35:08 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.49 2010/11/05 16:23:56 pooka Exp $
+#	$NetBSD: Makefile,v 1.50 2010/12/13 17:35:08 pooka Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/5/93
 
 # when making a change to this file, please check if the change is
@@ -7,6 +7,7 @@
 
 .include <bsd.own.mk>
 
+RUMPPRG=ifconfig
 MAN=	ifconfig.8
 
 #DBG+=-g
@@ -18,6 +19,10 @@
 
 .include "Makefile.inc"
 
+.PATH:		${.CURDIR}/../../lib/libc/net
+RUMPSRCS= getifaddrs.c
+CPPFLAGS+= -DRUMP_ACTION
+
 CPPFLAGS+=-I${NETBSDSRCDIR}/sys/dist/pf/
 SRCS+= pfsync.c
 
@@ -26,17 +31,4 @@
 COPTS.ifconfig.c+= -fno-loop-optimize
 .endif
 
-#
-# Compile-time debug flag.  If compiled with "make RUMP_ACTION=1",
-# make rump system calls to a server in another process.
-#
-.ifdef RUMP_ACTION
-.PATH:		${.CURDIR}/../../lib/libc/net
-CPPFLAGS+=	-DRUMP_SYS_NETWORKING -DRUMP_SYS_IOCTL -DRUMP_SYS_CLOSE
-CPPFLAGS+=	-DRUMP_ACTION
-LDADD+=		-lrumpclient
-DBG=		-g
-SRCS+=		getifaddrs.c
-.endif
-
 .include <bsd.prog.mk>

Index: src/sbin/ifconfig/Makefile.inc
diff -u src/sbin/ifconfig/Makefile.inc:1.7 src/sbin/ifconfig/Makefile.inc:1.8
--- src/sbin/ifconfig/Makefile.inc:1.7	Wed Sep 16 14:59:45 2009
+++ src/sbin/ifconfig/Makefile.inc	Mon Dec 13 17:35:08 2010
@@ -1,10 +1,8 @@
-#	$NetBSD: Makefile.inc,v 1.7 2009/09/16 14:59:45 tsutsui Exp $
+#	$NetBSD: Makefile.inc,v 1.8 2010/12/13 17:35:08 pooka Exp $
 
 # shared stuff with src/distrib/utils/x_ifconfig for install media.
 # stuff not required by install media should be into Makefile.
 
-PROG=	ifconfig
-
 DPADD+=${LIBUTIL}
 DPADD+=${LIBPROP}
 LDADD+=-lutil

Index: src/sbin/ifconfig/af_atalk.c
diff -u src/sbin/ifconfig/af_atalk.c:1.16 src/sbin/ifconfig/af_atalk.c:1.17
--- src/sbin/ifconfig/af_atalk.c:1.16	Sat Jan 30 18:30:33 2010
+++ src/sbin/ifconfig/af_atalk.c	Mon Dec 13 17:35:08 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: af_atalk.c,v 1.16 2010/01/30 18:30:33 is Exp $	*/
+/*	$NetBSD: af_atalk.c,v 1.17 2010/12/13 17:35:08 pooka Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: af_atalk.c,v 1.16 2010/01/30 18:30:33 is Exp $");
+__RCSID("$NetBSD: af_atalk.c,v 1.17 2010/12/13 17:35:08 pooka Exp $");
 #endif /* not lint */
 
 #include <sys/param.h> 
@@ -56,6 +56,7 @@
 #include "af_inetany.h"
 #include "parse.h"
 #include "extern.h"
+#include "prog_ops.h"
 
 #ifndef satocsat
 #define	satocsat(__sa) ((const struct sockaddr_at *)(__sa))
@@ -209,7 +210,7 @@
 	memset(&ifr, 0, sizeof(ifr));
 	estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
 	ifr.ifr_addr.sa_family = AF_APPLETALK;
-	if (ioctl(s, SIOCGIFADDR, &ifr) != -1)
+	if (prog_ioctl(s, SIOCGIFADDR, &ifr) != -1)
 		;
 	else if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
 		if (!force)
@@ -223,7 +224,7 @@
 
 	if (flags & IFF_POINTOPOINT) {
 		estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-		if (ioctl(s, SIOCGIFDSTADDR, &ifr) == -1) {
+		if (prog_ioctl(s, SIOCGIFDSTADDR, &ifr) == -1) {
 			if (errno == EADDRNOTAVAIL)
 				memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
 			else

Index: src/sbin/ifconfig/af_inet.c
diff -u src/sbin/ifconfig/af_inet.c:1.14 src/sbin/ifconfig/af_inet.c:1.15
--- src/sbin/ifconfig/af_inet.c:1.14	Fri Sep 11 22:06:29 2009
+++ src/sbin/ifconfig/af_inet.c	Mon Dec 13 17:35:08 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: af_inet.c,v 1.14 2009/09/11 22:06:29 dyoung Exp $	*/
+/*	$NetBSD: af_inet.c,v 1.15 2010/12/13 17:35:08 pooka Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: af_inet.c,v 1.14 2009/09/11 22:06:29 dyoung Exp $");
+__RCSID("$NetBSD: af_inet.c,v 1.15 2010/12/13 17:35:08 pooka Exp $");
 #endif /* not lint */
 
 #include <sys/param.h> 
@@ -57,6 +57,7 @@
 #include "env.h"
 #include "extern.h"
 #include "af_inetany.h"
+#include "prog_ops.h"
 
 static void in_constructor(void) __attribute__((constructor));
 static void in_status(prop_dictionary_t, prop_dictionary_t, bool);
@@ -97,7 +98,7 @@
 	}
 	memset(&ifr, 0, sizeof(ifr));
 	estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-	if (ioctl(s, SIOCGIFADDR, &ifr) == -1) {
+	if (prog_ioctl(s, SIOCGIFADDR, &ifr) == -1) {
 		if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT)
 			return;
 		warn("SIOCGIFADDR");
@@ -106,7 +107,7 @@
 	if (memcmp(&ifr.ifr_addr, &creq->ifra_addr, sizeof(ifr.ifr_addr)) == 0)
 		alias = false;
 	in_addreq = *creq;
-	if (ioctl(s, SIOCGIFALIAS, &in_addreq) == -1) {
+	if (prog_ioctl(s, SIOCGIFALIAS, &in_addreq) == -1) {
 		if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
 			return;
 		} else

Index: src/sbin/ifconfig/af_inet6.c
diff -u src/sbin/ifconfig/af_inet6.c:1.26 src/sbin/ifconfig/af_inet6.c:1.27
--- src/sbin/ifconfig/af_inet6.c:1.26	Fri Jan 22 23:50:07 2010
+++ src/sbin/ifconfig/af_inet6.c	Mon Dec 13 17:35:08 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: af_inet6.c,v 1.26 2010/01/22 23:50:07 dyoung Exp $	*/
+/*	$NetBSD: af_inet6.c,v 1.27 2010/12/13 17:35:08 pooka Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: af_inet6.c,v 1.26 2010/01/22 23:50:07 dyoung Exp $");
+__RCSID("$NetBSD: af_inet6.c,v 1.27 2010/12/13 17:35:08 pooka Exp $");
 #endif /* not lint */
 
 #include <sys/param.h> 
@@ -57,6 +57,7 @@
 #include "parse.h"
 #include "extern.h"
 #include "af_inetany.h"
+#include "prog_ops.h"
 
 static void in6_constructor(void) __attribute__((constructor));
 static void in6_alias(const char *, prop_dictionary_t, prop_dictionary_t,
@@ -302,7 +303,7 @@
 
 	if (flags & IFF_POINTOPOINT) {
 		ifr6 = *creq;
-		if (ioctl(s, SIOCGIFDSTADDR_IN6, &ifr6) == -1) {
+		if (prog_ioctl(s, SIOCGIFDSTADDR_IN6, &ifr6) == -1) {
 			if (errno != EADDRNOTAVAIL)
 				warn("SIOCGIFDSTADDR_IN6");
 			memset(&ifr6.ifr_addr, 0, sizeof(ifr6.ifr_addr));
@@ -319,7 +320,7 @@
 	}
 
 	ifr6 = *creq;
-	if (ioctl(s, SIOCGIFNETMASK_IN6, &ifr6) == -1) {
+	if (prog_ioctl(s, SIOCGIFNETMASK_IN6, &ifr6) == -1) {
 		if (errno != EADDRNOTAVAIL)
 			warn("SIOCGIFNETMASK_IN6");
 	} else {
@@ -329,7 +330,7 @@
 	}
 
 	ifr6 = *creq;
-	if (ioctl(s, SIOCGIFAFLAG_IN6, &ifr6) == -1) {
+	if (prog_ioctl(s, SIOCGIFAFLAG_IN6, &ifr6) == -1) {
 		if (errno != EADDRNOTAVAIL)
 			warn("SIOCGIFAFLAG_IN6");
 	} else {
@@ -352,7 +353,7 @@
 		struct in6_addrlifetime *lifetime;
 		ifr6 = *creq;
 		lifetime = &ifr6.ifr_ifru.ifru_lifetime;
-		if (ioctl(s, SIOCGIFALIFETIME_IN6, &ifr6) == -1) {
+		if (prog_ioctl(s, SIOCGIFALIFETIME_IN6, &ifr6) == -1) {
 			if (errno != EADDRNOTAVAIL)
 				warn("SIOCGIFALIFETIME_IN6");
 		} else if (lifetime->ia6t_preferred || lifetime->ia6t_expire) {

Index: src/sbin/ifconfig/af_inetany.c
diff -u src/sbin/ifconfig/af_inetany.c:1.12 src/sbin/ifconfig/af_inetany.c:1.13
--- src/sbin/ifconfig/af_inetany.c:1.12	Wed Jul  2 07:44:14 2008
+++ src/sbin/ifconfig/af_inetany.c	Mon Dec 13 17:35:08 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: af_inetany.c,v 1.12 2008/07/02 07:44:14 dyoung Exp $	*/
+/*	$NetBSD: af_inetany.c,v 1.13 2010/12/13 17:35:08 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2008 David Young.  All rights reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: af_inetany.c,v 1.12 2008/07/02 07:44:14 dyoung Exp $");
+__RCSID("$NetBSD: af_inetany.c,v 1.13 2010/12/13 17:35:08 pooka Exp $");
 #endif /* not lint */
 
 #include <sys/param.h> 
@@ -54,6 +54,7 @@
 #include "env.h"
 #include "extern.h"
 #include "af_inetany.h"
+#include "prog_ops.h"
 
 static void *
 loadbuf(const struct apbuf *b, const struct paddr_prefix *pfx)
@@ -90,9 +91,9 @@
 	else if (!prop_dictionary_get_bool(env, "alias", &alias) || alias ||
 	    param->gifaddr.cmd == 0)
 		return;
-	else if (ioctl(s, param->gifaddr.cmd, param->dgreq.buf) == -1)
+	else if (prog_ioctl(s, param->gifaddr.cmd, param->dgreq.buf) == -1)
 		err(EXIT_FAILURE, param->gifaddr.desc);
-	else if (ioctl(s, param->difaddr.cmd, param->dgreq.buf) == -1)
+	else if (prog_ioctl(s, param->difaddr.cmd, param->dgreq.buf) == -1)
 		err(EXIT_FAILURE, param->difaddr.desc);
 	else
 		return;
@@ -153,8 +154,8 @@
 		    MIN(param->mask.buflen, param->defmask.buflen));
 	}
 	if (replace) {
-		if (ioctl(s, param->gifaddr.cmd, param->dgreq.buf) == 0) {
-			rc = ioctl(s, param->difaddr.cmd, param->dgreq.buf);
+		if (prog_ioctl(s, param->gifaddr.cmd, param->dgreq.buf) == 0) {
+			rc = prog_ioctl(s, param->difaddr.cmd, param->dgreq.buf);
 			if (rc == -1)
 				err(EXIT_FAILURE, param->difaddr.desc);
 		} else if (errno == EADDRNOTAVAIL)
@@ -163,13 +164,13 @@
 			err(EXIT_FAILURE, param->gifaddr.desc);
 	} else if (delete) {
 		loadbuf(&param->dgaddr, addr);
-		if (ioctl(s, param->difaddr.cmd, param->dgreq.buf) == -1)
+		if (prog_ioctl(s, param->difaddr.cmd, param->dgreq.buf) == -1)
 			err(EXIT_FAILURE, param->difaddr.desc);
 		return;
 	}
 	if (param->pre_aifaddr != NULL &&
 	    (*param->pre_aifaddr)(env, param) == -1)
 		err(EXIT_FAILURE, "pre-%s", param->aifaddr.desc);
-	if (ioctl(s, param->aifaddr.cmd, param->req.buf) == -1)
+	if (prog_ioctl(s, param->aifaddr.cmd, param->req.buf) == -1)
 		err(EXIT_FAILURE, param->aifaddr.desc);
 }

Index: src/sbin/ifconfig/af_iso.c
diff -u src/sbin/ifconfig/af_iso.c:1.13 src/sbin/ifconfig/af_iso.c:1.14
--- src/sbin/ifconfig/af_iso.c:1.13	Tue Jul 15 21:27:58 2008
+++ src/sbin/ifconfig/af_iso.c	Mon Dec 13 17:35:08 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: af_iso.c,v 1.13 2008/07/15 21:27:58 dyoung Exp $	*/
+/*	$NetBSD: af_iso.c,v 1.14 2010/12/13 17:35:08 pooka Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: af_iso.c,v 1.13 2008/07/15 21:27:58 dyoung Exp $");
+__RCSID("$NetBSD: af_iso.c,v 1.14 2010/12/13 17:35:08 pooka Exp $");
 #endif /* not lint */
 
 #include <err.h>
@@ -56,6 +56,7 @@
 #include "parse.h"
 #include "extern.h"
 #include "af_inetany.h"
+#include "prog_ops.h"
 
 #define	DEFNSELLEN	1
 
@@ -177,7 +178,7 @@
 	}
 	memset(&isoifr, 0, sizeof(isoifr));
 	estrlcpy(isoifr.ifr_name, ifname, sizeof(isoifr.ifr_name));
-	if (ioctl(s, SIOCGIFADDR_ISO, &isoifr) == -1) {
+	if (prog_ioctl(s, SIOCGIFADDR_ISO, &isoifr) == -1) {
 		if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
 			if (!force)
 				return;
@@ -188,7 +189,7 @@
 	strlcpy(isoifr.ifr_name, ifname, sizeof(isoifr.ifr_name));
 	siso = &isoifr.ifr_Addr;
 	printf("\tiso %s", iso_ntoa(&siso->siso_addr));
-	if (ioctl(s, SIOCGIFNETMASK_ISO, &isoifr) == -1) {
+	if (prog_ioctl(s, SIOCGIFNETMASK_ISO, &isoifr) == -1) {
 		if (errno == EADDRNOTAVAIL)
 			memset(&isoifr.ifr_Addr, 0, sizeof(isoifr.ifr_Addr));
 		else
@@ -201,7 +202,7 @@
 	}
 
 	if (flags & IFF_POINTOPOINT) {
-		if (ioctl(s, SIOCGIFDSTADDR_ISO, &isoifr) == -1) {
+		if (prog_ioctl(s, SIOCGIFDSTADDR_ISO, &isoifr) == -1) {
 			if (errno == EADDRNOTAVAIL)
 			    memset(&isoifr.ifr_Addr, 0,
 				sizeof(isoifr.ifr_Addr));

Index: src/sbin/ifconfig/env.c
diff -u src/sbin/ifconfig/env.c:1.6 src/sbin/ifconfig/env.c:1.7
--- src/sbin/ifconfig/env.c:1.6	Wed Jul  2 07:44:14 2008
+++ src/sbin/ifconfig/env.c	Mon Dec 13 17:35:08 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: env.c,v 1.6 2008/07/02 07:44:14 dyoung Exp $	*/
+/*	$NetBSD: env.c,v 1.7 2010/12/13 17:35:08 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2008 David Young.  All rights reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: env.c,v 1.6 2008/07/02 07:44:14 dyoung Exp $");
+__RCSID("$NetBSD: env.c,v 1.7 2010/12/13 17:35:08 pooka Exp $");
 #endif /* not lint */
 
 #include <errno.h>
@@ -41,6 +41,7 @@
 
 #include "env.h"
 #include "util.h"
+#include "prog_ops.h"
 
 prop_dictionary_t
 prop_dictionary_augment(prop_dictionary_t bottom, prop_dictionary_t top)
@@ -92,7 +93,7 @@
 
 	memset(&ifr, 0, sizeof(ifr));
 	estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-	if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1)
+	if (prog_ioctl(s, SIOCGIFFLAGS, &ifr) == -1)
 		return -1;
 
 	*flagsp = (unsigned short)ifr.ifr_flags;

Index: src/sbin/ifconfig/ieee80211.c
diff -u src/sbin/ifconfig/ieee80211.c:1.24 src/sbin/ifconfig/ieee80211.c:1.25
--- src/sbin/ifconfig/ieee80211.c:1.24	Thu Jul  1 16:44:05 2010
+++ src/sbin/ifconfig/ieee80211.c	Mon Dec 13 17:35:08 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.c,v 1.24 2010/07/01 16:44:05 dyoung Exp $	*/
+/*	$NetBSD: ieee80211.c,v 1.25 2010/12/13 17:35:08 pooka Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ieee80211.c,v 1.24 2010/07/01 16:44:05 dyoung Exp $");
+__RCSID("$NetBSD: ieee80211.c,v 1.25 2010/12/13 17:35:08 pooka Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -62,6 +62,7 @@
 #include "parse.h"
 #include "env.h"
 #include "util.h"
+#include "prog_ops.h"
 
 static void ieee80211_statistics(prop_dictionary_t);
 static void ieee80211_status(prop_dictionary_t, prop_dictionary_t);
@@ -725,7 +726,7 @@
 {
 	int sroute;
 
-	sroute = socket(PF_ROUTE, SOCK_RAW, 0);
+	sroute = prog_socket(PF_ROUTE, SOCK_RAW, 0);
 	if (sroute < 0) {
 		perror("socket(PF_ROUTE,SOCK_RAW)");
 		return;
@@ -737,7 +738,7 @@
 		struct rt_msghdr *rtm;
 
 		do {
-			if (read(sroute, buf, sizeof(buf)) < 0) {
+			if (prog_read(sroute, buf, sizeof(buf)) < 0) {
 				perror("read(PF_ROUTE)");
 				break;
 			}
@@ -748,7 +749,7 @@
 		} while (rtm->rtm_type != RTM_IEEE80211 ||
 		    ifan->ifan_what != RTM_IEEE80211_SCAN);
 	}
-	close(sroute);
+	prog_close(sroute);
 }
 
 static void

Index: src/sbin/ifconfig/ifconfig.c
diff -u src/sbin/ifconfig/ifconfig.c:1.223 src/sbin/ifconfig/ifconfig.c:1.224
--- src/sbin/ifconfig/ifconfig.c:1.223	Mon Nov 15 22:42:37 2010
+++ src/sbin/ifconfig/ifconfig.c	Mon Dec 13 17:35:08 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ifconfig.c,v 1.223 2010/11/15 22:42:37 pooka Exp $	*/
+/*	$NetBSD: ifconfig.c,v 1.224 2010/12/13 17:35:08 pooka Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1983, 1993\
  The Regents of the University of California.  All rights reserved.");
-__RCSID("$NetBSD: ifconfig.c,v 1.223 2010/11/15 22:42:37 pooka Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.224 2010/12/13 17:35:08 pooka Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -100,6 +100,7 @@
 #include "media.h"
 #include "parse.h"
 #include "env.h"
+#include "prog_ops.h"
 
 static bool bflag, dflag, hflag, sflag, uflag;
 bool lflag, Nflag, vflag, zflag;
@@ -549,10 +550,6 @@
 	prop_dictionary_t env, oenv;
 	const char *ifname;
 
-#ifdef RUMP_ACTION
-	if (rumpclient_init() == -1)
-		err(1, "rump client init");
-#endif
 	memset(match, 0, sizeof(match));
 
 	init_afs();
@@ -665,6 +662,9 @@
 	if (rc != 0)
 		usage();
 
+	if (prog_init && prog_init() == -1)
+		err(1, "rump client init");
+
 	if ((oenv = prop_dictionary_create()) == NULL)
 		err(EXIT_FAILURE, "%s: prop_dictionary_create", __func__);
 
@@ -818,7 +818,7 @@
 
 	s = getsock(AF_INET);
 
-	if (ioctl(s, SIOCIFGCLONERS, &ifcr) == -1)
+	if (prog_ioctl(s, SIOCIFGCLONERS, &ifcr) == -1)
 		err(EXIT_FAILURE, "SIOCIFGCLONERS for count");
 
 	buf = malloc(ifcr.ifcr_total * IFNAMSIZ);
@@ -828,7 +828,7 @@
 	ifcr.ifcr_count = ifcr.ifcr_total;
 	ifcr.ifcr_buffer = buf;
 
-	if (ioctl(s, SIOCIFGCLONERS, &ifcr) == -1)
+	if (prog_ioctl(s, SIOCIFGCLONERS, &ifcr) == -1)
 		err(EXIT_FAILURE, "SIOCIFGCLONERS for names");
 
 	/*
@@ -1193,13 +1193,13 @@
 	printf("%s: flags=%s", ifname, &fbuf[2]);
 
 	estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-	if (ioctl(s, SIOCGIFMETRIC, &ifr) == -1)
+	if (prog_ioctl(s, SIOCGIFMETRIC, &ifr) == -1)
 		warn("SIOCGIFMETRIC %s", ifr.ifr_name);
 	else if (ifr.ifr_metric != 0)
 		printf(" metric %d", ifr.ifr_metric);
 
 	estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-	if (ioctl(s, SIOCGIFMTU, &ifr) != -1 && ifr.ifr_mtu != 0)
+	if (prog_ioctl(s, SIOCGIFMTU, &ifr) != -1 && ifr.ifr_mtu != 0)
 		printf(" mtu %d", ifr.ifr_mtu);
 	printf("\n");
 
@@ -1225,7 +1225,7 @@
 	ifdrv.ifd_len = 0;
 	ifdrv.ifd_data = NULL;
 	/* interface supports linkstr? */
-	if (ioctl(s, SIOCGLINKSTR, &ifdrv) != -1) {
+	if (prog_ioctl(s, SIOCGLINKSTR, &ifdrv) != -1) {
 		char *p;
 
 		p = malloc(ifdrv.ifd_len);
@@ -1233,7 +1233,7 @@
 			err(EXIT_FAILURE, "malloc linkstr buf failed");
 		ifdrv.ifd_data = p;
 		ifdrv.ifd_cmd = 0;
-		if (ioctl(s, SIOCGLINKSTR, &ifdrv) == -1)
+		if (prog_ioctl(s, SIOCGLINKSTR, &ifdrv) == -1)
 			err(EXIT_FAILURE, "failed to query linkstr");
 		printf("\tlinkstr: %s\n", (char *)ifdrv.ifd_data);
 		free(p);
@@ -1246,7 +1246,7 @@
 
 	estrlcpy(ifdr.ifdr_name, ifname, sizeof(ifdr.ifdr_name));
 
-	if (ioctl(s, zflag ? SIOCZIFDATA : SIOCGIFDATA, &ifdr) == -1)
+	if (prog_ioctl(s, zflag ? SIOCZIFDATA : SIOCGIFDATA, &ifdr) == -1)
 		err(EXIT_FAILURE, zflag ? "SIOCZIFDATA" : "SIOCGIFDATA");
 
 	ifi = &ifdr.ifdr_data;

Index: src/sbin/ifconfig/media.c
diff -u src/sbin/ifconfig/media.c:1.4 src/sbin/ifconfig/media.c:1.5
--- src/sbin/ifconfig/media.c:1.4	Thu Jul  1 16:44:05 2010
+++ src/sbin/ifconfig/media.c	Mon Dec 13 17:35:08 2010
@@ -1,6 +1,6 @@
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: media.c,v 1.4 2010/07/01 16:44:05 dyoung Exp $");
+__RCSID("$NetBSD: media.c,v 1.5 2010/12/13 17:35:08 pooka Exp $");
 #endif /* not lint */
 
 #include <assert.h>
@@ -24,6 +24,7 @@
 #include "media.h"
 #include "parse.h"
 #include "util.h"
+#include "prog_ops.h"
 
 static void init_current_media(prop_dictionary_t, prop_dictionary_t);
 static void media_constructor(void) __attribute__((constructor));
@@ -363,7 +364,7 @@
 	memset(&ifmr, 0, sizeof(ifmr));
 	estrlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
 
-	if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) {
+	if (prog_ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) {
 		/*
 		 * Interface doesn't support SIOC{G,S}IFMEDIA.
 		 */
@@ -380,7 +381,7 @@
 		err(EXIT_FAILURE, "malloc");
 	ifmr.ifm_ulist = media_list;
 
-	if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1)
+	if (prog_ioctl(s, SIOCGIFMEDIA, &ifmr) == -1)
 		err(EXIT_FAILURE, "SIOCGIFMEDIA");
 
 	printf("\tmedia: %s ", get_media_type_string(ifmr.ifm_current));

Index: src/sbin/ifconfig/util.c
diff -u src/sbin/ifconfig/util.c:1.15 src/sbin/ifconfig/util.c:1.16
--- src/sbin/ifconfig/util.c:1.15	Thu Jul  1 16:44:05 2010
+++ src/sbin/ifconfig/util.c	Mon Dec 13 17:35:08 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.15 2010/07/01 16:44:05 dyoung Exp $	*/
+/*	$NetBSD: util.c,v 1.16 2010/12/13 17:35:08 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2008 David Young.  All rights reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.15 2010/07/01 16:44:05 dyoung Exp $");
+__RCSID("$NetBSD: util.c,v 1.16 2010/12/13 17:35:08 pooka Exp $");
 #endif /* not lint */
 
 #include <ctype.h>
@@ -54,6 +54,7 @@
 #include "env.h"
 #include "extern.h"
 #include "util.h"
+#include "prog_ops.h"
 
 int
 getsock(int naf)
@@ -64,12 +65,12 @@
 		return s;
 
 	if (oaf != -1)
-		close(s);
+		prog_close(s);
 
 	if (naf == AF_UNSPEC)
 		naf = AF_INET;
 
-	s = socket(naf, SOCK_DGRAM, 0);
+	s = prog_socket(naf, SOCK_DGRAM, 0);
 	if (s == -1)
 		oaf = -1;
 	else
@@ -223,7 +224,7 @@
 
 	estrlcpy(data, ifname, IFNAMSIZ);
 
-	return ioctl(s, cmd, data);
+	return prog_ioctl(s, cmd, data);
 }
 
 int
@@ -274,7 +275,7 @@
 		iflr.flags = IFLR_PREFIX;
 		iflr.prefixlen = sdl->sdl_alen * NBBY;
 
-		if (ioctl(s, SIOCGLIFADDR, &iflr) == -1)
+		if (prog_ioctl(s, SIOCGLIFADDR, &iflr) == -1)
 			err(EXIT_FAILURE, "%s: ioctl", __func__);
 
 		if (((iflr.flags & IFLR_ACTIVE) != 0) != print_active_only)
@@ -305,7 +306,7 @@
 	memset(&ifap, 0, sizeof(ifap));
 	estrlcpy(ifap.ifap_name, ifname, sizeof(ifap.ifap_name));
 	memcpy(&ifap.ifap_addr, sa, MIN(sizeof(ifap.ifap_addr), sa->sa_len));
-	if (ioctl(s, SIOCGIFADDRPREF, &ifap) == -1) {
+	if (prog_ioctl(s, SIOCGIFADDRPREF, &ifap) == -1) {
 		if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT)
 			return 0;
 		warn("SIOCGIFADDRPREF");

Added files:

Index: src/sbin/ifconfig/ifconfig_hostops.c
diff -u /dev/null src/sbin/ifconfig/ifconfig_hostops.c:1.1
--- /dev/null	Mon Dec 13 17:35:08 2010
+++ src/sbin/ifconfig/ifconfig_hostops.c	Mon Dec 13 17:35:08 2010
@@ -0,0 +1,47 @@
+/*	$NetBSD: ifconfig_hostops.c,v 1.1 2010/12/13 17:35:08 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: ifconfig_hostops.c,v 1.1 2010/12/13 17:35:08 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+#include <unistd.h>
+
+#include "prog_ops.h"
+
+const struct prog_ops prog_ops = {
+	.op_socket = socket,
+	.op_ioctl = ioctl,
+	.op_read = read,
+	.op_close = close,
+};
Index: src/sbin/ifconfig/ifconfig_rumpops.c
diff -u /dev/null src/sbin/ifconfig/ifconfig_rumpops.c:1.1
--- /dev/null	Mon Dec 13 17:35:08 2010
+++ src/sbin/ifconfig/ifconfig_rumpops.c	Mon Dec 13 17:35:08 2010
@@ -0,0 +1,52 @@
+/*	$NetBSD: ifconfig_rumpops.c,v 1.1 2010/12/13 17:35:08 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: ifconfig_rumpops.c,v 1.1 2010/12/13 17:35:08 pooka 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_ioctl =	rump_sys_ioctl,
+	.op_read =	rump_sys_read,
+	.op_close =	rump_sys_close,
+};
Index: src/sbin/ifconfig/prog_ops.h
diff -u /dev/null src/sbin/ifconfig/prog_ops.h:1.1
--- /dev/null	Mon Dec 13 17:35:08 2010
+++ src/sbin/ifconfig/prog_ops.h	Mon Dec 13 17:35:08 2010
@@ -0,0 +1,61 @@
+/*      $NetBSD: prog_ops.h,v 1.1 2010/12/13 17:35:08 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>
+
+/* ifconfig is compiled outside of src/sbin/ifconfig too */
+#ifdef RUMP_ACTION
+struct prog_ops {
+	int (*op_init)(void);
+
+	int (*op_socket)(int, int, int);
+
+	int (*op_ioctl)(int, unsigned long, ...);
+	int (*op_read)(int, void *, size_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_ioctl prog_ops.op_ioctl
+#define prog_read prog_ops.op_read
+#define prog_close prog_ops.op_close
+#else
+#define prog_init ((int (*)(void))NULL)
+#define prog_socket socket
+#define prog_ioctl ioctl
+#define prog_read read
+#define prog_close close
+#endif
+
+#endif /* _PROG_OPS_H_ */

Reply via email to