learning-switch: Normalize the flows that are sent to the switch.
[sliver-openvswitch.git] / lib / learning-switch.c
index f52d3c9..c1cd909 100644 (file)
@@ -112,6 +112,7 @@ struct lswitch *
 lswitch_create(struct rconn *rconn, const struct lswitch_config *cfg)
 {
     struct lswitch *sw;
+    uint32_t ofpfw;
 
     sw = xzalloc(sizeof *sw);
     sw->rconn = rconn;
@@ -123,24 +124,26 @@ lswitch_create(struct rconn *rconn, const struct lswitch_config *cfg)
               : NULL);
     sw->action_normal = cfg->mode == LSW_NORMAL;
 
-    flow_wildcards_init_exact(&sw->wc);
-    if (cfg->wildcards) {
-        uint32_t ofpfw;
-
-        if (cfg->wildcards == UINT32_MAX) {
-            /* Try to wildcard as many fields as possible, but we cannot
-             * wildcard all fields.  We need in_port to detect moves.  We need
-             * Ethernet source and dest and VLAN VID to do L2 learning. */
-            ofpfw = (OFPFW10_DL_TYPE | OFPFW10_DL_VLAN_PCP
-                     | OFPFW10_NW_SRC_ALL | OFPFW10_NW_DST_ALL
-                     | OFPFW10_NW_TOS | OFPFW10_NW_PROTO
-                     | OFPFW10_TP_SRC | OFPFW10_TP_DST);
-        } else {
-            ofpfw = cfg->wildcards;
-        }
+    switch (cfg->wildcards) {
+    case 0:
+        ofpfw = 0;
+        break;
 
-        ofputil_wildcard_from_ofpfw10(ofpfw, &sw->wc);
+    case UINT32_MAX:
+        /* Try to wildcard as many fields as possible, but we cannot
+         * wildcard all fields.  We need in_port to detect moves.  We need
+         * Ethernet source and dest and VLAN VID to do L2 learning. */
+        ofpfw = (OFPFW10_DL_TYPE | OFPFW10_DL_VLAN_PCP
+                 | OFPFW10_NW_SRC_ALL | OFPFW10_NW_DST_ALL
+                 | OFPFW10_NW_TOS | OFPFW10_NW_PROTO
+                 | OFPFW10_TP_SRC | OFPFW10_TP_DST);
+        break;
+
+    default:
+        ofpfw = cfg->wildcards;
+        break;
     }
+    ofputil_wildcard_from_ofpfw10(ofpfw, &sw->wc);
 
     sw->default_queue = cfg->default_queue;
     hmap_init(&sw->queue_numbers);
@@ -573,6 +576,7 @@ process_packet_in(struct lswitch *sw, const struct ofp_header *oh)
          * new flow. */
         memset(&fm, 0, sizeof fm);
         cls_rule_init(&flow, &sw->wc, 0, &fm.cr);
+        ofputil_normalize_rule_quiet(&fm.cr);
         fm.table_id = 0xff;
         fm.command = OFPFC_ADD;
         fm.idle_timeout = sw->max_idle;