⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ospf6_snmp.c

📁 linux 路由软件 可支持RIP OSPF BGP等
💻 C
📖 第 1 页 / 共 2 页
字号:
      break;    case OSPFv3EXTLSACOUNT:               /*10*/      break;    case OSPFv3EXTAREALSDBLIMIT:          /*11*/      break;    case OSPFv3MULTICASTEXTENSIONS:       /*12*/      break;    case OSPFv3EXITOVERFLOWINTERVAL:      /*13*/      break;    case OSPFv3DEMANDEXTENSIONS:          /*14*/      break;    case OSPFv3TRAFFICENGINEERINGSUPPORT: /*15*/      break;    case OSPFv3REFERENCEBANDWIDTH:        /*16*/      break;    case OSPFv3RESTARTSUPPORT:            /*17*/      break;    case OSPFv3RESTARTINTERVAL:           /*18*/      break;    case OSPFv3RESTARTSTATUS:             /*19*/      break;    case OSPFv3RESTARTAGE:                /*20*/      break;    case OSPFv3RESTARTEXITREASON:         /*21*/      break;    default:      return NULL;    }  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;  listnode node;  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_info ("SNMP access by area: %s, exact=%d len=%d length=%d",             inet_ntoa (* (struct in_addr *) &area_id),             exact, len, *length);  for (node = listhead (ospf6->area_list); node; nextnode (node))    {      oa = (struct ospf6_area *) getdata (node);      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_info ("SNMP found area: %s, exact=%d len=%d length=%d",             inet_ntoa (* (struct in_addr *) &area->area_id),             exact, len, *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 *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;  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;  inet_ntop (AF_INET, &area_id, a, sizeof (a));  inet_ntop (AF_INET, &adv_router, b, sizeof (b));  inet_ntop (AF_INET, &id, c, sizeof (c));  zlog_info ("SNMP access by lsdb: area=%s exact=%d length=%d magic=%d"             " type=%#x adv_router=%s id=%s",             a, exact, *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 (node = listhead (ospf6->area_list); node; nextnode (node))        {          oa = (struct ospf6_area *) getdata (node);          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_info ("SNMP respond: No LSA to return");      return NULL;    }  oa = OSPF6_AREA (lsa->lsdb->data);  zlog_info ("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;}/* Register OSPFv3-MIB. */voidospf6_snmp_init (){  smux_init (ospf6d_oid, sizeof (ospf6d_oid) / sizeof (oid));  REGISTER_MIB ("OSPFv3MIB", ospfv3_variables, variable, ospfv3_oid);  smux_start ();}#endif /* HAVE_SNMP */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -