Plan 9 from Bell Labs’s /usr/web/sources/contrib/gabidiaz/root/sys/src/cmd/snmpfs/snmp.h

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/* snmp protocol stuff */
#define DROCOMM	"public"
#define DRWCOMM	"private"
#define DTIMEOUT	5
#define DRETRIES	1
#define DNREP		5
#define DMAXREP	10
#define DMAX_PKT	20480
#define DPORT		"snmp"
#define DVERSION	1

#define MAX_LEN	50	/* max char len of oids and values */
#define MAX_ELEM	32	/* max number of  in a single snmp packet */	
#define MAX_OID	16	/* max oid length */

/* error codes */
#define  FATAL	2
int DEBUG = 0;

/* snmp asn1 primitive types */
enum {
	IpAddress = 0x40,
	Counter = 0x41,
	Gauge = 0x42,
	TimeTicks  = 0x43,
	Opaque  = 0x44,
	NsapAddress = 0x45,
	Counter64  = 0x46,
	UIInteger32 = 0x47,
	EndOfMIB = 0x82
};

/* error codes for pdu parsing */
enum {
	noError,
	tooBig,
	noSuchName,
	badValue,
	readOnly,
	genErr,
	noAccess,
	wrongType,
	wrongLength,
	wrongEncoding,
	wrongValue,
	noCreation,
	inconsistenValue,
	resourceUnavailable,
	commitFailed,
	undoFailed,
	authorizationError,
	notWritable,
	inconsistentName
};

/* error codes for trap-pdu */
enum {
	coldstart,
	warmstart,
	linkdown,
	linkup,
	authfailure,
	neightborloss,
	enterprise
};

/* pdu types for snmp v1 and v2 (implicit sequences) */
/* WalkRequest is ficticious, and GetNextRequest is used */
/* to walk the snmp tree. See dosnmp() for the details. */
enum {
	GetRequest 		= 0xa0,
	GetNextRequest 	= 0xa1,
	WalkRequest		= 0xa8,
	GetResponse 		= 0xa2,
	SetRequest 		= 0xa3,
	Trap 			= 0xa4,
	GetBulkRequest 	= 0xa5,
	InformRequest 		= 0xa6,
	SNMPv2Trap 		= 0xa7
};



/* snmp structures */
typedef struct Pdu Pdu;
typedef struct Packet Packet;
typedef struct Traps Traps;
typedef struct Tuple Tuple;
typedef struct Session Session;

struct Pdu {
	uchar type;
	int reqid;
	int errstat;
	int erridx;
	int nrep;
	int maxrep;
	int nbind;
	Tuple *varbind;
};


struct Packet {
	int ver;
	char *comm;
	Pdu pdu;
};

struct Traps {
	char *oid;
	char *addr;
	int type;
	char *ts;
	int nbind;
	Tuple *varbind;
};

struct Tuple {
	char *oid;
	char *value;
};

/* communities and hostnames are 20 chars max */
/* behaviour is truncate larger ones */

struct Session {
 	char *host;
 	char *port;
 	char *rocomm;
 	char *rwcomm;
	int timeout;
	int retries;
};

/* snmp.c */
int error(int level, char *format, ... );
int alarmtr(void *v,char *why);


int canwalk(Packet *orig, Packet * p1, Packet * p2); 

char* asn2char(Elem e);

int encpkt(Packet *p, Bytes **pbytes);
int dec_pdu(Elist * el, Pdu *p);
int mkreqid(void);
int decpkt(uchar *buff,int n,Packet *p);
int  pdu2asn(Elem *epdu,Elem * e);

Elem char2asn(char *data);
Elem mkvarbind(Packet *p);
Elem mkpdu(int type, Elist *el);
Elist * mkgetbulkreq(Packet *p);
Elist * mkgetnreq(Packet *p);

int mkwalk(Packet *p, Packet *o);
int talk(Session *s, Packet *req, Packet *recv);

char * dumppkt(Packet *s);
char * doget(Session *s, Packet * req);
char * dowalk(Session *s, Packet * req);
char * dobulk(Session *s, Packet * req);
char * doset(Session *s, Packet *req);
char * dosnmp(Session *s, Packet * req);

void freesession(Session *s);
void freepdu(Pdu *p);
void freepacket(Packet * p);

void debugpkt(Packet *p);
void debugses(Session *s);


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].