From e12934f67196046526d6eedff779b4e52e87cdd8 Mon Sep 17 00:00:00 2001 From: Alexander Bluhm Date: Mon, 1 Jan 2024 18:52:10 +0000 Subject: Reduce code duplication in ip6 divert. Protocols like UDP or TCP keep only functions in netinet6 that are essentially different. Remove divert6_detach(), divert6_lock(), divert6_unlock(), divert6_bind(), and divert6_shutdown(). Replace them with identical IPv4 functions. INP_HDRINCL is an IPv4 only option, remove it from divert6_attach(). OK mvs@ sashan@ kn@ --- sys/netinet6/ip6_divert.c | 65 +++++------------------------------------------ sys/netinet6/ip6_divert.h | 7 +---- 2 files changed, 8 insertions(+), 64 deletions(-) diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index 6826bd9a287..89644174285 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.90 2023/09/16 09:33:27 mpi Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.91 2024/01/01 18:52:09 bluhm Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -65,11 +66,11 @@ const struct sysctl_bounded_args divert6ctl_vars[] = { const struct pr_usrreqs divert6_usrreqs = { .pru_attach = divert6_attach, - .pru_detach = divert6_detach, - .pru_lock = divert6_lock, - .pru_unlock = divert6_unlock, - .pru_bind = divert6_bind, - .pru_shutdown = divert6_shutdown, + .pru_detach = divert_detach, + .pru_lock = divert_lock, + .pru_unlock = divert_unlock, + .pru_bind = divert_bind, + .pru_shutdown = divert_shutdown, .pru_send = divert6_send, .pru_control = in6_control, .pru_sockaddr = in6_sockaddr, @@ -272,7 +273,6 @@ divert6_attach(struct socket *so, int proto, int wait) if (so->so_pcb != NULL) return EINVAL; - if ((so->so_state & SS_PRIV) == 0) return EACCES; @@ -283,57 +283,6 @@ divert6_attach(struct socket *so, int proto, int wait) error = soreserve(so, divert6_sendspace, divert6_recvspace); if (error) return (error); - sotoinpcb(so)->inp_flags |= INP_HDRINCL; - return (0); -} - -int -divert6_detach(struct socket *so) -{ - struct inpcb *inp = sotoinpcb(so); - - soassertlocked(so); - - if (inp == NULL) - return (EINVAL); - - in_pcbdetach(inp); - - return (0); -} - -void -divert6_lock(struct socket *so) -{ - struct inpcb *inp = sotoinpcb(so); - - NET_ASSERT_LOCKED(); - mtx_enter(&inp->inp_mtx); -} - -void -divert6_unlock(struct socket *so) -{ - struct inpcb *inp = sotoinpcb(so); - - NET_ASSERT_LOCKED(); - mtx_leave(&inp->inp_mtx); -} - -int -divert6_bind(struct socket *so, struct mbuf *addr, struct proc *p) -{ - struct inpcb *inp = sotoinpcb(so); - - soassertlocked(so); - return in_pcbbind(inp, addr, p); -} - -int -divert6_shutdown(struct socket *so) -{ - soassertlocked(so); - socantsendmore(so); return (0); } diff --git a/sys/netinet6/ip6_divert.h b/sys/netinet6/ip6_divert.h index aeff58338a6..27f2461155d 100644 --- a/sys/netinet6/ip6_divert.h +++ b/sys/netinet6/ip6_divert.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.h,v 1.22 2022/10/17 14:49:02 mvs Exp $ */ +/* $OpenBSD: ip6_divert.h,v 1.23 2024/01/01 18:52:09 bluhm Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -71,11 +71,6 @@ void divert6_init(void); void divert6_packet(struct mbuf *, int, u_int16_t); int divert6_sysctl(int *, u_int, void *, size_t *, void *, size_t); int divert6_attach(struct socket *, int, int); -int divert6_detach(struct socket *); -void divert6_lock(struct socket *); -void divert6_unlock(struct socket *); -int divert6_bind(struct socket *, struct mbuf *, struct proc *); -int divert6_shutdown(struct socket *); int divert6_send(struct socket *, struct mbuf *, struct mbuf *, struct mbuf *); #endif /* _KERNEL */ -- cgit v1.2.3