Skip to content

Commit 029a374

Browse files
Paolo Abenidavem330
authored andcommitted
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>
1 parent 560f1ba commit 029a374

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

net/ipv6/udp.c

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
326326
int err;
327327
int is_udplite = IS_UDPLITE(sk);
328328
bool checksum_valid = false;
329+
struct udp_mib *mib;
329330
int is_udp4;
330331

331332
if (flags & MSG_ERRQUEUE)
@@ -349,6 +350,7 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
349350
msg->msg_flags |= MSG_TRUNC;
350351

351352
is_udp4 = (skb->protocol == htons(ETH_P_IP));
353+
mib = __UDPX_MIB(sk, is_udp4);
352354

353355
/*
354356
* 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,
377379
if (unlikely(err)) {
378380
if (!peeked) {
379381
atomic_inc(&sk->sk_drops);
380-
if (is_udp4)
381-
UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS,
382-
is_udplite);
383-
else
384-
UDP6_INC_STATS(sock_net(sk), UDP_MIB_INERRORS,
385-
is_udplite);
382+
SNMP_INC_STATS(mib, UDP_MIB_INERRORS);
386383
}
387384
kfree_skb(skb);
388385
return err;
389386
}
390-
if (!peeked) {
391-
if (is_udp4)
392-
UDP_INC_STATS(sock_net(sk), UDP_MIB_INDATAGRAMS,
393-
is_udplite);
394-
else
395-
UDP6_INC_STATS(sock_net(sk), UDP_MIB_INDATAGRAMS,
396-
is_udplite);
397-
}
387+
if (!peeked)
388+
SNMP_INC_STATS(mib, UDP_MIB_INDATAGRAMS);
398389

399390
sock_recv_ts_and_drops(msg, sk, skb);
400391

@@ -443,17 +434,8 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
443434
csum_copy_err:
444435
if (!__sk_queue_drop_skb(sk, &udp_sk(sk)->reader_queue, skb, flags,
445436
udp_skb_destructor)) {
446-
if (is_udp4) {
447-
UDP_INC_STATS(sock_net(sk),
448-
UDP_MIB_CSUMERRORS, is_udplite);
449-
UDP_INC_STATS(sock_net(sk),
450-
UDP_MIB_INERRORS, is_udplite);
451-
} else {
452-
UDP6_INC_STATS(sock_net(sk),
453-
UDP_MIB_CSUMERRORS, is_udplite);
454-
UDP6_INC_STATS(sock_net(sk),
455-
UDP_MIB_INERRORS, is_udplite);
456-
}
437+
SNMP_INC_STATS(mib, UDP_MIB_CSUMERRORS);
438+
SNMP_INC_STATS(mib, UDP_MIB_INERRORS);
457439
}
458440
kfree_skb(skb);
459441

0 commit comments

Comments
 (0)