smux.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* SNMP support
  2. * Copyright (C) 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  18. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. * 02111-1307, USA.
  20. */
  21. #ifndef _ZEBRA_SNMP_H
  22. #define _ZEBRA_SNMP_H
  23. #define SMUX_PORT_DEFAULT 199
  24. #define SMUXMAXPKTSIZE 1500
  25. #define SMUXMAXSTRLEN 256
  26. #define SMUX_OPEN (ASN_APPLICATION | ASN_CONSTRUCTOR | 0)
  27. #define SMUX_CLOSE (ASN_APPLICATION | ASN_PRIMITIVE | 1)
  28. #define SMUX_RREQ (ASN_APPLICATION | ASN_CONSTRUCTOR | 2)
  29. #define SMUX_RRSP (ASN_APPLICATION | ASN_PRIMITIVE | 3)
  30. #define SMUX_SOUT (ASN_APPLICATION | ASN_PRIMITIVE | 4)
  31. #define SMUX_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0)
  32. #define SMUX_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 1)
  33. #define SMUX_GETRSP (ASN_CONTEXT | ASN_CONSTRUCTOR | 2)
  34. #define SMUX_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 3)
  35. #define SMUX_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 4)
  36. #define SMUX_MAX_FAILURE 3
  37. /* Structures here are mostly compatible with UCD SNMP 4.1.1 */
  38. #define MATCH_FAILED (-1)
  39. #define MATCH_SUCCEEDED 0
  40. /* SYNTAX TruthValue from SNMPv2-TC. */
  41. #define SNMP_TRUE 1
  42. #define SNMP_FALSE 2
  43. /* SYNTAX RowStatus from SNMPv2-TC. */
  44. #define SNMP_VALID 1
  45. #define SNMP_INVALID 2
  46. #define IN_ADDR_SIZE sizeof(struct in_addr)
  47. struct variable;
  48. #define REGISTER_MIB(descr, var, vartype, theoid) \
  49. smux_register_mib(descr, (struct variable *)var, sizeof(struct vartype), \
  50. sizeof(var)/sizeof(struct vartype), \
  51. theoid, sizeof(theoid)/sizeof(oid))
  52. typedef int (WriteMethod)(int action,
  53. u_char *var_val,
  54. u_char var_val_type,
  55. size_t var_val_len,
  56. u_char *statP,
  57. oid *name,
  58. size_t length,
  59. struct variable *v);
  60. typedef u_char *(FindVarMethod)(struct variable *v,
  61. oid *name,
  62. size_t *length,
  63. int exact,
  64. size_t *var_len,
  65. WriteMethod **write_method);
  66. /* SNMP variable */
  67. struct variable
  68. {
  69. /* Index of the MIB.*/
  70. u_char magic;
  71. /* Type of variable. */
  72. char type;
  73. /* Access control list. */
  74. u_short acl;
  75. /* Callback function. */
  76. FindVarMethod *findVar;
  77. /* Suffix of the MIB. */
  78. int namelen;
  79. oid name[MAX_OID_LEN];
  80. };
  81. /* SNMP tree. */
  82. struct subtree
  83. {
  84. /* Tree's oid. */
  85. oid name[MAX_OID_LEN];
  86. u_char name_len;
  87. /* List of the variables. */
  88. struct variable *variables;
  89. /* Length of the variables list. */
  90. int variables_num;
  91. /* Width of the variables list. */
  92. int variables_width;
  93. /* Registered flag. */
  94. int registered;
  95. };
  96. struct trap_object
  97. {
  98. FindVarMethod *findVar;
  99. int namelen;
  100. oid name[MAX_OID_LEN];
  101. };
  102. /* Declare SMUX return value. */
  103. #define SNMP_LOCAL_VARIABLES \
  104. static long snmp_int_val; \
  105. static struct in_addr snmp_in_addr_val;
  106. #define SNMP_INTEGER(V) \
  107. ( \
  108. *var_len = sizeof (snmp_int_val), \
  109. snmp_int_val = V, \
  110. (u_char *) &snmp_int_val \
  111. )
  112. #define SNMP_IPADDRESS(V) \
  113. ( \
  114. *var_len = sizeof (struct in_addr), \
  115. snmp_in_addr_val = V, \
  116. (u_char *) &snmp_in_addr_val \
  117. )
  118. extern void smux_init (struct thread_master *tm);
  119. extern void smux_start (void);
  120. extern void smux_register_mib(const char *, struct variable *,
  121. size_t, int, oid [], size_t);
  122. extern int smux_header_generic (struct variable *, oid [], size_t *,
  123. int, size_t *, WriteMethod **);
  124. extern int smux_trap (const oid *, size_t, const oid *, size_t,
  125. const struct trap_object *,
  126. size_t, unsigned int, u_char);
  127. extern int oid_compare (oid *, int, oid *, int);
  128. extern void oid2in_addr (oid [], int, struct in_addr *);
  129. extern void *oid_copy (void *, const void *, size_t);
  130. extern void oid_copy_addr (oid [], struct in_addr *, int);
  131. #endif /* _ZEBRA_SNMP_H */