| 1 |
#include <net-snmp/net-snmp-config.h> |
| 2 |
#include <net-snmp/net-snmp-includes.h> |
| 3 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 4 |
|
| 5 |
#include "sctpAssocTable.h" |
| 6 |
#include "sctpAssocLocalAddrTable.h" |
| 7 |
#include "sctpAssocRemAddrTable.h" |
| 8 |
#include "sctpTables_common.h" |
| 9 |
|
| 10 |
#include <util_funcs.h> |
| 11 |
|
| 12 |
#include <stdio.h> |
| 13 |
#include <errno.h> |
| 14 |
#include <stdlib.h> |
| 15 |
#include <unistd.h> |
| 16 |
#include <sys/types.h> |
| 17 |
#include <stdint.h> |
| 18 |
#include <sys/socket.h> |
| 19 |
#include <inet/mib2.h> |
| 20 |
|
| 21 |
#include "kernel_sunos5.h" |
| 22 |
|
| 23 |
static int |
| 24 |
parse_assoc_local_address(sctpTables_containers * containers, |
| 25 |
mib2_sctpConnLocalEntry_t *lce) |
| 26 |
{ |
| 27 |
int ret; |
| 28 |
sctpAssocLocalAddrTable_entry *entry; |
| 29 |
entry = sctpAssocLocalAddrTable_entry_create(); |
| 30 |
if (entry == NULL) |
| 31 |
return SNMP_ERR_GENERR; |
| 32 |
|
| 33 |
entry->sctpAssocId = 0; |
| 34 |
entry->sctpAssocLocalAddrType = lce->sctpAssocLocalAddrType; |
| 35 |
if (lce->sctpAssocLocalAddrType == INETADDRESSTYPE_IPV4) { |
| 36 |
entry->sctpAssocLocalAddr_len = 4; |
| 37 |
memcpy(entry->sctpAssocLocalAddr, |
| 38 |
lce->sctpAssocLocalAddr.s6_addr+12, |
| 39 |
entry->sctpAssocLocalAddr_len); |
| 40 |
} else if (lce->sctpAssocLocalAddrType == INETADDRESSTYPE_IPV6) { |
| 41 |
entry->sctpAssocLocalAddr_len = 16; |
| 42 |
memcpy(entry->sctpAssocLocalAddr, |
| 43 |
&lce->sctpAssocLocalAddr, |
| 44 |
entry->sctpAssocLocalAddr_len); |
| 45 |
} |
| 46 |
entry->sctpAssocLocalAddrStartTime = 0; |
| 47 |
ret = sctpAssocLocalAddrTable_add_or_update(containers->sctpAssocLocalAddrTable, |
| 48 |
entry); |
| 49 |
return ret; |
| 50 |
} |
| 51 |
|
| 52 |
static int |
| 53 |
parse_assoc(sctpTables_containers * containers, mib2_sctpConnEntry_t *sce) |
| 54 |
{ |
| 55 |
int ret; |
| 56 |
sctpAssocTable_entry *entry; |
| 57 |
|
| 58 |
entry = sctpAssocTable_entry_create(); |
| 59 |
if (entry == NULL) |
| 60 |
return SNMP_ERR_GENERR; |
| 61 |
|
| 62 |
switch (sce->sctpAssocState) { |
| 63 |
case MIB2_SCTP_closed: |
| 64 |
entry->sctpAssocState = SCTPASSOCSTATE_CLOSED; |
| 65 |
break; |
| 66 |
case MIB2_SCTP_cookieWait: |
| 67 |
entry->sctpAssocState = SCTPASSOCSTATE_COOKIEWAIT; |
| 68 |
break; |
| 69 |
case MIB2_SCTP_cookieEchoed: |
| 70 |
entry->sctpAssocState = SCTPASSOCSTATE_COOKIEECHOED; |
| 71 |
break; |
| 72 |
case MIB2_SCTP_established: |
| 73 |
entry->sctpAssocState = SCTPASSOCSTATE_ESTABLISHED; |
| 74 |
break; |
| 75 |
case MIB2_SCTP_shutdownPending: |
| 76 |
entry->sctpAssocState = SCTPASSOCSTATE_SHUTDOWNPENDING; |
| 77 |
break; |
| 78 |
case MIB2_SCTP_shutdownSent: |
| 79 |
entry->sctpAssocState = SCTPASSOCSTATE_SHUTDOWNSENT; |
| 80 |
break; |
| 81 |
case MIB2_SCTP_shutdownReceived: |
| 82 |
entry->sctpAssocState = SCTPASSOCSTATE_SHUTDOWNRECEIVED; |
| 83 |
break; |
| 84 |
case MIB2_SCTP_shutdownAckSent: |
| 85 |
entry->sctpAssocState = SCTPASSOCSTATE_SHUTDOWNACKSENT; |
| 86 |
break; |
| 87 |
} |
| 88 |
entry->sctpAssocHeartBeatInterval = sce->sctpAssocHeartBeatInterval; |
| 89 |
entry->sctpAssocId = sce->sctpAssocId; |
| 90 |
entry->sctpAssocPrimProcess = sce->sctpAssocPrimProcess; |
| 91 |
entry->sctpAssocLocalPort = sce->sctpAssocLocalPort; |
| 92 |
entry->sctpAssocRemPrimAddrType = sce->sctpAssocRemPrimAddrType; |
| 93 |
if (entry->sctpAssocRemPrimAddrType == INETADDRESSTYPE_IPV4) { |
| 94 |
entry->sctpAssocRemPrimAddr_len = 4; |
| 95 |
memcpy(entry->sctpAssocRemPrimAddr, sce->sctpAssocRemPrimAddr.s6_addr+12, |
| 96 |
entry->sctpAssocRemPrimAddr_len); |
| 97 |
} |
| 98 |
else { |
| 99 |
entry->sctpAssocRemPrimAddr_len = 16; |
| 100 |
memcpy(entry->sctpAssocRemPrimAddr, sce->sctpAssocRemPrimAddr.s6_addr, |
| 101 |
entry->sctpAssocRemPrimAddr_len); |
| 102 |
} |
| 103 |
entry->sctpAssocRemPort = sce->sctpAssocRemPort; |
| 104 |
entry->sctpAssocInStreams = sce->sctpAssocInStreams; |
| 105 |
entry->sctpAssocOutStreams = sce->sctpAssocOutStreams; |
| 106 |
entry->sctpAssocMaxRetr = sce->sctpAssocMaxRetr; |
| 107 |
entry->sctpAssocT1expireds = sce->sctpAssocT1expired; |
| 108 |
entry->sctpAssocRtxChunks = sce->sctpAssocRtxChunks; |
| 109 |
entry->sctpAssocT2expireds = sce->sctpAssocT2expired; |
| 110 |
entry->sctpAssocRemHostName[0] = 0; |
| 111 |
entry->sctpAssocRemHostName_len = 0; |
| 112 |
entry->sctpAssocDiscontinuityTime = 0; |
| 113 |
entry->sctpAssocStartTime = sce->sctpAssocStartTime; |
| 114 |
|
| 115 |
ret = sctpAssocTable_add_or_update(containers->sctpAssocTable, entry); |
| 116 |
return ret; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
static int |
| 121 |
parse_assoc_remote_address(sctpTables_containers * containers, |
| 122 |
mib2_sctpConnRemoteEntry_t *rce) |
| 123 |
{ |
| 124 |
int ret; |
| 125 |
sctpAssocRemAddrTable_entry *entry; |
| 126 |
|
| 127 |
entry = sctpAssocRemAddrTable_entry_create(); |
| 128 |
if (entry == NULL) |
| 129 |
return SNMP_ERR_GENERR; |
| 130 |
|
| 131 |
entry->sctpAssocId = rce->sctpAssocId; |
| 132 |
entry->sctpAssocRemAddrActive = rce->sctpAssocRemAddrActive; |
| 133 |
entry->sctpAssocRemAddrHBActive = rce->sctpAssocRemAddrHBActive; |
| 134 |
entry->sctpAssocRemAddrRTO = rce->sctpAssocRemAddrRTO; |
| 135 |
entry->sctpAssocRemAddrMaxPathRtx = rce->sctpAssocRemAddrMaxPathRtx; |
| 136 |
entry->sctpAssocRemAddrRtx = rce->sctpAssocRemAddrRtx; |
| 137 |
entry->sctpAssocRemAddrStartTime = 0; |
| 138 |
|
| 139 |
entry->sctpAssocRemAddrType = rce->sctpAssocRemAddrType; |
| 140 |
if (rce->sctpAssocRemAddrType == INETADDRESSTYPE_IPV4) { |
| 141 |
entry->sctpAssocRemAddr_len = 4; |
| 142 |
memcpy(entry->sctpAssocRemAddr, |
| 143 |
rce->sctpAssocRemAddr.s6_addr+12, |
| 144 |
entry->sctpAssocRemAddr_len); |
| 145 |
} else if (rce->sctpAssocRemAddrType == INETADDRESSTYPE_IPV6) { |
| 146 |
entry->sctpAssocRemAddr_len = 16; |
| 147 |
memcpy(entry->sctpAssocRemAddr, |
| 148 |
&rce->sctpAssocRemAddr, |
| 149 |
entry->sctpAssocRemAddr_len); |
| 150 |
} |
| 151 |
ret = |
| 152 |
sctpAssocRemAddrTable_add_or_update(containers->sctpAssocRemAddrTable, |
| 153 |
entry); |
| 154 |
return ret; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
int |
| 159 |
sctpTables_arch_load(sctpTables_containers * containers, u_long * flags) |
| 160 |
{ |
| 161 |
int ret = SNMP_ERR_NOERROR; |
| 162 |
mib2_sctpConnEntry_t sce; |
| 163 |
mib2_sctpConnLocalEntry_t lce; |
| 164 |
mib2_sctpConnRemoteEntry_t rce; |
| 165 |
req_e req = GET_FIRST; |
| 166 |
|
| 167 |
while (getMibstat(MIB_SCTP_CONN, &sce, sizeof(sce), req, &Get_everything, 0) == 0) { |
| 168 |
req = GET_NEXT; |
| 169 |
parse_assoc(containers, &sce); |
| 170 |
} |
| 171 |
req = GET_FIRST; |
| 172 |
while (getMibstat(MIB_SCTP_CONN_LOCAL, &lce, sizeof(lce), req, &Get_everything, 0) == 0) { |
| 173 |
req = GET_NEXT; |
| 174 |
parse_assoc_local_address(containers, &lce); |
| 175 |
} |
| 176 |
req = GET_FIRST; |
| 177 |
while (getMibstat(MIB_SCTP_CONN_REMOTE, &rce, sizeof(rce), req, &Get_everything, 0) == 0) { |
| 178 |
req = GET_NEXT; |
| 179 |
parse_assoc_remote_address(containers, &rce); |
| 180 |
} |
| 181 |
return ret; |
| 182 |
} |