2
2
* Interface MIB architecture support
4
* $Id: interface_linux.c,v 1.28.2.4 2006/04/25 17:39:54 hardaker Exp $
4
* $Id: interface_linux.c 16595 2007-07-06 21:14:03Z rstory $
6
6
#include <net-snmp/net-snmp-config.h>
7
7
#include <net-snmp/net-snmp-includes.h>
9
#ifdef HAVE_LINUX_ETHTOOL_H
10
#include <linux/types.h>
11
typedef __u64 u64; /* hack, so we may include kernel's ethtool.h */
12
typedef __u32 u32; /* ditto */
13
typedef __u16 u16; /* ditto */
14
typedef __u8 u8; /* ditto */
15
#include <linux/ethtool.h>
16
#endif /* HAVE_LINUX_ETHTOOL_H */
8
18
#include "mibII/mibII_common.h"
9
19
#include "if-mib/ifTable/ifTable_constants.h"
22
32
#include "interface_ioctl.h"
24
34
#include <sys/types.h>
26
#ifdef HAVE_LINUX_ETHTOOL_H
27
#include <sys/types.h>
28
typedef unsigned long long u64; /* hack, so we may include kernel's ethtool.h */
29
typedef __uint32_t u32; /* ditto */
30
typedef __uint16_t u16; /* ditto */
31
typedef __uint8_t u8; /* ditto */
32
#include <linux/ethtool.h>
33
#endif /* HAVE_LINUX_ETHTOOL_H */
34
38
#include <linux/sockios.h>
41
#define IF_NAMESIZE 16
37
45
netsnmp_linux_interface_get_if_speed(int fd, const char *name);
38
46
#ifdef HAVE_LINUX_ETHTOOL_H
40
48
netsnmp_linux_interface_get_if_speed_mii(int fd, const char *name);
51
#define PROC_SYS_NET_IPVx_NEIGH_RETRANS_TIME_MS "/proc/sys/net/ipv%d/neigh/%s/retrans_time_ms"
52
#define PROC_SYS_NET_IPVx_NEIGH_RETRANS_TIME "/proc/sys/net/ipv%d/neigh/%s/retrans_time"
53
static const char *proc_sys_retrans_time;
54
static unsigned short retrans_time_factor = 1;
57
#define PROC_SYS_NET_IPVx_BASE_REACHABLE_TIME_MS "/proc/sys/net/ipv%d/neigh/%s/base_reachable_time_ms"
58
#define PROC_SYS_NET_IPVx_BASE_REACHABLE_TIME "/proc/sys/net/ipv%d/neigh/%s/base_reachable_time"
59
static const char *proc_sys_basereachable_time;
60
static unsigned short basereachable_time_ms = 0;
45
62
netsnmp_arch_interface_init(void)
65
* Check which retransmit time interface is available
67
char proc_path[ 64+IF_NAMESIZE];
68
char proc_path2[64+IF_NAMESIZE];
71
snprintf(proc_path, sizeof(proc_path),
72
PROC_SYS_NET_IPVx_NEIGH_RETRANS_TIME_MS, 6, "default");
73
snprintf(proc_path2, sizeof(proc_path2),
74
PROC_SYS_NET_IPVx_NEIGH_RETRANS_TIME_MS, 4, "default");
76
if ((stat(proc_path, &st) == 0) || (stat(proc_path2, &st) == 0)) {
77
proc_sys_retrans_time = PROC_SYS_NET_IPVx_NEIGH_RETRANS_TIME_MS;
79
proc_sys_retrans_time = PROC_SYS_NET_IPVx_NEIGH_RETRANS_TIME;
80
retrans_time_factor = 10;
83
snprintf(proc_path, sizeof(proc_path), PROC_SYS_NET_IPVx_BASE_REACHABLE_TIME_MS, 6, "default");
84
snprintf(proc_path2, sizeof(proc_path), PROC_SYS_NET_IPVx_BASE_REACHABLE_TIME, 4, "default");
86
if ((stat(proc_path, &st) == 0) || (stat(proc_path2, &st) == 0)) {
87
proc_sys_basereachable_time = PROC_SYS_NET_IPVx_BASE_REACHABLE_TIME_MS;
88
basereachable_time_ms = 1;
91
proc_sys_basereachable_time = PROC_SYS_NET_IPVx_BASE_REACHABLE_TIME;
72
115
_arch_interface_has_ipv6(oid if_index, u_int *flags,
73
116
netsnmp_container *addr_container)
118
#ifdef NETSNMP_ENABLE_IPV6
76
119
netsnmp_ipaddress_entry *addr_entry = NULL;
77
120
netsnmp_iterator *addr_it = NULL;
78
121
u_int addr_container_flags = 0; /* must init to 0 */
162
205
* get the retransmit time
164
snprintf(line,sizeof(line),"/proc/sys/net/ipv4/neigh/%s/retrans_time",
207
snprintf(line,sizeof(line), proc_sys_retrans_time, 4,
166
209
if (!(fin = fopen(line, "r"))) {
167
210
DEBUGMSGTL(("access:interface",
171
214
if (fgets(line, sizeof(line), fin)) {
172
entry->retransmit_v4 = atoi(line) * 100;
215
entry->retransmit_v4 = atoi(line) * retrans_time_factor;
173
216
entry->ns_flags |= NETSNMP_INTERFACE_FLAGS_HAS_V4_RETRANSMIT;
191
234
* get the retransmit time
193
snprintf(line,sizeof(line),"/proc/sys/net/ipv6/neigh/%s/retrans_time",
236
snprintf(line,sizeof(line), proc_sys_retrans_time, 6,
195
238
if (!(fin = fopen(line, "r"))) {
196
239
DEBUGMSGTL(("access:interface",
200
243
if (fgets(line, sizeof(line), fin)) {
201
entry->retransmit_v6 = atoi(line);
244
entry->retransmit_v6 = atoi(line) * retrans_time_factor;
202
245
entry->ns_flags |= NETSNMP_INTERFACE_FLAGS_HAS_V6_RETRANSMIT;
208
251
* get the forwarding status
210
snprintf(line,sizeof(line),"/proc/sys/net/ipv6/conf/%s/forwarding",
253
snprintf(line, sizeof(line), "/proc/sys/net/ipv6/conf/%s/forwarding",
212
255
if (!(fin = fopen(line, "r"))) {
213
256
DEBUGMSGTL(("access:interface",
225
268
* get the reachable time
227
snprintf(line,sizeof(line),"/proc/sys/net/ipv6/neigh/%s/base_reachable_time",
270
snprintf(line, sizeof(line), proc_sys_basereachable_time, 6, entry->name);
229
271
if (!(fin = fopen(line, "r"))) {
230
272
DEBUGMSGTL(("access:interface",
231
273
"Failed to open %s\n", line));
234
276
if (fgets(line, sizeof(line), fin)) {
235
entry->reachable_time = atoi(line) * 1000; /* sec to millisec */
277
if (basereachable_time_ms) {
278
entry->reachable_time = atoi(line); /* millisec */
280
entry->reachable_time = atoi(line)*1000; /* sec to millisec */
236
283
entry->ns_flags |= NETSNMP_INTERFACE_FLAGS_HAS_V6_REACHABLE;
288
#endif /* NETSNMP_ENABLE_IPV6 */
286
333
while (*stats == ' ')
336
if ((*stats == 'N') &&
337
(0 == strncmp(stats, "No statistics available",
338
sizeof("No statistics available"))))
290
342
* Now parse the rest of the line (i.e. starting from 'stats')
291
343
* to extract the relevant statistics, and populate
365
416
* calculated stats.
367
* we have imcast, but not ibcast.
418
* we have imcast, but not ibcast.
369
420
entry->stats.inucast = entry->stats.imcast.low +
370
421
entry->stats.ibcast.low;
422
entry->stats.onucast = entry->stats.omcast.low +
423
entry->stats.obcast.low;
492
545
* ip version is to look for ip addresses. If anyone
493
546
* knows a better way, put it here!
548
#ifdef NETSNMP_ENABLE_IPV6
496
549
_arch_interface_has_ipv6(if_index, &flags, addr_container);
498
551
netsnmp_access_interface_ioctl_has_ipv4(fd, ifstart, 0, &flags);
513
566
entry = netsnmp_access_interface_entry_create(ifstart, 0);
514
567
if(NULL == entry) {
568
#ifdef NETSNMP_ENABLE_IPV6
516
569
netsnmp_access_ipaddress_container_free(addr_container, 0);
518
571
netsnmp_access_interface_container_free(container,
612
665
* hardcoded max packet size
613
666
* (see ip_frag_reasm: if(len > 65535) goto out_oversize;)
615
entry->reasm_max = 65535;
668
entry->reasm_max_v4 = entry->reasm_max_v6 = 65535;
670
NETSNMP_INTERFACE_FLAGS_HAS_V4_REASMMAX |
671
NETSNMP_INTERFACE_FLAGS_HAS_V6_REASMMAX;
617
673
netsnmp_access_interface_entry_overrides(entry);
624
680
if (flags & NETSNMP_INTERFACE_FLAGS_HAS_IPV4)
625
681
_arch_interface_flags_v4_get(entry);
683
#ifdef NETSNMP_ENABLE_IPV6
628
684
if (flags & NETSNMP_INTERFACE_FLAGS_HAS_IPV6)
629
685
_arch_interface_flags_v6_get(entry);
686
#endif /* NETSNMP_ENABLE_IPV6 */
633
689
* add to container
635
691
CONTAINER_INSERT(container, entry);
693
#ifdef NETSNMP_ENABLE_IPV6
638
694
netsnmp_access_ipaddress_container_free(addr_container, 0);