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 = malloc(sizeof(struct snmp_mappings))) == NULL) {
60 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
64 memset(m, 0, sizeof(struct snmp_mappings));
68 #define snmp_nodelist mappings->nodelist
69 #define snmp_intlist mappings->intlist
70 #define snmp_octlist mappings->octlist
71 #define snmp_oidlist mappings->oidlist
72 #define snmp_iplist mappings->iplist
73 #define snmp_ticklist mappings->ticklist
74 #define snmp_cntlist mappings->cntlist
75 #define snmp_gaugelist mappings->gaugelist
76 #define snmp_cnt64list mappings->cnt64list
77 #define snmp_enumlist mappings->enumlist
78 #define snmp_tablelist mappings->tablelist
79 #define snmp_tclist mappings->tclist
82 enum_pairs_free(struct enum_pairs *headp)
89 while ((e = STAILQ_FIRST(headp)) != NULL) {
90 STAILQ_REMOVE_HEAD(headp, link);
101 snmp_mapping_entryfree(struct snmp_oid2str *entry)
106 if (entry->tc == SNMP_TC_OWN)
107 enum_pairs_free(entry->snmp_enum);
113 snmp_mapping_listfree(struct snmp_mapping *headp)
115 struct snmp_oid2str *p;
117 while ((p = SLIST_FIRST(headp)) != NULL) {
118 SLIST_REMOVE_HEAD(headp, link);
123 if (p->tc == SNMP_TC_OWN)
124 enum_pairs_free(p->snmp_enum);
132 snmp_index_listfree(struct snmp_idxlist *headp)
136 while ((i = STAILQ_FIRST(headp)) != NULL) {
137 STAILQ_REMOVE_HEAD(headp, link);
138 if (i->tc == SNMP_TC_OWN)
139 enum_pairs_free(i->snmp_enum);
147 snmp_mapping_table_listfree(struct snmp_table_index *headp)
149 struct snmp_index_entry *t;
151 while ((t = SLIST_FIRST(headp)) != NULL) {
152 SLIST_REMOVE_HEAD(headp, link);
157 snmp_index_listfree(&(t->index_list));
163 snmp_enumtc_listfree(struct snmp_enum_tc *headp)
167 while ((t = SLIST_FIRST(headp)) != NULL) {
168 SLIST_REMOVE_HEAD(headp, link);
172 enum_pairs_free(t->snmp_enum);
178 snmp_mapping_free(struct snmp_toolinfo *snmptoolctx)
180 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL)
183 snmp_mapping_listfree(&snmptoolctx->snmp_nodelist);
184 snmp_mapping_listfree(&snmptoolctx->snmp_intlist);
185 snmp_mapping_listfree(&snmptoolctx->snmp_octlist);
186 snmp_mapping_listfree(&snmptoolctx->snmp_oidlist);
187 snmp_mapping_listfree(&snmptoolctx->snmp_iplist);
188 snmp_mapping_listfree(&snmptoolctx->snmp_ticklist);
189 snmp_mapping_listfree(&snmptoolctx->snmp_cntlist);
190 snmp_mapping_listfree(&snmptoolctx->snmp_gaugelist);
191 snmp_mapping_listfree(&snmptoolctx->snmp_cnt64list);
192 snmp_mapping_listfree(&snmptoolctx->snmp_enumlist);
193 snmp_mapping_table_listfree(&snmptoolctx->snmp_tablelist);
194 snmp_enumtc_listfree(&snmptoolctx->snmp_tclist);
195 free(snmptoolctx->mappings);
201 snmp_dump_enumpairs(struct enum_pairs *headp)
203 struct enum_pair *entry;
208 fprintf(stderr,"enums: ");
209 STAILQ_FOREACH(entry, headp, link)
210 fprintf(stderr,"%d - %s, ", entry->enum_val,
211 (entry->enum_str == NULL)?"NULL":entry->enum_str);
213 fprintf(stderr,"; ");
217 snmp_dump_oid2str(struct snmp_oid2str *entry)
219 char buf[ASN_OIDSTRLEN];
222 memset(buf, 0, sizeof(buf));
223 asn_oid2str_r(&(entry->var), buf);
224 DEBUG(stderr, "%s - %s - %d - %d - %d", buf, entry->string,
225 entry->syntax, entry->access, entry->strlen);
226 snmp_dump_enumpairs(entry->snmp_enum);
227 DEBUG(stderr,"%s \n", (entry->table_idx == NULL)?"No table":
228 entry->table_idx->string);
233 snmp_dump_indexlist(struct snmp_idxlist *headp)
240 STAILQ_FOREACH(entry, headp, link) {
241 fprintf(stderr,"%d, ", entry->syntax);
242 snmp_dump_enumpairs(entry->snmp_enum);
245 fprintf(stderr,"\n");
248 /* Initialize the enum pairs list of a oid2str entry. */
250 enum_pairs_init(void)
252 struct enum_pairs *snmp_enum;
254 if ((snmp_enum = malloc(sizeof(struct enum_pairs))) == NULL) {
255 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
259 STAILQ_INIT(snmp_enum);
264 * Given a number and string, allocate memory for a (int, string) pair and add
265 * it to the given oid2str mapping entry's enum pairs list.
268 enum_pair_insert(struct enum_pairs *headp, int32_t enum_val, char *enum_str)
270 struct enum_pair *e_new;
272 if ((e_new = malloc(sizeof(struct enum_pair))) == NULL) {
273 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
277 memset(e_new, 0, sizeof(struct enum_pair));
279 if ((e_new->enum_str = malloc(strlen(enum_str) + 1)) == NULL) {
280 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
285 e_new->enum_val = enum_val;
286 strlcpy(e_new->enum_str, enum_str, strlen(enum_str) + 1);
287 STAILQ_INSERT_TAIL(headp, e_new, link);
294 * Insert an entry in a list - entries are lexicographicaly order by asn_oid.
295 * Returns 1 on success, -1 if list is not initialized, 0 if a matching oid already
296 * exists. Error cheking is left to calling function.
299 snmp_mapping_insert(struct snmp_mapping *headp, struct snmp_oid2str *entry)
302 struct snmp_oid2str *temp, *prev;
307 if ((prev = SLIST_FIRST(headp)) == NULL ||
308 asn_compare_oid(&(entry->var), &(prev->var)) < 0) {
309 SLIST_INSERT_HEAD(headp, entry, link);
312 rc = -1; /* Make the compiler happy. */
314 SLIST_FOREACH(temp, headp, link) {
315 if ((rc = asn_compare_oid(&(entry->var), &(temp->var))) <= 0)
323 /* Ops, matching OIDs - hope the rest info also matches. */
324 if (strncmp(temp->string, entry->string, entry->strlen)) {
325 syslog(LOG_INFO, "Matching OIDs with different string "
326 "mappings: old - %s, new - %s", temp->string,
331 * Ok, we have that already.
332 * As long as the strings match - don't complain.
337 SLIST_INSERT_AFTER(temp, entry, link);
341 SLIST_INSERT_AFTER(prev, entry, link);
353 snmp_node_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
355 if (snmptoolctx != NULL && snmptoolctx->mappings)
356 return (snmp_mapping_insert(&snmptoolctx->snmp_nodelist,entry));
362 snmp_int_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
364 if (snmptoolctx != NULL && snmptoolctx->mappings)
365 return (snmp_mapping_insert(&snmptoolctx->snmp_intlist,entry));
371 snmp_oct_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
373 if (snmptoolctx != NULL && snmptoolctx->mappings)
374 return (snmp_mapping_insert(&snmptoolctx->snmp_octlist,entry));
380 snmp_oid_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
382 if (snmptoolctx != NULL && snmptoolctx->mappings)
383 return (snmp_mapping_insert(&snmptoolctx->snmp_oidlist,entry));
389 snmp_ip_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
391 if (snmptoolctx != NULL && snmptoolctx->mappings)
392 return (snmp_mapping_insert(&snmptoolctx->snmp_iplist,entry));
398 snmp_tick_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
400 if (snmptoolctx != NULL && snmptoolctx->mappings)
401 return (snmp_mapping_insert(&snmptoolctx->snmp_ticklist,entry));
407 snmp_cnt_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
409 if (snmptoolctx != NULL && snmptoolctx->mappings)
410 return (snmp_mapping_insert(&snmptoolctx->snmp_cntlist,entry));
416 snmp_gauge_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
418 if (snmptoolctx != NULL && snmptoolctx->mappings)
419 return (snmp_mapping_insert(&snmptoolctx->snmp_gaugelist,entry));
425 snmp_cnt64_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
427 if (snmptoolctx != NULL && snmptoolctx->mappings)
428 return (snmp_mapping_insert(&snmptoolctx->snmp_cnt64list,entry));
434 snmp_enum_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
436 if (snmptoolctx != NULL && snmptoolctx->mappings)
437 return (snmp_mapping_insert(&snmptoolctx->snmp_enumlist,entry));
443 snmp_leaf_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
445 switch (entry->syntax) {
446 case SNMP_SYNTAX_INTEGER:
447 return (snmp_int_insert(snmptoolctx, entry));
448 case SNMP_SYNTAX_OCTETSTRING:
449 return (snmp_oct_insert(snmptoolctx, entry));
450 case SNMP_SYNTAX_OID:
451 return (snmp_oid_insert(snmptoolctx, entry));
452 case SNMP_SYNTAX_IPADDRESS:
453 return (snmp_ip_insert(snmptoolctx, entry));
454 case SNMP_SYNTAX_COUNTER:
455 return (snmp_cnt_insert(snmptoolctx, entry));
456 case SNMP_SYNTAX_GAUGE:
457 return (snmp_gauge_insert(snmptoolctx, entry));
458 case SNMP_SYNTAX_TIMETICKS:
459 return (snmp_tick_insert(snmptoolctx, entry));
460 case SNMP_SYNTAX_COUNTER64:
461 return (snmp_cnt64_insert(snmptoolctx, entry));
470 snmp_index_insert(struct snmp_idxlist *headp, struct index *idx)
472 if (headp == NULL || idx == NULL)
475 STAILQ_INSERT_TAIL(headp, idx, link);
480 snmp_syntax_insert(struct snmp_idxlist *headp, struct enum_pairs *enums,
481 enum snmp_syntax syntax, enum snmp_tc tc)
485 if ((idx = malloc(sizeof(struct index))) == NULL) {
486 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
490 memset(idx, 0, sizeof(struct index));
492 if (snmp_index_insert(headp, idx) < 0) {
497 idx->syntax = syntax;
498 idx->snmp_enum = enums;
505 snmp_table_insert(struct snmp_toolinfo *snmptoolctx,
506 struct snmp_index_entry *entry)
509 struct snmp_index_entry *temp, *prev;
511 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL ||
515 if ((prev = SLIST_FIRST(&snmptoolctx->snmp_tablelist)) == NULL ||
516 asn_compare_oid(&(entry->var), &(prev->var)) < 0) {
517 SLIST_INSERT_HEAD(&snmptoolctx->snmp_tablelist, entry, link);
520 rc = -1; /* Make the compiler happy. */
522 SLIST_FOREACH(temp, &snmptoolctx->snmp_tablelist, link) {
523 if ((rc = asn_compare_oid(&(entry->var), &(temp->var))) <= 0)
531 /* Ops, matching OIDs - hope the rest info also matches. */
532 if (strncmp(temp->string, entry->string, entry->strlen)) {
533 syslog(LOG_INFO, "Matching OIDs with different string "
534 "mapping - old - %s, new - %s", temp->string,
541 SLIST_INSERT_AFTER(temp, entry, link);
545 SLIST_INSERT_AFTER(prev, entry, link);
557 snmp_enumtc_init(char *name)
559 struct enum_type *enum_tc;
561 if ((enum_tc = malloc(sizeof(struct enum_type))) == NULL) {
562 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
566 memset(enum_tc, 0, sizeof(struct enum_type));
567 if ((enum_tc->name = malloc(strlen(name) + 1)) == NULL) {
568 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
572 strlcpy(enum_tc->name, name, strlen(name) + 1);
578 snmp_enumtc_free(struct enum_type *tc)
583 enum_pairs_free(tc->snmp_enum);
588 snmp_enumtc_insert(struct snmp_toolinfo *snmptoolctx, struct enum_type *entry)
590 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL)
591 return; /* XXX no error handling? */
593 SLIST_INSERT_HEAD(&snmptoolctx->snmp_tclist, entry, link);
597 snmp_enumtc_lookup(struct snmp_toolinfo *snmptoolctx, char *name)
599 struct enum_type *temp;
601 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL)
604 SLIST_FOREACH(temp, &snmptoolctx->snmp_tclist, link) {
605 if (strcmp(temp->name, name) == 0)
612 snmp_mapping_dumplist(struct snmp_mapping *headp)
614 char buf[ASN_OIDSTRLEN];
615 struct snmp_oid2str *entry;
620 SLIST_FOREACH(entry,headp,link) {
621 memset(buf, 0, sizeof(buf));
622 asn_oid2str_r(&(entry->var), buf);
623 fprintf(stderr, "%s - %s - %d - %d - %d", buf, entry->string,
624 entry->syntax, entry->access ,entry->strlen);
625 fprintf(stderr," - %s \n", (entry->table_idx == NULL)?
626 "No table":entry->table_idx->string);
631 snmp_mapping_dumptable(struct snmp_table_index *headp)
633 char buf[ASN_OIDSTRLEN];
634 struct snmp_index_entry *entry;
639 SLIST_FOREACH(entry, headp, link) {
640 memset(buf, 0, sizeof(buf));
641 asn_oid2str_r(&(entry->var), buf);
642 fprintf(stderr,"%s - %s - %d - ", buf, entry->string,
644 snmp_dump_indexlist(&(entry->index_list));
649 snmp_mapping_dump(struct snmp_toolinfo *snmptoolctx /* int bits */)
651 if (!_bsnmptools_debug)
654 if (snmptoolctx == NULL) {
655 fprintf(stderr,"No snmptool context!\n");
659 if (snmptoolctx->mappings == NULL) {
660 fprintf(stderr,"No mappings!\n");
664 fprintf(stderr,"snmp_nodelist:\n");
665 snmp_mapping_dumplist(&snmptoolctx->snmp_nodelist);
667 fprintf(stderr,"snmp_intlist:\n");
668 snmp_mapping_dumplist(&snmptoolctx->snmp_intlist);
670 fprintf(stderr,"snmp_octlist:\n");
671 snmp_mapping_dumplist(&snmptoolctx->snmp_octlist);
673 fprintf(stderr,"snmp_oidlist:\n");
674 snmp_mapping_dumplist(&snmptoolctx->snmp_oidlist);
676 fprintf(stderr,"snmp_iplist:\n");
677 snmp_mapping_dumplist(&snmptoolctx->snmp_iplist);
679 fprintf(stderr,"snmp_ticklist:\n");
680 snmp_mapping_dumplist(&snmptoolctx->snmp_ticklist);
682 fprintf(stderr,"snmp_cntlist:\n");
683 snmp_mapping_dumplist(&snmptoolctx->snmp_cntlist);
685 fprintf(stderr,"snmp_gaugelist:\n");
686 snmp_mapping_dumplist(&snmptoolctx->snmp_gaugelist);
688 fprintf(stderr,"snmp_cnt64list:\n");
689 snmp_mapping_dumplist(&snmptoolctx->snmp_cnt64list);
691 fprintf(stderr,"snmp_enumlist:\n");
692 snmp_mapping_dumplist(&snmptoolctx->snmp_enumlist);
694 fprintf(stderr,"snmp_tablelist:\n");
695 snmp_mapping_dumptable(&snmptoolctx->snmp_tablelist);
699 enum_string_lookup(struct enum_pairs *headp, int32_t enum_val)
701 struct enum_pair *temp;
706 STAILQ_FOREACH(temp, headp, link) {
707 if (temp->enum_val == enum_val)
708 return (temp->enum_str);
715 enum_number_lookup(struct enum_pairs *headp, char *e_str)
717 struct enum_pair *tmp;
722 STAILQ_FOREACH(tmp, headp, link)
723 if (strncmp(tmp->enum_str, e_str, strlen(tmp->enum_str)) == 0)
724 return (tmp->enum_val);
730 snmp_lookuplist_string(struct snmp_mapping *headp, struct snmp_object *s)
732 struct snmp_oid2str *temp;
737 SLIST_FOREACH(temp, headp, link)
738 if (asn_compare_oid(&(temp->var), &(s->val.var)) == 0)
741 if ((s->info = temp) == NULL)
747 /* provided an asn_oid find the corresponding string for it */
749 snmp_lookup_leaf(struct snmp_mapping *headp, struct snmp_object *s)
751 struct snmp_oid2str *temp;
756 SLIST_FOREACH(temp,headp,link) {
757 if ((asn_compare_oid(&(temp->var), &(s->val.var)) == 0) ||
758 (asn_is_suboid(&(temp->var), &(s->val.var)))) {
768 snmp_lookup_leafstring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
770 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL || s == NULL)
773 switch (s->val.syntax) {
774 case SNMP_SYNTAX_INTEGER:
775 return (snmp_lookup_leaf(&snmptoolctx->snmp_intlist, s));
776 case SNMP_SYNTAX_OCTETSTRING:
777 return (snmp_lookup_leaf(&snmptoolctx->snmp_octlist, s));
778 case SNMP_SYNTAX_OID:
779 return (snmp_lookup_leaf(&snmptoolctx->snmp_oidlist, s));
780 case SNMP_SYNTAX_IPADDRESS:
781 return (snmp_lookup_leaf(&snmptoolctx->snmp_iplist, s));
782 case SNMP_SYNTAX_COUNTER:
783 return (snmp_lookup_leaf(&snmptoolctx->snmp_cntlist, s));
784 case SNMP_SYNTAX_GAUGE:
785 return (snmp_lookup_leaf(
786 &snmptoolctx->snmp_gaugelist, s));
787 case SNMP_SYNTAX_TIMETICKS:
788 return (snmp_lookup_leaf(
789 &snmptoolctx->snmp_ticklist, s));
790 case SNMP_SYNTAX_COUNTER64:
791 return (snmp_lookup_leaf(
792 &snmptoolctx->snmp_cnt64list, s));
793 case SNMP_SYNTAX_NOSUCHOBJECT:
795 case SNMP_SYNTAX_NOSUCHINSTANCE:
797 case SNMP_SYNTAX_ENDOFMIBVIEW:
798 return (snmp_lookup_allstring(snmptoolctx, s));
800 warnx("Unknown syntax - %d", s->val.syntax);
808 snmp_lookup_enumstring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
810 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL || s == NULL)
813 return (snmp_lookuplist_string(&snmptoolctx->snmp_enumlist, s));
817 snmp_lookup_oidstring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
819 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL || s == NULL)
822 return (snmp_lookuplist_string(&snmptoolctx->snmp_oidlist, s));
826 snmp_lookup_nodestring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
828 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL || s == NULL)
831 return (snmp_lookuplist_string(&snmptoolctx->snmp_nodelist, s));
835 snmp_lookup_allstring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
837 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL)
840 if (snmp_lookup_leaf(&snmptoolctx->snmp_intlist, s) > 0)
842 if (snmp_lookup_leaf(&snmptoolctx->snmp_octlist, s) > 0)
844 if (snmp_lookup_leaf(&snmptoolctx->snmp_oidlist, s) > 0)
846 if (snmp_lookup_leaf(&snmptoolctx->snmp_iplist, s) > 0)
848 if (snmp_lookup_leaf(&snmptoolctx->snmp_cntlist, s) > 0)
850 if (snmp_lookup_leaf(&snmptoolctx->snmp_gaugelist, s) > 0)
852 if (snmp_lookup_leaf(&snmptoolctx->snmp_ticklist, s) > 0)
854 if (snmp_lookup_leaf(&snmptoolctx->snmp_cnt64list, s) > 0)
856 if (snmp_lookuplist_string(&snmptoolctx->snmp_enumlist, s) > 0)
858 if (snmp_lookuplist_string(&snmptoolctx->snmp_nodelist, s) > 0)
865 snmp_lookup_nonleaf_string(struct snmp_toolinfo *snmptoolctx,
866 struct snmp_object *s)
868 if (snmptoolctx == NULL)
871 if (snmp_lookuplist_string(&snmptoolctx->snmp_nodelist, s) > 0)
873 if (snmp_lookuplist_string(&snmptoolctx->snmp_enumlist, s) > 0)
880 snmp_lookup_oidlist(struct snmp_mapping *hp, struct snmp_object *s, char *oid)
882 struct snmp_oid2str *temp;
887 SLIST_FOREACH(temp, hp, link) {
888 if (temp->strlen != strlen(oid))
891 if (strncmp(temp->string, oid, temp->strlen))
894 s->val.syntax = temp->syntax;
896 asn_append_oid(&(s->val.var), &(temp->var));
904 snmp_lookup_tablelist(struct snmp_toolinfo *snmptoolctx,
905 struct snmp_table_index *headp, struct snmp_object *s, char *oid)
907 struct snmp_index_entry *temp;
909 if (snmptoolctx == NULL || headp == NULL)
912 SLIST_FOREACH(temp, headp, link) {
913 if (temp->strlen != strlen(oid))
916 if (strncmp(temp->string, oid, temp->strlen))
920 * Another hack here - if we were given a table name
921 * return the corresponding pointer to it's entry.
922 * That should not change the reponce we'll get.
924 s->val.syntax = SNMP_SYNTAX_NULL;
925 asn_append_oid(&(s->val.var), &(temp->var));
926 if (snmp_lookup_leaf(&snmptoolctx->snmp_nodelist, s) > 0)
936 snmp_lookup_oidall(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s,
939 if (snmptoolctx == NULL || s == NULL || oid == NULL)
942 if (snmp_lookup_oidlist(&snmptoolctx->snmp_intlist, s, oid) > 0)
944 if (snmp_lookup_oidlist(&snmptoolctx->snmp_octlist, s, oid) > 0)
946 if (snmp_lookup_oidlist(&snmptoolctx->snmp_oidlist, s, oid) > 0)
948 if (snmp_lookup_oidlist(&snmptoolctx->snmp_iplist, s, oid) > 0)
950 if (snmp_lookup_oidlist(&snmptoolctx->snmp_ticklist, s, oid) > 0)
952 if (snmp_lookup_oidlist(&snmptoolctx->snmp_cntlist, s, oid) > 0)
954 if (snmp_lookup_oidlist(&snmptoolctx->snmp_gaugelist, s, oid) > 0)
956 if (snmp_lookup_oidlist(&snmptoolctx->snmp_cnt64list, s, oid) > 0)
958 if (snmp_lookup_oidlist(&snmptoolctx->snmp_nodelist, s, oid) > 0)
960 if (snmp_lookup_tablelist(snmptoolctx, &snmptoolctx->snmp_tablelist,
968 snmp_lookup_enumoid(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s,
971 if (snmptoolctx == NULL || s == NULL)
974 return (snmp_lookup_oidlist(&snmptoolctx->snmp_enumlist, s, oid));
978 snmp_lookup_oid(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s,
981 if (snmptoolctx == NULL || s == NULL)
984 switch (s->val.syntax) {
985 case SNMP_SYNTAX_INTEGER:
986 return (snmp_lookup_oidlist(&snmptoolctx->snmp_intlist,
988 case SNMP_SYNTAX_OCTETSTRING:
989 return (snmp_lookup_oidlist(&snmptoolctx->snmp_octlist,
991 case SNMP_SYNTAX_OID:
992 return (snmp_lookup_oidlist(&snmptoolctx->snmp_oidlist,
994 case SNMP_SYNTAX_IPADDRESS:
995 return (snmp_lookup_oidlist(&snmptoolctx->snmp_iplist,
997 case SNMP_SYNTAX_COUNTER:
998 return (snmp_lookup_oidlist(&snmptoolctx->snmp_cntlist,
1000 case SNMP_SYNTAX_GAUGE:
1001 return (snmp_lookup_oidlist(&snmptoolctx->snmp_gaugelist,
1003 case SNMP_SYNTAX_TIMETICKS:
1004 return (snmp_lookup_oidlist(&snmptoolctx->snmp_ticklist,
1006 case SNMP_SYNTAX_COUNTER64:
1007 return (snmp_lookup_oidlist(&snmptoolctx->snmp_cnt64list,
1009 case SNMP_SYNTAX_NULL:
1010 return (snmp_lookup_oidlist(&snmptoolctx->snmp_nodelist,
1013 warnx("Unknown syntax - %d", s->val.syntax);