paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
| 22 | #ifndef _ZEBRA_SNMP_H |
| 23 | #define _ZEBRA_SNMP_H |
| 24 | |
Vincent Bernat | 3a4c968 | 2012-05-23 00:52:46 +0200 | [diff] [blame] | 25 | #include <net-snmp/agent/net-snmp-agent-includes.h> |
| 26 | #include <net-snmp/agent/snmp_vars.h> |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 27 | |
David Lamparter | 388f885 | 2015-03-03 08:55:54 +0100 | [diff] [blame] | 28 | #include "thread.h" |
| 29 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 30 | /* Structures here are mostly compatible with UCD SNMP 4.1.1 */ |
| 31 | #define MATCH_FAILED (-1) |
| 32 | #define MATCH_SUCCEEDED 0 |
| 33 | |
| 34 | /* SYNTAX TruthValue from SNMPv2-TC. */ |
| 35 | #define SNMP_TRUE 1 |
| 36 | #define SNMP_FALSE 2 |
| 37 | |
| 38 | /* SYNTAX RowStatus from SNMPv2-TC. */ |
| 39 | #define SNMP_VALID 1 |
| 40 | #define SNMP_INVALID 2 |
| 41 | |
| 42 | #define IN_ADDR_SIZE sizeof(struct in_addr) |
| 43 | |
Vincent Bernat | 3a4c968 | 2012-05-23 00:52:46 +0200 | [diff] [blame] | 44 | #undef REGISTER_MIB |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 45 | #define REGISTER_MIB(descr, var, vartype, theoid) \ |
| 46 | smux_register_mib(descr, (struct variable *)var, sizeof(struct vartype), \ |
| 47 | sizeof(var)/sizeof(struct vartype), \ |
| 48 | theoid, sizeof(theoid)/sizeof(oid)) |
| 49 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 50 | struct trap_object |
| 51 | { |
Vincent Bernat | b8cf46b | 2012-05-25 08:56:44 +0200 | [diff] [blame] | 52 | int namelen; /* Negative if the object is not indexed */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 53 | oid name[MAX_OID_LEN]; |
| 54 | }; |
| 55 | |
| 56 | /* Declare SMUX return value. */ |
| 57 | #define SNMP_LOCAL_VARIABLES \ |
David Lamparter | dfee58f | 2015-03-04 06:44:57 +0100 | [diff] [blame] | 58 | static long snmp_int_val __attribute__ ((unused)); \ |
| 59 | static struct in_addr snmp_in_addr_val __attribute__ ((unused)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 60 | |
| 61 | #define SNMP_INTEGER(V) \ |
| 62 | ( \ |
Chris Caputo | 42176e6 | 2009-06-02 18:37:11 +0100 | [diff] [blame] | 63 | *var_len = sizeof (snmp_int_val), \ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 64 | snmp_int_val = V, \ |
| 65 | (u_char *) &snmp_int_val \ |
| 66 | ) |
| 67 | |
| 68 | #define SNMP_IPADDRESS(V) \ |
| 69 | ( \ |
| 70 | *var_len = sizeof (struct in_addr), \ |
| 71 | snmp_in_addr_val = V, \ |
| 72 | (u_char *) &snmp_in_addr_val \ |
| 73 | ) |
| 74 | |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 75 | extern void smux_init (struct thread_master *tm); |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 76 | extern void smux_register_mib(const char *, struct variable *, |
| 77 | size_t, int, oid [], size_t); |
| 78 | extern int smux_header_generic (struct variable *, oid [], size_t *, |
| 79 | int, size_t *, WriteMethod **); |
Vincent Bernat | 8046ba6 | 2012-05-31 13:30:28 +0200 | [diff] [blame] | 80 | extern int smux_header_table (struct variable *, oid *, size_t *, |
| 81 | int, size_t *, WriteMethod **); |
Vincent Bernat | b7c0d06 | 2012-05-25 11:17:01 +0200 | [diff] [blame] | 82 | |
| 83 | /* For traps, three OID are provided: |
| 84 | |
| 85 | 1. The enterprise OID to use (the last argument will be appended to |
| 86 | it to form the SNMP trap OID) |
| 87 | |
| 88 | 2. The base OID for objects to be sent in traps. |
| 89 | |
| 90 | 3. The index OID for objects to be sent in traps. This index is used |
| 91 | to designate a particular instance of a column. |
| 92 | |
| 93 | The provided trap object contains the bindings to be sent with the |
| 94 | trap. The base OID will be prefixed to the provided OID and, if the |
| 95 | length is positive, the requested OID is assumed to be a columnar |
| 96 | object and the index OID will be appended. |
| 97 | |
| 98 | The two first arguments are the MIB registry used to locate the trap |
| 99 | objects. |
| 100 | |
| 101 | The use of the arguments may differ depending on the implementation |
| 102 | used. |
| 103 | */ |
| 104 | extern int smux_trap (struct variable *, size_t, |
| 105 | const oid *, size_t, |
| 106 | const oid *, size_t, |
| 107 | const oid *, size_t, |
| 108 | const struct trap_object *, size_t, |
| 109 | u_char); |
Vincent Bernat | 3a4c968 | 2012-05-23 00:52:46 +0200 | [diff] [blame] | 110 | |
David Lamparter | dfee58f | 2015-03-04 06:44:57 +0100 | [diff] [blame] | 111 | extern int oid_compare (const oid *, int, const oid *, int); |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 112 | extern void oid2in_addr (oid [], int, struct in_addr *); |
Stephen Hemminger | 65d3fbb | 2009-05-15 09:59:03 -0700 | [diff] [blame] | 113 | extern void *oid_copy (void *, const void *, size_t); |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 114 | extern void oid_copy_addr (oid [], struct in_addr *, int); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 115 | |
| 116 | #endif /* _ZEBRA_SNMP_H */ |