1.\" 2.\" Copyright (c) 2001-2003 3.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4.\" All rights reserved. 5.\" 6.\" Author: Harti Brandt <harti@freebsd.org> 7.\" 8.\" Redistribution of this software and documentation and use in source and 9.\" binary forms, with or without modification, are permitted provided that 10.\" the following conditions are met: 11.\" 12.\" 1. Redistributions of source code or documentation must retain the above 13.\" copyright notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. Neither the name of the Institute nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY FRAUNHOFER FOKUS 22.\" AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 23.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 24.\" FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 25.\" FRAUNHOFER FOKUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 28.\" OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32.\" 33.\" $Begemot: bsnmp/snmp_mibII/snmp_mibII.3,v 1.3 2004/04/13 17:01:31 novo Exp $ 34.\" 35.Dd August 19, 2002 36.Dt snmp_mibII 3 37.Os 38.Sh NAME 39.Nm mibII , 40.Nm mibif_notify_f , 41.Nm mib_netsock , 42.Nm mib_if_set_dyn , 43.Nm mib_refresh_iflist , 44.Nm mib_find_if , 45.Nm mib_find_if_sys , 46.Nm mib_find_if_name , 47.Nm mib_first_if , 48.Nm mib_next_if , 49.Nm mib_register_newif , 50.Nm mib_unregister_newif , 51.Nm mib_fetch_ifmib , 52.Nm mib_if_admin , 53.Nm mib_find_ifa , 54.Nm mib_first_ififa , 55.Nm mib_next_ififa , 56.Nm mib_ifstack_create , 57.Nm mib_ifstack_delete , 58.Nm mib_find_rcvaddr , 59.Nm mib_rcvaddr_create , 60.Nm mib_rcvaddr_delete , 61.Nm mibif_notify , 62.Nm mibif_unnotify 63.Nd "mib-2 module for snmpd. 64.Sh LIBRARY 65.Pq begemotSnmpdModulePath."mibII" = "@MODPATH@snmp_mibII.so" 66.Sh SYNOPSIS 67.In bsnmp/snmpmod.h 68.In bsnmp/snmp_mibII.h 69.Ft typedef void 70.Fn (*mibif_notify_f) "struct mibif *ifp" "enum mibif_notify event" "void *uarg" 71.Vt extern int mib_netsock ; 72.Ft void 73.Fn mib_if_set_dyn "const char *ifname" 74.Ft void 75.Fn mib_refresh_iflist "void" 76.Ft struct mibif * 77.Fn mib_find_if "u_int ifindex" 78.Ft struct mibif * 79.Fn mib_find_if_sys "u_int sysindex" 80.Ft struct mibif * 81.Fn mib_find_if_name "const char *ifname" 82.Ft struct mibif * 83.Fn mib_first_if "void" 84.Ft struct mibif * 85.Fn mib_next_if "const struct mibif *ifp" 86.Ft int 87.Fn mib_register_newif "int (*func)(struct mibif *)" "const struct lmodule *mod" 88.Ft void 89.Fn mib_unregister_newif "const struct lmodule *mod" 90.Ft int 91.Fn mib_fetch_ifmib "struct mibif *ifp" 92.Ft int 93.Fn mib_if_admin "struct mibif *ifp" "int up" 94.Ft struct mibifa * 95.Fn mib_find_ifa "struct in_addr ipa" 96.Ft struct mibifa * 97.Fn mib_first_ififa "const struct mibif *ifp" 98.Ft struct mibifa * 99.Fn mib_next_ififa "struct mibifa *ifa" 100.Ft int 101.Fn mib_ifstack_create "const struct mibif *lower" "const struct mibif *upper" 102.Ft void 103.Fn mib_ifstack_delete "const struct mibif *lower" "const struct mibif *upper" 104.Ft struct mibrcvaddr * 105.Fn mib_find_rcvaddr "u_int ifindex" "const u_char *addr" "size_t addrlen" 106.Ft struct mibrcvaddr * 107.Fn mib_rcvaddr_create "struct mibif *ifp" "const u_char *addr" "size_t addrlen" 108.Ft void 109.Fn mib_rcvaddr_delete "struct mibrcvaddr *addr" 110.Ft void * 111.Fn mibif_notify "struct mibif *ifp" "const struct lmodule *mod" "mibif_notify_f func" "void *uarg" 112.Ft void 113.Fn mibif_unnotify "void *reg" 114.Sh DESCRIPTION 115The 116.Nm snmp_mibII 117module implements parts of the internet standard MIB-2. Most of the relevant 118MIBs are implemented. Some of the tables are restricted to be read-only 119instead of read-write. The exact current implementation can be found in 120.Pa @DEFPATH@mibII_tree.def . 121The module also exports a number of functions and global variables for use 122by other modules, that need to handle network interfaces. This man page describes 123these functions. 124.Ss DIRECT NETWORK ACCESS 125The 126.Nm 127module opens a socket that is used to execute all network related 128.Xr ioctl 2 129functions. This socket is globally available under the name 130.Va mib_netsock . 131.Ss NETWORK INTERFACES 132The 133.Nm 134module handles a list of all currently existing network interfaces. It allows 135other modules to handle their own interface lists with special information 136by providing a mechanism to register to events that change the interface list 137(see below). The basic data structure is the interface structure: 138.Bd -literal -offset indent 139struct mibif { 140 TAILQ_ENTRY(mibif) link; 141 u_int flags; 142 u_int index; /* logical ifindex */ 143 u_int sysindex; 144 char name[IFNAMSIZ]; 145 char descr[256]; 146 struct ifmibdata mib; 147 u_int32_t mibtick; 148 void *specmib; 149 size_t specmiblen; 150 u_char *physaddr; 151 u_int physaddrlen; 152 int has_connector; 153 int trap_enable; 154 u_int32_t counter_disc; 155 mibif_notify_f xnotify; 156 void *xnotify_data; 157 const struct lmodule *xnotify_mod; 158}; 159.Ed 160.Pp 161The 162.Nm 163module tries to implement the semantic if 164.Va ifIndex 165as described in RFC-2863. This RFC states, that an interface indexes may not 166be reused. That means, for example, if 167.Pa tun 168is a synthetic interface type and the system creates the interface 169.Pa tun0 , 170destroys this interfaces and again creates a 171.Pa tun 0 , 172then these interfaces must have different interface indexes, because in fact 173they are different interfaces. If, on the other hand, there is a hardware 174interface 175.Pa xl0 176and this interface disappears, because its driver is unloaded and appears 177again, because the driver is loaded again, the interface index must stay 178the same. 179.Nm 180implements this by differentiating between real and synthetic (dynamic) 181interfaces. An interface type can be declared dynamic by calling the function 182.Fn mib_if_set_dyn 183with the name if the interface type (for example 184.Qq tun ). 185For real interfaces, the module keeps the mapping between the interface name 186and its 187.Va ifIndex 188in a special list, if the interface is unloaded. For dynamic interfaces 189a new 190.Va ifIndex 191is generated each time the interface comes into existance. This 192means, that the interface index as seen by SNMP is not the same index 193as used by the system. The SNMP 194.Va ifIndex 195is held in field 196.Va index , 197the system's interface index is 198.Va sysindex . 199.Pp 200A call to 201.Nm mib_refresh_iflist 202causes the entire interface list to be re-created. 203.Pp 204The interface list can be traversed with the functions 205.Fn mib_first_if 206and 207.Fn mib_next_if . 208Be sure not to change the interface list while traversing the list with 209these two calls. 210.Pp 211There are three functions to find an interface by name or index. 212.Fn mib_find_if 213finds an interface by searching for an SNMP 214.Va ifIndex , 215.Fn mib_find_if_sys 216finds an interface by searching for a system interface index and 217.Fn mib_find_if_name 218finds an interface by looking for an interface name. Each of the 219function returns 220.Li NULL 221if the interface cannot be found. 222.Pp 223The function 224.Fn mib_fetch_ifmib 225causes the interface MIB to be refreshed from the kernel. 226.Pp 227The function 228.Fn mib_if_admin 229can be used to change the interface administrative state to up 230(argument is 1) or down (argument is 0). 231.Ss INTERFACE EVENTS 232A module can register itself to receive a notification when a new entry is 233created in the interface list. This is done by calling 234.Fn mib_register_newif . 235A module can register only one function, a second call to 236.Fn mib_register_newif 237causes the registration to be overwritten. The registration can be removed 238with a call to 239.Fn mib_unregister_newif . 240If is unregistered automatically, when the registering module is unloaded. 241.Pp 242A module can also register to events on a specific interface. This is done 243by calling 244.Fn mibif_notify . 245This causes the given callback 246.Fa func 247to be called with the interface pointer, a notification code and 248the user argument 249.Fa uarg 250when any of the following events occur: 251.Bl -tag -width "XXXXX" 252.It Li MIBIF_NOTIFY_DESTROY 253The interface is destroyed. 254.El 255.Pp 256This mechanism can be used to implement interface type specific MIB parts 257in other modules. The registration can be removed with 258.Fn mib_unnotify 259which the return value from 260.Fa mib_notify . 261Any notification registration is removed automatically when the interface 262is destroyed or the registering module is unloaded. 263.Em Note that only one module can register to any given interface . 264.Ss INTERFACE ADDRESSES 265The 266.Nm 267module handles a table of interface IP-addresses. These addresses are held 268in a 269.Bd -literal -offset indent 270struct mibifa { 271 TAILQ_ENTRY(mibifa) link; 272 struct in_addr inaddr; 273 struct in_addr inmask; 274 struct in_addr inbcast; 275 struct asn_oid index; 276 u_int ifindex; 277 u_int flags; 278}; 279.Ed 280.Pp 281The (ordered) list of IP-addresses on a given interface can be traversed by 282calling 283.Fn mib_first_ififa 284and 285.Fn mib_next_ififa . 286The list should not be considered read-only. 287.Ss INTERFACE RECEIVE ADDRESSES 288The internet MIB-2 contains a table of interface receive addresses. These 289addresses are handled in: 290.Bd -literal -offset indent 291struct mibrcvaddr { 292 TAILQ_ENTRY(mibrcvaddr) link; 293 struct asn_oid index; 294 u_int ifindex; 295 u_char addr[ASN_MAXOIDLEN]; 296 size_t addrlen; 297 u_int flags; 298}; 299enum { 300 MIBRCVADDR_VOLATILE = 0x00000001, 301 MIBRCVADDR_BCAST = 0x00000002, 302 MIBRCVADDR_HW = 0x00000004, 303}; 304.Ed 305.Pp 306Note, that the assignment of 307.Li MIBRCVADDR_BCAST 308is based on a list of known interface types. The flags should be handled 309by modules inplementing interface type specific MIBs. 310.Pp 311A receive address can be created with 312.Fn mib_rcvaddr_create 313and deleted with 314.Fn mib_rcvaddr_delete . 315This needs to be done only for addresses that are not automatically handled 316by the system. 317.Pp 318A receive address can be found with 319.Fn mib_find_rcvaddr . 320.Ss INTERFACE STACK TABLE 321The 322.Nm 323module maintains also the interface stack table. Because for complex stacks, 324there is no system supported generic way of getting this information, interface 325type specific modules need to help setting up stack entries. The 326.Nm 327module handles only the top and bottom entries. 328.Pp 329A table entry is created with 330.Fn mib_ifstack_create 331and deleted with 332.Fn mib_ifstack_delete . 333Both functions need the pointers to the interfaces. Entries are automatically 334deleted if any of the interfaces of the entry is destroyed. The functions handle 335both the stack table and the reverse stack table. 336.Sh FILES 337.Bl -tag -width ".It Pa @DEFPATH@mibII_tree.def" -compact 338.It Pa @DEFPATH@mibII_tree.def 339The description of the MIB tree implemented by 340.Nm . 341.It Pa /usr/local/share/snmp/mibs 342.It Pa @MIBSPATH@ 343The various internet MIBs. 344.Sh SEE ALSO 345.Xr snmpmod 3 , 346.Xr gensnmptree 1 347.Sh STANDARDS 348This implementation conforms to the applicable IETF RFCs. 349.Sh AUTHORS 350.An Hartmut Brandt Aq harti@freebsd.org 351