| 1 |
/* |
| 2 |
* IP-MIB architecture support |
| 3 |
* |
| 4 |
*/ |
| 5 |
#include <net-snmp/net-snmp-config.h> |
| 6 |
#include <net-snmp/net-snmp-features.h> |
| 7 |
#include <net-snmp/net-snmp-includes.h> |
| 8 |
|
| 9 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 10 |
#include <net-snmp/data_access/ipaddress.h> |
| 11 |
#include <net-snmp/data_access/interface.h> |
| 12 |
|
| 13 |
#include "ip-mib/ipAddressTable/ipAddressTable_constants.h" |
| 14 |
#include "ipaddress_private.h" |
| 15 |
|
| 16 |
#include "kernel_sunos5.h" |
| 17 |
#include "mibII/mibII_common.h" |
| 18 |
|
| 19 |
netsnmp_feature_child_of(ipaddress_arch_entry_copy, ipaddress_common); |
| 20 |
|
| 21 |
static int _load_v4(netsnmp_container *container, int idx_offset); |
| 22 |
#if defined( NETSNMP_ENABLE_IPV6 ) |
| 23 |
static int _load_v6(netsnmp_container *container, int idx_offset); |
| 24 |
#endif |
| 25 |
|
| 26 |
/* |
| 27 |
* initialize arch specific storage |
| 28 |
* |
| 29 |
* @retval 0: success |
| 30 |
* @retval <0: error |
| 31 |
*/ |
| 32 |
int |
| 33 |
netsnmp_arch_ipaddress_entry_init(netsnmp_ipaddress_entry *entry) |
| 34 |
{ |
| 35 |
init_kernel_sunos5(); |
| 36 |
return 0; |
| 37 |
} |
| 38 |
|
| 39 |
/* |
| 40 |
* cleanup arch specific storage |
| 41 |
*/ |
| 42 |
void |
| 43 |
netsnmp_arch_ipaddress_entry_cleanup(netsnmp_ipaddress_entry *entry) |
| 44 |
{ |
| 45 |
/* |
| 46 |
* Nothing to do. |
| 47 |
*/ |
| 48 |
} |
| 49 |
|
| 50 |
#ifndef NETSNMP_FEATURE_REMOVE_IPADDRESS_ARCH_ENTRY_COPY |
| 51 |
/* |
| 52 |
* copy arch specific storage |
| 53 |
*/ |
| 54 |
int |
| 55 |
netsnmp_arch_ipaddress_entry_copy(netsnmp_ipaddress_entry *lhs, |
| 56 |
netsnmp_ipaddress_entry *rhs) |
| 57 |
{ |
| 58 |
/* |
| 59 |
* Nothing to do. |
| 60 |
*/ |
| 61 |
return 0; |
| 62 |
} |
| 63 |
#endif /* NETSNMP_FEATURE_REMOVE_IPADDRESS_ARCH_ENTRY_COPY */ |
| 64 |
|
| 65 |
/* |
| 66 |
* create a new entry |
| 67 |
*/ |
| 68 |
int |
| 69 |
netsnmp_arch_ipaddress_create(netsnmp_ipaddress_entry *entry) |
| 70 |
{ |
| 71 |
if (NULL == entry) |
| 72 |
return -1; |
| 73 |
|
| 74 |
DEBUGMSGT(("access:ipaddress:create", "not applicable\n")); |
| 75 |
return 0; |
| 76 |
} |
| 77 |
|
| 78 |
/* |
| 79 |
* delete an entry |
| 80 |
*/ |
| 81 |
int |
| 82 |
netsnmp_arch_ipaddress_delete(netsnmp_ipaddress_entry *entry) |
| 83 |
{ |
| 84 |
if (NULL == entry) |
| 85 |
return -1; |
| 86 |
|
| 87 |
DEBUGMSGT(("access:ipaddress:create", "not applicable\n")); |
| 88 |
return 0; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* |
| 93 |
* @retval 0 no errors |
| 94 |
* @retval !0 errors |
| 95 |
*/ |
| 96 |
int |
| 97 |
netsnmp_arch_ipaddress_container_load(netsnmp_container *container, |
| 98 |
u_int load_flags) |
| 99 |
{ |
| 100 |
int rc = 0, idx_offset = 0; |
| 101 |
|
| 102 |
if (!(load_flags & NETSNMP_ACCESS_IPADDRESS_LOAD_IPV6_ONLY)) { |
| 103 |
rc = _load_v4(container, idx_offset); |
| 104 |
if(rc < 0) { |
| 105 |
u_int flags = NETSNMP_ACCESS_IPADDRESS_FREE_KEEP_CONTAINER; |
| 106 |
netsnmp_access_ipaddress_container_free(container, flags); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
#if defined( NETSNMP_ENABLE_IPV6 ) |
| 111 |
|
| 112 |
if (!(load_flags & NETSNMP_ACCESS_IPADDRESS_LOAD_IPV4_ONLY)) { |
| 113 |
if (rc < 0) |
| 114 |
rc = 0; |
| 115 |
|
| 116 |
idx_offset = rc; |
| 117 |
|
| 118 |
rc = _load_v6(container, idx_offset); |
| 119 |
if(rc < 0) { |
| 120 |
u_int flags = NETSNMP_ACCESS_IPADDRESS_FREE_KEEP_CONTAINER; |
| 121 |
netsnmp_access_ipaddress_container_free(container, flags); |
| 122 |
} |
| 123 |
} |
| 124 |
#endif |
| 125 |
|
| 126 |
/* |
| 127 |
* return no errors (0) if we found any interfaces |
| 128 |
*/ |
| 129 |
if(rc > 0) |
| 130 |
rc = 0; |
| 131 |
return rc; |
| 132 |
} |
| 133 |
|
| 134 |
/* |
| 135 |
* @retval >=idx_offset ok |
| 136 |
* @retval -1 memory allocation error |
| 137 |
* @retval -2 interface lookup error |
| 138 |
* @retval -3 container error |
| 139 |
*/ |
| 140 |
static int |
| 141 |
_load_v4(netsnmp_container *container, int idx_offset) |
| 142 |
{ |
| 143 |
mib2_ipAddrEntry_t ipae; |
| 144 |
netsnmp_ipaddress_entry *entry; |
| 145 |
req_e req = GET_FIRST; |
| 146 |
int rc = 0; |
| 147 |
|
| 148 |
DEBUGMSGTL(("access:ipaddress:container", "loading v4\n")); |
| 149 |
while ((rc = getMibstat(MIB_IP_ADDR, &ipae, sizeof(ipae), req, |
| 150 |
&Get_everything, NULL)) == 0) { |
| 151 |
req = GET_NEXT; |
| 152 |
if (ipae.ipAdEntAddr == INADDR_ANY) |
| 153 |
continue; |
| 154 |
entry = netsnmp_access_ipaddress_entry_create(); |
| 155 |
if (entry == NULL) |
| 156 |
return (-1); |
| 157 |
|
| 158 |
ipae.ipAdEntIfIndex.o_bytes[ipae.ipAdEntIfIndex.o_length] = '\0'; |
| 159 |
DEBUGMSGTL(("access:ipaddress:container", "found if %s\n", |
| 160 |
ipae.ipAdEntIfIndex.o_bytes)); |
| 161 |
/* Obtain interface index */ |
| 162 |
entry->if_index = |
| 163 |
netsnmp_access_interface_index_find(ipae.ipAdEntIfIndex.o_bytes); |
| 164 |
if (entry->if_index == 0) { |
| 165 |
DEBUGMSGTL(("access:ipaddress:container", "cannot find if %s\n", |
| 166 |
ipae.ipAdEntIfIndex.o_bytes)); |
| 167 |
netsnmp_access_ipaddress_entry_free(entry); |
| 168 |
return (-2); |
| 169 |
} |
| 170 |
|
| 171 |
if (strchr((const char *)&ipae.ipAdEntIfIndex.o_bytes, ':') != 0) |
| 172 |
entry->flags |= NETSNMP_ACCESS_IPADDRESS_ISALIAS; |
| 173 |
|
| 174 |
/* Get the address */ |
| 175 |
entry->ia_address_len = sizeof(ipae.ipAdEntAddr); |
| 176 |
netsnmp_assert(entry->ia_address_len == 4 && |
| 177 |
entry->ia_address_len <= sizeof(entry->ia_address)); |
| 178 |
memcpy(&entry->ia_address, &ipae.ipAdEntAddr, entry->ia_address_len); |
| 179 |
|
| 180 |
/* prefix */ |
| 181 |
entry->ia_prefix_len = ipae.ipAdEntInfo.ae_subnet_len; |
| 182 |
|
| 183 |
/* set the Origin */ |
| 184 |
if (ipae.ipAdEntInfo.ae_flags & IFF_DHCPRUNNING) |
| 185 |
entry->ia_origin = IPADDRESSORIGINTC_DHCP; |
| 186 |
else |
| 187 |
entry->ia_origin = IPADDRESSORIGINTC_MANUAL; |
| 188 |
|
| 189 |
/* set ipv4 constants */ |
| 190 |
entry->ia_type = IPADDRESSTYPE_UNICAST; |
| 191 |
entry->ia_status = IPADDRESSSTATUSTC_PREFERRED; |
| 192 |
|
| 193 |
entry->ns_ia_index = ++idx_offset; |
| 194 |
|
| 195 |
DEBUGMSGTL(("access:ipaddress:container", "insert if %" NETSNMP_PRIo "u, addrlen %d\n", |
| 196 |
entry->if_index, entry->ia_address_len)); |
| 197 |
|
| 198 |
if (CONTAINER_INSERT(container, entry) < 0) { |
| 199 |
DEBUGMSGTL(("access:ipaddress:container", "unable to insert %s\n", |
| 200 |
ipae.ipAdEntIfIndex.o_bytes)); |
| 201 |
netsnmp_access_ipaddress_entry_free(entry); |
| 202 |
return (-3); |
| 203 |
} |
| 204 |
} |
| 205 |
return (idx_offset); |
| 206 |
} |
| 207 |
|
| 208 |
/* |
| 209 |
* @retval >=idx_offset ok |
| 210 |
* @retval -1 memory allocation error |
| 211 |
* @retval -2 interface lookup error |
| 212 |
* @retval -3 container error |
| 213 |
*/ |
| 214 |
#if defined( NETSNMP_ENABLE_IPV6 ) |
| 215 |
static int |
| 216 |
_load_v6(netsnmp_container *container, int idx_offset) |
| 217 |
{ |
| 218 |
mib2_ipv6AddrEntry_t ip6ae; |
| 219 |
netsnmp_ipaddress_entry *entry; |
| 220 |
req_e req = GET_FIRST; |
| 221 |
int rc = 0; |
| 222 |
|
| 223 |
DEBUGMSGTL(("access:ipaddress:container", "loading v6... cache %d\n", |
| 224 |
MIB_IP6_ADDR)); |
| 225 |
while ((rc = getMibstat(MIB_IP6_ADDR, &ip6ae, sizeof(ip6ae), req, |
| 226 |
&Get_everything, NULL)) == 0) { |
| 227 |
req = GET_NEXT; |
| 228 |
if (memcmp((const void *)&ip6ae.ipv6AddrAddress, |
| 229 |
(const void *)&in6addr_any, |
| 230 |
sizeof (ip6ae.ipv6AddrAddress)) == 0) |
| 231 |
continue; |
| 232 |
entry = netsnmp_access_ipaddress_entry_create(); |
| 233 |
if (entry == NULL) |
| 234 |
return (-1); |
| 235 |
|
| 236 |
ip6ae.ipv6AddrIfIndex.o_bytes[ip6ae.ipv6AddrIfIndex.o_length] = '\0'; |
| 237 |
DEBUGMSGTL(("access:ipaddress:container", "found if %s\n", |
| 238 |
ip6ae.ipv6AddrIfIndex.o_bytes)); |
| 239 |
|
| 240 |
/* Obtain interface index */ |
| 241 |
entry->if_index = |
| 242 |
netsnmp_access_interface_index_find( |
| 243 |
ip6ae.ipv6AddrIfIndex.o_bytes); |
| 244 |
if (entry->if_index == 0) { |
| 245 |
DEBUGMSGTL(("access:ipaddress:container", "cannot find if %s\n", |
| 246 |
ip6ae.ipv6AddrIfIndex.o_bytes)); |
| 247 |
netsnmp_access_ipaddress_entry_free(entry); |
| 248 |
return (-2); |
| 249 |
} |
| 250 |
|
| 251 |
/* Get the address */ |
| 252 |
entry->ia_address_len = sizeof(ip6ae.ipv6AddrAddress); |
| 253 |
netsnmp_assert(entry->ia_address_len == 16 && |
| 254 |
entry->ia_address_len <= sizeof(entry->ia_address)); |
| 255 |
memcpy(&entry->ia_address, &ip6ae.ipv6AddrAddress, |
| 256 |
entry->ia_address_len); |
| 257 |
|
| 258 |
/* prefix */ |
| 259 |
entry->ia_prefix_len = ip6ae.ipv6AddrPfxLength; |
| 260 |
|
| 261 |
/* type is anycast? (mib2.h: 1 = yes, 2 = no) */ |
| 262 |
entry->ia_type = (ip6ae.ipv6AddrAnycastFlag == 1) ? |
| 263 |
IPADDRESSTYPE_ANYCAST : IPADDRESSTYPE_UNICAST; |
| 264 |
|
| 265 |
/* origin (mib2.h: 1 = stateless, 2 = stateful, 3 = unknown) */ |
| 266 |
DEBUGMSGTL(("access:ipaddress:container", "origin %d\n", |
| 267 |
ip6ae.ipv6AddrType)); |
| 268 |
if (ip6ae.ipv6AddrType == 1) |
| 269 |
entry->ia_origin = IPADDRESSORIGINTC_LINKLAYER; |
| 270 |
else if (ip6ae.ipv6AddrInfo.ae_flags & IFF_DHCPRUNNING) |
| 271 |
entry->ia_origin = IPADDRESSORIGINTC_DHCP; |
| 272 |
else |
| 273 |
entry->ia_origin = IPADDRESSORIGINTC_MANUAL; |
| 274 |
|
| 275 |
/* status */ |
| 276 |
entry->ia_status = ip6ae.ipv6AddrStatus; |
| 277 |
|
| 278 |
entry->ns_ia_index = ++idx_offset; |
| 279 |
|
| 280 |
DEBUGMSGTL(("access:ipaddress:container", "insert if %" NETSNMP_PRIo "u, addrlen %d\n", |
| 281 |
entry->if_index, entry->ia_address_len)); |
| 282 |
|
| 283 |
if (CONTAINER_INSERT(container, entry) < 0) { |
| 284 |
DEBUGMSGTL(("access:ipaddress:container", "unable to insert %s\n", |
| 285 |
ip6ae.ipv6AddrIfIndex.o_bytes)); |
| 286 |
netsnmp_access_ipaddress_entry_free(entry); |
| 287 |
return (-3); |
| 288 |
} |
| 289 |
} |
| 290 |
return (idx_offset); |
| 291 |
} |
| 292 |
#endif /* defined( NETSNMP_ENABLE_IPV6 ) */ |