cfm: Immediately signal fault on bad CCM reception.
authorEthan Jackson <ethan@nicira.com>
Fri, 25 Mar 2011 02:04:21 +0000 (19:04 -0700)
committerEthan Jackson <ethan@nicira.com>
Mon, 28 Mar 2011 18:30:51 +0000 (11:30 -0700)
Commit af5739857a (cfm: Immediately signal a fault upon receiving
an unexpected MPID.) caused the CFM library to immediately signal a
fault upon reception of an unexpected remote MPID.  This commit
does the same for MAIDs, and remote maintenance points with invalid
CCM intervals.

lib/cfm.c

index 1626514b60a859657617a255a5c020b535a83d0a..bdefde6c10379567dc5ed8d73a0fa53c08385a06 100644 (file)
--- a/lib/cfm.c
+++ b/lib/cfm.c
@@ -110,6 +110,21 @@ lookup_remote_mp(const struct hmap *hmap, uint16_t mpid)
     return NULL;
 }
 
+static struct remote_maid *
+lookup_remote_maid(const struct hmap *hmap, uint8_t maid[CCM_MAID_LEN])
+{
+    uint32_t hash;
+    struct remote_maid *rmaid;
+
+    hash = hash_bytes(maid, CCM_MAID_LEN, 0);
+    HMAP_FOR_EACH_WITH_HASH (rmaid, node, hash, hmap) {
+        if (memcmp(rmaid->maid, maid, CCM_MAID_LEN) == 0) {
+            return rmaid;
+        }
+    }
+    return NULL;
+}
+
 /* 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. */
@@ -392,42 +407,42 @@ cfm_process_heartbeat(struct cfm *cfm, const struct ofpbuf *p)
     }
 
     if (memcmp(ccm->maid, cfm->maid, sizeof ccm->maid)) {
-        uint32_t hash;
         struct remote_maid *rmaid;
 
-        hash = hash_bytes(ccm->maid, sizeof ccm->maid, 0);
-
-        HMAP_FOR_EACH_IN_BUCKET (rmaid, node, hash, &cfm->x_remote_maids) {
-            if (memcmp(rmaid->maid, ccm->maid, sizeof rmaid->maid) == 0) {
-                rmaid->recv_time = time_msec();
-                return;
-            }
+        rmaid = lookup_remote_maid(&cfm->x_remote_maids, ccm->maid);
+        if (rmaid) {
+            rmaid->recv_time = time_msec();
+        } else {
+            rmaid = xzalloc(sizeof *rmaid);
+            rmaid->recv_time = time_msec();
+            memcpy(rmaid->maid, ccm->maid, sizeof rmaid->maid);
+            hmap_insert(&cfm->x_remote_maids, &rmaid->node,
+                        hash_bytes(ccm->maid, CCM_MAID_LEN, 0));
         }
+        cfm->fault = true;
+    } else {
+        ccm_mpid = ntohs(ccm->mpid);
+        ccm_seq = ntohl(ccm->seq);
+        ccm_interval = ccm->flags & 0x7;
 
-        rmaid            = xzalloc(sizeof *rmaid);
-        rmaid->recv_time = time_msec();
-        memcpy(rmaid->maid, ccm->maid, sizeof rmaid->maid);
-        hmap_insert(&cfm->x_remote_maids, &rmaid->node, hash);
-        return;
-    }
+        rmp = lookup_remote_mp(&cfm->remote_mps, ccm_mpid);
 
-    ccm_mpid     = ntohs(ccm->mpid);
-    ccm_seq      = ntohl(ccm->seq);
-    ccm_interval = ccm->flags & 0x7;
+        if (!rmp) {
+            rmp = lookup_remote_mp(&cfm->x_remote_mps, ccm_mpid);
+        }
 
-    rmp = lookup_remote_mp(&cfm->remote_mps, ccm_mpid);
+        if (!rmp) {
+            rmp = xzalloc(sizeof *rmp);
+            rmp->mpid = ccm_mpid;
+            hmap_insert(&cfm->x_remote_mps, &rmp->node, hash_mpid(ccm_mpid));
+            rmp->fault = true;
+        }
 
-    if (!rmp) {
-        rmp = lookup_remote_mp(&cfm->x_remote_mps, ccm_mpid);
-    }
+        rmp->recv_time = time_msec();
+        rmp->fault = ccm_interval != cfmi->ccm_interval;
 
-    if (!rmp) {
-        rmp       = xzalloc(sizeof *rmp);
-        rmp->mpid = ccm_mpid;
-        hmap_insert(&cfm->x_remote_mps, &rmp->node, hash_mpid(ccm_mpid));
-        cfm->fault = true;
+        if (rmp->fault) {
+            cfm->fault = true;
+        }
     }
-
-    rmp->recv_time = time_msec();
-    rmp->fault     = ccm_interval != cfmi->ccm_interval;
 }