| 1 |
#include <net-snmp/net-snmp-config.h> |
| 2 |
#include <net-snmp/net-snmp-includes.h> |
| 3 |
|
| 4 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 5 |
#include <net-snmp/data_access/tcpConn.h> |
| 6 |
|
| 7 |
#include "tcp-mib/tcpConnectionTable/tcpConnectionTable_constants.h" |
| 8 |
#include "tcp-mib/data_access/tcpConn_private.h" |
| 9 |
|
| 10 |
#include "kernel_sunos5.h" |
| 11 |
|
| 12 |
static int _load_tcpconn_table_v4(netsnmp_container *, int); |
| 13 |
#if defined(NETSNMP_ENABLE_IPV6) && defined(SOLARIS_HAVE_IPV6_MIB_SUPPORT) |
| 14 |
static int _load_tcpconn_table_v6(netsnmp_container *, int); |
| 15 |
#endif |
| 16 |
|
| 17 |
int |
| 18 |
netsnmp_arch_tcpconn_entry_init(netsnmp_tcpconn_entry *ep) |
| 19 |
{ |
| 20 |
init_kernel_sunos5(); |
| 21 |
return 0; |
| 22 |
} |
| 23 |
|
| 24 |
void |
| 25 |
netsnmp_arch_tcpconn_entry_cleanup(netsnmp_tcpconn_entry *ep) |
| 26 |
{ |
| 27 |
/* |
| 28 |
* Do nothing |
| 29 |
*/ |
| 30 |
} |
| 31 |
|
| 32 |
int |
| 33 |
netsnmp_arch_tcpconn_entry_copy(netsnmp_tcpconn_entry *ep1, |
| 34 |
netsnmp_tcpconn_entry *ep2) |
| 35 |
{ |
| 36 |
/* |
| 37 |
* Do nothing |
| 38 |
*/ |
| 39 |
return 0; |
| 40 |
} |
| 41 |
|
| 42 |
#ifdef TCPCONN_DELETE_SUPPORTED |
| 43 |
int |
| 44 |
netsnmp_arch_tcpconn_entry_delete(netsnmp_tcpconn_entry *ep) |
| 45 |
{ |
| 46 |
/* |
| 47 |
* Not implemented |
| 48 |
*/ |
| 49 |
return (-1); |
| 50 |
} |
| 51 |
#endif /* TCPCONN_DELETE_SUPPORTED */ |
| 52 |
|
| 53 |
int |
| 54 |
netsnmp_arch_tcpconn_container_load(netsnmp_container * container, |
| 55 |
u_int load_flag) |
| 56 |
{ |
| 57 |
int rc; |
| 58 |
|
| 59 |
if ((rc = _load_tcpconn_table_v4(container, load_flag)) != 0) { |
| 60 |
u_int flag = NETSNMP_ACCESS_TCPCONN_FREE_KEEP_CONTAINER; |
| 61 |
netsnmp_access_tcpconn_container_free(container, flag); |
| 62 |
return (rc); |
| 63 |
} |
| 64 |
#if defined(NETSNMP_ENABLE_IPV6) && defined(SOLARIS_HAVE_IPV6_MIB_SUPPORT) |
| 65 |
if ((rc = _load_tcpconn_table_v6(container, load_flag)) != 0) { |
| 66 |
u_int flag = NETSNMP_ACCESS_TCPCONN_FREE_KEEP_CONTAINER; |
| 67 |
netsnmp_access_tcpconn_container_free(container, flag); |
| 68 |
return (rc); |
| 69 |
} |
| 70 |
#endif |
| 71 |
return (0); |
| 72 |
} |
| 73 |
|
| 74 |
static int |
| 75 |
_load_tcpconn_table_v4(netsnmp_container *container, int flag) |
| 76 |
{ |
| 77 |
mib2_tcpConnEntry_t tc; |
| 78 |
netsnmp_tcpconn_entry *ep; |
| 79 |
req_e req = GET_FIRST; |
| 80 |
|
| 81 |
DEBUGMSGT(("access:tcpconn:container", "load v4\n")); |
| 82 |
|
| 83 |
while (getMibstat(MIB_TCP_CONN, &tc, sizeof(tc), req, |
| 84 |
&Get_everything, 0)==0) { |
| 85 |
req = GET_NEXT; |
| 86 |
if ((flag & NETSNMP_ACCESS_TCPCONN_LOAD_ONLYLISTEN && |
| 87 |
tc.tcpConnState != MIB2_TCP_listen) || |
| 88 |
(flag & NETSNMP_ACCESS_TCPCONN_LOAD_NOLISTEN && |
| 89 |
tc.tcpConnState == MIB2_TCP_listen)) { |
| 90 |
continue; |
| 91 |
} |
| 92 |
ep = netsnmp_access_tcpconn_entry_create(); |
| 93 |
if (ep == NULL) |
| 94 |
return (-1); |
| 95 |
DEBUGMSGT(("access:tcpconn:container", "add entry\n")); |
| 96 |
|
| 97 |
/* |
| 98 |
* local address/port. |
| 99 |
*/ |
| 100 |
ep->loc_addr_len = sizeof(tc.tcpConnLocalAddress); |
| 101 |
if (sizeof(ep->loc_addr) < ep->loc_addr_len) { |
| 102 |
netsnmp_access_tcpconn_entry_free(ep); |
| 103 |
return (-1); |
| 104 |
} |
| 105 |
(void)memcpy(&ep->loc_addr, &tc.tcpConnLocalAddress, ep->loc_addr_len); |
| 106 |
|
| 107 |
ep->loc_port = tc.tcpConnLocalPort; |
| 108 |
|
| 109 |
/* |
| 110 |
* remote address/port. The address length is the same as the |
| 111 |
* local address, so no check needed. |
| 112 |
*/ |
| 113 |
ep->rmt_addr_len = sizeof(tc.tcpConnRemAddress); |
| 114 |
(void)memcpy(&ep->rmt_addr, &tc.tcpConnRemAddress, ep->rmt_addr_len); |
| 115 |
|
| 116 |
ep->rmt_port = tc.tcpConnRemPort; |
| 117 |
|
| 118 |
/* state/pid */ |
| 119 |
ep->tcpConnState = tc.tcpConnState; |
| 120 |
ep->pid = 0; |
| 121 |
ep->arch_data = NULL; |
| 122 |
|
| 123 |
/* index */ |
| 124 |
ep->arbitrary_index = CONTAINER_SIZE(container) + 1; |
| 125 |
CONTAINER_INSERT(container, (void *)ep); |
| 126 |
} |
| 127 |
return (0); |
| 128 |
} |
| 129 |
|
| 130 |
#if defined(NETSNMP_ENABLE_IPV6) && defined(SOLARIS_HAVE_IPV6_MIB_SUPPORT) |
| 131 |
static int |
| 132 |
_load_tcpconn_table_v6(netsnmp_container *container, int flag) |
| 133 |
{ |
| 134 |
mib2_tcp6ConnEntry_t tc6; |
| 135 |
netsnmp_tcpconn_entry *ep; |
| 136 |
req_e req = GET_FIRST; |
| 137 |
|
| 138 |
DEBUGMSGT(("access:tcpconn:container", "load v6\n")); |
| 139 |
|
| 140 |
while (getMibstat(MIB_TCP6_CONN, &tc6, sizeof(tc6), req, |
| 141 |
&Get_everything, 0)==0) { |
| 142 |
req = GET_NEXT; |
| 143 |
if ((flag & NETSNMP_ACCESS_TCPCONN_LOAD_ONLYLISTEN && |
| 144 |
tc6.tcp6ConnState != MIB2_TCP_listen) || |
| 145 |
(flag & NETSNMP_ACCESS_TCPCONN_LOAD_NOLISTEN && |
| 146 |
tc6.tcp6ConnState == MIB2_TCP_listen)) { |
| 147 |
continue; |
| 148 |
} |
| 149 |
ep = netsnmp_access_tcpconn_entry_create(); |
| 150 |
if (ep == NULL) |
| 151 |
return (-1); |
| 152 |
DEBUGMSGT(("access:tcpconn:container", "add entry\n")); |
| 153 |
|
| 154 |
/* |
| 155 |
* local address/port. |
| 156 |
*/ |
| 157 |
ep->loc_addr_len = sizeof(tc6.tcp6ConnLocalAddress); |
| 158 |
if (sizeof(ep->loc_addr) < ep->loc_addr_len) { |
| 159 |
netsnmp_access_tcpconn_entry_free(ep); |
| 160 |
return (-1); |
| 161 |
} |
| 162 |
(void)memcpy(&ep->loc_addr, &tc6.tcp6ConnLocalAddress, |
| 163 |
ep->loc_addr_len); |
| 164 |
|
| 165 |
ep->loc_port = tc6.tcp6ConnLocalPort; |
| 166 |
|
| 167 |
/* remote address/port */ |
| 168 |
ep->rmt_addr_len = sizeof(tc6.tcp6ConnRemAddress); |
| 169 |
(void)memcpy(&ep->rmt_addr, &tc6.tcp6ConnRemAddress, ep->rmt_addr_len); |
| 170 |
|
| 171 |
ep->rmt_port = tc6.tcp6ConnRemPort; |
| 172 |
|
| 173 |
/* state/pid */ |
| 174 |
ep->tcpConnState = tc6.tcp6ConnState; |
| 175 |
ep->pid = 0; |
| 176 |
ep->arch_data = NULL; |
| 177 |
|
| 178 |
/* index */ |
| 179 |
ep->arbitrary_index = CONTAINER_SIZE(container) + 1; |
| 180 |
CONTAINER_INSERT(container, (void *)ep); |
| 181 |
} |
| 182 |
return (0); |
| 183 |
} |
| 184 |
#endif /*defined(NETSNMP_ENABLE_IPV6)&&defined(SOLARIS_HAVE_IPV6_MIB_SUPPORT)*/ |