Module Name: src Committed By: ozaki-r Date: Fri Oct 28 05:20:08 UTC 2022
Modified Files: src/sys/dist/pf/net: pf.c src/sys/net: if_wg.c src/sys/netinet: dccp_usrreq.c dccp_var.h sctp_pcb.h src/sys/netinet6: dccp6_usrreq.c Log Message: Adjust pf, wg, dccp and sctp for struct inpcb integration To generate a diff of this commit: cvs rdiff -u -r1.84 -r1.85 src/sys/dist/pf/net/pf.c cvs rdiff -u -r1.69 -r1.70 src/sys/net/if_wg.c cvs rdiff -u -r1.22 -r1.23 src/sys/netinet/dccp_usrreq.c cvs rdiff -u -r1.6 -r1.7 src/sys/netinet/dccp_var.h cvs rdiff -u -r1.5 -r1.6 src/sys/netinet/sctp_pcb.h cvs rdiff -u -r1.12 -r1.13 src/sys/netinet6/dccp6_usrreq.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dist/pf/net/pf.c diff -u src/sys/dist/pf/net/pf.c:1.84 src/sys/dist/pf/net/pf.c:1.85 --- src/sys/dist/pf/net/pf.c:1.84 Mon Aug 10 10:59:34 2020 +++ src/sys/dist/pf/net/pf.c Fri Oct 28 05:20:08 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: pf.c,v 1.84 2020/08/10 10:59:34 rin Exp $ */ +/* $NetBSD: pf.c,v 1.85 2022/10/28 05:20:08 ozaki-r Exp $ */ /* $OpenBSD: pf.c,v 1.552.2.1 2007/11/27 16:37:57 henning Exp $ */ /* @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pf.c,v 1.84 2020/08/10 10:59:34 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pf.c,v 1.85 2022/10/28 05:20:08 ozaki-r Exp $"); #include "pflog.h" @@ -2758,11 +2758,8 @@ pf_socket_lookup(int direction, struct p 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); Index: src/sys/net/if_wg.c diff -u src/sys/net/if_wg.c:1.69 src/sys/net/if_wg.c:1.70 --- src/sys/net/if_wg.c:1.69 Fri Mar 25 08:57:50 2022 +++ src/sys/net/if_wg.c Fri Oct 28 05:20:08 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: if_wg.c,v 1.69 2022/03/25 08:57:50 hannken Exp $ */ +/* $NetBSD: if_wg.c,v 1.70 2022/10/28 05:20:08 ozaki-r Exp $ */ /* * Copyright (C) Ryota Ozaki <ozaki.ry...@gmail.com> @@ -41,7 +41,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.69 2022/03/25 08:57:50 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.70 2022/10/28 05:20:08 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_altq_enabled.h" @@ -3266,12 +3266,7 @@ wg_socreate(struct wg_softc *wg, int af, 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 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); Index: src/sys/netinet/dccp_usrreq.c diff -u src/sys/netinet/dccp_usrreq.c:1.22 src/sys/netinet/dccp_usrreq.c:1.23 --- src/sys/netinet/dccp_usrreq.c:1.22 Sat Dec 4 13:23:04 2021 +++ src/sys/netinet/dccp_usrreq.c Fri Oct 28 05:20:08 2022 @@ -1,5 +1,5 @@ /* $KAME: dccp_usrreq.c,v 1.67 2005/11/03 16:05:04 nishida Exp $ */ -/* $NetBSD: dccp_usrreq.c,v 1.22 2021/12/04 13:23:04 andvar Exp $ */ +/* $NetBSD: dccp_usrreq.c,v 1.23 2022/10/28 05:20:08 ozaki-r Exp $ */ /* * Copyright (c) 2003 Joacim Häggmark, Magnus Erixzon, Nils-Erik Mattsson @@ -67,7 +67,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.22 2021/12/04 13:23:04 andvar Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.23 2022/10/28 05:20:08 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -188,7 +188,6 @@ dccp_input(struct mbuf *m, int off, int 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 */ #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 } } 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 } 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 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 /* 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 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 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 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 { 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 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 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 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 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 #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 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; } Index: src/sys/netinet/dccp_var.h diff -u src/sys/netinet/dccp_var.h:1.6 src/sys/netinet/dccp_var.h:1.7 --- src/sys/netinet/dccp_var.h:1.6 Sun Nov 7 20:31:09 2021 +++ src/sys/netinet/dccp_var.h Fri Oct 28 05:20:08 2022 @@ -1,5 +1,5 @@ /* $KAME: dccp_var.h,v 1.29 2005/11/03 14:59:28 nishida Exp $ */ -/* $NetBSD: dccp_var.h,v 1.6 2021/11/07 20:31:09 andvar Exp $ */ +/* $NetBSD: dccp_var.h,v 1.7 2022/10/28 05:20:08 ozaki-r Exp $ */ /* * Copyright (c) 2003 Joacim Häggmark, Magnus Erixzon, Nils-Erik Mattsson @@ -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 */ Index: src/sys/netinet/sctp_pcb.h diff -u src/sys/netinet/sctp_pcb.h:1.5 src/sys/netinet/sctp_pcb.h:1.6 --- src/sys/netinet/sctp_pcb.h:1.5 Tue May 24 20:50:20 2022 +++ src/sys/netinet/sctp_pcb.h Fri Oct 28 05:20:08 2022 @@ -1,5 +1,5 @@ /* $KAME: sctp_pcb.h,v 1.21 2005/07/16 01:18:47 suz Exp $ */ -/* $NetBSD: sctp_pcb.h,v 1.5 2022/05/24 20:50:20 andvar Exp $ */ +/* $NetBSD: sctp_pcb.h,v 1.6 2022/10/28 05:20:08 ozaki-r Exp $ */ #ifndef __SCTP_PCB_H__ #define __SCTP_PCB_H__ @@ -41,6 +41,7 @@ * we would not allocate enough for Net/Open BSD :-< */ #include <net/if.h> +#include <netinet/in_pcb.h> #include <netinet/ip6.h> #include <netinet6/ip6_var.h> #include <netinet6/ip6protosw.h> @@ -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, uin 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__ */ Index: src/sys/netinet6/dccp6_usrreq.c diff -u src/sys/netinet6/dccp6_usrreq.c:1.12 src/sys/netinet6/dccp6_usrreq.c:1.13 --- src/sys/netinet6/dccp6_usrreq.c:1.12 Sat Sep 15 13:33:15 2018 +++ src/sys/netinet6/dccp6_usrreq.c Fri Oct 28 05:20:08 2022 @@ -1,5 +1,5 @@ /* $KAME: dccp6_usrreq.c,v 1.13 2005/07/27 08:42:56 nishida Exp $ */ -/* $NetBSD: dccp6_usrreq.c,v 1.12 2018/09/15 13:33:15 rjs Exp $ */ +/* $NetBSD: dccp6_usrreq.c,v 1.13 2022/10/28 05:20:08 ozaki-r Exp $ */ /* * Copyright (C) 2003 WIDE Project. @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dccp6_usrreq.c,v 1.12 2018/09/15 13:33:15 rjs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dccp6_usrreq.c,v 1.13 2022/10/28 05:20:08 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -114,30 +114,30 @@ dccp6_ctlinput(int cmd, const struct soc 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 soc 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 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 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 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 s } 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 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 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; }