Esempio n. 1
0
static struct inet6_dev * ipv6_add_dev(struct device *dev)
{
	struct inet6_dev *ndev, **bptr, *iter;
	int hash;

	if (dev->mtu < IPV6_MIN_MTU)
		return NULL;

	ndev = kmalloc(sizeof(struct inet6_dev), GFP_KERNEL);

	if (ndev) {
		char name[64];
		memset(ndev, 0, sizeof(struct inet6_dev));

		ndev->dev = dev;
		memcpy(&ndev->cnf, &ipv6_devconf_dflt, sizeof(ndev->cnf));
		ndev->cnf.mtu6 = dev->mtu;
		ndev->cnf.sysctl = NULL;
		ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
		if (ndev->nd_parms == NULL) {
			kfree(ndev);
			return NULL;
		}

		ipv6_statistics.Ip6LastChange = timeticks(jiffies);
		ndev->stats.ipv6.Ip6LastChange = timeticks(jiffies);

#ifdef CONFIG_PROC_FS
		sprintf(name, "%d", dev->ifindex);
		ndev->stats.proc_dir_entry = create_proc_entry(name, 0, proc_net_devsnmp6);
		if (!ndev->stats.proc_dir_entry)
			printk(KERN_WARNING
				"addrconf_notify(): cannot create /proc/net/dev_snmp6/%s\n",name);
		ndev->stats.proc_dir_entry->read_proc = afinet6_read_devsnmp;
		ndev->stats.proc_dir_entry->data = ndev;
#endif

#ifdef CONFIG_SYSCTL
		neigh_sysctl_register(dev, ndev->nd_parms, NET_IPV6, NET_IPV6_NEIGH, "ipv6");
		addrconf_sysctl_register(ndev, &ndev->cnf);
#endif
		hash = ipv6_devindex_hash(dev->ifindex);
		bptr = &inet6_dev_lst[hash];
		iter = *bptr;

		for (; iter; iter = iter->next)
			bptr = &iter->next;

		*bptr = ndev;

	}
	return ndev;
}
Esempio n. 2
0
int wpdu::restore_vbs(Pdu& pdu, const snmp_pdu *raw_pdu) const
{
   Vb tempvb;
   Oid tempoid;
   struct variable_list *vp;

   for(vp = raw_pdu->variables; vp; vp = vp->next_variable) {

    // extract the oid portion
    tempoid.set_data( (unsigned long *)vp->name,
                       ( unsigned int) vp->name_length);
    tempvb.set_oid( tempoid);

    // extract the value portion
    switch(vp->type) {

    // octet string
    case sNMP_SYNTAX_OCTETS:
     case sNMP_SYNTAX_OPAQUE:
    {
       OctetStr octets( (char *) vp->val.string,
                         (long) vp->val_len);
       tempvb.set_value( octets);
    }
    break;

    // object id
    case sNMP_SYNTAX_OID:
    {
         Oid oid( (unsigned long*) vp->val.objid,
              (int) vp->val_len);
      tempvb.set_value( oid);
    }
     break;

    // timeticks
    case sNMP_SYNTAX_TIMETICKS:
    {
       TimeTicks timeticks( (unsigned long) *(vp->val.integer));
       tempvb.set_value( timeticks);
    }
    break;

    // Gauge32
    case sNMP_SYNTAX_GAUGE32:
    {
       Gauge32 gauge32( (unsigned long) *(vp->val.integer));
       tempvb.set_value( gauge32);
    }
    break;

    // 32 bit counter
    case sNMP_SYNTAX_CNTR32:
    {
        Counter32 counter32( (unsigned long) *(vp->val.integer));
       tempvb.set_value( counter32);
      }
    break;

    // ip address
    case sNMP_SYNTAX_IPADDR:
    {
       char buffer[20];
       ACE_OS::sprintf( buffer,"%d.%d.%d.%d",
                        vp->val.string[0],
                        vp->val.string[1],
                        vp->val.string[2],
                        vp->val.string[3]);
       IpAddress ipaddress( buffer);
       tempvb.set_value( ipaddress);
    }
    break;

    // 32 bit integer
    case sNMP_SYNTAX_INT:
    {
       SnmpInt32 int32( (long) *(vp->val.integer));
      tempvb.set_value( int32);
    }
    break;

    // 32 bit unsigned integer
    case sNMP_SYNTAX_UINT32:
    {
      SnmpUInt32 uint32( (unsigned long) *(vp->val.integer));
      tempvb.set_value( uint32);
    }
     break;

    // v2 counter 64's
    case sNMP_SYNTAX_CNTR64:
     break;

    case sNMP_SYNTAX_NULL:
      tempvb.set_null();
    break;

    // v2 vb exceptions
    case sNMP_SYNTAX_NOSUCHOBJECT:
    case sNMP_SYNTAX_NOSUCHINSTANCE:
    case sNMP_SYNTAX_ENDOFMIBVIEW:
       set_exception_status( &tempvb, vp->type);
     break;

    default:
       tempvb.set_null();

    } // end switch

    // append the vb to the pdu
    pdu += tempvb;
  }

  return 0;
}
Esempio n. 3
0
/* Embedded code is not funny at all... */
int
mib_instance_search(struct oid_search_res *ret_oid)
{
  int i;
  Variable *var = &ret_oid->var;
  lua_State *L = mib_lua_state;

  /* Empty lua stack. */
  lua_pop(L, -1);
  /* Get function. */
  lua_rawgeti(L, LUA_ENVIRONINDEX, ret_oid->callback);
  /* op */
  lua_pushinteger(L, ret_oid->request);
  /* req_sub_oid */
  lua_newtable(L);
  for (i = 0; i < ret_oid->inst_id_len; i++) {
    lua_pushinteger(L, ret_oid->inst_id[i]);
    lua_rawseti(L, -2, i + 1);
  }

  if (ret_oid->request == MIB_REQ_SET) {
    /* req_val */
    switch (tag(var)) {
      case ASN1_TAG_INT:
        lua_pushinteger(L, integer(var));
        break;
      case ASN1_TAG_OCTSTR:
        lua_pushlstring(L, octstr(var), length(var));
        break;
      case ASN1_TAG_CNT:
        lua_pushnumber(L, count(var));
        break;
      case ASN1_TAG_IPADDR:
        lua_pushlstring(L, (char *)ipaddr(var), length(var));
        break;
      case ASN1_TAG_OBJID:
        lua_newtable(L);
        for (i = 0; i < length(var); i++) {
          lua_pushnumber(L, oid(var)[i]);
          lua_rawseti(L, -2, i + 1);
        }
        break;
      case ASN1_TAG_GAU:
        lua_pushnumber(L, gauge(var));
        break;
      case ASN1_TAG_TIMETICKS:
        lua_pushnumber(L, timeticks(var));
        break;
      default:
        lua_pushnil(L);
        break;
    }
    /* req_val_type */
    lua_pushinteger(L, tag(var));
  } else {
    /* req_val */
    lua_pushnil(L);
    /* req_val_type */
    lua_pushnil(L);
  }

  if (lua_pcall(L, 4, 4, 0) != 0) {
    SMARTSNMP_LOG(L_ERROR, "MIB search hander %d fail: %s\n", ret_oid->callback, lua_tostring(L, -1));
    tag(var) = ASN1_TAG_NO_SUCH_OBJ;
    return 0;
  }

  ret_oid->err_stat = lua_tointeger(L, -4);
  tag(var) = lua_tonumber(L, -1);

  if (!ret_oid->err_stat && MIB_TAG_VALID(tag(var))) {
    /* Return value */
    if (ret_oid->request != MIB_REQ_SET) {
      switch (tag(var)) {
        case ASN1_TAG_INT:
          length(var) = 1;
          integer(var) = lua_tointeger(L, -2);
          break;
        case ASN1_TAG_OCTSTR:
          length(var) = lua_objlen(L, -2);
          memcpy(octstr(var), lua_tostring(L, -2), length(var));
          break;
        case ASN1_TAG_CNT:
          length(var) = 1;
          count(var) = lua_tonumber(L, -2);
          break;
        case ASN1_TAG_IPADDR:
          length(var) = lua_objlen(L, -2);
          for (i = 0; i < length(var); i++) {
            lua_rawgeti(L, -2, i + 1);
            ipaddr(var)[i] = lua_tointeger(L, -1);
            lua_pop(L, 1);
          }
          break;
        case ASN1_TAG_OBJID:
          length(var) = lua_objlen(L, -2);
          for (i = 0; i < length(var); i++) {
            lua_rawgeti(L, -2, i + 1);
            oid(var)[i] = lua_tointeger(L, -1);
            lua_pop(L, 1);
          }
          break;
        case ASN1_TAG_GAU:
          length(var) = 1;
          gauge(var) = lua_tonumber(L, -2);
          break;
        case ASN1_TAG_TIMETICKS:
          length(var) = 1;
          timeticks(var) = lua_tonumber(L, -2);
          break;
        default:
          assert(0);
      }
    }

    /* For GETNEXT request, return the new oid */
    if (ret_oid->request == MIB_REQ_GETNEXT) {
      ret_oid->inst_id_len = lua_objlen(L, -3);
      for (i = 0; i < ret_oid->inst_id_len; i++) {
        lua_rawgeti(L, -3, i + 1);
        ret_oid->inst_id[i] = lua_tointeger(L, -1);
        lua_pop(L, 1);
      }
    }
  }

  return ret_oid->err_stat;
}
Esempio n. 4
0
// unload the data into SNMP++ objects
int SnmpMessage::unload(Pdu &pdu,                 // Pdu object
			OctetStr &community,      // community object
			snmp_version &version,    // SNMP version #
                        OctetStr *engine_id,      // optional v3
                        OctetStr *security_name,  // optional v3
                        long int *security_model,
                        UdpAddress *from_addr,
                        Snmp *snmp_session)
{
  pdu.clear();

  if (!valid_flag)
    return SNMP_CLASS_INVALID;

  snmp_pdu *raw_pdu;
  raw_pdu = snmp_pdu_create(0); // do a "snmp_free_pdu( raw_pdu)" before return

  int status;

#ifdef _SNMPv3
  OctetStr context_engine_id;
  OctetStr context_name;
  long int security_level = SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV;

  if ((security_model) && (security_name) && (engine_id) && (snmp_session)) {
    status = v3MP::I->snmp_parse(snmp_session, raw_pdu,
                         databuff, (int)bufflen, *engine_id,
                         *security_name, context_engine_id, context_name,
                         security_level, *security_model, version, *from_addr);
    if (status != SNMPv3_MP_OK) {
      pdu.set_request_id( raw_pdu->reqid);
      pdu.set_type( raw_pdu->command);
      snmp_free_pdu( raw_pdu);
      return status;
    }
    pdu.set_context_engine_id(context_engine_id);
    pdu.set_context_name(context_name);
    pdu.set_security_level(security_level);
    pdu.set_message_id(raw_pdu->msgid);
    pdu.set_maxsize_scopedpdu(raw_pdu->maxsize_scopedpdu);
  }
  else {
#endif
    unsigned char community_name[MAX_LEN_COMMUNITY + 1];
    int           community_len = MAX_LEN_COMMUNITY + 1;

    status = snmp_parse(raw_pdu, databuff, (int) bufflen,
                        community_name, community_len, version);
    if (status != SNMP_CLASS_SUCCESS) {
      snmp_free_pdu(raw_pdu);
      return status;
    }
    community.set_data( community_name, community_len);

#ifdef _SNMPv3
  }
#endif
  // load up the SNMP++ variables
  pdu.set_request_id(raw_pdu->reqid);
  pdu.set_error_status((int) raw_pdu->errstat);
  pdu.set_error_index((int) raw_pdu->errindex);
  pdu.set_type( raw_pdu->command);

  // deal with traps a little different
  if ( raw_pdu->command == sNMP_PDU_V1TRAP) {
    // timestamp
    TimeTicks timestamp;
    timestamp = raw_pdu->time;
    pdu.set_notify_timestamp( timestamp);

    // set the agent address
    IpAddress agent_addr(inet_ntoa(raw_pdu->agent_addr.sin_addr));
    if (agent_addr != "0.0.0.0")
    {
      pdu.set_v1_trap_address(agent_addr);

      LOG_BEGIN(DEBUG_LOG | 4);
      LOG("SNMPMessage: Trap address of received v1 trap");
      LOG(agent_addr.get_printable());
      LOG_END;
    }

    // set enterprise, notifyid
    Oid enterprise;

    if (raw_pdu->enterprise_length >0) {
      for (int i=0; i< raw_pdu->enterprise_length; i++) {
        enterprise += (int) (raw_pdu->enterprise[i]);
      }
      pdu.set_notify_enterprise(enterprise);
    }
    switch (raw_pdu->trap_type) {
    case 0:
      pdu.set_notify_id(coldStart);
      break;

    case 1:
      pdu.set_notify_id(warmStart);
      break;

    case 2:
      pdu.set_notify_id(linkDown);
      break;

    case 3:
      pdu.set_notify_id(linkUp);
      break;

    case 4:
      pdu.set_notify_id(authenticationFailure);
      break;

    case 5:
      pdu.set_notify_id(egpNeighborLoss);
      break;

    case 6: { // enterprise specific
      // base id + specific #
      Oid eOid = enterprise;
      eOid += 0ul;
      eOid += raw_pdu->specific_type;
      pdu.set_notify_id( eOid);
      break;
      }
    default:
      {
	LOG_BEGIN(WARNING_LOG | 3);
	LOG("SNMPMessage: Received trap with illegal trap type");
	LOG(raw_pdu->trap_type);
	LOG_END;
      }
    }
  }

  // vbs
  Vb tempvb;
  Oid tempoid;
  struct   variable_list *vp;
  int vb_nr = 1;

  for(vp = raw_pdu->variables; vp; vp = vp->next_variable, vb_nr++) {

    // extract the oid portion
    tempoid.set_data( (unsigned long *)vp->name,
                      ( unsigned int) vp->name_length);
    tempvb.set_oid( tempoid);

    // extract the value portion
    switch(vp->type){

      // octet string
    case sNMP_SYNTAX_OCTETS:
      {
	OctetStr octets( (unsigned char *) vp->val.string,
			 (unsigned long) vp->val_len);
	tempvb.set_value( octets);
      }
      break;
    case sNMP_SYNTAX_OPAQUE:
      {
	OpaqueStr octets( (unsigned char *) vp->val.string,
		          (unsigned long) vp->val_len);
	tempvb.set_value( octets);
      }
      break;

      // object id
    case sNMP_SYNTAX_OID:
      {
	Oid oid( (unsigned long*) vp->val.objid,
		 (int) vp->val_len);
	tempvb.set_value( oid);
        if ((vb_nr == 2) &&
            ((raw_pdu->command == sNMP_PDU_TRAP) ||
             (raw_pdu->command == sNMP_PDU_INFORM)) &&
            (tempoid == SNMP_MSG_OID_TRAPID))
        {
          // set notify_id
          pdu.set_notify_id(oid);
	  continue; // don't add vb to pdu
        }
      }
      break;

      // timeticks
    case sNMP_SYNTAX_TIMETICKS:
      {
	TimeTicks timeticks( (unsigned long) *(vp->val.integer));
	tempvb.set_value( timeticks);
        if ((vb_nr == 1) &&
            ((raw_pdu->command == sNMP_PDU_TRAP) ||
             (raw_pdu->command == sNMP_PDU_INFORM)) &&
            (tempoid == SNMP_MSG_OID_SYSUPTIME))
        {
          // set notify_timestamp
          pdu.set_notify_timestamp( timeticks);
	  continue; // don't add vb to pdu
        }
      }
      break;

      // 32 bit counter
    case sNMP_SYNTAX_CNTR32:
      {
	Counter32 counter32( (unsigned long) *(vp->val.integer));
	tempvb.set_value( counter32);
      }
      break;

      // 32 bit gauge
    case sNMP_SYNTAX_GAUGE32:
      {
	Gauge32 gauge32( (unsigned long) *(vp->val.integer));
	tempvb.set_value( gauge32);
      }
      break;

      // ip address
    case sNMP_SYNTAX_IPADDR:
      {
	char buffer[42];

	if (vp->val_len == 16)
	  sprintf( buffer, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
		   "%02x%02x:%02x%02x:%02x%02x:%02x%02x",
		   vp->val.string[ 0], vp->val.string[ 1], vp->val.string[ 2],
		   vp->val.string[ 3], vp->val.string[ 4], vp->val.string[ 5],
		   vp->val.string[ 6], vp->val.string[ 7], vp->val.string[ 8],
		   vp->val.string[ 9], vp->val.string[10], vp->val.string[11],
		   vp->val.string[12], vp->val.string[13], vp->val.string[14],
		   vp->val.string[15]);
	else
	  sprintf( buffer,"%d.%d.%d.%d",
		   vp->val.string[0], vp->val.string[1],
		   vp->val.string[2], vp->val.string[3]);
	IpAddress ipaddress( buffer);
	tempvb.set_value( ipaddress);
      }
      break;

      // 32 bit integer
    case sNMP_SYNTAX_INT:
      {
	SnmpInt32 int32( (long) *(vp->val.integer));
	tempvb.set_value( int32);
      }
      break;

      // 32 bit unsigned integer
/* Not distinguishable from Gauge32
    case sNMP_SYNTAX_UINT32:
      {
	SnmpUInt32 uint32( (unsigned long) *(vp->val.integer));
	tempvb.set_value( uint32);
      }
      break;
*/
      // v2 counter 64's
    case sNMP_SYNTAX_CNTR64:
      { // Frank Fock (was empty before)
	Counter64 c64(((counter64*)vp->val.counter64)->high,
		      ((counter64*)vp->val.counter64)->low);
	tempvb.set_value( c64);
	break;
      }
    case sNMP_SYNTAX_NULL:
	    tempvb.set_null();
	    break;
	
	    // v2 vb exceptions
    case sNMP_SYNTAX_NOSUCHOBJECT:
    case sNMP_SYNTAX_NOSUCHINSTANCE:
    case sNMP_SYNTAX_ENDOFMIBVIEW:
      tempvb.set_exception_status(vp->type);
      break;

    default:
      tempvb.set_null();

    } // end switch

    // append the vb to the pdu
    pdu += tempvb;
  }

  snmp_free_pdu( raw_pdu);

  return SNMP_CLASS_SUCCESS;
}
Esempio n. 5
0
void creatures::animate()
{
	ui::frame* f;
	int ml = get(LastValid);
	unsigned tm = (unsigned)timeticks();
	for(int mid = FirstCreature; mid<=ml; mid++)
	{
		if(creatures::get(mid, AnimationStop)>0)
		{
			creatures::set(mid, AnimationStop, creatures::get(mid, AnimationStop) - 1);
			continue;
		}
		res::token rs = (res::token)creatures::get(mid, Frame);
		int ac = creatures::get(mid, AnimationCicle);
		int fr = creatures::get(mid, AnimationFrame);
		int dr = creatures::get(mid, Direction);
		int fc = res::gframes(rs, ac) / 6;
		int x1 = creatures::get(mid, PositionX);
		int y1 = creatures::get(mid, PositionY);
		int p2, p3, x3, y3;
		switch(creatures::get(mid, Action))
		{
		case ActionWalk:
			if((hot::frame%2)==0)
				break;
		case ActionRun:
			f = ui::gframe(rs, ac, dr*fc + fr);
			x1 += f->mx; y1 += f->my;
			creatures::set(mid, PositionX, x1);
			creatures::set(mid, PositionY, y1);
			p3 = creatures::get(mid, Position);
			x3 = map::h2x(p3);
			y3 = map::h2y(p3);
			p2 = creatures::get(mid, Order);
			if(iabs(x3-x1)<=6 && iabs(y3-y1)<=6)
			{
				if(p2==p3)
				{
					creatures::set(mid, Action, ActionStand);
					creatures::set(mid, Position, p3);
					break;
				}
				else
					creatures::set(mid, Direction, map::d2o(map::direction(p3, p2)));
			}
			creatures::set(mid, AnimationFrame, (++fr)%fc);
			break;
		case ActionStand:
			if((hot::frame%2)==0)
				break;
			if(++fr>=fc)
			{
				creatures::set(mid, AnimationFrame, 0);
				creatures::set(mid, AnimationStop, (1+(xrand()%8))*12);
			}
			else
				creatures::set(mid, AnimationFrame, fr);
			break;
		}
	}
}