| 1 |
/* |
| 2 |
* ipSystemStatsTable and ipIfStatsTable MIB architecture support |
| 3 |
* |
| 4 |
* $Id$ |
| 5 |
*/ |
| 6 |
#include <net-snmp/net-snmp-config.h> |
| 7 |
#include <net-snmp/net-snmp-includes.h> |
| 8 |
#include "ip-mib/ipSystemStatsTable/ipSystemStatsTable_constants.h" |
| 9 |
|
| 10 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 11 |
#include <net-snmp/data_access/ipstats.h> |
| 12 |
#include <net-snmp/data_access/systemstats.h> |
| 13 |
#include "systemstats.h" |
| 14 |
#include "systemstats_private.h" |
| 15 |
|
| 16 |
/**---------------------------------------------------------------------*/ |
| 17 |
/* |
| 18 |
* local static vars |
| 19 |
*/ |
| 20 |
static int need_wrap_check = -1; |
| 21 |
|
| 22 |
/* |
| 23 |
* local static prototypes |
| 24 |
*/ |
| 25 |
static void _entry_release(void *entry, void *unused); |
| 26 |
|
| 27 |
/**---------------------------------------------------------------------*/ |
| 28 |
/* |
| 29 |
* initialization |
| 30 |
*/ |
| 31 |
void |
| 32 |
netsnmp_access_systemstats_init(void) |
| 33 |
{ |
| 34 |
netsnmp_container * ifcontainer; |
| 35 |
|
| 36 |
netsnmp_access_systemstats_arch_init(); |
| 37 |
|
| 38 |
/* |
| 39 |
* load once to set up ifIndexes |
| 40 |
*/ |
| 41 |
ifcontainer = netsnmp_access_systemstats_container_load(NULL, 0); |
| 42 |
if(NULL != ifcontainer) |
| 43 |
netsnmp_access_systemstats_container_free(ifcontainer, 0); |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
/**---------------------------------------------------------------------*/ |
| 48 |
/* |
| 49 |
* container functions |
| 50 |
*/ |
| 51 |
/** |
| 52 |
* initialize systemstats container |
| 53 |
*/ |
| 54 |
netsnmp_container * |
| 55 |
netsnmp_access_systemstats_container_init(u_int flags) |
| 56 |
{ |
| 57 |
netsnmp_container *container; |
| 58 |
|
| 59 |
DEBUGMSGTL(("access:systemstats:container", "init\n")); |
| 60 |
|
| 61 |
/* |
| 62 |
* create the containers. one indexed by ifIndex, the other |
| 63 |
* indexed by ifName. |
| 64 |
*/ |
| 65 |
container = netsnmp_container_find("access_systemstats:table_container"); |
| 66 |
if (NULL == container) |
| 67 |
return NULL; |
| 68 |
|
| 69 |
return container; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* load systemstats information in specified container |
| 74 |
* |
| 75 |
* @param container empty container, or NULL to have one created for you |
| 76 |
* @param load_flags flags to modify behaviour. |
| 77 |
* |
| 78 |
* @retval NULL error |
| 79 |
* @retval !NULL pointer to container |
| 80 |
*/ |
| 81 |
netsnmp_container* |
| 82 |
netsnmp_access_systemstats_container_load(netsnmp_container* container, u_int load_flags) |
| 83 |
{ |
| 84 |
int rc; |
| 85 |
|
| 86 |
DEBUGMSGTL(("access:systemstats:container", "load\n")); |
| 87 |
|
| 88 |
if (NULL == container) { |
| 89 |
container = netsnmp_access_systemstats_container_init(load_flags); |
| 90 |
if (NULL != container) |
| 91 |
container->container_name = strdup("systemstats_autocreate"); |
| 92 |
} |
| 93 |
if (NULL == container) { |
| 94 |
snmp_log(LOG_ERR, "no container specified/found for access_systemstats\n"); |
| 95 |
return NULL; |
| 96 |
} |
| 97 |
|
| 98 |
rc = netsnmp_access_systemstats_container_arch_load(container, load_flags); |
| 99 |
if (0 != rc) { |
| 100 |
netsnmp_access_systemstats_container_free(container, |
| 101 |
NETSNMP_ACCESS_SYSTEMSTATS_FREE_NOFLAGS); |
| 102 |
container = NULL; |
| 103 |
} |
| 104 |
|
| 105 |
return container; |
| 106 |
} |
| 107 |
|
| 108 |
void |
| 109 |
netsnmp_access_systemstats_container_free(netsnmp_container *container, u_int free_flags) |
| 110 |
{ |
| 111 |
DEBUGMSGTL(("access:systemstats:container", "free\n")); |
| 112 |
|
| 113 |
if (NULL == container) { |
| 114 |
snmp_log(LOG_ERR, "invalid container for netsnmp_access_systemstats_free\n"); |
| 115 |
return; |
| 116 |
} |
| 117 |
|
| 118 |
if(! (free_flags & NETSNMP_ACCESS_SYSTEMSTATS_FREE_DONT_CLEAR)) { |
| 119 |
/* |
| 120 |
* free all items. |
| 121 |
*/ |
| 122 |
CONTAINER_CLEAR(container, _entry_release, NULL); |
| 123 |
} |
| 124 |
|
| 125 |
CONTAINER_FREE(container); |
| 126 |
} |
| 127 |
|
| 128 |
/**---------------------------------------------------------------------*/ |
| 129 |
/* |
| 130 |
* entry functions |
| 131 |
*/ |
| 132 |
/** |
| 133 |
*/ |
| 134 |
netsnmp_systemstats_entry * |
| 135 |
netsnmp_access_systemstats_entry_get_by_index(netsnmp_container *container, oid index) |
| 136 |
{ |
| 137 |
netsnmp_index tmp; |
| 138 |
|
| 139 |
DEBUGMSGTL(("access:systemstats:entry", "by_index\n")); |
| 140 |
|
| 141 |
if (NULL == container) { |
| 142 |
snmp_log(LOG_ERR, |
| 143 |
"invalid container for netsnmp_access_systemstats_entry_get_by_index\n"); |
| 144 |
return NULL; |
| 145 |
} |
| 146 |
|
| 147 |
tmp.len = 1; |
| 148 |
tmp.oids = &index; |
| 149 |
|
| 150 |
return (netsnmp_systemstats_entry *) CONTAINER_FIND(container, &tmp); |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
*/ |
| 155 |
netsnmp_systemstats_entry * |
| 156 |
netsnmp_access_systemstats_entry_create(int version, int if_index, |
| 157 |
const char *tableName) |
| 158 |
{ |
| 159 |
netsnmp_systemstats_entry *entry = |
| 160 |
SNMP_MALLOC_TYPEDEF(netsnmp_systemstats_entry); |
| 161 |
|
| 162 |
DEBUGMSGTL(("access:systemstats:entry", "create\n")); |
| 163 |
|
| 164 |
if(NULL == entry) |
| 165 |
return NULL; |
| 166 |
|
| 167 |
entry->oid_index.len = 2; |
| 168 |
entry->oid_index.oids = entry->index; |
| 169 |
entry->index[0] = version; |
| 170 |
entry->index[1] = if_index; |
| 171 |
entry->tableName = tableName; |
| 172 |
return entry; |
| 173 |
} |
| 174 |
|
| 175 |
/** |
| 176 |
*/ |
| 177 |
void |
| 178 |
netsnmp_access_systemstats_entry_free(netsnmp_systemstats_entry * entry) |
| 179 |
{ |
| 180 |
DEBUGMSGTL(("access:systemstats:entry", "free\n")); |
| 181 |
|
| 182 |
if (NULL == entry) |
| 183 |
return; |
| 184 |
|
| 185 |
/* |
| 186 |
* SNMP_FREE not needed, for any of these, |
| 187 |
* since the whole entry is about to be freed |
| 188 |
*/ |
| 189 |
|
| 190 |
if (NULL != entry->old_stats) |
| 191 |
free(entry->old_stats); |
| 192 |
|
| 193 |
free(entry); |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
/**---------------------------------------------------------------------*/ |
| 198 |
/* |
| 199 |
* Utility routines |
| 200 |
*/ |
| 201 |
|
| 202 |
/** |
| 203 |
* \internal |
| 204 |
*/ |
| 205 |
static void |
| 206 |
_entry_release(void *entry, void *context) |
| 207 |
{ |
| 208 |
netsnmp_access_systemstats_entry_free(entry); |
| 209 |
} |
| 210 |
|
| 211 |
/* |
| 212 |
* Calculates the entries, which are not provided by OS, but can be |
| 213 |
* computed from the others. |
| 214 |
*/ |
| 215 |
static void |
| 216 |
_calculate_entries(netsnmp_systemstats_entry * entry) |
| 217 |
{ |
| 218 |
/* |
| 219 |
* HCInForwDatagrams = HCInNoRoutes + HCOutForwDatagrams |
| 220 |
*/ |
| 221 |
if (!entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCINFORWDATAGRAMS] |
| 222 |
&& entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFORWDATAGRAMS] |
| 223 |
&& entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCINNOROUTES]) { |
| 224 |
|
| 225 |
entry->stats.HCInForwDatagrams = entry->stats.HCInNoRoutes; |
| 226 |
u64Incr(&entry->stats.HCInForwDatagrams, &entry->stats.HCOutForwDatagrams); |
| 227 |
entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCINFORWDATAGRAMS] = 1; |
| 228 |
} |
| 229 |
|
| 230 |
/* |
| 231 |
* HCOutFragReqds = HCOutFragOKs + HCOutFragFails |
| 232 |
*/ |
| 233 |
if (!entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFRAGREQDS] |
| 234 |
&& entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFRAGOKS] |
| 235 |
&& entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFRAGFAILS]) { |
| 236 |
|
| 237 |
entry->stats.HCOutFragReqds = entry->stats.HCOutFragOKs; |
| 238 |
u64Incr(&entry->stats.HCOutFragReqds, &entry->stats.HCOutFragFails); |
| 239 |
entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFRAGREQDS] = 1; |
| 240 |
} |
| 241 |
|
| 242 |
/* |
| 243 |
* HCOutTransmits = HCOutRequests + HCOutForwDatagrams + HCOutFragCreates |
| 244 |
* - HCOutFragReqds - HCOutNoRoutes - HCOutDiscards |
| 245 |
*/ |
| 246 |
if (!entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTTRANSMITS] |
| 247 |
&& entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTREQUESTS] |
| 248 |
&& entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFORWDATAGRAMS] |
| 249 |
&& entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFRAGREQDS] |
| 250 |
&& entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTNOROUTES] |
| 251 |
&& entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFRAGCREATES] |
| 252 |
&& entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTDISCARDS]) { |
| 253 |
|
| 254 |
struct counter64 tmp, tmp2, tmp3; |
| 255 |
tmp = entry->stats.HCOutRequests; |
| 256 |
u64Incr(&tmp, &entry->stats.HCOutForwDatagrams); |
| 257 |
u64Incr(&tmp, &entry->stats.HCOutFragCreates); |
| 258 |
|
| 259 |
u64Subtract(&tmp, &entry->stats.HCOutFragReqds, &tmp2); |
| 260 |
u64Subtract(&tmp2, &entry->stats.HCOutNoRoutes, &tmp3); |
| 261 |
u64Subtract(&tmp3, &entry->stats.HCOutDiscards, &entry->stats.HCOutTransmits); |
| 262 |
|
| 263 |
entry->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTTRANSMITS] = 1; |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* update entry stats (checking for counter wrap) |
| 269 |
* |
| 270 |
* @retval 0 : success |
| 271 |
* @retval <0 : error |
| 272 |
*/ |
| 273 |
int |
| 274 |
netsnmp_access_systemstats_entry_update_stats(netsnmp_systemstats_entry * prev_vals, |
| 275 |
netsnmp_systemstats_entry * new_vals) |
| 276 |
{ |
| 277 |
DEBUGMSGTL(("access:systemstats", "check_wrap\n")); |
| 278 |
|
| 279 |
/* |
| 280 |
* sanity checks |
| 281 |
*/ |
| 282 |
if ((NULL == prev_vals) || (NULL == new_vals) || |
| 283 |
(prev_vals->index[0] != new_vals->index[0]) |
| 284 |
|| (prev_vals->index[1] != new_vals->index[1])) |
| 285 |
return -1; |
| 286 |
|
| 287 |
/* |
| 288 |
* if we've determined that we have 64 bit counters, just copy them. |
| 289 |
*/ |
| 290 |
if (0 == need_wrap_check) { |
| 291 |
memcpy(&prev_vals->stats, &new_vals->stats, sizeof(new_vals->stats)); |
| 292 |
_calculate_entries(prev_vals); |
| 293 |
return 0; |
| 294 |
} |
| 295 |
|
| 296 |
if (NULL == prev_vals->old_stats) { |
| 297 |
/* |
| 298 |
* if we don't have old stats, they can't have wrapped, so just copy |
| 299 |
*/ |
| 300 |
prev_vals->old_stats = SNMP_MALLOC_TYPEDEF(netsnmp_ipstats); |
| 301 |
if (NULL == prev_vals->old_stats) { |
| 302 |
return -2; |
| 303 |
} |
| 304 |
memcpy(&prev_vals->stats, &new_vals->stats, sizeof(new_vals->stats)); |
| 305 |
} |
| 306 |
else { |
| 307 |
/* |
| 308 |
* update straight 32 bit counters |
| 309 |
*/ |
| 310 |
memcpy(&prev_vals->stats.columnAvail[0], &new_vals->stats.columnAvail[0], sizeof(new_vals->stats.columnAvail)); |
| 311 |
prev_vals->stats.InHdrErrors = new_vals->stats.InHdrErrors; |
| 312 |
prev_vals->stats.InAddrErrors = new_vals->stats.InAddrErrors; |
| 313 |
prev_vals->stats.InUnknownProtos = new_vals->stats.InUnknownProtos; |
| 314 |
prev_vals->stats.InTruncatedPkts = new_vals->stats.InTruncatedPkts; |
| 315 |
prev_vals->stats.ReasmReqds = new_vals->stats.ReasmReqds; |
| 316 |
prev_vals->stats.ReasmOKs = new_vals->stats.ReasmOKs; |
| 317 |
prev_vals->stats.ReasmFails = new_vals->stats.ReasmFails; |
| 318 |
prev_vals->stats.InDiscards = new_vals->stats.InDiscards; |
| 319 |
|
| 320 |
/* |
| 321 |
* update 64bit counters |
| 322 |
*/ |
| 323 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCINNOROUTES]) |
| 324 |
if (0 != netsnmp_c64_check32_and_update( |
| 325 |
&prev_vals->stats.HCInNoRoutes, |
| 326 |
&new_vals->stats.HCInNoRoutes, |
| 327 |
&prev_vals->old_stats->HCInNoRoutes, |
| 328 |
&need_wrap_check)) |
| 329 |
NETSNMP_LOGONCE((LOG_ERR, |
| 330 |
"Error expanding HCInNoRoutes to 64bits in %s\n", |
| 331 |
prev_vals->tableName)); |
| 332 |
|
| 333 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTNOROUTES]) |
| 334 |
if (0 != netsnmp_c64_check32_and_update( |
| 335 |
&prev_vals->stats.HCOutNoRoutes, |
| 336 |
&new_vals->stats.HCOutNoRoutes, |
| 337 |
&prev_vals->old_stats->HCOutNoRoutes, |
| 338 |
&need_wrap_check)) |
| 339 |
NETSNMP_LOGONCE((LOG_ERR, |
| 340 |
"Error expanding HCOutNoRoutes to 64bits in %s\n", |
| 341 |
prev_vals->tableName)); |
| 342 |
|
| 343 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTDISCARDS]) |
| 344 |
if (0 != netsnmp_c64_check32_and_update( |
| 345 |
&prev_vals->stats.HCOutDiscards, |
| 346 |
&new_vals->stats.HCOutDiscards, |
| 347 |
&prev_vals->old_stats->HCOutDiscards, |
| 348 |
&need_wrap_check)) |
| 349 |
NETSNMP_LOGONCE((LOG_ERR, |
| 350 |
"Error expanding HCOutDiscards to 64bits in %s\n", |
| 351 |
prev_vals->tableName)); |
| 352 |
|
| 353 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFRAGREQDS]) |
| 354 |
if (0 != netsnmp_c64_check32_and_update( |
| 355 |
&prev_vals->stats.HCOutFragReqds, |
| 356 |
&new_vals->stats.HCOutFragReqds, |
| 357 |
&prev_vals->old_stats->HCOutFragReqds, |
| 358 |
&need_wrap_check)) |
| 359 |
NETSNMP_LOGONCE((LOG_ERR, |
| 360 |
"Error expanding HCOutFragReqds to 64bits in %s\n", |
| 361 |
prev_vals->tableName)); |
| 362 |
|
| 363 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFRAGOKS]) |
| 364 |
if (0 != netsnmp_c64_check32_and_update( |
| 365 |
&prev_vals->stats.HCOutFragOKs, |
| 366 |
&new_vals->stats.HCOutFragOKs, |
| 367 |
&prev_vals->old_stats->HCOutFragOKs, |
| 368 |
&need_wrap_check)) |
| 369 |
NETSNMP_LOGONCE((LOG_ERR, |
| 370 |
"Error expanding HCOutFragOKs to 64bits in %s\n", |
| 371 |
prev_vals->tableName)); |
| 372 |
|
| 373 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFRAGFAILS]) |
| 374 |
if (0 != netsnmp_c64_check32_and_update( |
| 375 |
&prev_vals->stats.HCOutFragFails, |
| 376 |
&new_vals->stats.HCOutFragFails, |
| 377 |
&prev_vals->old_stats->HCOutFragFails, |
| 378 |
&need_wrap_check)) |
| 379 |
NETSNMP_LOGONCE((LOG_ERR, |
| 380 |
"Error expanding HCOutFragFails to 64bits in %s\n", |
| 381 |
prev_vals->tableName)); |
| 382 |
|
| 383 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFRAGCREATES]) |
| 384 |
if (0 != netsnmp_c64_check32_and_update( |
| 385 |
&prev_vals->stats.HCOutFragCreates, |
| 386 |
&new_vals->stats.HCOutFragCreates, |
| 387 |
&prev_vals->old_stats->HCOutFragCreates, |
| 388 |
&need_wrap_check)) |
| 389 |
NETSNMP_LOGONCE((LOG_ERR, |
| 390 |
"Error expanding HCOutFragCreates to 64bits in %s\n", |
| 391 |
prev_vals->tableName)); |
| 392 |
|
| 393 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCINRECEIVES]) |
| 394 |
if (0 != netsnmp_c64_check32_and_update( |
| 395 |
&prev_vals->stats.HCInReceives, |
| 396 |
&new_vals->stats.HCInReceives, |
| 397 |
&prev_vals->old_stats->HCInReceives, |
| 398 |
&need_wrap_check)) |
| 399 |
NETSNMP_LOGONCE((LOG_ERR, |
| 400 |
"Error expanding HCInReceives to 64bits in %s\n", |
| 401 |
prev_vals->tableName)); |
| 402 |
|
| 403 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCINOCTETS]) |
| 404 |
if (0 != netsnmp_c64_check32_and_update( |
| 405 |
&prev_vals->stats.HCInOctets, |
| 406 |
&new_vals->stats.HCInOctets, |
| 407 |
&prev_vals->old_stats->HCInOctets, |
| 408 |
&need_wrap_check)) |
| 409 |
NETSNMP_LOGONCE((LOG_ERR, |
| 410 |
"Error expanding HCInOctets to 64bits in %s\n", |
| 411 |
prev_vals->tableName)); |
| 412 |
|
| 413 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCINFORWDATAGRAMS]) |
| 414 |
if (0 != netsnmp_c64_check32_and_update( |
| 415 |
&prev_vals->stats.HCInForwDatagrams, |
| 416 |
&new_vals->stats.HCInForwDatagrams, |
| 417 |
&prev_vals->old_stats->HCInForwDatagrams, |
| 418 |
&need_wrap_check)) |
| 419 |
NETSNMP_LOGONCE((LOG_ERR, |
| 420 |
"Error expanding HCInForwDatagrams to 64bits in %s\n", |
| 421 |
prev_vals->tableName)); |
| 422 |
|
| 423 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCINDELIVERS]) |
| 424 |
if (0 != netsnmp_c64_check32_and_update( |
| 425 |
&prev_vals->stats.HCInDelivers, |
| 426 |
&new_vals->stats.HCInDelivers, |
| 427 |
&prev_vals->old_stats->HCInDelivers, |
| 428 |
&need_wrap_check)) |
| 429 |
NETSNMP_LOGONCE((LOG_ERR, |
| 430 |
"Error expanding HCInDelivers to 64bits in %s\n", |
| 431 |
prev_vals->tableName)); |
| 432 |
|
| 433 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTREQUESTS]) |
| 434 |
if (0 != netsnmp_c64_check32_and_update( |
| 435 |
&prev_vals->stats.HCOutRequests, |
| 436 |
&new_vals->stats.HCOutRequests, |
| 437 |
&prev_vals->old_stats->HCOutRequests, |
| 438 |
&need_wrap_check)) |
| 439 |
NETSNMP_LOGONCE((LOG_ERR, |
| 440 |
"Error expanding HCOutRequests to 64bits in %s\n", |
| 441 |
prev_vals->tableName)); |
| 442 |
|
| 443 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTFORWDATAGRAMS]) |
| 444 |
if (0 != netsnmp_c64_check32_and_update( |
| 445 |
&prev_vals->stats.HCOutForwDatagrams, |
| 446 |
&new_vals->stats.HCOutForwDatagrams, |
| 447 |
&prev_vals->old_stats->HCOutForwDatagrams, |
| 448 |
&need_wrap_check)) |
| 449 |
NETSNMP_LOGONCE((LOG_ERR, |
| 450 |
"Error expanding HCOutForwDatagrams to 64bits in %s\n", |
| 451 |
prev_vals->tableName)); |
| 452 |
|
| 453 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTTRANSMITS]) |
| 454 |
if (0 != netsnmp_c64_check32_and_update( |
| 455 |
&prev_vals->stats.HCOutTransmits, |
| 456 |
&new_vals->stats.HCOutTransmits, |
| 457 |
&prev_vals->old_stats->HCOutTransmits, |
| 458 |
&need_wrap_check)) |
| 459 |
NETSNMP_LOGONCE((LOG_ERR, |
| 460 |
"Error expanding HCOutTransmits to 64bits in %s\n", |
| 461 |
prev_vals->tableName)); |
| 462 |
|
| 463 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTOCTETS]) |
| 464 |
if (0 != netsnmp_c64_check32_and_update( |
| 465 |
&prev_vals->stats.HCOutOctets, |
| 466 |
&new_vals->stats.HCOutOctets, |
| 467 |
&prev_vals->old_stats->HCOutOctets, |
| 468 |
&need_wrap_check)) |
| 469 |
NETSNMP_LOGONCE((LOG_ERR, |
| 470 |
"Error expanding HCOutOctets to 64bits in %s\n", |
| 471 |
prev_vals->tableName)); |
| 472 |
|
| 473 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCINMCASTPKTS]) |
| 474 |
if (0 != netsnmp_c64_check32_and_update( |
| 475 |
&prev_vals->stats.HCInMcastPkts, |
| 476 |
&new_vals->stats.HCInMcastPkts, |
| 477 |
&prev_vals->old_stats->HCInMcastPkts, |
| 478 |
&need_wrap_check)) |
| 479 |
NETSNMP_LOGONCE((LOG_ERR, |
| 480 |
"Error expanding HCInMcastPkts to 64bits in %s\n", |
| 481 |
prev_vals->tableName)); |
| 482 |
|
| 483 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCINMCASTOCTETS]) |
| 484 |
if (0 != netsnmp_c64_check32_and_update( |
| 485 |
&prev_vals->stats.HCInMcastOctets, |
| 486 |
&new_vals->stats.HCInMcastOctets, |
| 487 |
&prev_vals->old_stats->HCInMcastOctets, |
| 488 |
&need_wrap_check)) |
| 489 |
NETSNMP_LOGONCE((LOG_ERR, |
| 490 |
"Error expanding HCInMcastOctets to 64bits in %s\n", |
| 491 |
prev_vals->tableName)); |
| 492 |
|
| 493 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTMCASTPKTS]) |
| 494 |
if (0 != netsnmp_c64_check32_and_update( |
| 495 |
&prev_vals->stats.HCOutMcastPkts, |
| 496 |
&new_vals->stats.HCOutMcastPkts, |
| 497 |
&prev_vals->old_stats->HCOutMcastPkts, |
| 498 |
&need_wrap_check)) |
| 499 |
NETSNMP_LOGONCE((LOG_ERR, |
| 500 |
"Error expanding HCOutMcastPkts to 64bits in %s\n", |
| 501 |
prev_vals->tableName)); |
| 502 |
|
| 503 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTMCASTOCTETS]) |
| 504 |
if (0 != netsnmp_c64_check32_and_update( |
| 505 |
&prev_vals->stats.HCOutMcastOctets, |
| 506 |
&new_vals->stats.HCOutMcastOctets, |
| 507 |
&prev_vals->old_stats->HCOutMcastOctets, |
| 508 |
&need_wrap_check)) |
| 509 |
NETSNMP_LOGONCE((LOG_ERR, |
| 510 |
"Error expanding HCOutMcastOctets to 64bits in %s\n", |
| 511 |
prev_vals->tableName)); |
| 512 |
|
| 513 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCINBCASTPKTS]) |
| 514 |
if (0 != netsnmp_c64_check32_and_update( |
| 515 |
&prev_vals->stats.HCInBcastPkts, |
| 516 |
&new_vals->stats.HCInBcastPkts, |
| 517 |
&prev_vals->old_stats->HCInBcastPkts, |
| 518 |
&need_wrap_check)) |
| 519 |
NETSNMP_LOGONCE((LOG_ERR, |
| 520 |
"Error expanding HCInBcastPkts to 64bits in %s\n", |
| 521 |
prev_vals->tableName)); |
| 522 |
|
| 523 |
if (new_vals->stats.columnAvail[IPSYSTEMSTATSTABLE_HCOUTBCASTPKTS]) |
| 524 |
if (0 != netsnmp_c64_check32_and_update( |
| 525 |
&prev_vals->stats.HCOutBcastPkts, |
| 526 |
&new_vals->stats.HCOutBcastPkts, |
| 527 |
&prev_vals->old_stats->HCOutBcastPkts, |
| 528 |
&need_wrap_check)) |
| 529 |
NETSNMP_LOGONCE((LOG_ERR, |
| 530 |
"Error expanding HCOutBcastPkts to 64bits in %s\n", |
| 531 |
prev_vals->tableName)); |
| 532 |
} |
| 533 |
|
| 534 |
/* |
| 535 |
* if we've decided we no longer need to check wraps, free old stats |
| 536 |
*/ |
| 537 |
if (0 == need_wrap_check) { |
| 538 |
SNMP_FREE(prev_vals->old_stats); |
| 539 |
} else { |
| 540 |
/* |
| 541 |
* update old stats from new stats. |
| 542 |
* careful - old_stats is a pointer to stats... |
| 543 |
*/ |
| 544 |
memcpy(prev_vals->old_stats, &new_vals->stats, sizeof(new_vals->stats)); |
| 545 |
} |
| 546 |
|
| 547 |
_calculate_entries(prev_vals); |
| 548 |
|
| 549 |
return 0; |
| 550 |
} |
| 551 |
|
| 552 |
/** |
| 553 |
* update systemstats entry data (checking for counter wraps) |
| 554 |
* |
| 555 |
* Given an existing entry, update it with the new values from another |
| 556 |
* entry. |
| 557 |
* |
| 558 |
* @retval -2 : malloc failed |
| 559 |
* @retval -1 : systemstatss not the same |
| 560 |
* @retval 0 : no error |
| 561 |
*/ |
| 562 |
int |
| 563 |
netsnmp_access_systemstats_entry_update(netsnmp_systemstats_entry * lhs, |
| 564 |
netsnmp_systemstats_entry * rhs) |
| 565 |
{ |
| 566 |
DEBUGMSGTL(("access:systemstats", "copy\n")); |
| 567 |
|
| 568 |
if ((NULL == lhs) || (NULL == rhs) || |
| 569 |
(lhs->index[0] != rhs->index[0]) |
| 570 |
|| (lhs->index[1] != rhs->index[1])) |
| 571 |
return -1; |
| 572 |
|
| 573 |
/* |
| 574 |
* update stats |
| 575 |
*/ |
| 576 |
netsnmp_access_systemstats_entry_update_stats(lhs, rhs); |
| 577 |
|
| 578 |
/* |
| 579 |
* update other data |
| 580 |
*/ |
| 581 |
lhs->flags = rhs->flags; |
| 582 |
|
| 583 |
return 0; |
| 584 |
} |
| 585 |
|
| 586 |
/**---------------------------------------------------------------------*/ |
| 587 |
/* |
| 588 |
* |
| 589 |
*/ |