Lines Matching defs:vhe
188 struct carp_vhost_entry *cur_vhe; /* current active vhe */
294 struct carp_vhost_entry *vhe;
299 SRPL_FOREACH_LOCKED(vhe, &sc->carp_vhosts, vhost_entries) {
301 carp_hmac_prepare_ctx(vhe, i);
307 carp_hmac_prepare_ctx(struct carp_vhost_entry *vhe, u_int8_t ctx)
309 struct carp_softc *sc = vhe->parent_sc;
312 u_int8_t vhid = vhe->vhid & 0xff;
323 memset(vhe->vhe_pad, 0, sizeof(vhe->vhe_pad));
324 bcopy(sc->sc_key, vhe->vhe_pad, sizeof(sc->sc_key));
325 for (i = 0; i < sizeof(vhe->vhe_pad); i++)
326 vhe->vhe_pad[i] ^= 0x36;
329 SHA1Init(&vhe->vhe_sha1[ctx]);
330 SHA1Update(&vhe->vhe_sha1[ctx], vhe->vhe_pad, sizeof(vhe->vhe_pad));
331 SHA1Update(&vhe->vhe_sha1[ctx], (void *)&version, sizeof(version));
332 SHA1Update(&vhe->vhe_sha1[ctx], (void *)&type, sizeof(type));
335 if (vhe->vhe_leader) {
336 bcopy(&vhe->vhe_sha1[ctx], &sha1ctx, sizeof(sha1ctx));
343 if (!sc->sc_realmac && vhe->vhe_leader &&
344 memcmp(sc->sc_ac.ac_enaddr, vhe->vhe_enaddr, ETHER_ADDR_LEN) != 0)
345 SHA1Update(&vhe->vhe_sha1[ctx], sc->sc_ac.ac_enaddr,
348 SHA1Update(&vhe->vhe_sha1[ctx], (void *)&vhid, sizeof(vhid));
367 SHA1Update(&vhe->vhe_sha1[ctx],
392 SHA1Update(&vhe->vhe_sha1[ctx],
398 for (i = 0; i < sizeof(vhe->vhe_pad); i++)
399 vhe->vhe_pad[i] ^= 0x36 ^ 0x5c;
403 carp_hmac_generate(struct carp_vhost_entry *vhe, u_int32_t counter[2],
409 bcopy(&vhe->vhe_sha1[ctx], &sha1ctx, sizeof(sha1ctx));
411 SHA1Update(&sha1ctx, (void *)counter, sizeof(vhe->vhe_replay_cookie));
416 SHA1Update(&sha1ctx, vhe->vhe_pad, sizeof(vhe->vhe_pad));
422 carp_hmac_verify(struct carp_vhost_entry *vhe, u_int32_t counter[2],
429 carp_hmac_generate(vhe, counter, md2, i);
623 struct carp_vhost_entry *vhe;
646 SRPL_FOREACH_LOCKED(vhe, &sc->carp_vhosts, vhost_entries) {
647 if (vhe->vhid == ch->carp_vhid)
671 if (carp_hmac_verify(vhe, ch->carp_counter, ch->carp_md)) {
678 if (!memcmp(&vhe->vhe_replay_cookie, ch->carp_counter,
695 sc_tv.tv_usec = vhe->advskew * 1000000 / 256;
699 switch (vhe->state) {
713 timeout_del(&vhe->ad_tmo);
714 carp_set_state(vhe, BACKUP);
715 carp_setrun(vhe, 0);
727 carp_master_down(vhe);
736 carp_master_down(vhe);
747 carp_master_down(vhe);
755 carp_setrun(vhe, af);
871 struct carp_vhost_entry *vhe, *vhe0;
873 vhe = malloc(sizeof(*vhe), M_DEVBUF, M_NOWAIT | M_ZERO);
874 if (vhe == NULL)
877 refcnt_init(&vhe->vhost_refcnt);
878 carp_sc_ref(NULL, sc); /* give a sc ref to the vhe */
879 vhe->parent_sc = sc;
880 vhe->vhid = vhid;
881 vhe->advskew = advskew;
882 vhe->state = INIT;
883 timeout_set_proc(&vhe->ad_tmo, carp_timer_ad, vhe);
884 timeout_set_proc(&vhe->md_tmo, carp_timer_down, vhe);
885 timeout_set_proc(&vhe->md6_tmo, carp_timer_down, vhe);
889 /* mark the first vhe as leader */
891 vhe->vhe_leader = 1;
893 vhe, vhost_entries);
903 SRPL_INSERT_AFTER_LOCKED(&carp_vh_rc, vhe0, vhe, vhost_entries);
936 struct carp_vhost_entry *vhe;
939 SRPL_FOREACH_LOCKED(vhe, &sc->carp_vhosts, vhost_entries) {
940 timeout_del(&vhe->ad_tmo);
941 timeout_del(&vhe->md_tmo);
942 timeout_del(&vhe->md6_tmo);
986 struct carp_vhost_entry *vhe;
990 while ((vhe = SRPL_FIRST_LOCKED(&sc->carp_vhosts)) != NULL) {
991 SRPL_REMOVE_LOCKED(&carp_vh_rc, &sc->carp_vhosts, vhe,
993 carp_vh_unref(NULL, vhe); /* drop last ref */
999 carp_prepare_ad(struct mbuf *m, struct carp_vhost_entry *vhe,
1002 if (!vhe->vhe_replay_cookie) {
1003 arc4random_buf(&vhe->vhe_replay_cookie,
1004 sizeof(vhe->vhe_replay_cookie));
1007 bcopy(&vhe->vhe_replay_cookie, ch->carp_counter,
1014 carp_hmac_generate(vhe, ch->carp_counter, ch->carp_md, HMAC_NOV6LL);
1047 struct carp_vhost_entry *vhe;
1051 SRPL_FOREACH_LOCKED(vhe, &sc->carp_vhosts, vhost_entries) {
1052 if (vhe->state == MASTER)
1053 carp_send_ad(vhe);
1066 carp_send_ad(struct carp_vhost_entry *vhe)
1070 struct carp_softc *sc = vhe->parent_sc;
1091 advskew = vhe->advskew;
1101 ch.carp_vhid = vhe->vhid;
1108 sc->cur_vhe = vhe; /* we need the vhe later on the output path */
1151 carp_prepare_ad(m, vhe, ch_ptr);
1188 if (vhe->vhe_leader) {
1239 carp_prepare_ad(m, vhe, ch_ptr);
1279 timeout_add_tv(&vhe->ad_tmo, &tv);
1331 struct carp_vhost_entry *vhe;
1341 SRPL_FOREACH_LOCKED(vhe, &sc->carp_vhosts, vhost_entries) {
1342 if (vhe->state == MASTER && count < sizeof(sc->sc_lsmask) * 8)
1354 struct carp_vhost_entry *vhe;
1358 vhe = SRPL_FIRST(&sr, &sc->carp_vhosts);
1359 if (vhe->state == MASTER)
1394 struct carp_vhost_entry *vhe;
1398 vhe = SRPL_FIRST(&sr, &sc->carp_vhosts);
1399 active = (vhe->state == MASTER || sc->sc_balancing >= CARP_BAL_IP);
1537 carp_master_down(struct carp_vhost_entry *vhe)
1539 struct carp_softc *sc = vhe->parent_sc;
1543 switch (vhe->state) {
1551 carp_set_state(vhe, MASTER);
1552 carp_send_ad(vhe);
1553 if (sc->sc_balancing == CARP_BAL_NONE && vhe->vhe_leader) {
1562 carp_setrun(vhe, 0);
1571 struct carp_vhost_entry *vhe;
1574 SRPL_FOREACH_LOCKED(vhe, &sc->carp_vhosts, vhost_entries) {
1575 carp_setrun(vhe, af);
1584 carp_setrun(struct carp_vhost_entry *vhe, sa_family_t af)
1588 struct carp_softc *sc = vhe->parent_sc;
1604 if (sc->sc_if.if_flags & IFF_UP && vhe->vhid > 0 &&
1612 switch (vhe->state) {
1614 carp_set_state(vhe, BACKUP);
1615 carp_setrun(vhe, 0);
1618 timeout_del(&vhe->ad_tmo);
1620 if (sc->sc_advbase == 0 && vhe->advskew == 0)
1623 tv.tv_usec = 3 * vhe->advskew * 1000000 / 256;
1625 tv.tv_usec = vhe->advskew * 1000000 / 256;
1626 if (vhe->vhe_leader)
1630 timeout_add_tv(&vhe->md_tmo, &tv);
1634 timeout_add_tv(&vhe->md6_tmo, &tv);
1639 timeout_add_tv(&vhe->md_tmo, &tv);
1641 timeout_add_tv(&vhe->md6_tmo, &tv);
1647 if (sc->sc_advbase == 0 && vhe->advskew == 0)
1650 tv.tv_usec = vhe->advskew * 1000000 / 256;
1651 timeout_add_tv(&vhe->ad_tmo, &tv);
1761 carp_set_vhe_enaddr(struct carp_vhost_entry *vhe)
1763 struct carp_softc *sc = vhe->parent_sc;
1765 if (vhe->vhid != 0 && sc->sc_carpdevidx != 0) {
1766 if (vhe->vhe_leader && sc->sc_balancing == CARP_BAL_IP)
1767 vhe->vhe_enaddr[0] = 1;
1769 vhe->vhe_enaddr[0] = 0;
1770 vhe->vhe_enaddr[1] = 0;
1771 vhe->vhe_enaddr[2] = 0x5e;
1772 vhe->vhe_enaddr[3] = 0;
1773 vhe->vhe_enaddr[4] = 1;
1774 vhe->vhe_enaddr[5] = vhe->vhid;
1776 memset(vhe->vhe_enaddr, 0, ETHER_ADDR_LEN);
1782 struct carp_vhost_entry *vhe;
1785 SRPL_FOREACH_LOCKED(vhe, &sc->carp_vhosts, vhost_entries)
1786 carp_set_vhe_enaddr(vhe);
1788 vhe = SRPL_FIRST_LOCKED(&sc->carp_vhosts);
1794 if ((memcmp(sc->sc_ac.ac_enaddr + 1, vhe->vhe_enaddr + 1,
1799 bcopy(vhe->vhe_enaddr, sc->sc_ac.ac_enaddr, ETHER_ADDR_LEN);
1998 struct carp_vhost_entry *vhe;
2029 vhe = SRPL_FIRST_LOCKED(&sc->carp_vhosts);
2030 if (vhe->state != INIT && !(ifr->ifr_flags & IFF_UP)) {
2042 } else if (vhe->state == INIT && (ifr->ifr_flags & IFF_UP)) {
2050 vhe = SRPL_FIRST_LOCKED(&sc->carp_vhosts);
2070 if (vhe->state != INIT && carpr.carpr_state != vhe->state) {
2073 timeout_del(&vhe->ad_tmo);
2080 SRPL_FOREACH_LOCKED(vhe, &sc->carp_vhosts,
2082 carp_master_down(vhe);
2102 SRPL_FOREACH_LOCKED(vhe, &sc->carp_vhosts,
2104 vhe->advskew = carpr.carpr_advskews[i++];
2134 SRPL_FOREACH_LOCKED(vhe, &sc->carp_vhosts, vhost_entries) {
2135 carpr.carpr_vhids[i] = vhe->vhid;
2136 carpr.carpr_advskews[i] = vhe->advskew;
2137 carpr.carpr_states[i] = vhe->state;
2178 struct carp_vhost_entry *vhe, *vhe0;
2186 SRPL_FOREACH_LOCKED(vhe, &vr->carp_vhosts, vhost_entries) {
2189 if (vhe->vhid == carpr->carpr_vhids[i])
2195 if (vhe->vhid == vhe0->vhid)
2378 struct carp_vhost_entry *vhe;
2383 vhe = SRPL_FIRST(&sr, &sc->carp_vhosts);
2384 ismaster = (vhe->state == MASTER);
2401 struct carp_vhost_entry *vhe;
2405 SRPL_FOREACH_LOCKED(vhe, &sc->carp_vhosts, vhost_entries) {
2406 if (vhe->state == state)
2409 carp_set_state(vhe, state);
2414 carp_set_state(struct carp_vhost_entry *vhe, int state)
2416 struct carp_softc *sc = vhe->parent_sc;
2421 KASSERT(vhe->state != state);
2423 if (vhe->state == INIT || state == INIT)
2430 ("state transition (vhid %d): %s -> %s", vhe->vhid,
2431 carp_states[vhe->state], carp_states[state]));
2435 carp_states[vhe->state], carp_states[state]));
2437 vhe->state = state;
2445 * Link must be up if at least one vhe is in state MASTER to
2682 struct carp_vhost_entry *vhe = v;
2684 refcnt_take(&vhe->vhost_refcnt);
2690 struct carp_vhost_entry *vhe = v;
2692 if (refcnt_rele(&vhe->vhost_refcnt)) {
2693 carp_sc_unref(NULL, vhe->parent_sc);
2694 free(vhe, M_DEVBUF, sizeof(*vhe));