2 * collectd - src/network.c
3 * Copyright (C) 2005-2009 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
25 #include "configfile.h"
26 #include "utils_avltree.h"
34 # include <sys/socket.h>
40 # include <netinet/in.h>
43 # include <arpa/inet.h>
53 /* 1500 - 40 - 8 = Ethernet packet - IPv6 header - UDP header */
54 /* #define BUFF_SIZE 1452 */
56 #ifndef IPV6_ADD_MEMBERSHIP
57 # ifdef IPV6_JOIN_GROUP
58 # define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
60 # error "Neither IP_ADD_MEMBERSHIP nor IPV6_JOIN_GROUP is defined"
62 #endif /* !IP_ADD_MEMBERSHIP */
64 /* Buffer size to allocate. */
65 #define BUFF_SIZE 1024
68 * Maximum size required for encryption / signing:
71 * Hash/orig length: 22
73 * --------------------
76 #define BUFF_SIG_SIZE 57
81 typedef struct sockent
84 struct sockaddr_storage *addr;
87 #define SECURITY_LEVEL_NONE 0
89 # define SECURITY_LEVEL_SIGN 1
90 # define SECURITY_LEVEL_ENCRYPT 2
93 unsigned char shared_secret_hash[32];
94 gcry_cipher_hd_t cypher;
95 #endif /* HAVE_GCRYPT_H */
100 /* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
101 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
102 * +-------+-----------------------+-------------------------------+
103 * ! Ver. ! ! Length !
104 * +-------+-----------------------+-------------------------------+
111 typedef struct part_header_s part_header_t;
113 /* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
114 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
115 * +-------------------------------+-------------------------------+
117 * +-------------------------------+-------------------------------+
118 * : (Length - 4) Bytes :
119 * +---------------------------------------------------------------+
126 typedef struct part_string_s part_string_t;
128 /* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
129 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
130 * +-------------------------------+-------------------------------+
132 * +-------------------------------+-------------------------------+
133 * : (Length - 4 == 2 || 4 || 8) Bytes :
134 * +---------------------------------------------------------------+
141 typedef struct part_number_s part_number_t;
143 /* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
144 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
145 * +-------------------------------+-------------------------------+
147 * +-------------------------------+---------------+---------------+
148 * ! Num of values ! Type0 ! Type1 !
149 * +-------------------------------+---------------+---------------+
152 * +---------------------------------------------------------------+
155 * +---------------------------------------------------------------+
160 uint16_t *num_values;
161 uint8_t *values_types;
164 typedef struct part_values_s part_values_t;
166 /* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
167 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
168 * +-------------------------------+-------------------------------+
170 * +-------------------------------+-------------------------------+
171 * ! Hash (Bits 0 - 31) !
173 * ! Hash (Bits 224 - 255) !
174 * +---------------------------------------------------------------+
176 #define PART_SIGNATURE_SHA256_SIZE 36
177 struct part_signature_sha256_s
180 unsigned char hash[32];
182 typedef struct part_signature_sha256_s part_signature_sha256_t;
184 /* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
185 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
186 * +-------------------------------+-------------------------------+
188 * +-------------------------------+-------------------------------+
189 * ! Original length ! Padding (0 - 15 bytes) !
190 * +-------------------------------+-------------------------------+
191 * ! Hash (Bits 0 - 31) !
193 * ! Hash (Bits 128 - 159) !
194 * +---------------------------------------------------------------+
196 /* Size without padding */
197 #define PART_ENCRYPTION_AES256_SIZE 42
198 #define PART_ENCRYPTION_AES256_UNENCR_SIZE 20
199 struct part_encryption_aes256_s
202 unsigned char iv[16];
203 uint16_t orig_length;
204 unsigned char hash[20];
205 unsigned char padding[15];
207 typedef struct part_encryption_aes256_s part_encryption_aes256_t;
209 struct receive_list_entry_s
211 char data[BUFF_SIZE];
214 struct receive_list_entry_s *next;
216 typedef struct receive_list_entry_s receive_list_entry_t;
221 static int network_config_ttl = 0;
222 static int network_config_forward = 0;
224 static sockent_t *sending_sockets = NULL;
226 static receive_list_entry_t *receive_list_head = NULL;
227 static receive_list_entry_t *receive_list_tail = NULL;
228 static pthread_mutex_t receive_list_lock = PTHREAD_MUTEX_INITIALIZER;
229 static pthread_cond_t receive_list_cond = PTHREAD_COND_INITIALIZER;
231 static sockent_t *listen_sockets = NULL;
232 static struct pollfd *listen_sockets_pollfd = NULL;
233 static int listen_sockets_num = 0;
235 /* The receive and dispatch threads will run as long as `listen_loop' is set to
237 static int listen_loop = 0;
238 static int receive_thread_running = 0;
239 static pthread_t receive_thread_id;
240 static int dispatch_thread_running = 0;
241 static pthread_t dispatch_thread_id;
243 /* Buffer in which to-be-sent network packets are constructed. */
244 static char send_buffer[BUFF_SIZE];
245 static char *send_buffer_ptr;
246 static int send_buffer_fill;
247 static value_list_t send_buffer_vl = VALUE_LIST_STATIC;
248 static pthread_mutex_t send_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
250 /* In this cache we store all the values we received, so we can send out only
251 * those values which were *not* received via the network plugin, too. This is
252 * used for the `Forward false' option. */
253 static c_avl_tree_t *cache_tree = NULL;
254 static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
255 static time_t cache_flush_last = 0;
256 static int cache_flush_interval = 1800;
261 static int cache_flush (void)
271 c_avl_iterator_t *iter;
273 time_t curtime = time (NULL);
275 iter = c_avl_get_iterator (cache_tree);
276 while (c_avl_iterator_next (iter, (void *) &key, (void *) &value) == 0)
278 if ((curtime - *value) <= cache_flush_interval)
280 tmp = (char **) realloc (keys,
281 (keys_num + 1) * sizeof (char *));
285 c_avl_iterator_destroy (iter);
286 ERROR ("network plugin: cache_flush: realloc"
291 keys[keys_num] = key;
293 } /* while (c_avl_iterator_next) */
294 c_avl_iterator_destroy (iter);
296 for (i = 0; i < keys_num; i++)
298 if (c_avl_remove (cache_tree, keys[i], (void *) &key,
299 (void *) &value) != 0)
301 WARNING ("network plugin: cache_flush: c_avl_remove"
302 " (%s) failed.", keys[i]);
312 DEBUG ("network plugin: cache_flush: Removed %i %s",
313 keys_num, (keys_num == 1) ? "entry" : "entries");
314 cache_flush_last = curtime;
316 } /* int cache_flush */
318 static int cache_check (const value_list_t *vl)
321 time_t *value = NULL;
324 if (cache_tree == NULL)
327 if (format_name (key, sizeof (key), vl->host, vl->plugin,
328 vl->plugin_instance, vl->type, vl->type_instance))
331 pthread_mutex_lock (&cache_lock);
333 if (c_avl_get (cache_tree, key, (void *) &value) == 0)
335 if (*value < vl->time)
342 DEBUG ("network plugin: cache_check: *value = %i >= vl->time = %i",
343 (int) *value, (int) vl->time);
349 char *key_copy = strdup (key);
350 value = malloc (sizeof (time_t));
351 if ((key_copy != NULL) && (value != NULL))
354 c_avl_insert (cache_tree, key_copy, value);
364 if ((time (NULL) - cache_flush_last) > cache_flush_interval)
367 pthread_mutex_unlock (&cache_lock);
370 } /* int cache_check */
373 static gcry_cipher_hd_t network_get_aes256_cypher (sockent_t *se, /* {{{ */
374 const void *iv, size_t iv_size)
378 if (se->cypher == NULL)
380 err = gcry_cipher_open (&se->cypher,
381 GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC, /* flags = */ 0);
384 ERROR ("network plugin: gcry_cipher_open returned: %s",
385 gcry_strerror (err));
392 gcry_cipher_reset (se->cypher);
394 assert (se->cypher != NULL);
396 err = gcry_cipher_setkey (se->cypher,
397 se->shared_secret_hash, sizeof (se->shared_secret_hash));
400 ERROR ("network plugin: gcry_cipher_setkey returned: %s",
401 gcry_strerror (err));
402 gcry_cipher_close (se->cypher);
407 err = gcry_cipher_setiv (se->cypher, iv, iv_size);
410 ERROR ("network plugin: gcry_cipher_setkey returned: %s",
411 gcry_strerror (err));
412 gcry_cipher_close (se->cypher);
418 } /* }}} int network_get_aes256_cypher */
419 #endif /* HAVE_GCRYPT_H */
421 static int write_part_values (char **ret_buffer, int *ret_buffer_len,
422 const data_set_t *ds, const value_list_t *vl)
428 part_header_t pkg_ph;
429 uint16_t pkg_num_values;
430 uint8_t *pkg_values_types;
436 num_values = vl->values_len;
437 packet_len = sizeof (part_header_t) + sizeof (uint16_t)
438 + (num_values * sizeof (uint8_t))
439 + (num_values * sizeof (value_t));
441 if (*ret_buffer_len < packet_len)
444 pkg_values_types = (uint8_t *) malloc (num_values * sizeof (uint8_t));
445 if (pkg_values_types == NULL)
447 ERROR ("network plugin: write_part_values: malloc failed.");
451 pkg_values = (value_t *) malloc (num_values * sizeof (value_t));
452 if (pkg_values == NULL)
454 free (pkg_values_types);
455 ERROR ("network plugin: write_part_values: malloc failed.");
459 pkg_ph.type = htons (TYPE_VALUES);
460 pkg_ph.length = htons (packet_len);
462 pkg_num_values = htons ((uint16_t) vl->values_len);
464 for (i = 0; i < num_values; i++)
466 if (ds->ds[i].type == DS_TYPE_COUNTER)
468 pkg_values_types[i] = DS_TYPE_COUNTER;
469 pkg_values[i].counter = htonll (vl->values[i].counter);
473 pkg_values_types[i] = DS_TYPE_GAUGE;
474 pkg_values[i].gauge = htond (vl->values[i].gauge);
479 * Use `memcpy' to write everything to the buffer, because the pointer
480 * may be unaligned and some architectures, such as SPARC, can't handle
483 packet_ptr = *ret_buffer;
485 memcpy (packet_ptr + offset, &pkg_ph, sizeof (pkg_ph));
486 offset += sizeof (pkg_ph);
487 memcpy (packet_ptr + offset, &pkg_num_values, sizeof (pkg_num_values));
488 offset += sizeof (pkg_num_values);
489 memcpy (packet_ptr + offset, pkg_values_types, num_values * sizeof (uint8_t));
490 offset += num_values * sizeof (uint8_t);
491 memcpy (packet_ptr + offset, pkg_values, num_values * sizeof (value_t));
492 offset += num_values * sizeof (value_t);
494 assert (offset == packet_len);
496 *ret_buffer = packet_ptr + packet_len;
497 *ret_buffer_len -= packet_len;
499 free (pkg_values_types);
503 } /* int write_part_values */
505 static int write_part_number (char **ret_buffer, int *ret_buffer_len,
506 int type, uint64_t value)
511 part_header_t pkg_head;
516 packet_len = sizeof (pkg_head) + sizeof (pkg_value);
518 if (*ret_buffer_len < packet_len)
521 pkg_head.type = htons (type);
522 pkg_head.length = htons (packet_len);
523 pkg_value = htonll (value);
525 packet_ptr = *ret_buffer;
527 memcpy (packet_ptr + offset, &pkg_head, sizeof (pkg_head));
528 offset += sizeof (pkg_head);
529 memcpy (packet_ptr + offset, &pkg_value, sizeof (pkg_value));
530 offset += sizeof (pkg_value);
532 assert (offset == packet_len);
534 *ret_buffer = packet_ptr + packet_len;
535 *ret_buffer_len -= packet_len;
538 } /* int write_part_number */
540 static int write_part_string (char **ret_buffer, int *ret_buffer_len,
541 int type, const char *str, int str_len)
551 buffer_len = 2 * sizeof (uint16_t) + str_len + 1;
552 if (*ret_buffer_len < buffer_len)
555 pkg_type = htons (type);
556 pkg_length = htons (buffer_len);
558 buffer = *ret_buffer;
560 memcpy (buffer + offset, (void *) &pkg_type, sizeof (pkg_type));
561 offset += sizeof (pkg_type);
562 memcpy (buffer + offset, (void *) &pkg_length, sizeof (pkg_length));
563 offset += sizeof (pkg_length);
564 memcpy (buffer + offset, str, str_len);
566 memset (buffer + offset, '\0', 1);
569 assert (offset == buffer_len);
571 *ret_buffer = buffer + buffer_len;
572 *ret_buffer_len -= buffer_len;
575 } /* int write_part_string */
577 static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len,
578 value_t **ret_values, int *ret_num_values)
580 char *buffer = *ret_buffer;
581 size_t buffer_len = *ret_buffer_len;
596 NOTICE ("network plugin: packet is too short: "
597 "buffer_len = %zu", buffer_len);
601 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
602 buffer += sizeof (tmp16);
603 pkg_type = ntohs (tmp16);
605 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
606 buffer += sizeof (tmp16);
607 pkg_length = ntohs (tmp16);
609 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
610 buffer += sizeof (tmp16);
611 pkg_numval = ntohs (tmp16);
613 assert (pkg_type == TYPE_VALUES);
615 exp_size = 3 * sizeof (uint16_t)
616 + pkg_numval * (sizeof (uint8_t) + sizeof (value_t));
617 if ((buffer_len < 0) || (buffer_len < exp_size))
619 WARNING ("network plugin: parse_part_values: "
621 "Chunk of size %zu expected, "
622 "but buffer has only %zu bytes left.",
623 exp_size, buffer_len);
627 if (pkg_length != exp_size)
629 WARNING ("network plugin: parse_part_values: "
630 "Length and number of values "
631 "in the packet don't match.");
635 pkg_types = (uint8_t *) malloc (pkg_numval * sizeof (uint8_t));
636 pkg_values = (value_t *) malloc (pkg_numval * sizeof (value_t));
637 if ((pkg_types == NULL) || (pkg_values == NULL))
641 ERROR ("network plugin: parse_part_values: malloc failed.");
645 memcpy ((void *) pkg_types, (void *) buffer, pkg_numval * sizeof (uint8_t));
646 buffer += pkg_numval * sizeof (uint8_t);
647 memcpy ((void *) pkg_values, (void *) buffer, pkg_numval * sizeof (value_t));
648 buffer += pkg_numval * sizeof (value_t);
650 for (i = 0; i < pkg_numval; i++)
652 if (pkg_types[i] == DS_TYPE_COUNTER)
653 pkg_values[i].counter = ntohll (pkg_values[i].counter);
654 else if (pkg_types[i] == DS_TYPE_GAUGE)
655 pkg_values[i].gauge = ntohd (pkg_values[i].gauge);
658 *ret_buffer = buffer;
659 *ret_buffer_len = buffer_len - pkg_length;
660 *ret_num_values = pkg_numval;
661 *ret_values = pkg_values;
666 } /* int parse_part_values */
668 static int parse_part_number (void **ret_buffer, size_t *ret_buffer_len,
671 char *buffer = *ret_buffer;
672 size_t buffer_len = *ret_buffer_len;
676 size_t exp_size = 2 * sizeof (uint16_t) + sizeof (uint64_t);
681 if ((buffer_len < 0) || ((size_t) buffer_len < exp_size))
683 WARNING ("network plugin: parse_part_number: "
685 "Chunk of size %zu expected, "
686 "but buffer has only %zu bytes left.",
687 exp_size, buffer_len);
691 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
692 buffer += sizeof (tmp16);
693 pkg_type = ntohs (tmp16);
695 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
696 buffer += sizeof (tmp16);
697 pkg_length = ntohs (tmp16);
699 memcpy ((void *) &tmp64, buffer, sizeof (tmp64));
700 buffer += sizeof (tmp64);
701 *value = ntohll (tmp64);
703 *ret_buffer = buffer;
704 *ret_buffer_len = buffer_len - pkg_length;
707 } /* int parse_part_number */
709 static int parse_part_string (void **ret_buffer, size_t *ret_buffer_len,
710 char *output, int output_len)
712 char *buffer = *ret_buffer;
713 size_t buffer_len = *ret_buffer_len;
716 size_t header_size = 2 * sizeof (uint16_t);
721 if ((buffer_len < 0) || (buffer_len < header_size))
723 WARNING ("network plugin: parse_part_string: "
725 "Chunk of at least size %zu expected, "
726 "but buffer has only %zu bytes left.",
727 header_size, buffer_len);
731 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
732 buffer += sizeof (tmp16);
733 pkg_type = ntohs (tmp16);
735 memcpy ((void *) &tmp16, buffer, sizeof (tmp16));
736 buffer += sizeof (tmp16);
737 pkg_length = ntohs (tmp16);
739 /* Check that packet fits in the input buffer */
740 if (pkg_length > buffer_len)
742 WARNING ("network plugin: parse_part_string: "
744 "Chunk of size %"PRIu16" received, "
745 "but buffer has only %zu bytes left.",
746 pkg_length, buffer_len);
750 /* Check that pkg_length is in the valid range */
751 if (pkg_length <= header_size)
753 WARNING ("network plugin: parse_part_string: "
755 "Header claims this packet is only %hu "
756 "bytes long.", pkg_length);
760 /* Check that the package data fits into the output buffer.
761 * The previous if-statement ensures that:
762 * `pkg_length > header_size' */
764 || ((size_t) output_len < ((size_t) pkg_length - header_size)))
766 WARNING ("network plugin: parse_part_string: "
767 "Output buffer too small.");
771 /* All sanity checks successfull, let's copy the data over */
772 output_len = pkg_length - header_size;
773 memcpy ((void *) output, (void *) buffer, output_len);
774 buffer += output_len;
776 /* For some very weird reason '\0' doesn't do the trick on SPARC in
778 if (output[output_len - 1] != 0)
780 WARNING ("network plugin: parse_part_string: "
781 "Received string does not end "
782 "with a NULL-byte.");
786 *ret_buffer = buffer;
787 *ret_buffer_len = buffer_len - pkg_length;
790 } /* int parse_part_string */
792 /* Forward declaration: parse_part_sign_sha256 and parse_part_encr_aes256 call
793 * parse_packet and vice versa. */
794 #define PP_SIGNED 0x01
795 #define PP_ENCRYPTED 0x02
796 static int parse_packet (sockent_t *se,
797 void *buffer, size_t buffer_size, int flags);
799 #define BUFFER_READ(p,s) do { \
800 memcpy ((p), buffer + buffer_offset, (s)); \
801 buffer_offset += (s); \
805 static int parse_part_sign_sha256 (sockent_t *se, /* {{{ */
806 void **ret_buffer, size_t *ret_buffer_len, int flags)
810 size_t buffer_offset;
812 part_signature_sha256_t pss;
813 char hash[sizeof (pss.hash)];
817 unsigned char *hash_ptr;
819 buffer = *ret_buffer;
820 buffer_len = *ret_buffer_len;
823 if (se->shared_secret == NULL)
825 NOTICE ("network plugin: Received signed network packet but can't verify "
826 "it because no shared secret has been configured. Will accept it.");
830 if (buffer_len < PART_SIGNATURE_SHA256_SIZE)
833 BUFFER_READ (&pss.head.type, sizeof (pss.head.type));
834 BUFFER_READ (&pss.head.length, sizeof (pss.head.length));
835 BUFFER_READ (pss.hash, sizeof (pss.hash));
837 assert (buffer_offset == PART_SIGNATURE_SHA256_SIZE);
839 if (ntohs (pss.head.length) != PART_SIGNATURE_SHA256_SIZE)
841 ERROR ("network plugin: HMAC-SHA-256 with invalid length received.");
846 err = gcry_md_open (&hd, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC);
849 ERROR ("network plugin: Creating HMAC-SHA-256 object failed: %s",
850 gcry_strerror (err));
854 err = gcry_md_setkey (hd, se->shared_secret,
855 strlen (se->shared_secret));
858 ERROR ("network plugin: gcry_md_setkey failed: %s",
859 gcry_strerror (err));
864 gcry_md_write (hd, buffer + buffer_offset, buffer_len - buffer_offset);
865 hash_ptr = gcry_md_read (hd, GCRY_MD_SHA256);
866 if (hash_ptr == NULL)
868 ERROR ("network plugin: gcry_md_read failed.");
872 memcpy (hash, hash_ptr, sizeof (hash));
877 if (memcmp (pss.hash, hash, sizeof (pss.hash)) != 0)
879 WARNING ("network plugin: Verifying HMAC-SHA-256 signature failed: "
884 parse_packet (se, buffer + buffer_offset, buffer_len - buffer_offset,
888 *ret_buffer = buffer + buffer_len;
892 } /* }}} int parse_part_sign_sha256 */
893 /* #endif HAVE_GCRYPT_H */
895 #else /* if !HAVE_GCRYPT_H */
896 static int parse_part_sign_sha256 (sockent_t *se, /* {{{ */
897 void **ret_buffer, size_t *ret_buffer_size, int flags)
899 static int warning_has_been_printed = 0;
903 size_t buffer_offset;
905 part_signature_sha256_t pss;
907 buffer = *ret_buffer;
908 buffer_size = *ret_buffer_size;
911 if (buffer_size < PART_SIGNATURE_SHA256_SIZE)
914 BUFFER_READ (&pss.head.type, sizeof (pss.head.type));
915 BUFFER_READ (&pss.head.length, sizeof (pss.head.length));
916 BUFFER_READ (pss.hash, sizeof (pss.hash));
918 assert (buffer_offset == PART_SIGNATURE_SHA256_SIZE);
920 if (ntohs (pss.head.length) != PART_SIGNATURE_SHA256_SIZE)
922 ERROR ("network plugin: HMAC-SHA-256 with invalid length received.");
926 if (warning_has_been_printed == 0)
928 WARNING ("network plugin: Received signed packet, but the network "
929 "plugin was not linked with libgcrypt, so I cannot "
930 "verify the signature. The packet will be accepted.");
931 warning_has_been_printed = 1;
934 parse_packet (se, buffer + buffer_offset, buffer_size - buffer_offset,
937 *ret_buffer = buffer + buffer_size;
938 *ret_buffer_size = 0;
941 } /* }}} int parse_part_sign_sha256 */
942 #endif /* !HAVE_GCRYPT_H */
945 static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */
946 void **ret_buffer, size_t *ret_buffer_len,
949 char *buffer = *ret_buffer;
950 size_t buffer_len = *ret_buffer_len;
951 size_t orig_buffer_len;
953 size_t buffer_offset;
955 part_encryption_aes256_t pea;
956 unsigned char hash[sizeof (pea.hash)];
958 gcry_cipher_hd_t cypher;
961 /* Make sure at least the header if available. */
962 if (buffer_len < sizeof (pea))
964 NOTICE ("network plugin: parse_part_encr_aes256: "
965 "Discarding short packet.");
971 /* Copy the unencrypted information into `pea'. */
972 BUFFER_READ (&pea.head.type, sizeof (pea.head.type));
973 BUFFER_READ (&pea.head.length, sizeof (pea.head.length));
974 BUFFER_READ (pea.iv, sizeof (pea.iv));
976 /* Check the `part size'. */
977 part_size = ntohs (pea.head.length);
978 if (part_size > buffer_len)
980 NOTICE ("network plugin: parse_part_encr_aes256: "
981 "Discarding large part.");
985 cypher = network_get_aes256_cypher (se, pea.iv, sizeof (pea.iv));
989 /* Decrypt the packet in-place */
990 err = gcry_cipher_decrypt (cypher,
991 buffer + PART_ENCRYPTION_AES256_UNENCR_SIZE,
992 part_size - PART_ENCRYPTION_AES256_UNENCR_SIZE,
993 /* in = */ NULL, /* in len = */ 0);
996 ERROR ("network plugin: gcry_cipher_decrypt returned: %s",
997 gcry_strerror (err));
1001 /* Figure out the length of the payload and the length of the padding. */
1002 BUFFER_READ (&pea.orig_length, sizeof (pea.orig_length));
1004 orig_buffer_len = ntohs (pea.orig_length);
1005 if (orig_buffer_len > (part_size - PART_ENCRYPTION_AES256_SIZE))
1007 ERROR ("network plugin: Decryption failed: Invalid original length.");
1011 /* Calculate the size of the `padding' field. */
1012 padding_size = part_size - (orig_buffer_len + PART_ENCRYPTION_AES256_SIZE);
1013 if (padding_size > sizeof (pea.padding))
1015 ERROR ("network plugin: Part- and original length "
1016 "differ more than %zu bytes.", sizeof (pea.padding));
1020 BUFFER_READ (pea.hash, sizeof (pea.hash));
1022 /* Read the padding. */
1023 BUFFER_READ (pea.padding, padding_size);
1025 /* Check hash sum */
1026 memset (hash, 0, sizeof (hash));
1027 gcry_md_hash_buffer (GCRY_MD_SHA1, hash,
1028 buffer + buffer_offset, orig_buffer_len);
1030 if (memcmp (hash, pea.hash, sizeof (hash)) != 0)
1032 ERROR ("network plugin: Decryption failed: Checksum mismatch.");
1036 assert ((PART_ENCRYPTION_AES256_SIZE + padding_size + orig_buffer_len)
1039 parse_packet (se, buffer + PART_ENCRYPTION_AES256_SIZE + padding_size,
1040 orig_buffer_len, flags | PP_ENCRYPTED);
1042 /* Update return values */
1043 *ret_buffer = buffer + part_size;
1044 *ret_buffer_len = buffer_len - part_size;
1047 } /* }}} int parse_part_encr_aes256 */
1048 /* #endif HAVE_GCRYPT_H */
1050 #else /* if !HAVE_GCRYPT_H */
1051 static int parse_part_encr_aes256 (sockent_t *se, /* {{{ */
1052 void **ret_buffer, size_t *ret_buffer_size, int flags)
1054 static int warning_has_been_printed = 0;
1058 size_t buffer_offset;
1063 buffer = *ret_buffer;
1064 buffer_size = *ret_buffer_size;
1067 /* parse_packet assures this minimum size. */
1068 assert (buffer_size >= (sizeof (ph.type) + sizeof (ph.length)));
1070 BUFFER_READ (&ph.type, sizeof (ph.type));
1071 BUFFER_READ (&ph.length, sizeof (ph.length));
1072 ph_length = ntohs (ph.length);
1074 if ((ph_length < PART_ENCRYPTION_AES256_SIZE)
1075 || (ph_length > buffer_size))
1077 ERROR ("network plugin: AES-256 encrypted part "
1078 "with invalid length received.");
1082 if (warning_has_been_printed == 0)
1084 WARNING ("network plugin: Received encrypted packet, but the network "
1085 "plugin was not linked with libgcrypt, so I cannot "
1086 "decrypt it. The part will be discarded.");
1087 warning_has_been_printed = 1;
1090 *ret_buffer += ph_length;
1091 *ret_buffer_size -= ph_length;
1094 } /* }}} int parse_part_encr_aes256 */
1095 #endif /* !HAVE_GCRYPT_H */
1099 static int parse_packet (sockent_t *se, /* {{{ */
1100 void *buffer, size_t buffer_size, int flags)
1104 value_list_t vl = VALUE_LIST_INIT;
1108 int packet_was_signed = (flags & PP_SIGNED);
1109 int packet_was_encrypted = (flags & PP_ENCRYPTED);
1110 int printed_ignore_warning = 0;
1111 #endif /* HAVE_GCRYPT_H */
1114 memset (&vl, '\0', sizeof (vl));
1115 memset (&n, '\0', sizeof (n));
1118 while ((status == 0) && (0 < buffer_size)
1119 && ((unsigned int) buffer_size > sizeof (part_header_t)))
1121 uint16_t pkg_length;
1124 memcpy ((void *) &pkg_type,
1127 memcpy ((void *) &pkg_length,
1128 (void *) (buffer + sizeof (pkg_type)),
1129 sizeof (pkg_length));
1131 pkg_length = ntohs (pkg_length);
1132 pkg_type = ntohs (pkg_type);
1134 if (pkg_length > buffer_size)
1136 /* Ensure that this loop terminates eventually */
1137 if (pkg_length < (2 * sizeof (uint16_t)))
1140 if (pkg_type == TYPE_ENCR_AES256)
1142 status = parse_part_encr_aes256 (se,
1143 &buffer, &buffer_size, flags);
1146 ERROR ("network plugin: Decrypting AES256 "
1148 "with status %i.", status);
1153 else if ((se->security_level == SECURITY_LEVEL_ENCRYPT)
1154 && (packet_was_encrypted == 0))
1156 if (printed_ignore_warning == 0)
1158 INFO ("network plugin: Unencrypted packet or "
1159 "part has been ignored.");
1160 printed_ignore_warning = 1;
1162 buffer = ((char *) buffer) + pkg_length;
1165 #endif /* HAVE_GCRYPT_H */
1166 else if (pkg_type == TYPE_SIGN_SHA256)
1168 status = parse_part_sign_sha256 (se,
1169 &buffer, &buffer_size, flags);
1172 ERROR ("network plugin: Verifying HMAC-SHA-256 "
1174 "with status %i.", status);
1179 else if ((se->security_level == SECURITY_LEVEL_SIGN)
1180 && (packet_was_encrypted == 0)
1181 && (packet_was_signed == 0))
1183 if (printed_ignore_warning == 0)
1185 INFO ("network plugin: Unsigned packet or "
1186 "part has been ignored.");
1187 printed_ignore_warning = 1;
1189 buffer = ((char *) buffer) + pkg_length;
1192 #endif /* HAVE_GCRYPT_H */
1193 else if (pkg_type == TYPE_VALUES)
1195 status = parse_part_values (&buffer, &buffer_size,
1196 &vl.values, &vl.values_len);
1202 && (strlen (vl.host) > 0)
1203 && (strlen (vl.plugin) > 0)
1204 && (strlen (vl.type) > 0)
1205 && (cache_check (&vl) == 0))
1207 plugin_dispatch_values (&vl);
1211 DEBUG ("network plugin: parse_packet:"
1212 " NOT dispatching values");
1217 else if (pkg_type == TYPE_TIME)
1220 status = parse_part_number (&buffer, &buffer_size,
1224 vl.time = (time_t) tmp;
1225 n.time = (time_t) tmp;
1228 else if (pkg_type == TYPE_INTERVAL)
1231 status = parse_part_number (&buffer, &buffer_size,
1234 vl.interval = (int) tmp;
1236 else if (pkg_type == TYPE_HOST)
1238 status = parse_part_string (&buffer, &buffer_size,
1239 vl.host, sizeof (vl.host));
1241 sstrncpy (n.host, vl.host, sizeof (n.host));
1243 else if (pkg_type == TYPE_PLUGIN)
1245 status = parse_part_string (&buffer, &buffer_size,
1246 vl.plugin, sizeof (vl.plugin));
1248 sstrncpy (n.plugin, vl.plugin,
1251 else if (pkg_type == TYPE_PLUGIN_INSTANCE)
1253 status = parse_part_string (&buffer, &buffer_size,
1255 sizeof (vl.plugin_instance));
1257 sstrncpy (n.plugin_instance,
1259 sizeof (n.plugin_instance));
1261 else if (pkg_type == TYPE_TYPE)
1263 status = parse_part_string (&buffer, &buffer_size,
1264 vl.type, sizeof (vl.type));
1266 sstrncpy (n.type, vl.type, sizeof (n.type));
1268 else if (pkg_type == TYPE_TYPE_INSTANCE)
1270 status = parse_part_string (&buffer, &buffer_size,
1272 sizeof (vl.type_instance));
1274 sstrncpy (n.type_instance, vl.type_instance,
1275 sizeof (n.type_instance));
1277 else if (pkg_type == TYPE_MESSAGE)
1279 status = parse_part_string (&buffer, &buffer_size,
1280 n.message, sizeof (n.message));
1286 else if ((n.severity != NOTIF_FAILURE)
1287 && (n.severity != NOTIF_WARNING)
1288 && (n.severity != NOTIF_OKAY))
1290 INFO ("network plugin: "
1291 "Ignoring notification with "
1292 "unknown severity %i.",
1295 else if (n.time <= 0)
1297 INFO ("network plugin: "
1298 "Ignoring notification with "
1301 else if (strlen (n.message) <= 0)
1303 INFO ("network plugin: "
1304 "Ignoring notification with "
1305 "an empty message.");
1309 plugin_dispatch_notification (&n);
1312 else if (pkg_type == TYPE_SEVERITY)
1315 status = parse_part_number (&buffer, &buffer_size,
1318 n.severity = (int) tmp;
1322 DEBUG ("network plugin: parse_packet: Unknown part"
1323 " type: 0x%04hx", pkg_type);
1324 buffer = ((char *) buffer) + pkg_length;
1326 } /* while (buffer_size > sizeof (part_header_t)) */
1329 } /* }}} int parse_packet */
1331 static void free_sockent (sockent_t *se) /* {{{ */
1339 if (se->cypher != NULL)
1341 gcry_cipher_close (se->cypher);
1344 free (se->shared_secret);
1345 #endif /* HAVE_GCRYPT_H */
1352 } /* }}} void free_sockent */
1355 * int network_set_ttl
1357 * Set the `IP_MULTICAST_TTL', `IP_TTL', `IPV6_MULTICAST_HOPS' or
1358 * `IPV6_UNICAST_HOPS', depending on which option is applicable.
1360 * The `struct addrinfo' is used to destinguish between unicast and multicast
1363 static int network_set_ttl (const sockent_t *se, const struct addrinfo *ai)
1365 DEBUG ("network plugin: network_set_ttl: network_config_ttl = %i;",
1366 network_config_ttl);
1368 if ((network_config_ttl < 1) || (network_config_ttl > 255))
1371 if (ai->ai_family == AF_INET)
1373 struct sockaddr_in *addr = (struct sockaddr_in *) ai->ai_addr;
1376 if (IN_MULTICAST (ntohl (addr->sin_addr.s_addr)))
1377 optname = IP_MULTICAST_TTL;
1381 if (setsockopt (se->fd, IPPROTO_IP, optname,
1382 &network_config_ttl,
1383 sizeof (network_config_ttl)) == -1)
1386 ERROR ("setsockopt: %s",
1387 sstrerror (errno, errbuf, sizeof (errbuf)));
1391 else if (ai->ai_family == AF_INET6)
1393 /* Useful example: http://gsyc.escet.urjc.es/~eva/IPv6-web/examples/mcast.html */
1394 struct sockaddr_in6 *addr = (struct sockaddr_in6 *) ai->ai_addr;
1397 if (IN6_IS_ADDR_MULTICAST (&addr->sin6_addr))
1398 optname = IPV6_MULTICAST_HOPS;
1400 optname = IPV6_UNICAST_HOPS;
1402 if (setsockopt (se->fd, IPPROTO_IPV6, optname,
1403 &network_config_ttl,
1404 sizeof (network_config_ttl)) == -1)
1407 ERROR ("setsockopt: %s",
1408 sstrerror (errno, errbuf,
1415 } /* int network_set_ttl */
1417 static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai)
1422 /* allow multiple sockets to use the same PORT number */
1423 if (setsockopt(se->fd, SOL_SOCKET, SO_REUSEADDR,
1424 &yes, sizeof(yes)) == -1) {
1426 ERROR ("setsockopt: %s",
1427 sstrerror (errno, errbuf, sizeof (errbuf)));
1431 DEBUG ("fd = %i; calling `bind'", se->fd);
1433 if (bind (se->fd, ai->ai_addr, ai->ai_addrlen) == -1)
1437 sstrerror (errno, errbuf, sizeof (errbuf)));
1441 if (ai->ai_family == AF_INET)
1443 struct sockaddr_in *addr = (struct sockaddr_in *) ai->ai_addr;
1444 if (IN_MULTICAST (ntohl (addr->sin_addr.s_addr)))
1446 struct ip_mreq mreq;
1448 DEBUG ("fd = %i; IPv4 multicast address found", se->fd);
1450 mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr;
1451 mreq.imr_interface.s_addr = htonl (INADDR_ANY);
1453 if (setsockopt (se->fd, IPPROTO_IP, IP_MULTICAST_LOOP,
1454 &loop, sizeof (loop)) == -1)
1457 ERROR ("setsockopt: %s",
1458 sstrerror (errno, errbuf,
1463 if (setsockopt (se->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1464 &mreq, sizeof (mreq)) == -1)
1467 ERROR ("setsockopt: %s",
1468 sstrerror (errno, errbuf,
1474 else if (ai->ai_family == AF_INET6)
1476 /* Useful example: http://gsyc.escet.urjc.es/~eva/IPv6-web/examples/mcast.html */
1477 struct sockaddr_in6 *addr = (struct sockaddr_in6 *) ai->ai_addr;
1478 if (IN6_IS_ADDR_MULTICAST (&addr->sin6_addr))
1480 struct ipv6_mreq mreq;
1482 DEBUG ("fd = %i; IPv6 multicast address found", se->fd);
1484 memcpy (&mreq.ipv6mr_multiaddr,
1486 sizeof (addr->sin6_addr));
1488 /* http://developer.apple.com/documentation/Darwin/Reference/ManPages/man4/ip6.4.html
1489 * ipv6mr_interface may be set to zeroes to
1490 * choose the default multicast interface or to
1491 * the index of a particular multicast-capable
1492 * interface if the host is multihomed.
1493 * Membership is associ-associated with a
1494 * single interface; programs running on
1495 * multihomed hosts may need to join the same
1496 * group on more than one interface.*/
1497 mreq.ipv6mr_interface = 0;
1499 if (setsockopt (se->fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
1500 &loop, sizeof (loop)) == -1)
1503 ERROR ("setsockopt: %s",
1504 sstrerror (errno, errbuf,
1509 if (setsockopt (se->fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP,
1510 &mreq, sizeof (mreq)) == -1)
1513 ERROR ("setsockopt: %s",
1514 sstrerror (errno, errbuf,
1522 } /* int network_bind_socket */
1524 #define CREATE_SOCKET_FLAGS_LISTEN 0x0001
1525 static sockent_t *network_create_socket (const char *node, /* {{{ */
1526 const char *service,
1527 const char *shared_secret,
1531 struct addrinfo ai_hints;
1532 struct addrinfo *ai_list, *ai_ptr;
1535 sockent_t *se_head = NULL;
1536 sockent_t *se_tail = NULL;
1538 DEBUG ("node = %s, service = %s", node, service);
1540 memset (&ai_hints, '\0', sizeof (ai_hints));
1541 ai_hints.ai_flags = 0;
1543 ai_hints.ai_flags |= AI_PASSIVE;
1545 #ifdef AI_ADDRCONFIG
1546 ai_hints.ai_flags |= AI_ADDRCONFIG;
1548 ai_hints.ai_family = AF_UNSPEC;
1549 ai_hints.ai_socktype = SOCK_DGRAM;
1550 ai_hints.ai_protocol = IPPROTO_UDP;
1552 ai_return = getaddrinfo (node, service, &ai_hints, &ai_list);
1556 ERROR ("getaddrinfo (%s, %s): %s",
1557 (node == NULL) ? "(null)" : node,
1558 (service == NULL) ? "(null)" : service,
1559 (ai_return == EAI_SYSTEM)
1560 ? sstrerror (errno, errbuf, sizeof (errbuf))
1561 : gai_strerror (ai_return));
1565 for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
1570 if ((se = (sockent_t *) malloc (sizeof (sockent_t))) == NULL)
1573 ERROR ("malloc: %s",
1574 sstrerror (errno, errbuf,
1579 if ((se->addr = (struct sockaddr_storage *) malloc (sizeof (struct sockaddr_storage))) == NULL)
1582 ERROR ("malloc: %s",
1583 sstrerror (errno, errbuf,
1589 assert (sizeof (struct sockaddr_storage) >= ai_ptr->ai_addrlen);
1590 memset (se->addr, '\0', sizeof (struct sockaddr_storage));
1591 memcpy (se->addr, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
1592 se->addrlen = ai_ptr->ai_addrlen;
1594 se->fd = socket (ai_ptr->ai_family,
1595 ai_ptr->ai_socktype,
1596 ai_ptr->ai_protocol);
1602 ERROR ("socket: %s",
1603 sstrerror (errno, errbuf,
1610 if ((flags & CREATE_SOCKET_FLAGS_LISTEN) != 0)
1612 status = network_bind_socket (se, ai_ptr);
1621 else /* sending socket */
1623 network_set_ttl (se, ai_ptr);
1627 se->security_level = security_level;
1628 se->shared_secret = NULL;
1630 if (shared_secret != NULL)
1632 se->shared_secret = sstrdup (shared_secret);
1633 assert (se->shared_secret != NULL);
1635 memset (se->shared_secret_hash, 0,
1636 sizeof (se->shared_secret_hash));
1637 gcry_md_hash_buffer (GCRY_MD_SHA256,
1638 se->shared_secret_hash,
1640 strlen (se->shared_secret));
1643 /* Make compiler happy */
1645 shared_secret = NULL;
1646 #endif /* HAVE_GCRYPT_H */
1648 if (se_tail == NULL)
1659 /* We don't open more than one write-socket per node/service pair.. */
1660 if ((flags & CREATE_SOCKET_FLAGS_LISTEN) == 0)
1664 freeaddrinfo (ai_list);
1667 } /* }}} sockent_t *network_create_socket */
1669 static sockent_t *network_create_default_socket (int flags) /* {{{ */
1671 sockent_t *se_ptr = NULL;
1672 sockent_t *se_head = NULL;
1673 sockent_t *se_tail = NULL;
1675 se_ptr = network_create_socket (NET_DEFAULT_V6_ADDR, NET_DEFAULT_PORT,
1676 /* shared secret = */ NULL, SECURITY_LEVEL_NONE,
1679 /* Don't send to the same machine in IPv6 and IPv4 if both are available. */
1680 if (((flags & CREATE_SOCKET_FLAGS_LISTEN) == 0) && (se_ptr != NULL))
1687 while (se_tail->next != NULL)
1688 se_tail = se_tail->next;
1691 se_ptr = network_create_socket (NET_DEFAULT_V4_ADDR, NET_DEFAULT_PORT,
1692 /* shared secret = */ NULL, SECURITY_LEVEL_NONE,
1695 if (se_tail == NULL)
1698 se_tail->next = se_ptr;
1700 } /* }}} sockent_t *network_create_default_socket */
1702 static int network_add_listen_socket (const char *node, /* {{{ */
1703 const char *service, const char *shared_secret, int security_level)
1711 flags = CREATE_SOCKET_FLAGS_LISTEN;
1713 if (service == NULL)
1714 service = NET_DEFAULT_PORT;
1717 se = network_create_default_socket (flags);
1719 se = network_create_socket (node, service,
1720 shared_secret, security_level, flags);
1725 for (se_ptr = se; se_ptr != NULL; se_ptr = se_ptr->next)
1728 listen_sockets_pollfd = realloc (listen_sockets_pollfd,
1729 (listen_sockets_num + se_num)
1730 * sizeof (struct pollfd));
1732 for (se_ptr = se; se_ptr != NULL; se_ptr = se_ptr->next)
1734 listen_sockets_pollfd[listen_sockets_num].fd = se_ptr->fd;
1735 listen_sockets_pollfd[listen_sockets_num].events = POLLIN | POLLPRI;
1736 listen_sockets_pollfd[listen_sockets_num].revents = 0;
1737 listen_sockets_num++;
1740 se_ptr = listen_sockets;
1741 while ((se_ptr != NULL) && (se_ptr->next != NULL))
1742 se_ptr = se_ptr->next;
1745 listen_sockets = se;
1750 } /* }}} int network_add_listen_socket */
1752 static int network_add_sending_socket (const char *node, /* {{{ */
1753 const char *service, const char *shared_secret, int security_level)
1758 if (service == NULL)
1759 service = NET_DEFAULT_PORT;
1762 se = network_create_default_socket (/* flags = */ 0);
1764 se = network_create_socket (node, service,
1765 shared_secret, security_level,
1771 if (sending_sockets == NULL)
1773 sending_sockets = se;
1777 for (se_ptr = sending_sockets; se_ptr->next != NULL; se_ptr = se_ptr->next)
1782 } /* }}} int network_add_sending_socket */
1784 static void *dispatch_thread (void __attribute__((unused)) *arg) /* {{{ */
1788 receive_list_entry_t *ent;
1791 /* Lock and wait for more data to come in */
1792 pthread_mutex_lock (&receive_list_lock);
1793 while ((listen_loop == 0)
1794 && (receive_list_head == NULL))
1795 pthread_cond_wait (&receive_list_cond, &receive_list_lock);
1797 /* Remove the head entry and unlock */
1798 ent = receive_list_head;
1800 receive_list_head = ent->next;
1801 pthread_mutex_unlock (&receive_list_lock);
1803 /* Check whether we are supposed to exit. We do NOT check `listen_loop'
1804 * because we dispatch all missing packets before shutting down. */
1808 /* Look for the correct `sockent_t' */
1809 se = listen_sockets;
1810 while ((se != NULL) && (se->fd != ent->fd))
1815 ERROR ("network plugin: Got packet from FD %i, but can't "
1816 "find an appropriate socket entry.",
1822 parse_packet (se, ent->data, ent->data_len, /* flags = */ 0);
1827 } /* }}} void *dispatch_thread */
1829 static int network_receive (void)
1831 char buffer[BUFF_SIZE];
1837 receive_list_entry_t *private_list_head;
1838 receive_list_entry_t *private_list_tail;
1840 if (listen_sockets_num == 0)
1841 network_add_listen_socket (/* node = */ NULL,
1842 /* service = */ NULL,
1843 /* shared secret = */ NULL,
1844 /* encryption = */ 0);
1846 if (listen_sockets_num == 0)
1848 ERROR ("network: Failed to open a listening socket.");
1852 private_list_head = NULL;
1853 private_list_tail = NULL;
1855 while (listen_loop == 0)
1857 status = poll (listen_sockets_pollfd, listen_sockets_num, -1);
1864 ERROR ("poll failed: %s",
1865 sstrerror (errno, errbuf, sizeof (errbuf)));
1869 for (i = 0; (i < listen_sockets_num) && (status > 0); i++)
1871 receive_list_entry_t *ent;
1873 if ((listen_sockets_pollfd[i].revents
1874 & (POLLIN | POLLPRI)) == 0)
1878 buffer_len = recv (listen_sockets_pollfd[i].fd,
1879 buffer, sizeof (buffer),
1884 ERROR ("recv failed: %s",
1885 sstrerror (errno, errbuf,
1890 /* TODO: Possible performance enhancement: Do not free
1891 * these entries in the dispatch thread but put them in
1892 * another list, so we don't have to allocate more and
1893 * more of these structures. */
1894 ent = malloc (sizeof (receive_list_entry_t));
1897 ERROR ("network plugin: malloc failed.");
1900 memset (ent, 0, sizeof (receive_list_entry_t));
1901 ent->fd = listen_sockets_pollfd[i].fd;
1904 /* Hopefully this be optimized out by the compiler. It
1905 * might help prevent stupid bugs in the future though.
1907 assert (sizeof (ent->data) == sizeof (buffer));
1909 memcpy (ent->data, buffer, buffer_len);
1910 ent->data_len = buffer_len;
1912 if (private_list_head == NULL)
1913 private_list_head = ent;
1915 private_list_tail->next = ent;
1916 private_list_tail = ent;
1918 /* Do not block here. Blocking here has led to
1919 * insufficient performance in the past. */
1920 if (pthread_mutex_trylock (&receive_list_lock) == 0)
1922 if (receive_list_head == NULL)
1923 receive_list_head = private_list_head;
1925 receive_list_tail->next = private_list_head;
1926 receive_list_tail = private_list_tail;
1928 private_list_head = NULL;
1929 private_list_tail = NULL;
1931 pthread_cond_signal (&receive_list_cond);
1932 pthread_mutex_unlock (&receive_list_lock);
1934 } /* for (listen_sockets_pollfd) */
1935 } /* while (listen_loop == 0) */
1937 /* Make sure everything is dispatched before exiting. */
1938 if (private_list_head != NULL)
1940 pthread_mutex_lock (&receive_list_lock);
1942 if (receive_list_head == NULL)
1943 receive_list_head = private_list_head;
1945 receive_list_tail->next = private_list_head;
1946 receive_list_tail = private_list_tail;
1948 private_list_head = NULL;
1949 private_list_tail = NULL;
1951 pthread_cond_signal (&receive_list_cond);
1952 pthread_mutex_unlock (&receive_list_lock);
1956 } /* int network_receive */
1958 static void *receive_thread (void __attribute__((unused)) *arg)
1960 return (network_receive () ? (void *) 1 : (void *) 0);
1961 } /* void *receive_thread */
1963 static void network_init_buffer (void)
1965 memset (send_buffer, 0, sizeof (send_buffer));
1966 send_buffer_ptr = send_buffer;
1967 send_buffer_fill = 0;
1969 memset (&send_buffer_vl, 0, sizeof (send_buffer_vl));
1970 } /* int network_init_buffer */
1972 static void networt_send_buffer_plain (const sockent_t *se, /* {{{ */
1973 const char *buffer, size_t buffer_size)
1979 status = sendto (se->fd, buffer, buffer_size, 0 /* no flags */,
1980 (struct sockaddr *) se->addr, se->addrlen);
1986 ERROR ("network plugin: sendto failed: %s",
1987 sstrerror (errno, errbuf,
1994 } /* }}} void networt_send_buffer_plain */
1997 static void networt_send_buffer_signed (const sockent_t *se, /* {{{ */
1998 const char *in_buffer, size_t in_buffer_size)
2000 part_signature_sha256_t ps;
2001 char buffer[sizeof (ps) + in_buffer_size];
2005 unsigned char *hash;
2008 err = gcry_md_open (&hd, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC);
2011 ERROR ("network plugin: Creating HMAC object failed: %s",
2012 gcry_strerror (err));
2016 err = gcry_md_setkey (hd, se->shared_secret,
2017 strlen (se->shared_secret));
2020 ERROR ("network plugin: gcry_md_setkey failed: %s",
2021 gcry_strerror (err));
2026 /* Initialize the `ps' structure. */
2027 memset (&ps, 0, sizeof (ps));
2028 ps.head.type = htons (TYPE_SIGN_SHA256);
2029 ps.head.length = htons ((uint16_t) sizeof (ps));
2031 /* Calculate the hash value. */
2032 gcry_md_write (hd, in_buffer, in_buffer_size);
2033 hash = gcry_md_read (hd, GCRY_MD_SHA256);
2036 ERROR ("network plugin: gcry_md_read failed.");
2041 /* Add the signature and fill the rest of the buffer. */
2042 memcpy (ps.hash, hash, sizeof (ps.hash));
2043 memcpy (buffer, &ps, sizeof (ps));
2044 memcpy (buffer + sizeof (ps), in_buffer, in_buffer_size);
2049 networt_send_buffer_plain (se, buffer, sizeof (buffer));
2050 } /* }}} void networt_send_buffer_signed */
2052 static void networt_send_buffer_encrypted (sockent_t *se, /* {{{ */
2053 const char *in_buffer, size_t in_buffer_size)
2055 part_encryption_aes256_t pea;
2056 char buffer[sizeof (pea) + in_buffer_size];
2058 size_t buffer_offset;
2059 size_t padding_size;
2061 gcry_cipher_hd_t cypher;
2063 /* Round to the next multiple of 16, because AES has a block size of 128 bit.
2064 * the first 20 bytes of `pea' are not encrypted and must be subtracted. */
2065 buffer_size = in_buffer_size +
2066 (PART_ENCRYPTION_AES256_SIZE - PART_ENCRYPTION_AES256_UNENCR_SIZE);
2067 padding_size = buffer_size;
2068 /* Round to the next multiple of 16. */
2069 buffer_size = (buffer_size + 15) / 16;
2070 buffer_size = buffer_size * 16;
2071 /* Calculate padding_size */
2072 padding_size = buffer_size - padding_size;
2073 assert (padding_size <= sizeof (pea.padding));
2074 /* Now add the unencrypted bytes. */
2075 buffer_size += PART_ENCRYPTION_AES256_UNENCR_SIZE;
2077 DEBUG ("network plugin: networt_send_buffer_encrypted: "
2078 "buffer_size = %zu;", buffer_size);
2080 /* Initialize the header fields */
2081 memset (&pea, 0, sizeof (pea));
2082 pea.head.type = htons (TYPE_ENCR_AES256);
2083 pea.head.length = htons ((uint16_t) buffer_size);
2084 pea.orig_length = htons ((uint16_t) in_buffer_size);
2086 /* Chose a random initialization vector. */
2087 gcry_randomize ((void *) &pea.iv, sizeof (pea.iv), GCRY_STRONG_RANDOM);
2089 /* Create hash of the payload */
2090 gcry_md_hash_buffer (GCRY_MD_SHA1, pea.hash, in_buffer, in_buffer_size);
2092 /* Fill the extra field with random values. Some entropy in the encrypted
2093 * data is usually not a bad thing, I hope. */
2094 if (padding_size > 0)
2095 gcry_randomize ((void *) &pea.padding, padding_size, GCRY_STRONG_RANDOM);
2097 /* Initialize the buffer */
2099 memset (buffer, 0, sizeof (buffer));
2101 #define BUFFER_ADD(p,s) do { \
2102 memcpy (buffer + buffer_offset, (p), (s)); \
2103 buffer_offset += (s); \
2106 BUFFER_ADD (&pea.head.type, sizeof (pea.head.type));
2107 BUFFER_ADD (&pea.head.length, sizeof (pea.head.length));
2108 BUFFER_ADD (pea.iv, sizeof (pea.iv));
2109 BUFFER_ADD (&pea.orig_length, sizeof (pea.orig_length));
2110 BUFFER_ADD (pea.hash, sizeof (pea.hash));
2112 if (padding_size > 0)
2113 BUFFER_ADD (pea.padding, padding_size);
2115 BUFFER_ADD (in_buffer, in_buffer_size);
2117 assert (buffer_offset == buffer_size);
2119 cypher = network_get_aes256_cypher (se, pea.iv, sizeof (pea.iv));
2123 /* Encrypt the buffer in-place */
2124 err = gcry_cipher_encrypt (cypher,
2125 buffer + PART_ENCRYPTION_AES256_UNENCR_SIZE,
2126 buffer_size - PART_ENCRYPTION_AES256_UNENCR_SIZE,
2127 /* in = */ NULL, /* in len = */ 0);
2130 ERROR ("network plugin: gcry_cipher_encrypt returned: %s",
2131 gcry_strerror (err));
2135 /* Send it out without further modifications */
2136 networt_send_buffer_plain (se, buffer, buffer_size);
2138 } /* }}} void networt_send_buffer_encrypted */
2139 #endif /* HAVE_GCRYPT_H */
2141 static void network_send_buffer (char *buffer, size_t buffer_len) /* {{{ */
2145 DEBUG ("network plugin: network_send_buffer: buffer_len = %zu", buffer_len);
2147 for (se = sending_sockets; se != NULL; se = se->next)
2150 if (se->security_level == SECURITY_LEVEL_ENCRYPT)
2151 networt_send_buffer_encrypted (se, buffer, buffer_len);
2152 else if (se->security_level == SECURITY_LEVEL_SIGN)
2153 networt_send_buffer_signed (se, buffer, buffer_len);
2154 else /* if (se->security_level == SECURITY_LEVEL_NONE) */
2155 #endif /* HAVE_GCRYPT_H */
2156 networt_send_buffer_plain (se, buffer, buffer_len);
2157 } /* for (sending_sockets) */
2158 } /* }}} void network_send_buffer */
2160 static int add_to_buffer (char *buffer, int buffer_size, /* {{{ */
2161 value_list_t *vl_def,
2162 const data_set_t *ds, const value_list_t *vl)
2164 char *buffer_orig = buffer;
2166 if (strcmp (vl_def->host, vl->host) != 0)
2168 if (write_part_string (&buffer, &buffer_size, TYPE_HOST,
2169 vl->host, strlen (vl->host)) != 0)
2171 sstrncpy (vl_def->host, vl->host, sizeof (vl_def->host));
2174 if (vl_def->time != vl->time)
2176 if (write_part_number (&buffer, &buffer_size, TYPE_TIME,
2177 (uint64_t) vl->time))
2179 vl_def->time = vl->time;
2182 if (vl_def->interval != vl->interval)
2184 if (write_part_number (&buffer, &buffer_size, TYPE_INTERVAL,
2185 (uint64_t) vl->interval))
2187 vl_def->interval = vl->interval;
2190 if (strcmp (vl_def->plugin, vl->plugin) != 0)
2192 if (write_part_string (&buffer, &buffer_size, TYPE_PLUGIN,
2193 vl->plugin, strlen (vl->plugin)) != 0)
2195 sstrncpy (vl_def->plugin, vl->plugin, sizeof (vl_def->plugin));
2198 if (strcmp (vl_def->plugin_instance, vl->plugin_instance) != 0)
2200 if (write_part_string (&buffer, &buffer_size, TYPE_PLUGIN_INSTANCE,
2201 vl->plugin_instance,
2202 strlen (vl->plugin_instance)) != 0)
2204 sstrncpy (vl_def->plugin_instance, vl->plugin_instance, sizeof (vl_def->plugin_instance));
2207 if (strcmp (vl_def->type, vl->type) != 0)
2209 if (write_part_string (&buffer, &buffer_size, TYPE_TYPE,
2210 vl->type, strlen (vl->type)) != 0)
2212 sstrncpy (vl_def->type, ds->type, sizeof (vl_def->type));
2215 if (strcmp (vl_def->type_instance, vl->type_instance) != 0)
2217 if (write_part_string (&buffer, &buffer_size, TYPE_TYPE_INSTANCE,
2219 strlen (vl->type_instance)) != 0)
2221 sstrncpy (vl_def->type_instance, vl->type_instance, sizeof (vl_def->type_instance));
2224 if (write_part_values (&buffer, &buffer_size, ds, vl) != 0)
2227 return (buffer - buffer_orig);
2228 } /* }}} int add_to_buffer */
2230 static void flush_buffer (void)
2232 DEBUG ("network plugin: flush_buffer: send_buffer_fill = %i",
2235 network_send_buffer (send_buffer, (size_t) send_buffer_fill);
2236 network_init_buffer ();
2239 static int network_write (const data_set_t *ds, const value_list_t *vl,
2240 user_data_t __attribute__((unused)) *user_data)
2244 /* If the value is already in the cache, we have received it via the
2245 * network. We write it again if forwarding is activated. It's then in
2246 * the cache and should we receive it again we will ignore it. */
2247 status = cache_check (vl);
2248 if ((network_config_forward == 0)
2252 pthread_mutex_lock (&send_buffer_lock);
2254 status = add_to_buffer (send_buffer_ptr,
2255 sizeof (send_buffer) - (send_buffer_fill + BUFF_SIG_SIZE),
2260 /* status == bytes added to the buffer */
2261 send_buffer_fill += status;
2262 send_buffer_ptr += status;
2268 status = add_to_buffer (send_buffer_ptr,
2269 sizeof (send_buffer) - (send_buffer_fill + BUFF_SIG_SIZE),
2275 send_buffer_fill += status;
2276 send_buffer_ptr += status;
2282 ERROR ("network plugin: Unable to append to the "
2283 "buffer for some weird reason");
2285 else if ((sizeof (send_buffer) - send_buffer_fill) < 15)
2290 pthread_mutex_unlock (&send_buffer_lock);
2292 return ((status < 0) ? -1 : 0);
2293 } /* int network_write */
2295 static int network_config_set_boolean (const oconfig_item_t *ci, /* {{{ */
2298 if ((ci->values_num != 1)
2299 || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN)
2300 && (ci->values[0].type != OCONFIG_TYPE_STRING)))
2302 ERROR ("network plugin: The `%s' config option needs "
2303 "exactly one boolean argument.", ci->key);
2307 if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
2309 if (ci->values[0].value.boolean)
2316 char *str = ci->values[0].value.string;
2318 if ((strcasecmp ("true", str) == 0)
2319 || (strcasecmp ("yes", str) == 0)
2320 || (strcasecmp ("on", str) == 0))
2322 else if ((strcasecmp ("false", str) == 0)
2323 || (strcasecmp ("no", str) == 0)
2324 || (strcasecmp ("off", str) == 0))
2328 ERROR ("network plugin: Cannot parse string value `%s' of the `%s' "
2329 "option as boolean value.",
2336 } /* }}} int network_config_set_boolean */
2338 static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */
2341 if ((ci->values_num != 1)
2342 || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
2344 WARNING ("network plugin: The `TimeToLive' config option needs exactly "
2345 "one numeric argument.");
2349 tmp = (int) ci->values[0].value.number;
2350 if ((tmp > 0) && (tmp <= 255))
2351 network_config_ttl = tmp;
2354 } /* }}} int network_config_set_ttl */
2357 static int network_config_set_security_level (oconfig_item_t *ci, /* {{{ */
2361 if ((ci->values_num != 1)
2362 || (ci->values[0].type != OCONFIG_TYPE_STRING))
2364 WARNING ("network plugin: The `SecurityLevel' config option needs exactly "
2365 "one string argument.");
2369 str = ci->values[0].value.string;
2370 if (strcasecmp ("Encrypt", str) == 0)
2371 *retval = SECURITY_LEVEL_ENCRYPT;
2372 else if (strcasecmp ("Sign", str) == 0)
2373 *retval = SECURITY_LEVEL_SIGN;
2374 else if (strcasecmp ("None", str) == 0)
2375 *retval = SECURITY_LEVEL_NONE;
2378 WARNING ("network plugin: Unknown security level: %s.", str);
2383 } /* }}} int network_config_set_security_level */
2384 #endif /* HAVE_GCRYPT_H */
2386 static int network_config_listen_server (const oconfig_item_t *ci) /* {{{ */
2390 char *shared_secret = NULL;
2391 int security_level = SECURITY_LEVEL_NONE;
2394 if ((ci->values_num < 1) || (ci->values_num > 2)
2395 || (ci->values[0].type != OCONFIG_TYPE_STRING)
2396 || ((ci->values_num > 1) && (ci->values[1].type != OCONFIG_TYPE_STRING)))
2398 ERROR ("network plugin: The `%s' config option needs "
2399 "one or two string arguments.", ci->key);
2403 node = ci->values[0].value.string;
2404 if (ci->values_num >= 2)
2405 service = ci->values[1].value.string;
2409 for (i = 0; i < ci->children_num; i++)
2411 oconfig_item_t *child = ci->children + i;
2414 if (strcasecmp ("Secret", child->key) == 0)
2416 if ((child->values_num == 1)
2417 && (child->values[0].type == OCONFIG_TYPE_STRING))
2418 shared_secret = child->values[0].value.string;
2420 ERROR ("network plugin: The `Secret' option needs exactly one string "
2423 else if (strcasecmp ("SecurityLevel", child->key) == 0)
2424 network_config_set_security_level (child, &security_level);
2426 #endif /* HAVE_GCRYPT_H */
2428 WARNING ("network plugin: Option `%s' is not allowed here.",
2433 if ((security_level > SECURITY_LEVEL_NONE) && (shared_secret == NULL))
2435 ERROR ("network plugin: A security level higher than `none' was "
2436 "requested, but no shared key was given. Cowardly refusing to open "
2441 if (strcasecmp ("Listen", ci->key) == 0)
2442 network_add_listen_socket (node, service, shared_secret, security_level);
2444 network_add_sending_socket (node, service, shared_secret, security_level);
2447 } /* }}} int network_config_listen_server */
2449 static int network_config_set_cache_flush (const oconfig_item_t *ci) /* {{{ */
2452 if ((ci->values_num != 1)
2453 || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
2455 WARNING ("network plugin: The `CacheFlush' config option needs exactly "
2456 "one numeric argument.");
2460 tmp = (int) ci->values[0].value.number;
2462 network_config_ttl = tmp;
2465 } /* }}} int network_config_set_cache_flush */
2467 static int network_config (oconfig_item_t *ci) /* {{{ */
2471 for (i = 0; i < ci->children_num; i++)
2473 oconfig_item_t *child = ci->children + i;
2475 if ((strcasecmp ("Listen", child->key) == 0)
2476 || (strcasecmp ("Server", child->key) == 0))
2477 network_config_listen_server (child);
2478 else if (strcasecmp ("TimeToLive", child->key) == 0)
2479 network_config_set_ttl (child);
2480 else if (strcasecmp ("Forward", child->key) == 0)
2481 network_config_set_boolean (child, &network_config_forward);
2482 else if (strcasecmp ("CacheFlush", child->key) == 0)
2483 network_config_set_cache_flush (child);
2486 WARNING ("network plugin: Option `%s' is not allowed here.",
2492 } /* }}} int network_config */
2494 static int network_notification (const notification_t *n,
2495 user_data_t __attribute__((unused)) *user_data)
2497 char buffer[BUFF_SIZE];
2498 char *buffer_ptr = buffer;
2499 int buffer_free = sizeof (buffer);
2502 memset (buffer, '\0', sizeof (buffer));
2505 status = write_part_number (&buffer_ptr, &buffer_free, TYPE_TIME,
2506 (uint64_t) n->time);
2510 status = write_part_number (&buffer_ptr, &buffer_free, TYPE_SEVERITY,
2511 (uint64_t) n->severity);
2515 if (strlen (n->host) > 0)
2517 status = write_part_string (&buffer_ptr, &buffer_free, TYPE_HOST,
2518 n->host, strlen (n->host));
2523 if (strlen (n->plugin) > 0)
2525 status = write_part_string (&buffer_ptr, &buffer_free, TYPE_PLUGIN,
2526 n->plugin, strlen (n->plugin));
2531 if (strlen (n->plugin_instance) > 0)
2533 status = write_part_string (&buffer_ptr, &buffer_free,
2534 TYPE_PLUGIN_INSTANCE,
2535 n->plugin_instance, strlen (n->plugin_instance));
2540 if (strlen (n->type) > 0)
2542 status = write_part_string (&buffer_ptr, &buffer_free, TYPE_TYPE,
2543 n->type, strlen (n->type));
2548 if (strlen (n->type_instance) > 0)
2550 status = write_part_string (&buffer_ptr, &buffer_free, TYPE_TYPE_INSTANCE,
2551 n->type_instance, strlen (n->type_instance));
2556 status = write_part_string (&buffer_ptr, &buffer_free, TYPE_MESSAGE,
2557 n->message, strlen (n->message));
2561 network_send_buffer (buffer, sizeof (buffer) - buffer_free);
2564 } /* int network_notification */
2566 static int network_shutdown (void)
2570 /* Kill the listening thread */
2571 if (receive_thread_running != 0)
2573 INFO ("network plugin: Stopping receive thread.");
2574 pthread_kill (receive_thread_id, SIGTERM);
2575 pthread_join (receive_thread_id, NULL /* no return value */);
2576 memset (&receive_thread_id, 0, sizeof (receive_thread_id));
2577 receive_thread_running = 0;
2580 /* Shutdown the dispatching thread */
2581 if (dispatch_thread_running != 0)
2583 INFO ("network plugin: Stopping dispatch thread.");
2584 pthread_mutex_lock (&receive_list_lock);
2585 pthread_cond_broadcast (&receive_list_cond);
2586 pthread_mutex_unlock (&receive_list_lock);
2587 pthread_join (dispatch_thread_id, /* ret = */ NULL);
2588 dispatch_thread_running = 0;
2591 free_sockent (listen_sockets);
2593 if (send_buffer_fill > 0)
2596 if (cache_tree != NULL)
2601 while (c_avl_pick (cache_tree, &key, &value) == 0)
2606 c_avl_destroy (cache_tree);
2610 /* TODO: Close `sending_sockets' */
2612 plugin_unregister_config ("network");
2613 plugin_unregister_init ("network");
2614 plugin_unregister_write ("network");
2615 plugin_unregister_shutdown ("network");
2617 /* Let the init function do it's move again ;) */
2618 cache_flush_last = 0;
2621 } /* int network_shutdown */
2623 static int network_init (void)
2625 /* Check if we were already initialized. If so, just return - there's
2626 * nothing more to do (for now, that is). */
2627 if (cache_flush_last != 0)
2630 plugin_register_shutdown ("network", network_shutdown);
2632 network_init_buffer ();
2634 cache_tree = c_avl_create ((int (*) (const void *, const void *)) strcmp);
2635 cache_flush_last = time (NULL);
2637 /* setup socket(s) and so on */
2638 if (sending_sockets != NULL)
2640 plugin_register_write ("network", network_write,
2641 /* user_data = */ NULL);
2642 plugin_register_notification ("network", network_notification,
2643 /* user_data = */ NULL);
2646 /* If no threads need to be started, return here. */
2647 if ((listen_sockets_num == 0)
2648 || ((dispatch_thread_running != 0)
2649 && (receive_thread_running != 0)))
2652 if (dispatch_thread_running == 0)
2655 status = pthread_create (&dispatch_thread_id,
2656 NULL /* no attributes */,
2658 NULL /* no argument */);
2662 ERROR ("network: pthread_create failed: %s",
2663 sstrerror (errno, errbuf,
2668 dispatch_thread_running = 1;
2672 if (receive_thread_running == 0)
2675 status = pthread_create (&receive_thread_id,
2676 NULL /* no attributes */,
2678 NULL /* no argument */);
2682 ERROR ("network: pthread_create failed: %s",
2683 sstrerror (errno, errbuf,
2688 receive_thread_running = 1;
2693 } /* int network_init */
2696 * The flush option of the network plugin cannot flush individual identifiers.
2697 * All the values are added to a buffer and sent when the buffer is full, the
2698 * requested value may or may not be in there, it's not worth finding out. We
2699 * just send the buffer if `flush' is called - if the requested value was in
2700 * there, good. If not, well, then there is nothing to flush.. -octo
2702 static int network_flush (int timeout,
2703 const char __attribute__((unused)) *identifier,
2704 user_data_t __attribute__((unused)) *user_data)
2706 pthread_mutex_lock (&send_buffer_lock);
2708 if (((time (NULL) - cache_flush_last) >= timeout)
2709 && (send_buffer_fill > 0))
2714 pthread_mutex_unlock (&send_buffer_lock);
2717 } /* int network_flush */
2719 void module_register (void)
2721 plugin_register_complex_config ("network", network_config);
2722 plugin_register_init ("network", network_init);
2723 plugin_register_flush ("network", network_flush,
2724 /* user_data = */ NULL);
2725 } /* void module_register */
2727 /* vim: set fdm=marker : */