pknock: use preincrements where possible

Preincrements are much less error-prone and even do not need extra
parentheses.
This commit is contained in:
Jan Engelhardt
2009-10-03 01:05:12 +02:00
parent f474c7d4d4
commit ba9a3efec1
2 changed files with 9 additions and 9 deletions

View File

@@ -64,7 +64,7 @@ parse_ports(const char *portstring, uint16_t *ports, const char *proto)
if (buffer == NULL) if (buffer == NULL)
xtables_error(OTHER_PROBLEM, "strdup failed"); xtables_error(OTHER_PROBLEM, "strdup failed");
for (cp=buffer, i=0; cp != NULL && i<XT_PKNOCK_MAX_PORTS; cp=next, i++) for (cp = buffer, i = 0; cp != NULL && i < XT_PKNOCK_MAX_PORTS; cp = next, ++i)
{ {
next=strchr(cp, ','); next=strchr(cp, ',');
if (next != NULL) if (next != NULL)
@@ -292,7 +292,7 @@ static void pknock_print(const void *ip,
printf("pknock "); printf("pknock ");
if (info->option & XT_PKNOCK_KNOCKPORT) { if (info->option & XT_PKNOCK_KNOCKPORT) {
printf("knockports "); printf("knockports ");
for (i=0; i<info->ports_count; i++) for (i = 0; i < info->ports_count; ++i)
printf("%s%d", i ? "," : "", info->port[i]); printf("%s%d", i ? "," : "", info->port[i]);
printf(" "); printf(" ");
} }
@@ -314,7 +314,7 @@ static void pknock_save(const void *ip, const struct xt_entry_match *match)
if (info->option & XT_PKNOCK_KNOCKPORT) { if (info->option & XT_PKNOCK_KNOCKPORT) {
printf("--knockports "); printf("--knockports ");
for (i=0; i<info->ports_count; i++) for (i = 0; i < info->ports_count; ++i)
printf("%s%d", i ? "," : "", info->port[i]); printf("%s%d", i ? "," : "", info->port[i]);
printf(" "); printf(" ");
} }

View File

@@ -96,7 +96,7 @@ enum {
}; };
#define hashtable_for_each_safe(pos, n, head, size, i) \ #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)])) list_for_each_safe((pos), (n), (&head[(i)]))
#define pk_debug(msg, peer) pr_debug( \ #define pk_debug(msg, peer) pr_debug( \
@@ -176,7 +176,7 @@ alloc_hashtable(unsigned int size)
return NULL; return NULL;
} }
for (i = 0; i < size; i++) for (i = 0; i < size; ++i)
INIT_LIST_HEAD(&hash[i]); INIT_LIST_HEAD(&hash[i]);
return hash; 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 proc_dir_entry *pde = s->private;
const struct xt_pknock_rule *rule = pde->data; const struct xt_pknock_rule *rule = pde->data;
(*pos)++; ++*pos;
if (*pos >= peer_hashsize) if (*pos >= peer_hashsize)
return NULL; return NULL;
@@ -432,7 +432,7 @@ add_rule(struct xt_pknock_mtinfo *info)
rule = list_entry(pos, struct xt_pknock_rule, head); rule = list_entry(pos, struct xt_pknock_rule, head);
if (rulecmp(info, rule)) { if (rulecmp(info, rule)) {
rule->ref_count++; ++rule->ref_count;
if (info->option & XT_PKNOCK_CHECKIP) { if (info->option & XT_PKNOCK_CHECKIP) {
pr_debug("add_rule() (AC)" pr_debug("add_rule() (AC)"
" rule found: %s - " " rule found: %s - "
@@ -720,7 +720,7 @@ static void
crypt_to_hex(char *out, const char *crypt, unsigned int size) crypt_to_hex(char *out, const char *crypt, unsigned int size)
{ {
unsigned int i; unsigned int i;
for (i=0; i < size; i++) { for (i = 0; i < size; ++i) {
unsigned char c = crypt[i]; unsigned char c = crypt[i];
*out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1); *out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
*out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('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. */ /* Just update the timer when there is a state change. */
update_rule_timer(rule); update_rule_timer(rule);
peer->id_port_knocked++; ++peer->id_port_knocked;
if (is_last_knock(peer, info)) { if (is_last_knock(peer, info)) {
peer->status = ST_ALLOWED; peer->status = ST_ALLOWED;