Skip to content

Commit

Permalink
net: Convert net_ratelimit uses to net_<level>_ratelimited
Browse files Browse the repository at this point in the history
Standardize the net core ratelimited logging functions.

Coalesce formats, align arguments.
Change a printk then vprintk sequence to use printf extension %pV.

Signed-off-by: Joe Perches <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
JoePerches authored and davem330 committed May 15, 2012
1 parent 3a3bfb6 commit e87cc47
Show file tree
Hide file tree
Showing 76 changed files with 306 additions and 490 deletions.
8 changes: 3 additions & 5 deletions net/atm/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd,
error = sock_get_timestampns(sk, argp);
goto done;
case ATM_SETSC:
if (net_ratelimit())
pr_warning("ATM_SETSC is obsolete; used by %s:%d\n",
current->comm, task_pid_nr(current));
net_warn_ratelimited("ATM_SETSC is obsolete; used by %s:%d\n",
current->comm, task_pid_nr(current));
error = 0;
goto done;
case ATMSIGD_CTRL:
Expand All @@ -123,8 +122,7 @@ static int do_vcc_ioctl(struct socket *sock, unsigned int cmd,
work for 32-bit userspace. TBH I don't really want
to think about it at all. dwmw2. */
if (compat) {
if (net_ratelimit())
pr_warning("32-bit task cannot be atmsigd\n");
net_warn_ratelimited("32-bit task cannot be atmsigd\n");
error = -EINVAL;
goto done;
}
Expand Down
10 changes: 4 additions & 6 deletions net/caif/caif_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,9 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)

if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
(unsigned int)sk->sk_rcvbuf && rx_flow_is_on(cf_sk)) {
if (net_ratelimit())
pr_debug("sending flow OFF (queue len = %d %d)\n",
atomic_read(&cf_sk->sk.sk_rmem_alloc),
sk_rcvbuf_lowwater(cf_sk));
net_dbg_ratelimited("sending flow OFF (queue len = %d %d)\n",
atomic_read(&cf_sk->sk.sk_rmem_alloc),
sk_rcvbuf_lowwater(cf_sk));
set_rx_flow_off(cf_sk);
caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
}
Expand All @@ -144,8 +143,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
return err;
if (!sk_rmem_schedule(sk, skb->truesize) && rx_flow_is_on(cf_sk)) {
set_rx_flow_off(cf_sk);
if (net_ratelimit())
pr_debug("sending flow OFF due to rmem_schedule\n");
net_dbg_ratelimited("sending flow OFF due to rmem_schedule\n");
caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
}
skb->dev = NULL;
Expand Down
30 changes: 12 additions & 18 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1673,10 +1673,9 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)

if (skb_network_header(skb2) < skb2->data ||
skb2->network_header > skb2->tail) {
if (net_ratelimit())
pr_crit("protocol %04x is buggy, dev %s\n",
ntohs(skb2->protocol),
dev->name);
net_crit_ratelimited("protocol %04x is buggy, dev %s\n",
ntohs(skb2->protocol),
dev->name);
skb_reset_network_header(skb2);
}

Expand Down Expand Up @@ -2343,11 +2342,9 @@ EXPORT_SYMBOL(__skb_tx_hash);
static inline u16 dev_cap_txqueue(struct net_device *dev, u16 queue_index)
{
if (unlikely(queue_index >= dev->real_num_tx_queues)) {
if (net_ratelimit()) {
pr_warn("%s selects TX queue %d, but real number of TX queues is %d\n",
dev->name, queue_index,
dev->real_num_tx_queues);
}
net_warn_ratelimited("%s selects TX queue %d, but real number of TX queues is %d\n",
dev->name, queue_index,
dev->real_num_tx_queues);
return 0;
}
return queue_index;
Expand Down Expand Up @@ -2589,17 +2586,15 @@ int dev_queue_xmit(struct sk_buff *skb)
}
}
HARD_TX_UNLOCK(dev, txq);
if (net_ratelimit())
pr_crit("Virtual device %s asks to queue packet!\n",
dev->name);
net_crit_ratelimited("Virtual device %s asks to queue packet!\n",
dev->name);
} else {
/* Recursion is detected! It is possible,
* unfortunately
*/
recursion_alert:
if (net_ratelimit())
pr_crit("Dead loop on virtual device %s, fix it urgently!\n",
dev->name);
net_crit_ratelimited("Dead loop on virtual device %s, fix it urgently!\n",
dev->name);
}
}

Expand Down Expand Up @@ -3080,9 +3075,8 @@ static int ing_filter(struct sk_buff *skb, struct netdev_queue *rxq)
struct Qdisc *q;

if (unlikely(MAX_RED_LOOP < ttl++)) {
if (net_ratelimit())
pr_warn("Redir loop detected Dropping packet (%d->%d)\n",
skb->skb_iif, dev->ifindex);
net_warn_ratelimited("Redir loop detected Dropping packet (%d->%d)\n",
skb->skb_iif, dev->ifindex);
return TC_ACT_SHOT;
}

Expand Down
7 changes: 3 additions & 4 deletions net/core/pktgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2934,8 +2934,7 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,

if (datalen < sizeof(struct pktgen_hdr)) {
datalen = sizeof(struct pktgen_hdr);
if (net_ratelimit())
pr_info("increased datalen to %d\n", datalen);
net_info_ratelimited("increased datalen to %d\n", datalen);
}

udph->source = htons(pkt_dev->cur_udp_src);
Expand Down Expand Up @@ -3365,8 +3364,8 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
pkt_dev->errors++;
break;
default: /* Drivers are not supposed to return other values! */
if (net_ratelimit())
pr_info("%s xmit error: %d\n", pkt_dev->odevname, ret);
net_info_ratelimited("%s xmit error: %d\n",
pkt_dev->odevname, ret);
pkt_dev->errors++;
/* fallthru */
case NETDEV_TX_LOCKED:
Expand Down
8 changes: 3 additions & 5 deletions net/core/rtnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1524,11 +1524,9 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
err = 0;

errout:
if (err < 0 && modified && net_ratelimit())
printk(KERN_WARNING "A link change request failed with "
"some changes committed already. Interface %s may "
"have been left with an inconsistent configuration, "
"please check.\n", dev->name);
if (err < 0 && modified)
net_warn_ratelimited("A link change request failed with some changes committed already. Interface %s may have been left with an inconsistent configuration, please check.\n",
dev->name);

if (send_addr_notify)
call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
Expand Down
11 changes: 4 additions & 7 deletions net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3299,10 +3299,8 @@ bool skb_partial_csum_set(struct sk_buff *skb, u16 start, u16 off)
{
if (unlikely(start > skb_headlen(skb)) ||
unlikely((int)start + off > skb_headlen(skb) - 2)) {
if (net_ratelimit())
printk(KERN_WARNING
"bad partial csum: csum=%u/%u len=%u\n",
start, off, skb_headlen(skb));
net_warn_ratelimited("bad partial csum: csum=%u/%u len=%u\n",
start, off, skb_headlen(skb));
return false;
}
skb->ip_summed = CHECKSUM_PARTIAL;
Expand All @@ -3314,8 +3312,7 @@ EXPORT_SYMBOL_GPL(skb_partial_csum_set);

void __skb_warn_lro_forwarding(const struct sk_buff *skb)
{
if (net_ratelimit())
pr_warning("%s: received packets cannot be forwarded"
" while LRO is enabled\n", skb->dev->name);
net_warn_ratelimited("%s: received packets cannot be forwarded while LRO is enabled\n",
skb->dev->name);
}
EXPORT_SYMBOL(__skb_warn_lro_forwarding);
5 changes: 2 additions & 3 deletions net/decnet/dn_fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,8 @@ int dn_fib_semantic_match(int type, struct dn_fib_info *fi, const struct flowidn
res->fi = NULL;
return 1;
default:
if (net_ratelimit())
printk("DECnet: impossible routing event : dn_fib_semantic_match type=%d\n",
type);
net_err_ratelimited("DECnet: impossible routing event : dn_fib_semantic_match type=%d\n",
type);
res->fi = NULL;
return -EINVAL;
}
Expand Down
22 changes: 8 additions & 14 deletions net/decnet/dn_neigh.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ static int dn_neigh_construct(struct neighbour *neigh)
else if ((dev->type == ARPHRD_ETHER) || (dev->type == ARPHRD_LOOPBACK))
dn_dn2eth(neigh->ha, dn->addr);
else {
if (net_ratelimit())
printk(KERN_DEBUG "Trying to create neigh for hw %d\n", dev->type);
net_dbg_ratelimited("Trying to create neigh for hw %d\n",
dev->type);
return -EINVAL;
}

Expand Down Expand Up @@ -236,15 +236,13 @@ static int dn_long_output(struct neighbour *neigh, struct sk_buff *skb)
if (skb_headroom(skb) < headroom) {
struct sk_buff *skb2 = skb_realloc_headroom(skb, headroom);
if (skb2 == NULL) {
if (net_ratelimit())
printk(KERN_CRIT "dn_long_output: no memory\n");
net_crit_ratelimited("dn_long_output: no memory\n");
kfree_skb(skb);
return -ENOBUFS;
}
kfree_skb(skb);
skb = skb2;
if (net_ratelimit())
printk(KERN_INFO "dn_long_output: Increasing headroom\n");
net_info_ratelimited("dn_long_output: Increasing headroom\n");
}

data = skb_push(skb, sizeof(struct dn_long_packet) + 3);
Expand Down Expand Up @@ -281,15 +279,13 @@ static int dn_short_output(struct neighbour *neigh, struct sk_buff *skb)
if (skb_headroom(skb) < headroom) {
struct sk_buff *skb2 = skb_realloc_headroom(skb, headroom);
if (skb2 == NULL) {
if (net_ratelimit())
printk(KERN_CRIT "dn_short_output: no memory\n");
net_crit_ratelimited("dn_short_output: no memory\n");
kfree_skb(skb);
return -ENOBUFS;
}
kfree_skb(skb);
skb = skb2;
if (net_ratelimit())
printk(KERN_INFO "dn_short_output: Increasing headroom\n");
net_info_ratelimited("dn_short_output: Increasing headroom\n");
}

data = skb_push(skb, sizeof(struct dn_short_packet) + 2);
Expand Down Expand Up @@ -322,15 +318,13 @@ static int dn_phase3_output(struct neighbour *neigh, struct sk_buff *skb)
if (skb_headroom(skb) < headroom) {
struct sk_buff *skb2 = skb_realloc_headroom(skb, headroom);
if (skb2 == NULL) {
if (net_ratelimit())
printk(KERN_CRIT "dn_phase3_output: no memory\n");
net_crit_ratelimited("dn_phase3_output: no memory\n");
kfree_skb(skb);
return -ENOBUFS;
}
kfree_skb(skb);
skb = skb2;
if (net_ratelimit())
printk(KERN_INFO "dn_phase3_output: Increasing headroom\n");
net_info_ratelimited("dn_phase3_output: Increasing headroom\n");
}

data = skb_push(skb, sizeof(struct dn_short_packet) + 2);
Expand Down
11 changes: 7 additions & 4 deletions net/decnet/dn_nsp_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ extern int decnet_log_martians;

static void dn_log_martian(struct sk_buff *skb, const char *msg)
{
if (decnet_log_martians && net_ratelimit()) {
if (decnet_log_martians) {
char *devname = skb->dev ? skb->dev->name : "???";
struct dn_skb_cb *cb = DN_SKB_CB(skb);
printk(KERN_INFO "DECnet: Martian packet (%s) dev=%s src=0x%04hx dst=0x%04hx srcport=0x%04hx dstport=0x%04hx\n",
msg, devname, le16_to_cpu(cb->src), le16_to_cpu(cb->dst),
le16_to_cpu(cb->src_port), le16_to_cpu(cb->dst_port));
net_info_ratelimited("DECnet: Martian packet (%s) dev=%s src=0x%04hx dst=0x%04hx srcport=0x%04hx dstport=0x%04hx\n",
msg, devname,
le16_to_cpu(cb->src),
le16_to_cpu(cb->dst),
le16_to_cpu(cb->src_port),
le16_to_cpu(cb->dst_port));
}
}

Expand Down
5 changes: 2 additions & 3 deletions net/decnet/dn_nsp_out.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* DECnet An implementation of the DECnet protocol suite for the LINUX
* operating system. DECnet is implemented using the BSD Socket
Expand Down Expand Up @@ -554,8 +553,8 @@ static __inline__ void dn_nsp_do_disc(struct sock *sk, unsigned char msgflg,
unsigned char *msg;

if ((dst == NULL) || (rem == 0)) {
if (net_ratelimit())
printk(KERN_DEBUG "DECnet: dn_nsp_do_disc: BUG! Please report this to [email protected] rem=%u dst=%p\n", le16_to_cpu(rem), dst);
net_dbg_ratelimited("DECnet: dn_nsp_do_disc: BUG! Please report this to [email protected] rem=%u dst=%p\n",
le16_to_cpu(rem), dst);
return;
}

Expand Down
15 changes: 5 additions & 10 deletions net/decnet/dn_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,7 @@ static int dn_output(struct sk_buff *skb)
dn_to_neigh_output);

error:
if (net_ratelimit())
printk(KERN_DEBUG "dn_output: This should not happen\n");
net_dbg_ratelimited("dn_output: This should not happen\n");

kfree_skb(skb);

Expand Down Expand Up @@ -807,12 +806,10 @@ static int dn_forward(struct sk_buff *skb)
*/
static int dn_rt_bug(struct sk_buff *skb)
{
if (net_ratelimit()) {
struct dn_skb_cb *cb = DN_SKB_CB(skb);
struct dn_skb_cb *cb = DN_SKB_CB(skb);

printk(KERN_DEBUG "dn_rt_bug: skb from:%04x to:%04x\n",
le16_to_cpu(cb->src), le16_to_cpu(cb->dst));
}
net_dbg_ratelimited("dn_rt_bug: skb from:%04x to:%04x\n",
le16_to_cpu(cb->src), le16_to_cpu(cb->dst));

kfree_skb(skb);

Expand Down Expand Up @@ -1327,9 +1324,7 @@ static int dn_route_input_slow(struct sk_buff *skb)

out_dev = DN_FIB_RES_DEV(res);
if (out_dev == NULL) {
if (net_ratelimit())
printk(KERN_CRIT "Bug in dn_route_input_slow() "
"No output device\n");
net_crit_ratelimited("Bug in dn_route_input_slow() No output device\n");
goto e_inval;
}
dev_hold(out_dev);
Expand Down
4 changes: 2 additions & 2 deletions net/decnet/dn_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,8 @@ struct dn_fib_table *dn_fib_get_table(u32 n, int create)
if (!create)
return NULL;

if (in_interrupt() && net_ratelimit()) {
printk(KERN_DEBUG "DECnet: BUG! Attempt to create routing table from interrupt\n");
if (in_interrupt()) {
net_dbg_ratelimited("DECnet: BUG! Attempt to create routing table from interrupt\n");
return NULL;
}

Expand Down
3 changes: 1 addition & 2 deletions net/decnet/netfilter/dn_rtmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ static struct sk_buff *dnrmg_build_message(struct sk_buff *rt_skb, int *errp)
if (skb)
kfree_skb(skb);
*errp = -ENOMEM;
if (net_ratelimit())
printk(KERN_ERR "dn_rtmsg: error creating netlink message\n");
net_err_ratelimited("dn_rtmsg: error creating netlink message\n");
return NULL;
}

Expand Down
20 changes: 9 additions & 11 deletions net/ipv4/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,10 @@ static void icmp_unreach(struct sk_buff *skb)

if (!net->ipv4.sysctl_icmp_ignore_bogus_error_responses &&
inet_addr_type(net, iph->daddr) == RTN_BROADCAST) {
if (net_ratelimit())
pr_warn("%pI4 sent an invalid ICMP type %u, code %u error to a broadcast: %pI4 on %s\n",
&ip_hdr(skb)->saddr,
icmph->type, icmph->code,
&iph->daddr, skb->dev->name);
net_warn_ratelimited("%pI4 sent an invalid ICMP type %u, code %u error to a broadcast: %pI4 on %s\n",
&ip_hdr(skb)->saddr,
icmph->type, icmph->code,
&iph->daddr, skb->dev->name);
goto out;
}

Expand Down Expand Up @@ -906,8 +905,7 @@ static void icmp_timestamp(struct sk_buff *skb)
static void icmp_address(struct sk_buff *skb)
{
#if 0
if (net_ratelimit())
printk(KERN_DEBUG "a guy asks for address mask. Who is it?\n");
net_dbg_ratelimited("a guy asks for address mask. Who is it?\n");
#endif
}

Expand Down Expand Up @@ -943,10 +941,10 @@ static void icmp_address_reply(struct sk_buff *skb)
inet_ifa_match(ip_hdr(skb)->saddr, ifa))
break;
}
if (!ifa && net_ratelimit()) {
pr_info("Wrong address mask %pI4 from %s/%pI4\n",
mp, dev->name, &ip_hdr(skb)->saddr);
}
if (!ifa)
net_info_ratelimited("Wrong address mask %pI4 from %s/%pI4\n",
mp,
dev->name, &ip_hdr(skb)->saddr);
}
}

Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/ip_fragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,7 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *prev,
err = -ENOMEM;
goto out_fail;
out_oversize:
if (net_ratelimit())
pr_info("Oversized IP packet from %pI4\n", &qp->saddr);
net_info_ratelimited("Oversized IP packet from %pI4\n", &qp->saddr);
out_fail:
IP_INC_STATS_BH(net, IPSTATS_MIB_REASMFAILS);
return err;
Expand Down
Loading

0 comments on commit e87cc47

Please sign in to comment.