]>
The Tcpdump Group git mirrors - tcpdump/blob - makemib
3 # Copyright (c) 1990, 1996, by John Robert LoVerso.
5 # SMIv2 parsing copyright (c) 1999 by William C. Fenner.
7 # Redistribution and use in source and binary forms are permitted
8 # provided that the above copyright notice and this paragraph are
9 # duplicated in all such forms and that any documentation,
10 # advertising materials, and other materials related to such
11 # distribution and use acknowledge that the software was developed
12 # by John Robert LoVerso.
13 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 # @(#) $Id: makemib,v 1.2 1999-11-21 17:24:15 fenner Exp $ (jlv)
20 # This script will read either ASN.1-style MIB files or the ".defs" files
21 # created by the ISODE "mosy" program on such files.
23 # The output of this script is the "mib.h" file used by tcpdumps' ASN.1/SNMP
26 # This script needs to be run by "gawk" (GNU awk). "nawk" will work, but
27 # dump will get a recursion error if you process LARGE mibs. While it would
28 # by farily easy to rewrite this not to use recursion (and also easy to
29 # eliminate use of gsub and functions to use classic "awk"), you have to
30 # order the structure declarations in defined-first order for the compiler
31 # not to barf; too bad tsort doesn't take arguments.
36 * This file was generated by tcpdump/makemib on `date`
37 * You probably don't want to edit this by hand!
39 * struct mib somename = { desc, oid-octet, type, child-pointer, next-pointer
48 # for sanity, we prep the namespace with objects from RFC-1155
49 # (we manually establish the root)
51 oidadd("org", "iso", 3)
52 oidadd("dod", "org", 6)
53 oidadd("internet", "dod", 1)
54 oidadd("directory", "internet", 1)
55 oidadd("mgmt", "internet", 2)
56 #XXX oidadd("mib", "mgmt", 1)
57 oidadd("mib-2", "mgmt", 1)
58 oidadd("experimental", "internet", 3)
59 oidadd("private", "internet", 4)
60 oidadd("enterprises", "private", 1)
61 oidadd("ip", "mib-2", 4)
62 oidadd("transmission", "mib-2", 10)
68 # Read mosy "*.defs" file. mosy does all the parsing work; we just read
69 # its simple and straightforward output. It would not be too hard to make
70 # tcpdump directly read mosy output, but...
72 # Ignore these unless the current file is called something.defs; false
73 # positives are too common in DESCRIPTIONs.
75 NF > 1 && index($2,".")>0 && FILENAME ~ /\.defs/ {
76 # currently ignore items of the form "{ iso.3.6.1 }"
77 if (split($2, p, ".") == 2) {
78 oidadd($1, p[1], p[2])
85 # Make it easier to parse - used to be done by sed
86 { sub(/--\*.*\*--/, ""); sub(/--.*/, ""); gsub(/[{}]/, " & "); }
89 # this next section is simple and naive, but does the job ok
92 # foo OBJECT IDENTIFIER ::= { baz 17 }
94 # foo OBJECT IDENTIFIER ::=
96 $2$3$4 == "OBJECTIDENTIFIER::=" {
104 $1 == "{" && holddesc != "none" && NF == 4 {
105 oidadd(holddesc, $2, $3)
109 # foo OBJECT IDENTIFIER
111 $2$3 == "OBJECTIDENTIFIER" && $1 != "SYNTAX" && NF == 3 {
116 # OBJECT IDENTIFIER ::= { bar 1 }
117 # a couple of heuristics to exclude single words in e.g. long
118 # DESCRIPTION clauses
119 NF == 1 && $1 ~ "[a-z][a-z]*[A-Z]" && $1 !~ /[(){}.,]/ && holddesc == "none" {
122 $1$2$3 == "OBJECTIDENTIFIER::=" && holddesc != "none" {
123 oidadd(holddesc, $5, $6)
128 # foo OBJECT-TYPE ...
131 $2 == "MODULE-IDENTITY" || $2 == "MODULE-COMPLIANCE" ||
132 $2 == "OBJECT-IDENTITY" || $2 == "OBJECT-TYPE" ||
133 $2 == "OBJECT-GROUP" ||
134 $2 == "NOTIFICATION-TYPE" || $2 == "NOTIFICATION-GROUP" {
137 $1 == "::=" && holddesc != "none" && NF == 5 {
138 oidadd(holddesc, $3, $4)
150 # End of the road - output the data.
156 print "*mibroot = &_iso_obj;"
160 if (file == "" || file == "-")
166 # add a new object to the tree
168 # new OBJECT IDENTIFIER ::= { parent value }
171 function oidadd(new, parent, value) {
173 if (parent == "0" && value == 0)
176 print "/* oidadd" inn(FILENAME) ":", new, "in", parent, "as", value, "line", $0, "*/"
177 # use safe C identifiers
178 gsub(/[-&\/]/,"",new)
179 gsub(/[-&\/]/,"",parent)
180 # check if parent missing
181 if (oid[parent] == "") {
182 printf "/* parse problem%s: no parent for %s.%s(%d) */\n", \
183 inn(FILENAME), parent, new, value
186 # check if parent.value already exists
187 if (oid[new] > 0 && oid[new] != value) {
188 printf "/* parse problem%s: dup %s.%s(%d) != old (%d) */\n", \
189 inn(FILENAME), parent, new, value, oid[new]
192 # check for new name for parent.value
193 if (child[parent] != "") {
194 for (sib = child[parent]; sib != ""; sib = sibling[sib])
195 if (oid[sib] == value) {
197 printf "/* parse problem%s: new name" \
199 " for %s.%s(%d) ignored */\n", \
200 inn(FILENAME), new, parent, \
207 if (child[parent] == "") {
210 sibling[new] = child[parent]
216 # old(?) routine to recurse down the tree (in postfix order for convenience)
219 function dump(item, c, s) {
220 # newitem=sofar"."item"("oid[item]")"
221 # printf "/* %s c=%s s=%s */\n", newitem, child[item], sibling[item]
223 if (child[item] != "") {
225 c = "&_"child[item]"_obj"
228 if (sibling[item] != "") {
230 s = "&_"sibling[item]"_obj"
232 printf "_%s_obj = {\n\t\"%s\", %d, 0,\n\t%s, %s\n},\n", \
233 item, item, oid[item], c, s