On Thu, Jun 14, 2018 at 10:30:19AM +0200, Alexander Bluhm wrote:
> On Thu, Jun 14, 2018 at 01:01:51AM +0200, Alexander Bluhm wrote:
> > -                   if (!bcmp(&sc->sc_src, src, src->sa_len) &&
> > +                   if (sc->sc_src.sa.sa_family == src->sa_family &&
> > +                       sc->sc_dst.sa.sa_family == dst->sa_family &&
> > +                       !bcmp(&sc->sc_src, src, src->sa_len) &&
> >                         !bcmp(&sc->sc_dst, dst, dst->sa_len) &&
> 
> Claudio pointed out that bcmp also checks sa_family.
> 
> >     case AF_INET:
> > -           /* drop IPv4 packet to AF_INET6 socket */
> > -           if (inp->inp_flags & INP_IPV6) {
> > -                   (void) m_free(am);
> > -                   goto resetandabort;
> > -           }
> 
> Here Claudio wants the additional check.
> 
> What about this idea?  in_pcbconnect() calls in6_pcbconnect() if
> necessary.  The only check missing is INP_IPV6 in in6_pcbconnect().
> in_nam2sin() and in6_nam2sin6() care about sa_family.  So we can
> simplify the code.
> 
> ok?

I like this a lot better.
I'm not sure if I like this reachover from in_pcbconnect to
in6_pcbconnect. It is a bit of a layer violation from the old times.
Would be nice if those INET6 specifix reacovers could be removed from the
low level INET functions in the long run. In this regard this feels a bit
like a step back.

Why not leave the switch (src->sa_family)
but only call the in_pcbconnect or in6_pcbconnect there and let them
handle the errors via inX_nam2sinX()?

Then it may be possible to remove the #ifdef INET6 block in
in_pcbconnect() in a later step.
 
> bluhm
> 
> Index: netinet/in_pcb.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/in_pcb.c,v
> retrieving revision 1.237
> diff -u -p -r1.237 in_pcb.c
> --- netinet/in_pcb.c  11 Jun 2018 08:57:35 -0000      1.237
> +++ netinet/in_pcb.c  14 Jun 2018 08:18:36 -0000
> @@ -511,8 +511,7 @@ in_pcbconnect(struct inpcb *inp, struct 
>  #ifdef INET6
>       if (sotopf(inp->inp_socket) == PF_INET6)
>               return (in6_pcbconnect(inp, nam));
> -     if ((inp->inp_flags & INP_IPV6) != 0)
> -             panic("IPv6 pcb passed into in_pcbconnect");
> +     KASSERT((inp->inp_flags & INP_IPV6) == 0);
>  #endif /* INET6 */
>  
>       if ((error = in_nam2sin(nam, &sin)))
> Index: netinet/tcp_input.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_input.c,v
> retrieving revision 1.356
> diff -u -p -r1.356 tcp_input.c
> --- netinet/tcp_input.c       11 Jun 2018 07:40:26 -0000      1.356
> +++ netinet/tcp_input.c       14 Jun 2018 08:21:15 -0000
> @@ -3537,27 +3537,9 @@ syn_cache_get(struct sockaddr *src, stru
>               goto resetandabort;
>       am->m_len = src->sa_len;
>       memcpy(mtod(am, caddr_t), src, src->sa_len);
> -
> -     switch (src->sa_family) {
> -     case AF_INET:
> -             /* drop IPv4 packet to AF_INET6 socket */
> -             if (inp->inp_flags & INP_IPV6) {
> -                     (void) m_free(am);
> -                     goto resetandabort;
> -             }
> -             if (in_pcbconnect(inp, am)) {
> -                     (void) m_free(am);
> -                     goto resetandabort;
> -             }
> -             break;
> -#ifdef INET6
> -     case AF_INET6:
> -             if (in6_pcbconnect(inp, am)) {
> -                     (void) m_free(am);
> -                     goto resetandabort;
> -             }
> -             break;
> -#endif
> +     if (in_pcbconnect(inp, am)) {
> +             (void) m_free(am);
> +             goto resetandabort;
>       }
>       (void) m_free(am);
>  
> Index: netinet6/in6_pcb.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet6/in6_pcb.c,v
> retrieving revision 1.103
> diff -u -p -r1.103 in6_pcb.c
> --- netinet6/in6_pcb.c        7 Jun 2018 08:46:24 -0000       1.103
> +++ netinet6/in6_pcb.c        14 Jun 2018 08:19:10 -0000
> @@ -248,6 +248,8 @@ in6_pcbconnect(struct inpcb *inp, struct
>       int error;
>       struct sockaddr_in6 tmp;
>  
> +     KASSERT(inp->inp_flags & INP_IPV6);
> +
>       if ((error = in6_nam2sin6(nam, &sin6)))
>               return (error);
>       if (sin6->sin6_port == 0)
> 

-- 
:wq Claudio

Reply via email to