Add libtool-ltdl-devel as a prerequisite for building.
[freeradius.git] / src / include / smux.h
1 /* SNMP support
2  * Copyright (C) 2000 Jochen Friedrich <jochen@scram.de>
3  * Copyright (C) 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
4  *
5  * You should have received a copy of the GNU General Public License
6  * along with GNU Zebra; see the file COPYING.  If not, write to the Free
7  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
8  * 02111-1307, USA.
9  */
10
11 #ifndef _SMUX_H
12 #define _SMUX_H
13
14 #ifdef HAVE_ASN1_SNMP_SNMPIMPL_H
15 #include <asn1.h>
16 #include <snmp.h>
17 #include <snmp_impl.h>
18 #else
19 # ifdef HAVE_UCD_SNMP_ASN1_SNMP_SNMPIMPL_H
20 # include <ucd-snmp/ucd-snmp-config.h>
21 # include <ucd-snmp/asn1.h>
22 # include <ucd-snmp/snmp.h>
23 # include <ucd-snmp/snmp_impl.h>
24 # endif
25 #endif
26
27 #define SMUX_PORT_DEFAULT 199
28
29 #define SMUXMAXPKTSIZE    1500
30 #define SMUXMAXSTRLEN      256
31
32 #define SMUX_OPEN       (ASN_APPLICATION | ASN_CONSTRUCTOR | 0)
33 #define SMUX_CLOSE      (ASN_APPLICATION | ASN_PRIMITIVE | 1)
34 #define SMUX_RREQ       (ASN_APPLICATION | ASN_CONSTRUCTOR | 2)
35 #define SMUX_RRSP       (ASN_APPLICATION | ASN_PRIMITIVE | 3)
36 #define SMUX_SOUT       (ASN_APPLICATION | ASN_PRIMITIVE | 4)
37
38 #define SMUX_GET        (ASN_CONTEXT | ASN_CONSTRUCTOR | 0)
39 #define SMUX_GETNEXT    (ASN_CONTEXT | ASN_CONSTRUCTOR | 1)
40 #define SMUX_GETRSP     (ASN_CONTEXT | ASN_CONSTRUCTOR | 2)
41 #define SMUX_SET        (ASN_CONTEXT | ASN_CONSTRUCTOR | 3)
42
43 /* Structures here are mostly compatible with UCD SNMP 4.1.1 */
44
45 #define MATCH_FAILED     (-1)
46 #define MATCH_SUCCEEDED  0
47
48 struct variable;
49
50 #define REGISTER_MIB(descr, var, vartype, theoid)               \
51     smux_register_mib(descr, (struct variable *)var, sizeof(struct vartype), \
52     sizeof(var)/sizeof(struct vartype),                 \
53     theoid, sizeof(theoid)/sizeof(oid))
54
55 typedef int (WriteMethod)(int action,
56                           u_char  *var_val,
57                           u_char   var_val_type,
58                           size_t   var_val_len,
59                           const unsigned char  *statP,
60                           oid     *name,
61                           size_t   length);
62
63 typedef const unsigned char *(FindVarMethod)(struct variable *vp,
64   oid     *name,
65   size_t  *length,
66   int      exact,
67   size_t  *var_len,
68   WriteMethod   **write_method);
69
70 /* List */
71 struct list
72 {
73   struct list *next;
74   void        *data;
75 };
76
77 /* SNMP variable */
78 struct variable
79 {
80   /* Index of the MIB.*/
81   u_char magic;
82
83   /* Type of variable. */
84   char type;
85
86   /* Access control list. */
87   u_short acl;
88
89   /* Callback function. */
90   FindVarMethod *findVar;
91
92   /* Suffix of the MIB. */
93   u_char namelen;
94   oid name[MAX_OID_LEN];
95 };
96
97 /* SNMP tree. */
98 struct subtree
99 {
100   /* Tree's oid. */
101   oid name[MAX_OID_LEN];
102   u_char name_len;
103
104   /* List of the variables. */
105   struct variable *variables;
106
107   /* Length of the variables list. */
108   int variables_num;
109
110   /* Width of the variables list. */
111   int variables_width;
112
113   /* Registered flag. */
114   int registered;
115 };
116
117 /* Declare SMUX return value. */
118 #define SNMP_LOCAL_VARIABLES \
119   static int32_t snmp_int_val; \
120   static struct in_addr snmp_in_addr_val;
121
122 #define SNMP_INTEGER(V) \
123   ( \
124     *var_len = sizeof (int32_t), \
125     snmp_int_val = V, \
126     (u_char *) &snmp_int_val \
127   )
128
129 #define SNMP_IPADDRESS(V) \
130   ( \
131     *var_len = sizeof (struct in_addr), \
132     snmp_in_addr_val = V, \
133     (u_char *) &snmp_in_addr_val \
134   )
135
136 void smux_init(oid [], size_t);
137 void smux_start(void);
138 void smux_stop(void);
139 void smux_register_mib(const char *, struct variable *, size_t, int, oid [], size_t);
140 int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *,
141     WriteMethod **);
142 int smux_open(void);
143 int smux_str2oid (char *str, oid *my_oid, size_t *oid_len);
144 oid *smux_oid_dup (oid *objid, size_t objid_len);
145 int smux_register(void);
146
147 #endif /* _SMUX_H */