static u_char * rip2Globals (struct variable *v, oid name[], size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { if (smux_header_generic(v, name, length, exact, var_len, write_method) == MATCH_FAILED) return NULL; /* Retrun global counter. */ switch (v->magic) { case RIP2GLOBALROUTECHANGES: return SNMP_INTEGER (rip_global_route_changes); break; case RIP2GLOBALQUERIES: return SNMP_INTEGER (rip_global_queries); break; default: return NULL; break; } return NULL; }
static u_char * ospfv3AreaLsdbEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { struct ospf6_lsa *lsa = NULL; struct in_addr area_id; u_int16_t type; struct in_addr id; struct in_addr adv_router; int len; oid *offset; int offsetlen; char a[16], b[16], c[16]; struct ospf6_area *oa; struct listnode *node; memset (&area_id, 0, sizeof (struct in_addr)); type = 0; memset (&id, 0, sizeof (struct in_addr)); memset (&adv_router, 0, sizeof (struct in_addr)); /* Check OSPFv3 instance. */ if (ospf6 == NULL) return NULL; /* Get variable length. */ offset = name + v->namelen; offsetlen = *length - v->namelen; #define OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET \ (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE) if (exact && offsetlen != OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET) return NULL; /* Parse area-id */ len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE); if (len) oid2in_addr (offset, len, &area_id); offset += len; offsetlen -= len; /* Parse type */ len = (offsetlen < 1 ? offsetlen : 1); if (len) type = htons (*offset); offset += len; offsetlen -= len; /* Parse Router-ID */ len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE); if (len) oid2in_addr (offset, len, &adv_router); offset += len; offsetlen -= len; /* Parse LS-ID */ len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE); if (len) oid2in_addr (offset, len, &id); offset += len; offsetlen -= len; ospf6_id2str (area_id.s_addr, a, sizeof (a)); ospf6_id2str (adv_router.s_addr, b, sizeof (b)); ospf6_id2str (id.s_addr, c, sizeof (c)); zlog_debug ("SNMP access by lsdb: area=%s exact=%d length=%lu magic=%d" " type=%#x adv_router=%s id=%s", a, exact, (u_long)*length, v->magic, ntohs (type), b, c); if (exact) { oa = ospf6_area_lookup (area_id.s_addr, ospf6); lsa = ospf6_lsdb_lookup (type, id.s_addr, adv_router.s_addr, oa->lsdb); } else { for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa)) { if (lsa) continue; if (ntohl (oa->area_id) < ntohl (area_id.s_addr)) continue; lsa = ospf6_lsdb_lookup_next (type, id.s_addr, adv_router.s_addr, oa->lsdb); if (! lsa) { type = 0; memset (&id, 0, sizeof (struct in_addr)); memset (&adv_router, 0, sizeof (struct in_addr)); } } } if (! lsa) { zlog_debug ("SNMP respond: No LSA to return"); return NULL; } oa = OSPF6_AREA (lsa->lsdb->data); zlog_debug ("SNMP respond: area: %s lsa: %s", oa->name, lsa->name); /* Add Index (AreaId, Type, RouterId, Lsid) */ *length = v->namelen + OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET; offset = name + v->namelen; oid_copy_addr (offset, (struct in_addr *) &oa->area_id, IN_ADDR_SIZE); offset += IN_ADDR_SIZE; *offset = ntohs (lsa->header->type); offset++; oid_copy_addr (offset, (struct in_addr *) &lsa->header->adv_router, IN_ADDR_SIZE); offset += IN_ADDR_SIZE; oid_copy_addr (offset, (struct in_addr *) &lsa->header->id, IN_ADDR_SIZE); offset += IN_ADDR_SIZE; /* Return the current value of the variable */ switch (v->magic) { case OSPFv3AREALSDBAREAID: /* 1 */ area_id.s_addr = OSPF6_AREA (lsa->lsdb->data)->area_id; return SNMP_IPADDRESS (area_id); break; case OSPFv3AREALSDBTYPE: /* 2 */ return SNMP_INTEGER (ntohs (lsa->header->type)); break; case OSPFv3AREALSDBROUTERID: /* 3 */ adv_router.s_addr = lsa->header->adv_router; return SNMP_IPADDRESS (adv_router); break; case OSPFv3AREALSDBLSID: /* 4 */ id.s_addr = lsa->header->id; return SNMP_IPADDRESS (id); break; case OSPFv3AREALSDBSEQUENCE: /* 5 */ return SNMP_INTEGER (lsa->header->seqnum); break; case OSPFv3AREALSDBAGE: /* 6 */ ospf6_lsa_age_current (lsa); return SNMP_INTEGER (lsa->header->age); break; case OSPFv3AREALSDBCHECKSUM: /* 7 */ return SNMP_INTEGER (lsa->header->checksum); break; case OSPFv3AREALSDBADVERTISEMENT: /* 8 */ *var_len = ntohs (lsa->header->length); return (u_char *) lsa->header; break; case OSPFv3AREALSDBTYPEKNOWN: /* 9 */ return SNMP_INTEGER (OSPF6_LSA_IS_KNOWN (lsa->header->type) ? SNMP_TRUE : SNMP_FALSE); break; default: return NULL; break; } return NULL; }
static u_char * ospfv3AreaEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { struct ospf6_area *oa, *area = NULL; u_int32_t area_id = 0; struct listnode *node; unsigned int len; if (ospf6 == NULL) return NULL; len = *length - v->namelen; len = (len >= sizeof (u_int32_t) ? sizeof (u_int32_t) : 0); if (exact && len != sizeof (u_int32_t)) return NULL; if (len) oid2in_addr (name + v->namelen, len, (struct in_addr *) &area_id); zlog_debug ("SNMP access by area: %s, exact=%d len=%d length=%lu", inet_ntoa (* (struct in_addr *) &area_id), exact, len, (u_long)*length); for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa)) { if (area == NULL) { if (len == 0) /* return first area entry */ area = oa; else if (exact && ntohl (oa->area_id) == ntohl (area_id)) area = oa; else if (ntohl (oa->area_id) > ntohl (area_id)) area = oa; } } if (area == NULL) return NULL; *length = v->namelen + sizeof (u_int32_t); oid_copy_addr (name + v->namelen, (struct in_addr *) &area->area_id, sizeof (u_int32_t)); zlog_debug ("SNMP found area: %s, exact=%d len=%d length=%lu", inet_ntoa (* (struct in_addr *) &area->area_id), exact, len, (u_long)*length); switch (v->magic) { case OSPFv3AREAID: /* 1*/ return SNMP_IPADDRESS (INT32_INADDR (area->area_id)); break; case OSPFv3IMPORTASEXTERN: /* 2*/ return SNMP_INTEGER (ospf6->external_table->count); break; default: return NULL; break; } return NULL; }
static u_char * ospfv3AreaEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { struct ospf6_area *oa, *area = NULL; struct ospf6_lsa *lsa = NULL; u_int32_t area_id = 0; u_int32_t count; u_int16_t sum; struct listnode *node; unsigned int len; char a[16]; struct ospf6_route *ro; if (ospf6 == NULL) return NULL; if (smux_header_table(v, name, length, exact, var_len, write_method) == MATCH_FAILED) return NULL; len = *length - v->namelen; len = (len >= 1 ? sizeof 1 : 0); if (exact && len != 1) return NULL; if (len) area_id = htonl (name[v->namelen]); inet_ntop (AF_INET, &area_id, a, sizeof (a)); zlog_debug ("SNMP access by area: %s, exact=%d len=%d length=%lu", a, exact, len, (u_long)*length); for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa)) { if (area == NULL) { if (len == 0) /* return first area entry */ area = oa; else if (exact && ntohl (oa->area_id) == ntohl (area_id)) area = oa; else if (ntohl (oa->area_id) > ntohl (area_id)) area = oa; } } if (area == NULL) return NULL; *length = v->namelen + 1; name[v->namelen] = ntohl (area->area_id); inet_ntop (AF_INET, &area->area_id, a, sizeof (a)); zlog_debug ("SNMP found area: %s, exact=%d len=%d length=%lu", a, exact, len, (u_long)*length); switch (v->magic) { case OSPFv3IMPORTASEXTERN: /* No NSSA support */ return SNMP_INTEGER (IS_AREA_STUB(area)?2:1); case OSPFv3AREASPFRUNS: return SNMP_INTEGER (area->spf_calculation); case OSPFv3AREABDRRTRCOUNT: case OSPFv3AREAASBDRRTRCOUNT: count = 0; for (ro = ospf6_route_head (ospf6->brouter_table); ro; ro = ospf6_route_next (ro)) { if (ntohl (ro->path.area_id) != ntohl (area->area_id)) continue; if (v->magic == OSPFv3AREABDRRTRCOUNT && CHECK_FLAG (ro->path.router_bits, OSPF6_ROUTER_BIT_B)) count++; if (v->magic == OSPFv3AREAASBDRRTRCOUNT && CHECK_FLAG (ro->path.router_bits, OSPF6_ROUTER_BIT_E)) count++; } return SNMP_INTEGER (count); case OSPFv3AREASCOPELSACOUNT: return SNMP_INTEGER (area->lsdb->count); case OSPFv3AREASCOPELSACKSUMSUM: for (sum = 0, lsa = ospf6_lsdb_head (area->lsdb); lsa; lsa = ospf6_lsdb_next (lsa)) sum += ntohs (lsa->header->checksum); return SNMP_INTEGER (sum); case OSPFv3AREASUMMARY: return SNMP_INTEGER (2); /* sendAreaSummary */ case OSPFv3AREAROWSTATUS: return SNMP_INTEGER (1); /* Active */ case OSPFv3AREASTUBMETRIC: case OSPFv3AREANSSATRANSLATORROLE: case OSPFv3AREANSSATRANSLATORSTATE: case OSPFv3AREANSSATRANSLATORSTABINTERVAL: case OSPFv3AREANSSATRANSLATOREVENTS: case OSPFv3AREASTUBMETRICTYPE: case OSPFv3AREATEENABLED: /* Not implemented. */ return NULL; } return NULL; }
static u_char * ospfv3GeneralGroup (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { u_int16_t sum; u_int32_t count; struct ospf6_lsa *lsa = NULL; /* Check whether the instance identifier is valid */ if (smux_header_generic (v, name, length, exact, var_len, write_method) == MATCH_FAILED) return NULL; /* Return the current value of the variable */ switch (v->magic) { case OSPFv3ROUTERID: /* Router-ID of this OSPF instance. */ if (ospf6) return SNMP_INTEGER (ntohl (ospf6->router_id)); return SNMP_INTEGER (0); case OSPFv3ADMINSTAT: if (ospf6) return SNMP_INTEGER (CHECK_FLAG (ospf6->flag, OSPF6_DISABLED)? OSPF_STATUS_DISABLED:OSPF_STATUS_ENABLED); return SNMP_INTEGER (OSPF_STATUS_DISABLED); case OSPFv3VERSIONNUMBER: return SNMP_INTEGER (3); case OSPFv3AREABDRRTRSTATUS: if (ospf6) return SNMP_INTEGER (ospf6_is_router_abr (ospf6)?SNMP_TRUE:SNMP_FALSE); return SNMP_INTEGER (SNMP_FALSE); case OSPFv3ASBDRRTRSTATUS: if (ospf6) return SNMP_INTEGER (ospf6_asbr_is_asbr (ospf6)?SNMP_TRUE:SNMP_FALSE); return SNMP_INTEGER (SNMP_FALSE); case OSPFv3ASSCOPELSACOUNT: if (ospf6) return SNMP_INTEGER (ospf6->lsdb->count); return SNMP_INTEGER (0); case OSPFv3ASSCOPELSACHECKSUMSUM: if (ospf6) { for (sum = 0, lsa = ospf6_lsdb_head (ospf6->lsdb); lsa; lsa = ospf6_lsdb_next (lsa)) sum += ntohs (lsa->header->checksum); return SNMP_INTEGER (sum); } return SNMP_INTEGER (0); case OSPFv3ORIGINATENEWLSAS: return SNMP_INTEGER (0); /* Don't know where to get this value... */ case OSPFv3RXNEWLSAS: return SNMP_INTEGER (0); /* Don't know where to get this value... */ case OSPFv3EXTLSACOUNT: if (ospf6) { for (count = 0, lsa = ospf6_lsdb_type_head (htons (OSPF6_LSTYPE_AS_EXTERNAL), ospf6->lsdb); lsa; lsa = ospf6_lsdb_type_next (htons (OSPF6_LSTYPE_AS_EXTERNAL), lsa)) count += 1; return SNMP_INTEGER (count); } return SNMP_INTEGER (0); case OSPFv3EXTAREALSDBLIMIT: return SNMP_INTEGER (-1); case OSPFv3EXITOVERFLOWINTERVAL: return SNMP_INTEGER (0); /* Not supported */ case OSPFv3DEMANDEXTENSIONS: return SNMP_INTEGER (0); /* Not supported */ case OSPFv3REFERENCEBANDWIDTH: return SNMP_INTEGER (100000); case OSPFv3RESTARTSUPPORT: case OSPFv3RESTARTINTERVAL: case OSPFv3RESTARTSTRICTLSACHECKING: case OSPFv3RESTARTSTATUS: case OSPFv3RESTARTAGE: case OSPFv3RESTARTEXITREASON: case OSPFv3NOTIFICATIONENABLE: case OSPFv3STUBROUTERSUPPORT: case OSPFv3STUBROUTERADVERTISEMENT: case OSPFv3DISCONTINUITYTIME: case OSPFv3RESTARTTIME: /* TODO: Not implemented */ return NULL; } return NULL; }