Exemplo n.º 1
0
struct iface_config *del_iface(struct iface_config *ifc)
{
	struct iface_config	*next;
	int	i;

	next = ifc->next;

#if HAVE_LIBEVENT2
	event_free(ifc->event);
#endif
	pcap_freecode(&ifc->pcap_filter);
	pcap_close(ifc->pcap_handle);

	log_msg(LOG_DEBUG, "Closed interface %s", ifc->name);

	if (ifc->cache) {
		for (i = 0; i < cfg.hashsize; i++)
			if (*(ifc->cache + i))
				cache_prune(*(ifc->cache+i), ifc->cache+i);
		free(ifc->cache);
	}

	free(ifc);
	
	return next;

}
Exemplo n.º 2
0
/* function to handle the re-populating of the avl tree containing IP addresses
 * for deciding whether a connection of an incoming request is to be dropped.
 */
static void recheck_cached_file (cache_file_contents *cache, time_t now)
{
    if (now >= cache->file_recheck)
    {
        struct stat file_stat;
        FILE *file = NULL;
        int count = 0;
        char line [MAX_LINE_LEN];

        cache->file_recheck = now + 10;
        if (cache->filename == NULL)
        {
            cache_prune (cache);
            return;
        }
        if (stat (cache->filename, &file_stat) < 0)
        {
            WARN2 ("failed to check status of \"%s\": %s", cache->filename, strerror(errno));
            return;
        }
        if (file_stat.st_mtime == cache->file_mtime)
            return; /* common case, no update to file */

        cache->file_mtime = file_stat.st_mtime;

        file = fopen (cache->filename, "r");
        if (file == NULL)
        {
            WARN2("Failed to open file \"%s\": %s", cache->filename, strerror (errno));
            return;
        }

        cache_prune (cache);

        cache->contents = avl_tree_new (cache->compare, &cache->file_recheck);
        while (get_line (file, line, MAX_LINE_LEN))
        {
            if(!line[0] || line[0] == '#')
                continue;
            count++;
            cache->add_new_entry (cache, line, 0);
        }
        fclose (file);
        INFO2 ("%d entries read from file \"%s\"", count, cache->filename);
    }
}
Exemplo n.º 3
0
struct mcache_node *cache_lookup(uint8_t *l2_addr, uint8_t *ip_addr, 
	uint8_t len, time_t tstamp, uint16_t vlan_tag, struct mcache_node **cache)
{
	struct mcache_node *node;

	for (node = *cache; node != NULL; node = node->next) {
		/* New cache nodes are inserted at the begining of the list
		 * resulting cache list ordered by timestamp.
		 *
		 * If we find old cache node we can safely delete it and all
		 * following nodes.
		 */
		if (cfg.ratelimit > 0 && tstamp > node->tstamp + cfg.ratelimit) {
			cache_prune(node, cache);
			return NULL;
		}

		if (vlan_tag != node->vlan_tag)
			continue;

		if (len != node->addr_len)
			continue;

		if (memcmp(ip_addr, node->ip_addr, len))
			continue;

		if (memcmp(l2_addr, node->l2_addr, sizeof(node->l2_addr))) {
			cache_del(node, cache);
			return NULL;
		}

		return node;
	}

	return NULL;
}