Exemplo n.º 1
0
static char *slave_make_configuration_string(void){
  /*
   * This function should be called after calling
   * feedmode_inputfifo_enabled(), and if that function returns 1.
   * It will then add the infifo configuration to the masterservers list.
   */
  char *r;
  int n;

  if(valid_str(g.infifo) == 0){
    /*
     * This should have been caught already by the caller of this function
     */
    log_errx("Invalid setting of infifo.");
    return(NULL);
  }

  /* Leave room for 3, */
  n = strlen(g.infifo) + 1 + strlen(SLAVE_STRING_JOIN2);

  if(feedmode_masterservers_enabled()){
    if(valid_str(g.masterservers) == 0){
      /*
       * This should have been caught already by the caller of this function
       */
      log_errx("Invalid setting of masterservers.");
      return(NULL);
    }
    /* Leave room for the SEP1 char */
    n += strlen(g.masterservers) + strlen(SLAVE_STRING_JOIN1);
  }

  r = malloc(n + 1);
  if(r == NULL)
    return(NULL);

  if(feedmode_masterservers_enabled()){
    if(snprintf(r, n + 1, "3%s%s%s%s",
		SLAVE_STRING_JOIN2, g.infifo,
		SLAVE_STRING_JOIN1, g.masterservers) != n){
      log_errx("Configuration error in slave_make_configuration_string().");
      free(r);
      return(NULL);
    }
  }else{
    if(snprintf(r, n + 1, "3%s%s", SLAVE_STRING_JOIN2, g.infifo) != n){
      log_errx("Configuration error in slave_make_configuration_string().");
      free(r);
      return(NULL);
    }
  }

  return(r);
}
Exemplo n.º 2
0
static int bbserver_open(void){

  if(valid_str(g.bbserver) == 0){
    log_errx("No bbserver registrar defined.");
    return(1);
  }

  g.bbserverfp = popen(g.bbserver, "w");
  if(g.bbserverfp != NULL){
    if(fprintf(g.bbserverfp, "%s\n", "init") < 0){
      (void)pclose(g.bbserverfp);
      g.bbserverfp = NULL;
    }
  }

  if(g.bbserverfp != NULL){
    if(fflush(g.bbserverfp) != 0){
      (void)pclose(g.bbserverfp);
      g.bbserverfp = NULL;
    }
  }

  if(g.bbserverfp == NULL){
    log_err("Could not start bbserver registrar.");
    return(-1);
  }else
    log_info("Started bbserver registrar.");

  return(0);
}
Exemplo n.º 3
0
int httpd_open(void){

  if(g.httpd_enable == 0)
    return(0);

  if(valid_str(g.httpd) == 0){
    log_errx("No httpd defined.");
    return(1);
  }

  ghttpd_fp = popen(g.httpd, "w");
  if(ghttpd_fp != NULL){
    if(fprintf(ghttpd_fp, "%s\n", "init") < 0){
      (void)pclose(ghttpd_fp);
      ghttpd_fp = NULL;
    }
  }

  if(ghttpd_fp == NULL){
    log_err("Could not start httpd server.");
    return(-1);
  }else
    log_info("Started httpd.");

  return(0);
}
Exemplo n.º 4
0
 struct node *putloop(struct node 
void testcases()
{
	struct node *res1,*ptr1,*ptr2,*res;
	char *ip1,*op;
	int i,check;
	for(i=0;i<2;i++)
	{
		res1=NULL;
		ip1=NULL;
		ip1=NULL;
		ip1=malloc_str(testDB[i].input1);
		ip1=valid_str(ip1);
		if(ip1!=NULL)
		{
			ip1=rem_space(ip1);
			res1=create_list(ip1);
			res1=putloop(res1);
			res1=removeloop(res1);

			
		}
		
		
		
		display(res);
		 
		free(op);
		free(ip1);
		free(res);
		free(output);

	}

}
Exemplo n.º 5
0
/*
 * These are the functions called by main to launch and terminate
 * the slave threads.
 */
int init_slavet(void){

  struct slave_table_st *slavet;
  struct slave_options_st defaults;
  char *conf_str = NULL;
  int status = 0;

  defaults.infifo_mode = g.infifo_mode;
  defaults.infifo_grp = g.infifo_grp;
  defaults.slavestatsfile = g.slavestatsfile;
  defaults.slave_masterport = g.slave_masterport;
  defaults.slave_read_timeout_secs = g.slave_read_timeout_secs;
  defaults.slave_read_timeout_retry = g.slave_read_timeout_retry;
  defaults.slave_reopen_timeout_secs = g.slave_reopen_timeout_secs;
  defaults.slave_so_rcvbuf = g.slave_so_rcvbuf;
  defaults.slave_stats_logperiod_secs = g.slave_stats_logperiod_secs;

  /*
   * Check both of these here once and for all
   */
  if(feedmode_masterservers_enabled() && (valid_str(g.masterservers) == 0)){
    log_errx("Slave mode enabled with masterservers unset.");
    return(-1);
  }

  if(feedmode_inputfifo_enabled() && (valid_str(g.infifo) == 0)){
    log_errx("Input fifo mode enabled with invalid setting of infifo.");
    return(-1);
  }

  if(feedmode_inputfifo_enabled()){
    conf_str = slave_make_configuration_string();
    if(conf_str == NULL)
      return(-1);

    status = slave_table_create(&slavet, conf_str, &defaults);
    free(conf_str);
  }else
    status = slave_table_create(&slavet, g.masterservers, &defaults);

  if(status == 0)
    g.slavet = slavet;

  return(status);
}
Exemplo n.º 6
0
static void dump_policies()
{
	policy_t *policy = policy_list.next;
	eval_t *eval;
	log_info("================================================");
	log_info("|           Printing All Policies              |");
	log_info("================================================");
	while (policy != NULL) {
		log_info("Application ID: %d", policy->appID);
		eval = policy->eval_list.next;
		while (eval != NULL) {
			debug("location %s, bandwidth %d, cost %d -> interface %s",
				valid_str(eval->location),
				eval->bandwidth, eval->cost,
				valid_str(eval->interface));
			eval = eval->next;
		}
		log_info("================================================");
		policy = policy->next;
	}
}
Exemplo n.º 7
0
int starter_ifaces_load (char **ifaces, unsigned int omtu, int nat_t)
{
    char *tmp_phys, *phys;
    int n;
    char **i;
    int sock;
    int j, found;
    int ret = 0;

    starter_log(LOG_LEVEL_DEBUG, "starter_ifaces_load()");

    sock = socket(AF_INET, SOCK_DGRAM, 0);
    if (sock < 0) return -1;

    for (j=0; j<N_IPSEC_IF; j++) {
        found = 0;
        for (i=ifaces; i && *i; i++) {
            if ((valid_str(*i, &n, &tmp_phys)) && (tmp_phys) &&
                    (n>=0) && (n<N_IPSEC_IF)) {
                if (n==j) {
                    if (found) {
                        starter_log(LOG_LEVEL_ERR,
                                    "ignoring duplicate entry for interface ipsec%d",
                                    j);
                    }
                    else {
                        found++;
                        phys = _find_physical_iface(sock, tmp_phys);
                        if (phys) {
                            ret += _iface_up (sock, &(_ipsec_if[n]), phys,
                                              omtu, nat_t);
                        }
                        else {
                            ret += _iface_down (sock, &(_ipsec_if[n]));
                        }
                    }
                }
            }
            else if (j==0) {
                /**
                 * Only log in the first loop
                 */
                starter_log(LOG_LEVEL_ERR, "ignoring invalid interface '%s'",
                            *i);
            }
        }
        if (!found)
            ret += _iface_down (sock, &(_ipsec_if[j]));
    }

    close(sock);
    return ret; /* = number of changes - 'whack --listen' if > 0 */
}
Exemplo n.º 8
0
void testcases()
{
	struct node *res,*output;
	char *ip,*op;
	int i,check;
	for(i=0;i<9;i++)
	{
		res=output=NULL;
		ip=op=NULL;
		ip=malloc_str(testDB[i].input);
		
		ip=valid_str(ip);
		//if(ip==NULL)
			//printf("hai\n");
		if(ip!=NULL)
		{
			ip=rem_space(ip);
			res=create_list(ip);
			//display(res);
			res=swap_adj_nodes(res);
		}
		else
		{
			res=NULL;
		}
		op=malloc_str(testDB[i].output);
		output=create_list(op);
		//if(res==NULL)
			
		check=list_cmp(res,output);
		display(res);
		display(output);
		if(check==0)
			printf("passed\n");
		else 
			printf("failed\n");
		free(op);
		free(ip);
		free(res);
		free(output);

	}

}
Exemplo n.º 9
0
int	pipe_parsing(char *str)
{
  char	**tab_pipe;
  int	ret;
  int	tab_len;

  if (!valid_str(str) || !last_verif(str))
    return (0);
  if (in_str(str, token_val("|")) &&
      (tab_pipe = str_to_wordtab(str, token_val("|"))))
    {
      tab_len = count_tab(tab_pipe);
      ret = exec_pipe(tab_pipe, tab_len);
      free(tab_pipe);
    }
  else
    ret = parse_command_redir(str);
  return (ret);
}
Exemplo n.º 10
0
void testcases()
{
	struct node *res;
	char *ip;
	int i,check;
	float res1;
	for(i=0;i<10;i++)
	{
		res=NULL;
		ip=NULL;
		ip=malloc_str(testDB[i].input);
		
		ip=valid_str(ip);
		if(ip!=NULL)
		{
			ip=rem_space(ip);
			res=create_list(ip);
			res=mergesort(res);
			res1=get_median(res);
		}
		else
		{
			res1=0;
		}
			
		check=val_cmp(res1,testDB[i].value);
		//printf("%f\t%f\n",res1,testDB[i].value);
		
		if(check==0)
			printf("passed\n");
		else 
			printf("failed\n");
		
		free(ip);
		free(res);
		

	}

}
Exemplo n.º 11
0
static int get_n(t_words *cmd, t_alias *alias, t_alias **mod)
{
  t_alias	*pnew;

  pnew = NULL;
  while (alias)
    {
      if (MATCH(cmd->word, alias->name))
	pnew = alias;
      alias = alias->next;
    }
  if (!cmd->next)
    return (p_one(pnew));
  if (valid_str(cmd->word) == FALSE)
    return (EXIT_FAILURE);
  if (!pnew)
    return (mod_alias(cmd->word, cmd->next->word, mod));
  free(pnew->fill);
  if ((pnew->fill = my_strdup(cmd->next->word)) == NULL)
    return (EXIT_FAILURE);
  return (EXIT_SUCCESS);
}
Exemplo n.º 12
0
bool NodeSetAssociateData::load_other() {
    return NodeBase::load_other() &&
           valid_str(_key_map, PARAM_KEY, _key_data) &&
           valid_str(_key_map, PARAM_VALUE, _value_data);
}
Exemplo n.º 13
0
static int np_init(char *np_ip, char *np_port, char *ifname, char *ifip,
	    int udprcvsize){
  /*
   * Here np_ip should be a string of the form
   *
   * np_ip = "224.0.1.1 224.0.1.2 ..."
   *
   * and similarly for np_port. The strings can be set in the runtime
   * configuration file. 
   *
   * Returns:
   *  0 => ok
   *  1 => ips and/or ports not specified, or not the same number, or too many.
   * -1 => memory error.
   */
  int status = 0;
  int i;

  if((valid_str(np_ip) == 0) || (valid_str(np_port) == 0))
    return(1);

  if(valid_str(ifname)){
    gifname = malloc(IFNAMSIZ);
    if(gifname == NULL){
      status = -1;
      goto end;
    }else{
      strncpy(gifname, ifname, IFNAMSIZ);
      gifname[IFNAMSIZ - 1] = '\0';
    }
  }

  if(valid_str(ifip)){
    gifip = malloc(INET_ADDRSTRLEN);
    if(gifip == NULL){
      status = -1;
      goto end;
    }else{
      strncpy(gifip, ifip, INET_ADDRSTRLEN);
      gifip[INET_ADDRSTRLEN - 1] = '\0';
    }
  }

  if(np_ip != NULL){
    gip = strsplit_create(np_ip, NP_DELIM_STR, STRSPLIT_FLAG_IGNEMPTY);
    if(gip == NULL){
      status = -1;
      goto end;
    }
  }

  if(np_port != NULL){
    gport = strsplit_create(np_port, NP_DELIM_STR, STRSPLIT_FLAG_IGNEMPTY);
    if(gport == NULL){
      status = -1;
      goto end;
    }
  }

  if((gip->argc == 0) || (gport->argc == 0) || (gip->argc != gport->argc)){
    status = 1;
    goto end;
  }

  if(gip->argc > NPCAST_NUM_CHANNELS){
    status = 1;
    goto end;
  }
  gnpcast.numchannels = gip->argc;	/* used */

  gnpcast.channel = calloc(NPCAST_NUM_CHANNELS,
			   sizeof(struct npcast_channel_st));
  if(gnpcast.channel == NULL){
    status = -1;
    goto end;
  }

  /*
   * Disable all, and enable only those specified.
   */
  for(i = 0; i < NPCAST_NUM_CHANNELS; ++i){
    gnpcast.channel[i].f_enable = 0;
    gnpcast.channel[i].sfd = -1;
    gnpcast.channel[i].sa = NULL;
    gnpcast.channel[i].sender_sa = NULL;
  }

  for(i = 0; i < gnpcast.numchannels; ++i){
    gnpcast.channel[i].f_enable = 1;
    gnpcast.channel[i].ip = gip->argv[i];
    gnpcast.channel[i].port = gport->argv[i];
    gnpcast.channel[i].udprcvsize = udprcvsize;
  }

 end:

  if(status != 0){
    if(gifname != NULL){
      free(gifname);
      gifname = NULL;
    }

    if(gifip != NULL){
      free(gifip);
      gifip = NULL;
    }

    if(gip != NULL){
      strsplit_delete(gip);
      gip = NULL;
    }

    if(gport != NULL){
      strsplit_delete(gport);
      gport = NULL;
    }

    if(gnpcast.channel != NULL){
      free(gnpcast.channel);
      gnpcast.channel = NULL;
    }
  }

  if(status == 0){
    for(i = 0; i < NPCAST_NUM_CHANNELS; ++i){
      if(gnpcast.channel[i].f_enable){
	log_info("Enabled channel %d: %s:%s", 
		 i, gnpcast.channel[i].ip, gnpcast.channel[i].port);
      } else
	log_verbose(1, "Unconfigured channel %d", i); 
    }
  }

  return(status);
}
int
starter_ifaces_load(char **ifaces, unsigned int omtu, bool nat_t
, defaultroute_t *defaultroute)
{
    char *tmp_phys, *phys;
    int n;
    char **i;
    int sock;
    int j, found;
    int ret = 0;
    struct ifreq physreq, ipsecreq; // re-attach interface
    struct sockaddr_in *inp1, *inp2; // re-attach interface

    DBG(DBG_CONTROL,
	DBG_log("starter_ifaces_load()")
    )

    sock = socket(AF_INET, SOCK_DGRAM, 0);
    if (sock < 0)
	return -1;

    for (j = 0; j < N_IPSEC_IF; j++)
    {
	found = 0;

	for (i = ifaces; i && *i; i++)
	{
	    if (valid_str(*i, &n, &tmp_phys, defaultroute)
	    && tmp_phys
	    && n >= 0
	    && n < N_IPSEC_IF)
	    {
		if (n==j)
		{
		    if (found)
		    {
			plog( "ignoring duplicate entry for interface ipsec%d", j);
		    }
		    else
		    {
			found++;
			phys = _find_physical_iface(sock, tmp_phys);

			/* Re-attach ipsec interface if IP address changes
			 * [email protected]
			 */
			if (phys)
			{
			    memset ((void*)&physreq, 0, sizeof(physreq));
			    memset ((void*)&ipsecreq, 0, sizeof(ipsecreq));
			    strncpy(physreq.ifr_name, phys, IFNAMSIZ);
			    sprintf(ipsecreq.ifr_name, "ipsec%d", j);
			    ioctl(sock, SIOCGIFADDR, &physreq);
			    ioctl(sock, SIOCGIFADDR, &ipsecreq);
			    inp1 = (struct sockaddr_in *)&physreq.ifr_addr;
			    inp2 = (struct sockaddr_in *)&ipsecreq.ifr_addr;
			    if (inp1->sin_addr.s_addr != inp2->sin_addr.s_addr)
			    {
				plog("IP address of physical interface changed "
				     "-> reinit of ipsec interface");
				_iface_down (sock, &(_ipsec_if[n]));
			    }
			    ret += _iface_up (sock, &(_ipsec_if[n]), phys, omtu, nat_t);
			}
			else
			{
			    ret += _iface_down (sock, &(_ipsec_if[n]));
			}
		    }
		}
	    }
	    else if (j == 0)
	    {
		/* Only log in the first loop */
		plog("ignoring invalid interface '%s'", *i);
	    }
	}
	if (!found)
	    ret += _iface_down (sock, &(_ipsec_if[j]));
    }

    close(sock);
    return ret; /* = number of changes - 'whack --listen' if > 0 */
}
Exemplo n.º 15
0
bool NodeSetAppData::load_other() {
    return NodeBase::load_other()
           && valid_str(_key_map, _s_param_input, _app_data);
}
Exemplo n.º 16
0
static int slavenet_open(struct slave_element_st *slave){
  /*
   * This function returns the following errors:
   *
   * -1 => operating system error
   *  1 => timed out trying to connect
   *  2 => configuration error (of masterservers)
   *
   * When the error is 1 or -1, we can assume that it is a temporary
   * situation and keep retyring. When the error is 2, we should quit
   * the application.
   */
  int status = 0;
  int gai_code;
  char *nbs_str;
  ssize_t n;
  
  if(valid_str(slave->mastername) == 0){
    log_errx("No master host defined.");
    return(2);
  }

  if(valid_str(slave->masterport) == 0){
    log_errx("Master port not set.");
    return(2);
  }

  if(slave->slavetype == SLAVETYPE_NBS1)
    nbs_str = PROTOCOL_NBS1_STR;
  else if(slave->slavetype == SLAVETYPE_NBS2)
    nbs_str = PROTOCOL_NBS2_STR;
  else{
    log_errx("Invalid slave mode in slavenet_open.");
    return(2);
  }

  slave->slave_fd = tcp_client_open_conn(slave->mastername, slave->masterport,
					 -1, slave->options.slave_so_rcvbuf,
					 &gai_code);
  if(slave->slave_fd == -1){
    status = -1;
    if(gai_code != 0)
      log_errx("Slave cannot open connection to %s. %s.",
	       slave->mastername, gai_strerror(gai_code));
    else
      log_err2("Slave cannot open connection to", slave->mastername);
  }

  if(status != 0)
    return(status);

  /* Wait at most the same amount allowed to read from the master */
  n = writen(slave->slave_fd, nbs_str, strlen(nbs_str),
	     (unsigned int)slave->options.slave_read_timeout_secs, 0);
  if(n == -1){
    status = -1;
    log_err2("Cannot communicate with", slave->mastername);
  }else if((size_t)n != strlen(nbs_str)){
    log_errx("Cannot communicate with %s. Timed out.", slave->mastername);
    status = 1;
  }

  if(status != 0){
    (void)close(slave->slave_fd);
    slave->slave_fd = -1;
  }else{
    log_info("Opened connection to %s.", slave->mastername);
  }

  return(status);
}