aboutsummaryrefslogtreecommitdiff
path: root/contrib/ngatm
diff options
context:
space:
mode:
authorHartmut Brandt <harti@FreeBSD.org>2004-08-11 12:17:54 +0000
committerHartmut Brandt <harti@FreeBSD.org>2004-08-11 12:17:54 +0000
commit36919bb12fcb606403fad09d542bc20c92f63760 (patch)
treecbd9161ce8d4ea12b9063cb8a61d08b2e6b94637 /contrib/ngatm
parent8339b15086533b30b0928227360a8e1752119945 (diff)
downloadsrc-36919bb12fcb606403fad09d542bc20c92f63760.tar.gz
src-36919bb12fcb606403fad09d542bc20c92f63760.zip
Notes
Diffstat (limited to 'contrib/ngatm')
-rw-r--r--contrib/ngatm/libngatm/cccust.h4
-rw-r--r--contrib/ngatm/libngatm/unicust.h2
-rw-r--r--contrib/ngatm/snmp_atm/BEGEMOT-ATM.txt301
-rw-r--r--contrib/ngatm/snmp_atm/atm.h96
-rw-r--r--contrib/ngatm/snmp_atm/atm_tree.def75
-rw-r--r--contrib/ngatm/snmp_atm/snmp_atm.3217
-rw-r--r--contrib/ngatm/snmp_atm/snmp_atm.c622
-rw-r--r--contrib/ngatm/snmp_atm/snmp_atm.h102
8 files changed, 1417 insertions, 2 deletions
diff --git a/contrib/ngatm/libngatm/cccust.h b/contrib/ngatm/libngatm/cccust.h
index 6e6f30e02615..d67b12049cca 100644
--- a/contrib/ngatm/libngatm/cccust.h
+++ b/contrib/ngatm/libngatm/cccust.h
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Begemot: libunimsg/libngatm/cccust.h,v 1.1 2004/07/08 08:35:37 brandt Exp $
+ * $Begemot: libunimsg/libngatm/cccust.h,v 1.2 2004/07/16 18:48:24 brandt Exp $
*
* Customisation of call control source to user space.
*/
@@ -45,3 +45,5 @@
#define CCMALLOC(S) (malloc((S)))
#define CCZALLOC(S) (calloc(1, (S)))
#define CCFREE(P) do { free(P); } while (0)
+
+#define CCGETERRNO() (errno)
diff --git a/contrib/ngatm/libngatm/unicust.h b/contrib/ngatm/libngatm/unicust.h
index d018b063bb57..ff028a65a8e6 100644
--- a/contrib/ngatm/libngatm/unicust.h
+++ b/contrib/ngatm/libngatm/unicust.h
@@ -26,7 +26,7 @@
*
* Author: Hartmut Brandt <harti@freebsd.org>
*
- * $Begemot: libunimsg/libunimsg/unicust.h,v 1.4 2003/09/19 13:10:35 hbb Exp $
+ * $Begemot: libunimsg/libngatm/unicust.h,v 1.4 2003/09/19 13:10:35 hbb Exp $
*
* Customisation of signalling source to user space.
*/
diff --git a/contrib/ngatm/snmp_atm/BEGEMOT-ATM.txt b/contrib/ngatm/snmp_atm/BEGEMOT-ATM.txt
new file mode 100644
index 000000000000..f6cca9615e2c
--- /dev/null
+++ b/contrib/ngatm/snmp_atm/BEGEMOT-ATM.txt
@@ -0,0 +1,301 @@
+--
+-- Copyright (c) 2001-2002
+-- 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 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 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.
+--
+-- $Begemot: libunimsg/snmp_atm/BEGEMOT-ATM.txt,v 1.2 2004/08/06 14:50:26 brandt Exp $
+--
+-- Private Begemot MIB for ATM interfaces.
+--
+BEGEMOT-ATM-MIB DEFINITIONS ::= BEGIN
+
+IMPORTS
+ MODULE-IDENTITY, OBJECT-TYPE, Unsigned32, TimeTicks
+ FROM SNMPv2-SMI
+ TEXTUAL-CONVENTION, DisplayString
+ FROM SNMPv2-TC
+ ifIndex
+ FROM IF-MIB
+ begemot
+ FROM BEGEMOT-MIB;
+
+begemotAtm MODULE-IDENTITY
+ LAST-UPDATED "200407190000Z"
+ ORGANIZATION "German Aerospace Centre"
+ CONTACT-INFO
+ " Hartmut Brandt
+
+ Postal: German Aerospace Centre (DLR)
+ Institute of Communications and Navigation
+ 82234 Wessling
+ Germany
+
+ Fax: +49 8153 28 2844
+
+ E-mail: harti@freebsd.org"
+ DESCRIPTION
+ "The Begemot MIB for ATM interfaces."
+
+ ::= { begemot 101 }
+
+begemotAtmObjects OBJECT IDENTIFIER ::= { begemotAtm 1 }
+
+-- --------------------------------------------------------------------------
+
+AtmESI ::= TEXTUAL-CONVENTION
+ DISPLAY-HINT "1x:"
+ STATUS current
+ DESCRIPTION
+ "An ATM End System Identifier. This is basically the same as
+ an Ethernet Address and is assigned using the same rules."
+ SYNTAX OCTET STRING (SIZE(6))
+
+-- --------------------------------------------------------------------------
+
+--
+-- Interfaces table
+--
+begemotAtmIfTable OBJECT-TYPE
+ SYNTAX SEQUENCE OF BegemotAtmIfEntry
+ MAX-ACCESS not-accessible
+ STATUS current
+ DESCRIPTION
+ "This table contains an entry for each hardware ATM
+ interface. The table is indexed by the interface index."
+ ::= { begemotAtmObjects 1 }
+
+begemotAtmIfEntry OBJECT-TYPE
+ SYNTAX BegemotAtmIfEntry
+ MAX-ACCESS not-accessible
+ STATUS current
+ DESCRIPTION
+ "This is a table entry describing one ATM hardware interface."
+ INDEX { ifIndex }
+ ::= { begemotAtmIfTable 1 }
+
+BegemotAtmIfEntry ::= SEQUENCE {
+ begemotAtmIfName DisplayString,
+ begemotAtmIfPcr Unsigned32,
+ begemotAtmIfMedia INTEGER,
+ begemotAtmIfVpiBits Unsigned32,
+ begemotAtmIfVciBits Unsigned32,
+ begemotAtmIfMaxVpcs Unsigned32,
+ begemotAtmIfMaxVccs Unsigned32,
+ begemotAtmIfEsi AtmESI,
+ begemotAtmIfCarrierStatus INTEGER,
+ begemotAtmIfMode INTEGER
+}
+
+begemotAtmIfName OBJECT-TYPE
+ SYNTAX DisplayString (SIZE(1..15))
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Name of the ATM interface."
+ ::= { begemotAtmIfEntry 1 }
+
+begemotAtmIfPcr OBJECT-TYPE
+ SYNTAX Unsigned32
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "The line cell rate of the interface."
+ ::= { begemotAtmIfEntry 2 }
+
+begemotAtmIfMedia OBJECT-TYPE
+ SYNTAX INTEGER {
+ other(1),
+ unknown(3),
+ utp25(4),
+ taxi100(5),
+ taxi140(6),
+ mm155(7),
+ sm155(8),
+ utp155(9),
+ mm622(10),
+ sm622(11),
+ virtual(12)
+ }
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "The physical medium."
+ ::= { begemotAtmIfEntry 3 }
+
+begemotAtmIfVpiBits OBJECT-TYPE
+ SYNTAX Unsigned32 (0..12)
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Number of VPI bits that are used by the device."
+ ::= { begemotAtmIfEntry 4 }
+
+begemotAtmIfVciBits OBJECT-TYPE
+ SYNTAX Unsigned32 (0..16)
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Number of VCI bits that are used by the device."
+ ::= { begemotAtmIfEntry 5 }
+
+begemotAtmIfMaxVpcs OBJECT-TYPE
+ SYNTAX Unsigned32 (0..256)
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "The maximum number of VPC supported on this device. This may not
+ be larger than 2^begemotAtmIfVpiBits."
+ ::= { begemotAtmIfEntry 6 }
+
+begemotAtmIfMaxVccs OBJECT-TYPE
+ SYNTAX Unsigned32 (0..16777216)
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "The maximum number of VCC supported on this device. This may not
+ be larger than 2^(begemotAtmIfVpiBits + begemotAtmVciBits)."
+ ::= { begemotAtmIfEntry 7 }
+
+begemotAtmIfEsi OBJECT-TYPE
+ SYNTAX AtmESI
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "The default End System Identifier as reported by the hardware.
+ If the hardware has no ESI all six bytes are reported as 0."
+ ::= { begemotAtmIfEntry 8 }
+
+begemotAtmIfCarrierStatus OBJECT-TYPE
+ SYNTAX INTEGER { carrierOn(1), carrierOff(2), unknown(3), none(4) }
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "The state of the carrier. For interfaces which don't have the
+ notion of a carriere none is reported."
+ ::= { begemotAtmIfEntry 9 }
+
+begemotAtmIfMode OBJECT-TYPE
+ SYNTAX INTEGER { sonet(1), sdh(2), unknown(3) }
+ MAX-ACCESS read-write
+ STATUS current
+ DESCRIPTION
+ "The mode of the SUNI interface. For interfaces without SUNI
+ unknown is reported in which case the variable is read-only.
+ Some types of interfaces may not be able to change this value."
+ ::= { begemotAtmIfEntry 10 }
+
+begemotAtmIfTableLastChange OBJECT-TYPE
+ SYNTAX TimeTicks
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "The value of sysUpTime the last time that an entry in
+ begemotIfTable was created or destroyed. If the table is
+ unchanged since the last coldStart this value is zero."
+ ::= { begemotAtmObjects 2 }
+
+--
+-- Interface hardware table
+--
+begemotAtmHWTable OBJECT-TYPE
+ SYNTAX SEQUENCE OF BegemotAtmHWEntry
+ MAX-ACCESS not-accessible
+ STATUS current
+ DESCRIPTION
+ "This table augments the begemotAtmIfTable and contains an entry
+ for each hardware ATM interface. The entries describe the
+ ATM hardware interface."
+ ::= { begemotAtmObjects 3 }
+
+begemotAtmHWEntry OBJECT-TYPE
+ SYNTAX BegemotAtmHWEntry
+ MAX-ACCESS not-accessible
+ STATUS current
+ DESCRIPTION
+ "This is a table entry describing one ATM hardware interface."
+ AUGMENTS { begemotAtmIfEntry }
+ ::= { begemotAtmHWTable 1 }
+
+BegemotAtmHWEntry ::= SEQUENCE {
+ begemotAtmHWVendor DisplayString,
+ begemotAtmHWDevice DisplayString,
+ begemotAtmHWSerial Unsigned32,
+ begemotAtmHWVersion Unsigned32,
+ begemotAtmHWSoftVersion Unsigned32
+}
+
+begemotAtmHWVendor OBJECT-TYPE
+ SYNTAX DisplayString
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "A short string naming the vendor of the interface card."
+ ::= { begemotAtmHWEntry 1 }
+
+begemotAtmHWDevice OBJECT-TYPE
+ SYNTAX DisplayString
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "A short string naming the brand of the interface card."
+ ::= { begemotAtmHWEntry 2 }
+
+begemotAtmHWSerial OBJECT-TYPE
+ SYNTAX Unsigned32
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "The serial number of the interface card or 0 if it doesn't
+ report a serial number."
+ ::= { begemotAtmHWEntry 3 }
+
+begemotAtmHWVersion OBJECT-TYPE
+ SYNTAX Unsigned32
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "The hardware version of the interface card or 0 if it doesn't
+ report a hardware version number."
+ ::= { begemotAtmHWEntry 4 }
+
+begemotAtmHWSoftVersion OBJECT-TYPE
+ SYNTAX Unsigned32
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "The firmware version of the interface card or 0 if it doesn't
+ report a firmware version number."
+ ::= { begemotAtmHWEntry 5 }
+
+-- --------------------------------------------------------------------
+
+-- System specific parts
+begemotAtmSysGroup OBJECT IDENTIFIER ::= { begemotAtmObjects 4 }
+
+END
diff --git a/contrib/ngatm/snmp_atm/atm.h b/contrib/ngatm/snmp_atm/atm.h
new file mode 100644
index 000000000000..0df6f7e3eaec
--- /dev/null
+++ b/contrib/ngatm/snmp_atm/atm.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2004
+ * Deutsches Zentrum fuer Luft- und Raumfahrt.
+ * 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 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 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.
+ *
+ * $Begemot: libunimsg/snmp_atm/atm.h,v 1.2 2004/08/11 07:55:22 brandt Exp $
+ */
+
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <sys/socket.h>
+
+#include <net/if.h>
+#include <net/if_mib.h>
+
+#include <bsnmp/snmpmod.h>
+#include <bsnmp/snmp_mibII.h>
+#include "snmp_atm.h"
+
+/*
+ * Event registrations
+ */
+struct atmif_reg {
+ TAILQ_ENTRY(atmif_reg) link;
+ void *data;
+ atmif_event_f func;
+ const struct lmodule *mod;
+ struct atmif_priv *aif; /* back pointer */
+};
+TAILQ_HEAD(atmif_reg_list, atmif_reg);
+
+/*
+ * Interface data
+ */
+struct atmif_priv {
+ struct atmif pub; /* public part, must be first */
+ TAILQ_ENTRY(atmif_priv) link;
+ u_int index; /* if_index */
+ void *ifpreg;
+ struct atmif_sys *sys;
+ struct atmif_reg_list notify;
+};
+TAILQ_HEAD(atmif_list, atmif_priv);
+
+/* list of all (known) ATM interfaces */
+extern struct atmif_list atmif_list;
+
+extern struct lmodule *module;
+
+/* Check the carrier state of the interface */
+void atmif_check_carrier(struct atmif_priv *);
+
+/* Send notification to all listeners. */
+void atmif_send_notification(struct atmif_priv *, enum atmif_notify, uintptr_t);
+
+/* Get the interface point for a table access */
+int atmif_get_aif(struct snmp_value *, u_int, enum snmp_op,
+ struct atmif_priv **);
+
+/* Destroy system dependend stuff. */
+void atmif_sys_destroy(struct atmif_priv *);
+
+/* Attach to an ATM interface */
+int atmif_sys_attach_if(struct atmif_priv *);
+
+/* Get vendor string */
+int atm_sys_get_hw_vendor(struct atmif_priv *, struct snmp_value *);
+
+/* Get device string */
+int atm_sys_get_hw_device(struct atmif_priv *, struct snmp_value *);
+
+/* Extract the ATM MIB from the interface's private MIB */
+void atmif_sys_fill_mib(struct atmif_priv *);
diff --git a/contrib/ngatm/snmp_atm/atm_tree.def b/contrib/ngatm/snmp_atm/atm_tree.def
new file mode 100644
index 000000000000..ac70b0e7ee22
--- /dev/null
+++ b/contrib/ngatm/snmp_atm/atm_tree.def
@@ -0,0 +1,75 @@
+#
+# Copyright (c) 2000-2003
+# Fraunhofer Institut for Open Communication Systems (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 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 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.
+#
+# $Begemot: libunimsg/snmp_atm/atm_tree.def,v 1.3 2004/08/06 14:50:27 brandt Exp $
+#
+# SNMP module for ATM hardware interfaces.
+#
+# $Begemot: libunimsg/snmp_atm/atm_tree.def,v 1.3 2004/08/06 14:50:27 brandt Exp $
+#
+(1 internet
+ (4 private
+ (1 enterprises
+ (12325 fokus
+ (1 begemot
+ (101 begemotAtm
+ (1 begemotAtmObjects
+ (1 begemotAtmIfTable
+ (1 begemotAtmIfEntry : INTEGER op_atmif
+ (1 begemotAtmIfName OCTETSTRING GET)
+ (2 begemotAtmIfPcr UNSIGNED32 GET)
+ (3 begemotAtmIfMedia INTEGER GET)
+ (4 begemotAtmIfVpiBits UNSIGNED32 GET)
+ (5 begemotAtmIfVciBits UNSIGNED32 GET)
+ (6 begemotAtmIfMaxVpcs UNSIGNED32 GET)
+ (7 begemotAtmIfMaxVccs UNSIGNED32 GET)
+ (8 begemotAtmIfEsi OCTETSTRING GET)
+ (9 begemotAtmIfCarrierStatus INTEGER GET)
+ (10 begemotAtmIfMode INTEGER GET SET)
+ ))
+ (2 begemotAtmIfTableLastChange TIMETICKS op_atm GET)
+ (3 begemotAtmHWTable
+ (1 begemotAtmHWEntry : INTEGER op_atmhw
+ (1 begemotAtmHWVendor OCTETSTRING GET)
+ (2 begemotAtmHWDevice OCTETSTRING GET)
+ (3 begemotAtmHWSerial UNSIGNED32 GET)
+ (4 begemotAtmHWVersion UNSIGNED32 GET)
+ (5 begemotAtmHWSoftVersion UNSIGNED32 GET)
+ ))
+ (4 begemotAtmSysGroup
+ (1 begemotAtmFreeBSDGroup
+ )
+ )
+ )
+ ))
+ )
+ )
+))
diff --git a/contrib/ngatm/snmp_atm/snmp_atm.3 b/contrib/ngatm/snmp_atm/snmp_atm.3
new file mode 100644
index 000000000000..7fe2f4663975
--- /dev/null
+++ b/contrib/ngatm/snmp_atm/snmp_atm.3
@@ -0,0 +1,217 @@
+.\"
+.\" 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 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 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.
+.\"
+.\" $Begemot: libunimsg/snmp_atm/snmp_atm.3,v 1.1 2004/07/20 16:30:03 brandt Exp $
+.\"
+.Dd July 20, 2004
+.Dt snmp_atm 3
+.Os
+.Sh NAME
+.Nm atmif_event_f ,
+.Nm atm_find_if_name ,
+.Nm atm_find_if ,
+.Nm atm_notify_aif ,
+.Nm atm_unnotify_aif
+.Nd "ATM driver module for snmpd.
+.Sh LIBRARY
+.Pq begemotSnmpdModulePath."netgraph" = "@MODPATH@snmp_netgraph.so" (FreeBSD)
+.Pq begemotSnmpdModulePath."mibII" = "@MODPATH@snmp_mibII.so"
+.Pq begemotSnmpdModulePath."atm" = "@MODPATH@snmp_atm.so"
+.Sh SYNOPSIS
+.In bsnmp/snmpmod.h
+.In bsnmp/snmp_mibII.h
+.In bsnmp/snmp_atm.h
+.Ft typedef void
+.Fn (*atmif_event_f) "struct atmif *aif" "enum atmif_notify event" "uintptr_t data" "void *uarg"
+.Ft struct atmif *
+.Fn atm_find_if_name "const char *name"
+.Ft struct atmif *
+.Fn atm_find_if "u_int ifindex"
+.Ft void *
+.Fn atm_notify_aif "struct atmif *aif" "const struct lmodule *mod" "atmif_event_f func" "void *uarg"
+.Ft void
+.Fn atm_unnotify_aif "void *not"
+.Sh DESCRIPTION
+The
+.Nm snmp_atm
+module implements a number of tables and scalars that enable remote access to
+the ATM devices in the system. It also exports a number of
+functions, that allow other modules to easily access ATM devices.
+.Pp
+The module maintains an extension to the interface structure exported by
+.Xr snmp_mibII 3
+for all ATM devices. This structure has the following fields:
+.Bd -literal -offset indent
+struct atmif {
+ struct mibif *ifp; /* common interface data */
+ struct atmif_mib *mib; /* ATM MIB */
+ enum atmif_carrier_state carrier;
+ enum atmif_suni_mode mode; /* SUNI mode SDH or SONET */
+};
+.Ed
+.Pp
+The fields have the following meaning:
+.Bl -tag -width XXX
+.It Fa ifp
+The field points to the
+.Xr snmp_mibII 3
+interface structure.
+.It Fa mib
+The special ATM interface MIB (see below).
+.It Fa carrier
+The current state of the carrier. One of the following:
+.Bl -tag -width XXX
+.It Dv ATMIF_CARRIER_ON
+carrier detected,
+.It Dv ATMIF_CARRIER_OFF
+no carrier,
+.It Dv ATMIF_CARRIER_UNKNOWN
+the state of the carrier is unknown,
+.It Dv ATMIF_CARRIER_NONE
+the device has no notion of carrier or is not able to sense it.
+.El
+.It Fa mode
+For ATM devices with a SUNI chip this is the current mode of the interface:
+.Bl -tag -width XXX
+.It Dv ATMIF_SUNI_MODE_SONET
+The interface is in SONET mode.
+.It Dv ATMIF_SUNI_MODE_SDH
+The interface is in SDH mode.
+.It Dv ATMIF_SUNI_MODE_UNKNOWN
+The interface either has no SUNI interface or the mode is unknown (for example,
+interface is down).
+.El
+.El
+.Pp
+An ATM interface can be found by name or by SNMP interface index (see
+.Xr snmp_mibII 3
+for a discussion of interface indexes).
+The function
+.Fn atm_find_if_name
+searches an interface given a name.
+The function
+.Fn atm_find_if
+searches an interface by its interface index.
+Both functions return NULL if an interface cannot be found.
+.Pp
+The ATM MIB contains the following fields:
+.Bd -literal -offset indent
+struct atmif_mib {
+ u_int version; /* currently 0 */
+
+ u_int device; /* type of hardware (system specific) */
+ u_int serial; /* card serial number (device specific) */
+ u_int hw_version; /* card version (device specific) */
+ u_int sw_version; /* firmware version (device specific) */
+ u_int media; /* physical media (see MIB) */
+
+ u_char esi[6]; /* end system identifier (MAC) */
+ u_int pcr; /* supported peak cell rate */
+ u_int vpi_bits; /* number of used bits in VPI field */
+ u_int vci_bits; /* number of used bits in VCI field */
+ u_int max_vpcs; /* maximum number of VPCs */
+ u_int max_vccs; /* maximum number of VCCs */
+};
+.Ed
+.Ss NOTIFICATIONS
+An other module can register with
+.Nm
+to receive notifications when certain events happen on the ATM interface.
+The registration is done with
+.Fn atm_notify_aif
+which takes a pointer to the interface, the calling module pointer, a callback
+function and a user argument that is passed to the callback function.
+The callback function is called with the interface pointer, a notification
+code, a notification argument and the user argument. The following
+notifications are defined:
+.Bl -tag -width XXX
+.It Dv ATMIF_NOTIFY_DESTROY
+The interface is destroyed. The notification argument is not used.
+.It Dv ATMIF_NOTIFY_CARRIER
+The carrier state on the interface has changed. The argument is the
+.Em old
+state of the carrier. The new state can be obtained from the interface
+structure.
+.It Dv ATMIF_NOTIFY_VCC
+A permanent VCC has been created or destroyed. The argument is an u_int that
+can be decoded as follows:
+.Bd -literal -offset indent
+vpi = (arg >> 24) & 0xff;
+vci = (arg >> 8) & 0xffff;
+state = arg & 1;
+.Ed
+.Pp
+.Va state
+is 0 if the VCC was destroyed and 1 if it was created.
+.El
+The registration for notification can be undone by passing the return
+value from
+.Fn atm_notify_aif
+to
+.Fn atm_unnotify_aif .
+The registrations is automatically removed if the interface is destroyed.
+.Ss MIB
+The MIB implemented by the module is defined in
+.Pa BEGEMOT-ATM.txt .
+In the generic part there are two tables and one scalar, there is also
+a system specific group:
+.Bl -tag -width XXX
+.It Va begemotAtmIfTable
+This table is an extension of
+.Va ifTable .
+It contains a row for each ATM interface and is index with
+.Va ifIndex .
+All fields are read-only except the
+.Va begemotAtmIfMode
+column.
+.It Va begemotAtmIfTableLastChange
+Contains the tick when a row was created or destroyed in the above table or
+0, if the table did not change since start of the SNMP agent.
+.It Va begemotAtmHWTable
+Is also indexed by
+.Va ifIndex
+and contains hardware specific information. This table is read-only.
+.El
+.Sh FILES
+.Bl -tag -width "XXXXXXXXX"
+.It Pa @DEFPATH@atm_tree.def
+The description of the MIB tree implemented by
+.Nm .
+.It Pa @MIBSPATH@BEGEMOT-ATM.txt
+This is the MIB that is implemented by this module.
+.Sh SEE ALSO
+.Xr bsnmpd 1 ,
+.Xr snmpmod 3 ,
+.Xr snmp_mibII 3 ,
+.Xr snmp_netgraph 3 ,
+.Xr gensnmptree 1
+.Sh AUTHORS
+.An Hartmut Brandt Aq harti@freebsd.org
diff --git a/contrib/ngatm/snmp_atm/snmp_atm.c b/contrib/ngatm/snmp_atm/snmp_atm.c
new file mode 100644
index 000000000000..1106e8a237be
--- /dev/null
+++ b/contrib/ngatm/snmp_atm/snmp_atm.c
@@ -0,0 +1,622 @@
+/*
+ * 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 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 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.
+ *
+ * $Begemot: libunimsg/snmp_atm/snmp_atm.c,v 1.2 2004/08/06 17:30:40 brandt Exp $
+ *
+ * SNMP module for ATM hardware interfaces.
+ */
+
+#include "atm.h"
+#include "atm_tree.h"
+#include "atm_oid.h"
+
+#include <sys/ioctl.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <syslog.h>
+#include <net/if_types.h>
+#include <net/if_media.h>
+#include <net/if_atm.h>
+
+struct lmodule *module;
+
+/* list of all (known) ATM interfaces */
+struct atmif_list atmif_list = TAILQ_HEAD_INITIALIZER(atmif_list);
+
+/* whether we are started or not */
+static int started;
+
+/* last time table was changed */
+static uint32_t last_change;
+
+/* for the registration */
+static const struct asn_oid oid_begemotAtm = OIDX_begemotAtm;
+
+/* the registration */
+static u_int reg_atm;
+
+/*
+ * Find an ATM interface by name
+ */
+struct atmif *
+atm_find_if_name(const char *name)
+{
+ struct atmif_priv *aif;
+
+ TAILQ_FOREACH(aif, &atmif_list, link)
+ if (strcmp(aif->pub.ifp->name, name) == 0)
+ return (&aif->pub);
+ return (NULL);
+}
+
+/*
+ * get the interface from the interface index
+ */
+struct atmif *
+atm_find_if(u_int ifindex)
+{
+ struct atmif_priv *aif;
+
+ TAILQ_FOREACH(aif, &atmif_list, link)
+ if (aif->index == ifindex)
+ return (&aif->pub);
+ return (NULL);
+}
+
+/*
+ * Send notification to all listeners.
+ */
+void
+atmif_send_notification(struct atmif_priv *aif, enum atmif_notify code,
+ uintptr_t arg)
+{
+ struct atmif_reg *r0, *r1;
+
+ r0 = TAILQ_FIRST(&aif->notify);
+ while (r0 != NULL) {
+ r1 = TAILQ_NEXT(r0, link);
+ r0->func(&aif->pub, code, arg, r0->data);
+ r0 = r1;
+ }
+}
+
+/*
+ * Destroy an interface
+ */
+static void
+atmif_destroy(struct atmif_priv *aif)
+{
+ struct atmif_reg *r0;
+
+ atmif_send_notification(aif, ATMIF_NOTIFY_DESTROY,
+ (uintptr_t)0);
+
+ atmif_sys_destroy(aif);
+
+ if (aif->ifpreg != NULL)
+ mibif_unnotify(aif->ifpreg);
+
+ while ((r0 = TAILQ_FIRST(&aif->notify)) != NULL) {
+ TAILQ_REMOVE(&aif->notify, r0, link);
+ free(r0);
+ }
+
+ TAILQ_REMOVE(&atmif_list, aif, link);
+ free(aif);
+
+ last_change = this_tick;
+}
+
+/*
+ * Function gets called from the MIB-II module for events on that interface
+ */
+static void
+atmif_notify(struct mibif *ifp __unused, enum mibif_notify event, void *data)
+{
+ struct atmif_priv *aif = data;
+
+ switch (event) {
+
+ case MIBIF_NOTIFY_DESTROY:
+ atmif_destroy(aif);
+ break;
+ }
+}
+
+/*
+ * Check the carrier state of the interface
+ */
+void
+atmif_check_carrier(struct atmif_priv *aif)
+{
+ struct ifmediareq ifmr;
+ enum atmif_carrier_state ost = aif->pub.carrier;
+
+ memset(&ifmr, 0, sizeof(ifmr));
+ strcpy(ifmr.ifm_name, aif->pub.ifp->name);
+
+ if (ioctl(mib_netsock, SIOCGIFMEDIA, &ifmr) == -1) {
+ aif->pub.carrier = ATMIF_CARRIER_UNKNOWN;
+ return;
+ }
+ if (!ifmr.ifm_status & IFM_AVALID) {
+ aif->pub.carrier = ATMIF_CARRIER_UNKNOWN;
+ return;
+ }
+ if (ifmr.ifm_status & IFM_ACTIVE)
+ aif->pub.carrier = ATMIF_CARRIER_ON;
+ else
+ aif->pub.carrier = ATMIF_CARRIER_OFF;
+
+ if (ost != aif->pub.carrier)
+ atmif_send_notification(aif, ATMIF_NOTIFY_CARRIER,
+ (uintptr_t)ost);
+}
+
+/*
+ * Retrieve the SUNI mode
+ */
+static int
+atmif_get_mode(struct atmif_priv *aif)
+{
+ struct ifmediareq ifmr;
+
+ memset(&ifmr, 0, sizeof(ifmr));
+ strcpy(ifmr.ifm_name, aif->pub.ifp->name);
+
+ if (ioctl(mib_netsock, SIOCGIFMEDIA, &ifmr) < 0) {
+ syslog(LOG_ERR, "SIOCGIFMEDIA: %m");
+ aif->pub.mode = ATMIF_SUNI_MODE_UNKNOWN;
+ return (SNMP_ERR_GENERR);
+ }
+ if (ifmr.ifm_current & IFM_ATM_SDH)
+ aif->pub.mode = ATMIF_SUNI_MODE_SDH;
+ else
+ aif->pub.mode = ATMIF_SUNI_MODE_SONET;
+
+ return (SNMP_ERR_NOERROR);
+}
+
+/*
+ * Change the SUNI mod
+ */
+static int
+atmif_set_mode(struct atmif_priv *aif, int newmode)
+{
+ struct ifmediareq ifmr;
+ struct ifreq ifr;
+
+ memset(&ifmr, 0, sizeof(ifmr));
+ strcpy(ifmr.ifm_name, aif->pub.ifp->name);
+
+ /* get current mode */
+ if (ioctl(mib_netsock, SIOCGIFMEDIA, &ifmr) < 0) {
+ syslog(LOG_ERR, "SIOCGIFMEDIA: %m");
+ return (SNMP_ERR_GENERR);
+ }
+
+ memset(&ifr, 0, sizeof(ifr));
+ strcpy(ifr.ifr_name, aif->pub.ifp->name);
+
+ ifr.ifr_media = ifmr.ifm_current;
+ if (newmode == ATMIF_SUNI_MODE_SDH)
+ ifr.ifr_media |= IFM_ATM_SDH;
+ else
+ ifr.ifr_media &= ~IFM_ATM_SDH;
+
+ if (ioctl(mib_netsock, SIOCSIFMEDIA, &ifr) < 0) {
+ syslog(LOG_ERR, "SIOCSIFMEDIA: %m");
+ return (SNMP_ERR_GENERR);
+ }
+
+ aif->pub.mode = newmode;
+ return (SNMP_ERR_NOERROR);
+}
+
+/*
+ * Attach to an ATM interface
+ */
+static void
+attach_if(struct mibif *ifp)
+{
+ struct atmif_priv *aif;
+
+ /* we should not know it */
+ TAILQ_FOREACH(aif, &atmif_list, link)
+ if (aif->pub.ifp == ifp) {
+ syslog(LOG_CRIT, "new ATM if already known '%s'",
+ ifp->name);
+ return;
+ }
+
+ /*
+ * tap it
+ */
+ if ((aif = malloc(sizeof(*aif))) == NULL) {
+ syslog(LOG_ERR, "new atmif: %m");
+ return;
+ }
+ memset(aif, 0, sizeof(*aif));
+
+ aif->pub.ifp = ifp;
+ aif->index = ifp->index;
+
+ if (atmif_sys_attach_if(aif)) {
+ free(aif);
+ return;
+ }
+
+ aif->ifpreg = mibif_notify(ifp, module, atmif_notify, aif);
+
+ aif->pub.carrier = ATMIF_CARRIER_UNKNOWN;
+ atmif_check_carrier(aif);
+ (void)atmif_get_mode(aif);
+
+ INSERT_OBJECT_INT(aif, &atmif_list);
+
+ last_change = this_tick;
+
+ return;
+}
+
+/*
+ * Function gets called when a new interface is created. If this is an
+ * ATM interface, hook in. Claim the interface in any case even when
+ * the creation of our data structures fails.
+ */
+static int
+new_if(struct mibif *ifp)
+{
+ if (!started || ifp->mib.ifmd_data.ifi_type != IFT_ATM ||
+ ifp->xnotify != NULL)
+ return (0);
+
+ attach_if(ifp);
+ return (1);
+}
+
+/*
+ * Start the module
+ */
+static void
+atm_start(void)
+{
+ struct mibif *ifp;
+
+ reg_atm = or_register(&oid_begemotAtm,
+ "The Begemot MIB for ATM interfaces.", module);
+
+ started = 1;
+ for (ifp = mib_first_if(); ifp != NULL; ifp = mib_next_if(ifp))
+ if (ifp->mib.ifmd_data.ifi_type == IFT_ATM &&
+ ifp->xnotify == NULL)
+ attach_if(ifp);
+}
+
+/*
+ * Called when modules is loaded
+ */
+static int
+atm_init(struct lmodule *mod, int argc __unused, char *argv[] __unused)
+{
+ module = mod;
+
+ /* register to get creation messages for ATM interfaces */
+ if (mib_register_newif(new_if, module)) {
+ syslog(LOG_ERR, "cannot register newif function: %m");
+ return (-1);
+ }
+
+ return (0);
+}
+
+/*
+ * Called when module gets unloaded - free all resources
+ */
+static int
+atm_fini(void)
+{
+ struct atmif_priv *aif;
+
+ while ((aif = TAILQ_FIRST(&atmif_list)) != NULL)
+ atmif_destroy(aif);
+
+ mib_unregister_newif(module);
+ or_unregister(reg_atm);
+
+ return (0);
+}
+
+/*
+ * Other module unloaded/loaded
+ */
+static void
+atm_loading(const struct lmodule *mod, int loading)
+{
+ struct atmif_priv *aif;
+ struct atmif_reg *r0, *r1;
+
+ if (!loading) {
+ /* remove notifications for this module */
+ TAILQ_FOREACH(aif, &atmif_list, link)
+ TAILQ_FOREACH_SAFE(r0, &aif->notify, link, r1) {
+ if (r0->mod == mod) {
+ TAILQ_REMOVE(&aif->notify, r0, link);
+ free(r0);
+ }
+ }
+ }
+}
+
+const struct snmp_module config = {
+ .comment = "This module implements a private MIB for ATM interfaces.",
+ .init = atm_init,
+ .fini = atm_fini,
+ .start = atm_start,
+ .tree = atm_ctree,
+ .tree_size = atm_CTREE_SIZE,
+ .loading = atm_loading
+};
+
+/*
+ * Get the interface point for a table access
+ */
+int
+atmif_get_aif(struct snmp_value *value, u_int sub, enum snmp_op op,
+ struct atmif_priv **aifp)
+{
+ switch (op) {
+
+ case SNMP_OP_GETNEXT:
+ if ((*aifp = NEXT_OBJECT_INT(&atmif_list,
+ &value->var, sub)) == NULL)
+ return (SNMP_ERR_NOSUCHNAME);
+ value->var.len = sub + 1;
+ value->var.subs[sub] = (*aifp)->index;
+ break;
+
+ case SNMP_OP_GET:
+ if ((*aifp = FIND_OBJECT_INT(&atmif_list,
+ &value->var, sub)) == NULL)
+ return (SNMP_ERR_NOSUCHNAME);
+ break;
+
+ case SNMP_OP_SET:
+ if ((*aifp = FIND_OBJECT_INT(&atmif_list,
+ &value->var, sub)) == NULL)
+ return (SNMP_ERR_NO_CREATION);
+ break;
+
+ case SNMP_OP_ROLLBACK:
+ case SNMP_OP_COMMIT:
+ if ((*aifp = FIND_OBJECT_INT(&atmif_list,
+ &value->var, sub)) == NULL)
+ abort();
+ return (SNMP_ERR_NOERROR);
+ }
+
+ if ((*aifp)->pub.mib->pcr == 0) {
+ mib_fetch_ifmib((*aifp)->pub.ifp);
+ atmif_sys_fill_mib(*aifp);
+ atmif_check_carrier(*aifp);
+ }
+
+ return (SNMP_ERR_NOERROR);
+}
+
+/*
+ * Table of all ATM interfaces
+ */
+int
+op_atmif(struct snmp_context *ctx __unused, struct snmp_value *value,
+ u_int sub, u_int vindex __unused, enum snmp_op op)
+{
+ struct atmif_priv *aif;
+ int err;
+
+ if ((err = atmif_get_aif(value, sub, op, &aif)) != SNMP_ERR_NOERROR)
+ return (err);
+
+ if (op == SNMP_OP_SET) {
+ switch (value->var.subs[sub - 1]) {
+
+ default:
+ return (SNMP_ERR_NOT_WRITEABLE);
+
+ case LEAF_begemotAtmIfMode:
+ if ((err = atmif_get_mode(aif)) != SNMP_ERR_NOERROR)
+ return (err);
+ if (aif->pub.mode == ATMIF_SUNI_MODE_UNKNOWN)
+ return (SNMP_ERR_INCONS_VALUE);
+ if (value->v.integer != ATMIF_SUNI_MODE_SONET &&
+ value->v.integer != ATMIF_SUNI_MODE_SDH)
+ return (SNMP_ERR_WRONG_VALUE);
+ if ((u_int)value->v.integer == aif->pub.mode)
+ return (SNMP_ERR_NOERROR);
+ return (atmif_set_mode(aif, value->v.integer));
+ }
+ abort();
+ }
+
+ switch (value->var.subs[sub - 1]) {
+
+ case LEAF_begemotAtmIfName:
+ return (string_get(value, aif->pub.ifp->name, -1));
+
+ case LEAF_begemotAtmIfPcr:
+ value->v.uint32 = aif->pub.mib->pcr;
+ return (SNMP_ERR_NOERROR);
+
+ case LEAF_begemotAtmIfMedia:
+ value->v.integer = aif->pub.mib->media;
+ return (SNMP_ERR_NOERROR);
+
+ case LEAF_begemotAtmIfVpiBits:
+ value->v.uint32 = aif->pub.mib->vpi_bits;
+ return (SNMP_ERR_NOERROR);
+
+ case LEAF_begemotAtmIfVciBits:
+ value->v.uint32 = aif->pub.mib->vci_bits;
+ return (SNMP_ERR_NOERROR);
+
+ case LEAF_begemotAtmIfMaxVpcs:
+ value->v.uint32 = aif->pub.mib->max_vpcs;
+ return (SNMP_ERR_NOERROR);
+
+ case LEAF_begemotAtmIfMaxVccs:
+ value->v.uint32 = aif->pub.mib->max_vccs;
+ return (SNMP_ERR_NOERROR);
+
+ case LEAF_begemotAtmIfEsi:
+ return (string_get(value, aif->pub.mib->esi, 6));
+
+ case LEAF_begemotAtmIfCarrierStatus:
+ value->v.integer = aif->pub.carrier;
+ return (SNMP_ERR_NOERROR);
+
+ case LEAF_begemotAtmIfMode:
+ if ((err = atmif_get_mode(aif)) != SNMP_ERR_NOERROR)
+ return (err);
+ value->v.integer = aif->pub.mode;
+ return (SNMP_ERR_NOERROR);
+ }
+ abort();
+}
+
+/*
+ * Hardware table
+ */
+int
+op_atmhw(struct snmp_context *ctx __unused, struct snmp_value *value,
+ u_int sub, u_int vindex __unused, enum snmp_op op)
+{
+ struct atmif_priv *aif;
+ int err;
+
+ if ((err = atmif_get_aif(value, sub, op, &aif)) != SNMP_ERR_NOERROR)
+ return (err);
+ if (op == SNMP_OP_SET)
+ return (SNMP_ERR_NOT_WRITEABLE);
+
+ switch (value->var.subs[sub - 1]) {
+
+ case LEAF_begemotAtmHWVendor:
+ return (atm_sys_get_hw_vendor(aif, value));
+
+ case LEAF_begemotAtmHWDevice:
+ return (atm_sys_get_hw_device(aif, value));
+
+ case LEAF_begemotAtmHWSerial:
+ value->v.uint32 = aif->pub.mib->serial;
+ return (SNMP_ERR_NOERROR);
+
+ case LEAF_begemotAtmHWVersion:
+ value->v.uint32 = aif->pub.mib->hw_version;
+ return (SNMP_ERR_NOERROR);
+
+ case LEAF_begemotAtmHWSoftVersion:
+ value->v.uint32 = aif->pub.mib->sw_version;
+ return (SNMP_ERR_NOERROR);
+
+ }
+ abort();
+}
+
+/*
+ * Scalars
+ */
+int
+op_atm(struct snmp_context *ctx __unused, struct snmp_value *value,
+ u_int sub, u_int vindex __unused, enum snmp_op op)
+{
+ switch (op) {
+
+ case SNMP_OP_GETNEXT:
+ abort();
+
+ case SNMP_OP_GET:
+ switch (value->var.subs[sub - 1]) {
+
+ case LEAF_begemotAtmIfTableLastChange:
+ value->v.uint32 =
+ (last_change == 0 ? 0 : last_change - start_tick);
+ return (SNMP_ERR_NOERROR);
+ }
+ abort();
+
+ case SNMP_OP_SET:
+ return (SNMP_ERR_NOT_WRITEABLE);
+
+ case SNMP_OP_ROLLBACK:
+ case SNMP_OP_COMMIT:
+ abort();
+ }
+ abort();
+}
+
+/*
+ * Register for interface notifications
+ */
+void *
+atm_notify_aif(struct atmif *pub, const struct lmodule *mod,
+ atmif_event_f func, void *arg)
+{
+ struct atmif_priv *aif = (struct atmif_priv *)pub;
+ struct atmif_reg *r0;
+
+ if ((r0 = malloc(sizeof(*r0))) == NULL) {
+ syslog(LOG_CRIT, "out of memory");
+ return (NULL);
+ }
+ r0->func = func;
+ r0->mod = mod;
+ r0->data = arg;
+ r0->aif = aif;
+
+ TAILQ_INSERT_TAIL(&aif->notify, r0, link);
+
+ return (r0);
+}
+
+/*
+ * Unregister it
+ */
+void
+atm_unnotify_aif(void *arg)
+{
+ struct atmif_reg *r0 = arg;
+
+ TAILQ_REMOVE(&r0->aif->notify, r0, link);
+ free(r0);
+}
diff --git a/contrib/ngatm/snmp_atm/snmp_atm.h b/contrib/ngatm/snmp_atm/snmp_atm.h
new file mode 100644
index 000000000000..50784ccc45bb
--- /dev/null
+++ b/contrib/ngatm/snmp_atm/snmp_atm.h
@@ -0,0 +1,102 @@
+/*
+ * 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 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 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.
+ *
+ * $Begemot: libunimsg/snmp_atm/snmp_atm.h,v 1.2 2004/08/06 17:30:40 brandt Exp $
+ */
+#ifndef _BSNMP_SNMP_ATM_H
+#define _BSNMP_SNMP_ATM_H
+
+enum atmif_notify {
+ ATMIF_NOTIFY_DESTROY, /* interface has been destroyed */
+ ATMIF_NOTIFY_CARRIER, /* carriere change */
+ ATMIF_NOTIFY_VCC /* VCC change */
+};
+
+enum atmif_carrier_state {
+ ATMIF_CARRIER_ON = 1,
+ ATMIF_CARRIER_OFF = 2,
+ ATMIF_CARRIER_UNKNOWN = 3,
+ ATMIF_CARRIER_NONE = 4
+};
+
+enum atmif_suni_mode {
+ ATMIF_SUNI_MODE_SONET = 1,
+ ATMIF_SUNI_MODE_SDH = 2,
+ ATMIF_SUNI_MODE_UNKNOWN = 3
+};
+
+/* forward declaration */
+struct atmif;
+typedef void (*atmif_event_f)(struct atmif *, enum atmif_notify, uintptr_t,
+ void *);
+
+struct atmif_mib {
+ u_int version; /* currently 0 */
+
+ u_int device; /* type of hardware (system specific) */
+ u_int serial; /* card serial number (device specific) */
+ u_int hw_version; /* card version (device specific) */
+ u_int sw_version; /* firmware version (device specific) */
+ u_int media; /* physical media (see MIB) */
+
+ u_char esi[6]; /* end system identifier (MAC) */
+ u_int pcr; /* supported peak cell rate */
+ u_int vpi_bits; /* number of used bits in VPI field */
+ u_int vci_bits; /* number of used bits in VCI field */
+ u_int max_vpcs; /* maximum number of VPCs */
+ u_int max_vccs; /* maximum number of VCCs */
+};
+
+struct atmif {
+ struct mibif *ifp; /* common interface data */
+ struct atmif_mib *mib; /* ATM MIB */
+ enum atmif_carrier_state carrier;
+ enum atmif_suni_mode mode; /* SUNI mode SDH or SONET */
+};
+
+/* find an ATM interface by name */
+struct atmif *atm_find_if_name(const char *);
+
+/* get the interface from the interface index */
+struct atmif *atm_find_if(u_int);
+
+/* register for notifications */
+void *atm_notify_aif(struct atmif *, const struct lmodule *mod,
+ atmif_event_f, void *);
+void atm_unnotify_aif(void *);
+
+/* return the If for a system-specific node number */
+struct atmif *atm_node2if(u_int);
+
+/* return the node id for the if */
+u_int atm_if2node(struct atmif *);
+
+#endif