]>
The Tcpdump Group git mirrors - tcpdump/blob - makemib
3 # Copyright (c) 1990, 1996, by John Robert LoVerso.
6 # Redistribution and use in source and binary forms are permitted
7 # provided that the above copyright notice and this paragraph are
8 # duplicated in all such forms and that any documentation,
9 # advertising materials, and other materials related to such
10 # distribution and use acknowledge that the software was developed
11 # by John Robert LoVerso.
12 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 # @(#) $Id: makemib,v 1.1 1999-10-07 23:47:10 mcr 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
45 # use sed to make the ASN.1 easier to parse
46 # I should really just use a recursive descent parser in awk, but...
50 -e 's/\([{}]\)/ \1 /g' \
54 # for sanity, we prep the namespace with objects from RFC-1155
55 # (we manually establish the root)
57 oidadd("org", "iso", 3)
58 oidadd("dod", "org", 6)
59 oidadd("internet", "dod", 1)
60 oidadd("directory", "internet", 1)
61 oidadd("mgmt", "internet", 2)
62 oidadd("mib", "mgmt", 1)
63 oidadd("experimental", "internet", 3)
64 oidadd("private", "internet", 4)
65 oidadd("enterprises", "private", 1)
71 # Read mosy "*.defs" file. mosy does all the parsing work; we just read
72 # its simple and straightforward output. It would not be too hard to make
73 # tcpdump directly read mosy output, but...
76 NF > 1 && index($2,".")>0 {
77 # currently ignore items of the form "{ iso.3.6.1 }"
78 if (split($2, p, ".") == 2)
79 oidadd($1, p[1], p[2])
84 # this next section is simple and naive, but does the job 100%
87 $2$3$4 == "OBJECTIDENTIFIER::=" {
95 $1 == "::=" && holddesc != "none" && NF == 5 {
96 oidadd(holddesc, $3, $4)
101 # End of the road - output the data.
107 print "*mibroot = &_iso_obj;"
111 # add a new object to the tree
113 # new OBJECT IDENTIFIER ::= { parent value }
116 function oidadd(new, parent, value) {
117 # use safe C identifiers
118 gsub(/[-&\/]/,"",new)
119 gsub(/[-&\/]/,"",parent)
120 # check if parent missing
121 if (oid[parent] == 0) {
122 printf "/* parse problem: no parent for %s.%s(%d) */\n", \
126 # check if parent.value already exists
127 if (oid[new] > 0 && oid[new] != value) {
128 printf "/* parse problem: dup %s.%s(%d) != old (%d) */\n", \
129 parent, new, value, oid[new]
132 # check for new name for parent.value
133 if (child[parent] != "") {
134 for (sib = child[parent]; sib != ""; sib = sibling[sib])
135 if (oid[sib] == value) {
136 printf "/* parse problem: new name \"%s\"" \
137 " for %s.%s(%d) ignored */\n", \
138 new, parent, sib, value
144 if (child[parent] == "") {
147 sibling[new] = child[parent]
153 # old(?) routine to recurse down the tree (in postfix order for convenience)
156 function dump(item, c, s) {
157 # newitem=sofar"."item"("oid[item]")"
158 # printf "/* %s c=%s s=%s */\n", newitem, child[item], sibling[item]
160 if (child[item] != "") {
162 c = "&_"child[item]"_obj"
165 if (sibling[item] != "") {
167 s = "&_"sibling[item]"_obj"
169 printf "_%s_obj = {\n\t\"%s\", %d, 0,\n\t%s, %s\n},\n", \
170 item, item, oid[item], c, s