Skip to content

Commit 5191d70

Browse files
ArushiSinghalummakynes
authored andcommitted
netfilter: Replace printk() with pr_*() and define pr_fmt()
Using pr_<loglevel>() is more concise than printk(KERN_<LOGLEVEL>). This patch: * Replace printks having a log level with the appropriate pr_*() macros. * Define pr_fmt() to include relevant name. * Remove redundant prefixes from pr_*() calls. * Indent the code where possible. * Remove the useless output messages. * Remove periods from messages. Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 472a73e commit 5191d70

8 files changed

Lines changed: 37 additions & 26 deletions

File tree

‎net/netfilter/nf_conntrack_acct.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* published by the Free Software Foundation.
99
*/
1010

11+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12+
1113
#include <linux/netfilter.h>
1214
#include <linux/slab.h>
1315
#include <linux/kernel.h>
@@ -80,7 +82,7 @@ static int nf_conntrack_acct_init_sysctl(struct net *net)
8082
net->ct.acct_sysctl_header = register_net_sysctl(net, "net/netfilter",
8183
table);
8284
if (!net->ct.acct_sysctl_header) {
83-
printk(KERN_ERR "nf_conntrack_acct: can't register to sysctl.\n");
85+
pr_err("can't register to sysctl\n");
8486
goto out_register;
8587
}
8688
return 0;
@@ -125,7 +127,7 @@ int nf_conntrack_acct_init(void)
125127
{
126128
int ret = nf_ct_extend_register(&acct_extend);
127129
if (ret < 0)
128-
pr_err("nf_conntrack_acct: Unable to register extension\n");
130+
pr_err("Unable to register extension\n");
129131
return ret;
130132
}
131133

‎net/netfilter/nf_conntrack_ecache.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* published by the Free Software Foundation.
1212
*/
1313

14+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15+
1416
#include <linux/types.h>
1517
#include <linux/netfilter.h>
1618
#include <linux/skbuff.h>
@@ -372,7 +374,7 @@ static int nf_conntrack_event_init_sysctl(struct net *net)
372374
net->ct.event_sysctl_header =
373375
register_net_sysctl(net, "net/netfilter", table);
374376
if (!net->ct.event_sysctl_header) {
375-
printk(KERN_ERR "nf_ct_event: can't register to sysctl.\n");
377+
pr_err("can't register to sysctl\n");
376378
goto out_register;
377379
}
378380
return 0;
@@ -419,7 +421,7 @@ int nf_conntrack_ecache_init(void)
419421
{
420422
int ret = nf_ct_extend_register(&event_extend);
421423
if (ret < 0)
422-
pr_err("nf_ct_event: Unable to register event extension.\n");
424+
pr_err("Unable to register event extension\n");
423425

424426
BUILD_BUG_ON(__IPCT_MAX >= 16); /* ctmask, missed use u16 */
425427

‎net/netfilter/nf_conntrack_timestamp.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* published by the Free Software Foundation (or any later at your option).
77
*/
88

9+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10+
911
#include <linux/netfilter.h>
1012
#include <linux/slab.h>
1113
#include <linux/kernel.h>
@@ -58,7 +60,7 @@ static int nf_conntrack_tstamp_init_sysctl(struct net *net)
5860
net->ct.tstamp_sysctl_header = register_net_sysctl(net, "net/netfilter",
5961
table);
6062
if (!net->ct.tstamp_sysctl_header) {
61-
printk(KERN_ERR "nf_ct_tstamp: can't register to sysctl.\n");
63+
pr_err("can't register to sysctl\n");
6264
goto out_register;
6365
}
6466
return 0;
@@ -104,7 +106,7 @@ int nf_conntrack_tstamp_init(void)
104106
int ret;
105107
ret = nf_ct_extend_register(&tstamp_extend);
106108
if (ret < 0)
107-
pr_err("nf_ct_tstamp: Unable to register extension\n");
109+
pr_err("Unable to register extension\n");
108110
return ret;
109111
}
110112

‎net/netfilter/nf_nat_core.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* published by the Free Software Foundation.
99
*/
1010

11+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12+
1113
#include <linux/module.h>
1214
#include <linux/types.h>
1315
#include <linux/timer.h>
@@ -814,7 +816,7 @@ static int __init nf_nat_init(void)
814816
ret = nf_ct_extend_register(&nat_extend);
815817
if (ret < 0) {
816818
nf_ct_free_hashtable(nf_nat_bysource, nf_nat_htable_size);
817-
printk(KERN_ERR "nf_nat_core: Unable to register extension\n");
819+
pr_err("Unable to register extension\n");
818820
return ret;
819821
}
820822

‎net/netfilter/nf_nat_ftp.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* published by the Free Software Foundation.
99
*/
1010

11+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12+
1113
#include <linux/module.h>
1214
#include <linux/moduleparam.h>
1315
#include <linux/inet.h>
@@ -71,7 +73,7 @@ static unsigned int nf_nat_ftp(struct sk_buff *skb,
7173
char buffer[sizeof("|1||65535|") + INET6_ADDRSTRLEN];
7274
unsigned int buflen;
7375

74-
pr_debug("FTP_NAT: type %i, off %u len %u\n", type, matchoff, matchlen);
76+
pr_debug("type %i, off %u len %u\n", type, matchoff, matchlen);
7577

7678
/* Connection will come from wherever this packet goes, hence !dir */
7779
newaddr = ct->tuplehash[!dir].tuple.dst.u3;
@@ -136,8 +138,7 @@ static int __init nf_nat_ftp_init(void)
136138
/* Prior to 2.6.11, we had a ports param. No longer, but don't break users. */
137139
static int warn_set(const char *val, const struct kernel_param *kp)
138140
{
139-
printk(KERN_INFO KBUILD_MODNAME
140-
": kernel >= 2.6.10 only uses 'ports' for conntrack modules\n");
141+
pr_info("kernel >= 2.6.10 only uses 'ports' for conntrack modules\n");
141142
return 0;
142143
}
143144
module_param_call(ports, warn_set, NULL, NULL, 0);

‎net/netfilter/nf_nat_irc.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* 2 of the License, or (at your option) any later version.
1111
*/
1212

13+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14+
1315
#include <linux/module.h>
1416
#include <linux/moduleparam.h>
1517
#include <linux/tcp.h>
@@ -79,7 +81,7 @@ static unsigned int help(struct sk_buff *skb,
7981
*/
8082
/* AAA = "us", ie. where server normally talks to. */
8183
snprintf(buffer, sizeof(buffer), "%u %u", ntohl(newaddr.ip), port);
82-
pr_debug("nf_nat_irc: inserting '%s' == %pI4, port %u\n",
84+
pr_debug("inserting '%s' == %pI4, port %u\n",
8385
buffer, &newaddr.ip, port);
8486

8587
if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo, protoff, matchoff,
@@ -108,8 +110,7 @@ static int __init nf_nat_irc_init(void)
108110
/* Prior to 2.6.11, we had a ports param. No longer, but don't break users. */
109111
static int warn_set(const char *val, const struct kernel_param *kp)
110112
{
111-
printk(KERN_INFO KBUILD_MODNAME
112-
": kernel >= 2.6.10 only uses 'ports' for conntrack modules\n");
113+
pr_info("kernel >= 2.6.10 only uses 'ports' for conntrack modules\n");
113114
return 0;
114115
}
115116
module_param_call(ports, warn_set, NULL, NULL, 0);

‎net/netfilter/nfnetlink_queue.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* published by the Free Software Foundation.
1515
*
1616
*/
17+
18+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19+
1720
#include <linux/module.h>
1821
#include <linux/skbuff.h>
1922
#include <linux/init.h>
@@ -833,11 +836,8 @@ nfqnl_mangle(void *data, int data_len, struct nf_queue_entry *e, int diff)
833836
if (diff > skb_tailroom(e->skb)) {
834837
nskb = skb_copy_expand(e->skb, skb_headroom(e->skb),
835838
diff, GFP_ATOMIC);
836-
if (!nskb) {
837-
printk(KERN_WARNING "nf_queue: OOM "
838-
"in mangle, dropping packet\n");
839+
if (!nskb)
839840
return -ENOMEM;
840-
}
841841
kfree_skb(e->skb);
842842
e->skb = nskb;
843843
}
@@ -1536,20 +1536,20 @@ static int __init nfnetlink_queue_init(void)
15361536

15371537
status = register_pernet_subsys(&nfnl_queue_net_ops);
15381538
if (status < 0) {
1539-
pr_err("nf_queue: failed to register pernet ops\n");
1539+
pr_err("failed to register pernet ops\n");
15401540
goto out;
15411541
}
15421542

15431543
netlink_register_notifier(&nfqnl_rtnl_notifier);
15441544
status = nfnetlink_subsys_register(&nfqnl_subsys);
15451545
if (status < 0) {
1546-
pr_err("nf_queue: failed to create netlink socket\n");
1546+
pr_err("failed to create netlink socket\n");
15471547
goto cleanup_netlink_notifier;
15481548
}
15491549

15501550
status = register_netdevice_notifier(&nfqnl_dev_notifier);
15511551
if (status < 0) {
1552-
pr_err("nf_queue: failed to register netdevice notifier\n");
1552+
pr_err("failed to register netdevice notifier\n");
15531553
goto cleanup_netlink_subsys;
15541554
}
15551555

‎net/netfilter/xt_time.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* This file is distributed under the terms of the GNU General Public
1010
* License (GPL). Copies of the GPL can be obtained from gnu.org/gpl.
1111
*/
12+
13+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14+
1215
#include <linux/ktime.h>
1316
#include <linux/module.h>
1417
#include <linux/skbuff.h>
@@ -266,13 +269,11 @@ static int __init time_mt_init(void)
266269
int minutes = sys_tz.tz_minuteswest;
267270

268271
if (minutes < 0) /* east of Greenwich */
269-
printk(KERN_INFO KBUILD_MODNAME
270-
": kernel timezone is +%02d%02d\n",
271-
-minutes / 60, -minutes % 60);
272+
pr_info("kernel timezone is +%02d%02d\n",
273+
-minutes / 60, -minutes % 60);
272274
else /* west of Greenwich */
273-
printk(KERN_INFO KBUILD_MODNAME
274-
": kernel timezone is -%02d%02d\n",
275-
minutes / 60, minutes % 60);
275+
pr_info("kernel timezone is -%02d%02d\n",
276+
minutes / 60, minutes % 60);
276277

277278
return xt_register_match(&xt_time_mt_reg);
278279
}

0 commit comments

Comments
 (0)