document rlm_otp fd leak fix
[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  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #ifndef _SMUX_H
21 #define _SMUX_H
22
23 #ifdef HAVE_ASN1_SNMP_SNMPIMPL_H
24 #include <asn1.h>
25 #include <snmp.h>
26 #include <snmp_impl.h>
27 #else
28 # ifdef HAVE_UCD_SNMP_ASN1_SNMP_SNMPIMPL_H
29 # include <ucd-snmp/ucd-snmp-config.h>
30 # include <ucd-snmp/asn1.h>
31 # include <ucd-snmp/snmp.h>
32 # include <ucd-snmp/snmp_impl.h>
33 # endif
34 #endif
35
36 #define SMUX_PORT_DEFAULT 199
37
38 #define SMUXMAXPKTSIZE    1500
39 #define SMUXMAXSTRLEN      256
40
41 #define SMUX_OPEN       (ASN_APPLICATION | ASN_CONSTRUCTOR | 0)
42 #define SMUX_CLOSE      (ASN_APPLICATION | ASN_PRIMITIVE | 1)
43 #define SMUX_RREQ       (ASN_APPLICATION | ASN_CONSTRUCTOR | 2)
44 #define SMUX_RRSP       (ASN_APPLICATION | ASN_PRIMITIVE | 3)
45 #define SMUX_SOUT       (ASN_APPLICATION | ASN_PRIMITIVE | 4)
46
47 #define SMUX_GET        (ASN_CONTEXT | ASN_CONSTRUCTOR | 0)
48 #define SMUX_GETNEXT    (ASN_CONTEXT | ASN_CONSTRUCTOR | 1)
49 #define SMUX_GETRSP     (ASN_CONTEXT | ASN_CONSTRUCTOR | 2)
50 #define SMUX_SET        (ASN_CONTEXT | ASN_CONSTRUCTOR | 3)
51
52 /* Structures here are mostly compatible with UCD SNMP 4.1.1 */
53
54 #define MATCH_FAILED     (-1)
55 #define MATCH_SUCCEEDED  0
56
57 struct variable;
58
59 #define REGISTER_MIB(descr, var, vartype, theoid)               \
60     smux_register_mib(descr, (struct variable *)var, sizeof(struct vartype), \
61     sizeof(var)/sizeof(struct vartype),                 \
62     theoid, sizeof(theoid)/sizeof(oid))
63
64 typedef int (WriteMethod)(int action,
65                           u_char  *var_val,
66                           u_char   var_val_type,
67                           size_t   var_val_len,
68                           const unsigned char  *statP,
69                           oid     *name,
70                           size_t   length);
71
72 typedef const unsigned char *(FindVarMethod)(struct variable *vp,
73   oid     *name,
74   size_t  *length,
75   int      exact,
76   size_t  *var_len,
77   WriteMethod   **write_method);
78
79 /* List */
80 struct list
81 {
82   struct list *next;
83   void        *data;
84 };
85
86 /* SNMP variable */
87 struct variable
88 {
89   /* Index of the MIB.*/
90   u_char magic;
91
92   /* Type of variable. */
93   char type;
94
95   /* Access control list. */
96   u_short acl;
97
98   /* Callback function. */
99   FindVarMethod *findVar;
100
101   /* Suffix of the MIB. */
102   u_char namelen;
103   oid name[MAX_OID_LEN];
104 };
105
106 /* SNMP tree. */
107 struct subtree
108 {
109   /* Tree's oid. */
110   oid name[MAX_OID_LEN];
111   u_char name_len;
112
113   /* List of the variables. */
114   struct variable *variables;
115
116   /* Length of the variables list. */
117   int variables_num;
118
119   /* Width of the variables list. */
120   int variables_width;
121
122   /* Registered flag. */
123   int registered;
124 };
125
126 /* Declare SMUX return value. */
127 #define SNMP_LOCAL_VARIABLES \
128   static int32_t snmp_int_val; \
129   static struct in_addr snmp_in_addr_val;
130
131 #define SNMP_INTEGER(V) \
132   ( \
133     *var_len = sizeof (int32_t), \
134     snmp_int_val = V, \
135     (u_char *) &snmp_int_val \
136   )
137
138 #define SNMP_IPADDRESS(V) \
139   ( \
140     *var_len = sizeof (struct in_addr), \
141     snmp_in_addr_val = V, \
142     (u_char *) &snmp_in_addr_val \
143   )
144
145 void smux_init(oid [], size_t);
146 void smux_start(void);
147 void smux_stop(void);
148 void smux_register_mib(const char *, struct variable *, size_t, int, oid [], size_t);
149 int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *,
150     WriteMethod **);
151 int smux_open(void);
152 int smux_str2oid (char *str, oid *my_oid, size_t *oid_len);
153 oid *smux_oid_dup (oid *objid, size_t objid_len);
154 int smux_register(void);
155
156 #endif /* _SMUX_H */