2008-07-16 01:27:58 +04:00
|
|
|
/* $NetBSD: agr.c,v 1.15 2008/07/15 21:27:58 dyoung Exp $ */
|
2005-03-18 14:11:50 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c)2005 YAMAMOTO Takashi,
|
|
|
|
* 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>
|
|
|
|
#if !defined(lint)
|
2008-07-16 01:27:58 +04:00
|
|
|
__RCSID("$NetBSD: agr.c,v 1.15 2008/07/15 21:27:58 dyoung Exp $");
|
2005-03-18 14:11:50 +03:00
|
|
|
#endif /* !defined(lint) */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/agr/if_agrioctl.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2008-05-06 08:33:42 +04:00
|
|
|
#include <stdio.h>
|
2005-03-18 14:11:50 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <util.h>
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
#include "env.h"
|
2005-03-19 06:56:06 +03:00
|
|
|
#include "extern.h"
|
2008-05-08 03:55:06 +04:00
|
|
|
#include "parse.h"
|
|
|
|
#include "util.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 int agrsetport(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
static void agr_constructor(void) __attribute__((constructor));
|
2008-05-08 03:55:06 +04:00
|
|
|
static int checkifname(prop_dictionary_t);
|
|
|
|
static void assertifname(prop_dictionary_t);
|
2005-03-18 14:11:50 +03:00
|
|
|
|
2008-05-10 00:45:09 +04:00
|
|
|
static struct piface agrif = PIFACE_INITIALIZER(&agrif, "agr interface",
|
|
|
|
agrsetport, "agrport", &command_root.pb_parser);
|
|
|
|
|
2008-05-07 23:55:24 +04:00
|
|
|
static const struct kwinst agrkw[] = {
|
2008-05-19 22:00:31 +04:00
|
|
|
{.k_word = "agrport", .k_type = KW_T_INT, .k_int = AGRCMD_ADDPORT,
|
2008-05-10 00:45:09 +04:00
|
|
|
.k_nextparser = &agrif.pif_parser}
|
2008-05-19 22:00:31 +04:00
|
|
|
, {.k_word = "-agrport", .k_type = KW_T_INT, .k_int = AGRCMD_REMPORT,
|
2008-05-10 00:45:09 +04:00
|
|
|
.k_nextparser = &agrif.pif_parser}
|
2008-05-07 23:55:24 +04:00
|
|
|
};
|
|
|
|
|
2008-05-10 00:45:09 +04:00
|
|
|
struct pkw agr = PKW_INITIALIZER(&agr, "agr", NULL, "agrcmd",
|
2008-05-07 23:55:24 +04:00
|
|
|
agrkw, __arraycount(agrkw), NULL);
|
|
|
|
|
2005-03-18 14:11:50 +03:00
|
|
|
static int
|
2008-05-08 03:55:06 +04:00
|
|
|
checkifname(prop_dictionary_t env)
|
2005-03-18 14:11:50 +03:00
|
|
|
{
|
2008-05-08 03:55:06 +04:00
|
|
|
const char *ifname;
|
|
|
|
|
|
|
|
if ((ifname = getifname(env)) == NULL)
|
|
|
|
return 1;
|
2005-03-18 14:11:50 +03:00
|
|
|
|
2005-03-19 20:31:48 +03:00
|
|
|
return strncmp(ifname, "agr", 3) != 0 ||
|
|
|
|
!isdigit((unsigned char)ifname[3]);
|
2005-03-18 14:11:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-05-08 03:55:06 +04:00
|
|
|
assertifname(prop_dictionary_t env)
|
2005-03-18 14:11:50 +03:00
|
|
|
{
|
2008-05-08 03:55:06 +04:00
|
|
|
if (checkifname(env))
|
2005-03-18 14:11:50 +03:00
|
|
|
errx(EXIT_FAILURE, "valid only with agr(4) interfaces");
|
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
int
|
2008-07-16 01:27:58 +04:00
|
|
|
agrsetport(prop_dictionary_t env, prop_dictionary_t oenv)
|
2005-03-18 14:11:50 +03:00
|
|
|
{
|
2008-04-22 21:18:11 +04:00
|
|
|
char buf[IFNAMSIZ];
|
2005-03-18 14:11:50 +03:00
|
|
|
struct agrreq ar;
|
2008-05-07 01:13:20 +04:00
|
|
|
const char *port;
|
|
|
|
int64_t cmd;
|
2005-03-18 14:11:50 +03:00
|
|
|
|
2008-05-07 01:13:20 +04:00
|
|
|
if (!prop_dictionary_get_int64(env, "agrcmd", &cmd)) {
|
2008-05-06 08:33:42 +04:00
|
|
|
warnx("%s.%d", __func__, __LINE__);
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-05-07 01:13:20 +04:00
|
|
|
if (!prop_dictionary_get_cstring_nocopy(env, "agrport", &port)) {
|
2008-05-06 08:33:42 +04:00
|
|
|
warnx("%s.%d", __func__, __LINE__);
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
2008-05-07 01:13:20 +04:00
|
|
|
strlcpy(buf, port, sizeof(buf));
|
2008-04-22 21:18:11 +04:00
|
|
|
|
2008-05-08 03:55:06 +04:00
|
|
|
assertifname(env);
|
2005-03-18 14:11:50 +03:00
|
|
|
memset(&ar, 0, sizeof(ar));
|
|
|
|
ar.ar_version = AGRREQ_VERSION;
|
2008-05-07 01:13:20 +04:00
|
|
|
ar.ar_cmd = cmd;
|
2008-04-22 21:18:11 +04:00
|
|
|
ar.ar_buf = buf;
|
|
|
|
ar.ar_buflen = strlen(buf);
|
2005-03-18 14:11:50 +03:00
|
|
|
|
2008-05-08 03:55:06 +04:00
|
|
|
if (indirect_ioctl(env, SIOCSETAGR, &ar) == -1)
|
2005-03-18 14:11:50 +03:00
|
|
|
err(EXIT_FAILURE, "SIOCSETAGR");
|
2008-05-06 08:33:42 +04:00
|
|
|
return 0;
|
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 void
|
2008-05-06 21:29:04 +04:00
|
|
|
agr_status(prop_dictionary_t env, prop_dictionary_t oenv)
|
2005-03-18 14:11:50 +03:00
|
|
|
{
|
|
|
|
struct agrreq ar;
|
|
|
|
void *buf = NULL;
|
|
|
|
size_t buflen = 0;
|
|
|
|
struct agrportlist *apl;
|
|
|
|
struct agrportinfo *api;
|
|
|
|
int i;
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-08 03:55:06 +04:00
|
|
|
if (checkifname(env))
|
2005-03-18 14:11:50 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
again:
|
|
|
|
memset(&ar, 0, sizeof(ar));
|
|
|
|
ar.ar_version = AGRREQ_VERSION;
|
|
|
|
ar.ar_cmd = AGRCMD_PORTLIST;
|
|
|
|
ar.ar_buf = buf;
|
|
|
|
ar.ar_buflen = buflen;
|
|
|
|
|
2008-05-08 03:55:06 +04:00
|
|
|
if (indirect_ioctl(env, SIOCGETAGR, &ar) == -1) {
|
2005-03-18 14:11:50 +03:00
|
|
|
if (errno != E2BIG) {
|
|
|
|
warn("SIOCGETAGR");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(buf);
|
|
|
|
buf = NULL;
|
|
|
|
buflen = 0;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf == NULL) {
|
|
|
|
buflen = ar.ar_buflen;
|
|
|
|
buf = malloc(buflen);
|
|
|
|
if (buf == NULL) {
|
|
|
|
err(EXIT_FAILURE, "agr_status");
|
|
|
|
}
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
apl = buf;
|
|
|
|
api = (void *)(apl + 1);
|
|
|
|
|
|
|
|
for (i = 0; i < apl->apl_nports; i++) {
|
|
|
|
char tmp[256];
|
|
|
|
|
|
|
|
snprintb(tmp, sizeof(tmp), AGRPORTINFO_BITS, api->api_flags);
|
|
|
|
printf("\tagrport: %s, flags=%s\n", api->api_ifname, tmp);
|
|
|
|
api++;
|
|
|
|
}
|
|
|
|
}
|
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 status_func_t status;
|
2008-07-16 00:56:13 +04:00
|
|
|
static usage_func_t 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
|
|
|
static cmdloop_branch_t branch;
|
|
|
|
|
2008-07-16 00:56:13 +04:00
|
|
|
static void
|
|
|
|
agr_usage(prop_dictionary_t env)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "\t[ agrport i ] [ -agrport i ]\n");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
agr_constructor(void)
|
|
|
|
{
|
|
|
|
status_func_init(&status, agr_status);
|
2008-07-16 00:56:13 +04:00
|
|
|
usage_func_init(&usage, agr_usage);
|
|
|
|
register_status(&status);
|
|
|
|
register_usage(&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
|
|
|
cmdloop_branch_init(&branch, &agr.pk_parser);
|
|
|
|
register_cmdloop_branch(&branch);
|
|
|
|
}
|