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>
7133211Sharti *
8133211Sharti * Redistribution and use in source and binary forms, with or without
9133211Sharti * modification, are permitted provided that the following conditions
10133211Sharti * are met:
11133211Sharti * 1. Redistributions of source code must retain the above copyright
12133211Sharti *    notice, this list of conditions and the following disclaimer.
13122394Sharti * 2. Redistributions in binary form must reproduce the above copyright
14122394Sharti *    notice, this list of conditions and the following disclaimer in the
15122394Sharti *    documentation and/or other materials provided with the distribution.
16133211Sharti *
17133211Sharti * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18133211Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19133211Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20133211Sharti * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21133211Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22133211Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23133211Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24133211Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25133211Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26133211Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27133211Sharti * SUCH DAMAGE.
28122394Sharti *
29156066Sharti * $Begemot: bsnmp/snmp_mibII/snmp_mibII.h,v 1.18 2006/02/14 09:04:19 brandt_h Exp $
30122394Sharti *
31122394Sharti * Implementation of the interfaces and IP groups of MIB-II.
32122394Sharti */
33122394Sharti#ifndef snmp_mibII_h_
34122394Sharti#define snmp_mibII_h_
35122394Sharti
36122394Sharti/* forward declaration */
37122394Shartistruct mibif;
38122394Sharti
39122394Shartienum mibif_notify {
40122394Sharti	MIBIF_NOTIFY_DESTROY
41122394Sharti};
42122394Sharti
43122394Shartitypedef void (*mibif_notify_f)(struct mibif *, enum mibif_notify, void *);
44122394Sharti
45122394Sharti/*
46122394Sharti * Interfaces. This structure describes one interface as seen in the MIB.
47122394Sharti * Interfaces are indexed by ifindex. This is not the same as the index
48122394Sharti * used by the system because of the rules in RFC-2863 section 3.1.5. This
49122394Sharti * RFC requires, that an ifindex is not to be re-used for ANOTHER dynamically
50122394Sharti * interfaces once the interface was deleted. The system's ifindex is in
51122394Sharti * sysindex. Mapping is via the mapping table below.
52122394Sharti */
53122394Shartistruct mibif {
54122394Sharti	TAILQ_ENTRY(mibif) link;
55122394Sharti	u_int		flags;
56122394Sharti	u_int		index;		/* the logical ifindex */
57122394Sharti	u_int		sysindex;
58122394Sharti	char		name[IFNAMSIZ];
59122394Sharti	char		descr[256];
60122394Sharti	struct ifmibdata mib;
61146525Sharti	uint64_t	mibtick;
62122394Sharti	void		*specmib;
63122394Sharti	size_t		specmiblen;
64122394Sharti	u_char		*physaddr;
65122394Sharti	u_int		physaddrlen;
66122394Sharti	int		has_connector;
67122394Sharti	int		trap_enable;
68146525Sharti	uint64_t	counter_disc;
69122394Sharti
70122394Sharti	/*
71122394Sharti	 * This is needed to handle interface type specific information
72122394Sharti	 * in sub-modules. It contains a function pointer which handles
73122394Sharti	 * notifications and a data pointer to arbitrary data.
74122394Sharti	 * Should be set via the mibif_notify function.
75122394Sharti	 */
76122394Sharti	mibif_notify_f	xnotify;
77122394Sharti	void		*xnotify_data;
78122394Sharti	const struct lmodule *xnotify_mod;
79142810Sharti
80142810Sharti	/* to be set by ifType specific modules. This is ifSpecific. */
81142810Sharti	struct asn_oid	spec_oid;
82155602Sharti
83155602Sharti	/* private data - don't touch */
84155602Sharti	void		*private;
85122394Sharti};
86122394Sharti
87122394Sharti/*
88122394Sharti * Interface IP-address table.
89122394Sharti */
90122394Shartistruct mibifa {
91122394Sharti	TAILQ_ENTRY(mibifa) link;
92122394Sharti	struct in_addr	inaddr;
93122394Sharti	struct in_addr	inmask;
94122394Sharti	struct in_addr	inbcast;
95122394Sharti	struct asn_oid	index;		/* index for table search */
96122394Sharti	u_int		ifindex;
97122394Sharti	u_int		flags;
98122394Sharti};
99122394Sharti
100122394Sharti/*
101122394Sharti * Interface receive addresses. Interface link-level multicast, broadcast
102122394Sharti * and hardware addresses are handled automatically.
103122394Sharti */
104122394Shartistruct mibrcvaddr {
105122394Sharti	TAILQ_ENTRY(mibrcvaddr) link;
106122394Sharti	struct asn_oid	index;
107122394Sharti	u_int		ifindex;
108122394Sharti	u_char		addr[ASN_MAXOIDLEN];
109122394Sharti	size_t		addrlen;
110122394Sharti	u_int		flags;
111122394Sharti};
112122394Shartienum {
113122394Sharti	MIBRCVADDR_VOLATILE	= 0x00000001,
114122394Sharti	MIBRCVADDR_BCAST	= 0x00000002,
115122394Sharti	MIBRCVADDR_HW		= 0x00000004,
116122394Sharti};
117122394Sharti
118122394Sharti/* network socket */
119122394Shartiextern int mib_netsock;
120122394Sharti
121122394Sharti/* set an interface name to dynamic mode */
122122394Shartivoid mib_if_set_dyn(const char *);
123122394Sharti
124122394Sharti/* re-read the systems interface list */
125122394Shartivoid mib_refresh_iflist(void);
126122394Sharti
127122394Sharti/* find interface by index */
128122394Shartistruct mibif *mib_find_if(u_int);
129122394Shartistruct mibif *mib_find_if_sys(u_int);
130122394Shartistruct mibif *mib_find_if_name(const char *);
131122394Sharti
132122394Sharti/* iterate through all interfaces */
133122394Shartistruct mibif *mib_first_if(void);
134122394Shartistruct mibif *mib_next_if(const struct mibif *);
135122394Sharti
136122394Sharti/* register for interface creations */
137122394Shartiint mib_register_newif(int (*)(struct mibif *), const struct lmodule *);
138122394Shartivoid mib_unregister_newif(const struct lmodule *);
139122394Sharti
140122394Sharti/* get fresh MIB data */
141122394Shartiint mib_fetch_ifmib(struct mibif *);
142122394Sharti
143122394Sharti/* change the ADMIN status of an interface and refresh the MIB */
144122394Shartiint mib_if_admin(struct mibif *, int up);
145122394Sharti
146122394Sharti/* find interface address by address */
147122394Shartistruct mibifa *mib_find_ifa(struct in_addr);
148122394Sharti
149122394Sharti/* find first/next address for a given interface */
150122394Shartistruct mibifa *mib_first_ififa(const struct mibif *);
151122394Shartistruct mibifa *mib_next_ififa(struct mibifa *);
152122394Sharti
153122394Sharti/* create/delete stacking entries */
154122394Shartiint mib_ifstack_create(const struct mibif *lower, const struct mibif *upper);
155122394Shartivoid mib_ifstack_delete(const struct mibif *lower, const struct mibif *upper);
156122394Sharti
157122394Sharti/* find receive address */
158122394Shartistruct mibrcvaddr *mib_find_rcvaddr(u_int, const u_char *, size_t);
159122394Sharti
160122394Sharti/* create/delete receive addresses */
161122394Shartistruct mibrcvaddr *mib_rcvaddr_create(struct mibif *, const u_char *, size_t);
162122394Shartivoid mib_rcvaddr_delete(struct mibrcvaddr *);
163122394Sharti
164122394Sharti/* register for interface notification */
165122394Shartivoid *mibif_notify(struct mibif *, const struct lmodule *, mibif_notify_f,
166122394Sharti    void *);
167122394Shartivoid mibif_unnotify(void *);
168122394Sharti
169122394Sharti#endif
170