code:
/*-
 * Copyright (c) 2006 Shteryana Shopova <syrinx@FreeBSD.org>
 * All rights reserved.
 *
 * 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 THE 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 THE 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.
 *
 * Bridge MIB implementation for SNMPd.
 *
 * $FreeBSD: release/9.0.0/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.h 171791 2007-08-08 19:27:50Z syrinx $
 */

#ifndef	SNMP_BRIDGE_H
#define	SNMP_BRIDGE_H

#define	SNMP_BRIDGE_ID_LEN	8

typedef uint8_t	port_id[2];
typedef u_char	bridge_id[SNMP_BRIDGE_ID_LEN];

#define	SNMP_BRIDGE_MAX_PRIORITY	65535

#define	SNMP_BRIDGE_MIN_AGE_TIME	10
#define	SNMP_BRIDGE_MAX_AGE_TIME	1000000

#define	SNMP_BRIDGE_MIN_TXHC		1
#define	SNMP_BRIDGE_MAX_TXHC		10

#define	SNMP_BRIDGE_MIN_MAGE		600
#define	SNMP_BRIDGE_MAX_MAGE		4000

#define	SNMP_BRIDGE_MIN_HTIME		100
#define	SNMP_BRIDGE_MAX_HTIME		1000

#define	SNMP_BRIDGE_MIN_FDELAY		400
#define	SNMP_BRIDGE_MAX_FDELAY		3000

#define	SNMP_PORT_PATHCOST_OBSOLETE	65535
#define	SNMP_PORT_MIN_PATHCOST		0
#define	SNMP_PORT_MAX_PATHCOST		200000000
#define	SNMP_PORT_PATHCOST_AUTO		0

#define	SNMP_BRIDGE_DATA_MAXAGE		10
#define	SNMP_BRIDGE_DATA_MAXAGE_MIN	1
#define	SNMP_BRIDGE_DATA_MAXAGE_MAX	300

/* By default poll kernel data every 5 minutes. */
#define	SNMP_BRIDGE_POLL_INTERVAL	(5 * 60)
#define	SNMP_BRIDGE_POLL_INTERVAL_MIN	1
#define	SNMP_BRIDGE_POLL_INTERVAL_MAX	3600

/* Poll for a topology change once every 30 seconds. */
#define	SNMP_BRIDGE_TC_POLL_INTERVAL	30

struct bridge_if *bridge_get_default(void);

void bridge_set_default(struct bridge_if *bif);

const char *bridge_get_default_name(void);

int bridge_get_data_maxage(void);

/*
 * Bridge Addresses Table.
 */
struct tp_entry {
	uint32_t		sysindex;	/* The bridge if sysindex. */
	int32_t			port_no;
	enum TpFdbStatus	status;
	uint8_t			tp_addr[ETHER_ADDR_LEN];
	uint8_t			flags;
	TAILQ_ENTRY(tp_entry)	tp_e;
};

/*
 * Bridge ports.
 * The bridge port system interface index is used for a
 * port number. Transparent bridging statistics and STP
 * information for a port are also contained here.
 */
struct bridge_port {
	/* dot1dBase subtree objects. */
	uint32_t	sysindex;	/* The bridge interface sysindex. */
	int32_t		port_no;	/* The bridge member system index. */
	int32_t		if_idx;		/* SNMP ifIndex from mibII. */
	int8_t		span_enable;	/* Span flag set - private MIB. */
	struct asn_oid	circuit;	/* Unused. */
	uint32_t	dly_ex_drops;	/* Drops on output. */
	uint32_t	dly_mtu_drops;	/* MTU exceeded drops. */
	int32_t		status;		/* The entry status. */
	enum TruthValue	priv_set;	/* The private flag. */

	/* dot1dStp subtree objects. */
	int32_t		path_cost;
	int32_t		priority;
	int32_t		design_cost;
	uint32_t	fwd_trans;
	char		p_name[IFNAMSIZ]; /* Not in BRIDGE-MIB. */
	enum StpPortState	state;
	enum dot1dStpPortEnable	enable;
	port_id		design_port;
	bridge_id	design_root;
	bridge_id	design_bridge;

	/* rstpMib extensions. */
	int32_t		admin_path_cost;
	enum TruthValue	proto_migr;
	enum TruthValue	admin_edge;
	enum TruthValue	oper_edge;
	enum TruthValue	oper_ptp;
	enum StpPortAdminPointToPointType	admin_ptp;

	/* dot1dTp subtree objects. */
	int32_t		max_info;
	int32_t		in_frames;
	int32_t		out_frames;
	int32_t		in_drops;

	uint8_t		flags;
	TAILQ_ENTRY(bridge_port) b_p;
};

/*
 * A bridge interface.
 * The system interface index of the bridge is not required neither by the
 * standard BRIDGE-MIB nor by the private BEGEMOT-BRIDGE-MIB, but is used
 * as key for looking up the other info for this bridge.
 */
struct bridge_if {
	/* dot1dBase subtree objects. */
	uint32_t	sysindex;	/* The system interface index. */
	int32_t		num_ports;	/* Number of ports. */
	enum BaseType	br_type;	/* Bridge type. */
	enum RowStatus	if_status;	/* Bridge status. */
	char		bif_name[IFNAMSIZ]; /* Bridge interface name. */
	struct ether_addr br_addr;	/* Bridge address. */
	struct bridge_port *f_bp;	/* This bridge's first entry
					 * in the base ports TAILQ. */
	/* dot1dStp subtree objects. */
	int32_t		priority;
	int32_t		root_cost;
	int32_t		root_port;
	int32_t		max_age;	/* Current max age. */
	int32_t		hello_time;	/* Current hello time. */
	int32_t		fwd_delay;	/* Current forward delay. */
	int32_t		hold_time;
	int32_t		bridge_max_age;	/* Configured max age. */
	int32_t		bridge_hello_time; /* Configured hello time. */
	int32_t		bridge_fwd_delay; /* Configured forward delay. */
	int32_t		tx_hold_count;
	uint32_t	top_changes;
	enum dot1dStpVersion	stp_version;
	enum dot1dStpProtocolSpecification prot_spec;
	struct timeval	last_tc_time;
	bridge_id	design_root;

	/* dot1dTp subtree objects. */
	int32_t		lrnt_drops;	/* Dropped addresses. */
	int32_t		age_time;	/* Address entry timeout. */
	int32_t		num_addrs;	/* Current # of addresses in cache. */
	int32_t		max_addrs;	/* Max # of addresses in cache. */
	struct tp_entry	 *f_tpa;	/* This bridge's first entry in
					 * the tp addresses TAILQ. */

	time_t		entry_age;
	time_t		ports_age;
	time_t		addrs_age;
	TAILQ_ENTRY(bridge_if) b_if;
};

void bridge_ifs_fini(void);

struct bridge_if *bridge_if_find_ifs(uint32_t sysindex);

struct bridge_if *bridge_if_find_ifname(const char *b_name);

const char *bridge_if_find_name(uint32_t sysindex);

int bridge_compare_sysidx(uint32_t i1, uint32_t i2);

int bridge_attach_newif(struct mibif *ifp);

struct bridge_if *bridge_first_bif(void);

struct bridge_if *bridge_next_bif(struct bridge_if *b_pr);

void bridge_remove_bif(struct bridge_if *bif);

void bridge_update_all_ports(void);

void bridge_update_all_addrs(void);

void bridge_update_all_ifs(void);

void bridge_update_all(void *arg);

void bridge_update_tc_time(void *arg);

void bridge_ifs_dump(void);

/* Bridge ports. */
void bridge_ports_update_listage(void);

void bridge_ports_fini(void);

void bridge_members_free(struct bridge_if *bif);

struct bridge_port *bridge_new_port(struct mibif *mif, struct bridge_if *bif);

void bridge_port_remove(struct bridge_port *bp, struct bridge_if *bif);

struct bridge_port *bridge_port_bif_first(struct bridge_if *bif);

struct bridge_port *bridge_port_bif_next(struct bridge_port *bp);

struct bridge_port *bridge_port_find(int32_t if_idx, struct bridge_if *bif);

void bridge_port_getinfo_mibif(struct mibif *m_if, struct bridge_port *bp);

int bridge_getinfo_bif_ports(struct bridge_if *bif);

int bridge_update_memif(struct bridge_if *bif);

void bridge_ports_dump(struct bridge_if *bif);

/* Bridge addresses. */
void bridge_addrs_update_listage(void);

void bridge_addrs_fini(void);

void bridge_addrs_free(struct bridge_if *bif);

struct tp_entry *bridge_new_addrs(uint8_t *mac, struct bridge_if *bif);

void bridge_addrs_remove(struct tp_entry *te, struct bridge_if *bif);

struct tp_entry *bridge_addrs_find(uint8_t *mac, struct bridge_if *bif);

struct tp_entry *bridge_addrs_bif_first(struct bridge_if *bif);

struct tp_entry *bridge_addrs_bif_next(struct tp_entry *te);

int bridge_getinfo_bif_addrs(struct bridge_if *bif);

int bridge_update_addrs(struct bridge_if *bif);

void bridge_addrs_dump(struct bridge_if *bif);

/* Bridge PF. */

void bridge_pf_dump(void);

/* System specific. */

/* Open the socket for the ioctls. */
int bridge_ioctl_init(void);

/* Load bridge kernel module. */
int bridge_kmod_load(void);

/* Get the bridge interface information. */
int bridge_getinfo_bif(struct bridge_if *bif);

/* Get the bridge interface STP parameters. */
int bridge_get_op_param(struct bridge_if *bif);

/* Set the bridge priority. */
int bridge_set_priority(struct bridge_if *bif, int32_t priority);

/* Set the bridge max age. */
int bridge_set_maxage(struct bridge_if *bif, int32_t max_age);

/* Set the bridge hello time.*/
int bridge_set_hello_time(struct bridge_if *bif, int32_t hello_time);

/* Set the bridge forward delay.*/
int bridge_set_forward_delay(struct bridge_if *bif, int32_t fwd_delay);

/* Set the bridge address cache max age. */
int bridge_set_aging_time(struct bridge_if *bif, int32_t age_time);

/* Set the max number of entries in the bridge address cache. */
int bridge_set_max_cache(struct bridge_if *bif, int32_t max_cache);

/* Set the bridge TX hold count. */
int bridge_set_tx_hold_count(struct bridge_if *bif, int32_t tx_hc);

/* Set the bridge STP protocol version. */
int bridge_set_stp_version(struct bridge_if *bif, int32_t stp_proto);

/* Set the bridge interface status to up/down. */
int bridge_set_if_up(const char* b_name, int8_t up);

/* Create a bridge interface. */
int bridge_create(const char *b_name);

/* Destroy a bridge interface. */
int bridge_destroy(const char *b_name);

/* Fetch the bridge mac address. */
u_char *bridge_get_basemac(const char *bif_name, u_char *mac, size_t mlen);

/* Set a bridge member priority. */
int bridge_port_set_priority(const char *bif_name, struct bridge_port *bp,
    int32_t priority);

/* Set a bridge member STP-enabled flag. */
int bridge_port_set_stp_enable(const char *bif_name, struct bridge_port *bp,
    uint32_t enable);

/* Set a bridge member STP path cost. */
int bridge_port_set_path_cost(const char *bif_name, struct bridge_port *bp,
    int32_t path_cost);

/* Set admin point-to-point link. */
int bridge_port_set_admin_ptp(const char *bif_name, struct bridge_port *bp,
    uint32_t admin_ptp);

/* Set admin edge. */
int bridge_port_set_admin_edge(const char *bif_name, struct bridge_port *bp,
    uint32_t enable);

/* Set 'private' flag. */
int bridge_port_set_private(const char *bif_name, struct bridge_port *bp,
    uint32_t priv_set);

/* Add a bridge member port. */
int bridge_port_addm(struct bridge_port *bp, const char *b_name);

/* Delete a bridge member port. */
int bridge_port_delm(struct bridge_port *bp, const char *b_name);

/* Get the current value from the module for bridge PF control. */
int32_t bridge_get_pfval(uint8_t which);

/* Get/Set a bridge PF control. */
int32_t bridge_do_pfctl(int32_t bridge_ctl, enum snmp_op op, int32_t *val);

#endif /* SNMP_BRIDGE_H */


code:
/*
 * Copyright (c) 2001-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 *	All rights reserved.
 *
 * Author: Harti Brandt <harti@freebsd.org>
 *
 * Copyright (c) 2010 The FreeBSD Foundation
 * All rights reserved.
 *
 * Portions of this software were developed by Shteryana Sotirova Shopova
 * under sponsorship from the FreeBSD Foundation.
 *
 *
 * 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/lib/snmp.h,v 1.30 2004/08/06 08:46:54 brandt Exp $
 *
 * Header file for SNMP functions.
 */
#ifndef snmp_h_
#define snmp_h_

#include <sys/types.h>

#define SNMP_COMMUNITY_MAXLEN		128
#define SNMP_MAX_BINDINGS		100
#define	SNMP_CONTEXT_NAME_SIZ		(32 + 1)
#define	SNMP_ENGINE_ID_SIZ		32
#define	SNMP_TIME_WINDOW		150

enum snmp_syntax {
	SNMP_SYNTAX_NULL	= 0,
	SNMP_SYNTAX_INTEGER,		/* == INTEGER32 */
	SNMP_SYNTAX_OCTETSTRING,
	SNMP_SYNTAX_OID,
	SNMP_SYNTAX_IPADDRESS,
	SNMP_SYNTAX_COUNTER,
	SNMP_SYNTAX_GAUGE,		/* == UNSIGNED32 */
	SNMP_SYNTAX_TIMETICKS,

	/* v2 additions */
	SNMP_SYNTAX_COUNTER64,
	SNMP_SYNTAX_NOSUCHOBJECT,	/* exception */
	SNMP_SYNTAX_NOSUCHINSTANCE,	/* exception */
	SNMP_SYNTAX_ENDOFMIBVIEW,	/* exception */
};

struct snmp_value {
	struct asn_oid		var;
	enum snmp_syntax	syntax;
	union snmp_values {
	  int32_t		integer;	/* also integer32 */
	  struct {
	    u_int		len;
	    u_char		*octets;
	  }			octetstring;
	  struct asn_oid	oid;
	  u_char		ipaddress[4];
	  uint32_t		uint32;		/* also gauge32, counter32,
						   unsigned32, timeticks */
	  uint64_t		counter64;
	}			v;
};

enum snmp_version {
	SNMP_Verr = 0,
	SNMP_V1 = 1,
	SNMP_V2c = 2,
	SNMP_V3,
};

#define	SNMP_MPM_SNMP_V1		0
#define	SNMP_MPM_SNMP_V2c		1
#define	SNMP_MPM_SNMP_V3		3

#define	SNMP_ADM_STR32_SIZ		(32 + 1)
#define	SNMP_AUTH_KEY_SIZ		40
#define	SNMP_PRIV_KEY_SIZ		32
#define	SNMP_USM_AUTH_SIZE		12
#define	SNMP_USM_PRIV_SIZE		8
#define	SNMP_AUTH_HMACMD5_KEY_SIZ	16
#define	SNMP_AUTH_HMACSHA_KEY_SIZ	20
#define	SNMP_PRIV_AES_KEY_SIZ		16
#define	SNMP_PRIV_DES_KEY_SIZ		8

enum snmp_secmodel {
	SNMP_SECMODEL_ANY = 0,
	SNMP_SECMODEL_SNMPv1 = 1,
	SNMP_SECMODEL_SNMPv2c = 2,
	SNMP_SECMODEL_USM = 3,
	SNMP_SECMODEL_UNKNOWN
};

enum snmp_usm_level {
	SNMP_noAuthNoPriv = 1,
	SNMP_authNoPriv = 2,
	SNMP_authPriv = 3
};

enum snmp_authentication {
	SNMP_AUTH_NOAUTH = 0,
	SNMP_AUTH_HMAC_MD5,
	SNMP_AUTH_HMAC_SHA
};

enum snmp_privacy {
	SNMP_PRIV_NOPRIV = 0,
	SNMP_PRIV_DES = 1,
	SNMP_PRIV_AES
};

struct snmp_engine {
	uint8_t			engine_id[SNMP_ENGINE_ID_SIZ];
	uint32_t		engine_len;
	int32_t			engine_boots;
	int32_t			engine_time;
	int32_t			max_msg_size;
};

struct snmp_user {
	char				sec_name[SNMP_ADM_STR32_SIZ];
	enum snmp_authentication	auth_proto;
	enum snmp_privacy		priv_proto;
	uint8_t				auth_key[SNMP_AUTH_KEY_SIZ];
	uint8_t				priv_key[SNMP_PRIV_KEY_SIZ];
};

struct snmp_pdu {
	char			community[SNMP_COMMUNITY_MAXLEN + 1];
	enum snmp_version	version;
	u_int			type;

	/* SNMPv3 PDU header fields */
	int32_t			identifier;
	uint8_t			flags;
	int32_t			security_model;
	struct snmp_engine	engine;

	/* Associated USM user parameters */
	struct snmp_user	user;
	uint8_t			msg_digest[SNMP_USM_AUTH_SIZE];
	uint8_t			msg_salt[SNMP_USM_PRIV_SIZE];

	/*  View-based Access Model */
	/* XXX: put in separate structure - conflicts with struct snmp_context */
	uint32_t		context_engine_len;
	uint8_t			context_engine[SNMP_ENGINE_ID_SIZ];
	char			context_name[SNMP_CONTEXT_NAME_SIZ];

	/* trap only */
	struct asn_oid		enterprise;
	u_char			agent_addr[4];
	int32_t			generic_trap;
	int32_t			specific_trap;
	uint32_t		time_stamp;

	/* others */
	int32_t			request_id;
	int32_t			error_status;
	int32_t			error_index;

	/* fixes for encoding */
	size_t			outer_len;
	size_t			scoped_len;
	u_char			*outer_ptr;
	u_char			*digest_ptr;
	u_char			*encrypted_ptr;
	u_char			*scoped_ptr;
	u_char			*pdu_ptr;
	u_char			*vars_ptr;

	struct snmp_value	bindings[SNMP_MAX_BINDINGS];
	u_int			nbindings;
};
#define snmp_v1_pdu snmp_pdu

#define SNMP_PDU_GET		0
#define SNMP_PDU_GETNEXT	1
#define SNMP_PDU_RESPONSE	2
#define SNMP_PDU_SET		3
#define SNMP_PDU_TRAP		4	/* v1 */
#define SNMP_PDU_GETBULK	5	/* v2 */
#define SNMP_PDU_INFORM		6	/* v2 */
#define SNMP_PDU_TRAP2		7	/* v2 */
#define SNMP_PDU_REPORT		8	/* v2 */

#define SNMP_ERR_NOERROR	0
#define SNMP_ERR_TOOBIG		1
#define SNMP_ERR_NOSUCHNAME	2	/* v1 */
#define SNMP_ERR_BADVALUE	3	/* v1 */
#define SNMP_ERR_READONLY	4	/* v1 */
#define SNMP_ERR_GENERR		5
#define SNMP_ERR_NO_ACCESS	6	/* v2 */
#define SNMP_ERR_WRONG_TYPE	7	/* v2 */
#define SNMP_ERR_WRONG_LENGTH	8	/* v2 */
#define SNMP_ERR_WRONG_ENCODING	9	/* v2 */
#define SNMP_ERR_WRONG_VALUE	10	/* v2 */
#define SNMP_ERR_NO_CREATION	11	/* v2 */
#define SNMP_ERR_INCONS_VALUE	12	/* v2 */
#define SNMP_ERR_RES_UNAVAIL	13	/* v2 */
#define SNMP_ERR_COMMIT_FAILED	14	/* v2 */
#define SNMP_ERR_UNDO_FAILED	15	/* v2 */
#define SNMP_ERR_AUTH_ERR	16	/* v2 */
#define SNMP_ERR_NOT_WRITEABLE	17	/* v2 */
#define SNMP_ERR_INCONS_NAME	18	/* v2 */

#define SNMP_TRAP_COLDSTART	0
#define SNMP_TRAP_WARMSTART	1
#define SNMP_TRAP_LINKDOWN	2
#define SNMP_TRAP_LINKUP	3
#define SNMP_TRAP_AUTHENTICATION_FAILURE	4
#define SNMP_TRAP_EGP_NEIGHBOR_LOSS	5
#define SNMP_TRAP_ENTERPRISE	6

enum snmp_code {
	SNMP_CODE_OK = 0,
	SNMP_CODE_FAILED,
	SNMP_CODE_BADVERS,
	SNMP_CODE_BADLEN,
	SNMP_CODE_BADENC,
	SNMP_CODE_OORANGE,
	SNMP_CODE_BADSECLEVEL,
	SNMP_CODE_NOTINTIME,
	SNMP_CODE_BADUSER,
	SNMP_CODE_BADENGINE,
	SNMP_CODE_BADDIGEST,
	SNMP_CODE_EDECRYPT
};

#define	SNMP_MSG_AUTH_FLAG		0x1
#define	SNMP_MSG_PRIV_FLAG		0x2
#define	SNMP_MSG_REPORT_FLAG		0x4
#define	SNMP_MSG_AUTODISCOVER		0x80

void snmp_value_free(struct snmp_value *);
int snmp_value_parse(const char *, enum snmp_syntax, union snmp_values *);
int snmp_value_copy(struct snmp_value *, const struct snmp_value *);

void snmp_pdu_free(struct snmp_pdu *);
void snmp_pdu_init_secparams(struct snmp_pdu *);
enum snmp_code snmp_pdu_decode(struct asn_buf *b, struct snmp_pdu *pdu, int32_t *);
enum snmp_code snmp_pdu_decode_header(struct asn_buf *, struct snmp_pdu *);
enum snmp_code snmp_pdu_decode_scoped(struct asn_buf *, struct snmp_pdu *, int32_t *);
enum snmp_code snmp_pdu_encode(struct snmp_pdu *, struct asn_buf *);
enum snmp_code snmp_pdu_decode_secmode(struct asn_buf *, struct snmp_pdu *);

int snmp_pdu_snoop(const struct asn_buf *);

void snmp_pdu_dump(const struct snmp_pdu *pdu);

enum snmp_code snmp_passwd_to_keys(struct snmp_user *, char *);
enum snmp_code snmp_get_local_keys(struct snmp_user *, uint8_t *, uint32_t);
enum snmp_code snmp_calc_keychange(struct snmp_user *, uint8_t *);

extern void (*snmp_error)(const char *, ...);
extern void (*snmp_printf)(const char *, ...);

#define TRUTH_MK(F) ((F) ? 1 : 2)
#define TRUTH_GET(T) (((T) == 1) ? 1 : 0)
#define TRUTH_OK(T)  ((T) == 1 || (T) == 2)

#endif

repo_name: veiledmerc/mira

license: mit


code:
/*
 * Copyright (c) 2001-2002
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 *	All rights reserved.
 * Copyright (c) 2003-2004
 *	Hartmut Brandt
 *	All rights reserved.
 *
 * Author: Hartmut 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: libunimsg/snmp_atm/snmp_atm.h,v 1.2 2004/08/06 17:30:40 brandt Exp $
 */
#ifndef _BSNMP_SNMP_ATM_H
#define _BSNMP_SNMP_ATM_H

enum atmif_notify {
	ATMIF_NOTIFY_DESTROY,	/* interface has been destroyed */
	ATMIF_NOTIFY_CARRIER,	/* carriere change */
	ATMIF_NOTIFY_VCC	/* VCC change */
};

enum atmif_carrier_state {
	ATMIF_CARRIER_ON	= 1,
	ATMIF_CARRIER_OFF	= 2,
	ATMIF_CARRIER_UNKNOWN	= 3,
	ATMIF_CARRIER_NONE	= 4
};

enum atmif_suni_mode {
	ATMIF_SUNI_MODE_SONET	= 1,
	ATMIF_SUNI_MODE_SDH	= 2,
	ATMIF_SUNI_MODE_UNKNOWN	= 3
};

/* forward declaration */
struct atmif;
typedef void (*atmif_event_f)(struct atmif *, enum atmif_notify, uintptr_t,
    void *);

struct atmif_mib {
	u_int	version;	/* currently 0 */

	u_int	device;		/* type of hardware (system specific) */
	u_int	serial;		/* card serial number (device specific) */
	u_int	hw_version;	/* card version (device specific) */
	u_int	sw_version;	/* firmware version (device specific) */
	u_int	media;		/* physical media (see MIB) */

	u_char	esi[6];		/* end system identifier (MAC) */
	u_int	pcr;		/* supported peak cell rate */
	u_int	vpi_bits;	/* number of used bits in VPI field */
	u_int	vci_bits;	/* number of used bits in VCI field */
	u_int	max_vpcs;	/* maximum number of VPCs */
	u_int	max_vccs;	/* maximum number of VCCs */
};

struct atmif {
	struct mibif	*ifp;		/* common interface data */
	struct atmif_mib *mib;		/* ATM MIB */
	enum atmif_carrier_state carrier;
	enum atmif_suni_mode mode;	/* SUNI mode SDH or SONET */
};

/* find an ATM interface by name */
struct atmif *atm_find_if_name(const char *);

/* get the interface from the interface index */
struct atmif *atm_find_if(u_int);

/* register for notifications */
void *atm_notify_aif(struct atmif *, const struct lmodule *mod,
    atmif_event_f, void *);
void atm_unnotify_aif(void *);

/* return the If for a system-specific node number */
struct atmif *atm_node2if(u_int);

/* return the node id for the if */
u_int atm_if2node(struct atmif *);

#endif


code:
/*
 * 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.18 2006/02/14 09:04:19 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


code:
/*
 * Copyright (c) 2001-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 *	All rights reserved.
 *
 * Author: Harti Brandt <harti@freebsd.org>
 *
 * Redistribution of this software and documentation 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 or documentation 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 AND DOCUMENTATION IS PROVIDED BY FRAUNHOFER FOKUS
 * AND ITS 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
 * FRAUNHOFER FOKUS OR ITS 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.
 *
 * $FreeBSD: release/9.0.0/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.h 122405 2003-11-10 09:17:34Z harti $
 *
 * Netgraph interface for SNMPd. Exported stuff.
 */
#ifndef SNMP_NETGRAPH_H_
#define SNMP_NETGRAPH_H_

#include <netgraph/ng_message.h>

extern ng_ID_t	snmp_node;
extern u_char *snmp_nodename;

typedef void ng_cookie_f(const struct ng_mesg *, const char *, ng_ID_t, void *);
typedef void ng_hook_f(const char *, const u_char *, size_t, void *);

void *ng_register_cookie(const struct lmodule *, u_int32_t cookie,
    ng_ID_t, ng_cookie_f *, void *);
void ng_unregister_cookie(void *reg);

void *ng_register_hook(const struct lmodule *, const char *,
    ng_hook_f *, void *);
void ng_unregister_hook(void *reg);

void ng_unregister_module(const struct lmodule *);

int ng_output(const char *path, u_int cookie, u_int opcode,
    const void *arg, size_t arglen);
int ng_output_node(const char *node, u_int cookie, u_int opcode,
    const void *arg, size_t arglen);
int ng_output_id(ng_ID_t node, u_int cookie, u_int opcode,
    const void *arg, size_t arglen);

struct ng_mesg *ng_dialog(const char *path, u_int cookie, u_int opcode,
    const void *arg, size_t arglen);
struct ng_mesg *ng_dialog_node(const char *node, u_int cookie, u_int opcode,
    const void *arg, size_t arglen);
struct ng_mesg *ng_dialog_id(ng_ID_t id, u_int cookie, u_int opcode,
    const void *arg, size_t arglen);

int ng_send_data(const char *hook, const void *sndbuf, size_t sndlen);

ng_ID_t ng_mkpeer_id(ng_ID_t, const char *name, const char *type,
    const char *hook, const char *peerhook);
int ng_connect_node(const char *node, const char *ourhook, const char *peerhook);
int ng_connect_id(ng_ID_t id, const char *ourhook, const char *peerhook);
int ng_connect2_id(ng_ID_t id, ng_ID_t peer, const char *ourhook,
    const char *peerhook);
int ng_connect2_tee_id(ng_ID_t id, ng_ID_t peer, const char *ourhook,
    const char *peerhook);
int ng_rmhook(const char *ourhook);
int ng_rmhook_id(ng_ID_t, const char *);
int ng_rmhook_tee_id(ng_ID_t, const char *);
int ng_shutdown_id(ng_ID_t);

ng_ID_t ng_next_node_id(ng_ID_t node, const char *type, const char *hook);
ng_ID_t ng_node_id(const char *path);
ng_ID_t ng_node_id_node(const char *node);
ng_ID_t ng_node_name(ng_ID_t, char *);
ng_ID_t ng_node_type(ng_ID_t, char *);
int ng_peer_hook_id(ng_ID_t, const char *, char *);

#endif


code:
/*
 * 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/lib/snmpagent.h,v 1.13 2004/08/06 08:46:56 brandt Exp $
 *
 * Header file for SNMP functions. This requires snmp.h to be included.
 */
#ifndef snmp_agent_h_
#define snmp_agent_h_

struct snmp_dependency;

enum snmp_ret {
	/* OK, generate a response */
	SNMP_RET_OK	= 0,
	/* Error, ignore packet (no response) */
	SNMP_RET_IGN	= 1,
	/* Error, generate response from original packet */
	SNMP_RET_ERR	= 2
};

/* Semi-Opaque object for SET operations */
struct snmp_context {
	u_int	var_index;
	struct snmp_scratch *scratch;
	struct snmp_dependency *dep;
	void	*data;		/* user data */
	enum snmp_ret code;	/* return code */
};

struct snmp_scratch {
	void		*ptr1;
	void		*ptr2;
	uint32_t	int1;
	uint32_t	int2;
};

enum snmp_depop {
	SNMP_DEPOP_COMMIT,
	SNMP_DEPOP_ROLLBACK,
	SNMP_DEPOP_FINISH
};

typedef int (*snmp_depop_t)(struct snmp_context *, struct snmp_dependency *,
    enum snmp_depop);

struct snmp_dependency {
	struct asn_oid	obj;
	struct asn_oid	idx;
};

/*
 * The TREE
 */
enum snmp_node_type {
	SNMP_NODE_LEAF = 1,
	SNMP_NODE_COLUMN
};

enum snmp_op {
	SNMP_OP_GET 	= 1,
	SNMP_OP_GETNEXT,
	SNMP_OP_SET,
	SNMP_OP_COMMIT,
	SNMP_OP_ROLLBACK,
};

typedef int (*snmp_op_t)(struct snmp_context *, struct snmp_value *,
    u_int, u_int, enum snmp_op);

struct snmp_node {
	struct asn_oid oid;
	const char	*name;		/* name of the leaf */
	enum snmp_node_type type;	/* type of this node */
	enum snmp_syntax syntax;
	snmp_op_t	op;
	u_int		flags;
	uint32_t	index;		/* index data */
	void		*data;		/* application data */
	void		*tree_data;	/* application data */
};
extern struct snmp_node *tree;
extern u_int  tree_size;

#define SNMP_NODE_CANSET	0x0001	/* SET allowed */

#define SNMP_INDEXES_MAX	7
#define SNMP_INDEX_SHIFT	4
#define SNMP_INDEX_MASK	0xf
#define SNMP_INDEX_COUNT(V)	((V) & SNMP_INDEX_MASK)
#define SNMP_INDEX(V,I) \
	(((V) >> (((I) + 1) * SNMP_INDEX_SHIFT)) & SNMP_INDEX_MASK)

enum {
	SNMP_TRACE_GET		= 0x00000001,
	SNMP_TRACE_GETNEXT	= 0x00000002,
	SNMP_TRACE_SET		= 0x00000004,
	SNMP_TRACE_DEPEND	= 0x00000008,
	SNMP_TRACE_FIND		= 0x00000010,
};
/* trace flag for the following functions */
extern u_int snmp_trace;

/* called to write the trace */
extern void (*snmp_debug)(const char *fmt, ...);

enum snmp_ret snmp_get(struct snmp_pdu *pdu, struct asn_buf *resp_b,
    struct snmp_pdu *resp, void *);
enum snmp_ret snmp_getnext(struct snmp_pdu *pdu, struct asn_buf *resp_b,
    struct snmp_pdu *resp, void *);
enum snmp_ret snmp_getbulk(struct snmp_pdu *pdu, struct asn_buf *resp_b,
    struct snmp_pdu *resp, void *);
enum snmp_ret snmp_set(struct snmp_pdu *pdu, struct asn_buf *resp_b,
    struct snmp_pdu *resp, void *);

enum snmp_ret snmp_make_errresp(const struct snmp_pdu *, struct asn_buf *,
    struct asn_buf *);

struct snmp_dependency *snmp_dep_lookup(struct snmp_context *,
    const struct asn_oid *, const struct asn_oid *, size_t, snmp_depop_t);

struct snmp_context *snmp_init_context(void);
int snmp_dep_commit(struct snmp_context *);
int snmp_dep_rollback(struct snmp_context *);
void snmp_dep_finish(struct snmp_context *);

#endif


code:
/*
 * Copyright (c) 2001-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 *	All rights reserved.
 *
 * Author: Harti Brandt <harti@freebsd.org>
 *	   Kendy Kutzner
 *
 * 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/lib/snmpclient.h,v 1.19 2005/05/23 11:10:14 brandt_h Exp $
 */
#ifndef _BSNMP_SNMPCLIENT_H
#define _BSNMP_SNMPCLIENT_H

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <stddef.h>

#define SNMP_STRERROR_LEN 200

#define SNMP_LOCAL_PATH	"/tmp/snmpXXXXXXXXXXXXXX"

/*
 * transport methods
 */
#define	SNMP_TRANS_UDP		0
#define	SNMP_TRANS_LOC_DGRAM	1
#define	SNMP_TRANS_LOC_STREAM	2

/* type of callback function for responses
 * this callback function is responsible for free() any memory associated with
 * any of the PDUs. Therefor it may call snmp_pdu_free() */
typedef void (*snmp_send_cb_f)(struct snmp_pdu *, struct snmp_pdu *, void *);

/* type of callback function for timeouts */
typedef void (*snmp_timeout_cb_f)(void * );

/* timeout start function */
typedef void *(*snmp_timeout_start_f)(struct timeval *timeout,
    snmp_timeout_cb_f callback, void *);

/* timeout stop function */
typedef void (*snmp_timeout_stop_f)(void *timeout_id);

/*
 * Client context.
 */
struct snmp_client {
	enum snmp_version	version;
	int			trans;	/* which transport to use */

	/* these two are read-only for the application */
	char			*cport;	/* port number as string */
	char			*chost;	/* host name or IP address as string */

	char			read_community[SNMP_COMMUNITY_MAXLEN + 1];
	char			write_community[SNMP_COMMUNITY_MAXLEN + 1];

	/* SNMPv3 specific fields */
	int32_t			identifier;
	int32_t			security_model;
	struct snmp_engine	engine;
	struct snmp_user	user;

	/* SNMPv3 Access control - VACM*/
	uint32_t		clen;
	uint8_t			cengine[SNMP_ENGINE_ID_SIZ];
	char			cname[SNMP_CONTEXT_NAME_SIZ];

	struct timeval		timeout;
	u_int			retries;

	int			dump_pdus;

	size_t			txbuflen;
	size_t			rxbuflen;

	int			fd;

	int32_t			next_reqid;
	int32_t			max_reqid;
	int32_t			min_reqid;

	char			error[SNMP_STRERROR_LEN];

	snmp_timeout_start_f	timeout_start;
	snmp_timeout_stop_f	timeout_stop;

	char			local_path[sizeof(SNMP_LOCAL_PATH)];
};

/* the global context */
extern struct snmp_client snmp_client;

/* initizialies a snmp_client structure */
void snmp_client_init(struct snmp_client *);

/* initialize fields */
int snmp_client_set_host(struct snmp_client *, const char *);
int snmp_client_set_port(struct snmp_client *, const char *);

/* open connection to snmp server (hostname or portname can be NULL) */
int snmp_open(const char *_hostname, const char *_portname,
    const char *_read_community, const char *_write_community);

/* close connection */
void snmp_close(void);

/* initialize a snmp_pdu structure */
void snmp_pdu_create(struct snmp_pdu *, u_int _op);

/* add pairs of (struct asn_oid *, enum snmp_syntax) to an existing pdu */
int snmp_add_binding(struct snmp_pdu *, ...);

/* check wheater the answer is valid or not */
int snmp_pdu_check(const struct snmp_pdu *_req, const struct snmp_pdu *_resp);

int32_t snmp_pdu_send(struct snmp_pdu *_pdu, snmp_send_cb_f _func, void *_arg);

/*  append an index to an oid */
int snmp_oid_append(struct asn_oid *_oid, const char *_fmt, ...);

/* receive a packet */
int snmp_receive(int _blocking);

/*
 * This structure is used to describe an SNMP table that is to be fetched.
 * The C-structure that is produced by the fetch function must start with
 * a TAILQ_ENTRY and an u_int64_t.
 */
struct snmp_table {
	/* base OID of the table */
	struct asn_oid		table;
	/* type OID of the LastChange variable for the table if any */
	struct asn_oid		last_change;
	/* maximum number of iterations if table has changed */
	u_int			max_iter;
	/* size of the C-structure */
	size_t			entry_size;
	/* number of index fields */
	u_int			index_size;
	/* bit mask of required fields */
	uint64_t		req_mask;

	/* indexes and columns to fetch. Ended by a NULL syntax entry */
	struct snmp_table_entry {
	    /* the column sub-oid, ignored for index fields */
	    asn_subid_t		subid;
	    /* the syntax of the column or index */
	    enum snmp_syntax	syntax;
	    /* offset of the field into the C-structure. For octet strings
	     * this points to an u_char * followed by a size_t */
	    off_t		offset;
#if defined(__GNUC__) && __GNUC__ < 3
	}			entries[0];
#else
	}			entries[];
#endif
};

/* callback type for table fetch */
typedef void (*snmp_table_cb_f)(void *_list, void *_arg, int _res);

/* fetch a table. The argument points to a TAILQ_HEAD */
int snmp_table_fetch(const struct snmp_table *descr, void *);
int snmp_table_fetch_async(const struct snmp_table *, void *,
    snmp_table_cb_f, void *);

/* send a request and wait for the response */
int snmp_dialog(struct snmp_pdu *_req, struct snmp_pdu *_resp);

/* discover an authorative snmpEngineId */
int snmp_discover_engine(char *);

/* parse a server specification */
int snmp_parse_server(struct snmp_client *, const char *);

#endif /* _BSNMP_SNMPCLIENT_H */


code:
/*
 * Copyright (c) 2001-2003
 *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
 *	All rights reserved.
 *
 * Author: Harti Brandt <harti@freebsd.org>
 *
 * Copyright (c) 2010 The FreeBSD Foundation
 * All rights reserved.
 *
 * Portions of this software were developed by Shteryana Sotirova Shopova
 * under sponsorship from the FreeBSD Foundation.
 *
 * 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/snmpd/snmpmod.h,v 1.32 2006/02/14 09:04:20 brandt_h Exp $
 *
 * SNMP daemon data and functions exported to modules.
 */
#ifndef snmpmod_h_
#define snmpmod_h_

#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include "asn1.h"
#include "snmp.h"
#include "snmpagent.h"

#define MAX_MOD_ARGS	16

/*
 * These macros help to handle object lists for SNMP tables. They use
 * tail queues to hold the objects in ascending order in the list.
 * ordering can be done either on an integer/unsigned field, an asn_oid
 * or an ordering function.
 */
#define INSERT_OBJECT_OID_LINK_INDEX(PTR, LIST, LINK, INDEX) do {	\
	__typeof (PTR) _lelem;						\
									\
	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
		if (asn_compare_oid(&_lelem->INDEX, &(PTR)->INDEX) > 0)	\
			break;						\
	if (_lelem == NULL)						\
		TAILQ_INSERT_TAIL((LIST), (PTR), LINK);			\
	else								\
		TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK);		\
    } while (0)

#define INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, LINK, INDEX) do {	\
	__typeof (PTR) _lelem;						\
									\
	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
		if ((asn_subid_t)_lelem->INDEX > (asn_subid_t)(PTR)->INDEX)\
			break;						\
	if (_lelem == NULL)						\
		TAILQ_INSERT_TAIL((LIST), (PTR), LINK);			\
	else								\
		TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK);		\
    } while (0)

#define	INSERT_OBJECT_FUNC_LINK(PTR, LIST, LINK, FUNC) do {		\
	__typeof (PTR) _lelem;						\
									\
	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
		if ((FUNC)(_lelem, (PTR)) > 0)				\
			break;						\
	if (_lelem == NULL)						\
		TAILQ_INSERT_TAIL((LIST), (PTR), LINK);			\
	else								\
		TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK);		\
    } while (0)

#define	INSERT_OBJECT_FUNC_LINK_REV(PTR, LIST, HEAD, LINK, FUNC) do {	\
	__typeof (PTR) _lelem;						\
									\
	TAILQ_FOREACH_REVERSE(_lelem, (LIST), HEAD, LINK)		\
		if ((FUNC)(_lelem, (PTR)) < 0)				\
			break;						\
	if (_lelem == NULL)						\
		TAILQ_INSERT_HEAD((LIST), (PTR), LINK);			\
	else								\
		TAILQ_INSERT_AFTER((LIST), _lelem, (PTR), LINK);	\
    } while (0)

#define FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({	\
	__typeof (TAILQ_FIRST(LIST)) _lelem;				\
									\
	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
		if (index_compare(OID, SUB, &_lelem->INDEX) == 0)	\
			break;						\
	(_lelem);							\
    })

#define NEXT_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({	\
	__typeof (TAILQ_FIRST(LIST)) _lelem;				\
									\
	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
		if (index_compare(OID, SUB, &_lelem->INDEX) < 0)	\
			break;						\
	(_lelem);							\
    })

#define FIND_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({	\
	__typeof (TAILQ_FIRST(LIST)) _lelem;				\
									\
	if ((OID)->len - SUB != 1)					\
		_lelem = NULL;						\
	else								\
		TAILQ_FOREACH(_lelem, (LIST), LINK)			\
			if ((OID)->subs[SUB] == (asn_subid_t)_lelem->INDEX)\
				break;					\
	(_lelem);							\
    })

#define NEXT_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({	\
	__typeof (TAILQ_FIRST(LIST)) _lelem;				\
									\
	if ((OID)->len - SUB == 0)					\
		_lelem = TAILQ_FIRST(LIST);				\
	else								\
		TAILQ_FOREACH(_lelem, (LIST), LINK)			\
			if ((OID)->subs[SUB] < (asn_subid_t)_lelem->INDEX)\
				break;					\
	(_lelem);							\
    })

#define FIND_OBJECT_FUNC_LINK(LIST, OID, SUB, LINK, FUNC) ({		\
	__typeof (TAILQ_FIRST(LIST)) _lelem;				\
									\
	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
		if ((FUNC)(OID, SUB, _lelem) == 0)			\
			break;						\
	(_lelem);							\
    })

#define NEXT_OBJECT_FUNC_LINK(LIST, OID, SUB, LINK, FUNC) ({		\
	__typeof (TAILQ_FIRST(LIST)) _lelem;				\
									\
	TAILQ_FOREACH(_lelem, (LIST), LINK)				\
		if ((FUNC)(OID, SUB, _lelem) < 0)			\
			break;						\
	(_lelem);							\
    })

/*
 * Macros for the case where the index field is called 'index'
 */
#define INSERT_OBJECT_OID_LINK(PTR, LIST, LINK)				\
    INSERT_OBJECT_OID_LINK_INDEX(PTR, LIST, LINK, index)

#define INSERT_OBJECT_INT_LINK(PTR, LIST, LINK) do {			\
    INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, LINK, index)

#define FIND_OBJECT_OID_LINK(LIST, OID, SUB, LINK)			\
    FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, index)

#define NEXT_OBJECT_OID_LINK(LIST, OID, SUB, LINK)			\
    NEXT_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, index)

#define FIND_OBJECT_INT_LINK(LIST, OID, SUB, LINK)			\
    FIND_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, LINK, index)

#define NEXT_OBJECT_INT_LINK(LIST, OID, SUB, LINK)			\
    NEXT_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, LINK, index)

/*
 * Macros for the case where the index field is called 'index' and the
 * link field 'link'.
 */
#define INSERT_OBJECT_OID(PTR, LIST)					\
    INSERT_OBJECT_OID_LINK_INDEX(PTR, LIST, link, index)

#define INSERT_OBJECT_INT(PTR, LIST)					\
    INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, link, index)

#define	INSERT_OBJECT_FUNC_REV(PTR, LIST, HEAD, FUNC)			\
    INSERT_OBJECT_FUNC_LINK_REV(PTR, LIST, HEAD, link, FUNC)

#define FIND_OBJECT_OID(LIST, OID, SUB)					\
    FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, link, index)

#define FIND_OBJECT_INT(LIST, OID, SUB)					\
    FIND_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, link, index)

#define	FIND_OBJECT_FUNC(LIST, OID, SUB, FUNC)				\
    FIND_OBJECT_FUNC_LINK(LIST, OID, SUB, link, FUNC)

#define NEXT_OBJECT_OID(LIST, OID, SUB)					\
    NEXT_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, link, index)

#define NEXT_OBJECT_INT(LIST, OID, SUB)					\
    NEXT_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, link, index)

#define	NEXT_OBJECT_FUNC(LIST, OID, SUB, FUNC)				\
    NEXT_OBJECT_FUNC_LINK(LIST, OID, SUB, link, FUNC)

struct lmodule;

/* The tick when the program was started. This is the absolute time of
 * the start in 100th of a second. */
extern uint64_t start_tick;

/* The tick when the current packet was received. This is the absolute
 * time in 100th of second. */
extern uint64_t this_tick;

/* Get the current absolute time in 100th of a second. */
uint64_t get_ticks(void);

/*
 * Return code for proxy function
 */
enum snmpd_proxy_err {
	/* proxy code will process the PDU */
	SNMPD_PROXY_OK,
	/* proxy code does not process PDU */
	SNMPD_PROXY_REJ,
	/* drop this PDU */
	SNMPD_PROXY_DROP,
	/* drop because of bad community */
	SNMPD_PROXY_BADCOMM,
	/* drop because of bad community use */
	SNMPD_PROXY_BADCOMMUSE
};

/*
 * Input handling
 */
enum snmpd_input_err {
	/* proceed with packet */
	SNMPD_INPUT_OK,
	/* fatal error in packet, ignore it */
	SNMPD_INPUT_FAILED,
	/* value encoding has wrong length in a SET operation */
	SNMPD_INPUT_VALBADLEN,
	/* value encoding is out of range */
	SNMPD_INPUT_VALRANGE,
	/* value has bad encoding */
	SNMPD_INPUT_VALBADENC,
	/* need more data (truncated packet) */
	SNMPD_INPUT_TRUNC,
	/* unknown community */
	SNMPD_INPUT_BAD_COMM,
};

/*
 * Every loadable module must have one of this structures with
 * the external name 'config'.
 */
struct snmp_module {
	/* a comment describing what this module implements */
	const char *comment;

	/* the initialization function */
	int (*init)(struct lmodule *, int argc, char *argv[]);

	/* the finalisation function */
	int (*fini)(void);

	/* the idle function */
	void (*idle)(void);

	/* the dump function */
	void (*dump)(void);

	/* re-configuration function */
	void (*config)(void);

	/* start operation */
	void (*start)(void);

	/* proxy a PDU */
	enum snmpd_proxy_err (*proxy)(struct snmp_pdu *, void *,
	    const struct asn_oid *, const struct sockaddr *, socklen_t,
	    enum snmpd_input_err, int32_t, int);

	/* the tree this module is going to server */
	const struct snmp_node *tree;
	u_int tree_size;

	/* function called, when another module was unloaded/loaded */
	void (*loading)(const struct lmodule *, int);
};

/*
 * Stuff exported to modules
 */

/*
 * The system group.
 */
struct systemg {
	u_char		*descr;
	struct asn_oid	object_id;
	u_char		*contact;
	u_char		*name;
	u_char		*location;
	u_int32_t	services;
	u_int32_t	or_last_change;
};
extern struct systemg systemg;

/*
 * Community support.
 *
 * We have 2 fixed communities for SNMP read and write access. Modules
 * can create their communities dynamically. They are deleted automatically
 * if the module is unloaded.
 */
#define COMM_INITIALIZE	0
#define COMM_READ	1
#define COMM_WRITE	2

u_int comm_define(u_int, const char *descr, struct lmodule *, const char *str);
const char * comm_string(u_int);

/* community for current packet */
extern u_int community;

/*
 * SNMP User-based Security Model data. Modified via the snmp_usm(3) module.
 */
struct snmpd_usmstat {
	uint32_t	unsupported_seclevels;
	uint32_t	not_in_time_windows;
	uint32_t	unknown_users;
	uint32_t	unknown_engine_ids;
	uint32_t	wrong_digests;
	uint32_t	decrypt_errors;
};

extern struct snmpd_usmstat snmpd_usmstats;
struct snmpd_usmstat *bsnmpd_get_usm_stats(void);
void bsnmpd_reset_usm_stats(void);

struct usm_user {
	struct snmp_user		suser;
	uint8_t				user_engine_id[SNMP_ENGINE_ID_SIZ];
	uint32_t			user_engine_len;
	char				user_public[SNMP_ADM_STR32_SIZ];
	uint32_t			user_public_len;
	int32_t				status;
	int32_t				type;
	SLIST_ENTRY(usm_user)		up;
};

SLIST_HEAD(usm_userlist, usm_user);
struct usm_user *usm_first_user(void);
struct usm_user *usm_next_user(struct usm_user *);
struct usm_user *usm_find_user(uint8_t *, uint32_t, char *);
struct usm_user *usm_new_user(uint8_t *, uint32_t, char *);
void usm_delete_user(struct usm_user *);
void usm_flush_users(void);

/* USM user for current packet */
extern struct usm_user *usm_user;

/*
 * SNMP View-based Access Control Model data. Modified via the snmp_vacm(3) module.
 */
struct vacm_group;

struct vacm_user {
	/* Security user name from USM */
	char				secname[SNMP_ADM_STR32_SIZ];
	int32_t				sec_model;
	/* Back pointer to user assigned group name */
	struct vacm_group		*group;
	int32_t				type;
	int32_t				status;
	SLIST_ENTRY(vacm_user)		vvu;
	SLIST_ENTRY(vacm_user)		vvg;
};

SLIST_HEAD(vacm_userlist, vacm_user);

struct vacm_group {
	char				groupname[SNMP_ADM_STR32_SIZ];
	struct vacm_userlist		group_users;
	SLIST_ENTRY(vacm_group)		vge;
};

SLIST_HEAD(vacm_grouplist, vacm_group);

struct vacm_access {
	/* The group name is index, not a column in the table */
	struct vacm_group		*group;
	char				ctx_prefix[SNMP_ADM_STR32_SIZ];
	int32_t				sec_model;
	int32_t				sec_level;
	int32_t				ctx_match;
	struct vacm_view		*read_view;
	struct vacm_view		*write_view;
	struct vacm_view		*notify_view;
	int32_t				type;
	int32_t				status;
	TAILQ_ENTRY(vacm_access)	vva;
};

TAILQ_HEAD(vacm_accesslist, vacm_access);

struct vacm_view {
	char				viewname[SNMP_ADM_STR32_SIZ]; /* key */
	struct asn_oid			subtree; /* key */
	uint8_t				mask[16];
	uint8_t				exclude;
	int32_t				type;
	int32_t				status;
	SLIST_ENTRY(vacm_view)		vvl;
};

SLIST_HEAD(vacm_viewlist, vacm_view);

struct vacm_context {
	/* The ID of the module that registered this context */
	int32_t				regid;
	char				ctxname[SNMP_ADM_STR32_SIZ];
	SLIST_ENTRY(vacm_context)	vcl;
};

SLIST_HEAD(vacm_contextlist, vacm_context);

void vacm_groups_init(void);
struct vacm_user *vacm_first_user(void);
struct vacm_user *vacm_next_user(struct vacm_user *);
struct vacm_user *vacm_new_user(int32_t, char *);
int vacm_delete_user(struct vacm_user *);
int vacm_user_set_group(struct vacm_user *, u_char *, u_int);
struct vacm_access *vacm_first_access_rule(void);
struct vacm_access *vacm_next_access_rule(struct vacm_access *);
struct vacm_access *vacm_new_access_rule(char *, char *, int32_t, int32_t);
int vacm_delete_access_rule(struct vacm_access *);
struct vacm_view *vacm_first_view(void);
struct vacm_view *vacm_next_view(struct vacm_view *);
struct vacm_view *vacm_new_view(char *, struct asn_oid *);
int vacm_delete_view(struct vacm_view *);
struct vacm_context *vacm_first_context(void);
struct vacm_context *vacm_next_context(struct vacm_context *);
struct vacm_context *vacm_add_context(char *, int32_t);
void vacm_flush_contexts(int32_t);

/*
 * RFC 3413 SNMP Management Target & Notification MIB
 */

struct snmpd_target_stats {
	uint32_t			unavail_contexts;
	uint32_t			unknown_contexts;
};

#define	SNMP_UDP_ADDR_SIZ		6
#define	SNMP_TAG_SIZ			(255 + 1)

struct target_address {
	char				name[SNMP_ADM_STR32_SIZ];
	uint8_t				address[SNMP_UDP_ADDR_SIZ];
	int32_t				timeout;
	int32_t				retry;
	char				taglist[SNMP_TAG_SIZ];
	char				paramname[SNMP_ADM_STR32_SIZ];
	int32_t				type;
	int32_t				socket;
	int32_t				status;
	SLIST_ENTRY(target_address)	ta;
};

SLIST_HEAD(target_addresslist, target_address);

struct target_param {
	char				name[SNMP_ADM_STR32_SIZ];
	int32_t				mpmodel;
	int32_t				sec_model;
	char				secname[SNMP_ADM_STR32_SIZ];
	enum snmp_usm_level		sec_level;
	int32_t				type;
	int32_t				status;
	SLIST_ENTRY(target_param)	tp;
};

SLIST_HEAD(target_paramlist, target_param);

struct target_notify {
	char				name[SNMP_ADM_STR32_SIZ];
	char				taglist[SNMP_TAG_SIZ];
	int32_t				notify_type;
	int32_t				type;
	int32_t				status;
	SLIST_ENTRY(target_notify)	tn;
};

SLIST_HEAD(target_notifylist, target_notify);

extern struct snmpd_target_stats snmpd_target_stats;
struct snmpd_target_stats *bsnmpd_get_target_stats(void);
struct target_address *target_first_address(void);
struct target_address *target_next_address(struct target_address *);
struct target_address *target_new_address(char *);
int target_activate_address(struct target_address *);
int target_delete_address(struct target_address *);
struct target_param *target_first_param(void);
struct target_param *target_next_param(struct target_param *);
struct target_param *target_new_param(char *);
int target_delete_param(struct target_param *);
struct target_notify *target_first_notify(void);
struct target_notify *target_next_notify(struct target_notify *);
struct target_notify *target_new_notify(char *);
int target_delete_notify (struct target_notify *);
void target_flush_all(void);

/*
 * Well known OIDs
 */
extern const struct asn_oid oid_zeroDotZero;

/* SNMPv3 Engine Discovery */
extern const struct asn_oid oid_usmUnknownEngineIDs;
extern const struct asn_oid oid_usmNotInTimeWindows;

/*
 * Request ID ranges.
 *
 * A module can request a range of request ids and associate them with a
 * type field. All ranges are deleted if a module is unloaded.
 */
u_int reqid_allocate(int size, struct lmodule *);
int32_t reqid_next(u_int type);
int32_t reqid_base(u_int type);
int reqid_istype(int32_t reqid, u_int type);
u_int reqid_type(int32_t reqid);

/*
 * Timers.
 */
void *timer_start(u_int, void (*)(void *), void *, struct lmodule *);
void *timer_start_repeat(u_int, u_int, void (*)(void *), void *,
    struct lmodule *);
void timer_stop(void *);

/*
 * File descriptors
 */
void *fd_select(int, void (*)(int, void *), void *, struct lmodule *);
void fd_deselect(void *);
void fd_suspend(void *);
int fd_resume(void *);

/*
 * Object resources
 */
u_int or_register(const struct asn_oid *, const char *, struct lmodule *);
void or_unregister(u_int);

/*
 * Buffers
 */
void *buf_alloc(int tx);
size_t buf_size(int tx);

/* decode PDU and find community */
enum snmpd_input_err snmp_input_start(const u_char *, size_t, const char *,
    struct snmp_pdu *, int32_t *, size_t *);

/* process the pdu. returns either _OK or _FAILED */
enum snmpd_input_err snmp_input_finish(struct snmp_pdu *, const u_char *,
    size_t, u_char *, size_t *, const char *, enum snmpd_input_err, int32_t,
    void *);

void snmp_output(struct snmp_pdu *, u_char *, size_t *, const char *);
void snmp_send_port(void *, const struct asn_oid *, struct snmp_pdu *,
	const struct sockaddr *, socklen_t);
enum snmp_code snmp_pdu_auth_access(struct snmp_pdu *, int32_t *);

/* sending traps */
void snmp_send_trap(const struct asn_oid *, ...);

/*
 * Action support
 */
int string_save(struct snmp_value *, struct snmp_context *, ssize_t, u_char **);
void string_commit(struct snmp_context *);
void string_rollback(struct snmp_context *, u_char **);
int string_get(struct snmp_value *, const u_char *, ssize_t);
int string_get_max(struct snmp_value *, const u_char *, ssize_t, size_t);
void string_free(struct snmp_context *);

int ip_save(struct snmp_value *, struct snmp_context *, u_char *);
void ip_rollback(struct snmp_context *, u_char *);
void ip_commit(struct snmp_context *);
int ip_get(struct snmp_value *, u_char *);

int oid_save(struct snmp_value *, struct snmp_context *, struct asn_oid *);
void oid_rollback(struct snmp_context *, struct asn_oid *);
void oid_commit(struct snmp_context *);
int oid_get(struct snmp_value *, const struct asn_oid *);

int index_decode(const struct asn_oid *oid, u_int sub, u_int code, ...);
int index_compare(const struct asn_oid *, u_int, const struct asn_oid *);
int index_compare_off(const struct asn_oid *, u_int, const struct asn_oid *,
    u_int);
void index_append(struct asn_oid *, u_int, const struct asn_oid *);
void index_append_off(struct asn_oid *, u_int, const struct asn_oid *, u_int);

#endif


code:
/*-------------------------------------------------------------*/
/*--- Public header file for the library.                   ---*/
/*---                                               bzlib.h ---*/
/*-------------------------------------------------------------*/

/* ------------------------------------------------------------------
   This file is part of bzip2/libbzip2, a program and library for
   lossless, block-sorting data compression.

   bzip2/libbzip2 version 1.0.6 of 6 September 2010
   Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>

   Please read the WARNING, DISCLAIMER and PATENTS sections in the
   README file.

   This program is released under the terms of the license contained
   in the file LICENSE.
   ------------------------------------------------------------------ */

#ifndef _BZLIB_H
#define _BZLIB_H

#ifdef __cplusplus
extern "C" {
#endif

#define BZ_RUN               0
#define BZ_FLUSH             1
#define BZ_FINISH            2

#define BZ_OK                0
#define BZ_RUN_OK            1
#define BZ_FLUSH_OK          2
#define BZ_FINISH_OK         3
#define BZ_STREAM_END        4
#define BZ_SEQUENCE_ERROR    (-1)
#define BZ_PARAM_ERROR       (-2)
#define BZ_MEM_ERROR         (-3)
#define BZ_DATA_ERROR        (-4)
#define BZ_DATA_ERROR_MAGIC  (-5)
#define BZ_IO_ERROR          (-6)
#define BZ_UNEXPECTED_EOF    (-7)
#define BZ_OUTBUFF_FULL      (-8)
#define BZ_CONFIG_ERROR      (-9)

typedef
   struct {
      char *next_in;
      unsigned int avail_in;
      unsigned int total_in_lo32;
      unsigned int total_in_hi32;

      char *next_out;
      unsigned int avail_out;
      unsigned int total_out_lo32;
      unsigned int total_out_hi32;

      void *state;

      void *(*bzalloc)(void *,int,int);
      void (*bzfree)(void *,void *);
      void *opaque;
   }
   bz_stream;

#ifndef BZ_IMPORT
#define BZ_EXPORT
#endif

#ifndef BZ_NO_STDIO
/* Need a definitition for FILE */
#include <stdio.h>
#endif

#ifdef _WIN32
#   include <windows.h>
#   ifdef small
      /* windows.h define small to char */
#      undef small
#   endif
#   ifdef BZ_EXPORT
#   define BZ_API(func) WINAPI func
#   define BZ_EXTERN extern
#   else
   /* import windows dll dynamically */
#   define BZ_API(func) (WINAPI * func)
#   define BZ_EXTERN
#   endif
#else
#   define BZ_API(func) func
#   define BZ_EXTERN extern
#endif

/*-- Core (low-level) library functions --*/

BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
      bz_stream* strm,
      int        blockSize100k,
      int        verbosity,
      int        workFactor
   );

BZ_EXTERN int BZ_API(BZ2_bzCompress) (
      bz_stream* strm,
      int action
   );

BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
      bz_stream* strm
   );

BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
      bz_stream *strm,
      int       verbosity,
      int       small
   );

BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
      bz_stream* strm
   );

BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
      bz_stream *strm
   );

/*-- High(er) level library functions --*/

#ifndef BZ_NO_STDIO
#define BZ_MAX_UNUSED 5000

typedef void BZFILE;

BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
      int*  bzerror,
      FILE* f,
      int   verbosity,
      int   small,
      void* unused,
      int   nUnused
   );

BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
      int*    bzerror,
      BZFILE* b
   );

BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
      int*    bzerror,
      BZFILE* b,
      void**  unused,
      int*    nUnused
   );

BZ_EXTERN int BZ_API(BZ2_bzRead) (
      int*    bzerror,
      BZFILE* b,
      void*   buf,
      int     len
   );

BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
      int*  bzerror,
      FILE* f,
      int   blockSize100k,
      int   verbosity,
      int   workFactor
   );

BZ_EXTERN void BZ_API(BZ2_bzWrite) (
      int*    bzerror,
      BZFILE* b,
      void*   buf,
      int     len
   );

BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
      int*          bzerror,
      BZFILE*       b,
      int           abandon,
      unsigned int* nbytes_in,
      unsigned int* nbytes_out
   );

BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
      int*          bzerror,
      BZFILE*       b,
      int           abandon,
      unsigned int* nbytes_in_lo32,
      unsigned int* nbytes_in_hi32,
      unsigned int* nbytes_out_lo32,
      unsigned int* nbytes_out_hi32
   );
#endif

/*-- Utility functions --*/

BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
      char*         dest,
      unsigned int* destLen,
      char*         source,
      unsigned int  sourceLen,
      int           blockSize100k,
      int           verbosity,
      int           workFactor
   );

BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
      char*         dest,
      unsigned int* destLen,
      char*         source,
      unsigned int  sourceLen,
      int           small,
      int           verbosity
   );

/*--
   Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
   to support better zlib compatibility.
   This code is not _officially_ part of libbzip2 (yet);
   I haven't tested it, documented it, or considered the
   threading-safeness of it.
   If this code breaks, please contact both Yoshioka and me.
--*/

BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
      void
   );

#ifndef BZ_NO_STDIO
BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
      const char *path,
      const char *mode
   );

BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
      int        fd,
      const char *mode
   );

BZ_EXTERN int BZ_API(BZ2_bzread) (
      BZFILE* b,
      void* buf,
      int len
   );

BZ_EXTERN int BZ_API(BZ2_bzwrite) (
      BZFILE* b,
      void*   buf,
      int     len
   );

BZ_EXTERN int BZ_API(BZ2_bzflush) (
      BZFILE* b
   );

BZ_EXTERN void BZ_API(BZ2_bzclose) (
      BZFILE* b
   );

BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
      BZFILE *b,
      int    *errnum
   );
#endif

#ifdef __cplusplus
}
#endif

#endif

/*-------------------------------------------------------------*/
/*--- end                                           bzlib.h ---*/
/*-------------------------------------------------------------*/


code:
// <algorithm> -*- C++ -*-

// Copyright (C) 2001, 2002 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

/*
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Hewlett-Packard Company makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 *
 * Copyright (c) 1996,1997
 * Silicon Graphics Computer Systems, Inc.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Silicon Graphics makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 */

/** @file include/algorithm
 *  This is a Standard C++ Library header.
 */

#ifndef _GLIBCXX_ALGORITHM
#define _GLIBCXX_ALGORITHM 1

#pragma GCC system_header

#include <bits/stl_algobase.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
#include <bits/stl_algo.h>

#endif /* _GLIBCXX_ALGORITHM */


code:
// Backward-compat support -*- C++ -*-

// Copyright (C) 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

/*
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Hewlett-Packard Company makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 *
 * Copyright (c) 1996,1997
 * Silicon Graphics Computer Systems, Inc.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Silicon Graphics makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 */

#ifndef _BACKWARD_ALGO_H
#define _BACKWARD_ALGO_H 1

#include "backward_warning.h"
#include "algobase.h"
#include "tempbuf.h"
#include "iterator.h"
#include <bits/stl_algo.h>
#include <bits/stl_numeric.h>
#include <ext/algorithm>
#include <ext/numeric>

// Names from <stl_algo.h>
using std::for_each;
using std::find;
using std::find_if;
using std::adjacent_find;
using std::count;
using std::count_if;
using std::search;
using std::search_n;
using std::swap_ranges;
using std::transform;
using std::replace;
using std::replace_if;
using std::replace_copy;
using std::replace_copy_if;
using std::generate;
using std::generate_n;
using std::remove;
using std::remove_if;
using std::remove_copy;
using std::remove_copy_if;
using std::unique;
using std::unique_copy;
using std::reverse;
using std::reverse_copy;
using std::rotate;
using std::rotate_copy;
using std::random_shuffle;
using std::partition;
using std::stable_partition;
using std::sort;
using std::stable_sort;
using std::partial_sort;
using std::partial_sort_copy;
using std::nth_element;
using std::lower_bound;
using std::upper_bound;
using std::equal_range;
using std::binary_search;
using std::merge;
using std::inplace_merge;
using std::includes;
using std::set_union;
using std::set_intersection;
using std::set_difference;
using std::set_symmetric_difference;
using std::min_element;
using std::max_element;
using std::next_permutation;
using std::prev_permutation;
using std::find_first_of;
using std::find_end;

// Names from stl_heap.h
using std::push_heap;
using std::pop_heap;
using std::make_heap;
using std::sort_heap;

// Names from stl_numeric.h
using std::accumulate;
using std::inner_product;
using std::partial_sum;
using std::adjacent_difference;

// Names from ext/algorithm
using __gnu_cxx::random_sample;
using __gnu_cxx::random_sample_n;
using __gnu_cxx::is_sorted;
using __gnu_cxx::is_heap;
using __gnu_cxx::count;   // Extension returning void
using __gnu_cxx::count_if;   // Extension returning void

// Names from ext/numeric
using __gnu_cxx::power;
using __gnu_cxx::iota;

#endif /* _BACKWARD_ALGO_H */


code:
// Backward-compat support -*- C++ -*-

// Copyright (C) 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

/*
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Hewlett-Packard Company makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 * Copyright (c) 1996,1997
 * Silicon Graphics Computer Systems, Inc.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Silicon Graphics makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 */

#ifndef _BACKWARD_ALGOBASE_H
#define _BACKWARD_ALGOBASE_H 1

#include "backward_warning.h"
#include "pair.h"
#include "iterator.h"
#include <bits/stl_algobase.h>
#include <bits/stl_uninitialized.h>
#include <ext/algorithm>
#include <ext/memory>

// Names from stl_algobase.h
using std::iter_swap;
using std::swap;
using std::min;
using std::max;
using std::copy;
using std::copy_backward;
using std::fill;
using std::fill_n;
using std::mismatch;
using std::equal;
using std::lexicographical_compare;

// Names from stl_uninitialized.h
using std::uninitialized_copy;
using std::uninitialized_fill;
using std::uninitialized_fill_n;

// Names from ext/algorithm
using __gnu_cxx::copy_n;
using __gnu_cxx::lexicographical_compare_3way;

// Names from ext/memory
using __gnu_cxx::uninitialized_copy_n;

#endif /* _BACKWARD_ALGOBASE_H */


code:
// Backward-compat support -*- C++ -*-

// Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

/*
 * Copyright (c) 1996-1997
 * Silicon Graphics Computer Systems, Inc.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Silicon Graphics makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 */

#ifndef _BACKWARD_ALLOC_H
#define _BACKWARD_ALLOC_H 1

#include "backward_warning.h"
#include <bits/c++config.h>
#include <bits/allocator.h>

using std::allocator;

#endif


code:
// Copyright (C) 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

#ifndef _BACKWARD_BACKWARD_WARNING_H
#define _BACKWARD_BACKWARD_WARNING_H 1

#ifdef __DEPRECATED
#warning This file includes at least one deprecated or antiquated header. \
Please consider using one of the 32 headers found in section 17.4.1.2 of the \
C++ standard. Examples include substituting the <X> header for the <X.h> \
header for C++ includes, or <iostream> instead of the deprecated header \
<iostream.h>. To disable this warning use -Wno-deprecated.
#endif

#endif


code:
// Backward-compat support -*- C++ -*-

// Copyright (C) 2001, 2004 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

/*
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Hewlett-Packard Company makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 *
 * Copyright (c) 1996
 * Silicon Graphics Computer Systems, Inc.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Silicon Graphics makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 */

#ifndef _BACKWARD_BVECTOR_H
#define _BACKWARD_BVECTOR_H 1

#include "backward_warning.h"
#include <vector>

typedef std::vector<bool, std::allocator<bool> > bit_vector;

#endif /* _BACKWARD_BVECTOR_H */


code:
// Copyright (C) 2000 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

#ifndef _BACKWARD_COMPLEX_H
#define _BACKWARD_COMPLEX_H 1

#include "backward_warning.h"
#include <complex>

using std::complex;
typedef complex<float>		float_complex;
typedef complex<double>		double_complex;
typedef complex<long double>	long_double_complex;

#endif


code:
// Backward-compat support -*- C++ -*-

// Copyright (C) 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

/*
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Hewlett-Packard Company makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 */

// Inclusion of this file is DEPRECATED.  This is the original HP
// default allocator.  It is provided only for backward compatibility.
// This file WILL BE REMOVED in a future release.
//
// DO NOT USE THIS FILE unless you have an old container implementation
// that requires an allocator with the HP-style interface.
//
// Standard-conforming allocators have a very different interface.  The
// standard default allocator is declared in the header <memory>.

#ifndef _BACKWARD_DEFALLOC_H
#define _BACKWARD_DEFALLOC_H 1

#include "backward_warning.h"
#include "new.h"
#include <stddef.h>
#include <stdlib.h>
#include <limits.h>
#include "iostream.h"
#include "algobase.h"

template <class _Tp>
inline _Tp* allocate(ptrdiff_t __size, _Tp*) {
    set_new_handler(0);
    _Tp* __tmp = (_Tp*)(::operator new((size_t)(__size * sizeof(_Tp))));
    if (__tmp == 0) {
	cerr << "out of memory" << endl;
	exit(1);
    }
    return __tmp;
}

template <class _Tp>
inline void deallocate(_Tp* __buffer) {
    ::operator delete(__buffer);
}

template <class _Tp>
class allocator {
public:
    typedef _Tp value_type;
    typedef _Tp* pointer;
    typedef const _Tp* const_pointer;
    typedef _Tp& reference;
    typedef const _Tp& const_reference;
    typedef size_t size_type;
    typedef ptrdiff_t difference_type;
    pointer allocate(size_type __n) {
	return ::allocate((difference_type)__n, (pointer)0);
    }
    void deallocate(pointer __p) { ::deallocate(__p); }
    pointer address(reference __x) { return (pointer)&__x; }
    const_pointer const_address(const_reference __x) {
	return (const_pointer)&__x;
    }
    size_type init_page_size() {
	return max(size_type(1), size_type(4096/sizeof(_Tp)));
    }
    size_type max_size() const {
	return max(size_type(1), size_type(UINT_MAX/sizeof(_Tp)));
    }
};

class allocator<void> {
public:
    typedef void* pointer;
};

#endif /* _BACKWARD_DEFALLOC_H */


code:
// Backward-compat support -*- C++ -*-

// Copyright (C) 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

/*
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Hewlett-Packard Company makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 *
 * Copyright (c) 1997
 * Silicon Graphics Computer Systems, Inc.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Silicon Graphics makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 */

#ifndef _BACKWARD_DEQUE_H
#define _BACKWARD_DEQUE_H 1

#include "backward_warning.h"
#include "algobase.h"
#include "alloc.h"
#include <deque>

using std::deque;

#endif /* _BACKWARD_DEQUE_H */


code:
// Copyright (C) 2000, 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

#ifndef _BACKWARD_FSTREAM_H
#define _BACKWARD_FSTREAM_H 1

#include "backward_warning.h"
#include <fstream>

using std::filebuf;
using std::ifstream;
using std::ofstream;
using std::fstream;
using std::streampos;

#ifdef _GLIBCXX_USE_WCHAR_T
using std::wfilebuf;
using std::wifstream;
using std::wofstream;
using std::wfstream;
using std::wstreampos;
#endif

#endif


code:
// Backward-compat support -*- C++ -*-

// Copyright (C) 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

/*
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Hewlett-Packard Company makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 *
 * Copyright (c) 1996,1997
 * Silicon Graphics Computer Systems, Inc.
 *
 * Permission to use, copy, modify, distribute and sell this software
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.  Silicon Graphics makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 */

#ifndef _BACKWARD_FUNCTION_H
#define _BACKWARD_FUNCTION_H 1

#include "backward_warning.h"
#include <bits/c++config.h>
#include <stddef.h>
#include <bits/stl_function.h>
#include <ext/functional>

// Names from stl_function.h
using std::unary_function;
using std::binary_function;
using std::plus;
using std::minus;
using std::multiplies;
using std::divides;
using std::modulus;
using std::negate;
using std::equal_to;
using std::not_equal_to;
using std::greater;
using std::less;
using std::greater_equal;
using std::less_equal;
using std::logical_and;
using std::logical_or;
using std::logical_not;
using std::unary_negate;
using std::binary_negate;
using std::not1;
using std::not2;
using std::binder1st;
using std::binder2nd;
using std::bind1st;
using std::bind2nd;
using std::pointer_to_unary_function;
using std::pointer_to_binary_function;
using std::ptr_fun;
using std::mem_fun_t;
using std::const_mem_fun_t;
using std::mem_fun_ref_t;
using std::const_mem_fun_ref_t;
using std::mem_fun1_t;
using std::const_mem_fun1_t;
using std::mem_fun1_ref_t;
using std::const_mem_fun1_ref_t;
using std::mem_fun;
using std::mem_fun_ref;

// Names from ext/functional
using __gnu_cxx::identity_element;
using __gnu_cxx::unary_compose;
using __gnu_cxx::binary_compose;
using __gnu_cxx::compose1;
using __gnu_cxx::compose2;
using __gnu_cxx::identity;
using __gnu_cxx::select1st;
using __gnu_cxx::select2nd;
using __gnu_cxx::project1st;
using __gnu_cxx::project2nd;
using __gnu_cxx::constant_void_fun;
using __gnu_cxx::constant_unary_fun;
using __gnu_cxx::constant_binary_fun;
using __gnu_cxx::constant0;
using __gnu_cxx::constant1;
using __gnu_cxx::constant2;
using __gnu_cxx::subtractive_rng;
using __gnu_cxx::mem_fun1;
using __gnu_cxx::mem_fun1_ref;

#endif /* _BACKWARD_FUNCTION_H */