Esempio n. 1
0
int
update_block_list(char *addr, int err_level)
{
    size_t addr_len = strlen(addr);

    if (cache_key_exist(block_list, addr, addr_len)) {
        int *count = NULL;
        cache_lookup(block_list, addr, addr_len, &count);
        if (count != NULL) {
            if (*count > MAX_TRIES)
                return 1;
            (*count) += err_level;
        }
    } else if (err_level > 0) {
        int *count = (int *)ss_malloc(sizeof(int));
        *count = 1;
        cache_insert(block_list, addr, addr_len, count);
#ifdef __linux__
        if (mode != NO_FIREWALL_MODE)
            set_firewall_rule(addr, 1);
#endif
    }

    return 0;
}
Esempio n. 2
0
static void
free_firewall_rule(void *key, void *element)
{
    if (key == NULL)
        return;
    char *addr = (char *)key;
    set_firewall_rule(addr, 0);
    ss_free(element);
}
Esempio n. 3
0
int
remove_from_block_list(char *addr)
{
    size_t addr_len = strlen(addr);

#ifdef __linux__
    if (cache_key_exist(block_list, addr, addr_len))
        set_firewall_rule(addr, 0);
#endif

    return cache_remove(block_list, addr, addr_len);
}