summaryrefslogtreecommitdiffstats
path: root/contrib/tcpdump/makemib
diff options
context:
space:
mode:
authorfenner <fenner@FreeBSD.org>2000-01-30 00:45:58 +0000
committerfenner <fenner@FreeBSD.org>2000-01-30 00:45:58 +0000
commit54c4a9c9f2aca2e032cbf41f5eb012e2e9628dd4 (patch)
treed25e1fd8c818bfce397a4c7e3f2c66229c814b2a /contrib/tcpdump/makemib
parent0c669098d078c88cf703bade2263846b39e01d83 (diff)
downloadFreeBSD-src-54c4a9c9f2aca2e032cbf41f5eb012e2e9628dd4.zip
FreeBSD-src-54c4a9c9f2aca2e032cbf41f5eb012e2e9628dd4.tar.gz
Virgin import of tcpdump.org tcpdump v3.5
Diffstat (limited to 'contrib/tcpdump/makemib')
-rwxr-xr-xcontrib/tcpdump/makemib111
1 files changed, 87 insertions, 24 deletions
diff --git a/contrib/tcpdump/makemib b/contrib/tcpdump/makemib
index 3ab2d7d..8516263 100755
--- a/contrib/tcpdump/makemib
+++ b/contrib/tcpdump/makemib
@@ -2,6 +2,7 @@
#
# Copyright (c) 1990, 1996, by John Robert LoVerso.
# All rights reserved.
+# SMIv2 parsing copyright (c) 1999 by William C. Fenner.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
@@ -13,8 +14,7 @@
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
-# @(#) $Id: makemib,v 2.1 90/07/10 23:51:54 loverso Exp Locker: loverso $ (jlv
-)
+# @(#) $Id: makemib,v 1.2 1999/11/21 17:24:15 fenner Exp $ (jlv)
#
# This script will read either ASN.1-style MIB files or the ".defs" files
@@ -42,15 +42,9 @@ cat << EOF
EOF
-# use sed to make the ASN.1 easier to parse
-# I should really just use a recursive descent parser in awk, but...
-sed \
- -e 's/--\*.*\*--//' \
- -e 's/--.*//' \
- -e 's/\([{}]\)/ \1 /g' \
- $@ \
-| gawk '
+awk '
BEGIN {
+ debug=0;
# for sanity, we prep the namespace with objects from RFC-1155
# (we manually establish the root)
oid["iso"]=1
@@ -59,10 +53,13 @@ BEGIN {
oidadd("internet", "dod", 1)
oidadd("directory", "internet", 1)
oidadd("mgmt", "internet", 2)
- oidadd("mib", "mgmt", 1)
+#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"
}
@@ -72,30 +69,82 @@ BEGIN {
# 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 {
+NF > 1 && index($2,".")>0 && FILENAME ~ /\.defs/ {
# currently ignore items of the form "{ iso.3.6.1 }"
- if (split($2, p, ".") == 2)
+ if (split($2, p, ".") == 2) {
oidadd($1, p[1], p[2])
+ }
next
}
#
-# this next section is simple and naive, but does the job 100%
+# 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
#
+# foo OBJECT IDENTIFIER ::= { baz 17 }
+# or
+# foo OBJECT IDENTIFIER ::=
+# { baz 17 }
$2$3$4 == "OBJECTIDENTIFIER::=" {
holddesc="none"
if (NF == 8)
oidadd($1, $6, $7)
+ if (NF == 4)
+ holddesc=$1
+ next
+}
+$1 == "{" && holddesc != "none" && NF == 4 {
+ oidadd(holddesc, $2, $3)
+ holddesc="none"
+}
+#
+# foo OBJECT IDENTIFIER
+# ::= { bar 1 }
+$2$3 == "OBJECTIDENTIFIER" && $1 != "SYNTAX" && NF == 3 {
+ holddesc=$1
+}
+#
+# foo
+# OBJECT IDENTIFIER ::= { bar 1 }
+# a couple of heuristics to exclude single words in e.g. long
+# DESCRIPTION clauses
+NF == 1 && $1 ~ "[a-z][a-z]*[A-Z]" && $1 !~ /[(){}.,]/ && holddesc == "none" {
+ holddesc=$1
+}
+$1$2$3 == "OBJECTIDENTIFIER::=" && holddesc != "none" {
+ oidadd(holddesc, $5, $6)
+ holddesc="none"
}
-$2 == "OBJECT-TYPE" {
+#
+# "normal" style
+# foo OBJECT-TYPE ...
+# ...
+# ::= { baz 5 }
+$2 == "MODULE-IDENTITY" || $2 == "MODULE-COMPLIANCE" ||
+ $2 == "OBJECT-IDENTITY" || $2 == "OBJECT-TYPE" ||
+ $2 == "OBJECT-GROUP" ||
+ $2 == "NOTIFICATION-TYPE" || $2 == "NOTIFICATION-GROUP" {
holddesc=$1
}
$1 == "::=" && holddesc != "none" && NF == 5 {
oidadd(holddesc, $3, $4)
holddesc="none"
}
+#
+# foo ::= { baz 17 }
+$2$3 == "::={" {
+ oidadd($1,$4,$5)
+ holddesc="none"
+}
+
#
# End of the road - output the data.
@@ -107,6 +156,12 @@ END {
print "*mibroot = &_iso_obj;"
}
+function inn(file) {
+ if (file == "" || file == "-")
+ return ""
+ return " in " file
+}
+
#
# add a new object to the tree
#
@@ -114,28 +169,36 @@ END {
#
function oidadd(new, parent, value) {
+ # Ignore 0.0
+ if (parent == "0" && value == 0)
+ return
+ if (debug)
+ print "/* oidadd" inn(FILENAME) ":", new, "in", parent, "as", value, "line", $0, "*/"
# use safe C identifiers
gsub(/[-&\/]/,"",new)
gsub(/[-&\/]/,"",parent)
# check if parent missing
- if (oid[parent] == 0) {
- printf "/* parse problem: no parent for %s.%s(%d) */\n", \
- parent, new, value
+ if (oid[parent] == "") {
+ printf "/* parse problem%s: no parent for %s.%s(%d) */\n", \
+ inn(FILENAME), parent, new, value
return
}
# check if parent.value already exists
if (oid[new] > 0 && oid[new] != value) {
- printf "/* parse problem: dup %s.%s(%d) != old (%d) */\n", \
- parent, new, value, oid[new]
+ printf "/* parse problem%s: dup %s.%s(%d) != old (%d) */\n", \
+ inn(FILENAME), parent, new, value, oid[new]
return
}
# check for new name for parent.value
if (child[parent] != "") {
for (sib = child[parent]; sib != ""; sib = sibling[sib])
if (oid[sib] == value) {
- printf "/* parse problem: new name \"%s\"" \
- " for %s.%s(%d) ignored */\n", \
- new, parent, sib, value
+ if (new != sib)
+ printf "/* parse problem%s: new name" \
+ " \"%s\"" \
+ " for %s.%s(%d) ignored */\n", \
+ inn(FILENAME), new, parent, \
+ sib, value
return
}
}
@@ -169,5 +232,5 @@ function dump(item, c, s) {
printf "_%s_obj = {\n\t\"%s\", %d, 0,\n\t%s, %s\n},\n", \
item, item, oid[item], c, s
}
-'
+' $@
exit 0
OpenPOWER on IntegriCloud