On Fri, Sep 02, 2022 at 06:01:20PM +0300, Vitaliy Makkoveev wrote:
> We always call in6_setpeeraddr() and never call in_setpeeraddr() fro the
> inet6 case.
Should we do it the other way around?
By pushing the inet6 case into the callee allows less switches in
the callers. Instead of adding in6_sockaddr() and in6_peeraddr(),
just call the generic in_...() version. The difference is only in
in_setsockaddr() and in_setpeeraddr(). They can call the specific
in6_...() implementation. This reduces code in upper layers.
I did somethin like this a while ago and I think the code in the
caller got cleaner. Of course this trick only works as long as
in_...() and in6_...() have the same parameters.
bluhm
> Index: sys/netinet/in_pcb.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/in_pcb.c,v
> retrieving revision 1.273
> diff -u -p -r1.273 in_pcb.c
> --- sys/netinet/in_pcb.c 30 Aug 2022 11:53:04 -0000 1.273
> +++ sys/netinet/in_pcb.c 2 Sep 2022 14:59:02 -0000
> @@ -649,13 +649,6 @@ in_setpeeraddr(struct inpcb *inp, struct
> {
> struct sockaddr_in *sin;
>
> -#ifdef INET6
> - if (sotopf(inp->inp_socket) == PF_INET6) {
> - in6_setpeeraddr(inp, nam);
> - return;
> - }
> -#endif /* INET6 */
> -
> nam->m_len = sizeof(*sin);
> sin = mtod(nam, struct sockaddr_in *);
> memset(sin, 0, sizeof(*sin));