2 * Copyright (c) 2001-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
6 * Author: Harti Brandt <harti@freebsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $Begemot: bsnmp/snmp_mibII/mibII.h,v 1.16 2006/02/14 09:04:19 brandt_h Exp $
31 * Implementation of the interfaces and IP groups of MIB-II.
33 #include <sys/param.h>
34 #include <sys/sysctl.h>
35 #include <sys/socket.h>
36 #include <sys/sockio.h>
37 #include <sys/syslog.h>
48 #include <net/if_dl.h>
49 #include <net/if_mib.h>
50 #include <net/route.h>
51 #include <netinet/in.h>
52 #include <arpa/inet.h>
57 #include "snmp_mibII.h"
58 #include "mibII_tree.h"
60 /* maximum size of the interface alias unless overridden with net.ifdescr_maxlen */
61 #define MIBIF_ALIAS_SIZE (64 + 1)
62 #define MIBIF_ALIAS_SIZE_MAX 1024
65 * Interface list and flags.
67 TAILQ_HEAD(mibif_list, mibif);
70 MIBIF_HIGHSPEED = 0x0002,
71 MIBIF_VERYHIGHSPEED = 0x0004,
75 * Private mibif data - hang off from the mibif.
77 struct mibif_private {
79 uint64_t hc_outoctets;
86 #define MIBIF_PRIV(IFP) ((struct mibif_private *)((IFP)->private))
89 * Interface addresses.
91 TAILQ_HEAD(mibifa_list, mibifa);
93 MIBIFA_FOUND = 0x0001,
94 MIBIFA_DESTROYED = 0x0002,
100 TAILQ_HEAD(mibrcvaddr_list, mibrcvaddr);
102 MIBRCVADDR_FOUND = 0x00010000,
106 * Interface index mapping. The problem here is, that if the same interface
107 * is reinstantiated (for examble by unloading and loading the hardware driver)
108 * we must use the same index for this interface. For dynamic interfaces
109 * (clip, lane) we must use a fresh index, each time a new interface is created.
110 * To differentiate between these types of interfaces we use the following table
111 * which contains an entry for each dynamic interface type. All other interface
112 * types are supposed to be static. The mibindexmap contains an entry for
113 * all interfaces. The mibif pointer is NULL, if the interface doesn't exist
117 SLIST_ENTRY(mibdynif) link;
120 SLIST_HEAD(mibdynif_list, mibdynif);
123 STAILQ_ENTRY(mibindexmap) link;
126 struct mibif *mibif; /* may be NULL */
129 STAILQ_HEAD(mibindexmap_list, mibindexmap);
132 * Interface stacking. The generic code cannot know how the interfaces stack.
133 * For this reason it instantiates only the x.0 and 0.x table elements. All
134 * others have to be instantiated by the interface specific modules.
135 * The table is read-only.
138 TAILQ_ENTRY(mibifstack) link;
139 struct asn_oid index;
141 TAILQ_HEAD(mibifstack_list, mibifstack);
144 * NetToMediaTable (ArpTable)
147 TAILQ_ENTRY(mibarp) link;
148 struct asn_oid index; /* contains both the ifindex and addr */
149 u_char phys[128]; /* the physical address */
150 u_int physlen; /* and its length */
153 TAILQ_HEAD(mibarp_list, mibarp);
155 MIBARP_FOUND = 0x00010000,
156 MIBARP_PERM = 0x00000001,
160 * New if registrations
163 TAILQ_ENTRY(newifreg) link;
164 const struct lmodule *mod;
165 int (*func)(struct mibif *);
167 TAILQ_HEAD(newifreg_list, newifreg);
169 /* list of all IP addresses */
170 extern struct mibifa_list mibifa_list;
172 /* list of all interfaces */
173 extern struct mibif_list mibif_list;
175 /* list of dynamic interface names */
176 extern struct mibdynif_list mibdynif_list;
178 /* list of all interface index mappings */
179 extern struct mibindexmap_list mibindexmap_list;
181 /* list of all stacking entries */
182 extern struct mibifstack_list mibifstack_list;
184 /* list of all receive addresses */
185 extern struct mibrcvaddr_list mibrcvaddr_list;
187 /* list of all NetToMedia entries */
188 extern struct mibarp_list mibarp_list;
190 /* number of interfaces */
191 extern int32_t mib_if_number;
193 /* last change of interface table */
194 extern uint64_t mib_iftable_last_change;
196 /* last change of stack table */
197 extern uint64_t mib_ifstack_last_change;
199 /* if this is set, one of our lists may be bad. refresh them when idle */
200 extern int mib_iflist_bad;
202 /* last time refreshed */
203 extern uint64_t mibarpticks;
205 /* info on system clocks */
206 extern struct clockinfo clockinfo;
208 /* baud rate of fastest interface */
209 extern uint64_t mibif_maxspeed;
211 /* user-forced update interval */
212 extern u_int mibif_force_hc_update_interval;
214 /* current update interval */
215 extern u_int mibif_hc_update_interval;
217 /* re-compute update interval */
218 void mibif_reset_hc_timer(void);
220 /* interfaces' data poll interval */
221 extern u_int mibII_poll_ticks;
223 /* restart the data poll timer */
224 void mibif_restart_mibII_poll_timer(void);
226 #define MIBII_POLL_TICKS 100
228 /* get interfaces and interface addresses. */
229 void mib_fetch_interfaces(void);
231 /* check whether this interface(type) is dynamic */
232 int mib_if_is_dyn(const char *name);
234 /* destroy an interface address */
235 int mib_destroy_ifa(struct mibifa *);
237 /* restituate a deleted interface address */
238 void mib_undestroy_ifa(struct mibifa *);
240 /* change interface address */
241 int mib_modify_ifa(struct mibifa *);
243 /* undo if address modification */
244 void mib_unmodify_ifa(struct mibifa *);
246 /* create an interface address */
247 struct mibifa * mib_create_ifa(u_int ifindex, struct in_addr addr, struct in_addr mask, struct in_addr bcast);
249 /* delete a freshly created address */
250 void mib_uncreate_ifa(struct mibifa *);
252 /* create/delete arp entries */
253 struct mibarp *mib_arp_create(const struct mibif *, struct in_addr, const u_char *, size_t);
254 void mib_arp_delete(struct mibarp *);
257 struct mibarp *mib_find_arp(const struct mibif *, struct in_addr);
259 /* update arp table */
260 void mib_arp_update(void);
262 /* fetch routing table */
263 u_char *mib_fetch_rtab(int af, int info, int arg, size_t *lenp);
265 /* process routing message */
266 void mib_sroute_process(struct rt_msghdr *, struct sockaddr *,
267 struct sockaddr *, struct sockaddr *);
269 /* send a routing message */
270 void mib_send_rtmsg(struct rt_msghdr *, struct sockaddr *,
271 struct sockaddr *, struct sockaddr *);
273 /* extract addresses from routing message */
274 void mib_extract_addrs(int, u_char *, struct sockaddr **);
276 /* fetch routing table */
277 int mib_fetch_route(void);