#!/bin/sh
#
# Copyright (c) 1990, 1996
# John Robert LoVerso. All rights reserved.
# SMIv2 parsing copyright (c) 1999
# William C. Fenner.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notices, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notices, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# This script will read either ASN.1-style MIB files or the ".defs" files
# created by the ISODE "mosy" program on such files.
#
# The output of this script is the "mib.h" file used by tcpdumps' ASN.1/SNMP
# decoding code.
#
# This script needs to be run by "gawk" (GNU awk). "nawk" will work, but
# dump will get a recursion error if you process LARGE mibs. While it would
# by fairly easy to rewrite this not to use recursion (and also easy to
# eliminate use of gsub and functions to use classic "awk"), you have to
# order the structure declarations in defined-first order for the compiler
# not to barf; too bad tsort doesn't take arguments.
#
cat << EOF
/*
* This file was generated by tcpdump/makemib on `date`
* You probably don't want to edit this by hand!
*
* struct mib somename = { desc, oid-octet, type, child-pointer, next-pointer
};
*/
EOF
awk '
BEGIN {
debug=0;
# for sanity, we prep the namespace with objects from RFC-1155
# (we manually establish the root)
oid["iso"]=1
oidadd("org", "iso", 3)
oidadd("dod", "org", 6)
oidadd("internet", "dod", 1)
oidadd("directory", "internet", 1)
oidadd("mgmt", "internet", 2)
#XXX oidadd("mib", "mgmt", 1)
oidadd("mib-2", "mgmt", 1)
oidadd("experimental", "internet", 3)
oidadd("private", "internet", 4)
oidadd("enterprises", "private", 1)
oidadd("ip", "mib-2", 4)
oidadd("transmission", "mib-2", 10)
holddesc="none"
}
#
# Read mosy "*.defs" file. mosy does all the parsing work; we just read
# its simple and straightforward output. It would not be too hard to make
# tcpdump directly read mosy output, but...
#
# Ignore these unless the current file is called something.defs; false
# positives are too common in DESCRIPTIONs.
NF > 1 && index($2,".")>0 && FILENAME ~ /\.defs/ {
# currently ignore items of the form "{ iso.3.6.1 }"
if (split($2, p, ".") == 2) {
oidadd($1, p[1], p[2])
}
next
}
#
# Must be a MIB file
# Make it easier to parse - used to be done by sed
{ sub(/--\*.*\*--/, ""); sub(/--.*/, ""); gsub(/[{}]/, " & "); }
#
# this next section is simple and naive, but does the job ok
#