static void* convertible(PyObject* obj)
 {
     // Find a converter registration which can produce a Source
     // instance from obj
     return const_cast<rvalue_from_python_registration*>(
         find_chain(obj, rvalue_from_python_chain<Source>::value));
 }
Exemple #2
0
int ebtc_is_chain (const char *chainname, const ebtc_handle_t handle)
{


    return find_chain(chainname, handle) ? 0 : -1;

}
Exemple #3
0
const struct ebt_entry *ebtc_next_rule (const char *chainname,
                                        ebtc_handle_t *handle)
{


    chain_list_t            *chain;

    rule_list_t             *rule;




    chain = find_chain(chainname, *handle);

    if (!chain) {

        (*handle)->error_no = ERR_CHAINNOTFOUND;

        return NULL;

    }

    if (!chain->rules.cur)
        return NULL;

    rule = chain->rules.cur = chain->rules.cur->next;

    (*handle)->error_no = SUCCESS;

    return rule ? rule->entry : NULL;

}
Exemple #4
0
int ebtc_set_policy (const char *chainname, const char *policy,
                     ebtc_handle_t *handle)
{


    int                     i;

    int                     id = 0;

    chain_list_t            *chain = (*handle)->chains.first;




    

    for (i = 0; ; i++) {

        if (!*targets[i].name) {

            (*handle)->error_no = ERR_POLICYNOTFOUND;

            return -1;

        }

        if (!strcmp(policy, targets[i].name)) {

            id = targets[i].id;
            break;

        }

    }

    

    chain = find_chain(chainname, *handle);

    if (!chain) {

        (*handle)->error_no = ERR_CHAINNOTFOUND;

        return -1;

    }

    if (chain->entries.policy != id) {

        chain->entries.policy = id;
        (*handle)->changed = EBTC_TRUE;

    }

    (*handle)->error_no = SUCCESS;

    return 0;

}
Exemple #5
0
int ebtc_create_chain (const char *chainname, ebtc_handle_t *handle)
{


    chain_list_t            *chain;




    

    chain = find_chain(chainname, *handle);

    if (chain) {

        (*handle)->error_no = ERR_CHAINEXIST;

        return -1;

    }

    

    chain = (chain_list_t *)malloc(sizeof(chain_list_t));

    if (!chain) {

        (*handle)->error_no = ERR_ALLOCATEMEM;

        return -1;

    }

    memset(chain, 0, sizeof(chain_list_t));

    chain->hookid = NF_BR_NUMHOOKS;
    chain->id = (*handle)->chains.last_id++;

    snprintf(chain->entries.name, EBT_CHAIN_MAXNAMELEN, "%s", chainname);
    chain->entries.policy = EBT_ACCEPT;

    if ((*handle)->chains.last) {

        (*handle)->chains.last->next = chain;
        (*handle)->chains.last = chain;

    } else
        (*handle)->chains.last = (*handle)->chains.first = chain;

    (*handle)->changed = EBTC_TRUE;
    (*handle)->error_no = SUCCESS;

    return 0;

}
Exemple #6
0
/**
 * Configures the irreducible polynomial of the binary field.
 *
 * @param[in] f				- the new irreducible polynomial.
 */
static void fb_poly_set(const fb_t f) {
	fb_copy(core_get()->fb_poly, f);
#if FB_TRC == QUICK || !defined(STRIP)
	find_trace();
#endif
#if FB_SLV == QUICK || !defined(STRIP)
	find_solve();
#endif
#if FB_SRT == QUICK || !defined(STRIP)
	find_srz();
#endif
#if FB_INV == ITOHT || !defined(STRIP)
	find_chain();
#endif
}
Exemple #7
0
int ebtc_set_counter (const char *chainname, unsigned int rulenum,
                      const struct ebt_counter *counter, ebtc_handle_t *handle)
{


    chain_list_t            *chain;

    rule_list_t             *rule;




    

    chain = find_chain(chainname, *handle);

    if (!chain) {

        (*handle)->error_no = ERR_CHAINNOTFOUND;

        return -1;

    }

    

    rule = chain->rules.first;

    for (; rulenum > 0 && rule; rulenum--)
        rule = rule->next;

    if (rulenum || !rule) {

        (*handle)->error_no = ERR_RULENUM;

        return -1;

    }

    memcpy(&rule->counter.counter, counter, sizeof(ebt_counter_t));
    rule->counter.changed = EBTC_TRUE;

    (*handle)->changed = EBTC_TRUE;
    (*handle)->error_no = SUCCESS;

    return 0;

}
Exemple #8
0
int ebtc_flush_entries (const char *chainname, ebtc_handle_t *handle)
{


    chain_list_t            *chain;

    rule_list_t             *rule;

    rule_list_t             *rule_next;




    

    chain = find_chain(chainname, *handle);

    if (!chain) {

        (*handle)->error_no = ERR_CHAINNOTFOUND;

        return -1;

    }

    

    rule = chain->rules.first;

    while (rule) {

        rule_next = rule->next;

        free(rule);

        rule = rule_next;

    }

    memset(&chain->rules, 0, sizeof(chain->rules));

    (*handle)->changed = EBTC_TRUE;
    (*handle)->error_no = SUCCESS;

    return 0;

}
Exemple #9
0
int ebtc_is_builtin (const char *chainname, const ebtc_handle_t *handle)
{


    chain_list_t            *chain;




    chain = find_chain(chainname, *handle);

    if (!chain)
        return -1;

    return chain->hookid == NF_BR_NUMHOOKS ? -1 : 0;

}
Exemple #10
0
const struct ebt_counter *ebtc_read_counter (const char *chainname,
                                             unsigned int rulenum,
                                             ebtc_handle_t *handle)
{


    chain_list_t            *chain;

    rule_list_t             *rule;




    

    chain = find_chain(chainname, *handle);

    if (!chain) {

        (*handle)->error_no = ERR_CHAINNOTFOUND;

        return NULL;

    }

    

    rule = chain->rules.first;

    for (; rulenum > 0 && rule; rulenum--)
        rule = rule->next;

    if (rulenum || !rule) {

        (*handle)->error_no = ERR_RULENUM;

        return NULL;

    }

    (*handle)->error_no = SUCCESS;

    return &rule->counter.counter;

}
Exemple #11
0
const char *ebtc_get_policy (const char *chainname, const ebtc_handle_t *handle)
{


    int                     i;

    chain_list_t            *chain;

    chain2id_t              *chain2id;




    

    chain = find_chain(chainname, *handle);

    if (!chain) {

        (*handle)->error_no = ERR_CHAINNOTFOUND;

        return NULL;

    }

    

    for (chain2id = targets; *chain2id->name; chain2id++) {

        if (chain->entries.policy == chain2id->id) {

            (*handle)->error_no = SUCCESS;

            return chain2id->name;

        }

    }

    return NULL;

}
Exemple #12
0
int ebtc_zero_entries (const char *chainname, ebtc_handle_t *handle)
{


    chain_list_t            *chain;

    rule_list_t             *rule;




    

    chain = find_chain(chainname, *handle);

    if (!chain) {

        (*handle)->error_no = ERR_CHAINNOTFOUND;

        return -1;

    }

    

    rule = chain->rules.first;

    while (rule) {

        memset(&rule->counter.counter, 0, sizeof(ebt_counter_t));
        rule->counter.changed = EBTC_TRUE;

        rule = rule->next;

    }

    (*handle)->changed = EBTC_TRUE;
    (*handle)->error_no = SUCCESS;

    return 0;

}
/**
 * Configures the irreducible polynomial of the binary field.
 *
 * @param[in] f				- the new irreducible polynomial.
 */
static void fb_poly_set(fb_t f) {
	fb_copy(fb_poly, f);
#if FB_TRC == QUICK || !defined(STRIP)
	find_trace();
#endif
#if FB_SLV == QUICK || !defined(STRIP)
	find_solve();
#endif
#if FB_SRT == QUICK || !defined(STRIP)
	find_srz();
#endif
#if FB_INV == ITOHT || FB_INV == LOWER || !defined(STRIP)
	find_chain();
#endif

#ifdef WITH_PB
	/* Refresh configuration on pairing module. */
	pb_map_init();
#endif
}
Exemple #14
0
int ebtc_rename_chain (const char *chainname_old, const char *chainname_new,
                       ebtc_handle_t *handle)
{


    chain_list_t            *chain;




    

    chain = find_chain(chainname_old, *handle);

    if (!chain) {

        (*handle)->error_no = ERR_CHAINNOTFOUND;

        return -1;

    }

    if (chain->hookid != NF_BR_NUMHOOKS) { 

        (*handle)->error_no = ERR_BUILTINCHAIN;

        return -1;

    }

    

    snprintf(chain->entries.name, EBT_CHAIN_MAXNAMELEN, "%s", chainname_new);

    (*handle)->changed = EBTC_TRUE;

    return 0;

}
int main()
{
	get_data_from_keyboard();
	find_chain(people,n);
	return 0;
}
Exemple #16
0
int ebtc_target_jumptochain (ebt_standard_target_t *target, char *chainname,
                             ebtc_handle_t *handle)
{


    int                     i;

    chain_list_t            *chain;




    

    target->target.target_size = EBTC_SIZEOF(ebt_standard_target_t);
    target->target.target_size -= EBTC_SIZEOF(ebt_entry_target_t);

    snprintf(target->target.u.name, EBT_FUNCTION_MAXNAMELEN, "standard");

    

    for (i = 0; *targets[i].name; i++) {

        if (!strcmp(chainname, targets[i].name)) {

            target->verdict = targets[i].id;

            return 0;

        }

    }

    

    for (i = 0; *targets[i].name; i++) {

        if (!strcmp(chainname, targets[i].name)) {

            target->verdict = targets[i].id;

            return 0;

        }

    }

    

    chain = find_chain(chainname, *handle);

    if (!chain) {

        (*handle)->error_no = ERR_CHAINNOTFOUND;

        return -1;

    }

    if (chain->hookid != NF_BR_NUMHOOKS) {

        (*handle)->error_no = ERR_STDCHAINNOTALLOW;

        return -1;

    }

    target->verdict = chain->id;

    return 0;

}
Exemple #17
0
int ebtc_insert_entry (const char *chainname, const struct ebt_entry *entry,
                       unsigned int rulenum, ebtc_handle_t *handle)
{


    chain_list_t            *chain;

    rule_list_t             *rule_last = NULL;

    rule_list_t             *rule_cur;

    rule_list_t             *rule;

    unsigned int            size;




    if (check_entry(entry)) {

        (*handle)->error_no = ERR_BADENTRY;

        return -1;

    }

    

    chain = find_chain(chainname, *handle);

    if (!chain) {

        (*handle)->error_no = ERR_CHAINNOTFOUND;

        return -1;

    }

    

    size = sizeof(rule_list_t) + entry->next_offset;
    rule = (rule_list_t *)malloc(size);

    if (!rule) {

        (*handle)->error_no = ERR_ALLOCATEMEM;

        return -1;

    }

    memset(rule, 0, size);

    rule->entry = (ebt_entry_t *)(rule + 1);
    memcpy(rule->entry, entry, entry->next_offset);

    rule_cur = chain->rules.first;

    if (rule_cur) {

        for (; rulenum > 0 && rule_cur; rulenum--) {

            rule_last = rule_cur;
            rule_cur = rule_cur->next;

        }

        if (rulenum || !rule_cur) {

            (*handle)->error_no = ERR_RULENUM;

            return -1;

        }

        if (rule_last)
            rule_last->next = rule;
        else
            chain->rules.first = rule;

        rule->next = rule_cur;

    } else {

        if (rulenum != 0) {

            (*handle)->error_no = ERR_RULENUM;

            return -1;

        }

        chain->rules.first = chain->rules.last = rule;

    }

    chain->rules.count++;
    chain->rules.size += entry->next_offset;

    (*handle)->changed = EBTC_TRUE;
    (*handle)->error_no = SUCCESS;

    return 0;

}
Exemple #18
0
int ebtc_delete_entry (const char *chainname, unsigned int rulenum,
                       ebtc_handle_t *handle)
{


    chain_list_t            *chain;

    rule_list_t             *rule_last = NULL;

    rule_list_t             *rule;




    

    chain = find_chain(chainname, *handle);

    if (!chain) {

        (*handle)->error_no = ERR_CHAINNOTFOUND;

        return -1;

    }

    

    rule = chain->rules.first;

    if (!rule) {

        (*handle)->error_no = ERR_RULENUM;

        return -1;

    }

    for (; rulenum > 0 && rule; rulenum--) {

        rule_last = rule;
        rule = rule->next;

    }

    if (rulenum || !rule) {

        (*handle)->error_no = ERR_RULENUM;

        return -1;

    }

    if (rule_last)
        rule_last->next = rule->next;
    else
        chain->rules.first = rule->next;

    if (!rule->next)
        chain->rules.last = rule_last;

    chain->rules.count--;
    chain->rules.size -= rule->entry->next_offset;

    (*handle)->changed = EBTC_TRUE;

    

    free(rule);

    (*handle)->error_no = SUCCESS;

    return 0;

}
Exemple #19
0
int ebtc_replace_entry (const char *chainname, const struct ebt_entry *entry,
                        unsigned int rulenum, ebtc_handle_t *handle)
{


    chain_list_t            *chain;

    rule_list_t             *rule_last = NULL;

    rule_list_t             *rule_old;

    rule_list_t             *rule_new;

    unsigned int            size;




    if (check_entry(entry)) {

        (*handle)->error_no = ERR_BADENTRY;

        return -1;

    }

    

    chain = find_chain(chainname, *handle);

    if (!chain) {

        (*handle)->error_no = ERR_CHAINNOTFOUND;

        return -1;

    }

    

    size = sizeof(rule_list_t) + entry->next_offset;
    rule_new = (rule_list_t *)malloc(size);

    if (!rule_new) {

        (*handle)->error_no = ERR_ALLOCATEMEM;

        return -1;

    }

    memset(rule_new, 0, size);

    rule_new->entry = (ebt_entry_t *)(rule_new + 1);
    memcpy(rule_new->entry, entry, entry->next_offset);

    rule_old = chain->rules.first;

    if (!rule_old) {

        (*handle)->error_no = ERR_RULENUM;

        return -1;

    }

    for (; rulenum > 0 && rule_old; rulenum--) {

        rule_last = rule_old;
        rule_old = rule_old->next;

    }

    if (rulenum || !rule_old) {

        (*handle)->error_no = ERR_RULENUM;

        return -1;

    }

    if (rule_last)
        rule_last->next = rule_new;
    else
        chain->rules.first = rule_new;

    rule_new->next = rule_old->next;

    if (!rule_new->next)
        chain->rules.last = rule_new;

    chain->rules.size -= rule_old->entry->next_offset;
    chain->rules.size += entry->next_offset;

    (*handle)->changed = EBTC_TRUE;

    

    free(rule_old);

    (*handle)->error_no = SUCCESS;

    return 0;

}