pdu.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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
* 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 2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <syslog.h>
#include <string.h>
#include <netdb.h>
#include <nlist.h>
#include "snmp_msg.h"
#include "impl.h"
#include "trace.h"
#include "asn1.h"
#include "snmp.h"
#include "pdu.h"
#include "error.h"
/***** LOCAL CONSTANTS *****/
/*It is practically feasible to have a packet up to around 9k bytes (less than 9.5k).*/
#define COMMUNITY_LENGTH 128
/***** LOCAL VARIABLES *****/
/***** LOCAL FUNCTIONS *****/
static u_char *snmp_pdu_encode_variable(SNMP_variable *variable, u_char *data, int *length, char *error_label);
/********************************************************************/
{
error_label[0] = '\0';
{
return NULL;
}
return new;
}
/********************************************************************/
SNMP_variable *snmp_typed_variable_new(Oid *name, u_char type, SNMP_value *value, char *error_label)
{
error_label[0] = '\0';
{
return NULL;
}
{
return NULL;
}
{
return NULL;
}
/* name */
{
return NULL;
}
/* type */
/* val, val_len */
switch(type)
{
case INTEGER:
case COUNTER:
case GAUGE:
case TIMETICKS:
{
return NULL;
}
break;
case IPADDRESS:
case OPAQUE:
case STRING:
{
return NULL;
}
break;
case OBJID:
{
return NULL;
}
/* Should * sizeof(Subid), yiru's fix*/
break;
default:
return NULL;
}
return new;
}
/********************************************************************/
SNMP_variable *snmp_typed_variable_append(SNMP_variable *list, Oid *name, u_char type, SNMP_value *value, char *error_label)
{
error_label[0] = '\0';
{
return NULL;
}
{
}
else
{
SNMP_variable *v;
for(v = list; v; v = v->next_variable)
{
last = v;
}
}
return list;
}
/********************************************************************/
{
error_label[0] = '\0';
{
return NULL;
}
new->request_id = 0;
new->error_status = 0;
new->error_index = 0;
new->time_stamp = 0;
return new;
}
/********************************************************************/
{
int length;
error_label[0] = '\0';
return NULL;
}
/* LINTED */
if(length == -1)
{
return NULL;
}
if(trace_flags & TRACE_TRAFFIC)
{
trace("<< received %d bytes from %s\n\n",
}
if(trace_flags & TRACE_PACKET)
{
}
{
return NULL;
}
if(trace_flags & TRACE_PDU)
{
}
return pdu;
}
/********************************************************************/
/* this function does not close sd and does not free pdu */
{
int length = PACKET_LENGTH;
int bytes;
return -1;
}
error_label[0] = '\0';
{
return -1;
}
{
return -1;
}
if(trace_flags & TRACE_PDU)
{
}
{
return -1;
}
if(trace_flags & TRACE_PACKET)
{
}
/* LINTED */
if(bytes == -1)
{
return -1;
}
if(trace_flags & TRACE_TRAFFIC)
{
trace(">> sent %d bytes to %s\n\n",
}
return 0;
}
/********************************************************************/
{
{
return;
}
{
}
{
}
}
/********************************************************************/
{
while(variable_list)
{
SNMP_variable *v;
v = variable_list->next_variable;
variable_list = v;
}
}
/********************************************************************/
{
{
return;
}
{
}
{
}
}
/********************************************************************/
{
int count;
trace("PACKET:\n");
trace("-------\n");
{
{
trace("\n");
}
}
trace("\n\n");
}
/********************************************************************/
{
trace("PDU:\n");
trace("----\n");
{
trace("pdu is NULL!\n\n");
return;
}
{
case GET_REQ_MSG:
case GETNEXT_REQ_MSG:
case GET_RSP_MSG:
case SET_REQ_MSG:
trace("error status: %s\n",
break;
case TRP_REQ_MSG:
trace("enterprise: %s\n",
trace("IP agent addr: %s\n",
trace("generic: %s\n",
break;
default:
trace("\n");
return;
}
while(variable)
{
trace("--------------------------------------------------\n");
}
trace("--------------------------------------------------\n\n");
}
/********************************************************************/
{
int i;
{
trace("variable is NULL\n");
}
/*
trace("variable 0x%x\n", variable);
trace("next 0x%x\n", variable->next_variable);
*/
trace("value: ");
{
case INTEGER:
case COUNTER:
case GAUGE:
case TIMETICKS:
break;
case IPADDRESS:
{
}
else
{
}
break;
case OBJID:
break;
case STRING:
case OPAQUE:
case NULLOBJ:
default:
{
}
trace(" ( ");
{
}
trace(")\n");
break;
}
}
/********************************************************************/
/*
* Parses the packet and places the data into the pdu.
* If any errors are encountered, NULL is returned.
*/
{
int length = packet_length;
int len;
error_label[0] = '\0';
{
return NULL;
}
/* header of message */
{
return NULL;
}
{
return NULL;
}
/* version */
{
return NULL;
}
{
return NULL;
}
/* parse community */
{
return NULL;
}
{
return NULL;
}
/* header od pdu */
{
return NULL;
}
{
case GET_REQ_MSG:
case GETNEXT_REQ_MSG:
case GET_RSP_MSG:
case SET_REQ_MSG:
/* request id */
{
return NULL;
}
/* error status */
{
return NULL;
}
/* error index */
{
return NULL;
}
break;
case TRP_REQ_MSG:
/* enterprise */
{
return NULL;
}
{
return NULL;
}
/* agent address */
len = 4;
{
return NULL;
}
/* generic trap */
{
return NULL;
}
/* specific trap */
{
return NULL;
}
/* time stamp */
{
return NULL;
}
break;
default:
return NULL;
}
/* header of variables */
{
return NULL;
}
{
return NULL;
}
while(length > 0)
{
{
return NULL;
}
{
}
else
{
}
} /* while */
return pdu;
}
/********************************************************************/
{
error_label[0] = '\0';
{
return NULL;
}
/* header of variable */
if(d == NULL)
{
return NULL;
}
{
return NULL;
}
/* name */
if(d == NULL)
{
return NULL;
}
{
return NULL;
}
{
return NULL;
}
/* find out what type of object this is */
value_start = d;
if(d == NULL)
{
return NULL;
}
{
case INTEGER:
case COUNTER:
case GAUGE:
case TIMETICKS:
{
return NULL;
}
if(d == NULL)
{
return NULL;
}
break;
case STRING:
case IPADDRESS:
case OPAQUE:
{
return NULL;
}
if(d == NULL)
{
return NULL;
}
break;
case OBJID:
if(d == NULL)
{
return NULL;
}
{
return NULL;
}
break;
case NULLOBJ:
break;
default:
return NULL;
}
/* LINTED */
*data = d;
return variable;
}
/********************************************************************/
/*
* Takes a pdu and serializes the ASN PDU into the area
* pointed to by packet. length is the size of the data area available.
* Returns the length of the completed packet in length. If any errors
* occur, -1 is returned. If all goes well, 0 is returned.
*/
{
int buf_len;
int len;
return -1;
}
error_label[0] = '\0';
len = *packet_length;
/* encode the variables in packet */
{
return -1;
}
}
/* LINTED */
/* encode the header for the variables in buf */
{
return -1;
}
/* copy the encoded variables from packet to buf */
/* LINTED */
/* encode the pdu in packet */
len = *packet_length;
{
case GET_REQ_MSG:
case GETNEXT_REQ_MSG:
case GET_RSP_MSG:
case SET_REQ_MSG:
/* request id */
{
return -1;
}
/* error status */
{
return -1;
}
/* error index */
{
return -1;
}
break;
case TRP_REQ_MSG:
/* enterprise */
{
return -1;
}
/* agent-addr */
{
return -1;
}
/* generic trap */
{
return -1;
}
/* specific trap */
{
return -1;
}
/* time stamp */
{
return -1;
}
break;
default:
return -1;
} /* switch */
/* copy the encoded variables and their header from buf to packet */
if(len < total_length)
{
return -1;
}
/* LINTED */
/* encode the header of the pdu in buf */
len = PACKET_LENGTH;
/* LINTED */
{
return -1;
}
/* copy the pdu from packet to buf */
if(len < total_length)
{
return -1;
}
/* LINTED */
/* encode the message in packet */
len = *packet_length;
{
return -1;
}
/* LINTED */
{
return -1;
}
/* version */
{
return -1;
}
/* community */
/* LINTED */
{
return -1;
}
/* copy the pdu and its header from buf to packet */
if(len < total_length)
{
return -1;
}
/* LINTED */
return 0;
}
/********************************************************************/
static u_char *snmp_pdu_encode_variable(SNMP_variable *variable, u_char *data, int *length, char *error_label)
{
error_label[0] = '\0';
return NULL;
}
/* LINTED */
{
return NULL;
}
{
case INTEGER:
case GAUGE:
case COUNTER:
case TIMETICKS:
else
{
return NULL;
}
break;
case STRING:
case IPADDRESS:
case OPAQUE:
{
return NULL;
}
break;
case OBJID:
{
return NULL;
}
break;
case NULLOBJ:
{
return NULL;
}
break;
default:
return NULL;
} /* switch */
/* LINTED */
header_shift = 0;
if(dummy_len >= 0x80)
{
header_shift++;
if(dummy_len > 0xFF)
{
header_shift++;
}
}
if(header_shift)
{
if(*length < 0)
{
return NULL;
}
}
{
return NULL;
}
return data;
}
/********************************************************************/
{
if(shift_amount >= 0)
{
while(length--)
{
}
}
else
{
while(length--)
{
}
}
}
/********************************************************************/
{
error_label[0] = '\0';
{
return NULL;
}
{
return NULL;
}
{
return NULL;
}
return new;
}
/********************************************************************/
{
error_label[0] = '\0';
return (NULL);
}
return (NULL);
}
return (NULL);
}
} else {
}
return (new);
}
/********************************************************************/
{
error_label[0] = '\0';
{
return NULL;
}
{
return NULL;
}
{
return NULL;
}
{
return NULL;
}
{
}
if(last)
{
}
else
{
}
return new;
}
SNMP_variable *ssa_append_integer_variable(SNMP_variable *list, Oid *oid, int num,char *error_label,u_char asn1_type)
{
error("ssa_append_integer_variable failed: oid: %s, value: %d\n",
}
return(list);
}
char *error_label)
{
return (NULL);
error("ssa_append_string_variable failed: oid: %s, \
}
return (list);
}
{
error("ssa_append_oid_varaible(%s,%s) failed\n",
}
return(list);
}