| 1 |
|
| 2 |
/* |
| 3 |
* TCP MIB group implementation - tcp.c |
| 4 |
* |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <net-snmp/net-snmp-config.h> |
| 8 |
#include <net-snmp/net-snmp-features.h> |
| 9 |
#include "mibII_common.h" |
| 10 |
|
| 11 |
#ifdef HAVE_STDLIB_H |
| 12 |
#include <stdlib.h> |
| 13 |
#endif |
| 14 |
#ifdef HAVE_UNISTD_H |
| 15 |
#include <unistd.h> |
| 16 |
#endif |
| 17 |
|
| 18 |
#ifdef HAVE_SYS_PROTOSW_H |
| 19 |
#include <sys/protosw.h> |
| 20 |
#endif |
| 21 |
#ifdef HAVE_ARPA_INET_H |
| 22 |
#include <arpa/inet.h> |
| 23 |
#endif |
| 24 |
|
| 25 |
#if defined(osf4) || defined(osf5) || defined(aix4) || defined(hpux10) |
| 26 |
/* |
| 27 |
* these are undefed to remove a stupid warning on osf compilers |
| 28 |
* because they get redefined with a slightly different notation of the |
| 29 |
* same value. -- Wes |
| 30 |
*/ |
| 31 |
#undef TCP_NODELAY |
| 32 |
#undef TCP_MAXSEG |
| 33 |
#endif |
| 34 |
#ifdef HAVE_NETINET_TCP_H |
| 35 |
#include <netinet/tcp.h> |
| 36 |
#endif |
| 37 |
#ifdef HAVE_NETINET_TCPIP_H |
| 38 |
#include <netinet/tcpip.h> |
| 39 |
#endif |
| 40 |
#ifdef HAVE_NETINET_TCP_TIMER_H |
| 41 |
#if __FreeBSD_version >= 1500048 |
| 42 |
#define PR_SLOWHZ 2 /* 2 slow timeouts per second */ |
| 43 |
#define _KERNEL |
| 44 |
#define max(x, y) (((x) > (y)) ? (x) : (y)) |
| 45 |
#define MSEC_2_TICKS(m) max(1, (uint32_t)((hz == 1000) ? \ |
| 46 |
(m) : ((uint64_t)(m) * (uint64_t)hz)/(uint64_t)1000)) |
| 47 |
#endif |
| 48 |
#include <netinet/tcp_timer.h> |
| 49 |
#if __FreeBSD_version >= 1500048 |
| 50 |
#undef _KERNEL |
| 51 |
#endif |
| 52 |
#endif |
| 53 |
#ifdef HAVE_NETINET_TCP_VAR_H |
| 54 |
#ifdef openbsd7 |
| 55 |
#define _KERNEL /* OpenBSD 7.3 */ |
| 56 |
#endif |
| 57 |
#include <netinet/tcp_var.h> |
| 58 |
#ifdef openbsd7 |
| 59 |
#undef _KERNEL |
| 60 |
#endif |
| 61 |
#endif |
| 62 |
#ifdef HAVE_NETINET_TCP_FSM_H |
| 63 |
#include <netinet/tcp_fsm.h> |
| 64 |
#endif |
| 65 |
|
| 66 |
#include <net-snmp/net-snmp-includes.h> |
| 67 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 68 |
#include <net-snmp/agent/auto_nlist.h> |
| 69 |
#include <net-snmp/agent/sysORTable.h> |
| 70 |
|
| 71 |
#include "util_funcs/MIB_STATS_CACHE_TIMEOUT.h" |
| 72 |
#include "tcp.h" |
| 73 |
#include "tcpTable.h" |
| 74 |
|
| 75 |
#ifndef MIB_STATS_CACHE_TIMEOUT |
| 76 |
#define MIB_STATS_CACHE_TIMEOUT 5 |
| 77 |
#endif |
| 78 |
#ifndef TCP_STATS_CACHE_TIMEOUT |
| 79 |
#define TCP_STATS_CACHE_TIMEOUT MIB_STATS_CACHE_TIMEOUT |
| 80 |
#endif |
| 81 |
|
| 82 |
#if defined(HAVE_LIBPERFSTAT_H) && (defined(aix4) || defined(aix5) || defined(aix6) || defined(aix7)) && !defined(FIRST_PROTOCOL) |
| 83 |
#ifdef HAVE_SYS_PROTOSW_H |
| 84 |
#include <sys/protosw.h> |
| 85 |
#endif |
| 86 |
#include <libperfstat.h> |
| 87 |
#ifdef FIRST_PROTOCOL |
| 88 |
perfstat_protocol_t ps_proto; |
| 89 |
perfstat_id_t ps_name; |
| 90 |
#define _USE_FIRST_PROTOCOL 1 |
| 91 |
#endif |
| 92 |
#endif |
| 93 |
|
| 94 |
/********************* |
| 95 |
* |
| 96 |
* Kernel & interface information, |
| 97 |
* and internal forward declarations |
| 98 |
* |
| 99 |
*********************/ |
| 100 |
|
| 101 |
/* |
| 102 |
* FreeBSD4 *does* need an explicit variable 'hz' |
| 103 |
* since this appears in a system header file. |
| 104 |
* But only define it under FreeBSD, since it |
| 105 |
* breaks other systems (notable AIX) |
| 106 |
*/ |
| 107 |
#ifdef freebsd4 |
| 108 |
int hz = 1000; |
| 109 |
#endif |
| 110 |
|
| 111 |
/********************* |
| 112 |
* |
| 113 |
* Initialisation & common implementation functions |
| 114 |
* |
| 115 |
*********************/ |
| 116 |
|
| 117 |
|
| 118 |
/* |
| 119 |
* Define the OID pointer to the top of the mib tree that we're |
| 120 |
* registering underneath, and the OID for the MIB module |
| 121 |
*/ |
| 122 |
oid tcp_oid[] = { SNMP_OID_MIB2, 6 }; |
| 123 |
oid tcp_module_oid[] = { SNMP_OID_MIB2, 49 }; |
| 124 |
|
| 125 |
void |
| 126 |
init_tcp(void) |
| 127 |
{ |
| 128 |
netsnmp_handler_registration *reginfo; |
| 129 |
int rc; |
| 130 |
|
| 131 |
/* |
| 132 |
* register ourselves with the agent as a group of scalars... |
| 133 |
*/ |
| 134 |
DEBUGMSGTL(("mibII/tcpScalar", "Initialising TCP scalar group\n")); |
| 135 |
reginfo = netsnmp_create_handler_registration("tcp", tcp_handler, |
| 136 |
tcp_oid, OID_LENGTH(tcp_oid), HANDLER_CAN_RONLY); |
| 137 |
rc = netsnmp_register_scalar_group(reginfo, TCPRTOALGORITHM, TCPOUTRSTS); |
| 138 |
if (rc != SNMPERR_SUCCESS) |
| 139 |
return; |
| 140 |
|
| 141 |
/* |
| 142 |
* .... with a local cache |
| 143 |
* (except for HP-UX 11, which extracts objects individually) |
| 144 |
*/ |
| 145 |
#ifndef hpux11 |
| 146 |
netsnmp_inject_handler( reginfo, |
| 147 |
netsnmp_get_cache_handler(TCP_STATS_CACHE_TIMEOUT, |
| 148 |
tcp_load, tcp_free, |
| 149 |
tcp_oid, OID_LENGTH(tcp_oid))); |
| 150 |
#endif |
| 151 |
|
| 152 |
REGISTER_SYSOR_ENTRY(tcp_module_oid, |
| 153 |
"The MIB module for managing TCP implementations"); |
| 154 |
|
| 155 |
#if !defined(_USE_FIRST_PROTOCOL) |
| 156 |
#ifdef TCPSTAT_SYMBOL |
| 157 |
auto_nlist(TCPSTAT_SYMBOL, 0, 0); |
| 158 |
#endif |
| 159 |
#ifdef TCP_SYMBOL |
| 160 |
auto_nlist(TCP_SYMBOL, 0, 0); |
| 161 |
#endif |
| 162 |
#ifdef freebsd4 |
| 163 |
hz = sysconf(_SC_CLK_TCK); /* get ticks/s from system */ |
| 164 |
#endif |
| 165 |
#ifdef solaris2 |
| 166 |
init_kernel_sunos5(); |
| 167 |
#endif |
| 168 |
#endif |
| 169 |
} |
| 170 |
|
| 171 |
/********************* |
| 172 |
* |
| 173 |
* System specific implementation functions |
| 174 |
* |
| 175 |
*********************/ |
| 176 |
|
| 177 |
#ifdef hpux11 |
| 178 |
#define TCP_STAT_STRUCTURE int |
| 179 |
#endif |
| 180 |
|
| 181 |
#ifdef linux |
| 182 |
#define TCP_STAT_STRUCTURE struct tcp_mib |
| 183 |
#define USES_SNMP_DESIGNED_TCPSTAT |
| 184 |
#undef TCPSTAT_SYMBOL |
| 185 |
#endif |
| 186 |
|
| 187 |
#ifdef solaris2 |
| 188 |
#define TCP_STAT_STRUCTURE mib2_tcp_t |
| 189 |
#define USES_SNMP_DESIGNED_TCPSTAT |
| 190 |
#endif |
| 191 |
|
| 192 |
#ifdef NETBSD_STATS_VIA_SYSCTL |
| 193 |
#define TCP_STAT_STRUCTURE struct tcp_mib |
| 194 |
#define USES_SNMP_DESIGNED_TCPSTAT |
| 195 |
#undef TCP_NSTATS |
| 196 |
#endif |
| 197 |
|
| 198 |
#ifdef HAVE_IPHLPAPI_H |
| 199 |
#include <iphlpapi.h> |
| 200 |
#define TCP_STAT_STRUCTURE MIB_TCPSTATS |
| 201 |
#endif |
| 202 |
|
| 203 |
#ifdef HAVE_SYS_TCPIPSTATS_H |
| 204 |
#define TCP_STAT_STRUCTURE struct kna |
| 205 |
#define USES_TRADITIONAL_TCPSTAT |
| 206 |
#endif |
| 207 |
|
| 208 |
#ifdef TCP_NSTATS |
| 209 |
typedef uint32_t tcp_stats[TCP_NSTATS]; |
| 210 |
#define TCP_STAT_STRUCTURE tcp_stats |
| 211 |
#endif |
| 212 |
|
| 213 |
#ifdef dragonfly |
| 214 |
#define TCP_STAT_STRUCTURE struct tcp_stats |
| 215 |
#define USES_TRADITIONAL_TCPSTAT |
| 216 |
#endif |
| 217 |
|
| 218 |
#if !defined(TCP_STAT_STRUCTURE) |
| 219 |
#define TCP_STAT_STRUCTURE struct tcpstat |
| 220 |
#define USES_TRADITIONAL_TCPSTAT |
| 221 |
#endif |
| 222 |
|
| 223 |
TCP_STAT_STRUCTURE tcpstat; |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
/********************* |
| 228 |
* |
| 229 |
* System independent handler (mostly) |
| 230 |
* |
| 231 |
*********************/ |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
int |
| 236 |
tcp_handler(netsnmp_mib_handler *handler, |
| 237 |
netsnmp_handler_registration *reginfo, |
| 238 |
netsnmp_agent_request_info *reqinfo, |
| 239 |
netsnmp_request_info *requests) |
| 240 |
{ |
| 241 |
netsnmp_request_info *request; |
| 242 |
netsnmp_variable_list *requestvb; |
| 243 |
long ret_value = -1; |
| 244 |
oid subid; |
| 245 |
int type = ASN_COUNTER; |
| 246 |
|
| 247 |
/* |
| 248 |
* The cached data should already have been loaded by the |
| 249 |
* cache handler, higher up the handler chain. |
| 250 |
* But just to be safe, check this and load it manually if necessary |
| 251 |
*/ |
| 252 |
#if defined(_USE_FIRST_PROTOCOL) |
| 253 |
tcp_load(NULL, NULL); |
| 254 |
#endif |
| 255 |
|
| 256 |
|
| 257 |
/* |
| 258 |
* |
| 259 |
* |
| 260 |
*/ |
| 261 |
DEBUGMSGTL(("mibII/tcpScalar", "Handler - mode %s\n", |
| 262 |
se_find_label_in_slist("agent_mode", reqinfo->mode))); |
| 263 |
switch (reqinfo->mode) { |
| 264 |
case MODE_GET: |
| 265 |
for (request=requests; request; request=request->next) { |
| 266 |
requestvb = request->requestvb; |
| 267 |
subid = requestvb->name[OID_LENGTH(tcp_oid)]; /* XXX */ |
| 268 |
|
| 269 |
DEBUGMSGTL(( "mibII/tcpScalar", "oid: ")); |
| 270 |
DEBUGMSGOID(("mibII/tcpScalar", requestvb->name, |
| 271 |
requestvb->name_length)); |
| 272 |
DEBUGMSG(( "mibII/tcpScalar", "\n")); |
| 273 |
switch (subid) { |
| 274 |
#ifdef USES_SNMP_DESIGNED_TCPSTAT |
| 275 |
case TCPRTOALGORITHM: |
| 276 |
ret_value = tcpstat.tcpRtoAlgorithm; |
| 277 |
type = ASN_INTEGER; |
| 278 |
break; |
| 279 |
case TCPRTOMIN: |
| 280 |
ret_value = tcpstat.tcpRtoMin; |
| 281 |
type = ASN_INTEGER; |
| 282 |
break; |
| 283 |
case TCPRTOMAX: |
| 284 |
ret_value = tcpstat.tcpRtoMax; |
| 285 |
type = ASN_INTEGER; |
| 286 |
break; |
| 287 |
case TCPMAXCONN: |
| 288 |
ret_value = tcpstat.tcpMaxConn; |
| 289 |
type = ASN_INTEGER; |
| 290 |
break; |
| 291 |
case TCPACTIVEOPENS: |
| 292 |
ret_value = tcpstat.tcpActiveOpens; |
| 293 |
break; |
| 294 |
case TCPPASSIVEOPENS: |
| 295 |
ret_value = tcpstat.tcpPassiveOpens; |
| 296 |
break; |
| 297 |
case TCPATTEMPTFAILS: |
| 298 |
ret_value = tcpstat.tcpAttemptFails; |
| 299 |
break; |
| 300 |
case TCPESTABRESETS: |
| 301 |
ret_value = tcpstat.tcpEstabResets; |
| 302 |
break; |
| 303 |
case TCPCURRESTAB: |
| 304 |
ret_value = tcpstat.tcpCurrEstab; |
| 305 |
type = ASN_GAUGE; |
| 306 |
break; |
| 307 |
case TCPINSEGS: |
| 308 |
ret_value = tcpstat.tcpInSegs & 0xffffffff; |
| 309 |
break; |
| 310 |
case TCPOUTSEGS: |
| 311 |
ret_value = tcpstat.tcpOutSegs & 0xffffffff; |
| 312 |
break; |
| 313 |
case TCPRETRANSSEGS: |
| 314 |
ret_value = tcpstat.tcpRetransSegs; |
| 315 |
break; |
| 316 |
case TCPINERRS: |
| 317 |
#ifdef solaris2 |
| 318 |
ret_value = tcp_load(NULL, (void *)TCPINERRS); |
| 319 |
if (ret_value == -1) { |
| 320 |
netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); |
| 321 |
continue; |
| 322 |
} |
| 323 |
break; |
| 324 |
#elif defined(linux) |
| 325 |
if (tcpstat.tcpInErrsValid) { |
| 326 |
ret_value = tcpstat.tcpInErrs; |
| 327 |
break; |
| 328 |
} else { |
| 329 |
netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); |
| 330 |
continue; |
| 331 |
} |
| 332 |
#else /* linux */ |
| 333 |
netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); |
| 334 |
continue; |
| 335 |
#endif /* solaris2 */ |
| 336 |
case TCPOUTRSTS: |
| 337 |
#ifdef linux |
| 338 |
if (tcpstat.tcpOutRstsValid) { |
| 339 |
ret_value = tcpstat.tcpOutRsts; |
| 340 |
break; |
| 341 |
} |
| 342 |
#elif defined(solaris2) |
| 343 |
ret_value = tcpstat.tcpOutRsts; |
| 344 |
break; |
| 345 |
#endif /* linux */ |
| 346 |
netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); |
| 347 |
continue; |
| 348 |
#elif defined(TCP_NSTAT) |
| 349 |
case TCPRTOALGORITHM: /* Assume Van Jacobsen's algorithm */ |
| 350 |
ret_value = 4; |
| 351 |
type = ASN_INTEGER; |
| 352 |
break; |
| 353 |
case TCPRTOMIN: |
| 354 |
#ifdef TCPTV_NEEDS_HZ |
| 355 |
ret_value = TCPTV_MIN; |
| 356 |
#else |
| 357 |
ret_value = TCPTV_MIN / PR_SLOWHZ * 1000; |
| 358 |
#endif |
| 359 |
type = ASN_INTEGER; |
| 360 |
break; |
| 361 |
case TCPRTOMAX: |
| 362 |
#ifdef TCPTV_NEEDS_HZ |
| 363 |
ret_value = TCPTV_REXMTMAX; |
| 364 |
#else |
| 365 |
ret_value = TCPTV_REXMTMAX / PR_SLOWHZ * 1000; |
| 366 |
#endif |
| 367 |
type = ASN_INTEGER; |
| 368 |
break; |
| 369 |
case TCPMAXCONN: |
| 370 |
ret_value = -1; /* Dynamic maximum */ |
| 371 |
type = ASN_INTEGER; |
| 372 |
break; |
| 373 |
case TCPACTIVEOPENS: |
| 374 |
ret_value = tcpstat[TCP_STAT_CONNATTEMPT]; |
| 375 |
break; |
| 376 |
case TCPPASSIVEOPENS: |
| 377 |
ret_value = tcpstat[TCP_STAT_ACCEPTS]; |
| 378 |
break; |
| 379 |
/* |
| 380 |
* NB: tcps_drops is actually the sum of the two MIB |
| 381 |
* counters tcpAttemptFails and tcpEstabResets. |
| 382 |
*/ |
| 383 |
case TCPATTEMPTFAILS: |
| 384 |
ret_value = tcpstat[TCP_STAT_CONNDROPS]; |
| 385 |
break; |
| 386 |
case TCPESTABRESETS: |
| 387 |
ret_value = tcpstat[TCP_STAT_DROPS]; |
| 388 |
break; |
| 389 |
case TCPCURRESTAB: |
| 390 |
#ifdef USING_MIBII_TCPTABLE_MODULE |
| 391 |
ret_value = TCP_Count_Connections(); |
| 392 |
#else |
| 393 |
ret_value = 0; |
| 394 |
#endif |
| 395 |
type = ASN_GAUGE; |
| 396 |
break; |
| 397 |
case TCPINSEGS: |
| 398 |
ret_value = tcpstat[TCP_STAT_RCVTOTAL]; |
| 399 |
break; |
| 400 |
case TCPOUTSEGS: |
| 401 |
/* |
| 402 |
* RFC 1213 defines this as the number of segments sent |
| 403 |
* "excluding those containing only retransmitted octets" |
| 404 |
*/ |
| 405 |
ret_value = tcpstat[TCP_STAT_SNDTOTAL] - tcpstat[TCP_STAT_SNDREXMITPACK]; |
| 406 |
break; |
| 407 |
case TCPRETRANSSEGS: |
| 408 |
ret_value = tcpstat[TCP_STAT_SNDREXMITPACK]; |
| 409 |
break; |
| 410 |
case TCPINERRS: |
| 411 |
ret_value = tcpstat[TCP_STAT_RCVBADSUM] + tcpstat[TCP_STAT_RCVBADOFF] |
| 412 |
+ tcpstat[TCP_STAT_RCVMEMDROP] + tcpstat[TCP_STAT_RCVSHORT]; |
| 413 |
break; |
| 414 |
case TCPOUTRSTS: |
| 415 |
ret_value = tcpstat[TCP_STAT_SNDCTRL] - tcpstat[TCP_STAT_CLOSED]; |
| 416 |
break; |
| 417 |
#elif defined(USES_TRADITIONAL_TCPSTAT) && !defined(_USE_FIRST_PROTOCOL) |
| 418 |
#ifdef HAVE_SYS_TCPIPSTATS_H |
| 419 |
/* |
| 420 |
* This actually reads statistics for *all* the groups together, |
| 421 |
* so we need to isolate the TCP-specific bits. |
| 422 |
*/ |
| 423 |
#define tcpstat tcpstat.tcpstat |
| 424 |
#endif |
| 425 |
case TCPRTOALGORITHM: /* Assume Van Jacobsen's algorithm */ |
| 426 |
ret_value = 4; |
| 427 |
type = ASN_INTEGER; |
| 428 |
break; |
| 429 |
case TCPRTOMIN: |
| 430 |
#ifdef TCPTV_NEEDS_HZ |
| 431 |
ret_value = TCPTV_MIN; |
| 432 |
#else |
| 433 |
ret_value = TCPTV_MIN / PR_SLOWHZ * 1000; |
| 434 |
#endif |
| 435 |
type = ASN_INTEGER; |
| 436 |
break; |
| 437 |
case TCPRTOMAX: |
| 438 |
#ifdef TCPTV_NEEDS_HZ |
| 439 |
ret_value = TCPTV_REXMTMAX; |
| 440 |
#else |
| 441 |
ret_value = TCPTV_REXMTMAX / PR_SLOWHZ * 1000; |
| 442 |
#endif |
| 443 |
type = ASN_INTEGER; |
| 444 |
break; |
| 445 |
case TCPMAXCONN: |
| 446 |
ret_value = -1; /* Dynamic maximum */ |
| 447 |
type = ASN_INTEGER; |
| 448 |
break; |
| 449 |
case TCPACTIVEOPENS: |
| 450 |
ret_value = tcpstat.tcps_connattempt; |
| 451 |
break; |
| 452 |
case TCPPASSIVEOPENS: |
| 453 |
ret_value = tcpstat.tcps_accepts; |
| 454 |
break; |
| 455 |
/* |
| 456 |
* NB: tcps_drops is actually the sum of the two MIB |
| 457 |
* counters tcpAttemptFails and tcpEstabResets. |
| 458 |
*/ |
| 459 |
case TCPATTEMPTFAILS: |
| 460 |
ret_value = tcpstat.tcps_conndrops; |
| 461 |
break; |
| 462 |
case TCPESTABRESETS: |
| 463 |
ret_value = tcpstat.tcps_drops; |
| 464 |
break; |
| 465 |
case TCPCURRESTAB: |
| 466 |
#ifdef NETSNMP_FEATURE_CHECKING |
| 467 |
netsnmp_feature_want(tcp_count_connections) |
| 468 |
#endif |
| 469 |
#ifndef NETSNMP_FEATURE_REMOVE_TCP_COUNT_CONNECTIONS |
| 470 |
ret_value = TCP_Count_Connections(); |
| 471 |
#else |
| 472 |
ret_value = 0; |
| 473 |
#endif /* NETSNMP_FEATURE_REMOVE_TCP_COUNT_CONNECTIONS */ |
| 474 |
type = ASN_GAUGE; |
| 475 |
break; |
| 476 |
case TCPINSEGS: |
| 477 |
ret_value = tcpstat.tcps_rcvtotal & 0xffffffff; |
| 478 |
break; |
| 479 |
case TCPOUTSEGS: |
| 480 |
/* |
| 481 |
* RFC 1213 defines this as the number of segments sent |
| 482 |
* "excluding those containing only retransmitted octets" |
| 483 |
*/ |
| 484 |
ret_value = (tcpstat.tcps_sndtotal - tcpstat.tcps_sndrexmitpack) & 0xffffffff; |
| 485 |
break; |
| 486 |
case TCPRETRANSSEGS: |
| 487 |
ret_value = tcpstat.tcps_sndrexmitpack; |
| 488 |
break; |
| 489 |
case TCPINERRS: |
| 490 |
ret_value = tcpstat.tcps_rcvbadsum + tcpstat.tcps_rcvbadoff |
| 491 |
#ifdef HAVE_STRUCT_TCPSTAT_TCPS_RCVMEMDROP |
| 492 |
+ tcpstat.tcps_rcvmemdrop |
| 493 |
#endif |
| 494 |
+ tcpstat.tcps_rcvshort; |
| 495 |
break; |
| 496 |
case TCPOUTRSTS: |
| 497 |
ret_value = tcpstat.tcps_sndctrl - tcpstat.tcps_closed; |
| 498 |
break; |
| 499 |
#ifdef HAVE_SYS_TCPIPSTATS_H |
| 500 |
#undef tcpstat |
| 501 |
#endif |
| 502 |
#elif defined(hpux11) |
| 503 |
case TCPRTOALGORITHM: |
| 504 |
case TCPRTOMIN: |
| 505 |
case TCPRTOMAX: |
| 506 |
case TCPMAXCONN: |
| 507 |
case TCPCURRESTAB: |
| 508 |
if (subid == TCPCURRESTAB) |
| 509 |
type = ASN_GAUGE; |
| 510 |
else |
| 511 |
type = ASN_INTEGER; |
| 512 |
case TCPACTIVEOPENS: |
| 513 |
case TCPPASSIVEOPENS: |
| 514 |
case TCPATTEMPTFAILS: |
| 515 |
case TCPESTABRESETS: |
| 516 |
case TCPINSEGS: |
| 517 |
case TCPOUTSEGS: |
| 518 |
case TCPRETRANSSEGS: |
| 519 |
case TCPINERRS: |
| 520 |
case TCPOUTRSTS: |
| 521 |
/* |
| 522 |
* This is a bit of a hack, to shoehorn the HP-UX 11 |
| 523 |
* single-object retrieval approach into the caching |
| 524 |
* architecture. |
| 525 |
*/ |
| 526 |
if (tcp_load(NULL, (void*)subid) == -1 ) { |
| 527 |
netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); |
| 528 |
continue; |
| 529 |
} |
| 530 |
ret_value = tcpstat; |
| 531 |
break; |
| 532 |
#elif defined (WIN32) || defined (cygwin) |
| 533 |
case TCPRTOALGORITHM: |
| 534 |
ret_value = tcpstat.dwRtoAlgorithm; |
| 535 |
type = ASN_INTEGER; |
| 536 |
break; |
| 537 |
case TCPRTOMIN: |
| 538 |
ret_value = tcpstat.dwRtoMin; |
| 539 |
type = ASN_INTEGER; |
| 540 |
break; |
| 541 |
case TCPRTOMAX: |
| 542 |
ret_value = tcpstat.dwRtoMax; |
| 543 |
type = ASN_INTEGER; |
| 544 |
break; |
| 545 |
case TCPMAXCONN: |
| 546 |
ret_value = tcpstat.dwMaxConn; |
| 547 |
type = ASN_INTEGER; |
| 548 |
break; |
| 549 |
case TCPACTIVEOPENS: |
| 550 |
ret_value = tcpstat.dwActiveOpens; |
| 551 |
break; |
| 552 |
case TCPPASSIVEOPENS: |
| 553 |
ret_value = tcpstat.dwPassiveOpens; |
| 554 |
break; |
| 555 |
case TCPATTEMPTFAILS: |
| 556 |
ret_value = tcpstat.dwAttemptFails; |
| 557 |
break; |
| 558 |
case TCPESTABRESETS: |
| 559 |
ret_value = tcpstat.dwEstabResets; |
| 560 |
break; |
| 561 |
case TCPCURRESTAB: |
| 562 |
ret_value = tcpstat.dwCurrEstab; |
| 563 |
type = ASN_GAUGE; |
| 564 |
break; |
| 565 |
case TCPINSEGS: |
| 566 |
ret_value = tcpstat.dwInSegs; |
| 567 |
break; |
| 568 |
case TCPOUTSEGS: |
| 569 |
ret_value = tcpstat.dwOutSegs; |
| 570 |
break; |
| 571 |
case TCPRETRANSSEGS: |
| 572 |
ret_value = tcpstat.dwRetransSegs; |
| 573 |
break; |
| 574 |
case TCPINERRS: |
| 575 |
ret_value = tcpstat.dwInErrs; |
| 576 |
break; |
| 577 |
case TCPOUTRSTS: |
| 578 |
ret_value = tcpstat.dwOutRsts; |
| 579 |
break; |
| 580 |
#elif defined(_USE_FIRST_PROTOCOL) |
| 581 |
case TCPRTOALGORITHM: |
| 582 |
ret_value = 4; |
| 583 |
type = ASN_INTEGER; |
| 584 |
break; |
| 585 |
case TCPRTOMIN: |
| 586 |
ret_value = 0; |
| 587 |
type = ASN_INTEGER; |
| 588 |
break; |
| 589 |
case TCPRTOMAX: |
| 590 |
ret_value = 0; |
| 591 |
type = ASN_INTEGER; |
| 592 |
break; |
| 593 |
case TCPMAXCONN: |
| 594 |
ret_value = -1; |
| 595 |
type = ASN_INTEGER; |
| 596 |
break; |
| 597 |
case TCPACTIVEOPENS: |
| 598 |
ret_value = ps_proto.u.tcp.initiated; |
| 599 |
break; |
| 600 |
case TCPPASSIVEOPENS: |
| 601 |
ret_value = ps_proto.u.tcp.accepted; |
| 602 |
break; |
| 603 |
case TCPATTEMPTFAILS: |
| 604 |
ret_value = ps_proto.u.tcp.dropped; |
| 605 |
break; |
| 606 |
case TCPESTABRESETS: |
| 607 |
ret_value = ps_proto.u.tcp.dropped; |
| 608 |
break; |
| 609 |
case TCPCURRESTAB: |
| 610 |
/* this value is currently missing */ |
| 611 |
ret_value = 0; /*ps_proto.u.tcp.established;*/ |
| 612 |
type = ASN_GAUGE; |
| 613 |
break; |
| 614 |
case TCPINSEGS: |
| 615 |
ret_value = ps_proto.u.tcp.ipackets; |
| 616 |
break; |
| 617 |
case TCPOUTSEGS: |
| 618 |
ret_value = ps_proto.u.tcp.opackets; |
| 619 |
break; |
| 620 |
case TCPRETRANSSEGS: |
| 621 |
ret_value = 0; |
| 622 |
break; |
| 623 |
case TCPINERRS: |
| 624 |
ret_value = ps_proto.u.tcp.ierrors; |
| 625 |
break; |
| 626 |
case TCPOUTRSTS: |
| 627 |
ret_value = 0; |
| 628 |
break; |
| 629 |
#endif /* USES_SNMP_DESIGNED_TCPSTAT */ |
| 630 |
|
| 631 |
case TCPCONNTABLE: |
| 632 |
/* |
| 633 |
* This is not actually a valid scalar object. |
| 634 |
* The table registration should take precedence, |
| 635 |
* so skip this subtree, regardless of architecture. |
| 636 |
*/ |
| 637 |
netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT); |
| 638 |
continue; |
| 639 |
|
| 640 |
} |
| 641 |
snmp_set_var_typed_value(request->requestvb, (u_char)type, |
| 642 |
(u_char *)&ret_value, sizeof(ret_value)); |
| 643 |
} |
| 644 |
break; |
| 645 |
|
| 646 |
case MODE_GETNEXT: |
| 647 |
case MODE_GETBULK: |
| 648 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 649 |
case MODE_SET_RESERVE1: |
| 650 |
case MODE_SET_RESERVE2: |
| 651 |
case MODE_SET_ACTION: |
| 652 |
case MODE_SET_COMMIT: |
| 653 |
case MODE_SET_FREE: |
| 654 |
case MODE_SET_UNDO: |
| 655 |
snmp_log(LOG_WARNING, "mibII/tcp: Unsupported mode (%d)\n", |
| 656 |
reqinfo->mode); |
| 657 |
break; |
| 658 |
#endif /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 659 |
default: |
| 660 |
snmp_log(LOG_WARNING, "mibII/tcp: Unrecognised mode (%d)\n", |
| 661 |
reqinfo->mode); |
| 662 |
break; |
| 663 |
} |
| 664 |
|
| 665 |
return SNMP_ERR_NOERROR; |
| 666 |
} |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
/********************* |
| 671 |
* |
| 672 |
* Internal implementation functions |
| 673 |
* |
| 674 |
*********************/ |
| 675 |
|
| 676 |
#ifdef hpux11 |
| 677 |
int |
| 678 |
tcp_load(netsnmp_cache *cache, void *vmagic) |
| 679 |
{ |
| 680 |
int fd; |
| 681 |
struct nmparms p; |
| 682 |
unsigned int ulen; |
| 683 |
int ret; |
| 684 |
int magic = (int) vmagic; |
| 685 |
|
| 686 |
if ((fd = open_mib("/dev/ip", O_RDONLY, 0, NM_ASYNC_OFF)) < 0) { |
| 687 |
DEBUGMSGTL(("mibII/tcpScalar", "Failed to load TCP object %d (hpux11)\n", magic)); |
| 688 |
return (-1); /* error */ |
| 689 |
} |
| 690 |
|
| 691 |
switch (magic) { |
| 692 |
case TCPRTOALGORITHM: |
| 693 |
p.objid = ID_tcpRtoAlgorithm; |
| 694 |
break; |
| 695 |
case TCPRTOMIN: |
| 696 |
p.objid = ID_tcpRtoMin; |
| 697 |
break; |
| 698 |
case TCPRTOMAX: |
| 699 |
p.objid = ID_tcpRtoMax; |
| 700 |
break; |
| 701 |
case TCPMAXCONN: |
| 702 |
p.objid = ID_tcpMaxConn; |
| 703 |
break; |
| 704 |
case TCPACTIVEOPENS: |
| 705 |
p.objid = ID_tcpActiveOpens; |
| 706 |
break; |
| 707 |
case TCPPASSIVEOPENS: |
| 708 |
p.objid = ID_tcpPassiveOpens; |
| 709 |
break; |
| 710 |
case TCPATTEMPTFAILS: |
| 711 |
p.objid = ID_tcpAttemptFails; |
| 712 |
break; |
| 713 |
case TCPESTABRESETS: |
| 714 |
p.objid = ID_tcpEstabResets; |
| 715 |
break; |
| 716 |
case TCPCURRESTAB: |
| 717 |
p.objid = ID_tcpCurrEstab; |
| 718 |
break; |
| 719 |
case TCPINSEGS: |
| 720 |
p.objid = ID_tcpInSegs; |
| 721 |
break; |
| 722 |
case TCPOUTSEGS: |
| 723 |
p.objid = ID_tcpOutSegs; |
| 724 |
break; |
| 725 |
case TCPRETRANSSEGS: |
| 726 |
p.objid = ID_tcpRetransSegs; |
| 727 |
break; |
| 728 |
case TCPINERRS: |
| 729 |
p.objid = ID_tcpInErrs; |
| 730 |
break; |
| 731 |
case TCPOUTRSTS: |
| 732 |
p.objid = ID_tcpOutRsts; |
| 733 |
break; |
| 734 |
default: |
| 735 |
tcpstat = 0; |
| 736 |
close_mib(fd); |
| 737 |
return -1; |
| 738 |
} |
| 739 |
|
| 740 |
p.buffer = (void *)&tcpstat; |
| 741 |
ulen = sizeof(TCP_STAT_STRUCTURE); |
| 742 |
p.len = &ulen; |
| 743 |
ret = get_mib_info(fd, &p); |
| 744 |
close_mib(fd); |
| 745 |
|
| 746 |
DEBUGMSGTL(("mibII/tcpScalar", "%s TCP object %d (hpux11)\n", |
| 747 |
(ret < 0 ? "Failed to load" : "Loaded"), magic)); |
| 748 |
return (ret); /* 0: ok, < 0: error */ |
| 749 |
} |
| 750 |
#elif defined(linux) |
| 751 |
int |
| 752 |
tcp_load(netsnmp_cache *cache, void *vmagic) |
| 753 |
{ |
| 754 |
long ret_value = -1; |
| 755 |
|
| 756 |
ret_value = linux_read_tcp_stat(&tcpstat); |
| 757 |
|
| 758 |
if ( ret_value < 0 ) { |
| 759 |
DEBUGMSGTL(("mibII/tcpScalar", "Failed to load TCP scalar Group (linux)\n")); |
| 760 |
} else { |
| 761 |
DEBUGMSGTL(("mibII/tcpScalar", "Loaded TCP scalar Group (linux)\n")); |
| 762 |
} |
| 763 |
return ret_value; |
| 764 |
} |
| 765 |
#elif defined(solaris2) |
| 766 |
int |
| 767 |
tcp_load(netsnmp_cache *cache, void *vmagic) |
| 768 |
{ |
| 769 |
long ret_value = -1; |
| 770 |
int magic = (int)vmagic; |
| 771 |
mib2_ip_t ipstat; |
| 772 |
|
| 773 |
/* |
| 774 |
* tcpInErrs is actually implemented as part of the MIB_IP group |
| 775 |
* so we need to retrieve this independently |
| 776 |
*/ |
| 777 |
if (magic == TCPINERRS) { |
| 778 |
if (getMibstat |
| 779 |
(MIB_IP, &ipstat, sizeof(mib2_ip_t), GET_FIRST, |
| 780 |
&Get_everything, NULL) < 0) { |
| 781 |
DEBUGMSGTL(("mibII/tcpScalar", "Failed to load TCP object %d (solaris)\n", magic)); |
| 782 |
return -1; |
| 783 |
} else { |
| 784 |
DEBUGMSGTL(("mibII/tcpScalar", "Loaded TCP object %d (solaris)\n", magic)); |
| 785 |
return ipstat.tcpInErrs; |
| 786 |
} |
| 787 |
} |
| 788 |
|
| 789 |
/* |
| 790 |
* Otherwise, retrieve the whole of the MIB_TCP group (and cache it) |
| 791 |
*/ |
| 792 |
ret_value = getMibstat(MIB_TCP, &tcpstat, sizeof(mib2_tcp_t), |
| 793 |
GET_FIRST, &Get_everything, NULL); |
| 794 |
|
| 795 |
if ( ret_value < 0 ) { |
| 796 |
DEBUGMSGTL(("mibII/tcpScalar", "Failed to load TCP scalar Group (solaris)\n")); |
| 797 |
} else { |
| 798 |
DEBUGMSGTL(("mibII/tcpScalar", "Loaded TCP scalar Group (solaris)\n")); |
| 799 |
} |
| 800 |
return ret_value; |
| 801 |
} |
| 802 |
#elif defined(NETBSD_STATS_VIA_SYSCTL) |
| 803 |
int |
| 804 |
tcp_load(netsnmp_cache *cache, void *vmagic) |
| 805 |
{ |
| 806 |
long ret_value = -1; |
| 807 |
|
| 808 |
ret_value = netbsd_read_tcp_stat(&tcpstat); |
| 809 |
|
| 810 |
if ( ret_value < 0 ) { |
| 811 |
DEBUGMSGTL(("mibII/tcpScalar", "Failed to load TCP scalar Group (netbsd)\n")); |
| 812 |
} else { |
| 813 |
DEBUGMSGTL(("mibII/tcpScalar", "Loaded TCP scalar Group (netbsd)\n")); |
| 814 |
} |
| 815 |
return ret_value; |
| 816 |
} |
| 817 |
#elif defined (WIN32) || defined (cygwin) |
| 818 |
int |
| 819 |
tcp_load(netsnmp_cache *cache, void *vmagic) |
| 820 |
{ |
| 821 |
long ret_value = -1; |
| 822 |
|
| 823 |
ret_value = GetTcpStatistics(&tcpstat); |
| 824 |
|
| 825 |
if ( ret_value < 0 ) { |
| 826 |
DEBUGMSGTL(("mibII/tcpScalar", "Failed to load TCP scalar Group (win32)\n")); |
| 827 |
} else { |
| 828 |
DEBUGMSGTL(("mibII/tcpScalar", "Loaded TCP scalar Group (win32)\n")); |
| 829 |
} |
| 830 |
return ret_value; |
| 831 |
} |
| 832 |
#elif defined(_USE_FIRST_PROTOCOL) |
| 833 |
int |
| 834 |
tcp_load(netsnmp_cache *cache, void *vmagic) |
| 835 |
{ |
| 836 |
long ret_value = -1; |
| 837 |
|
| 838 |
strcpy(ps_name.name, "tcp"); |
| 839 |
ret_value = perfstat_protocol(&ps_name, &ps_proto, sizeof(ps_proto), 1); |
| 840 |
|
| 841 |
if ( ret_value < 0 ) { |
| 842 |
DEBUGMSGTL(("mibII/tcpScalar", "Failed to load TCP scalar Group (AIX)\n")); |
| 843 |
} else { |
| 844 |
ret_value = 0; |
| 845 |
DEBUGMSGTL(("mibII/tcpScalar", "Loaded TCP scalar Group (AIX)\n")); |
| 846 |
} |
| 847 |
return ret_value; |
| 848 |
} |
| 849 |
#elif (defined(NETSNMP_CAN_USE_SYSCTL) && defined(TCPCTL_STATS)) |
| 850 |
int |
| 851 |
tcp_load(netsnmp_cache *cache, void *vmagic) |
| 852 |
{ |
| 853 |
int sname[4] = { CTL_NET, PF_INET, IPPROTO_TCP, TCPCTL_STATS }; |
| 854 |
size_t len = sizeof(tcpstat); |
| 855 |
long ret_value = -1; |
| 856 |
|
| 857 |
ret_value = sysctl(sname, 4, &tcpstat, &len, 0, 0); |
| 858 |
|
| 859 |
if ( ret_value < 0 ) { |
| 860 |
DEBUGMSGTL(("mibII/tcpScalar", "Failed to load TCP scalar Group (sysctl)\n")); |
| 861 |
} else { |
| 862 |
DEBUGMSGTL(("mibII/tcpScalar", "Loaded TCP scalar Group (sysctl)\n")); |
| 863 |
} |
| 864 |
return ret_value; |
| 865 |
} |
| 866 |
#elif defined(HAVE_SYS_TCPIPSTATS_H) |
| 867 |
int |
| 868 |
tcp_load(netsnmp_cache *cache, void *vmagic) |
| 869 |
{ |
| 870 |
long ret_value = -1; |
| 871 |
|
| 872 |
ret_value = sysmp(MP_SAGET, MPSA_TCPIPSTATS, &tcpstat, sizeof(tcpstat)); |
| 873 |
|
| 874 |
if ( ret_value < 0 ) { |
| 875 |
DEBUGMSGTL(("mibII/tcpScalar", "Failed to load TCP scalar Group (tcpipstats)\n")); |
| 876 |
} else { |
| 877 |
DEBUGMSGTL(("mibII/tcpScalar", "Loaded TCP scalar Group (tcpipstats)\n")); |
| 878 |
} |
| 879 |
return ret_value; |
| 880 |
} |
| 881 |
#elif defined(TCPSTAT_SYMBOL) |
| 882 |
int |
| 883 |
tcp_load(netsnmp_cache *cache, void *vmagic) |
| 884 |
{ |
| 885 |
long ret_value = -1; |
| 886 |
|
| 887 |
if (auto_nlist(TCPSTAT_SYMBOL, (char *)&tcpstat, sizeof(tcpstat))) |
| 888 |
ret_value = 0; |
| 889 |
|
| 890 |
if ( ret_value < 0 ) { |
| 891 |
DEBUGMSGTL(("mibII/tcpScalar", "Failed to load TCP scalar Group (tcpstat)\n")); |
| 892 |
} else { |
| 893 |
DEBUGMSGTL(("mibII/tcpScalar", "Loaded TCP scalar Group (tcpstat)\n")); |
| 894 |
} |
| 895 |
return ret_value; |
| 896 |
} |
| 897 |
#else /* TCPSTAT_SYMBOL */ |
| 898 |
int |
| 899 |
tcp_load(netsnmp_cache *cache, void *vmagic) |
| 900 |
{ |
| 901 |
long ret_value = -1; |
| 902 |
|
| 903 |
DEBUGMSGTL(("mibII/tcpScalar", "Failed to load TCP scalar Group (null)\n")); |
| 904 |
return ret_value; |
| 905 |
} |
| 906 |
#endif /* WIN32 cygwin */ |
| 907 |
|
| 908 |
|
| 909 |
void |
| 910 |
tcp_free(netsnmp_cache *cache, void *magic) |
| 911 |
{ |
| 912 |
#if defined(_USE_FIRST_PROTOCOL) |
| 913 |
memset(&ps_proto, 0, sizeof(ps_proto)); |
| 914 |
#else |
| 915 |
memset(&tcpstat, 0, sizeof(tcpstat)); |
| 916 |
#endif |
| 917 |
} |
| 918 |
|