913ad8b93a9f1c31ae8ca54df392ccadb764cc44
[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 #define SMUX_PORT_DEFAULT 199
15
16 #define SMUXMAXPKTSIZE    1500
17 #define SMUXMAXSTRLEN      256
18
19 #define SMUX_OPEN       (ASN_APPLICATION | ASN_CONSTRUCTOR | 0)
20 #define SMUX_CLOSE      (ASN_APPLICATION | ASN_PRIMITIVE | 1)
21 #define SMUX_RREQ       (ASN_APPLICATION | ASN_CONSTRUCTOR | 2)
22 #define SMUX_RRSP       (ASN_APPLICATION | ASN_PRIMITIVE | 3)
23 #define SMUX_SOUT       (ASN_APPLICATION | ASN_PRIMITIVE | 4)
24
25 #define SMUX_GET        (ASN_CONTEXT | ASN_CONSTRUCTOR | 0)
26 #define SMUX_GETNEXT    (ASN_CONTEXT | ASN_CONSTRUCTOR | 1)
27 #define SMUX_GETRSP     (ASN_CONTEXT | ASN_CONSTRUCTOR | 2)
28 #define SMUX_SET        (ASN_CONTEXT | ASN_CONSTRUCTOR | 3)
29
30 /* Structures here are mostly compatible with UCD SNMP 4.1.1 */
31
32 #define MATCH_FAILED     (-1)
33 #define MATCH_SUCCEEDED  0
34
35 struct variable;
36
37 #define REGISTER_MIB(descr, var, vartype, theoid)               \
38     smux_register_mib(descr, (struct variable *)var, sizeof(struct vartype), \
39     sizeof(var)/sizeof(struct vartype),                 \
40     theoid, sizeof(theoid)/sizeof(oid))
41
42 typedef int (WriteMethod)(int action,
43                           u_char  *var_val,
44                           u_char   var_val_type,
45                           size_t   var_val_len,
46                           const unsigned char  *statP,
47                           oid     *name,
48                           size_t   length);
49
50 typedef const unsigned char *(FindVarMethod)(struct variable *vp,
51   oid     *name,
52   size_t  *length,
53   int      exact,
54   size_t  *var_len,
55   WriteMethod   **write_method);
56
57 /* List */
58 struct list
59 {
60   struct list *next;
61   void        *data;
62 };
63
64 /* SNMP variable */
65 struct variable
66 {
67   /* Index of the MIB.*/
68   u_char magic;
69
70   /* Type of variable. */
71   char type;
72
73   /* Access control list. */
74   u_short acl;
75
76   /* Callback function. */
77   FindVarMethod *findVar;
78
79   /* Suffix of the MIB. */
80   u_char namelen;
81   oid name[MAX_OID_LEN];
82 };
83
84 /* SNMP tree. */
85 struct subtree
86 {
87   /* Tree's oid. */
88   oid name[MAX_OID_LEN];
89   u_char name_len;
90
91   /* List of the variables. */
92   struct variable *variables;
93
94   /* Length of the variables list. */
95   int variables_num;
96
97   /* Width of the variables list. */
98   int variables_width;
99
100   /* Registered flag. */
101   int registered;
102 };
103
104 /* Declare SMUX return value. */
105 #define SNMP_LOCAL_VARIABLES \
106   static int32_t snmp_int_val; \
107   static struct in_addr snmp_in_addr_val;
108
109 #define SNMP_INTEGER(V) \
110   ( \
111     *var_len = sizeof (int32_t), \
112     snmp_int_val = V, \
113     (u_char *) &snmp_int_val \
114   )
115
116 #define SNMP_IPADDRESS(V) \
117   ( \
118     *var_len = sizeof (struct in_addr), \
119     snmp_in_addr_val = V, \
120     (u_char *) &snmp_in_addr_val \
121   )
122
123 typedef enum smux_event_t {
124   SMUX_NONE, SMUX_CONNECT, SMUX_READ
125 } smux_event_t;
126
127 void smux_init(oid [], size_t);
128 void smux_start(void);
129 void smux_stop(void);
130 void smux_register_mib(const char *, struct variable *, size_t, int, oid [], size_t);
131 int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *, 
132     WriteMethod **);
133 int smux_open(void);
134 int smux_str2oid (char *str, oid *my_oid, size_t *oid_len);
135 oid *smux_oid_dup (oid *objid, size_t objid_len);
136 int smux_register(void);
137
138 #endif /* _SMUX_H */