| 1568 | } |
| 1569 | |
| 1570 | static struct carp_softc* |
| 1571 | carp_alloc(struct ifnet *ifp) |
| 1572 | { |
| 1573 | struct carp_softc *sc; |
| 1574 | struct carp_if *cif; |
| 1575 | |
| 1576 | sx_assert(&carp_sx, SA_XLOCKED); |
| 1577 | |
| 1578 | if ((cif = ifp->if_carp) == NULL) |
| 1579 | cif = carp_alloc_if(ifp); |
| 1580 | |
| 1581 | sc = malloc(sizeof(*sc), M_CARP, M_WAITOK|M_ZERO); |
| 1582 | |
| 1583 | sc->sc_advbase = CARP_DFLTINTV; |
| 1584 | sc->sc_vhid = -1; /* required setting */ |
| 1585 | sc->sc_init_counter = 1; |
| 1586 | sc->sc_state = INIT; |
| 1587 | |
| 1588 | sc->sc_ifasiz = sizeof(struct ifaddr *); |
| 1589 | sc->sc_ifas = malloc(sc->sc_ifasiz, M_CARP, M_WAITOK|M_ZERO); |
| 1590 | sc->sc_carpdev = ifp; |
| 1591 | |
| 1592 | CARP_LOCK_INIT(sc); |
| 1593 | #ifdef INET |
| 1594 | callout_init_mtx(&sc->sc_md_tmo, &sc->sc_mtx, CALLOUT_RETURNUNLOCKED); |
| 1595 | #endif |
| 1596 | #ifdef INET6 |
| 1597 | callout_init_mtx(&sc->sc_md6_tmo, &sc->sc_mtx, CALLOUT_RETURNUNLOCKED); |
| 1598 | #endif |
| 1599 | callout_init_mtx(&sc->sc_ad_tmo, &sc->sc_mtx, CALLOUT_RETURNUNLOCKED); |
| 1600 | |
| 1601 | CIF_LOCK(cif); |
| 1602 | TAILQ_INSERT_TAIL(&cif->cif_vrs, sc, sc_list); |
| 1603 | CIF_UNLOCK(cif); |
| 1604 | |
| 1605 | mtx_lock(&carp_mtx); |
| 1606 | LIST_INSERT_HEAD(&carp_list, sc, sc_next); |
| 1607 | mtx_unlock(&carp_mtx); |
| 1608 | |
| 1609 | return (sc); |
| 1610 | } |
| 1611 | |
| 1612 | static void |
| 1613 | carp_grow_ifas(struct carp_softc *sc) |
no test coverage detected