2008-08-02 02:29:13 +04:00
|
|
|
/* $NetBSD: ifconfig.c,v 1.213 2008/08/01 22:29:13 dyoung Exp $ */
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-06 03:35:17 +04:00
|
|
|
/*-
|
2000-01-25 04:03:21 +03:00
|
|
|
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
|
1997-03-17 06:08:46 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-08-06 03:35:17 +04:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
|
|
* NASA Ames Research Center.
|
|
|
|
*
|
1997-03-17 06:08:46 +03:00
|
|
|
* 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.
|
|
|
|
*
|
1998-08-06 03:35:17 +04:00
|
|
|
* 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.
|
1997-03-17 06:08:46 +03:00
|
|
|
*/
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-09-23 05:38:45 +04:00
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 14:04:22 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-09-15 05:53:35 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
2008-07-20 05:20:21 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\
|
|
|
|
The Regents of the University of California. All rights reserved.");
|
2008-08-02 02:29:13 +04:00
|
|
|
__RCSID("$NetBSD: ifconfig.c,v 1.213 2008/08/01 22:29:13 dyoung Exp $");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
#include <sys/queue.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
1997-03-26 04:46:49 +03:00
|
|
|
#include <net/if_dl.h>
|
1997-03-17 06:08:46 +03:00
|
|
|
#include <net/if_media.h>
|
2000-01-25 02:24:16 +03:00
|
|
|
#include <net/if_ether.h>
|
2005-03-20 05:43:50 +03:00
|
|
|
#include <netinet/in.h> /* XXX */
|
|
|
|
#include <netinet/in_var.h> /* XXX */
|
2008-05-06 08:33:42 +04:00
|
|
|
|
1994-09-23 05:38:45 +04:00
|
|
|
#include <netdb.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
#include <assert.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <ctype.h>
|
1994-09-23 05:38:45 +04:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2008-04-21 09:33:55 +04:00
|
|
|
#include <stdbool.h>
|
1999-04-01 12:12:23 +04:00
|
|
|
#include <stddef.h>
|
1994-09-23 05:38:45 +04:00
|
|
|
#include <stdio.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1994-09-23 05:38:45 +04:00
|
|
|
#include <unistd.h>
|
2000-04-13 11:39:57 +04:00
|
|
|
#include <ifaddrs.h>
|
2002-09-21 01:21:53 +04:00
|
|
|
#include <util.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2005-03-19 06:56:06 +03:00
|
|
|
#include "extern.h"
|
2005-03-20 02:32:55 +03:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
#include "media.h"
|
2008-05-06 08:33:42 +04:00
|
|
|
#include "parse.h"
|
|
|
|
#include "env.h"
|
2005-03-18 14:11:50 +03:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static bool bflag, dflag, hflag, sflag, uflag;
|
|
|
|
bool lflag, vflag, zflag;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static char gflags[10 + 26 * 2 + 1] = "AabCdhlsuvz";
|
|
|
|
bool gflagset[10 + 26 * 2];
|
2008-05-06 08:33:42 +04:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static int carrier(prop_dictionary_t);
|
|
|
|
static int clone_command(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static void do_setifpreference(prop_dictionary_t);
|
|
|
|
static int flag_index(int);
|
|
|
|
static void init_afs(void);
|
|
|
|
static int list_cloners(prop_dictionary_t, prop_dictionary_t);
|
2008-05-06 08:33:42 +04:00
|
|
|
static int media_status_exec(prop_dictionary_t, prop_dictionary_t);
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static int no_cmds_exec(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static int notrailers(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static void printall(const char *, prop_dictionary_t);
|
|
|
|
static int setifaddr(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static int setifbroadaddr(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static int setifcaps(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static int setifdstormask(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static int setifflags(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static int setifmetric(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static int setifmtu(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static int setifnetmask(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static int setifprefixlen(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static void status(const struct sockaddr_dl *, prop_dictionary_t,
|
2008-05-06 21:29:04 +04:00
|
|
|
prop_dictionary_t);
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static void usage(void);
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-08 00:12:31 +04:00
|
|
|
static const struct kwinst ifflagskw[] = {
|
2008-05-06 08:33:42 +04:00
|
|
|
IFKW("arp", IFF_NOARP)
|
|
|
|
, IFKW("debug", IFF_DEBUG)
|
|
|
|
, IFKW("link0", IFF_LINK0)
|
|
|
|
, IFKW("link1", IFF_LINK1)
|
|
|
|
, IFKW("link2", IFF_LINK2)
|
2008-05-19 22:00:31 +04:00
|
|
|
, {.k_word = "down", .k_type = KW_T_INT, .k_int = -IFF_UP}
|
|
|
|
, {.k_word = "up", .k_type = KW_T_INT, .k_int = IFF_UP}
|
2008-05-06 08:33:42 +04:00
|
|
|
};
|
|
|
|
|
2008-05-08 00:12:31 +04:00
|
|
|
static const struct kwinst ifcapskw[] = {
|
2008-05-06 08:33:42 +04:00
|
|
|
IFKW("ip4csum-tx", IFCAP_CSUM_IPv4_Tx)
|
|
|
|
, IFKW("ip4csum-rx", IFCAP_CSUM_IPv4_Rx)
|
|
|
|
, IFKW("tcp4csum-tx", IFCAP_CSUM_TCPv4_Tx)
|
|
|
|
, IFKW("tcp4csum-rx", IFCAP_CSUM_TCPv4_Rx)
|
|
|
|
, IFKW("udp4csum-tx", IFCAP_CSUM_UDPv4_Tx)
|
|
|
|
, IFKW("udp4csum-rx", IFCAP_CSUM_UDPv4_Rx)
|
|
|
|
, IFKW("tcp6csum-tx", IFCAP_CSUM_TCPv6_Tx)
|
|
|
|
, IFKW("tcp6csum-rx", IFCAP_CSUM_TCPv6_Rx)
|
|
|
|
, IFKW("udp6csum-tx", IFCAP_CSUM_UDPv6_Tx)
|
|
|
|
, IFKW("udp6csum-rx", IFCAP_CSUM_UDPv6_Rx)
|
|
|
|
, IFKW("ip4csum", IFCAP_CSUM_IPv4_Tx|IFCAP_CSUM_IPv4_Rx)
|
|
|
|
, IFKW("tcp4csum", IFCAP_CSUM_TCPv4_Tx|IFCAP_CSUM_TCPv4_Rx)
|
|
|
|
, IFKW("udp4csum", IFCAP_CSUM_UDPv4_Tx|IFCAP_CSUM_UDPv4_Rx)
|
|
|
|
, IFKW("tcp6csum", IFCAP_CSUM_TCPv6_Tx|IFCAP_CSUM_TCPv6_Rx)
|
|
|
|
, IFKW("udp6csum", IFCAP_CSUM_UDPv6_Tx|IFCAP_CSUM_UDPv6_Rx)
|
|
|
|
, IFKW("tso4", IFCAP_TSOv4)
|
|
|
|
, IFKW("tso6", IFCAP_TSOv6)
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct pbranch command_root;
|
|
|
|
extern struct pbranch opt_command;
|
|
|
|
extern struct pbranch opt_family, opt_silent_family;
|
2008-05-08 01:29:27 +04:00
|
|
|
extern struct pkw cloning, silent_family, family, ifcaps, ifflags, misc;
|
2008-05-06 08:33:42 +04:00
|
|
|
|
|
|
|
struct pinteger parse_metric = PINTEGER_INITIALIZER(&parse_metric, "metric", 10,
|
|
|
|
setifmetric, "metric", &command_root.pb_parser);
|
|
|
|
|
|
|
|
struct pinteger parse_mtu = PINTEGER_INITIALIZER(&parse_mtu, "mtu", 10,
|
|
|
|
setifmtu, "mtu", &command_root.pb_parser);
|
|
|
|
|
|
|
|
struct pinteger parse_prefixlen = PINTEGER_INITIALIZER(&parse_prefixlen,
|
|
|
|
"prefixlen", 10, setifprefixlen, "prefixlen", &command_root.pb_parser);
|
|
|
|
|
|
|
|
struct pinteger parse_preference = PINTEGER_INITIALIZER1(&parse_preference,
|
|
|
|
"preference", INT16_MIN, INT16_MAX, 10, NULL, "preference",
|
|
|
|
&command_root.pb_parser);
|
|
|
|
|
|
|
|
struct paddr parse_netmask = PADDR_INITIALIZER(&parse_netmask, "netmask",
|
|
|
|
setifnetmask, "dstormask", NULL, NULL, NULL, &command_root.pb_parser);
|
|
|
|
|
|
|
|
struct paddr parse_broadcast = PADDR_INITIALIZER(&parse_broadcast,
|
|
|
|
"broadcast address",
|
|
|
|
setifbroadaddr, "broadcast", NULL, NULL, NULL, &command_root.pb_parser);
|
|
|
|
|
2008-05-08 00:12:31 +04:00
|
|
|
static const struct kwinst misckw[] = {
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
{.k_word = "alias", .k_key = "alias", .k_deact = "alias",
|
2008-05-06 08:33:42 +04:00
|
|
|
.k_type = KW_T_BOOL, .k_neg = true,
|
|
|
|
.k_bool = true, .k_negbool = false,
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
.k_nextparser = &command_root.pb_parser}
|
2008-05-06 08:33:42 +04:00
|
|
|
, {.k_word = "broadcast", .k_nextparser = &parse_broadcast.pa_parser}
|
|
|
|
, {.k_word = "delete", .k_key = "alias", .k_deact = "alias",
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
.k_type = KW_T_BOOL, .k_bool = false,
|
2008-05-06 08:33:42 +04:00
|
|
|
.k_nextparser = &command_root.pb_parser}
|
|
|
|
, {.k_word = "metric", .k_nextparser = &parse_metric.pi_parser}
|
|
|
|
, {.k_word = "mtu", .k_nextparser = &parse_mtu.pi_parser}
|
|
|
|
, {.k_word = "netmask", .k_nextparser = &parse_netmask.pa_parser}
|
|
|
|
, {.k_word = "preference", .k_act = "address",
|
|
|
|
.k_nextparser = &parse_preference.pi_parser}
|
|
|
|
, {.k_word = "prefixlen", .k_nextparser = &parse_prefixlen.pi_parser}
|
|
|
|
, {.k_word = "trailers", .k_neg = true,
|
|
|
|
.k_exec = notrailers, .k_nextparser = &command_root.pb_parser}
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
/* key: clonecmd */
|
2008-05-08 00:12:31 +04:00
|
|
|
static const struct kwinst clonekw[] = {
|
2008-05-19 22:00:31 +04:00
|
|
|
{.k_word = "create", .k_type = KW_T_INT, .k_int = SIOCIFCREATE,
|
2008-05-06 08:33:42 +04:00
|
|
|
.k_nextparser = &opt_silent_family.pb_parser},
|
2008-05-19 22:00:31 +04:00
|
|
|
{.k_word = "destroy", .k_type = KW_T_INT, .k_int = SIOCIFDESTROY}
|
2008-05-06 08:33:42 +04:00
|
|
|
};
|
1997-03-17 06:08:46 +03:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static struct kwinst familykw[24];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
struct pterm cloneterm = PTERM_INITIALIZER(&cloneterm, "list cloners",
|
|
|
|
list_cloners, "none");
|
|
|
|
|
|
|
|
struct pterm no_cmds = PTERM_INITIALIZER(&no_cmds, "no commands", no_cmds_exec,
|
|
|
|
"none");
|
|
|
|
|
|
|
|
struct pkw family_only =
|
|
|
|
PKW_INITIALIZER(&family_only, "family-only", NULL, "af", familykw,
|
|
|
|
__arraycount(familykw), &no_cmds.pt_parser);
|
|
|
|
|
|
|
|
struct paddr address = PADDR_INITIALIZER(&address,
|
|
|
|
"local address (address 1)",
|
|
|
|
setifaddr, "address", "netmask", NULL, "address", &command_root.pb_parser);
|
|
|
|
|
|
|
|
struct paddr dstormask = PADDR_INITIALIZER(&dstormask,
|
|
|
|
"destination/netmask (address 2)",
|
|
|
|
setifdstormask, "dstormask", NULL, "address", "dstormask",
|
|
|
|
&command_root.pb_parser);
|
|
|
|
|
|
|
|
struct paddr broadcast = PADDR_INITIALIZER(&broadcast,
|
|
|
|
"broadcast address (address 3)",
|
|
|
|
setifbroadaddr, "broadcast", NULL, "dstormask", "broadcast",
|
|
|
|
&command_root.pb_parser);
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static SIMPLEQ_HEAD(, afswtch) aflist = SIMPLEQ_HEAD_INITIALIZER(aflist);
|
|
|
|
|
2008-07-16 00:56:13 +04:00
|
|
|
static SIMPLEQ_HEAD(, usage_func) usage_funcs =
|
|
|
|
SIMPLEQ_HEAD_INITIALIZER(usage_funcs);
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static SIMPLEQ_HEAD(, status_func) status_funcs =
|
|
|
|
SIMPLEQ_HEAD_INITIALIZER(status_funcs);
|
|
|
|
static SIMPLEQ_HEAD(, statistics_func) statistics_funcs =
|
|
|
|
SIMPLEQ_HEAD_INITIALIZER(statistics_funcs);
|
|
|
|
static SIMPLEQ_HEAD(, cmdloop_branch) cmdloop_branches =
|
|
|
|
SIMPLEQ_HEAD_INITIALIZER(cmdloop_branches);
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
struct branch opt_clone_brs[] = {
|
|
|
|
{.b_nextparser = &cloning.pk_parser}
|
|
|
|
, {.b_nextparser = &opt_family.pb_parser}
|
|
|
|
}, opt_silent_family_brs[] = {
|
|
|
|
{.b_nextparser = &silent_family.pk_parser}
|
|
|
|
, {.b_nextparser = &command_root.pb_parser}
|
|
|
|
}, opt_family_brs[] = {
|
|
|
|
{.b_nextparser = &family.pk_parser}
|
|
|
|
, {.b_nextparser = &opt_command.pb_parser}
|
|
|
|
}, command_root_brs[] = {
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
{.b_nextparser = &ifflags.pk_parser}
|
2008-05-06 08:33:42 +04:00
|
|
|
, {.b_nextparser = &ifcaps.pk_parser}
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
, {.b_nextparser = &kwmedia.pk_parser}
|
2008-05-06 08:33:42 +04:00
|
|
|
, {.b_nextparser = &misc.pk_parser}
|
|
|
|
, {.b_nextparser = &address.pa_parser}
|
|
|
|
, {.b_nextparser = &dstormask.pa_parser}
|
|
|
|
, {.b_nextparser = &broadcast.pa_parser}
|
|
|
|
, {.b_nextparser = NULL}
|
|
|
|
}, opt_command_brs[] = {
|
|
|
|
{.b_nextparser = &no_cmds.pt_parser}
|
|
|
|
, {.b_nextparser = &command_root.pb_parser}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct branch opt_family_only_brs[] = {
|
|
|
|
{.b_nextparser = &no_cmds.pt_parser}
|
|
|
|
, {.b_nextparser = &family_only.pk_parser}
|
|
|
|
};
|
|
|
|
struct pbranch opt_family_only = PBRANCH_INITIALIZER(&opt_family_only,
|
|
|
|
"opt-family-only", opt_family_only_brs,
|
|
|
|
__arraycount(opt_family_only_brs), true);
|
|
|
|
struct pbranch opt_command = PBRANCH_INITIALIZER(&opt_command,
|
|
|
|
"optional command",
|
|
|
|
opt_command_brs, __arraycount(opt_command_brs), true);
|
|
|
|
|
|
|
|
struct pbranch command_root = PBRANCH_INITIALIZER(&command_root,
|
|
|
|
"command-root", command_root_brs, __arraycount(command_root_brs), true);
|
|
|
|
|
|
|
|
struct piface iface_opt_family_only =
|
|
|
|
PIFACE_INITIALIZER(&iface_opt_family_only, "iface-opt-family-only",
|
|
|
|
NULL, "if", &opt_family_only.pb_parser);
|
|
|
|
|
|
|
|
struct pkw family = PKW_INITIALIZER(&family, "family", NULL, "af",
|
|
|
|
familykw, __arraycount(familykw), &opt_command.pb_parser);
|
|
|
|
|
|
|
|
struct pkw silent_family = PKW_INITIALIZER(&silent_family, "silent family",
|
|
|
|
NULL, "af", familykw, __arraycount(familykw), &command_root.pb_parser);
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
struct pkw *family_users[] = {&family_only, &family, &silent_family};
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
struct pkw ifcaps = PKW_INITIALIZER(&ifcaps, "ifcaps", setifcaps,
|
|
|
|
"ifcap", ifcapskw, __arraycount(ifcapskw), &command_root.pb_parser);
|
|
|
|
|
|
|
|
struct pkw ifflags = PKW_INITIALIZER(&ifflags, "ifflags", setifflags,
|
|
|
|
"ifflag", ifflagskw, __arraycount(ifflagskw), &command_root.pb_parser);
|
|
|
|
|
|
|
|
struct pkw cloning = PKW_INITIALIZER(&cloning, "cloning", clone_command,
|
|
|
|
"clonecmd", clonekw, __arraycount(clonekw), NULL);
|
|
|
|
|
|
|
|
struct pkw misc = PKW_INITIALIZER(&misc, "misc", NULL, NULL,
|
|
|
|
misckw, __arraycount(misckw), NULL);
|
|
|
|
|
|
|
|
struct pbranch opt_clone = PBRANCH_INITIALIZER(&opt_clone,
|
|
|
|
"opt-clone", opt_clone_brs, __arraycount(opt_clone_brs), true);
|
|
|
|
|
|
|
|
struct pbranch opt_silent_family = PBRANCH_INITIALIZER(&opt_silent_family,
|
|
|
|
"optional silent family", opt_silent_family_brs,
|
|
|
|
__arraycount(opt_silent_family_brs), true);
|
|
|
|
|
|
|
|
struct pbranch opt_family = PBRANCH_INITIALIZER(&opt_family,
|
|
|
|
"opt-family", opt_family_brs, __arraycount(opt_family_brs), true);
|
|
|
|
|
|
|
|
struct piface iface_start = PIFACE_INITIALIZER(&iface_start,
|
|
|
|
"iface-opt-family", NULL, "if", &opt_clone.pb_parser);
|
|
|
|
|
|
|
|
struct piface iface_only = PIFACE_INITIALIZER(&iface_only, "iface",
|
|
|
|
media_status_exec, "if", NULL);
|
|
|
|
|
2008-07-16 00:56:13 +04:00
|
|
|
static bool
|
|
|
|
flag_is_registered(const char *flags, int flag)
|
|
|
|
{
|
|
|
|
return flags != NULL && strchr(flags, flag) != NULL;
|
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static int
|
2008-07-16 00:56:13 +04:00
|
|
|
check_flag(const char *flags, int flag)
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
{
|
2008-07-16 00:56:13 +04:00
|
|
|
if (flag_is_registered(flags, flag)) {
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
errno = EEXIST;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag >= '0' && flag <= '9')
|
|
|
|
return 0;
|
|
|
|
if (flag >= 'a' && flag <= 'z')
|
|
|
|
return 0;
|
|
|
|
if (flag >= 'A' && flag <= 'Z')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmdloop_branch_init(cmdloop_branch_t *b, struct parser *p)
|
|
|
|
{
|
|
|
|
b->b_parser = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
statistics_func_init(statistics_func_t *f, statistics_cb_t func)
|
|
|
|
{
|
|
|
|
f->f_func = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
status_func_init(status_func_t *f, status_cb_t func)
|
|
|
|
{
|
|
|
|
f->f_func = func;
|
|
|
|
}
|
|
|
|
|
2008-07-16 00:56:13 +04:00
|
|
|
void
|
|
|
|
usage_func_init(usage_func_t *f, usage_cb_t func)
|
|
|
|
{
|
|
|
|
f->f_func = func;
|
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
int
|
|
|
|
register_cmdloop_branch(cmdloop_branch_t *b)
|
|
|
|
{
|
|
|
|
SIMPLEQ_INSERT_TAIL(&cmdloop_branches, b, b_next);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
register_statistics(statistics_func_t *f)
|
|
|
|
{
|
|
|
|
SIMPLEQ_INSERT_TAIL(&statistics_funcs, f, f_next);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
register_status(status_func_t *f)
|
|
|
|
{
|
|
|
|
SIMPLEQ_INSERT_TAIL(&status_funcs, f, f_next);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-16 00:56:13 +04:00
|
|
|
int
|
|
|
|
register_usage(usage_func_t *f)
|
|
|
|
{
|
|
|
|
SIMPLEQ_INSERT_TAIL(&usage_funcs, f, f_next);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
int
|
|
|
|
register_family(struct afswtch *af)
|
|
|
|
{
|
|
|
|
SIMPLEQ_INSERT_TAIL(&aflist, af, af_next);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
register_flag(int flag)
|
|
|
|
{
|
|
|
|
if (check_flag(gflags, flag) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (strlen(gflags) + 1 >= sizeof(gflags)) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
gflags[strlen(gflags)] = flag;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
flag_index(int flag)
|
|
|
|
{
|
|
|
|
if (flag >= '0' && flag <= '9')
|
|
|
|
return flag - '0';
|
|
|
|
if (flag >= 'a' && flag <= 'z')
|
|
|
|
return 10 + flag - 'a';
|
|
|
|
if (flag >= 'A' && flag <= 'Z')
|
|
|
|
return 10 + 26 + flag - 'a';
|
|
|
|
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
set_flag(int flag)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
if ((idx = flag_index(flag)) == -1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return gflagset[idx] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
get_flag(int flag)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
if ((idx = flag_index(flag)) == -1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return gflagset[idx];
|
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
static struct parser *
|
|
|
|
init_parser(void)
|
|
|
|
{
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
cmdloop_branch_t *b;
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if (parser_init(&iface_opt_family_only.pif_parser) == -1)
|
|
|
|
err(EXIT_FAILURE, "parser_init(iface_opt_family_only)");
|
|
|
|
if (parser_init(&iface_only.pif_parser) == -1)
|
|
|
|
err(EXIT_FAILURE, "parser_init(iface_only)");
|
|
|
|
if (parser_init(&iface_start.pif_parser) == -1)
|
|
|
|
err(EXIT_FAILURE, "parser_init(iface_start)");
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
|
|
|
|
SIMPLEQ_FOREACH(b, &cmdloop_branches, b_next)
|
|
|
|
pbranch_addbranch(&command_root, b->b_parser);
|
2008-05-06 08:33:42 +04:00
|
|
|
|
|
|
|
return &iface_start.pif_parser;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-07-16 01:27:58 +04:00
|
|
|
no_cmds_exec(prop_dictionary_t env, prop_dictionary_t oenv)
|
2008-05-06 08:33:42 +04:00
|
|
|
{
|
|
|
|
const char *ifname;
|
|
|
|
unsigned short ignore;
|
|
|
|
|
|
|
|
/* ifname == NULL is ok. It indicates 'ifconfig -a'. */
|
|
|
|
if ((ifname = getifname(env)) == NULL)
|
|
|
|
;
|
2008-07-16 01:27:58 +04:00
|
|
|
else if (getifflags(env, oenv, &ignore) == -1)
|
2008-05-06 08:33:42 +04:00
|
|
|
err(EXIT_FAILURE, "SIOCGIFFLAGS %s", ifname);
|
|
|
|
|
|
|
|
printall(ifname, env);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-07-16 01:27:58 +04:00
|
|
|
media_status_exec(prop_dictionary_t env, prop_dictionary_t oenv)
|
2008-05-06 08:33:42 +04:00
|
|
|
{
|
|
|
|
const char *ifname;
|
|
|
|
unsigned short ignore;
|
|
|
|
|
|
|
|
/* ifname == NULL is ok. It indicates 'ifconfig -a'. */
|
|
|
|
if ((ifname = getifname(env)) == NULL)
|
|
|
|
;
|
2008-07-16 01:27:58 +04:00
|
|
|
else if (getifflags(env, oenv, &ignore) == -1)
|
2008-05-06 08:33:42 +04:00
|
|
|
err(EXIT_FAILURE, "SIOCGIFFLAGS %s", ifname);
|
|
|
|
|
|
|
|
exit(carrier(env));
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2008-05-07 01:20:05 +04:00
|
|
|
static void
|
2008-05-08 03:55:06 +04:00
|
|
|
do_setifcaps(prop_dictionary_t env)
|
2008-05-07 01:20:05 +04:00
|
|
|
{
|
|
|
|
struct ifcapreq ifcr;
|
|
|
|
prop_data_t d;
|
|
|
|
|
2008-05-07 01:58:05 +04:00
|
|
|
d = (prop_data_t )prop_dictionary_get(env, "ifcaps");
|
|
|
|
if (d == NULL)
|
2008-05-07 01:20:05 +04:00
|
|
|
return;
|
|
|
|
|
2008-05-07 01:58:05 +04:00
|
|
|
assert(sizeof(ifcr) == prop_data_size(d));
|
|
|
|
|
2008-05-07 01:20:05 +04:00
|
|
|
memcpy(&ifcr, prop_data_data_nocopy(d), sizeof(ifcr));
|
2008-05-08 03:55:06 +04:00
|
|
|
if (direct_ioctl(env, SIOCSIFCAP, &ifcr) == -1)
|
2008-05-07 01:20:05 +04:00
|
|
|
err(EXIT_FAILURE, "SIOCSIFCAP");
|
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
int
|
2008-05-06 08:33:42 +04:00
|
|
|
main(int argc, char **argv)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2008-05-06 08:33:42 +04:00
|
|
|
const struct afswtch *afp;
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
int af, s;
|
|
|
|
bool aflag = false, Cflag = false;
|
2008-05-06 08:33:42 +04:00
|
|
|
struct match match[32];
|
|
|
|
size_t nmatch;
|
|
|
|
struct parser *start;
|
|
|
|
int ch, narg = 0, rc;
|
2008-07-16 01:27:58 +04:00
|
|
|
prop_dictionary_t env, oenv;
|
2008-05-06 08:33:42 +04:00
|
|
|
const char *ifname;
|
|
|
|
|
|
|
|
memset(match, 0, sizeof(match));
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
init_afs();
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
start = init_parser();
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
/* Parse command-line options */
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
aflag = vflag = zflag = false;
|
|
|
|
while ((ch = getopt(argc, argv, gflags)) != -1) {
|
1997-03-17 06:08:46 +03:00
|
|
|
switch (ch) {
|
1998-09-06 21:51:32 +04:00
|
|
|
case 'A':
|
2001-04-28 08:11:10 +04:00
|
|
|
warnx("-A is deprecated");
|
1998-09-06 21:51:32 +04:00
|
|
|
break;
|
|
|
|
|
1997-03-17 06:08:46 +03:00
|
|
|
case 'a':
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
aflag = true;
|
1997-03-17 06:08:46 +03:00
|
|
|
break;
|
|
|
|
|
1999-07-03 21:31:15 +04:00
|
|
|
case 'b':
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
bflag = true;
|
1999-07-03 21:31:15 +04:00
|
|
|
break;
|
|
|
|
|
2000-07-20 22:42:02 +04:00
|
|
|
case 'C':
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
Cflag = true;
|
2000-07-20 22:42:02 +04:00
|
|
|
break;
|
|
|
|
|
1997-04-21 05:17:57 +04:00
|
|
|
case 'd':
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
dflag = true;
|
1997-04-21 05:17:57 +04:00
|
|
|
break;
|
2005-08-12 00:56:05 +04:00
|
|
|
case 'h':
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
hflag = true;
|
2005-08-12 00:56:05 +04:00
|
|
|
break;
|
1997-03-28 01:50:09 +03:00
|
|
|
case 'l':
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
lflag = true;
|
1997-03-17 06:08:46 +03:00
|
|
|
break;
|
|
|
|
|
1999-07-03 21:31:15 +04:00
|
|
|
case 's':
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
sflag = true;
|
1999-07-03 21:31:15 +04:00
|
|
|
break;
|
|
|
|
|
1997-04-21 05:17:57 +04:00
|
|
|
case 'u':
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
uflag = true;
|
1997-04-21 05:17:57 +04:00
|
|
|
break;
|
|
|
|
|
2002-05-24 01:38:01 +04:00
|
|
|
case 'v':
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
vflag = true;
|
2002-05-24 01:38:01 +04:00
|
|
|
break;
|
|
|
|
|
2003-04-12 05:07:43 +04:00
|
|
|
case 'z':
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
zflag = true;
|
2003-04-12 05:07:43 +04:00
|
|
|
break;
|
|
|
|
|
1997-03-17 06:08:46 +03:00
|
|
|
default:
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
if (!set_flag(ch))
|
|
|
|
usage();
|
|
|
|
break;
|
1997-03-17 06:08:46 +03:00
|
|
|
}
|
2008-05-06 08:33:42 +04:00
|
|
|
switch (ch) {
|
|
|
|
case 'a':
|
|
|
|
start = &opt_family_only.pb_parser;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'L':
|
|
|
|
case 'm':
|
|
|
|
case 'v':
|
|
|
|
case 'z':
|
|
|
|
if (start != &opt_family_only.pb_parser)
|
|
|
|
start = &iface_opt_family_only.pif_parser;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
start = &cloneterm.pt_parser;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
start = &no_cmds.pt_parser;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (start != &no_cmds.pt_parser &&
|
|
|
|
start != &opt_family_only.pb_parser)
|
|
|
|
start = &iface_only.pif_parser;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-03-17 06:08:46 +03:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1997-03-28 01:50:09 +03:00
|
|
|
/*
|
|
|
|
* -l means "list all interfaces", and is mutally exclusive with
|
|
|
|
* all other flags/commands.
|
|
|
|
*
|
2000-07-20 22:42:02 +04:00
|
|
|
* -C means "list all names of cloners", and it mutually exclusive
|
|
|
|
* with all other flags/commands.
|
|
|
|
*
|
1997-03-28 01:50:09 +03:00
|
|
|
* -a means "print status of all interfaces".
|
|
|
|
*/
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
if ((lflag || Cflag) && (aflag || get_flag('m') || vflag || zflag))
|
1999-07-03 21:31:15 +04:00
|
|
|
usage();
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
if ((lflag || Cflag) && get_flag('L'))
|
1997-03-28 01:50:09 +03:00
|
|
|
usage();
|
2000-07-20 22:42:02 +04:00
|
|
|
if (lflag && Cflag)
|
|
|
|
usage();
|
1997-03-17 06:08:46 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
nmatch = __arraycount(match);
|
|
|
|
|
|
|
|
rc = parse(argc, argv, start, match, &nmatch, &narg);
|
|
|
|
if (rc != 0)
|
1997-03-17 06:08:46 +03:00
|
|
|
usage();
|
|
|
|
|
2008-07-16 01:27:58 +04:00
|
|
|
if ((oenv = prop_dictionary_create()) == NULL)
|
2008-05-06 08:33:42 +04:00
|
|
|
err(EXIT_FAILURE, "%s: prop_dictionary_create", __func__);
|
2000-07-02 04:28:00 +04:00
|
|
|
|
2008-07-16 01:27:58 +04:00
|
|
|
if (matches_exec(match, oenv, nmatch) == -1)
|
2008-05-06 08:33:42 +04:00
|
|
|
err(EXIT_FAILURE, "exec_matches");
|
1997-03-17 06:08:46 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
argc -= narg;
|
|
|
|
argv += narg;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
env = (nmatch > 0) ? match[(int)nmatch - 1].m_env : NULL;
|
|
|
|
if (env == NULL)
|
2008-07-16 01:27:58 +04:00
|
|
|
env = oenv;
|
2008-05-06 08:33:42 +04:00
|
|
|
else
|
2008-07-16 01:27:58 +04:00
|
|
|
env = prop_dictionary_augment(env, oenv);
|
1997-03-17 06:08:46 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
/* Process any media commands that may have been issued. */
|
|
|
|
process_media_commands(env);
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
if ((af = getaf(env)) == -1)
|
2008-05-06 08:33:42 +04:00
|
|
|
af = AF_INET;
|
1999-07-03 21:31:15 +04:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if ((s = getsock(af)) == -1)
|
|
|
|
err(EXIT_FAILURE, "%s: getsock", __func__);
|
1997-03-17 06:08:46 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if ((ifname = getifname(env)) == NULL)
|
|
|
|
err(EXIT_FAILURE, "%s: getifname", __func__);
|
1999-05-17 20:00:05 +04:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if ((afp = lookup_af_bynum(af)) == NULL)
|
|
|
|
errx(EXIT_FAILURE, "%s: lookup_af_bynum", __func__);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
assert(afp->af_addr_commit != NULL);
|
2008-07-16 01:27:58 +04:00
|
|
|
(*afp->af_addr_commit)(env, oenv);
|
2000-04-20 06:08:55 +04:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
do_setifpreference(env);
|
2008-05-08 03:55:06 +04:00
|
|
|
do_setifcaps(env);
|
2001-06-02 20:17:06 +04:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
exit(EXIT_SUCCESS);
|
1997-03-17 06:08:46 +03:00
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static void
|
|
|
|
init_afs(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const struct afswtch *afp;
|
|
|
|
struct kwinst kw = {.k_type = KW_T_INT};
|
|
|
|
|
|
|
|
SIMPLEQ_FOREACH(afp, &aflist, af_next) {
|
|
|
|
kw.k_word = afp->af_name;
|
|
|
|
kw.k_int = afp->af_af;
|
|
|
|
for (i = 0; i < __arraycount(familykw); i++) {
|
|
|
|
if (familykw[i].k_word == NULL) {
|
|
|
|
familykw[i] = kw;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-20 02:16:55 +03:00
|
|
|
const struct afswtch *
|
2005-03-20 01:57:06 +03:00
|
|
|
lookup_af_bynum(int afnum)
|
|
|
|
{
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
const struct afswtch *afp;
|
2005-03-20 01:57:06 +03:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
SIMPLEQ_FOREACH(afp, &aflist, af_next) {
|
|
|
|
if (afp->af_af == afnum)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return afp;
|
2005-03-20 01:57:06 +03:00
|
|
|
}
|
|
|
|
|
1994-09-23 05:38:45 +04:00
|
|
|
void
|
2008-05-06 08:33:42 +04:00
|
|
|
printall(const char *ifname, prop_dictionary_t env0)
|
1993-05-04 13:26:52 +04:00
|
|
|
{
|
2000-04-13 11:39:57 +04:00
|
|
|
struct ifaddrs *ifap, *ifa;
|
2008-05-06 08:33:42 +04:00
|
|
|
struct ifreq ifr;
|
2001-01-08 17:06:12 +03:00
|
|
|
const struct sockaddr_dl *sdl = NULL;
|
2008-05-06 21:29:04 +04:00
|
|
|
prop_dictionary_t env, oenv;
|
2000-04-13 11:39:57 +04:00
|
|
|
int idx;
|
|
|
|
char *p;
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if (env0 == NULL)
|
|
|
|
env = prop_dictionary_create();
|
|
|
|
else
|
|
|
|
env = prop_dictionary_copy_mutable(env0);
|
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
oenv = prop_dictionary_create();
|
|
|
|
|
|
|
|
if (env == NULL || oenv == NULL)
|
2008-05-06 08:33:42 +04:00
|
|
|
errx(EXIT_FAILURE, "%s: prop_dictionary_copy/create", __func__);
|
|
|
|
|
2000-04-13 11:39:57 +04:00
|
|
|
if (getifaddrs(&ifap) != 0)
|
2001-10-25 02:10:15 +04:00
|
|
|
err(EXIT_FAILURE, "getifaddrs");
|
2000-04-13 11:39:57 +04:00
|
|
|
p = NULL;
|
|
|
|
idx = 0;
|
|
|
|
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
2008-05-06 08:33:42 +04:00
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
|
|
estrlcpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name));
|
|
|
|
if (sizeof(ifr.ifr_addr) >= ifa->ifa_addr->sa_len) {
|
|
|
|
memcpy(&ifr.ifr_addr, ifa->ifa_addr,
|
2000-04-13 11:39:57 +04:00
|
|
|
ifa->ifa_addr->sa_len);
|
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if (ifname != NULL && strcmp(ifname, ifa->ifa_name) != 0)
|
2001-04-28 08:11:10 +04:00
|
|
|
continue;
|
2000-04-13 11:39:57 +04:00
|
|
|
if (ifa->ifa_addr->sa_family == AF_LINK)
|
|
|
|
sdl = (const struct sockaddr_dl *) ifa->ifa_addr;
|
|
|
|
if (p && strcmp(p, ifa->ifa_name) == 0)
|
|
|
|
continue;
|
2008-05-06 21:29:04 +04:00
|
|
|
if (!prop_dictionary_set_cstring(env, "if", ifa->ifa_name))
|
2004-02-28 00:36:17 +03:00
|
|
|
continue;
|
2000-04-13 11:39:57 +04:00
|
|
|
p = ifa->ifa_name;
|
|
|
|
|
2003-05-17 04:48:13 +04:00
|
|
|
if (bflag && (ifa->ifa_flags & IFF_BROADCAST) == 0)
|
2000-04-13 11:39:57 +04:00
|
|
|
continue;
|
|
|
|
if (dflag && (ifa->ifa_flags & IFF_UP) != 0)
|
|
|
|
continue;
|
|
|
|
if (uflag && (ifa->ifa_flags & IFF_UP) == 0)
|
|
|
|
continue;
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if (sflag && carrier(env))
|
2000-04-13 11:39:57 +04:00
|
|
|
continue;
|
|
|
|
idx++;
|
|
|
|
/*
|
|
|
|
* Are we just listing the interfaces?
|
|
|
|
*/
|
|
|
|
if (lflag) {
|
|
|
|
if (idx > 1)
|
2004-11-11 23:37:18 +03:00
|
|
|
printf(" ");
|
2008-05-06 08:33:42 +04:00
|
|
|
fputs(ifa->ifa_name, stdout);
|
2000-04-13 11:39:57 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
status(sdl, env, oenv);
|
2001-10-06 21:05:29 +04:00
|
|
|
sdl = NULL;
|
2000-04-13 11:39:57 +04:00
|
|
|
}
|
|
|
|
if (lflag)
|
2004-11-11 23:37:18 +03:00
|
|
|
printf("\n");
|
2008-05-06 08:33:42 +04:00
|
|
|
prop_object_release((prop_object_t)env);
|
2008-05-06 21:29:04 +04:00
|
|
|
prop_object_release((prop_object_t)oenv);
|
2000-04-13 11:39:57 +04:00
|
|
|
freeifaddrs(ifap);
|
1993-05-04 13:26:52 +04:00
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static int
|
2008-05-06 08:33:42 +04:00
|
|
|
list_cloners(prop_dictionary_t env, prop_dictionary_t oenv)
|
2000-07-20 22:42:02 +04:00
|
|
|
{
|
|
|
|
struct if_clonereq ifcr;
|
|
|
|
char *cp, *buf;
|
2008-05-06 08:33:42 +04:00
|
|
|
int idx, s;
|
2000-07-20 22:42:02 +04:00
|
|
|
|
|
|
|
memset(&ifcr, 0, sizeof(ifcr));
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
s = getsock(AF_INET);
|
2000-07-20 22:42:02 +04:00
|
|
|
|
2001-10-25 02:10:15 +04:00
|
|
|
if (ioctl(s, SIOCIFGCLONERS, &ifcr) == -1)
|
|
|
|
err(EXIT_FAILURE, "SIOCIFGCLONERS for count");
|
2000-07-20 22:42:02 +04:00
|
|
|
|
|
|
|
buf = malloc(ifcr.ifcr_total * IFNAMSIZ);
|
|
|
|
if (buf == NULL)
|
2001-10-25 02:10:15 +04:00
|
|
|
err(EXIT_FAILURE, "unable to allocate cloner name buffer");
|
2000-07-20 22:42:02 +04:00
|
|
|
|
|
|
|
ifcr.ifcr_count = ifcr.ifcr_total;
|
|
|
|
ifcr.ifcr_buffer = buf;
|
|
|
|
|
2001-10-25 02:10:15 +04:00
|
|
|
if (ioctl(s, SIOCIFGCLONERS, &ifcr) == -1)
|
|
|
|
err(EXIT_FAILURE, "SIOCIFGCLONERS for names");
|
2000-07-20 22:42:02 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
2004-11-11 23:37:18 +03:00
|
|
|
printf(" ");
|
2000-07-20 22:42:02 +04:00
|
|
|
printf("%s", cp);
|
|
|
|
}
|
|
|
|
|
2004-11-11 23:37:18 +03:00
|
|
|
printf("\n");
|
2000-07-20 22:42:02 +04:00
|
|
|
free(buf);
|
2008-05-06 08:33:42 +04:00
|
|
|
exit(EXIT_SUCCESS);
|
2000-07-20 22:42:02 +04:00
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
static int
|
2008-07-16 01:27:58 +04:00
|
|
|
clone_command(prop_dictionary_t env, prop_dictionary_t oenv)
|
2000-07-02 04:28:00 +04:00
|
|
|
{
|
2008-05-06 20:15:17 +04:00
|
|
|
int64_t cmd;
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-06 20:15:17 +04:00
|
|
|
if (!prop_dictionary_get_int64(env, "clonecmd", &cmd)) {
|
2008-05-06 08:33:42 +04:00
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-05-08 03:55:06 +04:00
|
|
|
if (indirect_ioctl(env, (unsigned long)cmd, NULL) == -1) {
|
2008-05-06 08:33:42 +04:00
|
|
|
warn("%s", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2000-07-02 04:28:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static int
|
2008-07-16 01:27:58 +04:00
|
|
|
setifaddr(prop_dictionary_t env, prop_dictionary_t oenv)
|
2000-07-02 04:28:00 +04:00
|
|
|
{
|
2008-05-06 08:33:42 +04:00
|
|
|
const struct paddr_prefix *pfx0;
|
|
|
|
struct paddr_prefix *pfx;
|
|
|
|
prop_data_t d;
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
int af;
|
2008-05-06 08:33:42 +04:00
|
|
|
|
|
|
|
if ((af = getaf(env)) == -1)
|
|
|
|
af = AF_INET;
|
|
|
|
|
|
|
|
d = (prop_data_t)prop_dictionary_get(env, "address");
|
|
|
|
assert(d != NULL);
|
|
|
|
pfx0 = prop_data_data_nocopy(d);
|
|
|
|
|
2008-05-07 22:08:30 +04:00
|
|
|
if (pfx0->pfx_len >= 0) {
|
2008-05-06 08:33:42 +04:00
|
|
|
pfx = prefixlen_to_mask(af, pfx0->pfx_len);
|
|
|
|
if (pfx == NULL)
|
|
|
|
err(EXIT_FAILURE, "prefixlen_to_mask");
|
|
|
|
free(pfx);
|
|
|
|
}
|
2000-07-02 04:28:00 +04:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static int
|
2008-07-16 01:27:58 +04:00
|
|
|
setifnetmask(prop_dictionary_t env, prop_dictionary_t oenv)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2008-05-06 08:33:42 +04:00
|
|
|
const struct paddr_prefix *pfx;
|
|
|
|
prop_data_t d;
|
|
|
|
|
|
|
|
d = (prop_data_t)prop_dictionary_get(env, "dstormask");
|
|
|
|
assert(d != NULL);
|
|
|
|
pfx = prop_data_data_nocopy(d);
|
|
|
|
|
2008-07-16 01:27:58 +04:00
|
|
|
if (!prop_dictionary_set(oenv, "netmask", (prop_object_t)d))
|
2008-05-06 08:33:42 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static int
|
2008-07-16 01:27:58 +04:00
|
|
|
setifbroadaddr(prop_dictionary_t env, prop_dictionary_t oenv)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2008-05-06 08:33:42 +04:00
|
|
|
const struct paddr_prefix *pfx;
|
|
|
|
prop_data_t d;
|
|
|
|
unsigned short flags;
|
|
|
|
|
2008-07-16 01:27:58 +04:00
|
|
|
if (getifflags(env, oenv, &flags) == -1)
|
2008-05-06 08:33:42 +04:00
|
|
|
err(EXIT_FAILURE, "%s: getifflags", __func__);
|
|
|
|
|
|
|
|
if ((flags & IFF_BROADCAST) == 0)
|
|
|
|
errx(EXIT_FAILURE, "not a broadcast interface");
|
|
|
|
|
|
|
|
d = (prop_data_t)prop_dictionary_get(env, "broadcast");
|
|
|
|
assert(d != NULL);
|
|
|
|
pfx = prop_data_data_nocopy(d);
|
|
|
|
|
2008-07-16 01:27:58 +04:00
|
|
|
if (!prop_dictionary_set(oenv, "broadcast", (prop_object_t)d))
|
2008-05-06 08:33:42 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-09-23 05:38:45 +04:00
|
|
|
/*ARGSUSED*/
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static int
|
2008-07-16 01:27:58 +04:00
|
|
|
notrailers(prop_dictionary_t env, prop_dictionary_t oenv)
|
1994-09-23 05:38:45 +04:00
|
|
|
{
|
1997-04-21 05:17:57 +04:00
|
|
|
puts("Note: trailers are no longer sent, but always received");
|
2008-05-06 08:33:42 +04:00
|
|
|
return 0;
|
1994-09-23 05:38:45 +04:00
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*ARGSUSED*/
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static int
|
2008-07-16 01:27:58 +04:00
|
|
|
setifdstormask(prop_dictionary_t env, prop_dictionary_t oenv)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2008-05-06 08:33:42 +04:00
|
|
|
const char *key;
|
|
|
|
const struct paddr_prefix *pfx;
|
|
|
|
prop_data_t d;
|
|
|
|
unsigned short flags;
|
|
|
|
|
2008-07-16 01:27:58 +04:00
|
|
|
if (getifflags(env, oenv, &flags) == -1)
|
2008-05-06 08:33:42 +04:00
|
|
|
err(EXIT_FAILURE, "%s: getifflags", __func__);
|
|
|
|
|
|
|
|
d = (prop_data_t)prop_dictionary_get(env, "dstormask");
|
|
|
|
assert(d != NULL);
|
|
|
|
pfx = prop_data_data_nocopy(d);
|
|
|
|
|
|
|
|
if ((flags & IFF_BROADCAST) == 0) {
|
|
|
|
key = "dst";
|
|
|
|
} else {
|
|
|
|
key = "netmask";
|
|
|
|
}
|
|
|
|
|
2008-07-16 01:27:58 +04:00
|
|
|
if (!prop_dictionary_set(oenv, key, (prop_object_t)d))
|
2008-05-06 08:33:42 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static int
|
2008-07-16 01:27:58 +04:00
|
|
|
setifflags(prop_dictionary_t env, prop_dictionary_t oenv)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2008-05-08 03:55:06 +04:00
|
|
|
struct ifreq ifr;
|
2008-05-06 21:29:04 +04:00
|
|
|
int64_t ifflag;
|
|
|
|
bool rc;
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
rc = prop_dictionary_get_int64(env, "ifflag", &ifflag);
|
|
|
|
assert(rc);
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-08 03:55:06 +04:00
|
|
|
if (direct_ioctl(env, SIOCGIFFLAGS, &ifr) == -1)
|
2008-05-06 08:33:42 +04:00
|
|
|
return -1;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if (ifflag < 0) {
|
|
|
|
ifflag = -ifflag;
|
2008-05-08 03:55:06 +04:00
|
|
|
ifr.ifr_flags &= ~ifflag;
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
2008-05-08 03:55:06 +04:00
|
|
|
ifr.ifr_flags |= ifflag;
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-08 03:55:06 +04:00
|
|
|
if (direct_ioctl(env, SIOCSIFFLAGS, &ifr) == -1)
|
2008-05-06 08:33:42 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
static int
|
|
|
|
getifcaps(prop_dictionary_t env, prop_dictionary_t oenv, struct ifcapreq *oifcr)
|
2001-06-02 20:17:06 +04:00
|
|
|
{
|
2008-05-06 08:33:42 +04:00
|
|
|
bool rc;
|
|
|
|
struct ifcapreq ifcr;
|
|
|
|
const struct ifcapreq *tmpifcr;
|
|
|
|
prop_data_t capdata;
|
2001-06-02 20:17:06 +04:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
capdata = (prop_data_t)prop_dictionary_get(env, "ifcaps");
|
2001-06-02 20:17:06 +04:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if (capdata != NULL) {
|
|
|
|
tmpifcr = prop_data_data_nocopy(capdata);
|
|
|
|
*oifcr = *tmpifcr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-08 03:55:06 +04:00
|
|
|
(void)direct_ioctl(env, SIOCGIFCAP, &ifcr);
|
2008-05-06 08:33:42 +04:00
|
|
|
*oifcr = ifcr;
|
|
|
|
|
|
|
|
capdata = prop_data_create_data(&ifcr, sizeof(ifcr));
|
|
|
|
|
|
|
|
rc = prop_dictionary_set(oenv, "ifcaps", capdata);
|
|
|
|
|
|
|
|
prop_object_release((prop_object_t)capdata);
|
|
|
|
|
2008-05-06 22:09:50 +04:00
|
|
|
return rc ? 0 : -1;
|
2001-06-02 20:17:06 +04:00
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
static int
|
|
|
|
setifcaps(prop_dictionary_t env, prop_dictionary_t oenv)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2008-05-06 21:29:04 +04:00
|
|
|
int64_t ifcap;
|
|
|
|
int s;
|
|
|
|
bool rc;
|
2008-05-06 08:33:42 +04:00
|
|
|
prop_data_t capdata;
|
|
|
|
struct ifcapreq ifcr;
|
|
|
|
|
|
|
|
s = getsock(AF_INET);
|
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
rc = prop_dictionary_get_int64(env, "ifcap", &ifcap);
|
|
|
|
assert(rc);
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if (getifcaps(env, oenv, &ifcr) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (ifcap < 0) {
|
|
|
|
ifcap = -ifcap;
|
|
|
|
ifcr.ifcr_capenable &= ~ifcap;
|
|
|
|
} else
|
|
|
|
ifcr.ifcr_capenable |= ifcap;
|
2002-06-14 05:04:41 +04:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if ((capdata = prop_data_create_data(&ifcr, sizeof(ifcr))) == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2008-05-06 22:16:34 +04:00
|
|
|
rc = prop_dictionary_set(oenv, "ifcaps", capdata);
|
2008-05-06 22:09:50 +04:00
|
|
|
prop_object_release((prop_object_t)capdata);
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-06 22:09:50 +04:00
|
|
|
return rc ? 0 : -1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
static int
|
2008-07-16 01:27:58 +04:00
|
|
|
setifmetric(prop_dictionary_t env, prop_dictionary_t oenv)
|
2006-11-13 08:13:38 +03:00
|
|
|
{
|
2008-05-06 08:33:42 +04:00
|
|
|
struct ifreq ifr;
|
2008-05-06 21:29:04 +04:00
|
|
|
bool rc;
|
|
|
|
int64_t metric;
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
rc = prop_dictionary_get_int64(env, "metric", &metric);
|
|
|
|
assert(rc);
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
ifr.ifr_metric = metric;
|
2008-05-08 03:55:06 +04:00
|
|
|
if (direct_ioctl(env, SIOCSIFMETRIC, &ifr) == -1)
|
2008-05-06 08:33:42 +04:00
|
|
|
warn("SIOCSIFMETRIC");
|
|
|
|
return 0;
|
2006-11-13 08:13:38 +03:00
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
static void
|
|
|
|
do_setifpreference(prop_dictionary_t env)
|
2006-11-13 08:13:38 +03:00
|
|
|
{
|
|
|
|
struct if_addrprefreq ifap;
|
2008-05-06 08:33:42 +04:00
|
|
|
prop_data_t d;
|
|
|
|
const struct paddr_prefix *pfx;
|
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
memset(&ifap, 0, sizeof(ifap));
|
|
|
|
|
|
|
|
if (!prop_dictionary_get_int16(env, "preference",
|
|
|
|
&ifap.ifap_preference))
|
2008-05-06 08:33:42 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
d = (prop_data_t)prop_dictionary_get(env, "address");
|
|
|
|
assert(d != NULL);
|
2008-05-06 21:29:04 +04:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
pfx = prop_data_data_nocopy(d);
|
|
|
|
|
|
|
|
memcpy(&ifap.ifap_addr, &pfx->pfx_addr,
|
|
|
|
MIN(sizeof(ifap.ifap_addr), pfx->pfx_addr.sa_len));
|
2008-05-08 03:55:06 +04:00
|
|
|
if (direct_ioctl(env, SIOCSIFADDRPREF, &ifap) == -1)
|
2006-11-13 08:13:38 +03:00
|
|
|
warn("SIOCSIFADDRPREF");
|
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
static int
|
2008-07-16 01:27:58 +04:00
|
|
|
setifmtu(prop_dictionary_t env, prop_dictionary_t oenv)
|
1997-04-10 23:10:16 +04:00
|
|
|
{
|
2008-05-06 21:29:04 +04:00
|
|
|
int64_t mtu;
|
|
|
|
bool rc;
|
2008-05-06 08:33:42 +04:00
|
|
|
struct ifreq ifr;
|
2000-07-21 08:53:03 +04:00
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
rc = prop_dictionary_get_int64(env, "mtu", &mtu);
|
|
|
|
assert(rc);
|
2000-07-21 08:53:03 +04:00
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
ifr.ifr_mtu = mtu;
|
2008-05-08 03:55:06 +04:00
|
|
|
if (direct_ioctl(env, SIOCSIFMTU, &ifr) == -1)
|
2008-05-06 08:33:42 +04:00
|
|
|
warn("SIOCSIFMTU");
|
|
|
|
|
|
|
|
return 0;
|
2000-07-21 08:53:03 +04:00
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static int
|
2008-05-06 08:33:42 +04:00
|
|
|
carrier(prop_dictionary_t env)
|
1999-07-03 21:31:15 +04:00
|
|
|
{
|
|
|
|
struct ifmediareq ifmr;
|
|
|
|
|
2008-05-08 03:55:06 +04:00
|
|
|
memset(&ifmr, 0, sizeof(ifmr));
|
1999-07-03 21:31:15 +04:00
|
|
|
|
2008-05-08 03:55:06 +04:00
|
|
|
if (direct_ioctl(env, SIOCGIFMEDIA, &ifmr) == -1) {
|
1999-07-03 21:31:15 +04:00
|
|
|
/*
|
|
|
|
* Interface doesn't support SIOC{G,S}IFMEDIA;
|
|
|
|
* assume ok.
|
|
|
|
*/
|
2008-05-06 08:33:42 +04:00
|
|
|
return EXIT_SUCCESS;
|
1999-07-03 21:31:15 +04:00
|
|
|
}
|
|
|
|
if ((ifmr.ifm_status & IFM_AVALID) == 0) {
|
|
|
|
/*
|
|
|
|
* Interface doesn't report media-valid status.
|
|
|
|
* assume ok.
|
|
|
|
*/
|
2008-05-06 08:33:42 +04:00
|
|
|
return EXIT_SUCCESS;
|
1999-07-03 21:31:15 +04:00
|
|
|
}
|
|
|
|
/* otherwise, return ok for active, not-ok if not active. */
|
2008-05-06 08:33:42 +04:00
|
|
|
if (ifmr.ifm_status & IFM_ACTIVE)
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
else
|
|
|
|
return EXIT_FAILURE;
|
1999-07-03 21:31:15 +04:00
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static void
|
|
|
|
print_plural(const char *prefix, uint64_t n, const char *unit)
|
|
|
|
{
|
|
|
|
printf("%s%" PRIu64 " %s%s", prefix, n, unit, (n == 1) ? "" : "s");
|
|
|
|
}
|
2000-01-25 03:59:39 +03:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static void
|
|
|
|
print_human_bytes(bool humanize, uint64_t n)
|
|
|
|
{
|
|
|
|
char buf[5];
|
|
|
|
|
|
|
|
if (humanize) {
|
|
|
|
(void)humanize_number(buf, sizeof(buf),
|
|
|
|
(int64_t)n, "", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL);
|
|
|
|
printf(", %s byte%s", buf, (atof(buf) == 1.0) ? "" : "s");
|
|
|
|
} else
|
|
|
|
print_plural(", ", n, "byte");
|
|
|
|
}
|
2000-01-25 03:59:39 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Print the status of the interface. If an address family was
|
|
|
|
* specified, show it and it only; otherwise, show them all.
|
|
|
|
*/
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
2008-05-06 21:29:04 +04:00
|
|
|
status(const struct sockaddr_dl *sdl, prop_dictionary_t env,
|
|
|
|
prop_dictionary_t oenv)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
const struct if_data *ifi;
|
|
|
|
status_func_t *status_f;
|
|
|
|
statistics_func_t *statistics_f;
|
2002-05-24 01:38:01 +04:00
|
|
|
struct ifdatareq ifdr;
|
2008-05-06 08:33:42 +04:00
|
|
|
struct ifreq ifr;
|
2001-10-06 21:05:29 +04:00
|
|
|
char hbuf[NI_MAXHOST];
|
2002-09-21 01:21:53 +04:00
|
|
|
char fbuf[BUFSIZ];
|
2008-05-06 08:33:42 +04:00
|
|
|
int af, s;
|
|
|
|
const char *ifname;
|
|
|
|
struct ifcapreq ifcr;
|
|
|
|
unsigned short flags;
|
|
|
|
const struct afswtch *afp;
|
|
|
|
|
2008-05-06 20:15:17 +04:00
|
|
|
if ((af = getaf(env)) == -1) {
|
|
|
|
afp = NULL;
|
|
|
|
af = AF_UNSPEC;
|
|
|
|
} else
|
|
|
|
afp = lookup_af_bynum(af);
|
|
|
|
|
2008-05-08 03:55:06 +04:00
|
|
|
/* get out early if the family is unsupported by the kernel */
|
2008-05-06 20:15:17 +04:00
|
|
|
if ((s = getsock(af)) == -1)
|
2008-05-06 08:33:42 +04:00
|
|
|
err(EXIT_FAILURE, "%s: getsock", __func__);
|
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
if ((ifname = getifinfo(env, oenv, &flags)) == NULL)
|
2008-05-06 08:33:42 +04:00
|
|
|
err(EXIT_FAILURE, "%s: getifinfo", __func__);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2002-09-21 01:21:53 +04:00
|
|
|
(void)snprintb(fbuf, sizeof(fbuf), IFFBITS, flags);
|
2008-05-06 08:33:42 +04:00
|
|
|
printf("%s: flags=%s", ifname, &fbuf[2]);
|
|
|
|
|
|
|
|
estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
|
|
|
if (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)
|
|
|
|
printf(" mtu %d", ifr.ifr_mtu);
|
2004-11-11 23:37:18 +03:00
|
|
|
printf("\n");
|
2000-01-25 04:46:57 +03:00
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
if (getifcaps(env, oenv, &ifcr) == -1)
|
2008-05-06 08:33:42 +04:00
|
|
|
err(EXIT_FAILURE, "%s: getifcaps", __func__);
|
|
|
|
|
|
|
|
if (ifcr.ifcr_capabilities != 0) {
|
2002-09-21 01:21:53 +04:00
|
|
|
(void)snprintb(fbuf, sizeof(fbuf), IFCAPBITS,
|
2008-05-06 08:33:42 +04:00
|
|
|
ifcr.ifcr_capabilities);
|
2002-09-21 01:21:53 +04:00
|
|
|
printf("\tcapabilities=%s\n", &fbuf[2]);
|
|
|
|
(void)snprintb(fbuf, sizeof(fbuf), IFCAPBITS,
|
2008-05-06 08:33:42 +04:00
|
|
|
ifcr.ifcr_capenable);
|
2002-09-21 01:21:53 +04:00
|
|
|
printf("\tenabled=%s\n", &fbuf[2]);
|
2001-06-02 20:17:06 +04:00
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
SIMPLEQ_FOREACH(status_f, &status_funcs, f_next)
|
|
|
|
(*status_f->f_func)(env, oenv);
|
2000-01-25 04:46:57 +03:00
|
|
|
|
2001-10-06 21:05:29 +04:00
|
|
|
if (sdl != NULL &&
|
2005-01-20 19:16:10 +03:00
|
|
|
getnameinfo((const struct sockaddr *)sdl, sdl->sdl_len,
|
2001-10-06 21:05:29 +04:00
|
|
|
hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) == 0 &&
|
|
|
|
hbuf[0] != '\0')
|
|
|
|
printf("\taddress: %s\n", hbuf);
|
1997-03-17 06:08:46 +03:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
media_status(env, oenv);
|
1997-03-17 06:08:46 +03:00
|
|
|
|
2003-04-12 05:07:43 +04:00
|
|
|
if (!vflag && !zflag)
|
2002-05-24 01:38:01 +04:00
|
|
|
goto proto_status;
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
estrlcpy(ifdr.ifdr_name, ifname, sizeof(ifdr.ifdr_name));
|
2002-05-24 01:38:01 +04:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
if (ioctl(s, zflag ? SIOCZIFDATA:SIOCGIFDATA, &ifdr) == -1)
|
2003-04-12 05:07:43 +04:00
|
|
|
err(EXIT_FAILURE, zflag ? "SIOCZIFDATA" : "SIOCGIFDATA");
|
2002-05-24 01:38:01 +04:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
ifi = &ifdr.ifdr_data;
|
|
|
|
|
|
|
|
print_plural("\tinput: ", ifi->ifi_ipackets, "packet");
|
|
|
|
print_human_bytes(hflag, ifi->ifi_ibytes);
|
|
|
|
if (ifi->ifi_imcasts)
|
|
|
|
print_plural(", ", ifi->ifi_imcasts, "multicast");
|
|
|
|
if (ifi->ifi_ierrors)
|
|
|
|
print_plural(", ", ifi->ifi_ierrors, "error");
|
|
|
|
if (ifi->ifi_iqdrops)
|
|
|
|
print_plural(", ", ifi->ifi_iqdrops, "queue drop");
|
|
|
|
if (ifi->ifi_noproto)
|
|
|
|
printf(", %" PRIu64 " unknown protocol", ifi->ifi_noproto);
|
|
|
|
print_plural("\n\toutput: ", ifi->ifi_opackets, "packet");
|
|
|
|
print_human_bytes(hflag, ifi->ifi_obytes);
|
|
|
|
if (ifi->ifi_omcasts)
|
|
|
|
print_plural(", ", ifi->ifi_omcasts, "multicast");
|
|
|
|
if (ifi->ifi_oerrors)
|
|
|
|
print_plural(", ", ifi->ifi_oerrors, "error");
|
|
|
|
if (ifi->ifi_collisions)
|
|
|
|
print_plural(", ", ifi->ifi_collisions, "collision");
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
SIMPLEQ_FOREACH(statistics_f, &statistics_funcs, f_next)
|
|
|
|
(*statistics_f->f_func)(env);
|
2004-12-21 02:04:55 +03:00
|
|
|
|
1997-03-17 06:08:46 +03:00
|
|
|
proto_status:
|
2008-05-06 08:33:42 +04:00
|
|
|
|
|
|
|
if (afp != NULL)
|
2008-05-06 21:29:04 +04:00
|
|
|
(*afp->af_status)(env, oenv, true);
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
else SIMPLEQ_FOREACH(afp, &aflist, af_next)
|
2008-05-06 21:29:04 +04:00
|
|
|
(*afp->af_status)(env, oenv, false);
|
1998-09-06 21:51:32 +04:00
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static int
|
2008-07-16 01:27:58 +04:00
|
|
|
setifprefixlen(prop_dictionary_t env, prop_dictionary_t oenv)
|
1999-07-01 17:19:20 +04:00
|
|
|
{
|
2008-05-06 21:29:04 +04:00
|
|
|
bool rc;
|
|
|
|
int64_t plen;
|
2008-05-06 08:33:42 +04:00
|
|
|
int af;
|
|
|
|
struct paddr_prefix *pfx;
|
|
|
|
prop_data_t d;
|
|
|
|
|
|
|
|
if ((af = getaf(env)) == -1)
|
|
|
|
af = AF_INET;
|
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
rc = prop_dictionary_get_int64(env, "prefixlen", &plen);
|
|
|
|
assert(rc);
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-06 21:29:04 +04:00
|
|
|
pfx = prefixlen_to_mask(af, plen);
|
2008-05-06 08:33:42 +04:00
|
|
|
if (pfx == NULL)
|
|
|
|
err(EXIT_FAILURE, "prefixlen_to_mask");
|
|
|
|
|
2008-08-02 02:29:13 +04:00
|
|
|
d = prop_data_create_data(pfx, paddr_prefix_size(pfx));
|
2008-05-06 08:33:42 +04:00
|
|
|
if (d == NULL)
|
|
|
|
err(EXIT_FAILURE, "%s: prop_data_create_data", __func__);
|
|
|
|
|
2008-07-16 01:27:58 +04:00
|
|
|
if (!prop_dictionary_set(oenv, "netmask", (prop_object_t)d))
|
2008-05-06 08:33:42 +04:00
|
|
|
err(EXIT_FAILURE, "%s: prop_dictionary_set", __func__);
|
|
|
|
|
|
|
|
free(pfx);
|
|
|
|
return 0;
|
1999-07-01 17:19:20 +04:00
|
|
|
}
|
|
|
|
|
2008-07-16 01:19:24 +04:00
|
|
|
static void
|
2004-10-12 00:13:37 +04:00
|
|
|
usage(void)
|
1995-01-22 00:22:16 +03:00
|
|
|
{
|
2001-02-20 01:48:57 +03:00
|
|
|
const char *progname = getprogname();
|
2008-07-16 00:56:13 +04:00
|
|
|
usage_func_t *usage_f;
|
|
|
|
prop_dictionary_t env;
|
2000-06-30 21:45:11 +04:00
|
|
|
|
2008-07-16 00:56:13 +04:00
|
|
|
if ((env = prop_dictionary_create()) == NULL)
|
|
|
|
err(EXIT_FAILURE, "%s: prop_dictionary_create", __func__);
|
|
|
|
|
|
|
|
fprintf(stderr, "usage: %s [-h] %s[-v] [-z] %sinterface\n"
|
2001-04-27 13:10:04 +04:00
|
|
|
"\t[ af [ address [ dest_addr ] ] [ netmask mask ] [ prefixlen n ]\n"
|
|
|
|
"\t\t[ alias | -alias ] ]\n"
|
2008-07-16 00:56:13 +04:00
|
|
|
"\t[ up ] [ down ] [ metric n ] [ mtu n ]\n", progname,
|
|
|
|
flag_is_registered(gflags, 'm') ? "[-m] " : "",
|
|
|
|
flag_is_registered(gflags, 'L') ? "[-L] " : "");
|
|
|
|
|
|
|
|
SIMPLEQ_FOREACH(usage_f, &usage_funcs, f_next)
|
|
|
|
(*usage_f->f_func)(env);
|
|
|
|
|
|
|
|
fprintf(stderr,
|
2000-06-30 21:45:11 +04:00
|
|
|
"\t[ arp | -arp ]\n"
|
2006-11-13 08:13:38 +03:00
|
|
|
"\t[ preference n ]\n"
|
2000-06-30 21:45:11 +04:00
|
|
|
"\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n"
|
2008-07-16 00:56:13 +04:00
|
|
|
" %s -a [-b] [-d] [-h] %s[-u] [-v] [-z] [ af ]\n"
|
|
|
|
" %s -l [-b] [-d] [-s] [-u]\n"
|
2001-02-23 22:49:54 +03:00
|
|
|
" %s -C\n"
|
2000-07-02 04:28:00 +04:00
|
|
|
" %s interface create\n"
|
|
|
|
" %s interface destroy\n",
|
2008-07-16 00:56:13 +04:00
|
|
|
progname, flag_is_registered(gflags, 'm') ? "[-m] " : "",
|
|
|
|
progname, progname, progname, progname);
|
|
|
|
|
|
|
|
prop_object_release((prop_object_t)env);
|
2008-05-06 08:33:42 +04:00
|
|
|
exit(EXIT_FAILURE);
|
1995-01-22 00:22:16 +03:00
|
|
|
}
|