Пример #1
0
/*make a new unique name from a seed name, allocating memory*/
char* ns_make_unique_name(namespace_t *ns, const char* name){
  node_t* temp_node;
  char *curr_name, *curr_postfix_string;
  int curr_postfix;

  /*first see if we can get desired name*/
  if (!(temp_node = ns_search(ns, name, 0, SEARCH_EXACT))){

    if (!(curr_name = strdup(name))){
      printf("memory error\n");
      return 0;
    }

    return curr_name;
  }

  /*keep adding numbers onto the end until we find an unused name*/
  /*gentle reader, this sort of operation is not my forte therefore
    I ask that you remain strong while reading the following*/
  
  curr_postfix = 1; /*start with "name2"*/

  if (!(curr_postfix_string = (char*)malloc(12*sizeof(char)))){
    printf("memory error\n");
    return 0;
  }

  if (!(curr_name = (char*)malloc((12+strlen(name))*sizeof(char)))){
    printf("memory error\n");
    return 0;
  }

  while (1){

    /*increment postfix*/
    snprintf(curr_postfix_string,12,"%d",++curr_postfix);

    /*cat name & postfix > curr_name*/
    strcpy(curr_name,name);
    strcat(curr_name,curr_postfix_string);
    
    /*check curr_name*/
    if (!(temp_node = ns_search(ns, curr_name, 0, SEARCH_EXACT))){

      if (debug_readout)  printf("using unique name: %s\n",curr_name);

      free(curr_postfix_string);

      return curr_name;
    }
   
  }

  return 0;
}
Пример #2
0
static int destroy_sibling_or_exp(struct vrf *vrf, const struct netsession_tuple *tuple)
{
	const struct netsession_tuple *h;
	struct netsession_expect *exp;
	struct net_session *sibling;

	NS_PPTP_DEBUG("trying to timeout ct or exp for tuple ");

	h = ns_search((struct netsession_tuple *)tuple, NULL);
	
	if (h)  {
		sibling = ns_tuple_to_netsession(h);
		NS_PPTP_DEBUG("setting timeout of conntrack %p to 0\n", sibling);
		sibling->proto.gre.timeout	  = 0;
		sibling->proto.gre.stream_timeout = 0;
	//	if (del_timer(&sibling->timeout))
	//		sibling->timeout.function((unsigned long)sibling);
		ns_timeout((unsigned long)sibling);
		return 1;
	} else {
		exp = ns_expect_find_get(vrf, tuple, NULL);
		if (exp) {
			NS_PPTP_DEBUG("unexpect_related of expect %p\n", exp);
			ns_unexpect_related(exp);
			ns_expect_put(exp);
			return 1;
		}
	}
	return 0;
}
Пример #3
0
static s32
icmpv6_error_message(struct vrf *vrf,
		     struct sk_buff *skb,
		     unsigned int icmp6off,
		     enum netsession_info *nsinfo,
		     unsigned int hooknum)
{
	struct netsession_tuple intuple, origtuple;
	const struct netsession_l4proto *inproto;
    struct netsession_tuple *ret_tuple = NULL;

	/* Are they talking about one of our connections? */
	if (!ns_get_tuplepr(skb, 
                skb_network_header(skb) - skb->data 
                + sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr),
                PF_INET6, &origtuple)) {
        return -NS_ACCEPT;
	}

	/* rcu_read_lock()ed by nf_hook_slow */
	inproto = __ns_l4proto_find(PF_INET6, origtuple.dst.protonum);

	/* Ordinarily, we'd expect the inverted tupleproto, but it's
	   been preserved inside the ICMP. */
	if (!ns_invert_tuple(&intuple, &origtuple,
				&ns_l3proto_ipv6, inproto)) {
		return -NS_ACCEPT;
	}

	*nsinfo = NS_RELATED;

	ret_tuple = ns_search(&intuple, NULL);
	if (!ret_tuple) {
		return -NS_ACCEPT;
	}

    if(NS_DIRECTION(ret_tuple) == NS_DIR_REPLY)
        *nsinfo += NS_IS_REPLY;
	
	/* Update skb to refer to this connection */
    skb->ns = &ns_tuple_to_netsession(ret_tuple)->ns_general;
    ns_get(&ns_tuple_to_netsession(ret_tuple)->ns_general);
	skb->nsinfo = *nsinfo;

	return -NS_ACCEPT;
}