]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/smux.h
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / smux.h
index 1d259932a2549937af00251aec69597a7a2283d6..9adfacb3e45d5e55377513635c5dac84008cb5ca 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with GNU Zebra; see the file COPYING.  If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.  
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #ifndef _ZEBRA_SNMP_H
 #define _ZEBRA_SNMP_H
 
-#define SMUX_PORT_DEFAULT 199
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/agent/snmp_vars.h>
 
-#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 "thread.h"
 
 /* Structures here are mostly compatible with UCD SNMP 4.1.1 */
 #define MATCH_FAILED     (-1)
 
 #define IN_ADDR_SIZE sizeof(struct in_addr)
 
-struct variable;
-
-#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. */
-  u_char 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;
-};
+#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))
 
-struct trap_object
-{
-  FindVarMethod *findVar;
-  u_char namelen;
-  oid name[MAX_OID_LEN];
+struct trap_object {
+       int namelen; /* Negative if the object is not indexed */
+       oid name[MAX_OID_LEN];
 };
 
 /* Declare SMUX return value. */
-#define SNMP_LOCAL_VARIABLES \
-  static int32_t snmp_int_val; \
-  static struct in_addr snmp_in_addr_val;
-
-#define SNMP_INTEGER(V) \
-  ( \
-    *var_len = sizeof (int32_t), \
-    snmp_int_val = V, \
-    (u_char *) &snmp_int_val \
-  )
-
-#define SNMP_IPADDRESS(V) \
-  ( \
-    *var_len = sizeof (struct in_addr), \
-    snmp_in_addr_val = V, \
-    (u_char *) &snmp_in_addr_val \
-  )
-
-void smux_init (struct thread_master *tm, oid [], size_t);
-void smux_start (void);
-void smux_register_mib(char *, struct variable *, size_t, int, oid [], size_t);
-int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *, 
-    WriteMethod **);
-int smux_trap (oid *, size_t, oid *, size_t, struct trap_object *, size_t, unsigned int, u_char);
-
-int oid_compare (oid *, int, oid *, int);
-void oid2in_addr (oid [], int, struct in_addr *);
-void *oid_copy (void *, void *, size_t);
-void oid_copy_addr (oid [], struct in_addr *, int);
+#define SNMP_LOCAL_VARIABLES                                                   \
+       static long snmp_int_val __attribute__((unused));                      \
+       static struct in_addr snmp_in_addr_val __attribute__((unused));
+
+#define SNMP_INTEGER(V)                                                        \
+       (*var_len = sizeof(snmp_int_val), snmp_int_val = V,                    \
+        (uint8_t *)&snmp_int_val)
+
+#define SNMP_IPADDRESS(V)                                                      \
+       (*var_len = sizeof(struct in_addr), snmp_in_addr_val = V,              \
+        (uint8_t *)&snmp_in_addr_val)
+
+extern void smux_init(struct thread_master *tm);
+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:
+
+ 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, uint8_t);
+
+extern int oid_compare(const oid *, int, const oid *, int);
+extern void oid2in_addr(oid[], int, struct in_addr *);
+extern void *oid_copy(void *, const void *, size_t);
+extern void oid_copy_addr(oid[], struct in_addr *, int);
 
 #endif /* _ZEBRA_SNMP_H */