Exemple #1
0
void delete_hashlist(struct session *ses, struct hashtable *h, const char *pat, const char *msg_ok, const char *msg_none)
{
    struct listnode *templist;

    if (is_literal(pat))
    {
        if (delete_hash(h, pat))
        {
            if (msg_ok)
                tintin_printf(ses, msg_ok, pat);
        }
        else
        {
            if (msg_none)
                tintin_printf(ses, msg_none, pat);
        }
        return;
    }
    templist=hash2list(h, pat);
    for (struct listnode *ln=templist->next; ln; ln=ln->next)
    {
        if (msg_ok)
            tintin_printf(ses, msg_ok, ln->left);
        delete_hash(h, ln->left);
    }
    if (msg_none && !templist->next)
        tintin_printf(ses, msg_none, pat);
    zap_list(templist);
}
static void
delete_transaction_db() {
  debug( "Deleting transaction database ( db = %p, xid = %p, barrier_xid = %p ).", transaction_db, transaction_db->xid, transaction_db->barrier_xid );

  assert( transaction_db != NULL );
  assert( transaction_db->xid != NULL );
  assert( transaction_db->barrier_xid != NULL );

  hash_entry *e;
  hash_iterator iter;
  init_hash_iterator( transaction_db->xid, &iter );
  while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
    if ( e->value != NULL ) {
      free_transaction_entry( e->value );
    }
  }
  delete_hash( transaction_db->xid );
  transaction_db->xid = NULL;
  delete_hash( transaction_db->barrier_xid );
  transaction_db->barrier_xid = NULL;
  xfree( transaction_db );

  debug( "Transaction database is deleted ( %p ).", transaction_db );

  transaction_db = NULL;
}
bool
finalize_redirector() {
  hash_iterator iter;
  hash_entry *entry;
  host_entry *host_entry;

  if ( host_db != NULL ) {
    delete_timer_event( age_host_db, NULL );
    init_hash_iterator( host_db, &iter );
    while ( ( entry = iterate_hash_next( &iter ) ) != NULL ) {
      host_entry = entry->value;
      if ( host_entry != NULL ) {
        delete_host_route( host_entry->ip );
        xfree( host_entry );
      }
    }
    delete_hash( host_db );
  }
  host_db = NULL;

  if ( fd >= 0 ) {
    set_readable( fd, false );
    delete_fd_handler( fd );
  }

  return finalize_tun();
}
Exemple #4
0
int
destroy_vxlan_instance (struct vxlan_instance * vins)
{
	/* error handling */
	if (vxlan.vins_num < 1) {
		return -1;
	}

	if (vins == NULL) {
		error_warn ("%s: vxlan_instance is NULL!!", __func__);
		return -1;
	}
	
	/* Stop And Delete */
	if (pthread_cancel (vins->tid) != 0)
		error_warn ("%s: can not stop vxlan instance %s", vins->vxlan_tap_name);
	
	if (close (vins->tap_sock) < 0)
		error_warn ("%s: can not close tap socket %s : %s",
			    vins->vxlan_tap_name,
			    strerror (errno));

	destroy_fdb (vins->fdb);
	
	/* cleaning struct vxlan values */
	vxlan.vins_num--;
	delete_hash (&vxlan.vins_tuple, vins->vni);

	return 0;
}
Exemple #5
0
static void
finalize_exact_match_table( hash_table *exact_table ) {
  assert( exact_table != NULL );

  foreach_hash( exact_table, free_exact_match_entry, NULL );
  delete_hash( exact_table );
}
static bool
delete_user_from_multicast_group( struct in_addr maddr, unsigned int *n_users ) {
  assert( multicast_groups != NULL );
  assert( n_users != NULL );

  if ( !IN_MULTICAST( ntohl( maddr.s_addr ) ) ) {
    return false;
  }

  lock_multicast_group_table();

  unsigned int *in_use = search_hash( &multicast_groups->groups, &maddr );
  if ( in_use == NULL ) {
    *n_users = 0;
    unlock_multicast_group_table();
    return false;
  }

  ( *in_use )--;
  *n_users = *in_use;
  if ( *in_use == 0 ) {
    in_use = delete_hash( &multicast_groups->groups, &maddr );
    if ( in_use != NULL ) {
      free( in_use );
      in_use = NULL;
    }
  }

  unlock_multicast_group_table();

  return true;
}
Exemple #7
0
void
finalize_dpid_table( void ) {
  assert( dpid_table != NULL );

  foreach_hash( dpid_table, free_dpid_table_walker, NULL );
  delete_hash( dpid_table );
  dpid_table = NULL;
}
Exemple #8
0
static void
test_lookup_empty_table_returns_NULL() {
  table = create_hash( compare_string, hash_string );

  assert_true( lookup_hash_entry( table, alpha ) == NULL );

  delete_hash( table );
}
Exemple #9
0
static void delete_bucket(bucket b) {
    if(!b)
        return;
    delete_hash(b -> subnodes);
    delete_bucket(b -> next);
    free(b -> key);
    free(b);
}
Exemple #10
0
static void
test_nonexistent_entry_returns_NULL() {
  table = create_hash( compare_string, hash_string );

  assert_true( delete_hash_entry( table, "NO SUCH KEY" ) == NULL );

  delete_hash( table );
}
Exemple #11
0
static void
test_insert_and_lookup() {
  table = create_hash( compare_string, hash_string );

  insert_hash_entry( table, alpha, alpha );
  assert_string_equal( lookup_hash_entry( table, alpha ), "alpha" );

  delete_hash( table );
}
void
delete_datapath_db( hash_table *db ) {
  hash_iterator iter;
  init_hash_iterator( db, &iter );
  hash_entry *hash;
  while ( ( hash = iterate_hash_next( &iter ) ) != NULL ) {
    free_datapath_entry( hash->value );
  }
  delete_hash( db );
}
Exemple #13
0
static void
test_insert_and_lookup_by_atom_hash() {
  key mykey = { "alpha" };
  table = create_hash( compare_atom, hash_atom );

  insert_hash_entry( table, &mykey, alpha );
  assert_string_equal( lookup_hash_entry( table, &mykey ), "alpha" );

  delete_hash( table );
}
Exemple #14
0
static void
test_iterate_empty_hash() {
  hash_iterator iter;
  table = create_hash( compare_atom, hash_atom );
  init_hash_iterator( table, &iter );

  while ( iterate_hash_next( &iter ) != NULL ) { UNREACHABLE(); }

  delete_hash( table );
}
static void
xfree_all_sw_tx( all_sw_tx *tx ) {
  struct event_forward_operation_to_all_request_param *param = tx->request_param;
  xfree_event_forward_operation_to_all_request_param( param );
  tx->request_param = NULL;

  foreach_hash( tx->waiting_dpid, xfree_dpid, NULL );
  delete_hash( tx->waiting_dpid );
  tx->waiting_dpid = NULL;
  xfree( tx );
}
Exemple #16
0
int
fdb_del_entry (struct hash * fdb, u_int8_t * mac) 
{
	struct fdb_entry * entry;
	
	if ((entry = delete_hash (fdb, mac)) != NULL) {
		free (entry);
		return 1;
	} 

	return -1;
}
Exemple #17
0
void
delete_fdb( hash_table *fdb ) {
    if ( fdb != NULL ) {
        hash_iterator iter;
        hash_entry *e;
        init_hash_iterator( fdb, &iter );
        while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
            xfree( e->value );
        }
        delete_hash( fdb );
    }
}
Exemple #18
0
void
finalize_xid_table( void ) {
  for( int i = 0; i < XID_MAX_ENTRIES; i++ ) {
    if ( xid_table.entries[ i ] != NULL ) {
      free_xid_entry( xid_table.entries[ i ] );
      xid_table.entries[ i ] = NULL;
    }
  }
  delete_hash( xid_table.hash );
  xid_table.hash = NULL;
  xid_table.next_index = 0;
}
Exemple #19
0
int
uninstall_acl_entry (struct vxlan_instance * vins, struct acl_entry ae)
{
        struct acl_entry * e;

        if (vins == NULL)
                return -1;

        if (CHECK_VNI (vins->vni, ae.vni) < 0)
                return -1;

        e = (struct acl_entry *) malloc (sizeof (struct acl_entry));
        memset (e, 0, sizeof (struct acl_entry));
        memcpy (e, &ae, sizeof (ae));

        switch (e->type) {
        case ACL_TYPE_MAC :
                delete_hash (&vins->acl_mac, &e->term_mac);
                break;
        case ACL_TYPE_IP4 :
                delete_hash (&vins->acl_ip4, &e->term_ip4);
                break;
        case ACL_TYPE_IP6 :
                delete_hash (&vins->acl_ip6, &e->term_ip6);
                break;
        case ACL_TYPE_RA :
                vins->acl_mask ^= ACL_MASK_RA;
                break;
        case ACL_TYPE_RS :
                vins->acl_mask ^= ACL_MASK_RS;
                break;
        default :
                return -1;
        }

        return 1;
}
Exemple #20
0
/**
 * Delete the global hash_table which stored the stats of parameters.
 * @param None
 * @return None
 */
static void
delete_stats_table() {
  hash_iterator iter;
  hash_entry *e;

  assert( stats != NULL );

  init_hash_iterator( stats, &iter );
  while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
    void *value = delete_hash_entry( stats, e->key );
    xfree( value );
  }
  delete_hash( stats );
  stats = NULL;
}
Exemple #21
0
static void
test_delete_entry() {
  table = create_hash( compare_string, hash_string );

  insert_hash_entry( table, alpha, alpha );
  insert_hash_entry( table, bravo, bravo );
  insert_hash_entry( table, charlie, charlie );

  delete_hash_entry( table, bravo );
  assert_string_equal( lookup_hash_entry( table, alpha ), "alpha" );
  assert_true( lookup_hash_entry( table, bravo ) == NULL );
  assert_string_equal( lookup_hash_entry( table, charlie ), "charlie" );

  delete_hash( table );
}
Exemple #22
0
static void
test_map() {
  table = create_hash( compare_string, hash_string );

  char key[] = "key";
  insert_hash_entry( table, key, alpha );
  insert_hash_entry( table, key, bravo );
  insert_hash_entry( table, key, charlie );

  map_hash( table, key, append_back, NULL );

  assert_string_equal( abc0[ 0 ], "charlie" );
  assert_string_equal( abc0[ 1 ], "bravo" );
  assert_string_equal( abc0[ 2 ], "alpha" );

  delete_hash( table );
}
Exemple #23
0
static void
test_insert_twice_overwrites_old_value() {
  char *prev;
  char key[] = "key";
  table = create_hash( compare_string, hash_string );

  char old_value[] = "old value";
  char new_value[] = "new value";

  insert_hash_entry( table, key, old_value );
  prev = insert_hash_entry( table, key, new_value );

  assert_string_equal( lookup_hash_entry( table, key ), "new value" );
  assert_string_equal( prev, "old value" );

  delete_hash( table );
}
bool
finalize_event_forward_interface( void ) {
  if ( efi_queue_name == NULL ) {
    warn( "already finalized." );
    return false;
  }
  delete_message_replied_callback( efi_queue_name, handle_efi_reply );

  xfree( efi_queue_name );
  efi_queue_name = NULL;

  _cleanup_tx_table();
  delete_hash( efi_tx_table );
  efi_tx_table = NULL;

  return true;
}
Exemple #25
0
static void
test_iterator() {
  table = create_hash( compare_string, hash_string );

  char one[] = "one";
  insert_hash_entry( table, one, ( void * ) 1 );

  char two[] = "two";
  insert_hash_entry( table, two, ( void * ) 2 );

  char three[] = "three";
  insert_hash_entry( table, three, ( void * ) 3 );

  char four[] = "four";
  insert_hash_entry( table, four, ( void * ) 4 );

  char five[] = "five";
  insert_hash_entry( table, five, ( void * ) 5 );

  char six[] = "six";
  insert_hash_entry( table, six, ( void * ) 6 );

  char seven[] = "seven";
  insert_hash_entry( table, seven, ( void * ) 7 );

  char eight[] = "eight";
  insert_hash_entry( table, eight, ( void * ) 8 );

  char nine[] = "nine";
  insert_hash_entry( table, nine, ( void * ) 9 );

  char ten[] = "ten";
  insert_hash_entry( table, ten, ( void * ) 10 );

  int sum = 0;
  hash_iterator iter;
  hash_entry *e;
  init_hash_iterator( table, &iter );
  while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
    sum += ( int ) ( uintptr_t ) e->value;
    delete_hash_entry( table, e->key );
  }
  assert_true( sum == 55 );

  delete_hash( table );
}
Exemple #26
0
static void
test_foreach() {
  table = create_hash( compare_string, hash_string );
  insert_hash_entry( table, alpha, alpha );
  insert_hash_entry( table, bravo, bravo );
  insert_hash_entry( table, charlie, charlie );
  delete_hash_entry( table, bravo );
  delete_hash_entry( table, charlie );

  foreach_hash( table, append_back_foreach, NULL );

  assert_string_equal( abc[ 0 ], "alpha" );
  assert_true( abc[ 1 ] == NULL );
  assert_true( abc[ 2 ] == NULL );

  delete_hash( table );
}
bool
finalize_redirector() {
  hash_iterator iter;
  hash_entry *entry;

  init_hash_iterator( host_db, &iter );
  while ( ( entry = iterate_hash_next( &iter ) ) != NULL ) {
      xfree( entry->value );
  }
  delete_hash( host_db );

  if ( fd >= 0 ) {
    set_readable( fd, false );
    delete_fd_handler( fd );
  }

  return finalize_tun();
}
void
print_with_graph_easy_format( void *param, size_t entries, const topology_link_status *s ) {
  size_t i;

  UNUSED( param );

  debug( "topology: entries %d", entries );

  hash_table *link_hash = create_hash( compare_link, hash_link );
  // show_topology graph-easy | graph-easy
  // Graph-Easy:
  //   http://search.cpan.org/~shlomif/Graph-Easy/bin/graph-easy
  printf("#! /usr/bin/env graph-easy\n" );

  for ( i = 0; i < entries; i++ ) {
    if ( s[ i ].status != TD_LINK_UP ) {
      continue;
    }
    topology_link_status r;
    r.from_dpid = s[ i ].to_dpid;
    r.from_portno = s[ i ].to_portno;
    r.to_dpid = s[ i ].from_dpid;
    r.to_portno = s[ i ].from_portno;

    topology_link_status *e = lookup_hash_entry( link_hash, &r );
    if ( e != NULL ) {
      delete_hash_entry( link_hash, e );
      print_link_status( e, true );
    } else {
      insert_hash_entry( link_hash, ( void * ) ( intptr_t ) &s[ i ], ( void *) ( intptr_t ) &s[ i ] );
    }
  }
  hash_iterator iter;
  init_hash_iterator( link_hash, &iter );
  hash_entry *e;
  while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
    topology_link_status *le = e->value;
    print_link_status( le, false );
  }

  delete_hash( link_hash );

  stop_trema();
}
Exemple #29
0
void
finalize_switch_port() {
  assert( switch_ports != NULL );

  hash_iterator iter;
  hash_entry *e;
  init_hash_iterator( switch_ports, &iter );
  while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
    switch_port *port = delete_hash_entry( switch_ports, e->key );
    if ( port == NULL ) {
      continue;
    }

    if ( port->device != NULL ) {
      delete_ether_device( port->device );
    }
    xfree( port );
  }
  delete_hash( switch_ports );
  switch_ports = NULL;
}
Exemple #30
0
void
finalize_match_table( void ) {
  list_element *list;

  pthread_mutex_lock( match_table_head.mutex );

  foreach_hash( match_table_head.exact_table, free_match_table_walker, NULL );
  delete_hash( match_table_head.exact_table );
  match_table_head.exact_table = NULL;

  for ( list = match_table_head.wildcard_table; list != NULL; list = list->next ) {
    free_match_entry( list->data );
  }
  delete_list( match_table_head.wildcard_table );
  match_table_head.wildcard_table = NULL;

  pthread_mutex_unlock( match_table_head.mutex );
  pthread_mutex_destroy( match_table_head.mutex );
  xfree( match_table_head.mutex );
  match_table_head.mutex = NULL;
}