Index | Thread | Search

From:
Vitaliy Makkoveev <otto@bsdbox.dev>
Subject:
Re: merge divert6 into divert
To:
Alexander Bluhm <alexander.bluhm@gmx.net>
Cc:
tech@openbsd.org
Date:
Mon, 1 Jan 2024 20:13:50 +0300

Download raw body.

Thread
> On 1 Jan 2024, at 20:10, Alexander Bluhm <alexander.bluhm@gmx.net> wrote:
> 
> Hi,
> 
> There is a lot of code duplication in netinet6/ip6_divert.c.  Other
> protocols like UDP or TCP only keep functions that are essentially
> different.  This also makes code review and understanding easier.
> 
> In a fist sweep remove divert6_detach, divert6_lock, divert6_unlock,
> divert6_bind, and divert6_shutdown.  The IPv4 code is identical.
> 
> Note that INP_HDRINCL is an IPv4 only option.  It should not be in
> divert6_attach.
> 
> ok?
> 

ok mvs

> bluhm
> 
> Index: netinet6/ip6_divert.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet6/ip6_divert.c,v
> diff -u -p -r1.90 ip6_divert.c
> --- netinet6/ip6_divert.c	16 Sep 2023 09:33:27 -0000	1.90
> +++ netinet6/ip6_divert.c	1 Jan 2024 16:46:12 -0000
> @@ -33,6 +33,7 @@
> #include <netinet/ip.h>
> #include <netinet/ip_var.h>
> #include <netinet/in_pcb.h>
> +#include <netinet/ip_divert.h>
> #include <netinet/ip6.h>
> #include <netinet6/in6_var.h>
> #include <netinet6/ip6_divert.h>
> @@ -65,11 +66,11 @@ const struct sysctl_bounded_args divert6
> 
> 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 pr
> 
> 	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 pr
> 	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);
> }
> Index: netinet6/ip6_divert.h
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet6/ip6_divert.h,v
> diff -u -p -r1.22 ip6_divert.h
> --- netinet6/ip6_divert.h	17 Oct 2022 14:49:02 -0000	1.22
> +++ netinet6/ip6_divert.h	1 Jan 2024 16:46:12 -0000
> @@ -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 */
>