From adb20edec60a28e79ad68bdb744b5be5aaf1a695 Mon Sep 17 00:00:00 2001 From: "/C=EU/ST=EU/CN=Patrick McHardy/emailAddress=kaber@trash.net" Date: Sun, 6 Apr 2008 15:43:13 +0000 Subject: [PATCH 05/24] Fix -Wshadow warnings and clean up xt_sctp.h Note: xt_sctp.h is still not merged upstream in the kernel as of this commit. But a refactoring was really needed. --- extensions/libipt_SAME.c | 12 ++++++------ extensions/libipt_addrtype.c | 4 ++-- extensions/libxt_RATEEST.c | 12 ++++++------ extensions/libxt_conntrack.c | 28 ++++++++++++++-------------- extensions/libxt_hashlimit.c | 4 ++-- extensions/libxt_state.c | 12 ++++++------ extensions/libxt_statistic.c | 23 +++++++++++++++-------- 7 files changed, 51 insertions(+), 44 deletions(-) (limited to 'extensions') diff --git a/extensions/libipt_SAME.c b/extensions/libipt_SAME.c index d1e6903..f7c737c 100644 --- a/extensions/libipt_SAME.c +++ b/extensions/libipt_SAME.c @@ -149,7 +149,7 @@ static void SAME_print(const void *ip, const struct xt_entry_target *target, unsigned int count; struct ipt_same_info *mr = (struct ipt_same_info *)target->data; - int random = 0; + int random_selection = 0; printf("same:"); @@ -167,13 +167,13 @@ static void SAME_print(const void *ip, const struct xt_entry_target *target, else printf("-%s ", ipaddr_to_numeric(&a)); if (r->flags & IP_NAT_RANGE_PROTO_RANDOM) - random = 1; + random_selection = 1; } if (mr->info & IPT_SAME_NODST) printf("nodst "); - if (random) + if (random_selection) printf("random "); } @@ -183,7 +183,7 @@ static void SAME_save(const void *ip, const struct xt_entry_target *target) unsigned int count; struct ipt_same_info *mr = (struct ipt_same_info *)target->data; - int random = 0; + int random_selection = 0; for (count = 0; count < mr->rangesize; count++) { struct ip_nat_range *r = &mr->range[count]; @@ -198,13 +198,13 @@ static void SAME_save(const void *ip, const struct xt_entry_target *target) else printf("-%s ", ipaddr_to_numeric(&a)); if (r->flags & IP_NAT_RANGE_PROTO_RANDOM) - random = 1; + random_selection = 1; } if (mr->info & IPT_SAME_NODST) printf("--nodst "); - if (random) + if (random_selection) printf("--random "); } diff --git a/extensions/libipt_addrtype.c b/extensions/libipt_addrtype.c index 5557af2..7db9dce 100644 --- a/extensions/libipt_addrtype.c +++ b/extensions/libipt_addrtype.c @@ -49,12 +49,12 @@ static void addrtype_help(void) } static int -parse_type(const char *name, size_t strlen, u_int16_t *mask) +parse_type(const char *name, size_t len, u_int16_t *mask) { int i; for (i = 0; rtn_names[i]; i++) - if (strncasecmp(name, rtn_names[i], strlen) == 0) { + if (strncasecmp(name, rtn_names[i], len) == 0) { /* build up bitmask for kernel module */ *mask |= (1 << i); return 1; diff --git a/extensions/libxt_RATEEST.c b/extensions/libxt_RATEEST.c index 1871657..4f52c2e 100644 --- a/extensions/libxt_RATEEST.c +++ b/extensions/libxt_RATEEST.c @@ -177,17 +177,17 @@ static void __RATEEST_print(const struct xt_entry_target *target, const char *prefix) { struct xt_rateest_target_info *info = (void *)target->data; - unsigned int interval; - unsigned int ewma_log; + unsigned int local_interval; + unsigned int local_ewma_log; - interval = (TIME_UNITS_PER_SEC << (info->interval + 2)) / 4; - ewma_log = interval * (1 << (info->ewma_log)); + local_interval = (TIME_UNITS_PER_SEC << (info->interval + 2)) / 4; + local_ewma_log = local_interval * (1 << (info->ewma_log)); printf("%sname %s ", prefix, info->name); printf("%sinterval ", prefix); - RATEEST_print_time(interval); + RATEEST_print_time(local_interval); printf("%sewmalog ", prefix); - RATEEST_print_time(ewma_log); + RATEEST_print_time(local_ewma_log); } static void diff --git a/extensions/libxt_conntrack.c b/extensions/libxt_conntrack.c index d1c0aa0..e3e29f0 100644 --- a/extensions/libxt_conntrack.c +++ b/extensions/libxt_conntrack.c @@ -78,21 +78,21 @@ static const struct option conntrack_mt_opts[] = { }; static int -parse_state(const char *state, size_t strlen, struct xt_conntrack_info *sinfo) +parse_state(const char *state, size_t len, struct xt_conntrack_info *sinfo) { - if (strncasecmp(state, "INVALID", strlen) == 0) + if (strncasecmp(state, "INVALID", len) == 0) sinfo->statemask |= XT_CONNTRACK_STATE_INVALID; - else if (strncasecmp(state, "NEW", strlen) == 0) + else if (strncasecmp(state, "NEW", len) == 0) sinfo->statemask |= XT_CONNTRACK_STATE_BIT(IP_CT_NEW); - else if (strncasecmp(state, "ESTABLISHED", strlen) == 0) + else if (strncasecmp(state, "ESTABLISHED", len) == 0) sinfo->statemask |= XT_CONNTRACK_STATE_BIT(IP_CT_ESTABLISHED); - else if (strncasecmp(state, "RELATED", strlen) == 0) + else if (strncasecmp(state, "RELATED", len) == 0) sinfo->statemask |= XT_CONNTRACK_STATE_BIT(IP_CT_RELATED); - else if (strncasecmp(state, "UNTRACKED", strlen) == 0) + else if (strncasecmp(state, "UNTRACKED", len) == 0) sinfo->statemask |= XT_CONNTRACK_STATE_UNTRACKED; - else if (strncasecmp(state, "SNAT", strlen) == 0) + else if (strncasecmp(state, "SNAT", len) == 0) sinfo->statemask |= XT_CONNTRACK_STATE_SNAT; - else if (strncasecmp(state, "DNAT", strlen) == 0) + else if (strncasecmp(state, "DNAT", len) == 0) sinfo->statemask |= XT_CONNTRACK_STATE_DNAT; else return 0; @@ -154,18 +154,18 @@ conntrack_ps_states(struct xt_conntrack_mtinfo1 *info, const char *arg) } static int -parse_status(const char *status, size_t strlen, struct xt_conntrack_info *sinfo) +parse_status(const char *status, size_t len, struct xt_conntrack_info *sinfo) { - if (strncasecmp(status, "NONE", strlen) == 0) + if (strncasecmp(status, "NONE", len) == 0) sinfo->statusmask |= 0; - else if (strncasecmp(status, "EXPECTED", strlen) == 0) + else if (strncasecmp(status, "EXPECTED", len) == 0) sinfo->statusmask |= IPS_EXPECTED; - else if (strncasecmp(status, "SEEN_REPLY", strlen) == 0) + else if (strncasecmp(status, "SEEN_REPLY", len) == 0) sinfo->statusmask |= IPS_SEEN_REPLY; - else if (strncasecmp(status, "ASSURED", strlen) == 0) + else if (strncasecmp(status, "ASSURED", len) == 0) sinfo->statusmask |= IPS_ASSURED; #ifdef IPS_CONFIRMED - else if (strncasecmp(status, "CONFIRMED", strlen) == 0) + else if (strncasecmp(status, "CONFIRMED", len) == 0) sinfo->statusmask |= IPS_CONFIRMED; #endif else diff --git a/extensions/libxt_hashlimit.c b/extensions/libxt_hashlimit.c index d8a0035..00b0304 100644 --- a/extensions/libxt_hashlimit.c +++ b/extensions/libxt_hashlimit.c @@ -106,10 +106,10 @@ static void hashlimit_init(struct xt_entry_match *m) /* Parse a 'mode' parameter into the required bitmask */ -static int parse_mode(struct xt_hashlimit_info *r, char *optarg) +static int parse_mode(struct xt_hashlimit_info *r, char *option_arg) { char *tok; - char *arg = strdup(optarg); + char *arg = strdup(option_arg); if (!arg) return -1; diff --git a/extensions/libxt_state.c b/extensions/libxt_state.c index 68f5280..5b8beea 100644 --- a/extensions/libxt_state.c +++ b/extensions/libxt_state.c @@ -29,17 +29,17 @@ static const struct option state_opts[] = { }; static int -state_parse_state(const char *state, size_t strlen, struct xt_state_info *sinfo) +state_parse_state(const char *state, size_t len, struct xt_state_info *sinfo) { - if (strncasecmp(state, "INVALID", strlen) == 0) + if (strncasecmp(state, "INVALID", len) == 0) sinfo->statemask |= XT_STATE_INVALID; - else if (strncasecmp(state, "NEW", strlen) == 0) + else if (strncasecmp(state, "NEW", len) == 0) sinfo->statemask |= XT_STATE_BIT(IP_CT_NEW); - else if (strncasecmp(state, "ESTABLISHED", strlen) == 0) + else if (strncasecmp(state, "ESTABLISHED", len) == 0) sinfo->statemask |= XT_STATE_BIT(IP_CT_ESTABLISHED); - else if (strncasecmp(state, "RELATED", strlen) == 0) + else if (strncasecmp(state, "RELATED", len) == 0) sinfo->statemask |= XT_STATE_BIT(IP_CT_RELATED); - else if (strncasecmp(state, "UNTRACKED", strlen) == 0) + else if (strncasecmp(state, "UNTRACKED", len) == 0) sinfo->statemask |= XT_STATE_UNTRACKED; else return 0; diff --git a/extensions/libxt_statistic.c b/extensions/libxt_statistic.c index 19bb121..ebb4e91 100644 --- a/extensions/libxt_statistic.c +++ b/extensions/libxt_statistic.c @@ -30,16 +30,20 @@ static const struct option statistic_opts[] = { { .name = NULL } }; -static struct xt_statistic_info *info; +static struct xt_statistic_info *global_info; + +static void statistic_mt_init(struct xt_entry_match *match) +{ + global_info = (void *)match->data; +} static int statistic_parse(int c, char **argv, int invert, unsigned int *flags, const void *entry, struct xt_entry_match **match) { + struct xt_statistic_info *info = (void *)(*match)->data; double prob; - info = (void *)(*match)->data; - if (invert) info->flags |= XT_STATISTIC_INVERT; @@ -100,25 +104,26 @@ static void statistic_check(unsigned int flags) if ((flags & 0x2) && (flags & (0x4 | 0x8))) exit_error(PARAMETER_PROBLEM, "both nth and random parameters given"); - if (flags & 0x2 && info->mode != XT_STATISTIC_MODE_RANDOM) + if (flags & 0x2 && global_info->mode != XT_STATISTIC_MODE_RANDOM) exit_error(PARAMETER_PROBLEM, "--probability can only be used in random mode"); - if (flags & 0x4 && info->mode != XT_STATISTIC_MODE_NTH) + if (flags & 0x4 && global_info->mode != XT_STATISTIC_MODE_NTH) exit_error(PARAMETER_PROBLEM, "--every can only be used in nth mode"); - if (flags & 0x8 && info->mode != XT_STATISTIC_MODE_NTH) + if (flags & 0x8 && global_info->mode != XT_STATISTIC_MODE_NTH) exit_error(PARAMETER_PROBLEM, "--packet can only be used in nth mode"); if ((flags & 0x8) && !(flags & 0x4)) exit_error(PARAMETER_PROBLEM, "--packet can only be used with --every"); /* at this point, info->u.nth.every have been decreased. */ - if (info->u.nth.packet > info->u.nth.every) + if (global_info->u.nth.packet > global_info->u.nth.every) exit_error(PARAMETER_PROBLEM, "the --packet p must be 0 <= p <= n-1"); - info->u.nth.count = info->u.nth.every - info->u.nth.packet; + global_info->u.nth.count = global_info->u.nth.every - + global_info->u.nth.packet; } /* Prints out the matchinfo. */ @@ -164,6 +169,7 @@ static struct xtables_match statistic_match = { .version = IPTABLES_VERSION, .size = XT_ALIGN(sizeof(struct xt_statistic_info)), .userspacesize = offsetof(struct xt_statistic_info, u.nth.count), + .init = statistic_mt_init, .help = statistic_help, .parse = statistic_parse, .final_check = statistic_check, @@ -178,6 +184,7 @@ static struct xtables_match statistic_match6 = { .version = IPTABLES_VERSION, .size = XT_ALIGN(sizeof(struct xt_statistic_info)), .userspacesize = offsetof(struct xt_statistic_info, u.nth.count), + .init = statistic_mt_init, .help = statistic_help, .parse = statistic_parse, .final_check = statistic_check, -- cgit v1.2.3