2 * collectd - src/snmp.c
3 * Copyright (C) 2007-2012 Florian octo Forster
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Florian octo Forster <octo at collectd.org>
31 #include "utils_complain.h"
33 #include <net-snmp/net-snmp-config.h>
34 #include <net-snmp/net-snmp-includes.h>
39 * Private data structes
46 typedef struct oid_s oid_t;
50 char string[DATA_MAX_NAME_LEN];
53 typedef union instance_u instance_t;
55 struct data_definition_s
57 char *name; /* used to reference this from the `Collect' option */
58 char *type; /* used to find the data_set */
61 char *instance_prefix;
66 struct data_definition_s *next;
71 typedef struct data_definition_s data_definition_t;
73 struct host_definition_s
79 /* snmpv1/2 options */
82 /* snmpv3 security options */
85 size_t auth_protocol_len;
86 char *auth_passphrase;
88 size_t priv_protocol_len;
89 char *priv_passphrase;
94 c_complain_t complaint;
96 data_definition_t **data_list;
99 typedef struct host_definition_s host_definition_t;
101 /* These two types are used to cache values in `csnmp_read_table' to handle
103 struct csnmp_list_instances_s
106 char instance[DATA_MAX_NAME_LEN];
107 struct csnmp_list_instances_s *next;
109 typedef struct csnmp_list_instances_s csnmp_list_instances_t;
111 struct csnmp_table_values_s
115 struct csnmp_table_values_s *next;
117 typedef struct csnmp_table_values_s csnmp_table_values_t;
122 static data_definition_t *data_head = NULL;
127 static int csnmp_read_host (user_data_t *ud);
132 static void csnmp_oid_init (oid_t *dst, oid const *src, size_t n)
134 assert (n <= STATIC_ARRAY_SIZE (dst->oid));
135 memcpy (dst->oid, src, sizeof (*src) * n);
139 static int csnmp_oid_compare (oid_t const *left, oid_t const *right)
141 return (snmp_oid_compare (left->oid, left->oid_len,
142 right->oid, right->oid_len));
145 static int csnmp_oid_suffix (oid_t *dst, oid_t const *src,
148 /* Make sure "src" is in "root"s subtree. */
149 if (src->oid_len <= root->oid_len)
151 if (snmp_oid_ncompare (root->oid, root->oid_len,
152 src->oid, src->oid_len,
153 /* n = */ root->oid_len) != 0)
156 memset (dst, 0, sizeof (*dst));
157 dst->oid_len = src->oid_len - root->oid_len;
158 memcpy (dst->oid, &src->oid[root->oid_len],
159 dst->oid_len * sizeof (dst->oid[0]));
163 static int csnmp_oid_to_string (char *buffer, size_t buffer_size,
166 char oid_str[MAX_OID_LEN][16];
167 char *oid_str_ptr[MAX_OID_LEN];
169 for (size_t i = 0; i < o->oid_len; i++)
171 ssnprintf (oid_str[i], sizeof (oid_str[i]), "%lu", (unsigned long) o->oid[i]);
172 oid_str_ptr[i] = oid_str[i];
175 return (strjoin (buffer, buffer_size,
176 oid_str_ptr, o->oid_len, /* separator = */ "."));
179 static void csnmp_host_close_session (host_definition_t *host) /* {{{ */
181 if (host->sess_handle == NULL)
184 snmp_sess_close (host->sess_handle);
185 host->sess_handle = NULL;
186 } /* }}} void csnmp_host_close_session */
188 static void csnmp_host_definition_destroy (void *arg) /* {{{ */
190 host_definition_t *hd;
197 if (hd->name != NULL)
199 DEBUG ("snmp plugin: Destroying host definition for host `%s'.",
203 csnmp_host_close_session (hd);
207 sfree (hd->community);
208 sfree (hd->username);
209 sfree (hd->auth_passphrase);
210 sfree (hd->priv_passphrase);
212 sfree (hd->data_list);
215 } /* }}} void csnmp_host_definition_destroy */
217 /* Many functions to handle the configuration. {{{ */
218 /* First there are many functions which do configuration stuff. It's a big
219 * bloated and messy, I'm afraid. */
222 * Callgraph for the config stuff:
224 * +-> call_snmp_init_once
225 * +-> csnmp_config_add_data
226 * ! +-> csnmp_config_add_data_instance
227 * ! +-> csnmp_config_add_data_instance_prefix
228 * ! +-> csnmp_config_add_data_values
229 * +-> csnmp_config_add_host
230 * +-> csnmp_config_add_host_version
231 * +-> csnmp_config_add_host_collect
232 * +-> csnmp_config_add_host_auth_protocol
233 * +-> csnmp_config_add_host_priv_protocol
234 * +-> csnmp_config_add_host_security_level
236 static void call_snmp_init_once (void)
238 static int have_init = 0;
241 init_snmp (PACKAGE_NAME);
243 } /* void call_snmp_init_once */
245 static int csnmp_config_add_data_instance (data_definition_t *dd, oconfig_item_t *ci)
247 char buffer[DATA_MAX_NAME_LEN];
250 status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
256 /* Instance is an OID */
257 dd->instance.oid.oid_len = MAX_OID_LEN;
259 if (!read_objid (buffer,
260 dd->instance.oid.oid, &dd->instance.oid.oid_len))
262 ERROR ("snmp plugin: read_objid (%s) failed.", buffer);
268 /* Instance is a simple string */
269 sstrncpy (dd->instance.string, buffer,
270 sizeof (dd->instance.string));
274 } /* int csnmp_config_add_data_instance */
276 static int csnmp_config_add_data_instance_prefix (data_definition_t *dd,
283 WARNING ("snmp plugin: data %s: InstancePrefix is ignored when `Table' "
284 "is set to `false'.", dd->name);
288 status = cf_util_get_string(ci, &dd->instance_prefix);
290 } /* int csnmp_config_add_data_instance_prefix */
292 static int csnmp_config_add_data_values (data_definition_t *dd, oconfig_item_t *ci)
294 if (ci->values_num < 1)
296 WARNING ("snmp plugin: `Values' needs at least one argument.");
300 for (int i = 0; i < ci->values_num; i++)
301 if (ci->values[i].type != OCONFIG_TYPE_STRING)
303 WARNING ("snmp plugin: `Values' needs only string argument.");
309 dd->values = malloc (sizeof (*dd->values) * ci->values_num);
310 if (dd->values == NULL)
312 dd->values_len = (size_t) ci->values_num;
314 for (int i = 0; i < ci->values_num; i++)
316 dd->values[i].oid_len = MAX_OID_LEN;
318 if (NULL == snmp_parse_oid (ci->values[i].value.string,
319 dd->values[i].oid, &dd->values[i].oid_len))
321 ERROR ("snmp plugin: snmp_parse_oid (%s) failed.",
322 ci->values[i].value.string);
331 } /* int csnmp_config_add_data_instance */
333 static int csnmp_config_add_data_blacklist(data_definition_t *dd, oconfig_item_t *ci)
335 if (ci->values_num < 1)
338 for (int i = 0; i < ci->values_num; i++)
340 if (ci->values[i].type != OCONFIG_TYPE_STRING)
342 WARNING ("snmp plugin: `Ignore' needs only string argument.");
350 for (int i = 0; i < ci->values_num; ++i)
352 if (strarray_add(&(dd->ignores), &(dd->ignores_len), ci->values[i].value.string) != 0)
354 ERROR("snmp plugin: Can't allocate memory");
355 strarray_free(dd->ignores, dd->ignores_len);
360 } /* int csnmp_config_add_data_blacklist */
362 static int csnmp_config_add_data_blacklist_match_inverted(data_definition_t *dd, oconfig_item_t *ci)
364 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
366 WARNING ("snmp plugin: `InvertMatch' needs exactly one boolean argument.");
370 dd->invert_match = ci->values[0].value.boolean ? 1 : 0;
373 } /* int csnmp_config_add_data_blacklist_match_inverted */
375 static int csnmp_config_add_data (oconfig_item_t *ci)
377 data_definition_t *dd;
380 dd = calloc (1, sizeof (*dd));
384 status = cf_util_get_string(ci, &dd->name);
394 for (int i = 0; i < ci->children_num; i++)
396 oconfig_item_t *option = ci->children + i;
398 if (strcasecmp ("Type", option->key) == 0)
399 status = cf_util_get_string(option, &dd->type);
400 else if (strcasecmp ("Table", option->key) == 0)
401 status = cf_util_get_boolean(option, &dd->is_table);
402 else if (strcasecmp ("Instance", option->key) == 0)
403 status = csnmp_config_add_data_instance (dd, option);
404 else if (strcasecmp ("InstancePrefix", option->key) == 0)
405 status = csnmp_config_add_data_instance_prefix (dd, option);
406 else if (strcasecmp ("Values", option->key) == 0)
407 status = csnmp_config_add_data_values (dd, option);
408 else if (strcasecmp ("Shift", option->key) == 0)
409 status = cf_util_get_double(option, &dd->shift);
410 else if (strcasecmp ("Scale", option->key) == 0)
411 status = cf_util_get_double(option, &dd->scale);
412 else if (strcasecmp ("Ignore", option->key) == 0)
413 status = csnmp_config_add_data_blacklist(dd, option);
414 else if (strcasecmp ("InvertMatch", option->key) == 0)
415 status = csnmp_config_add_data_blacklist_match_inverted(dd, option);
418 WARNING ("snmp plugin: Option `%s' not allowed here.", option->key);
424 } /* for (ci->children) */
428 if (dd->type == NULL)
430 WARNING ("snmp plugin: `Type' not given for data `%s'", dd->name);
434 if (dd->values == NULL)
436 WARNING ("snmp plugin: No `Value' given for data `%s'", dd->name);
442 } /* while (status == 0) */
447 sfree (dd->instance_prefix);
454 DEBUG ("snmp plugin: dd = { name = %s, type = %s, is_table = %s, values_len = %zu }",
455 dd->name, dd->type, (dd->is_table != 0) ? "true" : "false", dd->values_len);
457 if (data_head == NULL)
461 data_definition_t *last;
463 while (last->next != NULL)
469 } /* int csnmp_config_add_data */
471 static int csnmp_config_add_host_version (host_definition_t *hd, oconfig_item_t *ci)
475 if ((ci->values_num != 1)
476 || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
478 WARNING ("snmp plugin: The `Version' config option needs exactly one number argument.");
482 version = (int) ci->values[0].value.number;
483 if ((version < 1) || (version > 3))
485 WARNING ("snmp plugin: `Version' must either be `1', `2', or `3'.");
489 hd->version = version;
492 } /* int csnmp_config_add_host_address */
494 static int csnmp_config_add_host_collect (host_definition_t *host,
497 data_definition_t *data;
498 data_definition_t **data_list;
501 if (ci->values_num < 1)
503 WARNING ("snmp plugin: `Collect' needs at least one argument.");
507 for (int i = 0; i < ci->values_num; i++)
508 if (ci->values[i].type != OCONFIG_TYPE_STRING)
510 WARNING ("snmp plugin: All arguments to `Collect' must be strings.");
514 data_list_len = host->data_list_len + ci->values_num;
515 data_list = realloc (host->data_list,
516 sizeof (data_definition_t *) * data_list_len);
517 if (data_list == NULL)
519 host->data_list = data_list;
521 for (int i = 0; i < ci->values_num; i++)
523 for (data = data_head; data != NULL; data = data->next)
524 if (strcasecmp (ci->values[i].value.string, data->name) == 0)
529 WARNING ("snmp plugin: No such data configured: `%s'",
530 ci->values[i].value.string);
534 DEBUG ("snmp plugin: Collect: host = %s, data[%i] = %s;",
535 host->name, host->data_list_len, data->name);
537 host->data_list[host->data_list_len] = data;
538 host->data_list_len++;
539 } /* for (values_num) */
542 } /* int csnmp_config_add_host_collect */
544 static int csnmp_config_add_host_auth_protocol (host_definition_t *hd, oconfig_item_t *ci)
549 status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
553 if (strcasecmp("MD5", buffer) == 0) {
554 hd->auth_protocol = usmHMACMD5AuthProtocol;
555 hd->auth_protocol_len = sizeof(usmHMACMD5AuthProtocol)/sizeof(oid);
557 else if (strcasecmp("SHA", buffer) == 0) {
558 hd->auth_protocol = usmHMACSHA1AuthProtocol;
559 hd->auth_protocol_len = sizeof(usmHMACSHA1AuthProtocol)/sizeof(oid);
563 WARNING ("snmp plugin: The `AuthProtocol' config option must be `MD5' or `SHA'.");
567 DEBUG ("snmp plugin: host = %s; host->auth_protocol = %s;",
568 hd->name, hd->auth_protocol == usmHMACMD5AuthProtocol ? "MD5" : "SHA");
571 } /* int csnmp_config_add_host_auth_protocol */
573 static int csnmp_config_add_host_priv_protocol (host_definition_t *hd, oconfig_item_t *ci)
578 status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
582 if (strcasecmp("AES", buffer) == 0)
584 hd->priv_protocol = usmAESPrivProtocol;
585 hd->priv_protocol_len = sizeof(usmAESPrivProtocol)/sizeof(oid);
587 else if (strcasecmp("DES", buffer) == 0) {
588 hd->priv_protocol = usmDESPrivProtocol;
589 hd->priv_protocol_len = sizeof(usmDESPrivProtocol)/sizeof(oid);
593 WARNING ("snmp plugin: The `PrivProtocol' config option must be `AES' or `DES'.");
597 DEBUG ("snmp plugin: host = %s; host->priv_protocol = %s;",
598 hd->name, hd->priv_protocol == usmAESPrivProtocol ? "AES" : "DES");
601 } /* int csnmp_config_add_host_priv_protocol */
603 static int csnmp_config_add_host_security_level (host_definition_t *hd, oconfig_item_t *ci)
608 status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
612 if (strcasecmp("noAuthNoPriv", buffer) == 0)
613 hd->security_level = SNMP_SEC_LEVEL_NOAUTH;
614 else if (strcasecmp("authNoPriv", buffer) == 0)
615 hd->security_level = SNMP_SEC_LEVEL_AUTHNOPRIV;
616 else if (strcasecmp("authPriv", buffer) == 0)
617 hd->security_level = SNMP_SEC_LEVEL_AUTHPRIV;
620 WARNING ("snmp plugin: The `SecurityLevel' config option must be `noAuthNoPriv', `authNoPriv', or `authPriv'.");
624 DEBUG ("snmp plugin: host = %s; host->security_level = %d;",
625 hd->name, hd->security_level);
628 } /* int csnmp_config_add_host_security_level */
630 static int csnmp_config_add_host (oconfig_item_t *ci)
632 host_definition_t *hd;
635 /* Registration stuff. */
636 char cb_name[DATA_MAX_NAME_LEN];
638 hd = calloc (1, sizeof (*hd));
642 C_COMPLAIN_INIT (&hd->complaint);
644 status = cf_util_get_string(ci, &hd->name);
651 hd->sess_handle = NULL;
654 for (int i = 0; i < ci->children_num; i++)
656 oconfig_item_t *option = ci->children + i;
659 if (strcasecmp ("Address", option->key) == 0)
660 status = cf_util_get_string(option, &hd->address);
661 else if (strcasecmp ("Community", option->key) == 0)
662 status = cf_util_get_string(option, &hd->community);
663 else if (strcasecmp ("Version", option->key) == 0)
664 status = csnmp_config_add_host_version (hd, option);
665 else if (strcasecmp ("Collect", option->key) == 0)
666 csnmp_config_add_host_collect (hd, option);
667 else if (strcasecmp ("Interval", option->key) == 0)
668 cf_util_get_cdtime (option, &hd->interval);
669 else if (strcasecmp ("Username", option->key) == 0)
670 status = cf_util_get_string(option, &hd->username);
671 else if (strcasecmp ("AuthProtocol", option->key) == 0)
672 status = csnmp_config_add_host_auth_protocol (hd, option);
673 else if (strcasecmp ("PrivacyProtocol", option->key) == 0)
674 status = csnmp_config_add_host_priv_protocol (hd, option);
675 else if (strcasecmp ("AuthPassphrase", option->key) == 0)
676 status = cf_util_get_string(option, &hd->auth_passphrase);
677 else if (strcasecmp ("PrivacyPassphrase", option->key) == 0)
678 status = cf_util_get_string(option, &hd->priv_passphrase);
679 else if (strcasecmp ("SecurityLevel", option->key) == 0)
680 status = csnmp_config_add_host_security_level (hd, option);
681 else if (strcasecmp ("Context", option->key) == 0)
682 status = cf_util_get_string(option, &hd->context);
685 WARNING ("snmp plugin: csnmp_config_add_host: Option `%s' not allowed here.", option->key);
691 } /* for (ci->children) */
695 if (hd->address == NULL)
697 WARNING ("snmp plugin: `Address' not given for host `%s'", hd->name);
701 if (hd->community == NULL && hd->version < 3)
703 WARNING ("snmp plugin: `Community' not given for host `%s'", hd->name);
707 if (hd->version == 3)
709 if (hd->username == NULL)
711 WARNING ("snmp plugin: `Username' not given for host `%s'", hd->name);
715 if (hd->security_level == 0)
717 WARNING ("snmp plugin: `SecurityLevel' not given for host `%s'", hd->name);
721 if (hd->security_level == SNMP_SEC_LEVEL_AUTHNOPRIV || hd->security_level == SNMP_SEC_LEVEL_AUTHPRIV)
723 if (hd->auth_protocol == NULL)
725 WARNING ("snmp plugin: `AuthProtocol' not given for host `%s'", hd->name);
729 if (hd->auth_passphrase == NULL)
731 WARNING ("snmp plugin: `AuthPassphrase' not given for host `%s'", hd->name);
736 if (hd->security_level == SNMP_SEC_LEVEL_AUTHPRIV)
738 if (hd->priv_protocol == NULL)
740 WARNING ("snmp plugin: `PrivacyProtocol' not given for host `%s'", hd->name);
744 if (hd->priv_passphrase == NULL)
746 WARNING ("snmp plugin: `PrivacyPassphrase' not given for host `%s'", hd->name);
754 } /* while (status == 0) */
758 csnmp_host_definition_destroy (hd);
762 DEBUG ("snmp plugin: hd = { name = %s, address = %s, community = %s, version = %i }",
763 hd->name, hd->address, hd->community, hd->version);
765 ssnprintf (cb_name, sizeof (cb_name), "snmp-%s", hd->name);
767 status = plugin_register_complex_read (/* group = */ NULL, cb_name,
768 csnmp_read_host, hd->interval, &(user_data_t) {
770 .free_func = csnmp_host_definition_destroy,
774 ERROR ("snmp plugin: Registering complex read function failed.");
775 csnmp_host_definition_destroy (hd);
780 } /* int csnmp_config_add_host */
782 static int csnmp_config (oconfig_item_t *ci)
784 call_snmp_init_once ();
786 for (int i = 0; i < ci->children_num; i++)
788 oconfig_item_t *child = ci->children + i;
789 if (strcasecmp ("Data", child->key) == 0)
790 csnmp_config_add_data (child);
791 else if (strcasecmp ("Host", child->key) == 0)
792 csnmp_config_add_host (child);
795 WARNING ("snmp plugin: Ignoring unknown config option `%s'.", child->key);
797 } /* for (ci->children) */
800 } /* int csnmp_config */
802 /* }}} End of the config stuff. Now the interesting part begins */
804 static void csnmp_host_open_session (host_definition_t *host)
806 struct snmp_session sess;
809 if (host->sess_handle != NULL)
810 csnmp_host_close_session (host);
812 snmp_sess_init (&sess);
813 sess.peername = host->address;
814 switch (host->version)
817 sess.version = SNMP_VERSION_1;
820 sess.version = SNMP_VERSION_3;
823 sess.version = SNMP_VERSION_2c;
827 if (host->version == 3)
829 sess.securityName = host->username;
830 sess.securityNameLen = strlen (host->username);
831 sess.securityLevel = host->security_level;
833 if (sess.securityLevel == SNMP_SEC_LEVEL_AUTHNOPRIV || sess.securityLevel == SNMP_SEC_LEVEL_AUTHPRIV)
835 sess.securityAuthProto = host->auth_protocol;
836 sess.securityAuthProtoLen = host->auth_protocol_len;
837 sess.securityAuthKeyLen = USM_AUTH_KU_LEN;
838 error = generate_Ku (sess.securityAuthProto,
839 sess.securityAuthProtoLen,
840 (u_char *) host->auth_passphrase,
841 strlen(host->auth_passphrase),
842 sess.securityAuthKey,
843 &sess.securityAuthKeyLen);
844 if (error != SNMPERR_SUCCESS) {
845 ERROR ("snmp plugin: host %s: Error generating Ku from auth_passphrase. (Error %d)", host->name, error);
849 if (sess.securityLevel == SNMP_SEC_LEVEL_AUTHPRIV)
851 sess.securityPrivProto = host->priv_protocol;
852 sess.securityPrivProtoLen = host->priv_protocol_len;
853 sess.securityPrivKeyLen = USM_PRIV_KU_LEN;
854 error = generate_Ku (sess.securityAuthProto,
855 sess.securityAuthProtoLen,
856 (u_char *) host->priv_passphrase,
857 strlen(host->priv_passphrase),
858 sess.securityPrivKey,
859 &sess.securityPrivKeyLen);
860 if (error != SNMPERR_SUCCESS) {
861 ERROR ("snmp plugin: host %s: Error generating Ku from priv_passphrase. (Error %d)", host->name, error);
865 if (host->context != NULL)
867 sess.contextName = host->context;
868 sess.contextNameLen = strlen (host->context);
871 else /* SNMPv1/2 "authenticates" with community string */
873 sess.community = (u_char *) host->community;
874 sess.community_len = strlen (host->community);
877 /* snmp_sess_open will copy the `struct snmp_session *'. */
878 host->sess_handle = snmp_sess_open (&sess);
880 if (host->sess_handle == NULL)
884 snmp_error (&sess, NULL, NULL, &errstr);
886 ERROR ("snmp plugin: host %s: snmp_sess_open failed: %s",
887 host->name, (errstr == NULL) ? "Unknown problem" : errstr);
890 } /* void csnmp_host_open_session */
892 /* TODO: Check if negative values wrap around. Problem: negative temperatures. */
893 static value_t csnmp_value_list_to_value (struct variable_list *vl, int type,
894 double scale, double shift,
895 const char *host_name, const char *data_name)
898 uint64_t tmp_unsigned = 0;
899 int64_t tmp_signed = 0;
901 /* Set to true when the original SNMP type appears to have been signed. */
902 _Bool prefer_signed = 0;
904 if ((vl->type == ASN_INTEGER)
905 || (vl->type == ASN_UINTEGER)
906 || (vl->type == ASN_COUNTER)
908 || (vl->type == ASN_TIMETICKS)
910 || (vl->type == ASN_GAUGE))
912 tmp_unsigned = (uint32_t) *vl->val.integer;
913 tmp_signed = (int32_t) *vl->val.integer;
915 if (vl->type == ASN_INTEGER)
918 DEBUG ("snmp plugin: Parsed int32 value is %"PRIu64".", tmp_unsigned);
920 else if (vl->type == ASN_COUNTER64)
922 tmp_unsigned = (uint32_t) vl->val.counter64->high;
923 tmp_unsigned = tmp_unsigned << 32;
924 tmp_unsigned += (uint32_t) vl->val.counter64->low;
925 tmp_signed = (int64_t) tmp_unsigned;
926 DEBUG ("snmp plugin: Parsed int64 value is %"PRIu64".", tmp_unsigned);
928 else if (vl->type == ASN_OCTET_STR)
930 /* We'll handle this later.. */
934 char oid_buffer[1024] = { 0 };
936 snprint_objid (oid_buffer, sizeof (oid_buffer) - 1,
937 vl->name, vl->name_length);
940 if (vl->type == ASN_NULL)
941 INFO ("snmp plugin: OID \"%s\" is undefined (type ASN_NULL)",
945 WARNING ("snmp plugin: I don't know the ASN type #%i "
946 "(OID: \"%s\", data block \"%s\", host block \"%s\")",
947 (int) vl->type, oid_buffer,
948 (data_name != NULL) ? data_name : "UNKNOWN",
949 (host_name != NULL) ? host_name : "UNKNOWN");
954 if (vl->type == ASN_OCTET_STR)
958 if (vl->val.string != NULL)
961 size_t string_length;
963 string_length = sizeof (string) - 1;
964 if (vl->val_len < string_length)
965 string_length = vl->val_len;
967 /* The strings we get from the Net-SNMP library may not be null
968 * terminated. That is why we're using `memcpy' here and not `strcpy'.
969 * `string_length' is set to `vl->val_len' which holds the length of the
971 memcpy (string, vl->val.string, string_length);
972 string[string_length] = 0;
974 status = parse_value (string, &ret, type);
977 ERROR ("snmp plugin: host %s: csnmp_value_list_to_value: Parsing string as %s failed: %s",
978 (host_name != NULL) ? host_name : "UNKNOWN",
979 DS_TYPE_TO_STRING (type), string);
987 case DS_TYPE_COUNTER:
989 case DS_TYPE_ABSOLUTE:
990 memset (&ret, 0, sizeof (ret));
998 ERROR ("snmp plugin: csnmp_value_list_to_value: Unknown "
999 "data source type: %i.", type);
1003 } /* if (vl->type == ASN_OCTET_STR) */
1004 else if (type == DS_TYPE_COUNTER)
1006 ret.counter = tmp_unsigned;
1008 else if (type == DS_TYPE_GAUGE)
1012 else if (prefer_signed)
1013 ret.gauge = (scale * tmp_signed) + shift;
1015 ret.gauge = (scale * tmp_unsigned) + shift;
1017 else if (type == DS_TYPE_DERIVE)
1020 ret.derive = (derive_t) tmp_signed;
1022 ret.derive = (derive_t) tmp_unsigned;
1024 else if (type == DS_TYPE_ABSOLUTE)
1026 ret.absolute = (absolute_t) tmp_unsigned;
1030 ERROR ("snmp plugin: csnmp_value_list_to_value: Unknown data source "
1036 } /* value_t csnmp_value_list_to_value */
1038 /* csnmp_strvbcopy_hexstring converts the bit string contained in "vb" to a hex
1039 * representation and writes it to dst. Returns zero on success and ENOMEM if
1040 * dst is not large enough to hold the string. dst is guaranteed to be
1041 * nul-terminated. */
1042 static int csnmp_strvbcopy_hexstring (char *dst, /* {{{ */
1043 const struct variable_list *vb, size_t dst_size)
1051 buffer_free = dst_size;
1053 for (size_t i = 0; i < vb->val_len; i++)
1057 status = snprintf (buffer_ptr, buffer_free,
1058 (i == 0) ? "%02x" : ":%02x", (unsigned int) vb->val.bitstring[i]);
1059 assert (status >= 0);
1061 if (((size_t) status) >= buffer_free) /* truncated */
1063 dst[dst_size - 1] = 0;
1066 else /* if (status < buffer_free) */
1068 buffer_ptr += (size_t) status;
1069 buffer_free -= (size_t) status;
1074 } /* }}} int csnmp_strvbcopy_hexstring */
1076 /* csnmp_strvbcopy copies the octet string or bit string contained in vb to
1077 * dst. If non-printable characters are detected, it will switch to a hex
1078 * representation of the string. Returns zero on success, EINVAL if vb does not
1079 * contain a string and ENOMEM if dst is not large enough to contain the
1081 static int csnmp_strvbcopy (char *dst, /* {{{ */
1082 const struct variable_list *vb, size_t dst_size)
1087 if (vb->type == ASN_OCTET_STR)
1088 src = (char *) vb->val.string;
1089 else if (vb->type == ASN_BIT_STR)
1090 src = (char *) vb->val.bitstring;
1091 else if (vb->type == ASN_IPADDRESS)
1093 return ssnprintf (dst, dst_size, "%"PRIu8".%"PRIu8".%"PRIu8".%"PRIu8"",
1094 (uint8_t) vb->val.string[0],
1095 (uint8_t) vb->val.string[1],
1096 (uint8_t) vb->val.string[2],
1097 (uint8_t) vb->val.string[3]);
1105 num_chars = dst_size - 1;
1106 if (num_chars > vb->val_len)
1107 num_chars = vb->val_len;
1109 for (size_t i = 0; i < num_chars; i++)
1111 /* Check for control characters. */
1112 if ((unsigned char)src[i] < 32)
1113 return (csnmp_strvbcopy_hexstring (dst, vb, dst_size));
1117 dst[dst_size - 1] = 0;
1119 if (dst_size <= vb->val_len)
1123 } /* }}} int csnmp_strvbcopy */
1125 static int csnmp_instance_list_add (csnmp_list_instances_t **head,
1126 csnmp_list_instances_t **tail,
1127 const struct snmp_pdu *res,
1128 const host_definition_t *hd, const data_definition_t *dd)
1130 csnmp_list_instances_t *il;
1131 struct variable_list *vb;
1134 uint32_t is_matched;
1136 /* Set vb on the last variable */
1137 for (vb = res->variables;
1138 (vb != NULL) && (vb->next_variable != NULL);
1139 vb = vb->next_variable)
1144 csnmp_oid_init (&vb_name, vb->name, vb->name_length);
1146 il = calloc (1, sizeof (*il));
1149 ERROR ("snmp plugin: calloc failed.");
1154 status = csnmp_oid_suffix (&il->suffix, &vb_name, &dd->instance.oid);
1161 /* Get instance name */
1162 if ((vb->type == ASN_OCTET_STR) || (vb->type == ASN_BIT_STR) || (vb->type == ASN_IPADDRESS))
1166 csnmp_strvbcopy (il->instance, vb, sizeof (il->instance));
1168 for (uint32_t i = 0; i < dd->ignores_len; i++)
1170 status = fnmatch(dd->ignores[i], il->instance, 0);
1173 if (dd->invert_match == 0)
1185 if (dd->invert_match != 0 && is_matched == 0)
1190 for (ptr = il->instance; *ptr != '\0'; ptr++)
1192 if ((*ptr > 0) && (*ptr < 32))
1194 else if (*ptr == '/')
1197 DEBUG ("snmp plugin: il->instance = `%s';", il->instance);
1201 value_t val = csnmp_value_list_to_value (vb, DS_TYPE_COUNTER,
1202 /* scale = */ 1.0, /* shift = */ 0.0, hd->name, dd->name);
1203 ssnprintf (il->instance, sizeof (il->instance),
1204 "%llu", val.counter);
1207 /* TODO: Debugging output */
1216 } /* int csnmp_instance_list_add */
1218 static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *data,
1219 csnmp_list_instances_t *instance_list,
1220 csnmp_table_values_t **value_table)
1222 const data_set_t *ds;
1223 value_list_t vl = VALUE_LIST_INIT;
1225 csnmp_list_instances_t *instance_list_ptr;
1226 csnmp_table_values_t **value_table_ptr;
1230 oid_t current_suffix;
1232 ds = plugin_get_ds (data->type);
1235 ERROR ("snmp plugin: DataSet `%s' not defined.", data->type);
1238 assert (ds->ds_num == data->values_len);
1239 assert (data->values_len > 0);
1241 instance_list_ptr = instance_list;
1243 value_table_ptr = calloc (data->values_len, sizeof (*value_table_ptr));
1244 if (value_table_ptr == NULL)
1246 for (i = 0; i < data->values_len; i++)
1247 value_table_ptr[i] = value_table[i];
1249 vl.values_len = data->values_len;
1250 vl.values = malloc (sizeof (*vl.values) * vl.values_len);
1251 if (vl.values == NULL)
1253 ERROR ("snmp plugin: malloc failed.");
1254 sfree (value_table_ptr);
1258 sstrncpy (vl.host, host->name, sizeof (vl.host));
1259 sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin));
1261 vl.interval = host->interval;
1266 _Bool suffix_skipped = 0;
1268 /* Determine next suffix to handle. */
1269 if (instance_list != NULL)
1271 if (instance_list_ptr == NULL)
1277 memcpy (¤t_suffix, &instance_list_ptr->suffix, sizeof (current_suffix));
1279 else /* no instance configured */
1281 csnmp_table_values_t *ptr = value_table_ptr[0];
1288 memcpy (¤t_suffix, &ptr->suffix, sizeof (current_suffix));
1291 /* Update all the value_table_ptr to point at the entry with the same
1292 * trailing partial OID */
1293 for (i = 0; i < data->values_len; i++)
1295 while ((value_table_ptr[i] != NULL)
1296 && (csnmp_oid_compare (&value_table_ptr[i]->suffix, ¤t_suffix) < 0))
1297 value_table_ptr[i] = value_table_ptr[i]->next;
1299 if (value_table_ptr[i] == NULL)
1304 else if (csnmp_oid_compare (&value_table_ptr[i]->suffix, ¤t_suffix) > 0)
1306 /* This suffix is missing in the subtree. Indicate this with the
1307 * "suffix_skipped" flag and try the next instance / suffix. */
1311 } /* for (i = 0; i < columns; i++) */
1316 /* Matching the values failed. Start from the beginning again. */
1319 if (instance_list != NULL)
1320 instance_list_ptr = instance_list_ptr->next;
1322 value_table_ptr[0] = value_table_ptr[0]->next;
1327 /* if we reach this line, all value_table_ptr[i] are non-NULL and are set
1328 * to the same subid. instance_list_ptr is either NULL or points to the
1329 * same subid, too. */
1331 for (i = 1; i < data->values_len; i++)
1333 assert (value_table_ptr[i] != NULL);
1334 assert (csnmp_oid_compare (&value_table_ptr[i-1]->suffix,
1335 &value_table_ptr[i]->suffix) == 0);
1337 assert ((instance_list_ptr == NULL)
1338 || (csnmp_oid_compare (&instance_list_ptr->suffix,
1339 &value_table_ptr[0]->suffix) == 0));
1342 sstrncpy (vl.type, data->type, sizeof (vl.type));
1345 char temp[DATA_MAX_NAME_LEN];
1347 if (instance_list_ptr == NULL)
1348 csnmp_oid_to_string (temp, sizeof (temp), ¤t_suffix);
1350 sstrncpy (temp, instance_list_ptr->instance, sizeof (temp));
1352 if (data->instance_prefix == NULL)
1353 sstrncpy (vl.type_instance, temp, sizeof (vl.type_instance));
1355 ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s%s",
1356 data->instance_prefix, temp);
1359 for (i = 0; i < data->values_len; i++)
1360 vl.values[i] = value_table_ptr[i]->value;
1362 /* If we get here `vl.type_instance' and all `vl.values' have been set
1363 * vl.type_instance can be empty, i.e. a blank port description on a
1364 * switch if you're using IF-MIB::ifDescr as Instance.
1366 if (vl.type_instance[0] != '\0')
1367 plugin_dispatch_values (&vl);
1369 if (instance_list != NULL)
1370 instance_list_ptr = instance_list_ptr->next;
1372 value_table_ptr[0] = value_table_ptr[0]->next;
1373 } /* while (have_more) */
1376 sfree (value_table_ptr);
1379 } /* int csnmp_dispatch_table */
1381 static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
1383 struct snmp_pdu *req;
1384 struct snmp_pdu *res = NULL;
1385 struct variable_list *vb;
1387 const data_set_t *ds;
1389 size_t oid_list_len = data->values_len + 1;
1390 /* Holds the last OID returned by the device. We use this in the GETNEXT
1391 * request to proceed. */
1392 oid_t oid_list[oid_list_len];
1393 /* Set to false when an OID has left its subtree so we don't re-request it
1395 _Bool oid_list_todo[oid_list_len];
1400 /* `value_list_head' and `value_list_tail' implement a linked list for each
1401 * value. `instance_list_head' and `instance_list_tail' implement a linked list of
1402 * instance names. This is used to jump gaps in the table. */
1403 csnmp_list_instances_t *instance_list_head;
1404 csnmp_list_instances_t *instance_list_tail;
1405 csnmp_table_values_t **value_list_head;
1406 csnmp_table_values_t **value_list_tail;
1408 DEBUG ("snmp plugin: csnmp_read_table (host = %s, data = %s)",
1409 host->name, data->name);
1411 if (host->sess_handle == NULL)
1413 DEBUG ("snmp plugin: csnmp_read_table: host->sess_handle == NULL");
1417 ds = plugin_get_ds (data->type);
1420 ERROR ("snmp plugin: DataSet `%s' not defined.", data->type);
1424 if (ds->ds_num != data->values_len)
1426 ERROR ("snmp plugin: DataSet `%s' requires %zu values, but config talks about %zu",
1427 data->type, ds->ds_num, data->values_len);
1430 assert (data->values_len > 0);
1432 /* We need a copy of all the OIDs, because GETNEXT will destroy them. */
1433 memcpy (oid_list, data->values, data->values_len * sizeof (oid_t));
1434 if (data->instance.oid.oid_len > 0)
1435 memcpy (oid_list + data->values_len, &data->instance.oid, sizeof (oid_t));
1436 else /* no InstanceFrom option specified. */
1439 for (i = 0; i < oid_list_len; i++)
1440 oid_list_todo[i] = 1;
1442 /* We're going to construct n linked lists, one for each "value".
1443 * value_list_head will contain pointers to the heads of these linked lists,
1444 * value_list_tail will contain pointers to the tail of the lists. */
1445 value_list_head = calloc (data->values_len, sizeof (*value_list_head));
1446 value_list_tail = calloc (data->values_len, sizeof (*value_list_tail));
1447 if ((value_list_head == NULL) || (value_list_tail == NULL))
1449 ERROR ("snmp plugin: csnmp_read_table: calloc failed.");
1450 sfree (value_list_head);
1451 sfree (value_list_tail);
1455 instance_list_head = NULL;
1456 instance_list_tail = NULL;
1461 int oid_list_todo_num;
1463 req = snmp_pdu_create (SNMP_MSG_GETNEXT);
1466 ERROR ("snmp plugin: snmp_pdu_create failed.");
1471 oid_list_todo_num = 0;
1472 for (i = 0; i < oid_list_len; i++)
1474 /* Do not rerequest already finished OIDs */
1475 if (!oid_list_todo[i])
1477 oid_list_todo_num++;
1478 snmp_add_null_var (req, oid_list[i].oid, oid_list[i].oid_len);
1481 if (oid_list_todo_num == 0)
1483 /* The request is still empty - so we are finished */
1484 DEBUG ("snmp plugin: all variables have left their subtree");
1490 status = snmp_sess_synch_response (host->sess_handle, req, &res);
1491 if ((status != STAT_SUCCESS) || (res == NULL))
1493 char *errstr = NULL;
1495 snmp_sess_error (host->sess_handle, NULL, NULL, &errstr);
1497 c_complain (LOG_ERR, &host->complaint,
1498 "snmp plugin: host %s: snmp_sess_synch_response failed: %s",
1499 host->name, (errstr == NULL) ? "Unknown problem" : errstr);
1502 snmp_free_pdu (res);
1505 /* snmp_synch_response already freed our PDU */
1508 csnmp_host_close_session (host);
1515 assert (res != NULL);
1516 c_release (LOG_INFO, &host->complaint,
1517 "snmp plugin: host %s: snmp_sess_synch_response successful.",
1520 vb = res->variables;
1527 for (vb = res->variables, i = 0; (vb != NULL); vb = vb->next_variable, i++)
1529 /* Calculate value index from todo list */
1530 while ((i < oid_list_len) && !oid_list_todo[i])
1533 /* An instance is configured and the res variable we process is the
1534 * instance value (last index) */
1535 if ((data->instance.oid.oid_len > 0) && (i == data->values_len))
1537 if ((vb->type == SNMP_ENDOFMIBVIEW)
1538 || (snmp_oid_ncompare (data->instance.oid.oid,
1539 data->instance.oid.oid_len,
1540 vb->name, vb->name_length,
1541 data->instance.oid.oid_len) != 0))
1543 DEBUG ("snmp plugin: host = %s; data = %s; Instance left its subtree.",
1544 host->name, data->name);
1545 oid_list_todo[i] = 0;
1549 /* Allocate a new `csnmp_list_instances_t', insert the instance name and
1550 * add it to the list */
1551 if (csnmp_instance_list_add (&instance_list_head, &instance_list_tail,
1552 res, host, data) != 0)
1554 ERROR ("snmp plugin: host %s: csnmp_instance_list_add failed.",
1560 else /* The variable we are processing is a normal value */
1562 csnmp_table_values_t *vt;
1567 csnmp_oid_init (&vb_name, vb->name, vb->name_length);
1569 /* Calculate the current suffix. This is later used to check that the
1570 * suffix is increasing. This also checks if we left the subtree */
1571 ret = csnmp_oid_suffix (&suffix, &vb_name, data->values + i);
1574 DEBUG ("snmp plugin: host = %s; data = %s; i = %zu; "
1575 "Value probably left its subtree.",
1576 host->name, data->name, i);
1577 oid_list_todo[i] = 0;
1581 /* Make sure the OIDs returned by the agent are increasing. Otherwise our
1582 * table matching algorithm will get confused. */
1583 if ((value_list_tail[i] != NULL)
1584 && (csnmp_oid_compare (&suffix, &value_list_tail[i]->suffix) <= 0))
1586 DEBUG ("snmp plugin: host = %s; data = %s; i = %zu; "
1587 "Suffix is not increasing.",
1588 host->name, data->name, i);
1589 oid_list_todo[i] = 0;
1593 vt = calloc (1, sizeof (*vt));
1596 ERROR ("snmp plugin: calloc failed.");
1601 vt->value = csnmp_value_list_to_value (vb, ds->ds[i].type,
1602 data->scale, data->shift, host->name, data->name);
1603 memcpy (&vt->suffix, &suffix, sizeof (vt->suffix));
1606 if (value_list_tail[i] == NULL)
1607 value_list_head[i] = vt;
1609 value_list_tail[i]->next = vt;
1610 value_list_tail[i] = vt;
1613 /* Copy OID to oid_list[i] */
1614 memcpy (oid_list[i].oid, vb->name, sizeof (oid) * vb->name_length);
1615 oid_list[i].oid_len = vb->name_length;
1617 } /* for (vb = res->variables ...) */
1620 snmp_free_pdu (res);
1622 } /* while (status == 0) */
1625 snmp_free_pdu (res);
1629 snmp_free_pdu (req);
1633 csnmp_dispatch_table (host, data, instance_list_head, value_list_head);
1635 /* Free all allocated variables here */
1636 while (instance_list_head != NULL)
1638 csnmp_list_instances_t *next = instance_list_head->next;
1639 sfree (instance_list_head);
1640 instance_list_head = next;
1643 for (i = 0; i < data->values_len; i++)
1645 while (value_list_head[i] != NULL)
1647 csnmp_table_values_t *next = value_list_head[i]->next;
1648 sfree (value_list_head[i]);
1649 value_list_head[i] = next;
1653 sfree (value_list_head);
1654 sfree (value_list_tail);
1657 } /* int csnmp_read_table */
1659 static int csnmp_read_value (host_definition_t *host, data_definition_t *data)
1661 struct snmp_pdu *req;
1662 struct snmp_pdu *res = NULL;
1663 struct variable_list *vb;
1665 const data_set_t *ds;
1666 value_list_t vl = VALUE_LIST_INIT;
1671 DEBUG ("snmp plugin: csnmp_read_value (host = %s, data = %s)",
1672 host->name, data->name);
1674 if (host->sess_handle == NULL)
1676 DEBUG ("snmp plugin: csnmp_read_value: host->sess_handle == NULL");
1680 ds = plugin_get_ds (data->type);
1683 ERROR ("snmp plugin: DataSet `%s' not defined.", data->type);
1687 if (ds->ds_num != data->values_len)
1689 ERROR ("snmp plugin: DataSet `%s' requires %zu values, but config talks about %zu",
1690 data->type, ds->ds_num, data->values_len);
1694 vl.values_len = ds->ds_num;
1695 vl.values = malloc (sizeof (*vl.values) * vl.values_len);
1696 if (vl.values == NULL)
1698 for (i = 0; i < vl.values_len; i++)
1700 if (ds->ds[i].type == DS_TYPE_COUNTER)
1701 vl.values[i].counter = 0;
1703 vl.values[i].gauge = NAN;
1706 sstrncpy (vl.host, host->name, sizeof (vl.host));
1707 sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin));
1708 sstrncpy (vl.type, data->type, sizeof (vl.type));
1709 sstrncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance));
1711 vl.interval = host->interval;
1713 req = snmp_pdu_create (SNMP_MSG_GET);
1716 ERROR ("snmp plugin: snmp_pdu_create failed.");
1721 for (i = 0; i < data->values_len; i++)
1722 snmp_add_null_var (req, data->values[i].oid, data->values[i].oid_len);
1724 status = snmp_sess_synch_response (host->sess_handle, req, &res);
1726 if ((status != STAT_SUCCESS) || (res == NULL))
1728 char *errstr = NULL;
1730 snmp_sess_error (host->sess_handle, NULL, NULL, &errstr);
1731 ERROR ("snmp plugin: host %s: snmp_sess_synch_response failed: %s",
1732 host->name, (errstr == NULL) ? "Unknown problem" : errstr);
1735 snmp_free_pdu (res);
1739 csnmp_host_close_session (host);
1745 for (vb = res->variables; vb != NULL; vb = vb->next_variable)
1749 snprint_variable (buffer, sizeof (buffer),
1750 vb->name, vb->name_length, vb);
1751 DEBUG ("snmp plugin: Got this variable: %s", buffer);
1752 #endif /* COLLECT_DEBUG */
1754 for (i = 0; i < data->values_len; i++)
1755 if (snmp_oid_compare (data->values[i].oid, data->values[i].oid_len,
1756 vb->name, vb->name_length) == 0)
1757 vl.values[i] = csnmp_value_list_to_value (vb, ds->ds[i].type,
1758 data->scale, data->shift, host->name, data->name);
1759 } /* for (res->variables) */
1761 snmp_free_pdu (res);
1763 DEBUG ("snmp plugin: -> plugin_dispatch_values (&vl);");
1764 plugin_dispatch_values (&vl);
1768 } /* int csnmp_read_value */
1770 static int csnmp_read_host (user_data_t *ud)
1772 host_definition_t *host;
1779 if (host->interval == 0)
1780 host->interval = plugin_get_interval ();
1782 if (host->sess_handle == NULL)
1783 csnmp_host_open_session (host);
1785 if (host->sess_handle == NULL)
1789 for (i = 0; i < host->data_list_len; i++)
1791 data_definition_t *data = host->data_list[i];
1794 status = csnmp_read_table (host, data);
1796 status = csnmp_read_value (host, data);
1806 } /* int csnmp_read_host */
1808 static int csnmp_init (void)
1810 call_snmp_init_once ();
1813 } /* int csnmp_init */
1815 static int csnmp_shutdown (void)
1817 data_definition_t *data_this;
1818 data_definition_t *data_next;
1820 /* When we get here, the read threads have been stopped and all the
1821 * `host_definition_t' will be freed. */
1822 DEBUG ("snmp plugin: Destroying all data definitions.");
1824 data_this = data_head;
1826 while (data_this != NULL)
1828 data_next = data_this->next;
1830 sfree (data_this->name);
1831 sfree (data_this->type);
1832 sfree (data_this->values);
1833 sfree (data_this->ignores);
1836 data_this = data_next;
1840 } /* int csnmp_shutdown */
1842 void module_register (void)
1844 plugin_register_complex_config ("snmp", csnmp_config);
1845 plugin_register_init ("snmp", csnmp_init);
1846 plugin_register_shutdown ("snmp", csnmp_shutdown);
1847 } /* void module_register */
1850 * vim: shiftwidth=2 softtabstop=2 tabstop=8 fdm=marker