DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T m

⟦7e6c268f8⟧ TextFile

    Length: 11517 (0x2cfd)
    Types: TextFile
    Names: »mib.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z« 
        └─⟦de7628f85⟧ 
            └─⟦this⟧ »isode-6.0/snmp/mib.c« 

TextFile

/* mib.c - MIB realization */

#ifndef	lint
static char *rcsid = "$Header: /f/osi/snmp/RCS/mib.c,v 7.1 90/01/11 18:34:14 mrose Exp $";
#endif

/* 
 * $Header: /f/osi/snmp/RCS/mib.c,v 7.1 90/01/11 18:34:14 mrose Exp $
 *
 * Contributed by NYSERNet Inc.  This work was partially supported by the
 * U.S. Defense Advanced Research Projects Agency and the Rome Air Development
 * Center of the U.S. Air Force Systems Command under contract number
 * F30602-88-C-0016.
 *
 *
 * $Log:	mib.c,v $
 * Revision 7.1  90/01/11  18:34:14  mrose
 * real-sync
 * 
 * Revision 7.0  89/11/23  22:23:12  mrose
 * Release 6.0
 * 
 */

/*
 *				  NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */


#include <stdio.h>
#include "mib.h"
#ifdef	BSD42
#include <sys/file.h>
#endif
#ifdef	SYS5
#include <fcntl.h>
#endif

/* \f

   DATA */

static	int	kd;


struct nlist nl[] = {
    { "_arptab" },
    { "_arptab_size" },
    { "_boottime" },
    { "_icmpstat" },
    { "_ifnet" },
    { "_ipforwarding" },
    { "_ipstat" },
    { "_rthashsize" },
    { "_rthost" },
    { "_rtnet" },
    { "_tcb" },
    { "_tcpstat" },
    { "_udb" },
    { "_udpstat" },
    { "_mbstat" },
#ifdef	BSD44
    { "_radix_node_head" },
    { "_iso_systype" },
    { "_clnp_stat" },
    { "_iso_snpac_size" },
    { "_iso_snpac" },
    { "_esis_stat" },
#endif

    NULL
};

/* \f

 */

readmib () {
    register struct nlist *nz;

    if (nlist ("/vmunix", nl) == NOTOK)
	adios ("/vmunix", "unable to nlist");
    for (nz = nl; nz -> n_name; nz++)
	if (nz -> n_value == 0)
	    advise (LLOG_EXCEPTIONS, NULLCP, "\"%s\" not in /vmunix (warning)",
		    nz -> n_name);

    if ((kd = open ("/dev/kmem", O_RDONLY)) == NOTOK)
	adios ("/vmunix", "unable to read");

    init_system ();	    /* Internet-standard MIB */
    init_interfaces ();
    init_ip ();
    init_icmp ();
    init_tcp ();
    init_udp ();

    init_clnp ();	    /* experimental CLNP group */

    init_unix ();	    /* UNIX-specific enterprise */
}

/* \f

 */

checkmib () {
    register OT	    ot;

    init_snmp ();

    for (ot = text2obj ("iso"); ot; ot = ot -> ot_next)
	if (ot -> ot_status == OT_MANDATORY
	        && ot -> ot_getfnx == o_generic
	        && ot -> ot_info == NULL)
	    advise (LLOG_EXCEPTIONS, NULLCP,
		    "variable \"%s.0\" has no value (warning)", ot -> ot_text);
}

/* \f

 */

static	init_snmp ()
{
    register OT	    ot;

    if (ot = text2obj ("snmpInPkts"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_inpkts;
    if (ot = text2obj ("snmpOutPkts"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_outpkts;
    if (ot = text2obj ("snmpInBadVersions"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_badversions;
    if (ot = text2obj ("snmpInBadCommunityNames"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_badcommunitynames;
    if (ot = text2obj ("snmpInBadCommunityUses"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_badcommunityuses;
    if (ot = text2obj ("snmpInASNParseErrs"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_asnparseerrs;
    if (ot = text2obj ("snmpInBadTypes"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_badtypes;
    if (ot = text2obj ("snmpInTotalReqVars"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_totalreqvars;
    if (ot = text2obj ("snmpInTotalSetVars"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_totalsetvars;
    if (ot = text2obj ("snmpInGetRequests"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_ingetrequests;
    if (ot = text2obj ("snmpInGetNexts"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_ingetnexts;
    if (ot = text2obj ("snmpInSetRequests"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_insetrequests;
    if (ot = text2obj ("snmpOutTooBigs"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_toobigs;
    if (ot = text2obj ("snmpOutNoSuchNames"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_nosuchnames;
    if (ot = text2obj ("snmpOutBadValues"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_badvalues;
    if (ot = text2obj ("snmpOutReadOnlys"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_readonlys;
    if (ot = text2obj ("snmpOutGenErrs"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_generrs;
    if (ot = text2obj ("snmpOutGetResponses"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_outgetresponses;
    if (ot = text2obj ("snmpOutTraps"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_outtraps;
    if (ot = text2obj ("snmpEnableAuthTraps"))
	ot -> ot_getfnx = o_generic,
	ot -> ot_info = (caddr_t) &snmpstat.s_enableauthtraps;
}

/* \f

 */

set_variable (name, newvalue)
char   *name,
       *newvalue;
{
    caddr_t  value;
    register OT	    ot = text2obj (name);
    register OS	    os;

    if (ot == NULLOT) {
	advise (LLOG_EXCEPTIONS, NULLCP, "unknown object \"%s\"", name);
	return;
    }
    if (ot -> ot_getfnx == NULLIFP) {
	advise (LLOG_EXCEPTIONS, NULLCP, "no getfnx for object \"%s\"",
		ot -> ot_text);
	return;
    }
    if (ot -> ot_getfnx != o_generic) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"non-generic getfnx for object \"%s\"", ot -> ot_text);
	return;
    }
    if ((os = ot -> ot_syntax) == NULLOS) {
	advise (LLOG_EXCEPTIONS, NULLCP, "no syntax defined for object \"%s\"",
		ot -> ot_text);
	return;
    }
    if ((*os -> os_parse) (&value, newvalue) == NOTOK) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"invalid value for variable \"%s.0\": \"%s\"", 
		ot -> ot_text, newvalue);
	return;
    }
    if (ot -> ot_info) {
	(*os -> os_free) (ot -> ot_info);
	ot -> ot_info = NULL;
    }
    ot -> ot_info = value;
}

/* \f

 */

int	getkmem (n, buffer, cc)
struct nlist *n;
caddr_t	buffer;
int	cc;
{
    if (n -> n_value == 0) {
	advise (LLOG_EXCEPTIONS, NULLCP, "\"%s\" not in /vmunix", n -> n_name);
	return NOTOK;
    }
    if (lseek (kd, (long) n -> n_value, L_SET) == NOTOK) {
	advise (LLOG_EXCEPTIONS, "failed", "lseek of 0x%x for \"%s\" in kmem",
		(long) n -> n_value, n -> n_name);
	return NOTOK;
    }
    if (read (kd, buffer, cc) != cc) {
	advise (LLOG_EXCEPTIONS, "failed", "read of \"%s\" from kmem",
		n -> n_name);
	return NOTOK;
    }

    return OK;
}
	    
/* \f

 */

int	o_generic (oi, v, offset)
OI	oi;
register struct type_SNMP_VarBind *v;
int	offset;
{
    register OID    oid = oi -> oi_name;
    register OT	    ot = oi -> oi_type;
    register OS	    os = ot -> ot_syntax;

    switch (offset) {
	case type_SNMP_PDUs_get__request:
	    if (oid -> oid_nelem != ot -> ot_name -> oid_nelem + 1
		    || oid -> oid_elements[oid -> oid_nelem - 1] != 0)
		return int_SNMP_error__status_noSuchName;
	    break;

	case type_SNMP_PDUs_get__next__request:
	    if (oid -> oid_nelem > ot -> ot_name -> oid_nelem + 1)
		return int_SNMP_error__status_noSuchName;
	    if (oid -> oid_nelem == ot -> ot_name -> oid_nelem) {
		OID	new;

		if ((new = oid_extend (oid, 1)) == NULLOID)
		    return int_SNMP_error__status_genErr;
		new -> oid_elements[new -> oid_nelem - 1] = 0;

		if (v -> name)
		    free_SNMP_ObjectName (v -> name);
		v -> name = new;
	    }
	    else
		return NOTOK;
	    break;

	default:
	    return int_SNMP_error__status_genErr;
    }
	
    if (os == NULLOS) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"no syntax defined for object \"%s\"", ot -> ot_text);

	return (offset == type_SNMP_PDUs_get__next__request ? NOTOK
		: int_SNMP_error__status_genErr);
    }
    if (ot -> ot_info == NULL) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"no value defined for object \"%s\"", ot -> ot_text);

	return (offset == type_SNMP_PDUs_get__next__request ? NOTOK
		: int_SNMP_error__status_noSuchName);
    }

    if (v -> value)
	free_SNMP_ObjectSyntax (v -> value), v -> value = NULL;
    if ((*os -> os_encode) (ot -> ot_info, &v -> value) == NOTOK) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"encoding error for variable \"%s\"",
		oid2ode (oi -> oi_name));

	return int_SNMP_error__status_genErr;
    }

    return int_SNMP_error__status_noError;
}
	    
/* \f

 */

int	o_number (oi, v, number)
OI	oi;
register struct type_SNMP_VarBind *v;
integer	number;
{
    int	    result;
    caddr_t value;
    register OT	    ot = oi -> oi_type;
    register OS	    os = ot -> ot_syntax;

    if (os == NULLOS) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"no syntax defined for object \"%s\"", ot -> ot_text);

	return int_SNMP_error__status_genErr;
    }

    if ((value = (caddr_t) malloc (sizeof (integer))) == NULL)
	adios (NULLCP, "out of memory");
    *((integer *) value) = number;

    if (v -> value)
	free_SNMP_ObjectSyntax (v -> value), v -> value = NULL;
    result = (*os -> os_encode) (value, &v -> value);
    free ((char *) value);

    if (result == NOTOK) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"encoding error for variable \"%s\"",
		oid2ode (oi -> oi_name));

	return int_SNMP_error__status_genErr;
    }

    return int_SNMP_error__status_noError;
}
	    
/* \f

 */

int	o_string (oi, v, base, len)
OI	oi;
register struct type_SNMP_VarBind *v;
char   *base;
int	len;
{
    int	    result;
    struct qbuf *value;
    register OT	    ot = oi -> oi_type;
    register OS	    os = ot -> ot_syntax;

    if (os == NULLOS) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"no syntax defined for object \"%s\"", ot -> ot_text);

	return int_SNMP_error__status_genErr;
    }

    if ((value = str2qb (base, len, 1)) == NULL)
	adios (NULLCP, "out of memory");

    if (v -> value)
	free_SNMP_ObjectSyntax (v -> value), v -> value = NULL;
    result = (*os -> os_encode) (value, &v -> value);

    if (result == NOTOK) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"encoding error for variable \"%s\"",
		oid2ode (oi -> oi_name));

	return int_SNMP_error__status_genErr;
    }

    return int_SNMP_error__status_noError;
}

/* \f

 */

int	o_specific (oi, v, value)
OI	oi;
register struct type_SNMP_VarBind *v;
caddr_t	value;
{
    int	    result;
    register OT	    ot = oi -> oi_type;
    register OS	    os = ot -> ot_syntax;

    if (os == NULLOS) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"no syntax defined for object \"%s\"", ot -> ot_text);

	return int_SNMP_error__status_genErr;
    }

    if (v -> value)
	free_SNMP_ObjectSyntax (v -> value), v -> value = NULL;
    result = (*os -> os_encode) (value, &v -> value);

    if (result == NOTOK) {
	advise (LLOG_EXCEPTIONS, NULLCP,
		"encoding error for variable \"%s\"",
		oid2ode (oi -> oi_name));

	return int_SNMP_error__status_genErr;
    }

    return int_SNMP_error__status_noError;
}

/* \f

 */

OID	oid_extend (q, howmuch)
register OID	q;
int	howmuch;
{
    register unsigned int   i,
			   *ip,
			   *jp;
    OID	    oid;

    if (q == NULLOID)
	return NULLOID;
    if ((i = q -> oid_nelem) < 1)
	return NULLOID;
    if ((oid = (OID) malloc (sizeof *oid)) == NULLOID)
	return NULLOID;

    if ((ip = (unsigned int *)
	 	    calloc ((unsigned) (i + howmuch + 1), sizeof *ip))
		== NULL) {
	free ((char *) oid);
	return NULLOID;
    }

    oid -> oid_elements = ip, oid -> oid_nelem = i + howmuch;

    for (i = 0, jp = q -> oid_elements; i < oid -> oid_nelem; i++, jp++)
	*ip++ = *jp;

    return oid;
}