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 * ospfv3WwLsdbEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { struct ospf6_lsa *lsa = NULL; u_int32_t ifindex, area_id, id, instid, adv_router; u_int16_t type; int len; oid *offset; int offsetlen; char a[16], b[16], c[16]; struct ospf6_area *oa; struct listnode *node; struct interface *iif; struct ospf6_interface *oi = NULL; struct list *ifslist; if (smux_header_table(v, name, length, exact, var_len, write_method) == MATCH_FAILED) return NULL; instid = ifindex = area_id = type = id = adv_router = 0; /* Check OSPFv3 instance. */ if (ospf6 == NULL) return NULL; /* Get variable length. */ offset = name + v->namelen; offsetlen = *length - v->namelen; if (exact && (v->magic & OSPFv3WWASTABLE) && offsetlen != 3) return NULL; if (exact && (v->magic & OSPFv3WWAREATABLE) && offsetlen != 4) return NULL; if (exact && (v->magic & OSPFv3WWLINKTABLE) && offsetlen != 5) return NULL; if (v->magic & OSPFv3WWLINKTABLE) { /* Parse ifindex */ len = (offsetlen < 1 ? 0 : 1); if (len) ifindex = *offset; offset += len; offsetlen -= len; /* Parse instance ID */ len = (offsetlen < 1 ? 0 : 1); if (len) instid = *offset; offset += len; offsetlen -= len; } else if (v->magic & OSPFv3WWAREATABLE) { /* Parse area-id */ len = (offsetlen < 1 ? 0 : 1); if (len) area_id = htonl (*offset); offset += len; offsetlen -= len; } /* Parse type */ len = (offsetlen < 1 ? 0 : 1); if (len) type = htons (*offset); offset += len; offsetlen -= len; /* Parse Router-ID */ len = (offsetlen < 1 ? 0 : 1); if (len) adv_router = htonl (*offset); offset += len; offsetlen -= len; /* Parse LS-ID */ len = (offsetlen < 1 ? 0 : 1); if (len) id = htonl (*offset); offset += len; offsetlen -= len; if (exact) { if (v->magic & OSPFv3WWASTABLE) { lsa = ospf6_lsdb_lookup (type, id, adv_router, ospf6->lsdb); } else if (v->magic & OSPFv3WWAREATABLE) { oa = ospf6_area_lookup (area_id, ospf6); if (!oa) return NULL; lsa = ospf6_lsdb_lookup (type, id, adv_router, oa->lsdb); } else if (v->magic & OSPFv3WWLINKTABLE) { oi = ospf6_interface_lookup_by_ifindex (ifindex); if (!oi || oi->instance_id != instid) return NULL; lsa = ospf6_lsdb_lookup (type, id, adv_router, oi->lsdb); } } else { if (v->magic & OSPFv3WWASTABLE) { if (ospf6->lsdb->count) lsa = ospf6_lsdb_lookup_next (type, id, adv_router, ospf6->lsdb); } else if (v->magic & OSPFv3WWAREATABLE) for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa)) { if (oa->area_id < area_id) continue; if (oa->lsdb->count) lsa = ospf6_lsdb_lookup_next (type, id, adv_router, oa->lsdb); if (lsa) break; type = 0; id = 0; adv_router = 0; } else if (v->magic & OSPFv3WWLINKTABLE) { /* We build a sorted list of interfaces */ ifslist = list_new (); if (!ifslist) return NULL; ifslist->cmp = (int (*)(void *, void *))if_icmp_func; for (ALL_LIST_ELEMENTS_RO (iflist, node, iif)) listnode_add_sort (ifslist, iif); for (ALL_LIST_ELEMENTS_RO (ifslist, node, iif)) { if (!iif->ifindex) continue; oi = ospf6_interface_lookup_by_ifindex (iif->ifindex); if (!oi) continue; if (iif->ifindex < ifindex) continue; if (oi->instance_id < instid) continue; if (oi->lsdb->count) lsa = ospf6_lsdb_lookup_next (type, id, adv_router, oi->lsdb); if (lsa) break; type = 0; id = 0; adv_router = 0; oi = NULL; } list_delete_all_node (ifslist); }