summaryrefslogtreecommitdiffstats
path: root/contrib/bsnmp/snmp_mibII/snmp_mibII.h
blob: 93451843b06e6d95af6f35eba324dfd34206f9de (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
/*
 * 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/snmp_mibII.h,v 1.17 2005/05/23 09:03:43 brandt_h Exp $
 *
 * Implementation of the interfaces and IP groups of MIB-II.
 */
#ifndef snmp_mibII_h_
#define snmp_mibII_h_

/* forward declaration */
struct mibif;

enum mibif_notify {
	MIBIF_NOTIFY_DESTROY
};

typedef void (*mibif_notify_f)(struct mibif *, enum mibif_notify, void *);

/*
 * Interfaces. This structure describes one interface as seen in the MIB.
 * Interfaces are indexed by ifindex. This is not the same as the index
 * used by the system because of the rules in RFC-2863 section 3.1.5. This
 * RFC requires, that an ifindex is not to be re-used for ANOTHER dynamically
 * interfaces once the interface was deleted. The system's ifindex is in
 * sysindex. Mapping is via the mapping table below.
 */
struct mibif {
	TAILQ_ENTRY(mibif) link;
	u_int		flags;
	u_int		index;		/* the logical ifindex */
	u_int		sysindex;
	char		name[IFNAMSIZ];
	char		descr[256];
	struct ifmibdata mib;
	uint64_t	mibtick;
	void		*specmib;
	size_t		specmiblen;
	u_char		*physaddr;
	u_int		physaddrlen;
	int		has_connector;
	int		trap_enable;
	uint64_t	counter_disc;

	/*
	 * This is needed to handle interface type specific information
	 * in sub-modules. It contains a function pointer which handles
	 * notifications and a data pointer to arbitrary data.
	 * Should be set via the mibif_notify function.
	 */
	mibif_notify_f	xnotify;
	void		*xnotify_data;
	const struct lmodule *xnotify_mod;

	/* to be set by ifType specific modules. This is ifSpecific. */
	struct asn_oid	spec_oid;

	/* private data - don't touch */
	void		*private;
};

/*
 * Interface IP-address table.
 */
struct mibifa {
	TAILQ_ENTRY(mibifa) link;
	struct in_addr	inaddr;
	struct in_addr	inmask;
	struct in_addr	inbcast;
	struct asn_oid	index;		/* index for table search */
	u_int		ifindex;
	u_int		flags;
};

/*
 * Interface receive addresses. Interface link-level multicast, broadcast
 * and hardware addresses are handled automatically.
 */
struct mibrcvaddr {
	TAILQ_ENTRY(mibrcvaddr) link;
	struct asn_oid	index;
	u_int		ifindex;
	u_char		addr[ASN_MAXOIDLEN];
	size_t		addrlen;
	u_int		flags;
};
enum {
	MIBRCVADDR_VOLATILE	= 0x00000001,
	MIBRCVADDR_BCAST	= 0x00000002,
	MIBRCVADDR_HW		= 0x00000004,
};

/* network socket */
extern int mib_netsock;

/* set an interface name to dynamic mode */
void mib_if_set_dyn(const char *);

/* re-read the systems interface list */
void mib_refresh_iflist(void);

/* find interface by index */
struct mibif *mib_find_if(u_int);
struct mibif *mib_find_if_sys(u_int);
struct mibif *mib_find_if_name(const char *);

/* iterate through all interfaces */
struct mibif *mib_first_if(void);
struct mibif *mib_next_if(const struct mibif *);

/* register for interface creations */
int mib_register_newif(int (*)(struct mibif *), const struct lmodule *);
void mib_unregister_newif(const struct lmodule *);

/* get fresh MIB data */
int mib_fetch_ifmib(struct mibif *);

/* change the ADMIN status of an interface and refresh the MIB */
int mib_if_admin(struct mibif *, int up);

/* find interface address by address */
struct mibifa *mib_find_ifa(struct in_addr);

/* find first/next address for a given interface */
struct mibifa *mib_first_ififa(const struct mibif *);
struct mibifa *mib_next_ififa(struct mibifa *);

/* create/delete stacking entries */
int mib_ifstack_create(const struct mibif *lower, const struct mibif *upper);
void mib_ifstack_delete(const struct mibif *lower, const struct mibif *upper);

/* find receive address */
struct mibrcvaddr *mib_find_rcvaddr(u_int, const u_char *, size_t);

/* create/delete receive addresses */
struct mibrcvaddr *mib_rcvaddr_create(struct mibif *, const u_char *, size_t);
void mib_rcvaddr_delete(struct mibrcvaddr *);

/* register for interface notification */
void *mibif_notify(struct mibif *, const struct lmodule *, mibif_notify_f,
    void *);
void mibif_unnotify(void *);

#endif
OpenPOWER on IntegriCloud