Beispiel #1
0
static void
process_expanded_assignment(ipset_iterator_t *iterator)
{
    if (iterator->assignment_iterator->finished)
    {
        /*
         * If there isn't anything in the expanded assignment, advance
         * to the next BDD assignment.
         */

        g_d_debug("Expanded assignment is finished");

        ipset_expanded_assignment_free(iterator->assignment_iterator);
        iterator->assignment_iterator = NULL;

        advance_assignment(iterator);
    } else {
        /*
         * Otherwise, we've found a fully expanded assignment, so
         * create an IP address for it and return.
         */

        create_ip_address(iterator);
    }
}
Beispiel #2
0
void
ipset_iterator_free(ipset_iterator_t *iterator)
{
    if (iterator == NULL)
        return;

    ipset_bdd_iterator_free(iterator->bdd_iterator);
    ipset_expanded_assignment_free(iterator->assignment_iterator);
    g_slice_free(ipset_iterator_t, iterator);
}
Beispiel #3
0
void
ipset_iterator_free(struct ipset_iterator *iterator)
{
    if (iterator->bdd_iterator != NULL) {
        ipset_bdd_iterator_free(iterator->bdd_iterator);
    }
    if (iterator->assignment_iterator != NULL) {
        ipset_expanded_assignment_free(iterator->assignment_iterator);
    }
    free(iterator);
}
Beispiel #4
0
END_TEST


START_TEST(test_bdd_assignment_expand_3)
{
    ipset_assignment_t  *a;

    a = ipset_assignment_new();
    ipset_assignment_set(a, 0, TRUE);
    ipset_assignment_set(a, 2, FALSE);

    ipset_expanded_assignment_t  *it;
    it = ipset_assignment_expand(a, 3);

    GByteArray  *ea = g_byte_array_sized_new(1);
    memset(ea->data, 0, 1);

    fail_if(it->finished,
            "Expanded assignment shouldn't be empty");
    IPSET_BIT_SET(ea->data, 0, TRUE);
    IPSET_BIT_SET(ea->data, 1, FALSE);
    IPSET_BIT_SET(ea->data, 2, FALSE);
    fail_unless(memcmp(ea->data, it->values->data, 1) == 0,
                "Expanded assignment 1 doesn't match");

    ipset_expanded_assignment_advance(it);
    fail_if(it->finished,
                "Expanded assignment should have at least 1 element");
    IPSET_BIT_SET(ea->data, 0, TRUE);
    IPSET_BIT_SET(ea->data, 1, TRUE);
    IPSET_BIT_SET(ea->data, 2, FALSE);
    fail_unless(memcmp(ea->data, it->values->data, 1) == 0,
                "Expanded assignment 2 doesn't match");

    ipset_expanded_assignment_advance(it);
    fail_unless(it->finished,
                "Expanded assignment should have 2 elements");

    g_byte_array_free(ea, TRUE);
    ipset_expanded_assignment_free(it);
    ipset_assignment_free(a);
}
Beispiel #5
0
static void
process_assignment(struct ipset_iterator *iterator)
{
    while (!iterator->bdd_iterator->finished) {
        if (iterator->bdd_iterator->value == iterator->desired_value) {
            /* If the BDD iterator hasn't finished, and the result of
             * the function with this assignment matches what the caller
             * wants, then we've found an assignment to generate IP
             * addresses from.
             *
             * Try to expand this assignment, and process the first
             * expanded assignment.  We want 32 + 1 variables if the
             * current address is IPv4; 128 + 1 if it's IPv6. */

            DEBUG("Got a matching BDD assignment");
            enum ipset_tribool  address_type = ipset_assignment_get
                (iterator->bdd_iterator->assignment, 0);

            if (address_type == IPSET_FALSE) {
                /* FALSE means IPv6*/
                DEBUG("Assignment is IPv6");
                iterator->multiple_expansion_state = IPSET_ITERATOR_NORMAL;
                expand_ipv6(iterator);
                return;
            } else if (address_type == IPSET_TRUE) {
                /* TRUE means IPv4*/
                DEBUG("Assignment is IPv4");
                iterator->multiple_expansion_state = IPSET_ITERATOR_NORMAL;
                expand_ipv4(iterator);
                return;
            } else {
                /* EITHER means that this assignment contains both IPv4
                 * and IPv6 addresses.  Expand it as IPv4 first. */
                DEBUG("Assignment is both IPv4 and IPv6");
                DEBUG("Expanding IPv4 first");
                iterator->multiple_expansion_state =
                    IPSET_ITERATOR_MULTIPLE_IPV4;
                ipset_assignment_set
                    (iterator->bdd_iterator->assignment, 0, IPSET_TRUE);
                expand_ipv4(iterator);
                return;
            }
        }

        /* The BDD iterator has a value, but it doesn't match the one we
         * want.  Advance the BDD iterator and try again. */
        DEBUG("Value is %d, skipping", iterator->bdd_iterator->value);
        ipset_bdd_iterator_advance(iterator->bdd_iterator);
    }

    /* If we fall through, then the BDD iterator has finished.  That
     * means there's nothing left for the set iterator. */

    DEBUG("Set iterator is finished");
    ipset_expanded_assignment_free(iterator->assignment_iterator);
    iterator->assignment_iterator = NULL;

    ipset_bdd_iterator_free(iterator->bdd_iterator);
    iterator->bdd_iterator = NULL;
    iterator->finished = true;
}