コード例 #1
0
ファイル: snmp.c プロジェクト: AsherBond/quagga
int
smux_header_generic (struct variable *v, oid *name, size_t *length, int exact,
		     size_t *var_len, WriteMethod **write_method)
{
  oid fulloid[MAX_OID_LEN];
  int ret;

  oid_copy (fulloid, v->name, v->namelen);
  fulloid[v->namelen] = 0;
  /* Check against full instance. */
  ret = oid_compare (name, *length, fulloid, v->namelen + 1);

  /* Check single instance. */
  if ((exact && (ret != 0)) || (!exact && (ret >= 0)))
	return MATCH_FAILED;

  /* In case of getnext, fill in full instance. */
  memcpy (name, fulloid, (v->namelen + 1) * sizeof (oid));
  *length = v->namelen + 1;

  *write_method = 0;
  *var_len = sizeof(long);    /* default to 'long' results */

  return MATCH_SUCCEEDED;
}
コード例 #2
0
ファイル: mid.c プロジェクト: brnrc/ion-dtn
mid_t *mid_copy(mid_t *src_mid)
{
    mid_t *result = 0;
    
    DTNMP_DEBUG_ENTRY("mid_copy","(%#llx)",
    		          (unsigned long) src_mid);
    
    /* Step 0: Sanity Check */
    if(src_mid == NULL)
    {
        DTNMP_DEBUG_ERR("mid_copy","Cannot copy from NULL source MID.", NULL);
        DTNMP_DEBUG_EXIT("mid_copy","->NULL",NULL);
        return NULL;
    }

    /* Step 1: Allocate the new MID. */
    if((result = (mid_t *)MTAKE(sizeof(mid_t))) == NULL)
    {
        DTNMP_DEBUG_ERR("mid_copy","Can't allocate %d bytes", sizeof(mid_t));
        DTNMP_DEBUG_EXIT("mid_copy","->NULL",NULL);
        return NULL;
    }

    /* Step 2: Start with a shallow copy. */
    memcpy(result, src_mid, sizeof(mid_t));

    /* Step 3: Now, deep copy the pointers. */
    result->oid = oid_copy(src_mid->oid);

    if((result->raw = (uint8_t *)MTAKE(src_mid->raw_size)) == NULL)
    {
        DTNMP_DEBUG_ERR("mid_copy","Can't allocate %d bytes",
        		        src_mid->raw_size);

        MRELEASE(result->oid);
        MRELEASE(result);

        DTNMP_DEBUG_EXIT("mid_copy","->NULL",NULL);
        return NULL;
    }

    memcpy(result->raw, src_mid->raw, src_mid->raw_size);

    DTNMP_DEBUG_EXIT("mid_copy","->%d", result);
    return result;
}
コード例 #3
0
ファイル: snmp.c プロジェクト: AsherBond/quagga
int
smux_header_table (struct variable *v, oid *name, size_t *length, int exact,
		   size_t *var_len, WriteMethod **write_method)
{
  /* If the requested OID name is less than OID prefix we
     handle, adjust it to our prefix. */
  if ((oid_compare (name, *length, v->name, v->namelen)) < 0)
    {
      if (exact)
	return MATCH_FAILED;
      oid_copy(name, v->name, v->namelen);
      *length = v->namelen;
    }

  *write_method = 0;
  *var_len = sizeof(long);

  return MATCH_SUCCEEDED;
}
コード例 #4
0
static struct ilo_oid_list *
alloc_oid_list (netsnmp_variable_list *var_src, char **error_ptr)
{
  struct ilo_oid_list *oid_list = NULL;

  oid_list = (struct ilo_oid_list *) malloc(sizeof(*oid_list));

  if (oid_list != NULL) 
    {
      memset(oid_list, 0, sizeof(struct ilo_oid_list));

      oid_list->type = var_src->type;
      oid_list->value_len = var_src->val_len;
      oid_list->index = var_src->index;

      if(get_netsnmp_var(oid_list, var_src) != NAGIOS_ILO_SUCCESS_STATUS) 
	{
	  ILO_ERR_DEBUG(error_ptr, "Unknown type '%d'\n", var_src->type);
	  return NULL;
	}

      oid_list->name = (oid *) malloc(MAX_OID_LEN);

      if (oid_list->name == NULL) 
	{
	  ILO_ERR_DEBUG(error_ptr, "malloc failed for the 'name' "
				    "member of the oid list\n");
	  return NULL;
	}

      oid_copy(oid_list->name, &oid_list->name_len, var_src->name, 
	       var_src->name_length);
      oid_list->next = NULL;
    } 
  else 
    {
      ILO_ERR_DEBUG(error_ptr, "malloc failed for entry of the oid list\n");
    }

  return oid_list;
}
コード例 #5
0
ファイル: smux.c プロジェクト: Quagga/people-jcollie
int
smux_trap (oid *name, size_t namelen,
	   oid *iname, size_t inamelen,
	   struct trap_object *trapobj, size_t trapobjlen,
	   unsigned int tick, u_char sptrap)
{
  unsigned int i;
  u_char buf[BUFSIZ];
  u_char *ptr;
  size_t len, length;
  struct in_addr addr;
  unsigned long val;
  u_char *h1, *h1e;

  ptr = buf;
  len = BUFSIZ;
  length = len;

  /* When SMUX connection is not established. */
  if (smux_sock < 0)
    return 0;

  /* SMUX header. */
  ptr = asn_build_header (ptr, &len, (u_char) SMUX_TRAP, 0);

  /* Sub agent enterprise oid. */
  ptr = asn_build_objid (ptr, &len,
			 (u_char) 
			 (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID),
			 smux_oid, smux_oid_len);

  /* IP address. */
  addr.s_addr = 0;
  ptr = asn_build_string (ptr, &len, 
			  (u_char)
			  (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_IPADDRESS),
			  (u_char *)&addr, sizeof (addr));

  /* Generic trap integer. */
  val = SNMP_TRAP_ENTERPRISESPECIFIC;
  ptr = asn_build_int (ptr, &len, 
		       (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
		       &val, sizeof (val));

  /* Specific trap integer. */
  val = sptrap;
  ptr = asn_build_int (ptr, &len, 
		       (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
		       &val, sizeof (val));

  /* Timeticks timestamp. */
  val = 0;
  ptr = asn_build_unsigned_int (ptr, &len, 
				(u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_TIMETICKS),
				&val, sizeof (val));
  
  /* Variables. */
  h1 = ptr;
  ptr = asn_build_sequence (ptr, &len, 
			    (u_char) (ASN_SEQUENCE | ASN_CONSTRUCTOR),
			    0);


  /* Iteration for each objects. */
  h1e = ptr;
  for (i = 0; i < trapobjlen; i++)
    {
      int ret;
      oid oid[MAX_OID_LEN];
      size_t oid_len;
      void *val;
      size_t val_len;
      u_char val_type;

      /* Make OID. */
      if (trapobj[i].namelen > 0) 
        {
          oid_copy (oid, name, namelen);
          oid_copy (oid + namelen, trapobj[i].name, trapobj[i].namelen);
          oid_copy (oid + namelen + trapobj[i].namelen, iname, inamelen);
          oid_len = namelen + trapobj[i].namelen + inamelen;
        }
      else 
        {
          oid_copy (oid, name, namelen);
          oid_copy (oid + namelen, trapobj[i].name, trapobj[i].namelen * (-1));
          oid_len = namelen + trapobj[i].namelen * (-1) ;
        }

      if (debug_smux) 
        {
          smux_oid_dump ("Trap", name, namelen);
          if (trapobj[i].namelen < 0)
            smux_oid_dump ("Trap", 
                           trapobj[i].name, (- 1) * (trapobj[i].namelen));
          else 
            {
              smux_oid_dump ("Trap", trapobj[i].name, (trapobj[i].namelen));
              smux_oid_dump ("Trap", iname, inamelen);
            }
          smux_oid_dump ("Trap", oid, oid_len);
          zlog_info ("BUFSIZ: %d // oid_len: %d", BUFSIZ, oid_len);
      }

      ret = smux_get (oid, &oid_len, 1, &val_type, &val, &val_len);

      if (debug_smux)
	zlog_debug ("smux_get result %d", ret);

      if (ret == 0)
	ptr = snmp_build_var_op (ptr, oid, &oid_len,
				 val_type, val_len, val, &len);
    }

  /* Now variable size is known, fill in size */
  asn_build_sequence(h1, &length,
		     (u_char) (ASN_SEQUENCE | ASN_CONSTRUCTOR),
		     ptr - h1e);

  /* Fill in size of whole sequence */
  len = BUFSIZ;
  asn_build_header (buf, &len, (u_char) SMUX_TRAP, (ptr - buf) - 2);

  return send (smux_sock, buf, (ptr - buf), 0);
}
コード例 #6
0
ファイル: smux.c プロジェクト: Quagga/people-jcollie
int
smux_getnext (oid *reqid, size_t *reqid_len, int exact, 
	      u_char *val_type,void **val, size_t *val_len)
{
  int j;
  oid save[MAX_OID_LEN];
  int savelen = 0;
  struct subtree *subtree;
  struct variable *v;
  int subresult;
  oid *suffix;
  size_t suffix_len;
  int result;
  WriteMethod *write_method=NULL;
  struct listnode *node, *nnode;


  /* Save incoming request. */
  oid_copy (save, reqid, *reqid_len);
  savelen = *reqid_len;

  /* Check */
  for (ALL_LIST_ELEMENTS (treelist, node, nnode, subtree))
    {
      subresult = oid_compare_part (reqid, *reqid_len, 
				    subtree->name, subtree->name_len);

      /* If request is in the tree. The agent has to make sure we
         only receive requests we have registered for. */
      /* Unfortunately, that's not true. In fact, a SMUX subagent has to
         behave as if it manages the whole SNMP MIB tree itself. It's the
         duty of the master agent to collect the best answer and return it
         to the manager. See RFC 1227 chapter 3.1.6 for the glory details
         :-). ucd-snmp really behaves bad here as it actually might ask
         multiple times for the same GETNEXT request as it throws away the
         answer when it expects it in a different subtree and might come
         back later with the very same request. --jochen */

      if (subresult <= 0)
	{
	  /* Prepare suffix. */
	  suffix = reqid + subtree->name_len;
	  suffix_len = *reqid_len - subtree->name_len;
	  if (subresult < 0)
	    {
	      oid_copy(reqid, subtree->name, subtree->name_len);
	      *reqid_len = subtree->name_len;
	    }
	  for (j = 0; j < subtree->variables_num; j++)
	    {
	      result = subresult;
	      v = &subtree->variables[j];

	      /* Next then check result >= 0. */
	      if (result == 0)
		result = oid_compare_part (suffix, suffix_len,
					   v->name, v->namelen);

	      if (result <= 0)
		{
		  if (debug_smux)
		    zlog_debug ("SMUX function call index is %d", v->magic);
		  if(result<0)
		    {
		      oid_copy(suffix, v->name, v->namelen);
		      suffix_len = v->namelen;
		    }
		  *val = (*v->findVar) (v, suffix, &suffix_len, exact,
					val_len, &write_method);
		  *reqid_len = suffix_len + subtree->name_len;
		  if (*val)
		    {
		      *val_type = v->type;
		      return 0;
		    }
		}
	    }
	}
    }
  memcpy (reqid, save, savelen * sizeof(oid));
  *reqid_len = savelen;

  return SNMP_ERR_NOSUCHNAME;
}
コード例 #7
0
int 
get_ilo_oid_list (struct snmp_session *session, oid *target_oid, 
		  size_t target_oid_len, char **error_ptr)
{
  int status;
  int running = TRUE;
  oid cur_oid[MAX_OID_LEN];
  size_t cur_oid_len;

  struct snmp_pdu *pdu_ptr, *response_ptr;
  netsnmp_variable_list	*var_list,*var_list_prev=NULL;
  struct ilo_oid_list *oid_list;

  struct ilo_snmp_priv *priv_ptr = container_of(error_ptr, 
						struct ilo_snmp_priv, err_str);

  if (priv_ptr == NULL) 
    {
      ILO_ERR_DEBUG(error_ptr, "priv_ptr is NULL!\n");
      return NAGIOS_ILO_FAIL_STATUS;
    }

  oid_copy(cur_oid, &cur_oid_len, target_oid, target_oid_len);

  while (running) 
    {
      pdu_ptr = snmp_pdu_create(SNMP_MSG_GETBULK);

      /* Max-repetitions: Tell get-bulk to attemp up to 'errindex' 
	   get-next operations to get the remaining objects.  */
      pdu_ptr->errindex = SNMP_GETBULK_ERRINDEX;

      /* Non-repeater.  */
      pdu_ptr->errstat = 0;

      snmp_add_null_var(pdu_ptr, cur_oid, cur_oid_len);

      status = snmp_synch_response(session, pdu_ptr, &response_ptr);
 
      if (status == STAT_SUCCESS && response_ptr->errstat == SNMP_ERR_NOERROR) 
	{

	  var_list = var_list_prev =response_ptr->variables;
		
	  /* Add each element of the netsnmp variable list to 
	     struct ilo_oid_list.  */
	  while (var_list) 
	    {
	      if (netsnmp_oid_is_subtree(target_oid, 
	  				 target_oid_len,
					 var_list->name, 
					 var_list->name_length) != 0) 
		{
		  running = FALSE;
		  break;
		}
		
	      oid_list = alloc_oid_list(var_list, error_ptr);
			  
	      if (oid_list == NULL) 
		{
		  ILO_ERR_DEBUG(error_ptr, "oid_list is NULL!\n");
		  return NAGIOS_ILO_FAIL_STATUS;
		}

	      oid_list_add(&priv_ptr->oid_list, oid_list);
	      var_list_prev = var_list;
	      var_list = var_list->next_variable;
	    }
	    var_list=var_list_prev;

	  if ((var_list->type == SNMP_ENDOFMIBVIEW) ||
	      (var_list->type == SNMP_NOSUCHOBJECT) ||
	      (var_list->type == SNMP_NOSUCHINSTANCE)) 
	    {
	      running = FALSE;
	    } 
	  else 
	    {
		oid_copy(cur_oid, &cur_oid_len, var_list->name,var_list->name_length);
	    }
	} 
      else 
	{ /* Cannot get the response */
	  if (status == STAT_SUCCESS) 
	    {
	      ILO_ERR_DEBUG(error_ptr, "Cannot get the response: %s\n",
			    snmp_errstring(response_ptr->errstat));
	    } 
	  else 
	    {
	      snmp_error(session, &session->s_errno, &session->s_snmp_errno, 
		 	 error_ptr);
	    }

	   return NAGIOS_ILO_FAIL_STATUS;

	}
	  
      if (response_ptr)
	snmp_free_pdu(response_ptr);	

    }

  return NAGIOS_ILO_SUCCESS_STATUS;
}
コード例 #8
0
ファイル: mid.c プロジェクト: brnrc/ion-dtn
mid_t *mid_construct(uint8_t type, uint8_t cat,
		             uvast *issuer, uvast *tag, oid_t *oid)
{
	mid_t *mid = NULL;
	DTNMP_DEBUG_ENTRY("mid_construct","(%#llx, %#llx, %#llx, %#llx, %#llx",
			         type, cat,
			         (unsigned long) issuer, (unsigned long) tag,
			         (unsigned long) oid);


	/* Step 0: Sanity Check */
	if(oid == NULL)
	{
		DTNMP_DEBUG_ERR("mid_construct","Bad Args.", NULL);
		DTNMP_DEBUG_EXIT("mid_construct","->NULL",NULL);
		return NULL;
	}

	/* Step 1: Allocate the MID. */
	if((mid = (mid_t *)MTAKE(sizeof(mid_t))) == NULL)
	{
		DTNMP_DEBUG_ERR("mid_construct","Can't allocate %d bytes.",
				        sizeof(mid_t));
		DTNMP_DEBUG_EXIT("mid_construct","->NULL",NULL);
		return NULL;
	}

	/* Step 2: Populate the MID. */

	/* Flag */
	mid->flags =  (oid->type & 0x03) << 6;
	mid->flags |= (tag != NULL) ? 0x20 : 0x00;
	mid->flags |= (issuer != NULL) ? 0x10 : 0x00;
	mid->flags |= (cat & 0x03) << 2;
	mid->flags |= (type & 0x03);

	/* Shallow copies */
	mid->type     = type;
	mid->category = cat;
	mid->issuer   = (issuer != NULL) ? *issuer : 0;
	mid->tag      = (tag != NULL) ? *tag : 0;

	if((mid->oid = oid_copy(oid)) == NULL)
	{
		DTNMP_DEBUG_ERR("mid_construct","Failed to copy OID.",NULL);

		MRELEASE(mid);
		DTNMP_DEBUG_EXIT("mid_construct","->NULL",NULL);
		return NULL;
	}

	/* Step 3: Build the serialized MID. */
	if (mid_internal_serialize(mid) == 0)
	{
		DTNMP_DEBUG_ERR("mid_construct","Failed to serialize MID.",NULL);

		mid_release(mid);

		DTNMP_DEBUG_EXIT("mid_construct","->NULL",NULL);
		return NULL;
	}


	DTNMP_DEBUG_EXIT("mid_construct","->0x%x",(unsigned long)mid);
	return mid;
}
コード例 #9
0
/*
 * Find an object in the MIB that is the lexicographical successor of the given one.
 */
mib_object_t* mib_get_next(varbind_t* req)
{
    int cmp;
    u16t oid_len;
    
    mib_iterator_init();
    while (!mib_iterator_is_end()) {
        // find the object
        cmp = oid_cmp(req->oid_ptr, ptr->varbind.oid_ptr);
        oid_len = oid_length(ptr->varbind.oid_ptr);

        if (!GET_NEXT_OID_PTR) {
            // handle a scalar object
            if (cmp < 0 || (cmp == 0 && req->oid_ptr->len < oid_len)) {
                #if ENABLE_MIB_TABLE || ENABLE_PROGMEM
                    oid_copy(req->oid_ptr, ptr->varbind.oid_ptr, 0);
                    CHECK_PTR_U(req->oid_ptr->ptr);
                #else
                    req->oid_ptr.len = ptr->varbind.oid_ptr.len;
                    req->oid_ptr.ptr = ptr->varbind.oid_ptr.ptr;
                #endif
                break;
            }
        } else {
            #if ENABLE_MIB_TABLE
            /* handle a tabular object */
            if (cmp < 0 || cmp == 0) {
                ptr_t* table_oid_ptr;
                if ((table_oid_ptr = (ptr->get_next_oid_fnc_ptr)(ptr, (cmp < 0 ? 0 : &req->oid_ptr->ptr[oid_len]),
                        cmp < 0 ? 0 : req->oid_ptr->len - oid_len)) != 0) {
                    /* copy the mib object's oid */
                    oid_copy(req->oid_ptr, ptr->varbind.oid_ptr, oid_len + table_oid_ptr->len);
                    CHECK_PTR_U(req->oid_ptr->ptr);
                    memcpy(&req->oid_ptr->ptr[oid_len], table_oid_ptr->ptr, table_oid_ptr->len);
                    req->oid_ptr->len += table_oid_ptr->len;

                    free(table_oid_ptr->ptr);
                    oid_free(table_oid_ptr);
                    break;                    
                }
            }
            #endif
        }
        mib_iterator_next();
    }

    if (mib_iterator_is_end()) {
        req->value_type = BER_TYPE_END_OF_MIB;
        snmp_log("mib does not contain next object\n");
        return 0;
    }

    if (ptr->get_fnc_ptr) {
        if ((ptr->get_fnc_ptr)(ptr, &req->oid_ptr->ptr[oid_len],
                                    req->oid_ptr->len - oid_len) == -1) {
            snmp_log("can not get the value of the object\n");
            return 0;
        }
    }

    /* copy the value */
    memcpy(&req->value, &ptr->varbind.value, sizeof(varbind_value_t));
    req->value_type = ptr->varbind.value_type;
    return ptr;
}