diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2024-01-19 02:24:08 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2024-01-19 02:24:08 +0000 |
commit | eb371ad0501cfdb75dc5be07360c0cfdae02d36f (patch) | |
tree | 59e85ce95720219758075775def59ad5b93ef1d3 | |
parent | 93070e34124cee6dbf7983685683e86a2f59cbdc (diff) |
Unify inpcb API for inet and inet6.
Many functions for IPv4 call their IPv6 counterpart if INP_IPV6 is
set at the socket's pcb. By using the generic API consistently,
the logic is not in the caller it gets more readable.
OK mvs@
-rw-r--r-- | sys/netinet/in_pcb.c | 13 | ||||
-rw-r--r-- | sys/netinet/tcp_usrreq.c | 38 | ||||
-rw-r--r-- | sys/netinet/udp_usrreq.c | 18 |
3 files changed, 24 insertions, 45 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 41a9dfbaf2c..29250092d80 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.285 2024/01/18 11:03:16 claudio Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.286 2024/01/19 02:24:07 bluhm Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -517,7 +517,7 @@ in_pcbconnect(struct inpcb *inp, struct mbuf *nam) #ifdef INET6 if (ISSET(inp->inp_flags, INP_IPV6)) return (in6_pcbconnect(inp, nam)); -#endif /* INET6 */ +#endif if ((error = in_nam2sin(nam, &sin))) return (error); @@ -652,6 +652,13 @@ in_setsockaddr(struct inpcb *inp, struct mbuf *nam) { struct sockaddr_in *sin; +#ifdef INET6 + if (ISSET(inp->inp_flags, INP_IPV6)) { + in6_setsockaddr(inp, nam); + return; + } +#endif + nam->m_len = sizeof(*sin); sin = mtod(nam, struct sockaddr_in *); memset(sin, 0, sizeof(*sin)); @@ -671,7 +678,7 @@ in_setpeeraddr(struct inpcb *inp, struct mbuf *nam) in6_setpeeraddr(inp, nam); return; } -#endif /* INET6 */ +#endif nam->m_len = sizeof(*sin); sin = mtod(nam, struct sockaddr_in *); diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 83f02631d04..e61d87ab187 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.228 2024/01/11 13:49:49 bluhm Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.229 2024/01/19 02:24:07 bluhm Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -502,7 +502,7 @@ tcp_detach(struct socket *so) { struct inpcb *inp; struct tcpcb *otp = NULL, *tp; - int error = 0; + int error; short ostate; soassertlocked(so); @@ -526,7 +526,7 @@ tcp_detach(struct socket *so) if (otp) tcp_trace(TA_USER, ostate, tp, otp, NULL, PRU_DETACH, 0); - return (error); + return (0); } /* @@ -685,26 +685,17 @@ tcp_accept(struct socket *so, struct mbuf *nam) struct inpcb *inp; struct tcpcb *tp; int error; - short ostate; soassertlocked(so); if ((error = tcp_sogetpcb(so, &inp, &tp))) return (error); - if (so->so_options & SO_DEBUG) - ostate = tp->t_state; - -#ifdef INET6 - if (inp->inp_flags & INP_IPV6) - in6_setpeeraddr(inp, nam); - else -#endif - in_setpeeraddr(inp, nam); + in_setpeeraddr(inp, nam); if (so->so_options & SO_DEBUG) - tcp_trace(TA_USER, ostate, tp, tp, NULL, PRU_ACCEPT, 0); - return (error); + tcp_trace(TA_USER, tp->t_state, tp, tp, NULL, PRU_ACCEPT, 0); + return (0); } /* @@ -994,12 +985,7 @@ tcp_sockaddr(struct socket *so, struct mbuf *nam) if ((error = tcp_sogetpcb(so, &inp, &tp))) return (error); -#ifdef INET6 - if (inp->inp_flags & INP_IPV6) - in6_setsockaddr(inp, nam); - else -#endif - in_setsockaddr(inp, nam); + in_setsockaddr(inp, nam); if (so->so_options & SO_DEBUG) tcp_trace(TA_USER, tp->t_state, tp, tp, NULL, @@ -1019,16 +1005,10 @@ tcp_peeraddr(struct socket *so, struct mbuf *nam) if ((error = tcp_sogetpcb(so, &inp, &tp))) return (error); -#ifdef INET6 - if (inp->inp_flags & INP_IPV6) - in6_setpeeraddr(inp, nam); - else -#endif - in_setpeeraddr(inp, nam); + in_setpeeraddr(inp, nam); if (so->so_options & SO_DEBUG) - tcp_trace(TA_USER, tp->t_state, tp, tp, NULL, - PRU_PEERADDR, 0); + tcp_trace(TA_USER, tp->t_state, tp, tp, NULL, PRU_PEERADDR, 0); return (0); } diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 61d38578af0..06a56ca35ad 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.313 2024/01/10 16:44:30 bluhm Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.314 2024/01/19 02:24:07 bluhm Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -936,9 +936,9 @@ udp_output(struct inpcb *inp, struct mbuf *m, struct mbuf *addr, struct in_addr laddr; int error = 0; -#ifdef DIAGNOSTIC - if ((inp->inp_flags & INP_IPV6) != 0) - panic("IPv6 inpcb to %s", __func__); +#ifdef INET6 + if (ISSET(inp->inp_flags, INP_IPV6)) + return (udp6_output(inp, m, addr, control)); #endif /* @@ -1230,7 +1230,6 @@ udp_send(struct socket *so, struct mbuf *m, struct mbuf *addr, struct mbuf *control) { struct inpcb *inp = sotoinpcb(so); - int error; soassertlocked(so); @@ -1265,14 +1264,7 @@ udp_send(struct socket *so, struct mbuf *m, struct mbuf *addr, } #endif -#ifdef INET6 - if (inp->inp_flags & INP_IPV6) - error = udp6_output(inp, m, addr, control); - else -#endif - error = udp_output(inp, m, addr, control); - - return (error); + return (udp_output(inp, m, addr, control)); } /* |