]> git.proxmox.com Git - mirror_frr.git/blob - lib/smux.h
2004-10-11 Paul Jakma <paul@dishone.st>
[mirror_frr.git] / lib / smux.h
1 /* SNMP support
2 * Copyright (C) 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22 #ifndef _ZEBRA_SNMP_H
23 #define _ZEBRA_SNMP_H
24
25 #define SMUX_PORT_DEFAULT 199
26
27 #define SMUXMAXPKTSIZE 1500
28 #define SMUXMAXSTRLEN 256
29
30 #define SMUX_OPEN (ASN_APPLICATION | ASN_CONSTRUCTOR | 0)
31 #define SMUX_CLOSE (ASN_APPLICATION | ASN_PRIMITIVE | 1)
32 #define SMUX_RREQ (ASN_APPLICATION | ASN_CONSTRUCTOR | 2)
33 #define SMUX_RRSP (ASN_APPLICATION | ASN_PRIMITIVE | 3)
34 #define SMUX_SOUT (ASN_APPLICATION | ASN_PRIMITIVE | 4)
35
36 #define SMUX_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0)
37 #define SMUX_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 1)
38 #define SMUX_GETRSP (ASN_CONTEXT | ASN_CONSTRUCTOR | 2)
39 #define SMUX_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 3)
40 #define SMUX_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 4)
41
42 #define SMUX_MAX_FAILURE 3
43
44 /* Structures here are mostly compatible with UCD SNMP 4.1.1 */
45 #define MATCH_FAILED (-1)
46 #define MATCH_SUCCEEDED 0
47
48 /* SYNTAX TruthValue from SNMPv2-TC. */
49 #define SNMP_TRUE 1
50 #define SNMP_FALSE 2
51
52 /* SYNTAX RowStatus from SNMPv2-TC. */
53 #define SNMP_VALID 1
54 #define SNMP_INVALID 2
55
56 #define IN_ADDR_SIZE sizeof(struct in_addr)
57
58 struct variable;
59
60 #define REGISTER_MIB(descr, var, vartype, theoid) \
61 smux_register_mib(descr, (struct variable *)var, sizeof(struct vartype), \
62 sizeof(var)/sizeof(struct vartype), \
63 theoid, sizeof(theoid)/sizeof(oid))
64
65 typedef int (WriteMethod)(int action,
66 u_char *var_val,
67 u_char var_val_type,
68 size_t var_val_len,
69 u_char *statP,
70 oid *name,
71 size_t length,
72 struct variable *v);
73
74 typedef u_char *(FindVarMethod)(struct variable *v,
75 oid *name,
76 size_t *length,
77 int exact,
78 size_t *var_len,
79 WriteMethod **write_method);
80
81 /* SNMP variable */
82 struct variable
83 {
84 /* Index of the MIB.*/
85 u_char magic;
86
87 /* Type of variable. */
88 char type;
89
90 /* Access control list. */
91 u_short acl;
92
93 /* Callback function. */
94 FindVarMethod *findVar;
95
96 /* Suffix of the MIB. */
97 u_char namelen;
98 oid name[MAX_OID_LEN];
99 };
100
101 /* SNMP tree. */
102 struct subtree
103 {
104 /* Tree's oid. */
105 oid name[MAX_OID_LEN];
106 u_char name_len;
107
108 /* List of the variables. */
109 struct variable *variables;
110
111 /* Length of the variables list. */
112 int variables_num;
113
114 /* Width of the variables list. */
115 int variables_width;
116
117 /* Registered flag. */
118 int registered;
119 };
120
121 struct trap_object
122 {
123 FindVarMethod *findVar;
124 u_char namelen;
125 oid name[MAX_OID_LEN];
126 };
127
128 /* Declare SMUX return value. */
129 #define SNMP_LOCAL_VARIABLES \
130 static int32_t snmp_int_val; \
131 static struct in_addr snmp_in_addr_val;
132
133 #define SNMP_INTEGER(V) \
134 ( \
135 *var_len = sizeof (int32_t), \
136 snmp_int_val = V, \
137 (u_char *) &snmp_int_val \
138 )
139
140 #define SNMP_IPADDRESS(V) \
141 ( \
142 *var_len = sizeof (struct in_addr), \
143 snmp_in_addr_val = V, \
144 (u_char *) &snmp_in_addr_val \
145 )
146
147 void smux_init (struct thread_master *tm, oid [], size_t);
148 void smux_start (void);
149 void smux_register_mib(const char *, struct variable *, size_t, int, oid [], size_t);
150 int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *,
151 WriteMethod **);
152 int smux_trap (oid *, size_t, oid *, size_t, struct trap_object *, size_t, unsigned int, u_char);
153
154 int oid_compare (oid *, int, oid *, int);
155 void oid2in_addr (oid [], int, struct in_addr *);
156 void *oid_copy (void *, void *, size_t);
157 void oid_copy_addr (oid [], struct in_addr *, int);
158
159 #endif /* _ZEBRA_SNMP_H */