Merge branch 'collectd-5.7'
[collectd.git] / src / snmp_agent.c
index af22312..d1579bd 100644 (file)
@@ -3,15 +3,15 @@
  *
  * Copyright(c) 2017 Intel Corporation. All rights reserved.
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
  *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@@ -34,7 +34,9 @@
 #include "utils_llist.h"
 
 #include <net-snmp/net-snmp-config.h>
+
 #include <net-snmp/net-snmp-includes.h>
+
 #include <net-snmp/agent/net-snmp-agent-includes.h>
 
 #define PLUGIN_NAME "snmp_agent"
@@ -88,7 +90,7 @@ struct snmp_agent_ctx_s {
 };
 typedef struct snmp_agent_ctx_s snmp_agent_ctx_t;
 
-snmp_agent_ctx_t *g_agent = NULL;
+static snmp_agent_ctx_t *g_agent = NULL;
 
 #define CHECK_DD_TYPE(_dd, _p, _pi, _t, _ti)                                   \
   (_dd->plugin ? !strcmp(_dd->plugin, _p) : 0) &&                              \
@@ -106,13 +108,13 @@ static int snmp_agent_unregister_oid_index(oid_t *oid, int index);
 static u_char snmp_agent_get_asn_type(oid *oid, size_t oid_len) {
   struct tree *node = get_tree(oid, oid_len, g_agent->tp);
 
-  return (node != NULL ? mib_to_asn_type(node->type) : 0);
+  return (node != NULL) ? mib_to_asn_type(node->type) : 0;
 }
 
 static char *snmp_agent_get_oid_name(oid *oid, size_t oid_len) {
   struct tree *node = get_tree(oid, oid_len, g_agent->tp);
 
-  return (node != NULL ? node->label : NULL);
+  return (node != NULL) ? node->label : NULL;
 }
 
 static int snmp_agent_oid_to_string(char *buf, size_t buf_size,
@@ -125,7 +127,7 @@ static int snmp_agent_oid_to_string(char *buf, size_t buf_size,
     oid_str_ptr[i] = oid_str[i];
   }
 
-  return (strjoin(buf, buf_size, oid_str_ptr, o->oid_len, "."));
+  return strjoin(buf, buf_size, oid_str_ptr, o->oid_len, ".");
 }
 
 static void snmp_agent_dump_data(void) {
@@ -208,20 +210,20 @@ static int snmp_agent_validate_data(void) {
       if (!dd->plugin) {
         ERROR(PLUGIN_NAME ": Plugin not defined for '%s'.'%s'", td->name,
               dd->name);
-        return (-EINVAL);
+        return -EINVAL;
       }
 
       if (dd->plugin_instance) {
         ERROR(PLUGIN_NAME ": PluginInstance should not be defined for table "
                           "data type '%s'.'%s'",
               td->name, dd->name);
-        return (-EINVAL);
+        return -EINVAL;
       }
 
       if (dd->oids_len == 0) {
         ERROR(PLUGIN_NAME ": No OIDs defined for '%s'.'%s'", td->name,
               dd->name);
-        return (-EINVAL);
+        return -EINVAL;
       }
 
       if (dd->is_instance) {
@@ -230,7 +232,7 @@ static int snmp_agent_validate_data(void) {
           ERROR(PLUGIN_NAME ": Type and TypeInstance are not valid for "
                             "instance data '%s'.'%s'",
                 td->name, dd->name);
-          return (-EINVAL);
+          return -EINVAL;
         }
 
         if (dd->oids_len > 1) {
@@ -238,14 +240,14 @@ static int snmp_agent_validate_data(void) {
               PLUGIN_NAME
               ": Only one OID should be specified for instance data '%s'.'%s'",
               td->name, dd->name);
-          return (-EINVAL);
+          return -EINVAL;
         }
       } else {
 
         if (!dd->type) {
           ERROR(PLUGIN_NAME ": Type not defined for data '%s'.'%s'", td->name,
                 dd->name);
-          return (-EINVAL);
+          return -EINVAL;
         }
       }
     }
@@ -256,28 +258,28 @@ static int snmp_agent_validate_data(void) {
 
     if (!dd->plugin) {
       ERROR(PLUGIN_NAME ": Plugin not defined for '%s'", dd->name);
-      return (-EINVAL);
+      return -EINVAL;
     }
 
     if (dd->oids_len == 0) {
       ERROR(PLUGIN_NAME ": No OIDs defined for '%s'", dd->name);
-      return (-EINVAL);
+      return -EINVAL;
     }
 
     if (dd->is_instance) {
       ERROR(PLUGIN_NAME
             ": Instance flag can't be specified for scalar data '%s'",
             dd->name);
-      return (-EINVAL);
+      return -EINVAL;
     }
 
     if (!dd->type) {
       ERROR(PLUGIN_NAME ": Type not defined for data '%s'", dd->name);
-      return (-EINVAL);
+      return -EINVAL;
     }
   }
 
-  return (0);
+  return 0;
 }
 
 static void snmp_agent_generate_oid2string(oid_t *oid, int offset, char *key) {
@@ -298,7 +300,7 @@ static int snmp_agent_generate_string2oid(oid_t *oid, const char *key) {
     oid->oid[oid->oid_len++] = key[i];
     if (oid->oid_len >= MAX_OID_LEN) {
       ERROR(PLUGIN_NAME ": Conversion key string %s to OID failed", key);
-      return (-EINVAL);
+      return -EINVAL;
     }
   }
 
@@ -336,10 +338,10 @@ static int snmp_agent_table_row_remove(table_definition_t *td,
   if (td->index_oid.oid_len) {
     if ((c_avl_get(td->instance_index, instance, (void **)&index) != 0) ||
         (c_avl_get(td->index_instance, index, (void **)&ins) != 0))
-      return (0);
+      return 0;
   } else {
     if (c_avl_get(td->instance_index, instance, (void **)&ins) != 0)
-      return (0);
+      return 0;
   }
 
   pthread_mutex_lock(&g_agent->agentx_lock);
@@ -363,15 +365,12 @@ static int snmp_agent_table_row_remove(table_definition_t *td,
         (index != NULL) ? *index : -1, ins);
 
   notification_t n = {
-    .severity = NOTIF_WARNING,
-    .time = cdtime(),
-    .plugin = PLUGIN_NAME
-  };
+      .severity = NOTIF_WARNING, .time = cdtime(), .plugin = PLUGIN_NAME};
   sstrncpy(n.host, hostname_g, sizeof(n.host));
   sstrncpy(n.plugin_instance, ins, sizeof(n.plugin_instance));
   ssnprintf(n.message, sizeof(n.message),
             "Removed data row from table %s instance %s index %d", td->name,
-            ins,  (index != NULL) ? *index : -1);
+            ins, (index != NULL) ? *index : -1);
   plugin_dispatch_notification(&n);
 
   if (td->index_oid.oid_len) {
@@ -384,13 +383,13 @@ static int snmp_agent_table_row_remove(table_definition_t *td,
     sfree(ins);
   }
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_clear_missing(const value_list_t *vl,
                                     __attribute__((unused)) user_data_t *ud) {
   if (vl == NULL)
-    return (-EINVAL);
+    return -EINVAL;
 
   for (llentry_t *te = llist_head(g_agent->tables); te != NULL; te = te->next) {
     table_definition_t *td = te->value;
@@ -402,13 +401,13 @@ static int snmp_agent_clear_missing(const value_list_t *vl,
         if (CHECK_DD_TYPE(dd, vl->plugin, vl->plugin_instance, vl->type,
                           vl->type_instance)) {
           snmp_agent_table_row_remove(td, vl->plugin_instance);
-          return (0);
+          return 0;
         }
       }
     }
   }
 
-  return (0);
+  return 0;
 }
 
 static void snmp_agent_free_data(data_definition_t **dd) {
@@ -425,7 +424,8 @@ static void snmp_agent_free_data(data_definition_t **dd) {
     char *instance;
 
     c_avl_iterator_t *iter = c_avl_get_iterator((*dd)->table->instance_index);
-    while (c_avl_iterator_next(iter, (void *)&instance, (void *)&instance) == 0) {
+    while (c_avl_iterator_next(iter, (void *)&instance, (void *)&instance) ==
+           0) {
       for (int i = 0; i < (*dd)->oids_len; i++)
         snmp_agent_unregister_oid_string(&(*dd)->oids[i], instance);
     }
@@ -545,8 +545,8 @@ static int snmp_agent_form_reply(struct netsnmp_request_info_s *requests,
   }
 
   requests->requestvb->type = dd->oids[oid_index].type;
-  snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type, data,
-                           data_len);
+  snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type,
+                           (const u_char *)data, data_len);
 
   return SNMP_ERR_NOERROR;
 }
@@ -594,13 +594,12 @@ snmp_agent_table_oid_handler(struct netsnmp_mib_handler_s *handler,
           char key[MAX_OID_LEN];
 
           memset(key, 0, sizeof(key));
-          snmp_agent_generate_oid2string(&oid, MIN(oid.oid_len,
-                                         dd->oids[i].oid_len), key);
+          snmp_agent_generate_oid2string(
+              &oid, MIN(oid.oid_len, dd->oids[i].oid_len), key);
 
           ret = c_avl_get(td->instance_index, key, (void **)&instance);
           if (ret != 0) {
-            DEBUG(PLUGIN_NAME ": Nonexisting index string '%s' requested",
-                  key);
+            DEBUG(PLUGIN_NAME ": Nonexisting index string '%s' requested", key);
             pthread_mutex_unlock(&g_agent->lock);
             return SNMP_NOSUCHINSTANCE;
           }
@@ -618,7 +617,7 @@ snmp_agent_table_oid_handler(struct netsnmp_mib_handler_s *handler,
         if (dd->is_instance) {
           requests->requestvb->type = ASN_OCTET_STR;
           snmp_set_var_typed_value(requests->requestvb,
-                                   requests->requestvb->type, instance,
+                                   requests->requestvb->type, (const u_char *)instance,
                                    strlen((instance)));
 
           pthread_mutex_unlock(&g_agent->lock);
@@ -679,7 +678,7 @@ static int snmp_agent_table_index_oid_handler(
 
       requests->requestvb->type = ASN_INTEGER;
       snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type,
-                               &index, sizeof(index));
+                               (const u_char *)&index, sizeof(index));
 
       pthread_mutex_unlock(&g_agent->lock);
 
@@ -725,7 +724,7 @@ static int snmp_agent_table_size_oid_handler(
 
       requests->requestvb->type = td->size_oid.type;
       snmp_set_var_typed_value(requests->requestvb, requests->requestvb->type,
-                               &size, sizeof(size));
+                               (const u_char *)&size, sizeof(size));
 
       pthread_mutex_unlock(&g_agent->lock);
 
@@ -811,7 +810,7 @@ static int snmp_agent_register_table_oids(void) {
     }
   }
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_register_scalar_oids(void) {
@@ -831,20 +830,20 @@ static int snmp_agent_register_scalar_oids(void) {
     }
   }
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_config_data_oids(data_definition_t *dd,
                                        oconfig_item_t *ci) {
   if (ci->values_num < 1) {
     WARNING(PLUGIN_NAME ": `OIDs' needs at least one argument");
-    return (-EINVAL);
+    return -EINVAL;
   }
 
   for (int i = 0; i < ci->values_num; i++)
     if (ci->values[i].type != OCONFIG_TYPE_STRING) {
       WARNING(PLUGIN_NAME ": `OIDs' needs only string argument");
-      return (-EINVAL);
+      return -EINVAL;
     }
 
   if (dd->oids != NULL)
@@ -852,7 +851,7 @@ static int snmp_agent_config_data_oids(data_definition_t *dd,
   dd->oids_len = 0;
   dd->oids = calloc(ci->values_num, sizeof(*dd->oids));
   if (dd->oids == NULL)
-    return (-ENOMEM);
+    return -ENOMEM;
   dd->oids_len = (size_t)ci->values_num;
 
   for (int i = 0; i < ci->values_num; i++) {
@@ -864,23 +863,23 @@ static int snmp_agent_config_data_oids(data_definition_t *dd,
             ci->values[i].value.string);
       sfree(dd->oids);
       dd->oids_len = 0;
-      return (-1);
+      return -1;
     }
   }
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_config_table_size_oid(table_definition_t *td,
                                             oconfig_item_t *ci) {
   if (ci->values_num < 1) {
     WARNING(PLUGIN_NAME ": `TableSizeOID' is empty");
-    return (-EINVAL);
+    return -EINVAL;
   }
 
   if (ci->values[0].type != OCONFIG_TYPE_STRING) {
     WARNING(PLUGIN_NAME ": `TableSizeOID' needs only string argument");
-    return (-EINVAL);
+    return -EINVAL;
   }
 
   td->size_oid.oid_len = MAX_OID_LEN;
@@ -890,10 +889,10 @@ static int snmp_agent_config_table_size_oid(table_definition_t *td,
     ERROR(PLUGIN_NAME ": Failed to parse table size OID (%s)",
           ci->values[0].value.string);
     td->size_oid.oid_len = 0;
-    return (-EINVAL);
+    return -EINVAL;
   }
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_config_table_index_oid(table_definition_t *td,
@@ -901,12 +900,12 @@ static int snmp_agent_config_table_index_oid(table_definition_t *td,
 
   if (ci->values_num < 1) {
     WARNING(PLUGIN_NAME ": `IndexOID' is empty");
-    return (-EINVAL);
+    return -EINVAL;
   }
 
   if (ci->values[0].type != OCONFIG_TYPE_STRING) {
     WARNING(PLUGIN_NAME ": `IndexOID' needs only string argument");
-    return (-EINVAL);
+    return -EINVAL;
   }
 
   td->index_oid.oid_len = MAX_OID_LEN;
@@ -916,10 +915,10 @@ static int snmp_agent_config_table_index_oid(table_definition_t *td,
     ERROR(PLUGIN_NAME ": Failed to parse table index OID (%s)",
           ci->values[0].value.string);
     td->index_oid.oid_len = 0;
-    return (-EINVAL);
+    return -EINVAL;
   }
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_config_table_data(table_definition_t *td,
@@ -932,13 +931,13 @@ static int snmp_agent_config_table_data(table_definition_t *td,
   dd = calloc(1, sizeof(*dd));
   if (dd == NULL) {
     ERROR(PLUGIN_NAME ": Failed to allocate memory for table data definition");
-    return (-ENOMEM);
+    return -ENOMEM;
   }
 
   ret = cf_util_get_string(ci, &dd->name);
   if (ret != 0) {
     sfree(dd);
-    return (-1);
+    return -1;
   }
 
   dd->scale = 1.0;
@@ -972,19 +971,19 @@ static int snmp_agent_config_table_data(table_definition_t *td,
 
     if (ret != 0) {
       snmp_agent_free_data(&dd);
-      return (-1);
+      return -1;
     }
   }
 
   llentry_t *entry = llentry_create(dd->name, dd);
   if (entry == NULL) {
     snmp_agent_free_data(&dd);
-    return (-ENOMEM);
+    return -ENOMEM;
   }
 
   llist_append(td->columns, entry);
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_config_data(oconfig_item_t *ci) {
@@ -996,13 +995,13 @@ static int snmp_agent_config_data(oconfig_item_t *ci) {
   dd = calloc(1, sizeof(*dd));
   if (dd == NULL) {
     ERROR(PLUGIN_NAME ": Failed to allocate memory for data definition");
-    return (-ENOMEM);
+    return -ENOMEM;
   }
 
   ret = cf_util_get_string(ci, &dd->name);
   if (ret != 0) {
     free(dd);
-    return (-1);
+    return -1;
   }
 
   dd->scale = 1.0;
@@ -1034,29 +1033,29 @@ static int snmp_agent_config_data(oconfig_item_t *ci) {
 
     if (ret != 0) {
       snmp_agent_free_data(&dd);
-      return (-1);
+      return -1;
     }
   }
 
   llentry_t *entry = llentry_create(dd->name, dd);
   if (entry == NULL) {
     snmp_agent_free_data(&dd);
-    return (-ENOMEM);
+    return -ENOMEM;
   }
 
   llist_append(g_agent->scalars, entry);
 
-  return (0);
+  return 0;
 }
 
 static int num_compare(const int *a, const int *b) {
   assert((a != NULL) && (b != NULL));
   if (*a < *b)
-    return (-1);
+    return -1;
   else if (*a > *b)
-    return (1);
+    return 1;
   else
-    return (0);
+    return 0;
 }
 
 static int snmp_agent_config_table(oconfig_item_t *ci) {
@@ -1068,20 +1067,20 @@ static int snmp_agent_config_table(oconfig_item_t *ci) {
   td = calloc(1, sizeof(*td));
   if (td == NULL) {
     ERROR(PLUGIN_NAME ": Failed to allocate memory for table definition");
-    return (-ENOMEM);
+    return -ENOMEM;
   }
 
   ret = cf_util_get_string(ci, &td->name);
   if (ret != 0) {
     sfree(td);
-    return (-1);
+    return -1;
   }
 
   td->columns = llist_create();
   if (td->columns == NULL) {
     ERROR(PLUGIN_NAME ": Failed to allocate memory for columns list");
     snmp_agent_free_table(&td);
-    return (-ENOMEM);
+    return -ENOMEM;
   }
 
   for (int i = 0; i < ci->children_num; i++) {
@@ -1100,33 +1099,33 @@ static int snmp_agent_config_table(oconfig_item_t *ci) {
 
     if (ret != 0) {
       snmp_agent_free_table(&td);
-      return (-ENOMEM);
+      return -ENOMEM;
     }
   }
 
   llentry_t *entry = llentry_create(td->name, td);
   if (entry == NULL) {
     snmp_agent_free_table(&td);
-    return (-ENOMEM);
+    return -ENOMEM;
   }
 
   td->instance_index =
       c_avl_create((int (*)(const void *, const void *))strcmp);
   if (td->instance_index == NULL) {
     snmp_agent_free_table(&td);
-    return (-ENOMEM);
+    return -ENOMEM;
   }
 
   td->index_instance =
       c_avl_create((int (*)(const void *, const void *))num_compare);
   if (td->index_instance == NULL) {
     snmp_agent_free_table(&td);
-    return (-ENOMEM);
+    return -ENOMEM;
   }
 
   llist_append(g_agent->tables, entry);
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_get_value_from_ds_type(const value_t *val, int type,
@@ -1149,10 +1148,10 @@ static int snmp_agent_get_value_from_ds_type(const value_t *val, int type,
     break;
   default:
     ERROR(PLUGIN_NAME ": Unknown data source type: %i", type);
-    return (-EINVAL);
+    return -EINVAL;
   }
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_set_vardata(void *data, size_t *data_len, u_char asn_type,
@@ -1178,13 +1177,13 @@ static int snmp_agent_set_vardata(void *data, size_t *data_len, u_char asn_type,
   case ASN_TIMETICKS:
   case ASN_GAUGE:
     if (*data_len < sizeof(*var.integer))
-      return (-EINVAL);
+      return -EINVAL;
     *var.integer = new_value;
     *data_len = sizeof(*var.integer);
     break;
   case ASN_COUNTER64:
     if (*data_len < sizeof(*var.counter64))
-      return (-EINVAL);
+      return -EINVAL;
     var.counter64->high = (u_long)((int64_t)new_value >> 32);
     var.counter64->low = (u_long)((int64_t)new_value & 0xFFFFFFFF);
     *data_len = sizeof(*var.counter64);
@@ -1194,22 +1193,22 @@ static int snmp_agent_set_vardata(void *data, size_t *data_len, u_char asn_type,
       char buf[DATA_MAX_NAME_LEN];
       snprintf(buf, sizeof(buf), "%.2f", val->gauge);
       if (*data_len < strlen(buf))
-        return (-EINVAL);
+        return -EINVAL;
       *data_len = strlen(buf);
       memcpy(var.string, buf, *data_len);
     } else {
       ERROR(PLUGIN_NAME ": Failed to convert %d ds type to %d asn type", type,
             asn_type);
-      return (-EINVAL);
+      return -EINVAL;
     }
     break;
   default:
     ERROR(PLUGIN_NAME ": Failed to convert %d ds type to %d asn type", type,
           asn_type);
-    return (-EINVAL);
+    return -EINVAL;
   }
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_register_oid_index(oid_t *oid, int index,
@@ -1231,7 +1230,7 @@ static int snmp_agent_update_index(table_definition_t *td,
                                    const char *instance) {
 
   if (c_avl_get(td->instance_index, instance, NULL) == 0)
-    return (0);
+    return 0;
 
   int ret;
   int *index = NULL;
@@ -1239,14 +1238,14 @@ static int snmp_agent_update_index(table_definition_t *td,
 
   ins = strdup(instance);
   if (ins == NULL)
-    return (-ENOMEM);
+    return -ENOMEM;
 
   /* need to generate index for the table */
   if (td->index_oid.oid_len) {
     index = calloc(1, sizeof(*index));
     if (index == NULL) {
       sfree(ins);
-      return (-ENOMEM);
+      return -ENOMEM;
     }
 
     *index = c_avl_size(td->instance_index) + 1;
@@ -1291,7 +1290,7 @@ static int snmp_agent_update_index(table_definition_t *td,
                                             snmp_agent_table_oid_handler);
       } else {
         ret = snmp_agent_register_oid_string(&dd->oids[i], ins,
-                                            snmp_agent_table_oid_handler);
+                                             snmp_agent_table_oid_handler);
       }
 
       if (ret != 0)
@@ -1303,10 +1302,7 @@ static int snmp_agent_update_index(table_definition_t *td,
         (index != NULL) ? *index : -1, ins);
 
   notification_t n = {
-    .severity = NOTIF_OKAY,
-    .time = cdtime(),
-    .plugin = PLUGIN_NAME
-  };
+      .severity = NOTIF_OKAY, .time = cdtime(), .plugin = PLUGIN_NAME};
   sstrncpy(n.host, hostname_g, sizeof(n.host));
   sstrncpy(n.plugin_instance, ins, sizeof(n.plugin_instance));
   ssnprintf(n.message, sizeof(n.message),
@@ -1314,13 +1310,13 @@ static int snmp_agent_update_index(table_definition_t *td,
             (index != NULL) ? *index : -1);
   plugin_dispatch_notification(&n);
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_write(value_list_t const *vl) {
 
   if (vl == NULL)
-    return (-EINVAL);
+    return -EINVAL;
 
   for (llentry_t *te = llist_head(g_agent->tables); te != NULL; te = te->next) {
     table_definition_t *td = te->value;
@@ -1332,13 +1328,13 @@ static int snmp_agent_write(value_list_t const *vl) {
         if (CHECK_DD_TYPE(dd, vl->plugin, vl->plugin_instance, vl->type,
                           vl->type_instance)) {
           snmp_agent_update_index(td, vl->plugin_instance);
-          return (0);
+          return 0;
         }
       }
     }
   }
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_collect(const data_set_t *ds, const value_list_t *vl,
@@ -1350,19 +1346,19 @@ static int snmp_agent_collect(const data_set_t *ds, const value_list_t *vl,
 
   pthread_mutex_unlock(&g_agent->lock);
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_preinit(void) {
   if (g_agent != NULL) {
     /* already initialized if config callback was called before init callback */
-    return (0);
+    return 0;
   }
 
   g_agent = calloc(1, sizeof(*g_agent));
   if (g_agent == NULL) {
     ERROR(PLUGIN_NAME ": Failed to allocate memory for snmp agent context");
-    return (-ENOMEM);
+    return -ENOMEM;
   }
 
   g_agent->tables = llist_create();
@@ -1374,7 +1370,7 @@ static int snmp_agent_preinit(void) {
                                1);
   if (err != 0) {
     ERROR(PLUGIN_NAME ": Failed to set agent role (%d)", err);
-    return (-1);
+    return -1;
   }
 
   /*
@@ -1385,14 +1381,14 @@ static int snmp_agent_preinit(void) {
   err = init_agent(PLUGIN_NAME);
   if (err != 0) {
     ERROR(PLUGIN_NAME ": Failed to initialize the agent library (%d)", err);
-    return (-1);
+    return -1;
   }
 
   init_snmp(PLUGIN_NAME);
 
   g_agent->tp = read_all_mibs();
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_init(void) {
@@ -1429,7 +1425,7 @@ static int snmp_agent_init(void) {
     return ret;
   }
 
-  return (0);
+  return 0;
 }
 
 static void *snmp_agent_thread_run(void __attribute__((unused)) * arg) {
@@ -1460,7 +1456,7 @@ static int snmp_agent_register_oid(oid_t *oid, Netsnmp_Node_Handler *handler) {
     WARNING(PLUGIN_NAME
             ": Skipped registration: OID (%s) is not found in main tree",
             oid_str);
-    return (0);
+    return 0;
   }
 
   reg = netsnmp_create_handler_registration(oid_name, handler, oid->oid,
@@ -1468,7 +1464,7 @@ static int snmp_agent_register_oid(oid_t *oid, Netsnmp_Node_Handler *handler) {
   if (reg == NULL) {
     ERROR(PLUGIN_NAME ": Failed to create handler registration for OID (%s)",
           oid_str);
-    return (-1);
+    return -1;
   }
 
   pthread_mutex_lock(&g_agent->agentx_lock);
@@ -1476,20 +1472,20 @@ static int snmp_agent_register_oid(oid_t *oid, Netsnmp_Node_Handler *handler) {
   if (netsnmp_register_instance(reg) != MIB_REGISTERED_OK) {
     ERROR(PLUGIN_NAME ": Failed to register handler for OID (%s)", oid_str);
     pthread_mutex_unlock(&g_agent->agentx_lock);
-    return (-1);
+    return -1;
   }
 
   pthread_mutex_unlock(&g_agent->agentx_lock);
 
   DEBUG(PLUGIN_NAME ": Registered handler for OID (%s)", oid_str);
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_free_config(void) {
 
   if (g_agent == NULL)
-    return (-EINVAL);
+    return -EINVAL;
 
   for (llentry_t *te = llist_head(g_agent->tables); te != NULL; te = te->next)
     snmp_agent_free_table((table_definition_t **)&te->value);
@@ -1499,7 +1495,7 @@ static int snmp_agent_free_config(void) {
     snmp_agent_free_data((data_definition_t **)&de->value);
   llist_destroy(g_agent->scalars);
 
-  return (0);
+  return 0;
 }
 
 static int snmp_agent_shutdown(void) {
@@ -1509,7 +1505,7 @@ static int snmp_agent_shutdown(void) {
 
   if (g_agent == NULL) {
     ERROR(PLUGIN_NAME ": snmp_agent_shutdown: plugin not initialized");
-    return (-EINVAL);
+    return -EINVAL;
   }
 
   if (pthread_cancel(g_agent->thread) != 0)
@@ -1536,7 +1532,7 @@ static int snmp_agent_config(oconfig_item_t *ci) {
 
   if (ret != 0) {
     sfree(g_agent);
-    return (-EINVAL);
+    return -EINVAL;
   }
 
   for (int i = 0; i < ci->children_num; i++) {
@@ -1555,7 +1551,7 @@ static int snmp_agent_config(oconfig_item_t *ci) {
       snmp_agent_free_config();
       snmp_shutdown(PLUGIN_NAME);
       sfree(g_agent);
-      return (-EINVAL);
+      return -EINVAL;
     }
   }
 
@@ -1565,10 +1561,10 @@ static int snmp_agent_config(oconfig_item_t *ci) {
     snmp_agent_free_config();
     snmp_shutdown(PLUGIN_NAME);
     sfree(g_agent);
-    return (-EINVAL);
+    return -EINVAL;
   }
 
-  return (0);
+  return 0;
 }
 
 void module_register(void) {