It doesn't really make sense for the CFM code to be composing
packets.  Its caller is better placed to compose the appropriate
L2 header.  This commit pulls that logic out of the CFM library.
---
 lib/cfm.c         |   28 +++++++---------------------
 lib/cfm.h         |    3 +--
 ofproto/ofproto.c |   15 ++++++++++-----
 vswitchd/bridge.c |    9 +--------
 4 files changed, 19 insertions(+), 36 deletions(-)

diff --git a/lib/cfm.c b/lib/cfm.c
index aeb7144..4b2b9bd 100644
--- a/lib/cfm.c
+++ b/lib/cfm.c
@@ -108,23 +108,6 @@ lookup_remote_mp(const struct hmap *hmap, uint16_t mpid)
     return NULL;
 }
 
-static struct ofpbuf *
-compose_message(struct cfm_internal *cfmi)
-{
-    struct ccm ccm;
-    struct ofpbuf *packet;
-
-    packet = ofpbuf_new(0);
-
-    compose_ccm(cfmi->cfm.mpid, cfmi->cfm.maid, cfmi->ccm_interval,
-                ++cfmi->seq, &ccm);
-
-    compose_packet(packet, eth_addr_ccm, cfmi->cfm.eth_src, ETH_TYPE_CFM,
-                   &ccm, sizeof ccm);
-
-    return packet;
-}
-
 /* Allocates a 'cfm' object.  This object should have its 'mpid', 'maid',
  * 'eth_src', and 'interval' filled out.  When changes are made to the 'cfm'
  * object, cfm_configure should be called before using it. */
@@ -175,13 +158,14 @@ cfm_destroy(struct cfm *cfm)
 }
 
 /* Should be run periodically to update fault statistics and generate CCM
- * messages.  If necessary, returns a packet which the caller is responsible
- * for sending, un-initing, and deallocating.  Otherwise returns NULL. */
-struct ofpbuf *
+ * messages.  If necessary, returns a statically allocated ccm which the caller
+ * is responsible for sending.  Otherwise returns NULL. */
+const struct ccm *
 cfm_run(struct cfm *cfm)
 {
     long long now = time_msec();
     struct cfm_internal *cfmi = cfm_to_internal(cfm);
+    static struct ccm ccm;
 
     /* According to the 802.1ag specification we should assume every other MP
      * with the same MAID has the same transmission interval that we have.  If
@@ -227,7 +211,9 @@ cfm_run(struct cfm *cfm)
 
     if (now >= cfmi->ccm_sent + cfmi->ccm_interval_ms) {
         cfmi->ccm_sent = now;
-        return compose_message(cfmi);
+        compose_ccm(cfmi->cfm.mpid, cfmi->cfm.maid, cfmi->ccm_interval,
+                    ++cfmi->seq, &ccm);
+        return &ccm;
     }
 
     return NULL;
diff --git a/lib/cfm.h b/lib/cfm.h
index f7007bb..569cf26 100644
--- a/lib/cfm.h
+++ b/lib/cfm.h
@@ -32,7 +32,6 @@ struct cfm {
     uint16_t mpid;              /* The MPID of this CFM. */
     uint8_t maid[CCM_MAID_LEN]; /* The MAID of this CFM. */
     int interval;               /* The requested transmission interval. */
-    uint8_t eth_src[ETH_ADDR_LEN];
 
     /* Statistics. */
     struct hmap remote_mps;     /* Expected remote MPs. */
@@ -64,7 +63,7 @@ struct cfm *cfm_create(void);
 
 void cfm_destroy(struct cfm *);
 
-struct ofpbuf *cfm_run(struct cfm *);
+const struct ccm *cfm_run(struct cfm *);
 
 void cfm_wait(struct cfm *);
 
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 6f2b43c..78b35ac 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -991,7 +991,6 @@ ofproto_iface_set_cfm(struct ofproto *ofproto, uint32_t 
port_no,
 
     ofport->cfm->mpid = cfm->mpid;
     ofport->cfm->interval = cfm->interval;
-    memcpy(ofport->cfm->eth_src, cfm->eth_src, ETH_ADDR_LEN);
     memcpy(ofport->cfm->maid, cfm->maid, CCM_MAID_LEN);
 
     cfm_update_remote_mps(ofport->cfm, remote_mps, n_remote_mps);
@@ -1729,10 +1728,16 @@ static void
 ofport_run(struct ofproto *ofproto, struct ofport *ofport)
 {
     if (ofport->cfm) {
-        struct ofpbuf *packet = cfm_run(ofport->cfm);
-        if (packet) {
-            ofproto_send_packet(ofproto, ofport->odp_port, 0, packet);
-            ofpbuf_delete(packet);
+        const struct ccm *ccm = cfm_run(ofport->cfm);
+
+        if (ccm) {
+            struct ofpbuf packet;
+
+            ofpbuf_init(&packet, 0);
+            compose_packet(&packet, eth_addr_ccm, ofport->opp.hw_addr,
+                           ETH_TYPE_CFM, ccm, sizeof *ccm);
+            ofproto_send_packet(ofproto, ofport->odp_port, 0, &packet);
+            ofpbuf_uninit(&packet);
         }
     }
 }
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 4eab695..9323312 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -4583,7 +4583,7 @@ iface_update_cfm(struct iface *iface)
     struct cfm cfm;
     uint16_t *remote_mps;
     struct ovsrec_monitor *mon;
-    uint8_t ea[ETH_ADDR_LEN], maid[CCM_MAID_LEN];
+    uint8_t maid[CCM_MAID_LEN];
 
     mon = iface->cfg->monitor;
 
@@ -4592,12 +4592,6 @@ iface_update_cfm(struct iface *iface)
         return;
     }
 
-    if (netdev_get_etheraddr(iface->netdev, ea)) {
-        VLOG_WARN("interface %s: Failed to get ethernet address. "
-                  "Skipping Monitor.", iface->name);
-        return;
-    }
-
     if (!cfm_generate_maid(mon->md_name, mon->ma_name, maid)) {
         VLOG_WARN("interface %s: Failed to generate MAID.", iface->name);
         return;
@@ -4606,7 +4600,6 @@ iface_update_cfm(struct iface *iface)
     cfm.mpid     = mon->mpid;
     cfm.interval = mon->interval ? *mon->interval : 1000;
 
-    memcpy(cfm.eth_src, ea, sizeof cfm.eth_src);
     memcpy(cfm.maid, maid, sizeof cfm.maid);
 
     remote_mps = xzalloc(mon->n_remote_mps * sizeof *remote_mps);
-- 
1.7.4.1

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to