mibII.h revision 122394
1122394Sharti/*
2122394Sharti * Copyright (c) 2001-2003
3122394Sharti *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4122394Sharti *	All rights reserved.
5122394Sharti *
6122394Sharti * Author: Harti Brandt <harti@freebsd.org>
7122394Sharti *
8122394Sharti * Redistribution of this software and documentation and use in source and
9122394Sharti * binary forms, with or without modification, are permitted provided that
10122394Sharti * the following conditions are met:
11122394Sharti *
12122394Sharti * 1. Redistributions of source code or documentation must retain the above
13122394Sharti *    copyright notice, this list of conditions and the following disclaimer.
14122394Sharti * 2. Redistributions in binary form must reproduce the above copyright
15122394Sharti *    notice, this list of conditions and the following disclaimer in the
16122394Sharti *    documentation and/or other materials provided with the distribution.
17122394Sharti * 3. Neither the name of the Institute nor the names of its contributors
18122394Sharti *    may be used to endorse or promote products derived from this software
19122394Sharti *    without specific prior written permission.
20122394Sharti *
21122394Sharti * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY FRAUNHOFER FOKUS
22122394Sharti * AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23122394Sharti * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
24122394Sharti * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
25122394Sharti * FRAUNHOFER FOKUS OR ITS CONTRIBUTORS  BE LIABLE FOR ANY DIRECT, INDIRECT,
26122394Sharti * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27122394Sharti * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28122394Sharti * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29122394Sharti * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30122394Sharti * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31122394Sharti * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32122394Sharti *
33122394Sharti * $Begemot: bsnmp/snmp_mibII/mibII.h,v 1.11 2002/03/21 10:43:06 hbb Exp $
34122394Sharti *
35122394Sharti * Implementation of the interfaces and IP groups of MIB-II.
36122394Sharti */
37122394Sharti#include <sys/param.h>
38122394Sharti#include <sys/sysctl.h>
39122394Sharti#include <sys/socket.h>
40122394Sharti#include <sys/sockio.h>
41122394Sharti#include <sys/syslog.h>
42122394Sharti#include <sys/time.h>
43122394Sharti#include <stdio.h>
44122394Sharti#include <stdlib.h>
45122394Sharti#include <string.h>
46122394Sharti#include <errno.h>
47122394Sharti#include <unistd.h>
48122394Sharti#include <err.h>
49122394Sharti#include <ctype.h>
50122394Sharti#include <net/if.h>
51122394Sharti#include <net/if_dl.h>
52122394Sharti#include <net/if_mib.h>
53122394Sharti#include <net/route.h>
54122394Sharti#include <netinet/in.h>
55122394Sharti#include <arpa/inet.h>
56122394Sharti
57122394Sharti#include "asn1.h"
58122394Sharti#include "snmp.h"
59122394Sharti#include "snmpmod.h"
60122394Sharti#include "snmp_mibII.h"
61122394Sharti#include "mibII_tree.h"
62122394Sharti
63122394Sharti
64122394Sharti/*
65122394Sharti * Interface list and flags.
66122394Sharti */
67122394ShartiTAILQ_HEAD(mibif_list, mibif);
68122394Shartienum {
69122394Sharti	MIBIF_FOUND		= 0x0001,
70122394Sharti	MIBIF_HIGHSPEED		= 0x0002,
71122394Sharti	MIBIF_VERYHIGHSPEED	= 0x0004,
72122394Sharti};
73122394Sharti#define hc_inoctets	mib.ifmd_data.ifi_ibytes
74122394Sharti#define hc_outoctets	mib.ifmd_data.ifi_obytes
75122394Sharti#define hc_omcasts	mib.ifmd_data.ifi_omcasts
76122394Sharti#define hc_opackets	mib.ifmd_data.ifi_opackets
77122394Sharti#define hc_imcasts	mib.ifmd_data.ifi_imcasts
78122394Sharti#define hc_ipackets	mib.ifmd_data.ifi_ipackets
79122394Sharti
80122394Sharti/*
81122394Sharti * Interface addresses.
82122394Sharti */
83122394ShartiTAILQ_HEAD(mibifa_list, mibifa);
84122394Shartienum {
85122394Sharti	MIBIFA_FOUND	 = 0x0001,
86122394Sharti	MIBIFA_DESTROYED = 0x0002,
87122394Sharti};
88122394Sharti
89122394Sharti/*
90122394Sharti * Receive addresses
91122394Sharti */
92122394ShartiTAILQ_HEAD(mibrcvaddr_list, mibrcvaddr);
93122394Shartienum {
94122394Sharti	MIBRCVADDR_FOUND	= 0x00010000,
95122394Sharti};
96122394Sharti
97122394Sharti/*
98122394Sharti * Interface index mapping. The problem here is, that if the same interface
99122394Sharti * is reinstantiated (for examble by unloading and loading the hardware driver)
100122394Sharti * we must use the same index for this interface. For dynamic interfaces
101122394Sharti * (clip, lane) we must use a fresh index, each time a new interface is created.
102122394Sharti * To differentiate between these types of interfaces we use the following table
103122394Sharti * which contains an entry for each dynamic interface type. All other interface
104122394Sharti * types are supposed to be static. The mibindexmap contains an entry for
105122394Sharti * all interfaces. The mibif pointer is NULL, if the interface doesn't exist
106122394Sharti * anymore.
107122394Sharti */
108122394Shartistruct mibdynif {
109122394Sharti	SLIST_ENTRY(mibdynif) link;
110122394Sharti	char	name[IFNAMSIZ];
111122394Sharti};
112122394ShartiSLIST_HEAD(mibdynif_list, mibdynif);
113122394Sharti
114122394Shartistruct mibindexmap {
115122394Sharti	STAILQ_ENTRY(mibindexmap) link;
116122394Sharti	u_short		sysindex;
117122394Sharti	u_int		ifindex;
118122394Sharti	struct mibif	*mibif;		/* may be NULL */
119122394Sharti	char		name[IFNAMSIZ];
120122394Sharti};
121122394ShartiSTAILQ_HEAD(mibindexmap_list, mibindexmap);
122122394Sharti
123122394Sharti/*
124122394Sharti * Interface stacking. The generic code cannot know how the interfaces stack.
125122394Sharti * For this reason it instantiates only the x.0 and 0.x table elements. All
126122394Sharti * others have to be instantiated by the interface specific modules.
127122394Sharti * The table is read-only.
128122394Sharti */
129122394Shartistruct mibifstack {
130122394Sharti	TAILQ_ENTRY(mibifstack) link;
131122394Sharti	struct asn_oid index;
132122394Sharti};
133122394ShartiTAILQ_HEAD(mibifstack_list, mibifstack);
134122394Sharti
135122394Sharti/*
136122394Sharti * NetToMediaTable (ArpTable)
137122394Sharti */
138122394Shartistruct mibarp {
139122394Sharti	TAILQ_ENTRY(mibarp) link;
140122394Sharti	struct asn_oid	index;		/* contains both the ifindex and addr */
141122394Sharti	u_char		phys[128];	/* the physical address */
142122394Sharti	u_int		physlen;	/* and its length */
143122394Sharti	u_int		flags;
144122394Sharti};
145122394ShartiTAILQ_HEAD(mibarp_list, mibarp);
146122394Shartienum {
147122394Sharti	MIBARP_FOUND	= 0x00010000,
148122394Sharti	MIBARP_PERM	= 0x00000001,
149122394Sharti};
150122394Sharti
151122394Sharti/*
152122394Sharti * New if registrations
153122394Sharti */
154122394Shartistruct newifreg {
155122394Sharti	TAILQ_ENTRY(newifreg) link;
156122394Sharti	const struct lmodule *mod;
157122394Sharti	int	(*func)(struct mibif *);
158122394Sharti};
159122394ShartiTAILQ_HEAD(newifreg_list, newifreg);
160122394Sharti
161122394Sharti/* list of all IP addresses */
162122394Shartiextern struct mibifa_list mibifa_list;
163122394Sharti
164122394Sharti/* list of all interfaces */
165122394Shartiextern struct mibif_list mibif_list;
166122394Sharti
167122394Sharti/* list of dynamic interface names */
168122394Shartiextern struct mibdynif_list mibdynif_list;
169122394Sharti
170122394Sharti/* list of all interface index mappings */
171122394Shartiextern struct mibindexmap_list mibindexmap_list;
172122394Sharti
173122394Sharti/* list of all stacking entries */
174122394Shartiextern struct mibifstack_list mibifstack_list;
175122394Sharti
176122394Sharti/* list of all receive addresses */
177122394Shartiextern struct mibrcvaddr_list mibrcvaddr_list;
178122394Sharti
179122394Sharti/* list of all NetToMedia entries */
180122394Shartiextern struct mibarp_list mibarp_list;
181122394Sharti
182122394Sharti/* number of interfaces */
183122394Shartiextern int32_t mib_if_number;
184122394Sharti
185122394Sharti/* last change of interface table */
186122394Shartiextern u_int32_t mib_iftable_last_change;
187122394Sharti
188122394Sharti/* last change of stack table */
189122394Shartiextern u_int32_t mib_ifstack_last_change;
190122394Sharti
191122394Sharti/* if this is set, one of our lists may be bad. refresh them when idle */
192122394Shartiextern int mib_iflist_bad;
193122394Sharti
194122394Sharti/* last time refreshed */
195122394Shartiextern u_int32_t mibarpticks;
196122394Sharti
197122394Sharti/* info on system clocks */
198122394Shartiextern struct clockinfo clockinfo;
199122394Sharti
200122394Sharti/* get interfaces and interface addresses. */
201122394Shartivoid mib_fetch_interfaces(void);
202122394Sharti
203122394Sharti/* check whether this interface(type) is dynamic */
204122394Shartiint mib_if_is_dyn(const char *name);
205122394Sharti
206122394Sharti/* destroy an interface address */
207122394Shartiint mib_destroy_ifa(struct mibifa *);
208122394Sharti
209122394Sharti/* restituate a deleted interface address */
210122394Shartivoid mib_undestroy_ifa(struct mibifa *);
211122394Sharti
212122394Sharti/* change interface address */
213122394Shartiint mib_modify_ifa(struct mibifa *);
214122394Sharti
215122394Sharti/* undo if address modification */
216122394Shartivoid mib_unmodify_ifa(struct mibifa *);
217122394Sharti
218122394Sharti/* create an interface address */
219122394Shartistruct mibifa * mib_create_ifa(u_int ifindex, struct in_addr addr, struct in_addr mask, struct in_addr bcast);
220122394Sharti
221122394Sharti/* delete a freshly created address */
222122394Shartivoid mib_uncreate_ifa(struct mibifa *);
223122394Sharti
224122394Sharti/* create/delete arp entries */
225122394Shartistruct mibarp *mib_arp_create(const struct mibif *, struct in_addr, const u_char *, size_t);
226122394Shartivoid mib_arp_delete(struct mibarp *);
227122394Sharti
228122394Sharti/* find arp entry */
229122394Shartistruct mibarp *mib_find_arp(const struct mibif *, struct in_addr);
230122394Sharti
231122394Sharti/* update arp table */
232122394Shartivoid mib_arp_update(void);
233122394Sharti
234122394Sharti/* fetch routing table */
235122394Shartiu_char *mib_fetch_rtab(int af, int info, int arg, size_t *lenp);
236122394Sharti
237122394Sharti/* extract addresses from routing message */
238122394Shartivoid mib_extract_addrs(int, u_char *, struct sockaddr **);
239