From 3a4c96885ec878ae4631b0fb7bb7839578725976 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 23 May 2012 00:52:46 +0200 Subject: smux: isolate SMUX implementation from SNMP implementation lib/snmp.c gets OID related helper functions that can be used with another SNMP interface. smux.h is cleaned of SMUX specific bits to only expose functions that may be used by an alternative implementation. We also do not redefine functions already present in NetSNMP. Just use the appropriate headers. --- lib/smux.h | 81 ++++---------------------------------------------------------- 1 file changed, 4 insertions(+), 77 deletions(-) (limited to 'lib/smux.h') diff --git a/lib/smux.h b/lib/smux.h index f5754ed9..83ae56ce 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -22,24 +22,8 @@ #ifndef _ZEBRA_SNMP_H #define _ZEBRA_SNMP_H -#define SMUX_PORT_DEFAULT 199 - -#define SMUXMAXPKTSIZE 1500 -#define SMUXMAXSTRLEN 256 - -#define SMUX_OPEN (ASN_APPLICATION | ASN_CONSTRUCTOR | 0) -#define SMUX_CLOSE (ASN_APPLICATION | ASN_PRIMITIVE | 1) -#define SMUX_RREQ (ASN_APPLICATION | ASN_CONSTRUCTOR | 2) -#define SMUX_RRSP (ASN_APPLICATION | ASN_PRIMITIVE | 3) -#define SMUX_SOUT (ASN_APPLICATION | ASN_PRIMITIVE | 4) - -#define SMUX_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0) -#define SMUX_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 1) -#define SMUX_GETRSP (ASN_CONTEXT | ASN_CONSTRUCTOR | 2) -#define SMUX_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 3) -#define SMUX_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 4) - -#define SMUX_MAX_FAILURE 3 +#include +#include /* Structures here are mostly compatible with UCD SNMP 4.1.1 */ #define MATCH_FAILED (-1) @@ -55,69 +39,12 @@ #define IN_ADDR_SIZE sizeof(struct in_addr) -struct variable; - +#undef REGISTER_MIB #define REGISTER_MIB(descr, var, vartype, theoid) \ smux_register_mib(descr, (struct variable *)var, sizeof(struct vartype), \ sizeof(var)/sizeof(struct vartype), \ theoid, sizeof(theoid)/sizeof(oid)) -typedef int (WriteMethod)(int action, - u_char *var_val, - u_char var_val_type, - size_t var_val_len, - u_char *statP, - oid *name, - size_t length, - struct variable *v); - -typedef u_char *(FindVarMethod)(struct variable *v, - oid *name, - size_t *length, - int exact, - size_t *var_len, - WriteMethod **write_method); - -/* SNMP variable */ -struct variable -{ - /* Index of the MIB.*/ - u_char magic; - - /* Type of variable. */ - char type; - - /* Access control list. */ - u_short acl; - - /* Callback function. */ - FindVarMethod *findVar; - - /* Suffix of the MIB. */ - int namelen; - oid name[MAX_OID_LEN]; -}; - -/* SNMP tree. */ -struct subtree -{ - /* Tree's oid. */ - oid name[MAX_OID_LEN]; - u_char name_len; - - /* List of the variables. */ - struct variable *variables; - - /* Length of the variables list. */ - int variables_num; - - /* Width of the variables list. */ - int variables_width; - - /* Registered flag. */ - int registered; -}; - struct trap_object { FindVarMethod *findVar; @@ -145,7 +72,6 @@ struct trap_object ) extern void smux_init (struct thread_master *tm); -extern void smux_start (void); extern void smux_register_mib(const char *, struct variable *, size_t, int, oid [], size_t); extern int smux_header_generic (struct variable *, oid [], size_t *, @@ -153,6 +79,7 @@ extern int smux_header_generic (struct variable *, oid [], size_t *, extern int smux_trap (const oid *, size_t, const oid *, size_t, const struct trap_object *, size_t, unsigned int, u_char); + extern int oid_compare (oid *, int, oid *, int); extern void oid2in_addr (oid [], int, struct in_addr *); extern void *oid_copy (void *, const void *, size_t); -- cgit v1.2.1 From 4b89e45d928d41bb5d32a00ba7b402d6a3bbdf44 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 24 May 2012 21:22:01 +0200 Subject: smux: remove `tick` argument from smux_trap() smux_trap() contains an argument whose use appears to be to set sysUpTime.0/timestamp field in SNMP trap. However, this value is not used in smux_trap(). Moreover, it is expected that this field is the value of sysUpTime.0 when the trap was sent and not any other time related to the trap. To avoid any confusion, we remove this field from the signature of the function. --- lib/smux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/smux.h') diff --git a/lib/smux.h b/lib/smux.h index 83ae56ce..78460e68 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -78,7 +78,7 @@ extern int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *, WriteMethod **); extern int smux_trap (const oid *, size_t, const oid *, size_t, const struct trap_object *, - size_t, unsigned int, u_char); + size_t, u_char); extern int oid_compare (oid *, int, oid *, int); extern void oid2in_addr (oid [], int, struct in_addr *); -- cgit v1.2.1 From b8cf46b715b2c21db5dce8118c70b4dd9b5255a3 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 25 May 2012 08:56:44 +0200 Subject: smux: drop findVar element from trap object struct This element was not unused. --- lib/smux.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/smux.h') diff --git a/lib/smux.h b/lib/smux.h index 78460e68..b7d5096e 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -47,8 +47,7 @@ struct trap_object { - FindVarMethod *findVar; - int namelen; + int namelen; /* Negative if the object is not indexed */ oid name[MAX_OID_LEN]; }; -- cgit v1.2.1 From b7c0d0651cd64f644d02ef5e4d1b82febe7e57d8 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 25 May 2012 11:17:01 +0200 Subject: agentx: handle SNMP traps smux_trap() signature has been changed to provide appropriate level information to send SNMPv2 notifications. This includes the addition of the enterprise OID to use (from which is derived the SNMP trap OID) and the MIB registry to locate the appropriate function for variable bindings provided by the trap. The SMUX implementation has been updated but ignore the provided enterprise OID. Instead, it still uses the SMUX peer OID to keep compatibility with previous versions of Quagga. The SMUX implementation also ignores the provided MIB registry since it uses smux_get() function to grab the appropriate values. This is not possible with the AgentX implementation since there is no such function provided by NetSNMP. --- lib/smux.h | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'lib/smux.h') diff --git a/lib/smux.h b/lib/smux.h index b7d5096e..b29fdc72 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -75,9 +75,34 @@ extern void smux_register_mib(const char *, struct variable *, size_t, int, oid [], size_t); extern int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *, WriteMethod **); -extern int smux_trap (const oid *, size_t, const oid *, size_t, - const struct trap_object *, - size_t, u_char); + +/* For traps, three OID are provided: + + 1. The enterprise OID to use (the last argument will be appended to + it to form the SNMP trap OID) + + 2. The base OID for objects to be sent in traps. + + 3. The index OID for objects to be sent in traps. This index is used + to designate a particular instance of a column. + + The provided trap object contains the bindings to be sent with the + trap. The base OID will be prefixed to the provided OID and, if the + length is positive, the requested OID is assumed to be a columnar + object and the index OID will be appended. + + The two first arguments are the MIB registry used to locate the trap + objects. + + The use of the arguments may differ depending on the implementation + used. +*/ +extern int smux_trap (struct variable *, size_t, + const oid *, size_t, + const oid *, size_t, + const oid *, size_t, + const struct trap_object *, size_t, + u_char); extern int oid_compare (oid *, int, oid *, int); extern void oid2in_addr (oid [], int, struct in_addr *); -- cgit v1.2.1 From 8046ba6ec4d6e87bf8da6563c0f3e5e66c4652b3 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 31 May 2012 13:30:28 +0200 Subject: snmp: let handlers accept OID from a lesser prefix Most table handlers do not expect to be given an OID whose prefix is outside what they can handle. This is not a problem with the SMUX implementation since it always correct the OID such that the prefix matches. However, this is not the case for the AgentX implementation. A new function, smux_header_table() is used to do this normalization. --- lib/smux.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/smux.h') diff --git a/lib/smux.h b/lib/smux.h index b29fdc72..72b4eaf0 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -75,6 +75,8 @@ extern void smux_register_mib(const char *, struct variable *, size_t, int, oid [], size_t); extern int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *, WriteMethod **); +extern int smux_header_table (struct variable *, oid *, size_t *, + int, size_t *, WriteMethod **); /* For traps, three OID are provided: -- cgit v1.2.1