Reviewed-by: Steven Dake <sdake@xxxxxxxxxx> On 02/15/2012 09:09 AM, Jan Friesse wrote: > Thanks to totemip_getifaddrs infrastructure it's now possible to use > nodelist informations to autoconfigure interface bindnetaddr. Together > with cluster_name, interface section can be completely omitted. > > Signed-off-by: Jan Friesse <jfriesse@xxxxxxxxxx> > --- > exec/coroparse.c | 4 -- > exec/totemconfig.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 95 insertions(+), 4 deletions(-) > > diff --git a/exec/coroparse.c b/exec/coroparse.c > index 642ee00..e6a5cb8 100644 > --- a/exec/coroparse.c > +++ b/exec/coroparse.c > @@ -695,10 +695,6 @@ static int main_config_parser_cb(const char *path, > > free(data->bindnetaddr); > data->bindnetaddr = NULL; > - } else { > - *error_string = "No bindnetaddr for interface"; > - > - return (0); > } > > if (data->mcastaddr != NULL) { > diff --git a/exec/totemconfig.c b/exec/totemconfig.c > index f84687c..0b7951c 100644 > --- a/exec/totemconfig.c > +++ b/exec/totemconfig.c > @@ -311,6 +311,92 @@ static void put_nodelist_members_to_config(struct totem_config *totem_config) > icmap_iter_finalize(iter); > } > > +static void config_convert_nodelist_to_interface(struct totem_config *totem_config) > +{ > + icmap_iter_t iter; > + const char *iter_key; > + int res = 0; > + int node_pos; > + char tmp_key[ICMAP_KEYNAME_MAXLEN]; > + char tmp_key2[ICMAP_KEYNAME_MAXLEN]; > + char *node_addr_str; > + unsigned int ringnumber = 0; > + struct list_head addrs; > + struct list_head *list; > + struct totem_ip_if_address *if_addr; > + struct totem_ip_address node_addr; > + int node_found; > + > + if (totemip_getifaddrs(&addrs) == -1) { > + return ; > + } > + > + iter = icmap_iter_init("nodelist.node."); > + while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) { > + res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key); > + if (res != 2) { > + continue; > + } > + > + if (strcmp(tmp_key, "ring0_addr") != 0) { > + continue; > + } > + > + if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) { > + continue ; > + } > + > + if (totemip_parse(&node_addr, node_addr_str, 0) == -1) { > + free(node_addr_str); > + continue ; > + } > + free(node_addr_str); > + > + /* > + * Try to find node in if_addrs > + */ > + node_found = 0; > + for (list = addrs.next; list != &addrs; list = list->next) { > + if_addr = list_entry(list, struct totem_ip_if_address, list); > + > + if (totemip_equal(&node_addr, &if_addr->ip_addr)) { > + node_found = 1; > + break; > + } > + } > + > + if (node_found) { > + break ; > + } > + } > + > + icmap_iter_finalize(iter); > + > + if (node_found) { > + /* > + * We found node, so create interface section > + */ > + snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos); > + iter = icmap_iter_init(tmp_key); > + while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) { > + res = sscanf(iter_key, "nodelist.node.%u.ring%u%s", &node_pos, &ringnumber, tmp_key2); > + if (res != 3 || strcmp(tmp_key2, "_addr") != 0) { > + continue ; > + } > + > + if (icmap_get_string(iter_key, &node_addr_str) != CS_OK) { > + continue; > + } > + > + snprintf(tmp_key2, ICMAP_KEYNAME_MAXLEN, "totem.interface.%u.bindnetaddr", ringnumber); > + icmap_set_string(tmp_key2, node_addr_str); > + free(node_addr_str); > + } > + icmap_iter_finalize(iter); > + } > +} > + > + > extern int totem_config_read ( > struct totem_config *totem_config, > const char **error_string, > @@ -396,6 +482,15 @@ extern int totem_config_read ( > */ > totem_volatile_config_read(totem_config); > > + if (icmap_get_string("totem.interface.0.bindnetaddr", &str) != CS_OK) { > + /* > + * We were not able to find ring 0 bindnet addr. Try to use nodelist informations > + */ > + config_convert_nodelist_to_interface(totem_config); > + } else { > + free(str); > + } > + > iter = icmap_iter_init("totem.interface."); > while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) { > res = sscanf(iter_key, "totem.interface.%[^.].%s", ringnumber_key, tmp_key); _______________________________________________ discuss mailing list discuss@xxxxxxxxxxxx http://lists.corosync.org/mailman/listinfo/discuss