Skip to content

Commit be91fd5

Browse files
author
Jan Engelhardt
committed
netfilter: xtables: replace custom duprintf with pr_debug
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
1 parent 85bc3f3 commit be91fd5

7 files changed

Lines changed: 41 additions & 79 deletions

File tree

‎net/ipv4/netfilter/ipt_ah.c‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* it under the terms of the GNU General Public License version 2 as
66
* published by the Free Software Foundation.
77
*/
8-
8+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
99
#include <linux/in.h>
1010
#include <linux/module.h>
1111
#include <linux/skbuff.h>
@@ -18,21 +18,15 @@ MODULE_LICENSE("GPL");
1818
MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>");
1919
MODULE_DESCRIPTION("Xtables: IPv4 IPsec-AH SPI match");
2020

21-
#ifdef DEBUG_CONNTRACK
22-
#define duprintf(format, args...) printk(format , ## args)
23-
#else
24-
#define duprintf(format, args...)
25-
#endif
26-
2721
/* Returns 1 if the spi is matched by the range, 0 otherwise */
2822
static inline bool
2923
spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
3024
{
3125
bool r;
32-
duprintf("ah spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ',
33-
min,spi,max);
26+
pr_debug("spi_match:%c 0x%x <= 0x%x <= 0x%x\n",
27+
invert ? '!' : ' ', min, spi, max);
3428
r=(spi >= min && spi <= max) ^ invert;
35-
duprintf(" result %s\n",r? "PASS" : "FAILED");
29+
pr_debug(" result %s\n", r ? "PASS" : "FAILED");
3630
return r;
3731
}
3832

@@ -51,7 +45,7 @@ static bool ah_mt(const struct sk_buff *skb, const struct xt_match_param *par)
5145
/* We've been asked to examine this packet, and we
5246
* can't. Hence, no choice but to drop.
5347
*/
54-
duprintf("Dropping evil AH tinygram.\n");
48+
pr_debug("Dropping evil AH tinygram.\n");
5549
*par->hotdrop = true;
5650
return 0;
5751
}
@@ -67,7 +61,7 @@ static bool ah_mt_check(const struct xt_mtchk_param *par)
6761

6862
/* Must specify no unknown invflags */
6963
if (ahinfo->invflags & ~IPT_AH_INV_MASK) {
70-
duprintf("ipt_ah: unknown flags %X\n", ahinfo->invflags);
64+
pr_debug("unknown flags %X\n", ahinfo->invflags);
7165
return false;
7266
}
7367
return true;

‎net/ipv6/netfilter/ip6t_mh.c‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Based on net/netfilter/xt_tcpudp.c
1212
*
1313
*/
14+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1415
#include <linux/types.h>
1516
#include <linux/module.h>
1617
#include <net/ip.h>
@@ -24,12 +25,6 @@
2425
MODULE_DESCRIPTION("Xtables: IPv6 Mobility Header match");
2526
MODULE_LICENSE("GPL");
2627

27-
#ifdef DEBUG_IP_FIREWALL_USER
28-
#define duprintf(format, args...) printk(format , ## args)
29-
#else
30-
#define duprintf(format, args...)
31-
#endif
32-
3328
/* Returns 1 if the type is matched by the range, 0 otherwise */
3429
static inline bool
3530
type_match(u_int8_t min, u_int8_t max, u_int8_t type, bool invert)
@@ -51,13 +46,13 @@ static bool mh_mt6(const struct sk_buff *skb, const struct xt_match_param *par)
5146
if (mh == NULL) {
5247
/* We've been asked to examine this packet, and we
5348
can't. Hence, no choice but to drop. */
54-
duprintf("Dropping evil MH tinygram.\n");
49+
pr_debug("Dropping evil MH tinygram.\n");
5550
*par->hotdrop = true;
5651
return false;
5752
}
5853

5954
if (mh->ip6mh_proto != IPPROTO_NONE) {
60-
duprintf("Dropping invalid MH Payload Proto: %u\n",
55+
pr_debug("Dropping invalid MH Payload Proto: %u\n",
6156
mh->ip6mh_proto);
6257
*par->hotdrop = true;
6358
return false;

‎net/netfilter/x_tables.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* published by the Free Software Foundation.
1313
*
1414
*/
15-
15+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1616
#include <linux/kernel.h>
1717
#include <linux/socket.h>
1818
#include <linux/net.h>
@@ -54,12 +54,6 @@ struct xt_af {
5454

5555
static struct xt_af *xt;
5656

57-
#ifdef DEBUG_IP_FIREWALL_USER
58-
#define duprintf(format, args...) printk(format , ## args)
59-
#else
60-
#define duprintf(format, args...)
61-
#endif
62-
6357
static const char *const xt_prefix[NFPROTO_NUMPROTO] = {
6458
[NFPROTO_UNSPEC] = "x",
6559
[NFPROTO_IPV4] = "ip",
@@ -720,7 +714,7 @@ xt_replace_table(struct xt_table *table,
720714

721715
/* Check inside lock: is the old number correct? */
722716
if (num_counters != private->number) {
723-
duprintf("num_counters != table->private->number (%u/%u)\n",
717+
pr_debug("num_counters != table->private->number (%u/%u)\n",
724718
num_counters, private->number);
725719
local_bh_enable();
726720
*error = -EAGAIN;
@@ -777,7 +771,7 @@ struct xt_table *xt_register_table(struct net *net,
777771
goto unlock;
778772

779773
private = table->private;
780-
duprintf("table->private->number = %u\n", private->number);
774+
pr_debug("table->private->number = %u\n", private->number);
781775

782776
/* save number of initial entries */
783777
private->initial_entries = private->number;

‎net/netfilter/xt_esp.c‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* it under the terms of the GNU General Public License version 2 as
77
* published by the Free Software Foundation.
88
*/
9-
9+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1010
#include <linux/module.h>
1111
#include <linux/skbuff.h>
1212
#include <linux/in.h>
@@ -24,21 +24,15 @@ MODULE_DESCRIPTION("Xtables: IPsec-ESP packet match");
2424
MODULE_ALIAS("ipt_esp");
2525
MODULE_ALIAS("ip6t_esp");
2626

27-
#if 0
28-
#define duprintf(format, args...) printk(format , ## args)
29-
#else
30-
#define duprintf(format, args...)
31-
#endif
32-
3327
/* Returns 1 if the spi is matched by the range, 0 otherwise */
3428
static inline bool
3529
spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
3630
{
3731
bool r;
38-
duprintf("esp spi_match:%c 0x%x <= 0x%x <= 0x%x", invert ? '!' : ' ',
39-
min, spi, max);
32+
pr_debug("esp spi_match:%c 0x%x <= 0x%x <= 0x%x\n",
33+
invert ? '!' : ' ', min, spi, max);
4034
r = (spi >= min && spi <= max) ^ invert;
41-
duprintf(" result %s\n", r ? "PASS" : "FAILED");
35+
pr_debug(" result %s\n", r ? "PASS" : "FAILED");
4236
return r;
4337
}
4438

@@ -57,7 +51,7 @@ static bool esp_mt(const struct sk_buff *skb, const struct xt_match_param *par)
5751
/* We've been asked to examine this packet, and we
5852
* can't. Hence, no choice but to drop.
5953
*/
60-
duprintf("Dropping evil ESP tinygram.\n");
54+
pr_debug("Dropping evil ESP tinygram.\n");
6155
*par->hotdrop = true;
6256
return false;
6357
}
@@ -71,7 +65,7 @@ static bool esp_mt_check(const struct xt_mtchk_param *par)
7165
const struct xt_esp *espinfo = par->matchinfo;
7266

7367
if (espinfo->invflags & ~XT_ESP_INV_MASK) {
74-
duprintf("xt_esp: unknown flags %X\n", espinfo->invflags);
68+
pr_debug("unknown flags %X\n", espinfo->invflags);
7569
return false;
7670
}
7771

‎net/netfilter/xt_multiport.c‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* it under the terms of the GNU General Public License version 2 as
99
* published by the Free Software Foundation.
1010
*/
11-
11+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1212
#include <linux/module.h>
1313
#include <linux/types.h>
1414
#include <linux/udp.h>
@@ -26,12 +26,6 @@ MODULE_DESCRIPTION("Xtables: multiple port matching for TCP, UDP, UDP-Lite, SCTP
2626
MODULE_ALIAS("ipt_multiport");
2727
MODULE_ALIAS("ip6t_multiport");
2828

29-
#if 0
30-
#define duprintf(format, args...) printk(format , ## args)
31-
#else
32-
#define duprintf(format, args...)
33-
#endif
34-
3529
/* Returns 1 if the port is matched by the test, 0 otherwise. */
3630
static inline bool
3731
ports_match_v0(const u_int16_t *portlist, enum xt_multiport_flags flags,
@@ -63,7 +57,7 @@ ports_match_v1(const struct xt_multiport_v1 *minfo,
6357
if (minfo->pflags[i]) {
6458
/* range port matching */
6559
e = minfo->ports[++i];
66-
duprintf("src or dst matches with %d-%d?\n", s, e);
60+
pr_debug("src or dst matches with %d-%d?\n", s, e);
6761

6862
if (minfo->flags == XT_MULTIPORT_SOURCE
6963
&& src >= s && src <= e)
@@ -77,7 +71,7 @@ ports_match_v1(const struct xt_multiport_v1 *minfo,
7771
return true ^ minfo->invert;
7872
} else {
7973
/* exact port matching */
80-
duprintf("src or dst matches with %d?\n", s);
74+
pr_debug("src or dst matches with %d?\n", s);
8175

8276
if (minfo->flags == XT_MULTIPORT_SOURCE
8377
&& src == s)
@@ -109,7 +103,7 @@ multiport_mt_v0(const struct sk_buff *skb, const struct xt_match_param *par)
109103
/* We've been asked to examine this packet, and we
110104
* can't. Hence, no choice but to drop.
111105
*/
112-
duprintf("xt_multiport: Dropping evil offset=0 tinygram.\n");
106+
pr_debug("Dropping evil offset=0 tinygram.\n");
113107
*par->hotdrop = true;
114108
return false;
115109
}
@@ -133,7 +127,7 @@ multiport_mt(const struct sk_buff *skb, const struct xt_match_param *par)
133127
/* We've been asked to examine this packet, and we
134128
* can't. Hence, no choice but to drop.
135129
*/
136-
duprintf("xt_multiport: Dropping evil offset=0 tinygram.\n");
130+
pr_debug("Dropping evil offset=0 tinygram.\n");
137131
*par->hotdrop = true;
138132
return false;
139133
}

‎net/netfilter/xt_sctp.c‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
#include <linux/module.h>
23
#include <linux/skbuff.h>
34
#include <net/ip.h>
@@ -15,12 +16,6 @@ MODULE_DESCRIPTION("Xtables: SCTP protocol packet match");
1516
MODULE_ALIAS("ipt_sctp");
1617
MODULE_ALIAS("ip6t_sctp");
1718

18-
#ifdef DEBUG_SCTP
19-
#define duprintf(format, args...) printk(format , ## args)
20-
#else
21-
#define duprintf(format, args...)
22-
#endif
23-
2419
#define SCCHECK(cond, option, flag, invflag) (!((flag) & (option)) \
2520
|| (!!((invflag) & (option)) ^ (cond)))
2621

@@ -52,7 +47,7 @@ match_packet(const struct sk_buff *skb,
5247
const struct xt_sctp_flag_info *flag_info = info->flag_info;
5348
int flag_count = info->flag_count;
5449

55-
#ifdef DEBUG_SCTP
50+
#ifdef DEBUG
5651
int i = 0;
5752
#endif
5853

@@ -62,17 +57,19 @@ match_packet(const struct sk_buff *skb,
6257
do {
6358
sch = skb_header_pointer(skb, offset, sizeof(_sch), &_sch);
6459
if (sch == NULL || sch->length == 0) {
65-
duprintf("Dropping invalid SCTP packet.\n");
60+
pr_debug("Dropping invalid SCTP packet.\n");
6661
*hotdrop = true;
6762
return false;
6863
}
69-
70-
duprintf("Chunk num: %d\toffset: %d\ttype: %d\tlength: %d\tflags: %x\n",
71-
++i, offset, sch->type, htons(sch->length), sch->flags);
72-
64+
#ifdef DEBUG
65+
pr_debug("Chunk num: %d\toffset: %d\ttype: %d\tlength: %d"
66+
"\tflags: %x\n",
67+
++i, offset, sch->type, htons(sch->length),
68+
sch->flags);
69+
#endif
7370
offset += (ntohs(sch->length) + 3) & ~3;
7471

75-
duprintf("skb->len: %d\toffset: %d\n", skb->len, offset);
72+
pr_debug("skb->len: %d\toffset: %d\n", skb->len, offset);
7673

7774
if (SCTP_CHUNKMAP_IS_SET(info->chunkmap, sch->type)) {
7875
switch (chunk_match_type) {
@@ -124,17 +121,17 @@ sctp_mt(const struct sk_buff *skb, const struct xt_match_param *par)
124121
sctp_sctphdr_t _sh;
125122

126123
if (par->fragoff != 0) {
127-
duprintf("Dropping non-first fragment.. FIXME\n");
124+
pr_debug("Dropping non-first fragment.. FIXME\n");
128125
return false;
129126
}
130127

131128
sh = skb_header_pointer(skb, par->thoff, sizeof(_sh), &_sh);
132129
if (sh == NULL) {
133-
duprintf("Dropping evil TCP offset=0 tinygram.\n");
130+
pr_debug("Dropping evil TCP offset=0 tinygram.\n");
134131
*par->hotdrop = true;
135132
return false;
136133
}
137-
duprintf("spt: %d\tdpt: %d\n", ntohs(sh->source), ntohs(sh->dest));
134+
pr_debug("spt: %d\tdpt: %d\n", ntohs(sh->source), ntohs(sh->dest));
138135

139136
return SCCHECK(ntohs(sh->source) >= info->spts[0]
140137
&& ntohs(sh->source) <= info->spts[1],

‎net/netfilter/xt_tcpudp.c‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
#include <linux/types.h>
23
#include <linux/module.h>
34
#include <net/ip.h>
@@ -19,13 +20,6 @@ MODULE_ALIAS("ipt_tcp");
1920
MODULE_ALIAS("ip6t_udp");
2021
MODULE_ALIAS("ip6t_tcp");
2122

22-
#ifdef DEBUG_IP_FIREWALL_USER
23-
#define duprintf(format, args...) printk(format , ## args)
24-
#else
25-
#define duprintf(format, args...)
26-
#endif
27-
28-
2923
/* Returns 1 if the port is matched by the range, 0 otherwise */
3024
static inline bool
3125
port_match(u_int16_t min, u_int16_t max, u_int16_t port, bool invert)
@@ -46,7 +40,7 @@ tcp_find_option(u_int8_t option,
4640
u_int8_t _opt[60 - sizeof(struct tcphdr)];
4741
unsigned int i;
4842

49-
duprintf("tcp_match: finding option\n");
43+
pr_debug("finding option\n");
5044

5145
if (!optlen)
5246
return invert;
@@ -82,7 +76,7 @@ static bool tcp_mt(const struct sk_buff *skb, const struct xt_match_param *par)
8276
flag overwrite to pass the direction checks.
8377
*/
8478
if (par->fragoff == 1) {
85-
duprintf("Dropping evil TCP offset=1 frag.\n");
79+
pr_debug("Dropping evil TCP offset=1 frag.\n");
8680
*par->hotdrop = true;
8781
}
8882
/* Must not be a fragment. */
@@ -95,7 +89,7 @@ static bool tcp_mt(const struct sk_buff *skb, const struct xt_match_param *par)
9589
if (th == NULL) {
9690
/* We've been asked to examine this packet, and we
9791
can't. Hence, no choice but to drop. */
98-
duprintf("Dropping evil TCP offset=0 tinygram.\n");
92+
pr_debug("Dropping evil TCP offset=0 tinygram.\n");
9993
*par->hotdrop = true;
10094
return false;
10195
}
@@ -148,7 +142,7 @@ static bool udp_mt(const struct sk_buff *skb, const struct xt_match_param *par)
148142
if (uh == NULL) {
149143
/* We've been asked to examine this packet, and we
150144
can't. Hence, no choice but to drop. */
151-
duprintf("Dropping evil UDP tinygram.\n");
145+
pr_debug("Dropping evil UDP tinygram.\n");
152146
*par->hotdrop = true;
153147
return false;
154148
}

0 commit comments

Comments
 (0)