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>
47 #include <net/if_dl.h>
48 #include <net/if_mib.h>
49 #include <net/route.h>
50 #include <netinet/in.h>
51 #include <arpa/inet.h>
56 #include "snmp_mibII.h"
57 #include "mibII_tree.h"
60 * Interface list and flags.
62 TAILQ_HEAD(mibif_list, mibif);
65 MIBIF_HIGHSPEED = 0x0002,
66 MIBIF_VERYHIGHSPEED = 0x0004,
70 * Private mibif data - hang off from the mibif.
72 struct mibif_private {
74 uint64_t hc_outoctets;
80 #define MIBIF_PRIV(IFP) ((struct mibif_private *)((IFP)->private))
83 * Interface addresses.
85 TAILQ_HEAD(mibifa_list, mibifa);
87 MIBIFA_FOUND = 0x0001,
88 MIBIFA_DESTROYED = 0x0002,
94 TAILQ_HEAD(mibrcvaddr_list, mibrcvaddr);
96 MIBRCVADDR_FOUND = 0x00010000,
100 * Interface index mapping. The problem here is, that if the same interface
101 * is reinstantiated (for examble by unloading and loading the hardware driver)
102 * we must use the same index for this interface. For dynamic interfaces
103 * (clip, lane) we must use a fresh index, each time a new interface is created.
104 * To differentiate between these types of interfaces we use the following table
105 * which contains an entry for each dynamic interface type. All other interface
106 * types are supposed to be static. The mibindexmap contains an entry for
107 * all interfaces. The mibif pointer is NULL, if the interface doesn't exist
111 SLIST_ENTRY(mibdynif) link;
114 SLIST_HEAD(mibdynif_list, mibdynif);
117 STAILQ_ENTRY(mibindexmap) link;
120 struct mibif *mibif; /* may be NULL */
123 STAILQ_HEAD(mibindexmap_list, mibindexmap);
126 * Interface stacking. The generic code cannot know how the interfaces stack.
127 * For this reason it instantiates only the x.0 and 0.x table elements. All
128 * others have to be instantiated by the interface specific modules.
129 * The table is read-only.
132 TAILQ_ENTRY(mibifstack) link;
133 struct asn_oid index;
135 TAILQ_HEAD(mibifstack_list, mibifstack);
138 * NetToMediaTable (ArpTable)
141 TAILQ_ENTRY(mibarp) link;
142 struct asn_oid index; /* contains both the ifindex and addr */
143 u_char phys[128]; /* the physical address */
144 u_int physlen; /* and its length */
147 TAILQ_HEAD(mibarp_list, mibarp);
149 MIBARP_FOUND = 0x00010000,
150 MIBARP_PERM = 0x00000001,
154 * New if registrations
157 TAILQ_ENTRY(newifreg) link;
158 const struct lmodule *mod;
159 int (*func)(struct mibif *);
161 TAILQ_HEAD(newifreg_list, newifreg);
163 /* list of all IP addresses */
164 extern struct mibifa_list mibifa_list;
166 /* list of all interfaces */
167 extern struct mibif_list mibif_list;
169 /* list of dynamic interface names */
170 extern struct mibdynif_list mibdynif_list;
172 /* list of all interface index mappings */
173 extern struct mibindexmap_list mibindexmap_list;
175 /* list of all stacking entries */
176 extern struct mibifstack_list mibifstack_list;
178 /* list of all receive addresses */
179 extern struct mibrcvaddr_list mibrcvaddr_list;
181 /* list of all NetToMedia entries */
182 extern struct mibarp_list mibarp_list;
184 /* number of interfaces */
185 extern int32_t mib_if_number;
187 /* last change of interface table */
188 extern uint64_t mib_iftable_last_change;
190 /* last change of stack table */
191 extern uint64_t mib_ifstack_last_change;
193 /* if this is set, one of our lists may be bad. refresh them when idle */
194 extern int mib_iflist_bad;
196 /* last time refreshed */
197 extern uint64_t mibarpticks;
199 /* info on system clocks */
200 extern struct clockinfo clockinfo;
202 /* baud rate of fastest interface */
203 extern uint64_t mibif_maxspeed;
205 /* user-forced update interval */
206 extern u_int mibif_force_hc_update_interval;
208 /* current update interval */
209 extern u_int mibif_hc_update_interval;
211 /* re-compute update interval */
212 void mibif_reset_hc_timer(void);
214 /* get interfaces and interface addresses. */
215 void mib_fetch_interfaces(void);
217 /* check whether this interface(type) is dynamic */
218 int mib_if_is_dyn(const char *name);
220 /* destroy an interface address */
221 int mib_destroy_ifa(struct mibifa *);
223 /* restituate a deleted interface address */
224 void mib_undestroy_ifa(struct mibifa *);
226 /* change interface address */
227 int mib_modify_ifa(struct mibifa *);
229 /* undo if address modification */
230 void mib_unmodify_ifa(struct mibifa *);
232 /* create an interface address */
233 struct mibifa * mib_create_ifa(u_int ifindex, struct in_addr addr, struct in_addr mask, struct in_addr bcast);
235 /* delete a freshly created address */
236 void mib_uncreate_ifa(struct mibifa *);
238 /* create/delete arp entries */
239 struct mibarp *mib_arp_create(const struct mibif *, struct in_addr, const u_char *, size_t);
240 void mib_arp_delete(struct mibarp *);
243 struct mibarp *mib_find_arp(const struct mibif *, struct in_addr);
245 /* update arp table */
246 void mib_arp_update(void);
248 /* fetch routing table */
249 u_char *mib_fetch_rtab(int af, int info, int arg, size_t *lenp);
251 /* process routing message */
252 void mib_sroute_process(struct rt_msghdr *, struct sockaddr *,
253 struct sockaddr *, struct sockaddr *);
255 /* send a routing message */
256 void mib_send_rtmsg(struct rt_msghdr *, struct sockaddr *,
257 struct sockaddr *, struct sockaddr *);
259 /* extract addresses from routing message */
260 void mib_extract_addrs(int, u_char *, struct sockaddr **);
262 /* fetch routing table */
263 int mib_fetch_route(void);