Example #1
0
static void rt_print(const void *ip, const struct xt_entry_match *match,
                     int numeric)
{
    const struct ip6t_rt *rtinfo = (struct ip6t_rt *)match->data;

    printf("rt ");
    if (rtinfo->flags & IP6T_RT_TYP)
        printf("type:%s%d ", rtinfo->invflags & IP6T_RT_INV_TYP ? "!" : "",
               rtinfo->rt_type);
    print_nums("segsleft", rtinfo->segsleft[0], rtinfo->segsleft[1],
               rtinfo->invflags & IP6T_RT_INV_SGS);
    if (rtinfo->flags & IP6T_RT_LEN) {
        printf("length");
        printf(":%s", rtinfo->invflags & IP6T_RT_INV_LEN ? "!" : "");
        printf("%u", rtinfo->hdrlen);
        printf(" ");
    }
    if (rtinfo->flags & IP6T_RT_RES) printf("reserved ");
    if (rtinfo->flags & IP6T_RT_FST) printf("0-addrs ");
    print_addresses(rtinfo->addrnr, (struct in6_addr *)rtinfo->addrs);
    if (rtinfo->flags & IP6T_RT_FST_NSTRICT) printf("0-not-strict ");
    if (rtinfo->invflags & ~IP6T_RT_INV_MASK)
        printf("Unknown invflags: 0x%X ",
               rtinfo->invflags & ~IP6T_RT_INV_MASK);
}
Example #2
0
void
print_header(char *v)
{
	if (pflag) {
		char *s, *se;
		if (blaze822_mime_parameter(v, pflag, &s, &se)) {
			*se = 0;
			v = s;
		} else {
			return;
		}
	}

	status = 0;

	if (Hflag && !Aflag)
		printf("%s\t", curfile);

	if (Aflag)
		print_addresses(v);
	else if (Dflag)
		print_date(v);
	else if (dflag)
		print_decode_header(v);
	else
		printf("%s\n", v);
}
void set_net_address(void)
{
  uip_ipaddr_t ipaddr;
#if RPL_BORDER_ROUTER
  rpl_dag_t *dag;
#endif

  uip_ip6addr(&ipaddr, NET_ADDR_A, NET_ADDR_B, NET_ADDR_C, NET_ADDR_D, 0, 0, 0, 0);
  uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);  

 
//#if !UIP_CONF_ROUTER
//  uip_ds6_prefix_add(&ipaddr, 64, 0); // For on-link determination.
//#else
//  uip_ds6_prefix_add(&ipaddr, 64, 0, 0, 600, 600);
//#endif
  
  print_addresses();
  
#if RPL_BORDER_ROUTER
  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,&ipaddr);
  if(dag != NULL) {
    PRINTF("This node is setted as root of a DAG.\r\n");
  }
  else {
    PRINTF("Error while setting this node as root of a DAG.\r\n");
  }
#endif
  
}
Example #4
0
static void
do_find(isc_boolean_t want_event) {
	isc_result_t result;
	isc_boolean_t done = ISC_FALSE;
	unsigned int options;

	options = DNS_ADBFIND_INET | DNS_ADBFIND_INET6;
	if (want_event)
		options |= DNS_ADBFIND_WANTEVENT | DNS_ADBFIND_EMPTYEVENT;
	dns_fixedname_init(&target);
	result = dns_adb_createfind(view->adb, task, adb_callback, NULL,
				    dns_fixedname_name(&fixed),
				    dns_rootname, 0, options, 0,
				    dns_fixedname_name(&target), 0,
				    &find);
	if (result == ISC_R_SUCCESS) {
		if (!ISC_LIST_EMPTY(find->list)) {
			/*
			 * We have at least some of the addresses for the
			 * name.
			 */
			INSIST((find->options & DNS_ADBFIND_WANTEVENT) == 0);
			print_addresses(find);
			done = ISC_TRUE;
		} else {
			/*
			 * We don't know any of the addresses for this
			 * name.
			 */
			if ((find->options & DNS_ADBFIND_WANTEVENT) == 0) {
				/*
				 * And ADB isn't going to send us any events
				 * either.  This query loses.
				 */
				done = ISC_TRUE;
			}
			/*
			 * If the DNS_ADBFIND_WANTEVENT flag was set, we'll
			 * get an event when something happens.
			 */
		}
	} else if (result == DNS_R_ALIAS) {
		print_name(dns_fixedname_name(&target));
		done = ISC_TRUE;
	} else {
		printf("dns_adb_createfind() returned %s\n",
		       isc_result_totext(result));
		done = ISC_TRUE;
	}

	if (done) {
		if (find != NULL)
			dns_adb_destroyfind(&find);
		isc_app_shutdown();
	}
}
Example #5
0
int
main(int argc, char **argv)
{
    krb5_context context;
    krb5_error_code ret;
    krb5_addresses addrs;
    int optidx = 0;

    setprogname (argv[0]);

    if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
	usage(1);
    
    if (help_flag)
	usage (0);

    if(version_flag){
	print_version(NULL);
	exit(0);
    }

    argc -= optidx;
    argv += optidx;

    ret = krb5_init_context(&context);
    if (ret)
	errx (1, "krb5_init_context failed: %d", ret);

    ret = krb5_get_all_client_addrs (context, &addrs);
    if (ret)
	krb5_err (context, 1, ret, "krb5_get_all_client_addrs");
    printf ("client addresses\n");
    print_addresses (context, &addrs);
    krb5_free_addresses (context, &addrs);

    ret = krb5_get_all_server_addrs (context, &addrs);
    if (ret)
	krb5_err (context, 1, ret, "krb5_get_all_server_addrs");
    printf ("server addresses\n");
    print_addresses (context, &addrs);
    krb5_free_addresses (context, &addrs);
    return 0;
}
Example #6
0
File: ex15.c Project: rzurad/lcthw
int main(int argc, char *argv[]) {
    // create two arrays we care about
    int ages[] = {23, 43, 12, 89, 2};
    char *names[] = {"Alan", "Frank", "Mary", "John", "Lisa"};
    int count = sizeof(ages) / sizeof(int);

    print_indexing(names, ages, count);
    print_divider();
    print_pointers(names, ages, count);
    print_divider();
    print_pointers_as_arrays(names, ages, count);
    print_divider();
    print_stupid_complex(names, ages, count);
    print_divider();
    print_addresses(names, ages, count);

    return 0;
}
Example #7
0
static void rt_save(const void *ip, const struct xt_entry_match *match)
{
    const struct ip6t_rt *rtinfo = (struct ip6t_rt *)match->data;

    if (rtinfo->flags & IP6T_RT_TYP) {
        printf("%s--rt-type %u ",
               (rtinfo->invflags & IP6T_RT_INV_TYP) ? "! " : "",
               rtinfo->rt_type);
    }

    if (!(rtinfo->segsleft[0] == 0
            && rtinfo->segsleft[1] == 0xFFFFFFFF)) {
        printf("%s--rt-segsleft ",
               (rtinfo->invflags & IP6T_RT_INV_SGS) ? "! " : "");
        if (rtinfo->segsleft[0]
                != rtinfo->segsleft[1])
            printf("%u:%u ",
                   rtinfo->segsleft[0],
                   rtinfo->segsleft[1]);
        else
            printf("%u ",
                   rtinfo->segsleft[0]);
    }

    if (rtinfo->flags & IP6T_RT_LEN) {
        printf("%s--rt-len %u ",
               (rtinfo->invflags & IP6T_RT_INV_LEN) ? "! " : "",
               rtinfo->hdrlen);
    }

    if (rtinfo->flags & IP6T_RT_RES) printf("--rt-0-res ");
    if (rtinfo->flags & IP6T_RT_FST) printf("--rt-0-addrs ");
    print_addresses(rtinfo->addrnr, (struct in6_addr *)rtinfo->addrs);
    if (rtinfo->flags & IP6T_RT_FST_NSTRICT) printf("--rt-0-not-strict ");

}
int add_transaction(	tick_t now, int transaction_type, int slot_id,int *chan_id){
	transaction_t   *this_t = NULL;
	uint64_t    address = 0;
	addresses_t     this_a; 
	int		transaction_index;
	int		thread_id;
	thread_id = get_thread_id(global_biu,slot_id);

		address 			= get_physical_address(global_biu, slot_id);
		this_a.physical_address 	= address;
		// We need to setup an option in case address is already broken down!
		if (convert_address(dram_system.config.physical_address_mapping_policy, &dram_system.config,&(this_a)) == ADDRESS_MAPPING_FAILURE) {
		  /* ignore address mapping failure for now... */
	  }
//	  if(thread_id != -1){
	  if(thread_id != -1 ){
		int scramble_id = get_thread_set(thread_id);
		this_a.chan_id     = (this_a.chan_id + scramble_id) % dram_system.config.channel_count;
		this_a.rank_id     = (this_a.rank_id + scramble_id) % dram_system.config.rank_count;
		this_a.bank_id     = (this_a.bank_id + scramble_id) % dram_system.config.bank_count;
		this_a.row_id      = (this_a.row_id + scramble_id) % dram_system.config.row_count;
	  }

	*chan_id = this_a.chan_id;
	if(dram_system.dram_controller[this_a.chan_id].transaction_queue.transaction_count >= (dram_system.config.max_tq_size)){
	  return MEM_STATE_INVALID;
	} 
	transaction_index = dram_system.dram_controller[this_a.chan_id].transaction_queue.transaction_count;
	if (dram_system.dram_controller[this_a.chan_id].transaction_queue.transaction_count <= 0) {
	  dram_system.tq_info.last_transaction_retired_time = dram_system.current_dram_time;
	  //fprintf(stdout,"Reset retired time to %llu\n",dram_system.tq_info.last_transaction_retired_time);
	}
	this_a.thread_id = thread_id;
	this_t = &(dram_system.dram_controller[this_a.chan_id].transaction_queue.entry[transaction_index]);	/* in order queue. Grab next entry */
	
	this_t->status 			= MEM_STATE_VALID;
	this_t->arrival_time 		= now;
	this_t->completion_time 	= 0;
	this_t->transaction_type 	= transaction_type;
	this_t->transaction_id 	= dram_system.tq_info.transaction_id_ctr++;
	this_t->slot_id			= slot_id;
	this_t->critical_word_ready	= FALSE;
	this_t->critical_word_available	= FALSE;
	this_t->critical_word_ready_time= 0;
	this_t->issued_data = false;
	this_t->issued_command = false;
	this_t->issued_cas = false;
	this_t->issued_ras = false;
	this_t->tindex = transaction_index;


	// Update Address
	this_t->address.physical_address= address;
	this_t->address.chan_id= this_a.chan_id;
	this_t->address.bank_id= this_a.bank_id;
	this_t->address.rank_id= this_a.rank_id;
	this_t->address.row_id= this_a.row_id;
	  /* STATS FOR RANK & CHANNEL */
	  rank_distrib[ this_a.chan_id ][ this_a.rank_id ]++;
	  tot_reqs++;

	  /* */
		
	mem_gather_stat(GATHER_REQUEST_LOCALITY_STAT, (int)address);		/* send this address to the stat collection */

	if(get_transaction_debug()){
		print_addresses(&(this_a));
	}
	/*
	//Ohm--stat for dram_access
	dram_system.dram_controller[this_a.chan_id].rank[this_a.rank_id].r_p_info.dram_access++;
	dram_system.dram_controller[this_a.chan_id].rank[this_a.rank_id].r_p_gblinfo.dram_access++;
	*/
	this_t->next_c = transaction2commands(now,
			this_t->transaction_id,
			transaction_type,
			&(this_a)); 
	this_t->status = MEM_STATE_SCHEDULED;
	dram_system.dram_controller[this_a.chan_id].transaction_queue.transaction_count++;

	/* If the transaction selection policy is MOST/LEAST than you sort it */
	int trans_sel_policy = get_transaction_selection_policy(global_biu);
	if (trans_sel_policy == MOST_PENDING || trans_sel_policy == LEAST_PENDING) {
	  add_trans_pending_queue(this_a.chan_id,transaction_index);
	}
	
	if (transaction_type == MEMORY_WRITE_COMMAND) {
	  if (dram_system.dram_controller[this_t->address.chan_id].active_write_trans++ > 4) 
		dram_system.dram_controller[this_t->address.chan_id].active_write_flag = true;
	}
	return transaction_index;
}
Example #9
0
void
process_notification(int fd, char *notify_buf)
{
   char buf[256];
   union sctp_notification *snp;
   struct sctp_assoc_change *sac;
   struct sctp_paddr_change *spc;
   struct sctp_remote_error *sre;
   struct sctp_send_failed *ssf;
   struct sctp_shutdown_event *sse;
   struct sctp_pdapi_event *pdapi;
   struct sockaddr_in *msin;
   struct sockaddr_in6 *msin6;
   const char *str;
   struct sockaddr *sal;
   int num_loc;

   snp = (union sctp_notification *)notify_buf;
   switch(snp->sn_header.sn_type) {
   case SCTP_ASSOC_CHANGE:
      sac = &snp->sn_assoc_change;
      switch(sac->sac_state) {
      case SCTP_COMM_UP:
         str = "COMMUNICATION UP";
         break;
      case SCTP_COMM_LOST:
         str = "COMMUNICATION LOST";
         break;
      case SCTP_RESTART:
              str = "RESTART";
         break;
      case SCTP_SHUTDOWN_COMP:
         str = "SHUTDOWN COMPLETE";
         break;
      case SCTP_CANT_STR_ASSOC:
         str = "CANT START ASSOC";
         break;
      default:
         str = "UNKNOWN";
      } /* end switch(sac->sac_state) */
      printf("SCTP_ASSOC_CHANGE: %s, assoc=%xh\n", str, (uint32_t)sac->sac_assoc_id);
      
      if((sac->sac_state == SCTP_COMM_UP) ||
           (sac->sac_state == SCTP_RESTART)) {
              assoc_id = sac->sac_assoc_id;
           num_rem = sctp_getpaddrs(fd, sac->sac_assoc_id, &sar);
            printf("There are %d remote addresses and they are:\n", num_rem);
            print_addresses(sar, num_rem);

            num_loc = sctp_getladdrs(fd,sac->sac_assoc_id, &sal);
            printf("There are %d local addresses and they are:\n", num_loc);
            print_addresses(sal, num_loc);
            sctp_freeladdrs(sal);
        }
      break;
   case SCTP_PEER_ADDR_CHANGE:
      spc = &snp->sn_paddr_change;
      switch(spc->spc_state) {
      case SCTP_ADDR_REACHABLE:
         str = "ADDRESS REACHABLE";
         break;
      case SCTP_ADDR_UNREACHABLE:
         str = "ADDRESS UNAVAILABLE";
         break;
      case SCTP_ADDR_REMOVED:
         str = "ADDRESS REMOVED";
         break;
      case SCTP_ADDR_ADDED:
         str = "ADDRESS ADDED";
         break;
      case SCTP_ADDR_MADE_PRIM:
         str = "ADDRESS MADE PRIMARY";
         break;
      case SCTP_ADDR_CONFIRMED:
         str = "ADDRESS CONFIRMED";
         break;
      default:
         str = "UNKNOWN";
      } /* end switch */
      msin6 = (struct sockaddr_in6 *)&spc->spc_aaddr;
      if (msin6->sin6_family == AF_INET6) {
         inet_ntop(AF_INET6, (char*)&msin6->sin6_addr, buf, sizeof(buf));
      } else {
         msin = (struct sockaddr_in *)&spc->spc_aaddr;
         inet_ntop(AF_INET, (char*)&msin->sin_addr, buf, sizeof(buf));
      }
      printf("SCTP_PEER_ADDR_CHANGE: %s (%d), addr=%s, assoc=%xh\n", str, spc->spc_state, buf, (uint32_t)spc->spc_assoc_id);
      break;
   case SCTP_REMOTE_ERROR:
      sre = &snp->sn_remote_error;
      printf("SCTP_REMOTE_ERROR: assoc=%xh\n", (uint32_t)sre->sre_assoc_id);
      break;
   case SCTP_SEND_FAILED:
      ssf = &snp->sn_send_failed;
      printf("SCTP_SEND_FAILED: assoc=%xh\n", (uint32_t)ssf->ssf_assoc_id);
      break;
   case SCTP_ADAPTION_INDICATION:
     {
       struct sctp_adaption_event *ae;
       ae = &snp->sn_adaption_event;
       printf("SCTP_adaption_indication:0x%x\n", (unsigned int)ae->sai_adaption_ind);
     }
     break;
   case SCTP_PARTIAL_DELIVERY_EVENT:
     {
       pdapi = &snp->sn_pdapi_event;
       if(pdapi->pdapi_indication == SCTP_PARTIAL_DELIVERY_ABORTED){
          printf("SCTP_PD-API ABORTED\n");
       } else {
          printf("Unknown SCTP_PD-API EVENT %x\n", pdapi->pdapi_indication);
       }
     }
     break;
   case SCTP_SHUTDOWN_EVENT:
        sse = &snp->sn_shutdown_event;
      printf("SCTP_SHUTDOWN_EVENT: assoc=%xh\n", (uint32_t)sse->sse_assoc_id);
      break;
   default:
      printf("Unknown notification event type=%xh\n",  snp->sn_header.sn_type);
   }
}
int main (int argc, const char* argv[]) {

    // Check if the user has not given enough parameters
    if (argc != 3) {
        printf("Invalid command. Usage: \"%s [address] [port]\"\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    // Init structs and other variables
    struct addrinfo* results;
    int sockfd, nbytes;
    char buf[MAXDATASIZE];

    // Try to get addrinfo, exiting on error
    printf("Getting address information...\n");
    results = get_address_info(argv[1], argv[2]);
    if (!results) {
        fprintf(stderr, "Implement assignment 1!\n");
	exit(EXIT_FAILURE);
    }

    // Get IP addresses
    printf("Printing IP addresses for %s...\n", argv[1]);
    char* addr = print_addresses(results);
    if (!addr) {
        fprintf(stderr, "Implement assignment 2!\n");
        exit(EXIT_FAILURE);
    }
    printf("%s", addr);
    free(addr);

    // Bind and connect socket
    printf("Connecting to server...\n");
    sockfd = create_and_connect(results);
    if (!sockfd) {
        fprintf(stderr, "Implement assignment 3!\n");
        close(sockfd);
        exit(EXIT_FAILURE);
    }

    // We don't need this struct anymore
    freeaddrinfo(results);

    // Receive data
    printf("Receiving data...\n");
    nbytes = receive_data(sockfd, buf);
    if (!nbytes) {
        fprintf(stderr, "Implement assignment 4!\n");
        exit(EXIT_FAILURE);
    }
    buf[nbytes] = '\0';
    printf("Received: %s\n", buf);

    // Send data
    printf("Sending data...\n");
    nbytes = send_data(sockfd, buf);
    if (!nbytes) {
        fprintf(stderr, "Implement assignment 5!\n");
        exit(EXIT_FAILURE);
    }
    buf[nbytes] = '\0';
    printf("Sent: %s\n", buf);

    // Receive confirmation
    if ((nbytes = recv(sockfd, buf, MAXDATASIZE-1, 0)) == -1) {
        perror("recv error");
        exit(EXIT_FAILURE);
    }
    buf[nbytes] = '\0';
    printf("Received: %s\n", buf);

    // Close the socket after the sending and receiving is done
    close(sockfd);

    return 0;
}
Example #11
0
/*
	Please see cidrmerge.h
*/
unsigned int optimize(struct entry *addr,unsigned int len,int do_sort)
{
	unsigned int i,cur;
	unsigned int tmp_net;
	#ifdef LIBRARY_DEBUG
	char debug_buf[MAXLINE];
	unsigned int step=0;

	print_debug(STDOUT,debug_buf,"START optimize\n");
	#endif

	i=0;   /*pointer to last valid position*/
	cur=1; /*pointer to next addr to analize*/

	if (len <= 1)
	{
		/* empty or sigle element array is optimized by definition.*/
		return len;
	}

	if (do_sort)
	{
		sort_entries(addr,len);
	}

	/*Find first valid address and move it to first position*/
	while ((addr[0].prefix==INVALID_PREFIX) && (cur<len))
	{
		#ifdef LIBRARY_DEBUG
		printf ("SEARCH FIRST I: %d CUR: %d\n",i,cur);
		#endif
		if (addr[cur].prefix!=INVALID_PREFIX)
		{
			addr[0].network=addr[cur].network;
			addr[0].prefix=addr[cur].prefix;
			addr[cur].prefix=INVALID_PREFIX;
		}
		cur++;
	}

	while (cur<len)
	{
		#ifdef LIBRARY_DEBUG
		printf ("STEP: %u I: %d CUR: %d\n",step++,i,cur);
		#endif
		#ifdef LIBRARY_DEBUG_FULL
		print_addresses(STDOUT,addr,len,NULL,0);
		#endif

		/*check for expanded networks, they can never conflicts*/
		if (addr[cur].prefix>=EXPANDED_PREFIX)
		{
			#ifdef LIBRARY_DEBUG
			printf ("COPY EXPANDED I: %d CUR: %d\n",i,cur);
			#endif
			i++;
			addr[i].network=addr[cur].network;
			addr[i].prefix=addr[cur].prefix;
			cur++;
			while ((addr[i].prefix>=EXPANDED_PREFIX) && (cur<len))
			{
				#ifdef LIBRARY_DEBUG
				printf ("COPY ADDR[CUR] FOR EXPANDED I: %d CUR: %d\n",i,cur);
				#endif
				if (addr[cur].prefix!=INVALID_PREFIX)
				{
					i++;
					if (cur != i)
					{
						addr[i].network=addr[cur].network;
						addr[i].prefix=addr[cur].prefix;
						addr[cur].prefix=INVALID_PREFIX;
					}
				}
				cur++;
			}
		}
		else
		{
			/*If this test will fail we just skip addr[cur]*/
			if ((addr[cur].prefix<=32)&&((addr[cur].network&TONETMASK(addr[i].prefix))!=addr[i].network))
			{
				tmp_net=TONETMASK(addr[i].prefix-1);

				if ( (addr[i].prefix==addr[cur].prefix) && ( (addr[i].network&tmp_net) == (addr[cur].network&tmp_net) ) )
				{
					#ifdef LIBRARY_DEBUG
					printf ("COLLAPSE I: %d CUR: %d\n",i,cur);
					#endif

					if (i>0)
					{
						addr[cur].prefix=addr[i].prefix-1;
						addr[cur].network&=tmp_net;
						i--;
					}
					else
					{
						addr[i].prefix=addr[i].prefix-1;
						addr[i].network&=tmp_net;
						cur++;
					}
				}
				else
				{
					i++;

					addr[i].network=addr[cur].network;
					addr[i].prefix=addr[cur].prefix;

					cur++;
				}
			}
			else
			{
				#ifdef LIBRARY_DEBUG
				printf ("SKIP CUR: %d\n",cur);
				#endif

				cur++;
			}
		}
	}

	#ifdef LIBRARY_DEBUG
	print_debug(STDOUT,debug_buf,"END optimize\n");
	#endif

	if (addr[i].prefix!=INVALID_PREFIX)
	{
		return i+1;
	}
	else
	{
		return i;
	}
}
Example #12
0
/*
	Please see cidrmerge.h
*/
unsigned int apply_whitelist(struct entry *addr,struct entry **expanded_list,struct entry *white,unsigned int len1,unsigned int len2,unsigned int *size_expanded,int do_sort)
{
	unsigned int i1,i2,invalid,tmp,expanded_index=0;
	uint32_t supermask;
	struct entry tmp_entry;
	#ifdef LIBRARY_DEBUG
	char debug_buf[MAXLINE];
	unsigned int step=0;
	print_debug(STDOUT,debug_buf,"START apply_whitelist\n");
	#endif


	if (do_sort)
	{
		#ifdef LIBRARY_DEBUG
		print_debug(STDOUT,debug_buf,"Sorting entries\n");
		#endif
		sort_entries(addr,len1);
		sort_entries(white,len2);
	}

	i1=i2=0;
	while ((i1<len1)&&(i2<len2))
	{
		#ifdef LIBRARY_DEBUG
		print_debug(STDOUT,debug_buf,"STEP=%u I1=%d I2=%d\n",step++,i1,i2);
		#endif
		#ifdef LIBRARY_DEBUG_FULL
		print_addresses(STDOUT,addr,len1,NULL,0);
		#endif

		supermask=TONETMASK(addr[i1].prefix)&TONETMASK(white[i2].prefix);

		if ((addr[i1].prefix<=32)&&(addr[i1].network&supermask)==(white[i2].network&supermask))
		{
			#ifdef LIBRARY_DEBUG
			print_debug(STDOUT,debug_buf,"CONFLICT\n");
			print_address(STDOUT,addr[i1].network,addr[i1].prefix);
			print_address(STDOUT,white[i2].network,white[i2].prefix);
			#endif
			if (addr[i1].prefix<white[i2].prefix)
			{
				/*we have to expand the network*/

				/*invalidate all addr[i1] subnetworks */
				invalid=i1+1;
				while ((invalid<len1)&&(addr[invalid].network&supermask)==(white[i2].network&supermask))
				{
					/*address is already present in the expanded network, just drop it*/
					#ifdef LIBRARY_DEBUG
					print_debug(STDOUT,debug_buf,"INVALIDATING ");
					print_address(STDOUT,addr[invalid].network,addr[invalid].prefix);
					#endif
					addr[invalid].prefix=INVALID_PREFIX;

					invalid++;
				}

				invalid-=i1+1; /*invalid represents the number of invalidated positions*/

				#ifdef LIBRARY_DEBUG
				print_debug(STDOUT,debug_buf,"INVALID %u LEN1 %u\n",invalid,len1);
				#endif

				tmp=i2;
				i2+=1;
				while ( (i2<len2) && ((addr[i1].network&supermask)==(white[i2].network&supermask)) )
				{
					i2++;
				}

				#ifdef LIBRARY_DEBUG
				print_debug(STDOUT,debug_buf,"EXPAND expanded_index %u whitelist elements: %u num expand %d\n",expanded_index,i2-tmp,white[tmp].prefix-addr[i1].prefix);
				#endif

				tmp_entry.network=addr[i1].network;
				tmp_entry.prefix=addr[i1].prefix;

				addr[i1].prefix=EXPANDED_PREFIX+white[tmp].prefix-addr[i1].prefix;
				addr[i1].network=expanded_index;
				/* expanded positions are clean and optimized */
				expand(expanded_list,tmp_entry,&(white[tmp]),i2-tmp,white[tmp].prefix-tmp_entry.prefix,&expanded_index,size_expanded);

				i1+=invalid+1;

				#ifdef LIBRARY_DEBUG
				print_debug(STDOUT,debug_buf,"END MAIN EXPAND expanded_index %u i1: %u i2: %u\n",expanded_index,i1,i2);
				#endif

			}
			else
			{
				/*just invalidating entry i1*/
				#ifdef LIBRARY_DEBUG
				printf ("INVALIDATING ");
				print_address(STDOUT,addr[i1].network,addr[i1].prefix);
				#endif
				addr[i1].prefix=INVALID_PREFIX;
				i1++;
			}

		}
		else if ((addr[i1].prefix==INVALID_PREFIX)||(addr[i1].network&supermask)<=(white[i2].network&supermask))
		{
			i1++;
		}
		else
		{
			i2++;
		}
	}
	#ifdef LIBRARY_DEBUG
	print_debug(STDOUT,debug_buf,"END apply_whitelist\n");
	#endif
	return expanded_index;
}
Example #13
0
__inline
#endif
static void expand(struct entry **expanded_list,struct entry to_expand,struct entry *white,unsigned int len_white,unsigned int n,unsigned int *current_position,unsigned int *size_expanded)
{
	int first=*current_position,last=*current_position+n-1;
	unsigned int first_conflict,last_conflict,i;
	struct entry tmp_small,tmp_big;
	struct entry *result=*expanded_list;
	#ifdef LIBRARY_DEBUG
	char debug_buf[MAXLINE];
	#endif

	*current_position+=n;

	if (*current_position>*size_expanded)
	{
		/* we need to increase expanded_list array size */
		#ifdef LIBRARY_DEBUG
		print_debug(STDOUT,debug_buf,"BEFORE realloc: size_expanded: %u, MEM: %u\n", *size_expanded,(*size_expanded)*sizeof(struct entry));
		#endif

		*size_expanded+=BUCKET;
		#ifdef LIBRARY_DEBUG
		print_debug(STDOUT,debug_buf,"AFTER realloc size_expanded: %u,MEM: %u\n", *size_expanded,(*size_expanded)*sizeof(struct entry));
		#endif

		result=*expanded_list=realloc(*expanded_list,(*size_expanded)*sizeof(struct entry));
		if (result==NULL)
		{
			fprintf(stderr,"Error reallocating %lu bytes\n",(unsigned long)(*size_expanded)*sizeof(struct entry));
			exit(1);
		}
	}

	#ifdef LIBRARY_DEBUG
	print_debug(STDOUT,debug_buf,"\nTO EXPAND n %u:\n",n);
	print_address(STDOUT,to_expand.network,to_expand.prefix);

	print_debug(STDOUT,debug_buf,"START WHITE len_white %u:\n",len_white);
	print_addresses(STDOUT,white,len_white,NULL,0);
	print_debug(STDOUT,debug_buf,"END   WHITE\n");
	#endif

	while (first<=last)
	{
		tmp_small.prefix=tmp_big.prefix=to_expand.prefix+1;
		tmp_small.network=to_expand.network; 										/*last network bit set to 0 */
		tmp_big.network=to_expand.network+(0x1<<(32-tmp_small.prefix)); 	/*last network bit set to 1 */

		if ( (white[0].network & TONETMASK(tmp_small.prefix) ) == tmp_small.network )
		{
			/* conflicting whith tmp_small. */
			i=1;
			/* search for first conflicting position with tmp_big (it cant be the first) */
			while((i<len_white) && !( (white[i].network & TONETMASK(tmp_big.prefix) ) == tmp_big.network ))
			{
				i++;
			}
			first_conflict=i;
			/* search for last conflicting position with tmp_big*/
			while((i<len_white) && ( (white[i].network & TONETMASK(tmp_big.prefix) ) == tmp_big.network ))
			{
				i++;
			}
			last_conflict=i;
			/* check if there is at least one conflicting with tmp_big network into whitelist */
			if (first_conflict!=len_white)
			{
				if (white[first_conflict].prefix!=tmp_big.prefix)
				{

					#ifdef LIBRARY_DEBUG
					print_debug(STDOUT,debug_buf,"RE-CONFLICT BIG first %u last %u\n",first_conflict,last_conflict);
					print_address(STDOUT,tmp_big.network,tmp_big.prefix);
					#endif

					result[last].network=*current_position;
					result[last].prefix=EXPANDED_PREFIX+white[first_conflict].prefix-tmp_big.prefix;

					expand(expanded_list,tmp_big,&white[first_conflict],last_conflict-first_conflict,white[first_conflict].prefix-tmp_big.prefix,current_position,size_expanded);
				}
				else
				{
					#ifdef LIBRARY_DEBUG
					print_debug(STDOUT,debug_buf,"INVALIDATING BIG POSITION %u\n",last);
					#endif
					result[last].prefix=INVALID_PREFIX;
				}
			}
			else
			{
				#ifdef LIBRARY_DEBUG
				print_debug(STDOUT,debug_buf,"VALID BIG position %u:\n",last);
				print_address(STDOUT,tmp_big.network,tmp_big.prefix);
				#endif
				result[last].network=tmp_big.network;
				result[last].prefix=tmp_big.prefix;
			}
			to_expand.network=tmp_small.network;
			to_expand.prefix=tmp_small.prefix;
			last--;
		}
		else
		{
			/* conflicting with tmp_big */
			i=1;
			/* search for first conflicting position with tmp_small (it cant be the first)*/
			while((i<len_white) && !( (white[i].network & TONETMASK(tmp_small.prefix) ) == tmp_small.network ))
			{
				i++;
			}
			first_conflict=i;
			/* search for last conflicting position with tmp_small*/
			while((i<len_white) && ( (white[i].network & TONETMASK(tmp_small.prefix) ) == tmp_small.network ))
			{
				i++;
			}
			last_conflict=i;

			/* check if there is at least one conflicting with tmp_small network into whitelist */
			if (first_conflict!=len_white)
			{
				if (white[first_conflict].prefix!=tmp_small.prefix)
				{
					#ifdef LIBRARY_DEBUG
					print_debug(STDOUT,debug_buf,"RE-CONFLICT LOW first %u last %u\n",first_conflict,last_conflict);
					print_address(STDOUT,tmp_small.network,tmp_small.prefix);
					#endif

					result[first].network=*current_position;
					result[first].prefix=EXPANDED_PREFIX+white[first_conflict].prefix-tmp_small.prefix;

					expand(expanded_list,tmp_small,&white[first_conflict],last_conflict-first_conflict,white[first_conflict].prefix-tmp_small.prefix,current_position,size_expanded);
				}
				else
				{
					#ifdef LIBRARY_DEBUG
					print_debug(STDOUT,debug_buf,"INVALIDATING LOW POSITION %u\n",first);
					#endif
					result[first].prefix=INVALID_PREFIX;
				}
			}
			else
			{
				#ifdef LIBRARY_DEBUG
				print_debug(STDOUT,debug_buf,"VALID LOW position %u:\n",first);
				print_address(STDOUT,tmp_small.network,tmp_small.prefix);
				#endif

				result[first].network=tmp_small.network;
				result[first].prefix=tmp_small.prefix;
			}
			to_expand.network=tmp_big.network;
			to_expand.prefix=tmp_big.prefix;
			first++;
		}

		#ifdef LIBRARY_DEBUG
		print_debug(STDOUT,debug_buf,"first %d last %d\n",first,last);
		#endif
	}

	#ifdef LIBRARY_DEBUG
	print_debug(STDOUT,debug_buf,"EXPAND END. Local position %d, current position %u:\n",n,*current_position);
	print_debug(STDOUT,debug_buf,"\n");
	#endif
}