Skip to content

Commit 925bba2

Browse files
arjunroykuba-moo
authored andcommitted
tcp: Remove CMSG magic numbers for tcp_recvmsg().
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 <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5225d5f commit 925bba2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

net/ipv4/tcp.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@
280280
#include <asm/ioctls.h>
281281
#include <net/busy_poll.h>
282282

283+
/* Track pending CMSGs. */
284+
enum {
285+
TCP_CMSG_INQ = 1,
286+
TCP_CMSG_TS = 2
287+
};
288+
283289
struct percpu_counter tcp_orphan_count;
284290
EXPORT_SYMBOL_GPL(tcp_orphan_count);
285291

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

22742280
if (tp->recvmsg_inq)
2275-
*cmsg_flags = 1;
2281+
*cmsg_flags = TCP_CMSG_INQ;
22762282
timeo = sock_rcvtimeo(sk, nonblock);
22772283

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

24542460
if (TCP_SKB_CB(skb)->has_rxtstamp) {
24552461
tcp_update_recv_tstamps(skb, tss);
2456-
*cmsg_flags |= 2;
2462+
*cmsg_flags |= TCP_CMSG_TS;
24572463
}
24582464

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

25152521
if (cmsg_flags && ret >= 0) {
2516-
if (cmsg_flags & 2)
2522+
if (cmsg_flags & TCP_CMSG_TS)
25172523
tcp_recv_timestamp(msg, sk, &tss);
2518-
if (cmsg_flags & 1) {
2524+
if (cmsg_flags & TCP_CMSG_INQ) {
25192525
inq = tcp_inq_hint(sk);
25202526
put_cmsg(msg, SOL_TCP, TCP_CM_INQ, sizeof(inq), &inq);
25212527
}

0 commit comments

Comments
 (0)