Subject: tcp_segsize() simplification
To: None <tech-net@NetBSD.org>
From: None <seanb@qnx.com>
List: tech-net
Date: 03/24/2006 19:53:53
Hi:

The following is slightly cleaner / more readable.
No functional change.  Any objections before I commit?

Regards,

-seanb


Index: netinet/tcp_output.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/tcp_output.c,v
retrieving revision 1.141
diff -c -r1.141 tcp_output.c
*** netinet/tcp_output.c	24 Dec 2005 20:45:09 -0000	1.141
--- netinet/tcp_output.c	15 Mar 2006 19:54:36 -0000
***************
*** 248,254 ****
  	struct rtentry *rt;
  	struct ifnet *ifp;
  	int size;
! 	int iphlen;
  	int optlen;
  
  #ifdef DIAGNOSTIC
--- 248,254 ----
  	struct rtentry *rt;
  	struct ifnet *ifp;
  	int size;
! 	int hdrlen;
  	int optlen;
  
  #ifdef DIAGNOSTIC
***************
*** 258,269 ****
  	switch (tp->t_family) {
  #ifdef INET
  	case AF_INET:
! 		iphlen = sizeof(struct ip);
  		break;
  #endif
  #ifdef INET6
  	case AF_INET6:
! 		iphlen = sizeof(struct ip6_hdr);
  		break;
  #endif
  	default:
--- 258,269 ----
  	switch (tp->t_family) {
  #ifdef INET
  	case AF_INET:
! 		hdrlen = sizeof(struct ip) + sizeof(struct tcphdr);
  		break;
  #endif
  #ifdef INET6
  	case AF_INET6:
! 		hdrlen = sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
  		break;
  #endif
  	default:
***************
*** 300,320 ****
  			 * smaller than 1280, use 1280 as packet size and
  			 * attach fragment header.
  			 */
! 			size = IPV6_MMTU - iphlen - sizeof(struct ip6_frag) -
! 			    sizeof(struct tcphdr);
  		} else
! 			size = rt->rt_rmx.rmx_mtu - iphlen -
! 			    sizeof(struct tcphdr);
  #else
! 		size = rt->rt_rmx.rmx_mtu - iphlen - sizeof(struct tcphdr);
  #endif
  	} else if (ifp->if_flags & IFF_LOOPBACK)
! 		size = ifp->if_mtu - iphlen - sizeof(struct tcphdr);
  #ifdef INET
  	else if (inp && tp->t_mtudisc)
! 		size = ifp->if_mtu - iphlen - sizeof(struct tcphdr);
  	else if (inp && in_localaddr(inp->inp_faddr))
! 		size = ifp->if_mtu - iphlen - sizeof(struct tcphdr);
  #endif
  #ifdef INET6
  	else if (in6p) {
--- 300,318 ----
  			 * smaller than 1280, use 1280 as packet size and
  			 * attach fragment header.
  			 */
! 			size = IPV6_MMTU - hdrlen - sizeof(struct ip6_frag);
  		} else
! 			size = rt->rt_rmx.rmx_mtu - hdrlen;
  #else
! 		size = rt->rt_rmx.rmx_mtu - hdrlen;
  #endif
  	} else if (ifp->if_flags & IFF_LOOPBACK)
! 		size = ifp->if_mtu - hdrlen;
  #ifdef INET
  	else if (inp && tp->t_mtudisc)
! 		size = ifp->if_mtu - hdrlen;
  	else if (inp && in_localaddr(inp->inp_faddr))
! 		size = ifp->if_mtu - hdrlen;
  #endif
  #ifdef INET6
  	else if (in6p) {
***************
*** 324,330 ****
  			struct in_addr d;
  			bcopy(&in6p->in6p_faddr.s6_addr32[3], &d, sizeof(d));
  			if (tp->t_mtudisc || in_localaddr(d))
! 				size = ifp->if_mtu - iphlen - sizeof(struct tcphdr);
  		} else
  #endif
  		{
--- 322,328 ----
  			struct in_addr d;
  			bcopy(&in6p->in6p_faddr.s6_addr32[3], &d, sizeof(d));
  			if (tp->t_mtudisc || in_localaddr(d))
! 				size = ifp->if_mtu - hdrlen;
  		} else
  #endif
  		{
***************
*** 333,339 ****
  			 * or the node must use packet size <= 1280.
  			 */
  			size = tp->t_mtudisc ? IN6_LINKMTU(ifp) : IPV6_MMTU;
! 			size -= (iphlen + sizeof(struct tcphdr));
  		}
  	}
  #endif
--- 331,337 ----
  			 * or the node must use packet size <= 1280.
  			 */
  			size = tp->t_mtudisc ? IN6_LINKMTU(ifp) : IPV6_MMTU;
! 			size -= hdrlen;
  		}
  	}
  #endif