X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fiptables.c;h=8fad588e85120c9bf78d86e0ccf29b3b3ec6092b;hp=bf17cfbdd98ebc3fa30dac9b084bf64cff4cbca5;hb=ec51ddee94fa2ba1e01fe0e336ccc9c190a198ff;hpb=877672d20fcf0ed25f5fc5faa8aa3964c622bc27 diff --git a/src/iptables.c b/src/iptables.c index bf17cfbd..8fad588e 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -86,8 +86,8 @@ typedef struct { char name[64]; } ip_chain_t; -static ip_chain_t **chain_list = NULL; -static int chain_num = 0; +static ip_chain_t **chain_list; +static int chain_num; static int iptables_config(const char *key, const char *value) { /* int ip_value; */ @@ -98,10 +98,10 @@ static int iptables_config(const char *key, const char *value) { else if (strcasecmp(key, "Chain6") == 0) ip_version = IPV6; else - return (1); + return 1; ip_chain_t temp = {0}; - ip_chain_t * final, **list; + ip_chain_t *final, **list; char *table; int table_len; char *chain; @@ -113,9 +113,8 @@ static int iptables_config(const char *key, const char *value) { value_copy = strdup(value); if (value_copy == NULL) { - char errbuf[1024]; - ERROR("strdup failed: %s", sstrerror(errno, errbuf, sizeof(errbuf))); - return (1); + ERROR("strdup failed: %s", STRERRNO); + return 1; } /* @@ -131,7 +130,7 @@ static int iptables_config(const char *key, const char *value) { fields_num = strsplit(value_copy, fields, 4); if (fields_num < 2) { free(value_copy); - return (1); + return 1; } table = fields[0]; @@ -141,7 +140,7 @@ static int iptables_config(const char *key, const char *value) { if ((unsigned int)table_len > sizeof(temp.table)) { ERROR("Table `%s' too long.", table); free(value_copy); - return (1); + return 1; } sstrncpy(temp.table, table, table_len); @@ -149,7 +148,7 @@ static int iptables_config(const char *key, const char *value) { if ((unsigned int)chain_len > sizeof(temp.chain)) { ERROR("Chain `%s' too long.", chain); free(value_copy); - return (1); + return 1; } sstrncpy(temp.chain, chain, chain_len); @@ -164,7 +163,7 @@ static int iptables_config(const char *key, const char *value) { temp.rule.comment = strdup(comment); if (temp.rule.comment == NULL) { free(value_copy); - return (1); + return 1; } temp.rule_type = RTYPE_COMMENT; } @@ -182,19 +181,17 @@ static int iptables_config(const char *key, const char *value) { list = realloc(chain_list, (chain_num + 1) * sizeof(ip_chain_t *)); if (list == NULL) { - char errbuf[1024]; - ERROR("realloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf))); + ERROR("realloc failed: %s", STRERRNO); sfree(temp.rule.comment); - return (1); + return 1; } chain_list = list; - final = malloc(sizeof(* final)); + final = malloc(sizeof(*final)); if (final == NULL) { - char errbuf[1024]; - ERROR("malloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf))); + ERROR("malloc failed: %s", STRERRNO); sfree(temp.rule.comment); - return (1); + return 1; } memcpy(final, &temp, sizeof(temp)); chain_list[chain_num] = final; @@ -203,7 +200,7 @@ static int iptables_config(const char *key, const char *value) { DEBUG("Chain #%i: table = %s; chain = %s;", chain_num, final->table, final->chain); - return (0); + return 0; } /* int iptables_config */ static int submit6_match(const struct ip6t_entry_match *match, @@ -215,28 +212,28 @@ static int submit6_match(const struct ip6t_entry_match *match, /* Select the rules to collect */ if (chain->rule_type == RTYPE_NUM) { if (chain->rule.num != rule_num) - return (0); + return 0; } else { if (strcmp(match->u.user.name, "comment") != 0) - return (0); + return 0; if ((chain->rule_type == RTYPE_COMMENT) && (strcmp(chain->rule.comment, (char *)match->data) != 0)) - return (0); + return 0; } sstrncpy(vl.plugin, "ip6tables", sizeof(vl.plugin)); - status = ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s", - chain->table, chain->chain); + status = snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s", + chain->table, chain->chain); if ((status < 1) || ((unsigned int)status >= sizeof(vl.plugin_instance))) - return (0); + return 0; if (chain->name[0] != '\0') { sstrncpy(vl.type_instance, chain->name, sizeof(vl.type_instance)); } else { if (chain->rule_type == RTYPE_NUM) - ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%i", - chain->rule.num); + snprintf(vl.type_instance, sizeof(vl.type_instance), "%i", + chain->rule.num); else sstrncpy(vl.type_instance, (char *)match->data, sizeof(vl.type_instance)); } @@ -250,7 +247,7 @@ static int submit6_match(const struct ip6t_entry_match *match, vl.values = &(value_t){.derive = (derive_t)entry->counters.pcnt}; plugin_dispatch_values(&vl); - return (0); + return 0; } /* int submit6_match */ /* This needs to return `int' for IPT_MATCH_ITERATE to work. */ @@ -263,28 +260,28 @@ static int submit_match(const struct ipt_entry_match *match, /* Select the rules to collect */ if (chain->rule_type == RTYPE_NUM) { if (chain->rule.num != rule_num) - return (0); + return 0; } else { if (strcmp(match->u.user.name, "comment") != 0) - return (0); + return 0; if ((chain->rule_type == RTYPE_COMMENT) && (strcmp(chain->rule.comment, (char *)match->data) != 0)) - return (0); + return 0; } sstrncpy(vl.plugin, "iptables", sizeof(vl.plugin)); - status = ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s", - chain->table, chain->chain); + status = snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s", + chain->table, chain->chain); if ((status < 1) || ((unsigned int)status >= sizeof(vl.plugin_instance))) - return (0); + return 0; if (chain->name[0] != '\0') { sstrncpy(vl.type_instance, chain->name, sizeof(vl.type_instance)); } else { if (chain->rule_type == RTYPE_NUM) - ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%i", - chain->rule.num); + snprintf(vl.type_instance, sizeof(vl.type_instance), "%i", + chain->rule.num); else sstrncpy(vl.type_instance, (char *)match->data, sizeof(vl.type_instance)); } @@ -298,7 +295,7 @@ static int submit_match(const struct ipt_entry_match *match, vl.values = &(value_t){.derive = (derive_t)entry->counters.pcnt}; plugin_dispatch_values(&vl); - return (0); + return 0; } /* int submit_match */ /* ipv6 submit_chain */ @@ -407,7 +404,7 @@ static int iptables_read(void) { num_failures++; } /* for (i = 0 .. chain_num) */ - return ((num_failures < chain_num) ? 0 : -1); + return (num_failures < chain_num) ? 0 : -1; } /* int iptables_read */ static int iptables_shutdown(void) { @@ -418,7 +415,7 @@ static int iptables_shutdown(void) { } sfree(chain_list); - return (0); + return 0; } /* int iptables_shutdown */ static int iptables_init(void) { @@ -435,7 +432,7 @@ static int iptables_init(void) { "running \"setcap cap_net_admin=ep\" on the collectd binary."); } #endif - return (0); + return 0; } /* int iptables_init */ void module_register(void) {