Skip to content

Commit ab56222

Browse files
subravdavem330
authored andcommitted
tcp: Replace constants with #define macros
to record the state of SACK/FACK and DSACK for better readability and maintenance. Signed-off-by: Vijay Subramanian <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 08f4fc9 commit ab56222

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

include/linux/tcp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ struct tcp_sack_block {
238238
u32 end_seq;
239239
};
240240

241+
/*These are used to set the sack_ok field in struct tcp_options_received */
242+
#define TCP_SACK_SEEN (1 << 0) /*1 = peer is SACK capable, */
243+
#define TCP_FACK_ENABLED (1 << 1) /*1 = FACK is enabled locally*/
244+
#define TCP_DSACK_SEEN (1 << 2) /*1 = DSACK was received from peer*/
245+
241246
struct tcp_options_received {
242247
/* PAWS/RTTM data */
243248
long ts_recent_stamp;/* Time we stored ts_recent (for aging) */

include/net/tcp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,12 +773,12 @@ static inline int tcp_is_reno(const struct tcp_sock *tp)
773773

774774
static inline int tcp_is_fack(const struct tcp_sock *tp)
775775
{
776-
return tp->rx_opt.sack_ok & 2;
776+
return tp->rx_opt.sack_ok & TCP_FACK_ENABLED;
777777
}
778778

779779
static inline void tcp_enable_fack(struct tcp_sock *tp)
780780
{
781-
tp->rx_opt.sack_ok |= 2;
781+
tp->rx_opt.sack_ok |= TCP_FACK_ENABLED;
782782
}
783783

784784
static inline unsigned int tcp_left_out(const struct tcp_sock *tp)

net/ipv4/syncookies.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ bool cookie_check_timestamp(struct tcp_options_received *tcp_opt, bool *ecn_ok)
245245
if (!sysctl_tcp_timestamps)
246246
return false;
247247

248-
tcp_opt->sack_ok = (options >> 4) & 0x1;
248+
tcp_opt->sack_ok = (options & (1 << 4)) ? TCP_SACK_SEEN : 0;
249249
*ecn_ok = (options >> 5) & 1;
250250
if (*ecn_ok && !sysctl_tcp_ecn)
251251
return false;

net/ipv4/tcp_input.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,13 +865,13 @@ static void tcp_disable_fack(struct tcp_sock *tp)
865865
/* RFC3517 uses different metric in lost marker => reset on change */
866866
if (tcp_is_fack(tp))
867867
tp->lost_skb_hint = NULL;
868-
tp->rx_opt.sack_ok &= ~2;
868+
tp->rx_opt.sack_ok &= ~TCP_FACK_ENABLED;
869869
}
870870

871871
/* Take a notice that peer is sending D-SACKs */
872872
static void tcp_dsack_seen(struct tcp_sock *tp)
873873
{
874-
tp->rx_opt.sack_ok |= 4;
874+
tp->rx_opt.sack_ok |= TCP_DSACK_SEEN;
875875
}
876876

877877
/* Initialize metrics on socket. */
@@ -3878,7 +3878,7 @@ void tcp_parse_options(const struct sk_buff *skb, struct tcp_options_received *o
38783878
case TCPOPT_SACK_PERM:
38793879
if (opsize == TCPOLEN_SACK_PERM && th->syn &&
38803880
!estab && sysctl_tcp_sack) {
3881-
opt_rx->sack_ok = 1;
3881+
opt_rx->sack_ok = TCP_SACK_SEEN;
38823882
tcp_sack_reset(opt_rx);
38833883
}
38843884
break;

0 commit comments

Comments
 (0)