diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2015-05-15 10:09:24 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2015-05-15 10:09:24 +0000 |
commit | ca841eaed417bbf7a3c98537c1c58da366438e19 (patch) | |
tree | aacca98411b2c34de6e682671ea6d90660c3d85a /sys | |
parent | 6eceebde6144e8c88d4a722b87ccb569a02c58c9 (diff) |
Remove a NULL check in carp_set_ifp() as we always pass a valid ifp
pointer to this function.
ok claudio@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/netinet/ip_carp.c | 112 |
1 files changed, 54 insertions, 58 deletions
diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 07d5d6f557a..8460aa6074e 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.c,v 1.254 2015/04/28 14:51:50 mpi Exp $ */ +/* $OpenBSD: ip_carp.c,v 1.255 2015/05/15 10:09:23 mpi Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -1665,71 +1665,67 @@ carp_set_ifp(struct carp_softc *sc, struct ifnet *ifp) 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); } |