secchan: Factor common code into new function rule_update_actions().
authorBen Pfaff <blp@nicira.com>
Wed, 29 Apr 2009 22:43:24 +0000 (15:43 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 1 May 2009 17:55:29 +0000 (10:55 -0700)
rule_update() was only called in two places, and each time it was done
in the same way, so factor this out into a single new function
rule_update_actions().

secchan/ofproto.c

index 8b194986481b0c311b96a451d08c646fc7cbdf7f..12b7bc12a85cc8cefc6400c66c5fbc7d28400d6c 100644 (file)
@@ -1492,17 +1492,20 @@ rule_install(struct ofproto *p, struct rule *rule,
 }
 
 static void
-rule_update(struct ofproto *p, struct rule *rule)
+rule_update_actions(struct ofproto *ofproto, struct rule *rule)
 {
+    bool actions_changed = rule_make_actions(ofproto, rule, NULL);
     if (rule->may_install) {
         if (rule->installed) {
-            dpif_flow_set_actions(&p->dpif, &rule->cr.flow,
-                                  rule->odp_actions, rule->n_odp_actions);
+            if (actions_changed) {
+                dpif_flow_set_actions(&ofproto->dpif, &rule->cr.flow,
+                                      rule->odp_actions, rule->n_odp_actions);
+            }
         } else {
-            rule_install(p, rule, NULL);
+            rule_install(ofproto, rule, NULL);
         }
     } else {
-        rule_uninstall(p, rule);
+        rule_uninstall(ofproto, rule);
     }
 }
 
@@ -2512,11 +2515,7 @@ modify_flow(struct ofproto *p, const struct ofp_flow_mod *ofm,
         if (rule->cr.wc.wildcards) {
             p->need_revalidate = true;
         } else {
-            if (rule_make_actions(p, rule, NULL)) {
-                rule_update(p, rule);
-            } else if (rule->installed && !rule->may_install) {
-                rule_uninstall(p, rule);
-            }
+            rule_update_actions(p, rule);
         }
     }
 
@@ -2921,11 +2920,7 @@ revalidate_rule(struct ofproto *p, struct rule *rule)
         }
     }
 
-    if (rule_make_actions(p, rule, NULL)) {
-        rule_update(p, rule);
-    } else if (rule->installed && !rule->may_install) {
-        rule_uninstall(p, rule);
-    }
+    rule_update_actions(p, rule);
     return true;
 }