]>
Commit | Line | Data |
---|---|---|
3a4c9688 VB |
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 | * | |
896014f4 DL |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
3a4c9688 VB |
19 | */ |
20 | ||
21 | #include <zebra.h> | |
22 | ||
3a4c9688 VB |
23 | #include <net-snmp/net-snmp-config.h> |
24 | #include <net-snmp/net-snmp-includes.h> | |
25 | ||
26 | #include "smux.h" | |
27 | ||
28 | #define min(A,B) ((A) < (B) ? (A) : (B)) | |
29 | ||
30 | int | |
7e635035 | 31 | oid_compare (const oid *o1, int o1_len, const oid *o2, int o2_len) |
3a4c9688 VB |
32 | { |
33 | int i; | |
34 | ||
35 | for (i = 0; i < min (o1_len, o2_len); i++) | |
36 | { | |
37 | if (o1[i] < o2[i]) | |
38 | return -1; | |
39 | else if (o1[i] > o2[i]) | |
40 | return 1; | |
41 | } | |
42 | if (o1_len < o2_len) | |
43 | return -1; | |
44 | if (o1_len > o2_len) | |
45 | return 1; | |
46 | ||
47 | return 0; | |
48 | } | |
49 | ||
50 | void * | |
51 | oid_copy (void *dest, const void *src, size_t size) | |
52 | { | |
53 | return memcpy (dest, src, size * sizeof (oid)); | |
54 | } | |
55 | ||
56 | void | |
57 | oid2in_addr (oid oid[], int len, struct in_addr *addr) | |
58 | { | |
59 | int i; | |
60 | u_char *pnt; | |
61 | ||
62 | if (len == 0) | |
63 | return; | |
64 | ||
65 | pnt = (u_char *) addr; | |
66 | ||
67 | for (i = 0; i < len; i++) | |
68 | *pnt++ = oid[i]; | |
69 | } | |
70 | ||
71 | void | |
72 | oid_copy_addr (oid oid[], struct in_addr *addr, int len) | |
73 | { | |
74 | int i; | |
75 | u_char *pnt; | |
76 | ||
77 | if (len == 0) | |
78 | return; | |
79 | ||
80 | pnt = (u_char *) addr; | |
81 | ||
82 | for (i = 0; i < len; i++) | |
83 | oid[i] = *pnt++; | |
84 | } | |
85 | ||
86 | int | |
87 | smux_header_generic (struct variable *v, oid *name, size_t *length, int exact, | |
88 | size_t *var_len, WriteMethod **write_method) | |
89 | { | |
90 | oid fulloid[MAX_OID_LEN]; | |
91 | int ret; | |
92 | ||
93 | oid_copy (fulloid, v->name, v->namelen); | |
94 | fulloid[v->namelen] = 0; | |
95 | /* Check against full instance. */ | |
96 | ret = oid_compare (name, *length, fulloid, v->namelen + 1); | |
97 | ||
98 | /* Check single instance. */ | |
99 | if ((exact && (ret != 0)) || (!exact && (ret >= 0))) | |
100 | return MATCH_FAILED; | |
101 | ||
102 | /* In case of getnext, fill in full instance. */ | |
103 | memcpy (name, fulloid, (v->namelen + 1) * sizeof (oid)); | |
104 | *length = v->namelen + 1; | |
105 | ||
106 | *write_method = 0; | |
107 | *var_len = sizeof(long); /* default to 'long' results */ | |
108 | ||
109 | return MATCH_SUCCEEDED; | |
110 | } | |
8046ba6e VB |
111 | |
112 | int | |
113 | smux_header_table (struct variable *v, oid *name, size_t *length, int exact, | |
114 | size_t *var_len, WriteMethod **write_method) | |
115 | { | |
116 | /* If the requested OID name is less than OID prefix we | |
117 | handle, adjust it to our prefix. */ | |
118 | if ((oid_compare (name, *length, v->name, v->namelen)) < 0) | |
119 | { | |
120 | if (exact) | |
121 | return MATCH_FAILED; | |
122 | oid_copy(name, v->name, v->namelen); | |
123 | *length = v->namelen; | |
124 | } | |
125 | ||
126 | *write_method = 0; | |
127 | *var_len = sizeof(long); | |
128 | ||
129 | return MATCH_SUCCEEDED; | |
130 | } |