diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-06-07 16:18:03 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-06-07 16:18:03 +0000 |
commit | 429940db10521cedcfc7580aee589a7a551bf048 (patch) | |
tree | e850ae89899d80263bd28211b071b9666a9cb9c1 /sys | |
parent | a4ad79f42ea05614e4d012325e2fb73cbe5674e6 (diff) |
avoid is_ipv6 construct. a step towards IPv4-less kernel
Diffstat (limited to 'sys')
-rw-r--r-- | sys/netinet/tcp_debug.c | 18 | ||||
-rw-r--r-- | sys/netinet/tcp_input.c | 8 | ||||
-rw-r--r-- | sys/netinet/tcp_output.c | 14 | ||||
-rw-r--r-- | sys/netinet/tcp_subr.c | 76 | ||||
-rw-r--r-- | sys/netinet/tcp_usrreq.c | 26 |
5 files changed, 72 insertions, 70 deletions
diff --git a/sys/netinet/tcp_debug.c b/sys/netinet/tcp_debug.c index 3a908a11560..ba1cf2d203f 100644 --- a/sys/netinet/tcp_debug.c +++ b/sys/netinet/tcp_debug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_debug.c,v 1.10 2001/06/08 03:53:46 angelos Exp $ */ +/* $OpenBSD: tcp_debug.c,v 1.11 2002/06/07 16:18:02 itojun Exp $ */ /* $NetBSD: tcp_debug.c,v 1.10 1996/02/13 23:43:36 christos Exp $ */ /* @@ -141,23 +141,25 @@ tcp_trace(act, ostate, tp, headers, req, len) td->td_cb = *tp; else bzero((caddr_t)&td->td_cb, sizeof (*tp)); + switch (tp->pf) { #ifdef INET6 - if (tp->pf == PF_INET6) { + case PF_INET6: if (ti) { th = &ti6->ti6_t; td->td_ti6 = *ti6; - } else { + } else bzero(&td->td_ti6, sizeof(struct tcpipv6hdr)); - } - } else + break; #endif /* INET6 */ - { + case PF_INET: if (ti) { th = &ti->ti_t; td->td_ti = *ti; - } else { + } else bzero(&td->td_ti, sizeof(struct tcpiphdr)); - } + break; + default: + return; } td->td_req = req; diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 3db4bcdcda2..a307b6ac266 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_input.c,v 1.115 2002/06/07 15:51:54 itojun Exp $ */ +/* $OpenBSD: tcp_input.c,v 1.116 2002/06/07 16:18:02 itojun Exp $ */ /* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */ /* @@ -2946,7 +2946,6 @@ tcp_mss(tp, offer) struct ifnet *ifp; int mss, mssopt; int iphlen; - int is_ipv6 = 0; struct inpcb *inp; inp = tp->t_inpcb; @@ -2964,7 +2963,6 @@ tcp_mss(tp, offer) #ifdef INET6 case AF_INET6: iphlen = sizeof(struct ip6_hdr); - is_ipv6 = 1; break; #endif case AF_INET: @@ -2997,14 +2995,14 @@ tcp_mss(tp, offer) goto out; else if (ifp->if_flags & IFF_LOOPBACK) mss = ifp->if_mtu - iphlen - sizeof(struct tcphdr); - else if (!is_ipv6) { + else if (tp->pf == AF_INET) { if (ip_mtudisc) mss = ifp->if_mtu - iphlen - sizeof(struct tcphdr); else if (inp && in_localaddr(inp->inp_faddr)) mss = ifp->if_mtu - iphlen - sizeof(struct tcphdr); } #ifdef INET6 - else if (is_ipv6) { + else if (tp->pf == AF_INET6) { /* * for IPv6, path MTU discovery is always turned on, * or the node must use packet size <= 1280. diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index 2453d4c132c..344f4a1317e 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_output.c,v 1.50 2002/05/16 14:10:51 kjc Exp $ */ +/* $OpenBSD: tcp_output.c,v 1.51 2002/06/07 16:18:02 itojun Exp $ */ /* $NetBSD: tcp_output.c,v 1.16 1997/06/03 16:17:09 kml Exp $ */ /* @@ -1117,16 +1117,16 @@ send: #ifdef INET6 case AF_INET6: { - struct ip6_hdr *ipv6; + struct ip6_hdr *ip6; - ipv6 = mtod(m, struct ip6_hdr *); - ipv6->ip6_plen = m->m_pkthdr.len - + ip6 = mtod(m, struct ip6_hdr *); + ip6->ip6_plen = m->m_pkthdr.len - sizeof(struct ip6_hdr); - ipv6->ip6_nxt = IPPROTO_TCP; - ipv6->ip6_hlim = in6_selecthlim(tp->t_inpcb, NULL); + ip6->ip6_nxt = IPPROTO_TCP; + ip6->ip6_hlim = in6_selecthlim(tp->t_inpcb, NULL); #ifdef TCP_ECN if (needect) - ipv6->ip6_flow |= htonl(IPTOS_ECN_ECT0 << 20); + ip6->ip6_flow |= htonl(IPTOS_ECN_ECT0 << 20); #endif } error = ip6_output(m, tp->t_inpcb->inp_outputopts6, diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 733cccc1ff5..93251f3c079 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_subr.c,v 1.62 2002/05/16 14:10:51 kjc Exp $ */ +/* $OpenBSD: tcp_subr.c,v 1.63 2002/06/07 16:18:02 itojun Exp $ */ /* $NetBSD: tcp_subr.c,v 1.22 1996/02/13 23:44:00 christos Exp $ */ /* @@ -268,18 +268,18 @@ tcp_template(tp) #ifdef INET6 case AF_INET6: { - struct ip6_hdr *ipv6; + struct ip6_hdr *ip6; - ipv6 = mtod(m, struct ip6_hdr *); + ip6 = mtod(m, struct ip6_hdr *); - ipv6->ip6_src = inp->inp_laddr6; - ipv6->ip6_dst = inp->inp_faddr6; - ipv6->ip6_flow = htonl(0x60000000) | + ip6->ip6_src = inp->inp_laddr6; + ip6->ip6_dst = inp->inp_faddr6; + ip6->ip6_flow = htonl(0x60000000) | (inp->inp_ipv6.ip6_flow & htonl(0x0fffffff)); - ipv6->ip6_nxt = IPPROTO_TCP; - ipv6->ip6_plen = htons(sizeof(struct tcphdr)); /*XXX*/ - ipv6->ip6_hlim = in6_selecthlim(inp, NULL); /*XXX*/ + ip6->ip6_nxt = IPPROTO_TCP; + ip6->ip6_plen = htons(sizeof(struct tcphdr)); /*XXX*/ + ip6->ip6_hlim = in6_selecthlim(inp, NULL); /*XXX*/ th = (struct tcphdr *)(mtod(m, caddr_t) + sizeof(struct ip6_hdr)); @@ -330,30 +330,23 @@ tcp_respond(tp, template, m, ack, seq, flags) struct route *ro = 0; register struct tcphdr *th; register struct tcpiphdr *ti = (struct tcpiphdr *)template; -#ifdef INET6 - int is_ipv6 = 0; /* true iff IPv6 */ -#endif /* INET6 */ + int af; /* af on wire */ if (tp) { win = sbspace(&tp->t_inpcb->inp_socket->so_rcv); -#ifdef INET6 /* * If this is called with an unconnected * socket/tp/pcb (tp->pf is 0), we lose. */ - is_ipv6 = (tp->pf == PF_INET6); + af = tp->pf; /* * The route/route6 distinction is meaningless * unless you're allocating space or passing parameters. */ -#endif /* INET6 */ ro = &tp->t_inpcb->inp_route; - } -#ifdef INET6 - else - is_ipv6 = (((struct ip *)ti)->ip_v == 6); -#endif /* INET6 */ + } else + af = (((struct ip *)ti)->ip_v == 6) ? AF_INET6 : AF_INET; if (m == 0) { m = m_gethdr(M_DONTWAIT, MT_HEADER); if (m == NULL) @@ -364,14 +357,18 @@ tcp_respond(tp, template, m, ack, seq, flags) tlen = 0; #endif m->m_data += max_linkhdr; + switch (af) { #ifdef INET6 - if (is_ipv6) + case AF_INET6: bcopy(ti, mtod(m, caddr_t), sizeof(struct tcphdr) + sizeof(struct ip6_hdr)); - else + break; #endif /* INET6 */ + case AF_INET: bcopy(ti, mtod(m, caddr_t), sizeof(struct tcphdr) + sizeof(struct ip)); + break; + } ti = mtod(m, struct tcpiphdr *); flags = TH_ACK; @@ -380,34 +377,37 @@ tcp_respond(tp, template, m, ack, seq, flags) m->m_next = 0; m->m_data = (caddr_t)ti; tlen = 0; -#define xchg(a,b,type) { type t; t=a; a=b; b=t; } +#define xchg(a,b,type) do { type t; t=a; a=b; b=t; } while (0) + switch (af) { #ifdef INET6 - if (is_ipv6) { + case AF_INET6: m->m_len = sizeof(struct tcphdr) + sizeof(struct ip6_hdr); - xchg(((struct ip6_hdr *)ti)->ip6_dst,\ - ((struct ip6_hdr *)ti)->ip6_src,\ - struct in6_addr); + xchg(((struct ip6_hdr *)ti)->ip6_dst, + ((struct ip6_hdr *)ti)->ip6_src, struct in6_addr); th = (void *)((caddr_t)ti + sizeof(struct ip6_hdr)); - } else + break; #endif /* INET6 */ - { + case AF_INET: m->m_len = sizeof (struct tcpiphdr); xchg(ti->ti_dst.s_addr, ti->ti_src.s_addr, u_int32_t); th = (void *)((caddr_t)ti + sizeof(struct ip)); + break; } xchg(th->th_dport, th->th_sport, u_int16_t); #undef xchg } + switch (af) { #ifdef INET6 - if (is_ipv6) { + case AF_INET6: tlen += sizeof(struct tcphdr) + sizeof(struct ip6_hdr); th = (struct tcphdr *)((caddr_t)ti + sizeof(struct ip6_hdr)); - } else + break; #endif /* INET6 */ - { + case AF_INET: ti->ti_len = htons((u_int16_t)(sizeof (struct tcphdr) + tlen)); tlen += sizeof (struct tcpiphdr); th = (struct tcphdr *)((caddr_t)ti + sizeof(struct ip)); + break; } m->m_len = tlen; @@ -425,8 +425,9 @@ tcp_respond(tp, template, m, ack, seq, flags) th->th_win = htons((u_int16_t)win); th->th_urp = 0; + switch (af) { #ifdef INET6 - if (is_ipv6) { + case AF_INET6: ((struct ip6_hdr *)ti)->ip6_flow = htonl(0x60000000); ((struct ip6_hdr *)ti)->ip6_nxt = IPPROTO_TCP; ((struct ip6_hdr *)ti)->ip6_hlim = @@ -437,10 +438,10 @@ tcp_respond(tp, template, m, ack, seq, flags) sizeof(struct ip6_hdr), ((struct ip6_hdr *)ti)->ip6_plen); HTONS(((struct ip6_hdr *)ti)->ip6_plen); ip6_output(m, tp ? tp->t_inpcb->inp_outputopts6 : NULL, - (struct route_in6 *)ro, 0, NULL, NULL); - } else + (struct route_in6 *)ro, 0, NULL, NULL); + break; #endif /* INET6 */ - { + case AF_INET: bzero(ti->ti_x1, sizeof ti->ti_x1); ti->ti_len = htons((u_short)tlen - sizeof(struct ip)); @@ -454,7 +455,8 @@ tcp_respond(tp, template, m, ack, seq, flags) ((struct ip *)ti)->ip_len = tlen; ((struct ip *)ti)->ip_ttl = ip_defttl; ip_output(m, NULL, ro, ip_mtudisc ? IP_MTUDISC : 0, NULL, - tp ? tp->t_inpcb : NULL); + tp ? tp->t_inpcb : NULL); + break; } } diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 774bc38bc9c..d4740fdfb9b 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.61 2002/05/26 15:27:07 fgsch Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.62 2002/06/07 16:18:02 itojun Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -782,7 +782,6 @@ tcp_ident(oldp, oldlenp, newp, newlen) size_t newlen; { int error = 0, s; - int is_ipv6 = 0; struct tcp_ident_mapping tir; struct inpcb *inp; struct sockaddr_in *fin, *lin; @@ -800,7 +799,6 @@ tcp_ident(oldp, oldlenp, newp, newlen) switch (tir.faddr.ss_family) { #ifdef INET6 case AF_INET6: - is_ipv6 = 1; fin6 = (struct sockaddr_in6 *)&tir.faddr; error = in6_embedscope(&f6, fin6, NULL, NULL); if (error) @@ -820,33 +818,35 @@ tcp_ident(oldp, oldlenp, newp, newlen) } s = splsoftnet(); - if (is_ipv6) { + switch (tir.faddr.ss_family) { + case AF_INET6: #ifdef INET6 inp = in6_pcbhashlookup(&tcbtable, &f6, fin6->sin6_port, &l6, lin6->sin6_port); -#else - panic("tcp_ident: cannot happen"); + break; #endif - } - else + case AF_INET: inp = in_pcbhashlookup(&tcbtable, fin->sin_addr, fin->sin_port, lin->sin_addr, lin->sin_port); + break; + } if (inp == NULL) { ++tcpstat.tcps_pcbhashmiss; - if (is_ipv6) { + switch (tir.faddr.ss_family) { #ifdef INET6 + case AF_INET6: inp = in_pcblookup(&tcbtable, &f6, fin6->sin6_port, &l6, lin6->sin6_port, INPLOOKUP_WILDCARD | INPLOOKUP_IPV6); -#else - panic("tcp_ident: cannot happen"); + break; #endif - } - else + case AF_INET: inp = in_pcblookup(&tcbtable, &fin->sin_addr, fin->sin_port, &lin->sin_addr, lin->sin_port, INPLOOKUP_WILDCARD); + break; + } } if (inp != NULL && (inp->inp_socket->so_state & SS_CONNECTOUT)) { |