1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. 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.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 lint
|
1996-11-21 19:36:09 +00:00
|
|
|
static const char copyright[] =
|
1994-05-26 06:35:07 +00:00
|
|
|
"@(#) Copyright (c) 1983, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1998-07-06 06:53:43 +00:00
|
|
|
#if 0
|
1994-05-26 06:35:07 +00:00
|
|
|
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
|
1998-07-06 06:53:43 +00:00
|
|
|
#endif
|
1996-11-21 19:36:09 +00:00
|
|
|
static const char rcsid[] =
|
1999-08-28 00:22:10 +00:00
|
|
|
"$FreeBSD$";
|
1994-05-26 06:35:07 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
1996-11-21 19:36:09 +00:00
|
|
|
#include <sys/socket.h>
|
1996-01-01 09:05:22 +00:00
|
|
|
#include <sys/sysctl.h>
|
1996-12-10 17:11:53 +00:00
|
|
|
#include <sys/time.h>
|
1999-09-20 07:58:08 +00:00
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/linker.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2000-06-16 20:14:43 +00:00
|
|
|
#include <net/ethernet.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <net/if.h>
|
1997-01-03 20:19:50 +00:00
|
|
|
#include <net/if_var.h>
|
1994-12-30 22:42:41 +00:00
|
|
|
#include <net/if_dl.h>
|
1996-01-01 09:05:22 +00:00
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/route.h>
|
1996-11-21 19:36:09 +00:00
|
|
|
|
|
|
|
/* IP */
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <netinet/in.h>
|
1994-12-30 22:42:41 +00:00
|
|
|
#include <netinet/in_var.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <arpa/inet.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <netdb.h>
|
|
|
|
|
2000-11-27 08:44:57 +00:00
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet6/nd6.h> /* Define ND6_INFINITE_LIFETIME */
|
|
|
|
#endif
|
|
|
|
|
2001-07-21 00:35:11 +00:00
|
|
|
#ifndef NO_IPX
|
1996-11-21 19:36:09 +00:00
|
|
|
/* IPX */
|
1995-10-26 20:31:59 +00:00
|
|
|
#define IPXIP
|
|
|
|
#define IPTUNNEL
|
|
|
|
#include <netipx/ipx.h>
|
|
|
|
#include <netipx/ipx_if.h>
|
2001-07-21 00:35:11 +00:00
|
|
|
#endif
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
/* Appletalk */
|
1996-07-09 02:38:13 +00:00
|
|
|
#include <netatalk/at.h>
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
1996-11-21 19:36:09 +00:00
|
|
|
#include <fcntl.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2002-06-15 15:35:24 +00:00
|
|
|
#include <ifaddrs.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1997-05-04 06:27:45 +00:00
|
|
|
#include "ifconfig.h"
|
|
|
|
|
2000-02-10 03:03:09 +00:00
|
|
|
/* wrapper for KAME-special getnameinfo() */
|
|
|
|
#ifndef NI_WITHSCOPEID
|
|
|
|
#define NI_WITHSCOPEID 0
|
|
|
|
#endif
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
struct ifreq ifr, ridreq;
|
|
|
|
struct ifaliasreq addreq;
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
struct in6_ifreq in6_ridreq;
|
2000-11-27 08:44:57 +00:00
|
|
|
struct in6_aliasreq in6_addreq =
|
|
|
|
{ { 0 },
|
|
|
|
{ 0 },
|
|
|
|
{ 0 },
|
|
|
|
{ 0 },
|
|
|
|
0,
|
|
|
|
{ 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } };
|
1999-12-07 17:39:16 +00:00
|
|
|
#endif
|
1994-05-26 06:35:07 +00:00
|
|
|
struct sockaddr_in netmask;
|
1996-07-23 01:18:47 +00:00
|
|
|
struct netrange at_nr; /* AppleTalk net range */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2004-01-27 01:43:14 +00:00
|
|
|
char name[IFNAMSIZ];
|
1994-05-26 06:35:07 +00:00
|
|
|
int flags;
|
|
|
|
int setaddr;
|
|
|
|
int setipdst;
|
2001-07-26 16:44:19 +00:00
|
|
|
int setmask;
|
1994-05-26 06:35:07 +00:00
|
|
|
int doalias;
|
|
|
|
int clearaddr;
|
|
|
|
int newaddr = 1;
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
static int ip6lifetime;
|
|
|
|
#endif
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
struct afswtch;
|
|
|
|
|
2001-05-29 09:13:44 +00:00
|
|
|
int supmedia = 0;
|
2001-07-02 20:52:34 +00:00
|
|
|
int listcloners = 0;
|
2004-02-04 02:55:46 +00:00
|
|
|
int printname = 0; /* Print the name of the created interface. */
|
2001-05-29 09:13:44 +00:00
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
2000-02-10 03:03:09 +00:00
|
|
|
char addr_buf[MAXHOSTNAMELEN *2 + 1]; /*for getnameinfo()*/
|
1999-12-07 17:39:16 +00:00
|
|
|
#endif
|
|
|
|
|
2002-04-18 17:14:09 +00:00
|
|
|
void Perror(const char *cmd);
|
|
|
|
void checkatrange(struct sockaddr_at *);
|
|
|
|
int ifconfig(int argc, char *const *argv, const struct afswtch *afp);
|
|
|
|
void notealias(const char *, int, int, const struct afswtch *afp);
|
|
|
|
void list_cloners(void);
|
|
|
|
void printb(const char *s, unsigned value, const char *bits);
|
|
|
|
void rt_xaddrs(caddr_t, caddr_t, struct rt_addrinfo *);
|
|
|
|
void status(const struct afswtch *afp, int addrcount,
|
1997-05-10 17:14:53 +00:00
|
|
|
struct sockaddr_dl *sdl, struct if_msghdr *ifm,
|
2002-04-18 17:14:09 +00:00
|
|
|
struct ifa_msghdr *ifam);
|
|
|
|
void tunnel_status(int s);
|
|
|
|
void usage(void);
|
|
|
|
void ifmaybeload(char *name);
|
1996-11-21 19:36:09 +00:00
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
2002-04-18 17:14:09 +00:00
|
|
|
void in6_fillscopeid(struct sockaddr_in6 *sin6);
|
|
|
|
int prefix(void *, int);
|
|
|
|
static char *sec2str(time_t);
|
1999-12-07 17:39:16 +00:00
|
|
|
int explicit_prefix = 0;
|
|
|
|
#endif
|
|
|
|
|
2002-04-18 17:14:09 +00:00
|
|
|
typedef void c_func(const char *cmd, int arg, int s, const struct afswtch *afp);
|
|
|
|
typedef void c_func2(const char *arg, const char *arg2, int s, const struct afswtch *afp);
|
1996-11-21 19:36:09 +00:00
|
|
|
c_func setatphase, setatrange;
|
|
|
|
c_func setifaddr, setifbroadaddr, setifdstaddr, setifnetmask;
|
2001-06-11 12:39:29 +00:00
|
|
|
c_func2 settunnel;
|
|
|
|
c_func deletetunnel;
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
c_func setifprefixlen;
|
|
|
|
c_func setip6flags;
|
2000-11-27 08:44:57 +00:00
|
|
|
c_func setip6pltime;
|
2001-06-11 12:39:29 +00:00
|
|
|
c_func setip6vltime;
|
|
|
|
c_func2 setip6lifetime;
|
2002-06-15 15:35:24 +00:00
|
|
|
c_func setip6eui64;
|
1999-12-07 17:39:16 +00:00
|
|
|
#endif
|
1996-11-21 19:36:09 +00:00
|
|
|
c_func setifipdst;
|
2002-03-27 14:29:23 +00:00
|
|
|
c_func setifflags, setifmetric, setifmtu, setifcap;
|
2001-07-02 20:52:34 +00:00
|
|
|
c_func clone_destroy;
|
2004-02-04 02:55:46 +00:00
|
|
|
c_func setifname;
|
2001-07-02 20:52:34 +00:00
|
|
|
|
|
|
|
|
2002-04-18 17:14:09 +00:00
|
|
|
void clone_create(void);
|
1996-11-21 19:36:09 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
#define NEXTARG 0xffffff
|
2001-06-11 12:39:29 +00:00
|
|
|
#define NEXTARG2 0xfffffe
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
const
|
1994-05-26 06:35:07 +00:00
|
|
|
struct cmd {
|
1996-11-21 19:36:09 +00:00
|
|
|
const char *c_name;
|
1994-05-26 06:35:07 +00:00
|
|
|
int c_parameter; /* NEXTARG means next argv */
|
2002-04-18 17:14:09 +00:00
|
|
|
void (*c_func)(const char *, int, int, const struct afswtch *afp);
|
|
|
|
void (*c_func2)(const char *, const char *, int, const struct afswtch *afp);
|
1994-05-26 06:35:07 +00:00
|
|
|
} cmds[] = {
|
|
|
|
{ "up", IFF_UP, setifflags } ,
|
|
|
|
{ "down", -IFF_UP, setifflags },
|
|
|
|
{ "arp", -IFF_NOARP, setifflags },
|
|
|
|
{ "-arp", IFF_NOARP, setifflags },
|
|
|
|
{ "debug", IFF_DEBUG, setifflags },
|
|
|
|
{ "-debug", -IFF_DEBUG, setifflags },
|
2002-08-19 15:16:38 +00:00
|
|
|
{ "promisc", IFF_PPROMISC, setifflags },
|
|
|
|
{ "-promisc", -IFF_PPROMISC, setifflags },
|
2000-02-26 18:55:39 +00:00
|
|
|
{ "add", IFF_UP, notealias },
|
1994-05-26 06:35:07 +00:00
|
|
|
{ "alias", IFF_UP, notealias },
|
|
|
|
{ "-alias", -IFF_UP, notealias },
|
|
|
|
{ "delete", -IFF_UP, notealias },
|
2000-02-26 18:55:39 +00:00
|
|
|
{ "remove", -IFF_UP, notealias },
|
1994-05-26 06:35:07 +00:00
|
|
|
#ifdef notdef
|
|
|
|
#define EN_SWABIPS 0x1000
|
|
|
|
{ "swabips", EN_SWABIPS, setifflags },
|
|
|
|
{ "-swabips", -EN_SWABIPS, setifflags },
|
|
|
|
#endif
|
|
|
|
{ "netmask", NEXTARG, setifnetmask },
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
{ "prefixlen", NEXTARG, setifprefixlen },
|
|
|
|
{ "anycast", IN6_IFF_ANYCAST, setip6flags },
|
|
|
|
{ "tentative", IN6_IFF_TENTATIVE, setip6flags },
|
|
|
|
{ "-tentative", -IN6_IFF_TENTATIVE, setip6flags },
|
2001-06-11 12:39:29 +00:00
|
|
|
{ "deprecated", IN6_IFF_DEPRECATED, setip6flags },
|
|
|
|
{ "-deprecated", -IN6_IFF_DEPRECATED, setip6flags },
|
|
|
|
{ "autoconf", IN6_IFF_AUTOCONF, setip6flags },
|
|
|
|
{ "-autoconf", -IN6_IFF_AUTOCONF, setip6flags },
|
2000-11-27 08:44:57 +00:00
|
|
|
{ "pltime", NEXTARG, setip6pltime },
|
2001-06-11 12:39:29 +00:00
|
|
|
{ "vltime", NEXTARG, setip6vltime },
|
2002-06-15 15:35:24 +00:00
|
|
|
{ "eui64", 0, setip6eui64 },
|
1999-12-07 17:39:16 +00:00
|
|
|
#endif
|
1996-07-23 01:18:47 +00:00
|
|
|
{ "range", NEXTARG, setatrange },
|
|
|
|
{ "phase", NEXTARG, setatphase },
|
1994-05-26 06:35:07 +00:00
|
|
|
{ "metric", NEXTARG, setifmetric },
|
|
|
|
{ "broadcast", NEXTARG, setifbroadaddr },
|
|
|
|
{ "ipdst", NEXTARG, setifipdst },
|
2001-06-11 12:39:29 +00:00
|
|
|
{ "tunnel", NEXTARG2, NULL, settunnel },
|
|
|
|
{ "deletetunnel", 0, deletetunnel },
|
1994-08-08 10:45:06 +00:00
|
|
|
{ "link0", IFF_LINK0, setifflags },
|
|
|
|
{ "-link0", -IFF_LINK0, setifflags },
|
|
|
|
{ "link1", IFF_LINK1, setifflags },
|
|
|
|
{ "-link1", -IFF_LINK1, setifflags },
|
|
|
|
{ "link2", IFF_LINK2, setifflags },
|
|
|
|
{ "-link2", -IFF_LINK2, setifflags },
|
2002-09-27 18:57:47 +00:00
|
|
|
{ "monitor", IFF_MONITOR, setifflags },
|
|
|
|
{ "-monitor", -IFF_MONITOR, setifflags },
|
2003-10-01 08:32:37 +00:00
|
|
|
{ "staticarp", IFF_STATICARP, setifflags },
|
|
|
|
{ "-staticarp", -IFF_STATICARP, setifflags },
|
1997-05-04 06:27:45 +00:00
|
|
|
#ifdef USE_IF_MEDIA
|
|
|
|
{ "media", NEXTARG, setmedia },
|
2003-04-28 16:37:38 +00:00
|
|
|
{ "mode", NEXTARG, setmediamode },
|
1997-05-04 06:27:45 +00:00
|
|
|
{ "mediaopt", NEXTARG, setmediaopt },
|
|
|
|
{ "-mediaopt", NEXTARG, unsetmediaopt },
|
1999-03-15 01:22:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_VLANS
|
|
|
|
{ "vlan", NEXTARG, setvlantag },
|
|
|
|
{ "vlandev", NEXTARG, setvlandev },
|
|
|
|
{ "-vlandev", NEXTARG, unsetvlandev },
|
2001-05-26 09:27:08 +00:00
|
|
|
#endif
|
2001-07-02 20:52:34 +00:00
|
|
|
#if 0
|
|
|
|
/* XXX `create' special-cased below */
|
|
|
|
{"create", 0, clone_create },
|
|
|
|
{"plumb", 0, clone_create },
|
|
|
|
#endif
|
|
|
|
{"destroy", 0, clone_destroy },
|
|
|
|
{"unplumb", 0, clone_destroy },
|
2001-05-26 09:27:08 +00:00
|
|
|
#ifdef USE_IEEE80211
|
|
|
|
{ "ssid", NEXTARG, set80211ssid },
|
|
|
|
{ "nwid", NEXTARG, set80211ssid },
|
|
|
|
{ "stationname", NEXTARG, set80211stationname },
|
|
|
|
{ "station", NEXTARG, set80211stationname }, /* BSD/OS */
|
|
|
|
{ "channel", NEXTARG, set80211channel },
|
|
|
|
{ "authmode", NEXTARG, set80211authmode },
|
|
|
|
{ "powersavemode", NEXTARG, set80211powersavemode },
|
|
|
|
{ "powersave", 1, set80211powersave },
|
|
|
|
{ "-powersave", 0, set80211powersave },
|
|
|
|
{ "powersavesleep", NEXTARG, set80211powersavesleep },
|
|
|
|
{ "wepmode", NEXTARG, set80211wepmode },
|
|
|
|
{ "wep", 1, set80211wep },
|
|
|
|
{ "-wep", 0, set80211wep },
|
|
|
|
{ "weptxkey", NEXTARG, set80211weptxkey },
|
|
|
|
{ "wepkey", NEXTARG, set80211wepkey },
|
|
|
|
{ "nwkey", NEXTARG, set80211nwkey }, /* NetBSD */
|
|
|
|
{ "-nwkey", 0, set80211wep }, /* NetBSD */
|
2004-03-30 22:59:22 +00:00
|
|
|
{ "rtsthreshold",NEXTARG, set80211rtsthreshold },
|
|
|
|
{ "protmode", NEXTARG, set80211protmode },
|
|
|
|
{ "txpower", NEXTARG, set80211txpower },
|
2002-10-23 03:40:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_MAC
|
2002-10-23 22:50:04 +00:00
|
|
|
{ "maclabel", NEXTARG, setifmaclabel },
|
1997-05-04 06:27:45 +00:00
|
|
|
#endif
|
2001-09-18 20:13:48 +00:00
|
|
|
{ "rxcsum", IFCAP_RXCSUM, setifcap },
|
|
|
|
{ "-rxcsum", -IFCAP_RXCSUM, setifcap },
|
|
|
|
{ "txcsum", IFCAP_TXCSUM, setifcap },
|
|
|
|
{ "-txcsum", -IFCAP_TXCSUM, setifcap },
|
2001-09-18 17:43:30 +00:00
|
|
|
{ "netcons", IFCAP_NETCONS, setifcap },
|
|
|
|
{ "-netcons", -IFCAP_NETCONS, setifcap },
|
2004-04-11 13:36:52 +00:00
|
|
|
{ "polling", IFCAP_POLLING, setifcap },
|
|
|
|
{ "-polling", -IFCAP_POLLING, setifcap },
|
2004-07-26 13:25:45 +00:00
|
|
|
{ "vlanmtu", IFCAP_VLAN_MTU, setifcap },
|
|
|
|
{ "-vlanmtu", -IFCAP_VLAN_MTU, setifcap },
|
|
|
|
{ "vlanhwtag", IFCAP_VLAN_HWTAGGING, setifcap },
|
|
|
|
{ "-vlanhwtag", -IFCAP_VLAN_HWTAGGING, setifcap },
|
1994-11-20 19:45:58 +00:00
|
|
|
{ "normal", -IFF_LINK0, setifflags },
|
|
|
|
{ "compress", IFF_LINK0, setifflags },
|
|
|
|
{ "noicmp", IFF_LINK1, setifflags },
|
1994-08-08 10:45:06 +00:00
|
|
|
{ "mtu", NEXTARG, setifmtu },
|
2004-02-04 02:55:46 +00:00
|
|
|
{ "name", NEXTARG, setifname },
|
1994-05-26 06:35:07 +00:00
|
|
|
{ 0, 0, setifaddr },
|
|
|
|
{ 0, 0, setifdstaddr },
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XNS support liberally adapted from code written at the University of
|
|
|
|
* Maryland principally by James O'Toole and Chris Torek.
|
|
|
|
*/
|
2002-04-18 17:14:09 +00:00
|
|
|
typedef void af_status(int, struct rt_addrinfo *);
|
|
|
|
typedef void af_getaddr(const char *, int);
|
|
|
|
typedef void af_getprefix(const char *, int);
|
1996-11-21 19:36:09 +00:00
|
|
|
|
2002-03-27 14:29:23 +00:00
|
|
|
af_status in_status, at_status, link_status;
|
|
|
|
af_getaddr in_getaddr, at_getaddr, link_getaddr;
|
2001-07-21 00:35:11 +00:00
|
|
|
|
|
|
|
#ifndef NO_IPX
|
|
|
|
af_status ipx_status;
|
|
|
|
af_getaddr ipx_getaddr;
|
|
|
|
#endif
|
1996-11-21 19:36:09 +00:00
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
af_status in6_status;
|
|
|
|
af_getaddr in6_getaddr;
|
|
|
|
af_getprefix in6_getprefix;
|
|
|
|
#endif /*INET6*/
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
/* Known address families */
|
1996-11-21 19:36:09 +00:00
|
|
|
const
|
|
|
|
struct afswtch {
|
|
|
|
const char *af_name;
|
1994-05-26 06:35:07 +00:00
|
|
|
short af_af;
|
1996-11-21 19:36:09 +00:00
|
|
|
af_status *af_status;
|
|
|
|
af_getaddr *af_getaddr;
|
1999-12-07 17:39:16 +00:00
|
|
|
af_getprefix *af_getprefix;
|
1998-07-06 19:54:39 +00:00
|
|
|
u_long af_difaddr;
|
|
|
|
u_long af_aifaddr;
|
1994-05-26 06:35:07 +00:00
|
|
|
caddr_t af_ridreq;
|
|
|
|
caddr_t af_addreq;
|
|
|
|
} afs[] = {
|
|
|
|
#define C(x) ((caddr_t) &x)
|
1999-12-07 17:39:16 +00:00
|
|
|
{ "inet", AF_INET, in_status, in_getaddr, NULL,
|
1994-05-26 06:35:07 +00:00
|
|
|
SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) },
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
{ "inet6", AF_INET6, in6_status, in6_getaddr, in6_getprefix,
|
|
|
|
SIOCDIFADDR_IN6, SIOCAIFADDR_IN6,
|
|
|
|
C(in6_ridreq), C(in6_addreq) },
|
|
|
|
#endif /*INET6*/
|
2001-07-21 00:35:11 +00:00
|
|
|
#ifndef NO_IPX
|
1999-12-07 17:39:16 +00:00
|
|
|
{ "ipx", AF_IPX, ipx_status, ipx_getaddr, NULL,
|
1995-10-26 20:31:59 +00:00
|
|
|
SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) },
|
2001-07-21 00:35:11 +00:00
|
|
|
#endif
|
1999-12-07 17:39:16 +00:00
|
|
|
{ "atalk", AF_APPLETALK, at_status, at_getaddr, NULL,
|
1996-07-23 01:18:47 +00:00
|
|
|
SIOCDIFADDR, SIOCAIFADDR, C(addreq), C(addreq) },
|
2002-03-27 14:29:23 +00:00
|
|
|
{ "link", AF_LINK, link_status, link_getaddr, NULL,
|
|
|
|
0, SIOCSIFLLADDR, NULL, C(ridreq) },
|
|
|
|
{ "ether", AF_LINK, link_status, link_getaddr, NULL,
|
|
|
|
0, SIOCSIFLLADDR, NULL, C(ridreq) },
|
|
|
|
{ "lladdr", AF_LINK, link_status, link_getaddr, NULL,
|
2000-07-12 16:41:47 +00:00
|
|
|
0, SIOCSIFLLADDR, NULL, C(ridreq) },
|
1997-05-10 17:14:53 +00:00
|
|
|
#if 0 /* XXX conflicts with the media command */
|
|
|
|
#ifdef USE_IF_MEDIA
|
2000-07-12 16:41:47 +00:00
|
|
|
{ "media", AF_UNSPEC, media_status, NULL, NULL, }, /* XXX not real!! */
|
1997-05-10 17:14:53 +00:00
|
|
|
#endif
|
1999-03-15 01:22:01 +00:00
|
|
|
#ifdef USE_VLANS
|
2000-07-12 16:41:47 +00:00
|
|
|
{ "vlan", AF_UNSPEC, vlan_status, NULL, NULL, }, /* XXX not real!! */
|
1999-03-15 01:22:01 +00:00
|
|
|
#endif
|
2001-05-26 09:27:08 +00:00
|
|
|
#ifdef USE_IEEE80211
|
|
|
|
{ "ieee80211", AF_UNSPEC, ieee80211_status, NULL, NULL, }, /* XXX not real!! */
|
|
|
|
#endif
|
2002-10-23 03:40:47 +00:00
|
|
|
#ifdef USE_MAC
|
2002-10-23 22:50:04 +00:00
|
|
|
{ "maclabel", AF_UNSPEC, maclabel_status, NULL, NULL, },
|
2002-10-23 03:40:47 +00:00
|
|
|
#endif
|
1997-05-10 17:14:53 +00:00
|
|
|
#endif
|
1994-05-26 06:35:07 +00:00
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
1996-01-01 09:05:22 +00:00
|
|
|
/*
|
|
|
|
* Expand the compacted form of addresses as returned via the
|
|
|
|
* configuration read via sysctl().
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo)
|
1996-01-01 09:05:22 +00:00
|
|
|
{
|
|
|
|
struct sockaddr *sa;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset(rtinfo->rti_info, 0, sizeof(rtinfo->rti_info));
|
|
|
|
for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {
|
|
|
|
if ((rtinfo->rti_addrs & (1 << i)) == 0)
|
|
|
|
continue;
|
|
|
|
rtinfo->rti_info[i] = sa = (struct sockaddr *)cp;
|
2004-04-13 11:24:43 +00:00
|
|
|
cp += SA_SIZE(sa);
|
1996-01-01 09:05:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-05-04 06:14:47 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
usage(void)
|
1997-05-04 06:14:47 +00:00
|
|
|
{
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifndef INET6
|
2001-07-02 20:52:34 +00:00
|
|
|
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
|
1998-07-06 06:53:43 +00:00
|
|
|
"usage: ifconfig interface address_family [address [dest_address]]",
|
|
|
|
" [parameters]",
|
2001-07-02 20:52:34 +00:00
|
|
|
" ifconfig -C",
|
|
|
|
" ifconfig interface create",
|
2001-05-29 09:13:44 +00:00
|
|
|
" ifconfig -a [-d] [-m] [-u] [address_family]",
|
2000-07-19 17:24:53 +00:00
|
|
|
" ifconfig -l [-d] [-u] [address_family]",
|
2001-05-29 09:13:44 +00:00
|
|
|
" ifconfig [-d] [-m] [-u]");
|
1999-12-07 17:39:16 +00:00
|
|
|
#else
|
2001-07-02 20:52:34 +00:00
|
|
|
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
|
1999-12-07 17:39:16 +00:00
|
|
|
"usage: ifconfig [-L] interface address_family [address [dest_address]]",
|
|
|
|
" [parameters]",
|
2001-07-02 20:52:34 +00:00
|
|
|
" ifconfig -C",
|
|
|
|
" ifconfig interface create",
|
2001-05-29 09:13:44 +00:00
|
|
|
" ifconfig -a [-L] [-d] [-m] [-u] [address_family]",
|
2000-07-19 17:24:53 +00:00
|
|
|
" ifconfig -l [-d] [-u] [address_family]",
|
2001-05-29 09:13:44 +00:00
|
|
|
" ifconfig [-L] [-d] [-m] [-u]");
|
1999-12-07 17:39:16 +00:00
|
|
|
#endif
|
1997-05-04 06:14:47 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
1996-01-01 09:05:22 +00:00
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
int
|
2002-04-18 17:14:09 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
1997-05-04 06:14:47 +00:00
|
|
|
int c;
|
|
|
|
int all, namesonly, downonly, uponly;
|
2004-04-30 22:34:12 +00:00
|
|
|
int need_nl = 0, count = 0;
|
1997-05-10 17:14:53 +00:00
|
|
|
const struct afswtch *afp = 0;
|
2001-10-17 18:30:13 +00:00
|
|
|
int addrcount, ifindex;
|
1997-05-10 17:14:53 +00:00
|
|
|
struct if_msghdr *ifm, *nextifm;
|
|
|
|
struct ifa_msghdr *ifam;
|
|
|
|
struct sockaddr_dl *sdl;
|
|
|
|
char *buf, *lim, *next;
|
1996-01-01 09:05:22 +00:00
|
|
|
size_t needed;
|
1996-11-21 19:36:09 +00:00
|
|
|
int mib[6];
|
1997-05-04 06:14:47 +00:00
|
|
|
|
|
|
|
/* Parse leading line options */
|
1997-10-16 03:55:29 +00:00
|
|
|
all = downonly = uponly = namesonly = 0;
|
2001-07-02 20:52:34 +00:00
|
|
|
while ((c = getopt(argc, argv, "adlmuC"
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
"L"
|
|
|
|
#endif
|
|
|
|
)) != -1) {
|
1997-05-04 06:14:47 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'a': /* scan all interfaces */
|
|
|
|
all++;
|
|
|
|
break;
|
2001-07-02 20:52:34 +00:00
|
|
|
case 'd': /* restrict scan to "down" interfaces */
|
|
|
|
downonly++;
|
1999-12-07 17:39:16 +00:00
|
|
|
break;
|
1997-05-04 06:14:47 +00:00
|
|
|
case 'l': /* scan interface names only */
|
|
|
|
namesonly++;
|
|
|
|
break;
|
2001-07-02 20:52:34 +00:00
|
|
|
case 'm': /* show media choices in status */
|
|
|
|
supmedia = 1;
|
1997-05-04 06:14:47 +00:00
|
|
|
break;
|
1997-10-27 03:28:44 +00:00
|
|
|
case 'u': /* restrict scan to "up" interfaces */
|
1997-05-04 06:14:47 +00:00
|
|
|
uponly++;
|
|
|
|
break;
|
2001-07-02 20:52:34 +00:00
|
|
|
case 'C':
|
|
|
|
listcloners = 1;
|
|
|
|
break;
|
|
|
|
#ifdef INET6
|
|
|
|
case 'L':
|
|
|
|
ip6lifetime++; /* print IPv6 address lifetime */
|
1997-05-04 06:27:45 +00:00
|
|
|
break;
|
2001-07-02 20:52:34 +00:00
|
|
|
#endif
|
1997-05-04 06:14:47 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2001-07-02 20:52:34 +00:00
|
|
|
if (listcloners) {
|
|
|
|
/* -C must be solitary */
|
|
|
|
if (all || supmedia || uponly || downonly || namesonly ||
|
|
|
|
argc > 0)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
list_cloners();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
1997-05-04 06:14:47 +00:00
|
|
|
/* -l cannot be used with -a or -m */
|
2001-05-29 09:13:44 +00:00
|
|
|
if (namesonly && (all || supmedia))
|
1997-05-04 06:14:47 +00:00
|
|
|
usage();
|
|
|
|
|
|
|
|
/* nonsense.. */
|
|
|
|
if (uponly && downonly)
|
|
|
|
usage();
|
|
|
|
|
2000-07-18 22:07:31 +00:00
|
|
|
/* no arguments is equivalent to '-a' */
|
|
|
|
if (!namesonly && argc < 1)
|
|
|
|
all = 1;
|
|
|
|
|
1997-05-04 06:14:47 +00:00
|
|
|
/* -a and -l allow an address family arg to limit the output */
|
|
|
|
if (all || namesonly) {
|
|
|
|
if (argc > 1)
|
|
|
|
usage();
|
|
|
|
|
2001-10-17 18:30:13 +00:00
|
|
|
ifindex = 0;
|
1997-05-04 06:14:47 +00:00
|
|
|
if (argc == 1) {
|
|
|
|
for (afp = afs; afp->af_name; afp++)
|
|
|
|
if (strcmp(afp->af_name, *argv) == 0) {
|
|
|
|
argc--, argv++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (afp->af_name == NULL)
|
|
|
|
usage();
|
|
|
|
/* leave with afp non-zero */
|
|
|
|
}
|
|
|
|
} else {
|
1998-07-06 06:53:43 +00:00
|
|
|
/* not listing, need an argument */
|
1997-05-04 06:14:47 +00:00
|
|
|
if (argc < 1)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
strncpy(name, *argv, sizeof(name));
|
|
|
|
argc--, argv++;
|
1999-09-20 07:58:08 +00:00
|
|
|
|
|
|
|
/* check and maybe load support for this interface */
|
|
|
|
ifmaybeload(name);
|
2001-07-02 20:52:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: We must special-case the `create' command right
|
|
|
|
* here as we would otherwise fail when trying to find
|
|
|
|
* the interface.
|
|
|
|
*/
|
2001-08-17 22:16:11 +00:00
|
|
|
if (argc > 0 && (strcmp(argv[0], "create") == 0 ||
|
|
|
|
strcmp(argv[0], "plumb") == 0)) {
|
2001-07-02 20:52:34 +00:00
|
|
|
clone_create();
|
|
|
|
argc--, argv++;
|
|
|
|
if (argc == 0)
|
2004-02-04 02:55:46 +00:00
|
|
|
goto end;
|
2001-07-02 20:52:34 +00:00
|
|
|
}
|
2001-10-17 18:30:13 +00:00
|
|
|
ifindex = if_nametoindex(name);
|
|
|
|
if (ifindex == 0)
|
|
|
|
errx(1, "interface %s does not exist", name);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
1997-05-04 06:14:47 +00:00
|
|
|
|
|
|
|
/* Check for address family */
|
1994-05-26 06:35:07 +00:00
|
|
|
if (argc > 0) {
|
1997-05-04 06:14:47 +00:00
|
|
|
for (afp = afs; afp->af_name; afp++)
|
|
|
|
if (strcmp(afp->af_name, *argv) == 0) {
|
|
|
|
argc--, argv++;
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
}
|
1997-05-04 06:14:47 +00:00
|
|
|
if (afp->af_name == NULL)
|
1997-05-07 04:28:26 +00:00
|
|
|
afp = NULL; /* not a family, NULL */
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
1996-01-01 09:05:22 +00:00
|
|
|
|
2004-04-30 22:34:12 +00:00
|
|
|
retry:
|
1996-01-01 09:05:22 +00:00
|
|
|
mib[0] = CTL_NET;
|
|
|
|
mib[1] = PF_ROUTE;
|
|
|
|
mib[2] = 0;
|
2001-10-17 18:30:13 +00:00
|
|
|
mib[3] = 0; /* address family */
|
1996-01-01 09:05:22 +00:00
|
|
|
mib[4] = NET_RT_IFLIST;
|
2001-10-17 18:30:13 +00:00
|
|
|
mib[5] = ifindex; /* interface index */
|
1996-01-01 09:05:22 +00:00
|
|
|
|
1996-01-08 10:23:25 +00:00
|
|
|
/* if particular family specified, only ask about it */
|
1997-05-04 06:14:47 +00:00
|
|
|
if (afp)
|
1996-01-08 10:23:25 +00:00
|
|
|
mib[3] = afp->af_af;
|
|
|
|
|
1996-01-01 09:05:22 +00:00
|
|
|
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
|
1996-01-08 10:23:25 +00:00
|
|
|
errx(1, "iflist-sysctl-estimate");
|
1996-01-01 09:05:22 +00:00
|
|
|
if ((buf = malloc(needed)) == NULL)
|
|
|
|
errx(1, "malloc");
|
2004-04-30 22:34:12 +00:00
|
|
|
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
|
|
|
|
if (errno == ENOMEM && count++ < 10) {
|
|
|
|
warnx("Routing table grew, retrying");
|
|
|
|
free(buf);
|
|
|
|
sleep(1);
|
|
|
|
goto retry;
|
|
|
|
}
|
1996-01-01 09:05:22 +00:00
|
|
|
errx(1, "actual retrieval of interface table");
|
2004-04-30 22:34:12 +00:00
|
|
|
}
|
1996-01-01 09:05:22 +00:00
|
|
|
lim = buf + needed;
|
|
|
|
|
1997-05-10 17:14:53 +00:00
|
|
|
next = buf;
|
|
|
|
while (next < lim) {
|
1996-01-01 09:05:22 +00:00
|
|
|
|
|
|
|
ifm = (struct if_msghdr *)next;
|
1997-05-10 17:14:53 +00:00
|
|
|
|
1996-01-01 09:05:22 +00:00
|
|
|
if (ifm->ifm_type == RTM_IFINFO) {
|
|
|
|
sdl = (struct sockaddr_dl *)(ifm + 1);
|
|
|
|
flags = ifm->ifm_flags;
|
|
|
|
} else {
|
1997-05-10 17:14:53 +00:00
|
|
|
fprintf(stderr, "out of sync parsing NET_RT_IFLIST\n");
|
|
|
|
fprintf(stderr, "expected %d, got %d\n", RTM_IFINFO,
|
|
|
|
ifm->ifm_type);
|
|
|
|
fprintf(stderr, "msglen = %d\n", ifm->ifm_msglen);
|
|
|
|
fprintf(stderr, "buf:%p, next:%p, lim:%p\n", buf, next,
|
|
|
|
lim);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
next += ifm->ifm_msglen;
|
|
|
|
ifam = NULL;
|
|
|
|
addrcount = 0;
|
|
|
|
while (next < lim) {
|
|
|
|
|
|
|
|
nextifm = (struct if_msghdr *)next;
|
|
|
|
|
|
|
|
if (nextifm->ifm_type != RTM_NEWADDR)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (ifam == NULL)
|
|
|
|
ifam = (struct ifa_msghdr *)nextifm;
|
|
|
|
|
|
|
|
addrcount++;
|
|
|
|
next += nextifm->ifm_msglen;
|
1996-01-01 09:05:22 +00:00
|
|
|
}
|
2004-01-31 22:59:03 +00:00
|
|
|
memcpy(name, sdl->sdl_data,
|
|
|
|
sizeof(name) < sdl->sdl_nlen ?
|
|
|
|
sizeof(name)-1 : sdl->sdl_nlen);
|
|
|
|
name[sizeof(name) < sdl->sdl_nlen ?
|
|
|
|
sizeof(name)-1 : sdl->sdl_nlen] = '\0';
|
1996-01-01 09:05:22 +00:00
|
|
|
|
1997-05-04 06:14:47 +00:00
|
|
|
if (all || namesonly) {
|
|
|
|
if (uponly)
|
|
|
|
if ((flags & IFF_UP) == 0)
|
|
|
|
continue; /* not up */
|
|
|
|
if (downonly)
|
|
|
|
if (flags & IFF_UP)
|
|
|
|
continue; /* not down */
|
|
|
|
if (namesonly) {
|
1998-03-19 20:58:45 +00:00
|
|
|
if (afp == NULL ||
|
2002-03-27 14:29:23 +00:00
|
|
|
afp->af_status != link_status ||
|
1998-03-19 20:58:45 +00:00
|
|
|
sdl->sdl_type == IFT_ETHER) {
|
|
|
|
if (need_nl)
|
|
|
|
putchar(' ');
|
|
|
|
fputs(name, stdout);
|
|
|
|
need_nl++;
|
|
|
|
}
|
1997-05-04 06:14:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
1996-01-01 09:05:22 +00:00
|
|
|
}
|
|
|
|
|
1997-05-10 17:14:53 +00:00
|
|
|
if (argc > 0)
|
|
|
|
ifconfig(argc, argv, afp);
|
|
|
|
else
|
|
|
|
status(afp, addrcount, sdl, ifm, ifam);
|
1996-01-01 09:05:22 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
|
1997-05-04 06:14:47 +00:00
|
|
|
if (namesonly && need_nl > 0)
|
|
|
|
putchar('\n');
|
2004-02-04 02:55:46 +00:00
|
|
|
end:
|
|
|
|
if (printname)
|
|
|
|
printf("%s\n", name);
|
1997-05-04 06:14:47 +00:00
|
|
|
|
1994-12-30 22:42:41 +00:00
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
1996-01-01 09:05:22 +00:00
|
|
|
int
|
2002-04-18 17:14:09 +00:00
|
|
|
ifconfig(int argc, char *const *argv, const struct afswtch *afp)
|
1994-12-30 22:42:41 +00:00
|
|
|
{
|
1997-05-04 06:14:47 +00:00
|
|
|
int s;
|
1995-03-12 19:05:03 +00:00
|
|
|
|
1997-05-10 17:14:53 +00:00
|
|
|
if (afp == NULL)
|
|
|
|
afp = &afs[0];
|
2000-07-12 16:41:47 +00:00
|
|
|
ifr.ifr_addr.sa_family = afp->af_af == AF_LINK ? AF_INET : afp->af_af;
|
1994-05-26 06:35:07 +00:00
|
|
|
strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
|
1997-05-04 06:14:47 +00:00
|
|
|
|
1998-07-06 06:53:43 +00:00
|
|
|
if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
|
|
|
|
err(1, "socket");
|
1996-01-01 09:05:22 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
while (argc > 0) {
|
2002-03-20 17:55:10 +00:00
|
|
|
const struct cmd *p;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
for (p = cmds; p->c_name; p++)
|
|
|
|
if (strcmp(*argv, p->c_name) == 0)
|
|
|
|
break;
|
|
|
|
if (p->c_name == 0 && setaddr)
|
|
|
|
p++; /* got src, do dst */
|
2001-06-11 12:39:29 +00:00
|
|
|
if (p->c_func || p->c_func2) {
|
1994-05-26 06:35:07 +00:00
|
|
|
if (p->c_parameter == NEXTARG) {
|
|
|
|
if (argv[1] == NULL)
|
|
|
|
errx(1, "'%s' requires argument",
|
|
|
|
p->c_name);
|
1997-05-10 17:14:53 +00:00
|
|
|
(*p->c_func)(argv[1], 0, s, afp);
|
1994-05-26 06:35:07 +00:00
|
|
|
argc--, argv++;
|
2001-06-11 12:39:29 +00:00
|
|
|
} else if (p->c_parameter == NEXTARG2) {
|
|
|
|
if (argc < 3)
|
|
|
|
errx(1, "'%s' requires 2 arguments",
|
|
|
|
p->c_name);
|
|
|
|
(*p->c_func2)(argv[1], argv[2], s, afp);
|
|
|
|
argc -= 2, argv += 2;
|
1994-05-26 06:35:07 +00:00
|
|
|
} else
|
1997-05-10 17:14:53 +00:00
|
|
|
(*p->c_func)(*argv, p->c_parameter, s, afp);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
argc--, argv++;
|
|
|
|
}
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
if (ifr.ifr_addr.sa_family == AF_INET6 && explicit_prefix == 0) {
|
|
|
|
/* Aggregatable address architecture defines all prefixes
|
|
|
|
are 64. So, it is convenient to set prefixlen to 64 if
|
|
|
|
it is not specified. */
|
|
|
|
setifprefixlen("64", 0, s, afp);
|
|
|
|
/* in6_getprefix("64", MASK) if MASK is available here... */
|
|
|
|
}
|
|
|
|
#endif
|
2001-07-21 00:35:11 +00:00
|
|
|
#ifndef NO_IPX
|
1997-05-04 06:14:47 +00:00
|
|
|
if (setipdst && ifr.ifr_addr.sa_family == AF_IPX) {
|
1995-10-26 20:31:59 +00:00
|
|
|
struct ipxip_req rq;
|
|
|
|
int size = sizeof(rq);
|
|
|
|
|
|
|
|
rq.rq_ipx = addreq.ifra_addr;
|
|
|
|
rq.rq_ip = addreq.ifra_dstaddr;
|
|
|
|
|
|
|
|
if (setsockopt(s, 0, SO_IPXIP_ROUTE, &rq, size) < 0)
|
|
|
|
Perror("Encapsulation Routing");
|
|
|
|
}
|
2001-07-21 00:35:11 +00:00
|
|
|
#endif
|
1997-05-04 06:14:47 +00:00
|
|
|
if (ifr.ifr_addr.sa_family == AF_APPLETALK)
|
1996-07-23 01:18:47 +00:00
|
|
|
checkatrange((struct sockaddr_at *) &addreq.ifra_addr);
|
1996-01-08 03:46:27 +00:00
|
|
|
if (clearaddr) {
|
1997-05-10 17:14:53 +00:00
|
|
|
if (afp->af_ridreq == NULL || afp->af_difaddr == 0) {
|
1996-01-08 03:46:27 +00:00
|
|
|
warnx("interface %s cannot change %s addresses!",
|
1997-05-10 17:14:53 +00:00
|
|
|
name, afp->af_name);
|
2004-03-10 08:46:39 +00:00
|
|
|
clearaddr = 0;
|
1996-01-08 03:46:27 +00:00
|
|
|
}
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
if (clearaddr) {
|
|
|
|
int ret;
|
1997-05-10 17:14:53 +00:00
|
|
|
strncpy(afp->af_ridreq, name, sizeof ifr.ifr_name);
|
|
|
|
if ((ret = ioctl(s, afp->af_difaddr, afp->af_ridreq)) < 0) {
|
1994-05-26 06:35:07 +00:00
|
|
|
if (errno == EADDRNOTAVAIL && (doalias >= 0)) {
|
|
|
|
/* means no previous address for interface */
|
|
|
|
} else
|
|
|
|
Perror("ioctl (SIOCDIFADDR)");
|
|
|
|
}
|
|
|
|
}
|
1996-01-08 03:46:27 +00:00
|
|
|
if (newaddr) {
|
1999-12-29 13:53:13 +00:00
|
|
|
if (afp->af_addreq == NULL || afp->af_aifaddr == 0) {
|
1996-01-08 03:46:27 +00:00
|
|
|
warnx("interface %s cannot change %s addresses!",
|
1997-05-10 17:14:53 +00:00
|
|
|
name, afp->af_name);
|
1999-12-29 13:53:13 +00:00
|
|
|
newaddr = 0;
|
1996-01-08 03:46:27 +00:00
|
|
|
}
|
|
|
|
}
|
2001-07-26 16:44:19 +00:00
|
|
|
if (newaddr && (setaddr || setmask)) {
|
1997-05-10 17:14:53 +00:00
|
|
|
strncpy(afp->af_addreq, name, sizeof ifr.ifr_name);
|
|
|
|
if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0)
|
1994-05-26 06:35:07 +00:00
|
|
|
Perror("ioctl (SIOCAIFADDR)");
|
|
|
|
}
|
1997-05-04 06:14:47 +00:00
|
|
|
close(s);
|
1994-12-30 22:42:41 +00:00
|
|
|
return(0);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
#define RIDADDR 0
|
|
|
|
#define ADDR 1
|
|
|
|
#define MASK 2
|
|
|
|
#define DSTADDR 3
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifaddr(const char *addr, int param, int s, const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
1999-12-29 13:53:13 +00:00
|
|
|
if (*afp->af_getaddr == NULL)
|
|
|
|
return;
|
1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Delay the ioctl to set the interface addr until flags are all set.
|
|
|
|
* The address interpretation may depend on the flags,
|
|
|
|
* and the flags may change when the address is set.
|
|
|
|
*/
|
|
|
|
setaddr++;
|
2000-07-12 16:41:47 +00:00
|
|
|
if (doalias == 0 && afp->af_af != AF_LINK)
|
1994-05-26 06:35:07 +00:00
|
|
|
clearaddr = 1;
|
|
|
|
(*afp->af_getaddr)(addr, (doalias >= 0 ? ADDR : RIDADDR));
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
settunnel(const char *src, const char *dst, int s, const struct afswtch *afp)
|
2001-06-11 12:39:29 +00:00
|
|
|
{
|
|
|
|
struct addrinfo hints, *srcres, *dstres;
|
|
|
|
struct ifaliasreq addreq;
|
|
|
|
int ecode;
|
|
|
|
#ifdef INET6
|
|
|
|
struct in6_aliasreq in6_addreq;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = afp->af_af;
|
|
|
|
|
|
|
|
if ((ecode = getaddrinfo(src, NULL, NULL, &srcres)) != 0)
|
|
|
|
errx(1, "error in parsing address string: %s",
|
|
|
|
gai_strerror(ecode));
|
|
|
|
|
|
|
|
if ((ecode = getaddrinfo(dst, NULL, NULL, &dstres)) != 0)
|
|
|
|
errx(1, "error in parsing address string: %s",
|
|
|
|
gai_strerror(ecode));
|
|
|
|
|
|
|
|
if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
|
|
|
|
errx(1,
|
|
|
|
"source and destination address families do not match");
|
|
|
|
|
|
|
|
switch (srcres->ai_addr->sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
memset(&addreq, 0, sizeof(addreq));
|
|
|
|
strncpy(addreq.ifra_name, name, IFNAMSIZ);
|
|
|
|
memcpy(&addreq.ifra_addr, srcres->ai_addr,
|
|
|
|
srcres->ai_addr->sa_len);
|
|
|
|
memcpy(&addreq.ifra_dstaddr, dstres->ai_addr,
|
|
|
|
dstres->ai_addr->sa_len);
|
|
|
|
|
|
|
|
if (ioctl(s, SIOCSIFPHYADDR, &addreq) < 0)
|
|
|
|
warn("SIOCSIFPHYADDR");
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
memset(&in6_addreq, 0, sizeof(in6_addreq));
|
|
|
|
strncpy(in6_addreq.ifra_name, name, IFNAMSIZ);
|
|
|
|
memcpy(&in6_addreq.ifra_addr, srcres->ai_addr,
|
|
|
|
srcres->ai_addr->sa_len);
|
|
|
|
memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr,
|
|
|
|
dstres->ai_addr->sa_len);
|
|
|
|
|
|
|
|
if (ioctl(s, SIOCSIFPHYADDR_IN6, &in6_addreq) < 0)
|
|
|
|
warn("SIOCSIFPHYADDR_IN6");
|
|
|
|
break;
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
default:
|
|
|
|
warn("address family not supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
freeaddrinfo(srcres);
|
|
|
|
freeaddrinfo(dstres);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
deletetunnel(const char *vname, int param, int s, const struct afswtch *afp)
|
2001-06-11 12:39:29 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (ioctl(s, SIOCDIFPHYADDR, &ifr) < 0)
|
|
|
|
err(1, "SIOCDIFPHYADDR");
|
|
|
|
}
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifnetmask(const char *addr, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
1999-12-29 13:53:13 +00:00
|
|
|
if (*afp->af_getaddr == NULL)
|
|
|
|
return;
|
2001-07-26 16:44:19 +00:00
|
|
|
setmask++;
|
1994-05-26 06:35:07 +00:00
|
|
|
(*afp->af_getaddr)(addr, MASK);
|
|
|
|
}
|
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifprefixlen(const char *addr, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1999-12-07 17:39:16 +00:00
|
|
|
{
|
|
|
|
if (*afp->af_getprefix)
|
|
|
|
(*afp->af_getprefix)(addr, MASK);
|
|
|
|
explicit_prefix = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setip6flags(const char *dummyaddr __unused, int flag, int dummysoc __unused,
|
|
|
|
const struct afswtch *afp)
|
1999-12-07 17:39:16 +00:00
|
|
|
{
|
|
|
|
if (afp->af_af != AF_INET6)
|
|
|
|
err(1, "address flags can be set only for inet6 addresses");
|
|
|
|
|
|
|
|
if (flag < 0)
|
|
|
|
in6_addreq.ifra_flags &= ~(-flag);
|
|
|
|
else
|
|
|
|
in6_addreq.ifra_flags |= flag;
|
|
|
|
}
|
2000-11-27 08:44:57 +00:00
|
|
|
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setip6pltime(const char *seconds, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
2000-11-27 08:44:57 +00:00
|
|
|
{
|
2001-06-11 12:39:29 +00:00
|
|
|
setip6lifetime("pltime", seconds, s, afp);
|
2000-11-27 08:44:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setip6vltime(const char *seconds, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
2000-11-27 08:44:57 +00:00
|
|
|
{
|
2001-06-11 12:39:29 +00:00
|
|
|
setip6lifetime("vltime", seconds, s, afp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setip6lifetime(const char *cmd, const char *val, int s,
|
|
|
|
const struct afswtch *afp)
|
2001-06-11 12:39:29 +00:00
|
|
|
{
|
|
|
|
time_t newval, t;
|
|
|
|
char *ep;
|
|
|
|
|
|
|
|
t = time(NULL);
|
|
|
|
newval = (time_t)strtoul(val, &ep, 0);
|
|
|
|
if (val == ep)
|
|
|
|
errx(1, "invalid %s", cmd);
|
|
|
|
if (afp->af_af != AF_INET6)
|
|
|
|
errx(1, "%s not allowed for the AF", cmd);
|
|
|
|
if (strcmp(cmd, "vltime") == 0) {
|
|
|
|
in6_addreq.ifra_lifetime.ia6t_expire = t + newval;
|
|
|
|
in6_addreq.ifra_lifetime.ia6t_vltime = newval;
|
|
|
|
} else if (strcmp(cmd, "pltime") == 0) {
|
|
|
|
in6_addreq.ifra_lifetime.ia6t_preferred = t + newval;
|
|
|
|
in6_addreq.ifra_lifetime.ia6t_pltime = newval;
|
|
|
|
}
|
2000-11-27 08:44:57 +00:00
|
|
|
}
|
2002-06-15 15:35:24 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
setip6eui64(const char *cmd, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
|
|
|
{
|
|
|
|
struct ifaddrs *ifap, *ifa;
|
|
|
|
const struct sockaddr_in6 *sin6 = NULL;
|
|
|
|
const struct in6_addr *lladdr = NULL;
|
|
|
|
struct in6_addr *in6;
|
|
|
|
|
|
|
|
if (afp->af_af != AF_INET6)
|
|
|
|
errx(EXIT_FAILURE, "%s not allowed for the AF", cmd);
|
|
|
|
in6 = (struct in6_addr *)&in6_addreq.ifra_addr.sin6_addr;
|
|
|
|
if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0)
|
|
|
|
errx(EXIT_FAILURE, "interface index is already filled");
|
|
|
|
if (getifaddrs(&ifap) != 0)
|
|
|
|
err(EXIT_FAILURE, "getifaddrs");
|
|
|
|
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
|
|
|
if (ifa->ifa_addr->sa_family == AF_INET6 &&
|
|
|
|
strcmp(ifa->ifa_name, name) == 0) {
|
|
|
|
sin6 = (const struct sockaddr_in6 *)ifa->ifa_addr;
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
|
|
|
|
lladdr = &sin6->sin6_addr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!lladdr)
|
|
|
|
errx(EXIT_FAILURE, "could not determine link local address");
|
|
|
|
|
|
|
|
memcpy(&in6->s6_addr[8], &lladdr->s6_addr[8], 8);
|
|
|
|
|
|
|
|
freeifaddrs(ifap);
|
|
|
|
}
|
1999-12-07 17:39:16 +00:00
|
|
|
#endif
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifbroadaddr(const char *addr, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
1999-12-29 13:53:13 +00:00
|
|
|
if (*afp->af_getaddr == NULL)
|
|
|
|
return;
|
1994-05-26 06:35:07 +00:00
|
|
|
(*afp->af_getaddr)(addr, DSTADDR);
|
|
|
|
}
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifipdst(const char *addr, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
in_getaddr(addr, DSTADDR);
|
|
|
|
setipdst++;
|
|
|
|
clearaddr = 0;
|
|
|
|
newaddr = 0;
|
|
|
|
}
|
|
|
|
#define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr))
|
1996-11-21 19:36:09 +00:00
|
|
|
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
notealias(const char *addr, int param, int s, const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
if (setaddr && doalias == 0 && param < 0)
|
2002-10-02 02:17:59 +00:00
|
|
|
if (afp->af_addreq != NULL && afp->af_ridreq != NULL)
|
|
|
|
bcopy((caddr_t)rqtosa(af_addreq),
|
|
|
|
(caddr_t)rqtosa(af_ridreq),
|
|
|
|
rqtosa(af_addreq)->sa_len);
|
1994-05-26 06:35:07 +00:00
|
|
|
doalias = param;
|
|
|
|
if (param < 0) {
|
|
|
|
clearaddr = 1;
|
|
|
|
newaddr = 0;
|
|
|
|
} else
|
|
|
|
clearaddr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifdstaddr(const char *addr, int param __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
1999-12-29 13:53:13 +00:00
|
|
|
if (*afp->af_getaddr == NULL)
|
|
|
|
return;
|
1994-05-26 06:35:07 +00:00
|
|
|
(*afp->af_getaddr)(addr, DSTADDR);
|
|
|
|
}
|
|
|
|
|
1999-03-15 01:22:01 +00:00
|
|
|
/*
|
|
|
|
* Note: doing an SIOCIGIFFLAGS scribbles on the union portion
|
|
|
|
* of the ifreq structure, which may confuse other parts of ifconfig.
|
|
|
|
* Make a private copy so we can avoid that.
|
|
|
|
*/
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifflags(const char *vname, int value, int s, const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
1999-03-15 01:22:01 +00:00
|
|
|
struct ifreq my_ifr;
|
|
|
|
|
|
|
|
bcopy((char *)&ifr, (char *)&my_ifr, sizeof(struct ifreq));
|
|
|
|
|
|
|
|
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) {
|
1994-05-26 06:35:07 +00:00
|
|
|
Perror("ioctl (SIOCGIFFLAGS)");
|
|
|
|
exit(1);
|
|
|
|
}
|
1999-03-15 01:22:01 +00:00
|
|
|
strncpy(my_ifr.ifr_name, name, sizeof (my_ifr.ifr_name));
|
2002-08-19 15:16:38 +00:00
|
|
|
flags = (my_ifr.ifr_flags & 0xffff) | (my_ifr.ifr_flagshigh << 16);
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
if (value < 0) {
|
|
|
|
value = -value;
|
|
|
|
flags &= ~value;
|
|
|
|
} else
|
|
|
|
flags |= value;
|
2002-08-18 07:05:00 +00:00
|
|
|
my_ifr.ifr_flags = flags & 0xffff;
|
|
|
|
my_ifr.ifr_flagshigh = flags >> 16;
|
1999-03-15 01:22:01 +00:00
|
|
|
if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&my_ifr) < 0)
|
1994-05-26 06:35:07 +00:00
|
|
|
Perror(vname);
|
|
|
|
}
|
|
|
|
|
2001-09-18 17:43:30 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifcap(const char *vname, int value, int s, const struct afswtch *afp)
|
2001-09-18 17:43:30 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0) {
|
|
|
|
Perror("ioctl (SIOCGIFCAP)");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
flags = ifr.ifr_curcap;
|
|
|
|
if (value < 0) {
|
|
|
|
value = -value;
|
|
|
|
flags &= ~value;
|
|
|
|
} else
|
|
|
|
flags |= value;
|
|
|
|
ifr.ifr_reqcap = flags;
|
|
|
|
if (ioctl(s, SIOCSIFCAP, (caddr_t)&ifr) < 0)
|
|
|
|
Perror(vname);
|
|
|
|
}
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifmetric(const char *val, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
|
|
|
ifr.ifr_metric = atoi(val);
|
|
|
|
if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0)
|
1998-07-06 06:53:43 +00:00
|
|
|
warn("ioctl (set metric)");
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setifmtu(const char *val, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1994-08-08 10:45:06 +00:00
|
|
|
{
|
|
|
|
strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
|
|
|
ifr.ifr_mtu = atoi(val);
|
|
|
|
if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0)
|
1998-07-06 06:53:43 +00:00
|
|
|
warn("ioctl (set mtu)");
|
1994-08-08 10:45:06 +00:00
|
|
|
}
|
|
|
|
|
2004-02-04 02:55:46 +00:00
|
|
|
void
|
|
|
|
setifname(const char *val, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
|
|
|
{
|
|
|
|
char *newname;
|
|
|
|
|
|
|
|
newname = strdup(val);
|
|
|
|
|
|
|
|
ifr.ifr_data = newname;
|
|
|
|
if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) {
|
|
|
|
warn("ioctl (set name)");
|
|
|
|
free(newname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strlcpy(name, newname, sizeof(name));
|
|
|
|
free(newname);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Even if we just created the interface, we don't need to print
|
|
|
|
* its name because we just nailed it down separately.
|
|
|
|
*/
|
|
|
|
printname = 0;
|
|
|
|
}
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
#define IFFBITS \
|
1999-06-06 09:17:51 +00:00
|
|
|
"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \
|
1996-11-21 19:36:09 +00:00
|
|
|
"\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \
|
2004-03-12 23:43:40 +00:00
|
|
|
"\20MULTICAST\21POLLING\23MONITOR\24STATICARP"
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2001-09-18 17:43:30 +00:00
|
|
|
#define IFCAPBITS \
|
2004-04-11 13:36:52 +00:00
|
|
|
"\020\1RXCSUM\2TXCSUM\3NETCONS\4VLAN_MTU\5VLAN_HWTAGGING\6JUMBO_MTU\7POLLING"
|
2001-09-18 17:43:30 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Print the status of the interface. If an address family was
|
|
|
|
* specified, show it and it only; otherwise, show them all.
|
|
|
|
*/
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
status(const struct afswtch *afp, int addrcount, struct sockaddr_dl *sdl,
|
|
|
|
struct if_msghdr *ifm, struct ifa_msghdr *ifam)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
1996-11-21 19:36:09 +00:00
|
|
|
const struct afswtch *p = NULL;
|
1997-05-10 17:14:53 +00:00
|
|
|
struct rt_addrinfo info;
|
|
|
|
int allfamilies, s;
|
1999-06-19 18:42:31 +00:00
|
|
|
struct ifstat ifs;
|
1997-05-10 17:14:53 +00:00
|
|
|
|
|
|
|
if (afp == NULL) {
|
|
|
|
allfamilies = 1;
|
|
|
|
afp = &afs[0];
|
|
|
|
} else
|
|
|
|
allfamilies = 0;
|
|
|
|
|
2000-07-12 16:41:47 +00:00
|
|
|
ifr.ifr_addr.sa_family = afp->af_af == AF_LINK ? AF_INET : afp->af_af;
|
2001-10-17 18:30:13 +00:00
|
|
|
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
1997-05-10 17:14:53 +00:00
|
|
|
|
1998-07-06 06:53:43 +00:00
|
|
|
if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
|
|
|
|
err(1, "socket");
|
1997-05-10 17:14:53 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
printf("%s: ", name);
|
|
|
|
printb("flags", flags, IFFBITS);
|
2001-12-03 15:12:45 +00:00
|
|
|
if (ifm->ifm_data.ifi_metric)
|
|
|
|
printf(" metric %ld", ifm->ifm_data.ifi_metric);
|
|
|
|
if (ifm->ifm_data.ifi_mtu)
|
|
|
|
printf(" mtu %ld", ifm->ifm_data.ifi_mtu);
|
1994-05-26 06:35:07 +00:00
|
|
|
putchar('\n');
|
1996-01-01 09:05:22 +00:00
|
|
|
|
2001-09-18 17:43:30 +00:00
|
|
|
if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) {
|
|
|
|
if (ifr.ifr_curcap != 0) {
|
|
|
|
printb("\toptions", ifr.ifr_curcap, IFCAPBITS);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
if (supmedia && ifr.ifr_reqcap != 0) {
|
|
|
|
printf("\tcapability list:\n");
|
|
|
|
printb("\t\t", ifr.ifr_reqcap, IFCAPBITS);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
tunnel_status(s);
|
|
|
|
|
1997-05-10 17:14:53 +00:00
|
|
|
while (addrcount > 0) {
|
|
|
|
|
1996-01-01 09:05:22 +00:00
|
|
|
info.rti_addrs = ifam->ifam_addrs;
|
|
|
|
|
|
|
|
/* Expand the compacted addresses */
|
|
|
|
rt_xaddrs((char *)(ifam + 1), ifam->ifam_msglen + (char *)ifam,
|
|
|
|
&info);
|
|
|
|
|
1997-05-10 17:14:53 +00:00
|
|
|
if (!allfamilies) {
|
2000-07-12 16:41:47 +00:00
|
|
|
if (afp->af_af == info.rti_info[RTAX_IFA]->sa_family) {
|
1996-01-08 10:23:25 +00:00
|
|
|
p = afp;
|
1997-05-10 17:14:53 +00:00
|
|
|
(*p->af_status)(s, &info);
|
1996-01-08 10:23:25 +00:00
|
|
|
}
|
1996-01-01 09:05:22 +00:00
|
|
|
} else for (p = afs; p->af_name; p++) {
|
2000-07-12 16:41:47 +00:00
|
|
|
if (p->af_af == info.rti_info[RTAX_IFA]->sa_family)
|
1997-05-10 17:14:53 +00:00
|
|
|
(*p->af_status)(s, &info);
|
1996-01-01 09:05:22 +00:00
|
|
|
}
|
1997-05-10 17:14:53 +00:00
|
|
|
addrcount--;
|
|
|
|
ifam = (struct ifa_msghdr *)((char *)ifam + ifam->ifam_msglen);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2002-03-27 14:29:23 +00:00
|
|
|
if (allfamilies || afp->af_status == link_status)
|
|
|
|
link_status(s, (struct rt_addrinfo *)sdl);
|
1997-05-10 17:14:53 +00:00
|
|
|
#ifdef USE_IF_MEDIA
|
|
|
|
if (allfamilies || afp->af_status == media_status)
|
|
|
|
media_status(s, NULL);
|
1999-03-15 01:22:01 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_VLANS
|
|
|
|
if (allfamilies || afp->af_status == vlan_status)
|
|
|
|
vlan_status(s, NULL);
|
2001-05-26 09:27:08 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_IEEE80211
|
|
|
|
if (allfamilies || afp->af_status == ieee80211_status)
|
|
|
|
ieee80211_status(s, NULL);
|
2002-10-23 03:40:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_MAC
|
2002-10-23 22:50:04 +00:00
|
|
|
if (allfamilies || afp->af_status == maclabel_status)
|
|
|
|
maclabel_status(s, NULL);
|
1997-05-10 17:14:53 +00:00
|
|
|
#endif
|
1999-06-19 20:07:24 +00:00
|
|
|
strncpy(ifs.ifs_name, name, sizeof ifs.ifs_name);
|
|
|
|
if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0)
|
|
|
|
printf("%s", ifs.ascii);
|
|
|
|
|
2003-01-23 18:31:56 +00:00
|
|
|
if (!allfamilies && !p &&
|
|
|
|
#ifdef USE_IF_MEDIA
|
|
|
|
afp->af_status != media_status &&
|
|
|
|
#endif
|
2002-03-27 14:29:23 +00:00
|
|
|
afp->af_status != link_status
|
2000-11-30 21:35:09 +00:00
|
|
|
#ifdef USE_VLANS
|
2000-11-30 23:01:43 +00:00
|
|
|
&& afp->af_status != vlan_status
|
2000-11-30 21:35:09 +00:00
|
|
|
#endif
|
|
|
|
)
|
1997-05-10 17:14:53 +00:00
|
|
|
warnx("%s has no %s interface address!", name, afp->af_name);
|
|
|
|
|
|
|
|
close(s);
|
|
|
|
return;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
tunnel_status(int s)
|
2001-06-11 12:39:29 +00:00
|
|
|
{
|
|
|
|
char psrcaddr[NI_MAXHOST];
|
|
|
|
char pdstaddr[NI_MAXHOST];
|
|
|
|
u_long srccmd, dstcmd;
|
|
|
|
struct ifreq *ifrp;
|
|
|
|
const char *ver = "";
|
|
|
|
#ifdef NI_WITHSCOPEID
|
|
|
|
const int niflag = NI_NUMERICHOST | NI_WITHSCOPEID;
|
|
|
|
#else
|
|
|
|
const int niflag = NI_NUMERICHOST;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
struct in6_ifreq in6_ifr;
|
|
|
|
int s6;
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
psrcaddr[0] = pdstaddr[0] = '\0';
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
memset(&in6_ifr, 0, sizeof(in6_ifr));
|
|
|
|
strncpy(in6_ifr.ifr_name, name, IFNAMSIZ);
|
|
|
|
s6 = socket(AF_INET6, SOCK_DGRAM, 0);
|
|
|
|
if (s6 < 0) {
|
|
|
|
srccmd = SIOCGIFPSRCADDR;
|
|
|
|
dstcmd = SIOCGIFPDSTADDR;
|
|
|
|
ifrp = 𝔦
|
|
|
|
} else {
|
|
|
|
close(s6);
|
|
|
|
srccmd = SIOCGIFPSRCADDR_IN6;
|
|
|
|
dstcmd = SIOCGIFPDSTADDR_IN6;
|
|
|
|
ifrp = (struct ifreq *)&in6_ifr;
|
|
|
|
}
|
|
|
|
#else /* INET6 */
|
|
|
|
srccmd = SIOCGIFPSRCADDR;
|
|
|
|
dstcmd = SIOCGIFPDSTADDR;
|
|
|
|
ifrp = 𝔦
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
if (ioctl(s, srccmd, (caddr_t)ifrp) < 0)
|
|
|
|
return;
|
|
|
|
#ifdef INET6
|
|
|
|
if (ifrp->ifr_addr.sa_family == AF_INET6)
|
|
|
|
in6_fillscopeid((struct sockaddr_in6 *)&ifrp->ifr_addr);
|
|
|
|
#endif
|
|
|
|
getnameinfo(&ifrp->ifr_addr, ifrp->ifr_addr.sa_len,
|
|
|
|
psrcaddr, sizeof(psrcaddr), 0, 0, niflag);
|
|
|
|
#ifdef INET6
|
|
|
|
if (ifrp->ifr_addr.sa_family == AF_INET6)
|
|
|
|
ver = "6";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ioctl(s, dstcmd, (caddr_t)ifrp) < 0)
|
|
|
|
return;
|
|
|
|
#ifdef INET6
|
|
|
|
if (ifrp->ifr_addr.sa_family == AF_INET6)
|
|
|
|
in6_fillscopeid((struct sockaddr_in6 *)&ifrp->ifr_addr);
|
|
|
|
#endif
|
|
|
|
getnameinfo(&ifrp->ifr_addr, ifrp->ifr_addr.sa_len,
|
|
|
|
pdstaddr, sizeof(pdstaddr), 0, 0, niflag);
|
|
|
|
|
|
|
|
printf("\ttunnel inet%s %s --> %s\n", ver,
|
|
|
|
psrcaddr, pdstaddr);
|
|
|
|
}
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
in_status(int s __unused, struct rt_addrinfo * info)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
1996-01-01 09:05:22 +00:00
|
|
|
struct sockaddr_in *sin, null_sin;
|
|
|
|
|
|
|
|
memset(&null_sin, 0, sizeof(null_sin));
|
|
|
|
|
1997-05-10 17:14:53 +00:00
|
|
|
sin = (struct sockaddr_in *)info->rti_info[RTAX_IFA];
|
1994-05-26 06:35:07 +00:00
|
|
|
printf("\tinet %s ", inet_ntoa(sin->sin_addr));
|
1996-01-01 09:05:22 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
if (flags & IFF_POINTOPOINT) {
|
1996-01-01 09:05:22 +00:00
|
|
|
/* note RTAX_BRD overlap with IFF_BROADCAST */
|
1997-05-10 17:14:53 +00:00
|
|
|
sin = (struct sockaddr_in *)info->rti_info[RTAX_BRD];
|
1996-01-01 09:05:22 +00:00
|
|
|
if (!sin)
|
|
|
|
sin = &null_sin;
|
1994-05-26 06:35:07 +00:00
|
|
|
printf("--> %s ", inet_ntoa(sin->sin_addr));
|
|
|
|
}
|
1996-01-01 09:05:22 +00:00
|
|
|
|
1997-05-10 17:14:53 +00:00
|
|
|
sin = (struct sockaddr_in *)info->rti_info[RTAX_NETMASK];
|
1996-01-01 09:05:22 +00:00
|
|
|
if (!sin)
|
|
|
|
sin = &null_sin;
|
1996-11-21 19:36:09 +00:00
|
|
|
printf("netmask 0x%lx ", (unsigned long)ntohl(sin->sin_addr.s_addr));
|
1996-01-01 09:05:22 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
if (flags & IFF_BROADCAST) {
|
1996-01-01 09:05:22 +00:00
|
|
|
/* note RTAX_BRD overlap with IFF_POINTOPOINT */
|
1997-05-10 17:14:53 +00:00
|
|
|
sin = (struct sockaddr_in *)info->rti_info[RTAX_BRD];
|
1996-01-01 09:05:22 +00:00
|
|
|
if (sin && sin->sin_addr.s_addr != 0)
|
1994-05-26 06:35:07 +00:00
|
|
|
printf("broadcast %s", inet_ntoa(sin->sin_addr));
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
2001-06-11 12:39:29 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
in6_fillscopeid(struct sockaddr_in6 *sin6)
|
2001-06-11 12:39:29 +00:00
|
|
|
{
|
|
|
|
#if defined(__KAME__) && defined(KAME_SCOPEID)
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
|
|
|
|
sin6->sin6_scope_id =
|
|
|
|
ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]);
|
|
|
|
sin6->sin6_addr.s6_addr[2] = sin6->sin6_addr.s6_addr[3] = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
in6_status(int s __unused, struct rt_addrinfo * info)
|
1999-12-07 17:39:16 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin, null_sin;
|
|
|
|
struct in6_ifreq ifr6;
|
|
|
|
int s6;
|
|
|
|
u_int32_t flags6;
|
|
|
|
struct in6_addrlifetime lifetime;
|
|
|
|
time_t t = time(NULL);
|
2000-02-10 03:03:09 +00:00
|
|
|
int error;
|
2000-02-28 18:38:19 +00:00
|
|
|
u_int32_t scopeid;
|
1999-12-07 17:39:16 +00:00
|
|
|
|
|
|
|
memset(&null_sin, 0, sizeof(null_sin));
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in6 *)info->rti_info[RTAX_IFA];
|
|
|
|
strncpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name));
|
|
|
|
if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
|
|
|
perror("ifconfig: socket");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ifr6.ifr_addr = *sin;
|
|
|
|
if (ioctl(s6, SIOCGIFAFLAG_IN6, &ifr6) < 0) {
|
|
|
|
perror("ifconfig: ioctl(SIOCGIFAFLAG_IN6)");
|
|
|
|
close(s6);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
flags6 = ifr6.ifr_ifru.ifru_flags6;
|
|
|
|
memset(&lifetime, 0, sizeof(lifetime));
|
|
|
|
ifr6.ifr_addr = *sin;
|
|
|
|
if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) {
|
|
|
|
perror("ifconfig: ioctl(SIOCGIFALIFETIME_IN6)");
|
|
|
|
close(s6);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lifetime = ifr6.ifr_ifru.ifru_lifetime;
|
|
|
|
close(s6);
|
|
|
|
|
2000-02-10 03:03:09 +00:00
|
|
|
/* XXX: embedded link local addr check */
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) &&
|
|
|
|
*(u_short *)&sin->sin6_addr.s6_addr[2] != 0) {
|
|
|
|
u_short index;
|
|
|
|
|
|
|
|
index = *(u_short *)&sin->sin6_addr.s6_addr[2];
|
|
|
|
*(u_short *)&sin->sin6_addr.s6_addr[2] = 0;
|
|
|
|
if (sin->sin6_scope_id == 0)
|
|
|
|
sin->sin6_scope_id = ntohs(index);
|
|
|
|
}
|
2000-02-28 18:38:19 +00:00
|
|
|
scopeid = sin->sin6_scope_id;
|
1999-12-07 17:39:16 +00:00
|
|
|
|
2000-02-10 03:03:09 +00:00
|
|
|
error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, addr_buf,
|
|
|
|
sizeof(addr_buf), NULL, 0,
|
|
|
|
NI_NUMERICHOST|NI_WITHSCOPEID);
|
|
|
|
if (error != 0)
|
|
|
|
inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
|
|
|
|
sizeof(addr_buf));
|
|
|
|
printf("\tinet6 %s ", addr_buf);
|
1999-12-07 17:39:16 +00:00
|
|
|
|
|
|
|
if (flags & IFF_POINTOPOINT) {
|
|
|
|
/* note RTAX_BRD overlap with IFF_BROADCAST */
|
|
|
|
sin = (struct sockaddr_in6 *)info->rti_info[RTAX_BRD];
|
|
|
|
/*
|
|
|
|
* some of the interfaces do not have valid destination
|
|
|
|
* address.
|
|
|
|
*/
|
|
|
|
if (sin && sin->sin6_family == AF_INET6) {
|
2000-02-10 03:03:09 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
/* XXX: embedded link local addr check */
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) &&
|
|
|
|
*(u_short *)&sin->sin6_addr.s6_addr[2] != 0) {
|
|
|
|
u_short index;
|
|
|
|
|
|
|
|
index = *(u_short *)&sin->sin6_addr.s6_addr[2];
|
|
|
|
*(u_short *)&sin->sin6_addr.s6_addr[2] = 0;
|
|
|
|
if (sin->sin6_scope_id == 0)
|
|
|
|
sin->sin6_scope_id = ntohs(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = getnameinfo((struct sockaddr *)sin,
|
|
|
|
sin->sin6_len, addr_buf,
|
|
|
|
sizeof(addr_buf), NULL, 0,
|
|
|
|
NI_NUMERICHOST|NI_WITHSCOPEID);
|
|
|
|
if (error != 0)
|
|
|
|
inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
|
|
|
|
sizeof(addr_buf));
|
|
|
|
printf("--> %s ", addr_buf);
|
1999-12-07 17:39:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in6 *)info->rti_info[RTAX_NETMASK];
|
|
|
|
if (!sin)
|
|
|
|
sin = &null_sin;
|
|
|
|
printf("prefixlen %d ", prefix(&sin->sin6_addr,
|
|
|
|
sizeof(struct in6_addr)));
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
if ((flags6 & IN6_IFF_ANYCAST) != 0)
|
1999-12-07 17:39:16 +00:00
|
|
|
printf("anycast ");
|
2001-06-11 12:39:29 +00:00
|
|
|
if ((flags6 & IN6_IFF_TENTATIVE) != 0)
|
1999-12-07 17:39:16 +00:00
|
|
|
printf("tentative ");
|
2001-06-11 12:39:29 +00:00
|
|
|
if ((flags6 & IN6_IFF_DUPLICATED) != 0)
|
1999-12-07 17:39:16 +00:00
|
|
|
printf("duplicated ");
|
2001-06-11 12:39:29 +00:00
|
|
|
if ((flags6 & IN6_IFF_DETACHED) != 0)
|
1999-12-07 17:39:16 +00:00
|
|
|
printf("detached ");
|
2001-06-11 12:39:29 +00:00
|
|
|
if ((flags6 & IN6_IFF_DEPRECATED) != 0)
|
1999-12-07 17:39:16 +00:00
|
|
|
printf("deprecated ");
|
2001-06-11 12:39:29 +00:00
|
|
|
if ((flags6 & IN6_IFF_AUTOCONF) != 0)
|
|
|
|
printf("autoconf ");
|
|
|
|
if ((flags6 & IN6_IFF_TEMPORARY) != 0)
|
|
|
|
printf("temporary ");
|
1999-12-07 17:39:16 +00:00
|
|
|
|
2000-02-28 18:38:19 +00:00
|
|
|
if (scopeid)
|
2000-03-06 05:29:56 +00:00
|
|
|
printf("scopeid 0x%x ", scopeid);
|
1999-12-07 17:39:16 +00:00
|
|
|
|
|
|
|
if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) {
|
|
|
|
printf("pltime ");
|
|
|
|
if (lifetime.ia6t_preferred) {
|
|
|
|
printf("%s ", lifetime.ia6t_preferred < t
|
|
|
|
? "0" : sec2str(lifetime.ia6t_preferred - t));
|
|
|
|
} else
|
|
|
|
printf("infty ");
|
|
|
|
|
|
|
|
printf("vltime ");
|
|
|
|
if (lifetime.ia6t_expire) {
|
|
|
|
printf("%s ", lifetime.ia6t_expire < t
|
|
|
|
? "0" : sec2str(lifetime.ia6t_expire - t));
|
|
|
|
} else
|
|
|
|
printf("infty ");
|
|
|
|
}
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
#endif /*INET6*/
|
|
|
|
|
2001-07-21 00:35:11 +00:00
|
|
|
#ifndef NO_IPX
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
ipx_status(int s __unused, struct rt_addrinfo * info)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
1996-01-01 09:05:22 +00:00
|
|
|
struct sockaddr_ipx *sipx, null_sipx;
|
|
|
|
|
|
|
|
memset(&null_sipx, 0, sizeof(null_sipx));
|
|
|
|
|
1997-05-10 17:14:53 +00:00
|
|
|
sipx = (struct sockaddr_ipx *)info->rti_info[RTAX_IFA];
|
1995-10-26 20:31:59 +00:00
|
|
|
printf("\tipx %s ", ipx_ntoa(sipx->sipx_addr));
|
1996-01-01 09:05:22 +00:00
|
|
|
|
|
|
|
if (flags & IFF_POINTOPOINT) {
|
1997-05-10 17:14:53 +00:00
|
|
|
sipx = (struct sockaddr_ipx *)info->rti_info[RTAX_BRD];
|
1996-01-01 09:05:22 +00:00
|
|
|
if (!sipx)
|
|
|
|
sipx = &null_sipx;
|
1995-10-26 20:31:59 +00:00
|
|
|
printf("--> %s ", ipx_ntoa(sipx->sipx_addr));
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
}
|
2001-07-21 00:35:11 +00:00
|
|
|
#endif
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
at_status(int s __unused, struct rt_addrinfo * info)
|
1996-07-09 02:38:13 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_at *sat, null_sat;
|
1996-07-23 01:18:47 +00:00
|
|
|
struct netrange *nr;
|
1996-07-09 02:38:13 +00:00
|
|
|
|
|
|
|
memset(&null_sat, 0, sizeof(null_sat));
|
|
|
|
|
1997-05-10 17:14:53 +00:00
|
|
|
sat = (struct sockaddr_at *)info->rti_info[RTAX_IFA];
|
1996-09-04 19:41:31 +00:00
|
|
|
nr = &sat->sat_range.r_netrange;
|
1996-07-23 01:18:47 +00:00
|
|
|
printf("\tatalk %d.%d range %d-%d phase %d",
|
|
|
|
ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node,
|
|
|
|
ntohs(nr->nr_firstnet), ntohs(nr->nr_lastnet), nr->nr_phase);
|
1996-07-09 02:38:13 +00:00
|
|
|
if (flags & IFF_POINTOPOINT) {
|
|
|
|
/* note RTAX_BRD overlap with IFF_BROADCAST */
|
1997-05-10 17:14:53 +00:00
|
|
|
sat = (struct sockaddr_at *)info->rti_info[RTAX_BRD];
|
1996-07-09 02:38:13 +00:00
|
|
|
if (!sat)
|
|
|
|
sat = &null_sat;
|
1996-07-23 01:18:47 +00:00
|
|
|
printf("--> %d.%d",
|
1996-07-09 02:38:13 +00:00
|
|
|
ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node);
|
|
|
|
}
|
1996-07-23 01:18:47 +00:00
|
|
|
if (flags & IFF_BROADCAST) {
|
|
|
|
/* note RTAX_BRD overlap with IFF_POINTOPOINT */
|
1997-05-10 17:14:53 +00:00
|
|
|
sat = (struct sockaddr_at *)info->rti_info[RTAX_BRD];
|
1996-07-23 01:18:47 +00:00
|
|
|
if (sat)
|
|
|
|
printf(" broadcast %d.%d",
|
|
|
|
ntohs(sat->sat_addr.s_net),
|
|
|
|
sat->sat_addr.s_node);
|
|
|
|
}
|
1996-07-09 02:38:13 +00:00
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
link_status(int s __unused, struct rt_addrinfo *info)
|
1994-12-30 22:42:41 +00:00
|
|
|
{
|
1997-05-10 17:14:53 +00:00
|
|
|
struct sockaddr_dl *sdl = (struct sockaddr_dl *)info;
|
1996-01-01 09:05:22 +00:00
|
|
|
|
2003-01-22 00:14:34 +00:00
|
|
|
if (sdl->sdl_alen > 0) {
|
2002-03-27 14:29:23 +00:00
|
|
|
if (sdl->sdl_type == IFT_ETHER &&
|
|
|
|
sdl->sdl_alen == ETHER_ADDR_LEN)
|
|
|
|
printf("\tether %s\n",
|
|
|
|
ether_ntoa((struct ether_addr *)LLADDR(sdl)));
|
2003-01-22 00:14:34 +00:00
|
|
|
else {
|
|
|
|
int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0;
|
|
|
|
|
|
|
|
printf("\tlladdr %s\n", link_ntoa(sdl) + n);
|
|
|
|
}
|
1994-12-30 22:42:41 +00:00
|
|
|
}
|
|
|
|
}
|
1995-05-30 06:12:45 +00:00
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
Perror(const char *cmd)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
switch (errno) {
|
|
|
|
|
|
|
|
case ENXIO:
|
|
|
|
errx(1, "%s: no such interface", cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EPERM:
|
|
|
|
errx(1, "%s: permission denied", cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err(1, "%s", cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SIN(x) ((struct sockaddr_in *) &(x))
|
|
|
|
struct sockaddr_in *sintab[] = {
|
|
|
|
SIN(ridreq.ifr_addr), SIN(addreq.ifra_addr),
|
|
|
|
SIN(addreq.ifra_mask), SIN(addreq.ifra_broadaddr)};
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
in_getaddr(const char *s, int which)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
struct sockaddr_in *sin = sintab[which];
|
1994-05-26 06:35:07 +00:00
|
|
|
struct hostent *hp;
|
|
|
|
struct netent *np;
|
|
|
|
|
|
|
|
sin->sin_len = sizeof(*sin);
|
|
|
|
if (which != MASK)
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
|
2001-05-04 18:45:36 +00:00
|
|
|
if (which == ADDR) {
|
|
|
|
char *p = NULL;
|
|
|
|
|
|
|
|
if((p = strrchr(s, '/')) != NULL) {
|
|
|
|
/* address is `name/masklen' */
|
|
|
|
int masklen;
|
|
|
|
int ret;
|
|
|
|
struct sockaddr_in *min = sintab[MASK];
|
|
|
|
*p = '\0';
|
|
|
|
ret = sscanf(p+1, "%u", &masklen);
|
|
|
|
if(ret != 1 || (masklen < 0 || masklen > 32)) {
|
|
|
|
*p = '/';
|
|
|
|
errx(1, "%s: bad value", s);
|
|
|
|
}
|
|
|
|
min->sin_len = sizeof(*min);
|
|
|
|
min->sin_addr.s_addr = htonl(~((1LL << (32 - masklen)) - 1) &
|
|
|
|
0xffffffff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-04-26 16:52:40 +00:00
|
|
|
if (inet_aton(s, &sin->sin_addr))
|
1996-11-21 19:36:09 +00:00
|
|
|
return;
|
|
|
|
if ((hp = gethostbyname(s)) != 0)
|
1997-12-26 23:28:17 +00:00
|
|
|
bcopy(hp->h_addr, (char *)&sin->sin_addr,
|
|
|
|
MIN(hp->h_length, sizeof(sin->sin_addr)));
|
1996-11-21 19:36:09 +00:00
|
|
|
else if ((np = getnetbyname(s)) != 0)
|
1994-05-26 06:35:07 +00:00
|
|
|
sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
|
|
|
|
else
|
|
|
|
errx(1, "%s: bad value", s);
|
|
|
|
}
|
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
#define SIN6(x) ((struct sockaddr_in6 *) &(x))
|
|
|
|
struct sockaddr_in6 *sin6tab[] = {
|
|
|
|
SIN6(in6_ridreq.ifr_addr), SIN6(in6_addreq.ifra_addr),
|
|
|
|
SIN6(in6_addreq.ifra_prefixmask), SIN6(in6_addreq.ifra_dstaddr)};
|
|
|
|
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
in6_getaddr(const char *s, int which)
|
1999-12-07 17:39:16 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
struct sockaddr_in6 *sin = sin6tab[which];
|
2000-02-10 03:03:09 +00:00
|
|
|
struct addrinfo hints, *res;
|
|
|
|
int error = -1;
|
1999-12-07 17:39:16 +00:00
|
|
|
|
|
|
|
newaddr &= 1;
|
|
|
|
|
|
|
|
sin->sin6_len = sizeof(*sin);
|
|
|
|
if (which != MASK)
|
|
|
|
sin->sin6_family = AF_INET6;
|
|
|
|
|
2001-05-04 18:45:36 +00:00
|
|
|
if (which == ADDR) {
|
|
|
|
char *p = NULL;
|
|
|
|
if((p = strrchr(s, '/')) != NULL) {
|
|
|
|
*p = '\0';
|
|
|
|
in6_getprefix(p + 1, MASK);
|
|
|
|
explicit_prefix = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-10 03:03:09 +00:00
|
|
|
if (sin->sin6_family == AF_INET6) {
|
|
|
|
bzero(&hints, sizeof(struct addrinfo));
|
|
|
|
hints.ai_family = AF_INET6;
|
|
|
|
error = getaddrinfo(s, NULL, &hints, &res);
|
|
|
|
}
|
|
|
|
if (error != 0) {
|
|
|
|
if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1)
|
|
|
|
errx(1, "%s: bad value", s);
|
|
|
|
} else
|
|
|
|
bcopy(res->ai_addr, sin, res->ai_addrlen);
|
1999-12-07 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
in6_getprefix(const char *plen, int which)
|
1999-12-07 17:39:16 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
struct sockaddr_in6 *sin = sin6tab[which];
|
|
|
|
u_char *cp;
|
1999-12-07 17:39:16 +00:00
|
|
|
int len = atoi(plen);
|
|
|
|
|
|
|
|
if ((len < 0) || (len > 128))
|
|
|
|
errx(1, "%s: bad value", plen);
|
|
|
|
sin->sin6_len = sizeof(*sin);
|
|
|
|
if (which != MASK)
|
|
|
|
sin->sin6_family = AF_INET6;
|
|
|
|
if ((len == 0) || (len == 128)) {
|
|
|
|
memset(&sin->sin6_addr, 0xff, sizeof(struct in6_addr));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memset((void *)&sin->sin6_addr, 0x00, sizeof(sin->sin6_addr));
|
|
|
|
for (cp = (u_char *)&sin->sin6_addr; len > 7; len -= 8)
|
|
|
|
*cp++ = 0xff;
|
|
|
|
*cp = 0xff << (8 - len);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Print a value a la the %b format of the kernel's printf
|
|
|
|
*/
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
printb(const char *s, unsigned v, const char *bits)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
int i, any = 0;
|
|
|
|
char c;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
if (bits && *bits == 8)
|
|
|
|
printf("%s=%o", s, v);
|
|
|
|
else
|
|
|
|
printf("%s=%x", s, v);
|
|
|
|
bits++;
|
|
|
|
if (bits) {
|
|
|
|
putchar('<');
|
1996-11-21 19:36:09 +00:00
|
|
|
while ((i = *bits++) != '\0') {
|
1994-05-26 06:35:07 +00:00
|
|
|
if (v & (1 << (i-1))) {
|
|
|
|
if (any)
|
|
|
|
putchar(',');
|
|
|
|
any = 1;
|
|
|
|
for (; (c = *bits) > 32; bits++)
|
|
|
|
putchar(c);
|
|
|
|
} else
|
|
|
|
for (; *bits > 32; bits++)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
putchar('>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-21 00:35:11 +00:00
|
|
|
#ifndef NO_IPX
|
1995-10-26 20:31:59 +00:00
|
|
|
#define SIPX(x) ((struct sockaddr_ipx *) &(x))
|
|
|
|
struct sockaddr_ipx *sipxtab[] = {
|
|
|
|
SIPX(ridreq.ifr_addr), SIPX(addreq.ifra_addr),
|
|
|
|
SIPX(addreq.ifra_mask), SIPX(addreq.ifra_broadaddr)};
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
ipx_getaddr(const char *addr, int which)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_ipx *sipx = sipxtab[which];
|
|
|
|
|
|
|
|
sipx->sipx_family = AF_IPX;
|
|
|
|
sipx->sipx_len = sizeof(*sipx);
|
|
|
|
sipx->sipx_addr = ipx_addr(addr);
|
|
|
|
if (which == MASK)
|
|
|
|
printf("Attempt to set IPX netmask will be ineffectual\n");
|
|
|
|
}
|
2001-07-21 00:35:11 +00:00
|
|
|
#endif
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
at_getaddr(const char *addr, int which)
|
1996-07-09 02:38:13 +00:00
|
|
|
{
|
1996-07-23 01:18:47 +00:00
|
|
|
struct sockaddr_at *sat = (struct sockaddr_at *) &addreq.ifra_addr;
|
1996-07-09 02:38:13 +00:00
|
|
|
u_int net, node;
|
|
|
|
|
1996-07-23 01:18:47 +00:00
|
|
|
sat->sat_family = AF_APPLETALK;
|
1996-07-09 02:38:13 +00:00
|
|
|
sat->sat_len = sizeof(*sat);
|
1996-07-23 01:18:47 +00:00
|
|
|
if (which == MASK)
|
1998-07-06 06:53:43 +00:00
|
|
|
errx(1, "AppleTalk does not use netmasks");
|
1996-07-09 02:38:13 +00:00
|
|
|
if (sscanf(addr, "%u.%u", &net, &node) != 2
|
1996-09-04 19:41:31 +00:00
|
|
|
|| net > 0xffff || node > 0xfe)
|
1996-07-23 01:18:47 +00:00
|
|
|
errx(1, "%s: illegal address", addr);
|
1996-07-09 02:38:13 +00:00
|
|
|
sat->sat_addr.s_net = htons(net);
|
|
|
|
sat->sat_addr.s_node = node;
|
1996-07-23 01:18:47 +00:00
|
|
|
}
|
|
|
|
|
2000-07-12 16:41:47 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
link_getaddr(const char *addr, int which)
|
2000-07-12 16:41:47 +00:00
|
|
|
{
|
2002-03-27 14:29:23 +00:00
|
|
|
char *temp;
|
|
|
|
struct sockaddr_dl sdl;
|
|
|
|
struct sockaddr *sa = &ridreq.ifr_addr;
|
|
|
|
|
|
|
|
if (which != ADDR)
|
|
|
|
errx(1, "can't set link-level netmask or broadcast");
|
|
|
|
if ((temp = malloc(strlen(addr) + 1)) == NULL)
|
|
|
|
errx(1, "malloc failed");
|
|
|
|
temp[0] = ':';
|
|
|
|
strcpy(temp + 1, addr);
|
|
|
|
sdl.sdl_len = sizeof(sdl);
|
|
|
|
link_addr(temp, &sdl);
|
|
|
|
free(temp);
|
|
|
|
if (sdl.sdl_alen > sizeof(sa->sa_data))
|
|
|
|
errx(1, "malformed link-level address");
|
|
|
|
sa->sa_family = AF_LINK;
|
|
|
|
sa->sa_len = sdl.sdl_alen;
|
|
|
|
bcopy(LLADDR(&sdl), sa->sa_data, sdl.sdl_alen);
|
2000-07-12 16:41:47 +00:00
|
|
|
}
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
/* XXX FIXME -- should use strtoul for better parsing. */
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setatrange(const char *range, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1996-07-23 01:18:47 +00:00
|
|
|
{
|
2003-10-26 04:36:47 +00:00
|
|
|
u_int first = 123, last = 123;
|
1996-07-23 01:18:47 +00:00
|
|
|
|
2003-10-26 04:36:47 +00:00
|
|
|
if (sscanf(range, "%u-%u", &first, &last) != 2
|
1996-07-23 01:18:47 +00:00
|
|
|
|| first == 0 || first > 0xffff
|
|
|
|
|| last == 0 || last > 0xffff || first > last)
|
|
|
|
errx(1, "%s: illegal net range: %u-%u", range, first, last);
|
|
|
|
at_nr.nr_firstnet = htons(first);
|
|
|
|
at_nr.nr_lastnet = htons(last);
|
|
|
|
}
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
setatphase(const char *phase, int dummy __unused, int s,
|
|
|
|
const struct afswtch *afp)
|
1996-07-23 01:18:47 +00:00
|
|
|
{
|
|
|
|
if (!strcmp(phase, "1"))
|
|
|
|
at_nr.nr_phase = 1;
|
|
|
|
else if (!strcmp(phase, "2"))
|
|
|
|
at_nr.nr_phase = 2;
|
|
|
|
else
|
|
|
|
errx(1, "%s: illegal phase", phase);
|
|
|
|
}
|
|
|
|
|
1996-11-21 19:36:09 +00:00
|
|
|
void
|
1996-07-23 01:18:47 +00:00
|
|
|
checkatrange(struct sockaddr_at *sat)
|
|
|
|
{
|
|
|
|
if (at_nr.nr_phase == 0)
|
|
|
|
at_nr.nr_phase = 2; /* Default phase 2 */
|
|
|
|
if (at_nr.nr_firstnet == 0)
|
|
|
|
at_nr.nr_firstnet = /* Default range of one */
|
|
|
|
at_nr.nr_lastnet = sat->sat_addr.s_net;
|
|
|
|
printf("\tatalk %d.%d range %d-%d phase %d\n",
|
|
|
|
ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node,
|
|
|
|
ntohs(at_nr.nr_firstnet), ntohs(at_nr.nr_lastnet), at_nr.nr_phase);
|
|
|
|
if ((u_short) ntohs(at_nr.nr_firstnet) >
|
|
|
|
(u_short) ntohs(sat->sat_addr.s_net)
|
|
|
|
|| (u_short) ntohs(at_nr.nr_lastnet) <
|
|
|
|
(u_short) ntohs(sat->sat_addr.s_net))
|
|
|
|
errx(1, "AppleTalk address is not in range");
|
1996-09-04 19:41:31 +00:00
|
|
|
sat->sat_range.r_netrange = at_nr;
|
1996-07-09 02:38:13 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
int
|
2002-04-18 17:14:09 +00:00
|
|
|
prefix(void *val, int size)
|
1999-12-07 17:39:16 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
u_char *name = (u_char *)val;
|
|
|
|
int byte, bit, plen = 0;
|
1999-12-07 17:39:16 +00:00
|
|
|
|
|
|
|
for (byte = 0; byte < size; byte++, plen += 8)
|
|
|
|
if (name[byte] != 0xff)
|
|
|
|
break;
|
|
|
|
if (byte == size)
|
|
|
|
return (plen);
|
|
|
|
for (bit = 7; bit != 0; bit--, plen++)
|
|
|
|
if (!(name[byte] & (1 << bit)))
|
|
|
|
break;
|
|
|
|
for (; bit != 0; bit--)
|
|
|
|
if (name[byte] & (1 << bit))
|
|
|
|
return(0);
|
|
|
|
byte++;
|
|
|
|
for (; byte < size; byte++)
|
|
|
|
if (name[byte])
|
|
|
|
return(0);
|
|
|
|
return (plen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2002-04-18 17:14:09 +00:00
|
|
|
sec2str(time_t total)
|
1999-12-07 17:39:16 +00:00
|
|
|
{
|
|
|
|
static char result[256];
|
|
|
|
int days, hours, mins, secs;
|
|
|
|
int first = 1;
|
|
|
|
char *p = result;
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
days = total / 3600 / 24;
|
|
|
|
hours = (total / 3600) % 24;
|
|
|
|
mins = (total / 60) % 60;
|
|
|
|
secs = total % 60;
|
|
|
|
|
|
|
|
if (days) {
|
|
|
|
first = 0;
|
|
|
|
p += sprintf(p, "%dd", days);
|
|
|
|
}
|
|
|
|
if (!first || hours) {
|
|
|
|
first = 0;
|
|
|
|
p += sprintf(p, "%dh", hours);
|
|
|
|
}
|
|
|
|
if (!first || mins) {
|
|
|
|
first = 0;
|
|
|
|
p += sprintf(p, "%dm", mins);
|
|
|
|
}
|
|
|
|
sprintf(p, "%ds", secs);
|
|
|
|
} else
|
|
|
|
sprintf(result, "%lu", (unsigned long)total);
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
#endif /*INET6*/
|
|
|
|
|
1999-09-20 07:58:08 +00:00
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
ifmaybeload(char *name)
|
1999-09-20 07:58:08 +00:00
|
|
|
{
|
|
|
|
struct module_stat mstat;
|
|
|
|
int fileid, modid;
|
|
|
|
char ifkind[35], *cp, *dp;
|
|
|
|
|
|
|
|
/* turn interface and unit into module name */
|
|
|
|
strcpy(ifkind, "if_");
|
2001-07-02 20:52:34 +00:00
|
|
|
for (cp = name, dp = ifkind + 3;
|
|
|
|
(*cp != 0) && !isdigit(*cp); cp++, dp++)
|
1999-09-20 07:58:08 +00:00
|
|
|
*dp = *cp;
|
|
|
|
*dp = 0;
|
|
|
|
|
|
|
|
/* scan files in kernel */
|
|
|
|
mstat.version = sizeof(struct module_stat);
|
|
|
|
for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) {
|
|
|
|
/* scan modules in file */
|
|
|
|
for (modid = kldfirstmod(fileid); modid > 0;
|
|
|
|
modid = modfnext(modid)) {
|
|
|
|
if (modstat(modid, &mstat) < 0)
|
|
|
|
continue;
|
|
|
|
/* strip bus name if present */
|
|
|
|
if ((cp = strchr(mstat.name, '/')) != NULL) {
|
|
|
|
cp++;
|
|
|
|
} else {
|
|
|
|
cp = mstat.name;
|
|
|
|
}
|
|
|
|
/* already loaded? */
|
2004-02-27 06:43:14 +00:00
|
|
|
if (strncmp(name, cp, strlen(cp)) == 0 ||
|
|
|
|
strncmp(ifkind, cp, strlen(cp)) == 0)
|
1999-09-20 07:58:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not present, we should try to load it */
|
|
|
|
kldload(ifkind);
|
|
|
|
}
|
2001-07-02 20:52:34 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
list_cloners(void)
|
|
|
|
{
|
|
|
|
struct if_clonereq ifcr;
|
|
|
|
char *cp, *buf;
|
|
|
|
int idx;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (s == -1)
|
|
|
|
err(1, "socket");
|
|
|
|
|
|
|
|
memset(&ifcr, 0, sizeof(ifcr));
|
|
|
|
|
|
|
|
if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0)
|
|
|
|
err(1, "SIOCIFGCLONERS for count");
|
|
|
|
|
|
|
|
buf = malloc(ifcr.ifcr_total * IFNAMSIZ);
|
|
|
|
if (buf == NULL)
|
|
|
|
err(1, "unable to allocate cloner name buffer");
|
|
|
|
|
|
|
|
ifcr.ifcr_count = ifcr.ifcr_total;
|
|
|
|
ifcr.ifcr_buffer = buf;
|
|
|
|
|
|
|
|
if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0)
|
|
|
|
err(1, "SIOCIFGCLONERS for names");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In case some disappeared in the mean time, clamp it down.
|
|
|
|
*/
|
|
|
|
if (ifcr.ifcr_count > ifcr.ifcr_total)
|
|
|
|
ifcr.ifcr_count = ifcr.ifcr_total;
|
|
|
|
|
|
|
|
for (cp = buf, idx = 0; idx < ifcr.ifcr_count; idx++, cp += IFNAMSIZ) {
|
|
|
|
if (idx > 0)
|
|
|
|
putchar(' ');
|
|
|
|
printf("%s", cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
clone_create(void)
|
2001-07-02 20:52:34 +00:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (s == -1)
|
|
|
|
err(1, "socket");
|
|
|
|
|
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
|
|
(void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
|
|
|
if (ioctl(s, SIOCIFCREATE, &ifr) < 0)
|
|
|
|
err(1, "SIOCIFCREATE");
|
|
|
|
|
2004-02-04 02:55:46 +00:00
|
|
|
/*
|
|
|
|
* If we get a different name back then we put in, we probably
|
|
|
|
* want to print it out, but we might change our mind later so
|
|
|
|
* we just signal our intrest and leave the printout for later.
|
|
|
|
*/
|
2001-07-02 20:52:34 +00:00
|
|
|
if (strcmp(name, ifr.ifr_name) != 0) {
|
2004-02-04 02:55:46 +00:00
|
|
|
printname = 1;
|
2001-07-02 20:52:34 +00:00
|
|
|
strlcpy(name, ifr.ifr_name, sizeof(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
close(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-04-18 17:14:09 +00:00
|
|
|
clone_destroy(const char *val, int d, int s, const struct afswtch *rafp)
|
2001-07-02 20:52:34 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
|
|
|
if (ioctl(s, SIOCIFDESTROY, &ifr) < 0)
|
|
|
|
err(1, "SIOCIFDESTROY");
|
2004-02-04 02:55:46 +00:00
|
|
|
/*
|
|
|
|
* If we create and destroy an interface in the same command,
|
|
|
|
* there isn't any reason to print it's name.
|
|
|
|
*/
|
|
|
|
printname = 0;
|
2001-07-02 20:52:34 +00:00
|
|
|
}
|