Flooding MPRs are interface specific
authorHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Tue, 25 Oct 2016 11:44:48 +0000 (13:44 +0200)
committerHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Tue, 25 Oct 2016 11:44:48 +0000 (13:44 +0200)
src-plugins/nhdp/mpr/mpr.c
src-plugins/nhdp/mpr/neighbor-graph-flooding.c
src-plugins/nhdp/nhdp/nhdp_db.h
src-plugins/nhdp/nhdp/nhdp_domain.c
src-plugins/nhdp/nhdp/nhdp_domain.h
src-plugins/nhdp/nhdp/nhdp_reader.c
src-plugins/nhdp/nhdp/nhdp_writer.c
src-plugins/nhdp/nhdpinfo/nhdpinfo.c
src-plugins/olsrv2/olsrv2/olsrv2.c

index 2847640..3073772 100644 (file)
@@ -174,7 +174,7 @@ _update_nhdp_flooding(struct neighbor_graph *graph) {
     if (current_mpr_node != NULL) {
       OONF_DEBUG(LOG_MPR, "Processing MPR node %s",
           netaddr_to_string(&buf1, &current_mpr_node->addr));
-      current_link->neigh->neigh_is_flooding_mpr = true;
+      current_link->neigh_is_flooding_mpr = true;
     }
   }
 }
@@ -190,7 +190,7 @@ _clear_nhdp_flooding(void) {
   OONF_DEBUG(LOG_MPR, "Clear FLOODING MPRs");
 
   list_for_each_element(nhdp_db_get_link_list(), current_link, _global_node) {
-    current_link->neigh->neigh_is_flooding_mpr = false;
+    current_link->neigh_is_flooding_mpr = false;
   }
 }
 
index cc292e9..0705d3f 100644 (file)
@@ -121,7 +121,7 @@ static bool
 _is_allowed_link_tuple(const struct nhdp_domain *domain,
     struct nhdp_interface *current_interface, struct nhdp_link *lnk) {
   if (_is_reachable_link_tuple(domain, current_interface, lnk)
-      && lnk->neigh->flooding_willingness > RFC7181_WILLINGNESS_NEVER) {
+      && lnk->flooding_willingness > RFC7181_WILLINGNESS_NEVER) {
     return true;
   }
   return false;
@@ -280,7 +280,7 @@ _calculate_n2(const struct nhdp_domain *domain, struct mpr_flooding_data *data)
 static uint32_t
 _get_willingness_n1(const struct nhdp_domain *domain __attribute__((unused)),
     struct n1_node *node) {
-  return node->neigh->flooding_willingness;
+  return node->link->flooding_willingness;
 }
 
 void
index fff2f65..13301fb 100644 (file)
@@ -203,6 +203,15 @@ struct nhdp_link {
   /*! timestamp when the current link status was set */
   uint64_t last_status_change;
 
+  /*! true if the local router has been selected as a MPR by the neighbor */
+  bool local_is_flooding_mpr;
+
+  /*! true if the neighbor has been selected as a MPR by this router */
+  bool neigh_is_flooding_mpr;
+
+  /*! Willingness of neighbor for flooding data */
+  uint8_t flooding_willingness;
+
   /*! internal field for NHDP processing */
   int _process_count;
 
@@ -290,15 +299,6 @@ struct nhdp_neighbor {
   /*! pointer to other (dualstack) representation of this neighbor */
   struct nhdp_neighbor *dualstack_partner;
 
-  /*! true if the local router has been selected as a MPR by the neighbor */
-  bool local_is_flooding_mpr;
-
-  /*! true if the neighbor has been selected as a MPR by this router */
-  bool neigh_is_flooding_mpr;
-
-  /*! Willingness of neighbor for flooding data */
-  uint8_t flooding_willingness;
-
   /*! internal field for NHDP processing */
   int _process_count;
 
index a59be2a..58f36a0 100644 (file)
@@ -354,6 +354,11 @@ nhdp_domain_init_link(struct nhdp_link *lnk) {
   struct nhdp_link_domaindata *data;
   int i;
 
+  /* initialize flooding MPR settings */
+  lnk->flooding_willingness = RFC7181_WILLINGNESS_NEVER;
+  lnk->local_is_flooding_mpr = false;
+  lnk->neigh_is_flooding_mpr = false;
+
   /* initialize metrics */
   for (i=0; i<NHDP_MAXIMUM_DOMAINS; i++) {
     lnk->_domaindata[i].metric.in = RFC7181_METRIC_INFINITE;
@@ -406,11 +411,6 @@ nhdp_domain_init_neighbor(struct nhdp_neighbor *neigh) {
   struct nhdp_neighbor_domaindata *data;
   int i;
 
-  /* initialize flooding MPR settings */
-  neigh->flooding_willingness = RFC7181_WILLINGNESS_NEVER;
-  neigh->local_is_flooding_mpr = false;
-  neigh->neigh_is_flooding_mpr = false;
-
   for (i=0; i<NHDP_MAXIMUM_DOMAINS; i++) {
     neigh->_domaindata[i].metric.in = RFC7181_METRIC_INFINITE;
     neigh->_domaindata[i].metric.out = RFC7181_METRIC_INFINITE;
@@ -576,14 +576,15 @@ nhdp_domain_process_mprtypes_tlv(
  */
 void
 nhdp_domain_process_mpr_tlv(uint8_t *mprtypes, size_t mprtypes_size,
-    struct nhdp_neighbor *neigh, struct rfc5444_reader_tlvblock_entry *tlv) {
+    struct nhdp_link *lnk, struct rfc5444_reader_tlvblock_entry *tlv) {
   struct nhdp_domain *domain;
+  struct nhdp_neighbor *neigh;
   size_t bit_idx, byte_idx;
   size_t i;
 
-  neigh->local_is_flooding_mpr = false;
+  lnk->local_is_flooding_mpr = false;
   list_for_each_element(&_domain_list, domain, _node) {
-    nhdp_domain_get_neighbordata(domain, neigh)->local_is_mpr = false;
+    nhdp_domain_get_neighbordata(domain, lnk->neigh)->local_is_mpr = false;
   }
 
   if (!tlv) {
@@ -591,10 +592,10 @@ nhdp_domain_process_mpr_tlv(uint8_t *mprtypes, size_t mprtypes_size,
   }
 
   /* set flooding MPR flag */
-  neigh->local_is_flooding_mpr =
+  lnk->local_is_flooding_mpr =
       (tlv->single_value[0] & RFC7181_MPR_FLOODING) != 0;
   OONF_DEBUG(LOG_NHDP_R, "Flooding MPR for neighbor: %s",
-      neigh->local_is_flooding_mpr ? "true" : "false");
+      lnk->local_is_flooding_mpr ? "true" : "false");
 
   /* set routing MPR flags */
   for (i=0; i<mprtypes_size; i++) {
@@ -609,11 +610,11 @@ nhdp_domain_process_mpr_tlv(uint8_t *mprtypes, size_t mprtypes_size,
       continue;
     }
 
-    nhdp_domain_get_neighbordata(domain, neigh)->local_is_mpr =
+    nhdp_domain_get_neighbordata(domain, lnk->neigh)->local_is_mpr =
         (tlv->single_value[byte_idx] & (1 << bit_idx)) != 0;
 
     OONF_DEBUG(LOG_NHDP_R, "Routing MPR for neighbor in domain %u: %s",
-        domain->ext, nhdp_domain_get_neighbordata(domain, neigh)->local_is_mpr ? "true" : "false");
+        domain->ext, nhdp_domain_get_neighbordata(domain, lnk->neigh)->local_is_mpr ? "true" : "false");
   }
 
   _node_is_selected_as_mpr = false;
@@ -690,16 +691,16 @@ nhdp_domain_process_willingness_tlv(
  * @param neigh NHDP neighbor
  */
 void
-nhdp_domain_store_willingness(struct nhdp_neighbor *neigh) {
+nhdp_domain_store_willingness(struct nhdp_link *lnk) {
   struct nhdp_neighbor_domaindata *neighdata;
   struct nhdp_domain *domain;
 
-  neigh->flooding_willingness = _flooding_domain._tmp_willingness;
+  lnk->flooding_willingness = _flooding_domain._tmp_willingness;
   OONF_DEBUG(LOG_NHDP_R, "Set flooding willingness: %u",
-      neigh->flooding_willingness);
+      lnk->flooding_willingness);
 
   list_for_each_element(&_domain_list, domain, _node) {
-    neighdata = nhdp_domain_get_neighbordata(domain, neigh);
+    neighdata = nhdp_domain_get_neighbordata(domain, lnk->neigh);
     neighdata->willingness = domain->_tmp_willingness;
     OONF_DEBUG(LOG_NHDP_R, "Set routing willingness for domain %u: %u",
         domain->ext, neighdata->willingness);
@@ -740,19 +741,19 @@ nhdp_domain_encode_mprtypes_tlvvalue(
  */
 size_t
 nhdp_domain_encode_mpr_tlvvalue(
-    uint8_t *tlvvalue, size_t tlvsize, struct nhdp_neighbor *neigh) {
+    uint8_t *tlvvalue, size_t tlvsize, struct nhdp_link *lnk) {
   struct nhdp_domain *domain;
   size_t bit_idx, byte_idx, len;
 
   memset(tlvvalue, 0, tlvsize);
   len = 0;
   /* set flooding MPR flag */
-  if (neigh->neigh_is_flooding_mpr) {
+  if (lnk->neigh_is_flooding_mpr) {
     tlvvalue[0] |= RFC7181_MPR_FLOODING;
   }
 
   OONF_DEBUG(LOG_NHDP_W, "Set flooding MPR: %s",
-      neigh->neigh_is_flooding_mpr ? "true" : "false");
+      lnk->neigh_is_flooding_mpr ? "true" : "false");
 
   list_for_each_element(&_domain_list, domain, _node) {
     bit_idx = (domain->index + 1) & 7;
@@ -765,12 +766,12 @@ nhdp_domain_encode_mpr_tlvvalue(
       len = byte_idx + 1;
     }
 
-    if (nhdp_domain_get_neighbordata(domain, neigh)->neigh_is_mpr) {
+    if (nhdp_domain_get_neighbordata(domain, lnk->neigh)->neigh_is_mpr) {
       tlvvalue[byte_idx] |= (1 << bit_idx);
     }
 
     OONF_DEBUG(LOG_NHDP_W, "Set routing MPR for domain %u: %s",
-        domain->ext, nhdp_domain_get_neighbordata(domain, neigh)->neigh_is_mpr ? "true" : "false");
+        domain->ext, nhdp_domain_get_neighbordata(domain, lnk->neigh)->neigh_is_mpr ? "true" : "false");
   }
   return len;
 }
@@ -1249,15 +1250,18 @@ _remove_mpr(struct nhdp_domain *domain) {
 
 static void
 _cb_update_everyone_mpr(struct nhdp_domain *domain) {
+  struct nhdp_link *lnk;
   struct nhdp_neighbor *neigh;
   struct nhdp_neighbor_domaindata *domaindata;
 
-  list_for_each_element(nhdp_db_get_neigh_list(), neigh, _global_node) {
-    if (&_flooding_domain == domain) {
-      neigh->neigh_is_flooding_mpr =
-          neigh->flooding_willingness > RFC7181_WILLINGNESS_NEVER;
+  if (&_flooding_domain == domain) {
+    list_for_each_element(nhdp_db_get_link_list(), lnk, _global_node) {
+      lnk->neigh_is_flooding_mpr =
+          lnk->flooding_willingness > RFC7181_WILLINGNESS_NEVER;
     }
-    else if (domain->mpr == &_everyone_mprs) {
+  }
+  list_for_each_element(nhdp_db_get_neigh_list(), neigh, _global_node) {
+    if (domain->mpr == &_everyone_mprs) {
       domaindata = nhdp_domain_get_neighbordata(domain, neigh);
       domaindata->neigh_is_mpr =
           domaindata->willingness > RFC7181_WILLINGNESS_NEVER;
index 5c9dd6f..4b4797d 100644 (file)
@@ -296,15 +296,15 @@ EXPORT size_t nhdp_domain_process_mprtypes_tlv(
     uint8_t *mprtypes, size_t mprtypes_size,
     struct rfc5444_reader_tlvblock_entry *tlv);
 EXPORT void nhdp_domain_process_mpr_tlv(uint8_t *mprtypes, size_t mprtypes_size,
-    struct nhdp_neighbor *, struct rfc5444_reader_tlvblock_entry *tlv);
+    struct nhdp_link *, struct rfc5444_reader_tlvblock_entry *tlv);
 EXPORT void nhdp_domain_process_willingness_tlv(
     uint8_t *mpr_types, size_t mprtypes_size,
     struct rfc5444_reader_tlvblock_entry *tlv);
-EXPORT void nhdp_domain_store_willingness(struct nhdp_neighbor *);
+EXPORT void nhdp_domain_store_willingness(struct nhdp_link *);
 EXPORT size_t nhdp_domain_encode_mprtypes_tlvvalue(
     uint8_t *mprtypes, size_t mprtypes_size);
 EXPORT size_t nhdp_domain_encode_mpr_tlvvalue(
-    uint8_t *tlvvalue, size_t tlvsize, struct nhdp_neighbor *);
+    uint8_t *tlvvalue, size_t tlvsize, struct nhdp_link *);
 EXPORT size_t nhdp_domain_encode_willingness_tlvvalue(
     uint8_t *tlvvalue, size_t tlvsize);
 
index 9e69937..c11f6fa 100644 (file)
@@ -728,7 +728,7 @@ _process_domainspecific_linkdata(struct netaddr *addr __attribute__((unused))) {
 
   /* process MPR settings of link */
   nhdp_domain_process_mpr_tlv(_current.mprtypes, _current.mprtypes_size,
-      _current.neighbor, _nhdp_address_pass2_tlvs[IDX_ADDRTLV2_MPR].tlv);
+      _current.link, _nhdp_address_pass2_tlvs[IDX_ADDRTLV2_MPR].tlv);
 
   /* update out metric with other sides in metric */
   tlv = _nhdp_address_pass2_tlvs[IDX_ADDRTLV2_LINKMETRIC].tlv;
@@ -968,7 +968,7 @@ _cb_msg_pass2_end(struct rfc5444_reader_tlvblock_context *context, bool dropped)
   nhdp_db_neighbor_set_originator(_current.neighbor, &context->orig_addr);
 
   /* copy willingness to permanent storage */
-  nhdp_domain_store_willingness(_current.neighbor);
+  nhdp_domain_store_willingness(_current.link);
 
   /* update ip flooding settings */
   nhdp_interface_update_status(_current.localif);
index 2e67e5b..cc37b43 100644 (file)
@@ -418,7 +418,7 @@ _add_link_address(struct rfc5444_writer *writer, struct rfc5444_writer_content_p
 
   /* add MPR tlvs */
   if (laddr != NULL) {
-    len = nhdp_domain_encode_mpr_tlvvalue(mprvalue, sizeof(mprvalue), naddr->neigh);
+    len = nhdp_domain_encode_mpr_tlvvalue(mprvalue, sizeof(mprvalue), laddr->link);
 
     if (len) {
       rfc5444_writer_add_addrtlv(writer, address,
index f36a050..b7d5b74 100644 (file)
@@ -154,6 +154,15 @@ static int _cb_create_text_neighbor_address(struct oonf_viewer_template *);
 /*! template key for links remote mac address */
 #define KEY_LINK_MAC                "link_mac"
 
+/*! template key signaling link has selected node as flooding MPR */
+#define KEY_LINK_FLOOD_LOCAL        "link_flood_local"
+
+/*! template key signaling route has selected link as flooding MPR */
+#define KEY_LINK_FLOOD_REMOTE       "link_flood_remote"
+
+/*! template key for link flooding willingness */
+#define KEY_LINK_FLOOD_WILL         "link_flood_willingness"
+
 /*! template key for a link IP address */
 #define KEY_LINK_ADDRESS            "link_address"
 
@@ -172,21 +181,12 @@ static int _cb_create_text_neighbor_address(struct oonf_viewer_template *);
 /*! template key for neighbors dualstack originator IP */
 #define KEY_NEIGHBOR_DUALSTACK      "neighbor_dualstack"
 
-/*! template key signaling neighbor has selected node as flooding MPR */
-#define KEY_NEIGHBOR_FLOOD_LOCAL    "neighbor_flood_local"
-
-/*! template key signaling route has selected neighbor as flooding MPR */
-#define KEY_NEIGHBOR_FLOOD_REMOTE   "neighbor_flood_remote"
-
 /*! template key for number of symmetric links of neighbor */
 #define KEY_NEIGHBOR_SYMMETRIC      "neighbor_symmetric"
 
 /*! template key for number of links of neighbor */
 #define KEY_NEIGHBOR_LINKCOUNT      "neighbor_linkcount"
 
-/*! template key for neighbor flooding willingness */
-#define KEY_NEIGHBOR_FLOOD_WILL     "neighbor_flood_willingness"
-
 /*! template key for neighbor address */
 #define KEY_NEIGHBOR_ADDRESS        "neighbor_address"
 
@@ -253,6 +253,9 @@ static struct isonumber_str       _value_link_vtime;
 static char                       _value_link_status[NHDP_LINK_STATUS_TXTLENGTH];
 static struct netaddr_str         _value_link_dualstack;
 static struct netaddr_str         _value_link_mac;
+static char                       _value_link_flood_local[TEMPLATE_JSON_BOOL_LENGTH];
+static char                       _value_link_flood_remote[TEMPLATE_JSON_BOOL_LENGTH];
+static char                       _value_link_willingness[3];
 
 static struct netaddr_str         _value_link_address;
 
@@ -262,11 +265,8 @@ static struct isonumber_str       _value_twohop_vtime;
 
 static struct netaddr_str         _value_neighbor_originator;
 static struct netaddr_str         _value_neighbor_dualstack;
-static char                       _value_neighbor_flood_local[TEMPLATE_JSON_BOOL_LENGTH];
-static char                       _value_neighbor_flood_remote[TEMPLATE_JSON_BOOL_LENGTH];
 static char                       _value_neighbor_symmetric[TEMPLATE_JSON_BOOL_LENGTH];
 static char                       _value_neighbor_linkcount[10];
-static char                       _value_neighbor_willingness[3];
 static struct netaddr_str         _value_neighbor_address;
 static char                       _value_neighbor_address_lost[TEMPLATE_JSON_BOOL_LENGTH];
 static struct isonumber_str       _value_neighbor_address_lost_vtime;
@@ -320,6 +320,9 @@ static struct abuf_template_data_entry _tde_link[] = {
     { KEY_LINK_STATUS, _value_link_status, true },
     { KEY_LINK_DUALSTACK, _value_link_dualstack.buf, true },
     { KEY_LINK_MAC, _value_link_mac.buf, true },
+    { KEY_LINK_FLOOD_LOCAL, _value_link_flood_local, true },
+    { KEY_LINK_FLOOD_REMOTE, _value_link_flood_remote, true },
+    { KEY_LINK_FLOOD_WILL, _value_link_willingness, false },
     { KEY_NEIGHBOR_ORIGINATOR, _value_neighbor_originator.buf, true },
     { KEY_NEIGHBOR_DUALSTACK, _value_neighbor_dualstack.buf, true },
 };
@@ -362,9 +365,6 @@ static struct abuf_template_data_entry _tde_neigh_key[] = {
 
 static struct abuf_template_data_entry _tde_neigh[] = {
     { KEY_NEIGHBOR_DUALSTACK, _value_neighbor_dualstack.buf, true },
-    { KEY_NEIGHBOR_FLOOD_LOCAL, _value_neighbor_flood_local, true },
-    { KEY_NEIGHBOR_FLOOD_REMOTE, _value_neighbor_flood_remote, true },
-    { KEY_NEIGHBOR_FLOOD_WILL, _value_neighbor_willingness, false },
     { KEY_NEIGHBOR_SYMMETRIC, _value_neighbor_symmetric, true },
     { KEY_NEIGHBOR_LINKCOUNT, _value_neighbor_linkcount, false },
 };
@@ -617,6 +617,16 @@ _initialize_nhdp_link_values(struct nhdp_link *lnk) {
   }
 
   netaddr_to_string(&_value_link_mac, &lnk->remote_mac);
+
+  strscpy(_value_link_flood_local,
+      json_getbool(lnk->local_is_flooding_mpr),
+      sizeof(_value_link_flood_local));
+  strscpy(_value_link_flood_remote,
+      json_getbool(lnk->neigh_is_flooding_mpr),
+      sizeof(_value_link_flood_remote));
+  snprintf(_value_link_willingness, sizeof(_value_link_willingness),
+      "%d", lnk->flooding_willingness);
+
 }
 
 /**
@@ -709,15 +719,6 @@ _initialize_nhdp_neighbor_values(struct nhdp_neighbor *neigh) {
     strscpy(_value_neighbor_dualstack.buf, "-", sizeof(_value_neighbor_dualstack));
   }
 
-  strscpy(_value_neighbor_flood_local,
-      json_getbool(neigh->local_is_flooding_mpr),
-      sizeof(_value_neighbor_flood_local));
-  strscpy(_value_neighbor_flood_remote,
-      json_getbool(neigh->neigh_is_flooding_mpr),
-      sizeof(_value_neighbor_flood_remote));
-  snprintf(_value_neighbor_willingness, sizeof(_value_neighbor_willingness),
-      "%d", neigh->flooding_willingness);
-
   strscpy(_value_neighbor_symmetric,
       json_getbool(neigh->symmetric > 0),
       sizeof(_value_neighbor_symmetric));
index 90b3600..351ae90 100644 (file)
@@ -509,14 +509,14 @@ olsrv2_mpr_shall_forwarding(struct rfc5444_reader_tlvblock_context *context,
   }
 
   /* forward if this neighbor has selected us as a flooding MPR */
-  forward = neigh->local_is_flooding_mpr && neigh->symmetric > 0;
+  forward = laddr->link->local_is_flooding_mpr && neigh->symmetric > 0;
   OONF_DEBUG(LOG_OLSRV2, "Do %sforward message type %u from %s"
       " with seqno %u (%s/%u)",
       forward ? "" : "not ",
       context->msg_type,
       netaddr_to_string(&buf, &context->orig_addr),
       context->seqno,
-      neigh->local_is_flooding_mpr ? "true" : "false", neigh->symmetric);
+      laddr->link->local_is_flooding_mpr ? "true" : "false", neigh->symmetric);
   return forward;
 }