diff --git a/exec/totemconfig.c b/exec/totemconfig.c index 381cf4fb..ad1b1166 100644 --- a/exec/totemconfig.c +++ b/exec/totemconfig.c @@ -1,893 +1,897 @@ /* * Copyright (c) 2002-2005 MontaVista Software, Inc. * Copyright (c) 2006-2010 Red Hat, Inc. * * All rights reserved. * * Author: Steven Dake (sdake@redhat.com) * * This software licensed under BSD license, the text of which follows: * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of the MontaVista Software, Inc. nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_LIBNSS #include #include #include #include #endif #include "util.h" #include "totemconfig.h" #include "tlist.h" /* for HZ */ #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST 4 #define TOKEN_TIMEOUT 1000 #define TOKEN_RETRANSMIT_TIMEOUT (int)(TOKEN_TIMEOUT / (TOKEN_RETRANSMITS_BEFORE_LOSS_CONST + 0.2)) #define TOKEN_HOLD_TIMEOUT (int)(TOKEN_RETRANSMIT_TIMEOUT * 0.8 - (1000/(int)HZ)) #define JOIN_TIMEOUT 50 #define MERGE_TIMEOUT 200 #define DOWNCHECK_TIMEOUT 1000 #define FAIL_TO_RECV_CONST 50 #define SEQNO_UNCHANGED_CONST 30 #define MINIMUM_TIMEOUT (int)(1000/HZ)*3 #define MAX_NETWORK_DELAY 50 #define WINDOW_SIZE 50 #define MAX_MESSAGES 17 #define RRP_PROBLEM_COUNT_TIMEOUT 2000 #define RRP_PROBLEM_COUNT_THRESHOLD_DEFAULT 10 #define RRP_PROBLEM_COUNT_THRESHOLD_MIN 5 static char error_string_response[512]; static struct objdb_iface_ver0 *global_objdb; static void add_totem_config_notification( struct objdb_iface_ver0 *objdb, struct totem_config *totem_config, hdb_handle_t totem_object_handle); /* These just makes the code below a little neater */ static inline int objdb_get_string ( const struct objdb_iface_ver0 *objdb, hdb_handle_t object_service_handle, const char *key, const char **value) { int res; *value = NULL; if ( !(res = objdb->object_key_get (object_service_handle, key, strlen (key), (void *)value, NULL))) { if (*value) { return 0; } } return -1; } static inline void objdb_get_int ( const struct objdb_iface_ver0 *objdb, hdb_handle_t object_service_handle, const char *key, unsigned int *intvalue) { char *value = NULL; if (!objdb->object_key_get (object_service_handle, key, strlen (key), (void *)&value, NULL)) { if (value) { *intvalue = atoi(value); } } } static unsigned int totem_handle_find ( struct objdb_iface_ver0 *objdb, hdb_handle_t *totem_find_handle) { hdb_handle_t object_find_handle; unsigned int res; /* * Find a network section */ objdb->object_find_create ( OBJECT_PARENT_HANDLE, "network", strlen ("network"), &object_find_handle); res = objdb->object_find_next ( object_find_handle, totem_find_handle); objdb->object_find_destroy (object_find_handle); /* * Network section not found in configuration, checking for totem */ if (res == -1) { objdb->object_find_create ( OBJECT_PARENT_HANDLE, "totem", strlen ("totem"), &object_find_handle); res = objdb->object_find_next ( object_find_handle, totem_find_handle); objdb->object_find_destroy (object_find_handle); } if (res == -1) { return (-1); } return (0); } static void totem_volatile_config_read ( struct objdb_iface_ver0 *objdb, struct totem_config *totem_config, hdb_handle_t object_totem_handle) { objdb_get_int (objdb,object_totem_handle, "token", &totem_config->token_timeout); objdb_get_int (objdb,object_totem_handle, "token_retransmit", &totem_config->token_retransmit_timeout); objdb_get_int (objdb,object_totem_handle, "hold", &totem_config->token_hold_timeout); objdb_get_int (objdb,object_totem_handle, "token_retransmits_before_loss_const", &totem_config->token_retransmits_before_loss_const); objdb_get_int (objdb,object_totem_handle, "join", &totem_config->join_timeout); objdb_get_int (objdb,object_totem_handle, "send_join", &totem_config->send_join_timeout); objdb_get_int (objdb,object_totem_handle, "consensus", &totem_config->consensus_timeout); objdb_get_int (objdb,object_totem_handle, "merge", &totem_config->merge_timeout); objdb_get_int (objdb,object_totem_handle, "downcheck", &totem_config->downcheck_timeout); objdb_get_int (objdb,object_totem_handle, "fail_recv_const", &totem_config->fail_to_recv_const); objdb_get_int (objdb,object_totem_handle, "seqno_unchanged_const", &totem_config->seqno_unchanged_const); objdb_get_int (objdb,object_totem_handle, "rrp_token_expired_timeout", &totem_config->rrp_token_expired_timeout); objdb_get_int (objdb,object_totem_handle, "rrp_problem_count_timeout", &totem_config->rrp_problem_count_timeout); objdb_get_int (objdb,object_totem_handle, "rrp_problem_count_threshold", &totem_config->rrp_problem_count_threshold); objdb_get_int (objdb,object_totem_handle, "heartbeat_failures_allowed", &totem_config->heartbeat_failures_allowed); objdb_get_int (objdb,object_totem_handle, "max_network_delay", &totem_config->max_network_delay); objdb_get_int (objdb,object_totem_handle, "window_size", &totem_config->window_size); objdb_get_string (objdb, object_totem_handle, "vsftype", &totem_config->vsf_type); objdb_get_int (objdb,object_totem_handle, "max_messages", &totem_config->max_messages); } static void totem_get_crypto_type( const struct objdb_iface_ver0 *objdb, hdb_handle_t object_totem_handle, struct totem_config *totem_config) { const char *str; totem_config->crypto_accept = TOTEM_CRYPTO_ACCEPT_OLD; if (!objdb_get_string (objdb, object_totem_handle, "crypto_accept", &str)) { if (strcmp(str, "new") == 0) { totem_config->crypto_accept = TOTEM_CRYPTO_ACCEPT_NEW; } } totem_config->crypto_type = TOTEM_CRYPTO_SOBER; #ifdef HAVE_LIBNSS /* * We must set these even if the key does not exist. * Encryption type can be set on-the-fly using CFG */ totem_config->crypto_crypt_type = CKM_AES_CBC_PAD; totem_config->crypto_sign_type = CKM_SHA256_RSA_PKCS; #endif if (!objdb_get_string (objdb, object_totem_handle, "crypto_type", &str)) { if (strcmp(str, "sober") == 0) { return; } #ifdef HAVE_LIBNSS if (strcmp(str, "nss") == 0) { totem_config->crypto_type = TOTEM_CRYPTO_NSS; } #endif } } extern int totem_config_read ( struct objdb_iface_ver0 *objdb, struct totem_config *totem_config, const char **error_string) { int res = 0; hdb_handle_t object_totem_handle; hdb_handle_t object_interface_handle; const char *str; unsigned int ringnumber = 0; hdb_handle_t object_find_interface_handle; const char *transport_type; res = totem_handle_find (objdb, &object_totem_handle); if (res == -1) { printf ("couldn't find totem handle\n"); return (-1); } memset (totem_config, 0, sizeof (struct totem_config)); totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX); if (totem_config->interfaces == 0) { *error_string = "Out of memory trying to allocate ethernet interface storage area"; return -1; } memset (totem_config->interfaces, 0, sizeof (struct totem_interface) * INTERFACE_MAX); totem_config->secauth = 1; strcpy (totem_config->rrp_mode, "none"); if (!objdb_get_string (objdb, object_totem_handle, "version", &str)) { if (strcmp (str, "2") == 0) { totem_config->version = 2; } } if (!objdb_get_string (objdb, object_totem_handle, "secauth", &str)) { if (strcmp (str, "on") == 0) { totem_config->secauth = 1; } if (strcmp (str, "off") == 0) { totem_config->secauth = 0; } } if (totem_config->secauth == 1) { totem_get_crypto_type(objdb, object_totem_handle, totem_config); } if (!objdb_get_string (objdb, object_totem_handle, "rrp_mode", &str)) { strcpy (totem_config->rrp_mode, str); } /* * Get interface node id */ objdb_get_int (objdb, object_totem_handle, "nodeid", &totem_config->node_id); totem_config->clear_node_high_bit = 0; if (!objdb_get_string (objdb,object_totem_handle, "clear_node_high_bit", &str)) { if (strcmp (str, "yes") == 0) { totem_config->clear_node_high_bit = 1; } } objdb_get_int (objdb,object_totem_handle, "threads", &totem_config->threads); objdb_get_int (objdb,object_totem_handle, "netmtu", &totem_config->net_mtu); /* * Get things that might change in the future */ totem_volatile_config_read (objdb, totem_config, object_totem_handle); objdb->object_find_create ( object_totem_handle, "interface", strlen ("interface"), &object_find_interface_handle); while (objdb->object_find_next ( object_find_interface_handle, &object_interface_handle) == 0) { objdb_get_int (objdb, object_interface_handle, "ringnumber", &ringnumber); /* * Get interface multicast address */ if (!objdb_get_string (objdb, object_interface_handle, "mcastaddr", &str)) { res = totemip_parse (&totem_config->interfaces[ringnumber].mcast_addr, str, 0); } totem_config->broadcast_use = 0; if (!objdb_get_string (objdb, object_interface_handle, "broadcast", &str)) { if (strcmp (str, "yes") == 0) { totem_config->broadcast_use = 1; totemip_parse ( &totem_config->interfaces[ringnumber].mcast_addr, "255.255.255.255", 0); } } /* * Get mcast port */ if (!objdb_get_string (objdb, object_interface_handle, "mcastport", &str)) { totem_config->interfaces[ringnumber].ip_port = atoi (str); } /* * Get the bind net address */ if (!objdb_get_string (objdb, object_interface_handle, "bindnetaddr", &str)) { res = totemip_parse (&totem_config->interfaces[ringnumber].bindnet, str, totem_config->interfaces[ringnumber].mcast_addr.family); } totem_config->interface_count++; } objdb->object_find_destroy (object_find_interface_handle); add_totem_config_notification(objdb, totem_config, object_totem_handle); totem_config->transport_number = 0; objdb_get_string (objdb, object_totem_handle, "transport", &transport_type); if (transport_type) { if (strcmp (transport_type, "iba") == 0) { totem_config->transport_number = 1; } } return 0; } int totem_config_validate ( struct totem_config *totem_config, const char **error_string) { static char local_error_reason[512]; char parse_error[512]; const char *error_reason = local_error_reason; int i; unsigned int interface_max = INTERFACE_MAX; if (totem_config->interface_count == 0) { error_reason = "No interfaces defined"; goto parse_error; } for (i = 0; i < totem_config->interface_count; i++) { /* * Some error checking of parsed data to make sure its valid */ struct totem_ip_address null_addr; memset (&null_addr, 0, sizeof (struct totem_ip_address)); if (memcmp (&totem_config->interfaces[i].mcast_addr, &null_addr, sizeof (struct totem_ip_address)) == 0) { error_reason = "No multicast address specified"; goto parse_error; } if (totem_config->interfaces[i].ip_port == 0) { error_reason = "No multicast port specified"; goto parse_error; } if (totem_config->interfaces[i].mcast_addr.family == AF_INET6 && totem_config->node_id == 0) { error_reason = "An IPV6 network requires that a node ID be specified."; goto parse_error; } if (totem_config->broadcast_use == 0) { if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) { error_reason = "Multicast address family does not match bind address family"; goto parse_error; } if (totem_config->interfaces[i].mcast_addr.family != totem_config->interfaces[i].bindnet.family) { error_reason = "Not all bind address belong to the same IP family"; goto parse_error; } + if (totemip_is_mcast (&totem_config->interfaces[i].mcast_addr) != 0) { + error_reason = "mcastaddr is not a correct multicast address."; + goto parse_error; + } } } if (totem_config->version != 2) { error_reason = "This totem parser can only parse version 2 configurations."; goto parse_error; } if (totem_config->token_retransmits_before_loss_const == 0) { totem_config->token_retransmits_before_loss_const = TOKEN_RETRANSMITS_BEFORE_LOSS_CONST; } /* * Setup timeout values that are not setup by user */ if (totem_config->token_timeout == 0) { totem_config->token_timeout = TOKEN_TIMEOUT; if (totem_config->token_retransmits_before_loss_const == 0) { totem_config->token_retransmits_before_loss_const = TOKEN_RETRANSMITS_BEFORE_LOSS_CONST; } if (totem_config->token_retransmit_timeout == 0) { totem_config->token_retransmit_timeout = (int)(totem_config->token_timeout / (totem_config->token_retransmits_before_loss_const + 0.2)); } if (totem_config->token_hold_timeout == 0) { totem_config->token_hold_timeout = (int)(totem_config->token_retransmit_timeout * 0.8 - (1000/HZ)); } } if (totem_config->max_network_delay == 0) { totem_config->max_network_delay = MAX_NETWORK_DELAY; } if (totem_config->max_network_delay < MINIMUM_TIMEOUT) { snprintf (local_error_reason, sizeof(local_error_reason), "The max_network_delay parameter (%d ms) may not be less then (%d ms).", totem_config->max_network_delay, MINIMUM_TIMEOUT); goto parse_error; } if (totem_config->window_size == 0) { totem_config->window_size = WINDOW_SIZE; } if (totem_config->max_messages == 0) { totem_config->max_messages = MAX_MESSAGES; } if (totem_config->token_timeout < MINIMUM_TIMEOUT) { snprintf (local_error_reason, sizeof(local_error_reason), "The token timeout parameter (%d ms) may not be less then (%d ms).", totem_config->token_timeout, MINIMUM_TIMEOUT); goto parse_error; } if (totem_config->token_retransmit_timeout == 0) { totem_config->token_retransmit_timeout = (int)(totem_config->token_timeout / (totem_config->token_retransmits_before_loss_const + 0.2)); } if (totem_config->token_hold_timeout == 0) { totem_config->token_hold_timeout = (int)(totem_config->token_retransmit_timeout * 0.8 - (1000/HZ)); } if (totem_config->token_retransmit_timeout < MINIMUM_TIMEOUT) { snprintf (local_error_reason, sizeof(local_error_reason), "The token retransmit timeout parameter (%d ms) may not be less then (%d ms).", totem_config->token_retransmit_timeout, MINIMUM_TIMEOUT); goto parse_error; } if (totem_config->token_hold_timeout == 0) { totem_config->token_hold_timeout = TOKEN_HOLD_TIMEOUT; } if (totem_config->token_hold_timeout < MINIMUM_TIMEOUT) { snprintf (local_error_reason, sizeof(local_error_reason), "The token hold timeout parameter (%d ms) may not be less then (%d ms).", totem_config->token_hold_timeout, MINIMUM_TIMEOUT); goto parse_error; } if (totem_config->join_timeout == 0) { totem_config->join_timeout = JOIN_TIMEOUT; } if (totem_config->join_timeout < MINIMUM_TIMEOUT) { snprintf (local_error_reason, sizeof(local_error_reason), "The join timeout parameter (%d ms) may not be less then (%d ms).", totem_config->join_timeout, MINIMUM_TIMEOUT); goto parse_error; } if (totem_config->consensus_timeout == 0) { totem_config->consensus_timeout = (int)(float)(1.2 * totem_config->token_timeout); } if (totem_config->consensus_timeout < MINIMUM_TIMEOUT) { snprintf (local_error_reason, sizeof(local_error_reason), "The consensus timeout parameter (%d ms) may not be less then (%d ms).", totem_config->consensus_timeout, MINIMUM_TIMEOUT); goto parse_error; } if (totem_config->merge_timeout == 0) { totem_config->merge_timeout = MERGE_TIMEOUT; } if (totem_config->merge_timeout < MINIMUM_TIMEOUT) { snprintf (local_error_reason, sizeof(local_error_reason), "The merge timeout parameter (%d ms) may not be less then (%d ms).", totem_config->merge_timeout, MINIMUM_TIMEOUT); goto parse_error; } if (totem_config->downcheck_timeout == 0) { totem_config->downcheck_timeout = DOWNCHECK_TIMEOUT; } if (totem_config->downcheck_timeout < MINIMUM_TIMEOUT) { snprintf (local_error_reason, sizeof(local_error_reason), "The downcheck timeout parameter (%d ms) may not be less then (%d ms).", totem_config->downcheck_timeout, MINIMUM_TIMEOUT); goto parse_error; } /* * RRP values validation */ if (strcmp (totem_config->rrp_mode, "none") && strcmp (totem_config->rrp_mode, "active") && strcmp (totem_config->rrp_mode, "passive")) { snprintf (local_error_reason, sizeof(local_error_reason), "The RRP mode \"%s\" specified is invalid. It must be none, active, or passive.\n", totem_config->rrp_mode); goto parse_error; } if (totem_config->rrp_problem_count_timeout == 0) { totem_config->rrp_problem_count_timeout = RRP_PROBLEM_COUNT_TIMEOUT; } if (totem_config->rrp_problem_count_timeout < MINIMUM_TIMEOUT) { snprintf (local_error_reason, sizeof(local_error_reason), "The RRP problem count timeout parameter (%d ms) may not be less then (%d ms).", totem_config->rrp_problem_count_timeout, MINIMUM_TIMEOUT); goto parse_error; } if (totem_config->rrp_problem_count_threshold == 0) { totem_config->rrp_problem_count_threshold = RRP_PROBLEM_COUNT_THRESHOLD_DEFAULT; } if (totem_config->rrp_problem_count_threshold < RRP_PROBLEM_COUNT_THRESHOLD_MIN) { snprintf (local_error_reason, sizeof(local_error_reason), "The RRP problem count threshold (%d problem count) may not be less then (%d problem count).", totem_config->rrp_problem_count_threshold, RRP_PROBLEM_COUNT_THRESHOLD_MIN); goto parse_error; } if (totem_config->rrp_token_expired_timeout == 0) { totem_config->rrp_token_expired_timeout = totem_config->token_retransmit_timeout; } if (totem_config->rrp_token_expired_timeout < MINIMUM_TIMEOUT) { snprintf (local_error_reason, sizeof(local_error_reason), "The RRP token expired timeout parameter (%d ms) may not be less then (%d ms).", totem_config->rrp_token_expired_timeout, MINIMUM_TIMEOUT); goto parse_error; } if (strcmp (totem_config->rrp_mode, "none") == 0) { interface_max = 1; } if (interface_max < totem_config->interface_count) { snprintf (parse_error, sizeof(parse_error), "%d is too many configured interfaces for the rrp_mode setting %s.", totem_config->interface_count, totem_config->rrp_mode); error_reason = parse_error; goto parse_error; } if (totem_config->fail_to_recv_const == 0) { totem_config->fail_to_recv_const = FAIL_TO_RECV_CONST; } if (totem_config->seqno_unchanged_const == 0) { totem_config->seqno_unchanged_const = SEQNO_UNCHANGED_CONST; } if (totem_config->net_mtu == 0) { totem_config->net_mtu = 1500; } if ((MESSAGE_QUEUE_MAX) < totem_config->max_messages) { snprintf (local_error_reason, sizeof(local_error_reason), "The max_messages parameter (%d messages) may not be greater then (%d messages).", totem_config->max_messages, MESSAGE_QUEUE_MAX); goto parse_error; } if (totem_config->threads > SEND_THREADS_MAX) { totem_config->threads = SEND_THREADS_MAX; } if (totem_config->secauth == 0) { totem_config->threads = 0; } if (totem_config->net_mtu > FRAME_SIZE_MAX) { error_reason = "This net_mtu parameter is greater then the maximum frame size"; goto parse_error; } if (totem_config->vsf_type == NULL) { totem_config->vsf_type = "none"; } return (0); parse_error: snprintf (error_string_response, sizeof(error_string_response), "parse error in config: %s\n", error_reason); *error_string = error_string_response; return (-1); } static int read_keyfile ( const char *key_location, struct totem_config *totem_config, const char **error_string) { int fd; int res; ssize_t expected_key_len = sizeof (totem_config->private_key); int saved_errno; char error_str[100]; fd = open (key_location, O_RDONLY); if (fd == -1) { strerror_r (errno, error_str, 100); snprintf (error_string_response, sizeof(error_string_response), "Could not open %s: %s\n", key_location, error_str); goto parse_error; } res = read (fd, totem_config->private_key, expected_key_len); saved_errno = errno; close (fd); if (res == -1) { strerror_r (errno, error_str, 100); snprintf (error_string_response, sizeof(error_string_response), "Could not read %s: %s\n", key_location, error_str); goto parse_error; } totem_config->private_key_len = expected_key_len; if (res != expected_key_len) { snprintf (error_string_response, sizeof(error_string_response), "Could only read %d bits of 1024 bits from %s.\n", res * 8, key_location); goto parse_error; } return 0; parse_error: *error_string = error_string_response; return (-1); } int totem_config_keyread ( struct objdb_iface_ver0 *objdb, struct totem_config *totem_config, const char **error_string) { int got_key = 0; const char *key_location = NULL; hdb_handle_t object_totem_handle; int res; memset (totem_config->private_key, 0, 128); totem_config->private_key_len = 128; if (totem_config->secauth == 0) { return (0); } res = totem_handle_find (objdb, &object_totem_handle); if (res == -1) { return (-1); } /* objdb may store the location of the key file */ if (!objdb_get_string (objdb,object_totem_handle, "keyfile", &key_location) && key_location) { res = read_keyfile(key_location, totem_config, error_string); if (res) { goto key_error; } got_key = 1; } else { /* Or the key itself may be in the objdb */ char *key = NULL; size_t key_len; res = objdb->object_key_get (object_totem_handle, "key", strlen ("key"), (void *)&key, &key_len); if (res == 0 && key) { if (key_len > sizeof (totem_config->private_key)) { goto key_error; } memcpy(totem_config->private_key, key, key_len); totem_config->private_key_len = key_len; got_key = 1; } } /* In desperation we read the default filename */ if (!got_key) { const char *filename = getenv("COROSYNC_TOTEM_AUTHKEY_FILE"); if (!filename) filename = COROSYSCONFDIR "/authkey"; res = read_keyfile(filename, totem_config, error_string); if (res) goto key_error; } return (0); key_error: *error_string = error_string_response; return (-1); } static void totem_key_change_notify(object_change_type_t change_type, hdb_handle_t parent_object_handle, hdb_handle_t object_handle, const void *object_name_pt, size_t object_name_len, const void *key_name_pt, size_t key_len, const void *key_value_pt, size_t key_value_len, void *priv_data_pt) { struct totem_config *totem_config = priv_data_pt; if (memcmp(object_name_pt, "totem", object_name_len) == 0) totem_volatile_config_read(global_objdb, totem_config, object_handle); // CHECK } static void totem_objdb_reload_notify(objdb_reload_notify_type_t type, int flush, void *priv_data_pt) { struct totem_config *totem_config = priv_data_pt; hdb_handle_t totem_object_handle; if (totem_config == NULL) return; /* * A new totem {} key might exist, cancel the * existing notification at the start of reload, * and start a new one on the new object when * it's all settled. */ if (type == OBJDB_RELOAD_NOTIFY_START) { global_objdb->object_track_stop( totem_key_change_notify, NULL, NULL, NULL, totem_config); } if (type == OBJDB_RELOAD_NOTIFY_END || type == OBJDB_RELOAD_NOTIFY_FAILED) { if (!totem_handle_find(global_objdb, &totem_object_handle)) { global_objdb->object_track_start(totem_object_handle, 1, totem_key_change_notify, NULL, // object_create_notify, NULL, // object_destroy_notify, NULL, // object_reload_notify totem_config); // priv_data /* * Reload the configuration */ totem_volatile_config_read(global_objdb, totem_config, totem_object_handle); } else { log_printf(LOGSYS_LEVEL_ERROR, "totem objdb tracking stopped, cannot find totem{} handle on objdb\n"); } } } static void add_totem_config_notification( struct objdb_iface_ver0 *objdb, struct totem_config *totem_config, hdb_handle_t totem_object_handle) { global_objdb = objdb; objdb->object_track_start(totem_object_handle, 1, totem_key_change_notify, NULL, // object_create_notify, NULL, // object_destroy_notify, NULL, // object_reload_notify totem_config); // priv_data /* * Reload notify must be on the parent object */ objdb->object_track_start(OBJECT_PARENT_HANDLE, 1, NULL, // key_change_notify, NULL, // object_create_notify, NULL, // object_destroy_notify, totem_objdb_reload_notify, // object_reload_notify totem_config); // priv_data } diff --git a/exec/totemip.c b/exec/totemip.c index f6613e89..d6bb34a9 100644 --- a/exec/totemip.c +++ b/exec/totemip.c @@ -1,653 +1,671 @@ /* * Copyright (c) 2005-2007, 2009 Red Hat, Inc. * * All rights reserved. * * Author: Patrick Caulfield (pcaulfie@redhat.com) * * This software licensed under BSD license, the text of which follows: * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of the MontaVista Software, Inc. nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ /* IPv4/6 abstraction */ #include #include #include #include #include #include #include #include #if defined(COROSYNC_SOLARIS) #include #include #endif #if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN) #include #include #include #include #include #include #endif #include #include #include #include #include #include #if defined(COROSYNC_LINUX) #include #include #include #endif #include #include #define LOCALHOST_IPV4 "127.0.0.1" #define LOCALHOST_IPV6 "::1" #define NETLINK_BUFSIZE 16384 #ifdef SO_NOSIGPIPE void totemip_nosigpipe(int s) { int on = 1; setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(on)); } #endif /* Compare two addresses */ int totemip_equal(const struct totem_ip_address *addr1, const struct totem_ip_address *addr2) { int addrlen = 0; if (addr1->family != addr2->family) return 0; if (addr1->family == AF_INET) { addrlen = sizeof(struct in_addr); } if (addr1->family == AF_INET6) { addrlen = sizeof(struct in6_addr); } assert(addrlen); if (memcmp(addr1->addr, addr2->addr, addrlen) == 0) return 1; else return 0; } /* Copy a totem_ip_address */ void totemip_copy(struct totem_ip_address *addr1, const struct totem_ip_address *addr2) { memcpy(addr1, addr2, sizeof(struct totem_ip_address)); } void totemip_copy_endian_convert(struct totem_ip_address *addr1, const struct totem_ip_address *addr2) { addr1->nodeid = swab32(addr2->nodeid); addr1->family = swab16(addr2->family); memcpy(addr1->addr, addr2->addr, TOTEMIP_ADDRLEN); } +/* + * Multicast address range is 224.0.0.0 to 239.255.255.255 this + * translates to the first 4 bits == 1110 (0xE). + * http://en.wikipedia.org/wiki/Multicast_address + */ +int32_t totemip_is_mcast(struct totem_ip_address *ip_addr) +{ + uint32_t addr = 0; + + if (ip_addr->family == AF_INET) { + addr = ntohl(*(int32_t*)ip_addr->addr); + if ((addr >> 28) != 0xE) { + return -1; + } + } + return 0; +} + /* For sorting etc. params are void * for qsort's benefit */ int totemip_compare(const void *a, const void *b) { int i; const struct totem_ip_address *totemip_a = (const struct totem_ip_address *)a; const struct totem_ip_address *totemip_b = (const struct totem_ip_address *)b; struct in_addr ipv4_a1; struct in_addr ipv4_a2; struct in6_addr ipv6_a1; struct in6_addr ipv6_a2; unsigned short family; /* * Use memcpy to align since totem_ip_address is unaligned on various archs */ memcpy (&family, &totemip_a->family, sizeof (unsigned short)); if (family == AF_INET) { memcpy (&ipv4_a1, totemip_a->addr, sizeof (struct in_addr)); memcpy (&ipv4_a2, totemip_b->addr, sizeof (struct in_addr)); if (ipv4_a1.s_addr == ipv4_a2.s_addr) { return (0); } if (htonl(ipv4_a1.s_addr) < htonl(ipv4_a2.s_addr)) { return -1; } else { return +1; } } else if (family == AF_INET6) { /* * We can only compare 8 bits at time for portability reasons */ memcpy (&ipv6_a1, totemip_a->addr, sizeof (struct in6_addr)); memcpy (&ipv6_a2, totemip_b->addr, sizeof (struct in6_addr)); for (i = 0; i < 16; i++) { int res = ipv6_a1.s6_addr[i] - ipv6_a2.s6_addr[i]; if (res) { return res; } } return 0; } else { /* * Family not set, should be! */ assert (0); } return 0; } /* Build a localhost totem_ip_address */ int totemip_localhost(int family, struct totem_ip_address *localhost) { const char *addr_text; memset (localhost, 0, sizeof (struct totem_ip_address)); if (family == AF_INET) { addr_text = LOCALHOST_IPV4; if (inet_pton(family, addr_text, (char *)&localhost->nodeid) <= 0) { return -1; } } else { addr_text = LOCALHOST_IPV6; } if (inet_pton(family, addr_text, (char *)localhost->addr) <= 0) return -1; localhost->family = family; return 0; } int totemip_localhost_check(const struct totem_ip_address *addr) { struct totem_ip_address localhost; if (totemip_localhost(addr->family, &localhost)) return 0; return totemip_equal(addr, &localhost); } const char *totemip_print(const struct totem_ip_address *addr) { static char buf[INET6_ADDRSTRLEN]; return (inet_ntop(addr->family, addr->addr, buf, sizeof(buf))); } /* Make a totem_ip_address into a usable sockaddr_storage */ int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr, uint16_t port, struct sockaddr_storage *saddr, int *addrlen) { int ret = -1; if (ip_addr->family == AF_INET) { struct sockaddr_in *sin = (struct sockaddr_in *)saddr; memset(sin, 0, sizeof(struct sockaddr_in)); #if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN) sin->sin_len = sizeof(struct sockaddr_in); #endif sin->sin_family = ip_addr->family; sin->sin_port = ntohs(port); memcpy(&sin->sin_addr, ip_addr->addr, sizeof(struct in_addr)); *addrlen = sizeof(struct sockaddr_in); ret = 0; } if (ip_addr->family == AF_INET6) { struct sockaddr_in6 *sin = (struct sockaddr_in6 *)saddr; memset(sin, 0, sizeof(struct sockaddr_in6)); #if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN) sin->sin6_len = sizeof(struct sockaddr_in6); #endif sin->sin6_family = ip_addr->family; sin->sin6_port = ntohs(port); sin->sin6_scope_id = 2; memcpy(&sin->sin6_addr, ip_addr->addr, sizeof(struct in6_addr)); *addrlen = sizeof(struct sockaddr_in6); ret = 0; } return ret; } /* Converts an address string string into a totem_ip_address. family can be AF_INET, AF_INET6 or 0 ("for "don't care") */ int totemip_parse(struct totem_ip_address *totemip, const char *addr, int family) { struct addrinfo *ainfo; struct addrinfo ahints; struct sockaddr_in *sa; struct sockaddr_in6 *sa6; int ret; memset(&ahints, 0, sizeof(ahints)); ahints.ai_socktype = SOCK_DGRAM; ahints.ai_protocol = IPPROTO_UDP; ahints.ai_family = family; /* Lookup the nodename address */ ret = getaddrinfo(addr, NULL, &ahints, &ainfo); if (ret) return -1; sa = (struct sockaddr_in *)ainfo->ai_addr; sa6 = (struct sockaddr_in6 *)ainfo->ai_addr; totemip->family = ainfo->ai_family; if (ainfo->ai_family == AF_INET) memcpy(totemip->addr, &sa->sin_addr, sizeof(struct in_addr)); else memcpy(totemip->addr, &sa6->sin6_addr, sizeof(struct in6_addr)); return 0; } /* Make a sockaddr_* into a totem_ip_address */ int totemip_sockaddr_to_totemip_convert(const struct sockaddr_storage *saddr, struct totem_ip_address *ip_addr) { int ret = -1; ip_addr->family = saddr->ss_family; ip_addr->nodeid = 0; if (saddr->ss_family == AF_INET) { const struct sockaddr_in *sin = (const struct sockaddr_in *)saddr; memcpy(ip_addr->addr, &sin->sin_addr, sizeof(struct in_addr)); ret = 0; } if (saddr->ss_family == AF_INET6) { const struct sockaddr_in6 *sin = (const struct sockaddr_in6 *)saddr; memcpy(ip_addr->addr, &sin->sin6_addr, sizeof(struct in6_addr)); ret = 0; } return ret; } /* * On Solaris, man if_tcp describes this method */ #if defined(COROSYNC_SOLARIS) int totemip_iface_check(struct totem_ip_address *bindnet, struct totem_ip_address *boundto, int *interface_up, int *interface_num, int mask_high_bit) { struct sockaddr_storage bindnet_ss; struct sockaddr_in *bindnet_sin = (struct sockaddr_in *)&bindnet_ss; struct sockaddr_in *sockaddr_in; int id_fd; struct lifconf lifconf; struct lifreq *lifreq; int numreqs = 0; int i; in_addr_t mask_addr; int res = -1; int addrlen; totemip_totemip_to_sockaddr_convert (bindnet, 0, &bindnet_ss, &addrlen); *interface_up = 0; id_fd = socket (AF_INET, SOCK_STREAM, 0); lifconf.lifc_family = AF_UNSPEC; lifconf.lifc_flags = 0; lifconf.lifc_buf = NULL; lifconf.lifc_len = 0; do { numreqs += 32; lifconf.lifc_len = sizeof (struct lifreq) * numreqs; lifconf.lifc_buf = (void *)realloc(lifconf.lifc_buf, lifconf.lifc_len); res = ioctl (id_fd, SIOCGLIFCONF, &lifconf); if (res < 0) { close (id_fd); return -1; } } while (lifconf.lifc_len == sizeof (struct lifconf) * numreqs); res = -1; lifreq = (struct lifreq *)lifconf.lifc_buf; /* * Find interface address to bind to */ for (i = 0; i < lifconf.lifc_len / sizeof (struct lifreq); i++) { sockaddr_in = (struct sockaddr_in *)&lifreq[i].lifr_addr; mask_addr = inet_addr ("255.255.255.0"); if ((sockaddr_in->sin_family == AF_INET) && (sockaddr_in->sin_addr.s_addr & mask_addr) == (bindnet_sin->sin_addr.s_addr & mask_addr)) { res = i; /* * Setup boundto output */ totemip_sockaddr_to_totemip_convert((struct sockaddr_storage *)sockaddr_in, boundto); boundto->nodeid = sockaddr_in->sin_addr.s_addr; #if __BYTE_ORDER == __BIG_ENDIAN boundto->nodeid = swab32 (boundto->nodeid); #endif if (ioctl(id_fd, SIOCGLIFFLAGS, &lifreq[i]) < 0) { printf ("couldn't do ioctl\n"); } *interface_up = lifreq[i].lifr_flags & IFF_UP; if (ioctl(id_fd, SIOCGLIFINDEX, &lifreq[i]) < 0) { printf ("couldn't do ioctl\n"); } *interface_num = lifreq[i].lifr_index; break; } } free (lifconf.lifc_buf); close (id_fd); return (res); } #endif #if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN) int totemip_iface_check(struct totem_ip_address *bindnet, struct totem_ip_address *boundto, int *interface_up, int *interface_num, int mask_high_bit) { #define NEXT_IFR(a) ((struct ifreq *)((u_char *)&(a)->ifr_addr +\ ((a)->ifr_addr.sa_len ? (a)->ifr_addr.sa_len : sizeof((a)->ifr_addr)))) struct sockaddr_in *intf_addr_mask; struct sockaddr_storage bindnet_ss; struct sockaddr_in *intf_addr_sin; struct sockaddr_in *bindnet_sin = (struct sockaddr_in *)&bindnet_ss; struct ifaddrs *ifap, *ifa; int res = -1; int addrlen; *interface_up = 0; *interface_num = 0; totemip_totemip_to_sockaddr_convert(bindnet, 0, &bindnet_ss, &addrlen); if (getifaddrs(&ifap) != 0) return -1; for (ifa = ifap; ifa; ifa = ifa->ifa_next) { intf_addr_sin = (struct sockaddr_in *)ifa->ifa_addr; intf_addr_mask = (struct sockaddr_in *)ifa->ifa_netmask; if (intf_addr_sin->sin_family != AF_INET) continue; if ( bindnet_sin->sin_family == AF_INET && (intf_addr_sin->sin_addr.s_addr & intf_addr_mask->sin_addr.s_addr) == (bindnet_sin->sin_addr.s_addr & intf_addr_mask->sin_addr.s_addr)) { totemip_copy(boundto, bindnet); memcpy(boundto->addr, &intf_addr_sin->sin_addr, sizeof(intf_addr_sin->sin_addr)); /* Get interface infos */ *interface_up = ifa->ifa_flags & IFF_UP; *interface_num = if_nametoindex(ifa->ifa_name); /* * Handle case, when nodeid is set to 0 or not set. */ if (bindnet->family == AF_INET && bindnet->nodeid == 0) { unsigned int nodeid = 0; memcpy (&nodeid, boundto->addr, sizeof (int)); #if _BYTE_ORDER == _BIG_ENDIAN nodeid = swab32 (nodeid); #endif /* * Mask 32nd bit off to workaround bugs in other peoples code * (if configuration requests it). */ if (mask_high_bit) { nodeid &= 0x7FFFFFFF; } boundto->nodeid = nodeid; } res = 0; break; /* for */ } } freeifaddrs(ifap); return (res); } #elif defined(COROSYNC_LINUX) static void parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) { while (RTA_OK(rta, len)) { if (rta->rta_type <= max) tb[rta->rta_type] = rta; rta = RTA_NEXT(rta,len); } } int totemip_iface_check(struct totem_ip_address *bindnet, struct totem_ip_address *boundto, int *interface_up, int *interface_num, int mask_high_bit) { int fd; int res = -1; struct { struct nlmsghdr nlh; struct rtgenmsg g; } req; struct sockaddr_nl nladdr; struct totem_ip_address ipaddr; static char rcvbuf[NETLINK_BUFSIZE]; *interface_up = 0; *interface_num = 0; memset(&ipaddr, 0, sizeof(ipaddr)); /* Make sure we preserve these */ ipaddr.family = bindnet->family; ipaddr.nodeid = bindnet->nodeid; /* Ask netlink for a list of interface addresses */ fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (fd <0) return -1; setsockopt(fd,SOL_SOCKET,SO_RCVBUF,&rcvbuf,sizeof(rcvbuf)); memset(&nladdr, 0, sizeof(nladdr)); nladdr.nl_family = AF_NETLINK; memset(&req, 0, sizeof(req)); req.nlh.nlmsg_len = sizeof(req); req.nlh.nlmsg_type = RTM_GETADDR; req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST; req.nlh.nlmsg_pid = 0; req.nlh.nlmsg_seq = 1; req.g.rtgen_family = bindnet->family; if (sendto(fd, (void *)&req, sizeof(req), 0, (struct sockaddr*)&nladdr, sizeof(nladdr)) < 0) { close(fd); return -1; } /* Look through the return buffer for our address */ while (1) { int status; struct nlmsghdr *h; struct iovec iov = { rcvbuf, sizeof(rcvbuf) }; struct msghdr msg = { (void*)&nladdr, sizeof(nladdr), &iov, 1, NULL, 0, 0 }; status = recvmsg(fd, &msg, 0); if (!status) { close(fd); return -1; } h = (struct nlmsghdr *)rcvbuf; if (h->nlmsg_type == NLMSG_DONE) break; if (h->nlmsg_type == NLMSG_ERROR) { close(fd); return -1; } while (NLMSG_OK(h, status)) { if (h->nlmsg_type == RTM_NEWADDR) { struct ifaddrmsg *ifa = NLMSG_DATA(h); struct rtattr *tb[IFA_MAX+1]; int len = h->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa)); int found_if = 0; memset(tb, 0, sizeof(tb)); parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), len); memcpy(ipaddr.addr, RTA_DATA(tb[IFA_ADDRESS]), TOTEMIP_ADDRLEN); if (totemip_equal(&ipaddr, bindnet)) { found_if = 1; } /* If the address we have is an IPv4 network address, then substitute the actual IP address of this interface */ if (!found_if && tb[IFA_LOCAL] && ifa->ifa_family == AF_INET) { uint32_t network; uint32_t addr; uint32_t netmask = htonl(~((1<<(32-ifa->ifa_prefixlen))-1)); memcpy(&network, RTA_DATA(tb[IFA_LOCAL]), sizeof(uint32_t)); memcpy(&addr, bindnet->addr, sizeof(uint32_t)); if ((addr & netmask) == (network & netmask)) { memcpy(ipaddr.addr, RTA_DATA(tb[IFA_ADDRESS]), TOTEMIP_ADDRLEN); found_if = 1; } } if (found_if) { /* Found it - check I/F is UP */ struct ifreq ifr; int ioctl_fd; /* Can't do ioctls on netlink FDs */ ioctl_fd = socket(AF_INET, SOCK_STREAM, 0); if (ioctl_fd < 0) { close(fd); return -1; } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_ifindex = ifa->ifa_index; /* SIOCGIFFLAGS needs an interface name */ status = ioctl(ioctl_fd, SIOCGIFNAME, &ifr); status = ioctl(ioctl_fd, SIOCGIFFLAGS, &ifr); close(ioctl_fd); if (status) { res = -1; goto finished; } if (ifr.ifr_flags & IFF_UP) *interface_up = 1; *interface_num = ifa->ifa_index; /* * Mask 32nd bit off to workaround bugs in other peoples code * (if configuration requests it). */ if (ipaddr.family == AF_INET && ipaddr.nodeid == 0) { unsigned int nodeid = 0; memcpy (&nodeid, ipaddr.addr, sizeof (int)); #if __BYTE_ORDER == __BIG_ENDIAN nodeid = swab32 (nodeid); #endif if (mask_high_bit) { nodeid &= 0x7FFFFFFF; } ipaddr.nodeid = nodeid; } totemip_copy (boundto, &ipaddr); res = 0; goto finished; } } h = NLMSG_NEXT(h, status); } } res = -1; /* address not found */ finished: close(fd); return res; } #endif /* COROSYNC_LINUX */ diff --git a/include/corosync/totem/totemip.h b/include/corosync/totem/totemip.h index 9f45b5f9..e7f1d18d 100644 --- a/include/corosync/totem/totemip.h +++ b/include/corosync/totem/totemip.h @@ -1,104 +1,105 @@ /* * Copyright (c) 2005-2007, 2009 Red Hat, Inc. * * All rights reserved. * * Author: Patrick Caulfield (pcaulfie@redhat.com) * * This software licensed under BSD license, the text of which follows: * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of the MontaVista Software, Inc. nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ /* IPv4/6 abstraction */ #ifndef TOTEMIP_H_DEFINED #define TOTEMIP_H_DEFINED #include #include #ifdef __cplusplus extern "C" { #endif #ifdef SO_NOSIGPIPE #ifndef MSG_NOSIGNAL #define MSG_NOSIGNAL 0 #endif void totemip_nosigpipe(int s); #else #define totemip_nosigpipe(s) #endif #define TOTEMIP_ADDRLEN (sizeof(struct in6_addr)) /* These are the things that get passed around */ #define TOTEM_IP_ADDRESS struct totem_ip_address { unsigned int nodeid; unsigned short family; unsigned char addr[TOTEMIP_ADDRLEN]; } __attribute__((packed)); extern int totemip_equal(const struct totem_ip_address *addr1, const struct totem_ip_address *addr2); extern int totemip_compare(const void *a, const void *b); +extern int totemip_is_mcast(struct totem_ip_address *addr); extern void totemip_copy(struct totem_ip_address *addr1, const struct totem_ip_address *addr2); extern void totemip_copy_endian_convert(struct totem_ip_address *addr1, const struct totem_ip_address *addr2); int totemip_localhost(int family, struct totem_ip_address *localhost); extern int totemip_localhost_check(const struct totem_ip_address *addr); extern const char *totemip_print(const struct totem_ip_address *addr); extern int totemip_sockaddr_to_totemip_convert(const struct sockaddr_storage *saddr, struct totem_ip_address *ip_addr); extern int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr, uint16_t port, struct sockaddr_storage *saddr, int *addrlen); extern int totemip_parse(struct totem_ip_address *totemip, const char *addr, int family); extern int totemip_iface_check(struct totem_ip_address *bindnet, struct totem_ip_address *boundto, int *interface_up, int *interface_num, int mask_high_bit); /* These two simulate a zero in_addr by clearing the family field */ static inline void totemip_zero_set(struct totem_ip_address *addr) { addr->family = 0; } static inline int totemip_zero_check(const struct totem_ip_address *addr) { return (addr->family == 0); } #ifdef __cplusplus } #endif #endif