[ovs-dev] [PATCH 2/6] cfm: Immediately signal fault on bad CCM reception.
Ethan Jackson
ethan at nicira.com
Fri Mar 25 23:39:25 UTC 2011
Commit af5739857a23c29953520e0fe9e79860d12b256c 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 | 72 ++++++++++++++++++++++++++++++++++++------------------------
1 files changed, 43 insertions(+), 29 deletions(-)
diff --git a/lib/cfm.c b/lib/cfm.c
index 1626514..5c969e4 100644
--- a/lib/cfm.c
+++ b/lib/cfm.c
@@ -110,6 +110,20 @@ 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_IN_BUCKET (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 +406,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;
}
--
1.7.4.1
More information about the dev
mailing list