Debian Codegraph @

agent/mibgroup/ip-mib/data_access/defaultrouter_solaris2.c

raw
1 /*
2 * Interface MIB architecture support
3 *
4 * $Id:$
5 */
6 #include <net-snmp/net-snmp-config.h>
7 #include <net-snmp/net-snmp-includes.h>
8 #include "mibII/mibII_common.h"
9
10 #include <net-snmp/agent/net-snmp-agent-includes.h>
11 #include <net-snmp/data_access/defaultrouter.h>
12 #include <net-snmp/data_access/interface.h>
13
14 #include "ip-mib/ipDefaultRouterTable/ipDefaultRouterTable.h"
15 #include "defaultrouter_private.h"
16
17 #include <inet/ip.h>
18 #include <inet/mib2.h>
19
20 #if !defined(SA_SIZE) && !defined(RT_ROUNDUP)
21 #define RT_ROUNDUP(a) \
22 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
23 #endif
24
25 /**---------------------------------------------------------------------*/
26 /*
27 * local static prototypes
28 */
29 static int _load_defaultrouter_from_mib2(netsnmp_container *, int);
30
31 static int idx_offset;
32
33 /*
34 * initialize arch specific storage
35 *
36 * @retval 0: success
37 * @retval <0: error
38 */
39 int
40 netsnmp_arch_defaultrouter_entry_init(netsnmp_defaultrouter_entry *entry)
41 {
42 /*
43 * init
44 */
45 return 0;
46 }
47
48 /**
49 *
50 * @retval 0 no errors
51 * @retval !0 errors
52 */
53 int
54 netsnmp_arch_defaultrouter_container_load(netsnmp_container *container,
55 u_int load_flags)
56 {
57 int err;
58
59 err = 0;
60 idx_offset = 0;
61
62 DEBUGMSGTL(("access:defaultrouter:entry:arch", "load\n"));
63 if (NULL == container) {
64 snmp_log(LOG_ERR,
65 "netsnmp_arch_defaultrouter_container_load: container invalid\n");
66 return 1;
67 }
68
69 err = _load_defaultrouter_from_mib2(container, AF_INET);
70 if (err != 0) {
71 u_int flags = NETSNMP_ACCESS_DEFAULTROUTER_FREE_KEEP_CONTAINER;
72 netsnmp_access_defaultrouter_container_free(container, flags);
73 goto out;
74 }
75
76 #ifdef NETSNMP_ENABLE_IPV6
77 err = _load_defaultrouter_from_mib2(container, AF_INET6);
78 if (err != 0) {
79 u_int flags = NETSNMP_ACCESS_DEFAULTROUTER_FREE_KEEP_CONTAINER;
80 netsnmp_access_defaultrouter_container_free(container, flags);
81 goto out;
82 }
83 #endif
84
85 out:
86 return err;
87 }
88
89
90 static int
91 IP_Cmp_Route(void *addr, void *ep)
92 {
93 return (0); /* found */
94 }
95
96
97 /**
98 *
99 * @retval 0 no errors
100 * @retval !0 errors
101 */
102 static int
103 _load_defaultrouter_from_mib2(netsnmp_container *container, int family)
104 {
105 netsnmp_defaultrouter_entry *entry;
106 mib2_ipRouteEntry_t Curentry, Nextentry;
107 int req_type;
108 int err = 0;
109 int idx_offset = 0;
110
111 for (Nextentry.ipRouteDest = (u_long) -2, req_type = GET_FIRST;;
112 Nextentry = Curentry, req_type = GET_NEXT) {
113 if (getMibstat(MIB_IP_ROUTE, &Curentry, sizeof(mib2_ipRouteEntry_t),
114 req_type, &IP_Cmp_Route, &Nextentry) != 0)
115 break;
116 DEBUGMSGTL(("access:defaultrouter", "nexthop %x type %x\n", Curentry.ipRouteNextHop, Curentry.ipRouteInfo.re_ire_type));
117 if (!(Curentry.ipRouteInfo.re_ire_type & IRE_DEFAULT))
118 continue;
119 entry = netsnmp_access_defaultrouter_entry_create();
120 Curentry.ipRouteIfIndex.o_bytes[Curentry.ipRouteIfIndex.o_length] = '\0';
121 entry->ns_dr_index = ++idx_offset;
122 entry->dr_if_index = netsnmp_access_interface_index_find(
123 Curentry.ipRouteIfIndex.o_bytes);
124
125 entry->dr_addresstype = INETADDRESSTYPE_IPV4;
126 entry->dr_address_len = 4;
127 memcpy(entry->dr_address, &Curentry.ipRouteNextHop, 4);
128
129 entry->dr_lifetime = Curentry.ipRouteAge;
130 entry->dr_preference = Curentry.ipRouteMetric1;
131
132 if ((err = CONTAINER_INSERT(container, entry)) < 0) {
133 DEBUGMSGTL(("access:defaultrouter:container",
134 "error with defaultrouter_entry: "
135 "insert into container failed.\n"));
136 netsnmp_access_defaultrouter_entry_free(entry);
137 /* goto out; */
138 }
139 }
140
141 return 0;
142 }