/* *=========================================================================== * ipnet_if_mib_handler_ifNumber *=========================================================================== * Description: MIB handler for ifNumber * Parameters: See file 'ipsnmp.h' * Returns: IPSNMP_ERROR_XXX * */ IP_STATIC Ip_s32 ipnet_if_mib_handler_ifNumber(Ip_s32 cmd, char *id, Ipsnmp_varbind *vb, Ip_s32 magic, struct Ipsnmp_node_object *nodeobj) { Ip_s32 ret = -1, ifNumber = 0; char *iid; (void)id; (void)vb; if (cmd == IPSNMP_MIB_COMMAND_GET || cmd == IPSNMP_MIB_COMMAND_NEXT) { iid = ipsnmp_create_iid_integer(nodeobj->id, 0); if (iid == IP_NULL) return IPSNMP_ERROR_GENERROR; ifNumber = IPNET_NETIF_NUM_ATTACHED; ret = (Ip_s32) ipsnmp_util_put_integer(magic, iid, ifNumber); ipcom_free(iid); } return ret; }
/* *=========================================================================== * ipnet_if_mib_handler_ifXTable *=========================================================================== * Description: MIB handler for variables in ifXTable * Parameters: See file 'ipsnmp.h' * Returns: IPSNMP_ERROR_XXX * */ IP_STATIC Ip_s32 ipnet_if_mib_handler_ifXTable(Ip_s32 cmd, char *id, Ipsnmp_varbind *vb, Ip_s32 magic, struct Ipsnmp_node_object *nodeobj) { Ip_s32 lid, ret = -1; Ip_s32 ifLinkUpDownTrapEnable = 0; char *iid; char *buf = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID); char *best = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID); Ipnet_netif *best_netif; if (buf == IP_NULL || best == IP_NULL) { ret = IPSNMP_ERROR_GENERROR; goto exit; } lid = ipsnmp_util_last_subid(nodeobj->id); ip_assert((lid >= 1 && lid <= 5) || (lid >= 14 && lid <= 19)); best_netif = ipnet_if_mib_table_search_ifTable(id, buf, best, cmd, &ret); if (best_netif == IP_NULL) goto exit; if (cmd == IPSNMP_MIB_COMMAND_GET || cmd == IPSNMP_MIB_COMMAND_NEXT) { iid = ipsnmp_create_iid_direct(nodeobj->id, best); if (iid == IP_NULL) { ret = IPSNMP_ERROR_GENERROR; goto exit; } switch(lid) { case 1: /* ifName */ ret = ipsnmp_util_put_octetstring(magic, iid, (Ip_u8 *)best_netif->ipcom.name, ipcom_strlen(best_netif->ipcom.name)); break; case 2: /* ifInMulticastPkts */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifInMulticastPkts); break; case 3: /* ifInBroadcastPkts */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifInBroadcastPkts); break; case 4: /* ifOutMulticastPkts */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifOutMulticastPkts); break; case 5: /* ifOutBroadcastPkts */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifOutBroadcastPkts); break; case 14: /* ifLinkUpDownTrapEnable */ if (best_netif->ipcom.mib2.ifLinkUpDownTrapEnable == 0) best_netif->ipcom.mib2.ifLinkUpDownTrapEnable = 1; ret = ipsnmp_util_put_integer(magic, iid, best_netif->ipcom.mib2.ifLinkUpDownTrapEnable); break; case 15: /* ifHighSpeed */ if (best_netif->ipcom.type == IP_IFT_PPP) ret = ipsnmp_util_put_gauge32(magic, iid, 0); else ret = ipsnmp_util_put_gauge32(magic, iid, 100); break; case 16: /* ifPromiscuousMode */ if (IP_BIT_ISSET(best_netif->ipcom.flags, IP_IFF_PROMISC)) ret = ipsnmp_util_put_integer(magic, iid, 1); else ret = ipsnmp_util_put_integer(magic, iid, 2); break; case 17: /* ifConnectorPresent */ ret = ipsnmp_util_put_integer(magic, iid, 2); break; case 18: /* ifAlias */ ret = ipsnmp_util_put_octetstring(magic, iid, IP_NULL, 0); break; case 19: /* ifCounterDiscontinuityTime */ ret = ipsnmp_util_put_timeticks(magic, iid, 0); break; default: IP_PANIC(); ret = IPSNMP_ERROR_GENERROR; break; } ipcom_free(iid); } if (cmd == IPSNMP_MIB_COMMAND_TEST || cmd == IPSNMP_MIB_COMMAND_SET) { switch(lid) { case 14: /* ifLinkUpDownTrapEnable */ ret = ipsnmp_util_get_integer(vb, &ifLinkUpDownTrapEnable); if (ret == IPSNMP_ERROR_NOERROR) { if (ifLinkUpDownTrapEnable != 1 && ifLinkUpDownTrapEnable != 2) { ret = IPSNMP_ERROR_WRONGVALUE; } } if (ret == IPSNMP_ERROR_NOERROR && cmd == IPSNMP_MIB_COMMAND_SET) { best_netif->ipcom.mib2.ifLinkUpDownTrapEnable = ifLinkUpDownTrapEnable; } break; case 16: /* ifPromiscuousMode */ case 18: /* ifAlias */ ret = IPSNMP_ERROR_NOSUCHNAME; break; default: IP_PANIC(); ret = IPSNMP_ERROR_GENERROR; break; } } exit: if (buf != IP_NULL) ipcom_free(buf); if (best != IP_NULL) ipcom_free(best); return ret; }
/* *=========================================================================== * ipnet_if_mib_handler_ifTable *=========================================================================== * Description: MIB handler for variables in ifTable * Parameters: See file 'ipsnmp.h' * Returns: IPSNMP_ERROR_XXX * */ IP_STATIC Ip_s32 ipnet_if_mib_handler_ifTable(Ip_s32 cmd, char *id, Ipsnmp_varbind *vb, Ip_s32 magic, struct Ipsnmp_node_object *nodeobj) { Ip_s32 lid, ret = -1; Ipnet_netif *best_netif; Ip_s32 ifAdminStatus = 0; char *iid; char *buf = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID); char *best = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID); struct Ip_ifreq ifreq; Ip_fd fd; if (buf == IP_NULL || best == IP_NULL) { ret = IPSNMP_ERROR_GENERROR; goto exit; } lid = ipsnmp_util_last_subid(nodeobj->id); ip_assert(lid >= 1 && lid <= 20); ip_assert(lid != 12 && lid != 18); best_netif = ipnet_if_mib_table_search_ifTable(id, buf, best, cmd, &ret); if (best_netif == IP_NULL) goto exit; if (cmd == IPSNMP_MIB_COMMAND_GET || cmd == IPSNMP_MIB_COMMAND_NEXT) { iid = ipsnmp_create_iid_direct(nodeobj->id, best); if (iid == IP_NULL) { ret = IPSNMP_ERROR_GENERROR; goto exit; } switch(lid) { case 1: /* ifIndex */ ret = ipsnmp_util_put_integer(magic, iid, best_netif->ipcom.ifindex); break; case 2: /* ifDescr */ ret = ipsnmp_util_put_octetstring(magic, iid, (Ip_u8 *)best_netif->ipcom.name, ipcom_strlen(best_netif->ipcom.name)); break; case 3: /* ifType */ ret = ipsnmp_util_put_integer(magic, iid, best_netif->ipcom.type); break; case 4: /* ifMtu */ ret = ipsnmp_util_put_integer(magic, iid, best_netif->ipcom.mtu); break; case 5: /* ifSpeed */ if (best_netif->ipcom.type == IP_IFT_PPP) ret = ipsnmp_util_put_gauge32(magic, iid, IPCOM_DRV_PPP_BAUDRATE); else ret = ipsnmp_util_put_gauge32(magic, iid, 100000000); break; case 6: /* ifPhysAddr */ ret = ipsnmp_util_put_octetstring(magic, iid, best_netif->ipcom.link_addr, best_netif->ipcom.link_addr_size); break; case 7: /* ifAdminStatus */ if (IP_BIT_ISSET(best_netif->ipcom.flags, IP_IFF_UP)) ret = ipsnmp_util_put_integer(magic, iid, 1); else ret = ipsnmp_util_put_integer(magic, iid, 2); break; case 8: /* ifOperStatus */ if (IP_BIT_ISSET(best_netif->ipcom.flags, IP_IFF_UP)) ret = ipsnmp_util_put_integer(magic, iid, 1); else ret = ipsnmp_util_put_integer(magic, iid, 2); break; case 9: /* ifLastChange */ ret = ipsnmp_util_put_timeticks(magic, iid, best_netif->ipcom.mib2.ifLastChange); break; case 10: /* ifInOctets */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifInOctets); break; case 11: /* ifInUcastPkts */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifInUcastPkts); break; case 13: /* ifInDiscards */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifInDiscards); break; case 14: /* ifInErrors */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifInErrors); break; case 15: /* ifInUnknownProtos */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifInUnknownProtos); break; case 16: /* ifOutOctets */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifOutOctets); break; case 17: /* ifOutUcastPkts */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifOutUcastPkts); break; case 19: /* ifOutDiscards */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifOutDiscards); break; case 20: /* ifOutErrors */ ret = ipsnmp_util_put_counter32(magic, iid, best_netif->ipcom.mib2.ifOutErrors); break; default: IP_PANIC(); ret = IPSNMP_ERROR_GENERROR; break; } ipcom_free(iid); } if (cmd == IPSNMP_MIB_COMMAND_TEST || cmd == IPSNMP_MIB_COMMAND_SET) { switch(lid) { case 7: /* ifAdminStatus */ ret = ipsnmp_util_get_integer(vb, &ifAdminStatus); if (ret == IPSNMP_ERROR_NOERROR) { if (ifAdminStatus != 1 && ifAdminStatus != 2) { ret = IPSNMP_ERROR_WRONGVALUE; } } if (ret == IPSNMP_ERROR_NOERROR && cmd == IPSNMP_MIB_COMMAND_SET) { fd = ipnet_do_socket(IP_AF_INET, IP_SOCK_DGRAM, IP_IPPROTO_UDP, IP_FALSE); if(fd != IP_INVALID_SOCKET) { /* Change interface status */ ipcom_memset(&ifreq, 0, sizeof(struct Ip_ifreq)); ipcom_strcpy(ifreq.ifr_name, best_netif->ipcom.name); if (ipnet_sys_socketioctl(fd, IP_SIOCGIFFLAGS, &ifreq) < 0) { IPCOM_LOG1(ERR, "Failed to get interface flags: %s", ipcom_strerror(ipcom_errno)); ret = IPSNMP_ERROR_GENERROR; } if (ifAdminStatus == 1) IP_BIT_SET(ifreq.ip_ifr_flags, IP_IFF_UP); else IP_BIT_CLR(ifreq.ip_ifr_flags, IP_IFF_UP); if (ipnet_sys_socketioctl(fd, IP_SIOCSIFFLAGS, &ifreq) < 0) { IPCOM_LOG1(ERR, "Failed to set interface flags: %s", ipcom_strerror(ipcom_errno)); ret = IPSNMP_ERROR_GENERROR; } ipnet_sys_socketclose(fd); } else { IPCOM_LOG0(ERR, "Failed to create socket for ioctl call"); ret = IPSNMP_ERROR_GENERROR; } } break; default: IP_PANIC(); ret = IPSNMP_ERROR_GENERROR; break; } } exit: if (buf != IP_NULL) ipcom_free(buf); if (best != IP_NULL) ipcom_free(best); return ret; }
/* *=========================================================================== * ipnet_ip_forward_mib_handler_ipCidrRouteTable *=========================================================================== * Description: MIB handler for ipCidrRouteDest * Parameters: See file 'ipsnmp.h' * Returns: IPSNMP_ERROR_XXX * */ IP_STATIC Ip_s32 ipnet_ip_forward_mib_handler_ipCidrRouteTable(Ip_s32 cmd, char *id, Ipsnmp_varbind *vb, Ip_s32 magic, struct Ipsnmp_node_object *nodeobj) { Ip_s32 lid, bestindex, ret = -1; char *iid; char *buf = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID); char *best = ipcom_malloc(IPSNMP_CONFIG_MAX_OBJECT_ID); if(buf == IP_NULL || best == IP_NULL) { ret = IPSNMP_ERROR_GENERROR; goto exit; } lid = ipsnmp_util_last_subid(nodeobj->id); ip_assert(lid >= 1 && lid <= 16); bestindex = ipnet_ip_forward_mib_table_search_ipCidrRouteTable(id, buf, best, cmd); if(bestindex == -2) { ret = IPSNMP_ERROR_GENERROR; goto exit; } else if(bestindex == -1) { ret = IPSNMP_ERROR_NOSUCHNAME; goto exit; } if(cmd == IPSNMP_MIB_COMMAND_GET || cmd == IPSNMP_MIB_COMMAND_NEXT) { iid = ipsnmp_create_iid_direct(nodeobj->id, best); if(iid == IP_NULL) { ret = IPSNMP_ERROR_GENERROR; goto exit; } ip_assert(routewalk.bestrt != IP_NULL); switch(lid) { case 1: /* ipCidrRouteDest */ ret = ipsnmp_util_put_ipaddress(magic, iid, ip_ntohl(*(Ip_u32 *)routewalk.bestrt->hdr.key)); break; case 2: /* ipCidrRouteMask */ if(routewalk.bestrt->hdr.mask != IP_NULL) ret = ipsnmp_util_put_ipaddress(magic, iid, ip_ntohl(*(Ip_u32 *)routewalk.bestrt->hdr.mask)); else ret = ipsnmp_util_put_ipaddress(magic, iid, 0xffffffff); break; case 3: /* ipCidrRouteTos */ ret = ipsnmp_util_put_integer(magic, iid, 0); break; case 4: /* ipCidrRouteNextHop */ if(IP_BIT_ISSET(routewalk.bestrt->hdr.flags, IPNET_RTF_GATEWAY)) { struct Ip_sockaddr_in *sa = (struct Ip_sockaddr_in *)routewalk.bestrt->gateway; ret = ipsnmp_util_put_ipaddress(magic, iid, ip_ntohl(sa->sin_addr.s_addr)); } else ret = ipsnmp_util_put_ipaddress(magic, iid, 0); break; case 5: /* ipCidrRouteIfIndex */ ret = ipsnmp_util_put_integer(magic, iid, routewalk.bestrt->netif->ipcom.ifindex); break; case 6: /* ipCidrRouteType */ if(IP_BIT_ISSET(routewalk.bestrt->hdr.flags, IPNET_RTF_GATEWAY)) ret = ipsnmp_util_put_integer(magic, iid, 4); /* remote */ else ret = ipsnmp_util_put_integer(magic, iid, 3); /* local */ break; case 7: /* ipCidrRouteProto */ ret = ipsnmp_util_put_integer(magic, iid, 2); /* local */ break; case 8: /* ipCidrRouteAge */ ret = ipsnmp_util_put_integer(magic, iid, 0); break; case 9: /* ipCidrRouteInfo */ ret = ipsnmp_util_put_oid(magic, iid, "0.0"); break; case 10: /* ipCidrRouteNextHopAS */ ret = ipsnmp_util_put_integer(magic, iid, 0); break; case 11: /* ipCidrRouteMetric1 */ ret = ipsnmp_util_put_integer(magic, iid, -1); break; case 12: /* ipCidrRouteMetric2 */ ret = ipsnmp_util_put_integer(magic, iid, -1); break; case 13: /* ipCidrRouteMetric3 */ ret = ipsnmp_util_put_integer(magic, iid, -1); break; case 14: /* ipCidrRouteMetric4 */ ret = ipsnmp_util_put_integer(magic, iid, -1); break; case 15: /* ipCidrRouteMetric5 */ ret = ipsnmp_util_put_integer(magic, iid, -1); break; case 16: /* ipCidrRouteStatus */ ret = ipsnmp_util_put_integer(magic, iid, 1); /* active */ break; default: IP_PANIC(); ret = IPSNMP_ERROR_GENERROR; break; } ipcom_free(iid); } if(cmd == IPSNMP_MIB_COMMAND_TEST || cmd == IPSNMP_MIB_COMMAND_SET) { (void)vb; switch(lid) { case 5: /* ipCidrRouteIfIndex */ case 6: /* ipCidrRouteType */ case 9: /* ipCidrRouteInfo */ case 10: /* ipCidrRouteNextHopAS */ case 11: /* ipCidrRouteMetric1 */ case 12: /* ipCidrRouteMetric2 */ case 13: /* ipCidrRouteMetric3 */ case 14: /* ipCidrRouteMetric4 */ case 15: /* ipCidrRouteMetric5 */ case 16: /* ipCidrRouteStatus */ ret = IPSNMP_ERROR_NOSUCHNAME; break; default: IP_PANIC(); ret = IPSNMP_ERROR_GENERROR; break; } } exit: if(buf != IP_NULL) ipcom_free(buf); if(best != IP_NULL) ipcom_free(best); return ret; }