]>
Commit | Line | Data |
---|---|---|
4b292b55 | 1 | /* -*- mode: c; c-file-style: "openbsd" -*- */ |
43c02e7b VB |
2 | /* |
3 | * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx> | |
4 | * | |
51434125 | 5 | * Permission to use, copy, modify, and/or distribute this software for any |
43c02e7b VB |
6 | * purpose with or without fee is hereby granted, provided that the above |
7 | * copyright notice and this permission notice appear in all copies. | |
8 | * | |
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
16 | */ | |
17 | ||
2eec5540 VB |
18 | #include <assert.h> |
19 | ||
43c02e7b | 20 | #include "lldpd.h" |
4e22da4c | 21 | #include "agent.h" |
fbb9deaa | 22 | #include "frame.h" |
43c02e7b | 23 | |
ab2d1c1f | 24 | #if HAVE_NET_SNMP_AGENT_UTIL_FUNCS_H |
43c02e7b | 25 | #include <net-snmp/agent/util_funcs.h> |
ab2d1c1f | 26 | #else |
26836a43 | 27 | /* The above header may be buggy. We just need this function. */ |
ab2d1c1f VB |
28 | int header_generic(struct variable *, oid *, size_t *, int, |
29 | size_t *, WriteMethod **); | |
30 | #endif | |
43c02e7b | 31 | |
43c02e7b VB |
32 | /* For net-snmp */ |
33 | extern int register_sysORTable(oid *, size_t, const char *); | |
34 | extern int unregister_sysORTable(oid *, size_t); | |
43c02e7b VB |
35 | |
36 | /* Global variable because no way to pass it as argument. Should not be used | |
37 | * elsewhere. */ | |
4e22da4c VB |
38 | #define scfg agent_scfg |
39 | struct lldpd *agent_scfg; | |
43c02e7b VB |
40 | |
41 | static inline uint8_t | |
42 | swap_bits(uint8_t n) | |
43 | { | |
44 | n = ((n&0xF0) >>4 ) | ( (n&0x0F) <<4); | |
45 | n = ((n&0xCC) >>2 ) | ( (n&0x33) <<2); | |
46 | n = ((n&0xAA) >>1 ) | ( (n&0x55) <<1); | |
47 | ||
48 | return n; | |
49 | }; | |
50 | ||
26836a43 VB |
51 | extern struct timeval starttime; |
52 | static long int | |
53 | lastchange(struct lldpd_port *port) | |
54 | { | |
55 | if (port->p_lastchange > starttime.tv_sec) | |
56 | return (port->p_lastchange - starttime.tv_sec)*100; | |
57 | return 0; | |
58 | } | |
59 | ||
60 | /* ------------- | |
61 | Helper functions to build header_*indexed_table() functions. | |
62 | Those functions keep an internal state. They are not reentrant! | |
63 | */ | |
64 | struct header_index { | |
65 | struct variable *vp; | |
66 | oid *name; /* Requested/returned OID */ | |
67 | size_t *length; /* Length of above OID */ | |
68 | int exact; | |
69 | oid best[MAX_OID_LEN]; /* Best OID */ | |
70 | size_t best_len; /* Best OID length */ | |
71 | void *entity; /* Best entity */ | |
72 | }; | |
73 | static struct header_index header_idx; | |
74 | ||
4e22da4c | 75 | static int |
26836a43 | 76 | header_index_init(struct variable *vp, oid *name, size_t *length, |
43c02e7b VB |
77 | int exact, size_t *var_len, WriteMethod **write_method) |
78 | { | |
4e22da4c VB |
79 | /* If the requested OID name is less than OID prefix we |
80 | handle, adjust it to our prefix. */ | |
26836a43 VB |
81 | if ((snmp_oid_compare(name, *length, vp->name, vp->namelen)) < 0) { |
82 | memcpy(name, vp->name, sizeof(oid) * vp->namelen); | |
83 | *length = vp->namelen; | |
84 | } | |
4e22da4c VB |
85 | /* Now, we can only handle OID matching our prefix. Those two |
86 | tests are not really necessary since NetSNMP won't give us | |
87 | OID "above" our prefix. But this makes unit tests | |
88 | easier. */ | |
89 | if (*length < vp->namelen) return 0; | |
90 | if (memcmp(name, vp->name, vp->namelen * sizeof(oid))) return 0; | |
91 | ||
26836a43 VB |
92 | if(write_method != NULL) *write_method = 0; |
93 | *var_len = sizeof(long); | |
94 | ||
95 | /* Initialize our header index structure */ | |
96 | header_idx.vp = vp; | |
97 | header_idx.name = name; | |
98 | header_idx.length = length; | |
99 | header_idx.exact = exact; | |
100 | header_idx.best_len = 0; | |
101 | header_idx.entity = NULL; | |
4e22da4c | 102 | return 1; |
26836a43 VB |
103 | } |
104 | ||
105 | static int | |
106 | header_index_add(oid *index, size_t len, void *entity) | |
107 | { | |
108 | int result; | |
109 | oid *target; | |
110 | size_t target_len; | |
111 | ||
112 | target = header_idx.name + header_idx.vp->namelen; | |
113 | target_len = *header_idx.length - header_idx.vp->namelen; | |
114 | if ((result = snmp_oid_compare(index, len, target, target_len)) < 0) | |
115 | return 0; /* Too small. */ | |
116 | if (result == 0) | |
117 | return header_idx.exact; | |
118 | if (header_idx.best_len == 0 || | |
119 | (snmp_oid_compare(index, len, | |
120 | header_idx.best, | |
121 | header_idx.best_len) < 0)) { | |
122 | memcpy(header_idx.best, index, sizeof(oid) * len); | |
123 | header_idx.best_len = len; | |
124 | header_idx.entity = entity; | |
125 | } | |
126 | return 0; /* No best match yet. */ | |
127 | } | |
43c02e7b | 128 | |
26836a43 VB |
129 | void* |
130 | header_index_best() | |
131 | { | |
132 | if (header_idx.entity == NULL) | |
133 | return NULL; | |
134 | if (header_idx.exact) | |
43c02e7b | 135 | return NULL; |
26836a43 VB |
136 | memcpy(header_idx.name + header_idx.vp->namelen, |
137 | header_idx.best, sizeof(oid) * header_idx.best_len); | |
138 | *header_idx.length = header_idx.vp->namelen + header_idx.best_len; | |
139 | return header_idx.entity; | |
140 | } | |
141 | /* ----------------------------- */ | |
142 | ||
143 | static struct lldpd_hardware* | |
144 | header_portindexed_table(struct variable *vp, oid *name, size_t *length, | |
145 | int exact, size_t *var_len, WriteMethod **write_method) | |
146 | { | |
147 | struct lldpd_hardware *hardware; | |
43c02e7b | 148 | |
4e22da4c | 149 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
43c02e7b | 150 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
26836a43 VB |
151 | oid index[1] = { hardware->h_ifindex }; |
152 | if (header_index_add(index, 1, | |
153 | hardware)) | |
6e75df87 | 154 | return hardware; |
43c02e7b | 155 | } |
26836a43 | 156 | return header_index_best(); |
43c02e7b VB |
157 | } |
158 | ||
fd6aa9a3 | 159 | #ifdef ENABLE_LLDPMED |
26836a43 VB |
160 | static struct lldpd_med_policy* |
161 | header_pmedindexed_policy_table(struct variable *vp, oid *name, size_t *length, | |
162 | int exact, size_t *var_len, WriteMethod **write_method) | |
fd6aa9a3 VB |
163 | { |
164 | struct lldpd_hardware *hardware; | |
26836a43 | 165 | int i; |
5fd6695c | 166 | oid index[2]; |
fd6aa9a3 | 167 | |
4e22da4c | 168 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
26836a43 | 169 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
4b292b55 | 170 | for (i = 0; i < LLDP_MED_APPTYPE_LAST; i++) { |
26836a43 VB |
171 | if (hardware->h_lport.p_med_policy[i].type != i+1) |
172 | continue; | |
5fd6695c VB |
173 | index[0] = hardware->h_ifindex; |
174 | index[1] = i + 1; | |
26836a43 VB |
175 | if (header_index_add(index, 2, |
176 | &hardware->h_lport.p_med_policy[i])) | |
177 | return &hardware->h_lport.p_med_policy[i]; | |
178 | } | |
179 | } | |
180 | return header_index_best(); | |
181 | } | |
fd6aa9a3 | 182 | |
26836a43 VB |
183 | static struct lldpd_med_loc* |
184 | header_pmedindexed_location_table(struct variable *vp, oid *name, size_t *length, | |
185 | int exact, size_t *var_len, WriteMethod **write_method) | |
186 | { | |
187 | struct lldpd_hardware *hardware; | |
188 | int i; | |
5fd6695c | 189 | oid index[2]; |
fd6aa9a3 | 190 | |
4e22da4c | 191 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
fd6aa9a3 | 192 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
4b292b55 | 193 | for (i = 0; i < LLDP_MED_LOCFORMAT_LAST; i++) { |
26836a43 | 194 | if (hardware->h_lport.p_med_location[i].format != i+1) |
fd6aa9a3 | 195 | continue; |
5fd6695c VB |
196 | index[0] = hardware->h_ifindex; |
197 | index[1] = i + 2; | |
26836a43 VB |
198 | if (header_index_add(index, 2, |
199 | &hardware->h_lport.p_med_location[i])) | |
200 | return &hardware->h_lport.p_med_location[i]; | |
fd6aa9a3 VB |
201 | } |
202 | } | |
26836a43 | 203 | return header_index_best(); |
fd6aa9a3 VB |
204 | } |
205 | #endif | |
206 | ||
7a53c5b9 | 207 | static struct lldpd_port* |
43c02e7b | 208 | header_tprindexed_table(struct variable *vp, oid *name, size_t *length, |
077f7601 VB |
209 | int exact, size_t *var_len, WriteMethod **write_method, |
210 | int withmed) | |
43c02e7b | 211 | { |
26836a43 VB |
212 | struct lldpd_hardware *hardware; |
213 | struct lldpd_port *port; | |
5fd6695c | 214 | oid index[3]; |
43c02e7b | 215 | |
4e22da4c | 216 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
26836a43 VB |
217 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
218 | TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { | |
4d1a5b39 | 219 | if (SMART_HIDDEN(port)) continue; |
077f7601 | 220 | if (withmed && !port->p_chassis->c_med_cap_available) continue; |
5fd6695c VB |
221 | index[0] = lastchange(port); |
222 | index[1] = hardware->h_ifindex; | |
223 | index[2] = port->p_chassis->c_index; | |
26836a43 VB |
224 | if (header_index_add(index, 3, |
225 | port)) | |
226 | return port; | |
227 | } | |
228 | } | |
229 | return header_index_best(); | |
230 | } | |
43c02e7b | 231 | |
2eec5540 | 232 | static struct lldpd_mgmt* |
e8c9b6bb VB |
233 | header_ipindexed_table(struct variable *vp, oid *name, size_t *length, |
234 | int exact, size_t *var_len, WriteMethod **write_method) | |
235 | { | |
236 | struct lldpd_chassis *chassis = LOCAL_CHASSIS(scfg); | |
e6b36c87 | 237 | struct lldpd_mgmt *mgmt; |
af3caa3b | 238 | oid index[2 + 16]; |
e8c9b6bb | 239 | |
4e22da4c | 240 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
e6b36c87 | 241 | TAILQ_FOREACH(mgmt, &chassis->c_mgmt, m_entries) { |
af3caa3b VB |
242 | int i; |
243 | switch (mgmt->m_family) { | |
244 | case LLDPD_AF_IPV4: index[0] = 1; break; | |
245 | case LLDPD_AF_IPV6: index[0] = 2; break; | |
246 | default: assert(0); | |
247 | } | |
248 | index[1] = mgmt->m_addrsize; | |
249 | if (index[1] > sizeof(index) - 2) | |
250 | continue; /* Odd... */ | |
251 | for (i = 0; i < index[1]; i++) | |
252 | index[i + 2] = mgmt->m_addr.octets[i]; | |
253 | if (header_index_add(index, 2 + index[1], mgmt)) | |
2eec5540 | 254 | return mgmt; |
e6b36c87 | 255 | } |
e8c9b6bb | 256 | |
e6b36c87 | 257 | return header_index_best(); |
e8c9b6bb VB |
258 | } |
259 | ||
2eec5540 | 260 | static struct lldpd_mgmt* |
26836a43 VB |
261 | header_tpripindexed_table(struct variable *vp, oid *name, size_t *length, |
262 | int exact, size_t *var_len, WriteMethod **write_method) | |
263 | { | |
264 | struct lldpd_hardware *hardware; | |
265 | struct lldpd_port *port; | |
e6b36c87 | 266 | struct lldpd_mgmt *mgmt; |
af3caa3b | 267 | oid index[5 + 16]; |
43c02e7b | 268 | |
4e22da4c | 269 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
26836a43 VB |
270 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
271 | TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { | |
4d1a5b39 | 272 | if (SMART_HIDDEN(port)) continue; |
e6b36c87 | 273 | TAILQ_FOREACH(mgmt, &port->p_chassis->c_mgmt, m_entries) { |
af3caa3b VB |
274 | int i; |
275 | index[0] = lastchange(port); | |
276 | index[1] = hardware->h_ifindex; | |
277 | index[2] = port->p_chassis->c_index; | |
278 | switch (mgmt->m_family) { | |
279 | case LLDPD_AF_IPV4: index[3] = 1; break; | |
280 | case LLDPD_AF_IPV6: index[3] = 2; break; | |
281 | default: assert(0); | |
282 | } | |
283 | index[4] = mgmt->m_addrsize; | |
284 | if (index[4] > sizeof(index) - 5) | |
285 | continue; /* Odd... */ | |
286 | for (i = 0; i < index[4]; i++) | |
287 | index[i + 5] = mgmt->m_addr.octets[i]; | |
288 | if (header_index_add(index, 5 + index[4], mgmt)) | |
2eec5540 | 289 | return mgmt; |
e6b36c87 | 290 | } |
26836a43 VB |
291 | } |
292 | } | |
293 | return header_index_best(); | |
294 | } | |
295 | ||
296 | #define TPR_VARIANT_MED_POLICY 2 | |
297 | #define TPR_VARIANT_MED_LOCATION 3 | |
077f7601 | 298 | static void* |
26836a43 VB |
299 | header_tprmedindexed_table(struct variable *vp, oid *name, size_t *length, |
300 | int exact, size_t *var_len, WriteMethod **write_method, int variant) | |
301 | { | |
302 | struct lldpd_hardware *hardware; | |
303 | struct lldpd_port *port; | |
304 | int j; | |
5fd6695c | 305 | oid index[4]; |
26836a43 | 306 | |
4e22da4c | 307 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
43c02e7b | 308 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
7a53c5b9 | 309 | TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { |
4d1a5b39 | 310 | if (SMART_HIDDEN(port)) continue; |
077f7601 | 311 | if (!port->p_chassis->c_med_cap_available) continue; |
4a2acc8e | 312 | switch (variant) { |
4a2acc8e | 313 | case TPR_VARIANT_MED_POLICY: |
26836a43 | 314 | for (j = 0; |
4b292b55 | 315 | j < LLDP_MED_APPTYPE_LAST; |
26836a43 VB |
316 | j++) { |
317 | if (port->p_med_policy[j].type != j+1) | |
318 | continue; | |
5fd6695c VB |
319 | index[0] = lastchange(port); |
320 | index[1] = hardware->h_ifindex; | |
321 | index[2] = port->p_chassis->c_index; | |
322 | index[3] = j+1; | |
26836a43 | 323 | if (header_index_add(index, 4, |
077f7601 | 324 | &port->p_med_policy[j])) |
4e22da4c | 325 | return &port->p_med_policy[j]; |
26836a43 | 326 | } |
4a2acc8e VB |
327 | break; |
328 | case TPR_VARIANT_MED_LOCATION: | |
26836a43 | 329 | for (j = 0; |
4b292b55 | 330 | j < LLDP_MED_LOCFORMAT_LAST; |
26836a43 VB |
331 | j++) { |
332 | if (port->p_med_location[j].format != j+1) | |
333 | continue; | |
5fd6695c VB |
334 | index[0] = lastchange(port); |
335 | index[1] = hardware->h_ifindex; | |
336 | index[2] = port->p_chassis->c_index; | |
337 | index[3] = j+2; | |
26836a43 | 338 | if (header_index_add(index, 4, |
077f7601 | 339 | &port->p_med_location[j])) |
4e22da4c | 340 | return &port->p_med_location[j]; |
26836a43 | 341 | } |
4a2acc8e | 342 | break; |
4a2acc8e | 343 | } |
43c02e7b VB |
344 | } |
345 | } | |
26836a43 | 346 | return header_index_best(); |
43c02e7b VB |
347 | } |
348 | ||
a1347cd8 | 349 | #ifdef ENABLE_DOT1 |
8888d191 | 350 | static struct lldpd_vlan* |
43c02e7b VB |
351 | header_pvindexed_table(struct variable *vp, oid *name, size_t *length, |
352 | int exact, size_t *var_len, WriteMethod **write_method) | |
353 | { | |
354 | struct lldpd_hardware *hardware; | |
26836a43 | 355 | struct lldpd_vlan *vlan; |
43c02e7b | 356 | |
4e22da4c | 357 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
43c02e7b | 358 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
6e75df87 | 359 | TAILQ_FOREACH(vlan, &hardware->h_lport.p_vlans, v_entries) { |
26836a43 VB |
360 | oid index[2] = { hardware->h_ifindex, |
361 | vlan->v_vid }; | |
362 | if (header_index_add(index, 2, vlan)) | |
6e75df87 | 363 | return vlan; |
43c02e7b VB |
364 | } |
365 | } | |
26836a43 | 366 | return header_index_best(); |
43c02e7b VB |
367 | } |
368 | ||
8888d191 | 369 | static struct lldpd_vlan* |
43c02e7b VB |
370 | header_tprvindexed_table(struct variable *vp, oid *name, size_t *length, |
371 | int exact, size_t *var_len, WriteMethod **write_method) | |
372 | { | |
373 | struct lldpd_hardware *hardware; | |
7a53c5b9 | 374 | struct lldpd_port *port; |
26836a43 | 375 | struct lldpd_vlan *vlan; |
43c02e7b | 376 | |
4e22da4c | 377 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
43c02e7b | 378 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
7a53c5b9 | 379 | TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { |
4d1a5b39 | 380 | if (SMART_HIDDEN(port)) continue; |
7a53c5b9 | 381 | TAILQ_FOREACH(vlan, &port->p_vlans, v_entries) { |
26836a43 VB |
382 | oid index[4] = { lastchange(port), |
383 | hardware->h_ifindex, | |
384 | port->p_chassis->c_index, | |
385 | vlan->v_vid }; | |
386 | if (header_index_add(index, 4, | |
387 | vlan)) | |
388 | return vlan; | |
389 | } | |
43c02e7b VB |
390 | } |
391 | } | |
26836a43 | 392 | return header_index_best(); |
43c02e7b | 393 | } |
26836a43 | 394 | |
dccc6964 VB |
395 | static struct lldpd_ppvid* |
396 | header_pppvidindexed_table(struct variable *vp, oid *name, size_t *length, | |
397 | int exact, size_t *var_len, WriteMethod **write_method) | |
398 | { | |
399 | struct lldpd_hardware *hardware; | |
26836a43 | 400 | struct lldpd_ppvid *ppvid; |
dccc6964 | 401 | |
4e22da4c | 402 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
dccc6964 VB |
403 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
404 | TAILQ_FOREACH(ppvid, &hardware->h_lport.p_ppvids, p_entries) { | |
26836a43 VB |
405 | oid index[2] = { hardware->h_ifindex, |
406 | ppvid->p_ppvid }; | |
407 | if (header_index_add(index, 2, | |
408 | ppvid)) | |
dccc6964 | 409 | return ppvid; |
dccc6964 VB |
410 | } |
411 | } | |
26836a43 | 412 | return header_index_best(); |
dccc6964 | 413 | } |
26836a43 | 414 | |
dccc6964 VB |
415 | static struct lldpd_ppvid* |
416 | header_tprppvidindexed_table(struct variable *vp, oid *name, size_t *length, | |
417 | int exact, size_t *var_len, WriteMethod **write_method) | |
418 | { | |
419 | struct lldpd_hardware *hardware; | |
420 | struct lldpd_port *port; | |
26836a43 | 421 | struct lldpd_ppvid *ppvid; |
dccc6964 | 422 | |
4e22da4c | 423 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
dccc6964 VB |
424 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
425 | TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { | |
4d1a5b39 | 426 | if (SMART_HIDDEN(port)) continue; |
dccc6964 | 427 | TAILQ_FOREACH(ppvid, &port->p_ppvids, p_entries) { |
26836a43 VB |
428 | oid index[4] = { lastchange(port), |
429 | hardware->h_ifindex, | |
430 | port->p_chassis->c_index, | |
431 | ppvid->p_ppvid }; | |
432 | if (header_index_add(index, 4, | |
433 | ppvid)) | |
434 | return ppvid; | |
dccc6964 VB |
435 | } |
436 | } | |
437 | } | |
26836a43 | 438 | return header_index_best(); |
dccc6964 | 439 | } |
26836a43 | 440 | |
fbb9deaa VB |
441 | static struct lldpd_pi* |
442 | header_ppiindexed_table(struct variable *vp, oid *name, size_t *length, | |
443 | int exact, size_t *var_len, WriteMethod **write_method) | |
444 | { | |
445 | struct lldpd_hardware *hardware; | |
26836a43 | 446 | struct lldpd_pi *pi; |
fbb9deaa | 447 | |
4e22da4c | 448 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
fbb9deaa VB |
449 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
450 | TAILQ_FOREACH(pi, &hardware->h_lport.p_pids, p_entries) { | |
26836a43 VB |
451 | oid index[2] = { hardware->h_ifindex, |
452 | frame_checksum((const u_char*)pi->p_pi, | |
453 | pi->p_pi_len, 0) }; | |
454 | if (header_index_add(index, 2, | |
455 | pi)) | |
fbb9deaa | 456 | return pi; |
fbb9deaa VB |
457 | } |
458 | } | |
26836a43 | 459 | return header_index_best(); |
fbb9deaa | 460 | } |
26836a43 | 461 | |
fbb9deaa VB |
462 | static struct lldpd_pi* |
463 | header_tprpiindexed_table(struct variable *vp, oid *name, size_t *length, | |
464 | int exact, size_t *var_len, WriteMethod **write_method) | |
465 | { | |
466 | struct lldpd_hardware *hardware; | |
467 | struct lldpd_port *port; | |
26836a43 | 468 | struct lldpd_pi *pi; |
fbb9deaa | 469 | |
4e22da4c | 470 | if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; |
fbb9deaa VB |
471 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
472 | TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { | |
4d1a5b39 | 473 | if (SMART_HIDDEN(port)) continue; |
fbb9deaa | 474 | TAILQ_FOREACH(pi, &port->p_pids, p_entries) { |
26836a43 VB |
475 | oid index[4] = { lastchange(port), |
476 | hardware->h_ifindex, | |
477 | port->p_chassis->c_index, | |
478 | frame_checksum((const u_char *)pi->p_pi, | |
479 | pi->p_pi_len, 0) }; | |
480 | if (header_index_add(index, 4, | |
481 | pi)) | |
482 | return pi; | |
fbb9deaa VB |
483 | } |
484 | } | |
485 | } | |
26836a43 | 486 | return header_index_best(); |
fbb9deaa | 487 | } |
a1347cd8 | 488 | #endif |
43c02e7b VB |
489 | |
490 | /* Scalars */ | |
491 | #define LLDP_SNMP_TXINTERVAL 1 | |
492 | #define LLDP_SNMP_TXMULTIPLIER 2 | |
493 | #define LLDP_SNMP_REINITDELAY 3 | |
494 | #define LLDP_SNMP_TXDELAY 4 | |
495 | #define LLDP_SNMP_NOTIFICATION 5 | |
496 | #define LLDP_SNMP_LASTUPDATE 6 | |
497 | #define LLDP_SNMP_STATS_INSERTS 7 | |
498 | #define LLDP_SNMP_STATS_DELETES 8 | |
499 | #define LLDP_SNMP_STATS_DROPS 9 | |
500 | #define LLDP_SNMP_STATS_AGEOUTS 10 | |
f645906c VB |
501 | /* Chassis */ |
502 | #define LLDP_SNMP_CIDSUBTYPE 1 | |
503 | #define LLDP_SNMP_CID 2 | |
504 | #define LLDP_SNMP_SYSNAME 3 | |
505 | #define LLDP_SNMP_SYSDESCR 4 | |
506 | #define LLDP_SNMP_SYSCAP_SUP 5 | |
507 | #define LLDP_SNMP_SYSCAP_ENA 6 | |
43c02e7b | 508 | /* Stats */ |
43c02e7b | 509 | #define LLDP_SNMP_STATS_TX 2 |
43c02e7b VB |
510 | #define LLDP_SNMP_STATS_RX_DISCARDED 4 |
511 | #define LLDP_SNMP_STATS_RX_ERRORS 5 | |
512 | #define LLDP_SNMP_STATS_RX 6 | |
513 | #define LLDP_SNMP_STATS_RX_TLVDISCARDED 7 | |
514 | #define LLDP_SNMP_STATS_RX_TLVUNRECOGNIZED 8 | |
515 | #define LLDP_SNMP_STATS_RX_AGEOUTS 9 | |
14e9519e | 516 | /* Ports */ |
14e9519e VB |
517 | #define LLDP_SNMP_PIDSUBTYPE 2 |
518 | #define LLDP_SNMP_PID 3 | |
519 | #define LLDP_SNMP_PORTDESC 4 | |
520 | #define LLDP_SNMP_DOT3_AUTONEG_SUPPORT 5 | |
521 | #define LLDP_SNMP_DOT3_AUTONEG_ENABLED 6 | |
522 | #define LLDP_SNMP_DOT3_AUTONEG_ADVERTISED 7 | |
523 | #define LLDP_SNMP_DOT3_AUTONEG_MAU 8 | |
524 | #define LLDP_SNMP_DOT3_AGG_STATUS 9 | |
525 | #define LLDP_SNMP_DOT3_AGG_ID 10 | |
526 | #define LLDP_SNMP_DOT3_MFS 11 | |
527 | #define LLDP_SNMP_DOT3_POWER_DEVICETYPE 12 | |
528 | #define LLDP_SNMP_DOT3_POWER_SUPPORT 13 | |
529 | #define LLDP_SNMP_DOT3_POWER_ENABLED 14 | |
530 | #define LLDP_SNMP_DOT3_POWER_PAIRCONTROL 15 | |
531 | #define LLDP_SNMP_DOT3_POWER_PAIRS 16 | |
532 | #define LLDP_SNMP_DOT3_POWER_CLASS 17 | |
533 | #define LLDP_SNMP_DOT3_POWER_TYPE 18 | |
534 | #define LLDP_SNMP_DOT3_POWER_SOURCE 19 | |
535 | #define LLDP_SNMP_DOT3_POWER_PRIORITY 20 | |
536 | #define LLDP_SNMP_DOT3_POWER_REQUESTED 21 | |
537 | #define LLDP_SNMP_DOT3_POWER_ALLOCATED 22 | |
538 | #define LLDP_SNMP_DOT1_PVID 23 | |
f645906c VB |
539 | /* Vlans */ |
540 | #define LLDP_SNMP_DOT1_VLANNAME 1 | |
f645906c | 541 | /* Protocol VLAN IDs */ |
f645906c VB |
542 | #define LLDP_SNMP_DOT1_PPVLAN_SUPPORTED 2 |
543 | #define LLDP_SNMP_DOT1_PPVLAN_ENABLED 3 | |
544 | /* Protocol Identity */ | |
545 | #define LLDP_SNMP_DOT1_PI 1 | |
43c02e7b | 546 | /* Management address */ |
f645906c VB |
547 | #define LLDP_SNMP_ADDR_LEN 1 |
548 | #define LLDP_SNMP_ADDR_IFSUBTYPE 2 | |
549 | #define LLDP_SNMP_ADDR_IFID 3 | |
550 | #define LLDP_SNMP_ADDR_OID 4 | |
077f7601 VB |
551 | /* LLDP-MED */ |
552 | #define LLDP_SNMP_MED_CAP_AVAILABLE 1 | |
553 | #define LLDP_SNMP_MED_CAP_ENABLED 2 | |
554 | #define LLDP_SNMP_MED_CLASS 3 | |
555 | #define LLDP_SNMP_MED_HW 4 | |
556 | #define LLDP_SNMP_MED_FW 5 | |
557 | #define LLDP_SNMP_MED_SW 6 | |
558 | #define LLDP_SNMP_MED_SN 7 | |
559 | #define LLDP_SNMP_MED_MANUF 8 | |
560 | #define LLDP_SNMP_MED_MODEL 9 | |
561 | #define LLDP_SNMP_MED_ASSET 10 | |
562 | #define LLDP_SNMP_MED_POLICY_VID 11 | |
563 | #define LLDP_SNMP_MED_POLICY_PRIO 12 | |
564 | #define LLDP_SNMP_MED_POLICY_DSCP 13 | |
565 | #define LLDP_SNMP_MED_POLICY_UNKNOWN 14 | |
566 | #define LLDP_SNMP_MED_POLICY_TAGGED 15 | |
567 | #define LLDP_SNMP_MED_LOCATION 16 | |
8e44f2dc VB |
568 | #define LLDP_SNMP_MED_POE_DEVICETYPE 17 |
569 | #define LLDP_SNMP_MED_POE_PSE_POWERVAL 19 | |
570 | #define LLDP_SNMP_MED_POE_PSE_POWERSOURCE 20 | |
571 | #define LLDP_SNMP_MED_POE_PSE_POWERPRIORITY 21 | |
572 | #define LLDP_SNMP_MED_POE_PD_POWERVAL 22 | |
573 | #define LLDP_SNMP_MED_POE_PD_POWERSOURCE 23 | |
574 | #define LLDP_SNMP_MED_POE_PD_POWERPRIORITY 24 | |
43c02e7b | 575 | |
51c72e72 VB |
576 | /* The following macro should be used anytime where the selected OID |
577 | is finally not returned (for example, when the associated data is | |
578 | not available). In this case, we retry the function with the next | |
579 | OID. */ | |
580 | #define TRYNEXT(X) \ | |
581 | do { \ | |
582 | if (!exact && (name[*length-1] < MAX_SUBID)) \ | |
583 | return X(vp, name, length, \ | |
584 | exact, var_len, write_method); \ | |
585 | return NULL; \ | |
586 | } while (0) | |
587 | ||
588 | ||
43c02e7b VB |
589 | static u_char* |
590 | agent_h_scalars(struct variable *vp, oid *name, size_t *length, | |
591 | int exact, size_t *var_len, WriteMethod **write_method) | |
592 | { | |
593 | static unsigned long long_ret; | |
594 | struct lldpd_hardware *hardware; | |
7a53c5b9 | 595 | struct lldpd_port *port; |
43c02e7b VB |
596 | |
597 | if (header_generic(vp, name, length, exact, var_len, write_method)) | |
598 | return NULL; | |
599 | ||
600 | switch (vp->magic) { | |
601 | case LLDP_SNMP_TXINTERVAL: | |
602 | long_ret = scfg->g_delay; | |
603 | return (u_char *)&long_ret; | |
604 | case LLDP_SNMP_TXMULTIPLIER: | |
7a53c5b9 | 605 | long_ret = LOCAL_CHASSIS(scfg)->c_ttl / scfg->g_delay; |
43c02e7b VB |
606 | return (u_char *)&long_ret; |
607 | case LLDP_SNMP_REINITDELAY: | |
608 | long_ret = 1; | |
609 | return (u_char *)&long_ret; | |
610 | case LLDP_SNMP_TXDELAY: | |
611 | long_ret = LLDPD_TX_MSGDELAY; | |
612 | return (u_char *)&long_ret; | |
613 | case LLDP_SNMP_NOTIFICATION: | |
614 | long_ret = 5; | |
615 | return (u_char *)&long_ret; | |
616 | case LLDP_SNMP_LASTUPDATE: | |
617 | long_ret = 0; | |
618 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) | |
42b39485 | 619 | TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { |
4d1a5b39 | 620 | if (SMART_HIDDEN(port)) continue; |
7a53c5b9 VB |
621 | if (port->p_lastchange > long_ret) |
622 | long_ret = port->p_lastchange; | |
42b39485 | 623 | } |
43c02e7b VB |
624 | if (long_ret) |
625 | long_ret = (long_ret - starttime.tv_sec) * 100; | |
626 | return (u_char *)&long_ret; | |
627 | case LLDP_SNMP_STATS_INSERTS: | |
628 | /* We assume this is equal to valid frames received on all ports */ | |
629 | long_ret = 0; | |
630 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) | |
631 | long_ret += hardware->h_rx_cnt; | |
632 | return (u_char *)&long_ret; | |
633 | case LLDP_SNMP_STATS_AGEOUTS: | |
634 | long_ret = 0; | |
635 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) | |
636 | long_ret += hardware->h_rx_ageout_cnt; | |
637 | return (u_char *)&long_ret; | |
638 | case LLDP_SNMP_STATS_DELETES: | |
639 | long_ret = 0; | |
640 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) | |
641 | long_ret += hardware->h_rx_ageout_cnt + | |
642 | hardware->h_rx_cnt?(hardware->h_rx_cnt - 1):0; | |
643 | return (u_char *)&long_ret; | |
644 | case LLDP_SNMP_STATS_DROPS: | |
645 | /* We assume that we never have insufficient resources */ | |
646 | long_ret = 0; | |
647 | return (u_char *)&long_ret; | |
648 | default: | |
649 | break; | |
51c72e72 VB |
650 | } |
651 | return NULL; | |
43c02e7b VB |
652 | } |
653 | ||
1d88c843 | 654 | #ifdef ENABLE_LLDPMED |
f645906c VB |
655 | static u_char* |
656 | agent_v_med_power(struct variable *vp, size_t *var_len, struct lldpd_med_power *power) | |
8e44f2dc | 657 | { |
f645906c | 658 | static unsigned long long_ret; |
8e44f2dc VB |
659 | |
660 | switch (vp->magic) { | |
661 | case LLDP_SNMP_MED_POE_DEVICETYPE: | |
662 | switch (power->devicetype) { | |
4b292b55 | 663 | case LLDP_MED_POW_TYPE_PSE: |
8e44f2dc | 664 | long_ret = 2; break; |
4b292b55 | 665 | case LLDP_MED_POW_TYPE_PD: |
8e44f2dc VB |
666 | long_ret = 3; break; |
667 | case 0: | |
668 | long_ret = 4; break; | |
669 | default: | |
670 | long_ret = 1; | |
671 | } | |
f645906c | 672 | return (u_char *)&long_ret; |
8e44f2dc VB |
673 | case LLDP_SNMP_MED_POE_PSE_POWERVAL: |
674 | case LLDP_SNMP_MED_POE_PD_POWERVAL: | |
675 | if (((vp->magic == LLDP_SNMP_MED_POE_PSE_POWERVAL) && | |
676 | (power->devicetype == | |
4b292b55 | 677 | LLDP_MED_POW_TYPE_PSE)) || |
8e44f2dc VB |
678 | ((vp->magic == LLDP_SNMP_MED_POE_PD_POWERVAL) && |
679 | (power->devicetype == | |
4b292b55 | 680 | LLDP_MED_POW_TYPE_PD))) { |
8e44f2dc | 681 | long_ret = power->val; |
f645906c | 682 | return (u_char *)&long_ret; |
8e44f2dc VB |
683 | } |
684 | break; | |
685 | case LLDP_SNMP_MED_POE_PSE_POWERSOURCE: | |
686 | if (power->devicetype == | |
4b292b55 | 687 | LLDP_MED_POW_TYPE_PSE) { |
8e44f2dc | 688 | switch (power->source) { |
4b292b55 | 689 | case LLDP_MED_POW_SOURCE_PRIMARY: |
8e44f2dc | 690 | long_ret = 2; break; |
4b292b55 | 691 | case LLDP_MED_POW_SOURCE_BACKUP: |
8e44f2dc VB |
692 | long_ret = 3; break; |
693 | default: | |
694 | long_ret = 1; | |
695 | } | |
f645906c | 696 | return (u_char *)&long_ret; |
8e44f2dc VB |
697 | } |
698 | break; | |
699 | case LLDP_SNMP_MED_POE_PD_POWERSOURCE: | |
700 | if (power->devicetype == | |
4b292b55 | 701 | LLDP_MED_POW_TYPE_PD) { |
8e44f2dc | 702 | switch (power->source) { |
4b292b55 | 703 | case LLDP_MED_POW_SOURCE_PSE: |
8e44f2dc | 704 | long_ret = 2; break; |
4b292b55 | 705 | case LLDP_MED_POW_SOURCE_LOCAL: |
8e44f2dc | 706 | long_ret = 3; break; |
4b292b55 | 707 | case LLDP_MED_POW_SOURCE_BOTH: |
8e44f2dc VB |
708 | long_ret = 4; break; |
709 | default: | |
710 | long_ret = 1; | |
711 | } | |
f645906c | 712 | return (u_char *)&long_ret; |
8e44f2dc VB |
713 | } |
714 | break; | |
715 | case LLDP_SNMP_MED_POE_PSE_POWERPRIORITY: | |
716 | case LLDP_SNMP_MED_POE_PD_POWERPRIORITY: | |
717 | if (((vp->magic == LLDP_SNMP_MED_POE_PSE_POWERPRIORITY) && | |
718 | (power->devicetype == | |
4b292b55 | 719 | LLDP_MED_POW_TYPE_PSE)) || |
8e44f2dc VB |
720 | ((vp->magic == LLDP_SNMP_MED_POE_PD_POWERPRIORITY) && |
721 | (power->devicetype == | |
4b292b55 | 722 | LLDP_MED_POW_TYPE_PD))) { |
8e44f2dc | 723 | switch (power->priority) { |
4b292b55 | 724 | case LLDP_MED_POW_PRIO_CRITICAL: |
8e44f2dc | 725 | long_ret = 2; break; |
4b292b55 | 726 | case LLDP_MED_POW_PRIO_HIGH: |
8e44f2dc | 727 | long_ret = 3; break; |
4b292b55 | 728 | case LLDP_MED_POW_PRIO_LOW: |
8e44f2dc VB |
729 | long_ret = 4; break; |
730 | default: | |
731 | long_ret = 1; | |
732 | } | |
f645906c | 733 | return (u_char *)&long_ret; |
8e44f2dc VB |
734 | } |
735 | break; | |
736 | } | |
737 | ||
f645906c | 738 | return NULL; |
8e44f2dc | 739 | } |
1d88c843 | 740 | static u_char* |
077f7601 | 741 | agent_h_local_med_power(struct variable *vp, oid *name, size_t *length, |
1d88c843 VB |
742 | int exact, size_t *var_len, WriteMethod **write_method) |
743 | { | |
5fd6695c VB |
744 | struct lldpd_med_power *power = NULL; |
745 | struct lldpd_hardware *hardware; | |
746 | int pse = 0; | |
747 | ||
7a53c5b9 | 748 | if (!LOCAL_CHASSIS(scfg)->c_med_cap_available) |
1d88c843 | 749 | return NULL; |
4a2acc8e | 750 | if (header_generic(vp, name, length, exact, var_len, write_method)) |
1d88c843 VB |
751 | return NULL; |
752 | ||
077f7601 VB |
753 | /* LLDP-MED requires only one device type for all |
754 | ports. Moreover, a PSE can only have one power source. At | |
755 | least, all PD values are global and not per-port. We try to | |
756 | do our best. For device type, we decide on the number of | |
757 | PD/PSE ports. */ | |
077f7601 VB |
758 | TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { |
759 | if (hardware->h_lport.p_med_power.devicetype == | |
4b292b55 | 760 | LLDP_MED_POW_TYPE_PSE) { |
077f7601 VB |
761 | pse++; |
762 | if (pse == 1) /* Take this port as a reference */ | |
763 | power = &hardware->h_lport.p_med_power; | |
764 | } else if (hardware->h_lport.p_med_power.devicetype == | |
4b292b55 | 765 | LLDP_MED_POW_TYPE_PD) { |
077f7601 VB |
766 | pse--; |
767 | if (pse == -1) /* Take this one instead */ | |
768 | power = &hardware->h_lport.p_med_power; | |
8e44f2dc | 769 | } |
077f7601 VB |
770 | } |
771 | if (power) { | |
f645906c VB |
772 | u_char *a; |
773 | if ((a = agent_v_med_power(vp, var_len, power)) != NULL) | |
774 | return a; | |
1dcd4665 | 775 | } |
077f7601 | 776 | TRYNEXT(agent_h_local_med_power); |
1dcd4665 | 777 | } |
8e44f2dc | 778 | static u_char* |
077f7601 | 779 | agent_h_remote_med_power(struct variable *vp, oid *name, size_t *length, |
8e44f2dc VB |
780 | int exact, size_t *var_len, WriteMethod **write_method) |
781 | { | |
077f7601 | 782 | struct lldpd_port *port; |
5fd6695c | 783 | u_char *a; |
8e44f2dc | 784 | |
077f7601 VB |
785 | if ((port = header_tprindexed_table(vp, name, length, |
786 | exact, var_len, write_method, 1)) == NULL) | |
8e44f2dc | 787 | return NULL; |
8e44f2dc | 788 | |
077f7601 | 789 | if ((a = agent_v_med_power(vp, var_len, &port->p_med_power)) != NULL) |
f645906c | 790 | return a; |
077f7601 | 791 | TRYNEXT(agent_h_remote_med_power); |
8e44f2dc VB |
792 | } |
793 | ||
1d88c843 | 794 | static u_char* |
077f7601 VB |
795 | agent_v_med(struct variable *vp, size_t *var_len, |
796 | struct lldpd_chassis *chassis, | |
797 | struct lldpd_port *port) | |
1d88c843 | 798 | { |
1d88c843 | 799 | static unsigned long long_ret; |
077f7601 | 800 | static uint8_t bit; |
1d88c843 VB |
801 | |
802 | switch (vp->magic) { | |
077f7601 VB |
803 | case LLDP_SNMP_MED_CLASS: |
804 | long_ret = chassis->c_med_type; | |
1be9e1b5 | 805 | return (u_char *)&long_ret; |
077f7601 | 806 | case LLDP_SNMP_MED_CAP_AVAILABLE: |
1d88c843 | 807 | *var_len = 1; |
077f7601 | 808 | bit = swap_bits(chassis->c_med_cap_available); |
40ecae87 | 809 | return (u_char *)&bit; |
077f7601 VB |
810 | case LLDP_SNMP_MED_CAP_ENABLED: |
811 | if (!port) break; | |
40ecae87 | 812 | *var_len = 1; |
7a53c5b9 | 813 | bit = swap_bits(port->p_med_cap_enabled); |
1d88c843 | 814 | return (u_char *)&bit; |
8e44f2dc | 815 | |
077f7601 | 816 | #define LLDP_H_MED(magic, variable) \ |
1d88c843 | 817 | case magic: \ |
077f7601 | 818 | if (chassis->variable) { \ |
1d88c843 | 819 | *var_len = strlen( \ |
077f7601 | 820 | chassis->variable); \ |
1d88c843 | 821 | return (u_char *) \ |
077f7601 | 822 | chassis->variable; \ |
1d88c843 VB |
823 | } \ |
824 | break | |
825 | ||
077f7601 | 826 | LLDP_H_MED(LLDP_SNMP_MED_HW, |
1d88c843 | 827 | c_med_hw); |
077f7601 | 828 | LLDP_H_MED(LLDP_SNMP_MED_SW, |
1d88c843 | 829 | c_med_sw); |
077f7601 | 830 | LLDP_H_MED(LLDP_SNMP_MED_FW, |
1d88c843 | 831 | c_med_fw); |
077f7601 | 832 | LLDP_H_MED(LLDP_SNMP_MED_SN, |
1d88c843 | 833 | c_med_sn); |
077f7601 | 834 | LLDP_H_MED(LLDP_SNMP_MED_MANUF, |
1d88c843 | 835 | c_med_manuf); |
077f7601 | 836 | LLDP_H_MED(LLDP_SNMP_MED_MODEL, |
1d88c843 | 837 | c_med_model); |
077f7601 | 838 | LLDP_H_MED(LLDP_SNMP_MED_ASSET, |
1d88c843 VB |
839 | c_med_asset); |
840 | ||
1d88c843 | 841 | } |
077f7601 VB |
842 | return NULL; |
843 | } | |
844 | static u_char* | |
845 | agent_h_local_med(struct variable *vp, oid *name, size_t *length, | |
846 | int exact, size_t *var_len, WriteMethod **write_method) | |
847 | { | |
5fd6695c VB |
848 | u_char *a; |
849 | ||
077f7601 VB |
850 | if (!LOCAL_CHASSIS(scfg)->c_med_cap_available) |
851 | return NULL; | |
852 | if (header_generic(vp, name, length, exact, var_len, write_method)) | |
853 | return NULL; | |
854 | ||
077f7601 VB |
855 | if ((a = agent_v_med(vp, var_len, |
856 | LOCAL_CHASSIS(scfg), NULL)) != NULL) | |
857 | return a; | |
858 | TRYNEXT(agent_h_local_med); | |
1d88c843 | 859 | } |
4a2acc8e VB |
860 | |
861 | static u_char* | |
077f7601 | 862 | agent_h_remote_med(struct variable *vp, oid *name, size_t *length, |
4a2acc8e VB |
863 | int exact, size_t *var_len, WriteMethod **write_method) |
864 | { | |
7a53c5b9 | 865 | struct lldpd_port *port; |
5fd6695c | 866 | u_char *a; |
4a2acc8e | 867 | |
077f7601 VB |
868 | if ((port = header_tprindexed_table(vp, name, length, |
869 | exact, var_len, write_method, 1)) == NULL) | |
4a2acc8e VB |
870 | return NULL; |
871 | ||
077f7601 VB |
872 | if ((a = agent_v_med(vp, var_len, |
873 | port->p_chassis, port)) != NULL) | |
874 | return a; | |
875 | TRYNEXT(agent_h_remote_med); | |
876 | } | |
4a2acc8e | 877 | |
077f7601 VB |
878 | static u_char* |
879 | agent_v_med_policy(struct variable *vp, size_t *var_len, | |
880 | struct lldpd_med_policy *policy) | |
881 | { | |
882 | static unsigned long long_ret; | |
4a2acc8e VB |
883 | |
884 | switch (vp->magic) { | |
077f7601 | 885 | case LLDP_SNMP_MED_POLICY_VID: |
4a2acc8e VB |
886 | long_ret = policy->vid; |
887 | return (u_char *)&long_ret; | |
077f7601 | 888 | case LLDP_SNMP_MED_POLICY_PRIO: |
4a2acc8e VB |
889 | long_ret = policy->priority; |
890 | return (u_char *)&long_ret; | |
077f7601 | 891 | case LLDP_SNMP_MED_POLICY_DSCP: |
4a2acc8e VB |
892 | long_ret = policy->dscp; |
893 | return (u_char *)&long_ret; | |
077f7601 | 894 | case LLDP_SNMP_MED_POLICY_UNKNOWN: |
4a2acc8e VB |
895 | long_ret = policy->unknown?1:2; |
896 | return (u_char *)&long_ret; | |
077f7601 | 897 | case LLDP_SNMP_MED_POLICY_TAGGED: |
4a2acc8e VB |
898 | long_ret = policy->tagged?1:2; |
899 | return (u_char *)&long_ret; | |
900 | default: | |
901 | return NULL; | |
077f7601 | 902 | } |
4a2acc8e | 903 | } |
4a2acc8e | 904 | static u_char* |
077f7601 | 905 | agent_h_remote_med_policy(struct variable *vp, oid *name, size_t *length, |
4a2acc8e VB |
906 | int exact, size_t *var_len, WriteMethod **write_method) |
907 | { | |
077f7601 | 908 | struct lldpd_med_policy *policy; |
4a2acc8e | 909 | |
077f7601 VB |
910 | if ((policy = (struct lldpd_med_policy *)header_tprmedindexed_table(vp, name, length, |
911 | exact, var_len, write_method, TPR_VARIANT_MED_POLICY)) == NULL) | |
4a2acc8e VB |
912 | return NULL; |
913 | ||
077f7601 VB |
914 | return agent_v_med_policy(vp, var_len, policy); |
915 | } | |
916 | static u_char* | |
917 | agent_h_local_med_policy(struct variable *vp, oid *name, size_t *length, | |
918 | int exact, size_t *var_len, WriteMethod **write_method) | |
919 | { | |
920 | struct lldpd_med_policy *policy; | |
921 | ||
922 | if ((policy = (struct lldpd_med_policy *)header_pmedindexed_policy_table(vp, name, length, | |
923 | exact, var_len, write_method)) == NULL) | |
924 | return NULL; | |
4a2acc8e | 925 | |
077f7601 VB |
926 | return agent_v_med_policy(vp, var_len, policy); |
927 | } | |
4a2acc8e | 928 | |
077f7601 VB |
929 | static u_char* |
930 | agent_v_med_location(struct variable *vp, size_t *var_len, | |
931 | struct lldpd_med_loc *location) | |
932 | { | |
4a2acc8e | 933 | switch (vp->magic) { |
077f7601 | 934 | case LLDP_SNMP_MED_LOCATION: |
4a2acc8e VB |
935 | *var_len = location->data_len; |
936 | return (u_char *)location->data; | |
937 | default: | |
938 | return NULL; | |
939 | } | |
077f7601 VB |
940 | } |
941 | static u_char* | |
942 | agent_h_remote_med_location(struct variable *vp, oid *name, size_t *length, | |
943 | int exact, size_t *var_len, WriteMethod **write_method) | |
944 | { | |
945 | struct lldpd_med_loc *location; | |
946 | ||
947 | if ((location = (struct lldpd_med_loc *)header_tprmedindexed_table(vp, name, length, | |
948 | exact, var_len, write_method, TPR_VARIANT_MED_LOCATION)) == NULL) | |
949 | return NULL; | |
950 | ||
951 | return agent_v_med_location(vp, var_len, location); | |
952 | } | |
953 | static u_char* | |
954 | agent_h_local_med_location(struct variable *vp, oid *name, size_t *length, | |
955 | int exact, size_t *var_len, WriteMethod **write_method) | |
956 | { | |
957 | struct lldpd_med_loc *location; | |
958 | ||
959 | if ((location = (struct lldpd_med_loc *)header_pmedindexed_location_table(vp, name, length, | |
960 | exact, var_len, write_method)) == NULL) | |
961 | return NULL; | |
962 | ||
963 | return agent_v_med_location(vp, var_len, location); | |
4a2acc8e | 964 | } |
1d88c843 VB |
965 | #endif |
966 | ||
43c02e7b | 967 | static u_char* |
f645906c VB |
968 | agent_v_chassis(struct variable *vp, size_t *var_len, |
969 | struct lldpd_chassis *chassis) | |
43c02e7b VB |
970 | { |
971 | static uint8_t bit; | |
972 | static unsigned long long_ret; | |
973 | ||
43c02e7b | 974 | switch (vp->magic) { |
f645906c VB |
975 | case LLDP_SNMP_CIDSUBTYPE: |
976 | long_ret = chassis->c_id_subtype; | |
43c02e7b | 977 | return (u_char *)&long_ret; |
f645906c VB |
978 | case LLDP_SNMP_CID: |
979 | *var_len = chassis->c_id_len; | |
980 | return (u_char *)chassis->c_id; | |
981 | case LLDP_SNMP_SYSNAME: | |
982 | *var_len = strlen(chassis->c_name); | |
983 | return (u_char *)chassis->c_name; | |
984 | case LLDP_SNMP_SYSDESCR: | |
985 | *var_len = strlen(chassis->c_descr); | |
986 | return (u_char *)chassis->c_descr; | |
987 | case LLDP_SNMP_SYSCAP_SUP: | |
43c02e7b | 988 | *var_len = 1; |
f645906c | 989 | bit = swap_bits(chassis->c_cap_available); |
43c02e7b | 990 | return (u_char *)&bit; |
f645906c | 991 | case LLDP_SNMP_SYSCAP_ENA: |
43c02e7b | 992 | *var_len = 1; |
f645906c | 993 | bit = swap_bits(chassis->c_cap_enabled); |
43c02e7b VB |
994 | return (u_char *)&bit; |
995 | default: | |
996 | break; | |
997 | } | |
f645906c VB |
998 | return NULL; |
999 | } | |
1000 | static u_char* | |
1001 | agent_h_local_chassis(struct variable *vp, oid *name, size_t *length, | |
1002 | int exact, size_t *var_len, WriteMethod **write_method) | |
1003 | { | |
1004 | if (header_generic(vp, name, length, exact, var_len, write_method)) | |
1005 | return NULL; | |
1006 | ||
1007 | return agent_v_chassis(vp, var_len, LOCAL_CHASSIS(scfg)); | |
1008 | } | |
1009 | static u_char* | |
1010 | agent_h_remote_chassis(struct variable *vp, oid*name, size_t *length, | |
1011 | int exact, size_t *var_len, WriteMethod **write_method) | |
1012 | { | |
1013 | struct lldpd_port *port; | |
1014 | ||
1015 | if ((port = header_tprindexed_table(vp, name, length, | |
077f7601 | 1016 | exact, var_len, write_method, 0)) == NULL) |
f645906c VB |
1017 | return NULL; |
1018 | ||
1019 | return agent_v_chassis(vp, var_len, port->p_chassis); | |
43c02e7b VB |
1020 | } |
1021 | ||
1022 | static u_char* | |
1023 | agent_h_stats(struct variable *vp, oid *name, size_t *length, | |
1024 | int exact, size_t *var_len, WriteMethod **write_method) | |
1025 | { | |
1026 | static unsigned long long_ret; | |
1027 | struct lldpd_hardware *hardware; | |
1028 | ||
1029 | if ((hardware = header_portindexed_table(vp, name, length, | |
1030 | exact, var_len, write_method)) == NULL) | |
1031 | return NULL; | |
1032 | ||
1033 | switch (vp->magic) { | |
1034 | case LLDP_SNMP_STATS_TX: | |
1035 | long_ret = hardware->h_tx_cnt; | |
1036 | return (u_char *)&long_ret; | |
1037 | case LLDP_SNMP_STATS_RX: | |
1038 | long_ret = hardware->h_rx_cnt; | |
1039 | return (u_char *)&long_ret; | |
1040 | case LLDP_SNMP_STATS_RX_DISCARDED: | |
1041 | case LLDP_SNMP_STATS_RX_ERRORS: | |
37387046 VB |
1042 | /* We discard only frame with errors. Therefore, the two values |
1043 | * are equal */ | |
43c02e7b VB |
1044 | long_ret = hardware->h_rx_discarded_cnt; |
1045 | return (u_char *)&long_ret; | |
1046 | case LLDP_SNMP_STATS_RX_TLVDISCARDED: | |
1047 | case LLDP_SNMP_STATS_RX_TLVUNRECOGNIZED: | |
37387046 VB |
1048 | /* We discard only unrecognized TLV. Malformed TLV |
1049 | implies dropping the whole frame */ | |
1050 | long_ret = hardware->h_rx_unrecognized_cnt; | |
43c02e7b VB |
1051 | return (u_char *)&long_ret; |
1052 | case LLDP_SNMP_STATS_RX_AGEOUTS: | |
1053 | long_ret = hardware->h_rx_ageout_cnt; | |
1054 | return (u_char *)&long_ret; | |
1055 | default: | |
1056 | break; | |
1057 | } | |
1058 | return NULL; | |
1059 | } | |
1060 | ||
a1347cd8 | 1061 | #ifdef ENABLE_DOT1 |
43c02e7b | 1062 | static u_char* |
f645906c | 1063 | agent_v_vlan(struct variable *vp, size_t *var_len, struct lldpd_vlan *vlan) |
43c02e7b | 1064 | { |
43c02e7b | 1065 | switch (vp->magic) { |
f645906c | 1066 | case LLDP_SNMP_DOT1_VLANNAME: |
43c02e7b VB |
1067 | *var_len = strlen(vlan->v_name); |
1068 | return (u_char *)vlan->v_name; | |
1069 | default: | |
1070 | break; | |
1071 | } | |
f645906c | 1072 | return NULL; |
43c02e7b | 1073 | } |
f645906c VB |
1074 | static u_char* |
1075 | agent_h_local_vlan(struct variable *vp, oid *name, size_t *length, | |
1076 | int exact, size_t *var_len, WriteMethod **write_method) | |
1077 | { | |
1078 | struct lldpd_vlan *vlan; | |
1079 | ||
1080 | if ((vlan = header_pvindexed_table(vp, name, length, | |
1081 | exact, var_len, write_method)) == NULL) | |
1082 | return NULL; | |
43c02e7b | 1083 | |
f645906c VB |
1084 | return agent_v_vlan(vp, var_len, vlan); |
1085 | } | |
43c02e7b VB |
1086 | static u_char* |
1087 | agent_h_remote_vlan(struct variable *vp, oid *name, size_t *length, | |
1088 | int exact, size_t *var_len, WriteMethod **write_method) | |
1089 | { | |
1090 | struct lldpd_vlan *vlan; | |
1091 | ||
1092 | if ((vlan = header_tprvindexed_table(vp, name, length, | |
1093 | exact, var_len, write_method)) == NULL) | |
1094 | return NULL; | |
1095 | ||
f645906c VB |
1096 | return agent_v_vlan(vp, var_len, vlan); |
1097 | } | |
1098 | ||
1099 | static u_char* | |
1100 | agent_v_ppvid(struct variable *vp, size_t *var_len, struct lldpd_ppvid *ppvid) | |
1101 | { | |
1102 | static unsigned long long_ret; | |
1103 | ||
43c02e7b | 1104 | switch (vp->magic) { |
f645906c | 1105 | case LLDP_SNMP_DOT1_PPVLAN_SUPPORTED: |
4b292b55 | 1106 | long_ret = (ppvid->p_cap_status & LLDP_PPVID_CAP_SUPPORTED)?1:2; |
f645906c VB |
1107 | return (u_char *)&long_ret; |
1108 | case LLDP_SNMP_DOT1_PPVLAN_ENABLED: | |
4b292b55 | 1109 | long_ret = (ppvid->p_cap_status & LLDP_PPVID_CAP_ENABLED)?1:2; |
dccc6964 VB |
1110 | return (u_char *)&long_ret; |
1111 | default: | |
1112 | break; | |
1113 | } | |
f645906c | 1114 | return NULL; |
dccc6964 VB |
1115 | } |
1116 | static u_char* | |
1117 | agent_h_local_ppvid(struct variable *vp, oid *name, size_t *length, | |
1118 | int exact, size_t *var_len, WriteMethod **write_method) | |
1119 | { | |
1120 | struct lldpd_ppvid *ppvid; | |
dccc6964 VB |
1121 | |
1122 | if ((ppvid = header_pppvidindexed_table(vp, name, length, | |
1123 | exact, var_len, write_method)) == NULL) | |
1124 | return NULL; | |
1125 | ||
f645906c | 1126 | return agent_v_ppvid(vp, var_len, ppvid); |
dccc6964 VB |
1127 | } |
1128 | ||
1129 | static u_char* | |
1130 | agent_h_remote_ppvid(struct variable *vp, oid *name, size_t *length, | |
1131 | int exact, size_t *var_len, WriteMethod **write_method) | |
1132 | { | |
1133 | struct lldpd_ppvid *ppvid; | |
dccc6964 VB |
1134 | |
1135 | if ((ppvid = header_tprppvidindexed_table(vp, name, length, | |
1136 | exact, var_len, write_method)) == NULL) | |
1137 | return NULL; | |
1138 | ||
f645906c VB |
1139 | return agent_v_ppvid(vp, var_len, ppvid); |
1140 | } | |
1141 | ||
1142 | static u_char* | |
1143 | agent_v_pi(struct variable *vp, size_t *var_len, struct lldpd_pi *pi) | |
1144 | { | |
dccc6964 | 1145 | switch (vp->magic) { |
f645906c VB |
1146 | case LLDP_SNMP_DOT1_PI: |
1147 | *var_len = pi->p_pi_len; | |
1148 | return (u_char *)pi->p_pi; | |
43c02e7b VB |
1149 | default: |
1150 | break; | |
1151 | } | |
1152 | return NULL; | |
1153 | } | |
fbb9deaa VB |
1154 | static u_char* |
1155 | agent_h_local_pi(struct variable *vp, oid *name, size_t *length, | |
1156 | int exact, size_t *var_len, WriteMethod **write_method) | |
1157 | { | |
1158 | struct lldpd_pi *pi; | |
1159 | ||
1160 | if ((pi = header_ppiindexed_table(vp, name, length, | |
1161 | exact, var_len, write_method)) == NULL) | |
1162 | return NULL; | |
1163 | ||
f645906c | 1164 | return agent_v_pi(vp, var_len, pi); |
fbb9deaa VB |
1165 | } |
1166 | static u_char* | |
1167 | agent_h_remote_pi(struct variable *vp, oid *name, size_t *length, | |
1168 | int exact, size_t *var_len, WriteMethod **write_method) | |
1169 | { | |
1170 | struct lldpd_pi *pi; | |
1171 | ||
1172 | if ((pi = header_tprpiindexed_table(vp, name, length, | |
1173 | exact, var_len, write_method)) == NULL) | |
1174 | return NULL; | |
1175 | ||
f645906c | 1176 | return agent_v_pi(vp, var_len, pi); |
fbb9deaa | 1177 | } |
a1347cd8 | 1178 | #endif |
43c02e7b VB |
1179 | |
1180 | static u_char* | |
14e9519e | 1181 | agent_v_port(struct variable *vp, size_t *var_len, struct lldpd_port *port) |
43c02e7b | 1182 | { |
14e9519e | 1183 | #ifdef ENABLE_DOT3 |
4e22da4c | 1184 | static uint16_t short_ret; |
43c02e7b | 1185 | static uint8_t bit; |
14e9519e | 1186 | #endif |
43c02e7b VB |
1187 | static unsigned long long_ret; |
1188 | ||
43c02e7b | 1189 | switch (vp->magic) { |
14e9519e | 1190 | case LLDP_SNMP_PIDSUBTYPE: |
7a53c5b9 | 1191 | long_ret = port->p_id_subtype; |
43c02e7b | 1192 | return (u_char *)&long_ret; |
14e9519e | 1193 | case LLDP_SNMP_PID: |
7a53c5b9 VB |
1194 | *var_len = port->p_id_len; |
1195 | return (u_char *)port->p_id; | |
14e9519e | 1196 | case LLDP_SNMP_PORTDESC: |
7a53c5b9 VB |
1197 | *var_len = strlen(port->p_descr); |
1198 | return (u_char *)port->p_descr; | |
a1347cd8 | 1199 | #ifdef ENABLE_DOT3 |
14e9519e | 1200 | case LLDP_SNMP_DOT3_AUTONEG_SUPPORT: |
3fd015c0 | 1201 | long_ret = 2 - port->p_macphy.autoneg_support; |
43c02e7b | 1202 | return (u_char *)&long_ret; |
14e9519e | 1203 | case LLDP_SNMP_DOT3_AUTONEG_ENABLED: |
3fd015c0 | 1204 | long_ret = 2 - port->p_macphy.autoneg_enabled; |
43c02e7b | 1205 | return (u_char *)&long_ret; |
14e9519e | 1206 | case LLDP_SNMP_DOT3_AUTONEG_ADVERTISED: |
43c02e7b | 1207 | *var_len = 2; |
4e22da4c VB |
1208 | short_ret = htons(port->p_macphy.autoneg_advertised); |
1209 | return (u_char *)&short_ret; | |
14e9519e | 1210 | case LLDP_SNMP_DOT3_AUTONEG_MAU: |
3fd015c0 | 1211 | long_ret = port->p_macphy.mau_type; |
43c02e7b | 1212 | return (u_char *)&long_ret; |
14e9519e | 1213 | case LLDP_SNMP_DOT3_AGG_STATUS: |
7a53c5b9 | 1214 | bit = swap_bits((port->p_aggregid > 0) ? 3 : 0); |
43c02e7b VB |
1215 | *var_len = 1; |
1216 | return (u_char *)&bit; | |
14e9519e | 1217 | case LLDP_SNMP_DOT3_AGG_ID: |
7a53c5b9 | 1218 | long_ret = port->p_aggregid; |
43c02e7b | 1219 | return (u_char *)&long_ret; |
14e9519e | 1220 | case LLDP_SNMP_DOT3_MFS: |
4e22da4c VB |
1221 | if (port->p_mfs) { |
1222 | long_ret = port->p_mfs; | |
1223 | return (u_char *)&long_ret; | |
1224 | } | |
1225 | break; | |
14e9519e | 1226 | case LLDP_SNMP_DOT3_POWER_DEVICETYPE: |
befbdf89 VB |
1227 | if (port->p_power.devicetype) { |
1228 | long_ret = (port->p_power.devicetype == LLDP_DOT3_POWER_PSE)?1:2; | |
1229 | return (u_char *)&long_ret; | |
1230 | } | |
1231 | break; | |
14e9519e | 1232 | case LLDP_SNMP_DOT3_POWER_SUPPORT: |
befbdf89 VB |
1233 | if (port->p_power.devicetype) { |
1234 | long_ret = (port->p_power.supported)?1:2; | |
1235 | return (u_char *)&long_ret; | |
1236 | } | |
1237 | break; | |
14e9519e | 1238 | case LLDP_SNMP_DOT3_POWER_ENABLED: |
befbdf89 VB |
1239 | if (port->p_power.devicetype) { |
1240 | long_ret = (port->p_power.enabled)?1:2; | |
1241 | return (u_char *)&long_ret; | |
1242 | } | |
1243 | break; | |
14e9519e | 1244 | case LLDP_SNMP_DOT3_POWER_PAIRCONTROL: |
befbdf89 VB |
1245 | if (port->p_power.devicetype) { |
1246 | long_ret = (port->p_power.paircontrol)?1:2; | |
1247 | return (u_char *)&long_ret; | |
1248 | } | |
1249 | break; | |
14e9519e | 1250 | case LLDP_SNMP_DOT3_POWER_PAIRS: |
befbdf89 VB |
1251 | if (port->p_power.devicetype) { |
1252 | long_ret = port->p_power.pairs; | |
1253 | return (u_char *)&long_ret; | |
1254 | } | |
1255 | break; | |
14e9519e | 1256 | case LLDP_SNMP_DOT3_POWER_CLASS: |
befbdf89 VB |
1257 | if (port->p_power.devicetype && port->p_power.class) { |
1258 | long_ret = port->p_power.class; | |
1259 | return (u_char *)&long_ret; | |
1260 | } | |
1261 | break; | |
14e9519e | 1262 | case LLDP_SNMP_DOT3_POWER_TYPE: |
608cb51c VB |
1263 | if (port->p_power.devicetype && |
1264 | port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) { | |
1265 | *var_len = 1; | |
1266 | bit = (((port->p_power.powertype == | |
4e22da4c | 1267 | LLDP_DOT3_POWER_8023AT_TYPE1)?0:1) << 7) | |
608cb51c VB |
1268 | (((port->p_power.devicetype == |
1269 | LLDP_DOT3_POWER_PSE)?0:1) << 6); | |
1270 | return (u_char *)&bit; | |
1271 | } | |
1272 | break; | |
14e9519e | 1273 | case LLDP_SNMP_DOT3_POWER_SOURCE: |
608cb51c VB |
1274 | if (port->p_power.devicetype && |
1275 | port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) { | |
1276 | *var_len = 1; | |
1277 | bit = swap_bits(port->p_power.source%(1<<2)); | |
1278 | return (u_char *)&bit; | |
1279 | } | |
1280 | break; | |
14e9519e | 1281 | case LLDP_SNMP_DOT3_POWER_PRIORITY: |
608cb51c VB |
1282 | if (port->p_power.devicetype && |
1283 | port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) { | |
4e22da4c VB |
1284 | /* See 30.12.2.1.16. This seems defined in reverse order... */ |
1285 | long_ret = 4 - port->p_power.priority; | |
608cb51c VB |
1286 | return (u_char *)&long_ret; |
1287 | } | |
1288 | break; | |
14e9519e | 1289 | case LLDP_SNMP_DOT3_POWER_REQUESTED: |
608cb51c VB |
1290 | if (port->p_power.devicetype && |
1291 | port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) { | |
1292 | long_ret = port->p_power.requested; | |
1293 | return (u_char *)&long_ret; | |
1294 | } | |
1295 | break; | |
14e9519e | 1296 | case LLDP_SNMP_DOT3_POWER_ALLOCATED: |
608cb51c VB |
1297 | if (port->p_power.devicetype && |
1298 | port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) { | |
1299 | long_ret = port->p_power.allocated; | |
1300 | return (u_char *)&long_ret; | |
1301 | } | |
1302 | break; | |
75b3469d VB |
1303 | #endif |
1304 | #ifdef ENABLE_DOT1 | |
14e9519e | 1305 | case LLDP_SNMP_DOT1_PVID: |
7a53c5b9 | 1306 | long_ret = port->p_pvid; |
75b3469d | 1307 | return (u_char *)&long_ret; |
a1347cd8 | 1308 | #endif |
43c02e7b VB |
1309 | default: |
1310 | break; | |
1311 | } | |
14e9519e VB |
1312 | return NULL; |
1313 | } | |
1314 | static u_char* | |
1315 | agent_h_remote_port(struct variable *vp, oid *name, size_t *length, | |
1316 | int exact, size_t *var_len, WriteMethod **write_method) | |
1317 | { | |
1318 | struct lldpd_port *port; | |
1319 | u_char *a; | |
1320 | ||
1321 | if ((port = header_tprindexed_table(vp, name, length, | |
077f7601 | 1322 | exact, var_len, write_method, 0)) == NULL) |
14e9519e VB |
1323 | return NULL; |
1324 | ||
077f7601 VB |
1325 | if ((a = agent_v_port(vp, var_len, port)) != NULL) |
1326 | return a; | |
1327 | TRYNEXT(agent_h_remote_port); | |
14e9519e VB |
1328 | } |
1329 | static u_char* | |
1330 | agent_h_local_port(struct variable *vp, oid *name, size_t *length, | |
1331 | int exact, size_t *var_len, WriteMethod **write_method) | |
1332 | { | |
1333 | struct lldpd_hardware *hardware; | |
1334 | u_char *a; | |
1335 | ||
1336 | if ((hardware = header_portindexed_table(vp, name, length, | |
1337 | exact, var_len, write_method)) == NULL) | |
1338 | return NULL; | |
1339 | ||
077f7601 VB |
1340 | if ((a = agent_v_port(vp, var_len, &hardware->h_lport)) != NULL) |
1341 | return a; | |
1342 | TRYNEXT(agent_h_local_port); | |
43c02e7b VB |
1343 | } |
1344 | ||
1345 | static u_char* | |
2eec5540 | 1346 | agent_v_management(struct variable *vp, size_t *var_len, struct lldpd_mgmt *mgmt) |
43c02e7b VB |
1347 | { |
1348 | static unsigned long int long_ret; | |
1349 | static oid zeroDotZero[2] = {0, 0}; | |
1350 | ||
1351 | switch (vp->magic) { | |
f645906c | 1352 | case LLDP_SNMP_ADDR_LEN: |
af3caa3b | 1353 | long_ret = mgmt->m_addrsize + 1; |
43c02e7b | 1354 | return (u_char*)&long_ret; |
f645906c | 1355 | case LLDP_SNMP_ADDR_IFSUBTYPE: |
2eec5540 | 1356 | if (mgmt->m_iface != 0) |
43c02e7b VB |
1357 | long_ret = LLDP_MGMT_IFACE_IFINDEX; |
1358 | else | |
1359 | long_ret = 1; | |
1360 | return (u_char*)&long_ret; | |
f645906c | 1361 | case LLDP_SNMP_ADDR_IFID: |
2eec5540 | 1362 | long_ret = mgmt->m_iface; |
43c02e7b | 1363 | return (u_char*)&long_ret; |
f645906c | 1364 | case LLDP_SNMP_ADDR_OID: |
43c02e7b VB |
1365 | *var_len = sizeof(zeroDotZero); |
1366 | return (u_char*)zeroDotZero; | |
1367 | default: | |
1368 | break; | |
1369 | } | |
1370 | return NULL; | |
1371 | } | |
43c02e7b VB |
1372 | static u_char* |
1373 | agent_h_local_management(struct variable *vp, oid *name, size_t *length, | |
1374 | int exact, size_t *var_len, WriteMethod **write_method) | |
1375 | { | |
26836a43 | 1376 | |
2eec5540 | 1377 | struct lldpd_mgmt *mgmt; |
e8c9b6bb | 1378 | |
2eec5540 | 1379 | if ((mgmt = header_ipindexed_table(vp, name, length, |
e8c9b6bb VB |
1380 | exact, var_len, write_method)) == NULL) |
1381 | return NULL; | |
1382 | ||
2eec5540 | 1383 | return agent_v_management(vp, var_len, mgmt); |
43c02e7b | 1384 | } |
43c02e7b VB |
1385 | static u_char* |
1386 | agent_h_remote_management(struct variable *vp, oid *name, size_t *length, | |
1387 | int exact, size_t *var_len, WriteMethod **write_method) | |
1388 | { | |
2eec5540 | 1389 | struct lldpd_mgmt *mgmt; |
43c02e7b | 1390 | |
2eec5540 | 1391 | if ((mgmt = header_tpripindexed_table(vp, name, length, |
26836a43 | 1392 | exact, var_len, write_method)) == NULL) |
43c02e7b VB |
1393 | return NULL; |
1394 | ||
2eec5540 | 1395 | return agent_v_management(vp, var_len, mgmt); |
43c02e7b VB |
1396 | } |
1397 | ||
f645906c VB |
1398 | /* |
1399 | Here is how it works: a agent_h_*() function will handle incoming | |
1400 | requests. It will use an appropriate header_*indexed_table() | |
1401 | function to grab the appropriate structure that was queried (a port, | |
1402 | a chassis, ...). It will then delegate to a agent_v_*() function the | |
1403 | responsability to extract the appropriate answer. | |
1404 | ||
1405 | agent_h_*() functions and header_*indexed_table() are not shared | |
1406 | between remote and not remote version while agent_v_*() functions | |
1407 | are the same for both version. | |
1408 | */ | |
1409 | ||
4e22da4c VB |
1410 | /* For testing purposes, keep this structure ordered by increasing OID! */ |
1411 | struct variable8 agent_lldp_vars[] = { | |
43c02e7b VB |
1412 | /* Scalars */ |
1413 | {LLDP_SNMP_TXINTERVAL, ASN_INTEGER, RONLY, agent_h_scalars, 3, {1, 1, 1}}, | |
1414 | {LLDP_SNMP_TXMULTIPLIER, ASN_INTEGER, RONLY, agent_h_scalars, 3, {1, 1, 2}}, | |
1415 | {LLDP_SNMP_REINITDELAY, ASN_INTEGER, RONLY, agent_h_scalars, 3, {1, 1, 3}}, | |
1416 | {LLDP_SNMP_TXDELAY, ASN_INTEGER, RONLY, agent_h_scalars, 3, {1, 1, 4}}, | |
1417 | {LLDP_SNMP_NOTIFICATION, ASN_INTEGER, RONLY, agent_h_scalars, 3, {1, 1, 5}}, | |
1418 | {LLDP_SNMP_LASTUPDATE, ASN_TIMETICKS, RONLY, agent_h_scalars, 3, {1, 2, 1}}, | |
1419 | {LLDP_SNMP_STATS_INSERTS, ASN_GAUGE, RONLY, agent_h_scalars, 3, {1, 2, 2}}, | |
1420 | {LLDP_SNMP_STATS_DELETES, ASN_GAUGE, RONLY, agent_h_scalars, 3, {1, 2, 3}}, | |
1421 | {LLDP_SNMP_STATS_DROPS, ASN_GAUGE, RONLY, agent_h_scalars, 3, {1, 2, 4}}, | |
1422 | {LLDP_SNMP_STATS_AGEOUTS, ASN_GAUGE, RONLY, agent_h_scalars, 3, {1, 2, 5}}, | |
43c02e7b VB |
1423 | /* Stats */ |
1424 | {LLDP_SNMP_STATS_TX, ASN_COUNTER, RONLY, agent_h_stats, 5, {1, 2, 6, 1, 2}}, | |
1425 | {LLDP_SNMP_STATS_RX_DISCARDED, ASN_COUNTER, RONLY, agent_h_stats, 5, {1, 2, 7, 1, 2}}, | |
1426 | {LLDP_SNMP_STATS_RX_ERRORS, ASN_COUNTER, RONLY, agent_h_stats, 5, {1, 2, 7, 1, 3}}, | |
1427 | {LLDP_SNMP_STATS_RX, ASN_COUNTER, RONLY, agent_h_stats, 5, {1, 2, 7, 1, 4}}, | |
1428 | {LLDP_SNMP_STATS_RX_TLVDISCARDED, ASN_COUNTER, RONLY, agent_h_stats, 5, {1, 2, 7, 1, 5}}, | |
1429 | {LLDP_SNMP_STATS_RX_TLVUNRECOGNIZED, ASN_COUNTER, RONLY, agent_h_stats, 5, {1, 2, 7, 1, 6}}, | |
1430 | {LLDP_SNMP_STATS_RX_AGEOUTS, ASN_GAUGE, RONLY, agent_h_stats, 5, {1, 2, 7, 1, 7}}, | |
4e22da4c VB |
1431 | /* Local chassis */ |
1432 | {LLDP_SNMP_CIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_chassis, 3, {1, 3, 1}}, | |
1433 | {LLDP_SNMP_CID, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, {1, 3, 2}}, | |
1434 | {LLDP_SNMP_SYSNAME, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, {1, 3, 3}}, | |
1435 | {LLDP_SNMP_SYSDESCR, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, {1, 3, 4}}, | |
1436 | {LLDP_SNMP_SYSCAP_SUP, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, {1, 3, 5}}, | |
1437 | {LLDP_SNMP_SYSCAP_ENA, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, {1, 3, 6}}, | |
43c02e7b | 1438 | /* Local ports */ |
14e9519e VB |
1439 | {LLDP_SNMP_PIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_port, 5, {1, 3, 7, 1, 2}}, |
1440 | {LLDP_SNMP_PID, ASN_OCTET_STR, RONLY, agent_h_local_port, 5, {1, 3, 7, 1, 3}}, | |
1441 | {LLDP_SNMP_PORTDESC, ASN_OCTET_STR, RONLY, agent_h_local_port, 5, {1, 3, 7, 1, 4}}, | |
4e22da4c VB |
1442 | /* Local management address */ |
1443 | {LLDP_SNMP_ADDR_LEN, ASN_INTEGER, RONLY, agent_h_local_management, 5, | |
1444 | {1, 3, 8, 1, 3}}, | |
1445 | {LLDP_SNMP_ADDR_IFSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_management, 5, | |
1446 | {1, 3, 8, 1, 4}}, | |
1447 | {LLDP_SNMP_ADDR_IFID, ASN_INTEGER, RONLY, agent_h_local_management, 5, | |
1448 | {1, 3, 8, 1, 5}}, | |
1449 | {LLDP_SNMP_ADDR_OID, ASN_OBJECT_ID, RONLY, agent_h_local_management, 5, | |
1450 | {1, 3, 8, 1, 6}}, | |
1451 | /* Remote ports */ | |
1452 | {LLDP_SNMP_CIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_chassis, 5, {1, 4, 1, 1, 4}}, | |
1453 | {LLDP_SNMP_CID, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, {1, 4, 1, 1, 5}}, | |
1454 | {LLDP_SNMP_PIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_port, 5, {1, 4, 1, 1, 6}}, | |
1455 | {LLDP_SNMP_PID, ASN_OCTET_STR, RONLY, agent_h_remote_port, 5, {1, 4, 1, 1, 7}}, | |
1456 | {LLDP_SNMP_PORTDESC, ASN_OCTET_STR, RONLY, agent_h_remote_port, 5, {1, 4, 1, 1, 8}}, | |
1457 | {LLDP_SNMP_SYSNAME, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, {1, 4, 1, 1, 9}}, | |
1458 | {LLDP_SNMP_SYSDESCR, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, {1, 4, 1, 1, 10}}, | |
1459 | {LLDP_SNMP_SYSCAP_SUP, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, {1, 4, 1, 1, 11}}, | |
1460 | {LLDP_SNMP_SYSCAP_ENA, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, {1, 4, 1, 1, 12}}, | |
1461 | /* Remote management address */ | |
1462 | {LLDP_SNMP_ADDR_IFSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_management, 5, | |
1463 | {1, 4, 2, 1, 3}}, | |
1464 | {LLDP_SNMP_ADDR_IFID, ASN_INTEGER, RONLY, agent_h_remote_management, 5, | |
1465 | {1, 4, 2, 1, 4}}, | |
1466 | {LLDP_SNMP_ADDR_OID, ASN_OBJECT_ID, RONLY, agent_h_remote_management, 5, | |
1467 | {1, 4, 2, 1, 5}}, | |
1468 | /* Dot3, local ports */ | |
a1347cd8 | 1469 | #ifdef ENABLE_DOT3 |
14e9519e | 1470 | {LLDP_SNMP_DOT3_AUTONEG_SUPPORT, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
43c02e7b | 1471 | {1, 5, 4623, 1, 2, 1, 1, 1}}, |
14e9519e | 1472 | {LLDP_SNMP_DOT3_AUTONEG_ENABLED, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
43c02e7b | 1473 | {1, 5, 4623, 1, 2, 1, 1, 2}}, |
14e9519e | 1474 | {LLDP_SNMP_DOT3_AUTONEG_ADVERTISED, ASN_OCTET_STR, RONLY, agent_h_local_port, 8, |
43c02e7b | 1475 | {1, 5, 4623, 1, 2, 1, 1, 3}}, |
14e9519e | 1476 | {LLDP_SNMP_DOT3_AUTONEG_MAU, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
43c02e7b | 1477 | {1, 5, 4623, 1, 2, 1, 1, 4}}, |
14e9519e | 1478 | {LLDP_SNMP_DOT3_POWER_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
42ee7382 | 1479 | {1, 5, 4623, 1, 2, 2, 1, 1}}, |
14e9519e | 1480 | {LLDP_SNMP_DOT3_POWER_SUPPORT, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
42ee7382 | 1481 | {1, 5, 4623, 1, 2, 2, 1, 2}}, |
14e9519e | 1482 | {LLDP_SNMP_DOT3_POWER_ENABLED, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
42ee7382 | 1483 | {1, 5, 4623, 1, 2, 2, 1, 3}}, |
14e9519e | 1484 | {LLDP_SNMP_DOT3_POWER_PAIRCONTROL, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
42ee7382 | 1485 | {1, 5, 4623, 1, 2, 2, 1, 4}}, |
14e9519e | 1486 | {LLDP_SNMP_DOT3_POWER_PAIRS, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
42ee7382 | 1487 | {1, 5, 4623, 1, 2, 2, 1, 5}}, |
14e9519e | 1488 | {LLDP_SNMP_DOT3_POWER_CLASS, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
42ee7382 | 1489 | {1, 5, 4623, 1, 2, 2, 1, 6}}, |
14e9519e | 1490 | {LLDP_SNMP_DOT3_POWER_TYPE, ASN_OCTET_STR, RONLY, agent_h_local_port, 8, |
608cb51c | 1491 | {1, 5, 4623, 1, 2, 2, 1, 7}}, |
14e9519e | 1492 | {LLDP_SNMP_DOT3_POWER_SOURCE, ASN_OCTET_STR, RONLY, agent_h_local_port, 8, |
608cb51c | 1493 | {1, 5, 4623, 1, 2, 2, 1, 8}}, |
14e9519e | 1494 | {LLDP_SNMP_DOT3_POWER_PRIORITY, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
608cb51c | 1495 | {1, 5, 4623, 1, 2, 2, 1, 9}}, |
14e9519e | 1496 | {LLDP_SNMP_DOT3_POWER_REQUESTED, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
608cb51c | 1497 | {1, 5, 4623, 1, 2, 2, 1, 10}}, |
14e9519e | 1498 | {LLDP_SNMP_DOT3_POWER_ALLOCATED, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
608cb51c | 1499 | {1, 5, 4623, 1, 2, 2, 1, 11}}, |
14e9519e | 1500 | {LLDP_SNMP_DOT3_AGG_STATUS, ASN_OCTET_STR, RONLY, agent_h_local_port, 8, |
43c02e7b | 1501 | {1, 5, 4623, 1, 2, 3, 1, 1}}, |
14e9519e | 1502 | {LLDP_SNMP_DOT3_AGG_ID, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
43c02e7b | 1503 | {1, 5, 4623, 1, 2, 3, 1, 2}}, |
14e9519e | 1504 | {LLDP_SNMP_DOT3_MFS, ASN_INTEGER, RONLY, agent_h_local_port, 8, |
548109b2 | 1505 | {1, 5, 4623, 1, 2, 4, 1, 1}}, |
75b3469d | 1506 | #endif |
4e22da4c | 1507 | /* Dot3, remote ports */ |
a1347cd8 | 1508 | #ifdef ENABLE_DOT3 |
14e9519e | 1509 | {LLDP_SNMP_DOT3_AUTONEG_SUPPORT, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
43c02e7b | 1510 | {1, 5, 4623, 1, 3, 1, 1, 1}}, |
14e9519e | 1511 | {LLDP_SNMP_DOT3_AUTONEG_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
43c02e7b | 1512 | {1, 5, 4623, 1, 3, 1, 1, 2}}, |
14e9519e | 1513 | {LLDP_SNMP_DOT3_AUTONEG_ADVERTISED, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8, |
43c02e7b | 1514 | {1, 5, 4623, 1, 3, 1, 1, 3}}, |
14e9519e | 1515 | {LLDP_SNMP_DOT3_AUTONEG_MAU, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
43c02e7b | 1516 | {1, 5, 4623, 1, 3, 1, 1, 4}}, |
14e9519e | 1517 | {LLDP_SNMP_DOT3_POWER_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
befbdf89 | 1518 | {1, 5, 4623, 1, 3, 2, 1, 1}}, |
14e9519e | 1519 | {LLDP_SNMP_DOT3_POWER_SUPPORT, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
befbdf89 | 1520 | {1, 5, 4623, 1, 3, 2, 1, 2}}, |
14e9519e | 1521 | {LLDP_SNMP_DOT3_POWER_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
befbdf89 | 1522 | {1, 5, 4623, 1, 3, 2, 1, 3}}, |
14e9519e | 1523 | {LLDP_SNMP_DOT3_POWER_PAIRCONTROL, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
befbdf89 | 1524 | {1, 5, 4623, 1, 3, 2, 1, 4}}, |
14e9519e | 1525 | {LLDP_SNMP_DOT3_POWER_PAIRS, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
befbdf89 | 1526 | {1, 5, 4623, 1, 3, 2, 1, 5}}, |
14e9519e | 1527 | {LLDP_SNMP_DOT3_POWER_CLASS, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
befbdf89 | 1528 | {1, 5, 4623, 1, 3, 2, 1, 6}}, |
14e9519e | 1529 | {LLDP_SNMP_DOT3_POWER_TYPE, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8, |
608cb51c | 1530 | {1, 5, 4623, 1, 3, 2, 1, 7}}, |
14e9519e | 1531 | {LLDP_SNMP_DOT3_POWER_SOURCE, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8, |
608cb51c | 1532 | {1, 5, 4623, 1, 3, 2, 1, 8}}, |
14e9519e | 1533 | {LLDP_SNMP_DOT3_POWER_PRIORITY, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
608cb51c | 1534 | {1, 5, 4623, 1, 3, 2, 1, 9}}, |
14e9519e | 1535 | {LLDP_SNMP_DOT3_POWER_REQUESTED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
608cb51c | 1536 | {1, 5, 4623, 1, 3, 2, 1, 10}}, |
14e9519e | 1537 | {LLDP_SNMP_DOT3_POWER_ALLOCATED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
608cb51c | 1538 | {1, 5, 4623, 1, 3, 2, 1, 11}}, |
14e9519e | 1539 | {LLDP_SNMP_DOT3_AGG_STATUS, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8, |
43c02e7b | 1540 | {1, 5, 4623, 1, 3, 3, 1, 1}}, |
14e9519e | 1541 | {LLDP_SNMP_DOT3_AGG_ID, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
43c02e7b | 1542 | {1, 5, 4623, 1, 3, 3, 1, 2}}, |
14e9519e | 1543 | {LLDP_SNMP_DOT3_MFS, ASN_INTEGER, RONLY, agent_h_remote_port, 8, |
548109b2 | 1544 | {1, 5, 4623, 1, 3, 4, 1, 1}}, |
a1347cd8 | 1545 | #endif |
1d88c843 VB |
1546 | #ifdef ENABLE_LLDPMED |
1547 | /* LLDP-MED local */ | |
077f7601 | 1548 | {LLDP_SNMP_MED_CLASS, ASN_INTEGER, RONLY, agent_h_local_med, 6, |
1d88c843 | 1549 | {1, 5, 4795, 1, 1, 1}}, |
077f7601 | 1550 | {LLDP_SNMP_MED_POLICY_VID, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, |
fd6aa9a3 | 1551 | {1, 5, 4795, 1, 2, 1, 1, 2}}, |
077f7601 | 1552 | {LLDP_SNMP_MED_POLICY_PRIO, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, |
fd6aa9a3 | 1553 | {1, 5, 4795, 1, 2, 1, 1, 3}}, |
077f7601 | 1554 | {LLDP_SNMP_MED_POLICY_DSCP, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, |
fd6aa9a3 | 1555 | {1, 5, 4795, 1, 2, 1, 1, 4}}, |
077f7601 | 1556 | {LLDP_SNMP_MED_POLICY_UNKNOWN, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, |
fd6aa9a3 | 1557 | {1, 5, 4795, 1, 2, 1, 1, 5}}, |
077f7601 | 1558 | {LLDP_SNMP_MED_POLICY_TAGGED, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, |
fd6aa9a3 | 1559 | {1, 5, 4795, 1, 2, 1, 1, 6}}, |
077f7601 | 1560 | {LLDP_SNMP_MED_HW, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, |
1d88c843 | 1561 | {1, 5, 4795, 1, 2, 2}}, |
077f7601 | 1562 | {LLDP_SNMP_MED_FW, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, |
1d88c843 | 1563 | {1, 5, 4795, 1, 2, 3}}, |
077f7601 | 1564 | {LLDP_SNMP_MED_SW, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, |
1d88c843 | 1565 | {1, 5, 4795, 1, 2, 4}}, |
077f7601 | 1566 | {LLDP_SNMP_MED_SN, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, |
1d88c843 | 1567 | {1, 5, 4795, 1, 2, 5}}, |
077f7601 | 1568 | {LLDP_SNMP_MED_MANUF, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, |
1d88c843 | 1569 | {1, 5, 4795, 1, 2, 6}}, |
077f7601 | 1570 | {LLDP_SNMP_MED_MODEL, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, |
1d88c843 | 1571 | {1, 5, 4795, 1, 2, 7}}, |
077f7601 | 1572 | {LLDP_SNMP_MED_ASSET, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, |
1d88c843 | 1573 | {1, 5, 4795, 1, 2, 8}}, |
077f7601 | 1574 | {LLDP_SNMP_MED_LOCATION, ASN_OCTET_STR, RONLY, agent_h_local_med_location, 8, |
1dcd4665 | 1575 | {1, 5, 4795, 1, 2, 9, 1, 2}}, |
077f7601 | 1576 | {LLDP_SNMP_MED_POE_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_local_med_power, 6, |
8e44f2dc VB |
1577 | {1, 5, 4795, 1, 2, 10}}, |
1578 | {LLDP_SNMP_MED_POE_PSE_POWERVAL, ASN_GAUGE, RONLY, agent_h_local_med_power, 8, | |
1579 | {1, 5, 4795, 1, 2, 11, 1, 1}}, | |
1580 | {LLDP_SNMP_MED_POE_PSE_POWERPRIORITY, ASN_INTEGER, RONLY, agent_h_local_med_power, 8, | |
1581 | {1, 5, 4795, 1, 2, 11, 1, 2}}, | |
077f7601 | 1582 | {LLDP_SNMP_MED_POE_PSE_POWERSOURCE, ASN_INTEGER, RONLY, agent_h_local_med_power, 6, |
8e44f2dc | 1583 | {1, 5, 4795, 1, 2, 12}}, |
077f7601 | 1584 | {LLDP_SNMP_MED_POE_PD_POWERVAL, ASN_GAUGE, RONLY, agent_h_local_med_power, 6, |
8e44f2dc | 1585 | {1, 5, 4795, 1, 2, 13}}, |
077f7601 | 1586 | {LLDP_SNMP_MED_POE_PD_POWERSOURCE, ASN_INTEGER, RONLY, agent_h_local_med_power, 6, |
8e44f2dc | 1587 | {1, 5, 4795, 1, 2, 14}}, |
077f7601 | 1588 | {LLDP_SNMP_MED_POE_PD_POWERPRIORITY, ASN_INTEGER, RONLY, agent_h_local_med_power, 6, |
8e44f2dc | 1589 | {1, 5, 4795, 1, 2, 15}}, |
1d88c843 | 1590 | /* LLDP-MED remote */ |
077f7601 | 1591 | {LLDP_SNMP_MED_CAP_AVAILABLE, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, |
1d88c843 | 1592 | {1, 5, 4795, 1, 3, 1, 1, 1}}, |
077f7601 | 1593 | {LLDP_SNMP_MED_CAP_ENABLED, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, |
1d88c843 | 1594 | {1, 5, 4795, 1, 3, 1, 1, 2}}, |
077f7601 | 1595 | {LLDP_SNMP_MED_CLASS, ASN_INTEGER, RONLY, agent_h_remote_med, 8, |
1d88c843 | 1596 | {1, 5, 4795, 1, 3, 1, 1, 3}}, |
4e22da4c VB |
1597 | {LLDP_SNMP_MED_POLICY_VID, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, |
1598 | {1, 5, 4795, 1, 3, 2, 1, 2}}, | |
1599 | {LLDP_SNMP_MED_POLICY_PRIO, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, | |
1600 | {1, 5, 4795, 1, 3, 2, 1, 3}}, | |
1601 | {LLDP_SNMP_MED_POLICY_DSCP, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, | |
1602 | {1, 5, 4795, 1, 3, 2, 1, 4}}, | |
1603 | {LLDP_SNMP_MED_POLICY_UNKNOWN, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, | |
1604 | {1, 5, 4795, 1, 3, 2, 1, 5}}, | |
1605 | {LLDP_SNMP_MED_POLICY_TAGGED, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, | |
1606 | {1, 5, 4795, 1, 3, 2, 1, 6}}, | |
077f7601 | 1607 | {LLDP_SNMP_MED_HW, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, |
1d88c843 | 1608 | {1, 5, 4795, 1, 3, 3, 1, 1}}, |
077f7601 | 1609 | {LLDP_SNMP_MED_FW, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, |
1d88c843 | 1610 | {1, 5, 4795, 1, 3, 3, 1, 2}}, |
077f7601 | 1611 | {LLDP_SNMP_MED_SW, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, |
1d88c843 | 1612 | {1, 5, 4795, 1, 3, 3, 1, 3}}, |
077f7601 | 1613 | {LLDP_SNMP_MED_SN, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, |
1d88c843 | 1614 | {1, 5, 4795, 1, 3, 3, 1, 4}}, |
077f7601 | 1615 | {LLDP_SNMP_MED_MANUF, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, |
1d88c843 | 1616 | {1, 5, 4795, 1, 3, 3, 1, 5}}, |
077f7601 | 1617 | {LLDP_SNMP_MED_MODEL, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, |
1d88c843 | 1618 | {1, 5, 4795, 1, 3, 3, 1, 6}}, |
077f7601 | 1619 | {LLDP_SNMP_MED_ASSET, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, |
1d88c843 | 1620 | {1, 5, 4795, 1, 3, 3, 1, 7}}, |
077f7601 | 1621 | {LLDP_SNMP_MED_LOCATION, ASN_OCTET_STR, RONLY, agent_h_remote_med_location, 8, |
4a2acc8e | 1622 | {1, 5, 4795, 1, 3, 4, 1, 2}}, |
077f7601 | 1623 | {LLDP_SNMP_MED_POE_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_remote_med_power, 8, |
1be9e1b5 | 1624 | {1, 5, 4795, 1, 3, 5, 1, 1}}, |
077f7601 | 1625 | {LLDP_SNMP_MED_POE_PSE_POWERVAL, ASN_GAUGE, RONLY, agent_h_remote_med_power, 8, |
1be9e1b5 | 1626 | {1, 5, 4795, 1, 3, 6, 1, 1}}, |
077f7601 | 1627 | {LLDP_SNMP_MED_POE_PSE_POWERSOURCE, ASN_INTEGER, RONLY, agent_h_remote_med_power, 8, |
1be9e1b5 | 1628 | {1, 5, 4795, 1, 3, 6, 1, 2}}, |
077f7601 | 1629 | {LLDP_SNMP_MED_POE_PSE_POWERPRIORITY, ASN_INTEGER, RONLY, agent_h_remote_med_power, 8, |
1be9e1b5 | 1630 | {1, 5, 4795, 1, 3, 6, 1, 3}}, |
077f7601 | 1631 | {LLDP_SNMP_MED_POE_PD_POWERVAL, ASN_GAUGE, RONLY, agent_h_remote_med_power, 8, |
1be9e1b5 | 1632 | {1, 5, 4795, 1, 3, 7, 1, 1}}, |
077f7601 | 1633 | {LLDP_SNMP_MED_POE_PD_POWERSOURCE, ASN_INTEGER, RONLY, agent_h_remote_med_power, 8, |
1be9e1b5 | 1634 | {1, 5, 4795, 1, 3, 7, 1, 2}}, |
077f7601 | 1635 | {LLDP_SNMP_MED_POE_PD_POWERPRIORITY, ASN_INTEGER, RONLY, agent_h_remote_med_power, 8, |
1be9e1b5 | 1636 | {1, 5, 4795, 1, 3, 7, 1, 3}}, |
4e22da4c VB |
1637 | #endif |
1638 | /* Dot1, local and remote ports */ | |
1639 | #ifdef ENABLE_DOT1 | |
1640 | {LLDP_SNMP_DOT1_PVID, ASN_INTEGER, RONLY, agent_h_local_port, 8, | |
1641 | {1, 5, 32962, 1, 2, 1, 1, 1}}, | |
1642 | {LLDP_SNMP_DOT1_PPVLAN_SUPPORTED, ASN_INTEGER, RONLY, agent_h_local_ppvid, 8, | |
1643 | {1, 5, 32962, 1, 2, 2, 1, 2}}, | |
1644 | {LLDP_SNMP_DOT1_PPVLAN_ENABLED, ASN_INTEGER, RONLY, agent_h_local_ppvid, 8, | |
1645 | {1, 5, 32962, 1, 2, 2, 1, 3}}, | |
1646 | {LLDP_SNMP_DOT1_VLANNAME, ASN_OCTET_STR, RONLY, agent_h_local_vlan, 8, | |
1647 | {1, 5, 32962, 1, 2, 3, 1, 2}}, | |
1648 | {LLDP_SNMP_DOT1_PI, ASN_OCTET_STR, RONLY, agent_h_local_pi, 8, | |
1649 | {1, 5, 32962, 1, 2, 4, 1, 2}}, | |
1650 | #endif | |
1651 | #ifdef ENABLE_DOT1 | |
1652 | {LLDP_SNMP_DOT1_PVID, ASN_INTEGER, RONLY, agent_h_remote_port, 8, | |
1653 | {1, 5, 32962, 1, 3, 1, 1, 1}}, | |
1654 | {LLDP_SNMP_DOT1_PPVLAN_SUPPORTED, ASN_INTEGER, RONLY, agent_h_remote_ppvid, 8, | |
1655 | {1, 5, 32962, 1, 3, 2, 1, 2}}, | |
1656 | {LLDP_SNMP_DOT1_PPVLAN_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_ppvid, 8, | |
1657 | {1, 5, 32962, 1, 3, 2, 1, 3}}, | |
1658 | /* Remote vlans */ | |
1659 | {LLDP_SNMP_DOT1_VLANNAME, ASN_OCTET_STR, RONLY, agent_h_remote_vlan, 8, | |
1660 | {1, 5, 32962, 1, 3, 3, 1, 2}}, | |
1661 | /* Protocol identity */ | |
1662 | {LLDP_SNMP_DOT1_PI, ASN_OCTET_STR, RONLY, agent_h_remote_pi, 8, | |
1663 | {1, 5, 32962, 1, 3, 4, 1, 2}}, | |
1d88c843 | 1664 | #endif |
43c02e7b | 1665 | }; |
4e22da4c VB |
1666 | size_t agent_lldp_vars_size(void) { |
1667 | return sizeof(agent_lldp_vars)/sizeof(struct variable8); | |
1668 | } | |
1669 | ||
350cd695 VB |
1670 | /* Logging NetSNMP messages */ |
1671 | static int | |
1672 | agent_log_callback(int major, int minor, | |
1673 | void *serverarg, void *clientarg) { | |
350cd695 VB |
1674 | struct snmp_log_message *slm = (struct snmp_log_message *)serverarg; |
1675 | char *msg = strdup(slm->msg); | |
5fd6695c | 1676 | (void)major; (void)minor; (void)clientarg; |
06f9c307 VB |
1677 | |
1678 | if (msg && msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = '\0'; | |
350cd695 VB |
1679 | switch (slm->priority) { |
1680 | case LOG_EMERG: log_warnx("snmp[emerg]: %s", msg?msg:slm->msg); break; | |
1681 | case LOG_ALERT: log_warnx("snmp[alert]: %s", msg?msg:slm->msg); break; | |
1682 | case LOG_CRIT: log_warnx("snmp[crit]: %s", msg?msg:slm->msg); break; | |
1683 | case LOG_ERR: log_warnx("snmp[err]: %s", msg?msg:slm->msg); break; | |
1684 | case LOG_WARNING: log_warnx("snmp[warning]: %s", msg?msg:slm->msg); break; | |
1685 | case LOG_NOTICE: log_info ("snmp[notice]: %s", msg?msg:slm->msg); break; | |
1686 | case LOG_INFO: log_info ("snmp[info]: %s", msg?msg:slm->msg); break; | |
1687 | case LOG_DEBUG: log_debug("snmp[debug]: %s", msg?msg:slm->msg); break; | |
1688 | } | |
1689 | free(msg); | |
1690 | return SNMP_ERR_NOERROR; | |
1691 | } | |
43c02e7b VB |
1692 | |
1693 | void | |
d6e889b6 | 1694 | agent_init(struct lldpd *cfg, char *agentx) |
43c02e7b VB |
1695 | { |
1696 | int rc; | |
43c02e7b VB |
1697 | |
1698 | LLOG_INFO("Enable SNMP subagent"); | |
1699 | netsnmp_enable_subagent(); | |
1700 | snmp_disable_log(); | |
350cd695 VB |
1701 | snmp_enable_calllog(); |
1702 | snmp_register_callback(SNMP_CALLBACK_LIBRARY, | |
1703 | SNMP_CALLBACK_LOGGING, | |
1704 | agent_log_callback, | |
1705 | NULL); | |
43c02e7b VB |
1706 | |
1707 | scfg = cfg; | |
1708 | ||
37954d62 VB |
1709 | /* We are chrooted, we don't want to handle persistent states */ |
1710 | netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, | |
1711 | NETSNMP_DS_LIB_DONT_PERSIST_STATE, TRUE); | |
1712 | /* Do not load any MIB */ | |
1713 | setenv("MIBS", "", 1); | |
350cd695 | 1714 | setenv("MIBDIRS", "/dev/null", 1); |
43c02e7b | 1715 | |
d72a05d4 VB |
1716 | /* We provide our UNIX domain transport */ |
1717 | agent_priv_register_domain(); | |
1718 | ||
bbea66e1 V |
1719 | if (agentx) |
1720 | netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, | |
1721 | NETSNMP_DS_AGENT_X_SOCKET, agentx); | |
37954d62 | 1722 | init_agent("lldpAgent"); |
4e22da4c | 1723 | REGISTER_MIB("lldp", agent_lldp_vars, variable8, lldp_oid); |
43c02e7b VB |
1724 | init_snmp("lldpAgent"); |
1725 | ||
1726 | if ((rc = register_sysORTable(lldp_oid, OID_LENGTH(lldp_oid), | |
1727 | "lldpMIB implementation by lldpd")) != 0) | |
1728 | LLOG_WARNX("Unable to register to sysORTable (%d)", rc); | |
1729 | } | |
1730 | ||
1731 | void | |
1732 | agent_shutdown() | |
1733 | { | |
1734 | unregister_sysORTable(lldp_oid, OID_LENGTH(lldp_oid)); | |
1735 | snmp_shutdown("lldpAgent"); | |
1736 | } |