From owner-p4-projects@FreeBSD.ORG Sat Aug 13 19:23:11 2011 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 249471065675; Sat, 13 Aug 2011 19:23:11 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DB0281065670 for ; Sat, 13 Aug 2011 19:23:10 +0000 (UTC) (envelope-from cnicutar@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id C8CFA8FC16 for ; Sat, 13 Aug 2011 19:23:10 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id p7DJNAYC084842 for ; Sat, 13 Aug 2011 19:23:10 GMT (envelope-from cnicutar@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id p7DJNAXh084839 for perforce@freebsd.org; Sat, 13 Aug 2011 19:23:10 GMT (envelope-from cnicutar@freebsd.org) Date: Sat, 13 Aug 2011 19:23:10 GMT Message-Id: <201108131923.p7DJNAXh084839@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to cnicutar@freebsd.org using -f From: Catalin Nicutar To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 197609 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Aug 2011 19:23:11 -0000 http://p4web.freebsd.org/@@197609?ac=10 Change 197609 by cnicutar@cnicutar_cronos on 2011/08/13 19:22:15 Improve UTO code readability. Affected files ... .. //depot/projects/soc2011/cnicutar_tcputo_9/src/sys/netinet/tcp.h#3 edit .. //depot/projects/soc2011/cnicutar_tcputo_9/src/sys/netinet/tcp_input.c#3 edit .. //depot/projects/soc2011/cnicutar_tcputo_9/src/sys/netinet/tcp_output.c#3 edit .. //depot/projects/soc2011/cnicutar_tcputo_9/src/sys/netinet/tcp_syncache.h#3 edit .. //depot/projects/soc2011/cnicutar_tcputo_9/src/sys/netinet/tcp_timer.c#3 edit .. //depot/projects/soc2011/cnicutar_tcputo_9/src/sys/netinet/tcp_var.h#3 edit Differences ... ==== //depot/projects/soc2011/cnicutar_tcputo_9/src/sys/netinet/tcp.h#3 (text+ko) ==== @@ -107,9 +107,11 @@ /* * The timeout ranges for TCP UTO have security implications; in particular, * long timeouts might allow for denial-of-service attacks. + * These are only defaults for net.inet.tcp.min_timeout and max_timeout, + * respectively. */ -#define TCP_UTOMIN 100 /* Minimum acceptable timeout. */ -#define TCP_UTOMAX 600 /* Maximum advertised timeout. */ +#define TCP_UTOMIN 100 /* Minimum user timeout in seconds. */ +#define TCP_UTOMAX 600 /* Maximum user timeout in seconds. */ /* ==== //depot/projects/soc2011/cnicutar_tcputo_9/src/sys/netinet/tcp_input.c#3 (text+ko) ==== @@ -1328,10 +1328,9 @@ if (to.to_flags & TOF_UTO) { /* * Storing the value even if the user might not - * accept it. Also, not clamping it just yet. + * accept it. */ - tp->rcv_uto = (to.to_uto & UTO_MINS) ? - (to.to_uto & ~(UTO_MINS)) * 60 : to.to_uto; + tp->rcv_uto = UTO_VALUE(to); /* * XXX-CN Using option both for send and receive. * Clear it for syncache. @@ -1532,10 +1531,8 @@ * The value is converter to seconds and not clamped (the user * needs to know the real value received). */ - if (to.to_flags & TOF_UTO) { - tp->rcv_uto = (to.to_uto & UTO_MINS) ? - (to.to_uto & ~(UTO_MINS)) * 60 : to.to_uto; - } + if (to.to_flags & TOF_UTO) + tp->rcv_uto = UTO_VALUE(to); /* * If echoed timestamp is later than the current time, ==== //depot/projects/soc2011/cnicutar_tcputo_9/src/sys/netinet/tcp_output.c#3 (text+ko) ==== @@ -1518,7 +1518,6 @@ /* * If the timeout is larger than UTO_MINS * we'll specify minutes. - * XXX-CN UTO_MINS is arbitrary. */ to->to_uto /= 60; to->to_uto |= UTO_MINS; ==== //depot/projects/soc2011/cnicutar_tcputo_9/src/sys/netinet/tcp_syncache.h#3 (text+ko) ==== @@ -82,8 +82,8 @@ struct label *sc_label; /* MAC label reference */ struct ucred *sc_cred; /* cred cache for jail checks */ - u_int32_t sc_snd_uto; /* user timeout to send */ - u_int32_t sc_rcv_uto; /* user timeout received */ + u_int32_t sc_snd_uto; /* Sent UTO (seconds) */ + u_int32_t sc_rcv_uto; /* Received UTO (seconds) */ }; /* ==== //depot/projects/soc2011/cnicutar_tcputo_9/src/sys/netinet/tcp_timer.c#3 (text+ko) ==== @@ -312,7 +312,7 @@ return; } callout_deactivate(&tp->t_timers->tt_keep); - if ((tp->snd_uto) || ((tp->t_flags & TF_RCV_UTO) && tp->rcv_uto)) { + if (USING_UTO(tp)) { /* * This connection is using UTO (either sending or has * received a value). We need to stop sending keepalives @@ -498,7 +498,7 @@ /* UTO starting again since it's the first retransmit. */ tp->t_suto = 0; - if (tp->snd_uto || ((tp->t_flags & TF_RCV_UTO) && tp->rcv_uto)) { + if (USING_UTO(tp)) { /* * Since we're using UTO for this connection we need to * compute how much time we've got left. ==== //depot/projects/soc2011/cnicutar_tcputo_9/src/sys/netinet/tcp_var.h#3 (text+ko) ==== @@ -207,9 +207,9 @@ void *t_pspare2[4]; /* 4 TBD */ uint64_t _pad[6]; /* 6 TBD (1-2 CC/RTT?) */ - uint32_t snd_uto; /* sent timeout */ - uint32_t rcv_uto; /* received suggestion from peer */ - int t_suto; /* uto starting time */ + uint32_t snd_uto; /* sent timeout (seconds) */ + uint32_t rcv_uto; /* received suggestion (seconds) */ + int t_suto; /* uto starting time (ticks) */ }; /* @@ -261,6 +261,12 @@ #define BYTES_THIS_ACK(tp, th) (th->th_ack - tp->snd_una) +#define USING_UTO(tp) (tp)->snd_uto || \ + (((tp)->t_flags & TF_RCV_UTO) && (tp)->rcv_uto) + +#define UTO_VALUE(to) ((to).to_uto & UTO_MINS) ? \ + ((to).to_uto & ~(UTO_MINS)) * 60 : (to).to_uto + /* * Flags for the t_oobflags field. */