net: sk_drops consolidation
Subsystems (6)
PATCH 1/1 net: sk_drops consolidation
sock_queue_rcv_skb() can update sk_drops itself, removing need for callers to take care of it. This is more consistent since sock_queue_rcv_skb() also reads sk_drops when queueing a skb.
This adds sk_drops managment to many protocols that not cared yet.
--- net/core/sock.c | 15 +++++++-------- net/ieee802154/dgram.c | 1 - net/ieee802154/raw.c | 1 - net/ipv4/raw.c | 1 - net/ipv4/udp.c | 19 ++++++++----------- net/ipv6/raw.c | 3 +-- net/ipv6/udp.c | 6 ++---- net/phonet/datagram.c | 6 ++---- net/phonet/pep.c | 2 -- 9 files changed, 20 insertions(+), 34 deletions(-)
net/core/sock.c +7 -8
@@ -274,7 +274,7 @@ static void sock_disable_timestamp(struct sock *sk, int flag)int sock_queue_rcv_skb (struct sock *sk,struct sk_buff *skb) { -int err =0 ; +int err;int skb_len;unsigned long flags;struct sk_buff_head *list = &sk->sk_receive_queue;
@@ -284,17 +284,17 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)*/ if (atomic_read (&sk->sk_rmem_alloc) + skb->truesize >= (unsigned )sk->sk_rcvbuf) { - err = -ENOMEM ; - goto out; +atomic_inc (&sk->sk_drops); +return -ENOMEM ; } err =sk_filter (sk, skb);if (err) - goto out; +return err;if (!sk_rmem_schedule (sk, skb->truesize)) { - err = -ENOBUFS ; - goto out; +atomic_inc (&sk->sk_drops); +return -ENOBUFS ; } skb->dev =NULL ;
@@ -314,8 +314,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)if (!sock_flag (sk,SOCK_DEAD )) sk->sk_data_ready (sk, skb_len); -out: -return err; +return 0 ; }EXPORT_SYMBOL (sock_queue_rcv_skb);
net/ieee802154/dgram.c +0 -1
@@ -318,7 +318,6 @@ out:static int dgram_rcv_skb (struct sock *sk,struct sk_buff *skb) {if (sock_queue_rcv_skb (sk, skb) <0 ) { -atomic_inc (&sk->sk_drops);kfree_skb (skb);return NET_RX_DROP ; }
net/ieee802154/raw.c +0 -1
@@ -206,7 +206,6 @@ out:static int raw_rcv_skb (struct sock *sk,struct sk_buff *skb) {if (sock_queue_rcv_skb (sk, skb) <0 ) { -atomic_inc (&sk->sk_drops);kfree_skb (skb);return NET_RX_DROP ; }
net/ipv4/raw.c +0 -1
@@ -292,7 +292,6 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)/* Charge it to the socket. */ if (sock_queue_rcv_skb (sk, skb) <0 ) { -atomic_inc (&sk->sk_drops);kfree_skb (skb);return NET_RX_DROP ; }
net/ipv4/udp.c +8 -11
@@ -1063,25 +1063,22 @@ EXPORT_SYMBOL(udp_lib_unhash);static int __udp_queue_rcv_skb (struct sock *sk,struct sk_buff *skb) { -int is_udplite =IS_UDPLITE (sk); -int rc; +int rc =sock_queue_rcv_skb (sk, skb); + +if (rc <0 ) { +int is_udplite =IS_UDPLITE (sk); -if ((rc =sock_queue_rcv_skb (sk, skb)) <0 ) {/* Note that an ENOMEM error is charged twice */ -if (rc == -ENOMEM ) { +if (rc == -ENOMEM )UDP_INC_STATS_BH (sock_net (sk),UDP_MIB_RCVBUFERRORS , is_udplite); -atomic_inc (&sk->sk_drops); - } - goto drop; +UDP_INC_STATS_BH (sock_net (sk),UDP_MIB_INERRORS , is_udplite); +kfree_skb (skb); +return -1 ; }return 0 ; -drop: -UDP_INC_STATS_BH (sock_net (sk),UDP_MIB_INERRORS , is_udplite); -kfree_skb (skb); -return -1 ; }/* returns:
net/ipv6/raw.c +1 -2
@@ -381,8 +381,7 @@ static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb) }/* Charge it to the socket. */ -if (sock_queue_rcv_skb (sk,skb)<0 ) { -atomic_inc (&sk->sk_drops); +if (sock_queue_rcv_skb (sk, skb) <0 ) {kfree_skb (skb);return NET_RX_DROP ; }
net/ipv6/udp.c +2 -4
@@ -385,13 +385,11 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb) goto drop; } -if ((rc =sock_queue_rcv_skb (sk,skb)) <0 ) { +if ((rc =sock_queue_rcv_skb (sk, skb)) <0 ) {/* Note that an ENOMEM error is charged twice */ -if (rc == -ENOMEM ) { +if (rc == -ENOMEM )UDP6_INC_STATS_BH (sock_net (sk),UDP_MIB_RCVBUFERRORS , is_udplite); -atomic_inc (&sk->sk_drops); - } goto drop; }
net/phonet/datagram.c +2 -4
@@ -159,11 +159,9 @@ out_nofree:static int pn_backlog_rcv (struct sock *sk,struct sk_buff *skb) {int err =sock_queue_rcv_skb (sk, skb); -if (err <0 ) { + +if (err <0 )kfree_skb (skb); -if (err == -ENOMEM ) -atomic_inc (&sk->sk_drops); - }return err ?NET_RX_DROP :NET_RX_SUCCESS ; }
net/phonet/pep.c +0 -2
@@ -360,8 +360,6 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb) err =sock_queue_rcv_skb (sk, skb);if (!err)return 0 ; -if (err == -ENOMEM ) -atomic_inc (&sk->sk_drops);break ; }
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Thu, 15 Oct 2009 04:47:40 +0200
Quoted 7 lines
sock_queue_rcv_skb()can updatesk_dropsitself, removing need for callers to take care of it. This is more consistent sincesock_queue_rcv_skb()also readssk_dropswhen queueing a skb.This adds
sk_dropsmanagment to many protocols that not cared yet.Signed-off-by Eric Dumazet <[email protected]>
Looks great, applied.
PATCH 1/1 net: sk_drops consolidation part 2
- skb_kill_datagram() can increment sk->sk_drops itself, not callers.
- UDP on IPV4 & IPV6 dropped frames (because of bad checksum or policy checks) increment sk_drops
--- net/core/datagram.c | 1 + net/ipv4/udp.c | 2 ++ net/ipv6/raw.c | 1 - net/ipv6/udp.c | 4 +++- 4 files changed, 6 insertions(+), 2 deletions(-)
net/core/datagram.c +1 -0
@@ -262,6 +262,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags) }kfree_skb (skb); +atomic_inc (&sk->sk_drops);sk_mem_reclaim_partial (sk);return err;
net/ipv4/udp.c +2 -0
@@ -866,6 +866,7 @@ static unsigned int first_packet_length(struct sock *sk) udp_lib_checksum_complete(skb)) {UDP_INC_STATS_BH (sock_net (sk),UDP_MIB_INERRORS ,IS_UDPLITE (sk)); +atomic_inc (&sk->sk_drops);__skb_unlink (skb, rcvq);__skb_queue_tail (&list_kill, skb); }
@@ -1185,6 +1186,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) drop:UDP_INC_STATS_BH (sock_net (sk),UDP_MIB_INERRORS , is_udplite); +atomic_inc (&sk->sk_drops);kfree_skb (skb);return -1 ; }
net/ipv6/raw.c +0 -1
@@ -517,7 +517,6 @@ csum_copy_err:as some normal condition. */ err = (flags&MSG_DONTWAIT ) ? -EAGAIN : -EHOSTUNREACH ; -atomic_inc (&sk->sk_drops); goto out; }
net/ipv6/udp.c +3 -1
@@ -390,11 +390,13 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)if (rc == -ENOMEM )UDP6_INC_STATS_BH (sock_net (sk),UDP_MIB_RCVBUFERRORS , is_udplite); - goto drop; + goto drop_no_sk_drops_inc; }return 0 ; drop: +atomic_inc (&sk->sk_drops); +drop_no_sk_drops_inc:UDP6_INC_STATS_BH (sock_net (sk),UDP_MIB_INERRORS , is_udplite);kfree_skb (skb);return -1 ;
Re: [PATCH net-next-2.6] net: sk_drops consolidation part 2
From: Eric Dumazet <[email protected]>
Date: Thu, 15 Oct 2009 12:12:40 +0200
Quoted 5 lines
-
skb_kill_datagram()can incrementsk->sk_dropsitself, not callers.- UDP on IPV4 & IPV6 dropped frames (because of bad checksum or policy checks) increment
sk_dropsSigned-off-by Eric Dumazet <[email protected]>
Applied.
Quoted 5 lines · Eric Dumazet
sock_queue_rcv_skb()can updatesk_dropsitself, removing need for callers to take care of it. This is more consistent sincesock_queue_rcv_skb()also readssk_dropswhen queueing a skb.This adds
sk_dropsmanagment to many protocols that not cared yet.
For what it's worth, Phonet parts look fine to me.
Signature · 1 line
Rémi Denis-Courmont
Quoted 9 lines · Rémi Denis-Courmont
For what it's worth, Phonet parts look fine to me.
Thanks for reviewing Rémi