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 #define DEBUG if (_bsnmptools_debug) fprintf
52 /* Allocate memory and initialize list. */
53 struct snmp_mappings *
54 snmp_mapping_init(void)
56 struct snmp_mappings *m;
58 if ((m = calloc(1, sizeof(struct snmp_mappings))) == NULL) {
59 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
66 #define snmp_nodelist mappings->nodelist
67 #define snmp_intlist mappings->intlist
68 #define snmp_octlist mappings->octlist
69 #define snmp_oidlist mappings->oidlist
70 #define snmp_iplist mappings->iplist
71 #define snmp_ticklist mappings->ticklist
72 #define snmp_cntlist mappings->cntlist
73 #define snmp_gaugelist mappings->gaugelist
74 #define snmp_cnt64list mappings->cnt64list
75 #define snmp_enumlist mappings->enumlist
76 #define snmp_tablelist mappings->tablelist
77 #define snmp_tclist mappings->tclist
80 enum_pairs_free(struct enum_pairs *headp)
87 while ((e = STAILQ_FIRST(headp)) != NULL) {
88 STAILQ_REMOVE_HEAD(headp, link);
99 snmp_mapping_entryfree(struct snmp_oid2str *entry)
104 if (entry->tc == SNMP_TC_OWN)
105 enum_pairs_free(entry->snmp_enum);
111 snmp_mapping_listfree(struct snmp_mapping *headp)
113 struct snmp_oid2str *p;
115 while ((p = SLIST_FIRST(headp)) != NULL) {
116 SLIST_REMOVE_HEAD(headp, link);
121 if (p->tc == SNMP_TC_OWN)
122 enum_pairs_free(p->snmp_enum);
130 snmp_index_listfree(struct snmp_idxlist *headp)
134 while ((i = STAILQ_FIRST(headp)) != NULL) {
135 STAILQ_REMOVE_HEAD(headp, link);
136 if (i->tc == SNMP_TC_OWN)
137 enum_pairs_free(i->snmp_enum);
145 snmp_mapping_table_listfree(struct snmp_table_index *headp)
147 struct snmp_index_entry *t;
149 while ((t = SLIST_FIRST(headp)) != NULL) {
150 SLIST_REMOVE_HEAD(headp, link);
155 snmp_index_listfree(&(t->index_list));
161 snmp_enumtc_listfree(struct snmp_enum_tc *headp)
165 while ((t = SLIST_FIRST(headp)) != NULL) {
166 SLIST_REMOVE_HEAD(headp, link);
170 enum_pairs_free(t->snmp_enum);
176 snmp_mapping_free(struct snmp_toolinfo *snmptoolctx)
178 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL)
181 snmp_mapping_listfree(&snmptoolctx->snmp_nodelist);
182 snmp_mapping_listfree(&snmptoolctx->snmp_intlist);
183 snmp_mapping_listfree(&snmptoolctx->snmp_octlist);
184 snmp_mapping_listfree(&snmptoolctx->snmp_oidlist);
185 snmp_mapping_listfree(&snmptoolctx->snmp_iplist);
186 snmp_mapping_listfree(&snmptoolctx->snmp_ticklist);
187 snmp_mapping_listfree(&snmptoolctx->snmp_cntlist);
188 snmp_mapping_listfree(&snmptoolctx->snmp_gaugelist);
189 snmp_mapping_listfree(&snmptoolctx->snmp_cnt64list);
190 snmp_mapping_listfree(&snmptoolctx->snmp_enumlist);
191 snmp_mapping_table_listfree(&snmptoolctx->snmp_tablelist);
192 snmp_enumtc_listfree(&snmptoolctx->snmp_tclist);
193 free(snmptoolctx->mappings);
199 snmp_dump_enumpairs(struct enum_pairs *headp)
201 struct enum_pair *entry;
206 fprintf(stderr,"enums: ");
207 STAILQ_FOREACH(entry, headp, link)
208 fprintf(stderr,"%d - %s, ", entry->enum_val,
209 (entry->enum_str == NULL)?"NULL":entry->enum_str);
211 fprintf(stderr,"; ");
215 snmp_dump_oid2str(struct snmp_oid2str *entry)
217 char buf[ASN_OIDSTRLEN];
220 memset(buf, 0, sizeof(buf));
221 asn_oid2str_r(&(entry->var), buf);
222 DEBUG(stderr, "%s - %s - %d - %d - %d", buf, entry->string,
223 entry->syntax, entry->access, entry->strlen);
224 snmp_dump_enumpairs(entry->snmp_enum);
225 DEBUG(stderr,"%s \n", (entry->table_idx == NULL)?"No table":
226 entry->table_idx->string);
231 snmp_dump_indexlist(struct snmp_idxlist *headp)
238 STAILQ_FOREACH(entry, headp, link) {
239 fprintf(stderr,"%d, ", entry->syntax);
240 snmp_dump_enumpairs(entry->snmp_enum);
243 fprintf(stderr,"\n");
246 /* Initialize the enum pairs list of a oid2str entry. */
248 enum_pairs_init(void)
250 struct enum_pairs *snmp_enum;
252 if ((snmp_enum = malloc(sizeof(struct enum_pairs))) == NULL) {
253 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
257 STAILQ_INIT(snmp_enum);
262 * Given a number and string, allocate memory for a (int, string) pair and add
263 * it to the given oid2str mapping entry's enum pairs list.
266 enum_pair_insert(struct enum_pairs *headp, int32_t enum_val, char *enum_str)
268 struct enum_pair *e_new;
270 if ((e_new = calloc(1, sizeof(struct enum_pair))) == NULL) {
271 syslog(LOG_ERR, "calloc() failed: %s", strerror(errno));
275 if ((e_new->enum_str = strdup(enum_str)) == NULL) {
276 syslog(LOG_ERR, "strdup() failed: %s", strerror(errno));
281 e_new->enum_val = enum_val;
282 STAILQ_INSERT_TAIL(headp, e_new, link);
289 * Insert an entry in a list - entries are lexicographicaly order by asn_oid.
290 * Returns 1 on success, -1 if list is not initialized, 0 if a matching oid already
291 * exists. Error cheking is left to calling function.
294 snmp_mapping_insert(struct snmp_mapping *headp, struct snmp_oid2str *entry)
297 struct snmp_oid2str *temp, *prev;
302 if ((prev = SLIST_FIRST(headp)) == NULL ||
303 asn_compare_oid(&(entry->var), &(prev->var)) < 0) {
304 SLIST_INSERT_HEAD(headp, entry, link);
307 rc = -1; /* Make the compiler happy. */
309 SLIST_FOREACH(temp, headp, link) {
310 if ((rc = asn_compare_oid(&(entry->var), &(temp->var))) <= 0)
318 /* Ops, matching OIDs - hope the rest info also matches. */
319 if (strncmp(temp->string, entry->string, entry->strlen)) {
320 syslog(LOG_INFO, "Matching OIDs with different string "
321 "mappings: old - %s, new - %s", temp->string,
326 * Ok, we have that already.
327 * As long as the strings match - don't complain.
332 SLIST_INSERT_AFTER(temp, entry, link);
336 SLIST_INSERT_AFTER(prev, entry, link);
348 snmp_node_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
350 if (snmptoolctx != NULL && snmptoolctx->mappings)
351 return (snmp_mapping_insert(&snmptoolctx->snmp_nodelist,entry));
357 snmp_int_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
359 if (snmptoolctx != NULL && snmptoolctx->mappings)
360 return (snmp_mapping_insert(&snmptoolctx->snmp_intlist,entry));
366 snmp_oct_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
368 if (snmptoolctx != NULL && snmptoolctx->mappings)
369 return (snmp_mapping_insert(&snmptoolctx->snmp_octlist,entry));
375 snmp_oid_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
377 if (snmptoolctx != NULL && snmptoolctx->mappings)
378 return (snmp_mapping_insert(&snmptoolctx->snmp_oidlist,entry));
384 snmp_ip_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
386 if (snmptoolctx != NULL && snmptoolctx->mappings)
387 return (snmp_mapping_insert(&snmptoolctx->snmp_iplist,entry));
393 snmp_tick_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
395 if (snmptoolctx != NULL && snmptoolctx->mappings)
396 return (snmp_mapping_insert(&snmptoolctx->snmp_ticklist,entry));
402 snmp_cnt_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
404 if (snmptoolctx != NULL && snmptoolctx->mappings)
405 return (snmp_mapping_insert(&snmptoolctx->snmp_cntlist,entry));
411 snmp_gauge_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
413 if (snmptoolctx != NULL && snmptoolctx->mappings)
414 return (snmp_mapping_insert(&snmptoolctx->snmp_gaugelist,entry));
420 snmp_cnt64_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
422 if (snmptoolctx != NULL && snmptoolctx->mappings)
423 return (snmp_mapping_insert(&snmptoolctx->snmp_cnt64list,entry));
429 snmp_enum_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
431 if (snmptoolctx != NULL && snmptoolctx->mappings)
432 return (snmp_mapping_insert(&snmptoolctx->snmp_enumlist,entry));
438 snmp_leaf_insert(struct snmp_toolinfo *snmptoolctx, struct snmp_oid2str *entry)
440 switch (entry->syntax) {
441 case SNMP_SYNTAX_INTEGER:
442 return (snmp_int_insert(snmptoolctx, entry));
443 case SNMP_SYNTAX_OCTETSTRING:
444 return (snmp_oct_insert(snmptoolctx, entry));
445 case SNMP_SYNTAX_OID:
446 return (snmp_oid_insert(snmptoolctx, entry));
447 case SNMP_SYNTAX_IPADDRESS:
448 return (snmp_ip_insert(snmptoolctx, entry));
449 case SNMP_SYNTAX_COUNTER:
450 return (snmp_cnt_insert(snmptoolctx, entry));
451 case SNMP_SYNTAX_GAUGE:
452 return (snmp_gauge_insert(snmptoolctx, entry));
453 case SNMP_SYNTAX_TIMETICKS:
454 return (snmp_tick_insert(snmptoolctx, entry));
455 case SNMP_SYNTAX_COUNTER64:
456 return (snmp_cnt64_insert(snmptoolctx, entry));
465 snmp_index_insert(struct snmp_idxlist *headp, struct index *idx)
467 if (headp == NULL || idx == NULL)
470 STAILQ_INSERT_TAIL(headp, idx, link);
475 snmp_syntax_insert(struct snmp_idxlist *headp, struct enum_pairs *enums,
476 enum snmp_syntax syntax, enum snmp_tc tc)
480 if ((idx = calloc(1, sizeof(struct index))) == NULL) {
481 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
485 if (snmp_index_insert(headp, idx) < 0) {
490 idx->syntax = syntax;
491 idx->snmp_enum = enums;
498 snmp_table_insert(struct snmp_toolinfo *snmptoolctx,
499 struct snmp_index_entry *entry)
502 struct snmp_index_entry *temp, *prev;
504 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL ||
508 if ((prev = SLIST_FIRST(&snmptoolctx->snmp_tablelist)) == NULL ||
509 asn_compare_oid(&(entry->var), &(prev->var)) < 0) {
510 SLIST_INSERT_HEAD(&snmptoolctx->snmp_tablelist, entry, link);
513 rc = -1; /* Make the compiler happy. */
515 SLIST_FOREACH(temp, &snmptoolctx->snmp_tablelist, link) {
516 if ((rc = asn_compare_oid(&(entry->var), &(temp->var))) <= 0)
524 /* Ops, matching OIDs - hope the rest info also matches. */
525 if (strncmp(temp->string, entry->string, entry->strlen)) {
526 syslog(LOG_INFO, "Matching OIDs with different string "
527 "mapping - old - %s, new - %s", temp->string,
534 SLIST_INSERT_AFTER(temp, entry, link);
538 SLIST_INSERT_AFTER(prev, entry, link);
550 snmp_enumtc_init(char *name)
552 struct enum_type *enum_tc;
554 if ((enum_tc = calloc(1, sizeof(struct enum_type))) == NULL) {
555 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
559 if ((enum_tc->name = strdup(name)) == NULL) {
560 syslog(LOG_ERR, "malloc() failed: %s", strerror(errno));
569 snmp_enumtc_free(struct enum_type *tc)
574 enum_pairs_free(tc->snmp_enum);
579 snmp_enumtc_insert(struct snmp_toolinfo *snmptoolctx, struct enum_type *entry)
581 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL)
582 return; /* XXX no error handling? */
584 SLIST_INSERT_HEAD(&snmptoolctx->snmp_tclist, entry, link);
588 snmp_enumtc_lookup(struct snmp_toolinfo *snmptoolctx, char *name)
590 struct enum_type *temp;
592 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL)
595 SLIST_FOREACH(temp, &snmptoolctx->snmp_tclist, link) {
596 if (strcmp(temp->name, name) == 0)
603 snmp_mapping_dumplist(struct snmp_mapping *headp)
605 char buf[ASN_OIDSTRLEN];
606 struct snmp_oid2str *entry;
611 SLIST_FOREACH(entry,headp,link) {
612 memset(buf, 0, sizeof(buf));
613 asn_oid2str_r(&(entry->var), buf);
614 fprintf(stderr, "%s - %s - %d - %d - %d", buf, entry->string,
615 entry->syntax, entry->access ,entry->strlen);
616 fprintf(stderr," - %s \n", (entry->table_idx == NULL)?
617 "No table":entry->table_idx->string);
622 snmp_mapping_dumptable(struct snmp_table_index *headp)
624 char buf[ASN_OIDSTRLEN];
625 struct snmp_index_entry *entry;
630 SLIST_FOREACH(entry, headp, link) {
631 memset(buf, 0, sizeof(buf));
632 asn_oid2str_r(&(entry->var), buf);
633 fprintf(stderr,"%s - %s - %d - ", buf, entry->string,
635 snmp_dump_indexlist(&(entry->index_list));
640 snmp_mapping_dump(struct snmp_toolinfo *snmptoolctx /* int bits */)
642 if (!_bsnmptools_debug)
645 if (snmptoolctx == NULL) {
646 fprintf(stderr,"No snmptool context!\n");
650 if (snmptoolctx->mappings == NULL) {
651 fprintf(stderr,"No mappings!\n");
655 fprintf(stderr,"snmp_nodelist:\n");
656 snmp_mapping_dumplist(&snmptoolctx->snmp_nodelist);
658 fprintf(stderr,"snmp_intlist:\n");
659 snmp_mapping_dumplist(&snmptoolctx->snmp_intlist);
661 fprintf(stderr,"snmp_octlist:\n");
662 snmp_mapping_dumplist(&snmptoolctx->snmp_octlist);
664 fprintf(stderr,"snmp_oidlist:\n");
665 snmp_mapping_dumplist(&snmptoolctx->snmp_oidlist);
667 fprintf(stderr,"snmp_iplist:\n");
668 snmp_mapping_dumplist(&snmptoolctx->snmp_iplist);
670 fprintf(stderr,"snmp_ticklist:\n");
671 snmp_mapping_dumplist(&snmptoolctx->snmp_ticklist);
673 fprintf(stderr,"snmp_cntlist:\n");
674 snmp_mapping_dumplist(&snmptoolctx->snmp_cntlist);
676 fprintf(stderr,"snmp_gaugelist:\n");
677 snmp_mapping_dumplist(&snmptoolctx->snmp_gaugelist);
679 fprintf(stderr,"snmp_cnt64list:\n");
680 snmp_mapping_dumplist(&snmptoolctx->snmp_cnt64list);
682 fprintf(stderr,"snmp_enumlist:\n");
683 snmp_mapping_dumplist(&snmptoolctx->snmp_enumlist);
685 fprintf(stderr,"snmp_tablelist:\n");
686 snmp_mapping_dumptable(&snmptoolctx->snmp_tablelist);
690 enum_string_lookup(struct enum_pairs *headp, int32_t enum_val)
692 struct enum_pair *temp;
697 STAILQ_FOREACH(temp, headp, link) {
698 if (temp->enum_val == enum_val)
699 return (temp->enum_str);
706 enum_number_lookup(struct enum_pairs *headp, char *e_str)
708 struct enum_pair *tmp;
713 STAILQ_FOREACH(tmp, headp, link)
714 if (strncmp(tmp->enum_str, e_str, strlen(tmp->enum_str)) == 0)
715 return (tmp->enum_val);
721 snmp_lookuplist_string(struct snmp_mapping *headp, struct snmp_object *s)
723 struct snmp_oid2str *temp;
728 SLIST_FOREACH(temp, headp, link)
729 if (asn_compare_oid(&(temp->var), &(s->val.var)) == 0)
732 if ((s->info = temp) == NULL)
738 /* provided an asn_oid find the corresponding string for it */
740 snmp_lookup_leaf(struct snmp_mapping *headp, struct snmp_object *s)
742 struct snmp_oid2str *temp;
747 SLIST_FOREACH(temp,headp,link) {
748 if ((asn_compare_oid(&(temp->var), &(s->val.var)) == 0) ||
749 (asn_is_suboid(&(temp->var), &(s->val.var)))) {
759 snmp_lookup_leafstring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
761 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL || s == NULL)
764 switch (s->val.syntax) {
765 case SNMP_SYNTAX_INTEGER:
766 return (snmp_lookup_leaf(&snmptoolctx->snmp_intlist, s));
767 case SNMP_SYNTAX_OCTETSTRING:
768 return (snmp_lookup_leaf(&snmptoolctx->snmp_octlist, s));
769 case SNMP_SYNTAX_OID:
770 return (snmp_lookup_leaf(&snmptoolctx->snmp_oidlist, s));
771 case SNMP_SYNTAX_IPADDRESS:
772 return (snmp_lookup_leaf(&snmptoolctx->snmp_iplist, s));
773 case SNMP_SYNTAX_COUNTER:
774 return (snmp_lookup_leaf(&snmptoolctx->snmp_cntlist, s));
775 case SNMP_SYNTAX_GAUGE:
776 return (snmp_lookup_leaf(
777 &snmptoolctx->snmp_gaugelist, s));
778 case SNMP_SYNTAX_TIMETICKS:
779 return (snmp_lookup_leaf(
780 &snmptoolctx->snmp_ticklist, s));
781 case SNMP_SYNTAX_COUNTER64:
782 return (snmp_lookup_leaf(
783 &snmptoolctx->snmp_cnt64list, s));
784 case SNMP_SYNTAX_NOSUCHOBJECT:
786 case SNMP_SYNTAX_NOSUCHINSTANCE:
788 case SNMP_SYNTAX_ENDOFMIBVIEW:
789 return (snmp_lookup_allstring(snmptoolctx, s));
791 warnx("Unknown syntax - %d", s->val.syntax);
799 snmp_lookup_enumstring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
801 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL || s == NULL)
804 return (snmp_lookuplist_string(&snmptoolctx->snmp_enumlist, s));
808 snmp_lookup_oidstring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
810 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL || s == NULL)
813 return (snmp_lookuplist_string(&snmptoolctx->snmp_oidlist, s));
817 snmp_lookup_nodestring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
819 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL || s == NULL)
822 return (snmp_lookuplist_string(&snmptoolctx->snmp_nodelist, s));
826 snmp_lookup_allstring(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s)
828 if (snmptoolctx == NULL || snmptoolctx->mappings == NULL)
831 if (snmp_lookup_leaf(&snmptoolctx->snmp_intlist, s) > 0)
833 if (snmp_lookup_leaf(&snmptoolctx->snmp_octlist, s) > 0)
835 if (snmp_lookup_leaf(&snmptoolctx->snmp_oidlist, s) > 0)
837 if (snmp_lookup_leaf(&snmptoolctx->snmp_iplist, s) > 0)
839 if (snmp_lookup_leaf(&snmptoolctx->snmp_cntlist, s) > 0)
841 if (snmp_lookup_leaf(&snmptoolctx->snmp_gaugelist, s) > 0)
843 if (snmp_lookup_leaf(&snmptoolctx->snmp_ticklist, s) > 0)
845 if (snmp_lookup_leaf(&snmptoolctx->snmp_cnt64list, s) > 0)
847 if (snmp_lookuplist_string(&snmptoolctx->snmp_enumlist, s) > 0)
849 if (snmp_lookuplist_string(&snmptoolctx->snmp_nodelist, s) > 0)
856 snmp_lookup_nonleaf_string(struct snmp_toolinfo *snmptoolctx,
857 struct snmp_object *s)
859 if (snmptoolctx == NULL)
862 if (snmp_lookuplist_string(&snmptoolctx->snmp_nodelist, s) > 0)
864 if (snmp_lookuplist_string(&snmptoolctx->snmp_enumlist, s) > 0)
871 snmp_lookup_oidlist(struct snmp_mapping *hp, struct snmp_object *s, char *oid)
873 struct snmp_oid2str *temp;
878 SLIST_FOREACH(temp, hp, link) {
879 if (temp->strlen != strlen(oid))
882 if (strncmp(temp->string, oid, temp->strlen))
885 s->val.syntax = temp->syntax;
887 asn_append_oid(&(s->val.var), &(temp->var));
895 snmp_lookup_tablelist(struct snmp_toolinfo *snmptoolctx,
896 struct snmp_table_index *headp, struct snmp_object *s, char *oid)
898 struct snmp_index_entry *temp;
900 if (snmptoolctx == NULL || headp == NULL)
903 SLIST_FOREACH(temp, headp, link) {
904 if (temp->strlen != strlen(oid))
907 if (strncmp(temp->string, oid, temp->strlen))
911 * Another hack here - if we were given a table name
912 * return the corresponding pointer to it's entry.
913 * That should not change the reponce we'll get.
915 s->val.syntax = SNMP_SYNTAX_NULL;
916 asn_append_oid(&(s->val.var), &(temp->var));
917 if (snmp_lookup_leaf(&snmptoolctx->snmp_nodelist, s) > 0)
927 snmp_lookup_oidall(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s,
930 if (snmptoolctx == NULL || s == NULL || oid == NULL)
933 if (snmp_lookup_oidlist(&snmptoolctx->snmp_intlist, s, oid) > 0)
935 if (snmp_lookup_oidlist(&snmptoolctx->snmp_octlist, s, oid) > 0)
937 if (snmp_lookup_oidlist(&snmptoolctx->snmp_oidlist, s, oid) > 0)
939 if (snmp_lookup_oidlist(&snmptoolctx->snmp_iplist, s, oid) > 0)
941 if (snmp_lookup_oidlist(&snmptoolctx->snmp_ticklist, s, oid) > 0)
943 if (snmp_lookup_oidlist(&snmptoolctx->snmp_cntlist, s, oid) > 0)
945 if (snmp_lookup_oidlist(&snmptoolctx->snmp_gaugelist, s, oid) > 0)
947 if (snmp_lookup_oidlist(&snmptoolctx->snmp_cnt64list, s, oid) > 0)
949 if (snmp_lookup_oidlist(&snmptoolctx->snmp_nodelist, s, oid) > 0)
951 if (snmp_lookup_tablelist(snmptoolctx, &snmptoolctx->snmp_tablelist,
959 snmp_lookup_enumoid(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s,
962 if (snmptoolctx == NULL || s == NULL)
965 return (snmp_lookup_oidlist(&snmptoolctx->snmp_enumlist, s, oid));
969 snmp_lookup_oid(struct snmp_toolinfo *snmptoolctx, struct snmp_object *s,
972 if (snmptoolctx == NULL || s == NULL)
975 switch (s->val.syntax) {
976 case SNMP_SYNTAX_INTEGER:
977 return (snmp_lookup_oidlist(&snmptoolctx->snmp_intlist,
979 case SNMP_SYNTAX_OCTETSTRING:
980 return (snmp_lookup_oidlist(&snmptoolctx->snmp_octlist,
982 case SNMP_SYNTAX_OID:
983 return (snmp_lookup_oidlist(&snmptoolctx->snmp_oidlist,
985 case SNMP_SYNTAX_IPADDRESS:
986 return (snmp_lookup_oidlist(&snmptoolctx->snmp_iplist,
988 case SNMP_SYNTAX_COUNTER:
989 return (snmp_lookup_oidlist(&snmptoolctx->snmp_cntlist,
991 case SNMP_SYNTAX_GAUGE:
992 return (snmp_lookup_oidlist(&snmptoolctx->snmp_gaugelist,
994 case SNMP_SYNTAX_TIMETICKS:
995 return (snmp_lookup_oidlist(&snmptoolctx->snmp_ticklist,
997 case SNMP_SYNTAX_COUNTER64:
998 return (snmp_lookup_oidlist(&snmptoolctx->snmp_cnt64list,
1000 case SNMP_SYNTAX_NULL:
1001 return (snmp_lookup_oidlist(&snmptoolctx->snmp_nodelist,
1004 warnx("Unknown syntax - %d", s->val.syntax);