Add support for the examination and modification of the devices.
This is implemented through SNMP and requires the ilmi daemon to run on the system. To prevent bloat in rescue the atmconfig for rescue is compiled without this stuff.
This commit is contained in:
parent
84b5d3520f
commit
d093c6fa50
@ -6,17 +6,41 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= atmconfig
|
||||
SRCS= main.c diag.c natm.c
|
||||
.ifndef RESCUE
|
||||
SRCS= ${.OBJDIR}/oid.h
|
||||
.endif
|
||||
SRCS+= main.c diag.c natm.c
|
||||
.ifndef RESCUE
|
||||
SRCS+= atmconfig_device.c
|
||||
.endif
|
||||
MAN= atmconfig.8
|
||||
# CFLAGS+= -DPATH_HELP='".:/usr/share/doc/atm:/usr/local/share/doc/atm"'
|
||||
|
||||
CFLAGS+= -I${.OBJDIR}
|
||||
|
||||
.ifndef RESCUE
|
||||
DPADD= ${LIBBSNMP}
|
||||
LDADD= -lbsnmp
|
||||
.endif
|
||||
|
||||
.ifndef RESCUE
|
||||
CLEANFILES+= oid.h
|
||||
.endif
|
||||
|
||||
.if ${MACHINE_ARCH} == "arm"
|
||||
WARNS?= 3
|
||||
.else
|
||||
WARNS?= 9
|
||||
.endif
|
||||
|
||||
FILES= atmconfig.help
|
||||
FILES= atmconfig.help atmconfig_device.help
|
||||
FILESDIR= /usr/share/doc/atm
|
||||
|
||||
SNMP_ATM_DEF= ${.CURDIR}/../../../contrib/ngatm/snmp_atm/atm_tree.def \
|
||||
${.CURDIR}/../../../lib/libbsnmp/modules/snmp_atm/atm_freebsd.def
|
||||
|
||||
${.OBJDIR}/oid.h: atm_oid.list ${SNMP_ATM_DEF}
|
||||
cat ${SNMP_ATM_DEF} | gensnmptree -e `tail -n +2 ${.CURDIR}/atm_oid.list` \
|
||||
> ${.OBJDIR}/oid.h
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
20
sbin/atm/atmconfig/atm_oid.list
Normal file
20
sbin/atm/atmconfig/atm_oid.list
Normal file
@ -0,0 +1,20 @@
|
||||
# $FreeBSD$
|
||||
begemotAtmIfTable
|
||||
begemotAtmIfName
|
||||
begemotAtmIfNodeId
|
||||
begemotAtmIfPcr
|
||||
begemotAtmIfMedia
|
||||
begemotAtmIfVpiBits
|
||||
begemotAtmIfVciBits
|
||||
begemotAtmIfMaxVpcs
|
||||
begemotAtmIfMaxVccs
|
||||
begemotAtmIfEsi
|
||||
begemotAtmIfCarrierStatus
|
||||
begemotAtmIfMode
|
||||
begemotAtmIfTableLastChange
|
||||
begemotAtmHWTable
|
||||
begemotAtmHWVendor
|
||||
begemotAtmHWDevice
|
||||
begemotAtmHWSerial
|
||||
begemotAtmHWVersion
|
||||
begemotAtmHWSoftVersion
|
@ -48,12 +48,14 @@ struct cmdtab {
|
||||
* client configuration info
|
||||
*/
|
||||
struct amodule {
|
||||
struct cmdtab cmd;
|
||||
const char *help;
|
||||
const struct cmdtab *cmd;
|
||||
};
|
||||
|
||||
#define DEF_MODULE(CMDTAB, HELP) \
|
||||
struct amodule amodule_1 = { CMDTAB, HELP };
|
||||
#define DEF_MODULE(CMDTAB) \
|
||||
struct amodule amodule_1 = { CMDTAB }
|
||||
|
||||
/* for compiled-in modules */
|
||||
void register_module(const struct amodule *);
|
||||
|
||||
/* print a message if we are verbose */
|
||||
void verb(const char *, ...) __printflike(1, 2);
|
||||
@ -70,6 +72,7 @@ struct penum {
|
||||
const char *str;
|
||||
};
|
||||
const char *penum(int32_t value, const struct penum *strtab, char *buf);
|
||||
int pparse(int32_t *, const struct penum *, const char *);
|
||||
|
||||
enum {
|
||||
OPT_NONE,
|
||||
@ -93,4 +96,7 @@ struct option {
|
||||
int parse_options(int *_pargc, char ***_pargv,
|
||||
const struct option *_opts);
|
||||
|
||||
/* XXX while this is compiled in */
|
||||
void device_register(void);
|
||||
|
||||
#endif /* _ATMCONFIG_H */
|
||||
|
@ -1,4 +1,34 @@
|
||||
#
|
||||
# Copyright (c) 2001-2003
|
||||
# Fraunhofer Institute for Open Communication Systems (FhG Fokus).
|
||||
# All rights reserved.
|
||||
# Copyright (c) 2004
|
||||
# Hartmut Brandt.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Author: Hartmut Brandt <harti@freebsd.org>
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# Help file for the atmconfig utility
|
||||
#
|
||||
# $FreeBSD$
|
||||
|
444
sbin/atm/atmconfig/atmconfig_device.c
Normal file
444
sbin/atm/atmconfig/atmconfig_device.c
Normal file
@ -0,0 +1,444 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2002
|
||||
* Fraunhofer Institute for Open Communication Systems (FhG Fokus).
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2003-2004
|
||||
* Hartmut Brandt.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Hartmut Brandt <harti@freebsd.org>
|
||||
*
|
||||
* 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>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "atmconfig.h"
|
||||
#include "atmconfig_device.h"
|
||||
#include "private.h"
|
||||
#include "oid.h"
|
||||
|
||||
#include <bsnmp/asn1.h>
|
||||
#include <bsnmp/snmp.h>
|
||||
#include <bsnmp/snmpclient.h>
|
||||
|
||||
/*
|
||||
* Description of the begemotAtmIfTable
|
||||
*/
|
||||
static const struct snmp_table atmif_table = {
|
||||
OIDX_begemotAtmIfTable,
|
||||
OIDX_begemotAtmIfTableLastChange, 2,
|
||||
sizeof(struct atmif),
|
||||
1, 0x7ffULL,
|
||||
{
|
||||
{ 0,
|
||||
SNMP_SYNTAX_INTEGER, offsetof(struct atmif, index) },
|
||||
{ OID_begemotAtmIfName,
|
||||
SNMP_SYNTAX_OCTETSTRING, offsetof(struct atmif, ifname) },
|
||||
{ OID_begemotAtmIfPcr,
|
||||
SNMP_SYNTAX_GAUGE, offsetof(struct atmif, pcr) },
|
||||
{ OID_begemotAtmIfMedia,
|
||||
SNMP_SYNTAX_INTEGER, offsetof(struct atmif, media) },
|
||||
{ OID_begemotAtmIfVpiBits,
|
||||
SNMP_SYNTAX_GAUGE, offsetof(struct atmif, vpi_bits) },
|
||||
{ OID_begemotAtmIfVciBits,
|
||||
SNMP_SYNTAX_GAUGE, offsetof(struct atmif, vci_bits) },
|
||||
{ OID_begemotAtmIfMaxVpcs,
|
||||
SNMP_SYNTAX_GAUGE, offsetof(struct atmif, max_vpcs) },
|
||||
{ OID_begemotAtmIfMaxVccs,
|
||||
SNMP_SYNTAX_GAUGE, offsetof(struct atmif, max_vccs) },
|
||||
{ OID_begemotAtmIfEsi,
|
||||
SNMP_SYNTAX_OCTETSTRING, offsetof(struct atmif, esi) },
|
||||
{ OID_begemotAtmIfCarrierStatus,
|
||||
SNMP_SYNTAX_INTEGER, offsetof(struct atmif, carrier) },
|
||||
{ OID_begemotAtmIfMode,
|
||||
SNMP_SYNTAX_INTEGER, offsetof(struct atmif, mode) },
|
||||
{ 0, SNMP_SYNTAX_NULL, 0 }
|
||||
}
|
||||
};
|
||||
|
||||
/* List of all ATM interfaces */
|
||||
struct atmif_list atmif_list = TAILQ_HEAD_INITIALIZER(atmif_list);
|
||||
|
||||
/*
|
||||
* ATM hardware table
|
||||
*/
|
||||
struct atmhw {
|
||||
TAILQ_ENTRY(atmhw) link;
|
||||
uint64_t found;
|
||||
int32_t index;
|
||||
u_char *vendor;
|
||||
size_t vendorlen;
|
||||
u_char *device;
|
||||
size_t devicelen;
|
||||
uint32_t serial;
|
||||
uint32_t version;
|
||||
uint32_t soft_version;
|
||||
};
|
||||
TAILQ_HEAD(atmhw_list, atmhw);
|
||||
|
||||
/* list of ATM hardware */
|
||||
static struct atmhw_list atmhw_list;
|
||||
|
||||
/*
|
||||
* Read ATM hardware table
|
||||
*/
|
||||
const struct snmp_table atmhw_table = {
|
||||
OIDX_begemotAtmHWTable,
|
||||
OIDX_begemotAtmIfTableLastChange, 2,
|
||||
sizeof(struct atmhw),
|
||||
1, 0x3fULL,
|
||||
{
|
||||
{ 0,
|
||||
SNMP_SYNTAX_INTEGER, offsetof(struct atmhw, index) },
|
||||
{ OID_begemotAtmHWVendor,
|
||||
SNMP_SYNTAX_OCTETSTRING, offsetof(struct atmhw, vendor) },
|
||||
{ OID_begemotAtmHWDevice,
|
||||
SNMP_SYNTAX_OCTETSTRING, offsetof(struct atmhw, device) },
|
||||
{ OID_begemotAtmHWSerial,
|
||||
SNMP_SYNTAX_GAUGE, offsetof(struct atmhw, serial) },
|
||||
{ OID_begemotAtmHWVersion,
|
||||
SNMP_SYNTAX_GAUGE, offsetof(struct atmhw, version) },
|
||||
{ OID_begemotAtmHWSoftVersion,
|
||||
SNMP_SYNTAX_GAUGE, offsetof(struct atmhw, soft_version) },
|
||||
{ 0, SNMP_SYNTAX_NULL, 0 }
|
||||
}
|
||||
};
|
||||
|
||||
static void device_status(int, char *[]);
|
||||
static void device_hardware(int, char *[]);
|
||||
static void device_modify(int, char *[]);
|
||||
|
||||
static const struct cmdtab device_tab[] = {
|
||||
{ "hardware", NULL, device_hardware },
|
||||
{ "status", NULL, device_status },
|
||||
{ "modify", NULL, device_modify },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static const struct cmdtab entry =
|
||||
{ "device", device_tab, NULL };
|
||||
|
||||
static DEF_MODULE(&entry);
|
||||
|
||||
/*
|
||||
* Carrier state to string
|
||||
*/
|
||||
static const struct penum strcarrier[] = {
|
||||
{ 1, "on" },
|
||||
{ 2, "off" },
|
||||
{ 3, "unknown" },
|
||||
{ 4, "none" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
/*
|
||||
* SUNI mode to string
|
||||
*/
|
||||
static const struct penum strsunimode[] = {
|
||||
{ 1, "sonet" },
|
||||
{ 2, "sdh" },
|
||||
{ 3, "unknown" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
* OIDs
|
||||
*/
|
||||
static const struct asn_oid
|
||||
oid_begemotAtmIfMode = OIDX_begemotAtmIfMode;
|
||||
|
||||
/*
|
||||
* Print 1st status line
|
||||
*/
|
||||
static void
|
||||
dev_status1(const struct atmif *aif)
|
||||
{
|
||||
char buf[100];
|
||||
|
||||
printf("%-5u %-8s %-6u %-4u %-5u %-4u %-5u "
|
||||
"%02x:%02x:%02x:%02x:%02x:%02x %s\n", aif->index,
|
||||
aif->ifname, aif->pcr,
|
||||
(1 << aif->vpi_bits) - 1, (1 << aif->vci_bits) - 1,
|
||||
aif->max_vpcs, aif->max_vccs, aif->esi[0],
|
||||
aif->esi[1], aif->esi[2], aif->esi[3], aif->esi[4], aif->esi[5],
|
||||
penum(aif->carrier, strcarrier, buf));
|
||||
}
|
||||
|
||||
/*
|
||||
* Print 2nd status line
|
||||
*/
|
||||
static void
|
||||
dev_status2(const struct atmif *aif)
|
||||
{
|
||||
char buf[100];
|
||||
|
||||
printf("%-5u %-8s %s\n", aif->index, aif->ifname,
|
||||
penum(aif->mode, strsunimode, buf));
|
||||
}
|
||||
|
||||
/*
|
||||
* Implement the 'device status' command
|
||||
*/
|
||||
static void
|
||||
device_status(int argc, char *argv[])
|
||||
{
|
||||
int opt, i;
|
||||
struct atmif *aif;
|
||||
static const struct option opts[] = {
|
||||
{ NULL, 0, NULL }
|
||||
};
|
||||
|
||||
const char dev1[] =
|
||||
"Interface Max Max\n"
|
||||
"Index Name PCR VPI VCI VPCs VCCs ESI Carrier\n";
|
||||
const char dev2[] =
|
||||
"Interface\n"
|
||||
"Index Name Mode\n";
|
||||
|
||||
while ((opt = parse_options(&argc, &argv, opts)) != -1)
|
||||
switch (opt) {
|
||||
}
|
||||
|
||||
snmp_open(NULL, NULL, NULL, NULL);
|
||||
atexit(snmp_close);
|
||||
|
||||
atmif_fetchtable();
|
||||
|
||||
if (TAILQ_EMPTY(&atmif_list))
|
||||
errx(1, "no ATM interfaces found");
|
||||
|
||||
if (argc > 0) {
|
||||
heading_init();
|
||||
for (i = 0; i < argc; i++) {
|
||||
if ((aif = atmif_find_name(argv[i])) == NULL) {
|
||||
warnx("%s: no such ATM interface", argv[i]);
|
||||
continue;
|
||||
}
|
||||
heading(dev1);
|
||||
dev_status1(aif);
|
||||
}
|
||||
heading_init();
|
||||
for (i = 0; i < argc; i++) {
|
||||
if ((aif = atmif_find_name(argv[i])) == NULL)
|
||||
continue;
|
||||
heading(dev2);
|
||||
dev_status2(aif);
|
||||
}
|
||||
} else {
|
||||
heading_init();
|
||||
TAILQ_FOREACH(aif, &atmif_list, link) {
|
||||
heading(dev1);
|
||||
dev_status1(aif);
|
||||
}
|
||||
heading_init();
|
||||
TAILQ_FOREACH(aif, &atmif_list, link) {
|
||||
heading(dev2);
|
||||
dev_status2(aif);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Print hardware info line
|
||||
*/
|
||||
static void
|
||||
dev_hardware(const struct atmif *aif)
|
||||
{
|
||||
const struct atmhw *hw;
|
||||
|
||||
TAILQ_FOREACH(hw, &atmhw_list, link)
|
||||
if (aif->index == hw->index)
|
||||
break;
|
||||
if (hw == NULL) {
|
||||
warnx("hardware info not found for '%s'", aif->ifname);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%-5u %-8s %-16s%-10s %-10u %-10u %u\n", aif->index,
|
||||
aif->ifname, hw->vendor, hw->device, hw->serial,
|
||||
hw->version, hw->soft_version);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show hardware configuration
|
||||
*/
|
||||
static void
|
||||
device_hardware(int argc, char *argv[])
|
||||
{
|
||||
int opt, i;
|
||||
struct atmif *aif;
|
||||
|
||||
static const struct option opts[] = {
|
||||
{ NULL, 0, NULL }
|
||||
};
|
||||
|
||||
static const char headline[] =
|
||||
"Interface \n"
|
||||
"Index Name Vendor Card Serial HW SW\n";
|
||||
|
||||
while ((opt = parse_options(&argc, &argv, opts)) != -1)
|
||||
switch (opt) {
|
||||
}
|
||||
|
||||
snmp_open(NULL, NULL, NULL, NULL);
|
||||
atexit(snmp_close);
|
||||
|
||||
atmif_fetchtable();
|
||||
|
||||
if (snmp_table_fetch(&atmhw_table, &atmhw_list) != 0)
|
||||
errx(1, "AtmHW table: %s", snmp_client.error);
|
||||
|
||||
if (argc > 0) {
|
||||
heading_init();
|
||||
for (i = 0; i < argc; i++) {
|
||||
if ((aif = atmif_find_name(argv[i])) == NULL) {
|
||||
warnx("interface not found '%s'", argv[i]);
|
||||
continue;
|
||||
}
|
||||
heading(headline);
|
||||
dev_hardware(aif);
|
||||
}
|
||||
} else {
|
||||
heading_init();
|
||||
TAILQ_FOREACH(aif, &atmif_list, link) {
|
||||
heading(headline);
|
||||
dev_hardware(aif);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Change device parameters
|
||||
*/
|
||||
static void
|
||||
device_modify(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
struct atmif *aif;
|
||||
int mode = 0;
|
||||
int n;
|
||||
struct snmp_pdu pdu, resp;
|
||||
|
||||
static const struct option opts[] = {
|
||||
#define MODIFY_MODE 0
|
||||
{ "mode", OPT_STRING, NULL },
|
||||
{ NULL, 0, NULL }
|
||||
};
|
||||
|
||||
while ((opt = parse_options(&argc, &argv, opts)) != -1)
|
||||
switch (opt) {
|
||||
|
||||
case MODIFY_MODE:
|
||||
if (pparse(&mode, strsunimode, optarg) == -1 ||
|
||||
mode == 3)
|
||||
errx(1, "illegal mode for -m '%s'", optarg);
|
||||
break;
|
||||
}
|
||||
|
||||
if (argc != 1)
|
||||
errx(1, "device modify needs one argument");
|
||||
|
||||
snmp_open(NULL, NULL, NULL, NULL);
|
||||
|
||||
atexit(snmp_close);
|
||||
atmif_fetchtable();
|
||||
|
||||
if ((aif = atmif_find_name(argv[0])) == NULL)
|
||||
errx(1, "%s: no such ATM interface", argv[0]);
|
||||
|
||||
snmp_pdu_create(&pdu, SNMP_PDU_SET);
|
||||
if (mode != 0) {
|
||||
n = snmp_add_binding(&pdu,
|
||||
&oid_begemotAtmIfMode, SNMP_SYNTAX_INTEGER,
|
||||
NULL);
|
||||
snmp_oid_append(&pdu.bindings[n + 0].var, "i",
|
||||
(asn_subid_t)aif->index);
|
||||
pdu.bindings[n + 0].v.integer = mode;
|
||||
}
|
||||
|
||||
if (pdu.nbindings == 0)
|
||||
errx(1, "must specify something to modify");
|
||||
|
||||
if (snmp_dialog(&pdu, &resp))
|
||||
errx(1, "No response from '%s': %s", snmp_client.chost,
|
||||
snmp_client.error);
|
||||
|
||||
if (snmp_pdu_check(&pdu, &resp) <= 0)
|
||||
errx(1, "Error modifying device");
|
||||
|
||||
snmp_pdu_free(&resp);
|
||||
snmp_pdu_free(&pdu);
|
||||
}
|
||||
|
||||
/* XXX while this is compiled in */
|
||||
void
|
||||
device_register(void)
|
||||
{
|
||||
register_module(&amodule_1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch the ATM interface table
|
||||
*/
|
||||
void
|
||||
atmif_fetchtable(void)
|
||||
{
|
||||
struct atmif *aif;
|
||||
|
||||
while ((aif = TAILQ_FIRST(&atmif_list)) != NULL) {
|
||||
free(aif->ifname);
|
||||
free(aif->esi);
|
||||
TAILQ_REMOVE(&atmif_list, aif, link);
|
||||
free(aif);
|
||||
}
|
||||
|
||||
if (snmp_table_fetch(&atmif_table, &atmif_list) != 0)
|
||||
errx(1, "AtmIf table: %s", snmp_client.error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find a named ATM interface
|
||||
*/
|
||||
struct atmif *
|
||||
atmif_find_name(const char *ifname)
|
||||
{
|
||||
struct atmif *atmif;
|
||||
|
||||
TAILQ_FOREACH(atmif, &atmif_list, link)
|
||||
if (strcmp(atmif->ifname, ifname) == 0)
|
||||
return (atmif);
|
||||
return (NULL);
|
||||
}
|
||||
/*
|
||||
* find an ATM interface by index
|
||||
*/
|
||||
struct atmif *
|
||||
atmif_find(u_int idx)
|
||||
{
|
||||
struct atmif *atmif;
|
||||
|
||||
TAILQ_FOREACH(atmif, &atmif_list, link)
|
||||
if (atmif->index == (int32_t)idx)
|
||||
return (atmif);
|
||||
return (NULL);
|
||||
}
|
75
sbin/atm/atmconfig/atmconfig_device.h
Normal file
75
sbin/atm/atmconfig/atmconfig_device.h
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2002
|
||||
* Fraunhofer Institute for Open Communication Systems (FhG Fokus).
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2003-2004
|
||||
* Hartmut Brandt.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Hartmut Brandt <harti@freebsd.org>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#ifndef ATMCONFIG_DEVICE_H_
|
||||
#define ATMCONFIG_DEVICE_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/queue.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* ATM interface table
|
||||
*/
|
||||
struct atmif {
|
||||
TAILQ_ENTRY(atmif) link;
|
||||
uint64_t found;
|
||||
int32_t index;
|
||||
u_char *ifname;
|
||||
size_t ifnamelen;
|
||||
uint32_t pcr;
|
||||
int32_t media;
|
||||
uint32_t vpi_bits;
|
||||
uint32_t vci_bits;
|
||||
uint32_t max_vpcs;
|
||||
uint32_t max_vccs;
|
||||
u_char *esi;
|
||||
size_t esilen;
|
||||
int32_t carrier;
|
||||
int32_t mode;
|
||||
};
|
||||
TAILQ_HEAD(atmif_list, atmif);
|
||||
|
||||
/* list of all ATM interfaces */
|
||||
extern struct atmif_list atmif_list;
|
||||
|
||||
/* fetch this table */
|
||||
void atmif_fetchtable(void);
|
||||
|
||||
/* find an ATM interface by name */
|
||||
struct atmif *atmif_find_name(const char *);
|
||||
|
||||
/* find an ATM interface by index */
|
||||
struct atmif *atmif_find(u_int);
|
||||
|
||||
#endif
|
62
sbin/atm/atmconfig/atmconfig_device.help
Normal file
62
sbin/atm/atmconfig/atmconfig_device.help
Normal file
@ -0,0 +1,62 @@
|
||||
# Copyright (c) 2003-2004
|
||||
# Hartmut Brandt.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Author: Hartmut Brandt <harti@freebsd.org>
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# Help file for the atmconfig utility
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
^0 device
|
||||
^^ device show information about ATM hardware interfaces
|
||||
This command shows information about the ATM hardware interfaces on the
|
||||
system. Status information can be obtained by:
|
||||
|
||||
atmconfig [common-options] device status [options] [device ...]
|
||||
|
||||
Information about the hardware of the ATM interfaces is reported by:
|
||||
|
||||
atmconfig [common-options] device hardware [options] [device ...]
|
||||
|
||||
The parameters of the a device can be changed by:
|
||||
|
||||
atmconfig [common-options] device modify [options] <device>
|
||||
|
||||
^1 status
|
||||
usage: atmconfig [common-options] device status [device ...]
|
||||
|
||||
If no device is given as argument information about all devices is shown.
|
||||
|
||||
^1 hardware
|
||||
usage: atmconfig [common-options] device hardware [device ...]
|
||||
|
||||
If now device is given as argument information about all devices is shown.
|
||||
|
||||
^1 modify
|
||||
usage: atmconfig [common-options] device modify [-mode mode] <device>
|
||||
|
||||
options:
|
||||
-mode switch the SUNI mode to either 'sonet' or 'sdh'.
|
||||
|
@ -38,6 +38,12 @@ __FBSDID("$FreeBSD$");
|
||||
#include <stdint.h>
|
||||
#include <fnmatch.h>
|
||||
#include <dirent.h>
|
||||
#ifndef RESCUE
|
||||
#include <bsnmp/asn1.h>
|
||||
#include <bsnmp/snmp.h>
|
||||
#include <bsnmp/snmpclient.h>
|
||||
#endif
|
||||
|
||||
#include "atmconfig.h"
|
||||
#include "private.h"
|
||||
|
||||
@ -55,7 +61,7 @@ static int need_heading;
|
||||
*/
|
||||
static void help_func(int argc, char *argv[]) __dead2;
|
||||
|
||||
static const struct cmdtab main_tab[] = {
|
||||
static const struct cmdtab static_main_tab[] = {
|
||||
{ "help", NULL, help_func },
|
||||
{ "options", NULL, NULL },
|
||||
{ "commands", NULL, NULL },
|
||||
@ -64,6 +70,10 @@ static const struct cmdtab main_tab[] = {
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static struct cmdtab *main_tab = NULL;
|
||||
static size_t main_tab_size = sizeof(static_main_tab) /
|
||||
sizeof(static_main_tab[0]);
|
||||
|
||||
static int
|
||||
substr(const char *s1, const char *s2)
|
||||
{
|
||||
@ -434,18 +444,113 @@ help_func(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifndef RESCUE
|
||||
/*
|
||||
* Parse a server specification
|
||||
*
|
||||
* syntax is [trans::][community@][server][:port]
|
||||
*/
|
||||
static void
|
||||
parse_server(char *name)
|
||||
{
|
||||
char *p, *s = name;
|
||||
|
||||
/* look for a double colon */
|
||||
for (p = s; *p != '\0'; p++) {
|
||||
if (*p == '\\' && p[1] != '\0') {
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
if (*p == ':' && p[1] == ':')
|
||||
break;
|
||||
}
|
||||
if (*p != '\0') {
|
||||
if (p > s) {
|
||||
if (p - s == 3 && strncmp(s, "udp", 3) == 0)
|
||||
snmp_client.trans = SNMP_TRANS_UDP;
|
||||
else if (p - s == 6 && strncmp(s, "stream", 6) == 0)
|
||||
snmp_client.trans = SNMP_TRANS_LOC_STREAM;
|
||||
else if (p - s == 5 && strncmp(s, "dgram", 5) == 0)
|
||||
snmp_client.trans = SNMP_TRANS_LOC_DGRAM;
|
||||
else
|
||||
errx(1, "unknown SNMP transport '%.*s'",
|
||||
(int)(p - s), s);
|
||||
}
|
||||
s = p + 2;
|
||||
}
|
||||
|
||||
/* look for a @ */
|
||||
for (p = s; *p != '\0'; p++) {
|
||||
if (*p == '\\' && p[1] != '\0') {
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
if (*p == '@')
|
||||
break;
|
||||
}
|
||||
|
||||
if (*p != '\0') {
|
||||
if (p - s > SNMP_COMMUNITY_MAXLEN)
|
||||
err(1, "community string too long");
|
||||
strncpy(snmp_client.read_community, s, p - s);
|
||||
snmp_client.read_community[p - s] = '\0';
|
||||
strncpy(snmp_client.write_community, s, p - s);
|
||||
snmp_client.write_community[p - s] = '\0';
|
||||
s = p + 1;
|
||||
}
|
||||
|
||||
/* look for a colon */
|
||||
for (p = s; *p != '\0'; p++) {
|
||||
if (*p == '\\' && p[1] != '\0') {
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
if (*p == ':')
|
||||
break;
|
||||
}
|
||||
|
||||
if (*p == ':') {
|
||||
if (p > s) {
|
||||
*p = '\0';
|
||||
snmp_client_set_host(&snmp_client, s);
|
||||
*p = ':';
|
||||
}
|
||||
snmp_client_set_port(&snmp_client, p + 1);
|
||||
} else if (p > s)
|
||||
snmp_client_set_host(&snmp_client, s);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int opt, i;
|
||||
const struct cmdtab *match, *cc, *tab;
|
||||
|
||||
while ((opt = getopt(argc, argv, "htv")) != -1)
|
||||
#ifndef RESCUE
|
||||
snmp_client_init(&snmp_client);
|
||||
snmp_client.trans = SNMP_TRANS_LOC_STREAM;
|
||||
snmp_client_set_host(&snmp_client, PATH_ILMI_SOCK);
|
||||
#endif
|
||||
|
||||
#ifdef RESCUE
|
||||
#define OPTSTR "htv"
|
||||
#else
|
||||
#define OPTSTR "htvs:"
|
||||
#endif
|
||||
|
||||
while ((opt = getopt(argc, argv, OPTSTR)) != -1)
|
||||
switch (opt) {
|
||||
|
||||
case 'h':
|
||||
help_func(0, argv);
|
||||
|
||||
#ifndef RESCUE
|
||||
case 's':
|
||||
parse_server(optarg);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case 'v':
|
||||
verbose++;
|
||||
break;
|
||||
@ -461,6 +566,15 @@ main(int argc, char *argv[])
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if ((main_tab = malloc(sizeof(static_main_tab))) == NULL)
|
||||
err(1, NULL);
|
||||
memcpy(main_tab, static_main_tab, sizeof(static_main_tab));
|
||||
|
||||
#ifndef RESCUE
|
||||
/* XXX while this is compiled in */
|
||||
device_register();
|
||||
#endif
|
||||
|
||||
cc = main_tab;
|
||||
i = 0;
|
||||
for (;;) {
|
||||
@ -586,6 +700,23 @@ penum(int32_t value, const struct penum *strtab, char *buf)
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* And the other way 'round
|
||||
*/
|
||||
int
|
||||
pparse(int32_t *val, const struct penum *tab, const char *str)
|
||||
{
|
||||
|
||||
while (tab->str != NULL) {
|
||||
if (strcmp(tab->str, str) == 0) {
|
||||
*val = tab->value;
|
||||
return (0);
|
||||
}
|
||||
tab++;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse command line options
|
||||
*/
|
||||
@ -733,3 +864,17 @@ parse_options(int *pargc, char ***pargv, const struct option *opts)
|
||||
}
|
||||
return (m - opts);
|
||||
}
|
||||
|
||||
/*
|
||||
* for compiled-in modules
|
||||
*/
|
||||
void
|
||||
register_module(const struct amodule *mod)
|
||||
{
|
||||
main_tab_size++;
|
||||
if ((main_tab = realloc(main_tab, main_tab_size * sizeof(main_tab[0])))
|
||||
== NULL)
|
||||
err(1, NULL);
|
||||
main_tab[main_tab_size - 2] = *mod->cmd;
|
||||
memset(&main_tab[main_tab_size - 1], 0, sizeof(main_tab[0]));
|
||||
}
|
||||
|
@ -51,6 +51,9 @@
|
||||
#ifndef FILE_HELP_OTHERS
|
||||
#define FILE_HELP_OTHERS "atmconfig_*.help"
|
||||
#endif
|
||||
#ifndef PATH_ILMI_SOCK
|
||||
#define PATH_ILMI_SOCK "/var/run/ilmid.sock"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Builtin commands
|
||||
|
Loading…
Reference in New Issue
Block a user