Skip to content

Commit

Permalink
tcp: Remove CMSG magic numbers for tcp_recvmsg().
Browse files Browse the repository at this point in the history
At present, tcp_recvmsg() uses flags to track if any CMSGs are pending
and what those CMSGs are. These flags are currently magic numbers,
used only within tcp_recvmsg().

To prepare for receive timestamp support in tcp receive zerocopy,
gently refactor these magic numbers into enums.

Signed-off-by: Arjun Roy <arjunroy@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Arjun Roy authored and Jakub Kicinski committed Jan 23, 2021
1 parent 5225d5f commit 925bba2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@
#include <asm/ioctls.h>
#include <net/busy_poll.h>

/* Track pending CMSGs. */
enum {
TCP_CMSG_INQ = 1,
TCP_CMSG_TS = 2
};

struct percpu_counter tcp_orphan_count;
EXPORT_SYMBOL_GPL(tcp_orphan_count);

Expand Down Expand Up @@ -2272,7 +2278,7 @@ static int tcp_recvmsg_locked(struct sock *sk, struct msghdr *msg, size_t len,
goto out;

if (tp->recvmsg_inq)
*cmsg_flags = 1;
*cmsg_flags = TCP_CMSG_INQ;
timeo = sock_rcvtimeo(sk, nonblock);

/* Urgent data needs to be handled specially. */
Expand Down Expand Up @@ -2453,7 +2459,7 @@ static int tcp_recvmsg_locked(struct sock *sk, struct msghdr *msg, size_t len,

if (TCP_SKB_CB(skb)->has_rxtstamp) {
tcp_update_recv_tstamps(skb, tss);
*cmsg_flags |= 2;
*cmsg_flags |= TCP_CMSG_TS;
}

if (used + offset < skb->len)
Expand Down Expand Up @@ -2513,9 +2519,9 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock,
release_sock(sk);

if (cmsg_flags && ret >= 0) {
if (cmsg_flags & 2)
if (cmsg_flags & TCP_CMSG_TS)
tcp_recv_timestamp(msg, sk, &tss);
if (cmsg_flags & 1) {
if (cmsg_flags & TCP_CMSG_INQ) {
inq = tcp_inq_hint(sk);
put_cmsg(msg, SOL_TCP, TCP_CM_INQ, sizeof(inq), &inq);
}
Expand Down

0 comments on commit 925bba2

Please sign in to comment.