📄 interface.c
字号:
if (NULL == e) return 0; if(index) *index = e->index; if(name) strcpy(name, e->name); if (entry) *entry = e; e = ITERATOR_NEXT(it); return 1;}#endif /* NETSNMP_NO_BACKWARDS_COMPATABILITY *//** * * @retval 0 : success * @retval < 0 : error */#ifndef NETSNMP_ACCESS_INTERFACE_NOARCHintnetsnmp_access_interface_entry_set_admin_status(netsnmp_interface_entry * entry, int ifAdminStatus){ int rc; DEBUGMSGTL(("access:interface:entry", "set_admin_status\n")); if (NULL == entry) return -1; if ((ifAdminStatus < IFADMINSTATUS_UP) || (ifAdminStatus > IFADMINSTATUS_TESTING)) return -2; rc = netsnmp_arch_set_admin_status(entry, ifAdminStatus); if (0 == rc) /* success */ entry->admin_status = ifAdminStatus; return rc;}#endif/**---------------------------------------------------------------------*//* * Utility routines *//** */static int_access_interface_entry_compare_name(const void *lhs, const void *rhs){ return strcmp(((const netsnmp_interface_entry *) lhs)->name, ((const netsnmp_interface_entry *) rhs)->name);}/** */static void_access_interface_entry_release(netsnmp_interface_entry * entry, void *context){ netsnmp_access_interface_entry_free(entry);}/** */static void_access_interface_entry_save_name(const char *name, oid index){ oid tmp; if(NULL == name) return; tmp = se_find_value_in_slist("interfaces", name); if (tmp == SE_DNE) { se_add_pair_to_slist("interfaces", strdup(name), index); DEBUGMSGTL(("access:interface:ifIndex", "saved ifIndex %d for %s\n", index, name)); } else netsnmp_assert(index == tmp);}/** * update stats * * @retval 0 : success * @retval -1 : error */intnetsnmp_access_interface_entry_update_stats(netsnmp_interface_entry * prev_vals, netsnmp_interface_entry * new_vals){ DEBUGMSGTL(("access:interface", "check_wrap\n")); /* * sanity checks */ if ((NULL == prev_vals) || (NULL == new_vals) || (NULL == prev_vals->name) || (NULL == new_vals->name) || (0 != strncmp(prev_vals->name, new_vals->name, strlen(prev_vals->name)))) return -1; /* * if we've determined that we have 64 bit counters, just copy them. */ if (0 == need_wrap_check) { memcpy(&prev_vals->stats, &new_vals->stats, sizeof(new_vals->stats)); return 0; } if (NULL == prev_vals->old_stats) { /* * if we don't have old stats, copy previous stats */ prev_vals->old_stats = SNMP_MALLOC_TYPEDEF(netsnmp_interface_stats); if (NULL == prev_vals->old_stats) { return -2; } memcpy(prev_vals->old_stats, &prev_vals->stats, sizeof(new_vals->stats)); } netsnmp_c64_check32_and_update(&prev_vals->stats.ibytes, &new_vals->stats.ibytes, &prev_vals->old_stats->ibytes, &need_wrap_check); netsnmp_c64_check32_and_update(&prev_vals->stats.iucast, &new_vals->stats.iucast, &prev_vals->old_stats->iucast, &need_wrap_check); netsnmp_c64_check32_and_update(&prev_vals->stats.imcast, &new_vals->stats.imcast, &prev_vals->old_stats->imcast, &need_wrap_check); netsnmp_c64_check32_and_update(&prev_vals->stats.ibcast, &new_vals->stats.ibcast, &prev_vals->old_stats->ibcast, &need_wrap_check); netsnmp_c64_check32_and_update(&prev_vals->stats.obytes, &new_vals->stats.obytes, &prev_vals->old_stats->obytes, &need_wrap_check); netsnmp_c64_check32_and_update(&prev_vals->stats.oucast, &new_vals->stats.oucast, &prev_vals->old_stats->oucast, &need_wrap_check); netsnmp_c64_check32_and_update(&prev_vals->stats.omcast, &new_vals->stats.omcast, &prev_vals->old_stats->omcast, &need_wrap_check); netsnmp_c64_check32_and_update(&prev_vals->stats.obcast, &new_vals->stats.obcast, &prev_vals->old_stats->obcast, &need_wrap_check); /* * if we've decided we no longer need to check wraps, free old stats */ if (0 == need_wrap_check) { SNMP_FREE(prev_vals->old_stats); } else { /* * update old stats from new stats. * careful - old_stats is a pointer to stats... */ memcpy(prev_vals->old_stats, &new_vals->stats, sizeof(new_vals->stats)); } return 0;}/** * copy interface entry data (after checking for counter wraps) * * @retval -2 : malloc failed * @retval -1 : interfaces not the same * @retval 0 : no error */intnetsnmp_access_interface_entry_copy(netsnmp_interface_entry * lhs, netsnmp_interface_entry * rhs){ DEBUGMSGTL(("access:interface", "copy\n")); if ((NULL == lhs) || (NULL == rhs) || (NULL == lhs->name) || (NULL == rhs->name) || (0 != strncmp(lhs->name, rhs->name, strlen(rhs->name)))) return -1; /* * update stats */ netsnmp_access_interface_entry_update_stats(lhs, rhs); /* * update data */ lhs->ns_flags = rhs->ns_flags; if((NULL != lhs->descr) && (NULL != rhs->descr) && (0 == strcmp(lhs->descr, rhs->descr))) ; else { if (NULL != lhs->descr) SNMP_FREE(lhs->descr); if (rhs->descr) { lhs->descr = strdup(rhs->descr); if(NULL == lhs->descr) return -2; } } lhs->type = rhs->type; lhs->speed = rhs->speed; lhs->speed_high = rhs->speed_high; lhs->retransmit_v6 = rhs->retransmit_v6; lhs->retransmit_v4 = rhs->retransmit_v4; lhs->reachable_time = rhs->reachable_time; lhs->mtu = rhs->mtu; lhs->lastchange = rhs->lastchange; lhs->discontinuity = rhs->discontinuity; lhs->reasm_max_v4 = rhs->reasm_max_v4; lhs->reasm_max_v6 = rhs->reasm_max_v6; lhs->admin_status = rhs->admin_status; lhs->oper_status = rhs->oper_status; lhs->promiscuous = rhs->promiscuous; lhs->connector_present = rhs->connector_present; lhs->forwarding_v6 = rhs->forwarding_v6; lhs->os_flags = rhs->os_flags; if(lhs->paddr_len == rhs->paddr_len) { if(rhs->paddr_len) memcpy(lhs->paddr,rhs->paddr,rhs->paddr_len); } else { if (NULL != lhs->paddr) SNMP_FREE(lhs->paddr); if (rhs->paddr) { lhs->paddr = malloc(rhs->paddr_len); if(NULL == lhs->paddr) return -2; memcpy(lhs->paddr,rhs->paddr,rhs->paddr_len); } } lhs->paddr_len = rhs->paddr_len; return 0;}voidnetsnmp_access_interface_entry_guess_speed(netsnmp_interface_entry *entry){ if (entry->type == IANAIFTYPE_ETHERNETCSMACD) entry->speed = 10000000; else if (entry->type == IANAIFTYPE_SOFTWARELOOPBACK) entry->speed = 10000000; else if (entry->type == IANAIFTYPE_ISO88025TOKENRING) entry->speed = 4000000; else entry->speed = 0;}netsnmp_conf_if_list *netsnmp_access_interface_entry_overrides_get(const char * name){ netsnmp_conf_if_list * if_ptr; netsnmp_assert(1 == _access_interface_init); if(NULL == name) return NULL; for (if_ptr = conf_list; if_ptr; if_ptr = if_ptr->next) if (!strcmp(if_ptr->name, name)) break; return if_ptr;}voidnetsnmp_access_interface_entry_overrides(netsnmp_interface_entry *entry){ netsnmp_conf_if_list * if_ptr; netsnmp_assert(1 == _access_interface_init); if (NULL == entry) return; /* * enforce mib size limit */ if(entry->descr && (strlen(entry->descr) > 255)) entry->descr[255] = 0; if_ptr = netsnmp_access_interface_entry_overrides_get(entry->name); if (if_ptr) { entry->type = if_ptr->type; entry->speed = if_ptr->speed; }}/**---------------------------------------------------------------------*//* * interface config token *//** */static void_parse_interface_config(const char *token, char *cptr){ netsnmp_conf_if_list *if_ptr, *if_new; char *name, *type, *speed, *ecp; char *st; name = strtok_r(cptr, " \t", &st); if (!name) { config_perror("Missing NAME parameter"); return; } type = strtok_r(NULL, " \t", &st); if (!type) { config_perror("Missing TYPE parameter"); return; } speed = strtok_r(NULL, " \t", &st); if (!speed) { config_perror("Missing SPEED parameter"); return; } if_ptr = conf_list; while (if_ptr) if (strcmp(if_ptr->name, name)) if_ptr = if_ptr->next; else break; if (if_ptr) config_pwarn("Duplicate interface specification"); if_new = SNMP_MALLOC_TYPEDEF(netsnmp_conf_if_list); if (!if_new) { config_perror("Out of memory"); return; } if_new->speed = strtoul(speed, &ecp, 0); if (*ecp) { config_perror("Bad SPEED value"); free(if_new); return; } if_new->type = strtol(type, &ecp, 0); if (*ecp || if_new->type < 0) { config_perror("Bad TYPE"); free(if_new); return; } if_new->name = strdup(name); if (!if_new->name) { config_perror("Out of memory"); free(if_new); return; } if_new->next = conf_list; conf_list = if_new;}static void_free_interface_config(void){ netsnmp_conf_if_list *if_ptr = conf_list, *if_next; while (if_ptr) { if_next = if_ptr->next; free(if_ptr->name); free(if_ptr); if_ptr = if_next; } conf_list = NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -