X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetwork.c;h=ac076cccb96dcd5986f406f91cb47747aca285f1;hb=290741f2e6de9e9b467463c1f0c6f031c4036428;hp=0ee6ed0b9834f96a9ad1cd885657c0e5f9719c89;hpb=af6222065f1f5d8969afdde89c9f26a73e1e1690;p=collectd.git diff --git a/src/network.c b/src/network.c index 0ee6ed0b..ac076ccc 100644 --- a/src/network.c +++ b/src/network.c @@ -36,12 +36,6 @@ #include "network.h" -#if HAVE_PTHREAD_H -# include -#endif -#if HAVE_SYS_SOCKET_H -# include -#endif #if HAVE_NETDB_H # include #endif @@ -59,7 +53,6 @@ #endif #if HAVE_LIBGCRYPT -# include # if defined __APPLE__ /* default xcode compiler throws warnings even when deprecated functionality * is not used. -Werror breaks the build because of erroneous warnings. @@ -120,6 +113,8 @@ struct sockent_client gcry_cipher_hd_t cypher; unsigned char password_hash[32]; #endif + cdtime_t next_resolve_reconnect; + cdtime_t resolve_interval; }; struct sockent_server @@ -281,8 +276,8 @@ typedef struct receive_list_entry_s receive_list_entry_t; static int network_config_ttl = 0; /* Ethernet - (IPv6 + UDP) = 1500 - (40 + 8) = 1452 */ static size_t network_config_packet_size = 1452; -static int network_config_forward = 0; -static int network_config_stats = 0; +static _Bool network_config_forward = 0; +static _Bool network_config_stats = 0; static sockent_t *sending_sockets = NULL; @@ -308,6 +303,7 @@ static pthread_t dispatch_thread_id; static char *send_buffer; static char *send_buffer_ptr; static int send_buffer_fill; +static cdtime_t send_buffer_last_update; static value_list_t send_buffer_vl = VALUE_LIST_STATIC; static pthread_mutex_t send_buffer_lock = PTHREAD_MUTEX_INITIALIZER; @@ -351,7 +347,7 @@ static _Bool check_send_okay (const value_list_t *vl) /* {{{ */ _Bool received = 0; int status; - if (network_config_forward != 0) + if (network_config_forward) return (1); if (vl->meta == NULL) @@ -618,14 +614,14 @@ static int write_part_values (char **ret_buffer, int *ret_buffer_len, if (*ret_buffer_len < packet_len) return (-1); - pkg_values_types = (uint8_t *) malloc (num_values * sizeof (uint8_t)); + pkg_values_types = malloc (num_values * sizeof (*pkg_values_types)); if (pkg_values_types == NULL) { ERROR ("network plugin: write_part_values: malloc failed."); return (-1); } - pkg_values = (value_t *) malloc (num_values * sizeof (value_t)); + pkg_values = malloc (num_values * sizeof (*pkg_values)); if (pkg_values == NULL) { free (pkg_values_types); @@ -769,18 +765,18 @@ static int write_part_string (char **ret_buffer, int *ret_buffer_len, } /* int write_part_string */ static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len, - value_t **ret_values, int *ret_num_values) + value_t **ret_values, size_t *ret_num_values) { char *buffer = *ret_buffer; size_t buffer_len = *ret_buffer_len; uint16_t tmp16; size_t exp_size; - int i; + size_t i; uint16_t pkg_length; uint16_t pkg_type; - uint16_t pkg_numval; + size_t pkg_numval; uint8_t *pkg_types; value_t *pkg_values; @@ -802,7 +798,7 @@ static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len, memcpy ((void *) &tmp16, buffer, sizeof (tmp16)); buffer += sizeof (tmp16); - pkg_numval = ntohs (tmp16); + pkg_numval = (size_t) ntohs (tmp16); assert (pkg_type == TYPE_VALUES); @@ -817,6 +813,7 @@ static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len, exp_size, buffer_len); return (-1); } + assert (pkg_numval <= ((buffer_len - 6) / 9)); if (pkg_length != exp_size) { @@ -826,20 +823,20 @@ static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len, return (-1); } - pkg_types = (uint8_t *) malloc (pkg_numval * sizeof (uint8_t)); - pkg_values = (value_t *) malloc (pkg_numval * sizeof (value_t)); + pkg_types = calloc (pkg_numval, sizeof (*pkg_types)); + pkg_values = calloc (pkg_numval, sizeof (*pkg_values)); if ((pkg_types == NULL) || (pkg_values == NULL)) { sfree (pkg_types); sfree (pkg_values); - ERROR ("network plugin: parse_part_values: malloc failed."); + ERROR ("network plugin: parse_part_values: calloc failed."); return (-1); } - memcpy ((void *) pkg_types, (void *) buffer, pkg_numval * sizeof (uint8_t)); - buffer += pkg_numval * sizeof (uint8_t); - memcpy ((void *) pkg_values, (void *) buffer, pkg_numval * sizeof (value_t)); - buffer += pkg_numval * sizeof (value_t); + memcpy (pkg_types, buffer, pkg_numval * sizeof (*pkg_types)); + buffer += pkg_numval * sizeof (*pkg_types); + memcpy (pkg_values, buffer, pkg_numval * sizeof (*pkg_values)); + buffer += pkg_numval * sizeof (*pkg_values); for (i = 0; i < pkg_numval; i++) { @@ -922,15 +919,19 @@ static int parse_part_number (void **ret_buffer, size_t *ret_buffer_len, } /* int parse_part_number */ static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len, - char *output, int output_len) + char *output, size_t const output_len) { char *buffer = *ret_buffer; size_t buffer_len = *ret_buffer_len; uint16_t tmp16; - size_t header_size = 2 * sizeof (uint16_t); + size_t const header_size = 2 * sizeof (uint16_t); uint16_t pkg_length; + size_t payload_size; + + if (output_len == 0) + return (EINVAL); if (buffer_len < header_size) { @@ -949,6 +950,7 @@ static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len, memcpy ((void *) &tmp16, buffer, sizeof (tmp16)); buffer += sizeof (tmp16); pkg_length = ntohs (tmp16); + payload_size = ((size_t) pkg_length) - header_size; /* Check that packet fits in the input buffer */ if (pkg_length > buffer_len) @@ -974,22 +976,24 @@ static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len, /* Check that the package data fits into the output buffer. * The previous if-statement ensures that: * `pkg_length > header_size' */ - if ((output_len < 0) - || ((size_t) output_len < ((size_t) pkg_length - header_size))) + if (output_len < payload_size) { WARNING ("network plugin: parse_part_string: " - "Output buffer too small."); + "Buffer too small: " + "Output buffer holds %zu bytes, " + "which is too small to hold the received " + "%zu byte string.", + output_len, payload_size); return (-1); } /* All sanity checks successfull, let's copy the data over */ - output_len = pkg_length - header_size; - memcpy ((void *) output, (void *) buffer, output_len); - buffer += output_len; + memcpy ((void *) output, (void *) buffer, payload_size); + buffer += payload_size; /* For some very weird reason '\0' doesn't do the trick on SPARC in * this statement. */ - if (output[output_len - 1] != 0) + if (output[payload_size - 1] != 0) { WARNING ("network plugin: parse_part_string: " "Received string does not end " @@ -1361,7 +1365,7 @@ static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */ warning_has_been_printed = 1; } - *ret_buffer += ph_length; + *ret_buffer = (void *) (((char *) *ret_buffer) + ph_length); *ret_buffer_size -= ph_length; return (0); @@ -1400,7 +1404,7 @@ static int parse_packet (sockent_t *se, /* {{{ */ (void *) buffer, sizeof (pkg_type)); memcpy ((void *) &pkg_length, - (void *) (buffer + sizeof (pkg_type)), + (void *) (((char *) buffer) + sizeof (pkg_type)), sizeof (pkg_length)); pkg_length = ntohs (pkg_length); @@ -1435,6 +1439,7 @@ static int parse_packet (sockent_t *se, /* {{{ */ printed_ignore_warning = 1; } buffer = ((char *) buffer) + pkg_length; + buffer_size -= (size_t) pkg_length; continue; } #endif /* HAVE_LIBGCRYPT */ @@ -1462,6 +1467,7 @@ static int parse_packet (sockent_t *se, /* {{{ */ printed_ignore_warning = 1; } buffer = ((char *) buffer) + pkg_length; + buffer_size -= (size_t) pkg_length; continue; } #endif /* HAVE_LIBGCRYPT */ @@ -1603,6 +1609,7 @@ static int parse_packet (sockent_t *se, /* {{{ */ DEBUG ("network plugin: parse_packet: Unknown part" " type: 0x%04hx", pkg_type); buffer = ((char *) buffer) + pkg_length; + buffer_size -= (size_t) pkg_length; } } /* while (buffer_size > sizeof (part_header_t)) */ @@ -2004,10 +2011,9 @@ static sockent_t *sockent_create (int type) /* {{{ */ if ((type != SOCKENT_TYPE_CLIENT) && (type != SOCKENT_TYPE_SERVER)) return (NULL); - se = malloc (sizeof (*se)); + se = calloc (1, sizeof (*se)); if (se == NULL) return (NULL); - memset (se, 0, sizeof (*se)); se->type = type; se->node = NULL; @@ -2030,6 +2036,8 @@ static sockent_t *sockent_create (int type) /* {{{ */ { se->data.client.fd = -1; se->data.client.addr = NULL; + se->data.client.resolve_interval = 0; + se->data.client.next_resolve_reconnect = 0; #if HAVE_LIBGCRYPT se->data.client.security_level = SECURITY_LEVEL_NONE; se->data.client.username = NULL; @@ -2096,6 +2104,26 @@ static int sockent_init_crypto (sockent_t *se) /* {{{ */ return (0); } /* }}} int sockent_init_crypto */ +static int sockent_client_disconnect (sockent_t *se) /* {{{ */ +{ + struct sockent_client *client; + + if ((se == NULL) || (se->type != SOCKENT_TYPE_CLIENT)) + return (EINVAL); + + client = &se->data.client; + if (client->fd >= 0) /* connected */ + { + close (client->fd); + client->fd = -1; + } + + sfree (client->addr); + client->addrlen = 0; + + return (0); +} /* }}} int sockent_client_disconnect */ + static int sockent_client_connect (sockent_t *se) /* {{{ */ { static c_complain_t complaint = C_COMPLAIN_INIT_STATIC; @@ -2104,12 +2132,22 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ struct addrinfo ai_hints; struct addrinfo *ai_list = NULL, *ai_ptr; int status; + _Bool reconnect = 0; + cdtime_t now; if ((se == NULL) || (se->type != SOCKENT_TYPE_CLIENT)) return (EINVAL); client = &se->data.client; - if (client->fd >= 0) /* already connected */ + + now = cdtime (); + if (client->resolve_interval != 0 && client->next_resolve_reconnect < now) { + DEBUG("network plugin: Reconnecting socket, resolve_interval = %lf, next_resolve_reconnect = %lf", + CDTIME_T_TO_DOUBLE(client->resolve_interval), CDTIME_T_TO_DOUBLE(client->next_resolve_reconnect)); + reconnect = 1; + } + + if (client->fd >= 0 && !reconnect) /* already connected and not stale*/ return (0); memset (&ai_hints, 0, sizeof (ai_hints)); @@ -2141,6 +2179,9 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { + if (client->fd >= 0) /* when we reconnect */ + sockent_client_disconnect(se); + client->fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol); @@ -2153,16 +2194,15 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ continue; } - client->addr = malloc (sizeof (*client->addr)); + client->addr = calloc (1, sizeof (*client->addr)); if (client->addr == NULL) { - ERROR ("network plugin: malloc failed."); + ERROR ("network plugin: calloc failed."); close (client->fd); client->fd = -1; continue; } - memset (client->addr, 0, sizeof (*client->addr)); assert (sizeof (*client->addr) >= ai_ptr->ai_addrlen); memcpy (client->addr, ai_ptr->ai_addr, ai_ptr->ai_addrlen); client->addrlen = ai_ptr->ai_addrlen; @@ -2178,28 +2218,11 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ freeaddrinfo (ai_list); if (client->fd < 0) return (-1); - return (0); -} /* }}} int sockent_client_connect */ - -static int sockent_client_disconnect (sockent_t *se) /* {{{ */ -{ - struct sockent_client *client; - - if ((se == NULL) || (se->type != SOCKENT_TYPE_CLIENT)) - return (EINVAL); - - client = &se->data.client; - if (client->fd >= 0) /* connected */ - { - close (client->fd); - client->fd = -1; - } - - sfree (client->addr); - client->addrlen = 0; + if (client->resolve_interval > 0) + client->next_resolve_reconnect = now + client->resolve_interval; return (0); -} /* }}} int sockent_client_disconnect */ +} /* }}} int sockent_client_connect */ /* Open the file descriptors for a initialized sockent structure. */ static int sockent_server_listen (sockent_t *se) /* {{{ */ @@ -2287,7 +2310,7 @@ static int sockent_server_listen (sockent_t *se) /* {{{ */ freeaddrinfo (ai_list); - if (se->data.server.fd_num <= 0) + if (se->data.server.fd_num == 0) return (-1); return (0); } /* }}} int sockent_server_listen */ @@ -2415,7 +2438,7 @@ static int network_receive (void) /* {{{ */ char buffer[network_config_packet_size]; int buffer_len; - int i; + size_t i; int status = 0; receive_list_entry_t *private_list_head; @@ -2469,14 +2492,14 @@ static int network_receive (void) /* {{{ */ * these entries in the dispatch thread but put them in * another list, so we don't have to allocate more and * more of these structures. */ - ent = malloc (sizeof (receive_list_entry_t)); + ent = calloc (1, sizeof (*ent)); if (ent == NULL) { - ERROR ("network plugin: malloc failed."); + ERROR ("network plugin: calloc failed."); status = ENOMEM; break; } - memset (ent, 0, sizeof (receive_list_entry_t)); + ent->data = malloc (network_config_packet_size); if (ent->data == NULL) { @@ -2556,11 +2579,12 @@ static void network_init_buffer (void) memset (send_buffer, 0, network_config_packet_size); send_buffer_ptr = send_buffer; send_buffer_fill = 0; + send_buffer_last_update = 0; memset (&send_buffer_vl, 0, sizeof (send_buffer_vl)); } /* int network_init_buffer */ -static void networt_send_buffer_plain (sockent_t *se, /* {{{ */ +static void network_send_buffer_plain (sockent_t *se, /* {{{ */ const char *buffer, size_t buffer_size) { int status; @@ -2590,7 +2614,7 @@ static void networt_send_buffer_plain (sockent_t *se, /* {{{ */ break; } /* while (42) */ -} /* }}} void networt_send_buffer_plain */ +} /* }}} void network_send_buffer_plain */ #if HAVE_LIBGCRYPT #define BUFFER_ADD(p,s) do { \ @@ -2598,7 +2622,7 @@ static void networt_send_buffer_plain (sockent_t *se, /* {{{ */ buffer_offset += (s); \ } while (0) -static void networt_send_buffer_signed (sockent_t *se, /* {{{ */ +static void network_send_buffer_signed (sockent_t *se, /* {{{ */ const char *in_buffer, size_t in_buffer_size) { part_signature_sha256_t ps; @@ -2672,10 +2696,10 @@ static void networt_send_buffer_signed (sockent_t *se, /* {{{ */ hd = NULL; buffer_offset = PART_SIGNATURE_SHA256_SIZE + username_len + in_buffer_size; - networt_send_buffer_plain (se, buffer, buffer_offset); -} /* }}} void networt_send_buffer_signed */ + network_send_buffer_plain (se, buffer, buffer_offset); +} /* }}} void network_send_buffer_signed */ -static void networt_send_buffer_encrypted (sockent_t *se, /* {{{ */ +static void network_send_buffer_encrypted (sockent_t *se, /* {{{ */ const char *in_buffer, size_t in_buffer_size) { part_encryption_aes256_t pea; @@ -2705,7 +2729,7 @@ static void networt_send_buffer_encrypted (sockent_t *se, /* {{{ */ - sizeof (pea.hash); assert (buffer_size <= sizeof (buffer)); - DEBUG ("network plugin: networt_send_buffer_encrypted: " + DEBUG ("network plugin: network_send_buffer_encrypted: " "buffer_size = %zu;", buffer_size); pea.head.length = htons ((uint16_t) (PART_ENCRYPTION_AES256_SIZE @@ -2752,8 +2776,8 @@ static void networt_send_buffer_encrypted (sockent_t *se, /* {{{ */ } /* Send it out without further modifications */ - networt_send_buffer_plain (se, buffer, buffer_size); -} /* }}} void networt_send_buffer_encrypted */ + network_send_buffer_plain (se, buffer, buffer_size); +} /* }}} void network_send_buffer_encrypted */ #undef BUFFER_ADD #endif /* HAVE_LIBGCRYPT */ @@ -2767,12 +2791,12 @@ static void network_send_buffer (char *buffer, size_t buffer_len) /* {{{ */ { #if HAVE_LIBGCRYPT if (se->data.client.security_level == SECURITY_LEVEL_ENCRYPT) - networt_send_buffer_encrypted (se, buffer, buffer_len); + network_send_buffer_encrypted (se, buffer, buffer_len); else if (se->data.client.security_level == SECURITY_LEVEL_SIGN) - networt_send_buffer_signed (se, buffer, buffer_len); + network_send_buffer_signed (se, buffer, buffer_len); else /* if (se->data.client.security_level == SECURITY_LEVEL_NONE) */ #endif /* HAVE_LIBGCRYPT */ - networt_send_buffer_plain (se, buffer, buffer_len); + network_send_buffer_plain (se, buffer, buffer_len); } /* for (sending_sockets) */ } /* }}} void network_send_buffer */ @@ -2895,6 +2919,7 @@ static int network_write (const data_set_t *ds, const value_list_t *vl, /* status == bytes added to the buffer */ send_buffer_fill += status; send_buffer_ptr += status; + send_buffer_last_update = cdtime(); stats_values_sent++; } @@ -2931,58 +2956,13 @@ static int network_write (const data_set_t *ds, const value_list_t *vl, return ((status < 0) ? -1 : 0); } /* int network_write */ -static int network_config_set_boolean (const oconfig_item_t *ci, /* {{{ */ - int *retval) -{ - if ((ci->values_num != 1) - || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN) - && (ci->values[0].type != OCONFIG_TYPE_STRING))) - { - ERROR ("network plugin: The `%s' config option needs " - "exactly one boolean argument.", ci->key); - return (-1); - } - - if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN) - { - if (ci->values[0].value.boolean) - *retval = 1; - else - *retval = 0; - } - else - { - char *str = ci->values[0].value.string; - - if (IS_TRUE (str)) - *retval = 1; - else if (IS_FALSE (str)) - *retval = 0; - else - { - ERROR ("network plugin: Cannot parse string value `%s' of the `%s' " - "option as boolean value.", - str, ci->key); - return (-1); - } - } - - return (0); -} /* }}} int network_config_set_boolean */ - static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */ { - int tmp; - if ((ci->values_num != 1) - || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) - { - WARNING ("network plugin: The `TimeToLive' config option needs exactly " - "one numeric argument."); - return (-1); - } + int tmp = 0; - tmp = (int) ci->values[0].value.number; - if ((tmp > 0) && (tmp <= 255)) + if (cf_util_get_int (ci, &tmp) != 0) + return (-1); + else if ((tmp > 0) && (tmp <= 255)) network_config_ttl = tmp; else { WARNING ("network plugin: The `TimeToLive' must be between 1 and 255."); @@ -2995,63 +2975,30 @@ static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */ static int network_config_set_interface (const oconfig_item_t *ci, /* {{{ */ int *interface) { - if ((ci->values_num != 1) - || (ci->values[0].type != OCONFIG_TYPE_STRING)) - { - WARNING ("network plugin: The `Interface' config option needs exactly " - "one string argument."); - return (-1); - } + char if_name[256]; - if (interface == NULL) + if (cf_util_get_string_buffer (ci, if_name, sizeof (if_name)) != 0) return (-1); - *interface = if_nametoindex (ci->values[0].value.string); - + *interface = if_nametoindex (if_name); return (0); } /* }}} int network_config_set_interface */ static int network_config_set_buffer_size (const oconfig_item_t *ci) /* {{{ */ { - int tmp; - if ((ci->values_num != 1) - || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) - { - WARNING ("network plugin: The `MaxPacketSize' config option needs exactly " - "one numeric argument."); - return (-1); - } + int tmp = 0; - tmp = (int) ci->values[0].value.number; - if ((tmp >= 1024) && (tmp <= 65535)) + if (cf_util_get_int (ci, &tmp) != 0) + return (-1); + else if ((tmp >= 1024) && (tmp <= 65535)) network_config_packet_size = tmp; - - return (0); -} /* }}} int network_config_set_buffer_size */ - -#if HAVE_LIBGCRYPT -static int network_config_set_string (const oconfig_item_t *ci, /* {{{ */ - char **ret_string) -{ - char *tmp; - if ((ci->values_num != 1) - || (ci->values[0].type != OCONFIG_TYPE_STRING)) - { - WARNING ("network plugin: The `%s' config option needs exactly " - "one string argument.", ci->key); + else { + WARNING ("network plugin: The `MaxPacketSize' must be between 1024 and 65535."); return (-1); } - tmp = strdup (ci->values[0].value.string); - if (tmp == NULL) - return (-1); - - sfree (*ret_string); - *ret_string = tmp; - return (0); -} /* }}} int network_config_set_string */ -#endif /* HAVE_LIBGCRYPT */ +} /* }}} int network_config_set_buffer_size */ #if HAVE_LIBGCRYPT static int network_config_set_security_level (oconfig_item_t *ci, /* {{{ */ @@ -3115,15 +3062,14 @@ static int network_config_add_listen (const oconfig_item_t *ci) /* {{{ */ #if HAVE_LIBGCRYPT if (strcasecmp ("AuthFile", child->key) == 0) - network_config_set_string (child, &se->data.server.auth_file); + cf_util_get_string (child, &se->data.server.auth_file); else if (strcasecmp ("SecurityLevel", child->key) == 0) network_config_set_security_level (child, &se->data.server.security_level); else #endif /* HAVE_LIBGCRYPT */ if (strcasecmp ("Interface", child->key) == 0) - network_config_set_interface (child, - &se->interface); + network_config_set_interface (child, &se->interface); else { WARNING ("network plugin: Option `%s' is not allowed here.", @@ -3154,7 +3100,7 @@ static int network_config_add_listen (const oconfig_item_t *ci) /* {{{ */ status = sockent_server_listen (se); if (status != 0) { - ERROR ("network plugin: network_config_add_server: sockent_server_listen failed."); + ERROR ("network plugin: network_config_add_listen: sockent_server_listen failed."); sockent_destroy (se); return (-1); } @@ -3202,17 +3148,18 @@ static int network_config_add_server (const oconfig_item_t *ci) /* {{{ */ #if HAVE_LIBGCRYPT if (strcasecmp ("Username", child->key) == 0) - network_config_set_string (child, &se->data.client.username); + cf_util_get_string (child, &se->data.client.username); else if (strcasecmp ("Password", child->key) == 0) - network_config_set_string (child, &se->data.client.password); + cf_util_get_string (child, &se->data.client.password); else if (strcasecmp ("SecurityLevel", child->key) == 0) network_config_set_security_level (child, &se->data.client.security_level); else #endif /* HAVE_LIBGCRYPT */ if (strcasecmp ("Interface", child->key) == 0) - network_config_set_interface (child, - &se->interface); + network_config_set_interface (child, &se->interface); + else if (strcasecmp ("ResolveInterval", child->key) == 0) + cf_util_get_cdtime(child, &se->data.client.resolve_interval); else { WARNING ("network plugin: Option `%s' is not allowed here.", @@ -3242,7 +3189,7 @@ static int network_config_add_server (const oconfig_item_t *ci) /* {{{ */ } /* No call to sockent_client_connect() here -- it is called from - * networt_send_buffer_plain(). */ + * network_send_buffer_plain(). */ status = sockent_add (se); if (status != 0) @@ -3281,9 +3228,9 @@ static int network_config (oconfig_item_t *ci) /* {{{ */ else if (strcasecmp ("MaxPacketSize", child->key) == 0) network_config_set_buffer_size (child); else if (strcasecmp ("Forward", child->key) == 0) - network_config_set_boolean (child, &network_config_forward); + cf_util_get_boolean (child, &network_config_forward); else if (strcasecmp ("ReportStats", child->key) == 0) - network_config_set_boolean (child, &network_config_stats); + cf_util_get_boolean (child, &network_config_stats); else { WARNING ("network plugin: Option `%s' is not allowed here.", @@ -3504,7 +3451,7 @@ static int network_init (void) network_init_gcrypt (); #endif - if (network_config_stats != 0) + if (network_config_stats) plugin_register_read ("network", network_stats_read); plugin_register_shutdown ("network", network_shutdown); @@ -3582,15 +3529,25 @@ static int network_init (void) * just send the buffer if `flush' is called - if the requested value was in * there, good. If not, well, then there is nothing to flush.. -octo */ -static int network_flush (__attribute__((unused)) cdtime_t timeout, +static int network_flush (cdtime_t timeout, __attribute__((unused)) const char *identifier, __attribute__((unused)) user_data_t *user_data) { pthread_mutex_lock (&send_buffer_lock); if (send_buffer_fill > 0) - flush_buffer (); - + { + if (timeout > 0) + { + cdtime_t now = cdtime (); + if ((send_buffer_last_update + timeout) > now) + { + pthread_mutex_unlock (&send_buffer_lock); + return (0); + } + } + flush_buffer (); + } pthread_mutex_unlock (&send_buffer_lock); return (0);