net: tcp: Define the TCP_MAX_WSCALE instead of literal number 14
authorGao Feng <fgao@ikuai8.com>
Tue, 4 Apr 2017 13:09:48 +0000 (21:09 +0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 5 Apr 2017 14:50:32 +0000 (07:50 -0700)
Define one new macro TCP_MAX_WSCALE instead of literal number '14',
and use U16_MAX instead of 65535 as the max value of TCP window.
There is another minor change, use rounddown(space, mss) instead of
(space / mss) * mss;

Signed-off-by: Gao Feng <fgao@ikuai8.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/tcp.h
net/ipv4/tcp.c
net/ipv4/tcp_input.c
net/ipv4/tcp_output.c

index 582e3772c0d9c54a2dc7c757c0b6452b78725525..cc6ae0a95201f0adc52c2c46b429566806da6745 100644 (file)
@@ -78,6 +78,9 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);
 /* Maximal number of ACKs sent quickly to accelerate slow-start. */
 #define TCP_MAX_QUICKACKS      16U
 
+/* Maximal number of window scale according to RFC1323 */
+#define TCP_MAX_WSCALE         14U
+
 /* urg_data states */
 #define TCP_URG_VALID  0x0100
 #define TCP_URG_NOTYET 0x0200
index 1665948dff8c6ce1a14dbe01e3133550179c33bb..94f0b5b50e0d728c3edab175aee9d769cd80907f 100644 (file)
@@ -2393,7 +2393,7 @@ static int tcp_repair_options_est(struct tcp_sock *tp,
                                u16 snd_wscale = opt.opt_val & 0xFFFF;
                                u16 rcv_wscale = opt.opt_val >> 16;
 
-                               if (snd_wscale > 14 || rcv_wscale > 14)
+                               if (snd_wscale > TCP_MAX_WSCALE || rcv_wscale > TCP_MAX_WSCALE)
                                        return -EFBIG;
 
                                tp->rx_opt.snd_wscale = snd_wscale;
index a75c48f62e272e34a852ce1ec2523a3828a43247..ed6606cf5b3ee772976e0764833a579b68fcbb12 100644 (file)
@@ -3759,11 +3759,12 @@ void tcp_parse_options(const struct sk_buff *skb,
                                    !estab && sysctl_tcp_window_scaling) {
                                        __u8 snd_wscale = *(__u8 *)ptr;
                                        opt_rx->wscale_ok = 1;
-                                       if (snd_wscale > 14) {
-                                               net_info_ratelimited("%s: Illegal window scaling value %d >14 received\n",
+                                       if (snd_wscale > TCP_MAX_WSCALE) {
+                                               net_info_ratelimited("%s: Illegal window scaling value %d > %u received\n",
                                                                     __func__,
-                                                                    snd_wscale);
-                                               snd_wscale = 14;
+                                                                    snd_wscale,
+                                                                    TCP_MAX_WSCALE);
+                                               snd_wscale = TCP_MAX_WSCALE;
                                        }
                                        opt_rx->snd_wscale = snd_wscale;
                                }
index 13971942211b214dc2bc26e1e442c4b7ba305e3d..0e807a83c1bc510debda6c516f633a8b380d3679 100644 (file)
@@ -212,12 +212,12 @@ void tcp_select_initial_window(int __space, __u32 mss,
 
        /* If no clamp set the clamp to the max possible scaled window */
        if (*window_clamp == 0)
-               (*window_clamp) = (65535 << 14);
+               (*window_clamp) = (U16_MAX << TCP_MAX_WSCALE);
        space = min(*window_clamp, space);
 
        /* Quantize space offering to a multiple of mss if possible. */
        if (space > mss)
-               space = (space / mss) * mss;
+               space = rounddown(space, mss);
 
        /* NOTE: offering an initial window larger than 32767
         * will break some buggy TCP stacks. If the admin tells us
@@ -234,13 +234,11 @@ void tcp_select_initial_window(int __space, __u32 mss,
 
        (*rcv_wscale) = 0;
        if (wscale_ok) {
-               /* Set window scaling on max possible window
-                * See RFC1323 for an explanation of the limit to 14
-                */
+               /* Set window scaling on max possible window */
                space = max_t(u32, space, sysctl_tcp_rmem[2]);
                space = max_t(u32, space, sysctl_rmem_max);
                space = min_t(u32, space, *window_clamp);
-               while (space > 65535 && (*rcv_wscale) < 14) {
+               while (space > U16_MAX && (*rcv_wscale) < TCP_MAX_WSCALE) {
                        space >>= 1;
                        (*rcv_wscale)++;
                }
@@ -253,7 +251,7 @@ void tcp_select_initial_window(int __space, __u32 mss,
        }
 
        /* Set the clamp no higher than max representable value */
-       (*window_clamp) = min(65535U << (*rcv_wscale), *window_clamp);
+       (*window_clamp) = min_t(__u32, U16_MAX << (*rcv_wscale), *window_clamp);
 }
 EXPORT_SYMBOL(tcp_select_initial_window);