+ /* Translate VLANs. */
+ vid = match->dl_vlan & htons(VLAN_VID_MASK);
+ pcp = htons((match->dl_vlan_pcp << VLAN_PCP_SHIFT) & VLAN_PCP_MASK);
+ switch (ofpfw & (OFPFW_DL_VLAN | OFPFW_DL_VLAN_PCP)) {
+ case OFPFW_DL_VLAN | OFPFW_DL_VLAN_PCP:
+ /* Wildcard everything. */
+ rule->flow.vlan_tci = htons(0);
+ rule->wc.vlan_tci_mask = htons(0);
+ break;
+
+ case OFPFW_DL_VLAN_PCP:
+ if (match->dl_vlan == htons(OFP_VLAN_NONE)) {
+ /* Match only packets without 802.1Q header. */
+ rule->flow.vlan_tci = htons(0);
+ rule->wc.vlan_tci_mask = htons(0xffff);
+ } else {
+ /* Wildcard PCP, specific VID. */
+ rule->flow.vlan_tci = vid | htons(VLAN_CFI);
+ rule->wc.vlan_tci_mask = htons(VLAN_VID_MASK | VLAN_CFI);
+ }
+ break;
+
+ case OFPFW_DL_VLAN:
+ /* Wildcard VID, specific PCP. */
+ rule->flow.vlan_tci = pcp | htons(VLAN_CFI);
+ rule->wc.vlan_tci_mask = htons(VLAN_PCP_MASK | VLAN_CFI);
+ break;
+
+ case 0:
+ if (match->dl_vlan == htons(OFP_VLAN_NONE)) {
+ /* This case is odd, since we can't have a specific PCP without an
+ * 802.1Q header. However, older versions of OVS treated this as
+ * matching packets withut an 802.1Q header, so we do here too. */
+ rule->flow.vlan_tci = htons(0);
+ rule->wc.vlan_tci_mask = htons(0xffff);
+ } else {
+ /* Specific VID and PCP. */
+ rule->flow.vlan_tci = vid | pcp | htons(VLAN_CFI);
+ rule->wc.vlan_tci_mask = htons(0xffff);
+ }
+ break;
+ }
+