diff options
Diffstat (limited to 'usr/src')
| -rw-r--r-- | usr/src/cmd/picl/plugins/sun4v/lib/snmp/Makefile | 15 | ||||
| -rw-r--r-- | usr/src/cmd/picl/plugins/sun4v/lib/snmp/asn1.c | 34 | ||||
| -rw-r--r-- | usr/src/cmd/picl/plugins/sun4v/lib/snmp/debug.c | 616 | ||||
| -rw-r--r-- | usr/src/cmd/picl/plugins/sun4v/lib/snmp/debug.h | 144 | ||||
| -rw-r--r-- | usr/src/cmd/picl/plugins/sun4v/lib/snmp/pdu.c | 8 | ||||
| -rw-r--r-- | usr/src/cmd/picl/plugins/sun4v/lib/snmp/snmplib.c | 63 |
6 files changed, 14 insertions, 866 deletions
diff --git a/usr/src/cmd/picl/plugins/sun4v/lib/snmp/Makefile b/usr/src/cmd/picl/plugins/sun4v/lib/snmp/Makefile index 5f57855e9b..8b8703a66a 100644 --- a/usr/src/cmd/picl/plugins/sun4v/lib/snmp/Makefile +++ b/usr/src/cmd/picl/plugins/sun4v/lib/snmp/Makefile @@ -23,6 +23,8 @@ # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # +# Copyright 2019 Peter Tribble. +# # # cmd/picl/plugins/sun4v/lib/snmp/Makefile @@ -30,7 +32,7 @@ LIBRARY= libpiclsnmp.a VERS= .1 -OBJECTS= snmplib.o pdu.o asn1.o debug.o +OBJECTS= snmplib.o pdu.o asn1.o # include library definitions include $(SRC)/Makefile.psm @@ -53,12 +55,6 @@ CPPFLAGS += -I. -I../../include -I$(SRC)/uts/sun4v CPPFLAGS += -D_REENTRANT # -# Be careful when enabling SNMP_DEBUG; the debug log can quickly grow -# very very large. Never run cycle stress test with SNMP_DEBUG enabled! -# -#CPPFLAGS += -DSNMP_DEBUG - -# # Do NOT uncomment the following two lines, unless you want to test # the behavior of the library with an SNMP agent over network. # @@ -68,11 +64,6 @@ CPPFLAGS += -D_REENTRANT CFLAGS += $(CCVERBOSE) -DBIG_ENDIAN LDLIBS += -lc -lnvpair -# It's OK not to build debug.c except when SNMP_DEBUG is enabled. -# Don't let lint complain about it. -# -ALWAYS_LINT_DEFS += -erroff=E_EMPTY_TRANSLATION_UNIT - .KEEP_STATE: diff --git a/usr/src/cmd/picl/plugins/sun4v/lib/snmp/asn1.c b/usr/src/cmd/picl/plugins/sun4v/lib/snmp/asn1.c index 4de8545981..3211495239 100644 --- a/usr/src/cmd/picl/plugins/sun4v/lib/snmp/asn1.c +++ b/usr/src/cmd/picl/plugins/sun4v/lib/snmp/asn1.c @@ -22,10 +22,9 @@ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright 2019 Peter Tribble. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * ASN.1 encoding related routines */ @@ -36,7 +35,6 @@ #include <sys/types.h> #include "asn1.h" #include "pdu.h" -#include "debug.h" /* * This routine builds a 'SEQUENCE OF' ASN.1 object in the buffer @@ -61,8 +59,6 @@ asn_build_sequence(uchar_t *buf, size_t *bufsz_p, uchar_t id, size_t length) if (bufsz_p) *bufsz_p -= 4; - LOGASNSEQ(buf, 4); - return (buf + 4); } @@ -91,8 +87,6 @@ asn_build_length(uchar_t *buf, size_t *bufsz_p, size_t length) buf[0] = (uchar_t)length; (*bufsz_p)--; - LOGASNLENGTH(buf, 1); - return (buf + 1); } else if (length <= 0xFF) { @@ -102,8 +96,6 @@ asn_build_length(uchar_t *buf, size_t *bufsz_p, size_t length) buf[1] = (uchar_t)length; *bufsz_p -= 2; - LOGASNLENGTH(buf, 2); - return (buf + 2); } else { @@ -115,8 +107,6 @@ asn_build_length(uchar_t *buf, size_t *bufsz_p, size_t length) buf[2] = (uchar_t)(length & 0xff); *bufsz_p -= 3; - LOGASNLENGTH(buf, 3); - return (buf + 3); } } @@ -171,8 +161,6 @@ asn_build_int(uchar_t *buf, size_t *bufsz_p, uchar_t id, int val) *bufsz_p -= valsz; - LOGASNINT(buf, p + valsz - buf); - return (p + valsz); } } @@ -192,17 +180,15 @@ asn_build_string(uchar_t *buf, size_t *bufsz_p, uchar_t id, uchar_t *str, if (*bufsz_p < slen) return (NULL); else { - if (str) { - (void) memcpy(p, str, slen); - } else { - (void) memset(p, 0, slen); - } - - *bufsz_p -= slen; + if (str) { + (void) memcpy(p, str, slen); + } else { + (void) memset(p, 0, slen); + } - LOGASNOCTSTR(buf, p + slen - buf); + *bufsz_p -= slen; - return (p + slen); + return (p + slen); } } @@ -318,8 +304,6 @@ asn_build_objid(uchar_t *buf, size_t *bufsz_p, uchar_t id, void *oidp, *bufsz_p -= oid_asnlen; - LOGASNOID(buf, p - buf); - return (p); } /* @@ -332,8 +316,6 @@ asn_build_null(uchar_t *buf, size_t *bufsz_p, uchar_t id) p = asn_build_header(buf, bufsz_p, id, 0); - LOGASNNULL(buf, p - buf); - return (p); } diff --git a/usr/src/cmd/picl/plugins/sun4v/lib/snmp/debug.c b/usr/src/cmd/picl/plugins/sun4v/lib/snmp/debug.c deleted file mode 100644 index 3a52599a63..0000000000 --- a/usr/src/cmd/picl/plugins/sun4v/lib/snmp/debug.c +++ /dev/null @@ -1,616 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef SNMP_DEBUG - -/* - * Debug routines - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <thread.h> -#include <synch.h> -#include <ctype.h> -#include <sys/types.h> -#include "asn1.h" -#include "pdu.h" -#include "snmplib.h" -#include "debug.h" - -/* - * Buffer and line limits - */ -#define SNMP_DBLOCK_SZ 4096 -#define SNMP_DMAX_LINE 80 -#define SNMP_NCHARS_IN_A_ROW 16 - -/* - * Debug flags - */ -#define SNMP_DEBUG_CMD 0x01 -#define SNMP_DEBUG_VAR 0x02 -#define SNMP_DEBUG_PDU 0x04 -#define SNMP_DEBUG_ASN 0x08 -#define SNMP_DEBUG_PKT 0x10 -#define SNMP_DEBUG_IO 0x20 - -#define SNMP_DEBUG_DEFAULT 0x15 /* cmd, pdu, pkt */ -#define SNMP_DEBUG_EXTENDED 0x35 /* cmd, pdu, pkt, io */ -#define SNMP_DEBUG_ALL 0x3f - -/* - * Formatting aids - */ -#define SNMP_DCMD_INDENT 2 -#define SNMP_DVAR_INDENT 4 -#define SNMP_DPDU_INDENT 6 -#define SNMP_DASN_INDENT 8 -#define SNMP_DPKT_INDENT 10 -#define SNMP_DIO_INDENT 12 - -#define SNMP_DHDR_PREFIX (const char *)" ___ " -#define SNMP_DHDR_SUFFIX (const char *)" ___" -#define SNMP_DTEXT_PREFIX (const char *)"| " - -/* - * All debug vars are protected by a single lock - */ -static mutex_t snmp_dbuf_lock; /* debug lock */ -static uint16_t snmp_debug_flag = SNMP_DEBUG_EXTENDED; /* debug flags */ -static char *snmp_dbuf = NULL; /* the debug buffer */ -static char *snmp_dbuf_curp = NULL; /* current dbuf index */ -static char *snmp_dbuf_tail = NULL; /* current dbuf tail */ -static int snmp_dbuf_sz = 0; /* current dbuf size */ -static int snmp_dbuf_overflow = 0; /* no more memory */ -static char snmp_lbuf[SNMP_DMAX_LINE]; /* scratch space */ - -/* - * Key-to-string - */ -typedef struct { - int key; - char *str; -} snmp_key_to_str_t; - -static snmp_key_to_str_t snmp_cmds[] = { - { SNMP_MSG_GET, "SNMP_MSG_GET" }, - { SNMP_MSG_GETNEXT, "SNMP_MSG_GETNEXT" }, - { SNMP_MSG_RESPONSE, "SNMP_MSG_RESPONSE" }, - { SNMP_MSG_SET, "SNMP_MSG_SET" }, - { SNMP_MSG_TRAP, "SNMP_MSG_TRAP" }, - { SNMP_MSG_GETBULK, "SNMP_MSG_GETBULK" }, - { SNMP_MSG_INFORM, "SNMP_MSG_INFORM" }, - { SNMP_MSG_TRAP2, "SNMP_MSG_TRAP2" }, - { SNMP_MSG_REPORT, "SNMP_MSG_REPORT" } -}; - -static snmp_key_to_str_t snmp_vartypes[] = { - { ASN_BOOLEAN, "ASN_BOOLEAN" }, - { ASN_INTEGER, "ASN_INTEGER" }, - { ASN_BIT_STR, "ASN_BIT_STR" }, - { ASN_OCTET_STR, "ASN_OCTET_STR" }, - { ASN_NULL, "ASN_NULL" }, - { ASN_OBJECT_ID, "ASN_OBJECT_ID" }, - { ASN_SEQUENCE, "ASN_SEQUENCE" } -}; - -static snmp_key_to_str_t snmp_asnencodings[] = { - { SNMP_DASN_SEQUENCE, "ASN SEQUENCE" }, - { SNMP_DASN_LENGTH, "ASN LENGTH" }, - { SNMP_DASN_INT, "ASN INT" }, - { SNMP_DASN_OCTET_STR, "ASN OCTET STR" }, - { SNMP_DASN_OID, "ASN OBJECT ID" }, - { SNMP_DASN_NULL, "ASN NULL" } -}; - -static char *debug_tags[] = { - "SNMP Command Request", - "Null Var", - "Response Var", - "Request PDU", - "Response PDU", - "Request Packet", - "Response Packet", - "WRITE", - "IOCTL", - "READ", - "SENDTO", - "RECVFROM" -}; -static const int n_tags = sizeof (debug_tags) / sizeof (char *); - -/* - * Helpers - */ -static char *snmp_cmdstr_lookup(int cmd); -static char *snmp_vtypestr_lookup(int vtype); -static char *snmp_asnencoding_lookup(int asnkey); -static void snmp_get_dumpchars(uchar_t *abuf, uchar_t *p, int nchars); -static void snmp_log_append(char *bufp); -static void snmp_dbuf_realloc(void); - -void -snmp_debug_init(void) -{ - (void) mutex_init(&snmp_dbuf_lock, USYNC_THREAD, NULL); - - (void) mutex_lock(&snmp_dbuf_lock); - snmp_dbuf_realloc(); - if (snmp_dbuf == NULL) - snmp_debug_flag = 0; /* really tragic */ - (void) mutex_unlock(&snmp_dbuf_lock); -} - -void -snmp_log_cmd(uint_t tag, int cmd, int n_oids, char *oidstr, int row) -{ - char *cmdstr; - int i; - - if (oidstr == NULL) - return; - - (void) mutex_lock(&snmp_dbuf_lock); - - if ((snmp_debug_flag & SNMP_DEBUG_CMD) == 0) { - (void) mutex_unlock(&snmp_dbuf_lock); - return; - } - - snmp_log_append("\n"); - - if (tag < n_tags) { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%s%s%s\n", - SNMP_DCMD_INDENT, ' ', SNMP_DHDR_PREFIX, - debug_tags[tag], SNMP_DHDR_SUFFIX); - snmp_log_append(snmp_lbuf); - } - - if ((cmdstr = snmp_cmdstr_lookup(cmd)) == NULL) { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%sCMD=%#x\n", - SNMP_DCMD_INDENT, ' ', SNMP_DTEXT_PREFIX, cmd); - } else { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%s%s\n", - SNMP_DCMD_INDENT, ' ', SNMP_DTEXT_PREFIX, cmdstr); - } - snmp_log_append(snmp_lbuf); - - for (i = 0; i < n_oids; i++) { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%s %s.%d\n", - SNMP_DCMD_INDENT, ' ', SNMP_DTEXT_PREFIX, - oidstr, row); - snmp_log_append(snmp_lbuf); - - oidstr += strlen(oidstr) + 1; - } - - (void) mutex_unlock(&snmp_dbuf_lock); -} - -void -snmp_log_var(uint_t tag, pdu_varlist_t *vp) -{ - char *vts; - - if (vp == NULL) - return; - - (void) mutex_lock(&snmp_dbuf_lock); - - if ((snmp_debug_flag & SNMP_DEBUG_VAR) == 0) { - (void) mutex_unlock(&snmp_dbuf_lock); - return; - } - - snmp_log_append("\n"); - - if (tag < n_tags) { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%s%s%s\n", - SNMP_DVAR_INDENT, ' ', SNMP_DHDR_PREFIX, - debug_tags[tag], SNMP_DHDR_SUFFIX); - snmp_log_append(snmp_lbuf); - } - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%snextvar = %#x\n", - SNMP_DVAR_INDENT, ' ', SNMP_DTEXT_PREFIX, vp->nextvar); - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%sname = %#x\n", - SNMP_DVAR_INDENT, ' ', SNMP_DTEXT_PREFIX, vp->name); - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%sname_len = %u\n", - SNMP_DVAR_INDENT, ' ', SNMP_DTEXT_PREFIX, vp->name_len); - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%sval.ptr = %#x\n", - SNMP_DVAR_INDENT, ' ', SNMP_DTEXT_PREFIX, vp->val.str); - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%sval_len = %u\n", - SNMP_DVAR_INDENT, ' ', SNMP_DTEXT_PREFIX, vp->val_len); - snmp_log_append(snmp_lbuf); - - if ((vts = snmp_vtypestr_lookup(vp->type)) == NULL) { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%stype = %#x\n", - SNMP_DVAR_INDENT, ' ', SNMP_DTEXT_PREFIX, vp->type); - } else { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%stype = %s\n", - SNMP_DVAR_INDENT, ' ', SNMP_DTEXT_PREFIX, vts); - } - snmp_log_append(snmp_lbuf); - - (void) mutex_unlock(&snmp_dbuf_lock); -} - -void -snmp_log_pdu(uint_t tag, snmp_pdu_t *pdu) -{ - char *cmdstr; - - if (pdu == NULL) - return; - - (void) mutex_lock(&snmp_dbuf_lock); - - if ((snmp_debug_flag & SNMP_DEBUG_PDU) == 0) { - (void) mutex_unlock(&snmp_dbuf_lock); - return; - } - - snmp_log_append("\n"); - - if (tag < n_tags) { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%s%s%s\n", - SNMP_DPDU_INDENT, ' ', SNMP_DHDR_PREFIX, - debug_tags[tag], SNMP_DHDR_SUFFIX); - snmp_log_append(snmp_lbuf); - } - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%sversion = %d\n", - SNMP_DPDU_INDENT, ' ', SNMP_DTEXT_PREFIX, pdu->version); - snmp_log_append(snmp_lbuf); - - if (pdu->community) { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, - "%*c%scommunity = %s\n", SNMP_DPDU_INDENT, ' ', - SNMP_DTEXT_PREFIX, pdu->community); - } else { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, - "%*c%scommunity = %#x\n", SNMP_DPDU_INDENT, ' ', - SNMP_DTEXT_PREFIX, pdu->community); - } - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%scommunity_len = %u\n", - SNMP_DPDU_INDENT, ' ', SNMP_DTEXT_PREFIX, pdu->community_len); - snmp_log_append(snmp_lbuf); - - if ((cmdstr = snmp_cmdstr_lookup(pdu->command)) == NULL) { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, - "%*c%scommand = %#x\n", SNMP_DPDU_INDENT, ' ', - SNMP_DTEXT_PREFIX, pdu->command); - } else { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, - "%*c%scommand = %s\n", SNMP_DPDU_INDENT, ' ', - SNMP_DTEXT_PREFIX, cmdstr); - } - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%sreqid = %d\n", - SNMP_DPDU_INDENT, ' ', SNMP_DTEXT_PREFIX, pdu->reqid); - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, - "%*c%serrstat = %#x (non-repeaters)\n", SNMP_DPDU_INDENT, ' ', - SNMP_DTEXT_PREFIX, pdu->errstat); - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, - "%*c%serrindex = %u (max-reps)\n", SNMP_DPDU_INDENT, ' ', - SNMP_DTEXT_PREFIX, pdu->errindex); - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%svars = %#x\n", - SNMP_DPDU_INDENT, ' ', SNMP_DTEXT_PREFIX, pdu->vars); - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%sreq_pkt = %#x\n", - SNMP_DPDU_INDENT, ' ', SNMP_DTEXT_PREFIX, pdu->req_pkt); - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%sreq_pktsz = %u\n", - SNMP_DPDU_INDENT, ' ', SNMP_DTEXT_PREFIX, pdu->req_pktsz); - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%sreply_pkt = %#x\n", - SNMP_DPDU_INDENT, ' ', SNMP_DTEXT_PREFIX, pdu->reply_pkt); - snmp_log_append(snmp_lbuf); - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%sreply_pktsz = %u\n", - SNMP_DPDU_INDENT, ' ', SNMP_DTEXT_PREFIX, pdu->reply_pktsz); - snmp_log_append(snmp_lbuf); - - snmp_log_append("\n"); - - (void) mutex_unlock(&snmp_dbuf_lock); -} - -void -snmp_log_asn(int key, uchar_t *pkt, size_t pktsz) -{ - char *p, *asnstr; - int i, len; - size_t nrows, nrem; - - if (pkt == NULL) - return; - - (void) mutex_lock(&snmp_dbuf_lock); - - if ((snmp_debug_flag & SNMP_DEBUG_ASN) == 0) { - (void) mutex_unlock(&snmp_dbuf_lock); - return; - } - - if ((asnstr = snmp_asnencoding_lookup(key)) == NULL) { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%sASNKEY=%#x\n", - SNMP_DASN_INDENT, ' ', SNMP_DTEXT_PREFIX, key); - } else { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%s%s\n", - SNMP_DASN_INDENT, ' ', SNMP_DTEXT_PREFIX, asnstr); - } - snmp_log_append(snmp_lbuf); - - nrows = pktsz / 16; - for (i = 0; i < nrows; i++) { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%s " - "%02x %02x %02x %02x %02x %02x %02x %02x " - "%02x %02x %02x %02x %02x %02x %02x %02x\n", - SNMP_DASN_INDENT, ' ', SNMP_DTEXT_PREFIX, - pkt[0], pkt[1], pkt[2], pkt[3], pkt[4], pkt[5], - pkt[6], pkt[7], pkt[8], pkt[9], pkt[10], pkt[11], - pkt[12], pkt[13], pkt[14], pkt[15]); - - pkt += 16; - snmp_log_append(snmp_lbuf); - } - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%s ", - SNMP_DASN_INDENT, ' ', SNMP_DTEXT_PREFIX); - - p = snmp_lbuf + SNMP_DASN_INDENT + strlen(SNMP_DTEXT_PREFIX) + 1; - len = SNMP_DMAX_LINE - SNMP_DASN_INDENT - strlen(SNMP_DTEXT_PREFIX) - 1; - - nrem = pktsz % 16; - for (i = 0; i < nrem; i++) { - (void) snprintf(p, len, " %02x", pkt[i]); - - p += 3; - len -= 3; - } - (void) snprintf(p, len, "\n"); - snmp_log_append(snmp_lbuf); - - (void) mutex_unlock(&snmp_dbuf_lock); -} - -void -snmp_log_pkt(uint_t tag, uchar_t *pkt, size_t pktsz) -{ - uchar_t ascii[SNMP_NCHARS_IN_A_ROW + 1]; - uchar_t *p = pkt; - char *bufp; - int nrows, nrem; - int i, len; - - if (pkt == NULL) - return; - - (void) mutex_lock(&snmp_dbuf_lock); - - if ((snmp_debug_flag & SNMP_DEBUG_PKT) == 0) { - (void) mutex_unlock(&snmp_dbuf_lock); - return; - } - - snmp_log_append("\n"); - - if (tag < n_tags) { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%s%s%s\n", - SNMP_DPKT_INDENT, ' ', - SNMP_DHDR_PREFIX, debug_tags[tag], SNMP_DHDR_SUFFIX); - snmp_log_append(snmp_lbuf); - } - - nrows = pktsz / SNMP_NCHARS_IN_A_ROW; - nrem = pktsz % SNMP_NCHARS_IN_A_ROW; - - for (i = 0; i < nrows; i++) { - snmp_get_dumpchars(ascii, p, SNMP_NCHARS_IN_A_ROW); - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%s" - "%02x %02x %02x %02x %02x %02x %02x %02x " - "%02x %02x %02x %02x %02x %02x %02x %02x " - "%s\n", - SNMP_DPKT_INDENT, ' ', SNMP_DTEXT_PREFIX, - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], - p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15], - ascii); - p += 16; - - snmp_log_append(snmp_lbuf); - } - - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, "%*c%s", - SNMP_DPKT_INDENT, ' ', SNMP_DTEXT_PREFIX); - - snmp_get_dumpchars(ascii, p, nrem); - - bufp = snmp_lbuf + SNMP_DPKT_INDENT + strlen(SNMP_DTEXT_PREFIX); - len = SNMP_DMAX_LINE - SNMP_DPKT_INDENT + strlen(SNMP_DTEXT_PREFIX); - for (i = 0; i < 16; i++) { - if (i < nrem) - (void) snprintf(bufp, len, "%02x ", p[i]); - else - (void) snprintf(bufp, len, " "); - - bufp += 3; - len -= 3; - } - (void) snprintf(bufp, len, "%s\n", ascii); - snmp_log_append(snmp_lbuf); - - (void) mutex_unlock(&snmp_dbuf_lock); -} - -void -snmp_log_io(uint_t tag, int a1, uint_t a2, uint_t a3) -{ - (void) mutex_lock(&snmp_dbuf_lock); - - if ((snmp_debug_flag & SNMP_DEBUG_IO) == 0) { - (void) mutex_unlock(&snmp_dbuf_lock); - return; - } - - snmp_log_append("\n"); - - if (tag < n_tags) { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, - "%*c%s%s(%d, %#x, %#x)\n", SNMP_DIO_INDENT, ' ', - SNMP_DTEXT_PREFIX, debug_tags[tag], a1, a2, a3); - } else { - (void) snprintf(snmp_lbuf, SNMP_DMAX_LINE, - "%*c%s%#x(%d, %#x, %#x)\n", SNMP_DIO_INDENT, ' ', - SNMP_DTEXT_PREFIX, tag, a1, a2, a3); - } - - snmp_log_append(snmp_lbuf); - - (void) mutex_unlock(&snmp_dbuf_lock); -} - -static char * -snmp_cmdstr_lookup(int cmd) -{ - int nelem = sizeof (snmp_cmds) / sizeof (snmp_key_to_str_t); - int i; - - for (i = 0; i < nelem; i++) { - if (snmp_cmds[i].key == cmd) - return (snmp_cmds[i].str); - } - - return (NULL); -} - -static char * -snmp_vtypestr_lookup(int vtype) -{ - int nelem = sizeof (snmp_vartypes) / sizeof (snmp_key_to_str_t); - int i; - - for (i = 0; i < nelem; i++) { - if (snmp_vartypes[i].key == vtype) - return (snmp_vartypes[i].str); - } - - return (NULL); -} - -static char * -snmp_asnencoding_lookup(int asnkey) -{ - int nelem = sizeof (snmp_asnencodings) / sizeof (snmp_key_to_str_t); - int i; - - for (i = 0; i < nelem; i++) { - if (snmp_asnencodings[i].key == asnkey) - return (snmp_asnencodings[i].str); - } - - return (NULL); -} - -static void -snmp_get_dumpchars(uchar_t *abuf, uchar_t *p, int nchars) -{ - int i; - - if (nchars > SNMP_NCHARS_IN_A_ROW) - nchars = SNMP_NCHARS_IN_A_ROW; - - abuf[nchars] = 0; - for (i = 0; i < nchars; i++) - abuf[i] = isprint(p[i]) ? p[i] : '.'; -} - -static void -snmp_log_append(char *bufp) -{ - int len; - - len = strlen(bufp); - if ((snmp_dbuf_curp + len) >= snmp_dbuf_tail) - snmp_dbuf_realloc(); - - (void) strcpy(snmp_dbuf_curp, bufp); - - snmp_dbuf_curp += len; -} - -static void -snmp_dbuf_realloc(void) -{ - char *p; - size_t offset = 0; - size_t count; - - count = snmp_dbuf_sz + SNMP_DBLOCK_SZ; - if ((p = (char *)calloc(count, 1)) == NULL) { - snmp_dbuf_overflow++; - snmp_dbuf_curp = snmp_dbuf; - return; - } - - if (snmp_dbuf) { - offset = snmp_dbuf_curp - snmp_dbuf; - (void) memcpy(p, snmp_dbuf, snmp_dbuf_sz); - free(snmp_dbuf); - } - - snmp_dbuf = p; - snmp_dbuf_sz += SNMP_DBLOCK_SZ; - - snmp_dbuf_curp = snmp_dbuf + offset; - snmp_dbuf_tail = snmp_dbuf + snmp_dbuf_sz; -} - -#endif diff --git a/usr/src/cmd/picl/plugins/sun4v/lib/snmp/debug.h b/usr/src/cmd/picl/plugins/sun4v/lib/snmp/debug.h deleted file mode 100644 index bc228a20d2..0000000000 --- a/usr/src/cmd/picl/plugins/sun4v/lib/snmp/debug.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _DEBUG_H -#define _DEBUG_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef SNMP_DEBUG - -/* - * ASN Debugging keys - */ -#define SNMP_DASN_SEQUENCE 1 -#define SNMP_DASN_LENGTH 2 -#define SNMP_DASN_INT 3 -#define SNMP_DASN_OCTET_STR 4 -#define SNMP_DASN_OID 5 -#define SNMP_DASN_NULL 6 - -/* - * Debug tags - */ -#define TAG_CMD_REQUEST 0 -#define TAG_NULL_VAR 1 -#define TAG_RESPONSE_VAR 2 -#define TAG_REQUEST_PDU 3 -#define TAG_RESPONSE_PDU 4 -#define TAG_REQUEST_PKT 5 -#define TAG_RESPONSE_PKT 6 -#define TAG_WRITE 7 -#define TAG_IOCTL 8 -#define TAG_READ 9 -#define TAG_SENDTO 10 -#define TAG_RECVFROM 11 - -/* - * Debug macros - */ -#define LOGINIT() \ - snmp_debug_init() - -#define LOGGET(tag, prefix, row) \ - snmp_log_cmd(tag, SNMP_MSG_GET, 1, prefix, row) - -#define LOGBULK(tag, n_oids, oidstrs, row) \ - snmp_log_cmd(tag, SNMP_MSG_GETBULK, n_oids, oidstrs, row) - -#define LOGNEXT(tag, prefix, row) \ - snmp_log_cmd(tag, SNMP_MSG_GETNEXT, 1, prefix, row) - -#define LOGVAR(tag, vp) \ - snmp_log_var(tag, vp) - -#define LOGPDU(tag, pdu) \ - snmp_log_pdu(tag, pdu) - -#define LOGASNSEQ(pkt, pktsz) \ - snmp_log_asn(SNMP_DASN_SEQUENCE, pkt, pktsz) - -#define LOGASNLENGTH(pkt, pktsz) \ - snmp_log_asn(SNMP_DASN_LENGTH, pkt, pktsz) - -#define LOGASNINT(pkt, pktsz) \ - snmp_log_asn(SNMP_DASN_INT, pkt, pktsz) - -#define LOGASNOCTSTR(pkt, pktsz) \ - snmp_log_asn(SNMP_DASN_OCTET_STR, pkt, pktsz) - -#define LOGASNOID(pkt, pktsz) \ - snmp_log_asn(SNMP_DASN_OID, pkt, pktsz) - -#define LOGASNNULL(pkt, pktsz) \ - snmp_log_asn(SNMP_DASN_NULL, pkt, pktsz) - -#define LOGPKT(tag, pkt, sz) \ - snmp_log_pkt(tag, pkt, sz) - -#define LOGIO(tag, a1, a2, a3) \ - snmp_log_io(tag, (int)a1, (uint_t)a2, (uint_t)a3) - -/* - * Exported debug interfaces - */ -extern void snmp_debug_init(void); -extern void snmp_log_cmd(uint_t tag, int cmd, int n_oids, - char *oidstr, int row); -extern void snmp_log_var(uint_t tag, pdu_varlist_t *vp); -extern void snmp_log_pdu(uint_t tag, snmp_pdu_t *pdu); -extern void snmp_log_asn(int key, uchar_t *pkt, size_t pktsz); -extern void snmp_log_pkt(uint_t tag, uchar_t *pkt, size_t pktsz); -extern void snmp_log_io(uint_t tag, int a1, uint_t a2, uint_t a3); - -#else /* SNMP_DEBUG */ - -#define LOGINIT() -#define LOGGET(tag, prefix, row) -#define LOGBULK(tag, n_oids, oidstrs, row) -#define LOGNEXT(tag, prefix, row) -#define LOGVAR(tag, vp) -#define LOGPDU(tag, pdu) -#define LOGASNSEQ(pkt, pktsz) -#define LOGASNLENGTH(pkt, pktsz) -#define LOGASNINT(pkt, pktsz) -#define LOGASNOCTSTR(pkt, pktsz) -#define LOGASNOID(pkt, pktsz) -#define LOGASNNULL(pkt, pktsz) -#define LOGPKT(tag, pkt, sz) -#define LOGIO(tag, a1, a2, a3) - -#endif /* SNMP_DEBUG */ - -#ifdef __cplusplus -} -#endif - -#endif /* _DEBUG_H */ diff --git a/usr/src/cmd/picl/plugins/sun4v/lib/snmp/pdu.c b/usr/src/cmd/picl/plugins/sun4v/lib/snmp/pdu.c index 8703a74aa5..31b0c86c70 100644 --- a/usr/src/cmd/picl/plugins/sun4v/lib/snmp/pdu.c +++ b/usr/src/cmd/picl/plugins/sun4v/lib/snmp/pdu.c @@ -22,10 +22,9 @@ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright 2019 Peter Tribble. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * SNMP PDU and packet transport related routines */ @@ -36,7 +35,6 @@ #include <sys/types.h> #include "asn1.h" #include "pdu.h" -#include "debug.h" /* * Static declarations @@ -276,8 +274,6 @@ snmp_add_null_vars(snmp_pdu_t *pdu, char *oidstrs, int n_oids, int row) vp->type = ASN_NULL; vp->nextvar = NULL; - LOGVAR(TAG_NULL_VAR, vp); - prev = vp; p += strlen(p) + 1; } @@ -601,8 +597,6 @@ snmp_parse_pdu(int reqid, uchar_t *msg, size_t *msgsz_p, snmp_pdu_t *reply_pdu) vp = newvp; if ((p = snmp_parse_variable(p, msgsz_p, vp)) == NULL) return (NULL); - - LOGVAR(TAG_RESPONSE_VAR, vp); } return (p); diff --git a/usr/src/cmd/picl/plugins/sun4v/lib/snmp/snmplib.c b/usr/src/cmd/picl/plugins/sun4v/lib/snmp/snmplib.c index 61c73b94f7..5629182a4a 100644 --- a/usr/src/cmd/picl/plugins/sun4v/lib/snmp/snmplib.c +++ b/usr/src/cmd/picl/plugins/sun4v/lib/snmp/snmplib.c @@ -22,6 +22,7 @@ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright 2019 Peter Tribble. */ /* @@ -47,7 +48,6 @@ #include "snmplib.h" #include "asn1.h" #include "pdu.h" -#include "debug.h" #pragma init(libpiclsnmp_init) /* need this in .init */ @@ -69,13 +69,6 @@ static uint_t n_mibcache_rows = 0; static mutex_t snmp_reqid_lock; static int snmp_reqid = 1; -#ifdef SNMP_DEBUG -uint_t snmp_nsends = 0; -uint_t snmp_sentbytes = 0; -uint_t snmp_nrecvs = 0; -uint_t snmp_rcvdbytes = 0; -#endif - #ifdef USE_SOCKETS #define SNMP_DEFAULT_PORT 161 #define SNMP_MAX_RECV_PKTSZ (64 * 1024) @@ -176,8 +169,6 @@ libpiclsnmp_init(void) (void) mutex_init(&refreshq_lock, USYNC_THREAD, NULL); (void) mutex_init(&snmp_reqid_lock, USYNC_THREAD, NULL); - - LOGINIT(); } picl_snmphdl_t @@ -877,20 +868,14 @@ fetch_single(struct picl_snmphdl *smd, char *prefix, int row, int *snmp_syserr) { snmp_pdu_t *pdu, *reply_pdu; - LOGGET(TAG_CMD_REQUEST, prefix, row); - if ((pdu = snmp_create_pdu(SNMP_MSG_GET, 0, prefix, 1, row)) == NULL) return (NULL); - LOGPDU(TAG_REQUEST_PDU, pdu); - if (snmp_make_packet(pdu) < 0) { snmp_free_pdu(pdu); return (NULL); } - LOGPKT(TAG_REQUEST_PKT, pdu->req_pkt, pdu->req_pktsz); - if (snmp_send_request(smd, pdu, snmp_syserr) < 0) { snmp_free_pdu(pdu); return (NULL); @@ -901,13 +886,9 @@ fetch_single(struct picl_snmphdl *smd, char *prefix, int row, int *snmp_syserr) return (NULL); } - LOGPKT(TAG_RESPONSE_PKT, pdu->reply_pkt, pdu->reply_pktsz); - reply_pdu = snmp_parse_reply(pdu->reqid, pdu->reply_pkt, pdu->reply_pktsz); - LOGPDU(TAG_RESPONSE_PDU, reply_pdu); - snmp_free_pdu(pdu); return (reply_pdu); @@ -920,8 +901,6 @@ fetch_bulk(struct picl_snmphdl *smd, char *oidstrs, int n_oids, snmp_pdu_t *pdu, *reply_pdu; int max_reps; - LOGBULK(TAG_CMD_REQUEST, n_oids, oidstrs, row); - /* * If we're fetching volatile properties using BULKGET, don't * venture to get multiple rows (passing max_reps=0 will make @@ -933,8 +912,6 @@ fetch_bulk(struct picl_snmphdl *smd, char *oidstrs, int n_oids, if (pdu == NULL) return; - LOGPDU(TAG_REQUEST_PDU, pdu); - /* * Make an ASN.1 encoded packet from the PDU information */ @@ -943,8 +920,6 @@ fetch_bulk(struct picl_snmphdl *smd, char *oidstrs, int n_oids, return; } - LOGPKT(TAG_REQUEST_PKT, pdu->req_pkt, pdu->req_pktsz); - /* * Send the request packet to the agent */ @@ -962,8 +937,6 @@ fetch_bulk(struct picl_snmphdl *smd, char *oidstrs, int n_oids, return; } - LOGPKT(TAG_RESPONSE_PKT, pdu->reply_pkt, pdu->reply_pktsz); - /* * Parse the reply, validate the response and create a * reply-PDU out of the information. Populate the mibcache @@ -972,8 +945,6 @@ fetch_bulk(struct picl_snmphdl *smd, char *oidstrs, int n_oids, reply_pdu = snmp_parse_reply(pdu->reqid, pdu->reply_pkt, pdu->reply_pktsz); if (reply_pdu) { - LOGPDU(TAG_RESPONSE_PDU, reply_pdu); - if (reply_pdu->errstat == SNMP_ERR_NOERROR) { if (is_vol) { /* Add a job to the cache refresh work queue */ @@ -995,21 +966,15 @@ fetch_next(struct picl_snmphdl *smd, char *prefix, int row, int *snmp_syserr) { snmp_pdu_t *pdu, *reply_pdu; - LOGNEXT(TAG_CMD_REQUEST, prefix, row); - pdu = snmp_create_pdu(SNMP_MSG_GETNEXT, 0, prefix, 1, row); if (pdu == NULL) return (NULL); - LOGPDU(TAG_REQUEST_PDU, pdu); - if (snmp_make_packet(pdu) < 0) { snmp_free_pdu(pdu); return (NULL); } - LOGPKT(TAG_REQUEST_PKT, pdu->req_pkt, pdu->req_pktsz); - if (snmp_send_request(smd, pdu, snmp_syserr) < 0) { snmp_free_pdu(pdu); return (NULL); @@ -1020,13 +985,9 @@ fetch_next(struct picl_snmphdl *smd, char *prefix, int row, int *snmp_syserr) return (NULL); } - LOGPKT(TAG_RESPONSE_PKT, pdu->reply_pkt, pdu->reply_pktsz); - reply_pdu = snmp_parse_reply(pdu->reqid, pdu->reply_pkt, pdu->reply_pktsz); - LOGPDU(TAG_RESPONSE_PDU, reply_pdu); - snmp_free_pdu(pdu); return (reply_pdu); @@ -1049,8 +1010,6 @@ snmp_send_request(struct picl_snmphdl *smd, snmp_pdu_t *pdu, int *snmp_syserr) #ifdef USE_SOCKETS ret = -1; while (ret < 0) { - LOGIO(TAG_SENDTO, smd->fd, pdu->req_pkt, pdu->req_pktsz); - ret = sendto(smd->fd, pdu->req_pkt, pdu->req_pktsz, 0, (struct sockaddr *)&smd->agent_addr, sizeof (struct sockaddr)); @@ -1059,8 +1018,6 @@ snmp_send_request(struct picl_snmphdl *smd, snmp_pdu_t *pdu, int *snmp_syserr) } } #else - LOGIO(TAG_WRITE, smd->fd, pdu->req_pkt, pdu->req_pktsz); - if (write(smd->fd, pdu->req_pkt, pdu->req_pktsz) < 0) { if (snmp_syserr) *snmp_syserr = errno; @@ -1068,11 +1025,6 @@ snmp_send_request(struct picl_snmphdl *smd, snmp_pdu_t *pdu, int *snmp_syserr) } #endif -#ifdef SNMP_DEBUG - snmp_nsends++; - snmp_sentbytes += pdu->req_pktsz; -#endif - return (0); } @@ -1084,7 +1036,7 @@ snmp_recv_reply(struct picl_snmphdl *smd, snmp_pdu_t *pdu, int *snmp_syserr) uchar_t *pkt; extern int errno; #ifdef USE_SOCKETS - struct sockaddr_in from; + struct sockaddr_in from; int fromlen; ssize_t msgsz; #endif @@ -1098,8 +1050,6 @@ snmp_recv_reply(struct picl_snmphdl *smd, snmp_pdu_t *pdu, int *snmp_syserr) fromlen = sizeof (struct sockaddr_in); - LOGIO(TAG_RECVFROM, smd->fd, pkt, SNMP_MAX_RECV_PKTSZ); - msgsz = recvfrom(smd->fd, pkt, SNMP_MAX_RECV_PKTSZ, 0, (struct sockaddr *)&from, &fromlen); if (msgsz < 0 || msgsz >= SNMP_MAX_RECV_PKTSZ) { @@ -1109,8 +1059,6 @@ snmp_recv_reply(struct picl_snmphdl *smd, snmp_pdu_t *pdu, int *snmp_syserr) pktsz = (size_t)msgsz; #else - LOGIO(TAG_IOCTL, smd->fd, DSSNMP_GETINFO, &snmp_info); - /* * The ioctl will block until we have snmp data available */ @@ -1124,8 +1072,6 @@ snmp_recv_reply(struct picl_snmphdl *smd, snmp_pdu_t *pdu, int *snmp_syserr) if ((pkt = (uchar_t *)calloc(1, pktsz)) == NULL) return (-1); - LOGIO(TAG_READ, smd->fd, pkt, pktsz); - if (read(smd->fd, pkt, pktsz) < 0) { free(pkt); if (snmp_syserr) @@ -1137,11 +1083,6 @@ snmp_recv_reply(struct picl_snmphdl *smd, snmp_pdu_t *pdu, int *snmp_syserr) pdu->reply_pkt = pkt; pdu->reply_pktsz = pktsz; -#ifdef SNMP_DEBUG - snmp_nrecvs++; - snmp_rcvdbytes += pktsz; -#endif - return (0); } |
