Index | Thread | Search

From:
Vitaliy Makkoveev <mvs@openbsd.org>
Subject:
Re: in_pcbnotifyall sockaddr_in
To:
Alexander Bluhm <alexander.bluhm@gmx.net>
Cc:
tech@openbsd.org
Date:
Tue, 30 Jan 2024 11:11:48 +0300

Download raw body.

Thread
On Sun, Jan 28, 2024 at 03:03:17PM +0100, Alexander Bluhm wrote:
> Hi,
> 
> in_pcbnotifyall() is an IPv4 only function.  All callers check that
> sockaddr dst is in fact a sockaddr_in.  Better pass the more spcific
> type and remove the runtime check at beginning of in_pcbnotifyall().
> 
> Use const sockaddr_in in in_pcbnotifyall() and const sockaddr_in6
> in6_pcbnotify() for dst parameter.
> 
> ok?
> 

ok mvs

> bluhm
> 
> Index: netinet/in_pcb.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.c,v
> diff -u -p -r1.286 in_pcb.c
> --- netinet/in_pcb.c	19 Jan 2024 02:24:07 -0000	1.286
> +++ netinet/in_pcb.c	28 Jan 2024 12:40:06 -0000
> @@ -720,18 +720,14 @@ in_peeraddr(struct socket *so, struct mb
>   * any errors for each matching socket.
>   */
>  void
> -in_pcbnotifyall(struct inpcbtable *table, struct sockaddr *dst, u_int rtable,
> -    int errno, void (*notify)(struct inpcb *, int))
> +in_pcbnotifyall(struct inpcbtable *table, const struct sockaddr_in *dst,
> +    u_int rtable, int errno, void (*notify)(struct inpcb *, int))
>  {
>  	SIMPLEQ_HEAD(, inpcb) inpcblist;
>  	struct inpcb *inp;
> -	struct in_addr faddr;
>  	u_int rdomain;
>  
> -	if (dst->sa_family != AF_INET)
> -		return;
> -	faddr = satosin(dst)->sin_addr;
> -	if (faddr.s_addr == INADDR_ANY)
> +	if (dst->sin_addr.s_addr == INADDR_ANY)
>  		return;
>  	if (notify == NULL)
>  		return;
> @@ -754,7 +750,7 @@ in_pcbnotifyall(struct inpcbtable *table
>  		if (ISSET(inp->inp_flags, INP_IPV6))
>  			continue;
>  #endif
> -		if (inp->inp_faddr.s_addr != faddr.s_addr ||
> +		if (inp->inp_faddr.s_addr != dst->sin_addr.s_addr ||
>  		    rtable_l2(inp->inp_rtableid) != rdomain) {
>  			continue;
>  		}
> Index: netinet/in_pcb.h
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.h,v
> diff -u -p -r1.148 in_pcb.h
> --- netinet/in_pcb.h	9 Jan 2024 19:57:00 -0000	1.148
> +++ netinet/in_pcb.h	28 Jan 2024 12:40:06 -0000
> @@ -352,7 +352,7 @@ void	 in_pcbinit(struct inpcbtable *, in
>  struct inpcb *
>  	 in_pcblookup_local_lock(struct inpcbtable *, const void *, u_int, int,
>  	    u_int, int);
> -void	 in_pcbnotifyall(struct inpcbtable *, struct sockaddr *,
> +void	 in_pcbnotifyall(struct inpcbtable *, const struct sockaddr_in *,
>  	    u_int, int, void (*)(struct inpcb *, int));
>  void	 in_pcbrehash(struct inpcb *);
>  void	 in_rtchange(struct inpcb *, int);
> @@ -367,7 +367,7 @@ struct rtentry *
>  	in_pcbrtentry(struct inpcb *);
>  
>  /* INET6 stuff */
> -void	in6_pcbnotify(struct inpcbtable *, struct sockaddr_in6 *,
> +void	in6_pcbnotify(struct inpcbtable *, const struct sockaddr_in6 *,
>  	u_int, const struct sockaddr_in6 *, u_int, u_int, int, void *,
>  	void (*)(struct inpcb *, int));
>  int	in6_selecthlim(const struct inpcb *);
> Index: netinet/tcp_subr.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_subr.c,v
> diff -u -p -r1.196 tcp_subr.c
> --- netinet/tcp_subr.c	27 Jan 2024 21:13:46 -0000	1.196
> +++ netinet/tcp_subr.c	28 Jan 2024 12:39:03 -0000
> @@ -833,7 +833,7 @@ tcp_ctlinput(int cmd, struct sockaddr *s
>  		}
>  		in_pcbunref(inp);
>  	} else
> -		in_pcbnotifyall(&tcbtable, sa, rdomain, errno, notify);
> +		in_pcbnotifyall(&tcbtable, satosin(sa), rdomain, errno, notify);
>  }
>  
>  
> Index: netinet/tcp_timer.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_timer.c,v
> diff -u -p -r1.75 tcp_timer.c
> --- netinet/tcp_timer.c	27 Jan 2024 21:35:13 -0000	1.75
> +++ netinet/tcp_timer.c	28 Jan 2024 12:39:03 -0000
> @@ -236,8 +236,8 @@ tcp_timer_rexmt(void *arg)
>  		sin.sin_len = sizeof(sin);
>  		sin.sin_family = AF_INET;
>  		sin.sin_addr = inp->inp_faddr;
> -		in_pcbnotifyall(&tcbtable, sintosa(&sin), inp->inp_rtableid,
> -		    EMSGSIZE, tcp_mtudisc);
> +		in_pcbnotifyall(&tcbtable, &sin, inp->inp_rtableid, EMSGSIZE,
> +		    tcp_mtudisc);
>  		goto out;
>  	}
>  
> Index: netinet/udp_usrreq.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/udp_usrreq.c,v
> diff -u -p -r1.315 udp_usrreq.c
> --- netinet/udp_usrreq.c	21 Jan 2024 01:17:20 -0000	1.315
> +++ netinet/udp_usrreq.c	28 Jan 2024 12:39:03 -0000
> @@ -919,7 +919,7 @@ udp_ctlinput(int cmd, struct sockaddr *s
>  			notify(inp, errno);
>  		in_pcbunref(inp);
>  	} else
> -		in_pcbnotifyall(&udbtable, sa, rdomain, errno, notify);
> +		in_pcbnotifyall(&udbtable, satosin(sa), rdomain, errno, notify);
>  }
>  
>  int
> Index: netinet6/in6_pcb.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet6/in6_pcb.c,v
> diff -u -p -r1.132 in6_pcb.c
> --- netinet6/in6_pcb.c	9 Jan 2024 19:57:01 -0000	1.132
> +++ netinet6/in6_pcb.c	28 Jan 2024 12:39:03 -0000
> @@ -423,7 +423,7 @@ in6_peeraddr(struct socket *so, struct m
>   *    once PCB to be notified has been located.
>   */
>  void
> -in6_pcbnotify(struct inpcbtable *table, struct sockaddr_in6 *dst,
> +in6_pcbnotify(struct inpcbtable *table, const struct sockaddr_in6 *dst,
>      uint fport_arg, const struct sockaddr_in6 *src, uint lport_arg,
>      u_int rtable, int cmd, void *cmdarg, void (*notify)(struct inpcb *, int))
>  {
>