On Thu, May 14, 2015 at 6:27 AM, Martin Pieuchot <[email protected]> wrote:

> ifp can never be NULL in carp_set_ifp(), so remove the check and gain
> one level of indentation.
>

pre
if  (X == null ) {dprintf(you broke this); return ;}
unindented code;
/pre

Same gain, more dev ease and corner case check.



> ok?


> Index: netinet/ip_carp.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_carp.c,v
> retrieving revision 1.254
> diff -u -p -r1.254 ip_carp.c
> --- netinet/ip_carp.c   28 Apr 2015 14:51:50 -0000      1.254
> +++ netinet/ip_carp.c   14 May 2015 10:18:52 -0000
> @@ -1665,71 +1665,67 @@ carp_set_ifp(struct carp_softc *sc, stru
>         if (ifp == sc->sc_carpdev)
>                 return (0);
>
> -       if (ifp != NULL) {
> -               if ((ifp->if_flags & IFF_MULTICAST) == 0)
> -                       return (EADDRNOTAVAIL);
> +       if ((ifp->if_flags & IFF_MULTICAST) == 0)
> +               return (EADDRNOTAVAIL);
>
> -               if (ifp->if_type == IFT_CARP)
> -                       return (EINVAL);
> -
> -               if (ifp->if_carp == NULL) {
> -                       ncif = malloc(sizeof(*cif), M_IFADDR,
> M_NOWAIT|M_ZERO);
> -                       if (ncif == NULL)
> -                               return (ENOBUFS);
> -                       if ((error = ifpromisc(ifp, 1))) {
> -                               free(ncif, M_IFADDR, sizeof(*ncif));
> -                               return (error);
> -                       }
> +       if (ifp->if_type == IFT_CARP)
> +               return (EINVAL);
>
> -                       ncif->vhif_ifp = ifp;
> -                       TAILQ_INIT(&ncif->vhif_vrs);
> -               } else {
> -                       cif = (struct carp_if *)ifp->if_carp;
> -                       if (carp_check_dup_vhids(sc, cif, NULL))
> -                               return (EINVAL);
> +       if (ifp->if_carp == NULL) {
> +               ncif = malloc(sizeof(*cif), M_IFADDR, M_NOWAIT|M_ZERO);
> +               if (ncif == NULL)
> +                       return (ENOBUFS);
> +               if ((error = ifpromisc(ifp, 1))) {
> +                       free(ncif, M_IFADDR, sizeof(*ncif));
> +                       return (error);
>                 }
>
> -               /* detach from old interface */
> -               if (sc->sc_carpdev != NULL)
> -                       carpdetach(sc);
> -
> -               /* attach carp interface to physical interface */
> -               if (ncif != NULL)
> -                       ifp->if_carp = (caddr_t)ncif;
> -               sc->sc_carpdev = ifp;
> -               sc->sc_if.if_capabilities = ifp->if_capabilities &
> -                   IFCAP_CSUM_MASK;
> +               ncif->vhif_ifp = ifp;
> +               TAILQ_INIT(&ncif->vhif_vrs);
> +       } else {
>                 cif = (struct carp_if *)ifp->if_carp;
> -               TAILQ_FOREACH(vr, &cif->vhif_vrs, sc_list) {
> -                       if (vr == sc)
> -                               myself = 1;
> -                       if (LIST_FIRST(&vr->carp_vhosts)->vhid <
> -                           LIST_FIRST(&sc->carp_vhosts)->vhid)
> -                               after = vr;
> -               }
> +               if (carp_check_dup_vhids(sc, cif, NULL))
> +                       return (EINVAL);
> +       }
>
> -               if (!myself) {
> -                       /* We're trying to keep things in order */
> -                       if (after == NULL) {
> -                               TAILQ_INSERT_TAIL(&cif->vhif_vrs, sc,
> sc_list);
> -                       } else {
> -                               TAILQ_INSERT_AFTER(&cif->vhif_vrs, after,
> -                                   sc, sc_list);
> -                       }
> -                       cif->vhif_nvrs++;
> -               }
> -               if (sc->sc_naddrs || sc->sc_naddrs6)
> -                       sc->sc_if.if_flags |= IFF_UP;
> -               carp_set_enaddr(sc);
> -               s = splnet();
> -               sc->lh_cookie = hook_establish(ifp->if_linkstatehooks, 1,
> -                   carp_carpdev_state, ifp);
> -               carp_carpdev_state(ifp);
> -               splx(s);
> -       } else {
> +       /* detach from old interface */
> +       if (sc->sc_carpdev != NULL)
>                 carpdetach(sc);
> -               sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
> +
> +       /* attach carp interface to physical interface */
> +       if (ncif != NULL)
> +               ifp->if_carp = (caddr_t)ncif;
> +       sc->sc_carpdev = ifp;
> +       sc->sc_if.if_capabilities = ifp->if_capabilities &
> +           IFCAP_CSUM_MASK;
> +       cif = (struct carp_if *)ifp->if_carp;
> +       TAILQ_FOREACH(vr, &cif->vhif_vrs, sc_list) {
> +               if (vr == sc)
> +                       myself = 1;
> +               if (LIST_FIRST(&vr->carp_vhosts)->vhid <
> +                   LIST_FIRST(&sc->carp_vhosts)->vhid)
> +                       after = vr;
>         }
> +
> +       if (!myself) {
> +               /* We're trying to keep things in order */
> +               if (after == NULL) {
> +                       TAILQ_INSERT_TAIL(&cif->vhif_vrs, sc, sc_list);
> +               } else {
> +                       TAILQ_INSERT_AFTER(&cif->vhif_vrs, after,
> +                           sc, sc_list);
> +               }
> +               cif->vhif_nvrs++;
> +       }
> +       if (sc->sc_naddrs || sc->sc_naddrs6)
> +               sc->sc_if.if_flags |= IFF_UP;
> +       carp_set_enaddr(sc);
> +       s = splnet();
> +       sc->lh_cookie = hook_establish(ifp->if_linkstatehooks, 1,
> +           carp_carpdev_state, ifp);
> +       carp_carpdev_state(ifp);
> +       splx(s);
> +
>         return (0);
>  }
>
>
>


-- 
---------------------------------------------------------------------------------------------------------------------
() ascii ribbon campaign - against html e-mail
/\

Reply via email to