Пример #1
0
void
tcp_manager::doRPC_tcp_connect_cb (RPC_delay_args *args, int fd)
{

  hostinfo *hi = lookup_host (args->l->address ());
  if (fd < 0) {
    warn << "locationtable: connect failed: " << strerror (errno) << "\n";
    (args->cb) (RPC_CANTSEND);
    args->l->set_alive (false);
    remove_host (hi);
    delete args;
  }
  else {
    struct linger li;
    li.l_onoff = 1;
    li.l_linger = 0;
    setsockopt (fd, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof (li));
    tcp_nodelay (fd);
    make_async(fd);
    hi->fd = fd;
    hi->xp = axprt_stream::alloc (fd);
    assert (hi->xp);
    send_RPC (args);
    while (hi->connect_waiters.size ())
      send_RPC (hi->connect_waiters.pop_front ());
  }
}
Пример #2
0
// -----------------------------------------------------
long
tcp_manager::doRPC (ptr<location> from, ptr<location> l,
		    const rpc_program &prog, int procno, 
		    ptr<void> in, void *out, aclnt_cb cb,
		    cbtmo_t cb_tmo)
{
  // hack to avoid limit on wrap()'s number of arguments
  RPC_delay_args *args = New RPC_delay_args (from, l, prog, procno,
					     in, out, cb, NULL);
  if (chord_rpc_style == CHORD_RPC_SFSBT) {
    tcpconnect (l->saddr ().sin_addr, ntohs (l->saddr ().sin_port),
		wrap (this, &tcp_manager::doRPC_tcp_connect_cb, args));
  } else {
    hostinfo *hi = lookup_host (l->address ());
    if (hi->fd == -2) { //no connect initiated
      // weird: tcpconnect wants the address in NBO, and port in HBO
      hi->fd = -1; // signal pending connect
      tcpconnect (l->saddr ().sin_addr, ntohs (l->saddr ().sin_port),
		  wrap (this, &tcp_manager::doRPC_tcp_connect_cb, args));
    } else if (hi->fd == -1) { //connect pending, add to waiters
      hi->connect_waiters.push_back (args);
    } else if (hi->fd > 0) { //already connected
      send_RPC (args);
    }

  }
  return 0;
}
Пример #3
0
int
acc_is_present (void *h, size_t s)
{
  splay_tree_key n;

  if (!s || !h)
    return 0;

  goacc_lazy_initialize ();

  struct goacc_thread *thr = goacc_thread ();
  struct gomp_device_descr *acc_dev = thr->dev;

  if (thr->dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)
    return h != NULL;

  gomp_mutex_lock (&acc_dev->lock);

  n = lookup_host (acc_dev, h, s);

  if (n && ((uintptr_t)h < n->host_start
	    || (uintptr_t)h + s > n->host_end
	    || s > n->host_end - n->host_start))
    n = NULL;

  gomp_mutex_unlock (&acc_dev->lock);

  return n != NULL;
}
Пример #4
0
static void
update_dev_host (int is_dev, void *h, size_t s)
{
  splay_tree_key n;
  void *d;
  struct goacc_thread *thr = goacc_thread ();
  struct gomp_device_descr *acc_dev = thr->dev;

  gomp_mutex_lock (&acc_dev->lock);

  n = lookup_host (acc_dev, h, s);

  /* No need to call lazy open, as the data must already have been
     mapped.  */

  if (!n)
    {
      gomp_mutex_unlock (&acc_dev->lock);
      gomp_fatal ("[%p,%d] is not mapped", h, (int)s);
    }

  d = (void *) (n->tgt->tgt_start + n->tgt_offset);

  gomp_mutex_unlock (&acc_dev->lock);

  if (is_dev)
    acc_dev->host2dev_func (acc_dev->target_id, d, h, s);
  else
    acc_dev->dev2host_func (acc_dev->target_id, h, d, s);
}
Пример #5
0
void *
acc_deviceptr (void *h)
{
  splay_tree_key n;
  void *d;
  void *offset;

  goacc_lazy_initialize ();

  struct goacc_thread *thr = goacc_thread ();
  struct gomp_device_descr *dev = thr->dev;

  if (thr->dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)
    return h;

  gomp_mutex_lock (&dev->lock);

  n = lookup_host (dev, h, 1);

  if (!n)
    {
      gomp_mutex_unlock (&dev->lock);
      return NULL;
    }

  offset = h - n->host_start;

  d = n->tgt->tgt_start + n->tgt_offset + offset;

  gomp_mutex_unlock (&dev->lock);

  return d;
}
Пример #6
0
static void
update_dev_host (int is_dev, void *h, size_t s)
{
  splay_tree_key n;
  void *d;

  goacc_lazy_initialize ();

  struct goacc_thread *thr = goacc_thread ();
  struct gomp_device_descr *acc_dev = thr->dev;

  if (acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)
    return;

  gomp_mutex_lock (&acc_dev->lock);

  n = lookup_host (acc_dev, h, s);

  if (!n)
    {
      gomp_mutex_unlock (&acc_dev->lock);
      gomp_fatal ("[%p,%d] is not mapped", h, (int)s);
    }

  d = (void *) (n->tgt->tgt_start + n->tgt_offset
		+ (uintptr_t) h - n->host_start);

  if (is_dev)
    acc_dev->host2dev_func (acc_dev->target_id, d, h, s);
  else
    acc_dev->dev2host_func (acc_dev->target_id, h, d, s);

  gomp_mutex_unlock (&acc_dev->lock);
}
Пример #7
0
void
gomp_acc_remove_pointer (void *h, bool force_copyfrom, int async, int mapnum)
{
  struct goacc_thread *thr = goacc_thread ();
  struct gomp_device_descr *acc_dev = thr->dev;
  splay_tree_key n;
  struct target_mem_desc *t;
  int minrefs = (mapnum == 1) ? 2 : 3;

  gomp_mutex_lock (&acc_dev->lock);

  n = lookup_host (acc_dev, h, 1);

  if (!n)
    {
      gomp_mutex_unlock (&acc_dev->lock);
      gomp_fatal ("%p is not a mapped block", (void *)h);
    }

  gomp_debug (0, "  %s: restore mappings\n", __FUNCTION__);

  t = n->tgt;

  struct target_mem_desc *tp;

  if (t->refcount == minrefs)
    {
      /* This is the last reference, so pull the descriptor off the
	 chain. This avoids gomp_unmap_vars via gomp_unmap_tgt from
	 freeing the device memory. */
      t->tgt_end = 0;
      t->to_free = 0;

      for (tp = NULL, t = acc_dev->openacc.data_environ; t != NULL;
	   tp = t, t = t->prev)
	{
	  if (n->tgt == t)
	    {
	      if (tp)
		tp->prev = t->prev;
	      else
		acc_dev->openacc.data_environ = t->prev;
	      break;
	    }
	}
    }

  if (force_copyfrom)
    t->list[0].copy_from = 1;

  gomp_mutex_unlock (&acc_dev->lock);

  /* If running synchronously, unmap immediately.  */
  if (async < acc_async_noval)
    gomp_unmap_vars (t, true);
  else
    t->device_descr->openacc.register_async_cleanup_func (t, async);

  gomp_debug (0, "  %s: mappings restored\n", __FUNCTION__);
}
Пример #8
0
void
acc_unmap_data (void *h)
{
  struct goacc_thread *thr = goacc_thread ();
  struct gomp_device_descr *acc_dev = thr->dev;

  /* No need to call lazy open, as the address must have been mapped.  */

  size_t host_size;

  gomp_mutex_lock (&acc_dev->lock);

  splay_tree_key n = lookup_host (acc_dev, h, 1);
  struct target_mem_desc *t;

  if (!n)
    {
      gomp_mutex_unlock (&acc_dev->lock);
      gomp_fatal ("%p is not a mapped block", (void *)h);
    }

  host_size = n->host_end - n->host_start;

  if (n->host_start != (uintptr_t) h)
    {
      gomp_mutex_unlock (&acc_dev->lock);
      gomp_fatal ("[%p,%d] surrounds %p",
		  (void *) n->host_start, (int) host_size, (void *) h);
    }

  t = n->tgt;

  if (t->refcount == 2)
    {
      struct target_mem_desc *tp;

      /* This is the last reference, so pull the descriptor off the
         chain. This avoids gomp_unmap_vars via gomp_unmap_tgt from
         freeing the device memory. */
      t->tgt_end = 0;
      t->to_free = 0;

      for (tp = NULL, t = acc_dev->openacc.data_environ; t != NULL;
	   tp = t, t = t->prev)
	if (n->tgt == t)
	  {
	    if (tp)
	      tp->prev = t->prev;
	    else
	      acc_dev->openacc.data_environ = t->prev;

	    break;
	  }
    }

  gomp_mutex_unlock (&acc_dev->lock);

  gomp_unmap_vars (t, true);
}
Пример #9
0
extern char *host_to_ip(const char *host)
{
    struct hostent *hep = lookup_host(host);
    static char ip[256];

    return (hep ? sprintf(ip, "%u.%u.%u.%u", hep->h_addr[0] & 0xff,
			  hep->h_addr[1] & 0xff, hep->h_addr[2] & 0xff, hep->h_addr[3] & 0xff), ip : empty_str);
}
Пример #10
0
//debug only 
int print_lookup_host(const char *host)
{
    char *ip = malloc (100 * sizeof(char));
    lookup_host(host , ip ) ;
    debug1("%s: PRINT DEBUG: %s",ARGV0,ip);
    if (ip!=NULL) free(ip);
    return 0;
}
Пример #11
0
int call_spamc(FILE *tmp_msg, char *user, int maxsize) {
   struct message msg;
   FILE *tmp_sa_msg;
   int tmp_msg_fd;
   int err,flags,is_spam;
   struct sockaddr addr;

   tmp_msg_fd=fileno(tmp_msg);
   flags = SPAMC_RAW_MODE | SPAMC_SAFE_FALLBACK;
   
#if WITH_DEBUG == 1
       fprintf(stderr, "SpamAssassin Check\n");
#endif

   msg.max_len=maxsize;
   msg.type=MESSAGE_NONE;
   msg.raw=(char *)malloc(msg.max_len);
   
   err=lookup_host(SPAMD_HOST, SPAMD_PORT, &addr);
   if(err!=EX_OK) {
	   fprintf(stderr, "BARF on lookup_host (%d)\n",err);
	   return;
   }
   rewind(tmp_msg);
   err=message_read(tmp_msg_fd,SPAMC_RAW_MODE, &msg);
   if(err != EX_OK) {
	fprintf(stderr, "BARF on message_read (%d)\n",err);
	return;
   }
   err=message_filter(&addr, user, flags|SPAMC_CHECK_ONLY, &msg);
   if(err != EX_OK) {
	fprintf(stderr, "BARF on message_filter (%d)\n",err);
	return;
   }
   is_spam=msg.is_spam;
   /* 
    * We currently run the message through the filter twice.  Becuase
    * libspamc doesn't fill in all the msg structures w/o CHECK_ONLY
    * Until this is fixed or a better workaround comes up this is how
    * it is handled (one 'check only' and one real check)
    */
   rewind(tmp_msg);
   err=message_filter(&addr, user, flags, &msg);
   if(err != EX_OK) {
	fprintf(stderr, "BARF on message_filter (%d)\n",err);
	return;
   }
   rewind(tmp_msg);
   if(err=message_write(tmp_msg_fd, &msg)<0) {
	fprintf(stderr, "BARF on message_write (%d)\n",err);
	return;
   }
   /* Restore from the original is_spam check */
   msg.is_spam = is_spam;
   if(msg.is_spam == EX_TOOBIG) msg.is_spam=0; /* Ignore Too Big errs */

   return msg.is_spam;
}
Пример #12
0
void
acc_map_data (void *h, void *d, size_t s)
{
  struct target_mem_desc *tgt;
  size_t mapnum = 1;
  void *hostaddrs = h;
  void *devaddrs = d;
  size_t sizes = s;
  unsigned short kinds = GOMP_MAP_ALLOC;

  goacc_lazy_initialize ();

  struct goacc_thread *thr = goacc_thread ();
  struct gomp_device_descr *acc_dev = thr->dev;

  if (acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)
    {
      if (d != h)
        gomp_fatal ("cannot map data on shared-memory system");

      tgt = gomp_map_vars (NULL, 0, NULL, NULL, NULL, NULL, true,
			   GOMP_MAP_VARS_OPENACC);
    }
  else
    {
      struct goacc_thread *thr = goacc_thread ();

      if (!d || !h || !s)
	gomp_fatal ("[%p,+%d]->[%p,+%d] is a bad map",
                    (void *)h, (int)s, (void *)d, (int)s);

      gomp_mutex_lock (&acc_dev->lock);

      if (lookup_host (acc_dev, h, s))
        {
	  gomp_mutex_unlock (&acc_dev->lock);
	  gomp_fatal ("host address [%p, +%d] is already mapped", (void *)h,
		      (int)s);
	}

      if (lookup_dev (thr->dev->openacc.data_environ, d, s))
        {
	  gomp_mutex_unlock (&acc_dev->lock);
	  gomp_fatal ("device address [%p, +%d] is already mapped", (void *)d,
		      (int)s);
	}

      gomp_mutex_unlock (&acc_dev->lock);

      tgt = gomp_map_vars (acc_dev, mapnum, &hostaddrs, &devaddrs, &sizes,
			   &kinds, true, GOMP_MAP_VARS_OPENACC);
    }

  gomp_mutex_lock (&acc_dev->lock);
  tgt->prev = acc_dev->openacc.data_environ;
  acc_dev->openacc.data_environ = tgt;
  gomp_mutex_unlock (&acc_dev->lock);
}
Пример #13
0
void
table_append(int ac, char *av[])
{
	struct ipfw_ioc_table tbl;
	char *p;
	int size;

	NEXT_ARG;
	if (isdigit(**av))
		tbl.id = atoi(*av);
	else
		errx(EX_USAGE, "table id `%s' invalid", *av);

	if (tbl.id < 0 || tbl.id > IPFW_TABLES_MAX - 1)
		errx(EX_USAGE, "table id `%d' invalid", tbl.id);

	NEXT_ARG;
	if (strcmp(*av, "ip") == 0)
		tbl.type = 1;
	else if (strcmp(*av, "mac") == 0)
		tbl.type = 2;
	else
		errx(EX_USAGE, "table type `%s' not supported", *av);

	NEXT_ARG;
        if (tbl.type == 1) { /* table type ipv4 */
                struct ipfw_ioc_table_ip_entry ip_ent;
                if (!ac)
                        errx(EX_USAGE, "IP address required");

                p = strchr(*av, '/');
                if (p) {
                        *p++ = '\0';
                        ip_ent.masklen = atoi(p);
                        if (ip_ent.masklen > 32)
                                errx(EX_DATAERR, "bad width ``%s''", p);
                } else {
                        ip_ent.masklen = 32;
                }

                if (lookup_host(*av, (struct in_addr *)&ip_ent.addr) != 0)
                        errx(EX_NOHOST, "hostname ``%s'' unknown", *av);

                tbl.ip_ent[0] = ip_ent;
                size = sizeof(tbl) + sizeof(ip_ent);
        } else if (tbl.type == 2) { /* table type mac */
                struct ipfw_ioc_table_mac_entry mac_ent;
                if (!ac)
                        errx(EX_USAGE, "MAC address required");

                mac_ent.addr = *ether_aton(*av);
                tbl.mac_ent[0] = mac_ent;
                size = sizeof(tbl) + sizeof(mac_ent);
        }
	if (do_set_x(IP_FW_TABLE_APPEND, &tbl, size) < 0 )
		errx(EX_USAGE, "do_set_x(IP_FW_TABLE_APPEND) "
			"table `%d' append `%s' failed", tbl.id, *av);
}
Пример #14
0
extern struct hostent *resolv(const char *stuff)
{
    struct hostent *hep;

    if ((hep = lookup_host(stuff)) == NULL)
	hep = lookup_ip(stuff);

    return hep;
}
Пример #15
0
/*
 * cmd->arg3 is count of the destination
 * cmd->arg1 is the type, random 0, round-robin 1, sticky 2
 */
void
parse_forward(ipfw_insn **cmd, int *ac, char **av[])
{
	ipfw_insn_sa *p = (ipfw_insn_sa *)(*cmd);
	struct sockaddr_in *sa;
	char *tok, *end = '\0';
	char *str;
	int count, port;

	(*cmd)->opcode = O_BASIC_FORWARD;
	NEXT_ARG1;
	/*
	 * multiple forward destinations are seperated by colon
	 * ip address and port are seperated by comma
	 * e.g. 192.168.1.1:80,192.168.1.2:8080
	 *      192.168.1.1,192.168.1.2 or keep the port the same
	 */
	tok = strtok(**av, ",");
	sa = &p->sa;
	count = 0;
	while (tok != NULL) {
		sa->sin_len = sizeof(struct sockaddr_in);
		sa->sin_family = AF_INET;
		sa->sin_port = 0;
		str = strchr(tok,':');
		if (str != NULL) {
			*(str++) = '\0';
			port = strtoport(str, &end, 0, 0);
			sa->sin_port = (u_short)port;
		}
		lookup_host(tok, &(sa->sin_addr));
		tok = strtok (NULL, ",");
		sa++;
		count++;
	}
	(*cmd)->arg3 = count;
	if (count == 0) {
		errx(EX_DATAERR, "forward `%s' not recognizable", **av);
	}
	NEXT_ARG1;
	if (count > 1) {
		if (strcmp(**av, "round-robin") == 0) {
			NEXT_ARG1;
			(*cmd)->arg1 = 1;
		} else if (strcmp(**av, "sticky") == 0) {
			NEXT_ARG1;
			(*cmd)->arg1 = 2;
		} else {
			/* random */
			(*cmd)->arg1 = 0;
		}
	}
	(*cmd)->len = LEN_OF_IPFWINSN + count * sizeof(struct sockaddr_in);
}
Пример #16
0
/* OS_GetHost, v0.1, 2005/01/181
 * Calls gethostbyname (tries x attempts)
 */
char *OS_GetHost(char *host, int attempts)
{
    int i = 0;
    int sz;
    char *ip;
    struct in_addr **addr_list;
    struct hostent *h;

   debug1("%s : DEBUG : OS_GetHost( host=%s , attempst=%d)",ARGV0,host,attempts);  
    if(host == NULL)
        return(NULL);

     if ((h = gethostbyname(host)) == NULL) {  // get the host info
             //herror("gethostbyname");
             verbose("%s: error : got null \n",ARGV0);
             sleep(1);
      }
     else
     {  // print information about this host:
             verbose("%s: Official name is: %s",ARGV0,h->h_name);
             verbose("%s: IP addresses: ",ARGV0);
             addr_list = (struct in_addr **)h->h_addr_list;
             for(i = 0; addr_list[i] != NULL; i++) {
                 verbose("%s:  %s ",ARGV0,inet_ntoa(*addr_list[i]));
             }
     }


    while(i <= attempts)
    {
        if((h = gethostbyname(host)) == NULL)
        {
            verbose("%s : WHILE : gethostbyname(host=%s)  returned null .. sleeping %d secs ",ARGV0,host,i+1);  
            debug_gethostname(host);
            print_lookup_host(host);
            sleep(i++);
            continue;
        }
        sz = strlen(inet_ntoa(*((struct in_addr *)h->h_addr)))+1;
        if((ip = (char *) calloc(sz, sizeof(char))) == NULL)
            return(NULL);
        strncpy(ip,inet_ntoa(*((struct in_addr *)h->h_addr)), sz-1);
        verbose("%s : WHILE: gethostbyname(host=%s)  returned ip:'%s'",ARGV0,host,ip);  

        if (ip != NULL ) return(ip);
        //try getaddrinfo before giving up
        verbose("%s : OS_GETHOST : trying getaddrinfo for:'%s'",ARGV0,host);  
        //alloc mem to  ip before sending 
        if((ip = (char *) calloc(sz, sizeof(char))) == NULL) return(NULL);
        if (lookup_host(host,ip) != -1 ) return(ip);
    }
    return(NULL);
}
Пример #17
0
void
rpc_manager::update_latency (ptr<location> from, ptr<location> l, u_int64_t lat)
{
  nrpc++;

  //update global latency
  float err = (lat - a_lat);
  a_lat = a_lat + GAIN*err;
  if (err < 0) err = -err;
  a_var = a_var + GAIN*(err - a_var);

  //update per-host latency
  hostinfo *h = lookup_host (l->address ());
  if (h) {
    h->nrpc++;
    if (h->a_lat == 0 && h->a_var == 0)
      h->a_lat = lat;
    else {
      err = (lat - h->a_lat);
      h->a_lat = h->a_lat + GAIN*err;
      if (err < 0) err = -err;
      h->a_var = h->a_var + GAIN*(err - h->a_var);
    }
    if (lat > h->maxdelay) h->maxdelay = lat;

    // Copy info over to just this location
    l->inc_nrpc ();
    l->set_distance (h->a_lat);
    l->set_variance (h->a_var);
  }

  //do the coordinate variance if available
  if (from && l && from->coords ().size () > 0 && l->coords ().size () > 0) {
    float predicted = Coord::distance_f (from->coords (), l->coords ());
    float sample_err = (lat - predicted);
    

    /*    
    warn << "To " << l->id () << " " << (int)sample_err << " " << (int)lat 
	 << " " << (int)predicted << " " 
	 << (int)c_err << " " << (int)c_var << " " 
	 << (int)(c_err_rel*1000) << "\n";
    */
    
    if (sample_err < 0) sample_err = -sample_err;
    float rel_err = sample_err/lat;

    c_err = (c_err*49 + sample_err)/50;
    c_err_rel = (c_err_rel*49 + rel_err)/50;
    c_var = c_var + GAIN*(sample_err - c_var);
   }
}
Пример #18
0
/*
 * Tries to guess table key type.
 * This procedure is used in legacy table auto-create
 * code AND in `ipfw -n` ruleset checking.
 *
 * Imported from old table_fill_xentry() parse code.
 */
static int
guess_key_type(char *key, uint8_t *ptype)
{
	char *p;
	struct in6_addr addr;
	uint32_t kv;

	if (ishexnumber(*key) != 0 || *key == ':') {
		/* Remove / if exists */
		if ((p = strchr(key, '/')) != NULL)
			*p = '\0';

		if ((inet_pton(AF_INET, key, &addr) == 1) ||
		    (inet_pton(AF_INET6, key, &addr) == 1)) {
			*ptype = IPFW_TABLE_CIDR;
			if (p != NULL)
				*p = '/';
			return (0);
		} else {
			/* Port or any other key */
			/* Skip non-base 10 entries like 'fa1' */
			kv = strtol(key, &p, 10);
			if (*p == '\0') {
				*ptype = IPFW_TABLE_NUMBER;
				return (0);
			} else if ((p != key) && (*p == '.')) {
				/*
				 * Warn on IPv4 address strings
				 * which are "valid" for inet_aton() but not
				 * in inet_pton().
				 *
				 * Typical examples: '10.5' or '10.0.0.05'
				 */
				return (1);
			}
		}
	}

	if (strchr(key, '.') == NULL) {
		*ptype = IPFW_TABLE_INTERFACE;
		return (0);
	}

	if (lookup_host(key, (struct in_addr *)&addr) != 0)
		return (1);

	*ptype = IPFW_TABLE_CIDR;
	return (0);
}
Пример #19
0
struct ypresp_val
ypdb_get_record(const char *domain, const char *map, datum key, int ypprivate)
{
	static struct ypresp_val res;
	static char keystr[YPMAXRECORD + 1];
	DBM *db;
	datum k, v;
	int host_lookup, hn;
	struct opt_map *map_info = NULL;

	host_lookup = 0;	/* XXX gcc -Wuninitialized */

	(void)memset(&res, 0, sizeof(res));

	db = ypdb_open_db(domain, map, &res.status, &map_info);
	if (db == NULL || (int)res.status < 0)
		return (res);

	if (map_info)
		host_lookup = map_info->host_lookup;

	k.dptr = key.dptr;
	k.dsize = key.dsize;

	if (yp_private(k, ypprivate)) {
		res.status = YP_NOKEY;
		goto done;
	}
	v = ypdb_fetch(db, k);

	if (v.dptr == NULL) {
		res.status = YP_NOKEY;
		if ((hn = strcmp(map, YP_HOSTNAME)) != 0 &&
		    strcmp(map, YP_HOSTADDR) != 0)
			return (res);

		/* note: lookup_host needs null terminated string */
		(void)strlcpy(keystr, key.dptr, (size_t)key.dsize + 1);
		res.status = lookup_host((hn == 0) ? TRUE : FALSE,
		    host_lookup, db, keystr, &res);
	} else {
		res.valdat.dptr = v.dptr;
		res.valdat.dsize = v.dsize;
	}

 done:
	ypdb_close_db(db);
	return (res);
}
Пример #20
0
void init_subnet_list(char *hostname) {
  char in_addr[16];
  char ip_address[512];

  if (lookup_host(hostname, in_addr, NULL) != 0) {
     log_printf(0, "init_subnet_list: lookup_host failed.  Hostname: %s\n", hostname);
     abort();
  }

  if (inet_ntop(AF_INET, in_addr, ip_address, 511) == NULL) {
     log_printf(0, "init_subnet_list: inet_ntop failed.  Hostname: %s\n", hostname);
     abort();
  }

  ipdecstr2address(ip_address, local_address);
}
Пример #21
0
void
tcp_manager::doRPC_tcp_cleanup (ptr<aclnt> c, RPC_delay_args *args,
                                clnt_stat err)
{
  hostinfo *hi = lookup_host (args->l->address ());
  if (err) { 
    nrpcfailed++;
  } else {
    nrpc++;
    if (hi) 
      hi->nrpc++;
  }
  if (hi) hi->orpc--;
  (*args->cb)(err);
  delete args;
}
Пример #22
0
static void
delete_copyout (unsigned f, void *h, size_t s, const char *libfnname)
{
  size_t host_size;
  splay_tree_key n;
  void *d;
  struct goacc_thread *thr = goacc_thread ();
  struct gomp_device_descr *acc_dev = thr->dev;

  if (acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)
    return;

  gomp_mutex_lock (&acc_dev->lock);

  n = lookup_host (acc_dev, h, s);

  /* No need to call lazy open, as the data must already have been
     mapped.  */

  if (!n)
    {
      gomp_mutex_unlock (&acc_dev->lock);
      gomp_fatal ("[%p,%d] is not mapped", (void *)h, (int)s);
    }

  d = (void *) (n->tgt->tgt_start + n->tgt_offset
		+ (uintptr_t) h - n->host_start);

  host_size = n->host_end - n->host_start;

  if (n->host_start != (uintptr_t) h || host_size != s)
    {
      gomp_mutex_unlock (&acc_dev->lock);
      gomp_fatal ("[%p,%d] surrounds2 [%p,+%d]",
		  (void *) n->host_start, (int) host_size, (void *) h, (int) s);
    }

  gomp_mutex_unlock (&acc_dev->lock);

  if (f & FLAG_COPYOUT)
    acc_dev->dev2host_func (acc_dev->target_id, h, d, s);

  acc_unmap_data (h);

  if (!acc_dev->free_func (acc_dev->target_id, d))
    gomp_fatal ("error in freeing device memory in %s", libfnname);
}
Пример #23
0
void
table_test(int ac, char *av[])
{
	struct ipfw_ioc_table tbl;
	int size;

	NEXT_ARG;
	if (isdigit(**av))
		tbl.id = atoi(*av);
	else
		errx(EX_USAGE, "table id `%s' invalid", *av);

	if (tbl.id < 0 || tbl.id > IPFW_TABLES_MAX - 1)
		errx(EX_USAGE, "table id `%d' invalid", tbl.id);

	NEXT_ARG;
	if (strcmp(*av, "ip") == 0)
		tbl.type = 1;
	else if (strcmp(*av, "mac") == 0)
		tbl.type = 2;
	else
		errx(EX_USAGE, "table type `%s' not supported", *av);

	NEXT_ARG;
        if (tbl.type == 1) { /* table type ipv4 */
                struct ipfw_ioc_table_ip_entry ip_ent;
                if (lookup_host(*av, (struct in_addr *)&ip_ent.addr) != 0)
                        errx(EX_NOHOST, "hostname ``%s'' unknown", *av);

                tbl.ip_ent[0] = ip_ent;
                size = sizeof(tbl) + sizeof(ip_ent);
        } else if (tbl.type == 2) { /* table type mac */
                struct ipfw_ioc_table_mac_entry mac_ent;
                if (!ac)
                        errx(EX_USAGE, "MAC address required");

                mac_ent.addr = *ether_aton(*av);
                tbl.mac_ent[0] = mac_ent;
                size = sizeof(tbl) + sizeof(mac_ent);
        }
	if (do_set_x(IP_FW_TABLE_TEST, &tbl, size) < 0 ) {
		printf("NO, %s not exists in table %d\n", *av, tbl.id);
	} else {
		printf("YES, %s exists in table %d\n", *av, tbl.id);
	}
}
Пример #24
0
long
rpc_manager::doRPC (ptr<location> from, ptr<location> l,
		    const rpc_program &prog, int procno, 
		    ptr<void> in, void *out, aclnt_cb cb,
		    cbtmo_t cb_tmo)
{
  ref<aclnt> c = aclnt::alloc (dgram_xprt, prog, 
			       (sockaddr *)&(l->saddr ()));

  // Make sure that there is an entry in the table for this guy.
  (void) lookup_host (l->address ());
  
  u_int64_t sent = getusec ();
  c->call (procno, in, out,
	   wrap (this, &rpc_manager::doRPCcb, cb, l, sent)); 
  return 0;
}
Пример #25
0
static void
delete_copyout (unsigned f, void *h, size_t s)
{
  size_t host_size;
  splay_tree_key n;
  void *d;
  struct goacc_thread *thr = goacc_thread ();
  struct gomp_device_descr *acc_dev = thr->dev;

  gomp_mutex_lock (&acc_dev->lock);

  n = lookup_host (acc_dev, h, s);

  /* No need to call lazy open, as the data must already have been
     mapped.  */

  if (!n)
    {
      gomp_mutex_unlock (&acc_dev->lock);
      gomp_fatal ("[%p,%d] is not mapped", (void *)h, (int)s);
    }

  d = (void *) (n->tgt->tgt_start + n->tgt_offset);

  host_size = n->host_end - n->host_start;

  if (n->host_start != (uintptr_t) h || host_size != s)
    {
      gomp_mutex_unlock (&acc_dev->lock);
      gomp_fatal ("[%p,%d] surrounds2 [%p,+%d]",
		  (void *) n->host_start, (int) host_size, (void *) h, (int) s);
    }

  gomp_mutex_unlock (&acc_dev->lock);

  if (f & FLAG_COPYOUT)
    acc_dev->dev2host_func (acc_dev->target_id, h, d, s);

  acc_unmap_data (h);

  acc_dev->free_func (acc_dev->target_id, d);
}
Пример #26
0
static void
add_host( const uint8_t *mac, const uint32_t ip, const uint64_t dpid, const uint16_t port ) {
  host_entry *entry;
  struct in_addr addr;

  addr.s_addr = htonl( ip );

  entry = lookup_host( ip );

  if ( entry != NULL ) {
    debug( "Updating a host entry (mac = %02x:%02x:%02x:%02x:%02x:%02x, "
           "ip = %s, dpid = %#" PRIx64 ", port = %u).",
           mac[ 0 ], mac[ 1 ], mac[ 2 ], mac[ 3 ], mac[ 4 ], mac[ 5 ],
           inet_ntoa( addr ), dpid, port );

    memcpy( entry->mac, mac, ETH_ADDRLEN );
    entry->dpid = dpid;
    entry->port = port;
    entry->updated_at = time( NULL );

    return;
  }

  debug( "Adding a host entry (mac = %02x:%02x:%02x:%02x:%02x:%02x, "
         "ip = %s, dpid = %#" PRIx64 ", port = %u).",
         mac[ 0 ], mac[ 1 ], mac[ 2 ], mac[ 3 ], mac[ 4 ], mac[ 5 ],
         inet_ntoa( addr ), dpid, port );

  entry = xmalloc( sizeof( host_entry ) );

  memcpy( entry->mac, mac, ETH_ADDRLEN );
  entry->ip = ip;
  entry->dpid = dpid;
  entry->port = port;
  entry->updated_at = time( NULL );

  insert_hash_entry( host_db, &entry->ip, entry );

  add_host_route( entry->ip );
}
Пример #27
0
static bool
resolve_bind_address (struct sockaddr *sa)
{
  struct address_list *al;

  /* Make sure this is called only once.  opt.bind_address doesn't
     change during a Wget run.  */
  static bool called, should_bind;
  static ip_address ip;
  if (called)
    {
      if (should_bind)
        sockaddr_set_data (sa, &ip, 0);
      return should_bind;
    }
  called = true;

  al = lookup_host (opt.bind_address, LH_BIND | LH_SILENT);
  if (!al)
    {
      /* #### We should be able to print the error message here. */
      logprintf (LOG_NOTQUIET,
                 _("%s: unable to resolve bind address `%s'; disabling bind.\n"),
                 exec_name, opt.bind_address);
      should_bind = false;
      return false;
    }

  /* Pick the first address in the list and use it as bind address.
     Perhaps we should try multiple addresses in succession, but I
     don't think that's necessary in practice.  */
  ip = *address_list_address_at (al, 0);
  address_list_release (al);

  sockaddr_set_data (sa, &ip, 0);
  should_bind = true;
  return true;
}
Пример #28
0
void
tcp_manager::send_RPC (RPC_delay_args *args)
{

  hostinfo *hi = lookup_host (args->l->address ());
  if (!hi->xp) {
    delaycb (0, 0, wrap (this, &tcp_manager::send_RPC_ateofcb, args));
  }
  else if (hi->xp->ateof()) {
    hostlru.remove (hi);
    hostlru.insert_tail (hi);
    args->l->set_alive (false);
    remove_host (hi);
    delaycb (0, 0, wrap (this, &tcp_manager::send_RPC_ateofcb, args));
  }
  else {
    hi->orpc++;
    args->now = getusec ();
    ptr<aclnt> c = aclnt::alloc (hi->xp, args->prog);
    c->call (args->procno, args->in, args->out, 
	     wrap (this, &tcp_manager::doRPC_tcp_cleanup, c, args));
  }
}
Пример #29
0
/* Lookup NAME in DIR for USER; set *NODE to the found name upon return.  If
   the name was not found, then return ENOENT.  On any error, clear *NODE.
   (*NODE, if found, should be locked, this call should unlock DIR no matter
   what.) */
error_t
netfs_attempt_lookup (struct iouser *user, struct node *dir,
		      char *name, struct node **node)
{
  error_t err;

  if (dir->nn->name)
    err = ENOTDIR;
  else
    err = fshelp_access (&dir->nn_stat, S_IEXEC, user);

  if (! err)
    {
      if (strcmp (name, ".") == 0)
	/* Current directory -- just add an additional reference to DIR and
	   return it.  */
	{
	  netfs_nref (dir);
	  *node = dir;
	  err = 0;
	}
      else if (strcmp (name, "..") == 0)
	err = EAGAIN;
      else
	err = lookup_host (dir->nn->mux, name, node);

      fshelp_touch (&dir->nn_stat, TOUCH_ATIME, hostmux_maptime);
    }

  pthread_mutex_unlock (&dir->lock);
  if (err)
    *node = 0;
  else
    pthread_mutex_lock (&(*node)->lock);

  return err;
}
Пример #30
0
static void
recv_packet_from_tun() {
  char data[ PKT_BUF_SIZE ];
  ssize_t ret;

  ret = read( fd, data, PKT_BUF_SIZE );

  if ( ret <= 0 ) {
    return;
  }

  debug( "%zd bytes packet received from tun interface (fd = %d).", ret, fd );

  // FIXME: we need to parse the ipv4 packet.

  ipv4_header_t *ip_header = ( ipv4_header_t * ) data;
  host_entry *entry = lookup_host( ntohl( ip_header->daddr ) );
  struct in_addr addr;
  addr.s_addr = ip_header->daddr;

  if ( entry == NULL ) {
    error( "Failed to resolve host location (ip = %s).",
           inet_ntoa( addr ) );
    return;
  }

  // create an Ethernet frame and send a packet-out
  void *p;
  uint16_t *type;
  buffer *frame;
  buffer *pout;
  openflow_actions *actions;
  size_t frame_length = ETH_ADDRLEN * 2 + 2 + ( size_t ) ret;

  frame = alloc_buffer_with_length( frame_length );

  p = append_back_buffer( frame, ETH_ADDRLEN );
  memcpy( p, entry->mac, ETH_ADDRLEN );
  p = append_back_buffer( frame, ETH_ADDRLEN );
  memcpy( p, redirector_mac, ETH_ADDRLEN );

  type = append_back_buffer( frame, 2 );
  *type = htons( ETH_ETHTYPE_IPV4 );

  p = append_back_buffer( frame, ( size_t ) ret );
  memcpy( p, data, ( size_t ) ret );

  debug( "Sending a packet-out to a switch (ip = %s, dpid = %#" PRIx64 ", port = %u).",
         inet_ntoa( addr ), entry->dpid, entry->port );

  actions = create_actions();
  append_action_output( actions, entry->port, UINT16_MAX );

  pout = create_packet_out( get_transaction_id(), UINT32_MAX, OFPP_NONE,
                            actions, frame );

  send_openflow_message( entry->dpid, pout );

  free_buffer( frame );
  free_buffer( pout );
  delete_actions( actions );
}