X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fiptables.c;h=1d127bf7c6a2b55872489bcabdfaa84c79ccc535;hb=47c86ace348a1d7a5352a83d10935209f89aa4f5;hp=f35b5d69d948e58c9bdaa984589d126849f93e8b;hpb=79963d13c1884d1d92667cc502ad20758b084a12;p=collectd.git diff --git a/src/iptables.c b/src/iptables.c index f35b5d69..1d127bf7 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -98,7 +98,7 @@ 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; @@ -115,7 +115,7 @@ static int iptables_config(const char *key, const char *value) { if (value_copy == NULL) { char errbuf[1024]; ERROR("strdup failed: %s", sstrerror(errno, errbuf, sizeof(errbuf))); - return (1); + return 1; } /* @@ -131,7 +131,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 +141,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 +149,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 +164,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; } @@ -185,7 +185,7 @@ static int iptables_config(const char *key, const char *value) { char errbuf[1024]; ERROR("realloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf))); sfree(temp.rule.comment); - return (1); + return 1; } chain_list = list; @@ -194,7 +194,7 @@ static int iptables_config(const char *key, const char *value) { char errbuf[1024]; ERROR("malloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf))); sfree(temp.rule.comment); - return (1); + return 1; } memcpy(final, &temp, sizeof(temp)); chain_list[chain_num] = final; @@ -203,37 +203,33 @@ 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, const struct ip6t_entry *entry, const ip_chain_t *chain, int rule_num) { int status; - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; /* 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; } - vl.values = values; - vl.values_len = 1; - sstrncpy(vl.host, hostname_g, sizeof(vl.host)); sstrncpy(vl.plugin, "ip6tables", sizeof(vl.plugin)); status = ssnprintf(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)); @@ -246,45 +242,42 @@ static int submit6_match(const struct ip6t_entry_match *match, } sstrncpy(vl.type, "ipt_bytes", sizeof(vl.type)); - values[0].derive = (derive_t)entry->counters.bcnt; + vl.values = &(value_t){.derive = (derive_t)entry->counters.bcnt}; + vl.values_len = 1; plugin_dispatch_values(&vl); sstrncpy(vl.type, "ipt_packets", sizeof(vl.type)); - values[0].derive = (derive_t)entry->counters.pcnt; + vl.values = &(value_t){.derive = (derive_t)entry->counters.pcnt}; plugin_dispatch_values(&vl); - return (0); -} /* int submit_match */ + return 0; +} /* int submit6_match */ /* This needs to return `int' for IPT_MATCH_ITERATE to work. */ static int submit_match(const struct ipt_entry_match *match, const struct ipt_entry *entry, const ip_chain_t *chain, int rule_num) { int status; - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; /* 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; } - vl.values = values; - vl.values_len = 1; - sstrncpy(vl.host, hostname_g, sizeof(vl.host)); sstrncpy(vl.plugin, "iptables", sizeof(vl.plugin)); status = ssnprintf(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)); @@ -297,14 +290,15 @@ static int submit_match(const struct ipt_entry_match *match, } sstrncpy(vl.type, "ipt_bytes", sizeof(vl.type)); - values[0].derive = (derive_t)entry->counters.bcnt; + vl.values = &(value_t){.derive = (derive_t)entry->counters.bcnt}; + vl.values_len = 1; plugin_dispatch_values(&vl); sstrncpy(vl.type, "ipt_packets", sizeof(vl.type)); - values[0].derive = (derive_t)entry->counters.pcnt; + vl.values = &(value_t){.derive = (derive_t)entry->counters.pcnt}; plugin_dispatch_values(&vl); - return (0); + return 0; } /* int submit_match */ /* ipv6 submit_chain */ @@ -413,7 +407,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) { @@ -424,7 +418,7 @@ static int iptables_shutdown(void) { } sfree(chain_list); - return (0); + return 0; } /* int iptables_shutdown */ static int iptables_init(void) { @@ -441,7 +435,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) {