Clean up the "have libsmi but no modules loaded" case.

Have asn1_print() print out OIDs regardless of whether we have any
modules loaded or not.

Have smi_decode_oid decode the OID to an array of unsigned ints
regardless of whether we have any modules loaded or not.

Have smi_print_variable() just use asn1_print() to print the OID of a
variable binding if we don't have any modules loaded; in that case,
we're not going to try to look the OID up with libsmi, so we don't need
a decoded version.

Have smi_print_value() not bother decoding the OID or looking the OID up
if we don't have any modules loaded; also, if we *do* have modules
loaded, check whether smi_decode_oid() succeeds.
This commit is contained in:
Guy Harris 2016-10-28 12:26:48 -07:00 committed by Francois-Xavier Le Bail
parent d3a64d8365
commit 67b7b0a0e8

View File

@ -751,51 +751,49 @@ asn1_print(netdissect_options *ndo,
p = (const u_char *)elem->data.raw; p = (const u_char *)elem->data.raw;
i = asnlen; i = asnlen;
if (!nd_smi_module_loaded) { if (!ndo->ndo_nflag && asnlen > 2) {
if (!ndo->ndo_nflag && asnlen > 2) { const struct obj_abrev *a = &obj_abrev_list[0];
const struct obj_abrev *a = &obj_abrev_list[0]; for (; a->node; a++) {
for (; a->node; a++) { if (i < a->oid_len)
if (i < a->oid_len) continue;
continue; if (!ND_TTEST2(*p, a->oid_len))
if (!ND_TTEST2(*p, a->oid_len)) continue;
continue; if (memcmp(a->oid, p, a->oid_len) == 0) {
if (memcmp(a->oid, p, a->oid_len) == 0) { objp = a->node->child;
objp = a->node->child; i -= a->oid_len;
i -= a->oid_len; p += a->oid_len;
p += a->oid_len; ND_PRINT((ndo, "%s", a->prefix));
ND_PRINT((ndo, "%s", a->prefix)); first = 1;
first = 1; break;
break;
}
} }
} }
}
for (; i-- > 0; p++) { for (; i-- > 0; p++) {
ND_TCHECK(*p); ND_TCHECK(*p);
o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8); o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8);
if (*p & ASN_LONGLEN) if (*p & ASN_LONGLEN)
continue; continue;
/* /*
* first subitem encodes two items with * first subitem encodes two items with
* 1st*OIDMUX+2nd * 1st*OIDMUX+2nd
* (see X.690:1997 clause 8.19 for the details) * (see X.690:1997 clause 8.19 for the details)
*/ */
if (first < 0) { if (first < 0) {
int s; int s;
if (!ndo->ndo_nflag) if (!ndo->ndo_nflag)
objp = mibroot; objp = mibroot;
first = 0; first = 0;
s = o / OIDMUX; s = o / OIDMUX;
if (s > 2) s = 2; if (s > 2) s = 2;
OBJ_PRINT(s, first); OBJ_PRINT(s, first);
o -= s * OIDMUX; o -= s * OIDMUX;
}
OBJ_PRINT(o, first);
if (--first < 0)
first = 0;
o = 0;
} }
OBJ_PRINT(o, first);
if (--first < 0)
first = 0;
o = 0;
} }
break; break;
} }
@ -923,31 +921,29 @@ smi_decode_oid(netdissect_options *ndo,
int o = 0, first = -1, i = asnlen; int o = 0, first = -1, i = asnlen;
unsigned int firstval; unsigned int firstval;
if (nd_smi_module_loaded) { for (*oidlen = 0; i-- > 0; p++) {
for (*oidlen = 0; i-- > 0; p++) { ND_TCHECK(*p);
ND_TCHECK(*p); o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8);
o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8); if (*p & ASN_LONGLEN)
if (*p & ASN_LONGLEN) continue;
continue;
/* /*
* first subitem encodes two items with 1st*OIDMUX+2nd * first subitem encodes two items with 1st*OIDMUX+2nd
* (see X.690:1997 clause 8.19 for the details) * (see X.690:1997 clause 8.19 for the details)
*/ */
if (first < 0) { if (first < 0) {
first = 0; first = 0;
firstval = o / OIDMUX; firstval = o / OIDMUX;
if (firstval > 2) firstval = 2; if (firstval > 2) firstval = 2;
o -= firstval * OIDMUX; o -= firstval * OIDMUX;
if (*oidlen < oidsize) {
oid[(*oidlen)++] = firstval;
}
}
if (*oidlen < oidsize) { if (*oidlen < oidsize) {
oid[(*oidlen)++] = o; oid[(*oidlen)++] = firstval;
} }
o = 0;
} }
if (*oidlen < oidsize) {
oid[(*oidlen)++] = o;
}
o = 0;
} }
return 0; return 0;
@ -1054,6 +1050,10 @@ smi_print_variable(netdissect_options *ndo,
SmiNode *smiNode = NULL; SmiNode *smiNode = NULL;
unsigned int i; unsigned int i;
if (!nd_smi_module_loaded) {
*status = asn1_print(ndo, elem);
return NULL;
}
*status = smi_decode_oid(ndo, elem, oid, sizeof(oid) / sizeof(unsigned int), *status = smi_decode_oid(ndo, elem, oid, sizeof(oid) / sizeof(unsigned int),
&oidlen); &oidlen);
if (*status < 0) if (*status < 0)
@ -1139,22 +1139,24 @@ smi_print_value(netdissect_options *ndo,
if (smiType->basetype == SMI_BASETYPE_BITS) { if (smiType->basetype == SMI_BASETYPE_BITS) {
/* print bit labels */ /* print bit labels */
} else { } else {
smi_decode_oid(ndo, elem, oid, if (nd_smi_module_loaded &&
sizeof(oid)/sizeof(unsigned int), smi_decode_oid(ndo, elem, oid,
&oidlen); sizeof(oid)/sizeof(unsigned int),
smiNode = smiGetNodeByOID(oidlen, oid); &oidlen) == 0) {
if (smiNode) { smiNode = smiGetNodeByOID(oidlen, oid);
if (ndo->ndo_vflag) { if (smiNode) {
ND_PRINT((ndo, "%s::", smiGetNodeModule(smiNode)->name)); if (ndo->ndo_vflag) {
} ND_PRINT((ndo, "%s::", smiGetNodeModule(smiNode)->name));
ND_PRINT((ndo, "%s", smiNode->name));
if (smiNode->oidlen < oidlen) {
for (i = smiNode->oidlen;
i < oidlen; i++) {
ND_PRINT((ndo, ".%u", oid[i]));
} }
ND_PRINT((ndo, "%s", smiNode->name));
if (smiNode->oidlen < oidlen) {
for (i = smiNode->oidlen;
i < oidlen; i++) {
ND_PRINT((ndo, ".%u", oid[i]));
}
}
done++;
} }
done++;
} }
} }
break; break;