mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	udp6: cleanup stats accounting in recvmsg()
In the udp6 code path, we needed multiple tests to select the correct mib to be updated. Since we touch at least a counter at each iteration, it's convenient to use the recently introduced __UDPX_MIB() helper once and remove some code duplication. Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									560f1ba4d8
								
							
						
					
					
						commit
						029a374348
					
				
					 1 changed files with 7 additions and 25 deletions
				
			
		| 
						 | 
					@ -326,6 +326,7 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
	int is_udplite = IS_UDPLITE(sk);
 | 
						int is_udplite = IS_UDPLITE(sk);
 | 
				
			||||||
	bool checksum_valid = false;
 | 
						bool checksum_valid = false;
 | 
				
			||||||
 | 
						struct udp_mib *mib;
 | 
				
			||||||
	int is_udp4;
 | 
						int is_udp4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (flags & MSG_ERRQUEUE)
 | 
						if (flags & MSG_ERRQUEUE)
 | 
				
			||||||
| 
						 | 
					@ -349,6 +350,7 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 | 
				
			||||||
		msg->msg_flags |= MSG_TRUNC;
 | 
							msg->msg_flags |= MSG_TRUNC;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	is_udp4 = (skb->protocol == htons(ETH_P_IP));
 | 
						is_udp4 = (skb->protocol == htons(ETH_P_IP));
 | 
				
			||||||
 | 
						mib = __UDPX_MIB(sk, is_udp4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * If checksum is needed at all, try to do it while copying the
 | 
						 * If checksum is needed at all, try to do it while copying the
 | 
				
			||||||
| 
						 | 
					@ -377,24 +379,13 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 | 
				
			||||||
	if (unlikely(err)) {
 | 
						if (unlikely(err)) {
 | 
				
			||||||
		if (!peeked) {
 | 
							if (!peeked) {
 | 
				
			||||||
			atomic_inc(&sk->sk_drops);
 | 
								atomic_inc(&sk->sk_drops);
 | 
				
			||||||
			if (is_udp4)
 | 
								SNMP_INC_STATS(mib, UDP_MIB_INERRORS);
 | 
				
			||||||
				UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS,
 | 
					 | 
				
			||||||
					      is_udplite);
 | 
					 | 
				
			||||||
			else
 | 
					 | 
				
			||||||
				UDP6_INC_STATS(sock_net(sk), UDP_MIB_INERRORS,
 | 
					 | 
				
			||||||
					       is_udplite);
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		kfree_skb(skb);
 | 
							kfree_skb(skb);
 | 
				
			||||||
		return err;
 | 
							return err;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (!peeked) {
 | 
						if (!peeked)
 | 
				
			||||||
		if (is_udp4)
 | 
							SNMP_INC_STATS(mib, UDP_MIB_INDATAGRAMS);
 | 
				
			||||||
			UDP_INC_STATS(sock_net(sk), UDP_MIB_INDATAGRAMS,
 | 
					 | 
				
			||||||
				      is_udplite);
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
			UDP6_INC_STATS(sock_net(sk), UDP_MIB_INDATAGRAMS,
 | 
					 | 
				
			||||||
				       is_udplite);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sock_recv_ts_and_drops(msg, sk, skb);
 | 
						sock_recv_ts_and_drops(msg, sk, skb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -443,17 +434,8 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 | 
				
			||||||
csum_copy_err:
 | 
					csum_copy_err:
 | 
				
			||||||
	if (!__sk_queue_drop_skb(sk, &udp_sk(sk)->reader_queue, skb, flags,
 | 
						if (!__sk_queue_drop_skb(sk, &udp_sk(sk)->reader_queue, skb, flags,
 | 
				
			||||||
				 udp_skb_destructor)) {
 | 
									 udp_skb_destructor)) {
 | 
				
			||||||
		if (is_udp4) {
 | 
							SNMP_INC_STATS(mib, UDP_MIB_CSUMERRORS);
 | 
				
			||||||
			UDP_INC_STATS(sock_net(sk),
 | 
							SNMP_INC_STATS(mib, UDP_MIB_INERRORS);
 | 
				
			||||||
				      UDP_MIB_CSUMERRORS, is_udplite);
 | 
					 | 
				
			||||||
			UDP_INC_STATS(sock_net(sk),
 | 
					 | 
				
			||||||
				      UDP_MIB_INERRORS, is_udplite);
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			UDP6_INC_STATS(sock_net(sk),
 | 
					 | 
				
			||||||
				       UDP_MIB_CSUMERRORS, is_udplite);
 | 
					 | 
				
			||||||
			UDP6_INC_STATS(sock_net(sk),
 | 
					 | 
				
			||||||
				       UDP_MIB_INERRORS, is_udplite);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	kfree_skb(skb);
 | 
						kfree_skb(skb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue