X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fofp-util.c;h=7b167257b82dc120650863215b7b481080421325;hb=dbba996be2f0d96f4d2999d51c4ef1d16809bad9;hp=5aa2b825e1142d0147ff461d291c42057dbce502;hpb=b78f6b77bcaefc7b1e480aa6063091cb9ad50ad2;p=sliver-openvswitch.git diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 5aa2b825e..7b167257b 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -36,6 +36,8 @@ VLOG_DEFINE_THIS_MODULE(ofp_util); +static ovs_be32 normalize_wildcards(const struct ofp_match *); + /* Rate limit for OpenFlow message parse errors. These always indicate a bug * in the peer and so there's not much point in showing a lot of them. */ static struct vlog_rate_limit bad_ofmsg_rl = VLOG_RATE_LIMIT_INIT(1, 5); @@ -868,8 +870,9 @@ ofputil_decode_flow_mod(struct flow_mod *fm, const struct ofp_header *oh) ofputil_decode_msg_type(oh, &type); if (ofputil_msg_type_code(type) == OFPUTIL_OFPT_FLOW_MOD) { /* Standard OpenFlow flow_mod. */ - struct ofp_match match, orig_match; const struct ofp_flow_mod *ofm; + uint16_t priority; + ovs_be32 wc; int error; /* Dissect the message. */ @@ -879,26 +882,37 @@ ofputil_decode_flow_mod(struct flow_mod *fm, const struct ofp_header *oh) return error; } + /* Set priority based on original wildcards. Normally we'd allow + * ofputil_cls_rule_from_match() to do this for us, but + * normalize_wildcards() can put wildcards where the original flow + * didn't have them. */ + priority = ntohs(ofm->priority); + if (!(ofm->match.wildcards & htonl(OFPFW_ALL))) { + priority = UINT16_MAX; + } + /* Normalize ofm->match. If normalization actually changes anything, * then log the differences. */ - match = ofm->match; - match.pad1[0] = match.pad2[0] = 0; - orig_match = match; - normalize_match(&match); - if (memcmp(&match, &orig_match, sizeof orig_match)) { + wc = normalize_wildcards(&ofm->match); + if (wc == ofm->match.wildcards) { + ofputil_cls_rule_from_match(&ofm->match, priority, &fm->cr); + } else { + struct ofp_match match = ofm->match; + match.wildcards = wc; + ofputil_cls_rule_from_match(&match, priority, &fm->cr); + if (!VLOG_DROP_INFO(&bad_ofmsg_rl)) { - char *old = ofp_match_to_literal_string(&orig_match); - char *new = ofp_match_to_literal_string(&match); + char *pre = ofp_match_to_string(&ofm->match, 1); + char *post = ofp_match_to_string(&match, 1); VLOG_INFO("normalization changed ofp_match, details:"); - VLOG_INFO(" pre: %s", old); - VLOG_INFO("post: %s", new); - free(old); - free(new); + VLOG_INFO(" pre: %s", pre); + VLOG_INFO("post: %s", post); + free(pre); + free(post); } } /* Translate the message. */ - ofputil_cls_rule_from_match(&match, ntohs(ofm->priority), &fm->cr); fm->cookie = ofm->cookie; fm->command = ntohs(ofm->command); fm->idle_timeout = ntohs(ofm->idle_timeout); @@ -1725,19 +1739,6 @@ make_echo_reply(const struct ofp_header *rq) return out; } -/* Converts the members of 'opp' from host to network byte order. */ -void -hton_ofp_phy_port(struct ofp_phy_port *opp) -{ - opp->port_no = htons(opp->port_no); - opp->config = htonl(opp->config); - opp->state = htonl(opp->state); - opp->curr = htonl(opp->curr); - opp->advertised = htonl(opp->advertised); - opp->supported = htonl(opp->supported); - opp->peer = htonl(opp->peer); -} - static int check_action_exact_len(const union ofp_action *a, unsigned int len, unsigned int required_len) @@ -1922,7 +1923,7 @@ check_action(const union ofp_action *a, unsigned int len, if (error) { return error; } - if (a->vlan_vid.vlan_vid & ~7) { + if (a->vlan_pcp.vlan_pcp & ~7) { return ofp_mkerr(OFPET_BAD_ACTION, OFPBAC_BAD_ARGUMENT); } return 0; @@ -1989,10 +1990,9 @@ validate_actions(const union ofp_action *actions, size_t n_actions, return 0; } -/* Returns true if 'action' outputs to 'port' (which must be in network byte - * order), false otherwise. */ +/* Returns true if 'action' outputs to 'port', false otherwise. */ bool -action_outputs_to_port(const union ofp_action *action, uint16_t port) +action_outputs_to_port(const union ofp_action *action, ovs_be16 port) { switch (ntohs(action->type)) { case OFPAT_OUTPUT: @@ -2028,123 +2028,29 @@ actions_next(struct actions_iterator *iter) } } -void -normalize_match(struct ofp_match *m) +static ovs_be32 +normalize_wildcards(const struct ofp_match *m) { - enum { OFPFW_NW = (OFPFW_NW_SRC_MASK | OFPFW_NW_DST_MASK | OFPFW_NW_PROTO + enum { OFPFW_NW = (OFPFW_NW_SRC_ALL | OFPFW_NW_DST_ALL | OFPFW_NW_PROTO | OFPFW_NW_TOS) }; enum { OFPFW_TP = OFPFW_TP_SRC | OFPFW_TP_DST }; - uint32_t wc; + ovs_be32 wc; - wc = ntohl(m->wildcards) & OFPFW_ALL; - if (wc & OFPFW_DL_TYPE) { - m->dl_type = 0; - - /* Can't sensibly match on network or transport headers if the - * data link type is unknown. */ - wc |= OFPFW_NW | OFPFW_TP; - m->nw_src = m->nw_dst = m->nw_proto = m->nw_tos = 0; - m->tp_src = m->tp_dst = 0; + wc = m->wildcards; + if (wc & htonl(OFPFW_DL_TYPE)) { + wc |= htonl(OFPFW_NW | OFPFW_TP); } else if (m->dl_type == htons(ETH_TYPE_IP)) { - if (wc & OFPFW_NW_PROTO) { - m->nw_proto = 0; - - /* Can't sensibly match on transport headers if the network - * protocol is unknown. */ - wc |= OFPFW_TP; - m->tp_src = m->tp_dst = 0; - } else if (m->nw_proto == IPPROTO_TCP || - m->nw_proto == IPPROTO_UDP || - m->nw_proto == IPPROTO_ICMP) { - if (wc & OFPFW_TP_SRC) { - m->tp_src = 0; - } - if (wc & OFPFW_TP_DST) { - m->tp_dst = 0; - } - } else { - /* Transport layer fields will always be extracted as zeros, so we - * can do an exact-match on those values. */ - wc &= ~OFPFW_TP; - m->tp_src = m->tp_dst = 0; - } - if (wc & OFPFW_NW_SRC_MASK) { - m->nw_src &= ofputil_wcbits_to_netmask(wc >> OFPFW_NW_SRC_SHIFT); - } - if (wc & OFPFW_NW_DST_MASK) { - m->nw_dst &= ofputil_wcbits_to_netmask(wc >> OFPFW_NW_DST_SHIFT); - } - if (wc & OFPFW_NW_TOS) { - m->nw_tos = 0; - } else { - m->nw_tos &= IP_DSCP_MASK; + if (wc & htonl(OFPFW_NW_PROTO) || (m->nw_proto != IPPROTO_TCP && + m->nw_proto != IPPROTO_UDP && + m->nw_proto != IPPROTO_ICMP)) { + wc |= htonl(OFPFW_TP); } } else if (m->dl_type == htons(ETH_TYPE_ARP)) { - if (wc & OFPFW_NW_PROTO) { - m->nw_proto = 0; - } - if (wc & OFPFW_NW_SRC_MASK) { - m->nw_src &= ofputil_wcbits_to_netmask(wc >> OFPFW_NW_SRC_SHIFT); - } - if (wc & OFPFW_NW_DST_MASK) { - m->nw_dst &= ofputil_wcbits_to_netmask(wc >> OFPFW_NW_DST_SHIFT); - } - m->tp_src = m->tp_dst = m->nw_tos = 0; - } else if (m->dl_type == htons(ETH_TYPE_IPV6)) { - /* Don't normalize IPv6 traffic, since OpenFlow doesn't have a - * way to express it. */ + wc |= htonl(OFPFW_TP); } else { - /* Network and transport layer fields will always be extracted as - * zeros, so we can do an exact-match on those values. */ - wc &= ~(OFPFW_NW | OFPFW_TP); - m->nw_proto = m->nw_src = m->nw_dst = m->nw_tos = 0; - m->tp_src = m->tp_dst = 0; - } - if (wc & OFPFW_DL_SRC) { - memset(m->dl_src, 0, sizeof m->dl_src); + wc |= htonl(OFPFW_NW | OFPFW_TP); } - if (wc & OFPFW_DL_DST) { - memset(m->dl_dst, 0, sizeof m->dl_dst); - } - m->wildcards = htonl(wc); -} - -/* Returns a string that describes 'match' in a very literal way, without - * interpreting its contents except in a very basic fashion. The returned - * string is intended to be fixed-length, so that it is easy to see differences - * between two such strings if one is put above another. This is useful for - * describing changes made by normalize_match(). - * - * The caller must free the returned string (with free()). */ -char * -ofp_match_to_literal_string(const struct ofp_match *match) -{ - return xasprintf("wildcards=%#10"PRIx32" " - " in_port=%5"PRId16" " - " dl_src="ETH_ADDR_FMT" " - " dl_dst="ETH_ADDR_FMT" " - " dl_vlan=%5"PRId16" " - " dl_vlan_pcp=%3"PRId8" " - " dl_type=%#6"PRIx16" " - " nw_tos=%#4"PRIx8" " - " nw_proto=%#4"PRIx16" " - " nw_src=%#10"PRIx32" " - " nw_dst=%#10"PRIx32" " - " tp_src=%5"PRId16" " - " tp_dst=%5"PRId16, - ntohl(match->wildcards), - ntohs(match->in_port), - ETH_ADDR_ARGS(match->dl_src), - ETH_ADDR_ARGS(match->dl_dst), - ntohs(match->dl_vlan), - match->dl_vlan_pcp, - ntohs(match->dl_type), - match->nw_tos, - match->nw_proto, - ntohl(match->nw_src), - ntohl(match->nw_dst), - ntohs(match->tp_src), - ntohs(match->tp_dst)); + return wc; } static uint32_t