示例#1
0
/* Returns true if 'wc' matches every packet, false if 'wc' fixes any bits or
 * fields. */
bool
flow_wildcards_is_catchall(const struct flow_wildcards *wc)
{
    int i;

    BUILD_ASSERT_DECL(FLOW_WC_SEQ == 8);

    if (wc->wildcards != FWW_ALL
        || wc->tun_id_mask != htonll(0)
        || wc->nw_src_mask != htonl(0)
        || wc->nw_dst_mask != htonl(0)
        || wc->tp_src_mask != htons(0)
        || wc->tp_dst_mask != htons(0)
        || wc->vlan_tci_mask != htons(0)
        || !ipv6_mask_is_any(&wc->ipv6_src_mask)
        || !ipv6_mask_is_any(&wc->ipv6_dst_mask)
        || wc->nw_frag_mask != 0) {
        return false;
    }

    for (i = 0; i < FLOW_N_REGS; i++) {
        if (wc->reg_masks[i] != 0) {
            return false;
        }
    }

    return true;
}
示例#2
0
static void
test_ipv6_static_masks(void)
{
    /* The 'exact' and 'any' addresses should be identical to
     * 'in6addr_exact' and  'in6addr_any' definitions, but we redefine
     * them here since the pre-defined ones are used in the functions
     * we're testing. */
    struct in6_addr exact   = {{{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, \
                                  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }}};

    struct in6_addr any     = {{{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \
                                  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }}};

    struct in6_addr neither = {{{ 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, \
                                  0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef }}};

    assert(ipv6_mask_is_exact(&exact));
    assert(!ipv6_mask_is_exact(&any));
    assert(!ipv6_mask_is_exact(&neither));

    assert(!ipv6_mask_is_any(&exact));
    assert(ipv6_mask_is_any(&any));
    assert(!ipv6_mask_is_any(&neither));

}
示例#3
0
文件: flow.c 项目: leihnwong/lazyctrl
/* Returns true if 'wc' matches every packet, false if 'wc' fixes any bits or
 * fields. */
bool
flow_wildcards_is_catchall(const struct flow_wildcards *wc)
{
    int i;

    BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);

    if (wc->wildcards != FWW_ALL
        || wc->tun_id_mask != htonll(0)
        || wc->nw_src_mask != htonl(0)
        || wc->nw_dst_mask != htonl(0)
        || wc->tp_src_mask != htons(0)
        || wc->tp_dst_mask != htons(0)
        || wc->vlan_tci_mask != htons(0)
        || wc->metadata_mask != htonll(0)
        || !eth_addr_is_zero(wc->dl_src_mask)
        || !eth_addr_is_zero(wc->dl_dst_mask)
        || !eth_addr_is_zero(wc->arp_sha_mask)
        || !eth_addr_is_zero(wc->arp_tha_mask)
        || !ipv6_mask_is_any(&wc->ipv6_src_mask)
        || !ipv6_mask_is_any(&wc->ipv6_dst_mask)
        || wc->ipv6_label_mask != htonl(0)
        || !ipv6_mask_is_any(&wc->nd_target_mask)
        || wc->nw_frag_mask != 0) {
        return false;
    }

    for (i = 0; i < FLOW_N_REGS; i++) {
        if (wc->reg_masks[i] != 0) {
            return false;
        }
    }

    return true;
}
示例#4
0
static void
test_ipv6_cidr(void)
{
    struct in6_addr dest;

    struct in6_addr src   = {{{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, \
                                0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }}};

    dest = ipv6_create_mask(0);
    assert(ipv6_mask_is_any(&dest));
    assert(ipv6_count_cidr_bits(&dest) == 0);
    assert(ipv6_is_cidr(&dest));

    dest = ipv6_create_mask(128);
    assert(ipv6_mask_is_exact(&dest));
    assert(ipv6_count_cidr_bits(&dest) == 128);
    assert(ipv6_is_cidr(&dest));

    dest = ipv6_create_mask(1);
    assert(ipv6_count_cidr_bits(&dest) == 1);
    assert(ipv6_is_cidr(&dest));

    dest = ipv6_create_mask(13);
    assert(ipv6_count_cidr_bits(&dest) == 13);
    assert(ipv6_is_cidr(&dest));

    dest = ipv6_create_mask(64);
    assert(ipv6_count_cidr_bits(&dest) == 64);
    assert(ipv6_is_cidr(&dest));

    dest = ipv6_create_mask(95);
    assert(ipv6_count_cidr_bits(&dest) == 95);
    assert(ipv6_is_cidr(&dest));

    dest = ipv6_create_mask(96);
    assert(ipv6_count_cidr_bits(&dest) == 96);
    assert(ipv6_is_cidr(&dest));

    dest = ipv6_create_mask(97);
    assert(ipv6_count_cidr_bits(&dest) == 97);
    assert(ipv6_is_cidr(&dest));

    dest = ipv6_create_mask(127);
    assert(ipv6_count_cidr_bits(&dest) == 127);
    assert(ipv6_is_cidr(&dest));

    src.s6_addr[8] = 0xf0;
    assert(ipv6_is_cidr(&src));
    assert(ipv6_count_cidr_bits(&src) == 68);

    src.s6_addr[15] = 0x01;
    assert(!ipv6_is_cidr(&src));
    src.s6_addr[15] = 0x00;
    assert(ipv6_is_cidr(&src));

    src.s6_addr[8] = 0x0f;
    assert(!ipv6_is_cidr(&src));
}
示例#5
0
文件: match.c 项目: AlickHill/Lantern
static void
format_ipv6_netmask(struct ds *s, const char *name,
                    const struct in6_addr *addr,
                    const struct in6_addr *netmask)
{
    if (!ipv6_mask_is_any(netmask)) {
        ds_put_format(s, "%s=", name);
        print_ipv6_masked(s, addr, netmask);
        ds_put_char(s, ',');
    }
}
示例#6
0
static void
nxm_put_ipv6(struct ofpbuf *b, uint32_t header,
             const struct in6_addr *value, const struct in6_addr *mask)
{
    if (ipv6_mask_is_any(mask)) {
        return;
    } else if (ipv6_mask_is_exact(mask)) {
        nxm_put_header(b, header);
        ofpbuf_put(b, value, sizeof *value);
    } else {
        nxm_put_header(b, NXM_MAKE_WILD_HEADER(header));
        ofpbuf_put(b, value, sizeof *value);
        ofpbuf_put(b, mask, sizeof *mask);
    }
}