From: Justin Pettit Date: Thu, 10 Nov 2011 01:42:17 +0000 (-0800) Subject: classifier: Don't check masks when adding IPv4/IPv6 addresses. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=209c0b17d90b8062e5a3cbd80a083ea02e18d880;p=openvswitch classifier: Don't check masks when adding IPv4/IPv6 addresses. The meta-flow code enforces IPv4/IPv6 masks, so there's no reason to do it again in the classifier. This allows a number of functions to be removed, since the only callers were in this classifier code. --- diff --git a/lib/classifier.c b/lib/classifier.c index 253a4d8b..9903ab70 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -286,35 +286,30 @@ cls_rule_set_nw_proto(struct cls_rule *rule, uint8_t nw_proto) void cls_rule_set_nw_src(struct cls_rule *rule, ovs_be32 nw_src) { - cls_rule_set_nw_src_masked(rule, nw_src, htonl(UINT32_MAX)); + rule->flow.nw_src = nw_src; + rule->wc.nw_src_mask = htonl(UINT32_MAX); } -bool -cls_rule_set_nw_src_masked(struct cls_rule *rule, ovs_be32 ip, ovs_be32 mask) +void +cls_rule_set_nw_src_masked(struct cls_rule *rule, + ovs_be32 nw_src, ovs_be32 mask) { - if (flow_wildcards_set_nw_src_mask(&rule->wc, mask)) { - rule->flow.nw_src = ip & mask; - return true; - } else { - return false; - } + rule->flow.nw_src = nw_src & mask; + rule->wc.nw_src_mask = mask; } void cls_rule_set_nw_dst(struct cls_rule *rule, ovs_be32 nw_dst) { - cls_rule_set_nw_dst_masked(rule, nw_dst, htonl(UINT32_MAX)); + rule->flow.nw_dst = nw_dst; + rule->wc.nw_dst_mask = htonl(UINT32_MAX); } -bool +void cls_rule_set_nw_dst_masked(struct cls_rule *rule, ovs_be32 ip, ovs_be32 mask) { - if (flow_wildcards_set_nw_dst_mask(&rule->wc, mask)) { - rule->flow.nw_dst = ip & mask; - return true; - } else { - return false; - } + rule->flow.nw_dst = ip & mask; + rule->wc.nw_dst_mask = mask; } void @@ -386,37 +381,31 @@ cls_rule_set_arp_tha(struct cls_rule *rule, const uint8_t tha[ETH_ADDR_LEN]) void cls_rule_set_ipv6_src(struct cls_rule *rule, const struct in6_addr *src) { - cls_rule_set_ipv6_src_masked(rule, src, &in6addr_exact); + rule->flow.ipv6_src = *src; + rule->wc.ipv6_src_mask = in6addr_exact; } -bool +void cls_rule_set_ipv6_src_masked(struct cls_rule *rule, const struct in6_addr *src, const struct in6_addr *mask) { - if (flow_wildcards_set_ipv6_src_mask(&rule->wc, mask)) { - rule->flow.ipv6_src = ipv6_addr_bitand(src, mask); - return true; - } else { - return false; - } + rule->flow.ipv6_src = ipv6_addr_bitand(src, mask); + rule->wc.ipv6_src_mask = *mask; } void cls_rule_set_ipv6_dst(struct cls_rule *rule, const struct in6_addr *dst) { - cls_rule_set_ipv6_dst_masked(rule, dst, &in6addr_exact); + rule->flow.ipv6_dst = *dst; + rule->wc.ipv6_dst_mask = in6addr_exact; } -bool +void cls_rule_set_ipv6_dst_masked(struct cls_rule *rule, const struct in6_addr *dst, const struct in6_addr *mask) { - if (flow_wildcards_set_ipv6_dst_mask(&rule->wc, mask)) { - rule->flow.ipv6_dst = ipv6_addr_bitand(dst, mask); - return true; - } else { - return false; - } + rule->flow.ipv6_dst = ipv6_addr_bitand(dst, mask); + rule->wc.ipv6_dst_mask = *mask; } void diff --git a/lib/classifier.h b/lib/classifier.h index 797afce7..c33f1e10 100644 --- a/lib/classifier.h +++ b/lib/classifier.h @@ -113,9 +113,9 @@ void cls_rule_set_tp_src(struct cls_rule *, ovs_be16); void cls_rule_set_tp_dst(struct cls_rule *, ovs_be16); void cls_rule_set_nw_proto(struct cls_rule *, uint8_t); void cls_rule_set_nw_src(struct cls_rule *, ovs_be32); -bool cls_rule_set_nw_src_masked(struct cls_rule *, ovs_be32 ip, ovs_be32 mask); +void cls_rule_set_nw_src_masked(struct cls_rule *, ovs_be32 ip, ovs_be32 mask); void cls_rule_set_nw_dst(struct cls_rule *, ovs_be32); -bool cls_rule_set_nw_dst_masked(struct cls_rule *, ovs_be32 ip, ovs_be32 mask); +void cls_rule_set_nw_dst_masked(struct cls_rule *, ovs_be32 ip, ovs_be32 mask); void cls_rule_set_nw_dscp(struct cls_rule *, uint8_t); void cls_rule_set_nw_ecn(struct cls_rule *, uint8_t); void cls_rule_set_nw_ttl(struct cls_rule *, uint8_t); @@ -127,10 +127,10 @@ void cls_rule_set_icmp_code(struct cls_rule *, uint8_t); void cls_rule_set_arp_sha(struct cls_rule *, const uint8_t[6]); void cls_rule_set_arp_tha(struct cls_rule *, const uint8_t[6]); void cls_rule_set_ipv6_src(struct cls_rule *, const struct in6_addr *); -bool cls_rule_set_ipv6_src_masked(struct cls_rule *, const struct in6_addr *, +void cls_rule_set_ipv6_src_masked(struct cls_rule *, const struct in6_addr *, const struct in6_addr *); void cls_rule_set_ipv6_dst(struct cls_rule *, const struct in6_addr *); -bool cls_rule_set_ipv6_dst_masked(struct cls_rule *, const struct in6_addr *, +void cls_rule_set_ipv6_dst_masked(struct cls_rule *, const struct in6_addr *, const struct in6_addr *); void cls_rule_set_ipv6_label(struct cls_rule *, ovs_be32); void cls_rule_set_nd_target(struct cls_rule *, const struct in6_addr *); diff --git a/lib/flow.c b/lib/flow.c index f928cbeb..08c76d96 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -764,66 +764,6 @@ flow_wildcards_has_extra(const struct flow_wildcards *a, || (a->vlan_tci_mask & b->vlan_tci_mask) != b->vlan_tci_mask); } -static bool -set_nw_mask(ovs_be32 *maskp, ovs_be32 mask) -{ - if (ip_is_cidr(mask)) { - *maskp = mask; - return true; - } else { - return false; - } -} - -/* Sets the IP (or ARP) source wildcard mask to CIDR 'mask' (consisting of N - * high-order 1-bit and 32-N low-order 0-bits). Returns true if successful, - * false if 'mask' is not a CIDR mask. */ -bool -flow_wildcards_set_nw_src_mask(struct flow_wildcards *wc, ovs_be32 mask) -{ - return set_nw_mask(&wc->nw_src_mask, mask); -} - -/* Sets the IP (or ARP) destination wildcard mask to CIDR 'mask' (consisting of - * N high-order 1-bit and 32-N low-order 0-bits). Returns true if successful, - * false if 'mask' is not a CIDR mask. */ -bool -flow_wildcards_set_nw_dst_mask(struct flow_wildcards *wc, ovs_be32 mask) -{ - return set_nw_mask(&wc->nw_dst_mask, mask); -} - -static bool -set_ipv6_mask(struct in6_addr *maskp, const struct in6_addr *mask) -{ - if (ipv6_is_cidr(mask)) { - *maskp = *mask; - return true; - } else { - return false; - } -} - -/* Sets the IPv6 source wildcard mask to CIDR 'mask' (consisting of N - * high-order 1-bit and 128-N low-order 0-bits). Returns true if successful, - * false if 'mask' is not a CIDR mask. */ -bool -flow_wildcards_set_ipv6_src_mask(struct flow_wildcards *wc, - const struct in6_addr *mask) -{ - return set_ipv6_mask(&wc->ipv6_src_mask, mask); -} - -/* Sets the IPv6 destination wildcard mask to CIDR 'mask' (consisting of - * N high-order 1-bit and 128-N low-order 0-bits). Returns true if - * successful, false if 'mask' is not a CIDR mask. */ -bool -flow_wildcards_set_ipv6_dst_mask(struct flow_wildcards *wc, - const struct in6_addr *mask) -{ - return set_ipv6_mask(&wc->ipv6_dst_mask, mask); -} - /* Sets the wildcard mask for register 'idx' in 'wc' to 'mask'. * (A 0-bit indicates a wildcard bit.) */ void diff --git a/lib/flow.h b/lib/flow.h index 443986e6..75988ec0 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -177,12 +177,6 @@ void flow_wildcards_init_exact(struct flow_wildcards *); bool flow_wildcards_is_exact(const struct flow_wildcards *); bool flow_wildcards_is_catchall(const struct flow_wildcards *); -bool flow_wildcards_set_nw_src_mask(struct flow_wildcards *, ovs_be32); -bool flow_wildcards_set_nw_dst_mask(struct flow_wildcards *, ovs_be32); -bool flow_wildcards_set_ipv6_src_mask(struct flow_wildcards *, - const struct in6_addr *); -bool flow_wildcards_set_ipv6_dst_mask(struct flow_wildcards *, - const struct in6_addr *); void flow_wildcards_set_reg_mask(struct flow_wildcards *, int idx, uint32_t mask);