Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.

This commit is contained in:
pooka 2010-12-13 17:35:08 +00:00
parent 84d9317cb6
commit a415ef09e9
15 changed files with 234 additions and 75 deletions

View File

@ -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 @@ SRCS+= af_inet6.c
.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 @@ SRCS+= pfsync.c
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>

View File

@ -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

View File

@ -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 @@ __RCSID("$NetBSD: af_atalk.c,v 1.16 2010/01/30 18:30:33 is Exp $");
#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 @@ at_status(prop_dictionary_t env, prop_dictionary_t oenv, bool force)
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 @@ at_status(prop_dictionary_t env, prop_dictionary_t oenv, bool force)
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

View File

@ -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 @@ __RCSID("$NetBSD: af_inet.c,v 1.14 2009/09/11 22:06:29 dyoung Exp $");
#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 @@ in_alias(const char *ifname, prop_dictionary_t env, prop_dictionary_t oenv,
}
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 @@ in_alias(const char *ifname, prop_dictionary_t env, prop_dictionary_t oenv,
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

View File

@ -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 @@ __RCSID("$NetBSD: af_inet6.c,v 1.26 2010/01/22 23:50:07 dyoung Exp $");
#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 @@ in6_alias(const char *ifname, prop_dictionary_t env, prop_dictionary_t oenv,
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 @@ in6_alias(const char *ifname, prop_dictionary_t env, prop_dictionary_t oenv,
}
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 @@ in6_alias(const char *ifname, prop_dictionary_t env, prop_dictionary_t oenv,
}
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 @@ in6_alias(const char *ifname, prop_dictionary_t env, prop_dictionary_t oenv,
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) {

View File

@ -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 @@ __RCSID("$NetBSD: af_inetany.c,v 1.12 2008/07/02 07:44:14 dyoung Exp $");
#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 @@ commit_address(prop_dictionary_t env, prop_dictionary_t oenv,
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 @@ commit_address(prop_dictionary_t env, prop_dictionary_t oenv,
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 @@ commit_address(prop_dictionary_t env, prop_dictionary_t oenv,
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);
}

View File

@ -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 @@ __RCSID("$NetBSD: af_iso.c,v 1.13 2008/07/15 21:27:58 dyoung Exp $");
#include "parse.h"
#include "extern.h"
#include "af_inetany.h"
#include "prog_ops.h"
#define DEFNSELLEN 1
@ -177,7 +178,7 @@ iso_status(prop_dictionary_t env, prop_dictionary_t oenv, bool force)
}
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 @@ iso_status(prop_dictionary_t env, prop_dictionary_t oenv, bool force)
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 @@ iso_status(prop_dictionary_t env, prop_dictionary_t oenv, bool force)
}
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));

View File

@ -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 @@ __RCSID("$NetBSD: env.c,v 1.6 2008/07/02 07:44:14 dyoung Exp $");
#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 @@ getifflags(prop_dictionary_t env, prop_dictionary_t oenv,
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;

View File

@ -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 @@ __RCSID("$NetBSD: ieee80211.c,v 1.24 2010/07/01 16:44:05 dyoung Exp $");
#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 @@ scan_and_wait(prop_dictionary_t env)
{
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 @@ scan_and_wait(prop_dictionary_t env)
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 @@ scan_and_wait(prop_dictionary_t env)
} while (rtm->rtm_type != RTM_IEEE80211 ||
ifan->ifan_what != RTM_IEEE80211_SCAN);
}
close(sroute);
prog_close(sroute);
}
static void

View File

@ -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 @@ __RCSID("$NetBSD: ifconfig.c,v 1.223 2010/11/15 22:42:37 pooka Exp $");
#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 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
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 @@ list_cloners(prop_dictionary_t env, prop_dictionary_t oenv)
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 @@ list_cloners(prop_dictionary_t env, prop_dictionary_t oenv)
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 @@ status(const struct sockaddr *sdl, prop_dictionary_t env,
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 @@ status(const struct sockaddr *sdl, prop_dictionary_t env,
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 @@ status(const struct sockaddr *sdl, prop_dictionary_t env,
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 @@ status(const struct sockaddr *sdl, prop_dictionary_t env,
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;

View File

@ -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,
};

View File

@ -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,
};

View File

@ -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 @@ __RCSID("$NetBSD: media.c,v 1.4 2010/07/01 16:44:05 dyoung Exp $");
#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 @@ media_status(prop_dictionary_t env, prop_dictionary_t oenv)
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 @@ media_status(prop_dictionary_t env, prop_dictionary_t oenv)
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));

61
sbin/ifconfig/prog_ops.h Normal file
View File

@ -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_ */

View File

@ -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 @@ __RCSID("$NetBSD: util.c,v 1.15 2010/07/01 16:44:05 dyoung Exp $");
#include "env.h"
#include "extern.h"
#include "util.h"
#include "prog_ops.h"
int
getsock(int naf)
@ -64,12 +65,12 @@ getsock(int naf)
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 @@ direct_ioctl(prop_dictionary_t env, unsigned long cmd, void *data)
estrlcpy(data, ifname, IFNAMSIZ);
return ioctl(s, cmd, data);
return prog_ioctl(s, cmd, data);
}
int
@ -274,7 +275,7 @@ print_link_addresses(prop_dictionary_t env, bool print_active_only)
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 @@ ifa_get_preference(const char *ifname, const struct sockaddr *sa)
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");