blob: bab3587bc3a7d7c29902841c195c8a9fd5ae1c22 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* 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
22#ifndef _ZEBRA_SNMP_H
23#define _ZEBRA_SNMP_H
24
25#define SMUX_PORT_DEFAULT 199
26
27#define SMUXMAXPKTSIZE 1500
28#define SMUXMAXSTRLEN 256
29
30#define SMUX_OPEN (ASN_APPLICATION | ASN_CONSTRUCTOR | 0)
31#define SMUX_CLOSE (ASN_APPLICATION | ASN_PRIMITIVE | 1)
32#define SMUX_RREQ (ASN_APPLICATION | ASN_CONSTRUCTOR | 2)
33#define SMUX_RRSP (ASN_APPLICATION | ASN_PRIMITIVE | 3)
34#define SMUX_SOUT (ASN_APPLICATION | ASN_PRIMITIVE | 4)
35
36#define SMUX_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0)
37#define SMUX_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 1)
38#define SMUX_GETRSP (ASN_CONTEXT | ASN_CONSTRUCTOR | 2)
39#define SMUX_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 3)
40#define SMUX_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 4)
41
42#define SMUX_MAX_FAILURE 3
43
44/* Structures here are mostly compatible with UCD SNMP 4.1.1 */
45#define MATCH_FAILED (-1)
46#define MATCH_SUCCEEDED 0
47
48/* SYNTAX TruthValue from SNMPv2-TC. */
49#define SNMP_TRUE 1
50#define SNMP_FALSE 2
51
52/* SYNTAX RowStatus from SNMPv2-TC. */
53#define SNMP_VALID 1
54#define SNMP_INVALID 2
55
56#define IN_ADDR_SIZE sizeof(struct in_addr)
57
58struct variable;
59
60#define REGISTER_MIB(descr, var, vartype, theoid) \
61 smux_register_mib(descr, (struct variable *)var, sizeof(struct vartype), \
62 sizeof(var)/sizeof(struct vartype), \
63 theoid, sizeof(theoid)/sizeof(oid))
64
65typedef int (WriteMethod)(int action,
66 u_char *var_val,
67 u_char var_val_type,
68 size_t var_val_len,
69 u_char *statP,
70 oid *name,
71 size_t length,
72 struct variable *v);
73
74typedef u_char *(FindVarMethod)(struct variable *v,
75 oid *name,
76 size_t *length,
77 int exact,
78 size_t *var_len,
79 WriteMethod **write_method);
80
81/* SNMP variable */
82struct variable
83{
84 /* Index of the MIB.*/
85 u_char magic;
86
87 /* Type of variable. */
88 char type;
89
90 /* Access control list. */
91 u_short acl;
92
93 /* Callback function. */
94 FindVarMethod *findVar;
95
96 /* Suffix of the MIB. */
vincent5e4914c2005-09-29 16:34:30 +000097 int namelen;
paul718e3742002-12-13 20:15:29 +000098 oid name[MAX_OID_LEN];
99};
100
101/* SNMP tree. */
102struct subtree
103{
104 /* Tree's oid. */
105 oid name[MAX_OID_LEN];
106 u_char name_len;
107
108 /* List of the variables. */
109 struct variable *variables;
110
111 /* Length of the variables list. */
112 int variables_num;
113
114 /* Width of the variables list. */
115 int variables_width;
116
117 /* Registered flag. */
118 int registered;
119};
120
121struct trap_object
122{
123 FindVarMethod *findVar;
vincent5e4914c2005-09-29 16:34:30 +0000124 int namelen;
paul718e3742002-12-13 20:15:29 +0000125 oid name[MAX_OID_LEN];
126};
127
128/* Declare SMUX return value. */
129#define SNMP_LOCAL_VARIABLES \
Chris Caputo42176e62009-06-02 18:37:11 +0100130 static long snmp_int_val; \
paul718e3742002-12-13 20:15:29 +0000131 static struct in_addr snmp_in_addr_val;
132
133#define SNMP_INTEGER(V) \
134 ( \
Chris Caputo42176e62009-06-02 18:37:11 +0100135 *var_len = sizeof (snmp_int_val), \
paul718e3742002-12-13 20:15:29 +0000136 snmp_int_val = V, \
137 (u_char *) &snmp_int_val \
138 )
139
140#define SNMP_IPADDRESS(V) \
141 ( \
142 *var_len = sizeof (struct in_addr), \
143 snmp_in_addr_val = V, \
144 (u_char *) &snmp_in_addr_val \
145 )
146
paul8cc41982005-05-06 21:25:49 +0000147extern void smux_init (struct thread_master *tm);
148extern void smux_start (void);
149extern void smux_register_mib(const char *, struct variable *,
150 size_t, int, oid [], size_t);
151extern int smux_header_generic (struct variable *, oid [], size_t *,
152 int, size_t *, WriteMethod **);
153extern int smux_trap (oid *, size_t, oid *, size_t, struct trap_object *,
154 size_t, unsigned int, u_char);
155extern int oid_compare (oid *, int, oid *, int);
156extern void oid2in_addr (oid [], int, struct in_addr *);
157extern void *oid_copy (void *, void *, size_t);
158extern void oid_copy_addr (oid [], struct in_addr *, int);
paul718e3742002-12-13 20:15:29 +0000159
160#endif /* _ZEBRA_SNMP_H */