2019-08-16 13:33:17 +03:00
|
|
|
/* $NetBSD: af_link.c,v 1.8 2019/08/16 10:33:17 msaitoh Exp $ */
|
2008-05-13 02:06:13 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2008 David Young. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2019-08-16 13:33:17 +03:00
|
|
|
__RCSID("$NetBSD: af_link.c,v 1.8 2019/08/16 10:33:17 msaitoh Exp $");
|
2008-05-13 02:06:13 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
2019-08-16 13:33:17 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
2008-05-13 02:06:13 +04:00
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2019-08-16 13:33:17 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
2008-05-13 02:06:13 +04:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <util.h>
|
|
|
|
|
|
|
|
#include "env.h"
|
|
|
|
#include "extern.h"
|
|
|
|
#include "af_inetany.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
|
|
|
static void link_status(prop_dictionary_t, prop_dictionary_t, bool);
|
|
|
|
static void link_commit_address(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
|
|
|
|
static const struct kwinst linkkw[] = {
|
|
|
|
{.k_word = "active", .k_key = "active", .k_type = KW_T_BOOL,
|
|
|
|
.k_bool = true, .k_nextparser = &command_root.pb_parser}
|
|
|
|
};
|
|
|
|
|
2014-01-20 02:31:13 +04:00
|
|
|
struct pkw link_pkw = PKW_INITIALIZER(&link_pkw, "link", NULL, 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
|
|
|
linkkw, __arraycount(linkkw), NULL);
|
|
|
|
|
|
|
|
static struct afswtch af = {
|
|
|
|
.af_name = "link", .af_af = AF_LINK, .af_status = link_status,
|
|
|
|
.af_addr_commit = link_commit_address
|
|
|
|
};
|
|
|
|
|
|
|
|
static cmdloop_branch_t branch;
|
|
|
|
|
|
|
|
static void link_constructor(void) __attribute__((constructor));
|
|
|
|
|
|
|
|
static void
|
2008-05-13 02:06:13 +04:00
|
|
|
link_status(prop_dictionary_t env, prop_dictionary_t oenv, bool force)
|
|
|
|
{
|
2009-04-22 02:46:39 +04:00
|
|
|
print_link_addresses(env, false);
|
2008-05-13 02:06:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
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
|
|
|
link_pre_aifaddr(prop_dictionary_t env, const struct afparam *param)
|
2008-05-13 02:06:13 +04:00
|
|
|
{
|
|
|
|
bool active;
|
|
|
|
struct if_laddrreq *iflr = param->req.buf;
|
|
|
|
|
|
|
|
if (prop_dictionary_get_bool(env, "active", &active) && active)
|
|
|
|
iflr->flags |= IFLR_ACTIVE;
|
|
|
|
|
|
|
|
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
|
|
|
static void
|
2008-05-13 02:06:13 +04:00
|
|
|
link_commit_address(prop_dictionary_t env, prop_dictionary_t oenv)
|
|
|
|
{
|
|
|
|
struct if_laddrreq dgreq = {
|
|
|
|
.addr = {
|
|
|
|
.ss_family = AF_LINK,
|
|
|
|
.ss_len = sizeof(dgreq.addr),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
struct if_laddrreq req = {
|
|
|
|
.addr = {
|
|
|
|
.ss_family = AF_LINK,
|
|
|
|
.ss_len = sizeof(req.addr),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct afparam linkparam = {
|
|
|
|
.req = BUFPARAM(req)
|
|
|
|
, .dgreq = BUFPARAM(dgreq)
|
|
|
|
, .name = {
|
|
|
|
{.buf = dgreq.iflr_name,
|
|
|
|
.buflen = sizeof(dgreq.iflr_name)},
|
|
|
|
{.buf = req.iflr_name,
|
|
|
|
.buflen = sizeof(req.iflr_name)}
|
|
|
|
}
|
|
|
|
, .dgaddr = BUFPARAM(dgreq.addr)
|
|
|
|
, .addr = BUFPARAM(req.addr)
|
|
|
|
, .aifaddr = IFADDR_PARAM(SIOCALIFADDR)
|
|
|
|
, .difaddr = IFADDR_PARAM(SIOCDLIFADDR)
|
|
|
|
, .gifaddr = IFADDR_PARAM(0)
|
|
|
|
, .pre_aifaddr = link_pre_aifaddr
|
|
|
|
};
|
|
|
|
commit_address(env, oenv, &linkparam);
|
|
|
|
}
|
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
|
|
|
|
link_constructor(void)
|
|
|
|
{
|
|
|
|
register_family(&af);
|
2014-01-20 02:31:13 +04:00
|
|
|
cmdloop_branch_init(&branch, &link_pkw.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
|
|
|
register_cmdloop_branch(&branch);
|
|
|
|
}
|