* pull: minor tidbits
@ 2009-05-26 11:26 Jan Engelhardt
2009-05-26 11:26 ` [PATCH 1/5] xtables: use extern "C" Jan Engelhardt
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Jan Engelhardt @ 2009-05-26 11:26 UTC (permalink / raw
To: kaber; +Cc: netfilter-devel
Please pull from
git://dev.medozas.de/iptables master
to receive non-API-touching minor cosmetics and a few fixes
to recently-reported issues:
xtables: use extern "C"
extensions: add const qualifiers in print/save functions
iptables: replace open-coded sizeof by ARRAY_SIZE
addrtype: fix one manpage type
manpages: do not include v4-only modules in ip6tables manpage
thanks,
Jan
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/5] xtables: use extern "C"
2009-05-26 11:26 pull: minor tidbits Jan Engelhardt
@ 2009-05-26 11:26 ` Jan Engelhardt
2009-05-26 11:26 ` [PATCH 2/5] extensions: add const qualifiers in print/save functions Jan Engelhardt
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Jan Engelhardt @ 2009-05-26 11:26 UTC (permalink / raw
To: kaber; +Cc: netfilter-devel
This fixes linking errors for 3rd-party C++ code.
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
include/xtables.h.in | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/include/xtables.h.in b/include/xtables.h.in
index a399f90..4d4ca0a 100644
--- a/include/xtables.h.in
+++ b/include/xtables.h.in
@@ -203,6 +203,10 @@ struct xtables_globals
void (*exit_err)(enum xtables_exittype status, const char *msg, ...) __attribute__((noreturn, format(printf,2,3)));
};
+#ifdef __cplusplus
+extern "C" {
+#endif
+
extern const char *xtables_modprobe_program;
extern struct xtables_match *xtables_matches;
extern struct xtables_target *xtables_targets;
@@ -295,4 +299,8 @@ extern void _init(void);
#endif
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* _XTABLES_H */
--
1.6.3.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/5] extensions: add const qualifiers in print/save functions
2009-05-26 11:26 pull: minor tidbits Jan Engelhardt
2009-05-26 11:26 ` [PATCH 1/5] xtables: use extern "C" Jan Engelhardt
@ 2009-05-26 11:26 ` Jan Engelhardt
2009-05-26 11:26 ` [PATCH 3/5] iptables: replace open-coded sizeof by ARRAY_SIZE Jan Engelhardt
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Jan Engelhardt @ 2009-05-26 11:26 UTC (permalink / raw
To: kaber; +Cc: netfilter-devel
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
extensions/libip6t_hl.c | 2 +-
extensions/libipt_DNAT.c | 4 ++--
extensions/libipt_MASQUERADE.c | 10 ++++------
extensions/libipt_NETMAP.c | 5 ++---
extensions/libipt_REDIRECT.c | 10 ++++------
extensions/libipt_SAME.c | 10 ++++------
extensions/libipt_SET.c | 6 ++----
extensions/libipt_SNAT.c | 4 ++--
extensions/libipt_realm.c | 4 ++--
extensions/libipt_set.c | 6 ++----
extensions/libxt_CONNSECMARK.c | 6 +++---
extensions/libxt_RATEEST.c | 2 +-
extensions/libxt_SECMARK.c | 6 +++---
| 4 ++--
extensions/libxt_connbytes.c | 8 ++++----
extensions/libxt_connmark.c | 4 ++--
extensions/libxt_conntrack.c | 5 +++--
extensions/libxt_hashlimit.c | 6 ++----
extensions/libxt_helper.c | 4 ++--
extensions/libxt_limit.c | 4 ++--
extensions/libxt_mark.c | 4 ++--
extensions/libxt_physdev.c | 6 ++----
extensions/libxt_pkttype.c | 6 +++---
extensions/libxt_quota.c | 4 ++--
extensions/libxt_rateest.c | 7 ++++---
extensions/libxt_state.c | 4 ++--
extensions/libxt_statistic.c | 4 ++--
extensions/libxt_time.c | 2 +-
28 files changed, 67 insertions(+), 80 deletions(-)
diff --git a/extensions/libip6t_hl.c b/extensions/libip6t_hl.c
index 9252c3d..ff76b74 100644
--- a/extensions/libip6t_hl.c
+++ b/extensions/libip6t_hl.c
@@ -89,7 +89,7 @@ static void hl_check(unsigned int flags)
static void hl_print(const void *ip, const struct xt_entry_match *match,
int numeric)
{
- static const char *op[] = {
+ static const char *const op[] = {
[IP6T_HL_EQ] = "==",
[IP6T_HL_NE] = "!=",
[IP6T_HL_LT] = "<",
diff --git a/extensions/libipt_DNAT.c b/extensions/libipt_DNAT.c
index dc79b44..8b2caec 100644
--- a/extensions/libipt_DNAT.c
+++ b/extensions/libipt_DNAT.c
@@ -219,7 +219,7 @@ static void print_range(const struct nf_nat_range *r)
static void DNAT_print(const void *ip, const struct xt_entry_target *target,
int numeric)
{
- struct ipt_natinfo *info = (void *)target;
+ const struct ipt_natinfo *info = (const void *)target;
unsigned int i = 0;
printf("to:");
@@ -235,7 +235,7 @@ static void DNAT_print(const void *ip, const struct xt_entry_target *target,
static void DNAT_save(const void *ip, const struct xt_entry_target *target)
{
- struct ipt_natinfo *info = (void *)target;
+ const struct ipt_natinfo *info = (const void *)target;
unsigned int i = 0;
for (i = 0; i < info->mr.rangesize; i++) {
diff --git a/extensions/libipt_MASQUERADE.c b/extensions/libipt_MASQUERADE.c
index 82c2230..90084d8 100644
--- a/extensions/libipt_MASQUERADE.c
+++ b/extensions/libipt_MASQUERADE.c
@@ -111,9 +111,8 @@ static void
MASQUERADE_print(const void *ip, const struct xt_entry_target *target,
int numeric)
{
- struct nf_nat_multi_range *mr
- = (struct nf_nat_multi_range *)target->data;
- struct nf_nat_range *r = &mr->range[0];
+ const struct nf_nat_multi_range *mr = (const void *)target->data;
+ const struct nf_nat_range *r = &mr->range[0];
if (r->flags & IP_NAT_RANGE_PROTO_SPECIFIED) {
printf("masq ports: ");
@@ -130,9 +129,8 @@ MASQUERADE_print(const void *ip, const struct xt_entry_target *target,
static void
MASQUERADE_save(const void *ip, const struct xt_entry_target *target)
{
- struct nf_nat_multi_range *mr
- = (struct nf_nat_multi_range *)target->data;
- struct nf_nat_range *r = &mr->range[0];
+ const struct nf_nat_multi_range *mr = (const void *)target->data;
+ const struct nf_nat_range *r = &mr->range[0];
if (r->flags & IP_NAT_RANGE_PROTO_SPECIFIED) {
printf("--to-ports %hu", ntohs(r->min.tcp.port));
diff --git a/extensions/libipt_NETMAP.c b/extensions/libipt_NETMAP.c
index 9820230..f03c05b 100644
--- a/extensions/libipt_NETMAP.c
+++ b/extensions/libipt_NETMAP.c
@@ -140,9 +140,8 @@ static void NETMAP_check(unsigned int flags)
static void NETMAP_print(const void *ip, const struct xt_entry_target *target,
int numeric)
{
- struct nf_nat_multi_range *mr
- = (struct nf_nat_multi_range *)target->data;
- struct nf_nat_range *r = &mr->range[0];
+ const struct nf_nat_multi_range *mr = (const void *)target->data;
+ const struct nf_nat_range *r = &mr->range[0];
struct in_addr a;
int bits;
diff --git a/extensions/libipt_REDIRECT.c b/extensions/libipt_REDIRECT.c
index 658f933..01f9d0f 100644
--- a/extensions/libipt_REDIRECT.c
+++ b/extensions/libipt_REDIRECT.c
@@ -124,9 +124,8 @@ static int REDIRECT_parse(int c, char **argv, int invert, unsigned int *flags,
static void REDIRECT_print(const void *ip, const struct xt_entry_target *target,
int numeric)
{
- struct nf_nat_multi_range *mr
- = (struct nf_nat_multi_range *)target->data;
- struct nf_nat_range *r = &mr->range[0];
+ const struct nf_nat_multi_range *mr = (const void *)target->data;
+ const struct nf_nat_range *r = &mr->range[0];
if (r->flags & IP_NAT_RANGE_PROTO_SPECIFIED) {
printf("redir ports ");
@@ -141,9 +140,8 @@ static void REDIRECT_print(const void *ip, const struct xt_entry_target *target,
static void REDIRECT_save(const void *ip, const struct xt_entry_target *target)
{
- struct nf_nat_multi_range *mr
- = (struct nf_nat_multi_range *)target->data;
- struct nf_nat_range *r = &mr->range[0];
+ const struct nf_nat_multi_range *mr = (const void *)target->data;
+ const struct nf_nat_range *r = &mr->range[0];
if (r->flags & IP_NAT_RANGE_PROTO_SPECIFIED) {
printf("--to-ports ");
diff --git a/extensions/libipt_SAME.c b/extensions/libipt_SAME.c
index a07d9f4..5cb0d3f 100644
--- a/extensions/libipt_SAME.c
+++ b/extensions/libipt_SAME.c
@@ -138,14 +138,13 @@ static void SAME_print(const void *ip, const struct xt_entry_target *target,
int numeric)
{
unsigned int count;
- struct ipt_same_info *mr
- = (struct ipt_same_info *)target->data;
+ const struct ipt_same_info *mr = (const void *)target->data;
int random_selection = 0;
printf("same:");
for (count = 0; count < mr->rangesize; count++) {
- struct nf_nat_range *r = &mr->range[count];
+ const struct nf_nat_range *r = &mr->range[count];
struct in_addr a;
a.s_addr = r->min_ip;
@@ -171,12 +170,11 @@ static void SAME_print(const void *ip, const struct xt_entry_target *target,
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;
+ const struct ipt_same_info *mr = (const void *)target->data;
int random_selection = 0;
for (count = 0; count < mr->rangesize; count++) {
- struct nf_nat_range *r = &mr->range[count];
+ const struct nf_nat_range *r = &mr->range[count];
struct in_addr a;
a.s_addr = r->min_ip;
diff --git a/extensions/libipt_SET.c b/extensions/libipt_SET.c
index 5da41a0..b717a88 100644
--- a/extensions/libipt_SET.c
+++ b/extensions/libipt_SET.c
@@ -129,8 +129,7 @@ print_target(const char *prefix, const struct ipt_set_info *info)
static void SET_print(const void *ip, const struct xt_entry_target *target,
int numeric)
{
- struct ipt_set_info_target *info =
- (struct ipt_set_info_target *) target->data;
+ const struct ipt_set_info_target *info = (const void *)target->data;
print_target("add-set", &info->add_set);
print_target("del-set", &info->del_set);
@@ -138,8 +137,7 @@ static void SET_print(const void *ip, const struct xt_entry_target *target,
static void SET_save(const void *ip, const struct xt_entry_target *target)
{
- struct ipt_set_info_target *info =
- (struct ipt_set_info_target *) target->data;
+ const struct ipt_set_info_target *info = (const void *)target->data;
print_target("--add-set", &info->add_set);
print_target("--del-set", &info->del_set);
diff --git a/extensions/libipt_SNAT.c b/extensions/libipt_SNAT.c
index 9609ad9..e592d80 100644
--- a/extensions/libipt_SNAT.c
+++ b/extensions/libipt_SNAT.c
@@ -219,7 +219,7 @@ static void print_range(const struct nf_nat_range *r)
static void SNAT_print(const void *ip, const struct xt_entry_target *target,
int numeric)
{
- struct ipt_natinfo *info = (void *)target;
+ const struct ipt_natinfo *info = (const void *)target;
unsigned int i = 0;
printf("to:");
@@ -235,7 +235,7 @@ static void SNAT_print(const void *ip, const struct xt_entry_target *target,
static void SNAT_save(const void *ip, const struct xt_entry_target *target)
{
- struct ipt_natinfo *info = (void *)target;
+ const struct ipt_natinfo *info = (const void *)target;
unsigned int i = 0;
for (i = 0; i < info->mr.rangesize; i++) {
diff --git a/extensions/libipt_realm.c b/extensions/libipt_realm.c
index 3dd63d3..0580610 100644
--- a/extensions/libipt_realm.c
+++ b/extensions/libipt_realm.c
@@ -207,7 +207,7 @@ print_realm(unsigned long id, unsigned long mask, int numeric)
static void realm_print(const void *ip, const struct xt_entry_match *match,
int numeric)
{
- struct ipt_realm_info *ri = (struct ipt_realm_info *) match->data;
+ const struct ipt_realm_info *ri = (const void *)match->data;
if (ri->invert)
printf("! ");
@@ -218,7 +218,7 @@ static void realm_print(const void *ip, const struct xt_entry_match *match,
static void realm_save(const void *ip, const struct xt_entry_match *match)
{
- struct ipt_realm_info *ri = (struct ipt_realm_info *) match->data;
+ const struct ipt_realm_info *ri = (const void *)match->data;
if (ri->invert)
printf("! ");
diff --git a/extensions/libipt_set.c b/extensions/libipt_set.c
index 845b2b0..33a2c8b 100644
--- a/extensions/libipt_set.c
+++ b/extensions/libipt_set.c
@@ -121,16 +121,14 @@ print_match(const char *prefix, const struct ipt_set_info *info)
static void set_print(const void *ip, const struct xt_entry_match *match,
int numeric)
{
- struct ipt_set_info_match *info =
- (struct ipt_set_info_match *) match->data;
+ const struct ipt_set_info_match *info = (const void *)match->data;
print_match("set", &info->match_set);
}
static void set_save(const void *ip, const struct xt_entry_match *match)
{
- struct ipt_set_info_match *info =
- (struct ipt_set_info_match *) match->data;
+ const struct ipt_set_info_match *info = (const void *)match->data;
print_match("--set", &info->match_set);
}
diff --git a/extensions/libxt_CONNSECMARK.c b/extensions/libxt_CONNSECMARK.c
index 1515f6f..11ec01a 100644
--- a/extensions/libxt_CONNSECMARK.c
+++ b/extensions/libxt_CONNSECMARK.c
@@ -69,7 +69,7 @@ static void CONNSECMARK_check(unsigned int flags)
"or --restore is allowed");
}
-static void print_connsecmark(struct xt_connsecmark_target_info *info)
+static void print_connsecmark(const struct xt_connsecmark_target_info *info)
{
switch (info->mode) {
case CONNSECMARK_SAVE:
@@ -89,7 +89,7 @@ static void
CONNSECMARK_print(const void *ip, const struct xt_entry_target *target,
int numeric)
{
- struct xt_connsecmark_target_info *info =
+ const struct xt_connsecmark_target_info *info =
(struct xt_connsecmark_target_info*)(target)->data;
printf("CONNSECMARK ");
@@ -99,7 +99,7 @@ CONNSECMARK_print(const void *ip, const struct xt_entry_target *target,
static void
CONNSECMARK_save(const void *ip, const struct xt_entry_target *target)
{
- struct xt_connsecmark_target_info *info =
+ const struct xt_connsecmark_target_info *info =
(struct xt_connsecmark_target_info*)target->data;
printf("--");
diff --git a/extensions/libxt_RATEEST.c b/extensions/libxt_RATEEST.c
index d4fd6dd..1a7b0a9 100644
--- a/extensions/libxt_RATEEST.c
+++ b/extensions/libxt_RATEEST.c
@@ -174,7 +174,7 @@ RATEEST_final_check(unsigned int flags)
static void
__RATEEST_print(const struct xt_entry_target *target, const char *prefix)
{
- struct xt_rateest_target_info *info = (void *)target->data;
+ const struct xt_rateest_target_info *info = (const void *)target->data;
unsigned int local_interval;
unsigned int local_ewma_log;
diff --git a/extensions/libxt_SECMARK.c b/extensions/libxt_SECMARK.c
index 9db2327..0c09c88 100644
--- a/extensions/libxt_SECMARK.c
+++ b/extensions/libxt_SECMARK.c
@@ -61,7 +61,7 @@ static void SECMARK_check(unsigned int flags)
xtables_error(PARAMETER_PROBLEM, PFX "parameter required");
}
-static void print_secmark(struct xt_secmark_target_info *info)
+static void print_secmark(const struct xt_secmark_target_info *info)
{
switch (info->mode) {
case SECMARK_MODE_SEL:
@@ -76,7 +76,7 @@ static void print_secmark(struct xt_secmark_target_info *info)
static void SECMARK_print(const void *ip, const struct xt_entry_target *target,
int numeric)
{
- struct xt_secmark_target_info *info =
+ const struct xt_secmark_target_info *info =
(struct xt_secmark_target_info*)(target)->data;
printf("SECMARK ");
@@ -85,7 +85,7 @@ static void SECMARK_print(const void *ip, const struct xt_entry_target *target,
static void SECMARK_save(const void *ip, const struct xt_entry_target *target)
{
- struct xt_secmark_target_info *info =
+ const struct xt_secmark_target_info *info =
(struct xt_secmark_target_info*)target->data;
printf("--");
--git a/extensions/libxt_comment.c b/extensions/libxt_comment.c
index 67d7f99..5f393bb 100644
--- a/extensions/libxt_comment.c
+++ b/extensions/libxt_comment.c
@@ -71,7 +71,7 @@ static void comment_check(unsigned int flags)
static void
comment_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
- struct xt_comment_info *commentinfo = (struct xt_comment_info *)match->data;
+ struct xt_comment_info *commentinfo = (void *)match->data;
commentinfo->comment[XT_MAX_COMMENT_LEN-1] = '\0';
printf("/* %s */ ", commentinfo->comment);
@@ -81,7 +81,7 @@ comment_print(const void *ip, const struct xt_entry_match *match, int numeric)
static void
comment_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_comment_info *commentinfo = (struct xt_comment_info *)match->data;
+ struct xt_comment_info *commentinfo = (void *)match->data;
commentinfo->comment[XT_MAX_COMMENT_LEN-1] = '\0';
printf("--comment ");
diff --git a/extensions/libxt_connbytes.c b/extensions/libxt_connbytes.c
index 9f6af1c..c7bdff0 100644
--- a/extensions/libxt_connbytes.c
+++ b/extensions/libxt_connbytes.c
@@ -102,7 +102,7 @@ static void connbytes_check(unsigned int flags)
"`--connbytes-dir' and `--connbytes-mode'");
}
-static void print_mode(struct xt_connbytes_info *sinfo)
+static void print_mode(const struct xt_connbytes_info *sinfo)
{
switch (sinfo->what) {
case XT_CONNBYTES_PKTS:
@@ -120,7 +120,7 @@ static void print_mode(struct xt_connbytes_info *sinfo)
}
}
-static void print_direction(struct xt_connbytes_info *sinfo)
+static void print_direction(const struct xt_connbytes_info *sinfo)
{
switch (sinfo->direction) {
case XT_CONNBYTES_DIR_ORIGINAL:
@@ -141,7 +141,7 @@ static void print_direction(struct xt_connbytes_info *sinfo)
static void
connbytes_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
- struct xt_connbytes_info *sinfo = (struct xt_connbytes_info *)match->data;
+ const struct xt_connbytes_info *sinfo = (const void *)match->data;
if (sinfo->count.from > sinfo->count.to)
printf("connbytes ! %llu:%llu ",
@@ -161,7 +161,7 @@ connbytes_print(const void *ip, const struct xt_entry_match *match, int numeric)
static void connbytes_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_connbytes_info *sinfo = (struct xt_connbytes_info *)match->data;
+ const struct xt_connbytes_info *sinfo = (const void *)match->data;
if (sinfo->count.from > sinfo->count.to)
printf("! --connbytes %llu:%llu ",
diff --git a/extensions/libxt_connmark.c b/extensions/libxt_connmark.c
index 2dca5a5..ce2002c 100644
--- a/extensions/libxt_connmark.c
+++ b/extensions/libxt_connmark.c
@@ -121,7 +121,7 @@ static void connmark_mt_check(unsigned int flags)
static void
connmark_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
- struct xt_connmark_info *info = (struct xt_connmark_info *)match->data;
+ const struct xt_connmark_info *info = (const void *)match->data;
printf("CONNMARK match ");
if (info->invert)
@@ -142,7 +142,7 @@ connmark_mt_print(const void *ip, const struct xt_entry_match *match, int numeri
static void connmark_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_connmark_info *info = (struct xt_connmark_info *)match->data;
+ const struct xt_connmark_info *info = (const void *)match->data;
if (info->invert)
printf("! ");
diff --git a/extensions/libxt_conntrack.c b/extensions/libxt_conntrack.c
index 358b255..96ea3ec 100644
--- a/extensions/libxt_conntrack.c
+++ b/extensions/libxt_conntrack.c
@@ -779,7 +779,8 @@ conntrack_dump_addr(const union nf_inet_addr *addr,
}
static void
-print_addr(struct in_addr *addr, struct in_addr *mask, int inv, int numeric)
+print_addr(const struct in_addr *addr, const struct in_addr *mask,
+ int inv, int numeric)
{
char buf[BUFSIZ];
@@ -801,7 +802,7 @@ print_addr(struct in_addr *addr, struct in_addr *mask, int inv, int numeric)
static void
matchinfo_print(const void *ip, const struct xt_entry_match *match, int numeric, const char *optpfx)
{
- struct xt_conntrack_info *sinfo = (void *)match->data;
+ const struct xt_conntrack_info *sinfo = (const void *)match->data;
if(sinfo->flags & XT_CONNTRACK_STATE) {
if (sinfo->invflags & XT_CONNTRACK_STATE)
diff --git a/extensions/libxt_hashlimit.c b/extensions/libxt_hashlimit.c
index 9a7e5de..aa56c65 100644
--- a/extensions/libxt_hashlimit.c
+++ b/extensions/libxt_hashlimit.c
@@ -525,8 +525,7 @@ static void print_mode(unsigned int mode, char separator)
static void hashlimit_print(const void *ip,
const struct xt_entry_match *match, int numeric)
{
- struct xt_hashlimit_info *r =
- (struct xt_hashlimit_info *)match->data;
+ const struct xt_hashlimit_info *r = (const void *)match->data;
fputs("limit: avg ", stdout); print_rate(r->cfg.avg);
printf("burst %u ", r->cfg.burst);
fputs("mode ", stdout);
@@ -590,8 +589,7 @@ hashlimit_mt6_print(const void *ip, const struct xt_entry_match *match,
static void hashlimit_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_hashlimit_info *r =
- (struct xt_hashlimit_info *)match->data;
+ const struct xt_hashlimit_info *r = (const void *)match->data;
fputs("--hashlimit ", stdout); print_rate(r->cfg.avg);
if (r->cfg.burst != XT_HASHLIMIT_BURST)
diff --git a/extensions/libxt_helper.c b/extensions/libxt_helper.c
index 8378be7..7b56bef 100644
--- a/extensions/libxt_helper.c
+++ b/extensions/libxt_helper.c
@@ -55,14 +55,14 @@ static void helper_check(unsigned int flags)
static void
helper_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
- struct xt_helper_info *info = (struct xt_helper_info *)match->data;
+ const struct xt_helper_info *info = (const void *)match->data;
printf("helper match %s\"%s\" ", info->invert ? "! " : "", info->name);
}
static void helper_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_helper_info *info = (struct xt_helper_info *)match->data;
+ const struct xt_helper_info *info = (const void *)match->data;
printf("%s--helper ",info->invert ? "! " : "");
xtables_save_string(info->name);
diff --git a/extensions/libxt_limit.c b/extensions/libxt_limit.c
index f785d2d..18224f3 100644
--- a/extensions/libxt_limit.c
+++ b/extensions/libxt_limit.c
@@ -144,14 +144,14 @@ static void print_rate(u_int32_t period)
static void
limit_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
- struct xt_rateinfo *r = (struct xt_rateinfo *)match->data;
+ const struct xt_rateinfo *r = (const void *)match->data;
printf("limit: avg "); print_rate(r->avg);
printf("burst %u ", r->burst);
}
static void limit_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_rateinfo *r = (struct xt_rateinfo *)match->data;
+ const struct xt_rateinfo *r = (const void *)match->data;
printf("--limit "); print_rate(r->avg);
if (r->burst != XT_LIMIT_BURST)
diff --git a/extensions/libxt_mark.c b/extensions/libxt_mark.c
index ceca995..0edff74 100644
--- a/extensions/libxt_mark.c
+++ b/extensions/libxt_mark.c
@@ -110,7 +110,7 @@ mark_mt_print(const void *ip, const struct xt_entry_match *match, int numeric)
static void
mark_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
- struct xt_mark_info *info = (struct xt_mark_info *)match->data;
+ const struct xt_mark_info *info = (const void *)match->data;
printf("MARK match ");
@@ -134,7 +134,7 @@ static void mark_mt_save(const void *ip, const struct xt_entry_match *match)
static void
mark_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_mark_info *info = (struct xt_mark_info *)match->data;
+ const struct xt_mark_info *info = (const void *)match->data;
if (info->invert)
printf("! ");
diff --git a/extensions/libxt_physdev.c b/extensions/libxt_physdev.c
index c87779b..5522a32 100644
--- a/extensions/libxt_physdev.c
+++ b/extensions/libxt_physdev.c
@@ -114,8 +114,7 @@ static void physdev_check(unsigned int flags)
static void
physdev_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
- struct xt_physdev_info *info =
- (struct xt_physdev_info*)match->data;
+ const struct xt_physdev_info *info = (const void *)match->data;
printf("PHYSDEV match");
if (info->bitmask & XT_PHYSDEV_OP_ISIN)
@@ -139,8 +138,7 @@ physdev_print(const void *ip, const struct xt_entry_match *match, int numeric)
static void physdev_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_physdev_info *info =
- (struct xt_physdev_info*)match->data;
+ const struct xt_physdev_info *info = (const void *)match->data;
if (info->bitmask & XT_PHYSDEV_OP_ISIN)
printf("%s--physdev-is-in ",
diff --git a/extensions/libxt_pkttype.c b/extensions/libxt_pkttype.c
index 0fa933f..50af3ed 100644
--- a/extensions/libxt_pkttype.c
+++ b/extensions/libxt_pkttype.c
@@ -111,7 +111,7 @@ static void pkttype_check(unsigned int flags)
xtables_error(PARAMETER_PROBLEM, "You must specify \"--pkt-type\"");
}
-static void print_pkttype(struct xt_pkttype_info *info)
+static void print_pkttype(const struct xt_pkttype_info *info)
{
unsigned int i;
@@ -130,7 +130,7 @@ static void print_pkttype(struct xt_pkttype_info *info)
static void pkttype_print(const void *ip, const struct xt_entry_match *match,
int numeric)
{
- struct xt_pkttype_info *info = (struct xt_pkttype_info *)match->data;
+ const struct xt_pkttype_info *info = (const void *)match->data;
printf("PKTTYPE %s= ", info->invert?"!":"");
print_pkttype(info);
@@ -138,7 +138,7 @@ static void pkttype_print(const void *ip, const struct xt_entry_match *match,
static void pkttype_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_pkttype_info *info = (struct xt_pkttype_info *)match->data;
+ const struct xt_pkttype_info *info = (const void *)match->data;
printf("%s--pkt-type ", info->invert ? "! " : "");
print_pkttype(info);
diff --git a/extensions/libxt_quota.c b/extensions/libxt_quota.c
index 2657b2a..4c1bcb0 100644
--- a/extensions/libxt_quota.c
+++ b/extensions/libxt_quota.c
@@ -25,14 +25,14 @@ static void quota_help(void)
static void
quota_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
- struct xt_quota_info *q = (struct xt_quota_info *) match->data;
+ const struct xt_quota_info *q = (const void *)match->data;
printf("quota: %llu bytes", (unsigned long long) q->quota);
}
static void
quota_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_quota_info *q = (struct xt_quota_info *) match->data;
+ const struct xt_quota_info *q = (const void *)match->data;
printf("--quota %llu ", (unsigned long long) q->quota);
}
diff --git a/extensions/libxt_rateest.c b/extensions/libxt_rateest.c
index 3cff07d..9f3a436 100644
--- a/extensions/libxt_rateest.c
+++ b/extensions/libxt_rateest.c
@@ -332,7 +332,8 @@ rateest_print_rate(u_int32_t rate, int numeric)
}
static void
-rateest_print_mode(struct xt_rateest_match_info *info, const char *prefix)
+rateest_print_mode(const struct xt_rateest_match_info *info,
+ const char *prefix)
{
if (info->flags & XT_RATEEST_MATCH_INVERT)
printf("! ");
@@ -355,7 +356,7 @@ rateest_print_mode(struct xt_rateest_match_info *info, const char *prefix)
static void
rateest_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
- struct xt_rateest_match_info *info = (void *)match->data;
+ const struct xt_rateest_match_info *info = (const void *)match->data;
printf("rateest match ");
@@ -405,7 +406,7 @@ rateest_print(const void *ip, const struct xt_entry_match *match, int numeric)
static void
rateest_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_rateest_match_info *info = (void *)match->data;
+ const struct xt_rateest_match_info *info = (const void *)match->data;
if (info->flags & XT_RATEEST_MATCH_REL) {
printf("--rateest1 %s ", info->name1);
diff --git a/extensions/libxt_state.c b/extensions/libxt_state.c
index 0f26443..7387e26 100644
--- a/extensions/libxt_state.c
+++ b/extensions/libxt_state.c
@@ -124,7 +124,7 @@ state_print(const void *ip,
const struct xt_entry_match *match,
int numeric)
{
- struct xt_state_info *sinfo = (struct xt_state_info *)match->data;
+ const struct xt_state_info *sinfo = (const void *)match->data;
printf("state ");
state_print_state(sinfo->statemask);
@@ -132,7 +132,7 @@ state_print(const void *ip,
static void state_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_state_info *sinfo = (struct xt_state_info *)match->data;
+ const struct xt_state_info *sinfo = (const void *)match->data;
printf("--state ");
state_print_state(sinfo->statemask);
diff --git a/extensions/libxt_statistic.c b/extensions/libxt_statistic.c
index fa044ad..5b03686 100644
--- a/extensions/libxt_statistic.c
+++ b/extensions/libxt_statistic.c
@@ -146,7 +146,7 @@ static void print_match(const struct xt_statistic_info *info, char *prefix)
static void
statistic_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
- struct xt_statistic_info *info = (struct xt_statistic_info *)match->data;
+ const struct xt_statistic_info *info = (const void *)match->data;
printf("statistic ");
print_match(info, "");
@@ -154,7 +154,7 @@ statistic_print(const void *ip, const struct xt_entry_match *match, int numeric)
static void statistic_save(const void *ip, const struct xt_entry_match *match)
{
- struct xt_statistic_info *info = (struct xt_statistic_info *)match->data;
+ const struct xt_statistic_info *info = (const void *)match->data;
print_match(info, "--");
}
diff --git a/extensions/libxt_time.c b/extensions/libxt_time.c
index eb8b671..1c81260 100644
--- a/extensions/libxt_time.c
+++ b/extensions/libxt_time.c
@@ -406,7 +406,7 @@ static inline void divide_time(unsigned int fulltime, unsigned int *hours,
static void time_print(const void *ip, const struct xt_entry_match *match,
int numeric)
{
- struct xt_time_info *info = (void *)match->data;
+ const struct xt_time_info *info = (const void *)match->data;
unsigned int h, m, s;
printf("TIME ");
--
1.6.3.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/5] iptables: replace open-coded sizeof by ARRAY_SIZE
2009-05-26 11:26 pull: minor tidbits Jan Engelhardt
2009-05-26 11:26 ` [PATCH 1/5] xtables: use extern "C" Jan Engelhardt
2009-05-26 11:26 ` [PATCH 2/5] extensions: add const qualifiers in print/save functions Jan Engelhardt
@ 2009-05-26 11:26 ` Jan Engelhardt
2009-05-26 11:26 ` [PATCH 4/5] addrtype: fix one manpage type Jan Engelhardt
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Jan Engelhardt @ 2009-05-26 11:26 UTC (permalink / raw
To: kaber; +Cc: netfilter-devel
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
extensions/dscp_helper.c | 6 ++----
extensions/libip6t_LOG.c | 12 +++---------
extensions/libip6t_REJECT.c | 11 ++++-------
extensions/libip6t_icmp6.c | 11 ++++-------
| 16 +++++-----------
extensions/libip6t_mh.c | 7 +++----
extensions/libipt_LOG.c | 12 +++---------
extensions/libipt_REJECT.c | 9 ++++-----
extensions/libipt_icmp.c | 11 ++++-------
extensions/libxt_dccp.c | 5 ++---
extensions/libxt_hashlimit.c | 3 +--
extensions/libxt_limit.c | 3 +--
extensions/libxt_pkttype.c | 12 +++---------
extensions/libxt_sctp.c | 18 ++----------------
extensions/libxt_tcp.c | 9 +++------
ip6tables-restore.c | 2 +-
iptables-restore.c | 2 +-
iptables-xml.c | 2 +-
18 files changed, 47 insertions(+), 104 deletions(-)
diff --git a/extensions/dscp_helper.c b/extensions/dscp_helper.c
index 8fa0f4a..75b1fec 100644
--- a/extensions/dscp_helper.c
+++ b/extensions/dscp_helper.c
@@ -51,7 +51,7 @@ class_to_dscp(const char *name)
{
unsigned int i;
- for (i = 0; i < sizeof(ds_classes) / sizeof(struct ds_class); i++) {
+ for (i = 0; i < ARRAY_SIZE(ds_classes); i++) {
if (!strncasecmp(name, ds_classes[i].name,
strlen(ds_classes[i].name)))
return ds_classes[i].dscp;
@@ -68,11 +68,9 @@ dscp_to_name(unsigned int dscp)
{
int i;
- for (i = 0; i < sizeof(ds_classes) / sizeof(struct ds_class); i++) {
+ for (i = 0; i < ARRAY_SIZE(ds_classes); ++i)
if (dscp == ds_classes[i].dscp)
return ds_classes[i].name;
- }
-
xtables_error(PARAMETER_PROBLEM,
"Invalid DSCP value `%d'\n", dscp);
diff --git a/extensions/libip6t_LOG.c b/extensions/libip6t_LOG.c
index 390cb97..f713201 100644
--- a/extensions/libip6t_LOG.c
+++ b/extensions/libip6t_LOG.c
@@ -72,9 +72,7 @@ parse_level(const char *level)
if (!xtables_strtoui(level, NULL, &lev, 0, 7)) {
unsigned int i = 0;
- for (i = 0;
- i < sizeof(ip6t_log_names) / sizeof(struct ip6t_log_names);
- i++) {
+ for (i = 0; i < ARRAY_SIZE(ip6t_log_names); ++i)
if (strncasecmp(level, ip6t_log_names[i].name,
strlen(level)) == 0) {
if (set++)
@@ -83,7 +81,6 @@ parse_level(const char *level)
level);
lev = ip6t_log_names[i].level;
}
- }
if (!set)
xtables_error(PARAMETER_PROBLEM,
@@ -201,15 +198,12 @@ static void LOG_print(const void *ip, const struct xt_entry_target *target,
printf("flags %u level %u ",
loginfo->logflags, loginfo->level);
else {
- for (i = 0;
- i < sizeof(ip6t_log_names) / sizeof(struct ip6t_log_names);
- i++) {
+ for (i = 0; i < ARRAY_SIZE(ip6t_log_names); ++i)
if (loginfo->level == ip6t_log_names[i].level) {
printf("level %s ", ip6t_log_names[i].name);
break;
}
- }
- if (i == sizeof(ip6t_log_names) / sizeof(struct ip6t_log_names))
+ if (i == ARRAY_SIZE(ip6t_log_names))
printf("UNKNOWN level %u ", loginfo->level);
if (loginfo->logflags & IP6T_LOG_TCPSEQ)
printf("tcp-sequence ");
diff --git a/extensions/libip6t_REJECT.c b/extensions/libip6t_REJECT.c
index 527f595..9ad3b68 100644
--- a/extensions/libip6t_REJECT.c
+++ b/extensions/libip6t_REJECT.c
@@ -43,7 +43,7 @@ print_reject_types(void)
printf("Valid reject types:\n");
- for (i = 0; i < sizeof(reject_table)/sizeof(struct reject_names); i++) {
+ for (i = 0; i < ARRAY_SIZE(reject_table); ++i) {
printf(" %-25s\t%s\n", reject_table[i].name, reject_table[i].desc);
printf(" %-25s\talias\n", reject_table[i].alias);
}
@@ -79,7 +79,6 @@ static int REJECT_parse(int c, char **argv, int invert, unsigned int *flags,
{
struct ip6t_reject_info *reject =
(struct ip6t_reject_info *)(*target)->data;
- unsigned int limit = sizeof(reject_table)/sizeof(struct reject_names);
unsigned int i;
switch(c) {
@@ -87,13 +86,12 @@ static int REJECT_parse(int c, char **argv, int invert, unsigned int *flags,
if (xtables_check_inverse(optarg, &invert, NULL, 0))
xtables_error(PARAMETER_PROBLEM,
"Unexpected `!' after --reject-with");
- for (i = 0; i < limit; i++) {
+ for (i = 0; i < ARRAY_SIZE(reject_table); ++i)
if ((strncasecmp(reject_table[i].name, optarg, strlen(optarg)) == 0)
|| (strncasecmp(reject_table[i].alias, optarg, strlen(optarg)) == 0)) {
reject->with = reject_table[i].with;
return 1;
}
- }
xtables_error(PARAMETER_PROBLEM, "unknown reject type \"%s\"", optarg);
default:
/* Fall through */
@@ -109,10 +107,9 @@ static void REJECT_print(const void *ip, const struct xt_entry_target *target,
= (const struct ip6t_reject_info *)target->data;
unsigned int i;
- for (i = 0; i < sizeof(reject_table)/sizeof(struct reject_names); i++) {
+ for (i = 0; i < ARRAY_SIZE(reject_table); ++i)
if (reject_table[i].with == reject->with)
break;
- }
printf("reject-with %s ", reject_table[i].name);
}
@@ -122,7 +119,7 @@ static void REJECT_save(const void *ip, const struct xt_entry_target *target)
= (const struct ip6t_reject_info *)target->data;
unsigned int i;
- for (i = 0; i < sizeof(reject_table)/sizeof(struct reject_names); i++)
+ for (i = 0; i < ARRAY_SIZE(reject_table); ++i)
if (reject_table[i].with == reject->with)
break;
diff --git a/extensions/libip6t_icmp6.c b/extensions/libip6t_icmp6.c
index 0678aac..e41a670 100644
--- a/extensions/libip6t_icmp6.c
+++ b/extensions/libip6t_icmp6.c
@@ -59,7 +59,7 @@ print_icmpv6types(void)
unsigned int i;
printf("Valid ICMPv6 Types:");
- for (i = 0; i < sizeof(icmpv6_codes)/sizeof(struct icmpv6_names); i++) {
+ for (i = 0; i < ARRAY_SIZE(icmpv6_codes); ++i) {
if (i && icmpv6_codes[i].type == icmpv6_codes[i-1].type) {
if (icmpv6_codes[i].code_min == icmpv6_codes[i-1].code_min
&& (icmpv6_codes[i].code_max
@@ -91,7 +91,7 @@ static const struct option icmp6_opts[] = {
static void
parse_icmpv6(const char *icmpv6type, u_int8_t *type, u_int8_t code[])
{
- unsigned int limit = sizeof(icmpv6_codes)/sizeof(struct icmpv6_names);
+ static const unsigned int limit = ARRAY_SIZE(icmpv6_codes);
unsigned int match = limit;
unsigned int i;
@@ -181,16 +181,13 @@ static void print_icmpv6type(u_int8_t type,
if (!numeric) {
unsigned int i;
- for (i = 0;
- i < sizeof(icmpv6_codes)/sizeof(struct icmpv6_names);
- i++) {
+ for (i = 0; i < ARRAY_SIZE(icmpv6_codes); ++i)
if (icmpv6_codes[i].type == type
&& icmpv6_codes[i].code_min == code_min
&& icmpv6_codes[i].code_max == code_max)
break;
- }
- if (i != sizeof(icmpv6_codes)/sizeof(struct icmpv6_names)) {
+ if (i != ARRAY_SIZE(icmpv6_codes)) {
printf("%s%s ",
invert ? "!" : "",
icmpv6_codes[i].name);
--git a/extensions/libip6t_ipv6header.c b/extensions/libip6t_ipv6header.c
index 479b313..2674c8f 100644
--- a/extensions/libip6t_ipv6header.c
+++ b/extensions/libip6t_ipv6header.c
@@ -77,7 +77,7 @@ proto_to_name(u_int8_t proto, int nolookup)
return pent->p_name;
}
- for (i = 0; i < sizeof(chain_protos)/sizeof(struct pprot); i++)
+ for (i = 0; i < ARRAY_SIZE(chain_protos); ++i)
if (chain_protos[i].num == proto)
return chain_protos[i].name;
@@ -94,16 +94,13 @@ name_to_proto(const char *s)
proto = pent->p_proto;
else {
unsigned int i;
- for (i = 0;
- i < sizeof(chain_protos)/sizeof(struct pprot);
- i++) {
+ for (i = 0; i < ARRAY_SIZE(chain_protos); ++i)
if (strcmp(s, chain_protos[i].name) == 0) {
proto = chain_protos[i].num;
break;
}
- }
- if (i == sizeof(chain_protos)/sizeof(struct pprot))
+ if (i == ARRAY_SIZE(chain_protos))
xtables_error(PARAMETER_PROBLEM,
"unknown header `%s' specified",
s);
@@ -116,16 +113,13 @@ static unsigned int
add_proto_to_mask(int proto){
unsigned int i=0, flag=0;
- for (i = 0;
- i < sizeof(chain_flags)/sizeof(struct numflag);
- i++) {
+ for (i = 0; i < ARRAY_SIZE(chain_flags); ++i)
if (proto == chain_flags[i].proto){
flag = chain_flags[i].flag;
break;
}
- }
- if (i == sizeof(chain_flags)/sizeof(struct numflag))
+ if (i == ARRAY_SIZE(chain_flags))
xtables_error(PARAMETER_PROBLEM,
"unknown header `%d' specified",
proto);
diff --git a/extensions/libip6t_mh.c b/extensions/libip6t_mh.c
index 9711f76..47d5544 100644
--- a/extensions/libip6t_mh.c
+++ b/extensions/libip6t_mh.c
@@ -48,7 +48,7 @@ static void print_types_all(void)
unsigned int i;
printf("Valid MH types:");
- for (i = 0; i < sizeof(mh_names)/sizeof(struct mh_name); i++) {
+ for (i = 0; i < ARRAY_SIZE(mh_names); ++i) {
if (i && mh_names[i].type == mh_names[i-1].type)
printf(" (%s)", mh_names[i].name);
else
@@ -75,7 +75,7 @@ static void mh_init(struct xt_entry_match *m)
static unsigned int name_to_type(const char *name)
{
int namelen = strlen(name);
- unsigned int limit = sizeof(mh_names)/sizeof(struct mh_name);
+ static const unsigned int limit = ARRAY_SIZE(mh_names);
unsigned int match = limit;
unsigned int i;
@@ -151,10 +151,9 @@ static const char *type_to_name(u_int8_t type)
{
unsigned int i;
- for (i = 0; i < sizeof(mh_names)/sizeof(struct mh_name); i++) {
+ for (i = 0; i < ARRAY_SIZE(mh_names); ++i)
if (mh_names[i].type == type)
return mh_names[i].name;
- }
return NULL;
}
diff --git a/extensions/libipt_LOG.c b/extensions/libipt_LOG.c
index ebcb574..5b90033 100644
--- a/extensions/libipt_LOG.c
+++ b/extensions/libipt_LOG.c
@@ -72,9 +72,7 @@ parse_level(const char *level)
if (!xtables_strtoui(level, NULL, &lev, 0, 7)) {
unsigned int i = 0;
- for (i = 0;
- i < sizeof(ipt_log_names) / sizeof(struct ipt_log_names);
- i++) {
+ for (i = 0; i < ARRAY_SIZE(ipt_log_names); ++i)
if (strncasecmp(level, ipt_log_names[i].name,
strlen(level)) == 0) {
if (set++)
@@ -83,7 +81,6 @@ parse_level(const char *level)
level);
lev = ipt_log_names[i].level;
}
- }
if (!set)
xtables_error(PARAMETER_PROBLEM,
@@ -201,15 +198,12 @@ static void LOG_print(const void *ip, const struct xt_entry_target *target,
printf("flags %u level %u ",
loginfo->logflags, loginfo->level);
else {
- for (i = 0;
- i < sizeof(ipt_log_names) / sizeof(struct ipt_log_names);
- i++) {
+ for (i = 0; i < ARRAY_SIZE(ipt_log_names); ++i)
if (loginfo->level == ipt_log_names[i].level) {
printf("level %s ", ipt_log_names[i].name);
break;
}
- }
- if (i == sizeof(ipt_log_names) / sizeof(struct ipt_log_names))
+ if (i == ARRAY_SIZE(ipt_log_names))
printf("UNKNOWN level %u ", loginfo->level);
if (loginfo->logflags & IPT_LOG_TCPSEQ)
printf("tcp-sequence ");
diff --git a/extensions/libipt_REJECT.c b/extensions/libipt_REJECT.c
index 5b23f54..888ff39 100644
--- a/extensions/libipt_REJECT.c
+++ b/extensions/libipt_REJECT.c
@@ -56,7 +56,7 @@ print_reject_types(void)
printf("Valid reject types:\n");
- for (i = 0; i < sizeof(reject_table)/sizeof(struct reject_names); i++) {
+ for (i = 0; i < ARRAY_SIZE(reject_table); ++i) {
printf(" %-25s\t%s\n", reject_table[i].name, reject_table[i].desc);
printf(" %-25s\talias\n", reject_table[i].alias);
}
@@ -93,7 +93,7 @@ static int REJECT_parse(int c, char **argv, int invert, unsigned int *flags,
const void *entry, struct xt_entry_target **target)
{
struct ipt_reject_info *reject = (struct ipt_reject_info *)(*target)->data;
- unsigned int limit = sizeof(reject_table)/sizeof(struct reject_names);
+ static const unsigned int limit = ARRAY_SIZE(reject_table);
unsigned int i;
switch(c) {
@@ -128,10 +128,9 @@ static void REJECT_print(const void *ip, const struct xt_entry_target *target,
= (const struct ipt_reject_info *)target->data;
unsigned int i;
- for (i = 0; i < sizeof(reject_table)/sizeof(struct reject_names); i++) {
+ for (i = 0; i < ARRAY_SIZE(reject_table); ++i)
if (reject_table[i].with == reject->with)
break;
- }
printf("reject-with %s ", reject_table[i].name);
}
@@ -141,7 +140,7 @@ static void REJECT_save(const void *ip, const struct xt_entry_target *target)
= (const struct ipt_reject_info *)target->data;
unsigned int i;
- for (i = 0; i < sizeof(reject_table)/sizeof(struct reject_names); i++)
+ for (i = 0; i < ARRAY_SIZE(reject_table); ++i)
if (reject_table[i].with == reject->with)
break;
diff --git a/extensions/libipt_icmp.c b/extensions/libipt_icmp.c
index 15c1787..5667955 100644
--- a/extensions/libipt_icmp.c
+++ b/extensions/libipt_icmp.c
@@ -83,7 +83,7 @@ print_icmptypes(void)
unsigned int i;
printf("Valid ICMP Types:");
- for (i = 0; i < sizeof(icmp_codes)/sizeof(struct icmp_names); i++) {
+ for (i = 0; i < ARRAY_SIZE(icmp_codes); ++i) {
if (i && icmp_codes[i].type == icmp_codes[i-1].type) {
if (icmp_codes[i].code_min == icmp_codes[i-1].code_min
&& (icmp_codes[i].code_max
@@ -115,7 +115,7 @@ static const struct option icmp_opts[] = {
static void
parse_icmp(const char *icmptype, u_int8_t *type, u_int8_t code[])
{
- unsigned int limit = sizeof(icmp_codes)/sizeof(struct icmp_names);
+ static const unsigned int limit = ARRAY_SIZE(icmp_codes);
unsigned int match = limit;
unsigned int i;
@@ -206,16 +206,13 @@ static void print_icmptype(u_int8_t type,
if (!numeric) {
unsigned int i;
- for (i = 0;
- i < sizeof(icmp_codes)/sizeof(struct icmp_names);
- i++) {
+ for (i = 0; i < ARRAY_SIZE(icmp_codes); ++i)
if (icmp_codes[i].type == type
&& icmp_codes[i].code_min == code_min
&& icmp_codes[i].code_max == code_max)
break;
- }
- if (i != sizeof(icmp_codes)/sizeof(struct icmp_names)) {
+ if (i != ARRAY_SIZE(icmp_codes)) {
printf("%s%s ",
invert ? "!" : "",
icmp_codes[i].name);
diff --git a/extensions/libxt_dccp.c b/extensions/libxt_dccp.c
index 413624e..7321145 100644
--- a/extensions/libxt_dccp.c
+++ b/extensions/libxt_dccp.c
@@ -102,13 +102,12 @@ parse_dccp_types(const char *typestring)
for (ptr = strtok(buffer, ","); ptr; ptr = strtok(NULL, ",")) {
unsigned int i;
- for (i = 0; i < sizeof(dccp_pkt_types)/sizeof(char *); i++) {
+ for (i = 0; i < ARRAY_SIZE(dccp_pkt_types); ++i)
if (!strcasecmp(dccp_pkt_types[i], ptr)) {
typemask |= (1 << i);
break;
}
- }
- if (i == sizeof(dccp_pkt_types)/sizeof(char *))
+ if (i == ARRAY_SIZE(dccp_pkt_types))
xtables_error(PARAMETER_PROBLEM,
"Unknown DCCP type `%s'", ptr);
}
diff --git a/extensions/libxt_hashlimit.c b/extensions/libxt_hashlimit.c
index aa56c65..84dd786 100644
--- a/extensions/libxt_hashlimit.c
+++ b/extensions/libxt_hashlimit.c
@@ -485,11 +485,10 @@ static void print_rate(u_int32_t period)
{
unsigned int i;
- for (i = 1; i < sizeof(rates)/sizeof(struct rates); i++) {
+ for (i = 1; i < ARRAY_SIZE(rates); ++i)
if (period > rates[i].mult
|| rates[i].mult/period < rates[i].mult%period)
break;
- }
printf("%u/%s ", rates[i-1].mult / period, rates[i-1].name);
}
diff --git a/extensions/libxt_limit.c b/extensions/libxt_limit.c
index 18224f3..498f009 100644
--- a/extensions/libxt_limit.c
+++ b/extensions/libxt_limit.c
@@ -132,11 +132,10 @@ static void print_rate(u_int32_t period)
{
unsigned int i;
- for (i = 1; i < sizeof(rates)/sizeof(struct rates); i++) {
+ for (i = 1; i < ARRAY_SIZE(rates); ++i)
if (period > rates[i].mult
|| rates[i].mult/period < rates[i].mult%period)
break;
- }
printf("%u/%s ", rates[i-1].mult / period, rates[i-1].name);
}
diff --git a/extensions/libxt_pkttype.c b/extensions/libxt_pkttype.c
index 50af3ed..e3db2aa 100644
--- a/extensions/libxt_pkttype.c
+++ b/extensions/libxt_pkttype.c
@@ -46,11 +46,9 @@ static void print_types(void)
unsigned int i;
printf("Valid packet types:\n");
- for (i = 0; i < sizeof(supported_types)/sizeof(struct pkttypes); i++)
- {
+ for (i = 0; i < ARRAY_SIZE(supported_types); ++i)
if(supported_types[i].printhelp == 1)
printf("\t%-14s\t\t%s\n", supported_types[i].name, supported_types[i].help);
- }
printf("\n");
}
@@ -71,14 +69,12 @@ static void parse_pkttype(const char *pkttype, struct xt_pkttype_info *info)
{
unsigned int i;
- for (i = 0; i < sizeof(supported_types)/sizeof(struct pkttypes); i++)
- {
+ for (i = 0; i < ARRAY_SIZE(supported_types); ++i)
if(strcasecmp(pkttype, supported_types[i].name)==0)
{
info->pkttype=supported_types[i].pkttype;
return;
}
- }
xtables_error(PARAMETER_PROBLEM, "Bad packet type '%s'", pkttype);
}
@@ -115,14 +111,12 @@ static void print_pkttype(const struct xt_pkttype_info *info)
{
unsigned int i;
- for (i = 0; i < sizeof(supported_types)/sizeof(struct pkttypes); i++)
- {
+ for (i = 0; i < ARRAY_SIZE(supported_types); ++i)
if(supported_types[i].pkttype==info->pkttype)
{
printf("%s ", supported_types[i].name);
return;
}
- }
printf("%d ", info->pkttype); /* in case we didn't find an entry in named-packtes */
}
diff --git a/extensions/libxt_sctp.c b/extensions/libxt_sctp.c
index b889406..829eade 100644
--- a/extensions/libxt_sctp.c
+++ b/extensions/libxt_sctp.c
@@ -17,20 +17,8 @@
#include <netinet/in.h>
#include <xtables.h>
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
#include <linux/netfilter/xt_sctp.h>
-/* Some ZS!#@:$%*#$! has replaced the ELEMCOUNT macro in ipt_sctp.h with
- * ARRAY_SIZE without noticing that this file is used from userspace,
- * and userspace doesn't have ARRAY_SIZE */
-
-#ifndef ELEMCOUNT
-#define ELEMCOUNT ARRAY_SIZE
-#endif
-
#if 0
#define DEBUGP(format, first...) printf(format, ##first)
#define static
@@ -198,7 +186,7 @@ parse_sctp_chunk(struct xt_sctp_info *einfo,
*chunk_flags++ = 0;
}
- for (i = 0; i < ELEMCOUNT(sctp_chunk_names); i++) {
+ for (i = 0; i < ARRAY_SIZE(sctp_chunk_names); ++i)
if (strcasecmp(sctp_chunk_names[i].name, ptr) == 0) {
DEBUGP("Chunk num %d\n", sctp_chunk_names[i].chunk_type);
SCTP_CHUNKMAP_SET(einfo->chunkmap,
@@ -206,7 +194,6 @@ parse_sctp_chunk(struct xt_sctp_info *einfo,
found = 1;
break;
}
- }
if (!found)
xtables_error(PARAMETER_PROBLEM,
"Unknown sctp chunk `%s'", ptr);
@@ -389,10 +376,9 @@ print_chunk(u_int32_t chunknum, int numeric)
else {
int i;
- for (i = 0; i < ELEMCOUNT(sctp_chunk_names); i++) {
+ for (i = 0; i < ARRAY_SIZE(sctp_chunk_names); ++i)
if (sctp_chunk_names[i].chunk_type == chunknum)
printf("%s", sctp_chunk_names[chunknum].name);
- }
}
}
diff --git a/extensions/libxt_tcp.c b/extensions/libxt_tcp.c
index d2ad53b..5ea9ebd 100644
--- a/extensions/libxt_tcp.c
+++ b/extensions/libxt_tcp.c
@@ -86,18 +86,15 @@ parse_tcp_flag(const char *flags)
for (ptr = strtok(buffer, ","); ptr; ptr = strtok(NULL, ",")) {
unsigned int i;
- for (i = 0;
- i < sizeof(tcp_flag_names)/sizeof(struct tcp_flag_names);
- i++) {
+ for (i = 0; i < ARRAY_SIZE(tcp_flag_names); ++i)
if (strcasecmp(tcp_flag_names[i].name, ptr) == 0) {
ret |= tcp_flag_names[i].flag;
break;
}
- }
- if (i == sizeof(tcp_flag_names)/sizeof(struct tcp_flag_names))
+ if (i == ARRAY_SIZE(tcp_flag_names))
xtables_error(PARAMETER_PROBLEM,
"Unknown TCP flag `%s'", ptr);
- }
+ }
free(buffer);
return ret;
diff --git a/ip6tables-restore.c b/ip6tables-restore.c
index 324dd1f..1d5efea 100644
--- a/ip6tables-restore.c
+++ b/ip6tables-restore.c
@@ -99,7 +99,7 @@ static int newargc;
* returns true if argument added, false otherwise */
static int add_argv(char *what) {
DEBUGP("add_argv: %s\n", what);
- if (what && ((newargc + 1) < sizeof(newargv)/sizeof(char *))) {
+ if (what && newargc + 1 < ARRAY_SIZE(newargv)) {
newargv[newargc] = strdup(what);
newargc++;
return 1;
diff --git a/iptables-restore.c b/iptables-restore.c
index f1c5e3e..2a797cc 100644
--- a/iptables-restore.c
+++ b/iptables-restore.c
@@ -99,7 +99,7 @@ static int newargc;
* returns true if argument added, false otherwise */
static int add_argv(char *what) {
DEBUGP("add_argv: %s\n", what);
- if (what && ((newargc + 1) < sizeof(newargv)/sizeof(char *))) {
+ if (what && newargc + 1 < ARRAY_SIZE(newargv)) {
newargv[newargc] = strdup(what);
newargc++;
return 1;
diff --git a/iptables-xml.c b/iptables-xml.c
index 543715b..e5d1941 100644
--- a/iptables-xml.c
+++ b/iptables-xml.c
@@ -110,7 +110,7 @@ static int
add_argv(char *what, int quoted)
{
DEBUGP("add_argv: %d %s\n", newargc, what);
- if (what && ((newargc + 1) < sizeof(newargv) / sizeof(char *))) {
+ if (what && newargc + 1 < ARRAY_SIZE(newargv)) {
newargv[newargc] = strdup(what);
newargvattr[newargc] = quoted;
newargc++;
--
1.6.3.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/5] addrtype: fix one manpage type
2009-05-26 11:26 pull: minor tidbits Jan Engelhardt
` (2 preceding siblings ...)
2009-05-26 11:26 ` [PATCH 3/5] iptables: replace open-coded sizeof by ARRAY_SIZE Jan Engelhardt
@ 2009-05-26 11:26 ` Jan Engelhardt
2009-05-26 11:26 ` [PATCH 5/5] manpages: do not include v4-only modules in ip6tables manpage Jan Engelhardt
2009-05-26 11:37 ` pull: minor tidbits Pablo Neira Ayuso
5 siblings, 0 replies; 9+ messages in thread
From: Jan Engelhardt @ 2009-05-26 11:26 UTC (permalink / raw
To: kaber; +Cc: netfilter-devel
References: http://bugs.debian.org/528457
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
extensions/libipt_addrtype.man | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/extensions/libipt_addrtype.man b/extensions/libipt_addrtype.man
index 731f9b1..16fd9df 100644
--- a/extensions/libipt_addrtype.man
+++ b/extensions/libipt_addrtype.man
@@ -58,7 +58,7 @@ chains. It cannot be specified with the
option.
.TP
\fB\-\-limit\-iface\-out\fP
-The address type checiking can be limited to the interface the packet is going
+The address type checking can be limited to the interface the packet is going
out. This option is only valid in the
.BR POSTROUTING ,
.B OUTPUT
--
1.6.3.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/5] manpages: do not include v4-only modules in ip6tables manpage
2009-05-26 11:26 pull: minor tidbits Jan Engelhardt
` (3 preceding siblings ...)
2009-05-26 11:26 ` [PATCH 4/5] addrtype: fix one manpage type Jan Engelhardt
@ 2009-05-26 11:26 ` Jan Engelhardt
2009-05-26 11:37 ` pull: minor tidbits Pablo Neira Ayuso
5 siblings, 0 replies; 9+ messages in thread
From: Jan Engelhardt @ 2009-05-26 11:26 UTC (permalink / raw
To: kaber; +Cc: netfilter-devel
References: http://bugs.debian.org/529954
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
extensions/GNUmakefile.in | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/extensions/GNUmakefile.in b/extensions/GNUmakefile.in
index 66a4f46..8d7f21d 100644
--- a/extensions/GNUmakefile.in
+++ b/extensions/GNUmakefile.in
@@ -161,7 +161,7 @@ man_run = \
${AM_VERBOSE_GEN} \
for ext in $(1); do \
f="${srcdir}/libxt_$$ext.man"; \
- if [ -f "$$f" ]; then \
+ if [ -f "$$f" ] && grep -q "$(3)" "$$f"; then \
echo ".SS $$ext"; \
cat "$$f"; \
continue; \
@@ -175,13 +175,13 @@ man_run = \
done >$@;
matches4.man: .initext4.dd $(wildcard ${srcdir}/lib*.man)
- $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf4_build_mod}),ip)
+ $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf4_build_mod}),ip,NFPROTO_IPV4)
matches6.man: .initext6.dd $(wildcard ${srcdir}/lib*.man)
- $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf6_build_mod}),ip6)
+ $(call man_run,$(call ex_matches,${pfx_build_mod} ${pf6_build_mod}),ip6,NFPROTO_IPV6)
targets4.man: .initext4.dd $(wildcard ${srcdir}/lib*.man)
- $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf4_build_mod}),ip)
+ $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf4_build_mod}),ip,NFPROTO_IPV4)
targets6.man: .initext6.dd $(wildcard ${srcdir}/lib*.man)
- $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf6_build_mod}),ip6)
+ $(call man_run,$(call ex_targets,${pfx_build_mod} ${pf6_build_mod}),ip6,NFPROTO_IPV6)
--
1.6.3.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: pull: minor tidbits
2009-05-26 11:26 pull: minor tidbits Jan Engelhardt
` (4 preceding siblings ...)
2009-05-26 11:26 ` [PATCH 5/5] manpages: do not include v4-only modules in ip6tables manpage Jan Engelhardt
@ 2009-05-26 11:37 ` Pablo Neira Ayuso
2009-05-26 12:08 ` Pablo Neira Ayuso
5 siblings, 1 reply; 9+ messages in thread
From: Pablo Neira Ayuso @ 2009-05-26 11:37 UTC (permalink / raw
To: Jan Engelhardt; +Cc: kaber, netfilter-devel
Hi Jan,
Jan Engelhardt wrote:
> Please pull from
> git://dev.medozas.de/iptables master
>
> to receive non-API-touching minor cosmetics and a few fixes
> to recently-reported issues:
>
> xtables: use extern "C"
> extensions: add const qualifiers in print/save functions
> iptables: replace open-coded sizeof by ARRAY_SIZE
> addrtype: fix one manpage type
> manpages: do not include v4-only modules in ip6tables manpage
This all look sane to me :). I'm going to apply them unless Patrick does
it faster than me ;).
BTW, one minor cosmetic comment:
+ for (i = 0; i < ARRAY_SIZE(sctp_chunk_names); ++i)
if (strcasecmp(sctp_chunk_names[i].name, ptr) == 0) {
DEBUGP("Chunk num %d\n", sctp_chunk_names[i].chunk_type);
SCTP_CHUNKMAP_SET(einfo->chunkmap,
@@ -206,7 +194,6 @@ parse_sctp_chunk(struct xt_sctp_info *einfo,
found = 1;
break;
}
- }
I like the brackets in the for() statement, it's good to disambiguate.
--
"Los honestos son inadaptados sociales" -- Les Luthiers
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: pull: minor tidbits
2009-05-26 11:37 ` pull: minor tidbits Pablo Neira Ayuso
@ 2009-05-26 12:08 ` Pablo Neira Ayuso
2009-05-26 13:08 ` Jan Engelhardt
0 siblings, 1 reply; 9+ messages in thread
From: Pablo Neira Ayuso @ 2009-05-26 12:08 UTC (permalink / raw
To: Jan Engelhardt; +Cc: kaber, netfilter-devel
Pablo Neira Ayuso wrote:
> Hi Jan,
>
> Jan Engelhardt wrote:
>> Please pull from
>> git://dev.medozas.de/iptables master
>>
>> to receive non-API-touching minor cosmetics and a few fixes
>> to recently-reported issues:
>>
>> xtables: use extern "C"
>> extensions: add const qualifiers in print/save functions
>> iptables: replace open-coded sizeof by ARRAY_SIZE
>> addrtype: fix one manpage type
>> manpages: do not include v4-only modules in ip6tables manpage
>
> This all look sane to me :). I'm going to apply them unless Patrick does
> it faster than me ;).
>
> BTW, one minor cosmetic comment:
> + for (i = 0; i < ARRAY_SIZE(sctp_chunk_names); ++i)
> if (strcasecmp(sctp_chunk_names[i].name, ptr) == 0) {
> DEBUGP("Chunk num %d\n", sctp_chunk_names[i].chunk_type);
> SCTP_CHUNKMAP_SET(einfo->chunkmap,
> @@ -206,7 +194,6 @@ parse_sctp_chunk(struct xt_sctp_info *einfo,
> found = 1;
> break;
> }
> - }
>
> I like the brackets in the for() statement, it's good to disambiguate.
BTW:
@@ -75,7 +75,7 @@ static void mh_init(struct xt_entry_match *m)
static unsigned int name_to_type(const char *name)
{
int namelen = strlen(name);
- unsigned int limit = sizeof(mh_names)/sizeof(struct mh_name);
+ static const unsigned int limit = ARRAY_SIZE(mh_names);
unsigned int match = limit;
unsigned int i;
The use of static here looks to me like a clever trick to avoid
recalculations? I think this is a bit of abuse of static, the compiler
itself should notice this and avoid re-calculations.
--
"Los honestos son inadaptados sociales" -- Les Luthiers
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: pull: minor tidbits
2009-05-26 12:08 ` Pablo Neira Ayuso
@ 2009-05-26 13:08 ` Jan Engelhardt
0 siblings, 0 replies; 9+ messages in thread
From: Jan Engelhardt @ 2009-05-26 13:08 UTC (permalink / raw
To: Pablo Neira Ayuso; +Cc: kaber, netfilter-devel
On Tuesday 2009-05-26 14:08, Pablo Neira Ayuso wrote:
>
>@@ -75,7 +75,7 @@ static void mh_init(struct xt_entry_match *m)
> static unsigned int name_to_type(const char *name)
> {
> int namelen = strlen(name);
>- unsigned int limit = sizeof(mh_names)/sizeof(struct mh_name);
>+ static const unsigned int limit = ARRAY_SIZE(mh_names);
> unsigned int match = limit;
> unsigned int i;
>
>The use of static here looks to me like a clever trick to avoid
>recalculations? I think this is a bit of abuse of static, the compiler
>itself should notice this and avoid re-calculations.
If you never take the address of limit, the static keyword is just
added safety sugar for when you do. Compiler does not recalculate
anything even without it, it's merely a hint to put it into the
right section, instead of the stack.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2009-05-26 13:08 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-26 11:26 pull: minor tidbits Jan Engelhardt
2009-05-26 11:26 ` [PATCH 1/5] xtables: use extern "C" Jan Engelhardt
2009-05-26 11:26 ` [PATCH 2/5] extensions: add const qualifiers in print/save functions Jan Engelhardt
2009-05-26 11:26 ` [PATCH 3/5] iptables: replace open-coded sizeof by ARRAY_SIZE Jan Engelhardt
2009-05-26 11:26 ` [PATCH 4/5] addrtype: fix one manpage type Jan Engelhardt
2009-05-26 11:26 ` [PATCH 5/5] manpages: do not include v4-only modules in ip6tables manpage Jan Engelhardt
2009-05-26 11:37 ` pull: minor tidbits Pablo Neira Ayuso
2009-05-26 12:08 ` Pablo Neira Ayuso
2009-05-26 13:08 ` Jan Engelhardt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.