From: Ethan Jackson <ethan@nicira.com>
Date: Mon, 3 Jun 2013 20:49:13 +0000 (-0700)
Subject: cfm: Update netdev when changed.
X-Git-Tag: sliver-openvswitch-1.10.90-3~6^2~177
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=9d46b444e3d7b57e5d0500bc12d3301fe528627c;p=sliver-openvswitch.git

cfm: Update netdev when changed.

If ofproto decided to change the netdev of a particular ofport,
cfm_demand mode would improperly continue using the old netdev to
collect stats.

Bug #17583.
Signed-off-by: Ethan Jackson <ethan@nicira.com>
---

diff --git a/lib/cfm.c b/lib/cfm.c
index d16e2dd8f..4d4ebcbd9 100644
--- a/lib/cfm.c
+++ b/lib/cfm.c
@@ -567,6 +567,16 @@ cfm_configure(struct cfm *cfm, const struct cfm_settings *s)
     return true;
 }
 
+/* Must be called when the netdev owned by 'cfm' should change. */
+void
+cfm_set_netdev(struct cfm *cfm, const struct netdev *netdev)
+{
+    if (cfm->netdev != netdev) {
+        netdev_close(cfm->netdev);
+        cfm->netdev = netdev_ref(netdev);
+    }
+}
+
 /* Returns true if 'cfm' should process packets from 'flow'. */
 bool
 cfm_should_process_flow(const struct cfm *cfm, const struct flow *flow)
diff --git a/lib/cfm.h b/lib/cfm.h
index eec9704dd..057da04b1 100644
--- a/lib/cfm.h
+++ b/lib/cfm.h
@@ -71,6 +71,7 @@ bool cfm_should_send_ccm(struct cfm *);
 void cfm_compose_ccm(struct cfm *, struct ofpbuf *packet, uint8_t eth_src[6]);
 void cfm_wait(struct cfm *);
 bool cfm_configure(struct cfm *, const struct cfm_settings *);
+void cfm_set_netdev(struct cfm *, const struct netdev *);
 bool cfm_should_process_flow(const struct cfm *cfm, const struct flow *);
 void cfm_process_heartbeat(struct cfm *, const struct ofpbuf *packet);
 int cfm_get_fault(const struct cfm *);
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 7c3abec18..13e2aad3e 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -1904,6 +1904,10 @@ port_modified(struct ofport *port_)
     if (port->bundle && port->bundle->bond) {
         bond_slave_set_netdev(port->bundle->bond, port, port->up.netdev);
     }
+
+    if (port->cfm) {
+        cfm_set_netdev(port->cfm, port->up.netdev);
+    }
 }
 
 static void