2 * This file was generated by mib2c and is intended for use as
3 * a mib module for the ucd-snmp snmpd agent.
8 * This should always be included first before anything else
10 #include <net-snmp/net-snmp-config.h>
22 * minimal include directives
24 #include <net-snmp/net-snmp-includes.h>
25 #include <net-snmp/agent/net-snmp-agent-includes.h>
27 #include "header_complex.h"
28 #include "mteTriggerTable.h"
29 #include "mteObjectsTable.h"
33 * mteObjectsTable_variables_oid:
34 * this is the top level oid that we want to register under. This
35 * is essentially a prefix, with the suffix appearing in the
40 oid mteObjectsTable_variables_oid[] =
41 { 1, 3, 6, 1, 2, 1, 88, 1, 3, 1 };
45 * variable2 mteObjectsTable_variables:
46 * this variable defines function callbacks and type return information
47 * for the mteObjectsTable mib section
51 struct variable2 mteObjectsTable_variables[] = {
53 * magic number , variable type , ro/rw , callback fn , L, oidsuffix
55 #define MTEOBJECTSID 5
56 {MTEOBJECTSID, ASN_OBJECT_ID, RWRITE, var_mteObjectsTable, 2, {1, 3}},
57 #define MTEOBJECTSIDWILDCARD 6
58 {MTEOBJECTSIDWILDCARD, ASN_INTEGER, RWRITE, var_mteObjectsTable, 2,
60 #define MTEOBJECTSENTRYSTATUS 7
61 {MTEOBJECTSENTRYSTATUS, ASN_INTEGER, RWRITE, var_mteObjectsTable, 2,
66 * (L = length of the oidsuffix)
71 * global storage of our data, saved in and configured by header_complex()
73 static struct header_complex_index *mteObjectsTableStorage = NULL;
79 * init_mteObjectsTable():
80 * Initialization routine. This is called when the agent starts up.
81 * At a minimum, registration of your variables should take place here.
84 init_mteObjectsTable(void)
86 DEBUGMSGTL(("mteObjectsTable", "initializing... "));
90 * register ourselves with the agent to handle our mib tree
92 REGISTER_MIB("mteObjectsTable", mteObjectsTable_variables, variable2,
93 mteObjectsTable_variables_oid);
97 * register our config handler(s) to deal with registrations
99 snmpd_register_config_handler("mteObjectsTable", parse_mteObjectsTable,
104 * we need to be called back later to store our data
106 snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
107 store_mteObjectsTable, NULL);
111 * place any other initialization junk you need here
115 DEBUGMSGTL(("mteObjectsTable", "done.\n"));
120 * mteObjectsTable_add(): adds a structure node to our data set
123 mteObjectsTable_add(struct mteObjectsTable_data *thedata)
125 netsnmp_variable_list *vars = NULL;
128 DEBUGMSGTL(("mteObjectsTable", "adding data... "));
130 * add the index variables to the varbind list, which is
131 * used by header_complex to index the data
135 snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->mteOwner, thedata->mteOwnerLen); /* mteOwner */
136 snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->mteObjectsName, thedata->mteObjectsNameLen); /* mteObjectsName */
137 snmp_varlist_add_variable(&vars, NULL, 0, ASN_UNSIGNED, (char *) &thedata->mteObjectsIndex, sizeof(thedata->mteObjectsIndex)); /* mteObjectsIndex */
141 header_complex_add_data(&mteObjectsTableStorage, vars, thedata);
142 DEBUGMSGTL(("mteObjectsTable", "registered an entry\n"));
145 DEBUGMSGTL(("mteObjectsTable", "done.\n"));
146 return SNMPERR_SUCCESS;
151 * parse_mteObjectsTable():
152 * parses .conf file entries needed to configure the mib.
155 parse_mteObjectsTable(const char *token, char *line)
158 struct mteObjectsTable_data *StorageTmp =
159 SNMP_MALLOC_STRUCT(mteObjectsTable_data);
161 DEBUGMSGTL(("mteObjectsTable", "parsing config... "));
164 if (StorageTmp == NULL) {
165 config_perror("malloc failure");
171 read_config_read_data(ASN_OCTET_STR, line, &StorageTmp->mteOwner,
172 &StorageTmp->mteOwnerLen);
173 if (StorageTmp->mteOwner == NULL) {
174 config_perror("invalid specification for mteOwner");
179 read_config_read_data(ASN_OCTET_STR, line,
180 &StorageTmp->mteObjectsName,
181 &StorageTmp->mteObjectsNameLen);
182 if (StorageTmp->mteObjectsName == NULL) {
183 config_perror("invalid specification for mteObjectsName");
188 read_config_read_data(ASN_UNSIGNED, line,
189 &StorageTmp->mteObjectsIndex, &tmpint);
192 read_config_read_data(ASN_OBJECT_ID, line,
193 &StorageTmp->mteObjectsID,
194 &StorageTmp->mteObjectsIDLen);
195 if (StorageTmp->mteObjectsID == NULL) {
196 config_perror("invalid specification for mteObjectsID");
201 read_config_read_data(ASN_INTEGER, line,
202 &StorageTmp->mteObjectsIDWildcard, &tmpint);
205 read_config_read_data(ASN_INTEGER, line,
206 &StorageTmp->mteObjectsEntryStatus, &tmpint);
211 mteObjectsTable_add(StorageTmp);
214 DEBUGMSGTL(("mteObjectsTable", "done.\n"));
221 * store_mteObjectsTable():
222 * stores .conf file entries needed to configure the mib.
225 store_mteObjectsTable(int majorID, int minorID, void *serverarg,
228 char line[SNMP_MAXBUF];
231 struct mteObjectsTable_data *StorageTmp;
232 struct header_complex_index *hcindex;
235 DEBUGMSGTL(("mteObjectsTable", "storing data... "));
238 for (hcindex = mteObjectsTableStorage; hcindex != NULL;
239 hcindex = hcindex->next) {
240 StorageTmp = (struct mteObjectsTable_data *) hcindex->data;
242 if (StorageTmp->storagetype != ST_READONLY) {
243 memset(line, 0, sizeof(line));
244 strcat(line, "mteObjectsTable ");
245 cptr = line + strlen(line);
249 read_config_store_data(ASN_OCTET_STR, cptr,
250 &StorageTmp->mteOwner,
251 &StorageTmp->mteOwnerLen);
253 read_config_store_data(ASN_OCTET_STR, cptr,
254 &StorageTmp->mteObjectsName,
255 &StorageTmp->mteObjectsNameLen);
257 read_config_store_data(ASN_UNSIGNED, cptr,
258 &StorageTmp->mteObjectsIndex,
261 read_config_store_data(ASN_OBJECT_ID, cptr,
262 &StorageTmp->mteObjectsID,
263 &StorageTmp->mteObjectsIDLen);
265 read_config_store_data(ASN_INTEGER, cptr,
266 &StorageTmp->mteObjectsIDWildcard,
269 read_config_store_data(ASN_INTEGER, cptr,
270 &StorageTmp->mteObjectsEntryStatus,
275 snmpd_store_config(line);
278 DEBUGMSGTL(("mteObjectsTable", "done.\n"));
279 return SNMPERR_SUCCESS;
286 * var_mteObjectsTable():
287 * Handle this table separately from the scalar value case.
288 * The workings of this are basically the same as for var_mteObjectsTable above.
291 var_mteObjectsTable(struct variable *vp,
295 size_t * var_len, WriteMethod ** write_method)
299 struct mteObjectsTable_data *StorageTmp = NULL;
302 DEBUGMSGTL(("mteObjectsTable",
303 "var_mteObjectsTable: Entering... \n"));
305 * this assumes you have registered all your data properly
308 header_complex(mteObjectsTableStorage, vp, name, length, exact,
309 var_len, write_method)) == NULL) {
310 if (vp->magic == MTEOBJECTSENTRYSTATUS)
311 *write_method = write_mteObjectsEntryStatus;
316 * this is where we do the value assignments for the mib results.
322 *write_method = write_mteObjectsID;
323 *var_len = (StorageTmp->mteObjectsIDLen) * sizeof(oid);
324 return (u_char *) StorageTmp->mteObjectsID;
326 case MTEOBJECTSIDWILDCARD:
327 *write_method = write_mteObjectsIDWildcard;
328 *var_len = sizeof(StorageTmp->mteObjectsIDWildcard);
329 return (u_char *) & StorageTmp->mteObjectsIDWildcard;
331 case MTEOBJECTSENTRYSTATUS:
332 *write_method = write_mteObjectsEntryStatus;
333 *var_len = sizeof(StorageTmp->mteObjectsEntryStatus);
334 return (u_char *) & StorageTmp->mteObjectsEntryStatus;
347 write_mteObjectsID(int action,
351 u_char * statP, oid * name, size_t name_len)
354 struct mteObjectsTable_data *StorageTmp = NULL;
355 static size_t tmplen;
357 name_len - (sizeof(mteObjectsTable_variables_oid) / sizeof(oid) +
361 DEBUGMSGTL(("mteObjectsTable",
362 "write_mteObjectsID entering action=%d... \n", action));
364 header_complex(mteObjectsTableStorage, NULL,
365 &name[sizeof(mteObjectsTable_variables_oid) /
366 sizeof(oid) + 3 - 1], &newlen, 1, NULL,
368 return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
370 if (StorageTmp && StorageTmp->storagetype == ST_READONLY) {
371 return SNMP_ERR_NOTWRITABLE;
376 if (var_val_type != ASN_OBJECT_ID) {
377 snmp_log(LOG_ERR, "write to mteObjectsID not ASN_OBJECT_ID\n");
378 return SNMP_ERR_WRONGTYPE;
385 * memory reseveration, final preparation...
392 * Release any resources that have been allocated
399 * The variable has been stored in objid for
400 * you to use, and you have just been asked to do something with
401 * it. Note that anything done here must be reversable in the UNDO case
403 tmpvar = StorageTmp->mteObjectsID;
404 tmplen = StorageTmp->mteObjectsIDLen;
405 memdup((u_char **) & StorageTmp->mteObjectsID, var_val,
407 StorageTmp->mteObjectsIDLen = var_val_len / sizeof(oid);
413 * Back out any changes made in the ACTION case
415 SNMP_FREE(StorageTmp->mteObjectsID);
416 StorageTmp->mteObjectsID = tmpvar;
417 StorageTmp->mteObjectsIDLen = tmplen;
423 * Things are working well, so it's now safe to make the change
424 * permanently. Make sure that anything done here can't fail!
429 return SNMP_ERR_NOERROR;
435 write_mteObjectsIDWildcard(int action,
439 u_char * statP, oid * name, size_t name_len)
442 struct mteObjectsTable_data *StorageTmp = NULL;
444 name_len - (sizeof(mteObjectsTable_variables_oid) / sizeof(oid) +
448 DEBUGMSGTL(("mteObjectsTable",
449 "write_mteObjectsIDWildcard entering action=%d... \n",
452 header_complex(mteObjectsTableStorage, NULL,
453 &name[sizeof(mteObjectsTable_variables_oid) /
454 sizeof(oid) + 3 - 1], &newlen, 1, NULL,
456 return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
458 if (StorageTmp && StorageTmp->storagetype == ST_READONLY) {
459 return SNMP_ERR_NOTWRITABLE;
464 if (var_val_type != ASN_INTEGER) {
466 "write to mteObjectsIDWildcard not ASN_INTEGER\n");
467 return SNMP_ERR_WRONGTYPE;
474 * memory reseveration, final preparation...
481 * Release any resources that have been allocated
488 * The variable has been stored in long_ret for
489 * you to use, and you have just been asked to do something with
490 * it. Note that anything done here must be reversable in the UNDO case
492 tmpvar = StorageTmp->mteObjectsIDWildcard;
493 StorageTmp->mteObjectsIDWildcard = *((long *) var_val);
499 * Back out any changes made in the ACTION case
501 StorageTmp->mteObjectsIDWildcard = tmpvar;
507 * Things are working well, so it's now safe to make the change
508 * permanently. Make sure that anything done here can't fail!
513 return SNMP_ERR_NOERROR;
522 write_mteObjectsEntryStatus(int action,
526 u_char * statP, oid * name, size_t name_len)
528 struct mteObjectsTable_data *StorageTmp = NULL;
529 static struct mteObjectsTable_data *StorageNew, *StorageDel;
531 name_len - (sizeof(mteObjectsTable_variables_oid) / sizeof(oid) +
533 static int old_value;
535 static netsnmp_variable_list *vars, *vp;
536 struct header_complex_index *hciptr;
540 header_complex(mteObjectsTableStorage, NULL,
541 &name[sizeof(mteObjectsTable_variables_oid) /
542 sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL);
544 if (var_val_type != ASN_INTEGER || var_val == NULL) {
546 "write to mteObjectsEntryStatus not ASN_INTEGER\n");
547 return SNMP_ERR_WRONGTYPE;
550 if (StorageTmp && StorageTmp->storagetype == ST_READONLY) {
551 return SNMP_ERR_NOTWRITABLE;
554 set_value = *((long *) var_val);
558 * check legal range, and notReady is reserved for us, not a user
560 if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY)
561 return SNMP_ERR_INCONSISTENTVALUE;
567 * stage one: test validity
569 if (StorageTmp == NULL) {
571 * create the row now?
576 * ditch illegal values now
578 if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE)
579 return SNMP_ERR_INCONSISTENTVALUE;
583 * destroying a non-existent row is actually legal
585 if (set_value == RS_DESTROY) {
586 return SNMP_ERR_NOERROR;
591 * illegal creation values
593 if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) {
594 return SNMP_ERR_INCONSISTENTVALUE;
598 * row exists. Check for a valid state change
600 if (set_value == RS_CREATEANDGO
601 || set_value == RS_CREATEANDWAIT) {
603 * can't create a row that exists
605 return SNMP_ERR_INCONSISTENTVALUE;
608 * XXX: interaction with row storage type needed
618 * memory reseveration, final preparation...
620 if (StorageTmp == NULL) {
627 snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0); /* mteOwner */
628 snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0); /* mteObjectsName */
629 snmp_varlist_add_variable(&vars, NULL, 0, ASN_UNSIGNED, NULL, 0); /* mteObjectsIndex */
631 if (header_complex_parse_oid
634 [sizeof(mteObjectsTable_variables_oid) / sizeof(oid) +
635 2]), newlen, vars) != SNMPERR_SUCCESS) {
637 * XXX: free, zero vars
639 return SNMP_ERR_INCONSISTENTNAME;
644 StorageNew = SNMP_MALLOC_STRUCT(mteObjectsTable_data);
645 StorageNew->mteOwner = netsnmp_strdup_and_null(vp->val.string,
647 StorageNew->mteOwnerLen = vp->val_len;
648 vp = vp->next_variable;
649 StorageNew->mteObjectsName =
650 netsnmp_strdup_and_null(vp->val.string,
652 StorageNew->mteObjectsNameLen = vp->val_len;
653 vp = vp->next_variable;
654 StorageNew->mteObjectsIndex = *(vp->val.integer);
657 * XXX: fill in default row values here into StorageNew
659 StorageNew->mteObjectsID = calloc(1, sizeof(oid) * sizeof(2)); /* 0.0 */
660 StorageNew->mteObjectsIDLen = 2;
661 StorageNew->mteObjectsIDWildcard = MTEOBJECTSIDWILDCARD_FALSE;
663 StorageNew->mteObjectsEntryStatus = set_value;
665 * XXX: free, zero vars, no longer needed?
677 * XXX: free, zero vars
680 * Release any resources that have been allocated
689 * The variable has been stored in set_value for you to
690 * use, and you have just been asked to do something with
691 * it. Note that anything done here must be reversable in
696 if (StorageTmp == NULL) {
698 * row creation, so add it
700 if (StorageNew != NULL)
701 mteObjectsTable_add(StorageNew);
703 * XXX: ack, and if it is NULL?
705 } else if (set_value != RS_DESTROY) {
709 old_value = StorageTmp->mteObjectsEntryStatus;
710 StorageTmp->mteObjectsEntryStatus = *((long *) var_val);
713 * destroy... extract it for now
716 header_complex_find_entry(mteObjectsTableStorage,
719 header_complex_extract_entry(&mteObjectsTableStorage,
729 * Back out any changes made in the ACTION case
731 if (StorageTmp == NULL) {
733 * row creation, so remove it again
736 header_complex_find_entry(mteObjectsTableStorage,
739 header_complex_extract_entry(&mteObjectsTableStorage,
744 } else if (StorageDel != NULL) {
746 * row deletion, so add it again
748 mteObjectsTable_add(StorageDel);
750 StorageTmp->mteObjectsEntryStatus = old_value;
759 * Things are working well, so it's now safe to make the change
760 * permanently. Make sure that anything done here can't fail!
762 if (StorageDel != NULL) {
765 * XXX: free it, its dead
769 && StorageTmp->mteObjectsEntryStatus == RS_CREATEANDGO) {
770 StorageTmp->mteObjectsEntryStatus = RS_ACTIVE;
771 } else if (StorageTmp &&
772 StorageTmp->mteObjectsEntryStatus ==
774 StorageTmp->mteObjectsEntryStatus = RS_NOTINSERVICE;
779 return SNMP_ERR_NOERROR;
783 mte_add_objects(netsnmp_variable_list * vars,
784 struct mteTriggerTable_data *item, const char *owner,
785 const char *name, oid * suffix, size_t suffix_len)
787 struct header_complex_index *hcptr = mteObjectsTableStorage;
789 DEBUGMSGTL(("mteObjectsTable",
790 "Searching for objects to add for owner=%s / name=%s\n",
793 if (vars == NULL || item == NULL || owner == NULL || name == NULL ||
798 * get to end of variable chain
800 while (vars->next_variable != NULL)
801 vars = vars->next_variable;
805 * get to start of objects list
808 (strcmp(((struct mteObjectsTable_data *) hcptr->data)->mteOwner,
810 strcmp(((struct mteObjectsTable_data *) hcptr->data)->
811 mteObjectsName, name) != 0))
818 strcmp(((struct mteObjectsTable_data *) hcptr->data)->mteOwner,
820 strcmp(((struct mteObjectsTable_data *) hcptr->data)->
821 mteObjectsName, name) == 0) {
823 * loop through objects
825 netsnmp_pdu *pdu = NULL, *response = NULL;
826 struct mteObjectsTable_data *node =
827 (struct mteObjectsTable_data *) hcptr->data;
828 oid theoid[MAX_OID_LEN];
834 memcpy(theoid, node->mteObjectsID,
835 node->mteObjectsIDLen * sizeof(oid));
836 theoid_len = node->mteObjectsIDLen;
837 if (node->mteObjectsIDWildcard == MTEOBJECTSIDWILDCARD_TRUE &&
838 suffix && suffix_len > 0) {
839 theoid_len += suffix_len;
840 if (theoid_len > MAX_OID_LEN) {
841 break; /* XXX: properly send trap or something? */
844 memcpy(&theoid[node->mteObjectsIDLen], suffix,
845 suffix_len * sizeof(oid));
851 pdu = snmp_pdu_create(SNMP_MSG_GET);
852 snmp_add_null_var(pdu, theoid, theoid_len);
853 response = mte_get_response(item, pdu);
857 vars->next_variable = response->variables;
858 vars = vars->next_variable;
859 DEBUGMSGTL(("mteObjectsTable", "Adding: "));
860 DEBUGMSGOID(("mteObjectsTable", response->variables->name,
861 response->variables->name_length));
862 DEBUGMSG(("mteObjectsTable", "\n"));
864 vars = response->variables;
867 * erase response notion of the values we stole from it
869 response->variables = NULL;
870 snmp_free_pdu(response);
878 DEBUGMSGTL(("mteObjectsTable", "Done adding objects\n"));
882 mte_add_object_to_table(const char *owner, const char *objname,
883 oid * oidname, size_t oidname_len, int iswild)
885 struct header_complex_index *hcptr = mteObjectsTableStorage, *lastnode;
886 static struct mteObjectsTable_data *StorageNew;
889 * malloc initial struct
891 StorageNew = SNMP_MALLOC_STRUCT(mteObjectsTable_data);
892 StorageNew->mteOwner = netsnmp_strdup_and_null(owner, strlen(owner));
893 StorageNew->mteOwnerLen = strlen(owner);
894 StorageNew->mteObjectsName = netsnmp_strdup_and_null(objname,
896 StorageNew->mteObjectsNameLen = strlen(objname);
899 * find the next number
902 * get to start of objects list
905 (strcmp(((struct mteObjectsTable_data *) hcptr->data)->mteOwner,
907 strcmp(((struct mteObjectsTable_data *) hcptr->data)->
908 mteObjectsName, objname) != 0))
913 * an object existed. Find the first one past and increment
914 * the previous number
918 strcmp(((struct mteObjectsTable_data *) hcptr->data)->
919 mteOwner, owner) == 0
920 && strcmp(((struct mteObjectsTable_data *) hcptr->data)->
921 mteObjectsName, objname) == 0) {
925 StorageNew->mteObjectsIndex =
926 ((struct mteObjectsTable_data *) lastnode->data)->
929 StorageNew->mteObjectsIndex = 1;
933 * XXX: fill in default row values here into StorageNew
935 StorageNew->mteObjectsID = snmp_duplicate_objid(oidname, oidname_len);
936 StorageNew->mteObjectsIDLen = oidname_len;
939 StorageNew->mteObjectsIDWildcard = MTEOBJECTSIDWILDCARD_TRUE;
941 StorageNew->mteObjectsIDWildcard = MTEOBJECTSIDWILDCARD_FALSE;
943 StorageNew->mteObjectsEntryStatus = RS_ACTIVE;
944 StorageNew->storagetype = ST_READONLY;
945 return mteObjectsTable_add(StorageNew);