From ba9a3efec1ad7afff19dc6f17137d8e1ee7f5ce7 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Sat, 3 Oct 2009 01:05:12 +0200 Subject: [PATCH] pknock: use preincrements where possible Preincrements are much less error-prone and even do not need extra parentheses. --- extensions/libxt_pknock.c | 6 +++--- extensions/xt_pknock.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/extensions/libxt_pknock.c b/extensions/libxt_pknock.c index d750944..149a43a 100644 --- a/extensions/libxt_pknock.c +++ b/extensions/libxt_pknock.c @@ -64,7 +64,7 @@ parse_ports(const char *portstring, uint16_t *ports, const char *proto) if (buffer == NULL) xtables_error(OTHER_PROBLEM, "strdup failed"); - for (cp=buffer, i=0; cp != NULL && ioption & XT_PKNOCK_KNOCKPORT) { printf("knockports "); - for (i=0; iports_count; i++) + for (i = 0; i < info->ports_count; ++i) printf("%s%d", i ? "," : "", info->port[i]); printf(" "); } @@ -314,7 +314,7 @@ static void pknock_save(const void *ip, const struct xt_entry_match *match) if (info->option & XT_PKNOCK_KNOCKPORT) { printf("--knockports "); - for (i=0; iports_count; i++) + for (i = 0; i < info->ports_count; ++i) printf("%s%d", i ? "," : "", info->port[i]); printf(" "); } diff --git a/extensions/xt_pknock.c b/extensions/xt_pknock.c index f6706d4..6949908 100644 --- a/extensions/xt_pknock.c +++ b/extensions/xt_pknock.c @@ -96,7 +96,7 @@ enum { }; #define hashtable_for_each_safe(pos, n, head, size, i) \ - for ((i) = 0; (i) < (size); (i)++) \ + for ((i) = 0; (i) < (size); ++(i)) \ list_for_each_safe((pos), (n), (&head[(i)])) #define pk_debug(msg, peer) pr_debug( \ @@ -176,7 +176,7 @@ alloc_hashtable(unsigned int size) return NULL; } - for (i = 0; i < size; i++) + for (i = 0; i < size; ++i) INIT_LIST_HEAD(&hash[i]); return hash; @@ -230,7 +230,7 @@ pknock_seq_next(struct seq_file *s, void *v, loff_t *pos) const struct proc_dir_entry *pde = s->private; const struct xt_pknock_rule *rule = pde->data; - (*pos)++; + ++*pos; if (*pos >= peer_hashsize) return NULL; @@ -432,7 +432,7 @@ add_rule(struct xt_pknock_mtinfo *info) rule = list_entry(pos, struct xt_pknock_rule, head); if (rulecmp(info, rule)) { - rule->ref_count++; + ++rule->ref_count; if (info->option & XT_PKNOCK_CHECKIP) { pr_debug("add_rule() (AC)" " rule found: %s - " @@ -720,7 +720,7 @@ static void crypt_to_hex(char *out, const char *crypt, unsigned int size) { unsigned int i; - for (i=0; i < size; i++) { + for (i = 0; i < size; ++i) { unsigned char c = crypt[i]; *out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1); *out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1); @@ -879,7 +879,7 @@ update_peer(struct peer *peer, const struct xt_pknock_mtinfo *info, /* Just update the timer when there is a state change. */ update_rule_timer(rule); - peer->id_port_knocked++; + ++peer->id_port_knocked; if (is_last_knock(peer, info)) { peer->status = ST_ALLOWED;