Exemplo n.º 1
0
void Set_routes::remove_empty_routes() {
	for (int i = get_num_routes() - 1; i >= 0; i--) {
		if (get_size_route(i) == 0) {
			remove_route(i);
		}
	}
}
Exemplo n.º 2
0
void Solution::merge_paths(int i, int j) {

	for (int k = 0; k < get_size_route(j); ++k) {
		printf("Trying to put stop %d fro; route %d to route %d \n",get_stop_route(j, k),j,i);
		int stopno = get_stop_route(j, k);
		//remove_stop_pos_route(j,k);
		insert_stop_route(stopno, i, get_size_route(i));
	}
	remove_route(j);
}
Exemplo n.º 3
0
/*!	Removes the default routes as set by AddDefaultRoutes() again. */
void
InterfaceAddress::RemoveDefaultRoutes(int32 option)
{
	net_route route;
	route.destination = local;
	route.gateway = NULL;
	route.interface_address = this;

	if (mask != NULL && (option == SIOCSIFNETMASK || option == SIOCSIFADDR)) {
		route.mask = mask;
		route.flags = 0;
		remove_route(domain, &route);
	}

	if (option == SIOCSIFADDR) {
		route.mask = NULL;
		route.flags = RTF_LOCAL | RTF_HOST;
		remove_route(domain, &route);
	}
}
/**
 * Removes an interface with the given name from the table
 * 
 * @param[in] ifname
 *     Interface name
 * 
 * @param[in] af
 *     Address family
 * 
 * @param[in] interface_exists 
 *      TRUE if the interface still exists (we need to remvoe filters from it);
 *      FALSE if it was deleted so we don't need to worry about deleting filters
 */
void
policy_table_delete_policy(char *ifname, uint8_t af, boolean interface_exists)
{
    hash_key_t k;
    policy_table_entry_t * policy;
    ped_policy_route_t  * route = NULL, * route_tmp = NULL;

    INSIST(if_table != NULL);
    INSIST(ifname != NULL);
    INSIST(strlen(ifname) <= MAX_IF_NAME_LEN);
    
    junos_trace(PED_TRACEFLAG_HT, "%s(%s, %d)", __func__, ifname, af);

    strcpy(k.ifname, ifname);
    k.af = af;

    policy = ht_remove(if_table, &k); // frees the key

    if(policy == NULL) return;
     
    // remove and delete filters only if the interface still exists
    // (if interface is deleted so are all attached filters)
    if(interface_exists) {
        if(policy->filter) {
            remove_filters_from_interface(ifname);
            free(policy->filter);
        }
        
        if(policy->pfd_filter) {
            remove_pfd_filter_from_interface(policy->ifname);
            policy->pfd_filter = FALSE;
        }
    }
    
    // remove and delete routes
    
    route = policy->route;
    while(route) {
        route_tmp = route;      // Save pointer to current route.
        route = route->next;    // Move to the next route.
        if(route->status != ROUTE_FAILED) {
            remove_route(route_tmp);
            if(route->status == ROUTE_PENDING) {
                --changes_pending;
            }
        }
        free(route_tmp);        // Free the current route data.
    }

    free(policy);
}
Exemplo n.º 5
0
status_t
control_routes(struct net_interface* _interface, net_domain* domain,
	int32 option, void* argument, size_t length)
{
	TRACE("control_routes(interface %p, domain %p, option %" B_PRId32 ")\n",
		_interface, domain, option);
	Interface* interface = (Interface*)_interface;

	switch (option) {
		case SIOCADDRT:
		case SIOCDELRT:
		{
			// add or remove a route
			if (length != sizeof(struct ifreq))
				return B_BAD_VALUE;

			route_entry entry;
			if (user_memcpy(&entry, &((ifreq*)argument)->ifr_route,
					sizeof(route_entry)) != B_OK)
				return B_BAD_ADDRESS;

			net_route_private route;
			status_t status;
			if ((status = user_copy_address(entry.destination,
					&route.destination)) != B_OK
				|| (status = user_copy_address(entry.mask, &route.mask)) != B_OK
				|| (status = user_copy_address(entry.gateway, &route.gateway))
					!= B_OK)
				return status;

			InterfaceAddress* address
				= interface->FirstForFamily(domain->family);

			route.mtu = entry.mtu;
			route.flags = entry.flags;
			route.interface_address = address;

			if (option == SIOCADDRT)
				status = add_route(domain, &route);
			else
				status = remove_route(domain, &route);

			if (address != NULL)
				address->ReleaseReference();
			return status;
		}
	}
	return B_BAD_VALUE;
}
Exemplo n.º 6
0
void
invalidate_routes(net_domain* _domain, net_interface* interface)
{
	net_domain_private* domain = (net_domain_private*)_domain;
	RecursiveLocker locker(domain->lock);

	TRACE("invalidate_routes(%i, %s)\n", domain->family, interface->name);

	RouteList::Iterator iterator = domain->routes.GetIterator();
	while (iterator.HasNext()) {
		net_route* route = iterator.Next();

		if (route->interface_address->interface == interface)
			remove_route(domain, route);
	}
}
/**
 * Clear everything except for the pfd_filter (no PSD policy for interface).
 * The policy will have no routes or filters afterward. If the policy does not 
 * exist it will be created.
 * 
 * @param[in] ifname
 *     The interface name of the policy
 * 
 * @param[in] af
 *      The address family for the interface name of the policy
 */
void
policy_table_clear_policy(char *ifname, uint8_t af)
{
    policy_table_entry_t * policy;
    ped_policy_route_t  * route = NULL, * route_tmp = NULL;

    INSIST(if_table != NULL);
    INSIST(ifname != NULL);
    INSIST(strlen(ifname) <= MAX_IF_NAME_LEN);
    
    junos_trace(PED_TRACEFLAG_HT, "%s(%s, %d)", __func__, ifname, af);

    policy = get_or_create_policy(ifname, af);

    // just remove anything but the pfd filter

    if(policy->broken) {
        return;
    }
    
    if(policy->filter) {
        free(policy->filter);
        policy->filter = NULL;
    }
        
    if(!remove_filters_from_interface(ifname)) {
        policy->broken = TRUE; // break it so it gets cleaned
        
        ERRMSG(PED, TRACE_LOG_ERR, "%s: Failed to remove "
            "filters on interface ", __func__, ifname);
    }
    
    route = policy->route;
    policy->route = NULL;
    
    while(route) {
        route_tmp = route;      // Save pointer to current route
        route = route->next;    // Move to the next route
        remove_route(route_tmp);
        if(route->status == ROUTE_PENDING) {
            --changes_pending;
        }
        free(route_tmp);        // Free the current route data.
    }
}
Exemplo n.º 8
0
void
invalidate_routes(InterfaceAddress* address)
{
	net_domain_private* domain = (net_domain_private*)address->domain;

	TRACE("invalidate_routes(%s)\n",
		AddressString(domain, address->local).Data());

	RecursiveLocker locker(domain->lock);

	RouteList::Iterator iterator = domain->routes.GetIterator();
	while (iterator.HasNext()) {
		net_route* route = iterator.Next();

		if (route->interface_address == address)
			remove_route(domain, route);
	}
}
Exemplo n.º 9
0
void Set_routes::clear() {
	int num_routes = get_num_routes(); /* Number of routes*/
	for (int i = 0; i < num_routes; i++) {
		remove_route(0);
	}
}
/**
 * Clean policy table, remove all UNVERIFIED filters and routes.
 * Anything left in the UNVERIFIED state (status) will be deleted.
 */
void
policy_table_clean(void)
{
    policy_table_entry_t * policy = NULL;
    ped_policy_route_t * route_tmp = NULL, * route = NULL;
    struct hashtable_itr * iterator = NULL;
    
    if(hashtable_count(if_table) < 1 || !clean_table ||
       !get_ssd_ready() || !get_ssd_idle()) {
        return; // nothing to do or don't clean yet
    }
    
    junos_trace(PED_TRACEFLAG_HT, "%s", __func__);
    
    iterator = hashtable_iterator(if_table); // mallocs
    INSIST(iterator != NULL);

    // go through all policies
    do {
        policy = hashtable_iterator_value(iterator);
        
        // if we have a broken policy, then remove it
        if(policy->broken) {
            
            // remove and delete filters
            if(policy->filter) {
                remove_filters_from_interface(policy->ifname);
                free(policy->filter);
            }
            
            if(policy->pfd_filter) {
                remove_pfd_filter_from_interface(policy->ifname);
                policy->pfd_filter = FALSE;
            }
            
            // remove and delete routes
            
            route = policy->route;
            while(route) {
                route_tmp = route;      // Save pointer to current route.
                route = route->next;    // Move to the next route.
                if(route_tmp->status != ROUTE_FAILED) {
                    remove_route(route_tmp);
                    if(route->status == ROUTE_PENDING) {
                        --changes_pending;
                    }
                }
                free(route_tmp);        // Free the current route data.
            }

            free(policy);
            
            if(hashtable_iterator_remove(iterator))
                continue;
            else
                break;
        }
        
        // else: policy is not broken 
        // but we will check for routes or filters that don't belong
        
        
        // Check filter:
        if(policy->filter && policy->filter->status == FILTER_UNVERIFIED) {
            free(policy->filter);
            policy->filter = NULL;
            remove_filters_from_interface(policy->ifname);
        }
        
        if(!policy->pfd_filter) {
            policy->pfd_filter = apply_pfd_filter_to_interface(policy->ifname);
        }

        // Check route(s):        
        route = policy->route;
        route_tmp = NULL;
        policy->route = NULL;  // Detach route list temporarily
        
        while(route) {
            
            // check we don't get FAILED routes (in non-broken policies)
            if(route->status == ROUTE_FAILED) {
                // log and crash because this shouldn't happen
                ERRMSG(PED, TRACE_LOG_EMERG, 
                    "%s: Found a route with status=FAILED in a non-broken "
                    "policy. This should not happen.", __func__);
                // abort() is called in the above ERRMSG
            }
            
            // its status should probably be ADDED...
            // unless it's not part of the PSD policy anymore it will be:
            // UNVERIFIED
            if(route->status == ROUTE_UNVERIFIED) {
                // we've received all routes from the PSD, so it is  
                // no longer part of the policy, and we need to delete it
                
                // copy route data into new mem to pass to callback
                // we choose to do this only when policy is not broken
                
                if(route_tmp) { // route_tmp points to last kept route

                    route_tmp->next = route->next;
                    
                    remove_route(route);
                    free(route);
                    
                    // make route point to the next route (in tmp->next) and
                    route = route_tmp->next;
                    
                } else {  // No previous routes that we've kept yet
                    
                    // use tmp ptr to save next
                    route_tmp = route->next;
                    
                    remove_route(route);
                    free(route);
                    
                    // restore route to next route (in tmp) and tmp to NULL
                    route = route_tmp;
                    route_tmp = NULL;
                }
            } else { // a route we are keeping

                if(policy->route == NULL) {
                    policy->route = route;  // First route in the new list
                }
                
                route_tmp = route; // move route_tmp to end
                route = route->next;
            }
        }
        
        // Done checking route(s)
        
    } while (hashtable_iterator_advance(iterator));

    free(iterator);
    
    clean_table = FALSE;
}