| 1 |
#include <net-snmp/net-snmp-config.h> |
| 2 |
#include <net-snmp/net-snmp-features.h> |
| 3 |
#include <net-snmp/net-snmp-includes.h> |
| 4 |
|
| 5 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 6 |
#include <net-snmp/data_access/ipaddress.h> |
| 7 |
#include <net-snmp/data_access/udp_endpoint.h> |
| 8 |
|
| 9 |
#include "udp-mib/udpEndpointTable/udpEndpointTable_constants.h" |
| 10 |
#include "udp-mib/data_access/udp_endpoint_private.h" |
| 11 |
|
| 12 |
#include "kernel_sunos5.h" |
| 13 |
|
| 14 |
netsnmp_feature_require(netsnmp_access_udp_endpoint_entry_create); |
| 15 |
netsnmp_feature_child_of(udp_endpoint_all, libnetsnmpmibs); |
| 16 |
netsnmp_feature_child_of(udp_endpoint_writable, udp_endpoint_all); |
| 17 |
|
| 18 |
static int _load_udp_endpoint_table_v4(netsnmp_container *, int); |
| 19 |
#if defined(NETSNMP_ENABLE_IPV6) && defined(SOLARIS_HAVE_IPV6_MIB_SUPPORT) |
| 20 |
static int _load_udp_endpoint_table_v6(netsnmp_container *, int); |
| 21 |
#endif |
| 22 |
|
| 23 |
#ifndef NETSNMP_FEATURE_REMOVE_UDP_ENDPOINT_WRITABLE |
| 24 |
int |
| 25 |
netsnmp_arch_udp_endpoint_entry_init(netsnmp_udp_endpoint_entry *ep) |
| 26 |
{ |
| 27 |
init_kernel_sunos5(); |
| 28 |
return 0; |
| 29 |
} |
| 30 |
|
| 31 |
void |
| 32 |
netsnmp_arch_udp_endpoint_entry_cleanup(netsnmp_udp_endpoint_entry *ep) |
| 33 |
{ |
| 34 |
/* |
| 35 |
* Do nothing |
| 36 |
*/ |
| 37 |
} |
| 38 |
|
| 39 |
int |
| 40 |
netsnmp_arch_udp_endpoint_entry_copy(netsnmp_udp_endpoint_entry *ep1, |
| 41 |
netsnmp_udp_endpoint_entry *ep2) |
| 42 |
{ |
| 43 |
/* |
| 44 |
* Do nothing |
| 45 |
*/ |
| 46 |
return 0; |
| 47 |
} |
| 48 |
|
| 49 |
int |
| 50 |
netsnmp_arch_udp_endpoint_delete(netsnmp_udp_endpoint_entry *ep) |
| 51 |
{ |
| 52 |
/* |
| 53 |
* Not implemented |
| 54 |
*/ |
| 55 |
return (-1); |
| 56 |
} |
| 57 |
#endif /* NETSNMP_FEATURE_REMOVE_UDP_ENDPOINT_WRITABLE */ |
| 58 |
|
| 59 |
int |
| 60 |
netsnmp_arch_udp_endpoint_container_load(netsnmp_container * container, |
| 61 |
u_int load_flag) |
| 62 |
{ |
| 63 |
int rc; |
| 64 |
|
| 65 |
if ((rc = _load_udp_endpoint_table_v4(container, load_flag)) != 0) { |
| 66 |
u_int flag = NETSNMP_ACCESS_UDP_ENDPOINT_FREE_KEEP_CONTAINER; |
| 67 |
netsnmp_access_udp_endpoint_container_free(container, flag); |
| 68 |
return (rc); |
| 69 |
} |
| 70 |
#if defined(NETSNMP_ENABLE_IPV6) && defined(SOLARIS_HAVE_IPV6_MIB_SUPPORT) |
| 71 |
if ((rc = _load_udp_endpoint_table_v6(container, load_flag)) != 0) { |
| 72 |
u_int flag = NETSNMP_ACCESS_UDP_ENDPOINT_FREE_KEEP_CONTAINER; |
| 73 |
netsnmp_access_udp_endpoint_container_free(container, flag); |
| 74 |
return (rc); |
| 75 |
} |
| 76 |
#endif |
| 77 |
return (0); |
| 78 |
} |
| 79 |
|
| 80 |
static int |
| 81 |
_load_udp_endpoint_table_v4(netsnmp_container *container, int flag) |
| 82 |
{ |
| 83 |
netsnmp_udp_endpoint_entry *ep; |
| 84 |
mib2_udpEntry_t ue; |
| 85 |
req_e req = GET_FIRST; |
| 86 |
|
| 87 |
DEBUGMSGT(("access:udp_endpoint:container", "load v4\n")); |
| 88 |
|
| 89 |
while (getMibstat(MIB_UDP_LISTEN, &ue, sizeof(ue), req, |
| 90 |
&Get_everything, 0)==0) { |
| 91 |
req = GET_NEXT; |
| 92 |
ep = netsnmp_access_udp_endpoint_entry_create(); |
| 93 |
if (ep == NULL) |
| 94 |
return (-1); |
| 95 |
DEBUGMSGT(("access:udp_endpoint:container", "add entry\n")); |
| 96 |
|
| 97 |
/* |
| 98 |
* local address/port. |
| 99 |
*/ |
| 100 |
ep->loc_addr_len = sizeof(ue.udpLocalAddress); |
| 101 |
if (sizeof(ep->loc_addr) < ep->loc_addr_len) { |
| 102 |
netsnmp_access_udp_endpoint_entry_free(ep); |
| 103 |
return (-1); |
| 104 |
} |
| 105 |
memcpy(&ep->loc_addr, &ue.udpLocalAddress, ep->loc_addr_len); |
| 106 |
|
| 107 |
ep->loc_port = ue.udpLocalPort; |
| 108 |
|
| 109 |
/* |
| 110 |
* remote address/port. The address length is the same as the |
| 111 |
* local address, so no check needed. If the remote address is |
| 112 |
* unspecified, then the type should be set to "unknown" (per RFC 4113). |
| 113 |
*/ |
| 114 |
if (ue.udpEntryInfo.ue_RemoteAddress == INADDR_ANY) { |
| 115 |
ep->rmt_addr_len = 0; |
| 116 |
} else { |
| 117 |
ep->rmt_addr_len = sizeof(ue.udpEntryInfo.ue_RemoteAddress); |
| 118 |
memcpy(&ep->rmt_addr, &ue.udpEntryInfo.ue_RemoteAddress, |
| 119 |
ep->rmt_addr_len); |
| 120 |
} |
| 121 |
|
| 122 |
ep->rmt_port = ue.udpEntryInfo.ue_RemotePort; |
| 123 |
|
| 124 |
/* |
| 125 |
* instance - if there is support for RFC 4293, then we also have |
| 126 |
* support for RFC 4113. |
| 127 |
*/ |
| 128 |
#ifdef SOLARIS_HAVE_RFC4293_SUPPORT |
| 129 |
ep->instance = ue.udpInstance; |
| 130 |
#else |
| 131 |
ep->instance = 0; |
| 132 |
#endif |
| 133 |
|
| 134 |
/* state */ |
| 135 |
ep->state = 0; |
| 136 |
|
| 137 |
/* index */ |
| 138 |
ep->index = CONTAINER_SIZE(container) + 1; |
| 139 |
ep->oid_index.oids = &ep->index; |
| 140 |
ep->oid_index.len = 1; |
| 141 |
|
| 142 |
CONTAINER_INSERT(container, (void *)ep); |
| 143 |
} |
| 144 |
return (0); |
| 145 |
} |
| 146 |
|
| 147 |
#if defined(NETSNMP_ENABLE_IPV6) && defined(SOLARIS_HAVE_IPV6_MIB_SUPPORT) |
| 148 |
static int |
| 149 |
_load_udp_endpoint_table_v6(netsnmp_container *container, int flag) |
| 150 |
{ |
| 151 |
netsnmp_udp_endpoint_entry *ep; |
| 152 |
mib2_udp6Entry_t ue6; |
| 153 |
req_e req = GET_FIRST; |
| 154 |
|
| 155 |
DEBUGMSGT(("access:udp_endpoint:container", "load v6\n")); |
| 156 |
|
| 157 |
while (getMibstat(MIB_UDP6_ENDPOINT, &ue6, sizeof(ue6), req, |
| 158 |
&Get_everything, 0)==0) { |
| 159 |
req = GET_NEXT; |
| 160 |
ep = netsnmp_access_udp_endpoint_entry_create(); |
| 161 |
if (ep == NULL) |
| 162 |
return (-1); |
| 163 |
DEBUGMSGT(("access:udp_endpoint:container", "add entry\n")); |
| 164 |
|
| 165 |
/* |
| 166 |
* local address/port. |
| 167 |
*/ |
| 168 |
ep->loc_addr_len = sizeof(ue6.udp6LocalAddress); |
| 169 |
if (sizeof(ep->loc_addr) < ep->loc_addr_len) { |
| 170 |
netsnmp_access_udp_endpoint_entry_free(ep); |
| 171 |
return (-1); |
| 172 |
} |
| 173 |
(void)memcpy(&ep->loc_addr, &ue6.udp6LocalAddress, ep->loc_addr_len); |
| 174 |
|
| 175 |
ep->loc_port = ue6.udp6LocalPort; |
| 176 |
|
| 177 |
/* remote address/port */ |
| 178 |
if (IN6_IS_ADDR_UNSPECIFIED(&ue6.udp6EntryInfo.ue_RemoteAddress)) { |
| 179 |
ep->rmt_addr_len = 0; |
| 180 |
} else { |
| 181 |
ep->rmt_addr_len = sizeof(ue6.udp6EntryInfo.ue_RemoteAddress); |
| 182 |
(void)memcpy(&ep->rmt_addr, &ue6.udp6EntryInfo.ue_RemoteAddress, |
| 183 |
ep->rmt_addr_len); |
| 184 |
} |
| 185 |
ep->rmt_port = ue6.udp6EntryInfo.ue_RemotePort; |
| 186 |
|
| 187 |
/* instance */ |
| 188 |
#ifdef SOLARIS_HAVE_RFC4293_SUPPORT |
| 189 |
ep->instance = ue6.udp6Instance; |
| 190 |
#else |
| 191 |
ep->instance = 0; |
| 192 |
#endif |
| 193 |
/* state */ |
| 194 |
ep->state = 0; |
| 195 |
|
| 196 |
/* index */ |
| 197 |
ep->index = CONTAINER_SIZE(container) + 1; |
| 198 |
ep->oid_index.oids = &ep->index; |
| 199 |
ep->oid_index.len = 1; |
| 200 |
|
| 201 |
CONTAINER_INSERT(container, (void *)ep); |
| 202 |
} |
| 203 |
return (0); |
| 204 |
} |
| 205 |
#endif /* defined(NETSNMP_ENABLE_IPV6)&&defined(SOLARIS_HAVE_IPV6_MIB_SUPPORT)*/ |