xref: /freebsd/contrib/bsnmp/snmp_mibII/snmp_mibII.h (revision d37ea99837e6ad50837fd9fe1771ddf1c3ba6002)
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.h,v 1.14 2003/12/03 10:01:19 hbb Exp $
34  *
35  * Implementation of the interfaces and IP groups of MIB-II.
36  */
37 #ifndef snmp_mibII_h_
38 #define snmp_mibII_h_
39 
40 /* forward declaration */
41 struct mibif;
42 
43 enum mibif_notify {
44 	MIBIF_NOTIFY_DESTROY
45 };
46 
47 typedef void (*mibif_notify_f)(struct mibif *, enum mibif_notify, void *);
48 
49 /*
50  * Interfaces. This structure describes one interface as seen in the MIB.
51  * Interfaces are indexed by ifindex. This is not the same as the index
52  * used by the system because of the rules in RFC-2863 section 3.1.5. This
53  * RFC requires, that an ifindex is not to be re-used for ANOTHER dynamically
54  * interfaces once the interface was deleted. The system's ifindex is in
55  * sysindex. Mapping is via the mapping table below.
56  */
57 struct mibif {
58 	TAILQ_ENTRY(mibif) link;
59 	u_int		flags;
60 	u_int		index;		/* the logical ifindex */
61 	u_int		sysindex;
62 	char		name[IFNAMSIZ];
63 	char		descr[256];
64 	struct ifmibdata mib;
65 	u_int32_t	mibtick;
66 	void		*specmib;
67 	size_t		specmiblen;
68 	u_char		*physaddr;
69 	u_int		physaddrlen;
70 	int		has_connector;
71 	int		trap_enable;
72 	u_int32_t	counter_disc;
73 
74 	/*
75 	 * This is needed to handle interface type specific information
76 	 * in sub-modules. It contains a function pointer which handles
77 	 * notifications and a data pointer to arbitrary data.
78 	 * Should be set via the mibif_notify function.
79 	 */
80 	mibif_notify_f	xnotify;
81 	void		*xnotify_data;
82 	const struct lmodule *xnotify_mod;
83 };
84 
85 /*
86  * Interface IP-address table.
87  */
88 struct mibifa {
89 	TAILQ_ENTRY(mibifa) link;
90 	struct in_addr	inaddr;
91 	struct in_addr	inmask;
92 	struct in_addr	inbcast;
93 	struct asn_oid	index;		/* index for table search */
94 	u_int		ifindex;
95 	u_int		flags;
96 };
97 
98 /*
99  * Interface receive addresses. Interface link-level multicast, broadcast
100  * and hardware addresses are handled automatically.
101  */
102 struct mibrcvaddr {
103 	TAILQ_ENTRY(mibrcvaddr) link;
104 	struct asn_oid	index;
105 	u_int		ifindex;
106 	u_char		addr[ASN_MAXOIDLEN];
107 	size_t		addrlen;
108 	u_int		flags;
109 };
110 enum {
111 	MIBRCVADDR_VOLATILE	= 0x00000001,
112 	MIBRCVADDR_BCAST	= 0x00000002,
113 	MIBRCVADDR_HW		= 0x00000004,
114 };
115 
116 /* network socket */
117 extern int mib_netsock;
118 
119 /* set an interface name to dynamic mode */
120 void mib_if_set_dyn(const char *);
121 
122 /* re-read the systems interface list */
123 void mib_refresh_iflist(void);
124 
125 /* find interface by index */
126 struct mibif *mib_find_if(u_int);
127 struct mibif *mib_find_if_sys(u_int);
128 struct mibif *mib_find_if_name(const char *);
129 
130 /* iterate through all interfaces */
131 struct mibif *mib_first_if(void);
132 struct mibif *mib_next_if(const struct mibif *);
133 
134 /* register for interface creations */
135 int mib_register_newif(int (*)(struct mibif *), const struct lmodule *);
136 void mib_unregister_newif(const struct lmodule *);
137 
138 /* get fresh MIB data */
139 int mib_fetch_ifmib(struct mibif *);
140 
141 /* change the ADMIN status of an interface and refresh the MIB */
142 int mib_if_admin(struct mibif *, int up);
143 
144 /* find interface address by address */
145 struct mibifa *mib_find_ifa(struct in_addr);
146 
147 /* find first/next address for a given interface */
148 struct mibifa *mib_first_ififa(const struct mibif *);
149 struct mibifa *mib_next_ififa(struct mibifa *);
150 
151 /* create/delete stacking entries */
152 int mib_ifstack_create(const struct mibif *lower, const struct mibif *upper);
153 void mib_ifstack_delete(const struct mibif *lower, const struct mibif *upper);
154 
155 /* find receive address */
156 struct mibrcvaddr *mib_find_rcvaddr(u_int, const u_char *, size_t);
157 
158 /* create/delete receive addresses */
159 struct mibrcvaddr *mib_rcvaddr_create(struct mibif *, const u_char *, size_t);
160 void mib_rcvaddr_delete(struct mibrcvaddr *);
161 
162 /* register for interface notification */
163 void *mibif_notify(struct mibif *, const struct lmodule *, mibif_notify_f,
164     void *);
165 void mibif_unnotify(void *);
166 
167 #endif
168