1 |
27 |
unneback |
#
|
2 |
|
|
# Define types of data by mib type, and translate into needed C code.
|
3 |
|
|
#
|
4 |
|
|
|
5 |
|
|
############################################################################
|
6 |
|
|
# source variable typing information:
|
7 |
|
|
include: mib2c.vartypes.conf
|
8 |
|
|
|
9 |
|
|
# Begin code template section
|
10 |
|
|
############################################################################
|
11 |
|
|
# variable statemnts used in a couple of places below
|
12 |
|
|
############################################################################
|
13 |
|
|
type: code-varInits
|
14 |
|
|
code: /* variables we may use later */
|
15 |
|
|
code: static long long_ret;
|
16 |
|
|
code: static unsigned char string[SPRINT_MAX_LEN];
|
17 |
|
|
code: static oid objid[MAX_OID_LEN];
|
18 |
|
|
code: static struct counter64 c64;
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
############################################################################
|
22 |
|
|
# The .h file
|
23 |
|
|
############################################################################
|
24 |
|
|
type: code-dot-h
|
25 |
|
|
code: /* This file was generated by mib2c and is intended for use as a mib module
|
26 |
|
|
code: for the ucd-snmp snmpd agent. */
|
27 |
|
|
code:
|
28 |
|
|
code: #ifndef _MIBGROUP_${OUTPUTNAME}_H
|
29 |
|
|
code: #define _MIBGROUP_${OUTPUTNAME}_H
|
30 |
|
|
code:
|
31 |
|
|
code: /* we may use header_generic and header_simple_table from the util_funcs module */
|
32 |
|
|
code:
|
33 |
|
|
code: config_require(util_funcs)
|
34 |
|
|
code:
|
35 |
|
|
code: /* function prototypes */
|
36 |
|
|
code:
|
37 |
|
|
code: void init_$outputName(void);
|
38 |
|
|
code: FindVarMethod var_$outputName;
|
39 |
|
|
code: $variables{'code-var_table-decl'}{'processed'}
|
40 |
|
|
code: $variables{'code-write-func-decl'}{'processed'}
|
41 |
|
|
code:
|
42 |
|
|
code: #endif /* _MIBGROUP_${OUTPUTNAME}_H */
|
43 |
|
|
|
44 |
|
|
############################################################################
|
45 |
|
|
# The .c file, top
|
46 |
|
|
############################################################################
|
47 |
|
|
type: code-main-part
|
48 |
|
|
code: /* This file was generated by mib2c and is intended for use as a mib module
|
49 |
|
|
code: for the ucd-snmp snmpd agent. */
|
50 |
|
|
code:
|
51 |
|
|
code: #ifdef IN_UCD_SNMP_SOURCE
|
52 |
|
|
code: /* If we're compiling this file inside the ucd-snmp source tree */
|
53 |
|
|
code:
|
54 |
|
|
code: /* This should always be included first before anything else */
|
55 |
|
|
code: #include
|
56 |
|
|
code:
|
57 |
|
|
code: /* minimal include directives */
|
58 |
|
|
code: #include \"mibincl.h\"
|
59 |
|
|
code: #include \"util_funcs.h\"
|
60 |
|
|
code:
|
61 |
|
|
code: #else /* !IN_UCD_SNMP_SOURCE */
|
62 |
|
|
code:
|
63 |
|
|
code: #include
|
64 |
|
|
code: #include
|
65 |
|
|
code: #include
|
66 |
|
|
code:
|
67 |
|
|
code: #endif /* !IN_UCD_SNMP_SOURCE */
|
68 |
|
|
code:
|
69 |
|
|
code: #include \"$outputName.h\"
|
70 |
|
|
code:
|
71 |
|
|
code: /*
|
72 |
|
|
code: * ${outputName}_variables_oid:
|
73 |
|
|
code: * this is the top level oid that we want to register under. This
|
74 |
|
|
code: * is essentially a prefix, with the suffix appearing in the
|
75 |
|
|
code: * variable below.
|
76 |
|
|
code: */
|
77 |
|
|
code:
|
78 |
|
|
code: oid ${outputName}_variables_oid[] = { $commaoid };
|
79 |
|
|
code:
|
80 |
|
|
code: /*
|
81 |
|
|
code: * variable$varlen ${outputName}_variables:
|
82 |
|
|
code: * this variable defines function callbacks and type return information
|
83 |
|
|
code: * for the $outputName mib section
|
84 |
|
|
code: */
|
85 |
|
|
code:
|
86 |
|
|
code: struct variable$varlen ${outputName}_variables[] = {
|
87 |
|
|
code: /* magic number , variable type , ro/rw , callback fn , L, oidsuffix */
|
88 |
|
|
code: $variables{'variable-structure-info'}{'processed'}
|
89 |
|
|
code: };
|
90 |
|
|
code: /* (L = length of the oidsuffix) */
|
91 |
|
|
code:
|
92 |
|
|
code: /*
|
93 |
|
|
code: * init_$outputName():
|
94 |
|
|
code: * Initialization routine. This is called when the agent starts up.
|
95 |
|
|
code: * At a minimum, registration of your variables should take place here.
|
96 |
|
|
code: */
|
97 |
|
|
code: void init_$outputName(void) {
|
98 |
|
|
code:
|
99 |
|
|
code: /* register ourselves with the agent to handle our mib tree */
|
100 |
|
|
code: REGISTER_MIB(\"$outputName\", ${outputName}_variables, variable$varlen,\
|
101 |
|
|
code: ${outputName}_variables_oid);
|
102 |
|
|
code:
|
103 |
|
|
code: /* place any other initialization junk you need here */
|
104 |
|
|
code: }
|
105 |
|
|
code:
|
106 |
|
|
code: /*
|
107 |
|
|
code: * var_$outputName():
|
108 |
|
|
code: * This function is called every time the agent gets a request for
|
109 |
|
|
code: * a scalar variable that might be found within your mib section
|
110 |
|
|
code: * registered above. It is up to you to do the right thing and
|
111 |
|
|
code: * return the correct value.
|
112 |
|
|
code: * You should also correct the value of \"var_len\" if necessary.
|
113 |
|
|
code: *
|
114 |
|
|
code: * Please see the documentation for more information about writing
|
115 |
|
|
code: * module extensions, and check out the examples in the examples
|
116 |
|
|
code: * and mibII directories.
|
117 |
|
|
code: */
|
118 |
|
|
code: unsigned char *
|
119 |
|
|
code: var_$outputName(struct variable *vp,
|
120 |
|
|
code: oid *name,
|
121 |
|
|
code: size_t *length,
|
122 |
|
|
code: int exact,
|
123 |
|
|
code: size_t *var_len,
|
124 |
|
|
code: WriteMethod **write_method)
|
125 |
|
|
code: {
|
126 |
|
|
code:
|
127 |
|
|
code: $variables{'code-varInits'}{'code'}
|
128 |
|
|
code:
|
129 |
|
|
code: if (header_generic(vp,name,length,exact,var_len,write_method)
|
130 |
|
|
code: == MATCH_FAILED )
|
131 |
|
|
code: return NULL;
|
132 |
|
|
code:
|
133 |
|
|
code: /*
|
134 |
|
|
code: * this is where we do the value assignments for the mib results.
|
135 |
|
|
code: */
|
136 |
|
|
code: switch(vp->magic) {\n\n
|
137 |
|
|
code: $variables{$outputName}{'code-case-statements'}{'processed'}
|
138 |
|
|
code: default:
|
139 |
|
|
code: ERROR_MSG(\"\");
|
140 |
|
|
code: }
|
141 |
|
|
code: return NULL;
|
142 |
|
|
code: }
|
143 |
|
|
code:
|
144 |
|
|
code: $variables{'code-var_table'}{'processed'}
|
145 |
|
|
code:
|
146 |
|
|
code: $variables{'code-write-func'}{'processed'}
|
147 |
|
|
|
148 |
|
|
############################################################################
|
149 |
|
|
# var_ function for tables, which is handled specially and used above
|
150 |
|
|
#
|
151 |
|
|
# Note: $vtable is set to the table name in the processtable loop.
|
152 |
|
|
############################################################################
|
153 |
|
|
|
154 |
|
|
#
|
155 |
|
|
# header file defs first
|
156 |
|
|
#
|
157 |
|
|
type: code-var_table-decl
|
158 |
|
|
processtable: code-var_table-decl
|
159 |
|
|
|
160 |
|
|
code: FindVarMethod var_$vtable;
|
161 |
|
|
|
162 |
|
|
#
|
163 |
|
|
# Code code per table
|
164 |
|
|
#
|
165 |
|
|
type: code-var_table
|
166 |
|
|
processtable: code-var_table
|
167 |
|
|
|
168 |
|
|
code: /*
|
169 |
|
|
code: * var_$vtable():
|
170 |
|
|
code: * Handle this table separately from the scalar value case.
|
171 |
|
|
code: * The workings of this are basically the same as for var_$outputName above.
|
172 |
|
|
code: */
|
173 |
|
|
code: unsigned char *
|
174 |
|
|
code: var_$vtable(struct variable *vp,
|
175 |
|
|
code: oid *name,
|
176 |
|
|
code: size_t *length,
|
177 |
|
|
code: int exact,
|
178 |
|
|
code: size_t *var_len,
|
179 |
|
|
code: WriteMethod **write_method)
|
180 |
|
|
code: {
|
181 |
|
|
code:
|
182 |
|
|
code: $variables{'code-varInits'}{'code'}
|
183 |
|
|
code:
|
184 |
|
|
code: /*
|
185 |
|
|
code: * This assumes that the table is a \'simple\' table.
|
186 |
|
|
code: * See the implementation documentation for the meaning of this.
|
187 |
|
|
code: * You will need to provide the correct value for the TABLE_SIZE parameter
|
188 |
|
|
code: *
|
189 |
|
|
code: * If this table does not meet the requirements for a simple table,
|
190 |
|
|
code: * you will need to provide the replacement code yourself.
|
191 |
|
|
code: * Mib2c is not smart enough to write this for you.
|
192 |
|
|
code: * Again, see the implementation documentation for what is required.
|
193 |
|
|
code: */
|
194 |
|
|
code: if (header_simple_table(vp,name,length,exact,var_len,write_method, TABLE_SIZE)
|
195 |
|
|
code: == MATCH_FAILED )
|
196 |
|
|
code: return NULL;
|
197 |
|
|
code:
|
198 |
|
|
code: /*
|
199 |
|
|
code: * this is where we do the value assignments for the mib results.
|
200 |
|
|
code: */
|
201 |
|
|
code: switch(vp->magic) {\n\n
|
202 |
|
|
code: $variables{$vtable}{'code-case-statements'}{'processed'}
|
203 |
|
|
code: default:
|
204 |
|
|
code: ERROR_MSG(\"\");
|
205 |
|
|
code: }
|
206 |
|
|
code: return NULL;
|
207 |
|
|
code: }
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
############################################################################
|
211 |
|
|
# case statement sections
|
212 |
|
|
############################################################################
|
213 |
|
|
type: code-case-statements
|
214 |
|
|
process: code-case-statements
|
215 |
|
|
skipif: $mib->{'access'} =~ /NoAccess/
|
216 |
|
|
|
217 |
|
|
code: case $NAME:
|
218 |
|
|
code: " . (($mib->{'access'} =~ /ReadWrite|WriteOnly|Create/) ? "*write_method = write_$mib->{label};" : "") . "
|
219 |
|
|
code: $variables{$mib->{'type'}}{'case'}
|
220 |
|
|
code:
|
221 |
|
|
|
222 |
|
|
############################################################################
|
223 |
|
|
# storage structure information
|
224 |
|
|
############################################################################
|
225 |
|
|
type: variable-structure-info
|
226 |
|
|
process: variable-structure-info
|
227 |
|
|
skipif: $mib->{'access'} =~ /NoAccess/
|
228 |
|
|
code: " . sprintf("#define %-20s $count", $NAME) . "
|
229 |
|
|
code: " . sprintf(" { %-20s, %-14s, %-6.6s, %s, %d, { %s } },", $NAME, $variables{$mib->{'type'}}{'asnType'}, $accessToUCD{$mib->{'access'}}, "var_$vroutine", $depth-1, $subid) . "
|
230 |
|
|
|
231 |
|
|
############################################################################
|
232 |
|
|
# write function defitition, also appended to the end of the .c file.
|
233 |
|
|
############################################################################
|
234 |
|
|
#
|
235 |
|
|
# Header info: declair write functions for set processing
|
236 |
|
|
#
|
237 |
|
|
process: code-write-func-decl
|
238 |
|
|
type: code-write-func-decl
|
239 |
|
|
skipif: $mib->{'access'} !~ /Write|Create/
|
240 |
|
|
code: WriteMethod write_$name;
|
241 |
|
|
#
|
242 |
|
|
# C code
|
243 |
|
|
#
|
244 |
|
|
type: code-write-func
|
245 |
|
|
process: code-write-func
|
246 |
|
|
skipif: $mib->{'access'} !~ /Write|Create/
|
247 |
|
|
code: int
|
248 |
|
|
code: write_$name(int action,
|
249 |
|
|
code: u_char *var_val,
|
250 |
|
|
code: u_char var_val_type,
|
251 |
|
|
code: size_t var_val_len,
|
252 |
|
|
code: u_char *statP,
|
253 |
|
|
code: oid *name,
|
254 |
|
|
code: size_t name_len)
|
255 |
|
|
code: {
|
256 |
|
|
code: $variables{$mib->{'type'}}{writeInit}
|
257 |
|
|
code: int size;
|
258 |
|
|
code:
|
259 |
|
|
code: switch ( action ) {
|
260 |
|
|
code: case RESERVE1:
|
261 |
|
|
code: if (var_val_type != $variables{$mib->{'type'}}{asnType}){
|
262 |
|
|
code: fprintf(stderr, \"write to $name not $variables{$mib->{'type'}}{asnType}\\n\");
|
263 |
|
|
code: return SNMP_ERR_WRONGTYPE;
|
264 |
|
|
code: }
|
265 |
|
|
code: if (var_val_len > sizeof($variables{$mib->{'type'}}{variable})){
|
266 |
|
|
code: fprintf(stderr,\"write to $name: bad length\\n\");
|
267 |
|
|
code: return SNMP_ERR_WRONGLENGTH;
|
268 |
|
|
code: }
|
269 |
|
|
code: break;
|
270 |
|
|
code:
|
271 |
|
|
code: case RESERVE2:
|
272 |
|
|
code: size = var_val_len;
|
273 |
|
|
code: $variables{$mib->{'type'}}{variable} = ($variables{$mib->{'type'}}{cast}) var_val;
|
274 |
|
|
code:
|
275 |
|
|
code: break;
|
276 |
|
|
code:
|
277 |
|
|
code: case FREE:
|
278 |
|
|
code: /* Release any resources that have been allocated */
|
279 |
|
|
code: break;
|
280 |
|
|
code:
|
281 |
|
|
code: case ACTION:
|
282 |
|
|
code: /* The variable has been stored in $variables{$mib->{'type'}}{variable} for
|
283 |
|
|
code: you to use, and you have just been asked to do something with
|
284 |
|
|
code: it. Note that anything done here must be reversable in the UNDO case */
|
285 |
|
|
code: break;
|
286 |
|
|
code:
|
287 |
|
|
code: case UNDO:
|
288 |
|
|
code: /* Back out any changes made in the ACTION case */
|
289 |
|
|
code: break;
|
290 |
|
|
code:
|
291 |
|
|
code: case COMMIT:
|
292 |
|
|
code: /* Things are working well, so it's now safe to make the change
|
293 |
|
|
code: permanently. Make sure that anything done here can't fail! */
|
294 |
|
|
code: break;
|
295 |
|
|
code: }
|
296 |
|
|
code: return SNMP_ERR_NOERROR;
|
297 |
|
|
code: }
|
298 |
|
|
code:
|
299 |
|
|
code:
|