Example #1
0
//-----------------------------------------------------------------------------
// learn routing table TODO what about the best route?
void learn_route_table(CnetAddr address, int hops, int link, int mtu,
                       CnetTime total_delay, uint16_t req_id) {
    if (route_exists(address) == FALSE) {
        int t = find_address(address);
        route_table[t].minhops = hops;
        route_table[t].minhop_link = link;
        route_table[t].min_mtu = mtu;
        route_table[t].total_delay = total_delay;
        route_table[t].req_id = req_id;
        routes[address] = 1;
    } else {
        if (route_notified[address]==0) {
            int t = find_address(address);
            if ((log((double)(route_table[t].minhops))*route_table[t].total_delay)
                    >(log((double)(hops))*total_delay)) {
                route_table[t].minhops = hops;
                route_table[t].minhop_link = link;
                route_table[t].min_mtu = mtu;
                route_table[t].total_delay = total_delay;
                route_table[t].req_id = req_id;

            }
        }
    }
}
static void
nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
                 socklen_t addrlen)
{
  struct Plugin *plugin = cls;
  struct IPv4HttpAddressWrapper *w_t4 = NULL;
  struct IPv6HttpAddressWrapper *w_t6 = NULL;
  int af;

  af = addr->sa_family;
  switch (af)
  {
  case AF_INET:
    w_t4 = find_address (plugin, addr, addrlen);
    if (w_t4 == NULL)
    {
      struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
      w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
      memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr));
      w_t4->addr.u4_port = a4->sin_port;

      GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
                                   plugin->ipv4_addr_tail, w_t4);

    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                     "Notifying transport to add IPv4 address `%s'\n",
                     http_plugin_address_to_string (NULL, &w_t4->addr,
                                                    sizeof (struct
                                                            IPv4HttpAddress)));
    plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
                                 sizeof (struct IPv4HttpAddress));
    }
    break;
  case AF_INET6:
    w_t6 = find_address (plugin, addr, addrlen);
    if (w_t6 == NULL)
    {
      w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
      struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
      memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr));
      w_t6->addr6.u6_port = a6->sin6_port;

      GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
                                   plugin->ipv6_addr_tail, w_t6);

      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                     "Notifying transport to add IPv6 address `%s'\n",
                     http_plugin_address_to_string (NULL, &w_t6->addr6,
                                                    sizeof (struct
                                                            IPv6HttpAddress)));
      plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
                                 sizeof (struct IPv6HttpAddress));
    }
    break;
  default:
    return;
  }

}
static void
nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
                    socklen_t addrlen)
{
  struct Plugin *plugin = cls;
  struct IPv4HttpAddressWrapper *w_t4 = NULL;
  struct IPv6HttpAddressWrapper *w_t6 = NULL;
  int af;

  af = addr->sa_family;
  switch (af)
  {
  case AF_INET:
    w_t4 = find_address (plugin, addr, addrlen);
    if (w_t4 == NULL)
      return;


    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                     "Notifying transport to remove IPv4 address `%s'\n",
                     http_plugin_address_to_string (NULL, &w_t4->addr,
                                                    sizeof (struct
                                                            IPv4HttpAddress)));
    plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
                                 sizeof (struct IPv4HttpAddress));

    GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, plugin->ipv4_addr_tail,
                                 w_t4);
    GNUNET_free (w_t4);
    break;
  case AF_INET6:
    w_t6 = find_address (plugin, addr, addrlen);
    if (w_t6 == NULL)
      return;

    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                     "Notifying transport to remove IPv6 address `%s'\n",
                     http_plugin_address_to_string (NULL, &w_t6->addr6,
                                                    sizeof (struct
                                                            IPv6HttpAddress)));

    plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
                                 sizeof (struct IPv6HttpAddress));

    GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
                                 w_t6);
    GNUNET_free (w_t6);
    break;
  default:
    return;
  }
}
static struct ATS_Address *
lookup_address (const struct GNUNET_PeerIdentity *peer,
                const char *plugin_name, const void *plugin_addr,
                size_t plugin_addr_len, uint32_t session_id,
                const struct GNUNET_ATS_Information *atsi,
                uint32_t atsi_count)
{
  struct ATS_Address *aa;
  struct ATS_Address *old;

  aa = create_address (peer,
                       plugin_name,
                       plugin_addr, plugin_addr_len,
                       session_id);

  aa->mlp_information = NULL;
  aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information));
  aa->ats_count = atsi_count;
  memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_ATS_Information));

  /* Get existing address or address with session == 0 */
  old = find_address (peer, aa);
  free_address (aa);
  if (old == NULL)
  {
    return NULL;
  }
  else if (old->session_id != session_id)
  {
    return NULL;
  }
  return old;
}
Example #5
0
//-----------------------------------------------------------------------------
// get a propagation delay on the way to destaddr
int get_propagation_delay(CnetAddr destaddr) {
    if (route_exists(destaddr)) {
        int t = find_address(destaddr);
        return route_table[t].total_delay;
    } else
        return -1;
}
QImage t_address_finder:: find_photo(t_user *user_config, const t_url &u) {
	mtx_finder.lock();
	find_address(user_config, u);
	QImage photo = last_photo;
	mtx_finder.unlock();
	return photo;
}
Example #7
0
//-----------------------------------------------------------------------------
// find a request id of a discovered route
int get_request_id_for_dest(CnetAddr dest) {
    if (route_exists(dest)) {
        int t = find_address(dest);
        return route_table[t].req_id;
    } else
        abort();
}
Example #8
0
/* Implement the pager_write_page callback from the pager library.  See
   <hurd/pager.h> for the interface description. */
error_t
pager_write_page (struct user_pager_info *pager,
		  vm_offset_t page,
		  vm_address_t buf)
{
  daddr_t addr;
  int disksize;
  struct rwlock *nplock;
  error_t err;

  err = find_address (pager, page, &addr, &disksize, &nplock, 0);
  if (err)
    return err;

  if (addr)
    {
      size_t wrote;
      err = store_write (store, addr << log2_dev_blocks_per_dev_bsize,
			 (void *)buf, disksize, &wrote);
      if (wrote != disksize)
	err = EIO;
    }
  else
    err = 0;

  if (nplock)
    rwlock_reader_unlock (nplock);

  return err;
}
Example #9
0
void update_last_packet(NL_PACKET *last) {
        int index = find_address(last->dest);
        //NL_PACKET * lastsend = &(NL_table[index].lastpacket);

        memcpy(&(NL_table[index].lastpacket), last, PACKET_SIZE((*last)));
        //free(temp);
}
Example #10
0
string t_address_finder::find_name(t_user *user_config, const t_url &u) {
	mtx_finder.lock();
	find_address(user_config, u);
	string name = last_name;
	mtx_finder.unlock();
	return name;
}
Example #11
0
std::unique_ptr<proto::Bip44Address> Blockchain::LoadAddress(
    const Identifier& nymID,
    const Identifier& accountID,
    const std::uint32_t index,
    const BIP44Chain chain) const
{
    LOCK_ACCOUNT()

    std::unique_ptr<proto::Bip44Address> output{};
    const std::string sNymID = nymID.str();
    const std::string sAccountID = accountID.str();
    auto account = load_account(accountLock, sNymID, sAccountID);

    if (false == bool(account)) {
        otErr << OT_METHOD << __FUNCTION__ << ": Account does not exist."
              << std::endl;

        return output;
    }

    const auto allocatedIndex =
        chain ? account->internalindex() : account->externalindex();

    if (index > allocatedIndex) {
        otErr << OT_METHOD << __FUNCTION__
              << ": Address has not been allocated." << std::endl;

        return output;
    }

    auto& address = find_address(index, chain, *account);
    output.reset(new proto::Bip44Address(address));

    return output;
}
Example #12
0
void NL_savehopcount(CnetAddr address, int hops, int link) {
	int t = find_address(address);

	if (NL_table[t].minhops > hops) {
		NL_table[t].minhops = hops;
		NL_table[t].minhop_link = link;
		given_stats = true;
	}
}
Example #13
0
static void NL_stats(CnetAddr address, int hops, int link, CnetInt64 usec)
{
    int	t;

    t = find_address(address);
    if(table[t].minhops >= hops) {
        table[t].minhops	= hops;
        table[t].minhop_link	= link;
    }
    int64_ADD(table[t].totaltime, table[t].totaltime, usec);
}
Example #14
0
/* ptr points to a return address, and does not have to be word-aligned. */
static bool PointsToValidCall( const void *ptr )
{
	const char *buf = (char *) ptr;

	/* We're reading buf backwards, between buf[-7] and buf[-1].  Find out how
	 * far we can read. */
	int len = 7;
	while( len )
	{
		int val = find_address( buf-len, g_ReadableBegin, g_ReadableEnd );
		if( val != -1 )
			break;
		--len;
	}

	// Permissible CALL sequences that we care about:
	//
	//	E8 xx xx xx xx			CALL near relative
	//	FF (group 2)			CALL near absolute indirect
	//
	// Minimum sequence is 2 bytes (call eax).
	// Maximum sequence is 7 bytes (call dword ptr [eax+disp32]).

	if (len >= 5 && buf[-5] == '\xe8')
		return true;

	// FF 14 xx					CALL [reg32+reg32*scale]
	if (len >= 3 && buf[-3] == '\xff' && buf[-2]=='\x14')
		return true;

	// FF 15 xx xx xx xx		CALL disp32
	if (len >= 6 && buf[-6] == '\xff' && buf[-5]=='\x15')
		return true;

	// FF 00-3F(!14/15)			CALL [reg32]
	if (len >= 2 && buf[-2] == '\xff' && (unsigned char)buf[-1] < '\x40')
		return true;

	// FF D0-D7					CALL reg32
	if (len >= 2 && buf[-2] == '\xff' && char(buf[-1]&0xF8) == '\xd0')
		return true;

	// FF 50-57 xx				CALL [reg32+reg32*scale+disp8]
	if (len >= 3 && buf[-3] == '\xff' && char(buf[-2]&0xF8) == '\x50')
		return true;

	// FF 90-97 xx xx xx xx xx	CALL [reg32+reg32*scale+disp32]
	if (len >= 7 && buf[-7] == '\xff' && char(buf[-6]&0xF8) == '\x90')
		return true;

	return false;
}
Example #15
0
//-----------------------------------------------------------------------------
// detect fragmentation size for the specified destination
int get_mtu(CnetAddr address, int need_send_mtu_request) {
    if (address!=nodeinfo.address) {
        if (route_exists(address) == 1) {
            int t = find_address(address);
            return route_table[t].min_mtu - PACKET_HEADER_SIZE - DATAGRAM_HEADER_SIZE - DL_FRAME_HEADER_SIZE;
        } else {
            if (need_send_mtu_request==TRUE)
                send_route_request(address);
            return -1;
        }
    } else
        return -1;
}
Example #16
0
int main(int argc, char **argv)
{
	prog_name = argv[0];
	
	if (argc > 2 && argv[1][0] == '-' && argv[1][1] == 'c')
		return child(atoi(argv[2]));
	
	printf("===============================\n");
	printf("=          Mempodipper        =\n");
	printf("=           by zx2c4          =\n");
	printf("=         Jan 21, 2012        =\n");
	printf("===============================\n\n");
	
	if (argc > 2 && argv[1][0] == '-' && argv[1][1] == 'o')
		return parent(strtoul(argv[2], NULL, 16));
	else
		return parent(find_address());
	
}
Example #17
0
/* Implement the pager_read_page callback from the pager library.  See
   <hurd/pager.h> for the interface description. */
error_t
pager_read_page (struct user_pager_info *pager,
		 vm_offset_t page,
		 vm_address_t *buf,
		 int *writelock)
{
  error_t err;
  struct rwlock *nplock;
  daddr_t addr;
  int disksize;

  err = find_address (pager, page, &addr, &disksize, &nplock, 1);
  if (err)
    return err;

  if (addr)
    {
      size_t read = 0;
      err = store_read (store, addr << log2_dev_blocks_per_dev_bsize,
			disksize, (void **)buf, &read);
      if (read != disksize)
	err = EIO;
      if (!err && disksize != __vm_page_size)
	bzero ((void *)(*buf + disksize), __vm_page_size - disksize);
      *writelock = 0;
    }
  else
    {
#if 0
      printf ("Write-locked pagein Object %#x\tOffset %#x\n", pager, page);
      fflush (stdout);
#endif
      *buf = (vm_address_t) mmap (0, vm_page_size, PROT_READ|PROT_WRITE,
				  MAP_ANON, 0, 0);
      *writelock = 1;
    }

  if (nplock)
    rwlock_reader_unlock (nplock);

  return err;
}
Example #18
0
/** Determines if specified bytes are in the extent map.  If every byte of the specified extent is defined by the extent map,
 *  then this function returns true, otherwise false. */
bool
ExtentMap::exists_all(ExtentPair what) const
{
    while (what.second>0) {
        try {
            ExtentPair found = find_address(what.first);
            assert(found.second > 0);
            assert(found.first <= what.first);
            assert(what.first <= found.first + found.second);
            rose_addr_t nfound = std::min(what.second, found.second-(what.first-found.first));
            what.first = found.first + found.second;
            what.second -= nfound;
        } catch (const std::bad_alloc&) { // thrown by find_address()
            assert(!ranges.contains(RangeType(what.first, what.second)));
            return false;
        }
    }
    assert(ranges.contains(RangeType(what.first, what.second)));
    return true;
}
Example #19
0
File: mail.c Project: avkrotov/fdm
char *
make_from(struct mail *m, char *user)
{
	time_t	t;
	char   *s, *from = NULL;
	size_t	fromlen = 0;

	from = find_header(m, "from", &fromlen, 1);
	if (from != NULL && fromlen > 0)
		from = find_address(from, fromlen, &fromlen);
	if (fromlen > INT_MAX)
		from = NULL;
	if (from == NULL) {
		from = user;
		fromlen = strlen(from);
	}

	t = time(NULL);
	xasprintf(&s, "From %.*s %.24s", (int) fromlen, from, ctime(&t));
	return (s);
}
Example #20
0
static int
find_address (rtx *address_of_x)
{
  rtx x = *address_of_x;
  enum rtx_code code = GET_CODE (x);
  const char *const fmt = GET_RTX_FORMAT (code);
  int i;
  int value = 0;
  int tem;

  if (code == MEM && rtx_equal_p (XEXP (x, 0), inc_insn.reg_res))
    {
      /* Match with *reg0.  */
      mem_insn.mem_loc = address_of_x;
      mem_insn.reg0 = inc_insn.reg_res;
      mem_insn.reg1_is_const = true;
      mem_insn.reg1_val = 0;
      mem_insn.reg1 = GEN_INT (0);
      return -1;
    }
  if (code == MEM && GET_CODE (XEXP (x, 0)) == PLUS
      && rtx_equal_p (XEXP (XEXP (x, 0), 0), inc_insn.reg_res))
    {
      rtx b = XEXP (XEXP (x, 0), 1);
      mem_insn.mem_loc = address_of_x;
      mem_insn.reg0 = inc_insn.reg_res;
      mem_insn.reg1 = b;
      mem_insn.reg1_is_const = inc_insn.reg1_is_const;
      if (CONST_INT_P (b))
	{
	  /* Match with *(reg0 + reg1) where reg1 is a const. */
	  HOST_WIDE_INT val = INTVAL (b);
	  if (inc_insn.reg1_is_const
	      && (inc_insn.reg1_val == val || inc_insn.reg1_val == -val))
	    {
	      mem_insn.reg1_val = val;
	      return -1;
	    }
	}
      else if (!inc_insn.reg1_is_const
	       && rtx_equal_p (inc_insn.reg1, b))
	/* Match with *(reg0 + reg1). */
	return -1;
    }

  if (code == SIGN_EXTRACT || code == ZERO_EXTRACT)
    {
      /* If REG occurs inside a MEM used in a bit-field reference,
	 that is unacceptable.  */
      if (find_address (&XEXP (x, 0)))
	return 1;
    }

  if (x == inc_insn.reg_res)
    return 1;

  /* Time for some deep diving.  */
  for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    {
      if (fmt[i] == 'e')
	{
	  tem = find_address (&XEXP (x, i));
	  /* If this is the first use, let it go so the rest of the
	     insn can be checked.  */
	  if (value == 0)
	    value = tem;
	  else if (tem != 0)
	    /* More than one match was found.  */
	    return 1;
	}
      else if (fmt[i] == 'E')
	{
	  int j;
	  for (j = XVECLEN (x, i) - 1; j >= 0; j--)
	    {
	      tem = find_address (&XVECEXP (x, i, j));
	      /* If this is the first use, let it go so the rest of
		 the insn can be checked.  */
	      if (value == 0)
		value = tem;
	      else if (tem != 0)
		/* More than one match was found.  */
		return 1;
	    }
	}
    }
  return value;
}
Example #21
0
static void
merge_in_block (int max_reg, basic_block bb)
{
  rtx insn;
  rtx curr;
  int success_in_block = 0;

  if (dump_file)
    fprintf (dump_file, "\n\nstarting bb %d\n", bb->index);

  FOR_BB_INSNS_REVERSE_SAFE (bb, insn, curr)
    {
      unsigned int uid = INSN_UID (insn);
      bool insn_is_add_or_inc = true;

      if (!NONDEBUG_INSN_P (insn))
	continue;

      /* This continue is deliberate.  We do not want the uses of the
	 jump put into reg_next_use because it is not considered safe to
	 combine a preincrement with a jump.  */
      if (JUMP_P (insn))
	continue;

      if (dump_file)
	dump_insn_slim (dump_file, insn);

      /* Does this instruction increment or decrement a register?  */
      if (parse_add_or_inc (insn, true))
	{
	  int regno = REGNO (inc_insn.reg_res);
	  /* Cannot handle case where there are three separate regs
	     before a mem ref.  Too many moves would be needed to be
	     profitable.  */
	  if ((inc_insn.form == FORM_PRE_INC) || inc_insn.reg1_is_const)
	    {
	      mem_insn.insn = get_next_ref (regno, bb, reg_next_use);
	      if (mem_insn.insn)
		{
		  bool ok = true;
		  if (!inc_insn.reg1_is_const)
		    {
		      /* We are only here if we are going to try a
			 HAVE_*_MODIFY_REG type transformation.  c is a
			 reg and we must sure that the path from the
			 inc_insn to the mem_insn.insn is both def and use
			 clear of c because the inc insn is going to move
			 into the mem_insn.insn.  */
		      int luid = DF_INSN_LUID (mem_insn.insn);
		      rtx other_insn
			= get_next_ref (REGNO (inc_insn.reg1), bb, reg_next_use);

		      if (other_insn && luid > DF_INSN_LUID (other_insn))
			ok = false;

		      other_insn
			= get_next_ref (REGNO (inc_insn.reg1), bb, reg_next_def);

		      if (other_insn && luid > DF_INSN_LUID (other_insn))
			ok = false;
		    }

		  if (dump_file)
		    dump_inc_insn (dump_file);

		  if (ok && find_address (&PATTERN (mem_insn.insn)) == -1)
		    {
		      if (dump_file)
			dump_mem_insn (dump_file);
		      if (try_merge ())
			{
			  success_in_block++;
			  insn_is_add_or_inc = false;
			}
		    }
		}
	    }
	}
      else
	{
	  insn_is_add_or_inc = false;
	  mem_insn.insn = insn;
	  if (find_mem (&PATTERN (insn)))
	    success_in_block++;
	}

      /* If the inc insn was merged with a mem, the inc insn is gone
	 and there is noting to update.  */
      if (DF_INSN_UID_GET (uid))
	{
	  df_ref *def_rec;
	  df_ref *use_rec;
	  /* Need to update next use.  */
	  for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
	    {
	      df_ref def = *def_rec;
	      reg_next_use[DF_REF_REGNO (def)] = NULL;
	      reg_next_inc_use[DF_REF_REGNO (def)] = NULL;
	      reg_next_def[DF_REF_REGNO (def)] = insn;
	    }

	  for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
	    {
	      df_ref use = *use_rec;
	      reg_next_use[DF_REF_REGNO (use)] = insn;
	      if (insn_is_add_or_inc)
		reg_next_inc_use[DF_REF_REGNO (use)] = insn;
	      else
		reg_next_inc_use[DF_REF_REGNO (use)] = NULL;
	    }
	}
      else if (dump_file)
	fprintf (dump_file, "skipping update of deleted insn %d\n", uid);
    }
Example #22
0
/* send a DHCP OFFER to a DHCP DISCOVER */
int sendOffer(struct dhcpMessage *oldpacket)
{
#ifdef DHCPD_HEAP_REPLACE_STACK
	struct dhcpMessage *packet;
#else
	struct dhcpMessage packet;
#endif
	struct dhcpOfferedAddr *lease = NULL;
	u_int32_t req_align, lease_time_align = server_config.lease;
	unsigned char *req, *lease_time;
	struct option_set *curr;
	//struct in_addr addr;

#ifdef DHCPD_HEAP_REPLACE_STACK
	packet = calloc(1,sizeof(struct dhcpMessage));
	if (!packet) {
		DHCPD_LOG(LOG_ERR, "Calloc failed...%d",__LINE__);
		return -1;
	}
	init_packet(packet, oldpacket, DHCPOFFER);
#else
	init_packet(&packet, oldpacket, DHCPOFFER);
#endif

	/* ADDME: if static, short circuit */
	/* the client is in our lease/offered table */
	if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) {
		if (!lease_expired(lease))
			lease_time_align = lease->expires - time(0);
#ifdef DHCPD_HEAP_REPLACE_STACK
		packet->yiaddr = lease->yiaddr;
#else
		packet.yiaddr = lease->yiaddr;
#endif
	/* Or the client has a requested ip */
	} else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) &&

		   /* Don't look here (ugly hackish thing to do) */
		   memcpy(&req_align, req, 4) &&

		   /* and the ip is in the lease range */
		   ntohl(req_align) >= ntohl(server_config.start) &&
		   ntohl(req_align) <= ntohl(server_config.end) &&

		   /* and its not already taken/offered */ /* ADDME: check that its not a static lease */
		   ((!(lease = find_lease_by_yiaddr(req_align)) ||

		   /* or its taken, but expired */ /* ADDME: or maybe in here */
		   lease_expired(lease)))) {
#ifdef DHCPD_HEAP_REPLACE_STACK
				packet->yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */
#else
				packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */
#endif

	/* otherwise, find a free IP */ /*ADDME: is it a static lease? */
	} else {
#ifdef DHCPD_HEAP_REPLACE_STACK
		packet->yiaddr = find_address(0);
		/* try for an expired lease */
		if (!packet->yiaddr) packet->yiaddr = find_address(1);
#else
		packet.yiaddr = find_address(0);

		/* try for an expired lease */
		if (!packet.yiaddr) packet.yiaddr = find_address(1);
#endif
	}
#ifdef DHCPD_HEAP_REPLACE_STACK
	if(!(packet->yiaddr)) {
		if (packet != NULL)
			free(packet);

#else
	if(!packet.yiaddr) {
#endif
		DHCPD_LOG(LOG_WARNING, "no IP addresses to give -- OFFER abandoned");
		return -1;
	}
#ifdef DHCPD_HEAP_REPLACE_STACK
	if (!add_lease(packet->chaddr, packet->yiaddr, server_config.offer_time)) {
		if (packet != NULL) {
			free(packet);
			packet = NULL;
		}
#else
	if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
#endif
		DHCPD_LOG(LOG_WARNING, "lease pool is full -- OFFER abandoned");
		return -1;
	}

	if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) {
		memcpy(&lease_time_align, lease_time, 4);
		lease_time_align = ntohl(lease_time_align);
		if (lease_time_align > server_config.lease)
			lease_time_align = server_config.lease;
	}

	/* Make sure we aren't just using the lease time from the previous offer */
	if (lease_time_align < server_config.min_lease)
		lease_time_align = server_config.lease;
	/* ADDME: end of short circuit */
#ifdef DHCPD_HEAP_REPLACE_STACK
	struct netif *netif = netif_find(server_config.interface);

	add_simple_option(packet->options, DHCP_LEASE_TIME, htonl(lease_time_align));
#ifdef __CONFIG_LWIP_V1
	add_simple_option(packet->options, DHCP_SUBNET, ip4_addr_get_u32(&netif->netmask));
	add_simple_option(packet->options, DHCP_ROUTER, ip4_addr_get_u32(&netif->gw));
	add_simple_option(packet->options, DHCP_DNS_SERVER, ip4_addr_get_u32(&netif->ip_addr));
#elif LWIP_IPV4 /* now only for IPv4 */
	add_simple_option(packet->options, DHCP_SUBNET, ip4_addr_get_u32(ip_2_ip4(&netif->netmask)));
	add_simple_option(packet->options, DHCP_ROUTER, ip4_addr_get_u32(ip_2_ip4(&netif->gw)));
	add_simple_option(packet->options, DHCP_DNS_SERVER, ip4_addr_get_u32(ip_2_ip4(&netif->ip_addr)));
#else
	#error "IPv4 not support!"
#endif

#else
	add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align));
#endif

	curr = server_config.options;
	while (curr) {
		if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
#ifdef DHCPD_HEAP_REPLACE_STACK
			add_option_string(packet->options, curr->data);
#else
			add_option_string(packet.options, curr->data);
#endif
		curr = curr->next;
	}
#ifdef DHCPD_HEAP_REPLACE_STACK
	add_bootp_options(packet);

	//addr.s_addr = packet->yiaddr;
	DHCPD_LOG(LOG_INFO, "sending OFFER of %s", inet_ntoa(packet->yiaddr));
	int ret = send_packet(packet, 0);
	if (packet != NULL) {
		free(packet);
		packet = NULL;
	}
	return ret;
#else
	add_bootp_options(&packet);

	addr.s_addr = packet.yiaddr;
	DHCPD_LOG(LOG_INFO, "sending OFFER of %s", inet_ntoa(addr));
	return send_packet(&packet, 0);
#endif
}


int sendNAK(struct dhcpMessage *oldpacket)
{
#ifdef DHCPD_HEAP_REPLACE_STACK
	struct dhcpMessage *packet;
#else
	struct dhcpMessage packet;
#endif
#ifdef DHCPD_HEAP_REPLACE_STACK
	packet = calloc(1,sizeof(struct dhcpMessage));
	if (!packet)
		DHCPD_LOG(LOG_ERR, "Calloc failed...%d",__LINE__);
	init_packet(packet, oldpacket, DHCPNAK);
#else
	init_packet(&packet, oldpacket, DHCPNAK);
#endif

	DEBUG(LOG_INFO, "sending NAK");
#ifdef DHCPD_HEAP_REPLACE_STACK
	int ret = send_packet(packet, 1);
	if (packet != NULL)
		free(packet);
	return ret;
#else
	return send_packet(&packet, 1);
#endif
}


int sendACK(struct dhcpMessage *oldpacket, u_int32_t yiaddr)
{
#ifdef DHCPD_HEAP_REPLACE_STACK
	struct dhcpMessage *packet;
#else
	struct dhcpMessage packet;
#endif
	struct option_set *curr;
	unsigned char *lease_time;
	u_int32_t lease_time_align = server_config.lease;
	//struct in_addr addr;

#ifdef DHCPD_HEAP_REPLACE_STACK
	packet = calloc(1,sizeof(struct dhcpMessage));
	if (!packet)
		DHCPD_LOG(LOG_ERR, "Calloc failed...%d",__LINE__);
	init_packet(packet, oldpacket, DHCPACK);
	packet->yiaddr = yiaddr;
#else
	init_packet(&packet, oldpacket, DHCPACK);

	packet.yiaddr = yiaddr;
#endif

	if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) {
		memcpy(&lease_time_align, lease_time, 4);
		lease_time_align = ntohl(lease_time_align);
		if (lease_time_align > server_config.lease)
			lease_time_align = server_config.lease;
		else if (lease_time_align < server_config.min_lease)
			lease_time_align = server_config.lease;
	}
#ifdef DHCPD_HEAP_REPLACE_STACK
	struct netif *netif = netif_find(server_config.interface);

	add_simple_option(packet->options, DHCP_LEASE_TIME, htonl(lease_time_align));
#ifdef __CONFIG_LWIP_V1
	add_simple_option(packet->options, DHCP_SUBNET, ip4_addr_get_u32(&netif->netmask));
	add_simple_option(packet->options, DHCP_ROUTER, ip4_addr_get_u32(&netif->gw));
	add_simple_option(packet->options, DHCP_DNS_SERVER, ip4_addr_get_u32(&netif->ip_addr));
#elif LWIP_IPV4 /* now only for IPv4 */
	add_simple_option(packet->options, DHCP_SUBNET, ip4_addr_get_u32(ip_2_ip4(&netif->netmask)));
	add_simple_option(packet->options, DHCP_ROUTER, ip4_addr_get_u32(ip_2_ip4(&netif->gw)));
	add_simple_option(packet->options, DHCP_DNS_SERVER, ip4_addr_get_u32(ip_2_ip4(&netif->ip_addr)));
#else
	#error "IPv4 not support!"
#endif

#else
	add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align));
#endif
	curr = server_config.options;
	while (curr) {
		if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
#ifdef DHCPD_HEAP_REPLACE_STACK
			add_option_string(packet->options, curr->data);
#else
			add_option_string(packet.options, curr->data);
#endif
		curr = curr->next;
	}
#ifdef DHCPD_HEAP_REPLACE_STACK
	add_bootp_options(packet);

	//addr.s_addr = packet->yiaddr;
	DHCPD_LOG(LOG_INFO, "sending ACK to %s", inet_ntoa(packet->yiaddr));
	int ret = 0;
	if (send_packet(packet, 0) < 0)
		ret = -1;

	add_lease(packet->chaddr, packet->yiaddr, lease_time_align);

	if (packet)
		free(packet);
	return ret;
#else
	add_bootp_options(&packet);

	//addr.s_addr = packet.yiaddr;
	DHCPD_LOG(LOG_INFO, "sending ACK to %s", inet_ntoa(packet->yiaddr));

	if (send_packet(&packet, 0) < 0)
		return -1;

	add_lease(packet.chaddr, packet.yiaddr, lease_time_align);
	return 0;
#endif
}


int send_inform(struct dhcpMessage *oldpacket)
{
#ifdef DHCPD_HEAP_REPLACE_STACK
	struct dhcpMessage *packet;
#else
	struct dhcpMessage packet;
#endif
	struct option_set *curr;
#ifdef DHCPD_HEAP_REPLACE_STACK
	packet = calloc(1,sizeof(struct dhcpMessage));
	if (!packet)
		DHCPD_LOG(LOG_ERR, "Calloc failed...%d",__LINE__);
	init_packet(packet, oldpacket, DHCPACK);
#else
	init_packet(&packet, oldpacket, DHCPACK);
#endif

	curr = server_config.options;
	while (curr) {
		if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
#ifdef DHCPD_HEAP_REPLACE_STACK
			add_option_string(packet->options, curr->data);
#else
			add_option_string(packet.options, curr->data);
#endif
		curr = curr->next;
	}
#ifdef DHCPD_HEAP_REPLACE_STACK
	add_bootp_options(packet);

	int ret = send_packet(packet, 0);
	if (packet)
		free(packet);
	return ret;
#else
	add_bootp_options(&packet);

	return send_packet(&packet, 0);
#endif
}
Example #23
0
static void NL_update_lastackexpected(CnetAddr address) {
	NL_table[find_address(address)].last_ack_expected = NL_table[find_address(
			address)].ackexpected;
}
Example #24
0
/* Return true if the given pointer is in executable memory. */
bool IsExecutableAddress( const void *p )
{
	int val = find_address( p, g_ExecutableBegin, g_ExecutableEnd );
	return val != -1;
}
Example #25
0
/* Return true if the given pointer is in readable memory, and on the stack. */
bool IsOnStack( const void *p )
{
	int val = find_address( p, g_ReadableBegin, g_ReadableEnd );
	return val != -1 && (val == g_StackBlock1 || val == g_StackBlock2 );
}
Example #26
0
/* send a DHCP OFFER to a DHCP DISCOVER */
int sendOffer(struct dhcpMessage *oldpacket)
{
        struct dhcpMessage packet;
        struct dhcpOfferedAddr *lease = NULL;
        u_int32_t req_align, lease_time_align = cur_iface->lease;
        char *req, *lease_time;
        struct option_set *curr;
        struct in_addr addr;
	//For static IP lease
	uint32_t static_lease_ip;

        //brcm begin
        char VIinfo[VENDOR_IDENTIFYING_INFO_LEN];
        //brcm end

        init_packet(&packet, oldpacket, DHCPOFFER);
        
	//For static IP lease
	static_lease_ip = getIpByMac(cur_iface->static_leases,
		oldpacket->chaddr);

	if(!static_lease_ip) {
        	/* the client is in our lease/offered table */
        	if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) {
                	if (!lease_expired(lease)) 
                        	lease_time_align = lease->expires - time(0);
                	packet.yiaddr = lease->yiaddr;
        	/* Or the client has a requested ip */
        	} else if ((req = (char *)get_option(oldpacket, DHCP_REQUESTED_IP)) &&

			/* Don't look here (ugly hackish thing to do) */
			memcpy(&req_align, req, 4) && 

			/* and the ip is in the lease range */
			ntohl(req_align) >= ntohl(cur_iface->start) &&
			ntohl(req_align) <= ntohl(cur_iface->end) && 

			/* and its not already taken/offered */
			((!(lease = find_lease_by_yiaddr(req_align)) ||

			/* or its taken, but expired */
			lease_expired(lease)))) {
				packet.yiaddr = req_align; 

		/* otherwise, find a free IP */
        	} else {
                	packet.yiaddr = find_address(0);
                
                	/* try for an expired lease */
			if (!packet.yiaddr) packet.yiaddr = find_address(1);
        	}
        
        	if(!packet.yiaddr) {
                	LOG(LOG_WARNING, "no IP addresses to give -- "
				"OFFER abandoned");
                	return -1;
        	}
        
        	if (!add_lease(packet.chaddr, packet.yiaddr,
			server_config.offer_time)) {
                	LOG(LOG_WARNING, "lease pool is full -- "
				"OFFER abandoned");
                	return -1;
        	}               

        	if ((lease_time = (char *)get_option(oldpacket, DHCP_LEASE_TIME))) {
                	memcpy(&lease_time_align, lease_time, 4);
                	lease_time_align = ntohl(lease_time_align);
                	if (lease_time_align > cur_iface->lease) 
                        	lease_time_align = cur_iface->lease;
        	}

        	/* Make sure we aren't just using the lease time from the
		 * previous offer */
        	if (lease_time_align < server_config.min_lease) 
                	lease_time_align = cur_iface->lease;

//<< jojopo : wifi leasetime 300 seconds , 2015/12/25
         if(isHostFromWireless(packet.chaddr))
            lease_time_align = 300;
//>> jojopo : end
	} else {
		/* It is a static lease... use it */
		packet.yiaddr = static_lease_ip;
	}
                
        add_simple_option(packet.options, DHCP_LEASE_TIME, lease_time_align);

        curr = cur_iface->options;
        while (curr) {
                if (curr->data[OPT_CODE] != DHCP_LEASE_TIME)
                        add_option_string(packet.options, curr->data);
                curr = curr->next;
        }

        add_bootp_options(&packet);

        //brcm begin
        /* if DHCPDISCOVER from client has device identity, send back gateway identity */
        if ((req = (char *)get_option(oldpacket, DHCP_VENDOR_IDENTIFYING))) {
          if (createVIoption(VENDOR_IDENTIFYING_FOR_GATEWAY, VIinfo) != -1)
            add_option_string(packet.options, (unsigned char *)VIinfo);
        }
        //brcm end

        addr.s_addr = packet.yiaddr;
        LOG(LOG_INFO, "sending OFFER of %s", inet_ntoa(addr));
        return send_packet(&packet, 0);
}
void
GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
                      const char *plugin_name, const void *plugin_addr,
                      size_t plugin_addr_len, uint32_t session_id,
                      const struct GNUNET_ATS_Information *atsi,
                      uint32_t atsi_count)
{
  struct ATS_Address *aa;
  struct ATS_Address *old;
  uint32_t i;

  if (GNUNET_NO == running)
    return;

  GNUNET_assert (NULL != addresses);

  aa = create_address (peer,
                       plugin_name,
                       plugin_addr, plugin_addr_len,
                       session_id);

  aa->mlp_information = NULL;
  aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information));
  aa->ats_count = atsi_count;
  memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_ATS_Information));

  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s' %u\n",
              GNUNET_i2s (peer),
              session_id);

  /* Get existing address or address with session == 0 */
  old = find_address (peer, aa);
  if (old == NULL)
  {
    GNUNET_assert (GNUNET_OK ==
                   GNUNET_CONTAINER_multihashmap_put (addresses,
                                                      &peer->hashPubKey, aa,
                                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
#if DEBUG_ATS
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' %X\n",
                GNUNET_i2s (peer), aa);
#endif
    old = aa;
  }
  else
  {
#if DEBUG_ATS
      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Updated existing address for peer `%s' %p old session %u new session %u\n",
                GNUNET_i2s (peer), old,
                old->session_id, session_id);
#endif
    GNUNET_free_non_null (old->ats);
    old->session_id = session_id;
    old->ats = NULL;
    old->ats_count = 0;
    old->ats = aa->ats;
    old->ats_count = aa->ats_count;
    GNUNET_free (aa->plugin);
    GNUNET_free (aa);
  }
  for (i = 0; i < atsi_count; i++)
    switch (ntohl (atsi[i].type))
    {
    case GNUNET_ATS_UTILIZATION_UP:
      old->atsp_utilization_out.value__ = atsi[i].value;
      break;
    case GNUNET_ATS_UTILIZATION_DOWN:
      old->atsp_utilization_in.value__ = atsi[i].value;
      break;
    case GNUNET_ATS_QUALITY_NET_DELAY:
      old->atsp_latency.rel_value = ntohl (atsi[i].value);
      break;
    case GNUNET_ATS_QUALITY_NET_DISTANCE:
      old->atsp_distance = ntohl (atsi[i].value);
      break;
    case GNUNET_ATS_COST_WAN:
      old->atsp_cost_wan = ntohl (atsi[i].value);
      break;
    case GNUNET_ATS_COST_LAN:
      old->atsp_cost_lan = ntohl (atsi[i].value);
      break;
    case GNUNET_ATS_COST_WLAN:
      old->atsp_cost_wlan = ntohl (atsi[i].value);
      break;
    case GNUNET_ATS_NETWORK_TYPE:
      old->atsp_network_type = ntohl (atsi[i].value);
      break;

    default:
      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                  "Received unsupported ATS type %u\n", ntohl (atsi[i].type));
      GNUNET_break (0);
      break;
    }
#if HAVE_LIBGLPK
  if (ats_mode == MLP)
    GAS_mlp_address_update (mlp, addresses, old);
#endif
}
Example #28
0
/* This x86 backtracer attempts to walk the stack frames.  If we come to a
 * place that doesn't look like a valid frame, we'll look forward and try
 * to find one again. */
static void do_backtrace( const void **buf, size_t size, const BacktraceContext *ctx )
{
	/* Read /proc/pid/maps to find the address range of the stack. */
	get_readable_ranges( g_ReadableBegin, g_ReadableEnd, 1024 );
	get_readable_ranges( g_ExecutableBegin, g_ExecutableEnd, 1024, READABLE_ONLY|EXECUTABLE_ONLY );

	/* Find the stack memory blocks. */
	g_StackBlock1 = find_address( ctx->sp, g_ReadableBegin, g_ReadableEnd );
	g_StackBlock2 = find_address( SavedStackPointer, g_ReadableBegin, g_ReadableEnd );

	/* Put eip at the top of the backtrace. */
	/* XXX: We want EIP even if it's not valid, but we can't put NULL on the
	 * list, since it's NULL-terminated.  Hmm. */
	unsigned i=0;
	if( i < size-1 && ctx->ip ) // -1 for NULL
		buf[i++] = ctx->ip;

	/* If we did a CALL to an invalid address (eg. call a NULL callback), then
	 * we won't have a stack frame for the function that called it (since the
	 * stack frame is set up by the called function), but if esp hasn't been
	 * changed after the CALL, the return address will be esp[0].  Grab it. */
	if( IsOnStack( ctx->sp ) )
	{
		const void *p = ((const void **) ctx->sp)[0];
		if( IsExecutableAddress( p ) && PointsToValidCall( p ) && i < size-1 ) // -1 for NULL
			buf[i++] = p;
	}

#if 0
	/* ebp is usually the frame pointer. */
	const StackFrame *frame = (StackFrame *) ctx->bp;

	/* If ebp doesn't point to a valid stack frame, we're probably in
	 * -fomit-frame-pointer code.  Ignore it; use esp instead.  It probably
	 * won't point to a stack frame, but it should at least give us a starting
	 * point in the stack. */
	if( !IsValidFrame( frame ) )
		frame = (StackFrame *) ctx->sp;
#endif

	/* Actually, let's just use esp.  Even if ebp points to a valid stack frame, there might be
	 * -fomit-frame-pointer calls in front of it, and we want to get those. */
	const StackFrame *frame = (StackFrame *) ctx->sp;

	while( i < size-1 ) // -1 for NULL
	{
		/* Make sure that this frame address is readable, and is on the stack. */
		if( !IsReadableFrame( frame ) )
			break;

		if( !IsValidFrame( frame ) )
		{
			/* We've lost the frame.  We might have crashed while in a call in -fomit-frame-pointer
			 * code.  Iterate through the stack word by word.  If a word is possibly a valid return
			 * address, record it.  This is important; if we don't do this, we'll lose too many
			 * stack frames at the top of the trace.  This can have false positives, and introduce
			 * garbage into the trace, but we should eventually find a real stack frame. */
			void **p = (void **) frame;
			if( IsExecutableAddress( *p ) && PointsToValidCall( *p ) )
				buf[i++] = *p;

			/* The frame pointer is invalid.  Just move forward one word. */
			frame = (StackFrame *) (((char *)frame)+4);
			continue;
		}

		/* Valid frame.  Store the return address, and hop forward. */
		buf[i++] = frame->return_address;
		frame = frame->link;
	}

	buf[i] = NULL;
}
Example #29
0
NL_PACKET * get_last_packet(CnetAddr address) {
        int index = find_address(address);
        return (NL_PACKET *) &(NL_table[index].lastpacket);
}
Example #30
0
bool Blockchain::StoreIncoming(
    const Identifier& nymID,
    const Identifier& accountID,
    const std::uint32_t index,
    const BIP44Chain chain,
    const proto::BlockchainTransaction& transaction) const
{
    LOCK_ACCOUNT()

    const std::string sNymID = nymID.str();
    const std::string sAccountID = accountID.str();
    auto account = load_account(accountLock, sNymID, sAccountID);

    if (false == bool(account)) {
        otErr << OT_METHOD << __FUNCTION__ << ": Account does not exist."
              << std::endl;

        return false;
    }

    const auto allocatedIndex =
        chain ? account->internalindex() : account->externalindex();

    if (index > allocatedIndex) {
        otErr << OT_METHOD << __FUNCTION__
              << ": Address has not been allocated." << std::endl;

        return false;
    }

    auto& address = find_address(index, chain, *account);
    bool exists = false;

    for (const auto& txid : address.incoming()) {
        if (txid == transaction.txid()) {
            exists = true;
            break;
        }
    }

    if (false == exists) { address.add_incoming(transaction.txid()); }

    auto saved = api_.Storage().Store(sNymID, account->type(), *account);

    if (false == saved) {
        otErr << OT_METHOD << __FUNCTION__ << ": Failed to save account."
              << std::endl;

        return false;
    }

    saved = api_.Storage().Store(transaction);

    if (false == saved) {
        otErr << OT_METHOD << __FUNCTION__ << ": Failed to save transaction."
              << std::endl;

        return false;
    }

    if (address.contact().empty()) { return true; }

    const auto contactID = Identifier::Factory(address.contact());

    return activity_.AddBlockchainTransaction(
        nymID, contactID, StorageBox::INCOMINGBLOCKCHAIN, transaction);
}