static void
incrRowStatusCounter(SmiNode *rowNode)
{
    SmiNode *smiNode;
    SmiType *smiType;
    SmiModule *smiModule;

    for (smiNode = smiGetFirstChildNode(rowNode);
	 smiNode;
	 smiNode = smiGetNextChildNode(smiNode)) {
	smiType = smiGetNodeType(smiNode);
	if (smiType && smiType->name) {
	    smiModule = smiGetTypeModule(smiType);
	    if (smiModule && smiModule->name
		&& strcmp(smiType->name, "RowStatus") == 0
		&& strcmp(smiModule->name, "SNMPv2-TC") == 0) {
		break;
	    }
	}
    }

    if (smiNode) {
#if 0
	fprintf(stderr, "** %s\t%s\t%s\n", rowNode->name,
		smiNode->name, smiType->name);
	/* xxx count rows indexed by ifIndex, InterfaceIndex, InterfaceIndexOrZero, ... */
#endif
    }
}
Beispiel #2
0
static int isGroup(SmiNode *smiNode)
{
    SmiNode *childNode;
    
    for(childNode = smiGetFirstChildNode(smiNode);
	childNode;
	childNode = smiGetNextChildNode(childNode)) {
	if ((childNode->nodekind == SMI_NODEKIND_SCALAR
	     || childNode->nodekind == SMI_NODEKIND_TABLE)
	    && childNode->status == SMI_STATUS_CURRENT) {
	    return 1;
	}
    }

    return 0;
}
Beispiel #3
0
static int isGroup(SmiNode *smiNode)
{
    SmiNode *childNode;

    if (smiNode->nodekind == SMI_NODEKIND_ROW) {
	return 1;
    }
    
    for(childNode = smiGetFirstChildNode(smiNode);
	childNode;
	childNode = smiGetNextChildNode(childNode)) {
	if (childNode->nodekind == SMI_NODEKIND_SCALAR) {
	    return 1;
	}
    }

    return 0;
}
Beispiel #4
0
static int isAccessible(SmiNode *groupNode)
{
    SmiNode *smiNode;
    int num = 0;
    
    for (smiNode = smiGetFirstChildNode(groupNode);
	 smiNode;
	 smiNode = smiGetNextChildNode(smiNode)) {
	if ((smiNode->nodekind == SMI_NODEKIND_SCALAR
	     || smiNode->nodekind == SMI_NODEKIND_COLUMN)
	    && (smiNode->access == SMI_ACCESS_READ_ONLY
		|| smiNode->access == SMI_ACCESS_READ_WRITE)) {
	    num++;
	}
    }

    return num;
}
Beispiel #5
0
MibNode * MibViewLoader::PopulateSubTree (SmiNode *smiNode, MibNode *parent, MibNode *sibling)
{
    SmiNode     *childNode;
    MibNode *current = NULL, *prev = NULL;
    
    if (smiNode)
    {
        current = new MibNode(SmiKindToMibNodeType(smiNode->nodekind), 
                              smiNode, parent, sibling);
        
        for (childNode = smiGetFirstChildNode(smiNode);
        childNode;
        childNode = smiGetNextChildNode(childNode))
        {
            if (PruneSubTree(childNode)) continue;
            
            prev = PopulateSubTree(childNode, current, prev);
        }
    }
    
    return current;
}
Beispiel #6
0
static void printAgtRegister(FILE *f, SmiNode *groupNode, int cnt)
{
    SmiNode *smiNode;
    char    *cGroupName;
    int     num = 0;

    for (smiNode = smiGetFirstChildNode(groupNode);
	 smiNode;
	 smiNode = smiGetNextChildNode(smiNode)) {
	if (smiNode->nodekind & (SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR)
	    && (smiNode->access == SMI_ACCESS_READ_ONLY
		|| smiNode->access == SMI_ACCESS_READ_WRITE)) {
	    num++;
	}
    }
    fprintf(f, "\n");

    if (cnt == 1) {
	fprintf(f,
		"/*\n"
		" * Registration functions for the various MIB groups.\n"
		" */\n\n");
    }
    
    cGroupName = translate(groupNode->name);

    fprintf(f, "int register_%s()\n{\n", cGroupName);
    fprintf(f,
	    "    return register_mib(\"%s\",\n"
	    "         %s_variables,\n"
	    "         sizeof(struct variable),\n"
	    "         sizeof(%s_variables)/sizeof(struct variable),\n"
	    "         %s_base,\n"
	    "         sizeof(%s_base)/sizeof(oid));\n",
	    cGroupName, cGroupName, cGroupName, cGroupName, cGroupName);
    fprintf(f, "};\n\n");

    xfree(cGroupName);
}
Beispiel #7
0
static void printCreateTable(SmiNode *groupNode)
{
    SmiNode *smiNode;
    SmiType *smiType;
    char    *sqlTableName;
    int     i;

    if (groupNode->nodekind == SMI_NODEKIND_ROW) {
	sqlTableName = translate(smiGetParentNode(groupNode)->name);
    } else {
	sqlTableName = translate(groupNode->name);
    }
    printf("create table %s (\n", sqlTableName);
    xfree(sqlTableName);

    for (smiNode = smiGetFirstChildNode(groupNode), i = 0;
	 smiNode;
	 smiNode = smiGetNextChildNode(smiNode), i++) {
	if (smiNode->nodekind & (SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR)
#if 0
	    && (smiNode->access == SMI_ACCESS_READ_ONLY
		|| smiNode->access == SMI_ACCESS_READ_WRITE)
#endif
	    ) {
	    smiType = smiGetNodeType(smiNode);
	    if (smiType && ! smiType->name) {
		smiType = smiGetParentType(smiType);
	    }
	    if (i) {
		printf(",\n");
	    }
	    if (smiType) {
		printf("    %s %s", smiNode->name, smiType->name);
	    }
	}
    }
    printf("\n);\n\n");
}
Beispiel #8
0
static void printGroup(int *x, int *y, SmiNode *smiNode)
{
    SmiNode *childNode;
    char string[4096];

    *y += Y_OFFSET;
    printString(*x, *y, 0, smiNode->name);

    for(childNode = smiGetFirstChildNode(smiNode);
	childNode;
	childNode = smiGetNextChildNode(childNode)) {
	if (childNode->nodekind == SMI_NODEKIND_SCALAR
	    || childNode->nodekind == SMI_NODEKIND_COLUMN) {
	    if (childNode->status != SMI_STATUS_OBSOLETE) {
		*y += Y_OFFSET;
		sprintf(string, "%s(%d)", childNode->name,
			childNode->oid[childNode->oidlen-1]);
		printString(*x + X_INDENT, *y, 0, string);
	    }
	}
    }
    *y += Y_OFFSET;
}
Beispiel #9
0
static void printClass(int *x, int *y, SmiNode *smiNode)
{
    SmiNode *childNode;
    SmiType *smiType;
    char string[4096];

    *y += Y_OFFSET;
    printString(*x, *y, 0, smiNode->name);

    for(childNode = smiGetFirstChildNode(smiNode);
	childNode;
	childNode = smiGetNextChildNode(childNode)) {
	if (childNode->nodekind == SMI_NODEKIND_SCALAR
	    || childNode->nodekind == SMI_NODEKIND_COLUMN) {
	    if (childNode->status != SMI_STATUS_OBSOLETE) {
		smiType = smiGetNodeType(childNode);
		*y += Y_OFFSET;
		sprintf(string, "%s : %s", childNode->name, smiType->name);
		printString(*x + X_INDENT, *y, 0, string);
	    }
	}
    }
    *y += Y_OFFSET;
}
Beispiel #10
0
int MibViewLoader::PruneSubTree(SmiNode *smiNode)
{
    SmiNode   *childNode;
    
    const int confmask = (SMI_NODEKIND_GROUP | SMI_NODEKIND_COMPLIANCE);
    const int leafmask = (SMI_NODEKIND_GROUP | SMI_NODEKIND_COMPLIANCE
                          | SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR
                          | SMI_NODEKIND_ROW | SMI_NODEKIND_NOTIFICATION);
    
    if (! smiNode) {
        return 1;
    }
    
    /*
     * First, prune all nodes which the user has told us to ignore.
     * In the case of ignoreleafs, we have to special case nodes with
     * an unknown status (which actually represent OBJECT-IDENTITY
     * definitions). More special case code is needed to exclude
     * module identity nodes.
     */
    
    if (ignoreconformance && (smiNode->nodekind & confmask)) {
        return 1;
    }
    
    if (ignoreleafs) {
        if (smiNode->nodekind & leafmask) {
            return 1;
        }
        if (smiNode->nodekind == SMI_NODEKIND_NODE
            && smiNode->status != SMI_STATUS_UNKNOWN) {
            SmiModule *smiModule = smiGetNodeModule(smiNode);
            if (smiModule && smiNode != smiGetModuleIdentityNode(smiModule)) {
                return 1;
            }
        }
    }
    
    /*
      * Next, generally do not prune nodes that belong to the set of
      * modules we are looking at.
      */
    
    if (IsPartOfLoadedModules(smiNode)) {
        if (!ignoreconformance || !smiGetFirstChildNode(smiNode)) {
            return 0;
        }
    }
    
    /*
     * Finally, prune all nodes where all child nodes are pruned.
     */
    
    for (childNode = smiGetFirstChildNode(smiNode);
    childNode;
    childNode = smiGetNextChildNode(childNode)) {
        
        /*
         * In the case of ignoreleafs, we have to peek at the child
         * nodes. Otherwise, we would prune too much. we still want to
         * see the path to the leafs we have pruned away. This also
         * interact with the semantics of ignoreconformance since we
         * still want in combination with ignoreleafs to see the path
         * to the pruned conformance leafs.
         */
        
        if (ignoreleafs && (childNode->nodekind & leafmask)) {
            if (IsPartOfLoadedModules(childNode)) {
                if (ignoreconformance && (childNode->nodekind & confmask)) {
                    return 1;
                }
                return 0;
            }
        }
        
        if (! PruneSubTree(childNode)) {
            return 0;
        }
    }
    
    return 1;
}
Beispiel #11
0
static void printHeaderTypedef(FILE *f, SmiModule *smiModule,
			       SmiNode *groupNode)
{
    SmiNode *smiNode;
    SmiType *smiType;
    char    *cModuleName, *cGroupName, *cName;
    unsigned minSize, maxSize;

    cModuleName = translateLower(smiModule->name);
    cGroupName = translate(groupNode->name);

    fprintf(f,
	    "/*\n"
	    " * C type definitions for %s::%s.\n"
	    " */\n\n",
	    smiModule->name, groupNode->name);
    
    fprintf(f, "typedef struct %s {\n", cGroupName);
	    
    for (smiNode = smiGetFirstChildNode(groupNode);
	 smiNode;
	 smiNode = smiGetNextChildNode(smiNode)) {
	if (smiNode->nodekind & (SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR)
#if 0
	    && (smiNode->access == SMI_ACCESS_READ_ONLY
		|| smiNode->access == SMI_ACCESS_READ_WRITE)
#endif
	    ) {
	    smiType = smiGetNodeType(smiNode);
	    if (!smiType) {
		continue;
	    }
	    
	    cName = translate(smiNode->name);
	    switch (smiType->basetype) {
	    case SMI_BASETYPE_OBJECTIDENTIFIER:
		maxSize = smiGetMaxSize(smiType);
		minSize = smiGetMinSize(smiType);
		fprintf(f,
			"    uint32_t  *%s;\n", cName);
		if (maxSize != minSize) {
		    fprintf(f,
			    "    size_t    _%sLength;\n", cName);
		}
		break;
	    case SMI_BASETYPE_OCTETSTRING:
	    case SMI_BASETYPE_BITS:
		maxSize = smiGetMaxSize(smiType);
		minSize = smiGetMinSize(smiType);
		fprintf(f,
			"    u_char    *%s;\n", cName);
		if (maxSize != minSize) {
		    fprintf(f,
			    "    size_t    _%sLength;\n", cName);
		}
		break;
	    case SMI_BASETYPE_ENUM:
	    case SMI_BASETYPE_INTEGER32:
		fprintf(f,
			"    int32_t   *%s;\n", cName);
		break;
	    case SMI_BASETYPE_UNSIGNED32:
		fprintf(f,
			"    uint32_t  *%s;\n", cName);
		break;
	    case SMI_BASETYPE_INTEGER64:
		fprintf(f,
			"    int64_t   *%s; \n", cName);
		break;
	    case SMI_BASETYPE_UNSIGNED64:
		fprintf(f,
			"    uint64_t  *%s; \n", cName);
		break;
	    default:
		fprintf(f,
			"    /* ?? */  __%s; \n", cName);
		break;
	    }
	    xfree(cName);
	}
    }
    
    fprintf(f,
	    "    void      *_clientData;\t\t"
	    "/* pointer to client data structure */\n");
    if (groupNode->nodekind == SMI_NODEKIND_ROW) {
	fprintf(f, "    struct %s *_nextPtr;\t"
		"/* pointer to next table entry */\n", cGroupName);
    }
    fprintf(f,
	    "\n    /* private space to hold actual values */\n\n");

    for (smiNode = smiGetFirstChildNode(groupNode);
	 smiNode;
	 smiNode = smiGetNextChildNode(smiNode)) {
	if (smiNode->nodekind & (SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR)
#if 0
	    && (smiNode->access == SMI_ACCESS_READ_ONLY
		|| smiNode->access == SMI_ACCESS_READ_WRITE)
#endif
	    ) {
	    smiType = smiGetNodeType(smiNode);
	    if (!smiType) {
		continue;
	    }
	    
	    cName = translate(smiNode->name);
	    switch (smiType->basetype) {
	    case SMI_BASETYPE_OBJECTIDENTIFIER:
		maxSize = smiGetMaxSize(smiType);
		fprintf(f,
			"    uint32_t  __%s[%u];\n", cName, maxSize);
		break;
	    case SMI_BASETYPE_OCTETSTRING:
	    case SMI_BASETYPE_BITS:
		maxSize = smiGetMaxSize(smiType);
		fprintf(f,
			"    u_char    __%s[%u];\n", cName, maxSize);
		break;
	    case SMI_BASETYPE_ENUM:
	    case SMI_BASETYPE_INTEGER32:
		fprintf(f,
			"    int32_t   __%s;\n", cName);
		break;
	    case SMI_BASETYPE_UNSIGNED32:
		fprintf(f,
			"    uint32_t  __%s;\n", cName);
		break;
	    case SMI_BASETYPE_INTEGER64:
		fprintf(f,
			"    int64_t   __%s; \n", cName);
		break;
	    case SMI_BASETYPE_UNSIGNED64:
		fprintf(f,
			"    uint64_t  __%s; \n", cName);
		break;
	    default:
		fprintf(f,
			"    /* ?? */  __%s; \n", cName);
		break;
	    }
	    xfree(cName);
	}
    }

    fprintf(f, "} %s_t;\n\n", cGroupName);

    fprintf(f,
	    "/*\n"
	    " * C manager interface stubs for %s::%s.\n"
	    " */\n\n",
	    smiModule->name, groupNode->name);
	    
    fprintf(f, "extern int\n"
	    "%s_mgr_get_%s(struct snmp_session *s, %s_t **%s);\n",
	    cModuleName, cGroupName, cGroupName, cGroupName);
    fprintf(f, "\n");

    fprintf(f,
	    "/*\n"
	    " * C agent interface stubs for %s::%s.\n"
	    " */\n\n",
	    smiModule->name, groupNode->name);
    
    fprintf(f, "extern int\n"
	    "%s_agt_read_%s(%s_t *%s);\n",
	    cModuleName, cGroupName, cGroupName, cGroupName);
    fprintf(f, "extern int\n"
	    "%s_agt_register_%s();\n\n",
	    cModuleName, cGroupName);
    xfree(cGroupName);
    xfree(cModuleName);
}
Beispiel #12
0
static void
dumpSizeOfPDU(FILE *f, SmiModule *smiModule, SmiNode *smiNode)
{
     SmiNode *child;
     int worst = 0;
     int best = 0;
     int avg = 0;
     int b, w, a, n = 0;
     
     for (child = smiGetFirstChildNode(smiNode);
	  child;
	  child = smiGetNextChildNode(child)) {
	  if (child->access == SMI_ACCESS_READ_WRITE
	      || child->access == SMI_ACCESS_READ_ONLY) {

	       b = ber_len_varbind(child, len_min);
	       a = ber_len_varbind(child, len_mean);
	       w = ber_len_varbind(child, len_max);
	       
	       best += b, worst += w, avg += a, n++;
	  }
     }

     /* varbind list sequence length and tag */
     best  += ber_len_length(best)  + 1;
     avg   += ber_len_length(avg)   + 1;
     worst += ber_len_length(worst) + 1;

     /* request-id as defined in RFC 3416 */
     best += ber_len_int32(0);
     avg += ber_len_int32(1073741824);
     worst += ber_len_int32(-214783648);
     
     /* error-status as defined in RFC 3416 */
     best += ber_len_int32(0);
     avg += ber_len_int32(0);
     worst += ber_len_int32(18);
     
     /* error-index as defined in RFC 3416 */
     best += ber_len_int32(0);
     avg += ber_len_int32(0);
     worst += ber_len_int32(n-1);

     /* PDU sequence length and tag */
     best  += ber_len_length(best)  + 1;
     avg += ber_len_length(avg) + 1;
     worst += ber_len_length(worst) + 1;
     
     fprintf(f, "%-23s %-23s \t%d\t[%d..%d]\n", smiModule->name, smiNode->name,
	     avg, best, worst);

     if (detail) {
	 for (child = smiGetFirstChildNode(smiNode);
	      child;
	      child = smiGetNextChildNode(child)) {
	     if (child->access == SMI_ACCESS_READ_WRITE
		 || child->access == SMI_ACCESS_READ_ONLY) {
		 
		 b = ber_len_varbind(child, len_min);
		 a = ber_len_varbind(child, len_mean);
		 w = ber_len_varbind(child, len_max);
		 
		 fprintf(f, "%-23s %-23s \t%d\t[%d..%d]\n",
			 "", child->name, a, b, w);
	     }
	 }
     }
}
Beispiel #13
0
static void
dumpSizeOfCreatePDU(FILE *f, SmiModule *smiModule, SmiNode *smiNode,
		    int ignoreDefaultColumns)
{
     SmiNode *child;
     SmiType *childType;
     SmiModule *childTypeModule;
     
     int worst = 0;
     int best = 0;
     int avg = 0;
     int b, w, a, n = 0;
     int isRowStatus;
     
     for (child = smiGetFirstChildNode(smiNode);
	  child;
	  child = smiGetNextChildNode(child)) {
	  if (child->access == SMI_ACCESS_READ_WRITE) {

	       /* Ensure RowStatus columns are present even if they
		* have a default value. */

	       childType = smiGetNodeType(child);
	       childTypeModule = childType
		    ? smiGetTypeModule(childType) : NULL;
	       
	       isRowStatus
		    = (childType && childType->name
		       && childTypeModule && childTypeModule->name)
		    ? (strcmp(childType->name, "RowStatus") == 0
		       && strcmp(childTypeModule->name, "SNMPv2-TC") == 0)
		    : 0;

	       /* xxx at least one PDU must be present xxx */

	       if (ignoreDefaultColumns
		   && child->value.basetype != SMI_BASETYPE_UNKNOWN
		   && !isRowStatus) {
		    continue;
	       }

	       b = ber_len_varbind(child, len_min);
	       a = ber_len_varbind(child, len_mean);
	       w = ber_len_varbind(child, len_max);

#if 0
	       fprintf(f, "  %-32s\t[%d..%d] | %d\n", child->name, b, w, a);
#endif
	       
	       best += b, worst += w, avg += a, n++;
	  }
     }

     /* varbind list sequence length and tag */
     best  += ber_len_length(best)  + 1;
     avg   += ber_len_length(avg)   + 1;
     worst += ber_len_length(worst) + 1;

     /* request-id as defined in RFC 3416 */
     best += ber_len_int32(0);
     avg += ber_len_int32(1073741824);
     worst += ber_len_int32(-214783648);
     
     /* error-status as defined in RFC 3416 */
     best += ber_len_int32(0);
     avg += ber_len_int32(0);
     worst += ber_len_int32(18);
     
     /* error-index as defined in RFC 3416 */
     best += ber_len_int32(0);
     avg += ber_len_int32(0);
     worst += ber_len_int32(n-1);

     /* PDU sequence length and tag */
     best  += ber_len_length(best)  + 1;
     avg += ber_len_length(avg) + 1;
     worst += ber_len_length(worst) + 1;
     
     fprintf(f, "%-23s %-23s \t%d\t[%d..%d]\n", smiModule->name, smiNode->name,
	     avg, best, worst);
}
Beispiel #14
0
static void printMgrGetScalarAssignement(FILE *f, SmiNode *groupNode)
{
    SmiNode *smiNode;
    SmiType *smiType;
    char    *cGroupName, *cName;
    unsigned maxSize, minSize;

    cGroupName = translate(groupNode->name);

    for (smiNode = smiGetFirstChildNode(groupNode);
	 smiNode;
	 smiNode = smiGetNextChildNode(smiNode)) {
	if (smiNode->nodekind & (SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR)
	    && (smiNode->access == SMI_ACCESS_READ_ONLY
		|| smiNode->access == SMI_ACCESS_READ_WRITE)) {

	    smiType = smiGetNodeType(smiNode);
	    if (!smiType) {
		continue;
	    }
	    
	    cName = translate(smiNode->name);
	    fprintf(f,
		    "        if (vars->name_length > sizeof(%s)/sizeof(oid)\n"
		    "            && memcmp(vars->name, %s, sizeof(%s)) == 0) {\n",
		    cName, cName, cName);
	    switch (smiType->basetype) {
	    case SMI_BASETYPE_INTEGER32:
	    case SMI_BASETYPE_UNSIGNED32:
	    case SMI_BASETYPE_ENUM:
		fprintf(f,
			"            (*%s)->__%s = *vars->val.integer;\n"
			"            (*%s)->%s = &((*%s)->__%s);\n",
			cGroupName, cName,
			cGroupName, cName, cGroupName, cName);
		break;
	    case SMI_BASETYPE_OCTETSTRING:
	    case SMI_BASETYPE_BITS:
		maxSize = smiGetMaxSize(smiType);
		minSize = smiGetMinSize(smiType);
		fprintf(f,
			"            memcpy((*%s)->__%s, vars->val.string, vars->val_len);\n",
			cGroupName, cName);
		if (minSize != maxSize) {
		    fprintf(f,
			    "            (*%s)->_%sLength = vars->val_len;\n",
			    cGroupName, cName);
		}
		fprintf(f,
			"            (*%s)->%s = (*%s)->__%s;\n",
			cGroupName, cName, cGroupName, cName);
		break;
	    case SMI_BASETYPE_OBJECTIDENTIFIER:
		break;
	    default:
		break;
	    }
	    fprintf(f,
		    "        }\n");
	    xfree(cName);
	}
    }

    xfree(cGroupName);
}
Beispiel #15
0
static void printAgtReadMethod(FILE *f, SmiNode *groupNode)
{
    SmiNode   *smiNode;
    SmiType   *smiType;
    char      *cName, *sName, *lName;

    sName = translate(groupNode->name);

    fprintf(f,
	    "static unsigned char *\nread_%s_stub(struct variable *vp,\n"
	    "    oid     *name,\n"
	    "    size_t  *length,\n"
	    "    int     exact,\n"
	    "    size_t  *var_len,\n"
	    "    WriteMethod **write_method)\n"
	    "{\n", sName);

    fprintf(f, "    static %s_t %s;\n\n", sName, sName);
    
    smiNode = smiGetFirstChildNode(groupNode);
    if (smiNode && smiNode->nodekind == SMI_NODEKIND_SCALAR) {
	fprintf(f,
		"    /* check whether the instance identifier is valid */\n"
		"\n"
		"    if (header_generic(vp, name, length, exact, var_len,\n"
		"                       write_method) == MATCH_FAILED) {\n"
		"        return NULL;\n"
		"    }\n"
		"\n");
    }

    fprintf(f,
	    "    /* call the user supplied function to retrieve values */\n"
	    "\n"
	    "    read_%s(&%s);\n"
	    "\n", sName, sName);

    fprintf(f,
	    "    /* return the current value of the variable */\n"
	    "\n"
	    "    switch (vp->magic) {\n"
	    "\n");

    for (smiNode = smiGetFirstChildNode(groupNode);
	 smiNode;
	 smiNode = smiGetNextChildNode(smiNode)) {
	if (smiNode->nodekind & (SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR)
	    && (smiNode->access == SMI_ACCESS_READ_ONLY
		|| smiNode->access == SMI_ACCESS_READ_WRITE)) {
	    cName = translateUpper(smiNode->name);
	    lName = translate(smiNode->name);
	    smiType = smiGetNodeType(smiNode);
	    if (! smiType) {
		continue;
	    }
	    fprintf(f, "    case %s:\n", cName);
	    switch (smiType->basetype) {
	    case SMI_BASETYPE_OBJECTIDENTIFIER:
		fprintf(f,
			"        *var_len = %s._%sLength;\n"
			"        return (unsigned char *) %s.%s;\n",
			sName, lName, sName, lName);
		break;
	    case SMI_BASETYPE_OCTETSTRING:
	    case SMI_BASETYPE_BITS:
		fprintf(f,
			"        *var_len = %s._%sLength;\n"
			"        return (unsigned char *) %s.%s;\n",
			sName, lName, sName, lName);
		break;
	    case SMI_BASETYPE_ENUM:
	    case SMI_BASETYPE_INTEGER32:
	    case SMI_BASETYPE_UNSIGNED32:
		fprintf(f,
			"        return (unsigned char *) &%s.%s;\n",
			sName, lName);
		break;
	    default:
		fprintf(f,
			"        /* add code to return the value here */\n");
	    }
	    fprintf(f, "\n");
	    xfree(cName);
	    xfree(lName);
	}
    }

    fprintf(f,
	    "    default:\n"
	    "         ERROR_MSG(\"\");\n"
	    "    }\n"
	    "\n"
	    "    return NULL;\n"
	    "}\n"
	    "\n");

    xfree(sName);
}
Beispiel #16
0
static void printAgtDefinesGroup(FILE *f, SmiNode *groupNode, int cnt)
{
    char         *cName, *cGroupName;
    SmiNode   	 *smiNode;
    SmiType   	 *smiType;
    int	      	 num = 0;
    unsigned int i;
    
    if (cnt == 1) {
	fprintf(f,
	"/*\n"
	" * Definitions of tags that are used internally to read/write\n"
	" * the selected object type. These tags should be unique.\n"
	" */\n\n");
    }

    cGroupName = translate(groupNode->name);

    for (smiNode = smiGetFirstChildNode(groupNode);
	 smiNode;
	 smiNode = smiGetNextChildNode(smiNode)) {
	if (smiNode->nodekind & (SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR)
	    && (smiNode->access == SMI_ACCESS_READ_ONLY
		|| smiNode->access == SMI_ACCESS_READ_WRITE)) {
	    num++;
	    cName = translateUpper(smiNode->name);
	    fprintf(f, "#define %-32s %d\n", cName,
		    smiNode->oid[smiNode->oidlen-1]);
	    xfree(cName);
	}
    }
    fprintf(f, "\n");

    if (num) {
	fprintf(f, "static oid %s_base[] = {", cGroupName);
	for (i = 0; i < groupNode->oidlen; i++) {
	    fprintf(f, "%s%d", i ? ", " : "", groupNode->oid[i]);
	}
	fprintf(f, "};\n\n");
	fprintf(f, "struct variable %s_variables[] = {\n", cGroupName);
	for (smiNode = smiGetFirstChildNode(groupNode);
	     smiNode;
	     smiNode = smiGetNextChildNode(smiNode)) {
	    if (smiNode->nodekind & (SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR)
		&& (smiNode->access == SMI_ACCESS_READ_ONLY
		    || smiNode->access == SMI_ACCESS_READ_WRITE)) {
		smiType = smiGetNodeType(smiNode);
		if (!smiType) {
		    continue;
		}
		cName = translateUpper(smiNode->name);
		fprintf(f, "    { %s, %s, %s, read_%s_stub, %d, {%d} },\n",
			cName, getBaseTypeString(smiType->basetype),
			getAccessString(smiNode->access),
			cGroupName, 1, smiNode->oid[smiNode->oidlen-1]);
		xfree(cName);
	    }
	}
	fprintf(f, "};\n\n");
    }

    xfree(cGroupName);
}
static void
addMetrics(Metrics *metrics, SmiModule *smiModule)
{
    SmiNode *smiNode;
    SmiType *smiType;
    size_t len;

    for (smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_ANY);
	 smiNode;
	 smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ANY)) {
	len = smiNode->description ? strlen(smiNode->description) : 0;
	switch (smiNode->nodekind) {
	case SMI_NODEKIND_TABLE:
	    incrStatusCounter(&metrics->statusTables, smiNode->status);
	    incrStatusCounter(&metrics->statusAll, smiNode->status);
	    incrLengthCounter(&metrics->lengthTables,
			      smiNode->description, smiNode->reference,
			      smiNode->units, smiNode->format);
	    incrLengthCounter(&metrics->lengthAll,
			      smiNode->description, smiNode->reference,
			      smiNode->units, smiNode->format);
	    break;
	case SMI_NODEKIND_ROW:
	    incrIndexCounter(&metrics->indexTables, smiNode->indexkind);
	    incrLengthCounter(&metrics->lengthRows,
			      smiNode->description, smiNode->reference,
			      smiNode->units, smiNode->format);
	    incrLengthCounter(&metrics->lengthAll,
			      smiNode->description, smiNode->reference,
			      smiNode->units, smiNode->format);
	    incrRowStatusCounter(smiNode);
	    {
		int cnt = 0;
		foreachIndexDo(NULL, smiNode, count, &cnt);
		incrIndexLenCounter(&metrics->indexLenTables, cnt);
		foreachIndexDo(NULL, smiNode, yadayada, smiModule);
	    }
	    {
		int cmplx = 0;
		foreachIndexDo(NULL, smiNode, complexity, &cmplx);
		incrIndexComplexityCounter(smiModule, smiNode, cmplx);
		incrIndexComplexityMetric(&metrics->indexComplexity, cmplx);
	    }
	    // count the childs ...
	    {
		    SmiModule *smiModule = smiGetModule("SNMPv2-TC");
		    SmiNode *childNode;
		    SmiType *rowStatus = smiGetType(smiModule, "RowStatus");
		    SmiType *storageType = smiGetType(smiModule, "StorageType");
		    // include index elements not in table
		    int n = 0;
		    for (childNode = smiGetFirstChildNode(smiNode);
			 childNode;
			 childNode = smiGetNextChildNode(childNode)) {
			    n++;
			    if (rowStatus == smiGetNodeType(childNode)) {
				    fprintf(stderr, "**** GEEEEEE - ROWSTATUS\n");
			    }
			    if (storageType == smiGetNodeType(childNode)) {
				    fprintf(stderr, "**** GEEEEEE - STORAGETYPE\n");
			    }
		    }
		    incrTableLenCounter(&metrics->tableLength, n);
	    }
	    break;
	case SMI_NODEKIND_COLUMN:
	    incrBasetypeCounter(&metrics->basetypesColumns, smiNode);
	    incrBasetypeCounter(&metrics->basetypesAll, smiNode);
	    incrStatusCounter(&metrics->statusColumns, smiNode->status);
	    incrStatusCounter(&metrics->statusAll, smiNode->status);
	    incrAccessCounter(&metrics->accessColumns, smiNode->access);
	    incrAccessCounter(&metrics->accessAll, smiNode->access);
	    incrLengthCounter(&metrics->lengthColumns,
			      smiNode->description, smiNode->reference,
			      smiNode->units, smiNode->format);
	    incrLengthCounter(&metrics->lengthAll,
			      smiNode->description, smiNode->reference,
			      smiNode->units, smiNode->format);
	    incrTypeAndNodeUsageCounter(smiModule, smiNode, INCR_TYPE);
	    break;
	case SMI_NODEKIND_SCALAR:
	    incrBasetypeCounter(&metrics->basetypesScalars, smiNode);
	    incrBasetypeCounter(&metrics->basetypesAll, smiNode);
	    incrStatusCounter(&metrics->statusScalars, smiNode->status);
	    incrStatusCounter(&metrics->statusAll, smiNode->status);
	    incrAccessCounter(&metrics->accessScalars, smiNode->access);
	    incrAccessCounter(&metrics->accessAll, smiNode->access);
	    incrLengthCounter(&metrics->lengthScalars,
			      smiNode->description, smiNode->reference,
			      smiNode->units, smiNode->format);
	    incrLengthCounter(&metrics->lengthAll,
			      smiNode->description, smiNode->reference,
			      smiNode->units, smiNode->format);
	    incrTypeAndNodeUsageCounter(smiModule, smiNode, INCR_TYPE);
	    break;
	case SMI_NODEKIND_NOTIFICATION:
	    incrStatusCounter(&metrics->statusNotifications, smiNode->status);
	    incrStatusCounter(&metrics->statusAll, smiNode->status);
	    incrLengthCounter(&metrics->lengthNotifications,
			      smiNode->description, smiNode->reference,
			      smiNode->units, smiNode->format);
	    incrLengthCounter(&metrics->lengthAll,
			      smiNode->description, smiNode->reference,
			      smiNode->units, smiNode->format);
	    break;
	case SMI_NODEKIND_GROUP:
	    incrStatusCounter(&metrics->statusGroups, smiNode->status);
	    incrStatusCounter(&metrics->statusAll, smiNode->status);
	    break;
	case SMI_NODEKIND_COMPLIANCE:
	    incrStatusCounter(&metrics->statusCompliances, smiNode->status);
	    incrStatusCounter(&metrics->statusAll, smiNode->status);
	    break;
	}
    }

    for (smiType = smiGetFirstType(smiModule);
	 smiType;
	 smiType = smiGetNextType(smiType)) {

	/*
	 * Ignore all types with empty descriptions coming from the
	 * "SNMPv2-SMI" module since they are not really defined
	 * types but part of the language itself.
	 */

	if (! smiType->description) {
	    SmiModule *m = smiGetTypeModule(smiType);
	    if (m && strcmp(m->name, "SNMPv2-SMI") == 0) {
		continue;
	    }
	}
    
	incrStatusCounter(&metrics->statusTypes, smiType->status);
	incrStatusCounter(&metrics->statusAll, smiType->status);
	incrLengthCounter(&metrics->lengthTypes,
			  smiType->description, smiType->reference,
			  smiType->units, smiType->format);
	incrLengthCounter(&metrics->lengthAll,
			  smiType->description, smiType->reference,
			  smiType->units, smiType->format);
    }
}
Beispiel #18
0
static void printMgrGetMethod(FILE *f, SmiModule *smiModule,
			      SmiNode *groupNode)
{
    SmiNode *smiNode;
    char    *cModuleName, *cGroupName;

    cModuleName = translateLower(smiModule->name);
    cGroupName = translate(groupNode->name);

    fprintf(f,
	    "int %s_mgr_get_%s(struct snmp_session *s, %s_t **%s)\n"
	    "{\n"
	    "    struct snmp_session *peer;\n"
	    "    struct snmp_pdu *request, *response;\n"
	    "    struct variable_list *vars;\n"
	    "    int status;\n"
	    "\n",
	    cModuleName, cGroupName, cGroupName, cGroupName);

    fprintf(f,
	    "    request = snmp_pdu_create(SNMP_MSG_GETNEXT);\n");
	    
    for (smiNode = smiGetFirstChildNode(groupNode);
	 smiNode;
	 smiNode = smiGetNextChildNode(smiNode)) {
	if (smiNode->nodekind & (SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR)
	    && (smiNode->access == SMI_ACCESS_READ_ONLY
		|| smiNode->access == SMI_ACCESS_READ_WRITE)) {
	    fprintf(f,
	    "    snmp_add_null_var(request, %s, sizeof(%s)/sizeof(oid));\n",
		    smiNode->name, smiNode->name);
	}
    }

    fprintf(f,
	    "\n"
	    "    peer = snmp_open(s);\n"
	    "    if (!peer) {\n"
	    "        snmp_free_pdu(request);\n"
	    "        return -1;\n"
	    "    }\n"
	    "\n"
	    "    status = snmp_synch_response(peer, request, &response);\n"
	    "    if (status != STAT_SUCCESS) {\n"
	    "        if (response) snmp_free_pdu(response);\n"
	    "        snmp_close(peer);\n"
	    "        return -2;\n"
	    "    }\n"
	    "\n");

    /* generate code for error checking and handling */

    fprintf(f,
	    "    *%s = (%s_t *) malloc(sizeof(%s_t));\n"
	    "    if (! *%s) {\n"
	    "        if (response) snmp_free_pdu(response);\n"
	    "        snmp_close(peer);\n"
	    "        return -4;\n"
	    "    }\n"
	    "\n",
	    cGroupName, cGroupName, cGroupName, cGroupName);

    fprintf(f,
	    "    for (vars = response->variables; vars; vars = vars->next_variable) {\n");
    printMgrGetScalarAssignement(f, groupNode);
    fprintf(f,
	    "    }\n"
	    "\n");


#if 0
    if (response->errstat != SNMP_ERR_NOERROR) {
	return -3;
    }

    /* copy to data structures */

    /* cleanup */

#endif

    fprintf(f,
	    "    if (response) snmp_free_pdu(response);\n"
	    "\n"
	    "    if (snmp_close(peer) == 0) {\n"
	    "        return -5;\n"
	    "    }\n"
	    "\n"
	    "    return 0;\n"
	    "}\n\n");

    xfree(cGroupName);
    xfree(cModuleName);
}