Beispiel #1
0
void *ipv6_rem_list_by_ttl(void *args){
	struct info *ptr;
	struct info *prev;

        while(1){
	        /* lock ipv6 info */
                if(pthread_mutex_lock(&mutex_ipv6_info) != 0){
			err(EXIT_FAILURE, "pthread: ttl: ipv6_info lock failed");
                }

                if(ipv6_info.next != NULL){
			prev = &ipv6_info;
			ptr = &ipv6_info;
			while(ptr->next != NULL){
				prev = ptr;
				ptr = ptr->next;

				if(ptr->state == STATE_TTL || ptr->state == STATE_NONCE){
                                        if(ptr->ttl != 0xffffffff && ptr->ttl != 0){
                                                ptr->ttl--;
                                        }
					if(ptr->ttl == 0){
						/* for syslog */
						char log_eid_addr[100];
						char log_rloc_addr[100];
						inet_ntop(AF_INET6, ptr->address, log_eid_addr, 100);
						if(ptr->af == 1){
							inet_ntop(AF_INET, ptr->nexthop, log_rloc_addr, 100);
						}else if(ptr->af == 2){
							inet_ntop(AF_INET6, ptr->nexthop, log_rloc_addr, 100);
						}else if(ptr->af == 0){
							if(ptr->state == STATE_TTL){
								strcpy(log_rloc_addr, "NativelyForward");
							}else if(ptr->state == STATE_NONCE){
								strcpy(log_rloc_addr, "Drop");
							}
						}
						syslog_write(LOG_INFO, "removed cache by ttl: %s/%d -> %s", log_eid_addr, ptr->prefix, log_rloc_addr);

                				delete_prefix(2, ptr->address, ptr->prefix);
						prev->next = ptr->next;
						free(ptr);
						ptr = prev;
					}
				}
			}
		}

                /* unlock ipv6 info */
                if(pthread_mutex_unlock(&mutex_ipv6_info) != 0){
			err(EXIT_FAILURE, "pthread: ttl: ipv4_info unlock failed");
                }

		sleep(1);
        }
}
Beispiel #2
0
int ipv6_rem_list_by_nonce(char *nonce){
        struct info *ptr;
        struct info *prev;

        while(1){
                /* lock ipv6 info */
                if(pthread_mutex_lock(&mutex_ipv6_info) != 0){
			err(EXIT_FAILURE, "pthread: ttl: ipv6_info lock failed");
                }

                if(ipv6_info.next != NULL){
                        prev = &ipv6_info;
                        ptr = &ipv6_info;
                        while(ptr->next != NULL){
                                prev = ptr;
                                ptr = ptr->next;

                                if(ptr->state == STATE_NONCE){
                                        if(!memcmp(ptr->nonce, nonce, 8)){
						/* for syslog */
						char log_eid_addr[100];
						inet_ntop(AF_INET6, ptr->address, log_eid_addr, 100);
						syslog_write(LOG_INFO, "removed temporary cache: %s/%d", log_eid_addr, ptr->prefix);

                                                delete_prefix(2, ptr->address, ptr->prefix);

                                                prev->next = ptr->next;
                                                free(ptr);
                                                ptr = prev;

				                /* unlock ipv6 info */
				                if(pthread_mutex_unlock(&mutex_ipv6_info) != 0){
							err(EXIT_FAILURE, "pthread: ttl: ipv6_info unlock failed");
				                }
						return 1;
                                        }
                                }
                        }
                }

                /* unlock ipv6 info */
                if(pthread_mutex_unlock(&mutex_ipv6_info) != 0){
			err(EXIT_FAILURE, "pthread: ttl: ipv6_info unlock failed");
                }
		return 0;
        }  
}
Beispiel #3
0
bool switch_lpm_trie_delete(switch_lpm_trie_t *trie,
                            const char *prefix,
                            int prefix_length) {
  node_t *current_node = trie->root;
  byte_t byte;
  unsigned short prefix_key;
  value_t *pdata = NULL;

  while (prefix_length >= 8) {
    byte = (byte_t)*prefix;
    node_t *node = get_next_node(current_node, byte);
    if (!node) return NULL;

    prefix++;
    prefix_length -= 8;
    current_node = node;
  }

  if (prefix_length == 0)
    prefix_key = 0;
  else
    prefix_key = get_prefix_key((unsigned)prefix_length, (byte_t)*prefix);

  pdata = get_prefix_ptr(current_node, prefix_key);
  if (!pdata) return false;

  if (trie->release_memory) {
    assert(delete_prefix(current_node, prefix_key) == 1);
    current_node->pref_num--;
    while (current_node->pref_num == 0 && current_node->branch_num == 0) {
      node_t *tmp = current_node;
      current_node = current_node->parent;
      if (!current_node) break;
      assert(delete_branch(current_node, tmp->child_id) == 1);
      switch_free(tmp);
      current_node->branch_num--;
    }
  }

  trie->num_entries--;
  return true;
}