summaryrefslogtreecommitdiffstats
path: root/contrib/bsnmp/snmp_mibII/mibII.h
blob: 4b0803d12f2b6c4ac8bd775117a96d5b1240977c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
 * Copyright (c) 2001-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 *	All rights reserved.
 *
 * Author: Harti Brandt <harti@freebsd.org>
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Begemot: bsnmp/snmp_mibII/mibII.h,v 1.15 2005/06/09 12:36:53 brandt_h Exp $
 *
 * Implementation of the interfaces and IP groups of MIB-II.
 */
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/syslog.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <err.h>
#include <ctype.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_mib.h>
#include <net/route.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include "asn1.h"
#include "snmp.h"
#include "snmpmod.h"
#include "snmp_mibII.h"
#include "mibII_tree.h"


/*
 * Interface list and flags.
 */
TAILQ_HEAD(mibif_list, mibif);
enum {
	MIBIF_FOUND		= 0x0001,
	MIBIF_HIGHSPEED		= 0x0002,
	MIBIF_VERYHIGHSPEED	= 0x0004,
};
#define hc_inoctets	mib.ifmd_data.ifi_ibytes
#define hc_outoctets	mib.ifmd_data.ifi_obytes
#define hc_omcasts	mib.ifmd_data.ifi_omcasts
#define hc_opackets	mib.ifmd_data.ifi_opackets
#define hc_imcasts	mib.ifmd_data.ifi_imcasts
#define hc_ipackets	mib.ifmd_data.ifi_ipackets

/*
 * Interface addresses.
 */
TAILQ_HEAD(mibifa_list, mibifa);
enum {
	MIBIFA_FOUND	 = 0x0001,
	MIBIFA_DESTROYED = 0x0002,
};

/*
 * Receive addresses
 */
TAILQ_HEAD(mibrcvaddr_list, mibrcvaddr);
enum {
	MIBRCVADDR_FOUND	= 0x00010000,
};

/*
 * Interface index mapping. The problem here is, that if the same interface
 * is reinstantiated (for examble by unloading and loading the hardware driver)
 * we must use the same index for this interface. For dynamic interfaces
 * (clip, lane) we must use a fresh index, each time a new interface is created.
 * To differentiate between these types of interfaces we use the following table
 * which contains an entry for each dynamic interface type. All other interface
 * types are supposed to be static. The mibindexmap contains an entry for
 * all interfaces. The mibif pointer is NULL, if the interface doesn't exist
 * anymore.
 */
struct mibdynif {
	SLIST_ENTRY(mibdynif) link;
	char	name[IFNAMSIZ];
};
SLIST_HEAD(mibdynif_list, mibdynif);

struct mibindexmap {
	STAILQ_ENTRY(mibindexmap) link;
	u_short		sysindex;
	u_int		ifindex;
	struct mibif	*mibif;		/* may be NULL */
	char		name[IFNAMSIZ];
};
STAILQ_HEAD(mibindexmap_list, mibindexmap);

/*
 * Interface stacking. The generic code cannot know how the interfaces stack.
 * For this reason it instantiates only the x.0 and 0.x table elements. All
 * others have to be instantiated by the interface specific modules.
 * The table is read-only.
 */
struct mibifstack {
	TAILQ_ENTRY(mibifstack) link;
	struct asn_oid index;
};
TAILQ_HEAD(mibifstack_list, mibifstack);

/*
 * NetToMediaTable (ArpTable)
 */
struct mibarp {
	TAILQ_ENTRY(mibarp) link;
	struct asn_oid	index;		/* contains both the ifindex and addr */
	u_char		phys[128];	/* the physical address */
	u_int		physlen;	/* and its length */
	u_int		flags;
};
TAILQ_HEAD(mibarp_list, mibarp);
enum {
	MIBARP_FOUND	= 0x00010000,
	MIBARP_PERM	= 0x00000001,
};

/*
 * New if registrations
 */
struct newifreg {
	TAILQ_ENTRY(newifreg) link;
	const struct lmodule *mod;
	int	(*func)(struct mibif *);
};
TAILQ_HEAD(newifreg_list, newifreg);

/* list of all IP addresses */
extern struct mibifa_list mibifa_list;

/* list of all interfaces */
extern struct mibif_list mibif_list;

/* list of dynamic interface names */
extern struct mibdynif_list mibdynif_list;

/* list of all interface index mappings */
extern struct mibindexmap_list mibindexmap_list;

/* list of all stacking entries */
extern struct mibifstack_list mibifstack_list;

/* list of all receive addresses */
extern struct mibrcvaddr_list mibrcvaddr_list;

/* list of all NetToMedia entries */
extern struct mibarp_list mibarp_list;

/* number of interfaces */
extern int32_t mib_if_number;

/* last change of interface table */
extern uint64_t mib_iftable_last_change;

/* last change of stack table */
extern uint64_t mib_ifstack_last_change;

/* if this is set, one of our lists may be bad. refresh them when idle */
extern int mib_iflist_bad;

/* last time refreshed */
extern uint64_t mibarpticks;

/* info on system clocks */
extern struct clockinfo clockinfo;

/* get interfaces and interface addresses. */
void mib_fetch_interfaces(void);

/* check whether this interface(type) is dynamic */
int mib_if_is_dyn(const char *name);

/* destroy an interface address */
int mib_destroy_ifa(struct mibifa *);

/* restituate a deleted interface address */
void mib_undestroy_ifa(struct mibifa *);

/* change interface address */
int mib_modify_ifa(struct mibifa *);

/* undo if address modification */
void mib_unmodify_ifa(struct mibifa *);

/* create an interface address */
struct mibifa * mib_create_ifa(u_int ifindex, struct in_addr addr, struct in_addr mask, struct in_addr bcast);

/* delete a freshly created address */
void mib_uncreate_ifa(struct mibifa *);

/* create/delete arp entries */
struct mibarp *mib_arp_create(const struct mibif *, struct in_addr, const u_char *, size_t);
void mib_arp_delete(struct mibarp *);

/* find arp entry */
struct mibarp *mib_find_arp(const struct mibif *, struct in_addr);

/* update arp table */
void mib_arp_update(void);

/* fetch routing table */
u_char *mib_fetch_rtab(int af, int info, int arg, size_t *lenp);

/* process routing message */
void mib_sroute_process(struct rt_msghdr *, struct sockaddr *,
    struct sockaddr *, struct sockaddr *);

/* send a routing message */
void mib_send_rtmsg(struct rt_msghdr *, struct sockaddr *,
    struct sockaddr *, struct sockaddr *);

/* extract addresses from routing message */
void mib_extract_addrs(int, u_char *, struct sockaddr **);

/* fetch routing table */
int mib_fetch_route(void);
OpenPOWER on IntegriCloud