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

📄 ospf_snmp.c

📁 router source code for the ospdf.
💻 C
📖 第 1 页 / 共 5 页
字号:
  listnode node;  struct ospf_interface *oi;  if (ospf == NULL)    return 0;  for (node = listhead (ospf->oiflist); node; nextnode (node))    {      oi = getdata (node);      if (oi && oi->address)	return 1;    }  return 0;}static u_char *ospfGeneralGroup (struct variable *v, oid *name, size_t *length,		  int exact, size_t *var_len, WriteMethod **write_method){  struct ospf *ospf;  ospf = ospf_lookup ();  /* 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 OSPFROUTERID:		/* 1 */      /* Router-ID of this OSPF instance. */      if (ospf)	return SNMP_IPADDRESS (ospf->router_id);      else	return SNMP_IPADDRESS (ospf_empty_addr);      break;    case OSPFADMINSTAT:		/* 2 */      /* The administrative status of OSPF in the router. */      if (ospf_admin_stat (ospf))	return SNMP_INTEGER (OSPF_STATUS_ENABLED);      else	return SNMP_INTEGER (OSPF_STATUS_DISABLED);      break;    case OSPFVERSIONNUMBER:	/* 3 */      /* OSPF version 2. */      return SNMP_INTEGER (OSPF_VERSION);      break;    case OSPFAREABDRRTRSTATUS:	/* 4 */      /* Area Border router status. */      if (ospf && CHECK_FLAG (ospf->flags, OSPF_FLAG_ABR))	return SNMP_INTEGER (SNMP_TRUE);      else	return SNMP_INTEGER (SNMP_FALSE);      break;    case OSPFASBDRRTRSTATUS:	/* 5 */      /* AS Border router status. */      if (ospf && CHECK_FLAG (ospf->flags, OSPF_FLAG_ASBR))	return SNMP_INTEGER (SNMP_TRUE);      else	return SNMP_INTEGER (SNMP_FALSE);      break;    case OSPFEXTERNLSACOUNT:	/* 6 */      /* External LSA counts. */      if (ospf)	return SNMP_INTEGER (ospf_lsdb_count_all (ospf->lsdb));      else	return SNMP_INTEGER (0);      break;    case OSPFEXTERNLSACKSUMSUM:	/* 7 */      /* External LSA checksum. */      return SNMP_INTEGER (0);      break;    case OSPFTOSSUPPORT:	/* 8 */      /* TOS is not supported. */      return SNMP_INTEGER (SNMP_FALSE);      break;    case OSPFORIGINATENEWLSAS:	/* 9 */      /* The number of new link-state advertisements. */      if (ospf)	return SNMP_INTEGER (ospf->lsa_originate_count);      else	return SNMP_INTEGER (0);      break;    case OSPFRXNEWLSAS:		/* 10 */      /* The number of link-state advertisements received determined         to be new instantiations. */      if (ospf)	return SNMP_INTEGER (ospf->rx_lsa_count);      else	return SNMP_INTEGER (0);      break;    case OSPFEXTLSDBLIMIT:	/* 11 */      /* There is no limit for the number of non-default         AS-external-LSAs. */      return SNMP_INTEGER (-1);      break;    case OSPFMULTICASTEXTENSIONS: /* 12 */      /* Multicast Extensions to OSPF is not supported. */      return SNMP_INTEGER (0);      break;    case OSPFEXITOVERFLOWINTERVAL: /* 13 */      /* Overflow is not supported. */      return SNMP_INTEGER (0);      break;    case OSPFDEMANDEXTENSIONS:	/* 14 */      /* Demand routing is not supported. */      return SNMP_INTEGER (SNMP_FALSE);      break;    default:      return NULL;    }  return NULL;}struct ospf_area *ospf_area_lookup_next (struct ospf *ospf, struct in_addr *area_id, int first){  struct ospf_area *area;  listnode node;  if (ospf == NULL)    return NULL;  if (first)    {      node = listhead (ospf->areas);      if (node)	{	  area = getdata (node);	  *area_id = area->area_id;	  return area;	}      return NULL;    }  for (node = listhead (ospf->areas); node; nextnode (node))    {      area = getdata (node);      if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr))	{	  *area_id = area->area_id;	  return area;	}    }  return NULL;}struct ospf_area *ospfAreaLookup (struct variable *v, oid name[], size_t *length,		struct in_addr *addr, int exact){  struct ospf *ospf;  struct ospf_area *area;  int len;  ospf = ospf_lookup ();  if (ospf == NULL)    return NULL;  if (exact)    {      /* Length is insufficient to lookup OSPF area. */      if (*length - v->namelen != sizeof (struct in_addr))	return NULL;      oid2in_addr (name + v->namelen, sizeof (struct in_addr), addr);      area = ospf_area_lookup_by_area_id (ospf, *addr);      return area;    }  else    {      len = *length - v->namelen;      if (len > 4)	len = 4;            oid2in_addr (name + v->namelen, len, addr);      area = ospf_area_lookup_next (ospf, addr, len == 0 ? 1 : 0);      if (area == NULL)	return NULL;      oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr));      *length = sizeof (struct in_addr) + v->namelen;      return area;    }  return NULL;}static u_char *ospfAreaEntry (struct variable *v, oid *name, size_t *length, int exact,	       size_t *var_len, WriteMethod **write_method){  struct ospf_area *area;  struct in_addr addr;  memset (&addr, 0, sizeof (struct in_addr));  area = ospfAreaLookup (v, name, length, &addr, exact);  if (! area)    return NULL;    /* Return the current value of the variable */  switch (v->magic)     {    case OSPFAREAID:		/* 1 */      return SNMP_IPADDRESS (area->area_id);      break;    case OSPFAUTHTYPE:		/* 2 */      return SNMP_INTEGER (area->auth_type);      break;    case OSPFIMPORTASEXTERN:	/* 3 */      return SNMP_INTEGER (area->external_routing + 1);      break;    case OSPFSPFRUNS:		/* 4 */      return SNMP_INTEGER (area->spf_calculation);      break;    case OSPFAREABDRRTRCOUNT:	/* 5 */      return SNMP_INTEGER (area->abr_count);      break;    case OSPFASBDRRTRCOUNT:	/* 6 */      return SNMP_INTEGER (area->asbr_count);      break;    case OSPFAREALSACOUNT:	/* 7 */      return SNMP_INTEGER (area->lsdb->total);      break;    case OSPFAREALSACKSUMSUM:	/* 8 */      return SNMP_INTEGER (0);      break;    case OSPFAREASUMMARY:	/* 9 */#define OSPF_noAreaSummary   1#define OSPF_sendAreaSummary 2      if (area->no_summary)	return SNMP_INTEGER (OSPF_noAreaSummary);      else	return SNMP_INTEGER (OSPF_sendAreaSummary);      break;    case OSPFAREASTATUS:	/* 10 */      return SNMP_INTEGER (SNMP_VALID);      break;    default:      return NULL;      break;    }  return NULL;}struct ospf_area *ospf_stub_area_lookup_next (struct in_addr *area_id, int first){  struct ospf_area *area;  listnode node;  struct ospf *ospf;  ospf = ospf_lookup ();  if (ospf == NULL)    return NULL;  for (node = listhead (ospf->areas); node; nextnode (node))    {      area = getdata (node);      if (area->external_routing == OSPF_AREA_STUB)	{	  if (first)	    {	      *area_id = area->area_id;	      return area;	    }	  else if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr))	    {	      *area_id = area->area_id;	      return area;	    }	}    }  return NULL;}struct ospf_area *ospfStubAreaLookup (struct variable *v, oid name[], size_t *length,		    struct in_addr *addr, int exact){  struct ospf *ospf;  struct ospf_area *area;  int len;  ospf = ospf_lookup ();  if (ospf == NULL)    return NULL;  /* Exact lookup. */  if (exact)    {      /* ospfStubAreaID + ospfStubTOS. */      if (*length != v->namelen + sizeof (struct in_addr) + 1)	return NULL;      /* Check ospfStubTOS is zero. */      if (name[*length - 1] != 0)	return NULL;      oid2in_addr (name + v->namelen, sizeof (struct in_addr), addr);      area = ospf_area_lookup_by_area_id (ospf, *addr);      if (area->external_routing == OSPF_AREA_STUB)	return area;      else	return NULL;    }  else    {      len = *length - v->namelen;      if (len > 4)	len = 4;            oid2in_addr (name + v->namelen, len, addr);      area = ospf_stub_area_lookup_next (addr, len == 0 ? 1 : 0);      if (area == NULL)	return NULL;      oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr));      /* Set TOS 0. */      name[v->namelen + sizeof (struct in_addr)] = 0;      *length = v->namelen + sizeof (struct in_addr) + 1;      return area;    }  return NULL;}static u_char *ospfStubAreaEntry (struct variable *v, oid *name, size_t *length,		   int exact, size_t *var_len, WriteMethod **write_method){  struct ospf_area *area;  struct in_addr addr;  memset (&addr, 0, sizeof (struct in_addr));  area = ospfStubAreaLookup (v, name, length, &addr, exact);  if (! area)    return NULL;  /* Return the current value of the variable */  switch (v->magic)     {    case OSPFSTUBAREAID:	/* 1 */      /* OSPF stub area id. */      return SNMP_IPADDRESS (area->area_id);      break;    case OSPFSTUBTOS:		/* 2 */      /* TOS value is not supported. */      return SNMP_INTEGER (0);      break;    case OSPFSTUBMETRIC:	/* 3 */      /* Default cost to stub area. */      return SNMP_INTEGER (area->default_cost);      break;    case OSPFSTUBSTATUS:	/* 4 */      /* Status of the stub area. */      return SNMP_INTEGER (SNMP_VALID);      break;    case OSPFSTUBMETRICTYPE:	/* 5 */      /* OSPF Metric type. */#define OSPF_ospfMetric     1#define OSPF_comparableCost 2#define OSPF_nonComparable  3      return SNMP_INTEGER (OSPF_ospfMetric);      break;    default:      return NULL;      break;    }  return NULL;}struct ospf_lsa *lsdb_lookup_next (struct ospf_area *area, u_char *type, int type_next,		  struct in_addr *ls_id, int ls_id_next,		  struct in_addr *router_id, int router_id_next){  struct ospf_lsa *lsa;  int i;  if (type_next)    i = OSPF_MIN_LSA;  else    i = *type;  for (; i < OSPF_MAX_LSA; i++)    {      *type = i;      lsa = ospf_lsdb_lookup_by_id_next (area->lsdb, *type, *ls_id, *router_id,					ls_id_next);      if (lsa)	return lsa;      ls_id_next = 1;    }  return NULL;}struct ospf_lsa *ospfLsdbLookup (struct variable *v, oid *name, size_t *length,		struct in_addr *area_id, u_char *type,		struct in_addr *ls_id, struct in_addr *router_id, int exact){  struct ospf *ospf;  struct ospf_area *area;  struct ospf_lsa *lsa;  int len;  int type_next;  int ls_id_next;  int router_id_next;  oid *offset;  int offsetlen;  ospf = ospf_lookup ();#define OSPF_LSDB_ENTRY_OFFSET \          (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)  if (exact)    {      /* Area ID + Type + LS ID + Router ID. */      if (*length - v->namelen != OSPF_LSDB_ENTRY_OFFSET)	return NULL;            /* Set OID offset for Area ID. */      offset = name + v->namelen;      /* Lookup area first. */      oid2in_addr (offset, IN_ADDR_SIZE, area_id);      area = ospf_area_lookup_by_area_id (ospf, *area_id);      if (! area)	return NULL;      offset += IN_ADDR_SIZE;      /* Type. */      *type = *offset;      offset++;      /* LS ID. */      oid2in_addr (offset, IN_ADDR_SIZE, ls_id);      offset += IN_ADDR_SIZE;      /* Router ID. */      oid2in_addr (offset, IN_ADDR_SIZE, router_id);      /* Lookup LSDB. */      return ospf_lsdb_lookup_by_id (area->lsdb, *type, *ls_id, *router_id);    }  else    {      /* Get variable length. */      offset = name + v->namelen;      offsetlen = *length - v->namelen;      len = offsetlen;      if (len > IN_ADDR_SIZE)	len = IN_ADDR_SIZE;      oid2in_addr (offset, len, area_id);      /* First we search area. */      if (len == IN_ADDR_SIZE)	area = ospf_area_lookup_by_area_id (ospf, *area_id);      else	area = ospf_area_lookup_next (ospf, area_id, len == 0 ? 1 : 0);      if (area == NULL)	return NULL;      do 	{	  /* Next we lookup type. */	  offset += IN_ADDR_SIZE;	  offsetlen -= IN_ADDR_SIZE;	  len = offsetlen;	  if (len <= 0)	    type_next = 1;	  else	    {	      len = 1;	      type_next = 0;

⌨️ 快捷键说明

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