Commit f26ba175 authored by Wei Yongjun's avatar Wei Yongjun Committed by David S. Miller

udp: Fix the SNMP counter of UDP_MIB_INDATAGRAMS

If UDP echo is sent to xinetd/echo-dgram, the UDP reply will be received
at the sender. But the SNMP counter of UDP_MIB_INDATAGRAMS will be not
increased, UDP6_MIB_INDATAGRAMS will be increased instead.

  Endpoint A                      Endpoint B
  UDP Echo request ----------->
  (IPv4, Dst port=7)
                   <----------    UDP Echo Reply
                                  (IPv4, Src port=7)

This bug is come from this patch cb75994e.

It do counter UDP[6]_MIB_INDATAGRAMS until udp[v6]_recvmsg. Because
xinetd used IPv6 socket to receive UDP messages, thus, when received
UDP packet, the UDP6_MIB_INDATAGRAMS will be increased in function
udpv6_recvmsg() even if the packet is a IPv4 UDP packet.

This patch fixed the problem.
Signed-off-by: default avatarWei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 70d9d158
...@@ -138,6 +138,7 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk, ...@@ -138,6 +138,7 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
int peeked; int peeked;
int err; int err;
int is_udplite = IS_UDPLITE(sk); int is_udplite = IS_UDPLITE(sk);
int is_udp4;
if (addr_len) if (addr_len)
*addr_len=sizeof(struct sockaddr_in6); *addr_len=sizeof(struct sockaddr_in6);
...@@ -158,6 +159,8 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk, ...@@ -158,6 +159,8 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
else if (copied < ulen) else if (copied < ulen)
msg->msg_flags |= MSG_TRUNC; msg->msg_flags |= MSG_TRUNC;
is_udp4 = (skb->protocol == htons(ETH_P_IP));
/* /*
* 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
* data. If the data is truncated, or if we only want a partial * data. If the data is truncated, or if we only want a partial
...@@ -180,9 +183,14 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk, ...@@ -180,9 +183,14 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
if (err) if (err)
goto out_free; goto out_free;
if (!peeked) if (!peeked) {
UDP6_INC_STATS_USER(sock_net(sk), if (is_udp4)
UDP_MIB_INDATAGRAMS, is_udplite); UDP_INC_STATS_USER(sock_net(sk),
UDP_MIB_INDATAGRAMS, is_udplite);
else
UDP6_INC_STATS_USER(sock_net(sk),
UDP_MIB_INDATAGRAMS, is_udplite);
}
sock_recv_timestamp(msg, sk, skb); sock_recv_timestamp(msg, sk, skb);
...@@ -196,7 +204,7 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk, ...@@ -196,7 +204,7 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
sin6->sin6_flowinfo = 0; sin6->sin6_flowinfo = 0;
sin6->sin6_scope_id = 0; sin6->sin6_scope_id = 0;
if (skb->protocol == htons(ETH_P_IP)) if (is_udp4)
ipv6_addr_set(&sin6->sin6_addr, 0, 0, ipv6_addr_set(&sin6->sin6_addr, 0, 0,
htonl(0xffff), ip_hdr(skb)->saddr); htonl(0xffff), ip_hdr(skb)->saddr);
else { else {
...@@ -207,7 +215,7 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk, ...@@ -207,7 +215,7 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
} }
} }
if (skb->protocol == htons(ETH_P_IP)) { if (is_udp4) {
if (inet->cmsg_flags) if (inet->cmsg_flags)
ip_cmsg_recv(msg, skb); ip_cmsg_recv(msg, skb);
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment