コード例 #1
0
ファイル: vlan-bitmap.c プロジェクト: Danesca/openvswitch
/* Allocates and returns a new 4096-bit bitmap that has 1-bit in positions in
 * the 'n_vlans' bits indicated in 'vlans' and 0-bits everywhere else.  Returns
 * a null pointer if there are no (valid) VLANs in 'vlans'. */
unsigned long *
vlan_bitmap_from_array(const int64_t *vlans, size_t n_vlans)
{
    unsigned long *b;
    size_t i, n;

    if (!n_vlans) {
        return NULL;
    }

    b = bitmap_allocate(4096);
    n = 0;
    for (i = 0; i < n_vlans; i++) {
        int64_t vlan = vlans[i];

        if (vlan >= 0 && vlan < 4096) {
            bitmap_set1(b, vlan);
            n++;
        }
    }

    if (!n) {
        free(b);
        return NULL;
    }

    return b;
}
コード例 #2
0
ファイル: vlan-bitmap.c プロジェクト: 0day-ci/ovs
/* Adds to 4096-bit VLAN bitmap 'b' a 1-bit in each position in the 'n_vlans'
 * bits indicated in 'vlans'.  Returns the number of 1-bits added to 'b'. */
int
vlan_bitmap_from_array__(const int64_t *vlans, size_t n_vlans,
                         unsigned long int *b)
{
    size_t i;
    int n;

    n = 0;
    for (i = 0; i < n_vlans; i++) {
        int64_t vlan = vlans[i];

        if (vlan >= 0 && vlan < 4096 && !bitmap_is_set(b, vlan)) {
            bitmap_set1(b, vlan);
            n++;
        }
    }

    return n;
}
コード例 #3
0
ファイル: binding.c プロジェクト: 0day-ci/ovs
static void
update_ct_zones(struct sset *lports, struct simap *ct_zones,
                unsigned long *ct_zone_bitmap)
{
    struct simap_node *ct_zone, *ct_zone_next;
    const char *iface_id;
    int scan_start = 1;

    /* xxx This is wasteful to assign a zone to each port--even if no
     * xxx security policy is applied. */

    /* Delete any zones that are associated with removed ports. */
    SIMAP_FOR_EACH_SAFE(ct_zone, ct_zone_next, ct_zones) {
        if (!sset_contains(lports, ct_zone->name)) {
            bitmap_set0(ct_zone_bitmap, ct_zone->data);
            simap_delete(ct_zones, ct_zone);
        }
    }

    /* Assign a unique zone id for each logical port. */
    SSET_FOR_EACH(iface_id, lports) {
        size_t zone;

        if (simap_contains(ct_zones, iface_id)) {
            continue;
        }

        /* We assume that there are 64K zones and that we own them all. */
        zone = bitmap_scan(ct_zone_bitmap, 0, scan_start, MAX_CT_ZONES + 1);
        if (zone == MAX_CT_ZONES + 1) {
            static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
            VLOG_WARN_RL(&rl, "exhausted all ct zones");
            return;
        }
        scan_start = zone + 1;

        bitmap_set1(ct_zone_bitmap, zone);
        simap_put(ct_zones, iface_id, zone);

        /* xxx We should erase any old entries for this
         * xxx zone, but we need a generic interface to the conntrack
         * xxx table. */
    }