print-snmp.c revision e66460324c0c1d5b6f767afeb6f3d201094156d3
1cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen/* 2cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 3cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * John Robert LoVerso. All rights reserved. 4cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * 5cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * Redistribution and use in source and binary forms, with or without 6cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * modification, are permitted provided that the following conditions 7cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * are met: 8cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * 9cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * 1. Redistributions of source code must retain the above copyright 10cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * notice, this list of conditions and the following disclaimer. 11cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * 12cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * 2. Redistributions in binary form must reproduce the above copyright 13cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * notice, this list of conditions and the following disclaimer in the 14cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * documentation and/or other materials provided with the distribution. 15cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * 16dd479e9769eceee9fcc34e2173376024f3aa3c5fJakob Stoklund Olesen * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 175907d863659eb972ebb2afe07bc863a4c616f0efJakob Stoklund Olesen * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18cfafc54040cc9722995558124f253d05a038176bJakob Stoklund Olesen * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19f428eb6c1b09a2322b7a577b0bf2e49dd107bceaJakob Stoklund Olesen * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23d0bb5e2ca05d9c942223bf05e5940bb0c6cc9d3fJakob Stoklund Olesen * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 250db841f9c2b9a25fb5ecb36e350d3a802c35654cJakob Stoklund Olesen * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * 27cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * 28cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * This implementation has been influenced by the CMU SNMP release, 29cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * by Steve Waldbusser. However, this shares no code with that system. 30b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen * Additional ASN.1 insight gained from Marshall T. Rose's _The_Open_Book_. 31cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * Earlier forms of this implementation were derived and/or inspired by an 32cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * awk script originally written by C. Philip Wood of LANL (but later 33f428eb6c1b09a2322b7a577b0bf2e49dd107bceaJakob Stoklund Olesen * heavily modified by John Robert LoVerso). The copyright notice for 34cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * that work is preserved below, even though it may not rightly apply 35cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * to this file. 36d0bb5e2ca05d9c942223bf05e5940bb0c6cc9d3fJakob Stoklund Olesen * 37cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * Support for SNMPv2c/SNMPv3 and the ability to link the module against 38cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * the libsmi was added by J. Schoenwaelder, Copyright (c) 1999. 39cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * 40cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * This started out as a very simple program, but the incremental decoding 41cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * (into the BE structure) complicated things. 42cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * 43cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen # Los Alamos National Laboratory 44cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen # 45533f58ecdd8a4732c2f0e149387c4d8d8d4142deJakob Stoklund Olesen # Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 46cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen # This software was produced under a U.S. Government contract 4798d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen # (W-7405-ENG-36) by Los Alamos National Laboratory, which is 4898d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen # operated by the University of California for the U.S. Department 49cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen # of Energy. The U.S. Government is licensed to use, reproduce, 50cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen # and distribute this software. Permission is granted to the 510db841f9c2b9a25fb5ecb36e350d3a802c35654cJakob Stoklund Olesen # public to copy and use this software without charge, provided 520db841f9c2b9a25fb5ecb36e350d3a802c35654cJakob Stoklund Olesen # that this Notice and any statement of authorship are reproduced 530db841f9c2b9a25fb5ecb36e350d3a802c35654cJakob Stoklund Olesen # on all copies. Neither the Government nor the University makes 540db841f9c2b9a25fb5ecb36e350d3a802c35654cJakob Stoklund Olesen # any warranty, express or implied, or assumes any liability or 55cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen # responsibility for the use of this software. 56cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen # @(#)snmp.awk.x 1.1 (LANL) 1/15/90 57cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen */ 58cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 5992a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen#ifndef lint 6092a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesenstatic const char rcsid[] _U_ = 6192a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.62.2.2 2005/05/06 07:57:19 guy Exp $ (LBL)"; 6292a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen#endif 63cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 64cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#ifdef HAVE_CONFIG_H 65cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#include "config.h" 66cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#endif 67cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 68b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen#include <tcpdump-stdinc.h> 69cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 70f428eb6c1b09a2322b7a577b0bf2e49dd107bceaJakob Stoklund Olesen#include <stdio.h> 71d0bb5e2ca05d9c942223bf05e5940bb0c6cc9d3fJakob Stoklund Olesen#include <string.h> 72d0bb5e2ca05d9c942223bf05e5940bb0c6cc9d3fJakob Stoklund Olesen 73b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen#ifdef HAVE_SMI_H 74b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen#include <smi.h> 75f428eb6c1b09a2322b7a577b0bf2e49dd107bceaJakob Stoklund Olesen#endif 76cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 77cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#include "interface.h" 7898d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen#include "addrtoname.h" 7922a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen 8022a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen#undef OPAQUE /* defined in <wingdi.h> */ 8122a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen 8222a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen/* 8322a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen * Universal ASN.1 types 8422a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen * (we only care about the tag values for those allowed in the Internet SMI) 8522a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen */ 8622a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesenconst char *Universal[] = { 8722a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "U-0", 8822a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "Boolean", 8922a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "Integer", 9022a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen#define INTEGER 2 9122a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "Bitstring", 9222a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "String", 9322a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen#define STRING 4 94f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen "Null", 95f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen#define ASN_NULL 5 9622a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "ObjID", 97fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen#define OBJECTID 6 9822a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "ObjectDes", 9922a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "U-8","U-9","U-10","U-11", /* 8-11 */ 10022a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "U-12","U-13","U-14","U-15", /* 12-15 */ 10122a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "Sequence", 10222a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen#define SEQUENCE 16 10322a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "Set" 10422a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen}; 10522a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen 10622a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen/* 10722a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen * Application-wide ASN.1 types from the Internet SMI and their tags 10822a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen */ 10922a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesenconst char *Application[] = { 11022a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "IpAddress", 111f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen#define IPADDR 0 112f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen "Counter", 113f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen#define COUNTER 1 114f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen "Gauge", 115f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen#define GAUGE 2 11622a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen "TimeTicks", 117cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#define TIMETICKS 3 118b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen "Opaque", 11922a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen#define OPAQUE 4 120bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen "C-5", 121b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen "Counter64" 122eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen#define COUNTER64 6 123eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen}; 124eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen 1257b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen/* 12696dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen * Context-specific ASN.1 types for the SNMP PDUs and their tags 127b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen */ 12896dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesenconst char *Context[] = { 12996dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen "GetRequest", 13096dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen#define GETREQ 0 13196dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen "GetNextRequest", 1325db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen#define GETNEXTREQ 1 1335db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen "GetResponse", 1345db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen#define GETRESP 2 1355db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen "SetRequest", 1365db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen#define SETREQ 3 1375db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen "Trap", 1385db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen#define TRAP 4 13996dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen "GetBulk", 14096dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen#define GETBULKREQ 5 14196dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen "Inform", 14296dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen#define INFORMREQ 6 14396dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen "V2Trap", 14496dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen#define V2TRAP 7 14596dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen "Report" 146034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen#define REPORT 8 147034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen}; 148034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 149034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen#define NOTIFY_CLASS(x) (x == TRAP || x == V2TRAP || x == INFORMREQ) 150cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#define READ_CLASS(x) (x == GETREQ || x == GETNEXTREQ || x == GETBULKREQ) 151cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#define WRITE_CLASS(x) (x == SETREQ) 152cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#define RESPONSE_CLASS(x) (x == GETRESP) 153cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#define INTERNAL_CLASS(x) (x == REPORT) 154cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 155533f58ecdd8a4732c2f0e149387c4d8d8d4142deJakob Stoklund Olesen/* 156cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * Context-specific ASN.1 types for the SNMP Exceptions and their tags 157cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen */ 158cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesenconst char *Exceptions[] = { 159cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen "noSuchObject", 160cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#define NOSUCHOBJECT 0 161cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen "noSuchInstance", 16298d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen#define NOSUCHINSTANCE 1 16398d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen "endOfMibView", 164ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen#define ENDOFMIBVIEW 2 165ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen}; 166cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 167cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen/* 168cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * Private ASN.1 types 169cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * The Internet SMI does not specify any 170cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen */ 171b853e6c3702149cdbbd6fa404334e3ba0055641aAndrew Trickconst char *Private[] = { 172b853e6c3702149cdbbd6fa404334e3ba0055641aAndrew Trick "P-0" 17392a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen}; 1747792e980c43536814ea42448db9799b4da32fef6Jakob Stoklund Olesen 1751d5b84508173b93faf513032b3847152e6060791Jakob Stoklund Olesen/* 176f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen * error-status values for any SNMP PDU 17792a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen */ 178200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesenconst char *ErrorStatus[] = { 179f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen "noError", 180f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen "tooBig", 1815db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen "noSuchName", 1825db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen "badValue", 1835db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen "readOnly", 184ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen "genErr", 185034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen "noAccess", 186034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen "wrongType", 187034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen "wrongLength", 188034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen "wrongEncoding", 189d17924b1bd0329acb8be2d7dfc5fc4434c24b832Jakob Stoklund Olesen "wrongValue", 190b64d92e29f38002e52a22fe36ea2d488968e3537Jakob Stoklund Olesen "noCreation", 1916bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen "inconsistentValue", 1926bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen "resourceUnavailable", 19398c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen "commitFailed", 1946bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen "undoFailed", 195b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen "authorizationError", 196b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen "notWritable", 197034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen "inconsistentName" 198034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen}; 199b64d92e29f38002e52a22fe36ea2d488968e3537Jakob Stoklund Olesen#define DECODE_ErrorStatus(e) \ 200b64d92e29f38002e52a22fe36ea2d488968e3537Jakob Stoklund Olesen ( e >= 0 && (size_t)e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \ 201cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen ? ErrorStatus[e] \ 202cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen : (snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf)) 203cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 204cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen/* 205cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * generic-trap values in the SNMP Trap-PDU 206200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen */ 207200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesenconst char *GenericTrap[] = { 208200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen "coldStart", 209200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen "warmStart", 210200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen "linkDown", 211cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen "linkUp", 212cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen "authenticationFailure", 213cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen "egpNeighborLoss", 214cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen "enterpriseSpecific" 215f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen#define GT_ENTERPRISE 6 216cfafc54040cc9722995558124f253d05a038176bJakob Stoklund Olesen}; 217b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen#define DECODE_GenericTrap(t) \ 218cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen ( t >= 0 && (size_t)t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \ 219cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen ? GenericTrap[t] \ 220cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen : (snprintf(buf, sizeof(buf), "gt=%d", t), buf)) 221cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 222cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen/* 223cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * ASN.1 type class table 224cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * Ties together the preceding Universal, Application, Context, and Private 225cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * type definitions. 226d0bb5e2ca05d9c942223bf05e5940bb0c6cc9d3fJakob Stoklund Olesen */ 227cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#define defineCLASS(x) { "x", x, sizeof(x)/sizeof(x[0]) } /* not ANSI-C */ 228b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesenstruct { 229b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen const char *name; 230cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen const char **Id; 231cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen int numIDs; 232cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen } Class[] = { 233cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen defineCLASS(Universal), 234cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#define UNIVERSAL 0 235cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen defineCLASS(Application), 236cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#define APPLICATION 1 237b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen defineCLASS(Context), 238cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#define CONTEXT 2 239cfafc54040cc9722995558124f253d05a038176bJakob Stoklund Olesen defineCLASS(Private), 240cfafc54040cc9722995558124f253d05a038176bJakob Stoklund Olesen#define PRIVATE 3 241cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen defineCLASS(Exceptions), 242cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#define EXCEPTIONS 4 243cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen}; 244cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 245cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen/* 246cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * defined forms for ASN.1 types 247f428eb6c1b09a2322b7a577b0bf2e49dd107bceaJakob Stoklund Olesen */ 248f428eb6c1b09a2322b7a577b0bf2e49dd107bceaJakob Stoklund Olesenconst char *Form[] = { 249cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen "Primitive", 250cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen#define PRIMITIVE 0 251d0bb5e2ca05d9c942223bf05e5940bb0c6cc9d3fJakob Stoklund Olesen "Constructed", 252d0bb5e2ca05d9c942223bf05e5940bb0c6cc9d3fJakob Stoklund Olesen#define CONSTRUCTED 1 253cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen}; 254cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 255b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen/* 256b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen * A structure for the OID tree for the compiled-in MIB. 257cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen * This is stored as a general-order tree. 258cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen */ 259cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesenstruct obj { 26092a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen const char *desc; /* name of object */ 26192a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen u_char oid; /* sub-id following parent */ 26292a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen u_char type; /* object type (unused) */ 26392a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen struct obj *child, *next; /* child and next sibling pointers */ 26492a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen} *objp = NULL; 26592a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen 26692a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen/* 26792a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen * Include the compiled in SNMP MIB. "mib.h" is produced by feeding 26892a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen * RFC-1156 format files into "makemib". "mib.h" MUST define at least 26992a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen * a value for `mibroot'. 2707792e980c43536814ea42448db9799b4da32fef6Jakob Stoklund Olesen * 2717792e980c43536814ea42448db9799b4da32fef6Jakob Stoklund Olesen * In particular, this is gross, as this is including initialized structures, 2727792e980c43536814ea42448db9799b4da32fef6Jakob Stoklund Olesen * and by right shouldn't be an "include" file. 2737792e980c43536814ea42448db9799b4da32fef6Jakob Stoklund Olesen */ 2747792e980c43536814ea42448db9799b4da32fef6Jakob Stoklund Olesen#include "mib.h" 2757792e980c43536814ea42448db9799b4da32fef6Jakob Stoklund Olesen 2767792e980c43536814ea42448db9799b4da32fef6Jakob Stoklund Olesen/* 2777792e980c43536814ea42448db9799b4da32fef6Jakob Stoklund Olesen * This defines a list of OIDs which will be abbreviated on output. 2787792e980c43536814ea42448db9799b4da32fef6Jakob Stoklund Olesen * Currently, this includes the prefixes for the Internet MIB, the 27992a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen * private enterprises tree, and the experimental tree. 2801d5b84508173b93faf513032b3847152e6060791Jakob Stoklund Olesen */ 2811d5b84508173b93faf513032b3847152e6060791Jakob Stoklund Olesenstruct obj_abrev { 2821d5b84508173b93faf513032b3847152e6060791Jakob Stoklund Olesen const char *prefix; /* prefix for this abrev */ 2831d5b84508173b93faf513032b3847152e6060791Jakob Stoklund Olesen struct obj *node; /* pointer into object table */ 2841d5b84508173b93faf513032b3847152e6060791Jakob Stoklund Olesen const char *oid; /* ASN.1 encoded OID */ 2851d5b84508173b93faf513032b3847152e6060791Jakob Stoklund Olesen} obj_abrev_list[] = { 2861d5b84508173b93faf513032b3847152e6060791Jakob Stoklund Olesen#ifndef NO_ABREV_MIB 2871d5b84508173b93faf513032b3847152e6060791Jakob Stoklund Olesen /* .iso.org.dod.internet.mgmt.mib */ 2881d5b84508173b93faf513032b3847152e6060791Jakob Stoklund Olesen { "", &_mib_obj, "\53\6\1\2\1" }, 2891d5b84508173b93faf513032b3847152e6060791Jakob Stoklund Olesen#endif 2901d5b84508173b93faf513032b3847152e6060791Jakob Stoklund Olesen#ifndef NO_ABREV_ENTER 291f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen /* .iso.org.dod.internet.private.enterprises */ 292f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen { "E:", &_enterprises_obj, "\53\6\1\4\1" }, 293f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen#endif 294f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen#ifndef NO_ABREV_EXPERI 295f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen /* .iso.org.dod.internet.experimental */ 296f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen { "X:", &_experimental_obj, "\53\6\1\3" }, 297f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen#endif 298f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen#ifndef NO_ABBREV_SNMPMODS 299cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen /* .iso.org.dod.internet.snmpV2.snmpModules */ 300cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen { "S:", &_snmpModules_obj, "\53\6\1\6\3" }, 30122a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen#endif 3025db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen { 0,0,0 } 303cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen}; 304cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 305cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen/* 30698d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen * This is used in the OID print routine to walk down the object tree 30798d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen * rooted at `mibroot'. 30898d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen */ 309107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen#define OBJ_PRINT(o, suppressdot) \ 310107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen{ \ 31198d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen if (objp) { \ 31298d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen do { \ 313107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen if ((o) == objp->oid) \ 31490c1d7ddfc65654f7efe72d56cad65d1af9e6b2aJakob Stoklund Olesen break; \ 31522a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen } while ((objp = objp->next) != NULL); \ 316f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen } \ 317f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen if (objp) { \ 318f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen printf(suppressdot?"%s":".%s", objp->desc); \ 319eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen objp = objp->child; \ 320eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen } else \ 321eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen printf(suppressdot?"%u":".%u", (o)); \ 322eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen} 323eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen 324eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen/* 325eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen * This is the definition for the Any-Data-Type storage used purely for 326eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen * temporary internal representation while decoding an ASN.1 data stream. 327107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen */ 328d2a50734234a80893ad71da90d9f32032c47e000Jakob Stoklund Olesenstruct be { 329eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen u_int32_t asnlen; 330eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen union { 331eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen caddr_t raw; 332eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen int32_t integer; 333107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen u_int32_t uns; 334107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen const u_char *str; 33590c1d7ddfc65654f7efe72d56cad65d1af9e6b2aJakob Stoklund Olesen struct { 33690c1d7ddfc65654f7efe72d56cad65d1af9e6b2aJakob Stoklund Olesen u_int32_t high; 33798d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen u_int32_t low; 33898d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen } uns64; 33998d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen } data; 34098d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen u_short id; 34198d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen u_char form, class; /* tag info */ 34298d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen u_char type; 34398d9648de7d571b2e6d139b65961a70d1833b0d7Jakob Stoklund Olesen#define BE_ANY 255 344770d42de3b7643b2b4f835f32e3a16275b9fbdbaJakob Stoklund Olesen#define BE_NONE 0 3456bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_NULL 1 3466bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_OCTET 2 3476bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_OID 3 3486bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_INT 4 3496bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_UNS 5 3506bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_STR 6 3516bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_SEQ 7 3526bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_INETADDR 8 3536bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_PDU 9 3546bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_UNS64 10 3556bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_NOSUCHOBJECT 128 3566bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_NOSUCHINST 129 3576bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define BE_ENDOFMIBVIEW 130 3586bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen}; 3596bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen 3606bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen/* 3616bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen * SNMP versions recognized by this module 3626bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen */ 3636bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesenconst char *SnmpVersion[] = { 3646bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen "SNMPv1", 3656bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define SNMP_VERSION_1 0 3666bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen "SNMPv2c", 3676bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define SNMP_VERSION_2 1 3686bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen "SNMPv2u", 3696bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define SNMP_VERSION_2U 2 3706bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen "SNMPv3" 3716bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#define SNMP_VERSION_3 3 3726bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen}; 3736bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen 3746bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen/* 3756bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen * Defaults for SNMP PDU components 376770d42de3b7643b2b4f835f32e3a16275b9fbdbaJakob Stoklund Olesen */ 37798c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen#define DEF_COMMUNITY "public" 37898c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen 3792710638db2eb84cd7eefb8bb9a1b7e5c49413d45Jakob Stoklund Olesen/* 38098c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen * constants for ASN.1 decoding 3813f5bedf5cbde2cc2badc86b1a0b377f6efcde71cJakob Stoklund Olesen */ 3823f5bedf5cbde2cc2badc86b1a0b377f6efcde71cJakob Stoklund Olesen#define OIDMUX 40 3833f5bedf5cbde2cc2badc86b1a0b377f6efcde71cJakob Stoklund Olesen#define ASNLEN_INETADDR 4 38498c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen#define ASN_SHIFT7 7 385d17924b1bd0329acb8be2d7dfc5fc4434c24b832Jakob Stoklund Olesen#define ASN_SHIFT8 8 38698c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen#define ASN_BIT8 0x80 38798c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen#define ASN_LONGLEN 0x80 38898c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen 3893f5bedf5cbde2cc2badc86b1a0b377f6efcde71cJakob Stoklund Olesen#define ASN_ID_BITS 0x1f 3903f5bedf5cbde2cc2badc86b1a0b377f6efcde71cJakob Stoklund Olesen#define ASN_FORM_BITS 0x20 39198c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen#define ASN_FORM_SHIFT 5 39298c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen#define ASN_CLASS_BITS 0xc0 3933f5bedf5cbde2cc2badc86b1a0b377f6efcde71cJakob Stoklund Olesen#define ASN_CLASS_SHIFT 6 3943f5bedf5cbde2cc2badc86b1a0b377f6efcde71cJakob Stoklund Olesen 3953f5bedf5cbde2cc2badc86b1a0b377f6efcde71cJakob Stoklund Olesen#define ASN_ID_EXT 0x1f /* extension ID in tag field */ 39698c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen 39798c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen/* 3983f5bedf5cbde2cc2badc86b1a0b377f6efcde71cJakob Stoklund Olesen * This decodes the next ASN.1 object in the stream pointed to by "p" 39998c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen * (and of real-length "len") and stores the intermediate data in the 40098c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen * provided BE object. 4012710638db2eb84cd7eefb8bb9a1b7e5c49413d45Jakob Stoklund Olesen * 4022710638db2eb84cd7eefb8bb9a1b7e5c49413d45Jakob Stoklund Olesen * This returns -l if it fails (i.e., the ASN.1 stream is not valid). 40398c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen * O/w, this returns the number of bytes parsed from "p". 40498c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen */ 40598c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesenstatic int 40698c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesenasn1_parse(register const u_char *p, u_int len, struct be *elem) 40798c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen{ 40898c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen u_char form, class, id; 40998c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen int i, hdr; 41098c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen 41198c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen elem->asnlen = 0; 41298c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen elem->type = BE_ANY; 4136bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen if (len < 1) { 4146bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen fputs("[nothing to parse]", stdout); 41598c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen return -1; 41698c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen } 41798c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen TCHECK(*p); 4183f5bedf5cbde2cc2badc86b1a0b377f6efcde71cJakob Stoklund Olesen 41998c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen /* 42098c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen * it would be nice to use a bit field, but you can't depend on them. 42198c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen * +---+---+---+---+---+---+---+---+ 42298c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen * + class |frm| id | 4236bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen * +---+---+---+---+---+---+---+---+ 4246bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen * 7 6 5 4 3 2 1 0 4256bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen */ 4266bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen id = *p & ASN_ID_BITS; /* lower 5 bits, range 00-1f */ 4276bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen#ifdef notdef 4286bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen form = (*p & 0xe0) >> 5; /* move upper 3 bits to lower 3 */ 4293f5bedf5cbde2cc2badc86b1a0b377f6efcde71cJakob Stoklund Olesen class = form >> 1; /* bits 7&6 -> bits 1&0, range 0-3 */ 430d17924b1bd0329acb8be2d7dfc5fc4434c24b832Jakob Stoklund Olesen form &= 0x1; /* bit 5 -> bit 0, range 0-1 */ 43198c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen#else 43298c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen form = (u_char)(*p & ASN_FORM_BITS) >> ASN_FORM_SHIFT; 43398c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen class = (u_char)(*p & ASN_CLASS_BITS) >> ASN_CLASS_SHIFT; 4343f5bedf5cbde2cc2badc86b1a0b377f6efcde71cJakob Stoklund Olesen#endif 43598c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen elem->form = form; 43698c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen elem->class = class; 43798c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen elem->id = id; 43898c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen p++; len--; hdr = 1; 43998c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen /* extended tag field */ 44098c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen if (id == ASN_ID_EXT) { 44198c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen /* 44257f1e2cee06f9b57995727d786aeb1031c5376bdJakob Stoklund Olesen * The ID follows, as a sequence of octets with the 44357f1e2cee06f9b57995727d786aeb1031c5376bdJakob Stoklund Olesen * 8th bit set and the remaining 7 bits being 44457f1e2cee06f9b57995727d786aeb1031c5376bdJakob Stoklund Olesen * the next 7 bits of the value, terminated with 4452710638db2eb84cd7eefb8bb9a1b7e5c49413d45Jakob Stoklund Olesen * an octet with the 8th bit not set. 4462710638db2eb84cd7eefb8bb9a1b7e5c49413d45Jakob Stoklund Olesen * 44798c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen * First, assemble all the octets with the 8th 44898c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen * bit set. XXX - this doesn't handle a value 44998c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen * that won't fit in 32 bits. 45098c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen */ 45198c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen for (id = 0; *p & ASN_BIT8; len--, hdr++, p++) { 45298c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen if (len < 1) { 45398c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen fputs("[Xtagfield?]", stdout); 45498c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen return -1; 45598c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen } 45698c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen TCHECK(*p); 45798c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen id = (id << 7) | (*p & ~ASN_BIT8); 45898c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen } 45998c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen if (len < 1) { 46098c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen fputs("[Xtagfield?]", stdout); 46198c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen return -1; 462b853e6c3702149cdbbd6fa404334e3ba0055641aAndrew Trick } 463b853e6c3702149cdbbd6fa404334e3ba0055641aAndrew Trick TCHECK(*p); 464770d42de3b7643b2b4f835f32e3a16275b9fbdbaJakob Stoklund Olesen elem->id = id = (id << 7) | *p; 465770d42de3b7643b2b4f835f32e3a16275b9fbdbaJakob Stoklund Olesen --len; 466b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen ++hdr; 467b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen ++p; 468b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen } 4691b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen if (len < 1) { 4701b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen fputs("[no asnlen]", stdout); 4711b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen return -1; 4721b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen } 473f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen TCHECK(*p); 474f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen elem->asnlen = *p; 475f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen p++; len--; hdr++; 476db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen if (elem->asnlen & ASN_BIT8) { 477eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen u_int32_t noct = elem->asnlen % ASN_BIT8; 478b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen elem->asnlen = 0; 479db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen if (len < noct) { 48096dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen printf("[asnlen? %d<%d]", len, noct); 481db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen return -1; 482db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen } 48396dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen TCHECK2(*p, noct); 48496dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen for (; noct-- > 0; len--, hdr++) 485f0ac26c51173a9a1d6e5b5794107dccc4c5b5792Jakob Stoklund Olesen elem->asnlen = (elem->asnlen << ASN_SHIFT8) | *p++; 486eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen } 487db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen if (len < elem->asnlen) { 488db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen printf("[len%d<asnlen%u]", len, elem->asnlen); 489b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen return -1; 490eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen } 491eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen if (form >= sizeof(Form)/sizeof(Form[0])) { 492eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen printf("[form?%d]", form); 49396dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen return -1; 49496dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen } 49596dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen if (class >= sizeof(Class)/sizeof(Class[0])) { 49696dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen printf("[class?%c/%d]", *Form[form], class); 497eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen return -1; 4986c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen } 499db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen if ((int)id >= Class[class].numIDs) { 500eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen printf("[id?%c/%s/%d]", *Form[form], Class[class].name, id); 50196dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen return -1; 502eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen } 50396dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen 504a50c539b7a9e74597da34bfaea5429a48481f18bJakob Stoklund Olesen switch (form) { 505b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen case PRIMITIVE: 50696dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen switch (class) { 507eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen case UNIVERSAL: 508612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesen switch (id) { 509db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen case STRING: 510eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen elem->type = BE_STR; 51196dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen elem->data.str = p; 512eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen break; 51396dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen 514b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen case INTEGER: { 515b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen register int32_t data; 51696dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen elem->type = BE_INT; 51796dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen data = 0; 51896dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen 519b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen TCHECK2(*p, elem->asnlen); 520f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen if (*p & ASN_BIT8) /* negative */ 521db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen data = -1; 5221b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen for (i = elem->asnlen; i-- > 0; p++) 5231b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen data = (data << ASN_SHIFT8) | *p; 5241b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen elem->data.integer = data; 525f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen break; 526f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen } 527db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen 528db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen case OBJECTID: 529f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen elem->type = BE_OID; 530f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen elem->data.raw = (caddr_t)p; 531f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen break; 532f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen 5331b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen case ASN_NULL: 5341b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen elem->type = BE_NULL; 535f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen elem->data.raw = NULL; 536f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen break; 537db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen 538f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen default: 539f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen elem->type = BE_OCTET; 5401b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen elem->data.raw = (caddr_t)p; 5411b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen printf("[P/U/%s]", 5427b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen Class[class].Id[id]); 543f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen break; 544f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen } 545f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen break; 546f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen 547f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen case APPLICATION: 548f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen switch (id) { 5497b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen case IPADDR: 5501b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen elem->type = BE_INETADDR; 5511b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen elem->data.raw = (caddr_t)p; 552f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen break; 553f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen 554f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen case COUNTER: 5557b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen case GAUGE: 5567b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen case TIMETICKS: { 5577b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen register u_int32_t data; 5587b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen TCHECK2(*p, elem->asnlen); 5597b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen elem->type = BE_UNS; 5607b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen data = 0; 5617b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen for (i = elem->asnlen; i-- > 0; p++) 5627b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen data = (data << 8) + *p; 5637b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen elem->data.uns = data; 5647b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen break; 5657b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen } 5667b41fbe87234f3ceef6ae11209730cbed4b69092Jakob Stoklund Olesen 5671b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen case COUNTER64: { 5681b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen register u_int32_t high, low; 5691b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen TCHECK2(*p, elem->asnlen); 5701b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen elem->type = BE_UNS64; 5711b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen high = 0, low = 0; 572db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen for (i = elem->asnlen; i-- > 0; p++) { 573db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen high = (high << 8) | 5741b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen ((low & 0xFF000000) >> 24); 5751b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen low = (low << 8) | *p; 576f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen } 577b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen elem->data.uns64.high = high; 578b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen elem->data.uns64.low = low; 5795db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen break; 5805db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen } 5815db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen 5825db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen default: 5835db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen elem->type = BE_OCTET; 5845db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen elem->data.raw = (caddr_t)p; 585f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen printf("[P/A/%s]", 586f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen Class[class].Id[id]); 587f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen break; 5885db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen } 589f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen break; 590f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen 591f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen case CONTEXT: 592f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen switch (id) { 593f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen case NOSUCHOBJECT: 594f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen elem->type = BE_NOSUCHOBJECT; 595f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen elem->data.raw = NULL; 596f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen break; 597f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen 598f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen case NOSUCHINSTANCE: 599f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen elem->type = BE_NOSUCHINST; 600f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen elem->data.raw = NULL; 6015db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen break; 602f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen 6035db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen case ENDOFMIBVIEW: 604f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen elem->type = BE_ENDOFMIBVIEW; 6055db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen elem->data.raw = NULL; 606f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen break; 607f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen } 608f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen break; 609f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen 610f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen default: 611f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen printf("[P/%s/%s]", 6125db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen Class[class].name, Class[class].Id[id]); 6135db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen TCHECK2(*p, elem->asnlen); 6145db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen elem->type = BE_OCTET; 6155db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen elem->data.raw = (caddr_t)p; 6165db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen break; 617f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen } 618f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen break; 619f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen 620f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen case CONSTRUCTED: 621f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen switch (class) { 622f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen case UNIVERSAL: 62396dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen switch (id) { 624200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen case SEQUENCE: 625200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen elem->type = BE_SEQ; 626200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen elem->data.raw = (caddr_t)p; 627200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen break; 628200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen 629200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen default: 630200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen elem->type = BE_OCTET; 631200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen elem->data.raw = (caddr_t)p; 632200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen printf("C/U/%s", Class[class].Id[id]); 633200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen break; 634200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen } 635200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen break; 636200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen 637200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen case CONTEXT: 638200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen elem->type = BE_PDU; 639200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen elem->data.raw = (caddr_t)p; 640200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen break; 641200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen 642200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen default: 643200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen elem->type = BE_OCTET; 644200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen elem->data.raw = (caddr_t)p; 645200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen printf("C/%s/%s", 646200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen Class[class].name, Class[class].Id[id]); 647200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen break; 648200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen } 649200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen break; 650200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen } 651b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen p += elem->asnlen; 652b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen len -= elem->asnlen; 65396dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen return elem->asnlen + hdr; 654b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen 6555db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesentrunc: 6565db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen fputs("[|snmp]", stdout); 657b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen return -1; 6585db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen} 659db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen 660db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen/* 661db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen * Display the ASN.1 object represented by the BE object. 66296dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen * This used to be an integral part of asn1_parse() before the intermediate 663874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesen * BE form was added. 664874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesen */ 665874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesenstatic int 666874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesenasn1_print(struct be *elem) 667db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen{ 668db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen u_char *p = (u_char *)elem->data.raw; 669db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen u_int32_t asnlen = elem->asnlen; 670db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen u_int32_t i; 671874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesen 672874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesen switch (elem->type) { 673b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen 674db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen case BE_OCTET: 6755db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen TCHECK2(*p, asnlen); 6765db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen for (i = asnlen; i-- > 0; p++) 677db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen printf("_%.2x", *p); 678db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen break; 6799a54352879e5aaac2e2c37490e5cb7844550db8bJakob Stoklund Olesen 6809a54352879e5aaac2e2c37490e5cb7844550db8bJakob Stoklund Olesen case BE_NULL: 6819a54352879e5aaac2e2c37490e5cb7844550db8bJakob Stoklund Olesen break; 6829a54352879e5aaac2e2c37490e5cb7844550db8bJakob Stoklund Olesen 6839a54352879e5aaac2e2c37490e5cb7844550db8bJakob Stoklund Olesen case BE_OID: { 6849a54352879e5aaac2e2c37490e5cb7844550db8bJakob Stoklund Olesen int o = 0, first = -1, i = asnlen; 6859a54352879e5aaac2e2c37490e5cb7844550db8bJakob Stoklund Olesen 6869a54352879e5aaac2e2c37490e5cb7844550db8bJakob Stoklund Olesen if (!sflag && !nflag && asnlen > 2) { 6879a54352879e5aaac2e2c37490e5cb7844550db8bJakob Stoklund Olesen struct obj_abrev *a = &obj_abrev_list[0]; 6889a54352879e5aaac2e2c37490e5cb7844550db8bJakob Stoklund Olesen size_t a_len = strlen(a->oid); 6899a54352879e5aaac2e2c37490e5cb7844550db8bJakob Stoklund Olesen for (; a->node; a++) { 690db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen TCHECK2(*p, a_len); 691b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen if (memcmp(a->oid, (char *)p, a_len) == 0) { 692b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen objp = a->node->child; 693b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen i -= strlen(a->oid); 694ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen p += strlen(a->oid); 695ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen fputs(a->prefix, stdout); 696ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen first = 1; 697ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen break; 698ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 699ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 700ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 7015db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen 7025db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen for (; !sflag && i-- > 0; p++) { 703ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen TCHECK(*p); 7045db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8); 7055db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen if (*p & ASN_LONGLEN) 706ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen continue; 7075db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen 708ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen /* 709ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen * first subitem encodes two items with 1st*OIDMUX+2nd 710ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen * (see X.690:1997 clause 8.19 for the details) 711ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen */ 712ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen if (first < 0) { 713ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen int s; 7145db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen if (!nflag) 71592a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen objp = mibroot; 716bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen first = 0; 717ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen s = o / OIDMUX; 718ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen if (s > 2) s = 2; 719fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen OBJ_PRINT(s, first); 720ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen o -= s * OIDMUX; 721ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 722db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen OBJ_PRINT(o, first); 723db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen if (--first < 0) 724db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen first = 0; 725ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen o = 0; 726ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 727ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen break; 728fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen } 729fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen 730fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen case BE_INT: 731fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen printf("%d", elem->data.integer); 732fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen break; 733fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen 734fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen case BE_UNS: 735fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen printf("%u", elem->data.uns); 736ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen break; 737ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen 738ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen case BE_UNS64: { /* idea borrowed from by Marshall Rose */ 739ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen double d; 7406c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen int j, carry; 7416c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen char *cpf, *cpl, last[6], first[30]; 742eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen if (elem->data.uns64.high == 0) { 743ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen printf("%u", elem->data.uns64.low); 7442dfbb3e9125aa0a66feab7a7638815b57da85968Jakob Stoklund Olesen break; 745612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesen } 746612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesen d = elem->data.uns64.high * 4294967296.0; /* 2^32 */ 747612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesen if (elem->data.uns64.high <= 0x1fffff) { 7482dfbb3e9125aa0a66feab7a7638815b57da85968Jakob Stoklund Olesen d += elem->data.uns64.low; 7492dfbb3e9125aa0a66feab7a7638815b57da85968Jakob Stoklund Olesen#if 0 /*is looks illegal, but what is the intention?*/ 7506c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen printf("%.f", d); 751eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen#else 7526c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen printf("%f", d); 75336d61863bc83bd2301e0224adc560098b35ec0dcJakob Stoklund Olesen#endif 754ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen break; 755ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 756eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen d += (elem->data.uns64.low & 0xfffff000); 757ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen#if 0 /*is looks illegal, but what is the intention?*/ 758ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen snprintf(first, sizeof(first), "%.f", d); 759ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen#else 760ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen snprintf(first, sizeof(first), "%f", d); 7616c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen#endif 762ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen snprintf(last, sizeof(last), "%5.5d", 763ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen elem->data.uns64.low & 0xfff); 764ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen for (carry = 0, cpf = first+strlen(first)-1, cpl = last+4; 765ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen cpl >= last; 766ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen cpf--, cpl--) { 767ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen j = carry + (*cpf - '0') + (*cpl - '0'); 7686c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen if (j > 9) { 769ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen j -= 10; 770ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen carry = 1; 771ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } else { 772ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen carry = 0; 773ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 774ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen *cpf = j + '0'; 775ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 776eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen fputs(first, stdout); 777fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen break; 778eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen } 779fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen 780fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen case BE_STR: { 7816c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen register int printable = 1, first = 1; 782fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen const u_char *p = elem->data.str; 783fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen TCHECK2(*p, asnlen); 784fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen for (i = asnlen; printable && i-- > 0; p++) 785612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesen printable = isprint(*p) || isspace(*p); 786eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen p = elem->data.str; 787ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen if (printable) { 788ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen putchar('"'); 789c0de99571297720a37ae405c77fb2ef4aaf00ccdJakob Stoklund Olesen if (fn_printn(p, asnlen, snapend)) { 790fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen putchar('"'); 791eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen goto trunc; 792c0de99571297720a37ae405c77fb2ef4aaf00ccdJakob Stoklund Olesen } 793c0de99571297720a37ae405c77fb2ef4aaf00ccdJakob Stoklund Olesen putchar('"'); 794c0de99571297720a37ae405c77fb2ef4aaf00ccdJakob Stoklund Olesen } else 7958a2bbdeee24b40da6187199658646d04329c139eJakob Stoklund Olesen for (i = asnlen; i-- > 0; p++) { 796612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesen printf(first ? "%.2x" : "_%.2x", *p); 7978a2bbdeee24b40da6187199658646d04329c139eJakob Stoklund Olesen first = 0; 798bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen } 799eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen break; 800612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesen } 8016c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen 8028a2bbdeee24b40da6187199658646d04329c139eJakob Stoklund Olesen case BE_SEQ: 8038a2bbdeee24b40da6187199658646d04329c139eJakob Stoklund Olesen printf("Seq(%u)", elem->asnlen); 804ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen break; 805ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen 806ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen case BE_INETADDR: 807ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen if (asnlen != ASNLEN_INETADDR) 808bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen printf("[inetaddr len!=%d]", ASNLEN_INETADDR); 809eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen TCHECK2(*p, asnlen); 810ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen for (i = asnlen; i-- != 0; p++) { 811ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen printf((i == asnlen-1) ? "%u" : ".%u", *p); 812ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 813db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen break; 814db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen 815ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen case BE_NOSUCHOBJECT: 816ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen case BE_NOSUCHINST: 817ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen case BE_ENDOFMIBVIEW: 818ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen printf("[%s]", Class[EXCEPTIONS].Id[elem->id]); 819ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen break; 820ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen 821ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen case BE_PDU: 822ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen printf("%s(%u)", 8236c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen Class[CONTEXT].Id[elem->id], elem->asnlen); 8246c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen break; 825eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen 826ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen case BE_ANY: 8276c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen fputs("[BE_ANY!?]", stdout); 828612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesen break; 829612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesen 830ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen default: 831ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen fputs("[be!?]", stdout); 832eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen break; 833ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 834ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen return 0; 835ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen 836ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesentrunc: 8376c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen fputs("[|snmp]", stdout); 838ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen return -1; 839ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen} 840ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen 841612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesen#ifdef notdef 842ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen/* 843ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen * This is a brute force ASN.1 printer: recurses to dump an entire structure. 844612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesen * This will work for any ASN.1 stream, not just an SNMP PDU. 8455c716bdccce2fa504e1aa0b67226165d181d2459Jakob Stoklund Olesen * 8466c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen * By adding newlines and spaces at the correct places, this would print in 8475c716bdccce2fa504e1aa0b67226165d181d2459Jakob Stoklund Olesen * Rose-Normal-Form. 8485c716bdccce2fa504e1aa0b67226165d181d2459Jakob Stoklund Olesen * 8495c716bdccce2fa504e1aa0b67226165d181d2459Jakob Stoklund Olesen * This is not currently used. 8505c716bdccce2fa504e1aa0b67226165d181d2459Jakob Stoklund Olesen */ 8515c716bdccce2fa504e1aa0b67226165d181d2459Jakob Stoklund Olesenstatic void 852612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesenasn1_decode(u_char *p, u_int length) 853612f7807c581eafb7c8105e1a55c8d839033bfb3Jakob Stoklund Olesen{ 8546c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen struct be elem; 8555c716bdccce2fa504e1aa0b67226165d181d2459Jakob Stoklund Olesen int i = 0; 8565c716bdccce2fa504e1aa0b67226165d181d2459Jakob Stoklund Olesen 8575c716bdccce2fa504e1aa0b67226165d181d2459Jakob Stoklund Olesen while (i >= 0 && length > 0) { 858bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen i = asn1_parse(p, length, &elem); 859ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen if (i >= 0) { 860ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen fputs(" ", stdout); 861ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen if (asn1_print(&elem) < 0) 862ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen return; 8636c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen if (elem.type == BE_SEQ || elem.type == BE_PDU) { 864ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen fputs(" {", stdout); 865ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen asn1_decode(elem.data.raw, elem.asnlen); 866ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen fputs(" }", stdout); 867ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 868eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen length -= i; 869fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen p += i; 870eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen } 871fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen } 872fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen} 8736c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen#endif 874fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen 875fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen#ifdef LIBSMI 876fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen 877eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesenstruct smi2be { 878ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen SmiBasetype basetype; 879ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen int be; 880c0de99571297720a37ae405c77fb2ef4aaf00ccdJakob Stoklund Olesen}; 881fe3f99f95c7c9ceaac3ceebbea31e40cfbc157e3Jakob Stoklund Olesen 882eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesenstatic struct smi2be smi2betab[] = { 883c0de99571297720a37ae405c77fb2ef4aaf00ccdJakob Stoklund Olesen { SMI_BASETYPE_INTEGER32, BE_INT }, 884c0de99571297720a37ae405c77fb2ef4aaf00ccdJakob Stoklund Olesen { SMI_BASETYPE_OCTETSTRING, BE_STR }, 885c0de99571297720a37ae405c77fb2ef4aaf00ccdJakob Stoklund Olesen { SMI_BASETYPE_OCTETSTRING, BE_INETADDR }, 886bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen { SMI_BASETYPE_OBJECTIDENTIFIER, BE_OID }, 887eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen { SMI_BASETYPE_UNSIGNED32, BE_UNS }, 8886c8afd728eb02742ce320ecd39bcf3774d8423b7Jakob Stoklund Olesen { SMI_BASETYPE_INTEGER64, BE_NONE }, 889ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen { SMI_BASETYPE_UNSIGNED64, BE_UNS64 }, 890ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen { SMI_BASETYPE_FLOAT32, BE_NONE }, 891ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen { SMI_BASETYPE_FLOAT64, BE_NONE }, 892ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen { SMI_BASETYPE_FLOAT128, BE_NONE }, 893ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen { SMI_BASETYPE_ENUM, BE_INT }, 894bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen { SMI_BASETYPE_BITS, BE_STR }, 895eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen { SMI_BASETYPE_UNKNOWN, BE_NONE } 896ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen}; 897ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen 898db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesenstatic int 8995db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesensmi_decode_oid(struct be *elem, unsigned int *oid, 9005db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen unsigned int oidsize, unsigned int *oidlen) 901db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen{ 902db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen u_char *p = (u_char *)elem->data.raw; 903db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen u_int32_t asnlen = elem->asnlen; 904db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen int o = 0, first = -1, i = asnlen; 905db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen 906db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen for (*oidlen = 0; sflag && i-- > 0; p++) { 907db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen TCHECK(*p); 908db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8); 909db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen if (*p & ASN_LONGLEN) 910db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen continue; 911db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen 912db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen /* 913db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen * first subitem encodes two items with 1st*OIDMUX+2nd 914db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen * (see X.690:1997 clause 8.19 for the details) 915db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen */ 916db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen if (first < 0) { 917db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen first = 0; 918db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen if (*oidlen < oidsize) { 9190db841f9c2b9a25fb5ecb36e350d3a802c35654cJakob Stoklund Olesen oid[*oidlen] = o / OIDMUX; 920ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen if (oid[*oidlen] > 2) oid[*oidlen] = 2; 9215928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen } 9225928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen o -= oid[*oidlen] * OIDMUX; 9235928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen if (*oidlen < oidsize) (*oidlen)++; 9249f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen } 9255928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen if (*oidlen < oidsize) { 9265928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen oid[(*oidlen)++] = o; 9275928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen } 9285928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen o = 0; 9295928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen } 9305928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen return 0; 9315928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen 9325928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesentrunc: 9335928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen fputs("[|snmp]", stdout); 9345928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen return -1; 9355928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen} 9365928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen 9375928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesenstatic int smi_check_type(SmiBasetype basetype, int be) 9385928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen{ 9395928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen int i; 9405928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen 9415928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen for (i = 0; smi2betab[i].basetype != SMI_BASETYPE_UNKNOWN; i++) { 9425928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen if (smi2betab[i].basetype == basetype && smi2betab[i].be == be) { 9435928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen return 1; 9445928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen } 9459f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen } 9469f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen 9479f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen return 0; 9489f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen} 9499f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen 9509f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesenstatic int smi_check_a_range(SmiType *smiType, SmiRange *smiRange, 9519f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen struct be *elem) 9529f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen{ 9539f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen int ok = 1; 9549f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen 9559f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen switch (smiType->basetype) { 9569f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen case SMI_BASETYPE_OBJECTIDENTIFIER: 9579f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen case SMI_BASETYPE_OCTETSTRING: 9589f4b893b84d9c2b56aa2abc3c96ce1e5ccc465e5Jakob Stoklund Olesen if (smiRange->minValue.value.unsigned32 9595928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen == smiRange->maxValue.value.unsigned32) { 9605928046306d8bbe7db35707c294689f515f90e56Jakob Stoklund Olesen ok = (elem->asnlen == smiRange->minValue.value.unsigned32); 961eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen } else { 962ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen ok = (elem->asnlen >= smiRange->minValue.value.unsigned32 963ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen && elem->asnlen <= smiRange->maxValue.value.unsigned32); 964ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 965b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen break; 966b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen 967200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen case SMI_BASETYPE_INTEGER32: 968200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen ok = (elem->data.integer >= smiRange->minValue.value.integer32 9695db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen && elem->data.integer <= smiRange->maxValue.value.integer32); 9705db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen break; 97196dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen 972b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen case SMI_BASETYPE_UNSIGNED32: 97396dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen ok = (elem->data.uns >= smiRange->minValue.value.unsigned32 97496dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen && elem->data.uns <= smiRange->maxValue.value.unsigned32); 97596dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen break; 9765db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen 97796dcd95a45968de6cb05864cf91aae33169cf179Jakob Stoklund Olesen case SMI_BASETYPE_UNSIGNED64: 9785db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen /* XXX */ 9791b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen break; 980f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen 981f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen /* case SMI_BASETYPE_INTEGER64: SMIng */ 982f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen /* case SMI_BASETYPE_FLOAT32: SMIng */ 9831b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen /* case SMI_BASETYPE_FLOAT64: SMIng */ 9841b400e840f58489c7950f815780cf08917cecaa8Jakob Stoklund Olesen /* case SMI_BASETYPE_FLOAT128: SMIng */ 985f4afdfc501b7185d24a0ef184fe3d0c0bbe22e0cJakob Stoklund Olesen 986200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen case SMI_BASETYPE_ENUM: 987200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen case SMI_BASETYPE_BITS: 988200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen case SMI_BASETYPE_UNKNOWN: 989200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen ok = 1; 990200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen break; 991200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen 992200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen default: 993200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen ok = 0; 994b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen break; 995874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesen } 9965db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen 997ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen return ok; 9989efa2a263ea470caacef1c85f6ca45e32bf516d3Jakob Stoklund Olesen} 9999efa2a263ea470caacef1c85f6ca45e32bf516d3Jakob Stoklund Olesen 1000ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesenstatic int smi_check_range(SmiType *smiType, struct be *elem) 10015db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen{ 1002874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesen SmiRange *smiRange; 1003ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen int ok = 1; 1004874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesen 1005ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen for (smiRange = smiGetFirstRange(smiType); 10065db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen smiRange; 1007874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesen smiRange = smiGetNextRange(smiRange)) { 1008874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesen 10095db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen ok = smi_check_a_range(smiType, smiRange, elem); 10105db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen 1011874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesen if (ok) { 1012874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesen break; 1013874be74179b087be36a6e7869f3aa8b70732aca1Jakob Stoklund Olesen } 1014200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen } 10155db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen 1016200729882a47535d4c2496283d26600171531fadJakob Stoklund Olesen if (ok) { 1017b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen SmiType *parentType; 1018b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen parentType = smiGetParentType(smiType); 1019ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen if (parentType) { 10205db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen ok = smi_check_range(parentType, elem); 1021ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 1022ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 10235db4289e404d76664f8aabe2675a4cc2d7b0e98eJakob Stoklund Olesen 1024b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen return ok; 1025b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen} 1026b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen 1027ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesenstatic SmiNode *smi_print_variable(struct be *elem, int *status) 1028ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen{ 1029034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen unsigned int oid[128], oidlen; 1030034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen SmiNode *smiNode = NULL; 1031034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen unsigned int i; 1032034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1033034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen *status = smi_decode_oid(elem, oid, sizeof(oid)/sizeof(unsigned int), 1034034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen &oidlen); 1035034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (*status < 0) 1036034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return NULL; 1037034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen smiNode = smiGetNodeByOID(oidlen, oid); 1038034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (! smiNode) { 1039034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen *status = asn1_print(elem); 1040db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen return NULL; 1041db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen } 1042034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (vflag) { 1043034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs(smiGetNodeModule(smiNode)->name, stdout); 1044034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("::", stdout); 1045034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1046034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs(smiNode->name, stdout); 1047034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (smiNode->oidlen < oidlen) { 1048034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen for (i = smiNode->oidlen; i < oidlen; i++) { 1049034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen printf(".%u", oid[i]); 1050034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1051034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1052034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen *status = 0; 1053034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return smiNode; 1054034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen} 1055034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1056034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesenstatic int 1057034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesensmi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem) 1058034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen{ 1059034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen unsigned int i, oid[128], oidlen; 1060034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen SmiType *smiType; 1061034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen SmiNamedNumber *nn; 1062034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen int done = 0; 1063034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1064034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (! smiNode || ! (smiNode->nodekind 1065034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen & (SMI_NODEKIND_SCALAR | SMI_NODEKIND_COLUMN))) { 1066034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return asn1_print(elem); 1067034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1068034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1069034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (elem->type == BE_NOSUCHOBJECT 1070034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen || elem->type == BE_NOSUCHINST 1071034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen || elem->type == BE_ENDOFMIBVIEW) { 1072034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return asn1_print(elem); 1073034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1074034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1075034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (NOTIFY_CLASS(pduid) && smiNode->access < SMI_ACCESS_NOTIFY) { 1076034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("[notNotifyable]", stdout); 1077034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1078034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1079034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (READ_CLASS(pduid) && smiNode->access < SMI_ACCESS_READ_ONLY) { 1080034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("[notReadable]", stdout); 1081034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1082034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1083034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (WRITE_CLASS(pduid) && smiNode->access < SMI_ACCESS_READ_WRITE) { 1084034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("[notWritable]", stdout); 1085034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1086034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1087034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (RESPONSE_CLASS(pduid) 1088034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen && smiNode->access == SMI_ACCESS_NOT_ACCESSIBLE) { 1089034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("[noAccess]", stdout); 1090034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1091034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1092034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen smiType = smiGetNodeType(smiNode); 1093034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (! smiType) { 1094034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return asn1_print(elem); 1095034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1096034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1097034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (! smi_check_type(smiType->basetype, elem->type)) { 1098034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("[wrongType]", stdout); 1099034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1100034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1101034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (! smi_check_range(smiType, elem)) { 1102034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("[outOfRange]", stdout); 1103034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1104034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1105034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen /* resolve bits to named bits */ 1106034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1107034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen /* check whether instance identifier is valid */ 1108034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1109034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen /* apply display hints (integer, octetstring) */ 1110034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1111034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen /* convert instance identifier to index type values */ 1112034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1113034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen switch (elem->type) { 1114034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen case BE_OID: 1115034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (smiType->basetype == SMI_BASETYPE_BITS) { 1116034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen /* print bit labels */ 1117034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } else { 1118034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen smi_decode_oid(elem, oid, 1119034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen sizeof(oid)/sizeof(unsigned int), 1120034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen &oidlen); 1121034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen smiNode = smiGetNodeByOID(oidlen, oid); 1122034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (smiNode) { 1123034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (vflag) { 1124034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs(smiGetNodeModule(smiNode)->name, stdout); 1125034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("::", stdout); 1126034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1127034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs(smiNode->name, stdout); 1128034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (smiNode->oidlen < oidlen) { 1129034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen for (i = smiNode->oidlen; 1130034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen i < oidlen; i++) { 1131034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen printf(".%u", oid[i]); 1132db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen } 1133db529a8a5d071610f3a8b467693bc40b073e68efJakob Stoklund Olesen } 1134034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen done++; 1135034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1136034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1137034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen break; 1138034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1139034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen case BE_INT: 1140034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (smiType->basetype == SMI_BASETYPE_ENUM) { 1141034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen for (nn = smiGetFirstNamedNumber(smiType); 1142034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen nn; 1143034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen nn = smiGetNextNamedNumber(nn)) { 1144034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (nn->value.value.integer32 1145034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen == elem->data.integer) { 1146034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs(nn->name, stdout); 1147034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen printf("(%d)", elem->data.integer); 1148034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen done++; 1149034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen break; 1150034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1151034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1152034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1153034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen break; 1154034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1155034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1156034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (! done) { 1157034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return asn1_print(elem); 1158034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1159034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return 0; 1160034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen} 1161034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen#endif 1162034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 116340a42a2ccaaa19a109667ed7abf224cc8733cd9cJakob Stoklund Olesen/* 1164034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * General SNMP header 1165034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * SEQUENCE { 1166034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * version INTEGER {version-1(0)}, 1167034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * community OCTET STRING, 1168034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * data ANY -- PDUs 1169034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * } 1170034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * PDUs for all but Trap: (see rfc1157 from page 15 on) 1171034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * SEQUENCE { 1172034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * request-id INTEGER, 1173034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * error-status INTEGER, 1174034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * error-index INTEGER, 1175034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * varbindlist SEQUENCE OF 1176034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * SEQUENCE { 1177034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * name ObjectName, 1178034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * value ObjectValue 1179034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * } 1180034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * } 1181034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * PDU for Trap: 1182034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * SEQUENCE { 1183034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * enterprise OBJECT IDENTIFIER, 1184034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * agent-addr NetworkAddress, 1185034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * generic-trap INTEGER, 1186034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * specific-trap INTEGER, 1187034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * time-stamp TimeTicks, 1188034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * varbindlist SEQUENCE OF 1189034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * SEQUENCE { 1190034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * name ObjectName, 1191034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * value ObjectValue 1192034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * } 1193034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * } 1194034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen */ 1195034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1196034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen/* 1197034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * Decode SNMP varBind 1198034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen */ 1199034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesenstatic void 1200034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesenvarbind_print(u_char pduid, const u_char *np, u_int length) 1201034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen{ 1202034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen struct be elem; 1203034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen int count = 0, ind; 1204034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen#ifdef LIBSMI 1205034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen SmiNode *smiNode = NULL; 1206034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen#endif 1207034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen int status; 1208034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1209034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen /* Sequence of varBind */ 1210034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if ((count = asn1_parse(np, length, &elem)) < 0) 1211034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return; 1212034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (elem.type != BE_SEQ) { 1213034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("[!SEQ of varbind]", stdout); 1214034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen asn1_print(&elem); 1215034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return; 1216034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1217034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if ((u_int)count < length) 1218034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen printf("[%d extra after SEQ of varbind]", length - count); 1219034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen /* descend */ 1220034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen length = elem.asnlen; 1221034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen np = (u_char *)elem.data.raw; 1222034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1223034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen for (ind = 1; length > 0; ind++) { 1224034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen const u_char *vbend; 1225034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen u_int vblength; 1226034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1227034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs(" ", stdout); 1228034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1229034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen /* Sequence */ 1230034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if ((count = asn1_parse(np, length, &elem)) < 0) 1231034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return; 1232034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (elem.type != BE_SEQ) { 1233034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("[!varbind]", stdout); 1234034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen asn1_print(&elem); 1235034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return; 1236034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1237034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen vbend = np + count; 1238034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen vblength = length - count; 1239034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen /* descend */ 1240034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen length = elem.asnlen; 1241034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen np = (u_char *)elem.data.raw; 1242034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1243034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen /* objName (OID) */ 1244034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if ((count = asn1_parse(np, length, &elem)) < 0) 1245034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return; 1246034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (elem.type != BE_OID) { 1247034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("[objName!=OID]", stdout); 1248034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen asn1_print(&elem); 1249034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return; 1250034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1251034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen#ifdef LIBSMI 1252034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen smiNode = smi_print_variable(&elem, &status); 1253034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen#else 1254034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen status = asn1_print(&elem); 1255034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen#endif 1256034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (status < 0) 1257034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return; 1258034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen length -= count; 1259034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen np += count; 1260034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1261034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (pduid != GETREQ && pduid != GETNEXTREQ 1262034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen && pduid != GETBULKREQ) 1263034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("=", stdout); 1264034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1265034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen /* objVal (ANY) */ 1266034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if ((count = asn1_parse(np, length, &elem)) < 0) 1267034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return; 1268034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (pduid == GETREQ || pduid == GETNEXTREQ 1269034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen || pduid == GETBULKREQ) { 1270034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (elem.type != BE_NULL) { 1271034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen fputs("[objVal!=NULL]", stdout); 1272034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (asn1_print(&elem) < 0) 1273034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen return; 1274034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } 1275034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen } else { 1276034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if (elem.type != BE_NULL) { 1277034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen#ifdef LIBSMI 1278034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen status = smi_print_value(smiNode, pduid, &elem); 127992a55f4bdd120cdd3bb5a004c792d4d24a940311Jakob Stoklund Olesen#else 1280bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen status = asn1_print(&elem); 1281bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen#endif 1282bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen } 1283bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen if (status < 0) 1284bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen return; 1285bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen } 1286bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen length = vblength; 128722a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen np = vbend; 12880db841f9c2b9a25fb5ecb36e350d3a802c35654cJakob Stoklund Olesen } 1289034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen} 1290034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen 1291034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen/* 1292034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * Decode SNMP PDUs: GetRequest, GetNextRequest, GetResponse, SetRequest, 1293034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen * GetBulk, Inform, V2Trap, and Report 1294ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen */ 1295ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesenstatic void 1296ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesensnmppdu_print(u_short pduid, const u_char *np, u_int length) 1297ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen{ 1298ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen struct be elem; 1299ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen int count = 0, error; 1300ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen 1301ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen /* reqId (Integer) */ 1302034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen if ((count = asn1_parse(np, length, &elem)) < 0) 1303a2ebf60ef2c434428af7f810b13327ab50245a67Jakob Stoklund Olesen return; 1304a2ebf60ef2c434428af7f810b13327ab50245a67Jakob Stoklund Olesen if (elem.type != BE_INT) { 130522a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen fputs("[reqId!=INT]", stdout); 1306034a80d065358b412cdd270e08fb6f1986e65e50Jakob Stoklund Olesen asn1_print(&elem); 1307a2ebf60ef2c434428af7f810b13327ab50245a67Jakob Stoklund Olesen return; 1308a2ebf60ef2c434428af7f810b13327ab50245a67Jakob Stoklund Olesen } 1309a2ebf60ef2c434428af7f810b13327ab50245a67Jakob Stoklund Olesen if (vflag) 1310ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen printf("R=%d ", elem.data.integer); 131122a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen length -= count; 131222a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen np += count; 1313fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen 131422a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen /* errorStatus (Integer) */ 131522a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen if ((count = asn1_parse(np, length, &elem)) < 0) 131622a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen return; 131722a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen if (elem.type != BE_INT) { 1318ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen fputs("[errorStatus!=INT]", stdout); 1319fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen asn1_print(&elem); 1320fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen return; 1321fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen } 1322ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen error = 0; 1323ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen if ((pduid == GETREQ || pduid == GETNEXTREQ || pduid == SETREQ 1324fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen || pduid == INFORMREQ || pduid == V2TRAP || pduid == REPORT) 1325fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen && elem.data.integer != 0) { 1326fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen char errbuf[20]; 1327fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen printf("[errorStatus(%s)!=0]", 1328fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen DECODE_ErrorStatus(elem.data.integer)); 1329fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen } else if (pduid == GETBULKREQ) { 1330fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen printf(" N=%d", elem.data.integer); 1331fd5c51342a429ecab86a645282d0b36b216c0256Jakob Stoklund Olesen } else if (elem.data.integer != 0) { 1332ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen char errbuf[20]; 1333ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen printf(" %s", DECODE_ErrorStatus(elem.data.integer)); 1334ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen error = elem.data.integer; 1335ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen } 1336ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen length -= count; 1337ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen np += count; 1338ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen 1339b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen /* errorIndex (Integer) */ 1340770d42de3b7643b2b4f835f32e3a16275b9fbdbaJakob Stoklund Olesen if ((count = asn1_parse(np, length, &elem)) < 0) 1341770d42de3b7643b2b4f835f32e3a16275b9fbdbaJakob Stoklund Olesen return; 1342770d42de3b7643b2b4f835f32e3a16275b9fbdbaJakob Stoklund Olesen if (elem.type != BE_INT) { 1343770d42de3b7643b2b4f835f32e3a16275b9fbdbaJakob Stoklund Olesen fputs("[errorIndex!=INT]", stdout); 1344ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen asn1_print(&elem); 1345770d42de3b7643b2b4f835f32e3a16275b9fbdbaJakob Stoklund Olesen return; 1346dd479e9769eceee9fcc34e2173376024f3aa3c5fJakob Stoklund Olesen } 13476bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen if ((pduid == GETREQ || pduid == GETNEXTREQ || pduid == SETREQ 13486bfba2e5af163442a1c6b11fe14aa9df9101cfd7Jakob Stoklund Olesen || pduid == INFORMREQ || pduid == V2TRAP || pduid == REPORT) 1349b853e6c3702149cdbbd6fa404334e3ba0055641aAndrew Trick && elem.data.integer != 0) 135098c8141b6d8fcbb9bd258ebcdd4171f55c5a8e9dJakob Stoklund Olesen printf("[errorIndex(%d)!=0]", elem.data.integer); 135146c83c80c5737743c955ff007fa6409804a7abf0Jakob Stoklund Olesen else if (pduid == GETBULKREQ) 1352b853e6c3702149cdbbd6fa404334e3ba0055641aAndrew Trick printf(" M=%d", elem.data.integer); 1353ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen else if (elem.data.integer != 0) { 1354ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen if (!error) 1355107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen printf("[errorIndex(%d) w/o errorStatus]", 1356107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen elem.data.integer); 1357107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen else { 1358eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen printf("@%d", elem.data.integer); 1359f22ca3fe5f0cfbb832cf41270f97cf5c0134fd7bJakob Stoklund Olesen error = elem.data.integer; 1360eb29157d80847c207b77910bcd40a6a6c91ca5c5Jakob Stoklund Olesen } 1361c1655e1a3c3a566b91b0513b56d61b58da1e36baJakob Stoklund Olesen } else if (error) { 1362107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen fputs("[errorIndex==0]", stdout); 1363107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen error = 0; 1364107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen } 1365107d366df762c18294dc00f5de916f62672353ffJakob Stoklund Olesen length -= count; 136622a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen np += count; 136722a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen 136846c83c80c5737743c955ff007fa6409804a7abf0Jakob Stoklund Olesen varbind_print(pduid, np, length); 1369ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen return; 1370ccdb3fcef9aeb9f683cd738afbe1cd961bb0c1efJakob Stoklund Olesen} 1371b64d92e29f38002e52a22fe36ea2d488968e3537Jakob Stoklund Olesen 1372b64d92e29f38002e52a22fe36ea2d488968e3537Jakob Stoklund Olesen/* 1373770d42de3b7643b2b4f835f32e3a16275b9fbdbaJakob Stoklund Olesen * Decode SNMP Trap PDU 1374770d42de3b7643b2b4f835f32e3a16275b9fbdbaJakob Stoklund Olesen */ 137547dbf6cef761c25cfeb0aa7d624a6f98288bb96aJakob Stoklund Olesenstatic void 137647dbf6cef761c25cfeb0aa7d624a6f98288bb96aJakob Stoklund Olesentrappdu_print(const u_char *np, u_int length) 13776094bd87d845afabba5b99ec4848fa6116bac682Jakob Stoklund Olesen{ 1378cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen struct be elem; 1379c46570dc05851395829bef904bb6ddb1260400d1Jakob Stoklund Olesen int count = 0, generic; 1380c46570dc05851395829bef904bb6ddb1260400d1Jakob Stoklund Olesen 1381c46570dc05851395829bef904bb6ddb1260400d1Jakob Stoklund Olesen putchar(' '); 1382cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 1383cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen /* enterprise (oid) */ 1384cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen if ((count = asn1_parse(np, length, &elem)) < 0) 1385cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen return; 1386cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen if (elem.type != BE_OID) { 1387cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen fputs("[enterprise!=OID]", stdout); 1388cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen asn1_print(&elem); 1389cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen return; 1390cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen } 1391cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen if (asn1_print(&elem) < 0) 1392cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen return; 1393af24964251e27c2dd863239ba66ffd967b593be5Jakob Stoklund Olesen length -= count; 139489cab93fe999f6d81b4b99a71ac797b7ecfec277Jakob Stoklund Olesen np += count; 1395af24964251e27c2dd863239ba66ffd967b593be5Jakob Stoklund Olesen 13964680dec5fb3a1b624f13ca9b2a555ca90a07973eJakob Stoklund Olesen putchar(' '); 1397b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen 1398f428eb6c1b09a2322b7a577b0bf2e49dd107bceaJakob Stoklund Olesen /* agent-addr (inetaddr) */ 1399cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen if ((count = asn1_parse(np, length, &elem)) < 0) 1400f6dff84d4e44d6c4a46c4f8a18e13c78f804547cJakob Stoklund Olesen return; 1401d0bb5e2ca05d9c942223bf05e5940bb0c6cc9d3fJakob Stoklund Olesen if (elem.type != BE_INETADDR) { 1402d0bb5e2ca05d9c942223bf05e5940bb0c6cc9d3fJakob Stoklund Olesen fputs("[agent-addr!=INETADDR]", stdout); 1403b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen asn1_print(&elem); 1404b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen return; 1405b5fa9333431673aac2ced8dea80152349a85cf6fJakob Stoklund Olesen } 14061b847deb26b52051de39f4cbecd224c9fbd0d1c2Jakob Stoklund Olesen if (asn1_print(&elem) < 0) 1407bece06f0c6936527e2b1c72d09f7d3a949af9a47Jakob Stoklund Olesen return; 140822a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen length -= count; 140922a1df6bf24c188dd637a0bb2cf9a2648806b6b1Jakob Stoklund Olesen np += count; 1410eda0fe8d58b0aaff5f18e7f13edfda3022384e70Jakob Stoklund Olesen 1411d0bb5e2ca05d9c942223bf05e5940bb0c6cc9d3fJakob Stoklund Olesen /* generic-trap (Integer) */ 1412cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen if ((count = asn1_parse(np, length, &elem)) < 0) 1413cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen return; 14148a61da8a689ee95874c833af4c7aa965fab5c0a9Jakob Stoklund Olesen if (elem.type != BE_INT) { 1415cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen fputs("[generic-trap!=INT]", stdout); 1416cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen asn1_print(&elem); 1417533f58ecdd8a4732c2f0e149387c4d8d8d4142deJakob Stoklund Olesen return; 1418533f58ecdd8a4732c2f0e149387c4d8d8d4142deJakob Stoklund Olesen } 1419ba05c01dabc40373760a20c874103fc58d4377f0Jakob Stoklund Olesen generic = elem.data.integer; 1420533f58ecdd8a4732c2f0e149387c4d8d8d4142deJakob Stoklund Olesen { 1421cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen char buf[20]; 1422cfafc54040cc9722995558124f253d05a038176bJakob Stoklund Olesen printf(" %s", DECODE_GenericTrap(generic)); 1423cfafc54040cc9722995558124f253d05a038176bJakob Stoklund Olesen } 1424cfafc54040cc9722995558124f253d05a038176bJakob Stoklund Olesen length -= count; 1425cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen np += count; 1426cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen 1427cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen /* specific-trap (Integer) */ 1428cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen if ((count = asn1_parse(np, length, &elem)) < 0) 1429cba2e06d525b723849cd8e1f083eb1e59a494b4eJakob Stoklund Olesen return; 1430 if (elem.type != BE_INT) { 1431 fputs("[specific-trap!=INT]", stdout); 1432 asn1_print(&elem); 1433 return; 1434 } 1435 if (generic != GT_ENTERPRISE) { 1436 if (elem.data.integer != 0) 1437 printf("[specific-trap(%d)!=0]", elem.data.integer); 1438 } else 1439 printf(" s=%d", elem.data.integer); 1440 length -= count; 1441 np += count; 1442 1443 putchar(' '); 1444 1445 /* time-stamp (TimeTicks) */ 1446 if ((count = asn1_parse(np, length, &elem)) < 0) 1447 return; 1448 if (elem.type != BE_UNS) { /* XXX */ 1449 fputs("[time-stamp!=TIMETICKS]", stdout); 1450 asn1_print(&elem); 1451 return; 1452 } 1453 if (asn1_print(&elem) < 0) 1454 return; 1455 length -= count; 1456 np += count; 1457 1458 varbind_print (TRAP, np, length); 1459 return; 1460} 1461 1462/* 1463 * Decode arbitrary SNMP PDUs. 1464 */ 1465static void 1466pdu_print(const u_char *np, u_int length, int version) 1467{ 1468 struct be pdu; 1469 int count = 0; 1470 1471 /* PDU (Context) */ 1472 if ((count = asn1_parse(np, length, &pdu)) < 0) 1473 return; 1474 if (pdu.type != BE_PDU) { 1475 fputs("[no PDU]", stdout); 1476 return; 1477 } 1478 if ((u_int)count < length) 1479 printf("[%d extra after PDU]", length - count); 1480 if (vflag) { 1481 fputs("{ ", stdout); 1482 } 1483 if (asn1_print(&pdu) < 0) 1484 return; 1485 fputs(" ", stdout); 1486 /* descend into PDU */ 1487 length = pdu.asnlen; 1488 np = (u_char *)pdu.data.raw; 1489 1490 if (version == SNMP_VERSION_1 && 1491 (pdu.id == GETBULKREQ || pdu.id == INFORMREQ || 1492 pdu.id == V2TRAP || pdu.id == REPORT)) { 1493 printf("[v2 PDU in v1 message]"); 1494 return; 1495 } 1496 1497 if (version == SNMP_VERSION_2 && pdu.id == TRAP) { 1498 printf("[v1 PDU in v2 message]"); 1499 return; 1500 } 1501 1502 switch (pdu.id) { 1503 case TRAP: 1504 trappdu_print(np, length); 1505 break; 1506 case GETREQ: 1507 case GETNEXTREQ: 1508 case GETRESP: 1509 case SETREQ: 1510 case GETBULKREQ: 1511 case INFORMREQ: 1512 case V2TRAP: 1513 case REPORT: 1514 snmppdu_print(pdu.id, np, length); 1515 break; 1516 } 1517 1518 if (vflag) { 1519 fputs(" } ", stdout); 1520 } 1521} 1522 1523/* 1524 * Decode a scoped SNMP PDU. 1525 */ 1526static void 1527scopedpdu_print(const u_char *np, u_int length, int version) 1528{ 1529 struct be elem; 1530 int i, count = 0; 1531 1532 /* Sequence */ 1533 if ((count = asn1_parse(np, length, &elem)) < 0) 1534 return; 1535 if (elem.type != BE_SEQ) { 1536 fputs("[!scoped PDU]", stdout); 1537 asn1_print(&elem); 1538 return; 1539 } 1540 length = elem.asnlen; 1541 np = (u_char *)elem.data.raw; 1542 1543 /* contextEngineID (OCTET STRING) */ 1544 if ((count = asn1_parse(np, length, &elem)) < 0) 1545 return; 1546 if (elem.type != BE_STR) { 1547 fputs("[contextEngineID!=STR]", stdout); 1548 asn1_print(&elem); 1549 return; 1550 } 1551 length -= count; 1552 np += count; 1553 1554 fputs("E= ", stdout); 1555 for (i = 0; i < (int)elem.asnlen; i++) { 1556 printf("0x%02X", elem.data.str[i]); 1557 } 1558 fputs(" ", stdout); 1559 1560 /* contextName (OCTET STRING) */ 1561 if ((count = asn1_parse(np, length, &elem)) < 0) 1562 return; 1563 if (elem.type != BE_STR) { 1564 fputs("[contextName!=STR]", stdout); 1565 asn1_print(&elem); 1566 return; 1567 } 1568 length -= count; 1569 np += count; 1570 1571 printf("C=%.*s ", (int)elem.asnlen, elem.data.str); 1572 1573 pdu_print(np, length, version); 1574} 1575 1576/* 1577 * Decode SNMP Community Header (SNMPv1 and SNMPv2c) 1578 */ 1579static void 1580community_print(const u_char *np, u_int length, int version) 1581{ 1582 struct be elem; 1583 int count = 0; 1584 1585 /* Community (String) */ 1586 if ((count = asn1_parse(np, length, &elem)) < 0) 1587 return; 1588 if (elem.type != BE_STR) { 1589 fputs("[comm!=STR]", stdout); 1590 asn1_print(&elem); 1591 return; 1592 } 1593 /* default community */ 1594 if (!(elem.asnlen == sizeof(DEF_COMMUNITY) - 1 && 1595 strncmp((char *)elem.data.str, DEF_COMMUNITY, 1596 sizeof(DEF_COMMUNITY) - 1) == 0)) 1597 /* ! "public" */ 1598 printf("C=%.*s ", (int)elem.asnlen, elem.data.str); 1599 length -= count; 1600 np += count; 1601 1602 pdu_print(np, length, version); 1603} 1604 1605/* 1606 * Decode SNMPv3 User-based Security Message Header (SNMPv3) 1607 */ 1608static void 1609usm_print(const u_char *np, u_int length) 1610{ 1611 struct be elem; 1612 int count = 0; 1613 1614 /* Sequence */ 1615 if ((count = asn1_parse(np, length, &elem)) < 0) 1616 return; 1617 if (elem.type != BE_SEQ) { 1618 fputs("[!usm]", stdout); 1619 asn1_print(&elem); 1620 return; 1621 } 1622 length = elem.asnlen; 1623 np = (u_char *)elem.data.raw; 1624 1625 /* msgAuthoritativeEngineID (OCTET STRING) */ 1626 if ((count = asn1_parse(np, length, &elem)) < 0) 1627 return; 1628 if (elem.type != BE_STR) { 1629 fputs("[msgAuthoritativeEngineID!=STR]", stdout); 1630 asn1_print(&elem); 1631 return; 1632 } 1633 length -= count; 1634 np += count; 1635 1636 /* msgAuthoritativeEngineBoots (INTEGER) */ 1637 if ((count = asn1_parse(np, length, &elem)) < 0) 1638 return; 1639 if (elem.type != BE_INT) { 1640 fputs("[msgAuthoritativeEngineBoots!=INT]", stdout); 1641 asn1_print(&elem); 1642 return; 1643 } 1644 if (vflag) 1645 printf("B=%d ", elem.data.integer); 1646 length -= count; 1647 np += count; 1648 1649 /* msgAuthoritativeEngineTime (INTEGER) */ 1650 if ((count = asn1_parse(np, length, &elem)) < 0) 1651 return; 1652 if (elem.type != BE_INT) { 1653 fputs("[msgAuthoritativeEngineTime!=INT]", stdout); 1654 asn1_print(&elem); 1655 return; 1656 } 1657 if (vflag) 1658 printf("T=%d ", elem.data.integer); 1659 length -= count; 1660 np += count; 1661 1662 /* msgUserName (OCTET STRING) */ 1663 if ((count = asn1_parse(np, length, &elem)) < 0) 1664 return; 1665 if (elem.type != BE_STR) { 1666 fputs("[msgUserName!=STR]", stdout); 1667 asn1_print(&elem); 1668 return; 1669 } 1670 length -= count; 1671 np += count; 1672 1673 printf("U=%.*s ", (int)elem.asnlen, elem.data.str); 1674 1675 /* msgAuthenticationParameters (OCTET STRING) */ 1676 if ((count = asn1_parse(np, length, &elem)) < 0) 1677 return; 1678 if (elem.type != BE_STR) { 1679 fputs("[msgAuthenticationParameters!=STR]", stdout); 1680 asn1_print(&elem); 1681 return; 1682 } 1683 length -= count; 1684 np += count; 1685 1686 /* msgPrivacyParameters (OCTET STRING) */ 1687 if ((count = asn1_parse(np, length, &elem)) < 0) 1688 return; 1689 if (elem.type != BE_STR) { 1690 fputs("[msgPrivacyParameters!=STR]", stdout); 1691 asn1_print(&elem); 1692 return; 1693 } 1694 length -= count; 1695 np += count; 1696 1697 if ((u_int)count < length) 1698 printf("[%d extra after usm SEQ]", length - count); 1699} 1700 1701/* 1702 * Decode SNMPv3 Message Header (SNMPv3) 1703 */ 1704static void 1705v3msg_print(const u_char *np, u_int length) 1706{ 1707 struct be elem; 1708 int count = 0; 1709 u_char flags; 1710 int model; 1711 const u_char *xnp = np; 1712 int xlength = length; 1713 1714 /* Sequence */ 1715 if ((count = asn1_parse(np, length, &elem)) < 0) 1716 return; 1717 if (elem.type != BE_SEQ) { 1718 fputs("[!message]", stdout); 1719 asn1_print(&elem); 1720 return; 1721 } 1722 length = elem.asnlen; 1723 np = (u_char *)elem.data.raw; 1724 1725 if (vflag) { 1726 fputs("{ ", stdout); 1727 } 1728 1729 /* msgID (INTEGER) */ 1730 if ((count = asn1_parse(np, length, &elem)) < 0) 1731 return; 1732 if (elem.type != BE_INT) { 1733 fputs("[msgID!=INT]", stdout); 1734 asn1_print(&elem); 1735 return; 1736 } 1737 length -= count; 1738 np += count; 1739 1740 /* msgMaxSize (INTEGER) */ 1741 if ((count = asn1_parse(np, length, &elem)) < 0) 1742 return; 1743 if (elem.type != BE_INT) { 1744 fputs("[msgMaxSize!=INT]", stdout); 1745 asn1_print(&elem); 1746 return; 1747 } 1748 length -= count; 1749 np += count; 1750 1751 /* msgFlags (OCTET STRING) */ 1752 if ((count = asn1_parse(np, length, &elem)) < 0) 1753 return; 1754 if (elem.type != BE_STR) { 1755 fputs("[msgFlags!=STR]", stdout); 1756 asn1_print(&elem); 1757 return; 1758 } 1759 if (elem.asnlen != 1) { 1760 printf("[msgFlags size %d]", elem.asnlen); 1761 return; 1762 } 1763 flags = elem.data.str[0]; 1764 if (flags != 0x00 && flags != 0x01 && flags != 0x03 1765 && flags != 0x04 && flags != 0x05 && flags != 0x07) { 1766 printf("[msgFlags=0x%02X]", flags); 1767 return; 1768 } 1769 length -= count; 1770 np += count; 1771 1772 fputs("F=", stdout); 1773 if (flags & 0x01) fputs("a", stdout); 1774 if (flags & 0x02) fputs("p", stdout); 1775 if (flags & 0x04) fputs("r", stdout); 1776 fputs(" ", stdout); 1777 1778 /* msgSecurityModel (INTEGER) */ 1779 if ((count = asn1_parse(np, length, &elem)) < 0) 1780 return; 1781 if (elem.type != BE_INT) { 1782 fputs("[msgSecurityModel!=INT]", stdout); 1783 asn1_print(&elem); 1784 return; 1785 } 1786 model = elem.data.integer; 1787 length -= count; 1788 np += count; 1789 1790 if ((u_int)count < length) 1791 printf("[%d extra after message SEQ]", length - count); 1792 1793 if (vflag) { 1794 fputs("} ", stdout); 1795 } 1796 1797 if (model == 3) { 1798 if (vflag) { 1799 fputs("{ USM ", stdout); 1800 } 1801 } else { 1802 printf("[security model %d]", model); 1803 return; 1804 } 1805 1806 np = xnp + (np - xnp); 1807 length = xlength - (np - xnp); 1808 1809 /* msgSecurityParameters (OCTET STRING) */ 1810 if ((count = asn1_parse(np, length, &elem)) < 0) 1811 return; 1812 if (elem.type != BE_STR) { 1813 fputs("[msgSecurityParameters!=STR]", stdout); 1814 asn1_print(&elem); 1815 return; 1816 } 1817 length -= count; 1818 np += count; 1819 1820 if (model == 3) { 1821 usm_print(elem.data.str, elem.asnlen); 1822 if (vflag) { 1823 fputs("} ", stdout); 1824 } 1825 } 1826 1827 if (vflag) { 1828 fputs("{ ScopedPDU ", stdout); 1829 } 1830 1831 scopedpdu_print(np, length, 3); 1832 1833 if (vflag) { 1834 fputs("} ", stdout); 1835 } 1836} 1837 1838/* 1839 * Decode SNMP header and pass on to PDU printing routines 1840 */ 1841void 1842snmp_print(const u_char *np, u_int length) 1843{ 1844 struct be elem; 1845 int count = 0; 1846 int version = 0; 1847 1848 putchar(' '); 1849 1850 /* initial Sequence */ 1851 if ((count = asn1_parse(np, length, &elem)) < 0) 1852 return; 1853 if (elem.type != BE_SEQ) { 1854 fputs("[!init SEQ]", stdout); 1855 asn1_print(&elem); 1856 return; 1857 } 1858 if ((u_int)count < length) 1859 printf("[%d extra after iSEQ]", length - count); 1860 /* descend */ 1861 length = elem.asnlen; 1862 np = (u_char *)elem.data.raw; 1863 1864 /* Version (INTEGER) */ 1865 if ((count = asn1_parse(np, length, &elem)) < 0) 1866 return; 1867 if (elem.type != BE_INT) { 1868 fputs("[version!=INT]", stdout); 1869 asn1_print(&elem); 1870 return; 1871 } 1872 1873 switch (elem.data.integer) { 1874 case SNMP_VERSION_1: 1875 case SNMP_VERSION_2: 1876 case SNMP_VERSION_3: 1877 if (vflag) 1878 printf("{ %s ", SnmpVersion[elem.data.integer]); 1879 break; 1880 default: 1881 printf("[version = %d]", elem.data.integer); 1882 return; 1883 } 1884 version = elem.data.integer; 1885 length -= count; 1886 np += count; 1887 1888 switch (version) { 1889 case SNMP_VERSION_1: 1890 case SNMP_VERSION_2: 1891 community_print(np, length, version); 1892 break; 1893 case SNMP_VERSION_3: 1894 v3msg_print(np, length); 1895 break; 1896 default: 1897 printf("[version = %d]", elem.data.integer); 1898 break; 1899 } 1900 1901 if (vflag) { 1902 fputs("} ", stdout); 1903 } 1904} 1905