X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetwork.c;h=5fed1b196933a5bb00d39d8e9f3c9d828930bd84;hb=483e801902bca3c779793224eddf3bb2749d7288;hp=cc3d6b3a3a3aa24af444be96e01bca5cb056260a;hpb=50c6b81549e3239034f71f00ff7dde4c6a8767e5;p=collectd.git diff --git a/src/network.c b/src/network.c index cc3d6b3a..5fed1b19 100644 --- a/src/network.c +++ b/src/network.c @@ -259,6 +259,7 @@ typedef struct receive_list_entry_s receive_list_entry_t; * Private variables */ 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; @@ -351,6 +352,43 @@ static _Bool check_send_okay (const value_list_t *vl) /* {{{ */ return (!received); } /* }}} _Bool check_send_okay */ +static _Bool check_notify_received (const notification_t *n) /* {{{ */ +{ + notification_meta_t *ptr; + + for (ptr = n->meta; ptr != NULL; ptr = ptr->next) + if ((strcmp ("network:received", ptr->name) == 0) + && (ptr->type == NM_TYPE_BOOLEAN)) + return ((_Bool) ptr->nm_value.nm_boolean); + + return (0); +} /* }}} _Bool check_notify_received */ + +static _Bool check_send_notify_okay (const notification_t *n) /* {{{ */ +{ + static c_complain_t complain_forwarding = C_COMPLAIN_INIT_STATIC; + _Bool received = 0; + + if (n->meta == NULL) + return (1); + + received = check_notify_received (n); + + if (network_config_forward && received) + { + c_complain_once (LOG_ERR, &complain_forwarding, + "network plugin: A notification has been received via the network " + "forwarding if enabled. Forwarding of notifications is currently " + "not supported, because there is not loop-deteciton available. " + "Please contact the collectd mailing list if you need this " + "feature."); + } + + /* By default, only *send* value lists that were not *received* by the + * network plugin. */ + return (!received); +} /* }}} _Bool check_send_notify_okay */ + static int network_dispatch_values (value_list_t *vl, /* {{{ */ const char *username) { @@ -405,7 +443,7 @@ static int network_dispatch_values (value_list_t *vl, /* {{{ */ } } - plugin_dispatch_values (vl); + plugin_dispatch_values_secure (vl); stats_values_dispatched++; meta_data_destroy (vl->meta); @@ -414,6 +452,29 @@ static int network_dispatch_values (value_list_t *vl, /* {{{ */ return (0); } /* }}} int network_dispatch_values */ +static int network_dispatch_notification (notification_t *n) /* {{{ */ +{ + int status; + + assert (n->meta == NULL); + + status = plugin_notification_meta_add_boolean (n, "network:received", 1); + if (status != 0) + { + ERROR ("network plugin: plugin_notification_meta_add_boolean failed."); + plugin_notification_meta_free (n->meta); + n->meta = NULL; + return (status); + } + + status = plugin_dispatch_notification (n); + + plugin_notification_meta_free (n->meta); + n->meta = NULL; + + return (status); +} /* }}} int network_dispatch_notification */ + #if HAVE_LIBGCRYPT static gcry_cipher_hd_t network_get_aes256_cypher (sockent_t *se, /* {{{ */ const void *iv, size_t iv_size, const char *username) @@ -704,7 +765,7 @@ static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len, exp_size = 3 * sizeof (uint16_t) + pkg_numval * (sizeof (uint8_t) + sizeof (value_t)); - if ((buffer_len < 0) || (buffer_len < exp_size)) + if (buffer_len < exp_size) { WARNING ("network plugin: parse_part_values: " "Packet too short: " @@ -788,9 +849,8 @@ static int parse_part_number (void **ret_buffer, size_t *ret_buffer_len, size_t exp_size = 2 * sizeof (uint16_t) + sizeof (uint64_t); uint16_t pkg_length; - uint16_t pkg_type; - if ((buffer_len < 0) || ((size_t) buffer_len < exp_size)) + if (buffer_len < exp_size) { WARNING ("network plugin: parse_part_number: " "Packet too short: " @@ -802,7 +862,7 @@ static int parse_part_number (void **ret_buffer, size_t *ret_buffer_len, memcpy ((void *) &tmp16, buffer, sizeof (tmp16)); buffer += sizeof (tmp16); - pkg_type = ntohs (tmp16); + /* pkg_type = ntohs (tmp16); */ memcpy ((void *) &tmp16, buffer, sizeof (tmp16)); buffer += sizeof (tmp16); @@ -828,9 +888,8 @@ static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len, size_t header_size = 2 * sizeof (uint16_t); uint16_t pkg_length; - uint16_t pkg_type; - if ((buffer_len < 0) || (buffer_len < header_size)) + if (buffer_len < header_size) { WARNING ("network plugin: parse_part_string: " "Packet too short: " @@ -842,7 +901,7 @@ static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len, memcpy ((void *) &tmp16, buffer, sizeof (tmp16)); buffer += sizeof (tmp16); - pkg_type = ntohs (tmp16); + /* pkg_type = ntohs (tmp16); */ memcpy ((void *) &tmp16, buffer, sizeof (tmp16)); buffer += sizeof (tmp16); @@ -1485,7 +1544,7 @@ static int parse_packet (sockent_t *se, /* {{{ */ } else { - plugin_dispatch_notification (&n); + network_dispatch_notification (&n); } } else if (pkg_type == TYPE_SEVERITY) @@ -1704,9 +1763,9 @@ static int network_set_interface (const sockent_t *se, const struct addrinfo *ai } /* else: Not a multicast interface. */ -#if defined(HAVE_IF_INDEXTONAME) && HAVE_IF_INDEXTONAME && defined(SO_BINDTODEVICE) if (se->interface != 0) { +#if defined(HAVE_IF_INDEXTONAME) && HAVE_IF_INDEXTONAME && defined(SO_BINDTODEVICE) char interface_name[IFNAMSIZ]; if (if_indextoname (se->interface, interface_name) == NULL) @@ -1723,20 +1782,21 @@ static int network_set_interface (const sockent_t *se, const struct addrinfo *ai sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); } - } /* #endif HAVE_IF_INDEXTONAME && SO_BINDTODEVICE */ #else - WARNING ("network plugin: Cannot set the interface on a unicast " + WARNING ("network plugin: Cannot set the interface on a unicast " "socket because " # if !defined(SO_BINDTODEVICE) - "the the \"SO_BINDTODEVICE\" socket option " + "the \"SO_BINDTODEVICE\" socket option " # else "the \"if_indextoname\" function " # endif "is not available on your system."); #endif + } + return (0); } /* }}} network_set_interface */ @@ -3087,14 +3147,17 @@ static int network_config (oconfig_item_t *ci) /* {{{ */ } /* }}} int network_config */ static int network_notification (const notification_t *n, - user_data_t __attribute__((unused)) *user_data) + user_data_t __attribute__((unused)) *user_data) { char buffer[network_config_packet_size]; char *buffer_ptr = buffer; int buffer_free = sizeof (buffer); int status; - memset (buffer, '\0', sizeof (buffer)); + if (!check_send_notify_okay (n)) + return (0); + + memset (buffer, 0, sizeof (buffer)); status = write_part_number (&buffer_ptr, &buffer_free, TYPE_TIME_HR, (uint64_t) n->time); @@ -3109,7 +3172,7 @@ static int network_notification (const notification_t *n, if (strlen (n->host) > 0) { status = write_part_string (&buffer_ptr, &buffer_free, TYPE_HOST, - n->host, strlen (n->host)); + n->host, strlen (n->host)); if (status != 0) return (-1); } @@ -3117,7 +3180,7 @@ static int network_notification (const notification_t *n, if (strlen (n->plugin) > 0) { status = write_part_string (&buffer_ptr, &buffer_free, TYPE_PLUGIN, - n->plugin, strlen (n->plugin)); + n->plugin, strlen (n->plugin)); if (status != 0) return (-1); } @@ -3125,8 +3188,8 @@ static int network_notification (const notification_t *n, if (strlen (n->plugin_instance) > 0) { status = write_part_string (&buffer_ptr, &buffer_free, - TYPE_PLUGIN_INSTANCE, - n->plugin_instance, strlen (n->plugin_instance)); + TYPE_PLUGIN_INSTANCE, + n->plugin_instance, strlen (n->plugin_instance)); if (status != 0) return (-1); } @@ -3134,7 +3197,7 @@ static int network_notification (const notification_t *n, if (strlen (n->type) > 0) { status = write_part_string (&buffer_ptr, &buffer_free, TYPE_TYPE, - n->type, strlen (n->type)); + n->type, strlen (n->type)); if (status != 0) return (-1); } @@ -3142,7 +3205,7 @@ static int network_notification (const notification_t *n, if (strlen (n->type_instance) > 0) { status = write_part_string (&buffer_ptr, &buffer_free, TYPE_TYPE_INSTANCE, - n->type_instance, strlen (n->type_instance)); + n->type_instance, strlen (n->type_instance)); if (status != 0) return (-1); } @@ -3235,13 +3298,13 @@ static int network_stats_read (void) /* {{{ */ vl.values[0].derive = (derive_t) copy_octets_rx; vl.values[1].derive = (derive_t) copy_octets_tx; sstrncpy (vl.type, "if_octets", sizeof (vl.type)); - plugin_dispatch_values (&vl); + plugin_dispatch_values_secure (&vl); /* Packets received / send */ vl.values[0].derive = (derive_t) copy_packets_rx; vl.values[1].derive = (derive_t) copy_packets_tx; sstrncpy (vl.type, "if_packets", sizeof (vl.type)); - plugin_dispatch_values (&vl); + plugin_dispatch_values_secure (&vl); /* Values (not) dispatched and (not) send */ sstrncpy (vl.type, "total_values", sizeof (vl.type)); @@ -3250,28 +3313,28 @@ static int network_stats_read (void) /* {{{ */ vl.values[0].derive = (derive_t) copy_values_dispatched; sstrncpy (vl.type_instance, "dispatch-accepted", sizeof (vl.type_instance)); - plugin_dispatch_values (&vl); + plugin_dispatch_values_secure (&vl); vl.values[0].derive = (derive_t) copy_values_not_dispatched; sstrncpy (vl.type_instance, "dispatch-rejected", sizeof (vl.type_instance)); - plugin_dispatch_values (&vl); + plugin_dispatch_values_secure (&vl); vl.values[0].derive = (derive_t) copy_values_sent; sstrncpy (vl.type_instance, "send-accepted", sizeof (vl.type_instance)); - plugin_dispatch_values (&vl); + plugin_dispatch_values_secure (&vl); vl.values[0].derive = (derive_t) copy_values_not_sent; sstrncpy (vl.type_instance, "send-rejected", sizeof (vl.type_instance)); - plugin_dispatch_values (&vl); + plugin_dispatch_values_secure (&vl); /* Receive queue length */ vl.values[0].gauge = (gauge_t) copy_receive_list_length; sstrncpy (vl.type, "queue_length", sizeof (vl.type)); vl.type_instance[0] = 0; - plugin_dispatch_values (&vl); + plugin_dispatch_values_secure (&vl); return (0); } /* }}} int network_stats_read */