]> git.proxmox.com Git - mirror_frr.git/blob - lib/snmp.c
debianpkg: Remove -werror from Ubuntu 14.04 and 12.04 build to skip warnings from...
[mirror_frr.git] / lib / snmp.c
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 #include <zebra.h>
23
24 #include <net-snmp/net-snmp-config.h>
25 #include <net-snmp/net-snmp-includes.h>
26
27 #include "smux.h"
28
29 #define min(A,B) ((A) < (B) ? (A) : (B))
30
31 int oid_compare(const oid *o1, int o1_len, const oid *o2, int o2_len)
32 {
33 int i;
34
35 for (i = 0; i < min(o1_len, o2_len); i++) {
36 if (o1[i] < o2[i])
37 return -1;
38 else if (o1[i] > o2[i])
39 return 1;
40 }
41 if (o1_len < o2_len)
42 return -1;
43 if (o1_len > o2_len)
44 return 1;
45
46 return 0;
47 }
48
49 void *oid_copy(void *dest, const void *src, size_t size)
50 {
51 return memcpy(dest, src, size * sizeof(oid));
52 }
53
54 void oid2in_addr(oid oid[], int len, struct in_addr *addr)
55 {
56 int i;
57 u_char *pnt;
58
59 if (len == 0)
60 return;
61
62 pnt = (u_char *)addr;
63
64 for (i = 0; i < len; i++)
65 *pnt++ = oid[i];
66 }
67
68 void oid_copy_addr(oid oid[], struct in_addr *addr, int len)
69 {
70 int i;
71 u_char *pnt;
72
73 if (len == 0)
74 return;
75
76 pnt = (u_char *)addr;
77
78 for (i = 0; i < len; i++)
79 oid[i] = *pnt++;
80 }
81
82 int smux_header_generic(struct variable *v, oid *name, size_t *length,
83 int exact, size_t *var_len, WriteMethod **write_method)
84 {
85 oid fulloid[MAX_OID_LEN];
86 int ret;
87
88 oid_copy(fulloid, v->name, v->namelen);
89 fulloid[v->namelen] = 0;
90 /* Check against full instance. */
91 ret = oid_compare(name, *length, fulloid, v->namelen + 1);
92
93 /* Check single instance. */
94 if ((exact && (ret != 0)) || (!exact && (ret >= 0)))
95 return MATCH_FAILED;
96
97 /* In case of getnext, fill in full instance. */
98 memcpy(name, fulloid, (v->namelen + 1) * sizeof(oid));
99 *length = v->namelen + 1;
100
101 *write_method = 0;
102 *var_len = sizeof(long); /* default to 'long' results */
103
104 return MATCH_SUCCEEDED;
105 }
106
107 int smux_header_table(struct variable *v, oid *name, size_t *length, int exact,
108 size_t *var_len, WriteMethod **write_method)
109 {
110 /* If the requested OID name is less than OID prefix we
111 handle, adjust it to our prefix. */
112 if ((oid_compare(name, *length, v->name, v->namelen)) < 0) {
113 if (exact)
114 return MATCH_FAILED;
115 oid_copy(name, v->name, v->namelen);
116 *length = v->namelen;
117 }
118
119 *write_method = 0;
120 *var_len = sizeof(long);
121
122 return MATCH_SUCCEEDED;
123 }