2 * Copyright (c) 2006 The FreeBSD Project
5 * Author: Shteryana Shopova <syrinx@FreeBSD.org>
7 * Redistribution of this software and documentation and use in source and
8 * binary forms, with or without modification, are permitted provided that
9 * the following conditions are met:
11 * 1. Redistributions of source code or documentation must retain the above
12 * copyright notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/param.h>
33 #include <sys/queue.h>
45 #include <bsnmp/asn1.h>
46 #include <bsnmp/snmp.h>
48 #include "bsnmptools.h"
50 extern int _bsnmptools_debug;
51 #define DEBUG if (_bsnmptools_debug) fprintf
53 /* Allocate memory and initialize list. */
54 struct snmp_mappings *
55 snmp_mapping_init(void)
57 struct snmp_mappings *m;
59 if ((m = calloc(1, sizeof(struct snmp_mappings))) == NULL) {
60 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
67 #define snmp_nodelist mappings->nodelist
68 #define snmp_intlist mappings->intlist
69 #define snmp_octlist mappings->octlist
70 #define snmp_oidlist mappings->oidlist
71 #define snmp_iplist mappings->iplist
72 #define snmp_ticklist mappings->ticklist
73 #define snmp_cntlist mappings->cntlist
74 #define snmp_gaugelist mappings->gaugelist
75 #define snmp_cnt64list mappings->cnt64list
76 #define snmp_enumlist mappings->enumlist
77 #define snmp_tablelist mappings->tablelist
78 #define snmp_tclist mappings->tclist
81 enum_pairs_free(struct enum_pairs *headp)
88 while ((e = STAILQ_FIRST(headp)) != NULL) {
89 STAILQ_REMOVE_HEAD(headp, link);
100 snmp_mapping_entryfree(struct snmp_oid2str *entry)
105 if (entry->tc == SNMP_TC_OWN)
106 enum_pairs_free(entry->snmp_enum);
112 snmp_mapping_listfree(struct snmp_mapping *headp)
114 struct snmp_oid2str *p;
116 while ((p = SLIST_FIRST(headp)) != NULL) {
117 SLIST_REMOVE_HEAD(headp, link);
122 if (p->tc == SNMP_TC_OWN)
123 enum_pairs_free(p->snmp_enum);
131 snmp_index_listfree(struct snmp_idxlist *headp)
135 while ((i = STAILQ_FIRST(headp)) != NULL) {
136 STAILQ_REMOVE_HEAD(headp, link);
137 if (i->tc == SNMP_TC_OWN)
138 enum_pairs_free(i->snmp_enum);
146 snmp_mapping_table_listfree(struct snmp_table_index *headp)
148 struct snmp_index_entry *t;
150 while ((t = SLIST_FIRST(headp)) != NULL) {
151 SLIST_REMOVE_HEAD(headp, link);
156 snmp_index_listfree(&(t->index_list));
162 snmp_enumtc_listfree(struct snmp_enum_tc *headp)
166 while ((t = SLIST_FIRST(headp)) != NULL) {
167 SLIST_REMOVE_HEAD(headp, link);
171 enum_pairs_free(t->snmp_enum);
177 snmp_mapping_free(struct snmp_toolinfo *snmptoolctx)
179 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL)
182 snmp_mapping_listfree(&snmptoolctx->snmp_nodelist);
183 snmp_mapping_listfree(&snmptoolctx->snmp_intlist);
184 snmp_mapping_listfree(&snmptoolctx->snmp_octlist);
185 snmp_mapping_listfree(&snmptoolctx->snmp_oidlist);
186 snmp_mapping_listfree(&snmptoolctx->snmp_iplist);
187 snmp_mapping_listfree(&snmptoolctx->snmp_ticklist);
188 snmp_mapping_listfree(&snmptoolctx->snmp_cntlist);
189 snmp_mapping_listfree(&snmptoolctx->snmp_gaugelist);
190 snmp_mapping_listfree(&snmptoolctx->snmp_cnt64list);
191 snmp_mapping_listfree(&snmptoolctx->snmp_enumlist);
192 snmp_mapping_table_listfree(&snmptoolctx->snmp_tablelist);
193 snmp_enumtc_listfree(&snmptoolctx->snmp_tclist);
194 free(snmptoolctx->mappings);
200 snmp_dump_enumpairs(struct enum_pairs *headp)
202 struct enum_pair *entry;
207 fprintf(stderr,"enums: ");
208 STAILQ_FOREACH(entry, headp, link)
209 fprintf(stderr,"%d - %s, ", entry->enum_val,
210 (entry->enum_str == NULL)?"NULL":entry->enum_str);
212 fprintf(stderr,"; ");
216 snmp_dump_oid2str(struct snmp_oid2str *entry)
218 char buf[ASN_OIDSTRLEN];
221 memset(buf, 0, sizeof(buf));
222 asn_oid2str_r(&(entry->var), buf);
223 DEBUG(stderr, "%s - %s - %d - %d - %d", buf, entry->string,
224 entry->syntax, entry->access, entry->strlen);
225 snmp_dump_enumpairs(entry->snmp_enum);
226 DEBUG(stderr,"%s \n", (entry->table_idx == NULL)?"No table":
227 entry->table_idx->string);
232 snmp_dump_indexlist(struct snmp_idxlist *headp)
239 STAILQ_FOREACH(entry, headp, link) {
240 fprintf(stderr,"%d, ", entry->syntax);
241 snmp_dump_enumpairs(entry->snmp_enum);
244 fprintf(stderr,"\n");
247 /* Initialize the enum pairs list of a oid2str entry. */
249 enum_pairs_init(void)
251 struct enum_pairs *snmp_enum;
253 if ((snmp_enum = malloc(sizeof(struct enum_pairs))) == NULL) {
254 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
258 STAILQ_INIT(snmp_enum);
263 * Given a number and string, allocate memory for a (int, string) pair and add
264 * it to the given oid2str mapping entry's enum pairs list.
267 enum_pair_insert(struct enum_pairs *headp, int32_t enum_val, char *enum_str)
269 struct enum_pair *e_new;
271 if ((e_new = calloc(1, sizeof(struct enum_pair))) == NULL) {
272 syslog(LOG_ERR, "calloc() failed: %s", strerror(errno));
276 if ((e_new->enum_str = strdup(enum_str)) == NULL) {
277 syslog(LOG_ERR, "strdup() failed: %s", strerror(errno));
282 e_new->enum_val = enum_val;
283 STAILQ_INSERT_TAIL(headp, e_new, link);
290 * Insert an entry in a list - entries are lexicographicaly order by asn_oid.
291 * Returns 1 on success, -1 if list is not initialized, 0 if a matching oid already
292 * exists. Error cheking is left to calling function.
295 snmp_mapping_insert(struct snmp_mapping *headp, struct snmp_oid2str *entry)
298 struct snmp_oid2str *temp, *prev;
303 if ((prev = SLIST_FIRST(headp)) == NULL ||
304 asn_compare_oid(&(entry->var), &(prev->var)) < 0) {
305 SLIST_INSERT_HEAD(headp, entry, link);
308 rc = -1; /* Make the compiler happy. */
310 SLIST_FOREACH(temp, headp, link) {
311 if ((rc = asn_compare_oid(&(entry->var), &(temp->var))) <= 0)
319 /* Ops, matching OIDs - hope the rest info also matches. */
320 if (strncmp(temp->string, entry->string, entry->strlen)) {
321 syslog(LOG_INFO, "Matching OIDs with different string "
322 "mappings: old - %s, new - %s", temp->string,
327 * Ok, we have that already.
328 * As long as the strings match - don't complain.
333 SLIST_INSERT_AFTER(temp, entry, link);
337 SLIST_INSERT_AFTER(prev, entry, link);
349 snmp_node_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
351 if (snmptoolctx != NULL && snmptoolctx->mappings)
352 return (snmp_mapping_insert(&snmptoolctx->snmp_nodelist,entry));
358 snmp_int_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
360 if (snmptoolctx != NULL && snmptoolctx->mappings)
361 return (snmp_mapping_insert(&snmptoolctx->snmp_intlist,entry));
367 snmp_oct_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
369 if (snmptoolctx != NULL && snmptoolctx->mappings)
370 return (snmp_mapping_insert(&snmptoolctx->snmp_octlist,entry));
376 snmp_oid_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
378 if (snmptoolctx != NULL && snmptoolctx->mappings)
379 return (snmp_mapping_insert(&snmptoolctx->snmp_oidlist,entry));
385 snmp_ip_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
387 if (snmptoolctx != NULL && snmptoolctx->mappings)
388 return (snmp_mapping_insert(&snmptoolctx->snmp_iplist,entry));
394 snmp_tick_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
396 if (snmptoolctx != NULL && snmptoolctx->mappings)
397 return (snmp_mapping_insert(&snmptoolctx->snmp_ticklist,entry));
403 snmp_cnt_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
405 if (snmptoolctx != NULL && snmptoolctx->mappings)
406 return (snmp_mapping_insert(&snmptoolctx->snmp_cntlist,entry));
412 snmp_gauge_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
414 if (snmptoolctx != NULL && snmptoolctx->mappings)
415 return (snmp_mapping_insert(&snmptoolctx->snmp_gaugelist,entry));
421 snmp_cnt64_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
423 if (snmptoolctx != NULL && snmptoolctx->mappings)
424 return (snmp_mapping_insert(&snmptoolctx->snmp_cnt64list,entry));
430 snmp_enum_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
432 if (snmptoolctx != NULL && snmptoolctx->mappings)
433 return (snmp_mapping_insert(&snmptoolctx->snmp_enumlist,entry));
439 snmp_leaf_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
441 switch (entry->syntax) {
442 case SNMP_SYNTAX_INTEGER:
443 return (snmp_int_insert(snmptoolctx, entry));
444 case SNMP_SYNTAX_OCTETSTRING:
445 return (snmp_oct_insert(snmptoolctx, entry));
446 case SNMP_SYNTAX_OID:
447 return (snmp_oid_insert(snmptoolctx, entry));
448 case SNMP_SYNTAX_IPADDRESS:
449 return (snmp_ip_insert(snmptoolctx, entry));
450 case SNMP_SYNTAX_COUNTER:
451 return (snmp_cnt_insert(snmptoolctx, entry));
452 case SNMP_SYNTAX_GAUGE:
453 return (snmp_gauge_insert(snmptoolctx, entry));
454 case SNMP_SYNTAX_TIMETICKS:
455 return (snmp_tick_insert(snmptoolctx, entry));
456 case SNMP_SYNTAX_COUNTER64:
457 return (snmp_cnt64_insert(snmptoolctx, entry));
466 snmp_index_insert(struct snmp_idxlist *headp, struct index *idx)
468 if (headp == NULL || idx == NULL)
471 STAILQ_INSERT_TAIL(headp, idx, link);
476 snmp_syntax_insert(struct snmp_idxlist *headp, struct enum_pairs *enums,
477 enum snmp_syntax syntax, enum snmp_tc tc)
481 if ((idx = calloc(1, sizeof(struct index))) == NULL) {
482 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
486 if (snmp_index_insert(headp, idx) < 0) {
491 idx->syntax = syntax;
492 idx->snmp_enum = enums;
499 snmp_table_insert(struct snmp_toolinfo *snmptoolctx,
500 struct snmp_index_entry *entry)
503 struct snmp_index_entry *temp, *prev;
505 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL ||
509 if ((prev = SLIST_FIRST(&snmptoolctx->snmp_tablelist)) == NULL ||
510 asn_compare_oid(&(entry->var), &(prev->var)) < 0) {
511 SLIST_INSERT_HEAD(&snmptoolctx->snmp_tablelist, entry, link);
514 rc = -1; /* Make the compiler happy. */
516 SLIST_FOREACH(temp, &snmptoolctx->snmp_tablelist, link) {
517 if ((rc = asn_compare_oid(&(entry->var), &(temp->var))) <= 0)
525 /* Ops, matching OIDs - hope the rest info also matches. */
526 if (strncmp(temp->string, entry->string, entry->strlen)) {
527 syslog(LOG_INFO, "Matching OIDs with different string "
528 "mapping - old - %s, new - %s", temp->string,
535 SLIST_INSERT_AFTER(temp, entry, link);
539 SLIST_INSERT_AFTER(prev, entry, link);
551 snmp_enumtc_init(char *name)
553 struct enum_type *enum_tc;
555 if ((enum_tc = calloc(1, sizeof(struct enum_type))) == NULL) {
556 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
560 if ((enum_tc->name = strdup(name)) == NULL) {
561 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
570 snmp_enumtc_free(struct enum_type *tc)
575 enum_pairs_free(tc->snmp_enum);
580 snmp_enumtc_insert(struct snmp_toolinfo *snmptoolctx, struct enum_type *entry)
582 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL)
583 return; /* XXX no error handling? */
585 SLIST_INSERT_HEAD(&snmptoolctx->snmp_tclist, entry, link);
589 snmp_enumtc_lookup(struct snmp_toolinfo *snmptoolctx, char *name)
591 struct enum_type *temp;
593 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL)
596 SLIST_FOREACH(temp, &snmptoolctx->snmp_tclist, link) {
597 if (strcmp(temp->name, name) == 0)
604 snmp_mapping_dumplist(struct snmp_mapping *headp)
606 char buf[ASN_OIDSTRLEN];
607 struct snmp_oid2str *entry;
612 SLIST_FOREACH(entry,headp,link) {
613 memset(buf, 0, sizeof(buf));
614 asn_oid2str_r(&(entry->var), buf);
615 fprintf(stderr, "%s - %s - %d - %d - %d", buf, entry->string,
616 entry->syntax, entry->access ,entry->strlen);
617 fprintf(stderr," - %s \n", (entry->table_idx == NULL)?
618 "No table":entry->table_idx->string);
623 snmp_mapping_dumptable(struct snmp_table_index *headp)
625 char buf[ASN_OIDSTRLEN];
626 struct snmp_index_entry *entry;
631 SLIST_FOREACH(entry, headp, link) {
632 memset(buf, 0, sizeof(buf));
633 asn_oid2str_r(&(entry->var), buf);
634 fprintf(stderr,"%s - %s - %d - ", buf, entry->string,
636 snmp_dump_indexlist(&(entry->index_list));
641 snmp_mapping_dump(struct snmp_toolinfo *snmptoolctx /* int bits */)
643 if (!_bsnmptools_debug)
646 if (snmptoolctx == NULL) {
647 fprintf(stderr,"No snmptool context!\n");
651 if (snmptoolctx->mappings == NULL) {
652 fprintf(stderr,"No mappings!\n");
656 fprintf(stderr,"snmp_nodelist:\n");
657 snmp_mapping_dumplist(&snmptoolctx->snmp_nodelist);
659 fprintf(stderr,"snmp_intlist:\n");
660 snmp_mapping_dumplist(&snmptoolctx->snmp_intlist);
662 fprintf(stderr,"snmp_octlist:\n");
663 snmp_mapping_dumplist(&snmptoolctx->snmp_octlist);
665 fprintf(stderr,"snmp_oidlist:\n");
666 snmp_mapping_dumplist(&snmptoolctx->snmp_oidlist);
668 fprintf(stderr,"snmp_iplist:\n");
669 snmp_mapping_dumplist(&snmptoolctx->snmp_iplist);
671 fprintf(stderr,"snmp_ticklist:\n");
672 snmp_mapping_dumplist(&snmptoolctx->snmp_ticklist);
674 fprintf(stderr,"snmp_cntlist:\n");
675 snmp_mapping_dumplist(&snmptoolctx->snmp_cntlist);
677 fprintf(stderr,"snmp_gaugelist:\n");
678 snmp_mapping_dumplist(&snmptoolctx->snmp_gaugelist);
680 fprintf(stderr,"snmp_cnt64list:\n");
681 snmp_mapping_dumplist(&snmptoolctx->snmp_cnt64list);
683 fprintf(stderr,"snmp_enumlist:\n");
684 snmp_mapping_dumplist(&snmptoolctx->snmp_enumlist);
686 fprintf(stderr,"snmp_tablelist:\n");
687 snmp_mapping_dumptable(&snmptoolctx->snmp_tablelist);
691 enum_string_lookup(struct enum_pairs *headp, int32_t enum_val)
693 struct enum_pair *temp;
698 STAILQ_FOREACH(temp, headp, link) {
699 if (temp->enum_val == enum_val)
700 return (temp->enum_str);
707 enum_number_lookup(struct enum_pairs *headp, char *e_str)
709 struct enum_pair *tmp;
714 STAILQ_FOREACH(tmp, headp, link)
715 if (strncmp(tmp->enum_str, e_str, strlen(tmp->enum_str)) == 0)
716 return (tmp->enum_val);
722 snmp_lookuplist_string(struct snmp_mapping *headp, struct snmp_object *s)
724 struct snmp_oid2str *temp;
729 SLIST_FOREACH(temp, headp, link)
730 if (asn_compare_oid(&(temp->var), &(s->val.var)) == 0)
733 if ((s->info = temp) == NULL)
739 /* provided an asn_oid find the corresponding string for it */
741 snmp_lookup_leaf(struct snmp_mapping *headp, struct snmp_object *s)
743 struct snmp_oid2str *temp;
748 SLIST_FOREACH(temp,headp,link) {
749 if ((asn_compare_oid(&(temp->var), &(s->val.var)) == 0) ||
750 (asn_is_suboid(&(temp->var), &(s->val.var)))) {
760 snmp_lookup_leafstring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
762 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL || s == NULL)
765 switch (s->val.syntax) {
766 case SNMP_SYNTAX_INTEGER:
767 return (snmp_lookup_leaf(&snmptoolctx->snmp_intlist, s));
768 case SNMP_SYNTAX_OCTETSTRING:
769 return (snmp_lookup_leaf(&snmptoolctx->snmp_octlist, s));
770 case SNMP_SYNTAX_OID:
771 return (snmp_lookup_leaf(&snmptoolctx->snmp_oidlist, s));
772 case SNMP_SYNTAX_IPADDRESS:
773 return (snmp_lookup_leaf(&snmptoolctx->snmp_iplist, s));
774 case SNMP_SYNTAX_COUNTER:
775 return (snmp_lookup_leaf(&snmptoolctx->snmp_cntlist, s));
776 case SNMP_SYNTAX_GAUGE:
777 return (snmp_lookup_leaf(
778 &snmptoolctx->snmp_gaugelist, s));
779 case SNMP_SYNTAX_TIMETICKS:
780 return (snmp_lookup_leaf(
781 &snmptoolctx->snmp_ticklist, s));
782 case SNMP_SYNTAX_COUNTER64:
783 return (snmp_lookup_leaf(
784 &snmptoolctx->snmp_cnt64list, s));
785 case SNMP_SYNTAX_NOSUCHOBJECT:
787 case SNMP_SYNTAX_NOSUCHINSTANCE:
789 case SNMP_SYNTAX_ENDOFMIBVIEW:
790 return (snmp_lookup_allstring(snmptoolctx, s));
792 warnx("Unknown syntax - %d", s->val.syntax);
800 snmp_lookup_enumstring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
802 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL || s == NULL)
805 return (snmp_lookuplist_string(&snmptoolctx->snmp_enumlist, s));
809 snmp_lookup_oidstring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
811 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL || s == NULL)
814 return (snmp_lookuplist_string(&snmptoolctx->snmp_oidlist, s));
818 snmp_lookup_nodestring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
820 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL || s == NULL)
823 return (snmp_lookuplist_string(&snmptoolctx->snmp_nodelist, s));
827 snmp_lookup_allstring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
829 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL)
832 if (snmp_lookup_leaf(&snmptoolctx->snmp_intlist, s) > 0)
834 if (snmp_lookup_leaf(&snmptoolctx->snmp_octlist, s) > 0)
836 if (snmp_lookup_leaf(&snmptoolctx->snmp_oidlist, s) > 0)
838 if (snmp_lookup_leaf(&snmptoolctx->snmp_iplist, s) > 0)
840 if (snmp_lookup_leaf(&snmptoolctx->snmp_cntlist, s) > 0)
842 if (snmp_lookup_leaf(&snmptoolctx->snmp_gaugelist, s) > 0)
844 if (snmp_lookup_leaf(&snmptoolctx->snmp_ticklist, s) > 0)
846 if (snmp_lookup_leaf(&snmptoolctx->snmp_cnt64list, s) > 0)
848 if (snmp_lookuplist_string(&snmptoolctx->snmp_enumlist, s) > 0)
850 if (snmp_lookuplist_string(&snmptoolctx->snmp_nodelist, s) > 0)
857 snmp_lookup_nonleaf_string(struct snmp_toolinfo *snmptoolctx,
858 struct snmp_object *s)
860 if (snmptoolctx == NULL)
863 if (snmp_lookuplist_string(&snmptoolctx->snmp_nodelist, s) > 0)
865 if (snmp_lookuplist_string(&snmptoolctx->snmp_enumlist, s) > 0)
872 snmp_lookup_oidlist(struct snmp_mapping *hp, struct snmp_object *s, char *oid)
874 struct snmp_oid2str *temp;
879 SLIST_FOREACH(temp, hp, link) {
880 if (temp->strlen != strlen(oid))
883 if (strncmp(temp->string, oid, temp->strlen))
886 s->val.syntax = temp->syntax;
888 asn_append_oid(&(s->val.var), &(temp->var));
896 snmp_lookup_tablelist(struct snmp_toolinfo *snmptoolctx,
897 struct snmp_table_index *headp, struct snmp_object *s, char *oid)
899 struct snmp_index_entry *temp;
901 if (snmptoolctx == NULL || headp == NULL)
904 SLIST_FOREACH(temp, headp, link) {
905 if (temp->strlen != strlen(oid))
908 if (strncmp(temp->string, oid, temp->strlen))
912 * Another hack here - if we were given a table name
913 * return the corresponding pointer to it's entry.
914 * That should not change the reponce we'll get.
916 s->val.syntax = SNMP_SYNTAX_NULL;
917 asn_append_oid(&(s->val.var), &(temp->var));
918 if (snmp_lookup_leaf(&snmptoolctx->snmp_nodelist, s) > 0)
928 snmp_lookup_oidall(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s,
931 if (snmptoolctx == NULL || s == NULL || oid == NULL)
934 if (snmp_lookup_oidlist(&snmptoolctx->snmp_intlist, s, oid) > 0)
936 if (snmp_lookup_oidlist(&snmptoolctx->snmp_octlist, s, oid) > 0)
938 if (snmp_lookup_oidlist(&snmptoolctx->snmp_oidlist, s, oid) > 0)
940 if (snmp_lookup_oidlist(&snmptoolctx->snmp_iplist, s, oid) > 0)
942 if (snmp_lookup_oidlist(&snmptoolctx->snmp_ticklist, s, oid) > 0)
944 if (snmp_lookup_oidlist(&snmptoolctx->snmp_cntlist, s, oid) > 0)
946 if (snmp_lookup_oidlist(&snmptoolctx->snmp_gaugelist, s, oid) > 0)
948 if (snmp_lookup_oidlist(&snmptoolctx->snmp_cnt64list, s, oid) > 0)
950 if (snmp_lookup_oidlist(&snmptoolctx->snmp_nodelist, s, oid) > 0)
952 if (snmp_lookup_tablelist(snmptoolctx, &snmptoolctx->snmp_tablelist,
960 snmp_lookup_enumoid(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s,
963 if (snmptoolctx == NULL || s == NULL)
966 return (snmp_lookup_oidlist(&snmptoolctx->snmp_enumlist, s, oid));
970 snmp_lookup_oid(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s,
973 if (snmptoolctx == NULL || s == NULL)
976 switch (s->val.syntax) {
977 case SNMP_SYNTAX_INTEGER:
978 return (snmp_lookup_oidlist(&snmptoolctx->snmp_intlist,
980 case SNMP_SYNTAX_OCTETSTRING:
981 return (snmp_lookup_oidlist(&snmptoolctx->snmp_octlist,
983 case SNMP_SYNTAX_OID:
984 return (snmp_lookup_oidlist(&snmptoolctx->snmp_oidlist,
986 case SNMP_SYNTAX_IPADDRESS:
987 return (snmp_lookup_oidlist(&snmptoolctx->snmp_iplist,
989 case SNMP_SYNTAX_COUNTER:
990 return (snmp_lookup_oidlist(&snmptoolctx->snmp_cntlist,
992 case SNMP_SYNTAX_GAUGE:
993 return (snmp_lookup_oidlist(&snmptoolctx->snmp_gaugelist,
995 case SNMP_SYNTAX_TIMETICKS:
996 return (snmp_lookup_oidlist(&snmptoolctx->snmp_ticklist,
998 case SNMP_SYNTAX_COUNTER64:
999 return (snmp_lookup_oidlist(&snmptoolctx->snmp_cnt64list,
1001 case SNMP_SYNTAX_NULL:
1002 return (snmp_lookup_oidlist(&snmptoolctx->snmp_nodelist,
1005 warnx("Unknown syntax - %d", s->val.syntax);