diff --git a/distrib/sets/lists/comp/mi b/distrib/sets/lists/comp/mi index 5752e08f2f9..fa851cbf15c 100644 --- a/distrib/sets/lists/comp/mi +++ b/distrib/sets/lists/comp/mi @@ -2706,7 +2706,7 @@ ./usr/include/netinet/in_l2tp.h comp-c-include ./usr/include/netinet/in_offload.h comp-c-include ./usr/include/netinet/in_pcb.h comp-c-include -./usr/include/netinet/in_pcb_hdr.h comp-c-include +./usr/include/netinet/in_pcb_hdr.h comp-obsolete obsolete ./usr/include/netinet/in_route.h comp-obsolete obsolete ./usr/include/netinet/in_selsrc.h comp-c-include ./usr/include/netinet/in_systm.h comp-c-include diff --git a/sys/dist/pf/net/pf.c b/sys/dist/pf/net/pf.c index 11163b10f45..dca821a102d 100644 --- a/sys/dist/pf/net/pf.c +++ b/sys/dist/pf/net/pf.c @@ -2758,11 +2758,8 @@ pf_socket_lookup(int direction, struct pf_pdesc *pd) struct inpcbtable *tb; struct inpcb *inp = NULL; struct socket *so = NULL; -#if defined(__NetBSD__) && defined(INET6) - struct in6pcb *in6p = NULL; -#else #define in6p inp -#endif /* __NetBSD__ && INET6 */ +#define in6p_socket inp_socket if (pd == NULL) return (-1); diff --git a/sys/net/if_wg.c b/sys/net/if_wg.c index 11838decc9b..08cca458efb 100644 --- a/sys/net/if_wg.c +++ b/sys/net/if_wg.c @@ -3266,12 +3266,7 @@ wg_socreate(struct wg_softc *wg, int af, struct socket **sop) so->so_upcallarg = wg; so->so_upcall = wg_so_upcall; so->so_rcv.sb_flags |= SB_UPCALL; - if (af == AF_INET) - in_pcb_register_overudp_cb(sotoinpcb(so), wg_overudp_cb, wg); -#if INET6 - else - in6_pcb_register_overudp_cb(sotoin6pcb(so), wg_overudp_cb, wg); -#endif + in_pcb_register_overudp_cb(sotoinpcb(so), wg_overudp_cb, wg); sounlock(so); *sop = so; @@ -3924,7 +3919,7 @@ wg_send_udp(struct wg_peer *wgp, struct mbuf *m) error = udp_send(so, m, wgsatosa(wgsa), NULL, curlwp); } else { #ifdef INET6 - error = udp6_output(sotoin6pcb(so), m, wgsatosin6(wgsa), + error = udp6_output(sotoinpcb(so), m, wgsatosin6(wgsa), NULL, curlwp); #else m_freem(m); diff --git a/sys/netinet/Makefile b/sys/netinet/Makefile index a044cdefc49..d1577964000 100644 --- a/sys/netinet/Makefile +++ b/sys/netinet/Makefile @@ -3,7 +3,7 @@ INCSDIR= /usr/include/netinet INCS= dccp.h icmp6.h icmp_var.h if_ether.h if_inarp.h igmp.h \ - igmp_var.h in.h in_gif.h in_l2tp.h in_pcb.h in_pcb_hdr.h \ + igmp_var.h in.h in_gif.h in_l2tp.h in_pcb.h \ in_offload.h in_selsrc.h in_systm.h \ in_var.h ip.h ip_carp.h ip6.h ip_ecn.h ip_encap.h \ ip_icmp.h ip_mroute.h ip_var.h pim.h pim_var.h portalgo.h \ diff --git a/sys/netinet/dccp_usrreq.c b/sys/netinet/dccp_usrreq.c index 000720a494e..dcc4b869c02 100644 --- a/sys/netinet/dccp_usrreq.c +++ b/sys/netinet/dccp_usrreq.c @@ -188,7 +188,6 @@ dccp_input(struct mbuf *m, int off, int proto) struct dccphdr *dh; struct dccplhdr *dlh; struct inpcb *inp = NULL, *oinp = NULL; - struct in6pcb *in6p = NULL, *oin6p = NULL; struct dccpcb *dp; struct ipovly *ipov = NULL; struct dccp_requesthdr *drqh; @@ -338,11 +337,11 @@ dccp_input(struct mbuf *m, int off, int proto) */ #ifdef INET6 if (isipv6) { - in6p = in6_pcblookup_connect(&dccpbtable, &ip6->ip6_src, + inp = in6_pcblookup_connect(&dccpbtable, &ip6->ip6_src, dh->dh_sport, &ip6->ip6_dst, dh->dh_dport, 0, 0); - if (in6p == 0) { + if (inp == NULL) { /* XXX stats increment? */ - in6p = in6_pcblookup_bind(&dccpbtable, &ip6->ip6_dst, + inp = in6_pcblookup_bind(&dccpbtable, &ip6->ip6_dst, dh->dh_dport, 0); } } else @@ -357,12 +356,12 @@ dccp_input(struct mbuf *m, int off, int proto) } } if (isipv6) { - DCCP_DEBUG((LOG_INFO, "in6p=%p\n", in6p)); + DCCP_DEBUG((LOG_INFO, "in6p=%p\n", inp)); } else { DCCP_DEBUG((LOG_INFO, "inp=%p\n", inp)); } - if (isipv6 ? in6p == NULL : inp == NULL) { + if (inp == NULL) { if (dccp_log_in_vain) { #ifdef INET6 char dbuf[INET6_ADDRSTRLEN+2], sbuf[INET6_ADDRSTRLEN+2]; @@ -409,14 +408,8 @@ dccp_input(struct mbuf *m, int off, int proto) } INP_LOCK(inp); -#ifdef INET6 - if (isipv6) - dp = in6todccpcb(in6p); - else -#endif - dp = intodccpcb(inp); - - if (dp == 0) { + dp = intodccpcb(inp); + if (dp == NULL) { INP_UNLOCK(inp); INP_INFO_WUNLOCK(&dccpbinfo); goto badunlocked; @@ -431,12 +424,7 @@ dccp_input(struct mbuf *m, int off, int proto) goto badunlocked; } -#if defined(INET6) - if (isipv6) - so = in6p->in6p_socket; - else -#endif - so = inp->inp_socket; + so = inp->inp_socket; if (so->so_options & SO_ACCEPTCONN) { DCCP_DEBUG((LOG_INFO, "so->options & SO_ACCEPTCONN! dp->state = %i\n", dp->state)); @@ -450,21 +438,16 @@ dccp_input(struct mbuf *m, int off, int proto) /* INP_LOCK(inp); XXX */ -#if defined(INET6) - if (isipv6) - oin6p = in6p; - else -#endif - oinp = inp; + oinp = inp; #ifdef INET6 if (isipv6) { - in6p = sotoin6pcb(so); - in6p->in6p_laddr = ip6->ip6_dst; - in6p->in6p_faddr = ip6->ip6_src; - in6p->in6p_lport = dh->dh_dport; - in6p->in6p_fport = dh->dh_sport; - in6_pcbstate(in6p, IN6P_CONNECTED); + inp = sotoinpcb(so); + inp->inp_laddr6 = ip6->ip6_dst; + inp->inp_faddr6 = ip6->ip6_src; + inp->inp_lport = dh->dh_dport; + inp->inp_fport = dh->dh_sport; + in_pcbstate(inp, INP_CONNECTED); } else #endif { @@ -478,27 +461,13 @@ dccp_input(struct mbuf *m, int off, int proto) if (!isipv6) in_pcbstate(inp, INP_BOUND); -#if defined(INET6) - if (isipv6) - dp = (struct dccpcb *)in6p->in6p_ppcb; - else -#endif - dp = (struct dccpcb *)inp->inp_ppcb; + dp = inp->inp_ppcb; dp->state = DCCPS_LISTEN; dp->who = DCCP_SERVER; -#if defined(INET6) - if (isipv6) { - dp->cslen = ((struct dccpcb *)oin6p->in6p_ppcb)->cslen; - dp->avgpsize = ((struct dccpcb *)oin6p->in6p_ppcb)->avgpsize; - dp->scode = ((struct dccpcb *)oin6p->in6p_ppcb)->scode; - } else -#endif - { - dp->cslen = ((struct dccpcb *)oinp->inp_ppcb)->cslen; - dp->avgpsize = ((struct dccpcb *)oinp->inp_ppcb)->avgpsize; - dp->scode = ((struct dccpcb *)oinp->inp_ppcb)->scode; - } + dp->cslen = ((struct dccpcb *)oinp->inp_ppcb)->cslen; + dp->avgpsize = ((struct dccpcb *)oinp->inp_ppcb)->avgpsize; + dp->scode = ((struct dccpcb *)oinp->inp_ppcb)->scode; dp->seq_snd = (((u_int64_t)random() << 32) | random()) % 281474976710656LL; dp->ref_seq.hi = dp->seq_snd >> 24; dp->ref_seq.lo = (u_int64_t)(dp->seq_snd & 0xffffff); @@ -690,12 +659,7 @@ dccp_input(struct mbuf *m, int off, int proto) DCCP_DEBUG((LOG_INFO, "Setting DCCPS_ESTAB & soisconnected\n")); dp->state = DCCPS_ESTAB; dccpstat.dccps_connects++; -#if defined(INET6) - if (isipv6) - soisconnected(in6p->in6p_socket); - else -#endif - soisconnected(inp->inp_socket); + soisconnected(inp->inp_socket); } else { dp->state = DCCPS_RESPOND; DCCP_DEBUG((LOG_INFO, "CC negotiation is not finished, cc_in_use[0] = %u, cc_in_use[1] = %u\n",dp->cc_in_use[0], dp->cc_in_use[1])); @@ -744,12 +708,7 @@ dccp_input(struct mbuf *m, int off, int proto) DCCP_DEBUG((LOG_INFO, "Setting DCCPS_ESTAB & soisconnected\n")); dp->state = DCCPS_ESTAB; dccpstat.dccps_connects++; -#if defined(INET6) - if (isipv6) - soisconnected(in6p->in6p_socket); - else -#endif - soisconnected(inp->inp_socket); + soisconnected(inp->inp_socket); } else { DCCP_DEBUG((LOG_INFO, "CC negotiation is not finished, cc_in_use[0] = %u, cc_in_use[1] = %u\n",dp->cc_in_use[0], dp->cc_in_use[1])); /* Force an output!!! */ @@ -1094,9 +1053,6 @@ dccp_ctloutput(int op, struct socket *so, struct sockopt *sopt) { int s, error = 0; struct inpcb *inp; -#if defined(INET6) - struct in6pcb *in6p; -#endif struct dccpcb *dp; int family; /* family of the socket */ @@ -1105,29 +1061,8 @@ dccp_ctloutput(int op, struct socket *so, struct sockopt *sopt) s = splsoftnet(); INP_INFO_RLOCK(&dccpbinfo); - switch (family) { - case PF_INET: - inp = sotoinpcb(so); -#if defined(INET6) - in6p = NULL; -#endif - break; -#if defined(INET6) - case PF_INET6: - inp = NULL; - in6p = sotoin6pcb(so); - break; -#endif - default: - INP_INFO_RUNLOCK(&dccpbinfo); - splx(s); - return EAFNOSUPPORT; - } -#if defined(INET6) - if (inp == NULL && in6p == NULL) -#else + inp = sotoinpcb(so); if (inp == NULL) -#endif { INP_INFO_RUNLOCK(&dccpbinfo); splx(s); @@ -1155,14 +1090,7 @@ dccp_ctloutput(int op, struct socket *so, struct sockopt *sopt) return (error); } - if (inp) - dp = intodccpcb(inp); -#if defined(INET6) - else if (in6p) - dp = in6todccpcb(in6p); -#endif - else - dp = NULL; + dp = intodccpcb(inp); if (op == PRCO_SETOPT) { error = dccp_optsset(dp, sopt); @@ -1185,7 +1113,6 @@ int dccp_output(struct dccpcb *dp, u_int8_t extra) { struct inpcb *inp; - struct in6pcb *in6p = NULL; struct socket *so; struct mbuf *m; @@ -1218,17 +1145,8 @@ dccp_output(struct dccpcb *dp, u_int8_t extra) KASSERT(mutex_assert(&dp->d_inpcb->inp_mtx, MA_OWNED)); #endif -#if defined(INET6) - if (isipv6) { - inp = 0; - in6p = dp->d_in6pcb; - so = in6p->in6p_socket; - } else -#endif - { - inp = dp->d_inpcb; - so = inp->inp_socket; - } + inp = dp->d_inpcb; + so = inp->inp_socket; if (dp->state != DCCPS_ESTAB && extra == 1) { /* Only let cc decide when to resend if we are in established state */ @@ -1435,12 +1353,12 @@ again: ip6 = mtod(m, struct ip6_hdr *); dh = (struct dccphdr *)(ip6 + 1); ip6->ip6_flow = (ip6->ip6_flow & ~IPV6_FLOWINFO_MASK) | - (in6p->in6p_flowinfo & IPV6_FLOWINFO_MASK); + (inp->inp_flowinfo & IPV6_FLOWINFO_MASK); ip6->ip6_vfc = (ip6->ip6_vfc & ~IPV6_VERSION_MASK) | (IPV6_VERSION & IPV6_VERSION_MASK); ip6->ip6_nxt = IPPROTO_DCCP; - ip6->ip6_src = in6p->in6p_laddr; - ip6->ip6_dst = in6p->in6p_faddr; + ip6->ip6_src = inp->inp_laddr6; + ip6->ip6_dst = inp->inp_faddr6; } else #endif { @@ -1453,16 +1371,8 @@ again: } dlh = (struct dccplhdr *)dh; - if (inp) { - dh->dh_sport = inp->inp_lport; - dh->dh_dport = inp->inp_fport; - } -#ifdef INET6 - else if (in6p) { - dh->dh_sport = in6p->in6p_lport; - dh->dh_dport = in6p->in6p_fport; - } -#endif + dh->dh_sport = inp->inp_lport; + dh->dh_dport = inp->inp_fport; dh->dh_cscov = dp->cslen; dh->dh_ccval = dp->ccval; dh->dh_type = type; @@ -1597,8 +1507,8 @@ again: if (isipv6) { DCCP_DEBUG((LOG_INFO, "Calling ip_output6, mbuf->m_len = %u, mbuf->m_pkthdr.len = %u\n", m->m_len, m->m_pkthdr.len)); - error = ip6_output(m, in6p->in6p_outputopts, &in6p->in6p_route, - (in6p->in6p_socket->so_options & SO_DONTROUTE), NULL, NULL, + error = ip6_output(m, inp->inp_outputopts6, &inp->inp_route, + (inp->inp_socket->so_options & SO_DONTROUTE), NULL, NULL, NULL); } else #endif @@ -1614,16 +1524,8 @@ again: return (error); } -#if defined(INET6) - if (isipv6) { - sbdrop(&in6p->in6p_socket->so_snd, len); - sowwakeup(in6p->in6p_socket); - } else -#endif - { - sbdrop(&inp->inp_socket->so_snd, len); - sowwakeup(inp->inp_socket); - } + sbdrop(&inp->inp_socket->so_snd, len); + sowwakeup(inp->inp_socket); if (dp->cc_in_use[0] > 0 && dp->state == DCCPS_ESTAB) { DCCP_DEBUG((LOG_INFO, "Calling *cc_sw[%u].cc_send_packet_sent!\n", dp->cc_in_use[0])); @@ -1650,27 +1552,17 @@ release: int dccp_abort(struct socket *so) { - struct inpcb *inp = 0; - struct in6pcb *in6p; + struct inpcb *inp = NULL; struct dccpcb *dp; DCCP_DEBUG((LOG_INFO, "Entering dccp_abort!\n")); INP_INFO_WLOCK(&dccpbinfo); - if (so->so_proto->pr_domain->dom_family == PF_INET6) { - in6p = sotoin6pcb(so); - if (in6p == 0) { - return EINVAL; - } - inp = 0; - dp = (struct dccpcb *)in6p->in6p_ppcb; - } else { - inp = sotoinpcb(so); - if (inp == 0) { - INP_INFO_WUNLOCK(&dccpbinfo); - return EINVAL; - } - dp = (struct dccpcb *)inp->inp_ppcb; + inp = sotoinpcb(so); + if (inp == NULL) { + INP_INFO_WUNLOCK(&dccpbinfo); + return EINVAL; } + dp = inp->inp_ppcb; dccp_disconnect2(dp); @@ -1683,7 +1575,6 @@ dccp_close(struct dccpcb *dp) { struct socket *so; struct inpcb *inp = dp->d_inpcb; - struct in6pcb *in6p = dp->d_in6pcb; so = dptosocket(dp); DCCP_DEBUG((LOG_INFO, "Entering dccp_close!\n")); @@ -1700,18 +1591,9 @@ dccp_close(struct dccpcb *dp) (*cc_sw[dp->cc_in_use[1]].cc_recv_free)(dp->cc_state[1]); pool_put(&dccpcb_pool, dp); - if (inp) { - inp->inp_ppcb = NULL; - soisdisconnected(so); - in_pcbdetach(inp); - } -#if defined(INET6) - else if (in6p) { - in6p->in6p_ppcb = 0; - soisdisconnected(so); - in6_pcbdetach(in6p); - } -#endif + inp->inp_ppcb = NULL; + soisdisconnected(so); + in_pcbdetach(inp); return ((struct dccpcb *)0); } @@ -1722,69 +1604,33 @@ dccp_close(struct dccpcb *dp) int dccp_attach(struct socket *so, int proto) { - struct inpcb *inp = 0; - struct in6pcb *in6p = 0; + struct inpcb *inp = NULL; struct dccpcb *dp; - int s, family, error = 0; + int s, error = 0; DCCP_DEBUG((LOG_INFO, "Entering dccp_attach(proto=%d)!\n", proto)); INP_INFO_WLOCK(&dccpbinfo); s = splsoftnet(); sosetlock(so); - family = so->so_proto->pr_domain->dom_family; - switch (family) { - case PF_INET: - inp = sotoinpcb(so); - if (inp != 0) { - error = EINVAL; - goto out; - } - error = soreserve(so, dccp_sendspace, dccp_recvspace); - if (error) - goto out; - error = in_pcballoc(so, &dccpbtable); - if (error) - goto out; - inp = sotoinpcb(so); - break; -#if defined(INET6) - case PF_INET6: - in6p = sotoin6pcb(so); - if (in6p != 0) { - error = EINVAL; - goto out; - } - error = soreserve(so, dccp_sendspace, dccp_recvspace); - if (error) - goto out; - error = in6_pcballoc(so, &dccpbtable); - if (error) - goto out; - in6p = sotoin6pcb(so); - break; -#endif - default: - error = EAFNOSUPPORT; + inp = sotoinpcb(so); + if (inp != 0) { + error = EINVAL; goto out; } + error = soreserve(so, dccp_sendspace, dccp_recvspace); + if (error) + goto out; + error = in_pcballoc(so, &dccpbtable); + if (error) + goto out; + inp = sotoinpcb(so); - if (inp) - dp = dccp_newdccpcb(PF_INET, (void *)inp); - else if (in6p) - dp = dccp_newdccpcb(PF_INET6, (void *)in6p); - else - dp = NULL; - + dp = dccp_newdccpcb(inp->inp_af, inp); if (dp == 0) { int nofd = so->so_state & SS_NOFDREF; so->so_state &= ~SS_NOFDREF; -#if defined(INET6) - if (proto == PF_INET6) { - in6_pcbdetach(in6p); - } else -#endif - in_pcbdetach(inp); + in_pcbdetach(inp); so->so_state |= nofd; error = ENOBUFS; goto out; @@ -1924,33 +1770,17 @@ dccp_doconnect(struct socket *so, struct sockaddr *nam, struct lwp *l, int isipv6) { struct inpcb *inp; -#ifdef INET6 - struct in6pcb *in6p; -#endif int error = 0; DCCP_DEBUG((LOG_INFO, "Entering dccp_doconnect!\n")); -#if defined(INET6) - if (isipv6) { - in6p = sotoin6pcb(so); - inp = 0; - } else -#endif - { - inp = sotoinpcb(so); - in6p = 0; - } + inp = sotoinpcb(so); -#if !defined(__NetBSD__) || !defined(INET6) if (inp->inp_lport == 0) { -#else - if (isipv6 ? in6p->in6p_lport == 0 : inp->inp_lport == 0) { -#endif #ifdef INET6 if (isipv6) { DCCP_DEBUG((LOG_INFO, "Running in6_pcbbind!\n")); - error = in6_pcbbind(in6p, NULL, l); + error = in6_pcbbind(inp, NULL, l); } else #endif /* INET6 */ { @@ -1964,7 +1794,7 @@ dccp_doconnect(struct socket *so, struct sockaddr *nam, #ifdef INET6 if (isipv6) { - error = in6_pcbconnect(in6p, (struct sockaddr_in6 *)nam, l); + error = in6_pcbconnect(inp, (struct sockaddr_in6 *)nam, l); DCCP_DEBUG((LOG_INFO, "in6_pcbconnect=%d\n",error)); } else #endif @@ -1986,26 +1816,14 @@ int dccp_detach(struct socket *so) { struct inpcb *inp; - struct in6pcb *in6p; struct dccpcb *dp; DCCP_DEBUG((LOG_INFO, "Entering dccp_detach!\n")); -#ifdef INET6 - if (so->so_proto->pr_domain->dom_family == AF_INET6) { - in6p = sotoin6pcb(so); - if (in6p == 0) { - return EINVAL; - } - dp = (struct dccpcb *)in6p->in6p_ppcb; - } else -#endif - { - inp = sotoinpcb(so); - if (inp == 0) { - return EINVAL; - } - dp = (struct dccpcb *)inp->inp_ppcb; + inp = sotoinpcb(so); + if (inp == NULL) { + return EINVAL; } + dp = inp->inp_ppcb; if (! dccp_disconnect2(dp)) { INP_UNLOCK(inp); } @@ -2021,7 +1839,6 @@ int dccp_disconnect(struct socket *so) { struct inpcb *inp; - struct in6pcb *in6p; struct dccpcb *dp; DCCP_DEBUG((LOG_INFO, "Entering dccp_disconnect!\n")); @@ -2041,23 +1858,12 @@ dccp_disconnect(struct socket *so) dp = (struct dccpcb *)inp->inp_ppcb; #else /* NetBSD */ -#ifdef INET6 - if (so->so_proto->pr_domain->dom_family == AF_INET6) { - in6p = sotoin6pcb(so); - if (in6p == 0) { - INP_INFO_WUNLOCK(&dccpbinfo); - return EINVAL; - } - dp = (struct dccpcb *)in6p->in6p_ppcb; - } else -#endif - { - inp = sotoinpcb(so); - if (inp == 0) { - return EINVAL; - } - dp = (struct dccpcb *)inp->inp_ppcb; + inp = sotoinpcb(so); + if (inp == NULL) { + INP_INFO_WUNLOCK(&dccpbinfo); + return EINVAL; } + dp = inp->inp_ppcb; #endif if (!dccp_disconnect2(dp)) { INP_UNLOCK(inp); @@ -2124,27 +1930,15 @@ dccp_send(struct socket *so, struct mbuf *m, struct sockaddr *addr, isipv6 = addr && addr->sa_family == AF_INET6; #endif -#if defined(INET6) - if (so->so_proto->pr_domain->dom_family == AF_INET6) { - struct in6pcb *in6p; - in6p = sotoin6pcb(so); - if (in6p == 0) { - error = EINVAL; - goto release; - } - dp = (struct dccpcb *)in6p->in6p_ppcb; - } else -#endif - { - INP_INFO_WLOCK(&dccpbinfo); - inp = sotoinpcb(so); - if (inp == 0) { - error = EINVAL; - goto release; - } - INP_LOCK(inp); - dp = (struct dccpcb *)inp->inp_ppcb; + INP_INFO_WLOCK(&dccpbinfo); + inp = sotoinpcb(so); + if (inp == NULL) { + error = EINVAL; + goto release; } + INP_LOCK(inp); + dp = inp->inp_ppcb; + if (dp->state != DCCPS_ESTAB) { DCCP_DEBUG((LOG_INFO, "We have no established connection!\n")); } @@ -2289,7 +2083,6 @@ struct dccpcb * dccp_newdccpcb(int family, void *aux) { struct inpcb *inp; - struct in6pcb *in6p; struct dccpcb *dp; DCCP_DEBUG((LOG_INFO, "Creating a new dccpcb!\n")); @@ -2332,18 +2125,15 @@ dccp_newdccpcb(int family, void *aux) dp->pktlenidx = 0; dp->pktcnt = 0; + inp = (struct inpcb *)aux; + dp->d_inpcb = inp; + inp->inp_ppcb = dp; switch (family) { case PF_INET: - inp = (struct inpcb *)aux; - dp->d_inpcb = inp; inp->inp_ip.ip_ttl = ip_defttl; - inp->inp_ppcb = dp; break; case PF_INET6: - in6p = (struct in6pcb *)aux; - dp->d_in6pcb = in6p; - in6p->in6p_ip6.ip6_hlim = in6_selecthlim_rt(in6p); - in6p->in6p_ppcb = dp; + inp->inp_ip6.ip6_hlim = in6_selecthlim_rt(inp); break; } diff --git a/sys/netinet/dccp_var.h b/sys/netinet/dccp_var.h index 09c6b3e5111..6e1c60a5520 100644 --- a/sys/netinet/dccp_var.h +++ b/sys/netinet/dccp_var.h @@ -96,7 +96,6 @@ struct dccpcb { (in each direction) */ void *cc_state[2]; struct inpcb *d_inpcb; /* Pointer back to Internet PCB */ - struct in6pcb *d_in6pcb; u_int32_t d_maxseg; /* Maximum segment size */ char options[DCCP_MAX_OPTIONS]; u_int8_t optlen; @@ -153,14 +152,7 @@ struct xdccpcb { #endif #define intodccpcb(ip) ((struct dccpcb *)((ip)->inp_ppcb)) -#define in6todccpcb(ip) ((struct dccpcb *)((ip)->in6p_ppcb)) - -#ifdef __NetBSD__ -#define dptosocket(dp) (((dp)->d_inpcb) ? (dp)->d_inpcb->inp_socket : \ - (((dp)->d_in6pcb) ? (dp)->d_in6pcb->in6p_socket : NULL)) -#else #define dptosocket(dp) ((dp)->d_inpcb->inp_socket) -#endif struct dccpstat { u_long dccps_connattempt; /* Initiated connections */ diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 20e140630a1..07537579f11 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -192,13 +192,13 @@ in_pcballoc(struct socket *so, void *v) struct inpcb *inp; int s; - KASSERT(so->so_proto->pr_domain->dom_family == AF_INET); + KASSERT(soaf(so) == AF_INET || soaf(so) == AF_INET6); inp = pool_get(&inpcb_pool, PR_NOWAIT); if (inp == NULL) return (ENOBUFS); memset(inp, 0, sizeof(*inp)); - inp->inp_af = AF_INET; + inp->inp_af = soaf(so); inp->inp_table = table; inp->inp_socket = so; inp->inp_errormtu = -1; @@ -207,6 +207,12 @@ in_pcballoc(struct socket *so, void *v) inp->inp_prefsrcip.s_addr = INADDR_ANY; inp->inp_overudp_cb = NULL; inp->inp_overudp_arg = NULL; +#ifdef INET6 + inp->inp_hops6 = -1; /* use kernel default */ + inp->inp_icmp6filt = NULL; + if (inp->inp_af == AF_INET6 && ip6_v6only) + inp->inp_flags |= IN6P_IPV6_V6ONLY; +#endif #if defined(IPSEC) if (ipsec_enabled) { int error = ipsec_init_pcbpolicy(so, &inp->inp_sp); @@ -214,14 +220,14 @@ in_pcballoc(struct socket *so, void *v) pool_put(&inpcb_pool, inp); return error; } - inp->inp_sp->sp_inph = (struct inpcb_hdr *)inp; + inp->inp_sp->sp_inp = inp; } #endif so->so_pcb = inp; s = splsoftnet(); - TAILQ_INSERT_HEAD(&table->inpt_queue, &inp->inp_head, inph_queue); - LIST_INSERT_HEAD(INPCBHASH_PORT(table, inp->inp_lport), &inp->inp_head, - inph_lhash); + TAILQ_INSERT_HEAD(&table->inpt_queue, inp, inp_queue); + LIST_INSERT_HEAD(INPCBHASH_PORT(table, inp->inp_lport), inp, + inp_lhash); in_pcbstate(inp, INP_ATTACHED); splx(s); return (0); @@ -260,7 +266,7 @@ in_pcbsetport(struct sockaddr_in *sin, struct inpcb *inp, kauth_cred_t cred) /* * Use RFC6056 randomized port selection */ - error = portalgo_randport(&lport, &inp->inp_head, cred); + error = portalgo_randport(&lport, inp, cred); if (error) return error; @@ -351,7 +357,7 @@ in_pcbbind_port(struct inpcb *inp, struct sockaddr_in *sin, kauth_cred_t cred) struct inpcb *t; vestigial_inpcb_t vestige; #ifdef INET6 - struct in6pcb *t6; + struct inpcb *t6; struct in6_addr mapped; #endif enum kauth_network_req req; @@ -374,7 +380,7 @@ in_pcbbind_port(struct inpcb *inp, struct sockaddr_in *sin, kauth_cred_t cred) #ifdef INET6 in6_in_2_v4mapin6(&sin->sin_addr, &mapped); t6 = in6_pcblookup_port(table, &mapped, sin->sin_port, wild, &vestige); - if (t6 && (reuseport & t6->in6p_socket->so_options) == 0) + if (t6 && (reuseport & t6->inp_socket->so_options) == 0) return (EADDRINUSE); if (!t6 && vestige.valid) { if (!!reuseport != !!vestige.reuse_port) { @@ -419,9 +425,9 @@ in_pcbbind_port(struct inpcb *inp, struct sockaddr_in *sin, kauth_cred_t cred) in_pcbstate(inp, INP_BOUND); } - LIST_REMOVE(&inp->inp_head, inph_lhash); - LIST_INSERT_HEAD(INPCBHASH_PORT(table, inp->inp_lport), &inp->inp_head, - inph_lhash); + LIST_REMOVE(inp, inp_lhash); + LIST_INSERT_HEAD(INPCBHASH_PORT(table, inp->inp_lport), inp, + inp_lhash); return (0); } @@ -628,8 +634,7 @@ in_pcbdetach(void *v) struct socket *so = inp->inp_socket; int s; - if (inp->inp_af != AF_INET) - return; + KASSERT(inp->inp_af == AF_INET || inp->inp_af == AF_INET6); #if defined(IPSEC) if (ipsec_enabled) @@ -639,14 +644,19 @@ in_pcbdetach(void *v) s = splsoftnet(); in_pcbstate(inp, INP_ATTACHED); - LIST_REMOVE(&inp->inp_head, inph_lhash); - TAILQ_REMOVE(&inp->inp_table->inpt_queue, &inp->inp_head, inph_queue); + LIST_REMOVE(inp, inp_lhash); + TAILQ_REMOVE(&inp->inp_table->inpt_queue, inp, inp_queue); splx(s); if (inp->inp_options) { m_free(inp->inp_options); } + if (inp->inp_outputopts6 != NULL) { + ip6_clearpktopts(inp->inp_outputopts6, -1); + free(inp->inp_outputopts6, M_IP6OPT); + } rtcache_free(&inp->inp_route); + ip6_freemoptions(inp->inp_moptions6); ip_freemoptions(inp->inp_moptions); sofree(so); /* drops the socket's lock */ @@ -691,7 +701,6 @@ in_pcbnotify(struct inpcbtable *table, struct in_addr faddr, u_int fport_arg, void (*notify)(struct inpcb *, int)) { struct inpcbhead *head; - struct inpcb_hdr *inph; struct inpcb *inp; u_int16_t fport = fport_arg, lport = lport_arg; int nmatch; @@ -701,8 +710,7 @@ in_pcbnotify(struct inpcbtable *table, struct in_addr faddr, u_int fport_arg, nmatch = 0; head = INPCBHASH_CONNECT(table, faddr, fport, laddr, lport); - LIST_FOREACH(inph, head, inph_hash) { - inp = (struct inpcb *)inph; + LIST_FOREACH(inp, head, inp_hash) { if (inp->inp_af != AF_INET) continue; @@ -721,13 +729,12 @@ void in_pcbnotifyall(struct inpcbtable *table, struct in_addr faddr, int errno, void (*notify)(struct inpcb *, int)) { - struct inpcb_hdr *inph; + struct inpcb *inp; if (in_nullhost(faddr) || notify == 0) return; - TAILQ_FOREACH(inph, &table->inpt_queue, inph_queue) { - struct inpcb *inp = (struct inpcb *)inph; + TAILQ_FOREACH(inp, &table->inpt_queue, inp_queue) { if (inp->inp_af != AF_INET) continue; if (in_hosteq(inp->inp_faddr, faddr)) @@ -770,10 +777,9 @@ in_purgeifmcast(struct ip_moptions *imo, struct ifnet *ifp) void in_pcbpurgeif0(struct inpcbtable *table, struct ifnet *ifp) { - struct inpcb_hdr *inph; + struct inpcb *inp; - TAILQ_FOREACH(inph, &table->inpt_queue, inph_queue) { - struct inpcb *inp = (struct inpcb *)inph; + TAILQ_FOREACH(inp, &table->inpt_queue, inp_queue) { bool need_unlock = false; if (inp->inp_af != AF_INET) @@ -796,10 +802,9 @@ void in_pcbpurgeif(struct inpcbtable *table, struct ifnet *ifp) { struct rtentry *rt; - struct inpcb_hdr *inph; + struct inpcb *inp; - TAILQ_FOREACH(inph, &table->inpt_queue, inph_queue) { - struct inpcb *inp = (struct inpcb *)inph; + TAILQ_FOREACH(inp, &table->inpt_queue, inp_queue) { if (inp->inp_af != AF_INET) continue; if ((rt = rtcache_validate(&inp->inp_route)) != NULL && @@ -875,7 +880,7 @@ in_pcblookup_port(struct inpcbtable *table, struct in_addr laddr, u_int lport_arg, int lookup_wildcard, vestigial_inpcb_t *vp) { struct inpcbhead *head; - struct inpcb_hdr *inph; + struct inpcb *inp; struct inpcb *match = NULL; int matchwild = 3; int wildcard; @@ -885,9 +890,7 @@ in_pcblookup_port(struct inpcbtable *table, struct in_addr laddr, vp->valid = 0; head = INPCBHASH_PORT(table, lport); - LIST_FOREACH(inph, head, inph_lhash) { - struct inpcb * const inp = (struct inpcb *)inph; - + LIST_FOREACH(inp, head, inp_lhash) { if (inp->inp_af != AF_INET) continue; if (inp->inp_lport != lport) @@ -988,7 +991,6 @@ in_pcblookup_connect(struct inpcbtable *table, vestigial_inpcb_t *vp) { struct inpcbhead *head; - struct inpcb_hdr *inph; struct inpcb *inp; u_int16_t fport = fport_arg, lport = lport_arg; @@ -996,8 +998,7 @@ in_pcblookup_connect(struct inpcbtable *table, vp->valid = 0; head = INPCBHASH_CONNECT(table, faddr, fport, laddr, lport); - LIST_FOREACH(inph, head, inph_hash) { - inp = (struct inpcb *)inph; + LIST_FOREACH(inp, head, inp_hash) { if (inp->inp_af != AF_INET) continue; @@ -1024,10 +1025,9 @@ in_pcblookup_connect(struct inpcbtable *table, out: /* Move this PCB to the head of hash chain. */ - inph = &inp->inp_head; - if (inph != LIST_FIRST(head)) { - LIST_REMOVE(inph, inph_hash); - LIST_INSERT_HEAD(head, inph, inph_hash); + if (inp != LIST_FIRST(head)) { + LIST_REMOVE(inp, inp_hash); + LIST_INSERT_HEAD(head, inp, inp_hash); } return (inp); } @@ -1037,13 +1037,11 @@ in_pcblookup_bind(struct inpcbtable *table, struct in_addr laddr, u_int lport_arg) { struct inpcbhead *head; - struct inpcb_hdr *inph; struct inpcb *inp; u_int16_t lport = lport_arg; head = INPCBHASH_BIND(table, laddr, lport); - LIST_FOREACH(inph, head, inph_hash) { - inp = (struct inpcb *)inph; + LIST_FOREACH(inp, head, inp_hash) { if (inp->inp_af != AF_INET) continue; @@ -1052,8 +1050,7 @@ in_pcblookup_bind(struct inpcbtable *table, goto out; } head = INPCBHASH_BIND(table, zeroin_addr, lport); - LIST_FOREACH(inph, head, inph_hash) { - inp = (struct inpcb *)inph; + LIST_FOREACH(inp, head, inp_hash) { if (inp->inp_af != AF_INET) continue; @@ -1071,10 +1068,9 @@ in_pcblookup_bind(struct inpcbtable *table, out: /* Move this PCB to the head of hash chain. */ - inph = &inp->inp_head; - if (inph != LIST_FIRST(head)) { - LIST_REMOVE(inph, inph_hash); - LIST_INSERT_HEAD(head, inph, inph_hash); + if (inp != LIST_FIRST(head)) { + LIST_REMOVE(inp, inp_hash); + LIST_INSERT_HEAD(head, inp, inp_hash); } return (inp); } @@ -1083,23 +1079,25 @@ void in_pcbstate(struct inpcb *inp, int state) { - if (inp->inp_af != AF_INET) + if (inp->inp_af == AF_INET6) { + in6_pcbstate(inp, state); return; + } if (inp->inp_state > INP_ATTACHED) - LIST_REMOVE(&inp->inp_head, inph_hash); + LIST_REMOVE(inp, inp_hash); switch (state) { case INP_BOUND: LIST_INSERT_HEAD(INPCBHASH_BIND(inp->inp_table, - inp->inp_laddr, inp->inp_lport), &inp->inp_head, - inph_hash); + inp->inp_laddr, inp->inp_lport), inp, + inp_hash); break; case INP_CONNECTED: LIST_INSERT_HEAD(INPCBHASH_CONNECT(inp->inp_table, inp->inp_faddr, inp->inp_fport, - inp->inp_laddr, inp->inp_lport), &inp->inp_head, - inph_hash); + inp->inp_laddr, inp->inp_lport), inp, + inp_hash); break; } @@ -1115,6 +1113,8 @@ in_pcbrtentry(struct inpcb *inp) struct sockaddr_in dst4; } u; + if (inp->inp_af == AF_INET6) + return in6_pcbrtentry(inp); if (inp->inp_af != AF_INET) return (NULL); diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index 37aa382ad76..5289f1a7296 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -68,11 +68,15 @@ #include #include -#include #include +#include + +typedef int (*pcb_overudp_cb_t)(struct mbuf **, int, struct socket *, + struct sockaddr *, void *); struct ip_moptions; struct mbuf; +struct icmp6_filter; /* * Common structure pcb for internet protocol implementation. @@ -81,33 +85,63 @@ struct mbuf; * up (to a socket structure) and down (to a protocol-specific) * control block. */ + struct inpcb { - struct inpcb_hdr inp_head; -#define inp_queue inp_head.inph_queue -#define inp_af inp_head.inph_af -#define inp_ppcb inp_head.inph_ppcb -#define inp_state inp_head.inph_state -#define inp_portalgo inp_head.inph_portalgo -#define inp_socket inp_head.inph_socket -#define inp_table inp_head.inph_table -#define inp_sp inp_head.inph_sp - struct route inp_route; /* placeholder for routing entry */ - u_int16_t inp_fport; /* foreign port */ - u_int16_t inp_lport; /* local port */ - int inp_flags; /* generic IP/datagram flags */ - struct ip inp_ip; /* header prototype; should have more */ - struct mbuf *inp_options; /* IP options */ - struct ip_moptions *inp_moptions; /* IP multicast options */ - int inp_errormtu; /* MTU of last xmit status = EMSGSIZE */ - uint8_t inp_ip_minttl; - bool inp_bindportonsend; - struct in_addr inp_prefsrcip; /* preferred src IP when wild */ - pcb_overudp_cb_t inp_overudp_cb; - void *inp_overudp_arg; + LIST_ENTRY(inpcb) inp_hash; + LIST_ENTRY(inpcb) inp_lhash; + TAILQ_ENTRY(inpcb) inp_queue; + int inp_af; /* address family - AF_INET or AF_INET6 */ + void * inp_ppcb; /* pointer to per-protocol pcb */ + int inp_state; /* bind/connect state */ +#define INP_ATTACHED 0 +#define INP_BOUND 1 +#define INP_CONNECTED 2 + int inp_portalgo; + struct socket *inp_socket; /* back pointer to socket */ + struct inpcbtable *inp_table; + struct inpcbpolicy *inp_sp; /* security policy */ + struct route inp_route; /* placeholder for routing entry */ + u_int16_t inp_fport; /* foreign port */ + u_int16_t inp_lport; /* local port */ + int inp_flags; /* generic IP/datagram flags */ + union { /* header prototype. */ + struct ip inp_ip; + struct ip6_hdr inp_ip6; + }; +#define inp_flowinfo inp_ip6.ip6_flow + struct mbuf *inp_options; /* IP options */ + bool inp_bindportonsend; + + /* We still need both for IPv6 due to v4-mapped addresses */ + struct ip_moptions *inp_moptions; /* IPv4 multicast options */ + struct ip6_moptions *inp_moptions6; /* IPv6 multicast options */ + + union { + /* IPv4 only stuffs */ + struct { + int inp_errormtu; /* MTU of last xmit status = EMSGSIZE */ + uint8_t inp_ip_minttl; + struct in_addr inp_prefsrcip; /* preferred src IP when wild */ + }; + /* IPv6 only stuffs */ + struct { + int inp_hops6; /* default IPv6 hop limit */ + int inp_cksum6; /* IPV6_CHECKSUM setsockopt */ + struct icmp6_filter *inp_icmp6filt; + struct ip6_pktopts *inp_outputopts6; /* IP6 options for outgoing packets */ + }; + }; + + pcb_overudp_cb_t inp_overudp_cb; + void *inp_overudp_arg; }; #define inp_faddr inp_ip.ip_dst #define inp_laddr inp_ip.ip_src +#define inp_faddr6 inp_ip6.ip6_dst +#define inp_laddr6 inp_ip6.ip6_src + +LIST_HEAD(inpcbhead, inpcb); /* flags in inp_flags: */ #define INP_RECVOPTS 0x0001 /* receive incoming IP options */ @@ -134,17 +168,69 @@ struct inpcb { #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\ INP_RECVIF|INP_RECVTTL|INP_RECVPKTINFO) +/* + * Flags for IPv6 in inp_flags + * We define KAME's original flags in higher 16 bits as much as possible + * for compatibility with *bsd*s. + */ +#define IN6P_RECVOPTS 0x00001000 /* receive incoming IP6 options */ +#define IN6P_RECVRETOPTS 0x00002000 /* receive IP6 options for reply */ +#define IN6P_RECVDSTADDR 0x00004000 /* receive IP6 dst address */ +#define IN6P_IPV6_V6ONLY 0x00008000 /* restrict AF_INET6 socket for v6 */ +#define IN6P_PKTINFO 0x00010000 /* receive IP6 dst and I/F */ +#define IN6P_HOPLIMIT 0x00020000 /* receive hoplimit */ +#define IN6P_HOPOPTS 0x00040000 /* receive hop-by-hop options */ +#define IN6P_DSTOPTS 0x00080000 /* receive dst options after rthdr */ +#define IN6P_RTHDR 0x00100000 /* receive routing header */ +#define IN6P_RTHDRDSTOPTS 0x00200000 /* receive dstoptions before rthdr */ +#define IN6P_TCLASS 0x00400000 /* traffic class */ +#define IN6P_BINDANY 0x00800000 /* allow bind to any address */ +#define IN6P_HIGHPORT 0x01000000 /* user wants "high" port binding */ +#define IN6P_LOWPORT 0x02000000 /* user wants "low" port binding */ +#define IN6P_ANONPORT 0x04000000 /* port chosen for user */ +#define IN6P_FAITH 0x08000000 /* accept FAITH'ed connections */ +/* XXX should move to an UDP control block */ +#define IN6P_ESPINUDP INP_ESPINUDP /* ESP over UDP for NAT-T */ + +#define IN6P_RFC2292 0x40000000 /* RFC2292 */ +#define IN6P_MTU 0x80000000 /* use minimum MTU */ + +#define IN6P_CONTROLOPTS (IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\ + IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\ + IN6P_TCLASS|IN6P_RFC2292|\ + IN6P_MTU) + #define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb) +#define soaf(so) (so->so_proto->pr_domain->dom_family) #define inp_lock(inp) solock((inp)->inp_socket) #define inp_unlock(inp) sounlock((inp)->inp_socket) #define inp_locked(inp) solocked((inp)->inp_socket) +TAILQ_HEAD(inpcbqueue, inpcb); + +struct vestigial_hooks; + +/* It's still referenced by kvm users */ +struct inpcbtable { + struct inpcbqueue inpt_queue; + struct inpcbhead *inpt_porthashtbl; + struct inpcbhead *inpt_bindhashtbl; + struct inpcbhead *inpt_connecthashtbl; + u_long inpt_porthash; + u_long inpt_bindhash; + u_long inpt_connecthash; + u_int16_t inpt_lastport; + u_int16_t inpt_lastlow; + + struct vestigial_hooks *vestige; +}; +#define inpt_lasthi inpt_lastport + #ifdef _KERNEL #include #include -struct inpcbtable; struct lwp; struct rtentry; struct sockaddr_in; @@ -185,6 +271,38 @@ struct rtentry * in_pcbrtentry(struct inpcb *); void in_pcbrtentry_unref(struct rtentry *, struct inpcb *); +void in6_pcbinit(struct inpcbtable *, int, int); +int in6_pcbbind(void *, struct sockaddr_in6 *, struct lwp *); +int in6_pcbconnect(void *, struct sockaddr_in6 *, struct lwp *); +void in6_pcbdetach(struct inpcb *); +void in6_pcbdisconnect(struct inpcb *); +struct inpcb *in6_pcblookup_port(struct inpcbtable *, struct in6_addr *, + u_int, int, struct vestigial_inpcb *); +int in6_pcbnotify(struct inpcbtable *, const struct sockaddr *, + u_int, const struct sockaddr *, u_int, int, void *, + void (*)(struct inpcb *, int)); +void in6_pcbpurgeif0(struct inpcbtable *, struct ifnet *); +void in6_pcbpurgeif(struct inpcbtable *, struct ifnet *); +void in6_pcbstate(struct inpcb *, int); +void in6_rtchange(struct inpcb *, int); +void in6_setpeeraddr(struct inpcb *, struct sockaddr_in6 *); +void in6_setsockaddr(struct inpcb *, struct sockaddr_in6 *); + +/* in in6_src.c */ +int in6_selecthlim(struct inpcb *, struct ifnet *); +int in6_selecthlim_rt(struct inpcb *); +int in6_pcbsetport(struct sockaddr_in6 *, struct inpcb *, struct lwp *); + +extern struct rtentry * + in6_pcbrtentry(struct inpcb *); +extern void + in6_pcbrtentry_unref(struct rtentry *, struct inpcb *); +extern struct inpcb *in6_pcblookup_connect(struct inpcbtable *, + const struct in6_addr *, u_int, const struct in6_addr *, u_int, int, + struct vestigial_inpcb *); +extern struct inpcb *in6_pcblookup_bind(struct inpcbtable *, + const struct in6_addr *, u_int, int); + static inline void in_pcb_register_overudp_cb(struct inpcb *inp, pcb_overudp_cb_t cb, void *arg) { @@ -193,6 +311,37 @@ in_pcb_register_overudp_cb(struct inpcb *inp, pcb_overudp_cb_t cb, void *arg) inp->inp_overudp_arg = arg; } +/* compute hash value for foreign and local in6_addr and port */ +#define IN6_HASH(faddr, fport, laddr, lport) \ + (((faddr)->s6_addr32[0] ^ (faddr)->s6_addr32[1] ^ \ + (faddr)->s6_addr32[2] ^ (faddr)->s6_addr32[3] ^ \ + (laddr)->s6_addr32[0] ^ (laddr)->s6_addr32[1] ^ \ + (laddr)->s6_addr32[2] ^ (laddr)->s6_addr32[3]) \ + + (fport) + (lport)) + +// from in_pcb_hdr.h +struct vestigial_inpcb; +struct in6_addr; + +/* Hooks for vestigial pcb entries. + * If vestigial entries exist for a table (TCP only) + * the vestigial pointer is set. + */ +typedef struct vestigial_hooks { + /* IPv4 hooks */ + void *(*init_ports4)(struct in_addr, u_int, int); + int (*next_port4)(void *, struct vestigial_inpcb *); + int (*lookup4)(struct in_addr, uint16_t, + struct in_addr, uint16_t, + struct vestigial_inpcb *); + /* IPv6 hooks */ + void *(*init_ports6)(const struct in6_addr*, u_int, int); + int (*next_port6)(void *, struct vestigial_inpcb *); + int (*lookup6)(const struct in6_addr *, uint16_t, + const struct in6_addr *, uint16_t, + struct vestigial_inpcb *); +} vestigial_hooks_t; + #endif /* _KERNEL */ #endif /* !_NETINET_IN_PCB_H_ */ diff --git a/sys/netinet/in_pcb_hdr.h b/sys/netinet/in_pcb_hdr.h deleted file mode 100644 index 0e3dcf7f577..00000000000 --- a/sys/netinet/in_pcb_hdr.h +++ /dev/null @@ -1,145 +0,0 @@ -/* $NetBSD: in_pcb_hdr.h,v 1.15 2020/08/28 07:01:57 riastradh Exp $ */ - -/* - * Copyright (C) 2003 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93 - */ - -#ifndef _NETINET_IN_PCB_HDR_H_ -#define _NETINET_IN_PCB_HDR_H_ - -#include -#include - -#include - -struct inpcbpolicy; -struct inpcbtable; -struct mbuf; -struct sockaddr; -struct socket; - -/* - * align it with inpcb and in6pcb! - */ -struct inpcb_hdr { - LIST_ENTRY(inpcb_hdr) inph_hash; - LIST_ENTRY(inpcb_hdr) inph_lhash; - TAILQ_ENTRY(inpcb_hdr) inph_queue; - int inph_af; /* address family - AF_INET */ - void * inph_ppcb; /* pointer to per-protocol pcb */ - int inph_state; /* bind/connect state */ - int inph_portalgo; - struct socket *inph_socket; /* back pointer to socket */ - struct inpcbtable *inph_table; - struct inpcbpolicy *inph_sp; /* security policy */ -}; - -#define sotoinpcb_hdr(so) ((struct inpcb_hdr *)(so)->so_pcb) -#define inph_locked(inph) (solocked((inph)->inph_socket)) - -LIST_HEAD(inpcbhead, inpcb_hdr); - -struct vestigial_inpcb; -struct in6_addr; - -/* Hooks for vestigial pcb entries. - * If vestigial entries exist for a table (TCP only) - * the vestigial pointer is set. - */ -typedef struct vestigial_hooks { - /* IPv4 hooks */ - void *(*init_ports4)(struct in_addr, u_int, int); - int (*next_port4)(void *, struct vestigial_inpcb *); - int (*lookup4)(struct in_addr, uint16_t, - struct in_addr, uint16_t, - struct vestigial_inpcb *); - /* IPv6 hooks */ - void *(*init_ports6)(const struct in6_addr*, u_int, int); - int (*next_port6)(void *, struct vestigial_inpcb *); - int (*lookup6)(const struct in6_addr *, uint16_t, - const struct in6_addr *, uint16_t, - struct vestigial_inpcb *); -} vestigial_hooks_t; - -TAILQ_HEAD(inpcbqueue, inpcb_hdr); - -struct inpcbtable { - struct inpcbqueue inpt_queue; - struct inpcbhead *inpt_porthashtbl; - struct inpcbhead *inpt_bindhashtbl; - struct inpcbhead *inpt_connecthashtbl; - u_long inpt_porthash; - u_long inpt_bindhash; - u_long inpt_connecthash; - u_int16_t inpt_lastport; - u_int16_t inpt_lastlow; - - vestigial_hooks_t *vestige; -}; -#define inpt_lasthi inpt_lastport - -/* states in inp_state: */ -#define INP_ATTACHED 0 -#define INP_BOUND 1 -#define INP_CONNECTED 2 - -typedef int (*pcb_overudp_cb_t)(struct mbuf **, int, struct socket *, - struct sockaddr *, void *); - -#endif /* !_NETINET_IN_PCB_HDR_H_ */ diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 0e5d5628e82..3e04d22aeea 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1256,8 +1256,7 @@ ip_ctloutput(int op, struct socket *so, struct sockopt *sopt) if (error) break; - error = portalgo_algo_index_select( - (struct inpcb_hdr *)inp, optval); + error = portalgo_algo_index_select(inp, optval); break; #if defined(IPSEC) diff --git a/sys/netinet/portalgo.c b/sys/netinet/portalgo.c index 163f23904c5..8fa34859a55 100644 --- a/sys/netinet/portalgo.c +++ b/sys/netinet/portalgo.c @@ -105,15 +105,15 @@ static bitmap inet6_reserve; typedef struct { const char *name; - int (*func)(int, uint16_t *, struct inpcb_hdr *, kauth_cred_t); + int (*func)(int, uint16_t *, struct inpcb *, kauth_cred_t); } portalgo_algorithm_t; -static int algo_bsd(int, uint16_t *, struct inpcb_hdr *, kauth_cred_t); -static int algo_random_start(int, uint16_t *, struct inpcb_hdr *, kauth_cred_t); -static int algo_random_pick(int, uint16_t *, struct inpcb_hdr *, kauth_cred_t); -static int algo_hash(int, uint16_t *, struct inpcb_hdr *, kauth_cred_t); -static int algo_doublehash(int, uint16_t *, struct inpcb_hdr *, kauth_cred_t); -static int algo_randinc(int, uint16_t *, struct inpcb_hdr *, kauth_cred_t); +static int algo_bsd(int, uint16_t *, struct inpcb *, kauth_cred_t); +static int algo_random_start(int, uint16_t *, struct inpcb *, kauth_cred_t); +static int algo_random_pick(int, uint16_t *, struct inpcb *, kauth_cred_t); +static int algo_hash(int, uint16_t *, struct inpcb *, kauth_cred_t); +static int algo_doublehash(int, uint16_t *, struct inpcb *, kauth_cred_t); +static int algo_randinc(int, uint16_t *, struct inpcb *, kauth_cred_t); static const portalgo_algorithm_t algos[] = { { @@ -151,16 +151,16 @@ static uint16_t portalgo_next_ephemeral[NPROTO][NAF][NRANGES][NALGOS]; * the port range. */ static int -pcb_getports(struct inpcb_hdr *inp_hdr, uint16_t *lastport, +pcb_getports(struct inpcb *inp, uint16_t *lastport, uint16_t *mymin, uint16_t *mymax, uint16_t **pnext_ephemeral, int algo) { - struct inpcbtable * const table = inp_hdr->inph_table; + struct inpcbtable * const table = inp->inp_table; struct socket *so; int portalgo_proto; int portalgo_af; int portalgo_range; - so = inp_hdr->inph_socket; + so = inp->inp_socket; switch (so->so_type) { case SOCK_DGRAM: /* UDP or DCCP */ case SOCK_CONN_DGRAM: @@ -173,11 +173,9 @@ pcb_getports(struct inpcb_hdr *inp_hdr, uint16_t *lastport, return EPFNOSUPPORT; } - switch (inp_hdr->inph_af) { + switch (inp->inp_af) { #ifdef INET case AF_INET: { - struct inpcb *inp = (struct inpcb *)(void *)inp_hdr; - portalgo_af = PORTALGO_IPV4; if (inp->inp_flags & INP_LOWPORT) { *mymin = lowportmin; @@ -195,10 +193,8 @@ pcb_getports(struct inpcb_hdr *inp_hdr, uint16_t *lastport, #endif #ifdef INET6 case AF_INET6: { - struct in6pcb *in6p = (struct in6pcb *)(void *)inp_hdr; - portalgo_af = PORTALGO_IPV6; - if (in6p->in6p_flags & IN6P_LOWPORT) { + if (inp->inp_flags & IN6P_LOWPORT) { *mymin = ip6_lowportmin; *mymax = ip6_lowportmax; *lastport = table->inpt_lastlow; @@ -241,9 +237,9 @@ pcb_getports(struct inpcb_hdr *inp_hdr, uint16_t *lastport, * shamelessly copied from in_pcb.c. */ static bool -check_suitable_port(uint16_t port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) +check_suitable_port(uint16_t port, struct inpcb *inp, kauth_cred_t cred) { - struct inpcbtable * const table = inp_hdr->inph_table; + struct inpcbtable * const table = inp->inp_table; #ifdef INET vestigial_inpcb_t vestigial; #endif @@ -255,10 +251,9 @@ check_suitable_port(uint16_t port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) DPRINTF("%s called for argument %d\n", __func__, port); - switch (inp_hdr->inph_af) { + switch (inp->inp_af) { #ifdef INET case AF_INET: { /* IPv4 */ - struct inpcb *inp = (struct inpcb *)(void *)inp_hdr; struct inpcb *pcb; struct sockaddr_in sin; @@ -303,15 +298,14 @@ check_suitable_port(uint16_t port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) #endif #ifdef INET6 case AF_INET6: { /* IPv6 */ - struct in6pcb *in6p = (struct in6pcb *)(void *)inp_hdr; struct sockaddr_in6 sin6; void *t; if (__BITMAP_ISSET(port, &inet6_reserve)) return false; - sin6.sin6_addr = in6p->in6p_laddr; - so = in6p->in6p_socket; + sin6.sin6_addr = inp->inp_laddr6; + so = inp->inp_socket; /* XXX: this is redundant when called from in6_pcbbind */ if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) == 0 && @@ -344,7 +338,7 @@ check_suitable_port(uint16_t port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) enum kauth_network_req req; /* We have a free port. Check with the secmodel. */ - if (in6p->in6p_flags & IN6P_LOWPORT) { + if (inp->inp_flags & IN6P_LOWPORT) { #ifndef IPNOPRIVPORTS req = KAUTH_REQ_NETWORK_BIND_PRIVPORT; #else @@ -377,7 +371,7 @@ check_suitable_port(uint16_t port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) /* This is the default BSD algorithm, as described in RFC 6056 */ static int -algo_bsd(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) +algo_bsd(int algo, uint16_t *port, struct inpcb *inp, kauth_cred_t cred) { uint16_t count; uint16_t mymin, mymax, lastport; @@ -385,7 +379,7 @@ algo_bsd(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) int error; DPRINTF("%s called\n", __func__); - error = pcb_getports(inp_hdr, &lastport, &mymin, &mymax, + error = pcb_getports(inp, &lastport, &mymin, &mymax, &next_ephemeral, algo); if (error) return error; @@ -396,7 +390,7 @@ algo_bsd(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) if (myport < mymin || mymax < myport) myport = mymax; *next_ephemeral = myport - 1; - if (check_suitable_port(myport, inp_hdr, cred)) { + if (check_suitable_port(myport, inp, cred)) { *port = myport; DPRINTF("%s returning port %d\n", __func__, *port); return 0; @@ -413,7 +407,7 @@ algo_bsd(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) * by a random amount. */ static int -algo_random_start(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, +algo_random_start(int algo, uint16_t *port, struct inpcb *inp, kauth_cred_t cred) { uint16_t count, num_ephemeral; @@ -423,7 +417,7 @@ algo_random_start(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, DPRINTF("%s called\n", __func__); - error = pcb_getports(inp_hdr, &lastport, &mymin, &mymax, + error = pcb_getports(inp, &lastport, &mymin, &mymax, &next_ephemeral, algo); if (error) return error; @@ -439,7 +433,7 @@ algo_random_start(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, count = num_ephemeral; do { - if (check_suitable_port(*next_ephemeral, inp_hdr, cred)) { + if (check_suitable_port(*next_ephemeral, inp, cred)) { *port = *next_ephemeral; DPRINTF("%s returning port %d\n", __func__, *port); return 0; @@ -467,7 +461,7 @@ algo_random_start(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, * give up before exhausting the free ports. */ static int -algo_random_pick(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, +algo_random_pick(int algo, uint16_t *port, struct inpcb *inp, kauth_cred_t cred) { uint16_t count, num_ephemeral; @@ -477,7 +471,7 @@ algo_random_pick(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, DPRINTF("%s called\n", __func__); - error = pcb_getports(inp_hdr, &lastport, &mymin, &mymax, + error = pcb_getports(inp, &lastport, &mymin, &mymax, &next_ephemeral, algo); if (error) return error; @@ -492,7 +486,7 @@ algo_random_pick(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, count = num_ephemeral; do { - if (check_suitable_port(*next_ephemeral, inp_hdr, cred)) { + if (check_suitable_port(*next_ephemeral, inp, cred)) { *port = *next_ephemeral; DPRINTF("%s returning port %d\n", __func__, *port); return 0; @@ -513,7 +507,7 @@ algo_random_pick(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, /* This is the implementation from FreeBSD, with tweaks */ static uint16_t -Fhash(const struct inpcb_hdr *inp_hdr) +Fhash(const struct inpcb *inp) { MD5_CTX f_ctx; uint32_t Ff[4]; @@ -524,11 +518,9 @@ Fhash(const struct inpcb_hdr *inp_hdr) cprng_fast(secret_f, sizeof(secret_f)); MD5Init(&f_ctx); - switch (inp_hdr->inph_af) { + switch (inp->inp_af) { #ifdef INET case AF_INET: { - const struct inpcb *inp = - (const struct inpcb *)(const void *)inp_hdr; MD5Update(&f_ctx, (const u_char *)&inp->inp_laddr, sizeof(inp->inp_laddr)); MD5Update(&f_ctx, (const u_char *)&inp->inp_faddr, @@ -540,14 +532,12 @@ Fhash(const struct inpcb_hdr *inp_hdr) #endif #ifdef INET6 case AF_INET6: { - const struct in6pcb *in6p = - (const struct in6pcb *)(const void *)inp_hdr; - MD5Update(&f_ctx, (const u_char *)&in6p->in6p_laddr, - sizeof(in6p->in6p_laddr)); - MD5Update(&f_ctx, (const u_char *)&in6p->in6p_faddr, - sizeof(in6p->in6p_faddr)); - MD5Update(&f_ctx, (const u_char *)&in6p->in6p_fport, - sizeof(in6p->in6p_fport)); + MD5Update(&f_ctx, (const u_char *)&inp->inp_laddr6, + sizeof(inp->inp_laddr6)); + MD5Update(&f_ctx, (const u_char *)&inp->inp_faddr6, + sizeof(inp->inp_faddr6)); + MD5Update(&f_ctx, (const u_char *)&inp->inp_fport, + sizeof(inp->inp_fport)); break; } #endif @@ -569,16 +559,12 @@ Fhash(const struct inpcb_hdr *inp_hdr) * late binding. */ static bool -iscompletetuple(struct inpcb_hdr *inp_hdr) +iscompletetuple(struct inpcb *inp) { -#ifdef INET6 - struct in6pcb *in6p; -#endif - switch (inp_hdr->inph_af) { + switch (inp->inp_af) { #ifdef INET case AF_INET: { - struct inpcb *inp = (struct inpcb *)(void *)inp_hdr; if (inp->inp_fport == 0 || in_nullhost(inp->inp_faddr)) { DPRINTF("%s fport or faddr missing, delaying port " "to connect/send\n", __func__); @@ -592,15 +578,14 @@ iscompletetuple(struct inpcb_hdr *inp_hdr) #endif #ifdef INET6 case AF_INET6: { - in6p = (struct in6pcb *)(void *)inp_hdr; - if (in6p->in6p_fport == 0 || memcmp(&in6p->in6p_faddr, - &in6addr_any, sizeof(in6p->in6p_faddr)) == 0) { + if (inp->inp_fport == 0 || memcmp(&inp->inp_faddr6, + &in6addr_any, sizeof(inp->inp_faddr6)) == 0) { DPRINTF("%s fport or faddr missing, delaying port " "to connect/send\n", __func__); - in6p->in6p_bindportonsend = true; + inp->inp_bindportonsend = true; return false; } else { - in6p->in6p_bindportonsend = false; + inp->inp_bindportonsend = false; } break; } @@ -614,7 +599,7 @@ iscompletetuple(struct inpcb_hdr *inp_hdr) } static int -algo_hash(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, +algo_hash(int algo, uint16_t *port, struct inpcb *inp, kauth_cred_t cred) { uint16_t count, num_ephemeral; @@ -625,12 +610,12 @@ algo_hash(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, DPRINTF("%s called\n", __func__); - error = pcb_getports(inp_hdr, &lastport, &mymin, &mymax, + error = pcb_getports(inp, &lastport, &mymin, &mymax, &next_ephemeral, algo); if (error) return error; - if (!iscompletetuple(inp_hdr)) { + if (!iscompletetuple(inp)) { *port = 0; return 0; } @@ -640,7 +625,7 @@ algo_hash(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, DPRINTF("num_ephemeral: %d\n", num_ephemeral); - offset = Fhash(inp_hdr); + offset = Fhash(inp); count = num_ephemeral; do { @@ -649,7 +634,7 @@ algo_hash(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, (*next_ephemeral)++; - if (check_suitable_port(myport, inp_hdr, cred)) { + if (check_suitable_port(myport, inp, cred)) { *port = myport; DPRINTF("%s returning port %d\n", __func__, *port); return 0; @@ -663,7 +648,7 @@ algo_hash(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, } static int -algo_doublehash(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, +algo_doublehash(int algo, uint16_t *port, struct inpcb *inp, kauth_cred_t cred) { uint16_t count, num_ephemeral; @@ -676,12 +661,12 @@ algo_doublehash(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, DPRINTF("%s called\n", __func__); - error = pcb_getports(inp_hdr, &lastport, &mymin, &mymax, + error = pcb_getports(inp, &lastport, &mymin, &mymax, &next_ephemeral, algo); if (error) return error; - if (!iscompletetuple(inp_hdr)) { + if (!iscompletetuple(inp)) { *port = 0; return 0; } @@ -692,8 +677,8 @@ algo_doublehash(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, /* Ephemeral port selection function */ num_ephemeral = mymax - mymin + 1; - offset = Fhash(inp_hdr); - idx = Fhash(inp_hdr) % __arraycount(dhtable); /* G */ + offset = Fhash(inp); + idx = Fhash(inp) % __arraycount(dhtable); /* G */ count = num_ephemeral; do { @@ -701,7 +686,7 @@ algo_doublehash(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, % num_ephemeral; dhtable[idx]++; - if (check_suitable_port(myport, inp_hdr, cred)) { + if (check_suitable_port(myport, inp, cred)) { *port = myport; DPRINTF("%s returning port %d\n", __func__, *port); return 0; @@ -716,7 +701,7 @@ algo_doublehash(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, } static int -algo_randinc(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, +algo_randinc(int algo, uint16_t *port, struct inpcb *inp, kauth_cred_t cred) { static const uint16_t N = 500; /* Determines the trade-off */ @@ -728,7 +713,7 @@ algo_randinc(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, DPRINTF("%s called\n", __func__); - error = pcb_getports(inp_hdr, &lastport, &mymin, &mymax, + error = pcb_getports(inp, &lastport, &mymin, &mymax, &next_ephemeral, algo); if (error) return error; @@ -746,7 +731,7 @@ algo_randinc(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, myport = mymin + (*next_ephemeral % num_ephemeral); - if (check_suitable_port(myport, inp_hdr, cred)) { + if (check_suitable_port(myport, inp, cred)) { *port = myport; DPRINTF("%s returning port %d\n", __func__, *port); return 0; @@ -759,7 +744,7 @@ algo_randinc(int algo, uint16_t *port, struct inpcb_hdr *inp_hdr, /* The generic function called in order to pick a port. */ int -portalgo_randport(uint16_t *port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) +portalgo_randport(uint16_t *port, struct inpcb *inp, kauth_cred_t cred) { int algo, error; uint16_t lport; @@ -767,8 +752,8 @@ portalgo_randport(uint16_t *port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) DPRINTF("%s called\n", __func__); - if (inp_hdr->inph_portalgo == PORTALGO_DEFAULT) { - switch (inp_hdr->inph_af) { + if (inp->inp_portalgo == PORTALGO_DEFAULT) { + switch (inp->inp_af) { #ifdef INET case AF_INET: default_algo = inet4_portalgo; @@ -789,16 +774,15 @@ portalgo_randport(uint16_t *port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) algo = default_algo; } else /* socket specifies the algorithm */ - algo = inp_hdr->inph_portalgo; + algo = inp->inp_portalgo; KASSERT(algo >= 0); KASSERT(algo < NALGOS); - switch (inp_hdr->inph_af) { + switch (inp->inp_af) { #ifdef INET case AF_INET: { char buf[INET_ADDRSTRLEN]; - struct inpcb *inp = (struct inpcb *)(void *)inp_hdr; DPRINTF("local addr: %s\n", IN_PRINT(buf, &inp->inp_laddr)); DPRINTF("local port: %d\n", inp->inp_lport); DPRINTF("foreign addr: %s\n", IN_PRINT(buf, &inp->inp_faddr)); @@ -809,13 +793,11 @@ portalgo_randport(uint16_t *port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) #ifdef INET6 case AF_INET6: { char buf[INET6_ADDRSTRLEN]; - struct in6pcb *in6p = (struct in6pcb *)(void *)inp_hdr; - - DPRINTF("local addr: %s\n", IN6_PRINT(buf, &in6p->in6p_laddr)); - DPRINTF("local port: %d\n", in6p->in6p_lport); + DPRINTF("local addr: %s\n", IN6_PRINT(buf, &inp->inp_laddr6)); + DPRINTF("local port: %d\n", inp->inp_lport); DPRINTF("foreign addr: %s\n", IN6_PRINT(buf, - &in6p->in6p_laddr)); - DPRINTF("foreign port: %d\n", in6p->in6p_fport); + &inp->inp_laddr6)); + DPRINTF("foreign port: %d\n", inp->inp_fport); break; } #endif @@ -825,13 +807,13 @@ portalgo_randport(uint16_t *port, struct inpcb_hdr *inp_hdr, kauth_cred_t cred) DPRINTF("%s portalgo = %d\n", __func__, algo); - error = (*algos[algo].func)(algo, &lport, inp_hdr, cred); + error = (*algos[algo].func)(algo, &lport, inp, cred); if (error == 0) { *port = lport; } else if (error != EAGAIN) { uint16_t lastport, mymin, mymax, *pnext_ephemeral; - error = pcb_getports(inp_hdr, &lastport, &mymin, + error = pcb_getports(inp, &lastport, &mymin, &mymax, &pnext_ephemeral, algo); if (error) return error; @@ -859,7 +841,7 @@ portalgo_algo_name_select(const char *name, int *algo) /* Sets the algorithm to be used by the pcb inp. */ int -portalgo_algo_index_select(struct inpcb_hdr *inp, int algo) +portalgo_algo_index_select(struct inpcb *inp, int algo) { DPRINTF("%s called with algo %d for pcb %p\n", __func__, algo, inp ); @@ -868,7 +850,7 @@ portalgo_algo_index_select(struct inpcb_hdr *inp, int algo) (algo != PORTALGO_DEFAULT)) return EINVAL; - inp->inph_portalgo = algo; + inp->inp_portalgo = algo; return 0; } diff --git a/sys/netinet/portalgo.h b/sys/netinet/portalgo.h index 634ca72e727..c58ca7abcad 100644 --- a/sys/netinet/portalgo.h +++ b/sys/netinet/portalgo.h @@ -33,14 +33,14 @@ #ifdef _KERNEL #include -struct inpcb_hdr; -int portalgo_randport(uint16_t *, struct inpcb_hdr *, kauth_cred_t); +struct inpcb; +int portalgo_randport(uint16_t *, struct inpcb *, kauth_cred_t); int sysctl_portalgo_selected4(SYSCTLFN_ARGS); int sysctl_portalgo_selected6(SYSCTLFN_ARGS); int sysctl_portalgo_reserve4(SYSCTLFN_ARGS); int sysctl_portalgo_reserve6(SYSCTLFN_ARGS); int sysctl_portalgo_available(SYSCTLFN_ARGS); -int portalgo_algo_index_select(struct inpcb_hdr *, int); +int portalgo_algo_index_select(struct inpcb *, int); #define PORTALGO_MAXLEN 16 #endif /* _KERNEL */ diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 9869a2958e9..4f608e13b92 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -165,7 +165,6 @@ void rip_input(struct mbuf *m, int off, int proto) { struct ip *ip = mtod(m, struct ip *); - struct inpcb_hdr *inph; struct inpcb *inp; struct inpcb *last = NULL; struct mbuf *n; @@ -183,8 +182,7 @@ rip_input(struct mbuf *m, int off, int proto) ip->ip_len = ntohs(ip->ip_len) - hlen; NTOHS(ip->ip_off); - TAILQ_FOREACH(inph, &rawcbtable.inpt_queue, inph_queue) { - inp = (struct inpcb *)inph; + TAILQ_FOREACH(inp, &rawcbtable.inpt_queue, inp_queue) { if (inp->inp_af != AF_INET) continue; if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != proto) @@ -241,12 +239,11 @@ rip_pcbnotify(struct inpcbtable *table, struct in_addr faddr, struct in_addr laddr, int proto, int errno, void (*notify)(struct inpcb *, int)) { - struct inpcb_hdr *inph; + struct inpcb *inp; int nmatch; nmatch = 0; - TAILQ_FOREACH(inph, &table->inpt_queue, inph_queue) { - struct inpcb *inp = (struct inpcb *)inph; + TAILQ_FOREACH(inp, &table->inpt_queue, inp_queue) { if (inp->inp_af != AF_INET) continue; if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != proto) diff --git a/sys/netinet/sctp_pcb.h b/sys/netinet/sctp_pcb.h index b9786a02144..0880bcb20a2 100644 --- a/sys/netinet/sctp_pcb.h +++ b/sys/netinet/sctp_pcb.h @@ -41,6 +41,7 @@ * we would not allocate enough for Net/Open BSD :-< */ #include +#include #include #include #include @@ -287,7 +288,7 @@ struct sctp_inpcb { */ union { struct inpcb inp; - char align[(sizeof(struct in6pcb) + SCTP_ALIGNM1) & + char align[(sizeof(struct inpcb) + SCTP_ALIGNM1) & ~SCTP_ALIGNM1]; } ip_inp; LIST_ENTRY(sctp_inpcb) sctp_list; /* lists all endpoints */ @@ -751,5 +752,41 @@ sctp_initiate_iterator(asoc_func af, uint32_t, uint32_t, void *, uint32_t, void in6_sin6_2_sin (struct sockaddr_in *, struct sockaddr_in6 *sin6); +#ifdef __NetBSD__ +#ifndef in6pcb +#define in6pcb inpcb +#endif +#ifndef sotoin6pcb +#define sotoin6pcb sotoinpcb +#endif +#ifndef in6p_flags +#define in6p_flags inp_flags +#endif +#ifndef in6p_af +#define in6p_af inp_af +#endif +#ifndef in6p_cksum +#define in6p_cksum inp_cksum6 +#endif +#ifndef in6p_hops +#define in6p_hops inp_hops6 +#endif +#ifndef in6p_flowinfo +#define in6p_flowinfo inp_flowinfo +#endif +#ifndef in6p_outputopts +#define in6p_outputopts inp_outputopts6 +#endif +#ifndef in6p_moptions +#define in6p_moptions inp_moptions6 +#endif +#ifndef inpcb_hdr +#define inpcb_hdr inpcb +#endif +#ifndef sp_inph +#define sp_inph sp_inp +#endif +#endif + #endif /* _KERNEL */ #endif /* !__SCTP_PCB_H__ */ diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 66a14980aaf..6113b9d4e2e 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -254,21 +254,7 @@ nd_hint(struct tcpcb *tp) if (tp == NULL) return; - switch (tp->t_family) { -#if NARP > 0 - case AF_INET: - if (tp->t_inpcb != NULL) - ro = &tp->t_inpcb->inp_route; - break; -#endif -#ifdef INET6 - case AF_INET6: - if (tp->t_in6pcb != NULL) - ro = &tp->t_in6pcb->in6p_route; - break; -#endif - } - + ro = &tp->t_inpcb->inp_route; if (ro == NULL) return; @@ -478,12 +464,7 @@ tcp_reass(struct tcpcb *tp, const struct tcphdr *th, struct mbuf *m, int tlen) #endif uint64_t *tcps; - if (tp->t_inpcb) - so = tp->t_inpcb->inp_socket; -#ifdef INET6 - else if (tp->t_in6pcb) - so = tp->t_in6pcb->in6p_socket; -#endif + so = tp->t_inpcb->inp_socket; TCP_REASS_LOCK_CHECK(tp); @@ -1198,7 +1179,6 @@ tcp_input(struct mbuf *m, int off, int proto) struct inpcb *inp; #ifdef INET6 struct ip6_hdr *ip6; - struct in6pcb *in6p; #endif u_int8_t *optp = NULL; int optlen = 0; @@ -1385,9 +1365,6 @@ tcp_input(struct mbuf *m, int off, int proto) */ findpcb: inp = NULL; -#ifdef INET6 - in6p = NULL; -#endif switch (af) { case AF_INET: inp = in_pcblookup_connect(&tcbtable, ip->ip_src, th->th_sport, @@ -1404,21 +1381,16 @@ findpcb: /* mapped addr case */ in6_in_2_v4mapin6(&ip->ip_src, &s); in6_in_2_v4mapin6(&ip->ip_dst, &d); - in6p = in6_pcblookup_connect(&tcbtable, &s, + inp = in6_pcblookup_connect(&tcbtable, &s, th->th_sport, &d, th->th_dport, 0, &vestige); - if (in6p == 0 && !vestige.valid) { + if (inp == NULL && !vestige.valid) { TCP_STATINC(TCP_STAT_PCBHASHMISS); - in6p = in6_pcblookup_bind(&tcbtable, &d, + inp = in6_pcblookup_bind(&tcbtable, &d, th->th_dport, 0); } } #endif -#ifndef INET6 - if (inp == NULL && !vestige.valid) -#else - if (inp == NULL && in6p == NULL && !vestige.valid) -#endif - { + if (inp == NULL && !vestige.valid) { TCP_STATINC(TCP_STAT_NOPORT); if (tcp_log_refused && (tiflags & (TH_RST|TH_ACK|TH_SYN)) == TH_SYN) { @@ -1429,14 +1401,8 @@ findpcb: } #if defined(IPSEC) if (ipsec_used) { - if (inp && ipsec_in_reject(m, inp)) { + if (inp && ipsec_in_reject(m, inp)) goto drop; - } -#ifdef INET6 - else if (in6p && ipsec_in_reject(m, in6p)) { - goto drop; - } -#endif } #endif /*IPSEC*/ break; @@ -1450,14 +1416,14 @@ findpcb: #else faith = 0; #endif - in6p = in6_pcblookup_connect(&tcbtable, &ip6->ip6_src, + inp = in6_pcblookup_connect(&tcbtable, &ip6->ip6_src, th->th_sport, &ip6->ip6_dst, th->th_dport, faith, &vestige); - if (!in6p && !vestige.valid) { + if (inp == NULL && !vestige.valid) { TCP_STATINC(TCP_STAT_PCBHASHMISS); - in6p = in6_pcblookup_bind(&tcbtable, &ip6->ip6_dst, + inp = in6_pcblookup_bind(&tcbtable, &ip6->ip6_dst, th->th_dport, faith); } - if (!in6p && !vestige.valid) { + if (inp == NULL && !vestige.valid) { TCP_STATINC(TCP_STAT_NOPORT); if (tcp_log_refused && (tiflags & (TH_RST|TH_ACK|TH_SYN)) == TH_SYN) { @@ -1467,9 +1433,8 @@ findpcb: goto dropwithreset_ratelim; } #if defined(IPSEC) - if (ipsec_used && in6p && ipsec_in_reject(m, in6p)) { + if (ipsec_used && inp && ipsec_in_reject(m, inp)) goto drop; - } #endif break; } @@ -1488,19 +1453,12 @@ findpcb: so = NULL; if (inp) { /* Check the minimum TTL for socket. */ - if (ip->ip_ttl < inp->inp_ip_minttl) + if (inp->inp_af == AF_INET && ip->ip_ttl < inp->inp_ip_minttl) goto drop; tp = intotcpcb(inp); so = inp->inp_socket; - } -#ifdef INET6 - else if (in6p) { - tp = in6totcpcb(in6p); - so = in6p->in6p_socket; - } -#endif - else if (vestige.valid) { + } else if (vestige.valid) { /* We do not support the resurrection of vtw tcpcps. */ tcp_vtw_input(th, &vestige, m, tlen); m = NULL; @@ -1523,12 +1481,12 @@ findpcb: #ifdef INET6 /* save packet options if user wanted */ - if (in6p && (in6p->in6p_flags & IN6P_CONTROLOPTS)) { - if (in6p->in6p_options) { - m_freem(in6p->in6p_options); - in6p->in6p_options = NULL; + if (inp && (inp->inp_flags & IN6P_CONTROLOPTS)) { + if (inp->inp_options) { + m_freem(inp->inp_options); + inp->inp_options = NULL; } - ip6_savecontrol(in6p, &in6p->in6p_options, ip6, m); + ip6_savecontrol(inp, &inp->inp_options, ip6, m); } #endif @@ -1634,23 +1592,8 @@ nosave:; * We have created a full-blown * connection. */ - tp = NULL; - inp = NULL; -#ifdef INET6 - in6p = NULL; -#endif - switch (so->so_proto->pr_domain->dom_family) { - case AF_INET: - inp = sotoinpcb(so); - tp = intotcpcb(inp); - break; -#ifdef INET6 - case AF_INET6: - in6p = sotoin6pcb(so); - tp = in6totcpcb(in6p); - break; -#endif - } + inp = sotoinpcb(so); + tp = intotcpcb(inp); if (tp == NULL) goto badsyn; /*XXX*/ tiwin <<= tp->snd_scale; @@ -2145,10 +2088,10 @@ after_listen: tp->snd_cwnd = tp->t_peermss; else { int ss = tcp_init_win; - if (inp != NULL && in_localaddr(inp->inp_faddr)) + if (inp->inp_af == AF_INET && in_localaddr(inp->inp_faddr)) ss = tcp_init_win_local; #ifdef INET6 - if (in6p != NULL && in6_localaddr(&in6p->in6p_faddr)) + else if (inp->inp_af == AF_INET6 && in6_localaddr(&inp->inp_faddr6)) ss = tcp_init_win_local; #endif tp->snd_cwnd = TCP_INITIAL_WINDOW(ss, tp->t_peermss); @@ -2912,8 +2855,7 @@ dodata: if (tp->t_state == TCPS_TIME_WAIT && (so->so_state & SS_NOFDREF) - && (tp->t_inpcb || af != AF_INET) - && (tp->t_in6pcb || af != AF_INET6) + && (tp->t_inpcb || af != AF_INET || af != AF_INET6) && ((af == AF_INET ? tcp4_vtw_enable : tcp6_vtw_enable) & 1) != 0 && TAILQ_EMPTY(&tp->segq) && vtw_add(af, tp)) { @@ -2996,14 +2938,7 @@ drop: * Drop space held by incoming segment and return. */ if (tp) { - if (tp->t_inpcb) - so = tp->t_inpcb->inp_socket; -#ifdef INET6 - else if (tp->t_in6pcb) - so = tp->t_in6pcb->in6p_socket; -#endif - else - so = NULL; + so = tp->t_inpcb->inp_socket; #ifdef TCP_DEBUG if (so && (so->so_options & SO_DEBUG) != 0) tcp_trace(TA_DROP, ostate, tp, tcp_saveti, 0); diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index df8393f19a9..b5dbc2294d7 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -227,9 +227,6 @@ tcp_segsize(struct tcpcb *tp, int *txsegsizep, int *rxsegsizep, bool *alwaysfragp) { struct inpcb *inp = tp->t_inpcb; -#ifdef INET6 - struct in6pcb *in6p = tp->t_in6pcb; -#endif struct socket *so = NULL; struct rtentry *rt; struct ifnet *ifp; @@ -240,8 +237,6 @@ tcp_segsize(struct tcpcb *tp, int *txsegsizep, int *rxsegsizep, *alwaysfragp = false; size = tcp_mssdflt; - KASSERT(!(tp->t_inpcb && tp->t_in6pcb)); - switch (tp->t_family) { case AF_INET: hdrlen = sizeof(struct ip) + sizeof(struct tcphdr); @@ -256,17 +251,8 @@ tcp_segsize(struct tcpcb *tp, int *txsegsizep, int *rxsegsizep, goto out; } - rt = NULL; - if (inp) { - rt = in_pcbrtentry(inp); - so = inp->inp_socket; - } -#ifdef INET6 - if (in6p) { - rt = in6_pcbrtentry(in6p); - so = in6p->in6p_socket; - } -#endif + rt = in_pcbrtentry(inp); + so = inp->inp_socket; if (rt == NULL) { goto out; } @@ -275,7 +261,7 @@ tcp_segsize(struct tcpcb *tp, int *txsegsizep, int *rxsegsizep, if (tp->t_mtudisc && rt->rt_rmx.rmx_mtu != 0) { #ifdef INET6 - if (in6p && rt->rt_rmx.rmx_mtu < IPV6_MMTU) { + if (inp->inp_af == AF_INET6 && rt->rt_rmx.rmx_mtu < IPV6_MMTU) { /* * RFC2460 section 5, last paragraph: if path MTU is * smaller than 1280, use 1280 as packet size and @@ -295,11 +281,11 @@ tcp_segsize(struct tcpcb *tp, int *txsegsizep, int *rxsegsizep, else if (inp && in_localaddr(inp->inp_faddr)) size = ifp->if_mtu - hdrlen; #ifdef INET6 - else if (in6p) { - if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_faddr)) { + else if (inp->inp_af == AF_INET6) { + if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) { /* mapped addr case */ struct in_addr d; - memcpy(&d, &in6p->in6p_faddr.s6_addr32[3], sizeof(d)); + memcpy(&d, &inp->inp_faddr6.s6_addr32[3], sizeof(d)); if (tp->t_mtudisc || in_localaddr(d)) size = ifp->if_mtu - hdrlen; } else { @@ -312,12 +298,7 @@ tcp_segsize(struct tcpcb *tp, int *txsegsizep, int *rxsegsizep, } } #endif - if (inp) - in_pcbrtentry_unref(rt, inp); -#ifdef INET6 - if (in6p) - in6_pcbrtentry_unref(rt, in6p); -#endif + in_pcbrtentry_unref(rt, inp); out: /* * Now we must make room for whatever extra TCP/IP options are in @@ -330,7 +311,7 @@ tcp_segsize(struct tcpcb *tp, int *txsegsizep, int *rxsegsizep, * fragmentation will occur... need more investigation */ - if (inp) { + if (inp->inp_af == AF_INET) { #if defined(IPSEC) if (ipsec_used && !ipsec_pcb_skip_ipsec(inp->inp_sp, IPSEC_DIR_OUTBOUND)) @@ -340,20 +321,20 @@ tcp_segsize(struct tcpcb *tp, int *txsegsizep, int *rxsegsizep, } #ifdef INET6 - if (in6p && tp->t_family == AF_INET) { + if (inp->inp_af == AF_INET6 && tp->t_family == AF_INET) { #if defined(IPSEC) if (ipsec_used && - !ipsec_pcb_skip_ipsec(in6p->in6p_sp, IPSEC_DIR_OUTBOUND)) + !ipsec_pcb_skip_ipsec(inp->inp_sp, IPSEC_DIR_OUTBOUND)) optlen += ipsec4_hdrsiz_tcp(tp); #endif /* XXX size -= ip_optlen(in6p); */ - } else if (in6p && tp->t_family == AF_INET6) { + } else if (inp->inp_af == AF_INET6) { #if defined(IPSEC) if (ipsec_used && - !ipsec_pcb_skip_ipsec(in6p->in6p_sp, IPSEC_DIR_OUTBOUND)) + !ipsec_pcb_skip_ipsec(inp->inp_sp, IPSEC_DIR_OUTBOUND)) optlen += ipsec6_hdrsiz_tcp(tp); #endif - optlen += ip6_optlen(in6p); + optlen += ip6_optlen(inp); } #endif size -= optlen; @@ -555,37 +536,15 @@ tcp_output(struct tcpcb *tp) #endif uint64_t *tcps; - KASSERT(!(tp->t_inpcb && tp->t_in6pcb)); - - so = NULL; - ro = NULL; - if (tp->t_inpcb) { - so = tp->t_inpcb->inp_socket; - ro = &tp->t_inpcb->inp_route; - } -#ifdef INET6 - else if (tp->t_in6pcb) { - so = tp->t_in6pcb->in6p_socket; - ro = &tp->t_in6pcb->in6p_route; - } -#endif + so = tp->t_inpcb->inp_socket; + ro = &tp->t_inpcb->inp_route; switch (af = tp->t_family) { case AF_INET: - if (tp->t_inpcb) - break; -#ifdef INET6 - /* mapped addr case */ - if (tp->t_in6pcb) - break; -#endif - return EINVAL; -#ifdef INET6 case AF_INET6: - if (tp->t_in6pcb) + if (tp->t_inpcb) break; return EINVAL; -#endif default: return EAFNOSUPPORT; } @@ -603,7 +562,7 @@ tcp_output(struct tcpcb *tp) */ has_tso4 = has_tso6 = false; - has_tso4 = tp->t_inpcb != NULL && + has_tso4 = tp->t_inpcb->inp_af == AF_INET && #if defined(IPSEC) (!ipsec_used || ipsec_pcb_skip_ipsec(tp->t_inpcb->inp_sp, IPSEC_DIR_OUTBOUND)) && @@ -616,15 +575,15 @@ tcp_output(struct tcpcb *tp) } #if defined(INET6) - has_tso6 = tp->t_in6pcb != NULL && + has_tso6 = tp->t_inpcb->inp_af == AF_INET6 && #if defined(IPSEC) - (!ipsec_used || ipsec_pcb_skip_ipsec(tp->t_in6pcb->in6p_sp, + (!ipsec_used || ipsec_pcb_skip_ipsec(tp->t_inpcb->inp_sp, IPSEC_DIR_OUTBOUND)) && #endif - (rt = rtcache_validate(&tp->t_in6pcb->in6p_route)) != NULL && + (rt = rtcache_validate(&tp->t_inpcb->inp_route)) != NULL && (rt->rt_ifp->if_capenable & IFCAP_TSOv6) != 0; if (rt != NULL) - rtcache_unref(rt, &tp->t_in6pcb->in6p_route); + rtcache_unref(rt, &tp->t_inpcb->inp_route); #endif /* defined(INET6) */ has_tso = (has_tso4 || has_tso6) && !alwaysfrag; @@ -659,12 +618,12 @@ tcp_output(struct tcpcb *tp) * slow start to get ack "clock" running again. */ int ss = tcp_init_win; - if (tp->t_inpcb && + if (tp->t_inpcb->inp_af == AF_INET && in_localaddr(tp->t_inpcb->inp_faddr)) ss = tcp_init_win_local; #ifdef INET6 - if (tp->t_in6pcb && - in6_localaddr(&tp->t_in6pcb->in6p_faddr)) + else if (tp->t_inpcb->inp_af == AF_INET6 && + in6_localaddr(&tp->t_inpcb->inp_faddr6)) ss = tcp_init_win_local; #endif tp->snd_cwnd = uimin(tp->snd_cwnd, @@ -1107,23 +1066,11 @@ send: if (flags & TH_SYN) { struct rtentry *synrt; - synrt = NULL; - if (tp->t_inpcb) - synrt = in_pcbrtentry(tp->t_inpcb); -#ifdef INET6 - if (tp->t_in6pcb) - synrt = in6_pcbrtentry(tp->t_in6pcb); -#endif - + synrt = in_pcbrtentry(tp->t_inpcb); tp->snd_nxt = tp->iss; tp->t_ourmss = tcp_mss_to_advertise(synrt != NULL ? synrt->rt_ifp : NULL, af); - if (tp->t_inpcb) - in_pcbrtentry_unref(synrt, tp->t_inpcb); -#ifdef INET6 - if (tp->t_in6pcb) - in6_pcbrtentry_unref(synrt, tp->t_in6pcb); -#endif + in_pcbrtentry_unref(synrt, tp->t_inpcb); if ((tp->t_flags & TF_NOOPT) == 0 && OPT_FITS(TCPOLEN_MAXSEG)) { *optp++ = TCPOPT_MAXSEG; *optp++ = TCPOLEN_MAXSEG; @@ -1593,13 +1540,13 @@ timer: case AF_INET: ip->ip_len = htons(m->m_pkthdr.len); packetlen = m->m_pkthdr.len; - if (tp->t_inpcb) { + if (tp->t_inpcb->inp_af == AF_INET) { ip->ip_ttl = tp->t_inpcb->inp_ip.ip_ttl; ip->ip_tos = tp->t_inpcb->inp_ip.ip_tos | ecn_tos; } #ifdef INET6 - else if (tp->t_in6pcb) { - ip->ip_ttl = in6_selecthlim(tp->t_in6pcb, NULL); /*XXX*/ + else if (tp->t_inpcb->inp_af == AF_INET6) { + ip->ip_ttl = in6_selecthlim(tp->t_inpcb, NULL); /*XXX*/ ip->ip_tos = ecn_tos; /*XXX*/ } #endif @@ -1608,14 +1555,14 @@ timer: case AF_INET6: packetlen = m->m_pkthdr.len; ip6->ip6_nxt = IPPROTO_TCP; - if (tp->t_in6pcb) { + if (tp->t_family == AF_INET6) { /* * we separately set hoplimit for every segment, since * the user might want to change the value via * setsockopt. Also, desired default hop limit might * be changed via Neighbor Discovery. */ - ip6->ip6_hlim = in6_selecthlim_rt(tp->t_in6pcb); + ip6->ip6_hlim = in6_selecthlim_rt(tp->t_inpcb); } ip6->ip6_flow |= htonl(ecn_tos << 20); /* ip6->ip6_flow = ??? (from template) */ @@ -1632,7 +1579,7 @@ timer: { struct mbuf *opts; - if (tp->t_inpcb) + if (tp->t_inpcb && tp->t_family == AF_INET) opts = tp->t_inpcb->inp_options; else opts = NULL; @@ -1646,12 +1593,12 @@ timer: { struct ip6_pktopts *opts; - if (tp->t_in6pcb) - opts = tp->t_in6pcb->in6p_outputopts; + if (tp->t_inpcb && tp->t_family == AF_INET6) + opts = tp->t_inpcb->inp_outputopts6; else opts = NULL; error = ip6_output(m, opts, ro, so->so_options & SO_DONTROUTE, - NULL, tp->t_in6pcb, NULL); + NULL, tp->t_inpcb, NULL); break; } #endif @@ -1663,12 +1610,7 @@ timer: out: if (error == ENOBUFS) { TCP_STATINC(TCP_STAT_SELFQUENCH); - if (tp->t_inpcb) - tcp_quench(tp->t_inpcb); -#ifdef INET6 - if (tp->t_in6pcb) - tcp6_quench(tp->t_in6pcb); -#endif + tcp_quench(tp->t_inpcb); error = 0; } else if ((error == EHOSTUNREACH || error == ENETDOWN) && TCPS_HAVERCVDSYN(tp->t_state)) { diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 442c4710d87..b2add6727d3 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -229,7 +229,7 @@ static int tcp_iss_secret_init(void); static void tcp_mtudisc_callback(struct in_addr); #ifdef INET6 -static void tcp6_mtudisc(struct in6pcb *, int); +static void tcp6_mtudisc(struct inpcb *, int); #endif static struct pool tcpcb_pool; @@ -448,9 +448,6 @@ struct mbuf * tcp_template(struct tcpcb *tp) { struct inpcb *inp = tp->t_inpcb; -#ifdef INET6 - struct in6pcb *in6p = tp->t_in6pcb; -#endif struct tcphdr *n; struct mbuf *m; int hlen; @@ -458,13 +455,13 @@ tcp_template(struct tcpcb *tp) switch (tp->t_family) { case AF_INET: hlen = sizeof(struct ip); - if (inp) + if (inp->inp_af == AF_INET) break; #ifdef INET6 - if (in6p) { + if (inp->inp_af == AF_INET6) { /* mapped addr case */ - if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr) - && IN6_IS_ADDR_V4MAPPED(&in6p->in6p_faddr)) + if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6) + && IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) break; } #endif @@ -472,7 +469,7 @@ tcp_template(struct tcpcb *tp) #ifdef INET6 case AF_INET6: hlen = sizeof(struct ip6_hdr); - if (in6p) { + if (inp != NULL) { /* more sainty check? */ break; } @@ -518,16 +515,16 @@ tcp_template(struct tcpcb *tp) ipov = mtod(m, struct ipovly *); ipov->ih_pr = IPPROTO_TCP; ipov->ih_len = htons(sizeof(struct tcphdr)); - if (inp) { + if (inp->inp_af == AF_INET) { ipov->ih_src = inp->inp_laddr; ipov->ih_dst = inp->inp_faddr; } #ifdef INET6 - else if (in6p) { + else if (inp->inp_af == AF_INET6) { /* mapped addr case */ - bcopy(&in6p->in6p_laddr.s6_addr32[3], &ipov->ih_src, + bcopy(&inp->inp_laddr6.s6_addr32[3], &ipov->ih_src, sizeof(ipov->ih_src)); - bcopy(&in6p->in6p_faddr.s6_addr32[3], &ipov->ih_dst, + bcopy(&inp->inp_faddr6.s6_addr32[3], &ipov->ih_dst, sizeof(ipov->ih_dst)); } #endif @@ -552,9 +549,9 @@ tcp_template(struct tcpcb *tp) ip6 = mtod(m, struct ip6_hdr *); ip6->ip6_nxt = IPPROTO_TCP; ip6->ip6_plen = htons(sizeof(struct tcphdr)); - ip6->ip6_src = in6p->in6p_laddr; - ip6->ip6_dst = in6p->in6p_faddr; - ip6->ip6_flow = in6p->in6p_flowinfo & IPV6_FLOWINFO_MASK; + ip6->ip6_src = inp->inp_laddr6; + ip6->ip6_dst = inp->inp_faddr6; + ip6->ip6_flow = inp->inp_flowinfo & IPV6_FLOWINFO_MASK; if (ip6_auto_flowlabel) { ip6->ip6_flow &= ~IPV6_FLOWLABEL_MASK; ip6->ip6_flow |= @@ -570,24 +567,16 @@ tcp_template(struct tcpcb *tp) * checksum right before the packet is sent off onto * the wire. */ - n->th_sum = in6_cksum_phdr(&in6p->in6p_laddr, - &in6p->in6p_faddr, htonl(sizeof(struct tcphdr)), + n->th_sum = in6_cksum_phdr(&inp->inp_laddr6, + &inp->inp_faddr6, htonl(sizeof(struct tcphdr)), htonl(IPPROTO_TCP)); break; } #endif } - if (inp) { - n->th_sport = inp->inp_lport; - n->th_dport = inp->inp_fport; - } -#ifdef INET6 - else if (in6p) { - n->th_sport = in6p->in6p_lport; - n->th_dport = in6p->in6p_fport; - } -#endif + n->th_sport = inp->inp_lport; + n->th_dport = inp->inp_fport; n->th_seq = 0; n->th_ack = 0; @@ -623,18 +612,13 @@ tcp_respond(struct tcpcb *tp, struct mbuf *mtemplate, struct mbuf *m, #ifdef INET6 struct ip6_hdr *ip6; #endif - int family; /* family on packet, not inpcb/in6pcb! */ + int family; /* family on packet, not inpcb! */ struct tcphdr *th; if (tp != NULL && (flags & TH_RST) == 0) { - KASSERT(!(tp->t_inpcb && tp->t_in6pcb)); + KASSERT(tp->t_inpcb != NULL); - if (tp->t_inpcb) - win = sbspace(&tp->t_inpcb->inp_socket->so_rcv); -#ifdef INET6 - if (tp->t_in6pcb) - win = sbspace(&tp->t_in6pcb->in6p_socket->so_rcv); -#endif + win = sbspace(&tp->t_inpcb->inp_socket->so_rcv); } th = NULL; /* Quell uninitialized warning */ @@ -822,8 +806,8 @@ tcp_respond(struct tcpcb *tp, struct mbuf *mtemplate, struct mbuf *m, th->th_sum = in6_cksum(m, IPPROTO_TCP, sizeof(struct ip6_hdr), tlen); ip6->ip6_plen = htons(tlen); - if (tp && tp->t_in6pcb) - ip6->ip6_hlim = in6_selecthlim_rt(tp->t_in6pcb); + if (tp && tp->t_inpcb->inp_af == AF_INET6) + ip6->ip6_hlim = in6_selecthlim_rt(tp->t_inpcb); else ip6->ip6_hlim = ip6_defhlim; ip6->ip6_flow &= ~IPV6_FLOWINFO_MASK; @@ -836,27 +820,27 @@ tcp_respond(struct tcpcb *tp, struct mbuf *mtemplate, struct mbuf *m, #endif } - if (tp != NULL && tp->t_inpcb != NULL) { + if (tp != NULL && tp->t_inpcb->inp_af == AF_INET) { ro = &tp->t_inpcb->inp_route; KASSERT(family == AF_INET); KASSERT(in_hosteq(ip->ip_dst, tp->t_inpcb->inp_faddr)); } #ifdef INET6 - else if (tp != NULL && tp->t_in6pcb != NULL) { - ro = (struct route *)&tp->t_in6pcb->in6p_route; + else if (tp != NULL && tp->t_inpcb->inp_af == AF_INET6) { + ro = (struct route *)&tp->t_inpcb->inp_route; #ifdef DIAGNOSTIC if (family == AF_INET) { - if (!IN6_IS_ADDR_V4MAPPED(&tp->t_in6pcb->in6p_faddr)) + if (!IN6_IS_ADDR_V4MAPPED(&tp->t_inpcb->inp_faddr6)) panic("tcp_respond: not mapped addr"); if (memcmp(&ip->ip_dst, - &tp->t_in6pcb->in6p_faddr.s6_addr32[3], + &tp->t_inpcb->inp_faddr6.s6_addr32[3], sizeof(ip->ip_dst)) != 0) { panic("tcp_respond: ip_dst != in6p_faddr"); } } else if (family == AF_INET6) { if (!IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, - &tp->t_in6pcb->in6p_faddr)) + &tp->t_inpcb->inp_faddr6)) panic("tcp_respond: ip6_dst != in6p_faddr"); } else panic("tcp_respond: address family mismatch"); @@ -875,7 +859,7 @@ tcp_respond(struct tcpcb *tp, struct mbuf *mtemplate, struct mbuf *m, #ifdef INET6 case AF_INET6: error = ip6_output(m, NULL, ro, 0, NULL, - tp ? tp->t_in6pcb : NULL, NULL); + tp ? tp->t_inpcb : NULL, NULL); break; #endif default: @@ -957,9 +941,8 @@ tcp_tcpcb_template(void) * empty reassembly queue and hooking it to the argument * protocol control block. */ -/* family selects inpcb, or in6pcb */ struct tcpcb * -tcp_newtcpcb(int family, void *aux) +tcp_newtcpcb(int family, struct inpcb *inp) { struct tcpcb *tp; int i; @@ -984,29 +967,21 @@ tcp_newtcpcb(int family, void *aux) switch (family) { case AF_INET: - { - struct inpcb *inp = (struct inpcb *)aux; - inp->inp_ip.ip_ttl = ip_defttl; inp->inp_ppcb = (void *)tp; tp->t_inpcb = inp; tp->t_mtudisc = ip_mtudisc; break; - } #ifdef INET6 case AF_INET6: - { - struct in6pcb *in6p = (struct in6pcb *)aux; + inp->inp_ip6.ip6_hlim = in6_selecthlim_rt(inp); + inp->inp_ppcb = (void *)tp; - in6p->in6p_ip6.ip6_hlim = in6_selecthlim_rt(in6p); - in6p->in6p_ppcb = (void *)tp; - - tp->t_in6pcb = in6p; + tp->t_inpcb = inp; /* for IPv6, always try to run path MTU discovery */ tp->t_mtudisc = 1; break; - } #endif /* INET6 */ default: for (i = 0; i < TCPT_NTIMERS; i++) @@ -1042,17 +1017,12 @@ tcp_newtcpcb(int family, void *aux) struct tcpcb * tcp_drop(struct tcpcb *tp, int errno) { - struct socket *so = NULL; + struct socket *so; - KASSERT(!(tp->t_inpcb && tp->t_in6pcb)); + KASSERT(tp->t_inpcb != NULL); - if (tp->t_inpcb) - so = tp->t_inpcb->inp_socket; -#ifdef INET6 - if (tp->t_in6pcb) - so = tp->t_in6pcb->in6p_socket; -#endif - if (!so) + so = tp->t_inpcb->inp_socket; + if (so != NULL) return NULL; if (TCPS_HAVERCVDSYN(tp->t_state)) { @@ -1077,9 +1047,6 @@ struct tcpcb * tcp_close(struct tcpcb *tp) { struct inpcb *inp; -#ifdef INET6 - struct in6pcb *in6p; -#endif struct socket *so; #ifdef RTV_RTT struct rtentry *rt = NULL; @@ -1088,21 +1055,8 @@ tcp_close(struct tcpcb *tp) int j; inp = tp->t_inpcb; -#ifdef INET6 - in6p = tp->t_in6pcb; -#endif - so = NULL; - ro = NULL; - if (inp) { - so = inp->inp_socket; - ro = &inp->inp_route; - } -#ifdef INET6 - else if (in6p) { - so = in6p->in6p_socket; - ro = (struct route *)&in6p->in6p_route; - } -#endif + so = inp->inp_socket; + ro = &inp->inp_route; #ifdef RTV_RTT /* @@ -1195,18 +1149,9 @@ tcp_close(struct tcpcb *tp) * (prevents access by timers) and only then detach it. */ tp->t_flags |= TF_DEAD; - if (inp) { - inp->inp_ppcb = 0; - soisdisconnected(so); - in_pcbdetach(inp); - } -#ifdef INET6 - else if (in6p) { - in6p->in6p_ppcb = 0; - soisdisconnected(so); - in6_pcbdetach(in6p); - } -#endif + inp->inp_ppcb = NULL; + soisdisconnected(so); + in_pcbdetach(inp); /* * pcb is no longer visble elsewhere, so we can safely release * the lock in callout_halt() if needed. @@ -1265,7 +1210,7 @@ tcp_drainstub(void) void tcp_drain(void) { - struct inpcb_hdr *inph; + struct inpcb *inp; struct tcpcb *tp; mutex_enter(softnet_lock); @@ -1274,20 +1219,8 @@ tcp_drain(void) /* * Free the sequence queue of all TCP connections. */ - TAILQ_FOREACH(inph, &tcbtable.inpt_queue, inph_queue) { - switch (inph->inph_af) { - case AF_INET: - tp = intotcpcb((struct inpcb *)inph); - break; -#ifdef INET6 - case AF_INET6: - tp = in6totcpcb((struct in6pcb *)inph); - break; -#endif - default: - tp = NULL; - break; - } + TAILQ_FOREACH(inp, &tcbtable.inpt_queue, inp_queue) { + tp = intotcpcb(inp); if (tp != NULL) { /* * If the tcpcb is already busy, @@ -1337,41 +1270,12 @@ tcp_notify(struct inpcb *inp, int error) sowwakeup(so); } -#ifdef INET6 -void -tcp6_notify(struct in6pcb *in6p, int error) -{ - struct tcpcb *tp = (struct tcpcb *)in6p->in6p_ppcb; - struct socket *so = in6p->in6p_socket; - - /* - * Ignore some errors if we are hooked up. - * If connection hasn't completed, has retransmitted several times, - * and receives a second error, give up now. This is better - * than waiting a long time to establish a connection that - * can never complete. - */ - if (tp->t_state == TCPS_ESTABLISHED && - (error == EHOSTUNREACH || error == ENETUNREACH || - error == EHOSTDOWN)) { - return; - } else if (TCPS_HAVEESTABLISHED(tp->t_state) == 0 && - tp->t_rxtshift > 3 && tp->t_softerror) - so->so_error = error; - else - tp->t_softerror = error; - cv_broadcast(&so->so_cv); - sorwakeup(so); - sowwakeup(so); -} -#endif - #ifdef INET6 void * tcp6_ctlinput(int cmd, const struct sockaddr *sa, void *d) { struct tcphdr th; - void (*notify)(struct in6pcb *, int) = tcp6_notify; + void (*notify)(struct inpcb *, int) = tcp_notify; int nmatch; struct ip6_hdr *ip6; const struct sockaddr_in6 *sa6_src = NULL; @@ -1487,7 +1391,6 @@ tcp_ctlinput(int cmd, const struct sockaddr *sa, void *v) tcp_seq seq; struct inpcb *inp; #ifdef INET6 - struct in6pcb *in6p; struct in6_addr src6, dst6; #endif @@ -1520,13 +1423,9 @@ tcp_ctlinput(int cmd, const struct sockaddr *sa, void *v) #endif if ((inp = in_pcblookup_connect(&tcbtable, ip->ip_dst, th->th_dport, ip->ip_src, th->th_sport, 0)) != NULL) -#ifdef INET6 - in6p = NULL; -#else ; -#endif #ifdef INET6 - else if ((in6p = in6_pcblookup_connect(&tcbtable, &dst6, + else if ((inp = in6_pcblookup_connect(&tcbtable, &dst6, th->th_dport, &src6, th->th_sport, 0, 0)) != NULL) ; #endif @@ -1541,17 +1440,8 @@ tcp_ctlinput(int cmd, const struct sockaddr *sa, void *v) */ icp = (struct icmp *)((char *)ip - offsetof(struct icmp, icmp_ip)); - if (inp) { - if ((tp = intotcpcb(inp)) == NULL) - return NULL; - } -#ifdef INET6 - else if (in6p) { - if ((tp = in6totcpcb(in6p)) == NULL) - return NULL; - } -#endif - else + tp = intotcpcb(inp); + if (tp == NULL) return NULL; seq = ntohl(th->th_seq); if (SEQ_LT(seq, tp->snd_una) || SEQ_GT(seq, tp->snd_max)) @@ -1634,19 +1524,6 @@ tcp_quench(struct inpcb *inp) } } -#ifdef INET6 -void -tcp6_quench(struct in6pcb *in6p) -{ - struct tcpcb *tp = in6totcpcb(in6p); - - if (tp) { - tp->snd_cwnd = tp->t_segsz; - tp->t_bytes_acked = 0; - } -} -#endif - /* * Path MTU Discovery handlers. */ @@ -1730,23 +1607,23 @@ tcp6_mtudisc_callback(struct in6_addr *faddr) } void -tcp6_mtudisc(struct in6pcb *in6p, int errno) +tcp6_mtudisc(struct inpcb *inp, int errno) { - struct tcpcb *tp = in6totcpcb(in6p); + struct tcpcb *tp = intotcpcb(inp); struct rtentry *rt; if (tp == NULL) return; - rt = in6_pcbrtentry(in6p); + rt = in6_pcbrtentry(inp); if (rt != NULL) { /* * If this was not a host route, remove and realloc. */ if ((rt->rt_flags & RTF_HOST) == 0) { - in6_pcbrtentry_unref(rt, in6p); - in6_rtchange(in6p, errno); - rt = in6_pcbrtentry(in6p); + in6_pcbrtentry_unref(rt, inp); + in6_rtchange(inp, errno); + rt = in6_pcbrtentry(inp); if (rt == NULL) return; } @@ -1763,7 +1640,7 @@ tcp6_mtudisc(struct in6pcb *in6p, int errno) tp->snd_cwnd = TCP_INITIAL_WINDOW(tcp_init_win, rt->rt_rmx.rmx_mtu); } - in6_pcbrtentry_unref(rt, in6p); + in6_pcbrtentry_unref(rt, inp); } /* @@ -1870,25 +1747,14 @@ tcp_mss_from_peer(struct tcpcb *tp, int offer) u_long bufsize; int mss; - KASSERT(!(tp->t_inpcb && tp->t_in6pcb)); + KASSERT(tp->t_inpcb != NULL); so = NULL; rt = NULL; - if (tp->t_inpcb) { - so = tp->t_inpcb->inp_socket; + so = tp->t_inpcb->inp_socket; #if defined(RTV_SPIPE) || defined(RTV_SSTHRESH) - rt = in_pcbrtentry(tp->t_inpcb); -#endif - } - -#ifdef INET6 - if (tp->t_in6pcb) { - so = tp->t_in6pcb->in6p_socket; -#if defined(RTV_SPIPE) || defined(RTV_SSTHRESH) - rt = in6_pcbrtentry(tp->t_in6pcb); -#endif - } + rt = in_pcbrtentry(tp->t_inpcb); #endif /* @@ -1901,11 +1767,11 @@ tcp_mss_from_peer(struct tcpcb *tp, int offer) mss = uimax(mss, 256); /* sanity */ tp->t_peermss = mss; mss -= tcp_optlen(tp); - if (tp->t_inpcb) + if (tp->t_inpcb->inp_af == AF_INET) mss -= ip_optlen(tp->t_inpcb); #ifdef INET6 - if (tp->t_in6pcb) - mss -= ip6_optlen(tp->t_in6pcb); + if (tp->t_inpcb->inp_af == AF_INET6) + mss -= ip6_optlen(tp->t_inpcb); #endif /* * XXX XXX What if mss goes negative or zero? This can happen if a @@ -1949,12 +1815,7 @@ tcp_mss_from_peer(struct tcpcb *tp, int offer) } #endif #if defined(RTV_SPIPE) || defined(RTV_SSTHRESH) - if (tp->t_inpcb) - in_pcbrtentry_unref(rt, tp->t_inpcb); -#ifdef INET6 - if (tp->t_in6pcb) - in6_pcbrtentry_unref(rt, tp->t_in6pcb); -#endif + in_pcbrtentry_unref(rt, tp->t_inpcb); #endif } @@ -1970,13 +1831,13 @@ tcp_established(struct tcpcb *tp) #endif u_long bufsize; - KASSERT(!(tp->t_inpcb && tp->t_in6pcb)); + KASSERT(tp->t_inpcb != NULL); so = NULL; rt = NULL; /* This is a while() to reduce the dreadful stairstepping below */ - while (tp->t_inpcb) { + while (tp->t_inpcb->inp_af == AF_INET) { so = tp->t_inpcb->inp_socket; #if defined(RTV_RPIPE) rt = in_pcbrtentry(tp->t_inpcb); @@ -2005,16 +1866,15 @@ tcp_established(struct tcpcb *tp) tp->t_msl = MIN(tp->t_msl, TCP_MAXMSL); #ifdef INET6 - /* The !tp->t_inpcb lets the compiler know it can't be v4 *and* v6 */ - while (!tp->t_inpcb && tp->t_in6pcb) { - so = tp->t_in6pcb->in6p_socket; + while (tp->t_inpcb->inp_af == AF_INET6) { + so = tp->t_inpcb->inp_socket; #if defined(RTV_RPIPE) - rt = in6_pcbrtentry(tp->t_in6pcb); + rt = in6_pcbrtentry(tp->t_inpcb); #endif if (__predict_true(tcp_msl_enable)) { extern const struct in6_addr in6addr_loopback; - if (IN6_ARE_ADDR_EQUAL(&tp->t_in6pcb->in6p_laddr, + if (IN6_ARE_ADDR_EQUAL(&tp->t_inpcb->inp_laddr6, &in6addr_loopback)) { tp->t_msl = tcp_msl_loop ? tcp_msl_loop : (TCPTV_MSL >> 2); break; @@ -2025,7 +1885,7 @@ tcp_established(struct tcpcb *tp) tp->t_msl = tcp_msl_local ? tcp_msl_local : (TCPTV_MSL >> 1); break; } - if (in6_localaddr(&tp->t_in6pcb->in6p_faddr)) { + if (in6_localaddr(&tp->t_inpcb->inp_faddr6)) { tp->t_msl = tcp_msl_local ? tcp_msl_local : (TCPTV_MSL >> 1); break; } @@ -2057,12 +1917,7 @@ tcp_established(struct tcpcb *tp) (void) sbreserve(&so->so_rcv, bufsize, so); } #ifdef RTV_RPIPE - if (tp->t_inpcb) - in_pcbrtentry_unref(rt, tp->t_inpcb); -#ifdef INET6 - if (tp->t_in6pcb) - in6_pcbrtentry_unref(rt, tp->t_in6pcb); -#endif + in_pcbrtentry_unref(rt, tp->t_inpcb); #endif } @@ -2078,14 +1933,9 @@ tcp_rmx_rtt(struct tcpcb *tp) struct rtentry *rt = NULL; int rtt; - KASSERT(!(tp->t_inpcb && tp->t_in6pcb)); + KASSERT(tp->t_inpcb != NULL); - if (tp->t_inpcb) - rt = in_pcbrtentry(tp->t_inpcb); -#ifdef INET6 - if (tp->t_in6pcb) - rt = in6_pcbrtentry(tp->t_in6pcb); -#endif + rt = in_pcbrtentry(tp->t_inpcb); if (rt == NULL) return; @@ -2113,12 +1963,7 @@ tcp_rmx_rtt(struct tcpcb *tp) ((tp->t_srtt >> 2) + tp->t_rttvar) >> (1 + 2), tp->t_rttmin, TCPTV_REXMTMAX); } - if (tp->t_inpcb) - in_pcbrtentry_unref(rt, tp->t_inpcb); -#ifdef INET6 - if (tp->t_in6pcb) - in6_pcbrtentry_unref(rt, tp->t_in6pcb); -#endif + in_pcbrtentry_unref(rt, tp->t_inpcb); #endif } @@ -2131,16 +1976,16 @@ tcp_seq tcp_new_iss(struct tcpcb *tp) { - if (tp->t_inpcb != NULL) { + if (tp->t_inpcb->inp_af == AF_INET) { return tcp_new_iss1(&tp->t_inpcb->inp_laddr, &tp->t_inpcb->inp_faddr, tp->t_inpcb->inp_lport, tp->t_inpcb->inp_fport, sizeof(tp->t_inpcb->inp_laddr)); } #ifdef INET6 - if (tp->t_in6pcb != NULL) { - return tcp_new_iss1(&tp->t_in6pcb->in6p_laddr, - &tp->t_in6pcb->in6p_faddr, tp->t_in6pcb->in6p_lport, - tp->t_in6pcb->in6p_fport, sizeof(tp->t_in6pcb->in6p_laddr)); + if (tp->t_inpcb->inp_af == AF_INET6) { + return tcp_new_iss1(&tp->t_inpcb->inp_laddr6, + &tp->t_inpcb->inp_faddr6, tp->t_inpcb->inp_lport, + tp->t_inpcb->inp_fport, sizeof(tp->t_inpcb->inp_laddr6)); } #endif @@ -2230,7 +2075,7 @@ ipsec4_hdrsiz_tcp(struct tcpcb *tp) struct inpcb *inp; size_t hdrsiz; - /* XXX mapped addr case (tp->t_in6pcb) */ + /* XXX mapped addr case (tp->t_inpcb) */ if (!tp || !tp->t_template || !(inp = tp->t_inpcb)) return 0; switch (tp->t_family) { @@ -2250,15 +2095,15 @@ ipsec4_hdrsiz_tcp(struct tcpcb *tp) size_t ipsec6_hdrsiz_tcp(struct tcpcb *tp) { - struct in6pcb *in6p; + struct inpcb *inp; size_t hdrsiz; - if (!tp || !tp->t_template || !(in6p = tp->t_in6pcb)) + if (!tp || !tp->t_template || !(inp = tp->t_inpcb)) return 0; switch (tp->t_family) { case AF_INET6: /* XXX: should use correct direction. */ - hdrsiz = ipsec_hdrsiz(tp->t_template, IPSEC_DIR_OUTBOUND, in6p); + hdrsiz = ipsec_hdrsiz(tp->t_template, IPSEC_DIR_OUTBOUND, inp); break; case AF_INET: /* mapped address case - tricky */ diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index 6a9dc8f87fd..14904c6eeba 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -558,9 +558,6 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst, struct syn_cache *sc; struct syn_cache_head *scp; struct inpcb *inp = NULL; -#ifdef INET6 - struct in6pcb *in6p = NULL; -#endif struct tcpcb *tp; int s; struct socket *oso; @@ -608,20 +605,11 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst, if (so == NULL) goto resetandabort; - switch (so->so_proto->pr_domain->dom_family) { - case AF_INET: - inp = sotoinpcb(so); - break; -#ifdef INET6 - case AF_INET6: - in6p = sotoin6pcb(so); - break; -#endif - } + inp = sotoinpcb(so); switch (src->sa_family) { case AF_INET: - if (inp) { + if (inp->inp_af == AF_INET) { inp->inp_laddr = ((struct sockaddr_in *)dst)->sin_addr; inp->inp_lport = ((struct sockaddr_in *)dst)->sin_port; inp->inp_options = ip_srcroute(m); @@ -632,44 +620,44 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst, } } #ifdef INET6 - else if (in6p) { + else if (inp->inp_af == AF_INET6) { /* IPv4 packet to AF_INET6 socket */ - memset(&in6p->in6p_laddr, 0, sizeof(in6p->in6p_laddr)); - in6p->in6p_laddr.s6_addr16[5] = htons(0xffff); + memset(&inp->inp_laddr6, 0, sizeof(inp->inp_laddr6)); + inp->inp_laddr6.s6_addr16[5] = htons(0xffff); bcopy(&((struct sockaddr_in *)dst)->sin_addr, - &in6p->in6p_laddr.s6_addr32[3], + &inp->inp_laddr6.s6_addr32[3], sizeof(((struct sockaddr_in *)dst)->sin_addr)); - in6p->in6p_lport = ((struct sockaddr_in *)dst)->sin_port; - in6totcpcb(in6p)->t_family = AF_INET; - if (sotoin6pcb(oso)->in6p_flags & IN6P_IPV6_V6ONLY) - in6p->in6p_flags |= IN6P_IPV6_V6ONLY; + inp->inp_lport = ((struct sockaddr_in *)dst)->sin_port; + intotcpcb(inp)->t_family = AF_INET; + if (sotoinpcb(oso)->inp_flags & IN6P_IPV6_V6ONLY) + inp->inp_flags |= IN6P_IPV6_V6ONLY; else - in6p->in6p_flags &= ~IN6P_IPV6_V6ONLY; - in6_pcbstate(in6p, IN6P_BOUND); + inp->inp_flags &= ~IN6P_IPV6_V6ONLY; + in_pcbstate(inp, INP_BOUND); } #endif break; #ifdef INET6 case AF_INET6: - if (in6p) { - in6p->in6p_laddr = ((struct sockaddr_in6 *)dst)->sin6_addr; - in6p->in6p_lport = ((struct sockaddr_in6 *)dst)->sin6_port; - in6_pcbstate(in6p, IN6P_BOUND); + if (inp->inp_af == AF_INET6) { + inp->inp_laddr6 = ((struct sockaddr_in6 *)dst)->sin6_addr; + inp->inp_lport = ((struct sockaddr_in6 *)dst)->sin6_port; + in_pcbstate(inp, INP_BOUND); } break; #endif } #ifdef INET6 - if (in6p && in6totcpcb(in6p)->t_family == AF_INET6 && sotoinpcb(oso)) { - struct in6pcb *oin6p = sotoin6pcb(oso); + if (inp && intotcpcb(inp)->t_family == AF_INET6 && sotoinpcb(oso)) { + struct inpcb *oinp = sotoinpcb(oso); /* inherit socket options from the listening socket */ - in6p->in6p_flags |= (oin6p->in6p_flags & IN6P_CONTROLOPTS); - if (in6p->in6p_flags & IN6P_CONTROLOPTS) { - m_freem(in6p->in6p_options); - in6p->in6p_options = NULL; + inp->inp_flags |= (oinp->inp_flags & IN6P_CONTROLOPTS); + if (inp->inp_flags & IN6P_CONTROLOPTS) { + m_freem(inp->inp_options); + inp->inp_options = NULL; } - ip6_savecontrol(in6p, &in6p->in6p_options, + ip6_savecontrol(inp, &inp->inp_options, mtod(m, struct ip6_hdr *), m); } #endif @@ -677,18 +665,10 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst, /* * Give the new socket our cached route reference. */ - if (inp) { - rtcache_copy(&inp->inp_route, &sc->sc_route); - rtcache_free(&sc->sc_route); - } -#ifdef INET6 - else { - rtcache_copy(&in6p->in6p_route, &sc->sc_route); - rtcache_free(&sc->sc_route); - } -#endif + rtcache_copy(&inp->inp_route, &sc->sc_route); + rtcache_free(&sc->sc_route); - if (inp) { + if (inp->inp_af == AF_INET) { struct sockaddr_in sin; memcpy(&sin, src, src->sa_len); if (in_pcbconnect(inp, &sin, &lwp0)) { @@ -696,14 +676,14 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst, } } #ifdef INET6 - else if (in6p) { + else if (inp->inp_af == AF_INET6) { struct sockaddr_in6 sin6; memcpy(&sin6, src, src->sa_len); if (src->sa_family == AF_INET) { /* IPv4 packet to AF_INET6 socket */ in6_sin_2_v4mapsin6((struct sockaddr_in *)src, &sin6); } - if (in6_pcbconnect(in6p, &sin6, NULL)) { + if (in6_pcbconnect(inp, &sin6, NULL)) { goto resetandabort; } } @@ -712,14 +692,7 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst, goto resetandabort; } - if (inp) - tp = intotcpcb(inp); -#ifdef INET6 - else if (in6p) - tp = in6totcpcb(in6p); -#endif - else - tp = NULL; + tp = intotcpcb(inp); tp->t_flags = sototcpcb(oso)->t_flags & TF_NODELAY; if (sc->sc_request_r_scale != 15) { @@ -773,10 +746,10 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst, tp->snd_cwnd = tp->t_peermss; else { int ss = tcp_init_win; - if (inp != NULL && in_localaddr(inp->inp_faddr)) + if (inp->inp_af == AF_INET && in_localaddr(inp->inp_faddr)) ss = tcp_init_win_local; #ifdef INET6 - if (in6p != NULL && in6_localaddr(&in6p->in6p_faddr)) + else if (inp->inp_af == AF_INET6 && in6_localaddr(&inp->inp_faddr6)) ss = tcp_init_win_local; #endif tp->snd_cwnd = TCP_INITIAL_WINDOW(ss, tp->t_peermss); @@ -1373,7 +1346,7 @@ syn_cache_respond(struct syn_cache *sc) rtcache_unref(rt, ro); error = ip6_output(m, NULL /*XXX*/, ro, 0, NULL, - tp ? tp->t_in6pcb : NULL, NULL); + tp ? tp->t_inpcb : NULL, NULL); break; #endif default: diff --git a/sys/netinet/tcp_timer.c b/sys/netinet/tcp_timer.c index 69c574aa066..6e89e1a4093 100644 --- a/sys/netinet/tcp_timer.c +++ b/sys/netinet/tcp_timer.c @@ -344,12 +344,7 @@ tcp_timer_rexmt(void *arg) return; } #ifdef TCP_DEBUG - if (tp->t_inpcb) - so = tp->t_inpcb->inp_socket; -#ifdef INET6 - if (tp->t_in6pcb) - so = tp->t_in6pcb->in6p_socket; -#endif + so = tp->t_inpcb->inp_socket; ostate = tp->t_state; #endif /* TCP_DEBUG */ @@ -391,14 +386,8 @@ tcp_timer_rexmt(void *arg) if (tp->t_mtudisc && tp->t_rxtshift > TCP_MAXRXTSHIFT / 6) { TCP_STATINC(TCP_STAT_PMTUBLACKHOLE); - /* try turning PMTUD off */ - if (tp->t_inpcb) - tp->t_mtudisc = 0; -#ifdef INET6 - /* try using IPv6 minimum MTU */ - if (tp->t_in6pcb) - tp->t_mtudisc = 0; -#endif + /* try turning PMTUD off or try using IPv6 minimum MTU */ + tp->t_mtudisc = 0; /* XXX: more sophisticated Black hole recovery code? */ } @@ -412,12 +401,7 @@ tcp_timer_rexmt(void *arg) * retransmit times until then. */ if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) { - if (tp->t_inpcb) - in_losing(tp->t_inpcb); -#ifdef INET6 - if (tp->t_in6pcb) - in6_losing(tp->t_in6pcb); -#endif + in_losing(tp->t_inpcb); /* * This operation is not described in RFC2988. The * point is to keep srtt+4*rttvar constant, so we @@ -482,13 +466,7 @@ tcp_timer_persist(void *arg) KERNEL_LOCK(1, NULL); #ifdef TCP_DEBUG - if (tp->t_inpcb) - so = tp->t_inpcb->inp_socket; -#ifdef INET6 - if (tp->t_in6pcb) - so = tp->t_in6pcb->in6p_socket; -#endif - + so = tp->t_inpcb->inp_socket; ostate = tp->t_state; #endif /* TCP_DEBUG */ @@ -563,12 +541,7 @@ tcp_timer_keep(void *arg) TCP_STATINC(TCP_STAT_KEEPTIMEO); if (TCPS_HAVEESTABLISHED(tp->t_state) == 0) goto dropit; - if (tp->t_inpcb) - so = tp->t_inpcb->inp_socket; -#ifdef INET6 - if (tp->t_in6pcb) - so = tp->t_in6pcb->in6p_socket; -#endif + so = tp->t_inpcb->inp_socket; KASSERT(so != NULL); if (so->so_options & SO_KEEPALIVE && tp->t_state <= TCPS_CLOSE_WAIT) { @@ -642,13 +615,7 @@ tcp_timer_2msl(void *arg) tp->snd_fack = tp->snd_una; #ifdef TCP_DEBUG - if (tp->t_inpcb) - so = tp->t_inpcb->inp_socket; -#ifdef INET6 - if (tp->t_in6pcb) - so = tp->t_in6pcb->in6p_socket; -#endif - + so = tp->t_inpcb->inp_socket; ostate = tp->t_state; #endif /* TCP_DEBUG */ diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 51b90e3143e..3075156ce2e 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -171,42 +171,6 @@ tcp_debug_trace(struct socket *so, struct tcpcb *tp, int ostate, int req) #endif } -static int -tcp_getpcb(struct socket *so, struct inpcb **inp, - struct in6pcb **in6p, struct tcpcb **tp) -{ - - KASSERT(solocked(so)); - - /* - * When a TCP is attached to a socket, then there will be - * a (struct inpcb) pointed at by the socket, and this - * structure will point at a subsidary (struct tcpcb). - */ - switch (so->so_proto->pr_domain->dom_family) { - case PF_INET: - *inp = sotoinpcb(so); - if (*inp == NULL) - return EINVAL; - *tp = intotcpcb(*inp); - break; -#ifdef INET6 - case PF_INET6: - *in6p = sotoin6pcb(so); - if (*in6p == NULL) - return EINVAL; - *tp = in6totcpcb(*in6p); - break; -#endif - default: - return EAFNOSUPPORT; - } - - KASSERT(tp != NULL); - - return 0; -} - static void change_keepalive(struct socket *so, struct tcpcb *tp) { @@ -295,9 +259,6 @@ tcp_ctloutput(int op, struct socket *so, struct sockopt *sopt) { int error = 0, s; struct inpcb *inp; -#ifdef INET6 - struct in6pcb *in6p; -#endif struct tcpcb *tp; struct tcp_info ti; u_int ui; @@ -310,32 +271,7 @@ tcp_ctloutput(int op, struct socket *so, struct sockopt *sopt) family = so->so_proto->pr_domain->dom_family; s = splsoftnet(); - switch (family) { - case PF_INET: - inp = sotoinpcb(so); -#ifdef INET6 - in6p = NULL; -#endif - break; -#ifdef INET6 - case PF_INET6: - inp = NULL; - in6p = sotoin6pcb(so); - break; -#endif - default: - splx(s); - panic("%s: af %d", __func__, family); - } -#ifndef INET6 - if (inp == NULL) -#else - if (inp == NULL && in6p == NULL) -#endif - { - splx(s); - return ECONNRESET; - } + inp = sotoinpcb(so); if (level != IPPROTO_TCP) { switch (family) { case PF_INET: @@ -350,14 +286,7 @@ tcp_ctloutput(int op, struct socket *so, struct sockopt *sopt) splx(s); return error; } - if (inp) - tp = intotcpcb(inp); -#ifdef INET6 - else if (in6p) - tp = in6totcpcb(in6p); -#endif - else - tp = NULL; + tp = intotcpcb(inp); switch (op) { case PRCO_SETOPT: @@ -513,39 +442,18 @@ tcp_attach(struct socket *so, int proto) { struct tcpcb *tp; struct inpcb *inp; -#ifdef INET6 - struct in6pcb *in6p; -#endif int s, error, family; /* Assign the lock (must happen even if we will error out). */ s = splsoftnet(); sosetlock(so); KASSERT(solocked(so)); + KASSERT(sotoinpcb(so) == NULL); - family = so->so_proto->pr_domain->dom_family; - switch (family) { - case PF_INET: - inp = sotoinpcb(so); -#ifdef INET6 - in6p = NULL; -#endif - break; -#ifdef INET6 - case PF_INET6: - inp = NULL; - in6p = sotoin6pcb(so); - break; -#endif - default: - error = EAFNOSUPPORT; - goto out; - } - + inp = sotoinpcb(so); KASSERT(inp == NULL); -#ifdef INET6 - KASSERT(in6p == NULL); -#endif + + family = soaf(so); #ifdef MBUFTRACE so->so_mowner = &tcp_sock_mowner; @@ -561,48 +469,17 @@ tcp_attach(struct socket *so, int proto) so->so_rcv.sb_flags |= SB_AUTOSIZE; so->so_snd.sb_flags |= SB_AUTOSIZE; - switch (family) { - case PF_INET: - error = in_pcballoc(so, &tcbtable); - if (error) - goto out; - inp = sotoinpcb(so); -#ifdef INET6 - in6p = NULL; -#endif - break; -#ifdef INET6 - case PF_INET6: - error = in6_pcballoc(so, &tcbtable); - if (error) - goto out; - inp = NULL; - in6p = sotoin6pcb(so); - break; -#endif - default: - error = EAFNOSUPPORT; + error = in_pcballoc(so, &tcbtable); + if (error) goto out; - } - if (inp) - tp = tcp_newtcpcb(family, (void *)inp); -#ifdef INET6 - else if (in6p) - tp = tcp_newtcpcb(family, (void *)in6p); -#endif - else - tp = NULL; + inp = sotoinpcb(so); + tp = tcp_newtcpcb(family, inp); if (tp == NULL) { int nofd = so->so_state & SS_NOFDREF; /* XXX */ so->so_state &= ~SS_NOFDREF; /* don't free the socket yet */ - if (inp) - in_pcbdetach(inp); -#ifdef INET6 - if (in6p) - in6_pcbdetach(in6p); -#endif + in_pcbdetach(inp); so->so_state |= nofd; error = ENOBUFS; goto out; @@ -620,13 +497,12 @@ out: static void tcp_detach(struct socket *so) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; + struct inpcb *inp; + struct tcpcb *tp; int s; - if (tcp_getpcb(so, &inp, &in6p, &tp) != 0) - return; + inp = sotoinpcb(so); + tp = intotcpcb(inp); s = splsoftnet(); (void)tcp_disconnect1(tp); @@ -636,15 +512,13 @@ tcp_detach(struct socket *so) static int tcp_accept(struct socket *so, struct sockaddr *nam) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; + struct inpcb *inp; + struct tcpcb *tp; int ostate = 0; - int error = 0; int s; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_ACCEPT); @@ -654,12 +528,12 @@ tcp_accept(struct socket *so, struct sockaddr *nam) * of the peer, storing through addr. */ s = splsoftnet(); - if (inp) { + if (inp->inp_af == AF_INET) { in_setpeeraddr(inp, (struct sockaddr_in *)nam); } #ifdef INET6 - if (in6p) { - in6_setpeeraddr(in6p, (struct sockaddr_in6 *)nam); + else if (inp->inp_af == AF_INET6) { + in6_setpeeraddr(inp, (struct sockaddr_in6 *)nam); } #endif tcp_debug_trace(so, tp, ostate, PRU_ACCEPT); @@ -672,18 +546,17 @@ static int tcp_bind(struct socket *so, struct sockaddr *nam, struct lwp *l) { struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; struct sockaddr_in *sin = (struct sockaddr_in *)nam; #ifdef INET6 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam; #endif /* INET6 */ - struct tcpcb *tp = NULL; + struct tcpcb *tp; int s; int error = 0; int ostate = 0; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_BIND); @@ -697,10 +570,10 @@ tcp_bind(struct socket *so, struct sockaddr *nam, struct lwp *l) break; #ifdef INET6 case PF_INET6: - error = in6_pcbbind(in6p, sin6, l); + error = in6_pcbbind(inp, sin6, l); if (!error) { /* mapped addr case */ - if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr)) + if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)) tp->t_family = AF_INET; else tp->t_family = AF_INET6; @@ -717,15 +590,14 @@ tcp_bind(struct socket *so, struct sockaddr *nam, struct lwp *l) static int tcp_listen(struct socket *so, struct lwp *l) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; + struct inpcb *inp; + struct tcpcb *tp; int error = 0; int ostate = 0; int s; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_LISTEN); @@ -733,14 +605,14 @@ tcp_listen(struct socket *so, struct lwp *l) * Prepare to accept connections. */ s = splsoftnet(); - if (inp && inp->inp_lport == 0) { + if (inp->inp_af == AF_INET && inp->inp_lport == 0) { error = in_pcbbind(inp, NULL, l); if (error) goto release; } #ifdef INET6 - if (in6p && in6p->in6p_lport == 0) { - error = in6_pcbbind(in6p, NULL, l); + if (inp->inp_af == AF_INET6 && inp->inp_lport == 0) { + error = in6_pcbbind(inp, NULL, l); if (error) goto release; } @@ -757,15 +629,14 @@ release: static int tcp_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; + struct inpcb *inp; + struct tcpcb *tp; int s; int error = 0; int ostate = 0; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_CONNECT); @@ -778,7 +649,7 @@ tcp_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) */ s = splsoftnet(); - if (inp) { + if (inp->inp_af == AF_INET) { if (inp->inp_lport == 0) { error = in_pcbbind(inp, NULL, l); if (error) @@ -787,16 +658,16 @@ tcp_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) error = in_pcbconnect(inp, (struct sockaddr_in *)nam, l); } #ifdef INET6 - if (in6p) { - if (in6p->in6p_lport == 0) { - error = in6_pcbbind(in6p, NULL, l); + if (inp->inp_af == AF_INET6) { + if (inp->inp_lport == 0) { + error = in6_pcbbind(inp, NULL, l); if (error) goto release; } - error = in6_pcbconnect(in6p, (struct sockaddr_in6 *)nam, l); + error = in6_pcbconnect(inp, (struct sockaddr_in6 *)nam, l); if (!error) { /* mapped addr case */ - if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_faddr)) + if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) tp->t_family = AF_INET; else tp->t_family = AF_INET6; @@ -807,11 +678,11 @@ tcp_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) goto release; tp->t_template = tcp_template(tp); if (tp->t_template == 0) { - if (inp) + if (inp->inp_af == AF_INET) in_pcbdisconnect(inp); #ifdef INET6 - if (in6p) - in6_pcbdisconnect(in6p); + else if (inp->inp_af == AF_INET6) + in6_pcbdisconnect(inp); #endif error = ENOBUFS; goto release; @@ -841,16 +712,14 @@ release: static int tcp_connect2(struct socket *so, struct socket *so2) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; - int error = 0; + struct inpcb *inp; + struct tcpcb *tp; int ostate = 0; KASSERT(solocked(so)); - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_CONNECT2); @@ -862,15 +731,14 @@ tcp_connect2(struct socket *so, struct socket *so2) static int tcp_disconnect(struct socket *so) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; + struct inpcb *inp; + struct tcpcb *tp; int error = 0; int ostate = 0; int s; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_DISCONNECT); @@ -896,15 +764,14 @@ tcp_disconnect(struct socket *so) static int tcp_shutdown(struct socket *so) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; + struct inpcb *inp; + struct tcpcb *tp; int error = 0; int ostate = 0; int s; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_SHUTDOWN); /* @@ -924,15 +791,14 @@ tcp_shutdown(struct socket *so) static int tcp_abort(struct socket *so) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; + struct inpcb *inp; + struct tcpcb *tp; int error = 0; int ostate = 0; int s; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_ABORT); @@ -974,25 +840,23 @@ tcp_stat(struct socket *so, struct stat *ub) static int tcp_peeraddr(struct socket *so, struct sockaddr *nam) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; + struct inpcb *inp; + struct tcpcb *tp; int ostate = 0; - int error = 0; int s; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_PEERADDR); s = splsoftnet(); - if (inp) { + if (inp->inp_af == AF_INET) { in_setpeeraddr(inp, (struct sockaddr_in *)nam); } #ifdef INET6 - if (in6p) { - in6_setpeeraddr(in6p, (struct sockaddr_in6 *)nam); + else if (inp->inp_af == AF_INET6) { + in6_setpeeraddr(inp, (struct sockaddr_in6 *)nam); } #endif tcp_debug_trace(so, tp, ostate, PRU_PEERADDR); @@ -1004,25 +868,23 @@ tcp_peeraddr(struct socket *so, struct sockaddr *nam) static int tcp_sockaddr(struct socket *so, struct sockaddr *nam) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; + struct inpcb *inp; + struct tcpcb *tp; int ostate = 0; - int error = 0; int s; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_SOCKADDR); s = splsoftnet(); - if (inp) { + if (inp->inp_af == AF_INET) { in_setsockaddr(inp, (struct sockaddr_in *)nam); } #ifdef INET6 - if (in6p) { - in6_setsockaddr(in6p, (struct sockaddr_in6 *)nam); + if (inp->inp_af == AF_INET6) { + in6_setsockaddr(inp, (struct sockaddr_in6 *)nam); } #endif tcp_debug_trace(so, tp, ostate, PRU_SOCKADDR); @@ -1034,15 +896,13 @@ tcp_sockaddr(struct socket *so, struct sockaddr *nam) static int tcp_rcvd(struct socket *so, int flags, struct lwp *l) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; + struct inpcb *inp; + struct tcpcb *tp; int ostate = 0; - int error = 0; int s; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_RCVD); @@ -1068,15 +928,13 @@ tcp_rcvd(struct socket *so, int flags, struct lwp *l) static int tcp_recvoob(struct socket *so, struct mbuf *m, int flags) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; + struct inpcb *inp; + struct tcpcb *tp; int ostate = 0; - int error = 0; int s; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_RCVOOB); @@ -1111,15 +969,14 @@ static int tcp_send(struct socket *so, struct mbuf *m, struct sockaddr *nam, struct mbuf *control, struct lwp *l) { - struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; - struct tcpcb *tp = NULL; + struct inpcb *inp; + struct tcpcb *tp; int ostate = 0; int error = 0; int s; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) - return error; + inp = sotoinpcb(so); + tp = intotcpcb(inp); ostate = tcp_debug_capture(tp, PRU_SEND); @@ -1148,17 +1005,13 @@ static int tcp_sendoob(struct socket *so, struct mbuf *m, struct mbuf *control) { struct inpcb *inp = NULL; - struct in6pcb *in6p = NULL; struct tcpcb *tp = NULL; int ostate = 0; int error = 0; int s; - if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) { - m_freem(m); - m_freem(control); - return error; - } + inp = sotoinpcb(so); + tp = intotcpcb(inp); if (tp->t_template == NULL) { /* * XXX FreeBSD appears to open the connection @@ -1256,14 +1109,7 @@ tcp_disconnect1(struct tcpcb *tp) { struct socket *so; - if (tp->t_inpcb) - so = tp->t_inpcb->inp_socket; -#ifdef INET6 - else if (tp->t_in6pcb) - so = tp->t_in6pcb->in6p_socket; -#endif - else - so = NULL; + so = tp->t_inpcb->inp_socket; if (TCPS_HAVEESTABLISHED(tp->t_state) == 0) tp = tcp_close(tp); @@ -1312,15 +1158,7 @@ tcp_usrclosed(struct tcpcb *tp) break; } if (tp && tp->t_state >= TCPS_FIN_WAIT_2) { - struct socket *so; - if (tp->t_inpcb) - so = tp->t_inpcb->inp_socket; -#ifdef INET6 - else if (tp->t_in6pcb) - so = tp->t_in6pcb->in6p_socket; -#endif - else - so = NULL; + struct socket *so = tp->t_inpcb->inp_socket; if (so) soisdisconnected(so); /* @@ -1333,11 +1171,11 @@ tcp_usrclosed(struct tcpcb *tp) if ((tp->t_state == TCPS_FIN_WAIT_2) && (tp->t_maxidle > 0)) TCP_TIMER_ARM(tp, TCPT_2MSL, tp->t_maxidle); else if (tp->t_state == TCPS_TIME_WAIT - && ((tp->t_inpcb + && ((tp->t_inpcb->inp_af == AF_INET && (tcp4_vtw_enable & 1) && vtw_add(AF_INET, tp)) || - (tp->t_in6pcb + (tp->t_inpcb->inp_af == AF_INET6 && (tcp6_vtw_enable & 1) && vtw_add(AF_INET6, tp)))) { tp = 0; @@ -1576,24 +1414,24 @@ inet6_ident_core(struct in6_addr *raddr, u_int rport, void *oldp, size_t *oldlenp, struct lwp *l, int dodrop) { - struct in6pcb *in6p; + struct inpcb *inp; struct socket *sockp; - in6p = in6_pcblookup_connect(&tcbtable, raddr, rport, laddr, lport, 0, 0); + inp = in6_pcblookup_connect(&tcbtable, raddr, rport, laddr, lport, 0, 0); - if (in6p == NULL || (sockp = in6p->in6p_socket) == NULL) + if (inp == NULL || (sockp = inp->inp_socket) == NULL) return ESRCH; if (dodrop) { struct tcpcb *tp; int error; - if (in6p == NULL || (tp = in6totcpcb(in6p)) == NULL || - (in6p->in6p_socket->so_options & SO_ACCEPTCONN) != 0) + if (inp == NULL || (tp = intotcpcb(inp)) == NULL || + (inp->inp_socket->so_options & SO_ACCEPTCONN) != 0) return ESRCH; error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET, - KAUTH_REQ_NETWORK_SOCKET_DROP, in6p->in6p_socket, tp, NULL); + KAUTH_REQ_NETWORK_SOCKET_DROP, inp->inp_socket, tp, NULL); if (error) return error; @@ -1739,10 +1577,8 @@ sysctl_inpcblist(SYSCTLFN_ARGS) const struct inpcb *inp; #ifdef INET6 struct sockaddr_in6 *in6; - const struct in6pcb *in6p; #endif struct inpcbtable *pcbtbl = __UNCONST(rnode->sysctl_data); - const struct inpcb_hdr *inph; struct tcpcb *tp; struct kinfo_pcb pcb; char *dp; @@ -1780,17 +1616,12 @@ sysctl_inpcblist(SYSCTLFN_ARGS) mutex_enter(softnet_lock); - TAILQ_FOREACH(inph, &pcbtbl->inpt_queue, inph_queue) { - inp = (const struct inpcb *)inph; -#ifdef INET6 - in6p = (const struct in6pcb *)inph; -#endif - - if (inph->inph_af != pf) + TAILQ_FOREACH(inp, &pcbtbl->inpt_queue, inp_queue) { + if (inp->inp_af != pf) continue; if (kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET, - KAUTH_REQ_NETWORK_SOCKET_CANSEE, inph->inph_socket, NULL, + KAUTH_REQ_NETWORK_SOCKET_CANSEE, inp->inp_socket, NULL, NULL) != 0) continue; @@ -1845,46 +1676,46 @@ sysctl_inpcblist(SYSCTLFN_ARGS) break; #ifdef INET6 case PF_INET6: - pcb.ki_family = in6p->in6p_socket->so_proto-> + pcb.ki_family = inp->inp_socket->so_proto-> pr_domain->dom_family; - pcb.ki_type = in6p->in6p_socket->so_proto->pr_type; - pcb.ki_protocol = in6p->in6p_socket->so_proto-> + pcb.ki_type = inp->inp_socket->so_proto->pr_type; + pcb.ki_protocol = inp->inp_socket->so_proto-> pr_protocol; - pcb.ki_pflags = in6p->in6p_flags; + pcb.ki_pflags = inp->inp_flags; - pcb.ki_sostate = in6p->in6p_socket->so_state; - pcb.ki_prstate = in6p->in6p_state; + pcb.ki_sostate = inp->inp_socket->so_state; + pcb.ki_prstate = inp->inp_state; if (proto == IPPROTO_TCP) { - tp = in6totcpcb(in6p); + tp = intotcpcb(inp); pcb.ki_tstate = tp->t_state; pcb.ki_tflags = tp->t_flags; } COND_SET_VALUE(pcb.ki_pcbaddr, - PTRTOUINT64(in6p), allowaddr); + PTRTOUINT64(inp), allowaddr); COND_SET_VALUE(pcb.ki_ppcbaddr, - PTRTOUINT64(in6p->in6p_ppcb), allowaddr); + PTRTOUINT64(inp->inp_ppcb), allowaddr); COND_SET_VALUE(pcb.ki_sockaddr, - PTRTOUINT64(in6p->in6p_socket), allowaddr); + PTRTOUINT64(inp->inp_socket), allowaddr); - pcb.ki_rcvq = in6p->in6p_socket->so_rcv.sb_cc; - pcb.ki_sndq = in6p->in6p_socket->so_snd.sb_cc; + pcb.ki_rcvq = inp->inp_socket->so_rcv.sb_cc; + pcb.ki_sndq = inp->inp_socket->so_snd.sb_cc; in6 = satosin6(&pcb.ki_src); in6->sin6_len = sizeof(*in6); in6->sin6_family = pf; - in6->sin6_port = in6p->in6p_lport; - in6->sin6_flowinfo = in6p->in6p_flowinfo; - in6->sin6_addr = in6p->in6p_laddr; + in6->sin6_port = inp->inp_lport; + in6->sin6_flowinfo = inp->inp_flowinfo; + in6->sin6_addr = inp->inp_laddr6; in6->sin6_scope_id = 0; /* XXX? */ - if (pcb.ki_prstate >= IN6P_CONNECTED) { + if (pcb.ki_prstate >= INP_CONNECTED) { in6 = satosin6(&pcb.ki_dst); in6->sin6_len = sizeof(*in6); in6->sin6_family = pf; - in6->sin6_port = in6p->in6p_fport; - in6->sin6_flowinfo = in6p->in6p_flowinfo; - in6->sin6_addr = in6p->in6p_faddr; + in6->sin6_port = inp->inp_fport; + in6->sin6_flowinfo = inp->inp_flowinfo; + in6->sin6_addr = inp->inp_faddr6; in6->sin6_scope_id = 0; /* XXX? */ } break; diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 9671cc5ea44..827c7ced9e6 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -253,7 +253,6 @@ struct tcpcb { struct mbuf *t_template; /* skeletal packet for transmit */ struct inpcb *t_inpcb; /* back pointer to internet pcb */ - struct in6pcb *t_in6pcb; /* back pointer to internet pcb */ callout_t t_delack_ch; /* delayed ACK callout */ /* * The following fields are used as in the protocol specification. @@ -523,16 +522,7 @@ struct tcp_opt_info { #define TOF_SIGLEN 0x0080 /* sigature length valid (RFC2385) */ #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) -#ifdef INET6 -#define in6totcpcb(ip) ((struct tcpcb *)(ip)->in6p_ppcb) -#endif -#ifndef INET6 #define sototcpcb(so) (intotcpcb(sotoinpcb(so))) -#else -#define sototcpcb(so) (((so)->so_proto->pr_domain->dom_family == AF_INET) \ - ? intotcpcb(sotoinpcb(so)) \ - : in6totcpcb(sotoin6pcb(so))) -#endif /* * See RFC2988 for a discussion of RTO calculation; comments assume @@ -830,19 +820,13 @@ u_long tcp_mss_to_advertise(const struct ifnet *, int); void tcp_mss_from_peer(struct tcpcb *, int); void tcp_tcpcb_template(void); struct tcpcb * - tcp_newtcpcb(int, void *); + tcp_newtcpcb(int, struct inpcb *); void tcp_notify(struct inpcb *, int); -#ifdef INET6 -void tcp6_notify(struct in6pcb *, int); -#endif u_int tcp_optlen(struct tcpcb *); int tcp_output(struct tcpcb *); void tcp_pulloutofband(struct socket *, struct tcphdr *, struct mbuf *, int); void tcp_quench(struct inpcb *); -#ifdef INET6 -void tcp6_quench(struct in6pcb *); -#endif void tcp_mtudisc(struct inpcb *, int); #ifdef INET6 void tcp6_mtudisc_callback(struct in6_addr *); diff --git a/sys/netinet/tcp_vtw.c b/sys/netinet/tcp_vtw.c index b5490210f5a..173b7c07afa 100644 --- a/sys/netinet/tcp_vtw.c +++ b/sys/netinet/tcp_vtw.c @@ -1969,21 +1969,21 @@ vtw_add(int af, struct tcpcb *tp) } case AF_INET6: { - struct in6pcb *inp = tp->t_in6pcb; + struct inpcb *inp = tp->t_inpcb; vtw_v6_t *v6 = (void*)vtw; - v6->faddr = inp->in6p_faddr; - v6->laddr = inp->in6p_laddr; - v6->fport = inp->in6p_fport; - v6->lport = inp->in6p_lport; + v6->faddr = inp->inp_faddr6; + v6->laddr = inp->inp_laddr6; + v6->fport = inp->inp_fport; + v6->lport = inp->inp_lport; - vtw->reuse_port = !!(inp->in6p_socket->so_options + vtw->reuse_port = !!(inp->inp_socket->so_options & SO_REUSEPORT); - vtw->reuse_addr = !!(inp->in6p_socket->so_options + vtw->reuse_addr = !!(inp->inp_socket->so_options & SO_REUSEADDR); - vtw->v6only = !!(inp->in6p_flags + vtw->v6only = !!(inp->inp_flags & IN6P_IPV6_V6ONLY); - vtw->uid = inp->in6p_socket->so_uidinfo->ui_uid; + vtw->uid = inp->inp_socket->so_uidinfo->ui_uid; vtw_inshash_v6(ctl, vtw); #ifdef VTW_DEBUG @@ -1992,14 +1992,14 @@ vtw_add(int af, struct tcpcb *tp) */ if (enable & 4) { KASSERT(vtw_lookup_hash_v6(ctl - , &inp->in6p_faddr, inp->in6p_fport - , &inp->in6p_laddr, inp->in6p_lport + , &inp->inp_faddr6, inp->inp_fport + , &inp->inp_laddr6, inp->inp_lport , 0) == vtw); KASSERT(vtw_lookup_hash_v6 (ctl - , &inp->in6p_faddr, inp->in6p_fport - , &inp->in6p_laddr, inp->in6p_lport + , &inp->inp_faddr6, inp->inp_fport + , &inp->inp_laddr6, inp->inp_lport , 1)); } /* Immediate port iterator functionality check: not wild @@ -2009,8 +2009,8 @@ vtw_add(int af, struct tcpcb *tp) struct vestigial_inpcb res; int cnt = 0; - it = tcp_init_ports_v6(&inp->in6p_laddr - , inp->in6p_lport, 0); + it = tcp_init_ports_v6(&inp->inp_laddr6 + , inp->inp_lport, 0); while (tcp_next_port_v6(it, &res)) { ++cnt; @@ -2026,7 +2026,7 @@ vtw_add(int af, struct tcpcb *tp) int cnt = 0; it = tcp_init_ports_v6(&any - , inp->in6p_lport, 1); + , inp->inp_lport, 1); while (tcp_next_port_v6(it, &res)) { ++cnt; diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index d7f265b7bf7..7648f5c281b 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -488,7 +488,6 @@ udp4_realinput(struct sockaddr_in *src, struct sockaddr_in *dst, u_int16_t *sport, *dport; int rcvcnt; struct in_addr *src4, *dst4; - struct inpcb_hdr *inph; struct inpcb *inp; struct mbuf *m = *mp; @@ -528,8 +527,7 @@ udp4_realinput(struct sockaddr_in *src, struct sockaddr_in *dst, /* * Locate pcb(s) for datagram. */ - TAILQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { - inp = (struct inpcb *)inph; + TAILQ_FOREACH(inp, &udbtable.inpt_queue, inp_queue) { if (inp->inp_af != AF_INET) continue; diff --git a/sys/netinet6/dccp6_usrreq.c b/sys/netinet6/dccp6_usrreq.c index 5c6d800fd84..31775f0723a 100644 --- a/sys/netinet6/dccp6_usrreq.c +++ b/sys/netinet6/dccp6_usrreq.c @@ -114,30 +114,30 @@ dccp6_ctlinput(int cmd, const struct sockaddr *sa, void *d) int dccp6_bind(struct socket *so, struct sockaddr *nam, struct lwp *td) { - struct in6pcb *in6p; + struct inpcb *inp; int error; - struct sockaddr_in6 *sin6p = (struct sockaddr_in6 *)nam; + struct sockaddr_in6 *sinp = (struct sockaddr_in6 *)nam; DCCP_DEBUG((LOG_INFO, "Entering dccp6_bind!\n")); INP_INFO_WLOCK(&dccpbinfo); - in6p = sotoin6pcb(so); - if (in6p == 0) { + inp = sotoinpcb(so); + if (inp == 0) { INP_INFO_WUNLOCK(&dccpbinfo); - DCCP_DEBUG((LOG_INFO, "dccp6_bind: in6p == 0!\n")); + DCCP_DEBUG((LOG_INFO, "dccp6_bind: inp == 0!\n")); return EINVAL; } /* Do not bind to multicast addresses! */ - if (sin6p->sin6_family == AF_INET6 && - IN6_IS_ADDR_MULTICAST(&sin6p->sin6_addr)) { + if (sinp->sin6_family == AF_INET6 && + IN6_IS_ADDR_MULTICAST(&sinp->sin6_addr)) { INP_INFO_WUNLOCK(&dccpbinfo); return EAFNOSUPPORT; } INP_LOCK(inp); - in6todccpcb(in6p)->inp_vflag &= ~INP_IPV4; - in6todccpcb(in6p)->inp_vflag |= INP_IPV6; + intodccpcb(inp)->inp_vflag &= ~INP_IPV4; + intodccpcb(inp)->inp_vflag |= INP_IPV6; - error = in6_pcbbind(in6p, sin6p, td); + error = in6_pcbbind(inp, sinp, td); INP_UNLOCK(inp); INP_INFO_WUNLOCK(&dccpbinfo); return error; @@ -146,7 +146,7 @@ dccp6_bind(struct socket *so, struct sockaddr *nam, struct lwp *td) int dccp6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) { - struct in6pcb *in6p; + struct inpcb *inp; struct dccpcb *dp; int error; struct sockaddr_in6 *sin6; @@ -162,7 +162,7 @@ dccp6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) return EINVAL; } INP_LOCK(inp); - if (inp->inp_faddr.s_addr != INADDR_ANY) { + if (inp->inp_faddr6.s_addr != INADDR_ANY) { INP_UNLOCK(inp); INP_INFO_WUNLOCK(&dccpbinfo); return EISCONN; @@ -170,15 +170,15 @@ dccp6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) dp = (struct dccpcb *)inp->inp_ppcb; #else - in6p = sotoin6pcb(so); - if (in6p == 0) { + inp = sotoinpcb(so); + if (inp == 0) { return EINVAL; } - if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) { + if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) { return EISCONN; } - dp = (struct dccpcb *)in6p->in6p_ppcb; + dp = (struct dccpcb *)inp->inp_ppcb; #endif if (dp->state == DCCPS_ESTAB) { DCCP_DEBUG((LOG_INFO, "Why are we in connect when we already have a established connection?\n")); @@ -232,24 +232,24 @@ bad: int dccp6_listen(struct socket *so, struct lwp *l) { - struct in6pcb *in6p; + struct inpcb *inp; struct dccpcb *dp; int error = 0; DCCP_DEBUG((LOG_INFO, "Entering dccp6_listen!\n")); INP_INFO_RLOCK(&dccpbinfo); - in6p = sotoin6pcb(so); - if (in6p == 0) { + inp = sotoinpcb(so); + if (inp == 0) { INP_INFO_RUNLOCK(&dccpbinfo); return EINVAL; } INP_LOCK(inp); INP_INFO_RUNLOCK(&dccpbinfo); - dp = in6todccpcb(in6p); - DCCP_DEBUG((LOG_INFO, "Checking in6p->in6p_lport!\n")); - if (in6p->in6p_lport == 0) { - error = in6_pcbbind(in6p, NULL, l); + dp = intodccpcb(inp); + DCCP_DEBUG((LOG_INFO, "Checking inp->inp_lport!\n")); + if (inp->inp_lport == 0) { + error = in6_pcbbind(inp, NULL, l); } if (error == 0) { dp->state = DCCPS_LISTEN; @@ -263,7 +263,7 @@ dccp6_listen(struct socket *so, struct lwp *l) int dccp6_accept(struct socket *so, struct sockaddr *nam) { - struct in6pcb *in6p = NULL; + struct inpcb *inp = NULL; int error = 0; DCCP_DEBUG((LOG_INFO, "Entering dccp6_accept!\n")); @@ -276,14 +276,14 @@ dccp6_accept(struct socket *so, struct sockaddr *nam) } INP_INFO_RLOCK(&dccpbinfo); - in6p = sotoin6pcb(so); - if (in6p == 0) { + inp = sotoinpcb(so); + if (inp == 0) { INP_INFO_RUNLOCK(&dccpbinfo); return EINVAL; } INP_LOCK(inp); INP_INFO_RUNLOCK(&dccpbinfo); - in6_setpeeraddr(in6p, (struct sockaddr_in6 *)nam); + in6_setpeeraddr(inp, (struct sockaddr_in6 *)nam); INP_UNLOCK(inp); return error; @@ -380,7 +380,7 @@ dccp6_peeraddr(struct socket *so, struct sockaddr *nam) KASSERT(sotoinpcb(so) != NULL); KASSERT(nam != NULL); - in6_setpeeraddr(sotoin6pcb(so), (struct sockaddr_in6 *)nam); + in6_setpeeraddr(sotoinpcb(so), (struct sockaddr_in6 *)nam); return 0; } @@ -391,7 +391,7 @@ dccp6_sockaddr(struct socket *so, struct sockaddr *nam) KASSERT(sotoinpcb(so) != NULL); KASSERT(nam != NULL); - in6_setsockaddr(sotoin6pcb(so), (struct sockaddr_in6 *)nam); + in6_setsockaddr(sotoinpcb(so), (struct sockaddr_in6 *)nam); return 0; } diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index eec4a88aef4..42bdfb59cb9 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -90,6 +90,7 @@ __KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.252 2022/08/29 09:14:02 knakahara Exp $" #include #include +#include #include #include #include @@ -1939,9 +1940,8 @@ icmp6_rip6_input(struct mbuf **mp, int off) { struct mbuf *m = *mp; struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); - struct inpcb_hdr *inph; - struct in6pcb *in6p; - struct in6pcb *last = NULL; + struct inpcb *inp; + struct inpcb *last = NULL; struct sockaddr_in6 rip6src; struct icmp6_hdr *icmp6; struct mbuf *n, *opts = NULL; @@ -1962,21 +1962,20 @@ icmp6_rip6_input(struct mbuf **mp, int off) return IPPROTO_DONE; } - TAILQ_FOREACH(inph, &raw6cbtable.inpt_queue, inph_queue) { - in6p = (struct in6pcb *)inph; - if (in6p->in6p_af != AF_INET6) + TAILQ_FOREACH(inp, &raw6cbtable.inpt_queue, inp_queue) { + if (inp->inp_af != AF_INET6) continue; - if (in6p->in6p_ip6.ip6_nxt != IPPROTO_ICMPV6) + if (inp->inp_ip6.ip6_nxt != IPPROTO_ICMPV6) continue; - if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) && - !IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, &ip6->ip6_dst)) + if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) && + !IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &ip6->ip6_dst)) continue; - if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr) && - !IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr, &ip6->ip6_src)) + if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6) && + !IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, &ip6->ip6_src)) continue; - if (in6p->in6p_icmp6filt && + if (inp->inp_icmp6filt && ICMP6_FILTER_WILLBLOCK(icmp6->icmp6_type, - in6p->in6p_icmp6filt)) + inp->inp_icmp6filt)) continue; if (last == NULL) { @@ -1988,23 +1987,23 @@ icmp6_rip6_input(struct mbuf **mp, int off) } #endif else if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) { - if (last->in6p_flags & IN6P_CONTROLOPTS) + if (last->inp_flags & IN6P_CONTROLOPTS) ip6_savecontrol(last, &opts, ip6, n); /* strip intermediate headers */ m_adj(n, off); - if (sbappendaddr(&last->in6p_socket->so_rcv, + if (sbappendaddr(&last->inp_socket->so_rcv, sin6tosa(&rip6src), n, opts) == 0) { - soroverflow(last->in6p_socket); + soroverflow(last->inp_socket); m_freem(n); if (opts) m_freem(opts); } else { - sorwakeup(last->in6p_socket); + sorwakeup(last->inp_socket); } opts = NULL; } - last = in6p; + last = inp; } #ifdef IPSEC @@ -2015,18 +2014,18 @@ icmp6_rip6_input(struct mbuf **mp, int off) } else #endif if (last) { - if (last->in6p_flags & IN6P_CONTROLOPTS) + if (last->inp_flags & IN6P_CONTROLOPTS) ip6_savecontrol(last, &opts, ip6, m); /* strip intermediate headers */ m_adj(m, off); - if (sbappendaddr(&last->in6p_socket->so_rcv, + if (sbappendaddr(&last->inp_socket->so_rcv, sin6tosa(&rip6src), m, opts) == 0) { - soroverflow(last->in6p_socket); + soroverflow(last->inp_socket); m_freem(m); if (opts) m_freem(opts); } else { - sorwakeup(last->in6p_socket); + sorwakeup(last->inp_socket); } } else { m_freem(m); @@ -2741,7 +2740,7 @@ int icmp6_ctloutput(int op, struct socket *so, struct sockopt *sopt) { int error = 0; - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); if (sopt->sopt_level != IPPROTO_ICMPV6) return rip6_ctloutput(op, so, sopt); @@ -2756,7 +2755,7 @@ icmp6_ctloutput(int op, struct socket *so, struct sockopt *sopt) error = sockopt_get(sopt, &fil, sizeof(fil)); if (error) break; - memcpy(in6p->in6p_icmp6filt, &fil, + memcpy(inp->inp_icmp6filt, &fil, sizeof(struct icmp6_filter)); error = 0; break; @@ -2772,11 +2771,11 @@ icmp6_ctloutput(int op, struct socket *so, struct sockopt *sopt) switch (sopt->sopt_name) { case ICMP6_FILTER: { - if (in6p->in6p_icmp6filt == NULL) { + if (inp->inp_icmp6filt == NULL) { error = EINVAL; break; } - error = sockopt_set(sopt, in6p->in6p_icmp6filt, + error = sockopt_set(sopt, inp->inp_icmp6filt, sizeof(struct icmp6_filter)); break; } diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 53fbd5903d5..76264a3ade5 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -129,76 +129,19 @@ int ip6_anonportmax = IPV6PORT_ANONMAX; int ip6_lowportmin = IPV6PORT_RESERVEDMIN; int ip6_lowportmax = IPV6PORT_RESERVEDMAX; -static struct pool in6pcb_pool; - -static int -in6pcb_poolinit(void) -{ - - pool_init(&in6pcb_pool, sizeof(struct in6pcb), 0, 0, 0, "in6pcbpl", - NULL, IPL_SOFTNET); - return 0; -} - void in6_pcbinit(struct inpcbtable *table, int bindhashsize, int connecthashsize) { - static ONCE_DECL(control); in_pcbinit(table, bindhashsize, connecthashsize); table->inpt_lastport = (u_int16_t)ip6_anonportmax; - - RUN_ONCE(&control, in6pcb_poolinit); -} - -int -in6_pcballoc(struct socket *so, void *v) -{ - struct inpcbtable *table = v; - struct in6pcb *in6p; - int s; - - KASSERT(so->so_proto->pr_domain->dom_family == AF_INET6); - - in6p = pool_get(&in6pcb_pool, PR_NOWAIT); - if (in6p == NULL) - return (ENOBUFS); - memset((void *)in6p, 0, sizeof(*in6p)); - in6p->in6p_af = AF_INET6; - in6p->in6p_table = table; - in6p->in6p_socket = so; - in6p->in6p_hops = -1; /* use kernel default */ - in6p->in6p_icmp6filt = NULL; - in6p->in6p_portalgo = PORTALGO_DEFAULT; - in6p->in6p_bindportonsend = false; -#if defined(IPSEC) - if (ipsec_enabled) { - int error = ipsec_init_pcbpolicy(so, &in6p->in6p_sp); - if (error != 0) { - pool_put(&in6pcb_pool, in6p); - return error; - } - in6p->in6p_sp->sp_inph = (struct inpcb_hdr *)in6p; - } -#endif /* IPSEC */ - s = splsoftnet(); - TAILQ_INSERT_HEAD(&table->inpt_queue, (struct inpcb_hdr*)in6p, - inph_queue); - LIST_INSERT_HEAD(IN6PCBHASH_PORT(table, in6p->in6p_lport), - &in6p->in6p_head, inph_lhash); - in6_pcbstate(in6p, IN6P_ATTACHED); - splx(s); - if (ip6_v6only) - in6p->in6p_flags |= IN6P_IPV6_V6ONLY; - so->so_pcb = (void *)in6p; - return (0); } /* - * Bind address from sin6 to in6p. + * Bind address from sin6 to inp. */ static int -in6_pcbbind_addr(struct in6pcb *in6p, struct sockaddr_in6 *sin6, struct lwp *l) +in6_pcbbind_addr(struct inpcb *inp, struct sockaddr_in6 *sin6, struct lwp *l) { int error; int s; @@ -220,7 +163,7 @@ in6_pcbbind_addr(struct in6pcb *in6p, struct sockaddr_in6 *sin6, struct lwp *l) s = pserialize_read_enter(); if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { - if ((in6p->in6p_flags & IN6P_IPV6_V6ONLY) != 0) { + if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) { error = EINVAL; goto out; } @@ -236,7 +179,7 @@ in6_pcbbind_addr(struct in6pcb *in6p, struct sockaddr_in6 *sin6, struct lwp *l) struct ifaddr *ifa; ifa = ifa_ifwithaddr((struct sockaddr *)&sin); if (ifa == NULL && - (in6p->in6p_flags & IN6P_BINDANY) == 0) { + (inp->inp_flags & IN6P_BINDANY) == 0) { error = EADDRNOTAVAIL; goto out; } @@ -247,10 +190,10 @@ in6_pcbbind_addr(struct in6pcb *in6p, struct sockaddr_in6 *sin6, struct lwp *l) } else if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { struct ifaddr *ifa = NULL; - if ((in6p->in6p_flags & IN6P_FAITH) == 0) { + if ((inp->inp_flags & IN6P_FAITH) == 0) { ifa = ifa_ifwithaddr(sin6tosa(sin6)); if (ifa == NULL && - (in6p->in6p_flags & IN6P_BINDANY) == 0) { + (inp->inp_flags & IN6P_BINDANY) == 0) { error = EADDRNOTAVAIL; goto out; } @@ -276,7 +219,7 @@ in6_pcbbind_addr(struct in6pcb *in6p, struct sockaddr_in6 *sin6, struct lwp *l) goto out; } } - in6p->in6p_laddr = sin6->sin6_addr; + inp->inp_laddr6 = sin6->sin6_addr; error = 0; out: pserialize_read_exit(s); @@ -284,13 +227,13 @@ out: } /* - * Bind port from sin6 to in6p. + * Bind port from sin6 to inp. */ static int -in6_pcbbind_port(struct in6pcb *in6p, struct sockaddr_in6 *sin6, struct lwp *l) +in6_pcbbind_port(struct inpcb *inp, struct sockaddr_in6 *sin6, struct lwp *l) { - struct inpcbtable *table = in6p->in6p_table; - struct socket *so = in6p->in6p_socket; + struct inpcbtable *table = inp->inp_table; + struct socket *so = inp->inp_socket; int wild = 0, reuseport = (so->so_options & SO_REUSEPORT); int error; @@ -348,12 +291,12 @@ in6_pcbbind_port(struct in6pcb *in6p, struct sockaddr_in6 *sin6, struct lwp *l) } { - struct in6pcb *t; + struct inpcb *t; struct vestigial_inpcb vestige; t = in6_pcblookup_port(table, &sin6->sin6_addr, sin6->sin6_port, wild, &vestige); - if (t && (reuseport & t->in6p_socket->so_options) == 0) + if (t && (reuseport & t->inp_socket->so_options) == 0) return (EADDRINUSE); if (!t && vestige.valid @@ -364,17 +307,17 @@ in6_pcbbind_port(struct in6pcb *in6p, struct sockaddr_in6 *sin6, struct lwp *l) if (sin6->sin6_port == 0) { int e; - e = in6_pcbsetport(sin6, in6p, l); + e = in6_pcbsetport(sin6, inp, l); if (e != 0) return (e); } else { - in6p->in6p_lport = sin6->sin6_port; - in6_pcbstate(in6p, IN6P_BOUND); + inp->inp_lport = sin6->sin6_port; + in_pcbstate(inp, INP_BOUND); } - LIST_REMOVE(&in6p->in6p_head, inph_lhash); - LIST_INSERT_HEAD(IN6PCBHASH_PORT(table, in6p->in6p_lport), - &in6p->in6p_head, inph_lhash); + LIST_REMOVE(inp, inp_lhash); + LIST_INSERT_HEAD(IN6PCBHASH_PORT(table, inp->inp_lport), + inp, inp_lhash); return (0); } @@ -382,20 +325,20 @@ in6_pcbbind_port(struct in6pcb *in6p, struct sockaddr_in6 *sin6, struct lwp *l) int in6_pcbbind(void *v, struct sockaddr_in6 *sin6, struct lwp *l) { - struct in6pcb *in6p = v; + struct inpcb *inp = v; struct sockaddr_in6 lsin6; int error; - if (in6p->in6p_af != AF_INET6) + if (inp->inp_af != AF_INET6) return (EINVAL); /* * If we already have a local port or a local address it means we're * bounded. */ - if (in6p->in6p_lport || !(IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) || - (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr) && - in6p->in6p_laddr.s6_addr32[3] == 0))) + if (inp->inp_lport || !(IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) || + (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6) && + inp->inp_laddr6.s6_addr32[3] == 0))) return (EINVAL); if (NULL != sin6) { @@ -405,30 +348,30 @@ in6_pcbbind(void *v, struct sockaddr_in6 *sin6, struct lwp *l) } else { /* We always bind to *something*, even if it's "anything". */ lsin6 = *((const struct sockaddr_in6 *) - in6p->in6p_socket->so_proto->pr_domain->dom_sa_any); + inp->inp_socket->so_proto->pr_domain->dom_sa_any); sin6 = &lsin6; } /* Bind address. */ - error = in6_pcbbind_addr(in6p, sin6, l); + error = in6_pcbbind_addr(inp, sin6, l); if (error) return (error); /* Bind port. */ - error = in6_pcbbind_port(in6p, sin6, l); + error = in6_pcbbind_port(inp, sin6, l); if (error) { /* * Reset the address here to "any" so we don't "leak" the - * in6pcb. + * inpcb. */ - in6p->in6p_laddr = in6addr_any; + inp->inp_laddr6 = in6addr_any; return (error); } #if 0 - in6p->in6p_flowinfo = 0; /* XXX */ + inp->inp_flowinfo = 0; /* XXX */ #endif return (0); } @@ -442,7 +385,7 @@ in6_pcbbind(void *v, struct sockaddr_in6 *sin6, struct lwp *l) int in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) { - struct in6pcb *in6p = v; + struct inpcb *inp = v; struct in6_addr *in6a = NULL; struct in6_addr ia6; struct ifnet *ifp = NULL; /* outgoing interface */ @@ -458,7 +401,7 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) (void)&in6a; /* XXX fool gcc */ - if (in6p->in6p_af != AF_INET6) + if (inp->inp_af != AF_INET6) return (EINVAL); if (sin6->sin6_len != sizeof(*sin6)) @@ -469,7 +412,7 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) return (EADDRNOTAVAIL); if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr) && - in6p->in6p_socket->so_type == SOCK_STREAM) + inp->inp_socket->so_type == SOCK_STREAM) return EADDRNOTAVAIL; if (sin6->sin6_scope_id == 0 && !ip6_use_defzone) @@ -479,15 +422,15 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) /* sanity check for mapped address case */ if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { - if ((in6p->in6p_flags & IN6P_IPV6_V6ONLY) != 0) + if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) return EINVAL; - if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) - in6p->in6p_laddr.s6_addr16[5] = htons(0xffff); - if (!IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr)) + if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) + inp->inp_laddr6.s6_addr16[5] = htons(0xffff); + if (!IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)) return EINVAL; } else { - if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr)) + if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)) return EINVAL; } @@ -497,8 +440,8 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) bound = curlwp_bind(); /* Source address selection. */ - if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr) && - in6p->in6p_laddr.s6_addr32[3] == 0) { + if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6) && + inp->inp_laddr6.s6_addr32[3] == 0) { #ifdef INET struct sockaddr_in sin; struct in_ifaddr *ia4; @@ -509,8 +452,8 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) sin.sin_family = AF_INET; memcpy(&sin.sin_addr, &sin6->sin6_addr.s6_addr32[3], sizeof(sin.sin_addr)); - ia4 = in_selectsrc(&sin, &in6p->in6p_route, - in6p->in6p_socket->so_options, NULL, &error, &_psref); + ia4 = in_selectsrc(&sin, &inp->inp_route, + inp->inp_socket->so_options, NULL, &error, &_psref); if (ia4 == NULL) { if (error == 0) error = EADDRNOTAVAIL; @@ -533,8 +476,8 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) * with the address specified by setsockopt(IPV6_PKTINFO). * Is it the intended behavior? */ - error = in6_selectsrc(sin6, in6p->in6p_outputopts, - in6p->in6p_moptions, &in6p->in6p_route, &in6p->in6p_laddr, + error = in6_selectsrc(sin6, inp->inp_outputopts6, + inp->inp_moptions6, &inp->inp_route, &inp->inp_laddr6, &ifp, &psref, &ia6); if (error == 0) in6a = &ia6; @@ -555,127 +498,89 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) } if (ifp != NULL) { - in6p->in6p_ip6.ip6_hlim = (u_int8_t)in6_selecthlim(in6p, ifp); + inp->inp_ip6.ip6_hlim = (u_int8_t)in6_selecthlim(inp, ifp); if_put(ifp, &psref); } else - in6p->in6p_ip6.ip6_hlim = (u_int8_t)in6_selecthlim_rt(in6p); + inp->inp_ip6.ip6_hlim = (u_int8_t)in6_selecthlim_rt(inp); curlwp_bindx(bound); - if (in6_pcblookup_connect(in6p->in6p_table, &sin6->sin6_addr, + if (in6_pcblookup_connect(inp->inp_table, &sin6->sin6_addr, sin6->sin6_port, - IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) ? in6a : &in6p->in6p_laddr, - in6p->in6p_lport, 0, &vestige) + IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) ? in6a : &inp->inp_laddr6, + inp->inp_lport, 0, &vestige) || vestige.valid) return (EADDRINUSE); - if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) || - (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr) && - in6p->in6p_laddr.s6_addr32[3] == 0)) + if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) || + (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6) && + inp->inp_laddr6.s6_addr32[3] == 0)) { - if (in6p->in6p_lport == 0) { - error = in6_pcbbind(in6p, NULL, l); + if (inp->inp_lport == 0) { + error = in6_pcbbind(inp, NULL, l); if (error != 0) return error; } - in6p->in6p_laddr = *in6a; + inp->inp_laddr6 = *in6a; } - in6p->in6p_faddr = sin6->sin6_addr; - in6p->in6p_fport = sin6->sin6_port; + inp->inp_faddr6 = sin6->sin6_addr; + inp->inp_fport = sin6->sin6_port; /* Late bind, if needed */ - if (in6p->in6p_bindportonsend) { + if (inp->inp_bindportonsend) { struct sockaddr_in6 lsin = *((const struct sockaddr_in6 *) - in6p->in6p_socket->so_proto->pr_domain->dom_sa_any); - lsin.sin6_addr = in6p->in6p_laddr; + inp->inp_socket->so_proto->pr_domain->dom_sa_any); + lsin.sin6_addr = inp->inp_laddr6; lsin.sin6_port = 0; - if ((error = in6_pcbbind_port(in6p, &lsin, l)) != 0) + if ((error = in6_pcbbind_port(inp, &lsin, l)) != 0) return error; } - in6_pcbstate(in6p, IN6P_CONNECTED); - in6p->in6p_flowinfo &= ~IPV6_FLOWLABEL_MASK; + in_pcbstate(inp, INP_CONNECTED); + inp->inp_flowinfo &= ~IPV6_FLOWLABEL_MASK; if (ip6_auto_flowlabel) - in6p->in6p_flowinfo |= + inp->inp_flowinfo |= (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK); #if defined(IPSEC) - if (ipsec_enabled && in6p->in6p_socket->so_type == SOCK_STREAM) - ipsec_pcbconn(in6p->in6p_sp); + if (ipsec_enabled && inp->inp_socket->so_type == SOCK_STREAM) + ipsec_pcbconn(inp->inp_sp); #endif return (0); } void -in6_pcbdisconnect(struct in6pcb *in6p) +in6_pcbdisconnect(struct inpcb *inp) { - memset((void *)&in6p->in6p_faddr, 0, sizeof(in6p->in6p_faddr)); - in6p->in6p_fport = 0; - in6_pcbstate(in6p, IN6P_BOUND); - in6p->in6p_flowinfo &= ~IPV6_FLOWLABEL_MASK; + memset((void *)&inp->inp_faddr6, 0, sizeof(inp->inp_faddr6)); + inp->inp_fport = 0; + in_pcbstate(inp, INP_BOUND); + inp->inp_flowinfo &= ~IPV6_FLOWLABEL_MASK; #if defined(IPSEC) if (ipsec_enabled) - ipsec_pcbdisconn(in6p->in6p_sp); + ipsec_pcbdisconn(inp->inp_sp); #endif - if (in6p->in6p_socket->so_state & SS_NOFDREF) - in6_pcbdetach(in6p); + if (inp->inp_socket->so_state & SS_NOFDREF) + in_pcbdetach(inp); } void -in6_pcbdetach(struct in6pcb *in6p) +in6_setsockaddr(struct inpcb *inp, struct sockaddr_in6 *sin6) { - struct socket *so = in6p->in6p_socket; - int s; - if (in6p->in6p_af != AF_INET6) + if (inp->inp_af != AF_INET6) return; -#if defined(IPSEC) - if (ipsec_enabled) - ipsec_delete_pcbpolicy(in6p); -#endif - so->so_pcb = NULL; - - s = splsoftnet(); - in6_pcbstate(in6p, IN6P_ATTACHED); - LIST_REMOVE(&in6p->in6p_head, inph_lhash); - TAILQ_REMOVE(&in6p->in6p_table->inpt_queue, &in6p->in6p_head, - inph_queue); - splx(s); - - if (in6p->in6p_options) { - m_freem(in6p->in6p_options); - } - if (in6p->in6p_outputopts != NULL) { - ip6_clearpktopts(in6p->in6p_outputopts, -1); - free(in6p->in6p_outputopts, M_IP6OPT); - } - rtcache_free(&in6p->in6p_route); - ip6_freemoptions(in6p->in6p_moptions); - ip_freemoptions(in6p->in6p_v4moptions); - sofree(so); /* drops the socket's lock */ - - pool_put(&in6pcb_pool, in6p); - mutex_enter(softnet_lock); /* reacquire it */ -} - -void -in6_setsockaddr(struct in6pcb *in6p, struct sockaddr_in6 *sin6) -{ - - if (in6p->in6p_af != AF_INET6) - return; - - sockaddr_in6_init(sin6, &in6p->in6p_laddr, in6p->in6p_lport, 0, 0); + sockaddr_in6_init(sin6, &inp->inp_laddr6, inp->inp_lport, 0, 0); (void)sa6_recoverscope(sin6); /* XXX: should catch errors */ } void -in6_setpeeraddr(struct in6pcb *in6p, struct sockaddr_in6 *sin6) +in6_setpeeraddr(struct inpcb *inp, struct sockaddr_in6 *sin6) { - if (in6p->in6p_af != AF_INET6) + if (inp->inp_af != AF_INET6) return; - sockaddr_in6_init(sin6, &in6p->in6p_faddr, in6p->in6p_fport, 0, 0); + sockaddr_in6_init(sin6, &inp->inp_faddr6, inp->inp_fport, 0, 0); (void)sa6_recoverscope(sin6); /* XXX: should catch errors */ } @@ -696,9 +601,9 @@ in6_setpeeraddr(struct in6pcb *in6p, struct sockaddr_in6 *sin6) int in6_pcbnotify(struct inpcbtable *table, const struct sockaddr *dst, u_int fport_arg, const struct sockaddr *src, u_int lport_arg, int cmd, - void *cmdarg, void (*notify)(struct in6pcb *, int)) + void *cmdarg, void (*notify)(struct inpcb *, int)) { - struct inpcb_hdr *inph; + struct inpcb *inp; struct sockaddr_in6 sa6_src; const struct sockaddr_in6 *sa6_dst; u_int16_t fport = fport_arg, lport = lport_arg; @@ -737,11 +642,10 @@ in6_pcbnotify(struct inpcbtable *table, const struct sockaddr *dst, } errno = inet6ctlerrmap[cmd]; - TAILQ_FOREACH(inph, &table->inpt_queue, inph_queue) { - struct in6pcb *in6p = (struct in6pcb *)inph; + TAILQ_FOREACH(inp, &table->inpt_queue, inp_queue) { struct rtentry *rt = NULL; - if (in6p->in6p_af != AF_INET6) + if (inp->inp_af != AF_INET6) continue; /* @@ -776,22 +680,22 @@ in6_pcbnotify(struct inpcbtable *table, const struct sockaddr *dst, * icmp6_mtudisc_update(). */ if ((PRC_IS_REDIRECT(cmd) || cmd == PRC_HOSTDEAD) && - IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) && - (rt = rtcache_validate(&in6p->in6p_route)) != NULL && + IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) && + (rt = rtcache_validate(&inp->inp_route)) != NULL && !(rt->rt_flags & RTF_HOST)) { const struct sockaddr_in6 *dst6; dst6 = (const struct sockaddr_in6 *) - rtcache_getdst(&in6p->in6p_route); + rtcache_getdst(&inp->inp_route); if (dst6 == NULL) ; else if (IN6_ARE_ADDR_EQUAL(&dst6->sin6_addr, &sa6_dst->sin6_addr)) { - rtcache_unref(rt, &in6p->in6p_route); + rtcache_unref(rt, &inp->inp_route); goto do_notify; } } - rtcache_unref(rt, &in6p->in6p_route); + rtcache_unref(rt, &inp->inp_route); /* * If the error designates a new path MTU for a destination @@ -802,10 +706,10 @@ in6_pcbnotify(struct inpcbtable *table, const struct sockaddr *dst, * sockets disconnected. * XXX: should we avoid to notify the value to TCP sockets? */ - if (cmd == PRC_MSGSIZE && (in6p->in6p_flags & IN6P_MTU) != 0 && - (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr) || - IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr, &sa6_dst->sin6_addr))) { - ip6_notify_pmtu(in6p, (const struct sockaddr_in6 *)dst, + if (cmd == PRC_MSGSIZE && (inp->inp_flags & IN6P_MTU) != 0 && + (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6) || + IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, &sa6_dst->sin6_addr))) { + ip6_notify_pmtu(inp, (const struct sockaddr_in6 *)dst, (u_int32_t *)cmdarg); } @@ -818,23 +722,23 @@ in6_pcbnotify(struct inpcbtable *table, const struct sockaddr *dst, * as usual. */ if (lport == 0 && fport == 0 && flowinfo && - in6p->in6p_socket != NULL && - flowinfo == (in6p->in6p_flowinfo & IPV6_FLOWLABEL_MASK) && - IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, &sa6_src.sin6_addr)) + inp->inp_socket != NULL && + flowinfo == (inp->inp_flowinfo & IPV6_FLOWLABEL_MASK) && + IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &sa6_src.sin6_addr)) goto do_notify; - else if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr, + else if (!IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, &sa6_dst->sin6_addr) || - in6p->in6p_socket == NULL || - (lport && in6p->in6p_lport != lport) || + inp->inp_socket == NULL || + (lport && inp->inp_lport != lport) || (!IN6_IS_ADDR_UNSPECIFIED(&sa6_src.sin6_addr) && - !IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, + !IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &sa6_src.sin6_addr)) || - (fport && in6p->in6p_fport != fport)) + (fport && inp->inp_fport != fport)) continue; do_notify: if (notify) - (*notify)(in6p, errno); + (*notify)(inp, errno); nmatch++; } return nmatch; @@ -843,24 +747,23 @@ in6_pcbnotify(struct inpcbtable *table, const struct sockaddr *dst, void in6_pcbpurgeif0(struct inpcbtable *table, struct ifnet *ifp) { - struct inpcb_hdr *inph; + struct inpcb *inp; struct ip6_moptions *im6o; struct in6_multi_mship *imm, *nimm; KASSERT(ifp != NULL); - TAILQ_FOREACH(inph, &table->inpt_queue, inph_queue) { - struct in6pcb *in6p = (struct in6pcb *)inph; + TAILQ_FOREACH(inp, &table->inpt_queue, inp_queue) { bool need_unlock = false; - if (in6p->in6p_af != AF_INET6) + if (inp->inp_af != AF_INET6) continue; - /* The caller holds either one of in6ps' lock */ - if (!in6p_locked(in6p)) { - in6p_lock(in6p); + /* The caller holds either one of inps' lock */ + if (!inp_locked(inp)) { + inp_lock(inp); need_unlock = true; } - im6o = in6p->in6p_moptions; + im6o = inp->inp_moptions6; if (im6o) { /* * Unselect the outgoing interface if it is being @@ -884,10 +787,10 @@ in6_pcbpurgeif0(struct inpcbtable *table, struct ifnet *ifp) } } - in_purgeifmcast(in6p->in6p_v4moptions, ifp); + in_purgeifmcast(inp->inp_moptions, ifp); if (need_unlock) - in6p_unlock(in6p); + inp_unlock(inp); } } @@ -895,88 +798,43 @@ void in6_pcbpurgeif(struct inpcbtable *table, struct ifnet *ifp) { struct rtentry *rt; - struct inpcb_hdr *inph; + struct inpcb *inp; - TAILQ_FOREACH(inph, &table->inpt_queue, inph_queue) { - struct in6pcb *in6p = (struct in6pcb *)inph; - if (in6p->in6p_af != AF_INET6) + TAILQ_FOREACH(inp, &table->inpt_queue, inp_queue) { + if (inp->inp_af != AF_INET6) continue; - if ((rt = rtcache_validate(&in6p->in6p_route)) != NULL && + if ((rt = rtcache_validate(&inp->inp_route)) != NULL && rt->rt_ifp == ifp) { - rtcache_unref(rt, &in6p->in6p_route); - in6_rtchange(in6p, 0); + rtcache_unref(rt, &inp->inp_route); + in6_rtchange(inp, 0); } else - rtcache_unref(rt, &in6p->in6p_route); + rtcache_unref(rt, &inp->inp_route); } } -/* - * Check for alternatives when higher level complains - * about service problems. For now, invalidate cached - * routing information. If the route was created dynamically - * (by a redirect), time to try a default gateway again. - */ -void -in6_losing(struct in6pcb *in6p) -{ - struct rtentry *rt; - struct rt_addrinfo info; - - if (in6p->in6p_af != AF_INET6) - return; - - if ((rt = rtcache_validate(&in6p->in6p_route)) == NULL) - return; - - memset(&info, 0, sizeof(info)); - info.rti_info[RTAX_DST] = rtcache_getdst(&in6p->in6p_route); - info.rti_info[RTAX_GATEWAY] = rt->rt_gateway; - info.rti_info[RTAX_NETMASK] = rt_mask(rt); - rt_missmsg(RTM_LOSING, &info, rt->rt_flags, 0); - if (rt->rt_flags & RTF_DYNAMIC) { - int error; - struct rtentry *nrt; - - error = rtrequest(RTM_DELETE, rt_getkey(rt), - rt->rt_gateway, rt_mask(rt), rt->rt_flags, &nrt); - rtcache_unref(rt, &in6p->in6p_route); - if (error == 0) { - rt_newmsg_dynamic(RTM_DELETE, nrt); - rt_free(nrt); - } - } else - rtcache_unref(rt, &in6p->in6p_route); - /* - * A new route can be allocated - * the next time output is attempted. - */ - rtcache_free(&in6p->in6p_route); -} - /* * After a routing change, flush old routing. A new route can be * allocated the next time output is attempted. */ void -in6_rtchange(struct in6pcb *in6p, int errno) +in6_rtchange(struct inpcb *inp, int errno) { - if (in6p->in6p_af != AF_INET6) + if (inp->inp_af != AF_INET6) return; - rtcache_free(&in6p->in6p_route); + rtcache_free(&inp->inp_route); /* * A new route can be allocated the next time * output is attempted. */ } -struct in6pcb * +struct inpcb * in6_pcblookup_port(struct inpcbtable *table, struct in6_addr *laddr6, u_int lport_arg, int lookup_wildcard, struct vestigial_inpcb *vp) { struct inpcbhead *head; - struct inpcb_hdr *inph; - struct in6pcb *in6p, *match = NULL; + struct inpcb *inp, *match = NULL; int matchwild = 3, wildcard; u_int16_t lport = lport_arg; @@ -984,59 +842,58 @@ in6_pcblookup_port(struct inpcbtable *table, struct in6_addr *laddr6, vp->valid = 0; head = IN6PCBHASH_PORT(table, lport); - LIST_FOREACH(inph, head, inph_lhash) { - in6p = (struct in6pcb *)inph; - if (in6p->in6p_af != AF_INET6) + LIST_FOREACH(inp, head, inp_lhash) { + if (inp->inp_af != AF_INET6) continue; - if (in6p->in6p_lport != lport) + if (inp->inp_lport != lport) continue; wildcard = 0; - if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_faddr)) { - if ((in6p->in6p_flags & IN6P_IPV6_V6ONLY) != 0) + if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) { + if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; } - if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) + if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) wildcard++; - if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr)) { - if ((in6p->in6p_flags & IN6P_IPV6_V6ONLY) != 0) + if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)) { + if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; if (!IN6_IS_ADDR_V4MAPPED(laddr6)) continue; /* duplicate of IPv4 logic */ wildcard = 0; - if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_faddr) && - in6p->in6p_faddr.s6_addr32[3]) + if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6) && + inp->inp_faddr6.s6_addr32[3]) wildcard++; - if (!in6p->in6p_laddr.s6_addr32[3]) { + if (!inp->inp_laddr6.s6_addr32[3]) { if (laddr6->s6_addr32[3]) wildcard++; } else { if (!laddr6->s6_addr32[3]) wildcard++; else { - if (in6p->in6p_laddr.s6_addr32[3] != + if (inp->inp_laddr6.s6_addr32[3] != laddr6->s6_addr32[3]) continue; } } - } else if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) { + } else if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) { if (IN6_IS_ADDR_V4MAPPED(laddr6)) { - if ((in6p->in6p_flags & IN6P_IPV6_V6ONLY) != 0) + if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; } if (!IN6_IS_ADDR_UNSPECIFIED(laddr6)) wildcard++; } else { if (IN6_IS_ADDR_V4MAPPED(laddr6)) { - if ((in6p->in6p_flags & IN6P_IPV6_V6ONLY) != 0) + if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; } if (IN6_IS_ADDR_UNSPECIFIED(laddr6)) wildcard++; else { - if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, + if (!IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, laddr6)) continue; } @@ -1044,7 +901,7 @@ in6_pcblookup_port(struct inpcbtable *table, struct in6_addr *laddr6, if (wildcard && !lookup_wildcard) continue; if (wildcard < matchwild) { - match = in6p; + match = inp; matchwild = wildcard; if (matchwild == 0) break; @@ -1105,11 +962,11 @@ in6_pcblookup_port(struct inpcbtable *table, struct in6_addr *laddr6, } /* - * WARNING: return value (rtentry) could be IPv4 one if in6pcb is connected to + * WARNING: return value (rtentry) could be IPv4 one if inpcb is connected to * IPv4 mapped address. */ struct rtentry * -in6_pcbrtentry(struct in6pcb *in6p) +in6_pcbrtentry(struct inpcb *inp) { struct rtentry *rt; struct route *ro; @@ -1121,9 +978,9 @@ in6_pcbrtentry(struct in6pcb *in6p) #endif } cdst; - ro = &in6p->in6p_route; + ro = &inp->inp_route; - if (in6p->in6p_af != AF_INET6) + if (inp->inp_af != AF_INET6) return (NULL); cdst.sa = rtcache_getdst(ro); @@ -1131,27 +988,27 @@ in6_pcbrtentry(struct in6pcb *in6p) ; #ifdef INET else if (cdst.sa->sa_family == AF_INET) { - KASSERT(IN6_IS_ADDR_V4MAPPED(&in6p->in6p_faddr)); - if (cdst.sa4->sin_addr.s_addr != in6p->in6p_faddr.s6_addr32[3]) + KASSERT(IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)); + if (cdst.sa4->sin_addr.s_addr != inp->inp_faddr6.s6_addr32[3]) rtcache_free(ro); } #endif else { if (!IN6_ARE_ADDR_EQUAL(&cdst.sa6->sin6_addr, - &in6p->in6p_faddr)) + &inp->inp_faddr6)) rtcache_free(ro); } if ((rt = rtcache_validate(ro)) == NULL) rt = rtcache_update(ro, 1); #ifdef INET - if (rt == NULL && IN6_IS_ADDR_V4MAPPED(&in6p->in6p_faddr)) { + if (rt == NULL && IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) { union { struct sockaddr dst; struct sockaddr_in dst4; } u; struct in_addr addr; - addr.s_addr = in6p->in6p_faddr.s6_addr32[3]; + addr.s_addr = inp->inp_faddr6.s6_addr32[3]; sockaddr_in_init(&u.dst4, &addr, 0); if (rtcache_setdst(ro, &u.dst) != 0) @@ -1160,13 +1017,13 @@ in6_pcbrtentry(struct in6pcb *in6p) rt = rtcache_init(ro); } else #endif - if (rt == NULL && !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) { + if (rt == NULL && !IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) { union { struct sockaddr dst; struct sockaddr_in6 dst6; } u; - sockaddr_in6_init(&u.dst6, &in6p->in6p_faddr, 0, 0, 0); + sockaddr_in6_init(&u.dst6, &inp->inp_faddr6, 0, 0, 0); if (rtcache_setdst(ro, &u.dst) != 0) return NULL; @@ -1176,50 +1033,48 @@ in6_pcbrtentry(struct in6pcb *in6p) } void -in6_pcbrtentry_unref(struct rtentry *rt, struct in6pcb *in6p) +in6_pcbrtentry_unref(struct rtentry *rt, struct inpcb *inp) { - rtcache_unref(rt, &in6p->in6p_route); + rtcache_unref(rt, &inp->inp_route); } -struct in6pcb * +struct inpcb * in6_pcblookup_connect(struct inpcbtable *table, const struct in6_addr *faddr6, u_int fport_arg, const struct in6_addr *laddr6, u_int lport_arg, int faith, struct vestigial_inpcb *vp) { struct inpcbhead *head; - struct inpcb_hdr *inph; - struct in6pcb *in6p; + struct inpcb *inp; u_int16_t fport = fport_arg, lport = lport_arg; if (vp) vp->valid = 0; head = IN6PCBHASH_CONNECT(table, faddr6, fport, laddr6, lport); - LIST_FOREACH(inph, head, inph_hash) { - in6p = (struct in6pcb *)inph; - if (in6p->in6p_af != AF_INET6) + LIST_FOREACH(inp, head, inp_hash) { + if (inp->inp_af != AF_INET6) continue; /* find exact match on both source and dest */ - if (in6p->in6p_fport != fport) + if (inp->inp_fport != fport) continue; - if (in6p->in6p_lport != lport) + if (inp->inp_lport != lport) continue; - if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) + if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) continue; - if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr, faddr6)) + if (!IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, faddr6)) continue; - if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) + if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) continue; - if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, laddr6)) + if (!IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, laddr6)) continue; if ((IN6_IS_ADDR_V4MAPPED(laddr6) || IN6_IS_ADDR_V4MAPPED(faddr6)) && - (in6p->in6p_flags & IN6P_IPV6_V6ONLY)) + (inp->inp_flags & IN6P_IPV6_V6ONLY)) continue; - return in6p; + return inp; } if (vp && table->vestige) { if ((*table->vestige->lookup6)(faddr6, fport_arg, @@ -1230,34 +1085,32 @@ in6_pcblookup_connect(struct inpcbtable *table, const struct in6_addr *faddr6, return NULL; } -struct in6pcb * +struct inpcb * in6_pcblookup_bind(struct inpcbtable *table, const struct in6_addr *laddr6, u_int lport_arg, int faith) { struct inpcbhead *head; - struct inpcb_hdr *inph; - struct in6pcb *in6p; + struct inpcb *inp; u_int16_t lport = lport_arg; #ifdef INET struct in6_addr zero_mapped; #endif head = IN6PCBHASH_BIND(table, laddr6, lport); - LIST_FOREACH(inph, head, inph_hash) { - in6p = (struct in6pcb *)inph; - if (in6p->in6p_af != AF_INET6) + LIST_FOREACH(inp, head, inp_hash) { + if (inp->inp_af != AF_INET6) continue; - if (faith && (in6p->in6p_flags & IN6P_FAITH) == 0) + if (faith && (inp->inp_flags & IN6P_FAITH) == 0) continue; - if (in6p->in6p_fport != 0) + if (inp->inp_fport != 0) continue; - if (in6p->in6p_lport != lport) + if (inp->inp_lport != lport) continue; if (IN6_IS_ADDR_V4MAPPED(laddr6) && - (in6p->in6p_flags & IN6P_IPV6_V6ONLY) != 0) + (inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; - if (IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, laddr6)) + if (IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, laddr6)) goto out; } #ifdef INET @@ -1265,76 +1118,73 @@ in6_pcblookup_bind(struct inpcbtable *table, const struct in6_addr *laddr6, memset(&zero_mapped, 0, sizeof(zero_mapped)); zero_mapped.s6_addr16[5] = 0xffff; head = IN6PCBHASH_BIND(table, &zero_mapped, lport); - LIST_FOREACH(inph, head, inph_hash) { - in6p = (struct in6pcb *)inph; - if (in6p->in6p_af != AF_INET6) + LIST_FOREACH(inp, head, inp_hash) { + if (inp->inp_af != AF_INET6) continue; - if (faith && (in6p->in6p_flags & IN6P_FAITH) == 0) + if (faith && (inp->inp_flags & IN6P_FAITH) == 0) continue; - if (in6p->in6p_fport != 0) + if (inp->inp_fport != 0) continue; - if (in6p->in6p_lport != lport) + if (inp->inp_lport != lport) continue; - if ((in6p->in6p_flags & IN6P_IPV6_V6ONLY) != 0) + if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; - if (IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, &zero_mapped)) + if (IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &zero_mapped)) goto out; } } #endif head = IN6PCBHASH_BIND(table, &zeroin6_addr, lport); - LIST_FOREACH(inph, head, inph_hash) { - in6p = (struct in6pcb *)inph; - if (in6p->in6p_af != AF_INET6) + LIST_FOREACH(inp, head, inp_hash) { + if (inp->inp_af != AF_INET6) continue; - if (faith && (in6p->in6p_flags & IN6P_FAITH) == 0) + if (faith && (inp->inp_flags & IN6P_FAITH) == 0) continue; - if (in6p->in6p_fport != 0) + if (inp->inp_fport != 0) continue; - if (in6p->in6p_lport != lport) + if (inp->inp_lport != lport) continue; if (IN6_IS_ADDR_V4MAPPED(laddr6) && - (in6p->in6p_flags & IN6P_IPV6_V6ONLY) != 0) + (inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; - if (IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, &zeroin6_addr)) + if (IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &zeroin6_addr)) goto out; } return (NULL); out: - inph = &in6p->in6p_head; - if (inph != LIST_FIRST(head)) { - LIST_REMOVE(inph, inph_hash); - LIST_INSERT_HEAD(head, inph, inph_hash); + if (inp != LIST_FIRST(head)) { + LIST_REMOVE(inp, inp_hash); + LIST_INSERT_HEAD(head, inp, inp_hash); } - return in6p; + return inp; } void -in6_pcbstate(struct in6pcb *in6p, int state) +in6_pcbstate(struct inpcb *inp, int state) { - if (in6p->in6p_af != AF_INET6) + if (inp->inp_af != AF_INET6) return; - if (in6p->in6p_state > IN6P_ATTACHED) - LIST_REMOVE(&in6p->in6p_head, inph_hash); + if (inp->inp_state > INP_ATTACHED) + LIST_REMOVE(inp, inp_hash); switch (state) { - case IN6P_BOUND: - LIST_INSERT_HEAD(IN6PCBHASH_BIND(in6p->in6p_table, - &in6p->in6p_laddr, in6p->in6p_lport), &in6p->in6p_head, - inph_hash); + case INP_BOUND: + LIST_INSERT_HEAD(IN6PCBHASH_BIND(inp->inp_table, + &inp->inp_laddr6, inp->inp_lport), inp, + inp_hash); break; - case IN6P_CONNECTED: - LIST_INSERT_HEAD(IN6PCBHASH_CONNECT(in6p->in6p_table, - &in6p->in6p_faddr, in6p->in6p_fport, - &in6p->in6p_laddr, in6p->in6p_lport), &in6p->in6p_head, - inph_hash); + case INP_CONNECTED: + LIST_INSERT_HEAD(IN6PCBHASH_CONNECT(inp->inp_table, + &inp->inp_faddr6, inp->inp_fport, + &inp->inp_laddr6, inp->inp_lport), inp, + inp_hash); break; } - in6p->in6p_state = state; + inp->inp_state = state; } diff --git a/sys/netinet6/in6_pcb.h b/sys/netinet6/in6_pcb.h index abc84a7570d..3dafbe2d624 100644 --- a/sys/netinet6/in6_pcb.h +++ b/sys/netinet6/in6_pcb.h @@ -64,143 +64,6 @@ #ifndef _NETINET6_IN6_PCB_H_ #define _NETINET6_IN6_PCB_H_ -#include -#include -#include - -/* - * Common structure pcb for internet protocol implementation. - * Here are stored pointers to local and foreign host table - * entries, local and foreign socket numbers, and pointers - * up (to a socket structure) and down (to a protocol-specific) - * control block. - */ -struct icmp6_filter; - -struct in6pcb { - struct inpcb_hdr in6p_head; -#define in6p_queue in6p_head.inph_queue -#define in6p_af in6p_head.inph_af -#define in6p_ppcb in6p_head.inph_ppcb -#define in6p_state in6p_head.inph_state -#define in6p_portalgo in6p_head.inph_portalgo -#define in6p_socket in6p_head.inph_socket -#define in6p_table in6p_head.inph_table -#define in6p_sp in6p_head.inph_sp - struct route in6p_route; /* placeholder for routing entry */ - u_int16_t in6p_fport; /* foreign port */ - u_int16_t in6p_lport; /* local port */ - u_int32_t in6p_flowinfo; /* priority and flowlabel */ - int in6p_flags; /* generic IP6/datagram flags */ - int in6p_hops; /* default hop limit */ - struct ip6_hdr in6p_ip6; /* header prototype */ - struct mbuf *in6p_options; /* IP6 options */ - struct ip6_pktopts *in6p_outputopts; /* IP6 options for outgoing packets */ - struct ip6_moptions *in6p_moptions; /* IP6 multicast options */ - struct icmp6_filter *in6p_icmp6filt; - int in6p_cksum; /* IPV6_CHECKSUM setsockopt */ - bool in6p_bindportonsend; - struct ip_moptions *in6p_v4moptions;/* IP4 multicast options */ - pcb_overudp_cb_t in6p_overudp_cb; - void *in6p_overudp_arg; -}; - -#define in6p_faddr in6p_ip6.ip6_dst -#define in6p_laddr in6p_ip6.ip6_src - -#define in6p_lock(in6p) solock((in6p)->in6p_socket) -#define in6p_unlock(in6p) sounlock((in6p)->in6p_socket) -#define in6p_locked(in6p) solocked((in6p)->in6p_socket) - -/* states in inp_state: */ -#define IN6P_ATTACHED INP_ATTACHED -#define IN6P_BOUND INP_BOUND -#define IN6P_CONNECTED INP_CONNECTED - -/* - * Flags in in6p_flags - * We define KAME's original flags in higher 16 bits as much as possible - * for compatibility with *bsd*s. - */ -#define IN6P_RECVOPTS 0x00001000 /* receive incoming IP6 options */ -#define IN6P_RECVRETOPTS 0x00002000 /* receive IP6 options for reply */ -#define IN6P_RECVDSTADDR 0x00004000 /* receive IP6 dst address */ -#define IN6P_IPV6_V6ONLY 0x00008000 /* restrict AF_INET6 socket for v6 */ -#define IN6P_PKTINFO 0x00010000 /* receive IP6 dst and I/F */ -#define IN6P_HOPLIMIT 0x00020000 /* receive hoplimit */ -#define IN6P_HOPOPTS 0x00040000 /* receive hop-by-hop options */ -#define IN6P_DSTOPTS 0x00080000 /* receive dst options after rthdr */ -#define IN6P_RTHDR 0x00100000 /* receive routing header */ -#define IN6P_RTHDRDSTOPTS 0x00200000 /* receive dstoptions before rthdr */ -#define IN6P_TCLASS 0x00400000 /* traffic class */ -#define IN6P_BINDANY 0x00800000 /* allow bind to any address */ -#define IN6P_HIGHPORT 0x01000000 /* user wants "high" port binding */ -#define IN6P_LOWPORT 0x02000000 /* user wants "low" port binding */ -#define IN6P_ANONPORT 0x04000000 /* port chosen for user */ -#define IN6P_FAITH 0x08000000 /* accept FAITH'ed connections */ -/* XXX should move to an UDP control block */ -#define IN6P_ESPINUDP INP_ESPINUDP /* ESP over UDP for NAT-T */ - -#define IN6P_RFC2292 0x40000000 /* RFC2292 */ -#define IN6P_MTU 0x80000000 /* use minimum MTU */ - -#define IN6P_CONTROLOPTS (IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\ - IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\ - IN6P_TCLASS|IN6P_RFC2292|\ - IN6P_MTU) - -#ifdef _KERNEL -/* compute hash value for foreign and local in6_addr and port */ -#define IN6_HASH(faddr, fport, laddr, lport) \ - (((faddr)->s6_addr32[0] ^ (faddr)->s6_addr32[1] ^ \ - (faddr)->s6_addr32[2] ^ (faddr)->s6_addr32[3] ^ \ - (laddr)->s6_addr32[0] ^ (laddr)->s6_addr32[1] ^ \ - (laddr)->s6_addr32[2] ^ (laddr)->s6_addr32[3]) \ - + (fport) + (lport)) - -#define sotoin6pcb(so) ((struct in6pcb *)(so)->so_pcb) - -void in6_losing(struct in6pcb *); -void in6_pcbinit(struct inpcbtable *, int, int); -int in6_pcballoc(struct socket *, void *); -int in6_pcbbind(void *, struct sockaddr_in6 *, struct lwp *); -int in6_pcbconnect(void *, struct sockaddr_in6 *, struct lwp *); -void in6_pcbdetach(struct in6pcb *); -void in6_pcbdisconnect(struct in6pcb *); -struct in6pcb *in6_pcblookup_port(struct inpcbtable *, struct in6_addr *, - u_int, int, struct vestigial_inpcb *); -int in6_pcbnotify(struct inpcbtable *, const struct sockaddr *, - u_int, const struct sockaddr *, u_int, int, void *, - void (*)(struct in6pcb *, int)); -void in6_pcbpurgeif0(struct inpcbtable *, struct ifnet *); -void in6_pcbpurgeif(struct inpcbtable *, struct ifnet *); -void in6_pcbstate(struct in6pcb *, int); -void in6_rtchange(struct in6pcb *, int); -void in6_setpeeraddr(struct in6pcb *, struct sockaddr_in6 *); -void in6_setsockaddr(struct in6pcb *, struct sockaddr_in6 *); - -/* in in6_src.c */ -int in6_selecthlim(struct in6pcb *, struct ifnet *); -int in6_selecthlim_rt(struct in6pcb *); -int in6_pcbsetport(struct sockaddr_in6 *, struct in6pcb *, struct lwp *); - -extern struct rtentry * - in6_pcbrtentry(struct in6pcb *); -extern void - in6_pcbrtentry_unref(struct rtentry *, struct in6pcb *); -extern struct in6pcb *in6_pcblookup_connect(struct inpcbtable *, - const struct in6_addr *, u_int, const struct in6_addr *, u_int, int, - struct vestigial_inpcb *); -extern struct in6pcb *in6_pcblookup_bind(struct inpcbtable *, - const struct in6_addr *, u_int, int); - -static inline void -in6_pcb_register_overudp_cb(struct in6pcb *in6p, pcb_overudp_cb_t cb, void *arg) -{ - - in6p->in6p_overudp_cb = cb; - in6p->in6p_overudp_arg = arg; -} -#endif /* _KERNEL */ +#include #endif /* !_NETINET6_IN6_PCB_H_ */ diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index 178eb31b676..125e21d7f3d 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -809,10 +809,10 @@ out: * 3. The system default hoplimit. */ int -in6_selecthlim(struct in6pcb *in6p, struct ifnet *ifp) +in6_selecthlim(struct inpcb *inp, struct ifnet *ifp) { - if (in6p && in6p->in6p_hops >= 0) - return (in6p->in6p_hops); + if (inp && inp->inp_hops6 >= 0) + return (inp->inp_hops6); else if (ifp) return (ND_IFINFO(ifp)->chlim); else @@ -820,35 +820,35 @@ in6_selecthlim(struct in6pcb *in6p, struct ifnet *ifp) } int -in6_selecthlim_rt(struct in6pcb *in6p) +in6_selecthlim_rt(struct inpcb *inp) { struct rtentry *rt; - if (in6p == NULL) - return in6_selecthlim(in6p, NULL); + if (inp == NULL) + return in6_selecthlim(inp, NULL); - rt = rtcache_validate(&in6p->in6p_route); + rt = rtcache_validate(&inp->inp_route); if (rt != NULL) { - int ret = in6_selecthlim(in6p, rt->rt_ifp); - rtcache_unref(rt, &in6p->in6p_route); + int ret = in6_selecthlim(inp, rt->rt_ifp); + rtcache_unref(rt, &inp->inp_route); return ret; } else - return in6_selecthlim(in6p, NULL); + return in6_selecthlim(inp, NULL); } /* * Find an empty port and set it to the specified PCB. */ int -in6_pcbsetport(struct sockaddr_in6 *sin6, struct in6pcb *in6p, struct lwp *l) +in6_pcbsetport(struct sockaddr_in6 *sin6, struct inpcb *inp, struct lwp *l) { - struct socket *so = in6p->in6p_socket; - struct inpcbtable *table = in6p->in6p_table; + struct socket *so = inp->inp_socket; + struct inpcbtable *table = inp->inp_table; u_int16_t lport, *lastport; enum kauth_network_req req; int error = 0; - if (in6p->in6p_flags & IN6P_LOWPORT) { + if (inp->inp_flags & IN6P_LOWPORT) { #ifndef IPNOPRIVPORTS req = KAUTH_REQ_NETWORK_BIND_PRIVPORT; #else @@ -870,14 +870,14 @@ in6_pcbsetport(struct sockaddr_in6 *sin6, struct in6pcb *in6p, struct lwp *l) /* * Use RFC6056 randomized port selection */ - error = portalgo_randport(&lport, &in6p->in6p_head, l->l_cred); + error = portalgo_randport(&lport, inp, l->l_cred); if (error) return error; - in6p->in6p_flags |= IN6P_ANONPORT; + inp->inp_flags |= IN6P_ANONPORT; *lastport = lport; - in6p->in6p_lport = htons(lport); - in6_pcbstate(in6p, IN6P_BOUND); + inp->inp_lport = htons(lport); + in6_pcbstate(inp, INP_BOUND); return (0); /* success */ } diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 64ffd8d6877..51455aa6c11 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1063,12 +1063,12 @@ ip6_unknown_opt(u_int8_t *optp, struct mbuf *m, int off) } void -ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, +ip6_savecontrol(struct inpcb *inp, struct mbuf **mp, struct ip6_hdr *ip6, struct mbuf *m) { - struct socket *so = in6p->in6p_socket; + struct socket *so = inp->inp_socket; #ifdef RFC2292 -#define IS2292(x, y) ((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y)) +#define IS2292(x, y) ((inp->inp_flags & IN6P_RFC2292) ? (x) : (y)) #else #define IS2292(x, y) (y) #endif @@ -1083,7 +1083,7 @@ ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, return; /* RFC 2292 sec. 5 */ - if ((in6p->in6p_flags & IN6P_PKTINFO) != 0) { + if ((inp->inp_flags & IN6P_PKTINFO) != 0) { struct in6_pktinfo pi6; memcpy(&pi6.ipi6_addr, &ip6->ip6_dst, sizeof(struct in6_addr)); @@ -1095,7 +1095,7 @@ ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, mp = &(*mp)->m_next; } - if (in6p->in6p_flags & IN6P_HOPLIMIT) { + if (inp->inp_flags & IN6P_HOPLIMIT) { int hlim = ip6->ip6_hlim & 0xff; *mp = sbcreatecontrol(&hlim, sizeof(hlim), @@ -1104,7 +1104,7 @@ ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, mp = &(*mp)->m_next; } - if ((in6p->in6p_flags & IN6P_TCLASS) != 0) { + if ((inp->inp_flags & IN6P_TCLASS) != 0) { u_int32_t flowinfo; int tclass; @@ -1126,7 +1126,7 @@ ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, * returned to normal user. * See also RFC3542 section 8 (or RFC2292 section 6). */ - if ((in6p->in6p_flags & IN6P_HOPOPTS) != 0) { + if ((inp->inp_flags & IN6P_HOPOPTS) != 0) { /* * Check if a hop-by-hop options header is contatined in the * received packet, and if so, store the options as ancillary @@ -1170,7 +1170,7 @@ ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, } /* IPV6_DSTOPTS and IPV6_RTHDR socket options */ - if (in6p->in6p_flags & (IN6P_DSTOPTS | IN6P_RTHDR)) { + if (inp->inp_flags & (IN6P_DSTOPTS | IN6P_RTHDR)) { struct ip6_hdr *xip6 = mtod(m, struct ip6_hdr *); int nxt = xip6->ip6_nxt, off = sizeof(struct ip6_hdr); @@ -1219,7 +1219,7 @@ ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, switch (nxt) { case IPPROTO_DSTOPTS: - if (!(in6p->in6p_flags & IN6P_DSTOPTS)) + if (!(inp->inp_flags & IN6P_DSTOPTS)) break; *mp = sbcreatecontrol(ip6e, elen, @@ -1230,7 +1230,7 @@ ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, break; case IPPROTO_ROUTING: - if (!(in6p->in6p_flags & IN6P_RTHDR)) + if (!(inp->inp_flags & IN6P_RTHDR)) break; *mp = sbcreatecontrol(ip6e, elen, @@ -1271,14 +1271,14 @@ ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, void -ip6_notify_pmtu(struct in6pcb *in6p, const struct sockaddr_in6 *dst, +ip6_notify_pmtu(struct inpcb *inp, const struct sockaddr_in6 *dst, uint32_t *mtu) { struct socket *so; struct mbuf *m_mtu; struct ip6_mtuinfo mtuctl; - so = in6p->in6p_socket; + so = inp->inp_socket; if (mtu == NULL) return; diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index 5d4a7b746a3..074fe7b38f0 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -121,8 +121,8 @@ static int ip6_pcbopt(int, u_char *, int, struct ip6_pktopts **, static int ip6_getpcbopt(struct ip6_pktopts *, int, struct sockopt *); static int ip6_setpktopt(int, u_char *, int, struct ip6_pktopts *, kauth_cred_t, int, int, int); -static int ip6_setmoptions(const struct sockopt *, struct in6pcb *); -static int ip6_getmoptions(struct sockopt *, struct in6pcb *); +static int ip6_setmoptions(const struct sockopt *, struct inpcb *); +static int ip6_getmoptions(struct sockopt *, struct inpcb *); static int ip6_copyexthdr(struct mbuf **, void *, int); static int ip6_insertfraghdr(struct mbuf *, struct mbuf *, int, struct ip6_frag **); @@ -196,7 +196,7 @@ ip6_output( struct route *ro, int flags, struct ip6_moptions *im6o, - struct in6pcb *in6p, + struct inpcb *inp, struct ifnet **ifpp /* XXX: just for statistics */ ) { @@ -286,7 +286,7 @@ ip6_output( #ifdef IPSEC if (ipsec_used) { /* Check the security policy (SP) for the packet */ - sp = ipsec6_check_policy(m, in6p, flags, &needipsec, &error); + sp = ipsec6_check_policy(m, inp, flags, &needipsec, &error); if (error != 0) { /* * Hack: -EINVAL is used to signal that a packet @@ -1297,7 +1297,7 @@ ip6_ctloutput(int op, struct socket *so, struct sockopt *sopt) { int optdatalen, uproto; void *optdata; - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); struct ip_moptions **mopts; int error, optval; int level, optname; @@ -1319,7 +1319,7 @@ ip6_ctloutput(int op, struct socket *so, struct sockopt *sopt) case IP_MULTICAST_IF: case IP_MULTICAST_LOOP: case IP_MULTICAST_TTL: - mopts = &in6p->in6p_v4moptions; + mopts = &inp->inp_moptions; switch (op) { case PRCO_GETOPT: return ip_getmoptions(*mopts, sopt); @@ -1341,7 +1341,7 @@ ip6_ctloutput(int op, struct socket *so, struct sockopt *sopt) switch (optname) { #ifdef RFC2292 case IPV6_2292PKTOPTIONS: - error = ip6_pcbopts(&in6p->in6p_outputopts, so, sopt); + error = ip6_pcbopts(&inp->inp_outputopts6, so, sopt); break; #endif @@ -1388,29 +1388,29 @@ ip6_ctloutput(int op, struct socket *so, struct sockopt *sopt) error = EINVAL; else { /* -1 = kernel default */ - in6p->in6p_hops = optval; + inp->inp_hops6 = optval; } break; #define OPTSET(bit) \ do { \ if (optval) \ - in6p->in6p_flags |= (bit); \ + inp->inp_flags |= (bit); \ else \ - in6p->in6p_flags &= ~(bit); \ + inp->inp_flags &= ~(bit); \ } while (/*CONSTCOND*/ 0) #ifdef RFC2292 #define OPTSET2292(bit) \ do { \ -in6p->in6p_flags |= IN6P_RFC2292; \ +inp->inp_flags |= IN6P_RFC2292; \ if (optval) \ - in6p->in6p_flags |= (bit); \ + inp->inp_flags |= (bit); \ else \ - in6p->in6p_flags &= ~(bit); \ + inp->inp_flags &= ~(bit); \ } while (/*CONSTCOND*/ 0) #endif -#define OPTBIT(bit) (in6p->in6p_flags & (bit) ? 1 : 0) +#define OPTBIT(bit) (inp->inp_flags & (bit) ? 1 : 0) case IPV6_RECVPKTINFO: #ifdef RFC2292 @@ -1434,7 +1434,7 @@ else \ break; } #endif - optp = &in6p->in6p_outputopts; + optp = &inp->inp_outputopts6; error = ip6_pcbopt(IPV6_HOPLIMIT, (u_char *)&optval, sizeof(optval), @@ -1519,8 +1519,8 @@ else \ * available only prior to bind(2). * see ipng mailing list, Jun 22 2001. */ - if (in6p->in6p_lport || - !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) { + if (inp->inp_lport || + !IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) { error = EINVAL; break; } @@ -1563,7 +1563,7 @@ else \ error = sockopt_get(sopt, &tclass, sizeof(tclass)); if (error) break; - optp = &in6p->in6p_outputopts; + optp = &inp->inp_outputopts6; error = ip6_pcbopt(optname, (u_char *)&tclass, sizeof(tclass), @@ -1581,7 +1581,7 @@ else \ break; { struct ip6_pktopts **optp; - optp = &in6p->in6p_outputopts; + optp = &inp->inp_outputopts6; error = ip6_pcbopt(optname, (u_char *)&optval, sizeof(optval), @@ -1669,7 +1669,7 @@ else \ free(optbuf, M_IP6OPT); break; } - optp = &in6p->in6p_outputopts; + optp = &inp->inp_outputopts6; error = ip6_pcbopt(optname, optbuf, optbuflen, optp, kauth_cred_get(), uproto); @@ -1683,7 +1683,7 @@ else \ case IPV6_MULTICAST_LOOP: case IPV6_JOIN_GROUP: case IPV6_LEAVE_GROUP: - error = ip6_setmoptions(sopt, in6p); + error = ip6_setmoptions(sopt, inp); break; case IPV6_PORTRANGE: @@ -1693,18 +1693,18 @@ else \ switch (optval) { case IPV6_PORTRANGE_DEFAULT: - in6p->in6p_flags &= ~(IN6P_LOWPORT); - in6p->in6p_flags &= ~(IN6P_HIGHPORT); + inp->inp_flags &= ~(IN6P_LOWPORT); + inp->inp_flags &= ~(IN6P_HIGHPORT); break; case IPV6_PORTRANGE_HIGH: - in6p->in6p_flags &= ~(IN6P_LOWPORT); - in6p->in6p_flags |= IN6P_HIGHPORT; + inp->inp_flags &= ~(IN6P_LOWPORT); + inp->inp_flags |= IN6P_HIGHPORT; break; case IPV6_PORTRANGE_LOW: - in6p->in6p_flags &= ~(IN6P_HIGHPORT); - in6p->in6p_flags |= IN6P_LOWPORT; + inp->inp_flags &= ~(IN6P_HIGHPORT); + inp->inp_flags |= IN6P_LOWPORT; break; default: @@ -1718,14 +1718,13 @@ else \ if (error) break; - error = portalgo_algo_index_select( - (struct inpcb_hdr *)in6p, optval); + error = portalgo_algo_index_select(inp, optval); break; #if defined(IPSEC) case IPV6_IPSEC_POLICY: if (ipsec_enabled) { - error = ipsec_set_policy(in6p, + error = ipsec_set_policy(inp, sopt->sopt_data, sopt->sopt_size, kauth_cred_get()); } else @@ -1784,7 +1783,7 @@ else \ break; case IPV6_UNICAST_HOPS: - optval = in6p->in6p_hops; + optval = inp->inp_hops6; break; case IPV6_RECVPKTINFO: @@ -1814,7 +1813,7 @@ else \ case IPV6_PORTRANGE: { int flags; - flags = in6p->in6p_flags; + flags = inp->inp_flags; if (flags & IN6P_HIGHPORT) optval = IPV6_PORTRANGE_HIGH; else if (flags & IN6P_LOWPORT) @@ -1841,7 +1840,7 @@ else \ { u_long pmtu = 0; struct ip6_mtuinfo mtuinfo; - struct route *ro = &in6p->in6p_route; + struct route *ro = &inp->inp_route; struct rtentry *rt; union { struct sockaddr dst; @@ -1855,7 +1854,7 @@ else \ * routing, or optional information to specify * the outgoing interface. */ - sockaddr_in6_init(&u.dst6, &in6p->in6p_faddr, 0, 0, 0); + sockaddr_in6_init(&u.dst6, &inp->inp_faddr6, 0, 0, 0); rt = rtcache_lookup(ro, &u.dst); error = ip6_getpmtu(rt, NULL, &pmtu, NULL); rtcache_unref(rt, ro); @@ -1911,7 +1910,7 @@ else \ case IPV6_DONTFRAG: case IPV6_USE_MIN_MTU: case IPV6_PREFER_TEMPADDR: - error = ip6_getpcbopt(in6p->in6p_outputopts, + error = ip6_getpcbopt(inp->inp_outputopts6, optname, sopt); break; @@ -1920,11 +1919,11 @@ else \ case IPV6_MULTICAST_LOOP: case IPV6_JOIN_GROUP: case IPV6_LEAVE_GROUP: - error = ip6_getmoptions(sopt, in6p); + error = ip6_getmoptions(sopt, inp); break; case IPV6_PORTALGO: - optval = ((struct inpcb_hdr *)in6p)->inph_portalgo; + optval = inp->inp_portalgo; error = sockopt_setint(sopt, optval); break; @@ -1937,7 +1936,7 @@ else \ * XXX: this will return EINVAL as sopt is * empty */ - error = ipsec_get_policy(in6p, sopt->sopt_data, + error = ipsec_get_policy(inp, sopt->sopt_data, sopt->sopt_size, &m); if (!error) error = sockopt_setmbuf(sopt, m); @@ -1960,7 +1959,7 @@ ip6_raw_ctloutput(int op, struct socket *so, struct sockopt *sopt) { int error = 0, optval; const int icmp6off = offsetof(struct icmp6_hdr, icmp6_cksum); - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); int level, optname; KASSERT(sopt != NULL); @@ -1995,14 +1994,14 @@ ip6_raw_ctloutput(int op, struct socket *so, struct sockopt *sopt) if (optval != icmp6off) error = EINVAL; } else - in6p->in6p_cksum = optval; + inp->inp_cksum6 = optval; break; case PRCO_GETOPT: if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) optval = icmp6off; else - optval = in6p->in6p_cksum; + optval = inp->inp_cksum6; error = sockopt_setint(sopt, optval); break; @@ -2423,17 +2422,17 @@ ip6_get_membership(const struct sockopt *sopt, struct ifnet **ifp, * Set the IP6 multicast options in response to user setsockopt(). */ static int -ip6_setmoptions(const struct sockopt *sopt, struct in6pcb *in6p) +ip6_setmoptions(const struct sockopt *sopt, struct inpcb *inp) { int error = 0; u_int loop, ifindex; struct ipv6_mreq mreq; struct in6_addr ia; struct ifnet *ifp; - struct ip6_moptions *im6o = in6p->in6p_moptions; + struct ip6_moptions *im6o = inp->inp_moptions6; struct in6_multi_mship *imm; - KASSERT(in6p_locked(in6p)); + KASSERT(inp_locked(inp)); if (im6o == NULL) { /* @@ -2443,7 +2442,7 @@ ip6_setmoptions(const struct sockopt *sopt, struct in6pcb *in6p) im6o = malloc(sizeof(*im6o), M_IPMOPTS, M_NOWAIT); if (im6o == NULL) return (ENOBUFS); - in6p->in6p_moptions = im6o; + inp->inp_moptions6 = im6o; im6o->im6o_multicast_if_index = 0; im6o->im6o_multicast_hlim = ip6_defmcasthlim; im6o->im6o_multicast_loop = IPV6_DEFAULT_MULTICAST_LOOP; @@ -2532,7 +2531,7 @@ ip6_setmoptions(const struct sockopt *sopt, struct in6pcb *in6p) } if (IN6_IS_ADDR_V4MAPPED(&ia)) { - error = ip_setmoptions(&in6p->in6p_v4moptions, sopt); + error = ip_setmoptions(&inp->inp_moptions, sopt); goto put_break; } /* @@ -2586,7 +2585,7 @@ ip6_setmoptions(const struct sockopt *sopt, struct in6pcb *in6p) break; if (IN6_IS_ADDR_V4MAPPED(&mreq.ipv6mr_multiaddr)) { - error = ip_setmoptions(&in6p->in6p_v4moptions, sopt); + error = ip_setmoptions(&inp->inp_moptions, sopt); break; } /* @@ -2659,7 +2658,7 @@ ip6_setmoptions(const struct sockopt *sopt, struct in6pcb *in6p) */ LIST_REMOVE(imm, i6mm_chain); in6_leavegroup(imm); - /* in6m_ifp should not leave thanks to in6p_lock */ + /* in6m_ifp should not leave thanks to inp_lock */ break; } @@ -2675,8 +2674,8 @@ ip6_setmoptions(const struct sockopt *sopt, struct in6pcb *in6p) im6o->im6o_multicast_hlim == ip6_defmcasthlim && im6o->im6o_multicast_loop == IPV6_DEFAULT_MULTICAST_LOOP && LIST_EMPTY(&im6o->im6o_memberships)) { - free(in6p->in6p_moptions, M_IPMOPTS); - in6p->in6p_moptions = NULL; + free(inp->inp_moptions6, M_IPMOPTS); + inp->inp_moptions6 = NULL; } return (error); @@ -2686,11 +2685,11 @@ ip6_setmoptions(const struct sockopt *sopt, struct in6pcb *in6p) * Return the IP6 multicast options in response to user getsockopt(). */ static int -ip6_getmoptions(struct sockopt *sopt, struct in6pcb *in6p) +ip6_getmoptions(struct sockopt *sopt, struct inpcb *inp) { u_int optval; int error; - struct ip6_moptions *im6o = in6p->in6p_moptions; + struct ip6_moptions *im6o = inp->inp_moptions6; switch (sopt->sopt_name) { case IPV6_MULTICAST_IF: @@ -2738,7 +2737,7 @@ ip6_freemoptions(struct ip6_moptions *im6o) if (im6o == NULL) return; - /* The owner of im6o (in6p) should be protected by solock */ + /* The owner of im6o (inp) should be protected by solock */ LIST_FOREACH_SAFE(imm, &im6o->im6o_memberships, i6mm_chain, nimm) { LIST_REMOVE(imm, i6mm_chain); in6_leavegroup(imm); @@ -3299,21 +3298,21 @@ ip6_splithdr(struct mbuf *m, struct ip6_exthdrs *exthdrs) * Compute IPv6 extension header length. */ int -ip6_optlen(struct in6pcb *in6p) +ip6_optlen(struct inpcb *inp) { int len; - if (!in6p->in6p_outputopts) + if (!inp->inp_outputopts6) return 0; len = 0; #define elen(x) \ (((struct ip6_ext *)(x)) ? (((struct ip6_ext *)(x))->ip6e_len + 1) << 3 : 0) - len += elen(in6p->in6p_outputopts->ip6po_hbh); - len += elen(in6p->in6p_outputopts->ip6po_dest1); - len += elen(in6p->in6p_outputopts->ip6po_rthdr); - len += elen(in6p->in6p_outputopts->ip6po_dest2); + len += elen(inp->inp_outputopts6->ip6po_hbh); + len += elen(inp->inp_outputopts6->ip6po_dest1); + len += elen(inp->inp_outputopts6->ip6po_rthdr); + len += elen(inp->inp_outputopts6->ip6po_dest2); return len; #undef elen } diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h index 920055c4759..a9cf5e5e454 100644 --- a/sys/netinet6/ip6_var.h +++ b/sys/netinet6/ip6_var.h @@ -288,7 +288,7 @@ extern int ip6_maxflows; /* maximum amount of flows for ip6ff */ extern int ip6_hashsize; /* size of hash table */ #endif -struct in6pcb; +struct inpcb; extern const struct pr_usrreqs rip6_usrreqs; int icmp6_ctloutput(int, struct socket *, struct sockopt *); @@ -306,9 +306,9 @@ int ip6_lasthdr(struct mbuf *, int, int, int *); struct ip6_hdr; int ip6_mforward(struct ip6_hdr *, struct ifnet *, struct mbuf *); int ip6_hopopts_input(u_int32_t *, u_int32_t *, struct mbuf **, int *); -void ip6_savecontrol(struct in6pcb *, struct mbuf **, struct ip6_hdr *, +void ip6_savecontrol(struct inpcb *, struct mbuf **, struct ip6_hdr *, struct mbuf *); -void ip6_notify_pmtu(struct in6pcb *, const struct sockaddr_in6 *, +void ip6_notify_pmtu(struct inpcb *, const struct sockaddr_in6 *, u_int32_t *); int ip6_sysctl(int *, u_int, void *, size_t *, void *, size_t); @@ -317,7 +317,7 @@ void ip6_forward(struct mbuf *, int, struct ifnet *); void ip6_mloopback(struct ifnet *, struct mbuf *, const struct sockaddr_in6 *); int ip6_output(struct mbuf *, struct ip6_pktopts *, struct route *, int, - struct ip6_moptions *, struct in6pcb *, struct ifnet **); + struct ip6_moptions *, struct inpcb *, struct ifnet **); int ip6_if_output(struct ifnet * const, struct ifnet * const, struct mbuf * const, const struct sockaddr_in6 * const, const struct rtentry *); @@ -328,7 +328,7 @@ int ip6_setpktopts(struct mbuf *, struct ip6_pktopts *, struct ip6_pktopts *, kauth_cred_t, int); void ip6_clearpktopts(struct ip6_pktopts *, int); struct ip6_pktopts *ip6_copypktopts(struct ip6_pktopts *, int); -int ip6_optlen(struct in6pcb *); +int ip6_optlen(struct inpcb *); void ip6_statinc(u_int); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 8e0694947de..4abb7e5c8d4 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -135,24 +135,24 @@ rip6_init(void) } static void -rip6_sbappendaddr(struct in6pcb *last, struct ip6_hdr *ip6, +rip6_sbappendaddr(struct inpcb *last, struct ip6_hdr *ip6, const struct sockaddr *sa, int hlen, struct mbuf *n) { struct mbuf *opts = NULL; - if (last->in6p_flags & IN6P_CONTROLOPTS) + if (last->inp_flags & IN6P_CONTROLOPTS) ip6_savecontrol(last, &opts, ip6, n); m_adj(n, hlen); - if (sbappendaddr(&last->in6p_socket->so_rcv, sa, n, opts) == 0) { - soroverflow(last->in6p_socket); + if (sbappendaddr(&last->inp_socket->so_rcv, sa, n, opts) == 0) { + soroverflow(last->inp_socket); m_freem(n); if (opts) m_freem(opts); RIP6_STATINC(RIP6_STAT_FULLSOCK); } else { - sorwakeup(last->in6p_socket); + sorwakeup(last->inp_socket); } } @@ -166,9 +166,8 @@ rip6_input(struct mbuf **mp, int *offp, int proto) { struct mbuf *m = *mp; struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); - struct inpcb_hdr *inph; - struct in6pcb *in6p; - struct in6pcb *last = NULL; + struct inpcb *inp; + struct inpcb *last = NULL; struct sockaddr_in6 rip6src; struct mbuf *n; @@ -189,20 +188,19 @@ rip6_input(struct mbuf **mp, int *offp, int proto) return IPPROTO_DONE; } - TAILQ_FOREACH(inph, &raw6cbtable.inpt_queue, inph_queue) { - in6p = (struct in6pcb *)inph; - if (in6p->in6p_af != AF_INET6) + TAILQ_FOREACH(inp, &raw6cbtable.inpt_queue, inp_queue) { + if (inp->inp_af != AF_INET6) continue; - if (in6p->in6p_ip6.ip6_nxt && - in6p->in6p_ip6.ip6_nxt != proto) + if (inp->inp_ip6.ip6_nxt && + inp->inp_ip6.ip6_nxt != proto) continue; - if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) && - !IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, &ip6->ip6_dst)) + if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) && + !IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &ip6->ip6_dst)) continue; - if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr) && - !IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr, &ip6->ip6_src)) + if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6) && + !IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, &ip6->ip6_src)) continue; - if (in6p->in6p_cksum != -1) { + if (inp->inp_cksum6 != -1) { RIP6_STATINC(RIP6_STAT_ISUM); if (in6_cksum(m, proto, *offp, m->m_pkthdr.len - *offp)) { @@ -224,7 +222,7 @@ rip6_input(struct mbuf **mp, int *offp, int proto) *offp, n); } - last = in6p; + last = inp; } #ifdef IPSEC @@ -264,7 +262,7 @@ rip6_ctlinput(int cmd, const struct sockaddr *sa, void *d) struct ip6ctlparam *ip6cp = NULL; const struct sockaddr_in6 *sa6_src = NULL; void *cmdarg; - void (*notify)(struct in6pcb *, int) = in6_rtchange; + void (*notify)(struct inpcb *, int) = in6_rtchange; int nxt; if (sa->sa_family != AF_INET6 || @@ -299,7 +297,7 @@ rip6_ctlinput(int cmd, const struct sockaddr *sa, void *d) if (ip6 && cmd == PRC_MSGSIZE) { const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *)sa; int valid = 0; - struct in6pcb *in6p; + struct inpcb *inp; /* * Check to see if we have a valid raw IPv6 socket @@ -308,11 +306,11 @@ rip6_ctlinput(int cmd, const struct sockaddr *sa, void *d) * XXX chase extension headers, or pass final nxt value * from icmp6_notify_error() */ - in6p = NULL; - in6p = in6_pcblookup_connect(&raw6cbtable, &sa6->sin6_addr, 0, + inp = NULL; + inp = in6_pcblookup_connect(&raw6cbtable, &sa6->sin6_addr, 0, (const struct in6_addr *)&sa6_src->sin6_addr, 0, 0, 0); #if 0 - if (!in6p) { + if (!inp) { /* * As the use of sendto(2) is fairly popular, * we may want to allow non-connected pcb too. @@ -320,13 +318,13 @@ rip6_ctlinput(int cmd, const struct sockaddr *sa, void *d) * We should at least check if the local * address (= s) is really ours. */ - in6p = in6_pcblookup_bind(&raw6cbtable, + inp = in6_pcblookup_bind(&raw6cbtable, &sa6->sin6_addr, 0, 0); } #endif - if (in6p && in6p->in6p_ip6.ip6_nxt && - in6p->in6p_ip6.ip6_nxt == nxt) + if (inp && inp->inp_ip6.ip6_nxt && + inp->inp_ip6.ip6_nxt == nxt) valid++; /* @@ -362,7 +360,7 @@ rip6_output(struct mbuf *m, struct socket * const so, { struct in6_addr *dst; struct ip6_hdr *ip6; - struct in6pcb *in6p; + struct inpcb *inp; u_int plen = m->m_pkthdr.len; int error = 0; struct ip6_pktopts opt, *optp = NULL; @@ -372,18 +370,18 @@ rip6_output(struct mbuf *m, struct socket * const so, int bound = curlwp_bind(); struct psref psref; - in6p = sotoin6pcb(so); + inp = sotoinpcb(so); dst = &dstsock->sin6_addr; if (control) { if ((error = ip6_setpktopts(control, &opt, - in6p->in6p_outputopts, + inp->inp_outputopts6, kauth_cred_get(), so->so_proto->pr_protocol)) != 0) { goto bad; } optp = &opt; } else - optp = in6p->in6p_outputopts; + optp = inp->inp_outputopts6; /* * Check and convert scope zone ID into internal form. @@ -430,8 +428,8 @@ rip6_output(struct mbuf *m, struct socket * const so, /* * Source address selection. */ - error = in6_selectsrc(dstsock, optp, in6p->in6p_moptions, - &in6p->in6p_route, &in6p->in6p_laddr, &oifp, &psref, &ip6->ip6_src); + error = in6_selectsrc(dstsock, optp, inp->inp_moptions6, + &inp->inp_route, &inp->inp_laddr6, &oifp, &psref, &ip6->ip6_src); if (error != 0) goto bad; @@ -451,18 +449,18 @@ rip6_output(struct mbuf *m, struct socket * const so, ip6->ip6_dst = dstsock->sin6_addr; /* fill in the rest of the IPv6 header fields */ - ip6->ip6_flow = in6p->in6p_flowinfo & IPV6_FLOWINFO_MASK; + ip6->ip6_flow = inp->inp_flowinfo & IPV6_FLOWINFO_MASK; ip6->ip6_vfc &= ~IPV6_VERSION_MASK; ip6->ip6_vfc |= IPV6_VERSION; /* ip6_plen will be filled in ip6_output, so not fill it here. */ - ip6->ip6_nxt = in6p->in6p_ip6.ip6_nxt; - ip6->ip6_hlim = in6_selecthlim(in6p, oifp); + ip6->ip6_nxt = inp->inp_ip6.ip6_nxt; + ip6->ip6_hlim = in6_selecthlim(inp, oifp); if_put(oifp, &psref); oifp = NULL; if (so->so_proto->pr_protocol == IPPROTO_ICMPV6 || - in6p->in6p_cksum != -1) { + inp->inp_cksum6 != -1) { const uint8_t nxt = ip6->ip6_nxt; int off; u_int16_t sum; @@ -471,7 +469,7 @@ rip6_output(struct mbuf *m, struct socket * const so, if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) off = offsetof(struct icmp6_hdr, icmp6_cksum); else - off = in6p->in6p_cksum; + off = inp->inp_cksum6; if (plen < off + 1) { error = EINVAL; goto bad; @@ -497,8 +495,8 @@ rip6_output(struct mbuf *m, struct socket * const so, { struct ifnet *ret_oifp = NULL; - error = ip6_output(m, optp, &in6p->in6p_route, 0, - in6p->in6p_moptions, in6p, &ret_oifp); + error = ip6_output(m, optp, &inp->inp_route, 0, + inp->inp_moptions6, inp, &ret_oifp); if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) { if (ret_oifp) icmp6_ifoutstat_inc(ret_oifp, type, code); @@ -580,10 +578,10 @@ extern u_long rip6_recvspace; int rip6_attach(struct socket *so, int proto) { - struct in6pcb *in6p; + struct inpcb *inp; int s, error; - KASSERT(sotoin6pcb(so) == NULL); + KASSERT(sotoinpcb(so) == NULL); sosetlock(so); error = kauth_authorize_network(kauth_cred_get(), @@ -600,17 +598,17 @@ rip6_attach(struct socket *so, int proto) splx(s); return error; } - if ((error = in6_pcballoc(so, &raw6cbtable)) != 0) { + if ((error = in_pcballoc(so, &raw6cbtable)) != 0) { splx(s); return error; } splx(s); - in6p = sotoin6pcb(so); - in6p->in6p_ip6.ip6_nxt = proto; - in6p->in6p_cksum = -1; + inp = sotoinpcb(so); + inp->inp_ip6.ip6_nxt = proto; + inp->inp_cksum6 = -1; - in6p->in6p_icmp6filt = kmem_alloc(sizeof(struct icmp6_filter), KM_SLEEP); - ICMP6_FILTER_SETPASSALL(in6p->in6p_icmp6filt); + inp->inp_icmp6filt = kmem_alloc(sizeof(struct icmp6_filter), KM_SLEEP); + ICMP6_FILTER_SETPASSALL(inp->inp_icmp6filt); KASSERT(solocked(so)); return error; } @@ -618,20 +616,20 @@ rip6_attach(struct socket *so, int proto) static void rip6_detach(struct socket *so) { - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); KASSERT(solocked(so)); - KASSERT(in6p != NULL); + KASSERT(inp != NULL); if (so == ip6_mrouter) { ip6_mrouter_done(); } /* xxx: RSVP */ - if (in6p->in6p_icmp6filt != NULL) { - kmem_free(in6p->in6p_icmp6filt, sizeof(struct icmp6_filter)); - in6p->in6p_icmp6filt = NULL; + if (inp->inp_icmp6filt != NULL) { + kmem_free(inp->inp_icmp6filt, sizeof(struct icmp6_filter)); + inp->inp_icmp6filt = NULL; } - in6_pcbdetach(in6p); + in_pcbdetach(inp); } static int @@ -645,14 +643,14 @@ rip6_accept(struct socket *so, struct sockaddr *nam) static int rip6_bind(struct socket *so, struct sockaddr *nam, struct lwp *l) { - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); struct sockaddr_in6 *addr = (struct sockaddr_in6 *)nam; struct ifaddr *ifa = NULL; int error = 0; int s; KASSERT(solocked(so)); - KASSERT(in6p != NULL); + KASSERT(inp != NULL); KASSERT(nam != NULL); if (addr->sin6_len != sizeof(*addr)) @@ -681,7 +679,7 @@ rip6_bind(struct socket *so, struct sockaddr *nam, struct lwp *l) goto out; } - in6p->in6p_laddr = addr->sin6_addr; + inp->inp_laddr6 = addr->sin6_addr; error = 0; out: pserialize_read_exit(s); @@ -699,7 +697,7 @@ rip6_listen(struct socket *so, struct lwp *l) static int rip6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) { - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); struct sockaddr_in6 *addr = (struct sockaddr_in6 *)nam; struct in6_addr in6a; struct ifnet *ifp = NULL; @@ -709,7 +707,7 @@ rip6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) int bound; KASSERT(solocked(so)); - KASSERT(in6p != NULL); + KASSERT(inp != NULL); KASSERT(nam != NULL); if (IFNET_READER_EMPTY()) @@ -734,9 +732,9 @@ rip6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) bound = curlwp_bind(); /* Source address selection. XXX: need pcblookup? */ - error = in6_selectsrc(addr, in6p->in6p_outputopts, - in6p->in6p_moptions, &in6p->in6p_route, - &in6p->in6p_laddr, &ifp, &psref, &in6a); + error = in6_selectsrc(addr, inp->inp_outputopts6, + inp->inp_moptions6, &inp->inp_route, + &inp->inp_laddr6, &ifp, &psref, &in6a); if (error != 0) goto out; /* XXX: see above */ @@ -744,8 +742,8 @@ rip6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) (error = in6_setscope(&addr->sin6_addr, ifp, NULL)) != 0) { goto out; } - in6p->in6p_laddr = in6a; - in6p->in6p_faddr = addr->sin6_addr; + inp->inp_laddr6 = in6a; + inp->inp_faddr6 = addr->sin6_addr; soisconnected(so); out: if_put(ifp, &psref); @@ -764,15 +762,15 @@ rip6_connect2(struct socket *so, struct socket *so2) static int rip6_disconnect(struct socket *so) { - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); KASSERT(solocked(so)); - KASSERT(in6p != NULL); + KASSERT(inp != NULL); if ((so->so_state & SS_ISCONNECTED) == 0) return ENOTCONN; - in6p->in6p_faddr = in6addr_any; + inp->inp_faddr6 = in6addr_any; so->so_state &= ~SS_ISCONNECTED; /* XXX */ return 0; } @@ -818,10 +816,10 @@ static int rip6_peeraddr(struct socket *so, struct sockaddr *nam) { KASSERT(solocked(so)); - KASSERT(sotoin6pcb(so) != NULL); + KASSERT(sotoinpcb(so) != NULL); KASSERT(nam != NULL); - in6_setpeeraddr(sotoin6pcb(so), (struct sockaddr_in6 *)nam); + in6_setpeeraddr(sotoinpcb(so), (struct sockaddr_in6 *)nam); return 0; } @@ -829,10 +827,10 @@ static int rip6_sockaddr(struct socket *so, struct sockaddr *nam) { KASSERT(solocked(so)); - KASSERT(sotoin6pcb(so) != NULL); + KASSERT(sotoinpcb(so) != NULL); KASSERT(nam != NULL); - in6_setsockaddr(sotoin6pcb(so), (struct sockaddr_in6 *)nam); + in6_setsockaddr(sotoinpcb(so), (struct sockaddr_in6 *)nam); return 0; } @@ -856,13 +854,13 @@ static int rip6_send(struct socket *so, struct mbuf *m, struct sockaddr *nam, struct mbuf *control, struct lwp *l) { - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); struct sockaddr_in6 tmp; struct sockaddr_in6 *dst; int error = 0; KASSERT(solocked(so)); - KASSERT(in6p != NULL); + KASSERT(inp != NULL); KASSERT(m != NULL); /* @@ -877,7 +875,7 @@ rip6_send(struct socket *so, struct mbuf *m, struct sockaddr *nam, goto release; } /* XXX */ - sockaddr_in6_init(&tmp, &in6p->in6p_faddr, 0, 0, 0); + sockaddr_in6_init(&tmp, &inp->inp_faddr6, 0, 0, 0); dst = &tmp; } else { if (nam == NULL) { diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c index 6bfa111ee6d..8e5bc819e72 100644 --- a/sys/netinet6/udp6_usrreq.c +++ b/sys/netinet6/udp6_usrreq.c @@ -134,7 +134,7 @@ static int udp6_sendspace = 9216; /* really max datagram size */ static int udp6_recvspace = 40 * (1024 + sizeof(struct sockaddr_in6)); /* 40 1K datagrams */ -static void udp6_notify(struct in6pcb *, int); +static void udp6_notify(struct inpcb *, int); static void sysctl_net_inet6_udp6_setup(struct sysctllog **); #ifdef IPSEC static int udp6_espinudp(struct mbuf **, int); @@ -175,11 +175,11 @@ udp6_init(void) * just wake up so that he can collect error status. */ static void -udp6_notify(struct in6pcb *in6p, int errno) +udp6_notify(struct inpcb *inp, int errno) { - in6p->in6p_socket->so_error = errno; - sorwakeup(in6p->in6p_socket); - sowwakeup(in6p->in6p_socket); + inp->inp_socket->so_error = errno; + sorwakeup(inp->inp_socket); + sowwakeup(inp->inp_socket); } void * @@ -193,7 +193,7 @@ udp6_ctlinput(int cmd, const struct sockaddr *sa, void *d) void *cmdarg; struct ip6ctlparam *ip6cp = NULL; const struct sockaddr_in6 *sa6_src = NULL; - void (*notify)(struct in6pcb *, int) = udp6_notify; + void (*notify)(struct inpcb *, int) = udp6_notify; struct udp_portonly { u_int16_t uh_sport; u_int16_t uh_dport; @@ -302,7 +302,7 @@ udp6_ctloutput(int op, struct socket *so, struct sockopt *sopt) { int s; int error = 0; - struct in6pcb *in6p; + struct inpcb *inp; int family; int optval; @@ -333,7 +333,7 @@ udp6_ctloutput(int op, struct socket *so, struct sockopt *sopt) switch (op) { case PRCO_SETOPT: - in6p = sotoin6pcb(so); + inp = sotoinpcb(so); switch (sopt->sopt_name) { case UDP_ENCAP: @@ -343,11 +343,11 @@ udp6_ctloutput(int op, struct socket *so, struct sockopt *sopt) switch(optval) { case 0: - in6p->in6p_flags &= ~IN6P_ESPINUDP; + inp->inp_flags &= ~IN6P_ESPINUDP; break; case UDP_ENCAP_ESPINUDP: - in6p->in6p_flags |= IN6P_ESPINUDP; + inp->inp_flags |= IN6P_ESPINUDP; break; default: @@ -378,15 +378,15 @@ udp6_sendup(struct mbuf *m, int off /* offset of data portion */, { struct mbuf *opts = NULL; struct mbuf *n; - struct in6pcb *in6p; + struct inpcb *inp; KASSERT(so != NULL); KASSERT(so->so_proto->pr_domain->dom_family == AF_INET6); - in6p = sotoin6pcb(so); - KASSERT(in6p != NULL); + inp = sotoinpcb(so); + KASSERT(inp != NULL); #if defined(IPSEC) - if (ipsec_used && ipsec_in_reject(m, in6p)) { + if (ipsec_used && ipsec_in_reject(m, inp)) { if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) icmp6_error(n, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN, 0); @@ -395,10 +395,10 @@ udp6_sendup(struct mbuf *m, int off /* offset of data portion */, #endif if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) { - if (in6p->in6p_flags & IN6P_CONTROLOPTS || - SOOPT_TIMESTAMP(in6p->in6p_socket->so_options)) { + if (inp->inp_flags & IN6P_CONTROLOPTS || + SOOPT_TIMESTAMP(inp->inp_socket->so_options)) { struct ip6_hdr *ip6 = mtod(n, struct ip6_hdr *); - ip6_savecontrol(in6p, &opts, ip6, n); + ip6_savecontrol(inp, &opts, ip6, n); } m_adj(n, off); @@ -421,8 +421,7 @@ udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst, int rcvcnt; struct in6_addr src6, *dst6; const struct in_addr *dst4; - struct inpcb_hdr *inph; - struct in6pcb *in6p; + struct inpcb *inp; struct mbuf *m = *mp; rcvcnt = 0; @@ -469,33 +468,32 @@ udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst, /* * Locate pcb(s) for datagram. */ - TAILQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { - in6p = (struct in6pcb *)inph; - if (in6p->in6p_af != AF_INET6) + TAILQ_FOREACH(inp, &udbtable.inpt_queue, inp_queue) { + if (inp->inp_af != AF_INET6) continue; - if (in6p->in6p_lport != dport) + if (inp->inp_lport != dport) continue; - if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) { - if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, + if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) { + if (!IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, dst6)) continue; } else { if (IN6_IS_ADDR_V4MAPPED(dst6) && - (in6p->in6p_flags & IN6P_IPV6_V6ONLY)) + (inp->inp_flags & IN6P_IPV6_V6ONLY)) continue; } - if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) { - if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr, - &src6) || in6p->in6p_fport != sport) + if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) { + if (!IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, + &src6) || inp->inp_fport != sport) continue; } else { if (IN6_IS_ADDR_V4MAPPED(&src6) && - (in6p->in6p_flags & IN6P_IPV6_V6ONLY)) + (inp->inp_flags & IN6P_IPV6_V6ONLY)) continue; } - udp6_sendup(m, off, sin6tosa(src), in6p->in6p_socket); + udp6_sendup(m, off, sin6tosa(src), inp->inp_socket); rcvcnt++; /* @@ -506,7 +504,7 @@ udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst, * port. It assumes that an application will never * clear these options after setting them. */ - if ((in6p->in6p_socket->so_options & + if ((inp->inp_socket->so_options & (SO_REUSEPORT|SO_REUSEADDR)) == 0) break; } @@ -514,18 +512,18 @@ udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst, /* * Locate pcb for datagram. */ - in6p = in6_pcblookup_connect(&udbtable, &src6, sport, dst6, + inp = in6_pcblookup_connect(&udbtable, &src6, sport, dst6, dport, 0, 0); - if (in6p == 0) { + if (inp == NULL) { UDP_STATINC(UDP_STAT_PCBHASHMISS); - in6p = in6_pcblookup_bind(&udbtable, dst6, dport, 0); - if (in6p == 0) + inp = in6_pcblookup_bind(&udbtable, dst6, dport, 0); + if (inp == NULL) return rcvcnt; } #ifdef IPSEC /* Handle ESP over UDP */ - if (in6p->in6p_flags & IN6P_ESPINUDP) { + if (inp->inp_flags & IN6P_ESPINUDP) { switch (udp6_espinudp(mp, off)) { case -1: /* Error, m was freed */ rcvcnt = -1; @@ -547,10 +545,10 @@ udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst, } #endif - if (in6p->in6p_overudp_cb != NULL) { + if (inp->inp_overudp_cb != NULL) { int ret; - ret = in6p->in6p_overudp_cb(mp, off, in6p->in6p_socket, - sin6tosa(src), in6p->in6p_overudp_arg); + ret = inp->inp_overudp_cb(mp, off, inp->inp_socket, + sin6tosa(src), inp->inp_overudp_arg); switch (ret) { case -1: /* Error, m was freed */ rcvcnt = -1; @@ -571,7 +569,7 @@ udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst, } } - udp6_sendup(m, off, sin6tosa(src), in6p->in6p_socket); + udp6_sendup(m, off, sin6tosa(src), inp->inp_socket); rcvcnt++; } @@ -731,7 +729,7 @@ bad: } int -udp6_output(struct in6pcb * const in6p, struct mbuf *m, +udp6_output(struct inpcb * const inp, struct mbuf *m, struct sockaddr_in6 * const addr6, struct mbuf * const control, struct lwp * const l) { @@ -790,11 +788,11 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, panic("%s: control but no lwp", __func__); } if ((error = ip6_setpktopts(control, &opt, - in6p->in6p_outputopts, l->l_cred, IPPROTO_UDP)) != 0) + inp->inp_outputopts6, l->l_cred, IPPROTO_UDP)) != 0) goto release; optp = &opt; } else - optp = in6p->in6p_outputopts; + optp = inp->inp_outputopts6; if (sin6) { @@ -802,7 +800,7 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, * Slightly different than v4 version in that we call * in6_selectsrc and in6_pcbsetport to fill in the local * address and port rather than in_pcbconnect. in_pcbconnect - * sets in6p_faddr which causes EISCONN below to be hit on + * sets inp_faddr which causes EISCONN below to be hit on * subsequent sendto. */ if (sin6->sin6_port == 0) { @@ -810,7 +808,7 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, goto release; } - if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) { + if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) { /* how about ::ffff:0.0.0.0 case? */ error = EISCONN; goto release; @@ -820,7 +818,7 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, fport = sin6->sin6_port; /* allow 0 port */ if (IN6_IS_ADDR_V4MAPPED(faddr)) { - if ((in6p->in6p_flags & IN6P_IPV6_V6ONLY)) { + if ((inp->inp_flags & IN6P_IPV6_V6ONLY)) { /* * I believe we should explicitly discard the * packet when mapped addresses are disabled, @@ -834,8 +832,8 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, error = EINVAL; goto release; } - if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) && - !IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr)) { + if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) && + !IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)) { /* * when remote addr is an IPv4-mapped address, * local addr should not be an IPv6 address, @@ -854,9 +852,9 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, int bound = curlwp_bind(); error = in6_selectsrc(sin6, optp, - in6p->in6p_moptions, - &in6p->in6p_route, - &in6p->in6p_laddr, &oifp, &psref, &_laddr); + inp->inp_moptions6, + &inp->inp_route, + &inp->inp_laddr6, &oifp, &psref, &_laddr); if (error) laddr = NULL; else @@ -877,7 +875,7 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, * udp_output() directly in this case, and thus we'll * never see this path. */ - if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) { + if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) { struct sockaddr_in sin_dst; struct in_addr ina; struct in_ifaddr *ia4; @@ -887,8 +885,8 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, memcpy(&ina, &faddr->s6_addr[12], sizeof(ina)); sockaddr_in_init(&sin_dst, &ina, 0); bound = curlwp_bind(); - ia4 = in_selectsrc(&sin_dst, &in6p->in6p_route, - in6p->in6p_socket->so_options, NULL, + ia4 = in_selectsrc(&sin_dst, &inp->inp_route, + inp->inp_socket->so_options, NULL, &error, &_psref); if (ia4 == NULL) { curlwp_bindx(bound); @@ -906,7 +904,7 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, laddr = &laddr_mapped; } else { - laddr = &in6p->in6p_laddr; /* XXX */ + laddr = &inp->inp_laddr6; /* XXX */ } } if (laddr == NULL) { @@ -914,33 +912,33 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, error = EADDRNOTAVAIL; goto release; } - if (in6p->in6p_lport == 0) { + if (inp->inp_lport == 0) { /* * Craft a sockaddr_in6 for the local endpoint. Use the * "any" as a base, set the address, and recover the * scope. */ struct sockaddr_in6 lsin6 = - *((const struct sockaddr_in6 *)in6p->in6p_socket->so_proto->pr_domain->dom_sa_any); + *((const struct sockaddr_in6 *)inp->inp_socket->so_proto->pr_domain->dom_sa_any); lsin6.sin6_addr = *laddr; error = sa6_recoverscope(&lsin6); if (error) goto release; - error = in6_pcbsetport(&lsin6, in6p, l); + error = in6_pcbsetport(&lsin6, inp, l); if (error) { - in6p->in6p_laddr = in6addr_any; + inp->inp_laddr6 = in6addr_any; goto release; } } } else { - if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) { + if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) { error = ENOTCONN; goto release; } - if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_faddr)) { - if ((in6p->in6p_flags & IN6P_IPV6_V6ONLY)) + if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) { + if ((inp->inp_flags & IN6P_IPV6_V6ONLY)) { /* * XXX: this case would happen when the @@ -956,9 +954,9 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, } else af = AF_INET; } - laddr = &in6p->in6p_laddr; - faddr = &in6p->in6p_faddr; - fport = in6p->in6p_fport; + laddr = &inp->inp_laddr6; + faddr = &inp->inp_faddr6; + fport = inp->inp_fport; } if (af == AF_INET) @@ -978,7 +976,7 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, * Stuff checksum and output datagram. */ udp6 = (struct udphdr *)(mtod(m, char *) + hlen); - udp6->uh_sport = in6p->in6p_lport; /* lport is always set in the PCB */ + udp6->uh_sport = inp->inp_lport; /* lport is always set in the PCB */ udp6->uh_dport = fport; if (plen <= 0xffff) udp6->uh_ulen = htons((u_int16_t)plen); @@ -989,14 +987,14 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, switch (af) { case AF_INET6: ip6 = mtod(m, struct ip6_hdr *); - ip6->ip6_flow = in6p->in6p_flowinfo & IPV6_FLOWINFO_MASK; + ip6->ip6_flow = inp->inp_flowinfo & IPV6_FLOWINFO_MASK; ip6->ip6_vfc &= ~IPV6_VERSION_MASK; ip6->ip6_vfc |= IPV6_VERSION; #if 0 /* ip6_plen will be filled in ip6_output. */ ip6->ip6_plen = htons((u_int16_t)plen); #endif ip6->ip6_nxt = IPPROTO_UDP; - ip6->ip6_hlim = in6_selecthlim_rt(in6p); + ip6->ip6_hlim = in6_selecthlim_rt(inp); ip6->ip6_src = *laddr; ip6->ip6_dst = *faddr; @@ -1006,8 +1004,8 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum); UDP6_STATINC(UDP6_STAT_OPACKETS); - error = ip6_output(m, optp, &in6p->in6p_route, 0, - in6p->in6p_moptions, in6p, NULL); + error = ip6_output(m, optp, &inp->inp_route, 0, + inp->inp_moptions6, inp, NULL); break; case AF_INET: #ifdef INET @@ -1025,7 +1023,7 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, memcpy(&ui->ui_src, &laddr->s6_addr[12], sizeof(ui->ui_src)); ui->ui_ulen = ui->ui_len; - flags = (in6p->in6p_socket->so_options & + flags = (inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST)); memcpy(&ui->ui_dst, &faddr->s6_addr[12], sizeof(ui->ui_dst)); @@ -1034,12 +1032,12 @@ udp6_output(struct in6pcb * const in6p, struct mbuf *m, udp6->uh_sum = 0xffff; ip->ip_len = htons(hlen + plen); - ip->ip_ttl = in6_selecthlim(in6p, NULL); /* XXX */ + ip->ip_ttl = in6_selecthlim(inp, NULL); /* XXX */ ip->ip_tos = 0; /* XXX */ UDP_STATINC(UDP_STAT_OPACKETS); - error = ip_output(m, NULL, &in6p->in6p_route, flags /* XXX */, - in6p->in6p_v4moptions, NULL); + error = ip_output(m, NULL, &inp->inp_route, flags /* XXX */, + inp->inp_moptions, NULL); break; #else error = EAFNOSUPPORT; @@ -1063,10 +1061,10 @@ releaseopt: static int udp6_attach(struct socket *so, int proto) { - struct in6pcb *in6p; + struct inpcb *inp; int s, error; - KASSERT(sotoin6pcb(so) == NULL); + KASSERT(sotoinpcb(so) == NULL); sosetlock(so); error = soreserve(so, udp6_sendspace, udp6_recvspace); @@ -1079,14 +1077,14 @@ udp6_attach(struct socket *so, int proto) * Always attach for IPv6, and only when necessary for IPv4. */ s = splsoftnet(); - error = in6_pcballoc(so, &udbtable); + error = in_pcballoc(so, &udbtable); splx(s); if (error) { return error; } - in6p = sotoin6pcb(so); - in6p->in6p_cksum = -1; /* just to be sure */ + inp = sotoinpcb(so); + inp->inp_cksum6 = -1; /* just to be sure */ KASSERT(solocked(so)); return 0; @@ -1095,14 +1093,14 @@ udp6_attach(struct socket *so, int proto) static void udp6_detach(struct socket *so) { - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); int s; KASSERT(solocked(so)); - KASSERT(in6p != NULL); + KASSERT(inp != NULL); s = splsoftnet(); - in6_pcbdetach(in6p); + in_pcbdetach(inp); splx(s); } @@ -1117,16 +1115,16 @@ udp6_accept(struct socket *so, struct sockaddr *nam) static int udp6_bind(struct socket *so, struct sockaddr *nam, struct lwp *l) { - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam; int error = 0; int s; KASSERT(solocked(so)); - KASSERT(in6p != NULL); + KASSERT(inp != NULL); s = splsoftnet(); - error = in6_pcbbind(in6p, sin6, l); + error = in6_pcbbind(inp, sin6, l); splx(s); return error; } @@ -1142,17 +1140,17 @@ udp6_listen(struct socket *so, struct lwp *l) static int udp6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) { - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); int error = 0; int s; KASSERT(solocked(so)); - KASSERT(in6p != NULL); + KASSERT(inp != NULL); - if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) + if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) return EISCONN; s = splsoftnet(); - error = in6_pcbconnect(in6p, (struct sockaddr_in6 *)nam, l); + error = in6_pcbconnect(inp, (struct sockaddr_in6 *)nam, l); splx(s); if (error == 0) soisconnected(so); @@ -1171,22 +1169,22 @@ udp6_connect2(struct socket *so, struct socket *so2) static int udp6_disconnect(struct socket *so) { - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); int s; KASSERT(solocked(so)); - KASSERT(in6p != NULL); + KASSERT(inp != NULL); - if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) + if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) return ENOTCONN; s = splsoftnet(); - in6_pcbdisconnect(in6p); - memset((void *)&in6p->in6p_laddr, 0, sizeof(in6p->in6p_laddr)); + in6_pcbdisconnect(inp); + memset((void *)&inp->inp_laddr6, 0, sizeof(inp->inp_laddr6)); splx(s); so->so_state &= ~SS_ISCONNECTED; /* XXX */ - in6_pcbstate(in6p, IN6P_BOUND); /* XXX */ + in6_pcbstate(inp, INP_BOUND); /* XXX */ return 0; } @@ -1208,11 +1206,11 @@ udp6_abort(struct socket *so) int s; KASSERT(solocked(so)); - KASSERT(sotoin6pcb(so) != NULL); + KASSERT(sotoinpcb(so) != NULL); s = splsoftnet(); soisdisconnected(so); - in6_pcbdetach(sotoin6pcb(so)); + in_pcbdetach(sotoinpcb(so)); splx(s); return 0; @@ -1247,10 +1245,10 @@ static int udp6_peeraddr(struct socket *so, struct sockaddr *nam) { KASSERT(solocked(so)); - KASSERT(sotoin6pcb(so) != NULL); + KASSERT(sotoinpcb(so) != NULL); KASSERT(nam != NULL); - in6_setpeeraddr(sotoin6pcb(so), (struct sockaddr_in6 *)nam); + in6_setpeeraddr(sotoinpcb(so), (struct sockaddr_in6 *)nam); return 0; } @@ -1258,10 +1256,10 @@ static int udp6_sockaddr(struct socket *so, struct sockaddr *nam) { KASSERT(solocked(so)); - KASSERT(sotoin6pcb(so) != NULL); + KASSERT(sotoinpcb(so) != NULL); KASSERT(nam != NULL); - in6_setsockaddr(sotoin6pcb(so), (struct sockaddr_in6 *)nam); + in6_setsockaddr(sotoinpcb(so), (struct sockaddr_in6 *)nam); return 0; } @@ -1285,16 +1283,16 @@ static int udp6_send(struct socket *so, struct mbuf *m, struct sockaddr *nam, struct mbuf *control, struct lwp *l) { - struct in6pcb *in6p = sotoin6pcb(so); + struct inpcb *inp = sotoinpcb(so); int error = 0; int s; KASSERT(solocked(so)); - KASSERT(in6p != NULL); + KASSERT(inp != NULL); KASSERT(m != NULL); s = splsoftnet(); - error = udp6_output(in6p, m, (struct sockaddr_in6 *)nam, control, l); + error = udp6_output(inp, m, (struct sockaddr_in6 *)nam, control, l); splx(s); return error; diff --git a/sys/netinet6/udp6_var.h b/sys/netinet6/udp6_var.h index c0e7864f7ae..a2e61d87fa1 100644 --- a/sys/netinet6/udp6_var.h +++ b/sys/netinet6/udp6_var.h @@ -97,7 +97,7 @@ void *udp6_ctlinput(int, const struct sockaddr *, void *); int udp6_ctloutput(int, struct socket *, struct sockopt *); void udp6_init(void); int udp6_input(struct mbuf **, int *, int); -int udp6_output(struct in6pcb *, struct mbuf *, struct sockaddr_in6 *, +int udp6_output(struct inpcb *, struct mbuf *, struct sockaddr_in6 *, struct mbuf *, struct lwp *); int udp6_sysctl(int *, u_int, void *, size_t *, void *, size_t); int udp6_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, diff --git a/sys/netipsec/ipsec.c b/sys/netipsec/ipsec.c index 759afaef807..40aa0262c32 100644 --- a/sys/netipsec/ipsec.c +++ b/sys/netipsec/ipsec.c @@ -160,7 +160,7 @@ static int ipsec_invalpcbcache(struct inpcbpolicy *, int); int crypto_support = 0; static struct secpolicy *ipsec_getpolicybysock(struct mbuf *, u_int, - struct inpcb_hdr *, int *); + struct inpcb *, int *); #ifdef INET6 int ip6_esp_trans_deflev = IPSEC_LEVEL_USE; @@ -171,7 +171,7 @@ struct secpolicy ip6_def_policy; int ip6_ipsec_ecn = 0; /* ECN ignore(-1)/forbidden(0)/allowed(1) */ #endif -static int ipsec_setspidx_inpcb(struct mbuf *, void *); +static int ipsec_setspidx_inpcb(struct mbuf *, struct inpcb *); static int ipsec_setspidx(struct mbuf *, struct secpolicyindex *, int, int); static void ipsec4_get_ulp(struct mbuf *m, struct secpolicyindex *, int); static int ipsec4_setspidx_ipaddr(struct mbuf *, struct secpolicyindex *); @@ -198,7 +198,7 @@ ipsec_checkpcbcache(struct mbuf *m, struct inpcbpolicy *pcbsp, int dir) KASSERT(IPSEC_DIR_IS_VALID(dir)); KASSERT(pcbsp != NULL); KASSERT(dir < __arraycount(pcbsp->sp_cache)); - KASSERT(inph_locked(pcbsp->sp_inph)); + KASSERT(inp_locked(pcbsp->sp_inp)); /* * Checking the generation and sp->state and taking a reference to an SP @@ -265,7 +265,7 @@ ipsec_fillpcbcache(struct inpcbpolicy *pcbsp, struct mbuf *m, KASSERT(IPSEC_DIR_IS_INOROUT(dir)); KASSERT(dir < __arraycount(pcbsp->sp_cache)); - KASSERT(inph_locked(pcbsp->sp_inph)); + KASSERT(inp_locked(pcbsp->sp_inp)); pcbsp->sp_cache[dir].cachesp = NULL; pcbsp->sp_cache[dir].cachehint = IPSEC_PCBHINT_UNKNOWN; @@ -301,7 +301,7 @@ ipsec_invalpcbcache(struct inpcbpolicy *pcbsp, int dir) { int i; - KASSERT(inph_locked(pcbsp->sp_inph)); + KASSERT(inp_locked(pcbsp->sp_inp)); for (i = IPSEC_DIR_INBOUND; i <= IPSEC_DIR_OUTBOUND; i++) { if (dir != IPSEC_DIR_ANY && i != dir) @@ -319,7 +319,7 @@ void ipsec_pcbconn(struct inpcbpolicy *pcbsp) { - KASSERT(inph_locked(pcbsp->sp_inph)); + KASSERT(inp_locked(pcbsp->sp_inp)); pcbsp->sp_cacheflags |= IPSEC_PCBSP_CONNECTED; ipsec_invalpcbcache(pcbsp, IPSEC_DIR_ANY); @@ -329,7 +329,7 @@ void ipsec_pcbdisconn(struct inpcbpolicy *pcbsp) { - KASSERT(inph_locked(pcbsp->sp_inph)); + KASSERT(inp_locked(pcbsp->sp_inp)); pcbsp->sp_cacheflags &= ~IPSEC_PCBSP_CONNECTED; ipsec_invalpcbcache(pcbsp, IPSEC_DIR_ANY); @@ -399,7 +399,7 @@ key_get_default_sp(int af, const char *where, int tag) * NOTE: IPv6 mapped address concern is implemented here. */ static struct secpolicy * -ipsec_getpolicybysock(struct mbuf *m, u_int dir, struct inpcb_hdr *inph, +ipsec_getpolicybysock(struct mbuf *m, u_int dir, struct inpcb *inp, int *error) { struct inpcbpolicy *pcbsp = NULL; @@ -408,22 +408,22 @@ ipsec_getpolicybysock(struct mbuf *m, u_int dir, struct inpcb_hdr *inph, int af; KASSERT(m != NULL); - KASSERT(inph != NULL); + KASSERT(inp != NULL); KASSERT(error != NULL); KASSERTMSG(IPSEC_DIR_IS_INOROUT(dir), "invalid direction %u", dir); - KASSERT(inph->inph_socket != NULL); - KASSERT(inph_locked(inph)); + KASSERT(inp->inp_socket != NULL); + KASSERT(inp_locked(inp)); - /* XXX FIXME inpcb/in6pcb vs socket*/ - af = inph->inph_af; + /* XXX FIXME inpcb vs socket*/ + af = inp->inp_af; KASSERTMSG(af == AF_INET || af == AF_INET6, "unexpected protocol family %u", af); - KASSERT(inph->inph_sp != NULL); + KASSERT(inp->inp_sp != NULL); /* If we have a cached entry, and if it is still valid, use it. */ IPSEC_STATINC(IPSEC_STAT_SPDCACHELOOKUP); - currsp = ipsec_checkpcbcache(m, inph->inph_sp, dir); + currsp = ipsec_checkpcbcache(m, inp->inp_sp, dir); if (currsp) { *error = 0; return currsp; @@ -435,8 +435,8 @@ ipsec_getpolicybysock(struct mbuf *m, u_int dir, struct inpcb_hdr *inph, #if defined(INET6) case AF_INET6: #endif - *error = ipsec_setspidx_inpcb(m, inph); - pcbsp = inph->inph_sp; + *error = ipsec_setspidx_inpcb(m, inp); + pcbsp = inp->inp_sp; break; default: *error = EPFNOSUPPORT; @@ -566,7 +566,7 @@ ipsec_getpolicybyaddr(struct mbuf *m, u_int dir, int flag, int *error) static struct secpolicy * ipsec_checkpolicy(struct mbuf *m, u_int dir, u_int flag, int *error, - void *inp) + struct inpcb *inp) { struct secpolicy *sp; @@ -575,9 +575,8 @@ ipsec_checkpolicy(struct mbuf *m, u_int dir, u_int flag, int *error, if (inp == NULL) { sp = ipsec_getpolicybyaddr(m, dir, flag, error); } else { - struct inpcb_hdr *inph = (struct inpcb_hdr *)inp; - KASSERT(inph->inph_socket != NULL); - sp = ipsec_getpolicybysock(m, dir, inph, error); + KASSERT(inp->inp_socket != NULL); + sp = ipsec_getpolicybysock(m, dir, inp, error); } if (sp == NULL) { KASSERTMSG(*error != 0, "getpolicy failed w/o error"); @@ -788,26 +787,25 @@ ipsec_mtu(struct mbuf *m, int *destmtu) } static int -ipsec_setspidx_inpcb(struct mbuf *m, void *pcb) +ipsec_setspidx_inpcb(struct mbuf *m, struct inpcb *inp) { - struct inpcb_hdr *inph = (struct inpcb_hdr *)pcb; int error; - KASSERT(inph != NULL); - KASSERT(inph->inph_sp != NULL); - KASSERT(inph->inph_sp->sp_out != NULL); - KASSERT(inph->inph_sp->sp_in != NULL); + KASSERT(inp != NULL); + KASSERT(inp->inp_sp != NULL); + KASSERT(inp->inp_sp->sp_out != NULL); + KASSERT(inp->inp_sp->sp_in != NULL); - error = ipsec_setspidx(m, &inph->inph_sp->sp_in->spidx, + error = ipsec_setspidx(m, &inp->inp_sp->sp_in->spidx, IPSEC_DIR_INBOUND, 1); if (error == 0) { - inph->inph_sp->sp_out->spidx = inph->inph_sp->sp_in->spidx; - inph->inph_sp->sp_out->spidx.dir = IPSEC_DIR_OUTBOUND; + inp->inp_sp->sp_out->spidx = inp->inp_sp->sp_in->spidx; + inp->inp_sp->sp_out->spidx.dir = IPSEC_DIR_OUTBOUND; } else { - memset(&inph->inph_sp->sp_in->spidx, 0, - sizeof(inph->inph_sp->sp_in->spidx)); - memset(&inph->inph_sp->sp_out->spidx, 0, - sizeof(inph->inph_sp->sp_out->spidx)); + memset(&inp->inp_sp->sp_in->spidx, 0, + sizeof(inp->inp_sp->sp_in->spidx)); + memset(&inp->inp_sp->sp_out->spidx, 0, + sizeof(inp->inp_sp->sp_out->spidx)); } return error; } @@ -1144,33 +1142,32 @@ ipsec_destroy_policy(struct secpolicy *sp) } int -ipsec_set_policy(void *inp, const void *request, size_t len, +ipsec_set_policy(struct inpcb *inp, const void *request, size_t len, kauth_cred_t cred) { - struct inpcb_hdr *inph = (struct inpcb_hdr *)inp; const struct sadb_x_policy *xpl; struct secpolicy *newsp, *oldsp; struct secpolicy **policy; int error; KASSERT(!cpu_softintr_p()); - KASSERT(inph != NULL); - KASSERT(inph_locked(inph)); + KASSERT(inp != NULL); + KASSERT(inp_locked(inp)); KASSERT(request != NULL); if (len < sizeof(*xpl)) return EINVAL; xpl = (const struct sadb_x_policy *)request; - KASSERT(inph->inph_sp != NULL); + KASSERT(inp->inp_sp != NULL); /* select direction */ switch (xpl->sadb_x_policy_dir) { case IPSEC_DIR_INBOUND: - policy = &inph->inph_sp->sp_in; + policy = &inp->inp_sp->sp_in; break; case IPSEC_DIR_OUTBOUND: - policy = &inph->inph_sp->sp_out; + policy = &inp->inp_sp->sp_out; break; default: IPSECLOG(LOG_ERR, "invalid direction=%u\n", @@ -1223,17 +1220,16 @@ ipsec_set_policy(void *inp, const void *request, size_t len, } int -ipsec_get_policy(void *inp, const void *request, size_t len, +ipsec_get_policy(struct inpcb *inp, const void *request, size_t len, struct mbuf **mp) { - struct inpcb_hdr *inph = (struct inpcb_hdr *)inp; const struct sadb_x_policy *xpl; struct secpolicy *policy; /* sanity check. */ - if (inph == NULL || request == NULL || mp == NULL) + if (inp == NULL || request == NULL || mp == NULL) return EINVAL; - KASSERT(inph->inph_sp != NULL); + KASSERT(inp->inp_sp != NULL); if (len < sizeof(*xpl)) return EINVAL; xpl = (const struct sadb_x_policy *)request; @@ -1241,10 +1237,10 @@ ipsec_get_policy(void *inp, const void *request, size_t len, /* select direction */ switch (xpl->sadb_x_policy_dir) { case IPSEC_DIR_INBOUND: - policy = inph->inph_sp->sp_in; + policy = inp->inp_sp->sp_in; break; case IPSEC_DIR_OUTBOUND: - policy = inph->inph_sp->sp_out; + policy = inp->inp_sp->sp_out; break; default: IPSECLOG(LOG_ERR, "invalid direction=%u\n", @@ -1269,25 +1265,24 @@ ipsec_get_policy(void *inp, const void *request, size_t len, } int -ipsec_delete_pcbpolicy(void *inp) +ipsec_delete_pcbpolicy(struct inpcb *inp) { - struct inpcb_hdr *inph = (struct inpcb_hdr *)inp; - KASSERT(inph != NULL); + KASSERT(inp != NULL); - if (inph->inph_sp == NULL) + if (inp->inp_sp == NULL) return 0; - if (inph->inph_sp->sp_in != NULL) - ipsec_destroy_policy(inph->inph_sp->sp_in); + if (inp->inp_sp->sp_in != NULL) + ipsec_destroy_policy(inp->inp_sp->sp_in); - if (inph->inph_sp->sp_out != NULL) - ipsec_destroy_policy(inph->inph_sp->sp_out); + if (inp->inp_sp->sp_out != NULL) + ipsec_destroy_policy(inp->inp_sp->sp_out); - ipsec_invalpcbcache(inph->inph_sp, IPSEC_DIR_ANY); + ipsec_invalpcbcache(inp->inp_sp, IPSEC_DIR_ANY); - ipsec_delpcbpolicy(inph->inph_sp); - inph->inph_sp = NULL; + ipsec_delpcbpolicy(inp->inp_sp); + inp->inp_sp = NULL; return 0; } @@ -1453,21 +1448,20 @@ ipsec_sp_reject(const struct secpolicy *sp, const struct mbuf *m) * Check security policy requirements. */ int -ipsec_in_reject(struct mbuf *m, void *inp) +ipsec_in_reject(struct mbuf *m, struct inpcb *inp) { - struct inpcb_hdr *inph = (struct inpcb_hdr *)inp; struct secpolicy *sp; int error; int result; KASSERT(m != NULL); - if (inph == NULL) + if (inp == NULL) sp = ipsec_getpolicybyaddr(m, IPSEC_DIR_INBOUND, IP_FORWARDING, &error); else sp = ipsec_getpolicybysock(m, IPSEC_DIR_INBOUND, - inph, &error); + inp, &error); if (sp != NULL) { result = ipsec_sp_reject(sp, m); @@ -1557,21 +1551,20 @@ ipsec_sp_hdrsiz(const struct secpolicy *sp, const struct mbuf *m) } size_t -ipsec_hdrsiz(struct mbuf *m, u_int dir, void *inp) +ipsec_hdrsiz(struct mbuf *m, u_int dir, struct inpcb *inp) { - struct inpcb_hdr *inph = (struct inpcb_hdr *)inp; struct secpolicy *sp; int error; size_t size; KASSERT(m != NULL); - KASSERTMSG(inph == NULL || inph->inph_socket != NULL, + KASSERTMSG(inp == NULL || inp->inp_socket != NULL, "socket w/o inpcb"); - if (inph == NULL) + if (inp == NULL) sp = ipsec_getpolicybyaddr(m, dir, IP_FORWARDING, &error); else - sp = ipsec_getpolicybysock(m, dir, inph, &error); + sp = ipsec_getpolicybysock(m, dir, inp, &error); if (sp != NULL) { size = ipsec_sp_hdrsiz(sp, m); @@ -1804,7 +1797,7 @@ ipsec_logsastr(const struct secasvar *sav, char *buf, size_t size) #ifdef INET6 struct secpolicy * -ipsec6_check_policy(struct mbuf *m, struct in6pcb *in6p, int flags, +ipsec6_check_policy(struct mbuf *m, struct inpcb *inp, int flags, int *needipsecp, int *errorp) { struct secpolicy *sp = NULL; @@ -1816,11 +1809,11 @@ ipsec6_check_policy(struct mbuf *m, struct in6pcb *in6p, int flags, goto skippolicycheck; } s = splsoftnet(); - if (in6p && ipsec_pcb_skip_ipsec(in6p->in6p_sp, IPSEC_DIR_OUTBOUND)) { + if (inp && ipsec_pcb_skip_ipsec(inp->inp_sp, IPSEC_DIR_OUTBOUND)) { splx(s); goto skippolicycheck; } - sp = ipsec_checkpolicy(m, IPSEC_DIR_OUTBOUND, flags, &error, in6p); + sp = ipsec_checkpolicy(m, IPSEC_DIR_OUTBOUND, flags, &error, inp); splx(s); /* diff --git a/sys/netipsec/ipsec.h b/sys/netipsec/ipsec.h index e04ec05222a..16a5af64a3f 100644 --- a/sys/netipsec/ipsec.h +++ b/sys/netipsec/ipsec.h @@ -45,7 +45,7 @@ #include #include -#include +#include #include /* @@ -126,7 +126,7 @@ struct inpcbpolicy { } sp_cache[3]; /* XXX 3 == IPSEC_DIR_MAX */ int sp_cacheflags; #define IPSEC_PCBSP_CONNECTED 1 - struct inpcb_hdr *sp_inph; /* back pointer */ + struct inpcb *sp_inp; /* back pointer */ }; extern u_int ipsec_spdgen; @@ -135,7 +135,7 @@ static __inline bool ipsec_pcb_skip_ipsec(struct inpcbpolicy *pcbsp, int dir) { - KASSERT(inph_locked(pcbsp->sp_inph)); + KASSERT(inp_locked(pcbsp->sp_inp)); return pcbsp->sp_cache[(dir)].cachehint == IPSEC_PCBHINT_NO && pcbsp->sp_cache[(dir)].cachegen == ipsec_spdgen; @@ -288,10 +288,10 @@ int ipsec_init_pcbpolicy(struct socket *so, struct inpcbpolicy **); int ipsec_copy_policy(const struct inpcbpolicy *, struct inpcbpolicy *); u_int ipsec_get_reqlevel(const struct ipsecrequest *); -int ipsec_set_policy(void *, const void *, size_t, kauth_cred_t); -int ipsec_get_policy(void *, const void *, size_t, struct mbuf **); -int ipsec_delete_pcbpolicy(void *); -int ipsec_in_reject(struct mbuf *, void *); +int ipsec_set_policy(struct inpcb *, const void *, size_t, kauth_cred_t); +int ipsec_get_policy(struct inpcb *, const void *, size_t, struct mbuf **); +int ipsec_delete_pcbpolicy(struct inpcb *); +int ipsec_in_reject(struct mbuf *, struct inpcb *); struct secasvar *ipsec_lookup_sa(const struct ipsecrequest *, const struct mbuf *); @@ -301,7 +301,7 @@ struct tcpcb; int ipsec_chkreplay(u_int32_t, const struct secasvar *); int ipsec_updatereplay(u_int32_t, const struct secasvar *); -size_t ipsec_hdrsiz(struct mbuf *, u_int, void *); +size_t ipsec_hdrsiz(struct mbuf *, u_int, struct inpcb *); size_t ipsec4_hdrsiz_tcp(struct tcpcb *); union sockaddr_union; diff --git a/sys/netipsec/ipsec6.h b/sys/netipsec/ipsec6.h index ca123b47a61..a165b082d1b 100644 --- a/sys/netipsec/ipsec6.h +++ b/sys/netipsec/ipsec6.h @@ -46,10 +46,10 @@ extern int ip6_ah_net_deflev; extern int ip6_ipsec_ecn; extern struct secpolicy ip6_def_policy; -struct in6pcb; +struct inpcb; struct tcp6cb; -struct secpolicy *ipsec6_check_policy(struct mbuf *, struct in6pcb *, +struct secpolicy *ipsec6_check_policy(struct mbuf *, struct inpcb *, int, int *, int *); size_t ipsec6_hdrsiz_tcp(struct tcpcb *); diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c index ac60673beea..286a38c3580 100644 --- a/usr.bin/fstat/fstat.c +++ b/usr.bin/fstat/fstat.c @@ -1062,9 +1062,6 @@ socktrans(struct file *f, struct socket *sock, int i) struct protosw proto; struct domain dom; struct inpcb inpcb; -#ifdef INET6 - struct in6pcb in6pcb; -#endif struct unpcb unpcb; struct ddpcb ddpcb; int len; @@ -1150,15 +1147,15 @@ socktrans(struct file *f, struct socket *sock, int i) case IPPROTO_TCP: if (so.so_pcb == NULL) break; - if (kvm_read(kd, (u_long)so.so_pcb, (char *)&in6pcb, - sizeof(in6pcb)) != sizeof(in6pcb)) { - dprintf("can't read in6pcb at %p", so.so_pcb); + if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb, + sizeof(inpcb)) != sizeof(inpcb)) { + dprintf("can't read inpcb at %p", so.so_pcb); goto bad; } - inet6_addrstr(lbuf, sizeof(lbuf), &in6pcb.in6p_laddr, - ntohs(in6pcb.in6p_lport), isdgram); - inet6_addrstr(fbuf, sizeof(fbuf), &in6pcb.in6p_faddr, - ntohs(in6pcb.in6p_fport), isdgram); + inet6_addrstr(lbuf, sizeof(lbuf), &inpcb.inp_laddr6, + ntohs(inpcb.inp_lport), isdgram); + inet6_addrstr(fbuf, sizeof(fbuf), &inpcb.inp_faddr6, + ntohs(inpcb.inp_fport), isdgram); break; default: break; diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index 4b0c79b96d8..a338da3e0f6 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -275,7 +275,7 @@ static struct kinfo_pcb * getpcblist_kmem(u_long off, const char *name, size_t *len) { struct inpcbtable table; - struct inpcb_hdr *next, *prev; + struct inpcb *next, *prev; struct inpcb inpcb; struct tcpcb tcpcb; struct socket sockb; @@ -1084,8 +1084,8 @@ tcp_dump(u_long off, const char *name, u_long pcbaddr) printf("State: %d", tcpcb.t_state); else printf("State: %s", tcpstates[tcpcb.t_state]); - printf(", flags 0x%x, inpcb 0x%lx, in6pcb 0x%lx\n\n", tcpcb.t_flags, - (u_long)tcpcb.t_inpcb, (u_long)tcpcb.t_in6pcb); + printf(", flags 0x%x, inpcb 0x%lx\n\n", tcpcb.t_flags, + (u_long)tcpcb.t_inpcb); printf("rxtshift %d, rxtcur %d, dupacks %d\n", tcpcb.t_rxtshift, tcpcb.t_rxtcur, tcpcb.t_dupacks); diff --git a/usr.bin/netstat/inet6.c b/usr.bin/netstat/inet6.c index c36a21d0328..da69035e444 100644 --- a/usr.bin/netstat/inet6.c +++ b/usr.bin/netstat/inet6.c @@ -141,7 +141,7 @@ extern const char * const tcptimers[]; #ifdef INET6 -struct in6pcb in6pcb; +struct inpcb inpcb; #ifdef TCP6 struct tcp6cb tcp6cb; #else @@ -287,7 +287,7 @@ getpcblist_kmem(u_long off, const char *name, size_t *len) { struct socket sockb; struct inpcbtable table; - struct inpcb_hdr *next, *prev; + struct inpcb *next, *prev; int istcp = strcmp(name, "tcp6") == 0; struct kinfo_pcb *pcblist; size_t size = 100, i; @@ -309,33 +309,33 @@ getpcblist_kmem(u_long off, const char *name, size_t *len) i = 0; while (next != TAILQ_END(head)) { - kread((u_long)next, (char *)&in6pcb, sizeof in6pcb); - next = TAILQ_NEXT(&in6pcb, in6p_queue); + kread((u_long)next, (char *)&inpcb, sizeof inpcb); + next = TAILQ_NEXT(&inpcb, inp_queue); prev = next; - if (in6pcb.in6p_af != AF_INET6) + if (inpcb.inp_af != AF_INET6) continue; - kread((u_long)in6pcb.in6p_socket, (char *)&sockb, + kread((u_long)inpcb.inp_socket, (char *)&sockb, sizeof (sockb)); if (istcp) { #ifdef TCP6 - kread((u_long)in6pcb.in6p_ppcb, + kread((u_long)inpcb.inp_ppcb, (char *)&tcp6cb, sizeof (tcp6cb)); #else - kread((u_long)in6pcb.in6p_ppcb, + kread((u_long)inpcb.inp_ppcb, (char *)&tcpcb, sizeof (tcpcb)); #endif } pcblist[i].ki_ppcbaddr = - istcp ? (uintptr_t) in6pcb.in6p_ppcb : (uintptr_t) prev; + istcp ? (uintptr_t) inpcb.inp_ppcb : (uintptr_t) prev; pcblist[i].ki_rcvq = (uint64_t)sockb.so_rcv.sb_cc; pcblist[i].ki_sndq = (uint64_t)sockb.so_snd.sb_cc; - sin6.sin6_addr = in6pcb.in6p_laddr; - sin6.sin6_port = in6pcb.in6p_lport; + sin6.sin6_addr = inpcb.inp_laddr6; + sin6.sin6_port = inpcb.inp_lport; memcpy(&pcblist[i].ki_s, &sin6, sizeof(sin6)); - sin6.sin6_addr = in6pcb.in6p_faddr; - sin6.sin6_port = in6pcb.in6p_fport; + sin6.sin6_addr = inpcb.inp_faddr6; + sin6.sin6_port = inpcb.inp_fport; memcpy(&pcblist[i].ki_d, &sin6, sizeof(sin6)); pcblist[i].ki_tstate = tcpcb.t_state; if (i++ == size) { @@ -1431,7 +1431,7 @@ inet6print(const struct in6_addr *in6, int port, const char *proto) */ char * -inet6name(const struct in6_addr *in6p) +inet6name(const struct in6_addr *inp) { char *cp; static char line[NI_MAXHOST]; @@ -1451,8 +1451,8 @@ inet6name(const struct in6_addr *in6p) domain[0] = 0; } cp = 0; - if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) { - hp = gethostbyaddr((const char *)in6p, sizeof(*in6p), AF_INET6); + if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(inp)) { + hp = gethostbyaddr((const char *)inp, sizeof(*inp), AF_INET6); if (hp) { if ((cp = strchr(hp->h_name, '.')) && !strcmp(cp + 1, domain)) @@ -1460,7 +1460,7 @@ inet6name(const struct in6_addr *in6p) cp = hp->h_name; } } - if (IN6_IS_ADDR_UNSPECIFIED(in6p)) + if (IN6_IS_ADDR_UNSPECIFIED(inp)) strlcpy(line, "*", sizeof(line)); else if (cp) strlcpy(line, cp, sizeof(line)); @@ -1468,7 +1468,7 @@ inet6name(const struct in6_addr *in6p) memset(&sin6, 0, sizeof(sin6)); sin6.sin6_len = sizeof(sin6); sin6.sin6_family = AF_INET6; - sin6.sin6_addr = *in6p; + sin6.sin6_addr = *inp; inet6_getscopeid(&sin6, INET6_IS_ADDR_LINKLOCAL | INET6_IS_ADDR_MC_LINKLOCAL); if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, @@ -1529,8 +1529,8 @@ tcp6_dump(u_long off, const char *name, u_long pcbaddr) printf("State: %d", mypcb.t_state); else printf("State: %s", tcp6states[mypcb.t_state]); - printf(", flags 0x%x, in6pcb 0x%lx\n\n", mypcb.t_flags, - (u_long)mypcb.t_in6pcb); + printf(", flags 0x%x, inpcb 0x%lx\n\n", mypcb.t_flags, + (u_long)mypcb.t_inpcb); printf("rxtshift %d, rxtcur %d, dupacks %d\n", mypcb.t_rxtshift, mypcb.t_rxtcur, mypcb.t_dupacks); diff --git a/usr.bin/sockstat/sockstat.c b/usr.bin/sockstat/sockstat.c index b6dd75f097a..33181b5309c 100644 --- a/usr.bin/sockstat/sockstat.c +++ b/usr.bin/sockstat/sockstat.c @@ -47,7 +47,6 @@ __RCSID("$NetBSD: sockstat.c,v 1.24 2021/08/27 18:09:30 rillig Exp $"); #include #include #include -#include #include #define _KMEMUSER diff --git a/usr.bin/systat/extern.h b/usr.bin/systat/extern.h index 2ccdcc9cc16..98817cd598a 100644 --- a/usr.bin/systat/extern.h +++ b/usr.bin/systat/extern.h @@ -67,15 +67,11 @@ extern double etime; extern bool showzero; struct inpcb; -#ifdef INET6 -struct in6pcb; -#endif int checkhost(struct inpcb *); int checkport(struct inpcb *); #ifdef INET6 -int checkhost6(struct in6pcb *); -int checkport6(struct in6pcb *); +int checkhost6(struct inpcb *); #endif void closebufcache(WINDOW *); void closedf(WINDOW *); diff --git a/usr.bin/systat/netcmds.c b/usr.bin/systat/netcmds.c index 123c2381f27..d0383a31a0b 100644 --- a/usr.bin/systat/netcmds.c +++ b/usr.bin/systat/netcmds.c @@ -245,20 +245,6 @@ checkport(struct inpcb *inp) return (1); } -#ifdef INET6 -int -checkport6(struct in6pcb *in6p) -{ - struct pitem *p; - - if (ports) - for (p = ports; p < ports+nports; p++) - if (p->port == in6p->in6p_lport || p->port == in6p->in6p_fport) - return (p->onoff); - return (1); -} -#endif - static void showports(void) { @@ -354,7 +340,7 @@ checkhost(struct inpcb *inp) #ifdef INET6 int -checkhost6(struct in6pcb *in6p) +checkhost6(struct inpcb *inp) { struct hitem *p; struct sockaddr_in6 *sin6; @@ -364,8 +350,8 @@ checkhost6(struct in6pcb *in6p) if (((struct sockaddr *)&p->addr)->sa_family != AF_INET6) continue; sin6 = (struct sockaddr_in6 *)&p->addr; - if (IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &in6p->in6p_laddr) || - IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &in6p->in6p_faddr)) + if (IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &inp->inp_laddr6) || + IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &inp->inp_faddr6)) return (p->onoff); } return (1); diff --git a/usr.bin/systat/netstat.c b/usr.bin/systat/netstat.c index d908dabb793..c05a79e0751 100644 --- a/usr.bin/systat/netstat.c +++ b/usr.bin/systat/netstat.c @@ -83,7 +83,7 @@ static const char *inetname(struct in_addr); static void inetprint(struct in_addr *, int, const char *); #ifdef INET6 static void fetchnetstat6(void *, int); -static void enter6(struct in6pcb *, struct socket *, int, const char *); +static void enter6(struct inpcb *, struct socket *, int, const char *); static const char *inet6name(struct in6_addr *); static void inet6print(struct in6_addr *, int, const char *); #endif @@ -213,7 +213,7 @@ static void fetchnetstat4(void *off, int istcp) { struct inpcbtable pcbtable; - struct inpcb_hdr **pprev, *next; + struct inpcb **pprev, *next; struct netinfo *p; struct inpcb inpcb, *inpcbp; struct socket sockb; @@ -231,7 +231,7 @@ fetchnetstat4(void *off, int istcp) error("Kernel state in transition"); return; } - pprev = &next->inph_queue.tqe_next; + pprev = &next->inp_queue.tqe_next; next = inpcb.inp_queue.tqe_next; if (inpcb.inp_af != AF_INET) @@ -256,41 +256,41 @@ static void fetchnetstat6(void *off, int istcp) { struct inpcbtable pcbtable; - struct inpcb_hdr **pprev, *next; + struct inpcb **pprev, *next; struct netinfo *p; struct socket sockb; struct tcpcb tcpcb; - struct in6pcb in6pcb, *in6pcbp; + struct inpcb inpcb, *inpcbp; KREAD(off, &pcbtable, sizeof pcbtable); pprev = &((struct inpcbtable *)off)->inpt_queue.tqh_first; next = TAILQ_FIRST(&pcbtable.inpt_queue); while (next != TAILQ_END(&pcbtable.inpt_queue)) { - in6pcbp = (struct in6pcb *)next; - KREAD(in6pcbp, &in6pcb, sizeof (in6pcb)); - if (in6pcb.in6p_queue.tqe_prev != pprev) { + inpcbp = (struct inpcb *)next; + KREAD(inpcbp, &inpcb, sizeof (inpcb)); + if (inpcb.inp_queue.tqe_prev != pprev) { for (p = netcb.ni_forw; p != nhead; p = p->ni_forw) p->ni_seen = 1; error("Kernel state in transition"); return; } - pprev = &next->inph_queue.tqe_next; - next = in6pcb.in6p_queue.tqe_next; + pprev = &next->inp_queue.tqe_next; + next = inpcb.inp_queue.tqe_next; - if (in6pcb.in6p_af != AF_INET6) + if (inpcb.inp_af != AF_INET6) continue; - if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&in6pcb.in6p_laddr)) + if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&inpcb.inp_laddr6)) continue; - if (nhosts && !checkhost6(&in6pcb)) + if (nhosts && !checkhost(&inpcb)) continue; - if (nports && !checkport6(&in6pcb)) + if (nports && !checkport(&inpcb)) continue; - KREAD(in6pcb.in6p_socket, &sockb, sizeof (sockb)); + KREAD(inpcb.inp_socket, &sockb, sizeof (sockb)); if (istcp) { - KREAD(in6pcb.in6p_ppcb, &tcpcb, sizeof (tcpcb)); - enter6(&in6pcb, &sockb, tcpcb.t_state, "tcp"); + KREAD(inpcb.inp_ppcb, &tcpcb, sizeof (tcpcb)); + enter6(&inpcb, &sockb, tcpcb.t_state, "tcp"); } else - enter6(&in6pcb, &sockb, 0, "udp"); + enter6(&inpcb, &sockb, 0, "udp"); } } #endif /*INET6*/ @@ -345,7 +345,7 @@ enter(struct inpcb *inp, struct socket *so, int state, const char *proto) #ifdef INET6 static void -enter6(struct in6pcb *in6p, struct socket *so, int state, const char *proto) +enter6(struct inpcb *inp, struct socket *so, int state, const char *proto) { struct netinfo *p; @@ -361,11 +361,11 @@ enter6(struct in6pcb *in6p, struct socket *so, int state, const char *proto) continue; if (!streq(proto, p->ni_proto)) continue; - if (p->ni_lport != in6p->in6p_lport || - !IN6_ARE_ADDR_EQUAL(&p->ni_laddr6, &in6p->in6p_laddr)) + if (p->ni_lport != inp->inp_lport || + !IN6_ARE_ADDR_EQUAL(&p->ni_laddr6, &inp->inp_laddr6)) continue; - if (IN6_ARE_ADDR_EQUAL(&p->ni_faddr6, &in6p->in6p_faddr) && - p->ni_fport == in6p->in6p_fport) + if (IN6_ARE_ADDR_EQUAL(&p->ni_faddr6, &inp->inp_faddr6) && + p->ni_fport == inp->inp_fport) break; } if (p == nhead) { @@ -378,10 +378,10 @@ enter6(struct in6pcb *in6p, struct socket *so, int state, const char *proto) netcb.ni_forw->ni_prev = p; netcb.ni_forw = p; p->ni_line = -1; - p->ni_laddr6 = in6p->in6p_laddr; - p->ni_lport = in6p->in6p_lport; - p->ni_faddr6 = in6p->in6p_faddr; - p->ni_fport = in6p->in6p_fport; + p->ni_laddr6 = inp->inp_laddr6; + p->ni_lport = inp->inp_lport; + p->ni_faddr6 = inp->inp_faddr6; + p->ni_fport = inp->inp_fport; p->ni_proto = proto; p->ni_flags = NIF_LACHG | NIF_FACHG; p->ni_family = AF_INET6;